update For_each_file() to pass both full path and file name only to the callback
All callbacks need to extract the filename anyway, so it simplify the code
This commit is contained in:
parent
a4593da4d4
commit
4a2754321f
@ -1225,17 +1225,11 @@ char * Format_font_filename(const char * fname)
|
||||
}
|
||||
|
||||
// Add a skin to the list
|
||||
void Add_font_or_skin(const char *name)
|
||||
static void Add_font_or_skin(const char * full_name, const char * fname)
|
||||
{
|
||||
const char * fname;
|
||||
int namelength;
|
||||
size_t namelength;
|
||||
(void)full_name;
|
||||
|
||||
// Cut the long name to keep only filename (no directory)
|
||||
fname = Find_last_separator(name);
|
||||
if (fname)
|
||||
fname++;
|
||||
else
|
||||
fname = name;
|
||||
namelength = strlen(fname);
|
||||
if (namelength>=10 && fname[0]!='_' && !strncasecmp(fname, SKIN_PREFIX, strlen(SKIN_PREFIX))
|
||||
&& (!strcasecmp(fname + namelength - 4,".png")
|
||||
|
||||
4
src/io.c
4
src/io.c
@ -358,7 +358,7 @@ int File_length_file(FILE * file)
|
||||
return infos_fichier.st_size;
|
||||
}
|
||||
|
||||
void For_each_file(const char * directory_name, void Callback(const char *))
|
||||
void For_each_file(const char * directory_name, void Callback(const char *, const char *))
|
||||
{
|
||||
// Pour scan de répertoire
|
||||
DIR* current_directory; //Répertoire courant
|
||||
@ -385,7 +385,7 @@ void For_each_file(const char * directory_name, void Callback(const char *))
|
||||
stat(full_filename,&Infos_enreg);
|
||||
if (S_ISREG(Infos_enreg.st_mode))
|
||||
{
|
||||
Callback(full_filename);
|
||||
Callback(full_filename, entry->d_name);
|
||||
}
|
||||
}
|
||||
closedir(current_directory);
|
||||
|
||||
2
src/io.h
2
src/io.h
@ -97,7 +97,7 @@ int Directory_exists(char * directory);
|
||||
int File_is_hidden(const char *fname, const char *full_name);
|
||||
|
||||
/// Scans a directory, calls Callback for each file in it,
|
||||
void For_each_file(const char * directory_name, void Callback(const char *));
|
||||
void For_each_file(const char * directory_name, void Callback(const char * full_name, const char * file_name));
|
||||
|
||||
typedef void T_File_dir_cb(void * pdata, const char * filename, const word * unicode_filename, byte is_file, byte is_directory, byte is_hidden);
|
||||
|
||||
|
||||
@ -1492,17 +1492,15 @@ const int Max_edits_for_safety_backup = 30;
|
||||
///
|
||||
/// Adds a file to Backups_main or Backups_spare lists, if it's a backup.
|
||||
///
|
||||
void Add_backup_file(const char *name)
|
||||
static void Add_backup_file(const char * full_name, const char *file_name)
|
||||
{
|
||||
T_String_list ** list;
|
||||
T_String_list * elem;
|
||||
int i;
|
||||
char file_name[MAX_PATH_CHARACTERS];
|
||||
(void)full_name;
|
||||
|
||||
// Only files names of the form a0000000.* and b0000000.* are expected
|
||||
|
||||
Extract_filename(file_name, name);
|
||||
|
||||
// Check first character
|
||||
if (file_name[0]==Main.safety_backup_prefix)
|
||||
list = &Backups_main;
|
||||
|
||||
14
src/text.c
14
src/text.c
@ -91,9 +91,8 @@ int Compare_fonts(T_Font * font_1, T_Font * font_2)
|
||||
}
|
||||
|
||||
// Ajout d'une fonte à la liste.
|
||||
void Add_font(const char *name)
|
||||
static void Add_font(const char *name, const char * font_name)
|
||||
{
|
||||
char * font_name;
|
||||
T_Font * font;
|
||||
int size=strlen(name)+1;
|
||||
int index;
|
||||
@ -162,17 +161,12 @@ void Add_font(const char *name)
|
||||
#endif
|
||||
}
|
||||
|
||||
font->Name = (char *)malloc(size);
|
||||
strcpy(font->Name, name);
|
||||
font->Name = strdup(name);
|
||||
// Label
|
||||
strcpy(font->Label, " ");
|
||||
memset(font->Label, ' ', sizeof(font->Label));
|
||||
font->Label[19] = '\0';
|
||||
if (font->Is_truetype)
|
||||
font->Label[17]=font->Label[18]='T'; // Logo TT
|
||||
font_name=Find_last_separator(font->Name);
|
||||
if (font_name==NULL)
|
||||
font_name=font->Name;
|
||||
else
|
||||
font_name++;
|
||||
for (index=0; index < 17 && font_name[index]!='\0' && font_name[index]!='.'; index++)
|
||||
font->Label[index]=font_name[index];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user