home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
LIBSRC.ZOO
/
libsrc
/
local
/
crt1.c
< prev
next >
Wrap
Text File
|
1992-04-16
|
4KB
|
120 lines
#define INCL_DOSSIGNALS
#include <os2.h>
#include <string.h>
char *__CopyRight[] = {
"/*",
" * Copyright (c) 1985 Regents of the University of California.",
" * All rights reserved.",
" *",
" * Redistribution and use in source and binary forms, with or without",
" * modification, are permitted provided that the following conditions",
" * are met:",
" * 1. Redistributions of source code must retain the above copyright",
" * notice, this list of conditions and the following disclaimer.",
" * 2. Redistributions in binary form must reproduce the above copyright",
" * notice, this list of conditions and the following disclaimer in the",
" * documentation and/or other materials provided with the distribution.",
" * 3. All advertising materials mentioning features or use of this software",
" * must display the following acknowledgement:",
" * This product includes software developed by the University of",
" * California, Berkeley and its contributors.",
" * 4. Neither the name of the University nor the names of its contributors",
" * may be used to endorse or promote products derived from this software",
" * without specific prior written permission.",
" *",
" * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND",
" * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE",
" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE",
" * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE",
" * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL",
" * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS",
" * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)",
" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT",
" * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY",
" * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF",
" * SUCH DAMAGE.",
" */"
};
ULONG Dos32SetExceptionHandler() asm ("Dos32SetExceptionHandler");
extern ULONG __SignalHandler();
static void setargv (char *);
static int _argc = 0;
static char **_argv = 0;
void crt1(char *command_line)
{
int rc;
EXCEPTIONREGISTRATIONRECORD ExRegRec;
/* Initialize the heap */
start_of_data();
/* Initialize resource usage values */
_init_rusage();
/* set argc and build argv[] */
setargv(command_line);
ExRegRec.prev_structure = 0;
ExRegRec.ExceptionHandler = __SignalHandler;
Dos32SetExceptionHandler (&ExRegRec);
/* GO! */
rc = main(_argc, _argv);
/* Flush all stdio buffers */
fflush(0);
/* Terminate the process */
exit (rc);
}
static void setargv (char * command_line)
{
char *cline;
int count, i;
char tmp[255];
if (command_line[0] == '\0')
return;
/* count the args */
for (cline = command_line; *cline++;) ;
while (*cline) {
if (*cline == ' ' || *cline == '\t')
++cline;
else {
_argc++;
while (*cline && *cline != ' ' && *cline != '\t')
++cline;
}
}
/* allocate space for argv[] */
_argv = (char **) malloc ((++_argc + 1) * sizeof(char *));
_argv[0] = strdup (command_line);
for (cline = command_line; *cline++;) ;
for (count = 1; count < _argc; ++count) {
while (*cline == ' ' || *cline == '\t') ++cline;
i = 0;
while (*cline && *cline != ' ' && *cline != '\t')
tmp[i++] = *cline++;
tmp[i] = '\0';
_argv[count] = strdup (tmp);
}
_argv[count] = 0;
}