<commit_before>/* Notes:
	* only supports jpegs/gifs right now
	* uses the setting value of "dir_directory" to open as the directory
	  (interfaces will want to set this when they choose to "open" a 
	  directory.)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <gphoto2.h>

char  dir_directory[1024];
char  dir_images[1024][1024];
int   dir_num_images;
int   dir_get_index;

int camera_id (char *id) {

        strcpy(id, "directory-scottf");

        return (GP_OK);
}

int camera_debug_set (int onoff) {

	return (GP_OK);
}

int camera_abilities (CameraAbilities *abilities, int *count) {

	*count = 1;

	strcpy(abilities[0].model, "Directory Browse");
	abilities[0].serial   = 0;
	abilities[0].parallel = 0;
	abilities[0].usb      = 0;
	abilities[0].ieee1394 = 0;

	abilities[0].speed[0] = 0;

	abilities[0].capture   = 0;
	abilities[0].config    = 1;
	abilities[0].file_delete  = 0;
	abilities[0].file_preview = 1;
	abilities[0].file_put  = 0;

	return (GP_OK);
}

int camera_init (CameraInit *init) {

	int i=0;

	dir_num_images = 0;

	for (i=0; i<1024; i++)
		strcpy(dir_images[i], "");

	strcpy(dir_directory, init->port_settings.path);
	if (strlen(dir_directory)==0) {
		strcpy(dir_directory, "/");
	}

	return (GP_OK);
}

int camera_exit () {

	return (GP_OK);
}

int camera_folder_list(char *folder_name, CameraFolderInfo *list) {

	DIR *d;
	struct dirent *de;
	struct stat st;
	char *ch;
	char buf[1024];
	int count=0;

	if ((d = opendir(folder_name))==NULL) {
		sprintf(buf, "Could not access folder %s", folder_name);
		gp_message(buf);
		return (GP_ERROR);
	}
	while (de = readdir(d)) {
		if ((strcmp(de->d_name, ".") !=0) &&
		    (strcmp(de->d_name, "..")!=0)) {
			sprintf(buf, "%s/%s", folder_name, de->d_name);
			if (stat(buf, &st)==0) {
				if (S_ISDIR(st.st_mode)) {
					strcpy(list[count++].name, de->d_name);
				}
			}
		}
	}

	return (count);
}

int camera_folder_set(char *folder_name) {

	DIR *dir;
	struct dirent *de;
	struct stat s;
	char *dot, fname[1024];

	strcpy(dir_directory, folder_name);
	dir = opendir(dir_directory);
	if (!dir) {
		perror("directory: folder_set");
		return (GP_ERROR);
	}
	de = readdir(dir);
	while (de) {
		gp_progress(-1);
		sprintf(fname, "%s/%s", dir_directory, de->d_name);
		stat(fname, &s);
                /* If it's a file ...*/
                if (S_ISREG(s.st_mode)) {
			dot = strrchr(de->d_name, '.');
			if (
			    (strcasecmp(dot, ".gif")==0)||
			    (strcasecmp(dot, ".jpg")==0)||
			    (strcasecmp(dot, ".jpeg")==0)) {
				strcpy(dir_images[dir_num_images++],
					de->d_name);
#ifdef DEBUG
				printf("directory: found \"%s\"\n", de->d_name);
#endif
			}
		}<commit_msg>fixed crashing from NULL pointer<commit_after>/* Notes:
	* only supports jpegs/gifs right now
	* uses the setting value of "dir_directory" to open as the directory
	  (interfaces will want to set this when they choose to "open" a 
	  directory.)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <gphoto2.h>

char  dir_directory[1024];
char  dir_images[1024][1024];
int   dir_num_images;
int   dir_get_index;

int camera_id (char *id) {

        strcpy(id, "directory-scottf");

        return (GP_OK);
}

int camera_debug_set (int onoff) {

	return (GP_OK);
}

int camera_abilities (CameraAbilities *abilities, int *count) {

	*count = 1;

	strcpy(abilities[0].model, "Directory Browse");
	abilities[0].serial   = 0;
	abilities[0].parallel = 0;
	abilities[0].usb      = 0;
	abilities[0].ieee1394 = 0;

	abilities[0].speed[0] = 0;

	abilities[0].capture   = 0;
	abilities[0].config    = 1;
	abilities[0].file_delete  = 0;
	abilities[0].file_preview = 1;
	abilities[0].file_put  = 0;

	return (GP_OK);
}

int camera_init (CameraInit *init) {

	int i=0;

	dir_num_images = 0;

	for (i=0; i<1024; i++)
		strcpy(dir_images[i], "");

	strcpy(dir_directory, init->port_settings.path);
	if (strlen(dir_directory)==0) {
		strcpy(dir_directory, "/");
	}

	return (GP_OK);
}

int camera_exit () {

	return (GP_OK);
}

int camera_folder_list(char *folder_name, CameraFolderInfo *list) {

	DIR *d;
	struct dirent *de;
	struct stat st;
	char *ch;
	char buf[1024];
	int count=0;

	if ((d = opendir(folder_name))==NULL)
		return (GP_ERROR);

	while (de = readdir(d)) {
		if ((strcmp(de->d_name, ".") !=0) &&
		    (strcmp(de->d_name, "..")!=0)) {
			sprintf(buf, "%s/%s", folder_name, de->d_name);
			if (stat(buf, &st)==0) {
				if (S_ISDIR(st.st_mode)) {
					strcpy(list[count++].name, de->d_name);
				}
			}
		}
	}

	return (count);
}

int camera_folder_set(char *folder_name) {

	DIR *dir;
	struct dirent *de;
	struct stat s;
	char *dot, fname[1024];

	strcpy(dir_directory, folder_name);
	dir = opendir(dir_directory);
	if (!dir)
		return (GP_ERROR);
	de = readdir(dir);
	while (de) {
		gp_progress(-1);
		sprintf(fname, "%s/%s", dir_directory, de->d_name);
		stat(fname, &s);
                /* If it's a file ...*/
                if (S_ISREG(s.st_mode)) {
			dot = strrchr(de->d_name, '.');
			if (dot) {
			   if (
			    (strcasecmp(dot, ".gif")==0)||
			    (strcasecmp(dot, ".jpg")==0)||
			    (strcasecmp(dot, ".jpeg")==0)) {
				strcpy(dir_images[dir_num_images++],
					de->d_name);
#ifdef DEBUG
				printf("directory: found \"%s\"\n", de->d_name);
#endif
			   }
			}
		}
{'fraction_non_alphanumeric': 0.17883617494440326, 'fraction_numerical': 0.023721275018532245, 'mean_word_length': 3.520100502512563, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3283007', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2161, 'n_words': 468}