static void add_define (const char * name, int nargs, const char * exps) { defn_t *p = lookup_definition(name); int h, len; /* trim off leading and trailing whitespace */ while (uisspace(*exps)) exps++; for (len = strlen(exps); len && uisspace(exps[len - 1]); len--); if (*exps == '#' && *(exps + 1) == '#') { yyerror("'##' at start of macro definition"); return; } if (len > 2 && *(exps + len - 2) == '#' && *(exps + len - 1) == '#') { yyerror("'##' at end of macro definition"); return; } if (p) { if (p->flags & DEF_IS_UNDEFINED) { p->exps = (char *)DREALLOC(p->exps, len + 1, TAG_COMPILER, "add_define: redef"); memcpy(p->exps, exps, len); p->exps[len] = 0; p->flags = 0; p->nargs = nargs; } else { if (p->flags & DEF_IS_PREDEF) { yyerror("Illegal to redefine predefined value."); return; } if (nargs != p->nargs || strcmp(exps, p->exps)) { char buf[200 + NSIZE]; sprintf(buf, "redefinition of #define %s\n", name); yywarn(buf); p->exps = (char *)DREALLOC(p->exps, len + 1, TAG_COMPILER, "add_define: redef"); memcpy(p->exps, exps, len); p->exps[len] = 0; p->nargs = nargs; } #ifndef LEXER p->flags &= ~DEF_IS_NOT_LOCAL; #endif } } else { p = ALLOCATE(defn_t, TAG_COMPILER, "add_define: def"); p->name = (char *) DXALLOC(strlen(name) + 1, TAG_COMPILER, "add_define: def name"); strcpy(p->name, name); p->exps = (char *) DXALLOC(len + 1, TAG_COMPILER, "add_define: def exps"); memcpy(p->exps, exps, len); p->exps[len] = 0; p->flags = 0; p->nargs = nargs; h = defhash(name); p->next = defns[h]; defns[h] = p; } }
/* _WinMain: * Entry point for Windows GUI programs, hooked by a macro in alwin.h, * which makes it look as if the application can still have a normal * main() function. */ int _WinMain(void *_main, void *hInst, void *hPrev, char *Cmd, int nShow) { int (*mainfunc) (int argc, char *argv[]) = (int (*)(int, char *[]))_main; char *argbuf; char *cmdline; char **argv; int argc; int argc_max; int i, q; /* can't use parameter because it doesn't include the executable name */ cmdline = GetCommandLine(); i = strlen(cmdline) + 1; argbuf = _AL_MALLOC(i); memcpy(argbuf, cmdline, i); argc = 0; argc_max = 64; argv = _AL_MALLOC(sizeof(char *) * argc_max); if (!argv) { _AL_FREE(argbuf); return 1; } i = 0; /* parse commandline into argc/argv format */ while (argbuf[i]) { while ((argbuf[i]) && (uisspace(argbuf[i]))) i++; if (argbuf[i]) { if ((argbuf[i] == '\'') || (argbuf[i] == '"')) { q = argbuf[i++]; if (!argbuf[i]) break; } else q = 0; argv[argc++] = &argbuf[i]; if (argc >= argc_max) { argc_max += 64; argv = _AL_REALLOC(argv, sizeof(char *) * argc_max); if (!argv) { _AL_FREE(argbuf); return 1; } } while ((argbuf[i]) && ((q) ? (argbuf[i] != q) : (!uisspace(argbuf[i])))) i++; if (argbuf[i]) { argbuf[i] = 0; i++; } } } argv[argc] = NULL; /* call the application entry point */ i = mainfunc(argc, argv); _AL_FREE(argv); _AL_FREE(argbuf); return i; }
static void processcommandline() { char *cmdline; int argc_max; int i, q; /* can't use parameter because it doesn't include the executable name */ cmdline = GetCommandLine(); i = strlen(cmdline) + 1; argbuf = malloc(i); memcpy(argbuf, cmdline, i); argc = 0; argc_max = 64; argv = malloc(sizeof(char *) * argc_max); if (!argv) { free(argbuf); return; } i = 0; /* parse commandline into argc/argv format */ while (argbuf[i]) { while ((argbuf[i]) && (uisspace(argbuf[i]))) i++; if (argbuf[i]) { if ((argbuf[i] == '\'') || (argbuf[i] == '"')) { q = argbuf[i++]; if (!argbuf[i]) break; } else q = 0; argv[argc++] = &argbuf[i]; if (argc >= argc_max) { argc_max += 64; argv = realloc(argv, sizeof(char *) * argc_max); if (!argv) { free(argbuf); return; } } while ((argbuf[i]) && ((q) ? (argbuf[i] != q) : (!uisspace(argbuf[i])))) i++; if (argbuf[i]) { argbuf[i] = 0; i++; } log_debug("Arg %i - %s\n",argc-1,argv[argc-1]); } } argv[argc] = NULL; // free(argbuf); }