home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / src / mingw-runtime-19991107 / mingw / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-18  |  2.1 KB  |  97 lines

  1. /*
  2.  * main.c
  3.  *
  4.  * Extra startup code for applications which do not have a main function
  5.  * of their own (but do have a WinMain). Generally these are GUI
  6.  * applications, but they don't *have* to be.
  7.  *
  8.  * This file is part of the Mingw32 package.
  9.  *
  10.  * Contributors:
  11.  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  12.  *  Maintained by Mumit Khan <khan@xraylith.wisc.EDU>
  13.  *
  14.  *  THIS SOFTWARE IS NOT COPYRIGHTED
  15.  *
  16.  *  This source code is offered for use in the public domain. You may
  17.  *  use, modify or distribute it freely.
  18.  *
  19.  *  This code is distributed in the hope that it will be useful but
  20.  *  WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
  21.  *  DISCLAMED. This includes but is not limited to warrenties of
  22.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  23.  *
  24.  * $Revision: 1.1.1.4 $
  25.  * $Author: khan $
  26.  * $Date: 1998/02/04 20:14:22 $
  27.  *
  28.  */
  29.  
  30. #include <stdlib.h>
  31. #include <process.h>
  32. #include <windows.h>
  33.  
  34. #define ISSPACE(a)    (a == ' ' || a == '\t')
  35.  
  36. extern int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, 
  37.                            LPSTR szCmdLine, int nShow);
  38.  
  39. int
  40. main (int argc, char *argv[], char *environ[])
  41. {
  42.   char *szCmd;
  43.   STARTUPINFO startinfo;
  44.   int nRet;
  45.  
  46.   /* Get the command line passed to the process. */
  47.   szCmd = GetCommandLineA ();
  48.   GetStartupInfoA (&startinfo);
  49.  
  50.   /* Strip off the name of the application and any leading
  51.    * whitespace. */
  52.   if (szCmd)
  53.     {
  54.       while (ISSPACE (*szCmd))
  55.     {
  56.       szCmd++;
  57.     }
  58.  
  59.       /* On my system I always get the app name enclosed
  60.        * in quotes... */
  61.       if (*szCmd == '\"')
  62.     {
  63.       do
  64.         {
  65.           szCmd++;
  66.         }
  67.       while (*szCmd != '\"' && *szCmd != '\0');
  68.  
  69.       if (*szCmd == '\"')
  70.         {
  71.           szCmd++;
  72.         }
  73.     }
  74.       else
  75.     {
  76.       /* If no quotes then assume first token is program
  77.        * name. */
  78.       while (!ISSPACE (*szCmd) && *szCmd != '\0')
  79.         {
  80.           szCmd++;
  81.         }
  82.     }
  83.  
  84.       while (ISSPACE (*szCmd))
  85.     {
  86.       szCmd++;
  87.     }
  88.     }
  89.  
  90.   nRet = WinMain (GetModuleHandle (NULL), NULL, szCmd,
  91.           (startinfo.dwFlags & STARTF_USESHOWWINDOW) ?
  92.           startinfo.wShowWindow : SW_SHOWDEFAULT);
  93.  
  94.   return nRet;
  95. }
  96.  
  97.