Allow spaces in compiler command line options (bug 3729, r=dvander)

This commit is contained in:
Fyren 2009-03-12 18:37:04 -07:00
parent 7fac7c8713
commit f6bb6037f3

View File

@ -805,17 +805,24 @@ SC_FUNC void set_extension(char *filename,char *extension,int force)
strcat(filename,extension); strcat(filename,extension);
} }
static const char *option_value(const char *optptr) static const char *option_value(const char *optptr,char **argv,int argc,int *arg)
{ {
return (*(optptr+1)=='=' || *(optptr+1)==':') ? optptr+2 : optptr+1; const char *ptr;
if (*(optptr+1)=='=' || *(optptr+1)==':')
ptr=optptr+2;
else
ptr=optptr+1;
if (strlen(ptr)==0 && *arg!=argc-1)
ptr=argv[++*arg];
return ptr;
} }
static int toggle_option(const char *optptr, int option) static int toggle_option(const char *optptr,int option)
{ {
switch (*option_value(optptr)) { switch ((*(optptr+1)=='=' || *(optptr+1)==':') ? *(optptr+2) : *(optptr+1)) {
case '\0':
option=!option;
break;
case '-': case '-':
option=FALSE; option=FALSE;
break; break;
@ -853,7 +860,7 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
ptr=&argv[arg][1]; ptr=&argv[arg][1];
switch (*ptr) { switch (*ptr) {
case 'A': case 'A':
i=atoi(option_value(ptr)); i=atoi(option_value(ptr,argv,argc,&arg));
if ((i % sizeof(cell))==0) if ((i % sizeof(cell))==0)
sc_dataalign=i; sc_dataalign=i;
else else
@ -876,11 +883,11 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
break; break;
#endif #endif
case 'c': case 'c':
strlcpy(codepage,option_value(ptr),MAXCODEPAGE); /* set name of codepage */ strlcpy(codepage,option_value(ptr,argv,argc,&arg),MAXCODEPAGE); /* set name of codepage */
break; break;
#if defined dos_setdrive #if defined dos_setdrive
case 'D': /* set active directory */ case 'D': /* set active directory */
ptr=option_value(ptr); ptr=option_value(ptr,argv,argc,&arg);
if (ptr[1]==':') if (ptr[1]==':')
dos_setdrive(toupper(*ptr)-'A'+1); /* set active drive */ dos_setdrive(toupper(*ptr)-'A'+1); /* set active drive */
chdir(ptr); chdir(ptr);
@ -888,7 +895,7 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
#endif #endif
#if 0 /* not allowed to change for SourceMod */ #if 0 /* not allowed to change for SourceMod */
case 'd': case 'd':
switch (*option_value(ptr)) { switch (*option_value(ptr,argv,argc,&arg)) {
case '0': case '0':
sc_debug=0; sc_debug=0;
break; break;
@ -909,17 +916,17 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
break; break;
#endif #endif
case 'e': case 'e':
strlcpy(ename,option_value(ptr),_MAX_PATH); /* set name of error file */ strlcpy(ename,option_value(ptr,argv,argc,&arg),_MAX_PATH); /* set name of error file */
break; break;
#if defined __WIN32__ || defined _WIN32 || defined _Windows #if defined __WIN32__ || defined _WIN32 || defined _Windows
case 'H': case 'H':
hwndFinish=(HWND)atoi(option_value(ptr)); hwndFinish=(HWND)atoi(option_value(ptr,argv,argc,&arg));
if (!IsWindow(hwndFinish)) if (!IsWindow(hwndFinish))
hwndFinish=(HWND)0; hwndFinish=(HWND)0;
break; break;
#endif #endif
case 'i': case 'i':
strlcpy(str,option_value(ptr),sizeof str); /* set name of include directory */ strlcpy(str,option_value(ptr,argv,argc,&arg),sizeof str); /* set name of include directory */
i=strlen(str); i=strlen(str);
if (i>0) { if (i>0) {
if (str[i-1]!=DIRSEP_CHAR) { if (str[i-1]!=DIRSEP_CHAR) {
@ -935,21 +942,22 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
sc_listing=TRUE; /* skip second pass & code generation */ sc_listing=TRUE; /* skip second pass & code generation */
break; break;
case 'o': case 'o':
strlcpy(oname,option_value(ptr),_MAX_PATH); /* set name of (binary) output file */ strlcpy(oname,option_value(ptr,argv,argc,&arg),_MAX_PATH); /* set name of (binary) output file */
break; break;
case 'O': case 'O':
pc_optimize=*option_value(ptr) - '0'; pc_optimize=*option_value(ptr,argv,argc,&arg) - '0';
if (pc_optimize<sOPTIMIZE_NONE || pc_optimize>=sOPTIMIZE_NUMBER || pc_optimize==sOPTIMIZE_NOMACRO) if (pc_optimize<sOPTIMIZE_NONE || pc_optimize>=sOPTIMIZE_NUMBER || pc_optimize==sOPTIMIZE_NOMACRO)
about(); about();
break; break;
case 'p': case 'p':
strlcpy(pname,option_value(ptr),_MAX_PATH); /* set name of implicit include file */ strlcpy(pname,option_value(ptr,argv,argc,&arg),_MAX_PATH); /* set name of implicit include file */
break; break;
#if !defined SC_LIGHT #if !defined SC_LIGHT
case 'r': case 'r':
strlcpy(rname,option_value(ptr),_MAX_PATH); /* set name of report file */ strlcpy(rname,option_value(ptr,argv,argc,&arg),_MAX_PATH); /* set name of report file */
sc_makereport=TRUE; sc_makereport=TRUE;
if (strlen(rname)>0) { #if 0 /* dead code due to option_value change to allow spaces between option and value */
if (strlen(rname)>0) {
set_extension(rname,".xml",FALSE); set_extension(rname,".xml",FALSE);
} else if ((name=get_sourcefile(0))!=NULL) { } else if ((name=get_sourcefile(0))!=NULL) {
assert(strlen(rname)==0); assert(strlen(rname)==0);
@ -962,28 +970,29 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
strcpy(rname,ptr); strcpy(rname,ptr);
set_extension(rname,".xml",TRUE); set_extension(rname,".xml",TRUE);
} /* if */ } /* if */
#endif
break; break;
#endif #endif
case 'S': case 'S':
i=atoi(option_value(ptr)); i=atoi(option_value(ptr,argv,argc,&arg));
if (i>32) if (i>32)
pc_stksize=(cell)i; /* stack size has minimum size */ pc_stksize=(cell)i; /* stack size has minimum size */
else else
about(); about();
break; break;
case 's': case 's':
skipinput=atoi(option_value(ptr)); skipinput=atoi(option_value(ptr,argv,argc,&arg));
break; break;
case 't': case 't':
sc_tabsize=atoi(option_value(ptr)); sc_tabsize=atoi(option_value(ptr,argv,argc,&arg));
break; break;
case 'v': case 'v':
verbosity= isdigit(*option_value(ptr)) ? atoi(option_value(ptr)) : 2; verbosity= isdigit(*option_value(ptr,argv,argc,&arg)) ? atoi(option_value(ptr,argv,argc,&arg)) : 2;
if (sc_asmfile && verbosity>1) if (sc_asmfile && verbosity>1)
verbosity=1; verbosity=1;
break; break;
case 'w': case 'w':
i=(int)strtol(option_value(ptr),(char **)&ptr,10); i=(int)strtol(option_value(ptr,argv,argc,&arg),(char **)&ptr,10);
if (*ptr=='-') if (*ptr=='-')
pc_enablewarning(i,0); pc_enablewarning(i,0);
else if (*ptr=='+') else if (*ptr=='+')
@ -993,13 +1002,13 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
break; break;
case 'X': case 'X':
if (*(ptr+1)=='D') { if (*(ptr+1)=='D') {
i=atoi(option_value(ptr+1)); i=atoi(option_value(ptr+1,argv,argc,&arg));
if (i>64) if (i>64)
pc_amxram=(cell)i; /* abstract machine data/stack has minimum size */ pc_amxram=(cell)i; /* abstract machine data/stack has minimum size */
else else
about(); about();
} else { } else {
i=atoi(option_value(ptr)); i=atoi(option_value(ptr,argv,argc,&arg));
if (i>64) if (i>64)
pc_amxlimit=(cell)i;/* abstract machine has minimum size */ pc_amxlimit=(cell)i;/* abstract machine has minimum size */
else else
@ -1227,7 +1236,7 @@ static void setconfig(char *root)
static void setcaption(void) static void setcaption(void)
{ {
pc_printf("SourcePawn Compiler " SVN_FULL_VERSION "\n"); pc_printf("SourcePawn Compiler " SVN_FULL_VERSION "\n");
pc_printf("Copyright (c) 1997-2006, ITB CompuPhase, (C)2004-2008 AlliedModders, LLC\n\n"); pc_printf("Copyright (c) 1997-2006, ITB CompuPhase, (C)2004-2009 AlliedModders, LLC\n\n");
} }
static void about(void) static void about(void)
@ -1267,7 +1276,7 @@ static void about(void)
pc_printf(" 2 full optimizations\n"); pc_printf(" 2 full optimizations\n");
pc_printf(" -p<name> set name of \"prefix\" file\n"); pc_printf(" -p<name> set name of \"prefix\" file\n");
#if !defined SC_LIGHT #if !defined SC_LIGHT
pc_printf(" -r[name] write cross reference report to console or to specified file\n"); pc_printf(" -r<name> write cross reference report to console or to specified file\n");
#endif #endif
pc_printf(" -S<num> stack/heap size in cells (default=%d)\n",(int)pc_stksize); pc_printf(" -S<num> stack/heap size in cells (default=%d)\n",(int)pc_stksize);
pc_printf(" -s<num> skip lines from the input file\n"); pc_printf(" -s<num> skip lines from the input file\n");
@ -1278,7 +1287,7 @@ static void about(void)
pc_printf(" -XD<num> abstract machine data/stack size limit in bytes\n"); pc_printf(" -XD<num> abstract machine data/stack size limit in bytes\n");
pc_printf(" -\\ use '\\' for escape characters\n"); pc_printf(" -\\ use '\\' for escape characters\n");
pc_printf(" -^ use '^' for escape characters\n"); pc_printf(" -^ use '^' for escape characters\n");
pc_printf(" -;[+/-] require a semicolon to end each statement (default=%c)\n", sc_needsemicolon ? '+' : '-'); pc_printf(" -;<+/-> require a semicolon to end each statement (default=%c)\n", sc_needsemicolon ? '+' : '-');
#if 0 /* not allowed in SourceMod */ #if 0 /* not allowed in SourceMod */
pc_printf(" -([+/-] require parantheses for function invocation (default=%c)\n", optproccall ? '-' : '+'); pc_printf(" -([+/-] require parantheses for function invocation (default=%c)\n", optproccall ? '-' : '+');
#endif #endif
@ -1289,8 +1298,8 @@ static void about(void)
pc_printf("equivalent.\n"); pc_printf("equivalent.\n");
#endif #endif
pc_printf("\nOptions with a value may optionally separate the value from the option letter\n"); pc_printf("\nOptions with a value may optionally separate the value from the option letter\n");
pc_printf("with a colon (\":\") or an equal sign (\"=\"). That is, the options \"-d0\", \"-d=0\"\n"); pc_printf("with a colon (\":\"), an equal sign (\"=\"), or a space (\" \"). That is, the options \"-d0\", \"-d=0\",\n");
pc_printf("and \"-d:0\" are all equivalent.\n"); pc_printf("\"-d:0\", and \"-d 0\" are all equivalent. \"-;\" is an exception to this and cannot use a space.\n");
} /* if */ } /* if */
norun = 1; norun = 1;
longjmp(errbuf,3); /* user abort */ longjmp(errbuf,3); /* user abort */