/[ascend]/trunk/tcltk98/generic/interface/Driver.c
ViewVC logotype

Diff of /trunk/tcltk98/generic/interface/Driver.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 520 by johnpye, Tue Apr 4 06:41:25 2006 UTC revision 521 by johnpye, Fri Apr 21 05:35:59 2006 UTC
# Line 134  extern int  Tktable_Init(Tcl_Interp*); Line 134  extern int  Tktable_Init(Tcl_Interp*);
134  /*  /*
135   *  Forward declarations for procedures defined later in this file.   *  Forward declarations for procedures defined later in this file.
136   */   */
137  static int  AscDriver(int, CONST84 char * argv[]);  int  AscDriver(int, CONST84 char * argv[]);
138  static void AscTrap(int);  static void AscTrap(int);
139  static int  AscCheckEnvironVars(Tcl_Interp*);  static int  AscCheckEnvironVars(Tcl_Interp*);
140  static void AscPrintHelpExit(CONST char *);  static void AscPrintHelpExit(CONST char *);
# Line 145  static void StdinProc(ClientData, int); Line 145  static void StdinProc(ClientData, int);
145  #ifdef DEBUG_MALLOC  #ifdef DEBUG_MALLOC
146  static void InitDebugMalloc(void);  static void InitDebugMalloc(void);
147  #endif /* DEBUG_MALLOC */  #endif /* DEBUG_MALLOC */
148  #ifdef __WIN32__  
 static void setargv(int*, char ***);  
 #endif /* __WIN32__ */  
149    
150    
151  /*  /*
# Line 252  static char build_name[]=TIMESTAMP; Line 250  static char build_name[]=TIMESTAMP;
250  #endif /* TIMESTAMP */  #endif /* TIMESTAMP */
251    
252    
253    /**
254  /*      Moved 'main' and 'WinMain' to separate 'main.c'
255   *  main or WinMain      so that ascend4.exe can be built without linkage to Tcl/Tk
256   *  */
  *  The main entry point for a Unix or Windows application.  
  *  
  *  Each just calls AscDriver().  
  *  These are based on functions from the Tk 8.0 distribution.  
  *  See unix/tkAppInit.c and win/winMain.c in their sources.  
  */  
 #ifndef __WIN32__  
   
 int main(int argc, CONST84 char *argv[])  
 {  
   AscDriver(argc, argv);  
   return 0;  
 }  
   
 #else /* __WIN32__ */  
   
 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,  
                      LPSTR lpszCmdLine, int nCmdShow)  
 {  
   int argc;  
   char **argv;  
   char *p;  
   char buffer[MAX_PATH];  
   
   UNUSED_PARAMETER(hInstance);  
   UNUSED_PARAMETER(hPrevInstance);  
   UNUSED_PARAMETER(lpszCmdLine);  
   UNUSED_PARAMETER(nCmdShow);  
   
   /*  
    * Set up the default locale to be standard "C" locale so parsing  
    * is performed correctly.  
    */  
   setlocale(LC_ALL, "C");  
   
   /*  
    * Increase the application queue size from default value of 8.  
    * At the default value, cross application SendMessage of WM_KILLFOCUS  
    * will fail because the handler will not be able to do a PostMessage!  
    * This is only needed for Windows 3.x, since NT dynamically expands  
    * the queue.  
    */  
   SetMessageQueue(64);  
   
   /*  
    * Create the console channels and install them as the standard  
    * channels.  All I/O will be discarded until TkConsoleInit is  
    * called to attach the console to a text widget.  
    */  
   
   /*  
    *  Windows expects us to parse our arguments ourselves.  
    */  
   setargv(&argc, &argv);  
   
   /*  
    * Replace argv[0] with full pathname of executable, and forward  
    * slashes substituted for backslashes.  
    */  
   GetModuleFileName(NULL, buffer, sizeof(buffer));  
   argv[0] = buffer;  
   for (p = buffer; *p != '\0'; p++) {  
     if (*p == '\\') {  
       *p = '/';  
     }  
   }  
   
   AscDriver(argc, argv);  
   return 1;  
 }  
 #endif /* __WIN32__ */  
257    
258    
259  /*  /*
# Line 348  int APIENTRY WinMain(HINSTANCE hInstance Line 275  int APIENTRY WinMain(HINSTANCE hInstance
275   *  in the Tk sources.   *  in the Tk sources.
276   *   *
277   */   */
278  static int AscDriver(int argc, CONST84 char *argv[])  int AscDriver(int argc, CONST84 char *argv[])
279  {  {
280    Tcl_Interp *interp;                   /* local version of global g_interp */    Tcl_Interp *interp;                   /* local version of global g_interp */
281    Tcl_Channel inChannel;    Tcl_Channel inChannel;
# Line 1270  int Asc_DebugMallocCmd(ClientData cdata, Line 1197  int Asc_DebugMallocCmd(ClientData cdata,
1197  }  }
1198  #endif /* DEBUG_MALLOC */  #endif /* DEBUG_MALLOC */
1199    
 #ifdef __WIN32__  
 /*  
  *-------------------------------------------------------------------------  
  *  
  * 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.  
  *  
  * Parameters:  
  *    argcptr  Filled with number of argument strings.  
  *    argvptr  Filled with argument strings (malloc'd).  
  *  
  * This function is from the Tk 8.0 distribution.  See win/winMain.c in  
  * their sources.  
  *  
  *--------------------------------------------------------------------------  
  */  
 static void  
 setargv(int *argcPtr, char ***argvPtr)  
 {  
     char *cmdLine, *p, *arg, *argSpace;  
     char **argv;  
     int argc, size, inquote, copy, slashes;  
   
     cmdLine = GetCommandLine();  
   
     /*  
      * 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 (isspace(*p)) {  
         size++;  
         while (isspace(*p)) {  
         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 (isspace(*p)) {  
         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 && isspace(*p))) {  
         break;  
         }  
         if (copy != 0) {  
         *arg = *p;  
         arg++;  
         }  
         p++;  
         }  
     *arg = '\0';  
     argSpace = arg + 1;  
     }  
     argv[argc] = NULL;  
   
     *argcPtr = argc;  
     *argvPtr = argv;  
 }  
1200    
 #endif /* __WIN32__ */  

Legend:
Removed from v.520  
changed lines
  Added in v.521

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22