diff options
author | nijtmans <nijtmans> | 2010-01-22 14:17:53 (GMT) |
---|---|---|
committer | nijtmans <nijtmans> | 2010-01-22 14:17:53 (GMT) |
commit | 3998cf77ee9513d59f553516618187a6bccb697f (patch) | |
tree | 000910596afd8ed4fc7d62d3df7ec8d8b277d252 /win/winMain.c | |
parent | 027efdef074cb8c116b5f9c888ad445ea692f654 (diff) | |
download | tk-3998cf77ee9513d59f553516618187a6bccb697f.zip tk-3998cf77ee9513d59f553516618187a6bccb697f.tar.gz tk-3998cf77ee9513d59f553516618187a6bccb697f.tar.bz2 |
fix more gcc warnings: missing initializer
Eliminate use of __argc and __argv for CYGWIN
Make cygwin configuration error into
a warning: CYGWIN compilation works
although there still are test failures.
Diffstat (limited to 'win/winMain.c')
-rw-r--r-- | win/winMain.c | 138 |
1 files changed, 137 insertions, 1 deletions
diff --git a/win/winMain.c b/win/winMain.c index 5b914b1..b42e05e 100644 --- a/win/winMain.c +++ b/win/winMain.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: winMain.c,v 1.28 2009/10/21 20:28:52 nijtmans Exp $ + * RCS: @(#) $Id: winMain.c,v 1.29 2010/01/22 14:17:53 nijtmans Exp $ */ /* Make sure this file is never compiled with Stubs! */ @@ -36,6 +36,10 @@ static void WishPanic(const char *format, ...); extern int Tktest_Init(Tcl_Interp *interp); #endif /* TK_TEST */ +#if defined(__CYGWIN__) +static void setargv(int *argcPtr, char ***argvPtr); +#endif /* __CYGWIN__ */ + static BOOL consoleRequired = TRUE; /* @@ -107,8 +111,12 @@ WinMain( * Get our args from the c-runtime. Ignore lpszCmdLine. */ +#if defined(__CYGWIN__) + setargv(&argc, &argv); +#else argc = __argc; argv = __argv; +#endif /* * Forward slashes substituted for backslashes. @@ -287,6 +295,134 @@ main( return 0; } #endif /* !__GNUC__ || TK_TEST */ + + +/* + *------------------------------------------------------------------------- + * + * setargv -- + * + * Parse the Windows command line string into argc/argv. Done here + * because we don't trust the builtin argument parser in crt0. Windows + * applications are responsible for breaking their command line into + * arguments. + * + * 2N backslashes + quote -> N backslashes + begin quoted string + * 2N + 1 backslashes + quote -> literal + * N backslashes + non-quote -> literal + * quote + quote in a quoted string -> single quote + * quote + quote not in quoted string -> empty string + * quote -> begin quoted string + * + * Results: + * Fills argcPtr with the number of arguments and argvPtr with the array + * of arguments. + * + * Side effects: + * Memory allocated. + * + *-------------------------------------------------------------------------- + */ + +#if defined(__CYGWIN__) +static void +setargv( + int *argcPtr, /* Filled with number of argument strings. */ + char ***argvPtr) /* Filled with argument strings (malloc'd). */ +{ + char *cmdLine, *p, *arg, *argSpace; + char **argv; + int argc, size, inquote, copy, slashes; + + cmdLine = GetCommandLine(); /* INTL: BUG */ + + /* + * Precompute an overly pessimistic guess at the number of arguments in + * the command line by counting non-space spans. + */ + + size = 2; + for (p = cmdLine; *p != '\0'; p++) { + if ((*p == ' ') || (*p == '\t')) { /* INTL: ISO space. */ + size++; + while ((*p == ' ') || (*p == '\t')) { /* INTL: ISO space. */ + p++; + } + if (*p == '\0') { + break; + } + } + } + argSpace = (char *) ckalloc( + (unsigned) (size * sizeof(char *) + strlen(cmdLine) + 1)); + argv = (char **) argSpace; + argSpace += size * sizeof(char *); + size--; + + p = cmdLine; + for (argc = 0; argc < size; argc++) { + argv[argc] = arg = argSpace; + while ((*p == ' ') || (*p == '\t')) { /* INTL: ISO space. */ + p++; + } + if (*p == '\0') { + break; + } + + inquote = 0; + slashes = 0; + while (1) { + copy = 1; + while (*p == '\\') { + slashes++; + p++; + } + if (*p == '"') { + if ((slashes & 1) == 0) { + copy = 0; + if ((inquote) && (p[1] == '"')) { + p++; + copy = 1; + } else { + inquote = !inquote; + } + } + slashes >>= 1; + } + + while (slashes) { + *arg = '\\'; + arg++; + slashes--; + } + + if ((*p == '\0') || (!inquote && + ((*p == ' ') || (*p == '\t')))) { /* INTL: ISO space. */ + break; + } + if (copy != 0) { + *arg = *p; + arg++; + } + p++; + } + *arg = '\0'; + argSpace = arg + 1; + } + argv[argc] = NULL; + + *argcPtr = argc; + *argvPtr = argv; +} +#endif /* __CYGWIN__ */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ /* * Local Variables: |