<commit_before>#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gphoto2.h>

#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define _(String) (String)
#    define N_(String) (String)
#  endif
#else
#  define _(String) (String)
#  define N_(String) (String)
#endif

#include "barbie.h"

extern char packet_1[];

static char *models[] = {
	"Barbie",
	"Nick Click",
	"WWF",
	"Hot Wheels",
	NULL
};

int camera_id (CameraText *id) {

	strcpy(id->text, "barbie");

	return (GP_OK);
}

int camera_abilities (CameraAbilitiesList *list) {

	int x=0;
	CameraAbilities *a;

	while (models[x]) {

		/* Allocate the new abilities */
		a = gp_abilities_new();

		/* Fill in the appropriate flags/data */
		strcpy(a->model, models[x]);
		a->port      = GP_PORT_SERIAL;
		a->speed[0]  = 57600;
		a->speed[1]  = 0;
		a->operations        = GP_OPERATION_NONE;
		a->file_operations   = GP_FILE_OPERATION_PREVIEW;
		a->folder_operations = GP_FOLDER_OPERATION_NONE;

		/* Append it to the list */
		gp_abilities_list_append(list, a);

		x++;
	}	
	return (GP_OK);
}

int camera_init(Camera *camera) {

	gp_port_settings settings;
	BarbieStruct *b;
        int ret;

	/* First, set up all the function pointers */
	camera->functions->id 		= camera_id;
	camera->functions->abilities 	= camera_abilities;
	camera->functions->init 	= camera_init;
	camera->functions->exit 	= camera_exit;
	camera->functions->folder_list_folders  = camera_folder_list_folders;
	camera->functions->folder_list_files    = camera_folder_list_files;
	camera->functions->file_get 	= camera_file_get;
	camera->functions->file_get_preview =  camera_file_get_preview;
	camera->functions->summary	= camera_summary;
	camera->functions->manual 	= camera_manual;
	camera->functions->about 	= camera_about;

	b = (BarbieStruct*)malloc(sizeof(BarbieStruct));
	camera->camlib_data = b;

        if ((ret = gp_port_new(&(b->dev), GP_PORT_SERIAL)) < 0) {
            return (ret);
        }
	gp_port_timeout_set(b->dev, 5000);
	strcpy(settings.serial.port, camera->port->path);

	settings.serial.speed	= 57600;
	settings.serial.bits	= 8;
	settings.serial.parity	= 0;
	settings.serial.stopbits= 1;

	gp_port_settings_set(b->dev, settings);
	gp_port_open(b->dev);

	/* Create the filesystem */
	b->fs = gp_filesystem_new();

	return (barbie_ping(b));
}

int camera_exit(Camera *camera) {

	BarbieStruct *b = (BarbieStruct*)camera->camlib_data;

	gp_port_close(b->dev);
	gp_filesystem_free(b->fs);

	return GP_OK;
}


int camera_folder_list (Camera *camera, const char *folder, CameraList *list) {

	/* there are never any subfolders */

	return GP_OK;
}

int camera_file_list (Camera *camera, const char *folder, CameraList *list) 
{

	int count, x;
	BarbieStruct *b = (BarbieStruct*)camera->camlib_data;

	count = barbie_file_count(b);

	/* Populate the filesystem */
	gp_filesystem_populate (b->fs, "/", "mattel%02i.ppm", count);

	for (x = 0; x < gp_filesystem_count (b->fs, folder); x++) 
		gp_list_append (list, 
				gp_filesystem_name (b->fs, folder, x), 
				GP_LIST_FILE);

	return GP_OK;
}

int camera_file_get (Camera *camera, const char *folder, const char *filename, <commit_msg>fixed list_folders/files naming bug<commit_after>#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gphoto2.h>

#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define _(String) (String)
#    define N_(String) (String)
#  endif
#else
#  define _(String) (String)
#  define N_(String) (String)
#endif

#include "barbie.h"

extern char packet_1[];

static char *models[] = {
	"Barbie",
	"Nick Click",
	"WWF",
	"Hot Wheels",
	NULL
};

int camera_id (CameraText *id) {

	strcpy(id->text, "barbie");

	return (GP_OK);
}

int camera_abilities (CameraAbilitiesList *list) {

	int x=0;
	CameraAbilities *a;

	while (models[x]) {

		/* Allocate the new abilities */
		a = gp_abilities_new();

		/* Fill in the appropriate flags/data */
		strcpy(a->model, models[x]);
		a->port      = GP_PORT_SERIAL;
		a->speed[0]  = 57600;
		a->speed[1]  = 0;
		a->operations        = GP_OPERATION_NONE;
		a->file_operations   = GP_FILE_OPERATION_PREVIEW;
		a->folder_operations = GP_FOLDER_OPERATION_NONE;

		/* Append it to the list */
		gp_abilities_list_append(list, a);

		x++;
	}	
	return (GP_OK);
}

int camera_init(Camera *camera) {

	gp_port_settings settings;
	BarbieStruct *b;
        int ret;

	/* First, set up all the function pointers */
	camera->functions->id 		= camera_id;
	camera->functions->abilities 	= camera_abilities;
	camera->functions->init 	= camera_init;
	camera->functions->exit 	= camera_exit;
	camera->functions->folder_list_folders  = camera_folder_list_folders;
	camera->functions->folder_list_files    = camera_folder_list_files;
	camera->functions->file_get 	= camera_file_get;
	camera->functions->file_get_preview =  camera_file_get_preview;
	camera->functions->summary	= camera_summary;
	camera->functions->manual 	= camera_manual;
	camera->functions->about 	= camera_about;

	b = (BarbieStruct*)malloc(sizeof(BarbieStruct));
	camera->camlib_data = b;

        if ((ret = gp_port_new(&(b->dev), GP_PORT_SERIAL)) < 0) {
            return (ret);
        }
	gp_port_timeout_set(b->dev, 5000);
	strcpy(settings.serial.port, camera->port->path);

	settings.serial.speed	= 57600;
	settings.serial.bits	= 8;
	settings.serial.parity	= 0;
	settings.serial.stopbits= 1;

	gp_port_settings_set(b->dev, settings);
	gp_port_open(b->dev);

	/* Create the filesystem */
	b->fs = gp_filesystem_new();

	return (barbie_ping(b));
}

int camera_exit(Camera *camera) {

	BarbieStruct *b = (BarbieStruct*)camera->camlib_data;

	gp_port_close(b->dev);
	gp_filesystem_free(b->fs);

	return GP_OK;
}


int camera_folder_list_folders (Camera *camera, const char *folder, CameraList *list) {

	/* there are never any subfolders */

	return GP_OK;
}

int camera_folder_list_files (Camera *camera, const char *folder, CameraList *list) 
{

	int count, x;
	BarbieStruct *b = (BarbieStruct*)camera->camlib_data;

	count = barbie_file_count(b);

	/* Populate the filesystem */
	gp_filesystem_populate (b->fs, "/", "mattel%02i.ppm", count);

	for (x = 0; x < gp_filesystem_count (b->fs, folder); x++) 
		gp_list_append (list, 
				gp_filesystem_name (b->fs, folder, x), 
				GP_LIST_FILE);

	return GP_OK;
}

int camera_file_get (Camera *camera, const char *folder, const char *filename, 
{'fraction_non_alphanumeric': 0.14094060898402172, 'fraction_numerical': 0.008139885438649382, 'mean_word_length': 4.270055599682287, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 105, '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': '6576478', 'n_tokens_mistral': 2618, 'n_tokens_neox': 2446, 'n_words': 519}