remove big static strings in Init_Program()
This commit is contained in:
parent
75c93b0ce4
commit
8f0d036fe1
56
src/main.c
56
src/main.c
@ -348,15 +348,14 @@ struct {
|
|||||||
*
|
*
|
||||||
* @param argc argument count
|
* @param argc argument count
|
||||||
* @param argv argument values
|
* @param argv argument values
|
||||||
* @param main_filename pointer to receive 1st file name
|
* @param filenames pointers to receive file names
|
||||||
* @param main_directory pointer to receive 1st file directory
|
* @param directories pointers to receive file directories
|
||||||
* @param spare_filename pointer to receive 2nd file name
|
|
||||||
* @param spare_directory pointer to receive 2nd file directory
|
|
||||||
* @return the number of file to open (0, 1 or 2)
|
* @return the number of file to open (0, 1 or 2)
|
||||||
*/
|
*/
|
||||||
int Analyze_command_line(int argc, char * argv[], char *main_filename, char *main_directory, char *spare_filename, char *spare_directory)
|
int Analyze_command_line(int argc, char * argv[], char * filenames[], char * directories[])
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
char *filename;
|
||||||
int index;
|
int index;
|
||||||
int file_in_command_line;
|
int file_in_command_line;
|
||||||
|
|
||||||
@ -553,23 +552,23 @@ int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai
|
|||||||
}
|
}
|
||||||
else if (File_exists(argv[index]))
|
else if (File_exists(argv[index]))
|
||||||
{
|
{
|
||||||
file_in_command_line ++;
|
|
||||||
buffer = Realpath(argv[index], NULL);
|
buffer = Realpath(argv[index], NULL);
|
||||||
|
filename = Find_last_separator(buffer);
|
||||||
if (file_in_command_line == 1)
|
if (filename != NULL)
|
||||||
{
|
{
|
||||||
// Separate path from filename
|
*filename = '\0';
|
||||||
Extract_path(main_directory, buffer);
|
filename++;
|
||||||
Extract_filename(main_filename, buffer);
|
directories[file_in_command_line] = strdup(buffer);
|
||||||
|
filenames[file_in_command_line] = strdup(filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Separate path from filename
|
directories[file_in_command_line] = strdup(".");
|
||||||
Extract_path(spare_directory, buffer);
|
filenames[file_in_command_line] = strdup(buffer);
|
||||||
Extract_filename(spare_filename, buffer);
|
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
|
file_in_command_line++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -618,11 +617,9 @@ int Init_program(int argc,char * argv[])
|
|||||||
T_Gui_skin *gfx;
|
T_Gui_skin *gfx;
|
||||||
int file_in_command_line;
|
int file_in_command_line;
|
||||||
T_Gradient_array initial_gradients;
|
T_Gradient_array initial_gradients;
|
||||||
static char main_filename [MAX_PATH_CHARACTERS];
|
char * filenames[2] = {NULL, NULL};
|
||||||
static char main_directory[MAX_PATH_CHARACTERS];
|
char * directories[2] = {NULL, NULL};
|
||||||
static char spare_filename [MAX_PATH_CHARACTERS];
|
word * filename_unicode;
|
||||||
static char spare_directory[MAX_PATH_CHARACTERS];
|
|
||||||
static word filename_unicode[MAX_PATH_CHARACTERS];
|
|
||||||
|
|
||||||
#if defined(__MINT__)
|
#if defined(__MINT__)
|
||||||
printf("===============================\n");
|
printf("===============================\n");
|
||||||
@ -770,7 +767,7 @@ int Init_program(int argc,char * argv[])
|
|||||||
// Analyse command-line as soon as possible.
|
// Analyse command-line as soon as possible.
|
||||||
// This must come after video mode initialization because
|
// This must come after video mode initialization because
|
||||||
// a video mode may be requested as a command-line parameter
|
// a video mode may be requested as a command-line parameter
|
||||||
file_in_command_line=Analyze_command_line(argc, argv, main_filename, main_directory, spare_filename, spare_directory);
|
file_in_command_line = Analyze_command_line(argc, argv, filenames, directories);
|
||||||
|
|
||||||
#if defined(USE_JOYSTICK) && (defined(USE_SDL) || defined(USE_SDL2))
|
#if defined(USE_JOYSTICK) && (defined(USE_SDL) || defined(USE_SDL2))
|
||||||
GFX2_Log(GFX2_DEBUG, "%d joystick(s) attached\n", SDL_NumJoysticks());
|
GFX2_Log(GFX2_DEBUG, "%d joystick(s) attached\n", SDL_NumJoysticks());
|
||||||
@ -1065,9 +1062,9 @@ int Init_program(int argc,char * argv[])
|
|||||||
// Make sure the load dialog points to the right place when first shown.
|
// Make sure the load dialog points to the right place when first shown.
|
||||||
// Done after loading everything else, but before checking for emergency
|
// Done after loading everything else, but before checking for emergency
|
||||||
// backups
|
// backups
|
||||||
if (file_in_command_line > 0)
|
if (file_in_command_line > 0 && directories[0] != NULL)
|
||||||
{
|
{
|
||||||
strcpy(Main.selector.Directory, main_directory);
|
strcpy(Main.selector.Directory, directories[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test de recuperation de fichiers sauvés
|
// Test de recuperation de fichiers sauvés
|
||||||
@ -1136,11 +1133,12 @@ int Init_program(int argc,char * argv[])
|
|||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// Load this file
|
// Load this file
|
||||||
Init_context_layered_image(&context, spare_filename, spare_directory);
|
Init_context_layered_image(&context, filenames[1], directories[1]);
|
||||||
if (Get_Unicode_Filename(filename_unicode, spare_filename, spare_directory))
|
filename_unicode = Get_Unicode_Filename(NULL, filenames[1], directories[1]);
|
||||||
context.File_name_unicode = filename_unicode;
|
context.File_name_unicode = filename_unicode;
|
||||||
Load_image(&context);
|
Load_image(&context);
|
||||||
Destroy_context(&context);
|
Destroy_context(&context);
|
||||||
|
free(filename_unicode);
|
||||||
Redraw_layered_image();
|
Redraw_layered_image();
|
||||||
End_of_modification();
|
End_of_modification();
|
||||||
|
|
||||||
@ -1150,11 +1148,12 @@ int Init_program(int argc,char * argv[])
|
|||||||
__attribute__ ((fallthrough));
|
__attribute__ ((fallthrough));
|
||||||
#endif
|
#endif
|
||||||
case 1:
|
case 1:
|
||||||
Init_context_layered_image(&context, main_filename, main_directory);
|
Init_context_layered_image(&context, filenames[0], directories[0]);
|
||||||
if (Get_Unicode_Filename(filename_unicode, main_filename, main_directory))
|
filename_unicode = Get_Unicode_Filename(NULL, filenames[0], directories[0]);
|
||||||
context.File_name_unicode = filename_unicode;
|
context.File_name_unicode = filename_unicode;
|
||||||
Load_image(&context);
|
Load_image(&context);
|
||||||
Destroy_context(&context);
|
Destroy_context(&context);
|
||||||
|
free(filename_unicode);
|
||||||
Redraw_layered_image();
|
Redraw_layered_image();
|
||||||
End_of_modification();
|
End_of_modification();
|
||||||
|
|
||||||
@ -1187,6 +1186,11 @@ int Init_program(int argc,char * argv[])
|
|||||||
|
|
||||||
Allow_drag_and_drop(1);
|
Allow_drag_and_drop(1);
|
||||||
|
|
||||||
|
while (file_in_command_line-- > 0)
|
||||||
|
{
|
||||||
|
free(directories[file_in_command_line]);
|
||||||
|
free(filenames[file_in_command_line]);
|
||||||
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user