home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / crt1.c < prev    next >
Text File  |  1992-04-16  |  4KB  |  120 lines

  1. #define INCL_DOSSIGNALS
  2. #include <os2.h>
  3. #include <string.h>
  4.  
  5. char *__CopyRight[] = {
  6.    "/*",
  7.    " * Copyright (c) 1985 Regents of the University of California.",
  8.    " * All rights reserved.",
  9.    " *",
  10.    " * Redistribution and use in source and binary forms, with or without",
  11.    " * modification, are permitted provided that the following conditions",
  12.    " * are met:",
  13.    " * 1. Redistributions of source code must retain the above copyright",
  14.    " *    notice, this list of conditions and the following disclaimer.",
  15.    " * 2. Redistributions in binary form must reproduce the above copyright",
  16.    " *    notice, this list of conditions and the following disclaimer in the",
  17.    " *    documentation and/or other materials provided with the distribution.",
  18.    " * 3. All advertising materials mentioning features or use of this software",
  19.    " *    must display the following acknowledgement:",
  20.    " *    This product includes software developed by the University of",
  21.    " *    California, Berkeley and its contributors.",
  22.    " * 4. Neither the name of the University nor the names of its contributors",
  23.    " *    may be used to endorse or promote products derived from this software",
  24.    " *    without specific prior written permission.",
  25.    " *",
  26.    " * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND",
  27.    " * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE",
  28.    " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE",
  29.    " * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE",
  30.    " * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL",
  31.    " * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS",
  32.    " * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)",
  33.    " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT",
  34.    " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY",
  35.    " * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF",
  36.    " * SUCH DAMAGE.",
  37.    " */"
  38. };
  39.  
  40. ULONG Dos32SetExceptionHandler() asm ("Dos32SetExceptionHandler");
  41.  
  42. extern ULONG __SignalHandler();
  43.  
  44. static void setargv (char *);
  45.  
  46. static int _argc = 0;
  47. static char **_argv = 0;
  48.  
  49. void crt1(char *command_line)
  50. {
  51.    int rc;
  52.    EXCEPTIONREGISTRATIONRECORD ExRegRec;
  53.  
  54.     /* Initialize the heap */
  55.    start_of_data();
  56.  
  57.     /* Initialize resource usage values */
  58.    _init_rusage();
  59.  
  60.     /* set argc and build argv[] */
  61.    setargv(command_line);
  62.  
  63.    ExRegRec.prev_structure = 0;
  64.    ExRegRec.ExceptionHandler = __SignalHandler;
  65.    Dos32SetExceptionHandler (&ExRegRec);
  66.  
  67.     /* GO! */
  68.    rc = main(_argc, _argv);
  69.  
  70.     /* Flush all stdio buffers */
  71.    fflush(0);
  72.  
  73.     /* Terminate the process */
  74.    exit (rc);
  75. }
  76.  
  77. static void setargv (char * command_line)
  78. {
  79.    char *cline;
  80.    int count, i;
  81.    char tmp[255];
  82.  
  83.    if (command_line[0] == '\0')
  84.       return;
  85.  
  86.     /* count the args */
  87.    for (cline = command_line; *cline++;) ;
  88.  
  89.    while (*cline) {
  90.       if (*cline == ' ' || *cline == '\t')
  91.          ++cline;
  92.       else {
  93.          _argc++;
  94.          while (*cline && *cline != ' ' && *cline != '\t')
  95.             ++cline;
  96.       }
  97.    }
  98.  
  99.     /* allocate space for argv[] */
  100.    _argv = (char **) malloc ((++_argc + 1) * sizeof(char *));
  101.  
  102.    _argv[0] = strdup (command_line);
  103.  
  104.    for (cline = command_line; *cline++;) ;
  105.  
  106.    for (count = 1; count < _argc; ++count) {
  107.       while (*cline == ' ' || *cline == '\t') ++cline;
  108.  
  109.       i = 0;
  110.       while (*cline && *cline != ' ' && *cline != '\t')
  111.          tmp[i++] = *cline++;
  112.  
  113.       tmp[i] = '\0';
  114.  
  115.       _argv[count] = strdup (tmp);
  116.    }
  117.    _argv[count] = 0;
  118. }
  119.  
  120.