Process Win32 commandline

This commit is contained in:
Thomas Bernard 2018-06-22 14:38:40 +02:00
parent e4b3ca7109
commit d809adb540

View File

@ -37,6 +37,10 @@
#include <signal.h>
#ifndef _MSC_VER
#include <unistd.h>
#else
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#endif
#if defined(USE_SDL) || defined(USE_SDL2)
#include <SDL.h>
@ -104,35 +108,45 @@ static int setsize_height;
//--- Affichage de la syntaxe, et de la liste des modes vidéos disponibles ---
void Display_syntax(void)
{
int mode_index;
printf("Syntax: grafx2 [<arguments>] [<picture1>] [<picture2>]\n\n");
printf("<arguments> can be:]\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 (2 to 256, 256=max precision)\n");
printf("\t-gamma n to adjust Gamma correction (1 to 30, 10=no correction)\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("\t-size <resolution> to set the image size\n");
printf("Arguments can be prefixed either by / - or --\n");
printf("They can also be abbreviated.\n\n");
printf("Available video modes:\n\n");
int mode_index, i;
char modes[1024*2];
const char * syntax =
"Syntax: grafx2 [<arguments>] [<picture1>] [<picture2>]\n\n"
"<arguments> can be:\n"
"\t-? -h -H -help for this help screen\n"
"\t-wide to emulate a video mode with wide pixels (2x1)\n"
"\t-tall to emulate a video mode with tall pixels (1x2)\n"
"\t-double to emulate a video mode with double pixels (2x2)\n"
"\t-wide2 to emulate a video mode with double wide pixels (4x2)\n"
"\t-tall2 to emulate a video mode with double tall pixels (2x4)\n"
"\t-triple to emulate a video mode with triple pixels (3x3)\n"
"\t-quadruple to emulate a video mode with quadruple pixels (4x4)\n"
"\t-rgb n to reduce RGB precision (2 to 256, 256=max precision)\n"
"\t-gamma n to adjust Gamma correction (1 to 30, 10=no correction)\n"
"\t-skin <filename> to use an alternate file with the menu graphics\n"
"\t-mode <videomode> to set a video mode\n"
"\t-size <resolution> to set the image size\n"
"Arguments can be prefixed either by / - or --\n"
"They can also be abbreviated.\n\n";
fputs(syntax, stdout);
i = snprintf(modes, sizeof(modes), "Available video modes:\n\n");
for (mode_index = 0; mode_index < Nb_video_modes; mode_index += 12)
{
int k;
for (k = 0; k < 6; k++)
{
if (mode_index + k >= Nb_video_modes) break;
printf("%12s",Mode_label(mode_index + k));
i += snprintf(modes + i, sizeof(modes) - i, "%12s", Mode_label(mode_index + k));
}
puts("");
i += snprintf(modes + i, sizeof(modes) - i, "\n");
}
fputs(modes, stdout);
#if defined(WIN32)
MessageBoxA(NULL, syntax, "GrafX2", MB_OK);
MessageBoxA(NULL, modes, "GrafX2", MB_OK);
#endif
}
// ---------------------------- Sortie impromptue ----------------------------
@ -1169,21 +1183,84 @@ int main(int argc,char * argv[])
{
#if defined(WIN32) && !defined(USE_SDL) && !defined(USE_SDL2)
TCHAR ModuleFileName[MAX_PATH];
TCHAR ModuleShortFileName[MAX_PATH];
int i;
TCHAR TmpArg[MAX_PATH];
TCHAR ShortFileName[MAX_PATH];
int i, j, k;
int inquote = 0;
int argc = 0;
char arg_buffer[4096];
char * argv[16] = {NULL};
char * argv[64] = {NULL};
Init_Win32(hInstance, hPrevInstance);
GetModuleFileName(NULL, ModuleFileName, MAX_PATH);
GetShortPathName(ModuleFileName, ModuleShortFileName, MAX_PATH);
argv[argc++] = arg_buffer;
for (i = 0; i < (int)sizeof(arg_buffer); i++) {
arg_buffer[i] = (char)ModuleShortFileName[i];
if (arg_buffer[i] == 0) break;
if (GetModuleFileName(NULL, ModuleFileName, MAX_PATH) == 0)
{
MessageBoxA(NULL, "Error initializing program", NULL, MB_OK | MB_ICONERROR);
return 1;
}
// TODO : parse command line
GetShortPathName(ModuleFileName, ShortFileName, MAX_PATH);
argv[argc++] = arg_buffer;
for (i = 0; i < (int)sizeof(arg_buffer); )
{
arg_buffer[i] = (char)ShortFileName[i];
if (arg_buffer[i++] == 0) break;
}
k = 0;
for (j = 0; pCmdLine[j] != 0 && k < MAX_PATH - 1; j++)
{
if (inquote)
{
if (pCmdLine[j] == '"')
{
inquote = 0;
continue;
}
}
else
{
if (pCmdLine[j] == '"')
{
inquote = 1;
continue;
}
if (pCmdLine[j] == ' ' || pCmdLine[j] == '\t')
{ // next argument
TmpArg[k++] = '\0';
argv[argc++] = arg_buffer + i;
if (GetShortPathName(TmpArg, ShortFileName, MAX_PATH) > 0)
{
for (k = 0; ShortFileName[k] != 0; k++)
arg_buffer[i++] = ShortFileName[k];
}
else
{
for (k = 0; TmpArg[k] != 0; k++)
arg_buffer[i++] = TmpArg[k];
}
arg_buffer[i++] = 0;
k = 0;
continue;
}
}
TmpArg[k++] = pCmdLine[j];
}
TmpArg[k] = '\0';
if (k > 0)
{
argv[argc++] = arg_buffer + i;
if (GetShortPathName(TmpArg, ShortFileName, MAX_PATH) > 0)
{
for (k = 0; ShortFileName[k] != 0; k++)
arg_buffer[i++] = ShortFileName[k];
}
else
{
for (k = 0; TmpArg[k] != 0; k++)
arg_buffer[i++] = TmpArg[k];
}
arg_buffer[i++] = 0;
}
// TODO : nCmdShow indicates if the window must be maximized, etc.
#endif
if(!Init_program(argc,argv))
{