Better command-line handling (issue 266) contributed by Pasi Kallinen

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1227 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-11-29 18:25:14 +00:00
parent 224902e18e
commit 0a7bd889d1
2 changed files with 224 additions and 160 deletions

View File

@ -343,6 +343,9 @@ static const T_Help_table helptable_credits[] =
HELP_TEXT (" Petter Lindquist")
HELP_TEXT (" C64 file and image formats")
HELP_TEXT ("")
HELP_TEXT (" Pasi Kallinen")
HELP_TEXT (" Better command-line handling")
HELP_TEXT ("")
HELP_TEXT ("")
HELP_TITLE(" ART")
HELP_TEXT ("")
@ -414,10 +417,10 @@ static const T_Help_table helptable_credits[] =
HELP_TEXT (" HoraK-FDF iLKke Iw2evk ")
HELP_TEXT (" Jamon keito kusma ")
HELP_TEXT (" Lord Graga MagerValp mind ")
HELP_TEXT (" MooZ the Peach petter ")
HELP_TEXT (" richienyhus tape.wyrm TeeEmCee ")
HELP_TEXT (" tempest Timo Kurrpa titus^Rab ")
HELP_TEXT (" Tobé 00ai99")
HELP_TEXT (" MooZ Pasi Kallinen the Peach ")
HELP_TEXT (" petter richienyhus tape.wyrm ")
HELP_TEXT (" TeeEmCee tempest Timo Kurrpa ")
HELP_TEXT (" titus^Rab Tobé 00ai99")
HELP_TEXT ("")
HELP_TEXT ("")
HELP_TEXT (" ... posted the annoying bug reports.")

165
main.c
View File

@ -2,6 +2,7 @@
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2009 Pasi Kallinen
Copyright 2008 Peter Gordon
Copyright 2008 Franck Charlet
Copyright 2007 Adrien Destugues
@ -81,19 +82,21 @@
void Display_syntax(void)
{
int mode_index;
printf("Syntax: grafx2 [<arguments>] [<picture>]\n\n");
printf("Syntax: grafx2 [<arguments>] [<picture1>] [<picture2>]\n\n");
printf("<arguments> can be:]\n");
printf("\t/? /h /help for this help screen\n");
printf("\t/wide to emulate a video mode with wide pixels (2x1)\n");
printf("\t/tall to emulate a video mode with tall pixels (1x2)\n");
printf("\t/double to emulate a video mode with double pixels (2x2)\n");
printf("\t/wide2 to emulate a video mode with double wide pixels (4x2)\n");
printf("\t/tall2 to emulate a video mode with double tall pixels (2x4)\n");
printf("\t/triple to emulate a video mode with triple pixels (3x3)\n");
printf("\t/quadruple to emulate a video mode with quadruple pixels (4x4)\n");
printf("\t/rgb n to reduce RGB precision from 256 to n levels\n");
printf("\t/skin <filename> to use an alternate file with the menu graphics\n");
printf("\t/mode <videomode> to set a video mode\n\n");
printf("\t-? -h -H -help for this help screen\n");
printf("\t-wide to emulate a video mode with wide pixels (2x1)\n");
printf("\t-tall to emulate a video mode with tall pixels (1x2)\n");
printf("\t-double to emulate a video mode with double pixels (2x2)\n");
printf("\t-wide2 to emulate a video mode with double wide pixels (4x2)\n");
printf("\t-tall2 to emulate a video mode with double tall pixels (2x4)\n");
printf("\t-triple to emulate a video mode with triple pixels (3x3)\n");
printf("\t-quadruple to emulate a video mode with quadruple pixels (4x4)\n");
printf("\t-rgb n to reduce RGB precision from 256 to n levels\n");
printf("\t-skin <filename> to use an alternate file with the menu graphics\n");
printf("\t-mode <videomode> to set a video mode\n");
printf("Arguments can be prefixed either by / - or --\n");
printf("They can also be abbreviated.\n\n");
printf("Available video modes:\n\n");
for (mode_index = 0; mode_index < Nb_video_modes; mode_index += 12)
{
@ -171,13 +174,49 @@ void Error_function(int error_code, const char *filename, int line_number, const
}
}
enum CMD_PARAMS
{
CMDPARAM_HELP,
CMDPARAM_MODE,
CMDPARAM_PIXELRATIO_TALL,
CMDPARAM_PIXELRATIO_WIDE,
CMDPARAM_PIXELRATIO_DOUBLE,
CMDPARAM_PIXELRATIO_TRIPLE,
CMDPARAM_PIXELRATIO_QUAD,
CMDPARAM_PIXELRATIO_TALL2,
CMDPARAM_PIXELRATIO_WIDE2,
CMDPARAM_RGB,
CMDPARAM_SKIN
};
struct {
const char *param;
int id;
} cmdparams[] = {
{"?", CMDPARAM_HELP},
{"h", CMDPARAM_HELP},
{"H", CMDPARAM_HELP},
{"help", CMDPARAM_HELP},
{"mode", CMDPARAM_MODE},
{"tall", CMDPARAM_PIXELRATIO_TALL},
{"wide", CMDPARAM_PIXELRATIO_WIDE},
{"double", CMDPARAM_PIXELRATIO_DOUBLE},
{"triple", CMDPARAM_PIXELRATIO_TRIPLE},
{"quadruple", CMDPARAM_PIXELRATIO_QUAD},
{"tall2", CMDPARAM_PIXELRATIO_TALL2},
{"wide2", CMDPARAM_PIXELRATIO_WIDE2},
{"rgb", CMDPARAM_RGB},
{"skin", CMDPARAM_SKIN}
};
#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof(x[0]))
// --------------------- Analyse de la ligne de commande ---------------------
void Analyze_command_line(int argc, char * argv[])
{
char *buffer ;
int index;
File_in_command_line = 0;
Resolution_in_command_line = 0;
@ -185,17 +224,46 @@ void Analyze_command_line(int argc, char * argv[])
for (index = 1; index<argc; index++)
{
if ( !strcmp(argv[index],"/?") ||
!strcmp(argv[index],"/h") ||
!strcmp(argv[index],"/H") )
char *s = argv[index];
int is_switch = ((strchr(s,'/') == s) || (strchr(s,'-') == s) || (strstr(s,"--") == s));
int tmpi;
int paramtype = -1;
if (is_switch)
{
// help
int param_matches = 0;
int param_match = -1;
if (*s == '-')
{
s++;
if (*s == '-')
s++;
}
else
s++;
for (tmpi = 0; tmpi < ARRAY_SIZE(cmdparams); tmpi++)
{
if (!strcmp(s, cmdparams[tmpi].param))
{
paramtype = cmdparams[tmpi].id;
break;
}
else if (strstr(cmdparams[tmpi].param, s))
{
param_matches++;
param_match = cmdparams[tmpi].id;
}
}
if (paramtype == -1 && param_matches == 1)
paramtype = param_match;
}
switch (paramtype)
{
case CMDPARAM_HELP:
Display_syntax();
exit(0);
}
else if ( !strcmp(argv[index],"/mode") )
{
// mode
case CMDPARAM_MODE:
index++;
if (index<argc)
{
@ -219,37 +287,29 @@ void Analyze_command_line(int argc, char * argv[])
Display_syntax();
exit(0);
}
}
else if ( !strcmp(argv[index],"/tall") )
{
break;
case CMDPARAM_PIXELRATIO_TALL:
Pixel_ratio = PIXEL_TALL;
}
else if ( !strcmp(argv[index],"/wide") )
{
break;
case CMDPARAM_PIXELRATIO_WIDE:
Pixel_ratio = PIXEL_WIDE;
}
else if ( !strcmp(argv[index],"/double") )
{
break;
case CMDPARAM_PIXELRATIO_DOUBLE:
Pixel_ratio = PIXEL_DOUBLE;
}
else if ( !strcmp(argv[index],"/triple") )
{
break;
case CMDPARAM_PIXELRATIO_TRIPLE:
Pixel_ratio = PIXEL_TRIPLE;
}
else if ( !strcmp(argv[index],"/quadruple") )
{
break;
case CMDPARAM_PIXELRATIO_QUAD:
Pixel_ratio = PIXEL_QUAD;
}
else if ( !strcmp(argv[index],"/tall2") )
{
break;
case CMDPARAM_PIXELRATIO_TALL2:
Pixel_ratio = PIXEL_TALL2;
}
else if ( !strcmp(argv[index],"/wide2") )
{
break;
case CMDPARAM_PIXELRATIO_WIDE2:
Pixel_ratio = PIXEL_WIDE2;
}
else if ( !strcmp(argv[index],"/rgb") )
{
break;
case CMDPARAM_RGB:
// echelle des composants RGB
index++;
if (index<argc)
@ -270,9 +330,8 @@ void Analyze_command_line(int argc, char * argv[])
Display_syntax();
exit(0);
}
}
else if ( !strcmp(argv[index],"/skin") )
{
break;
case CMDPARAM_SKIN:
// GUI skin file
index++;
if (index<argc)
@ -285,9 +344,8 @@ void Analyze_command_line(int argc, char * argv[])
Display_syntax();
exit(0);
}
}
else
{
break;
default:
// Si ce n'est pas un paramètre, c'est le nom du fichier à ouvrir
if (File_in_command_line > 1)
{
@ -307,7 +365,9 @@ void Analyze_command_line(int argc, char * argv[])
Extract_path(Main_file_directory, buffer);
Extract_filename(Main_filename, buffer);
free(buffer);
} else {
}
else
{
Extract_path(Spare_file_directory, buffer);
Extract_filename(Spare_filename, buffer);
free(buffer);
@ -319,6 +379,7 @@ void Analyze_command_line(int argc, char * argv[])
Display_syntax();
exit(0);
}
break;
}
}
}