6 If you use this file, add -DHAVE_REARGV=1 to your
9 Contributed by Jack Fitts (fittsj%wmv009@bcsaic.boeing.com)
15 * Revision 1.2 1995/01/07 14:47:24 mike
16 * remove return 1 from void function
18 * Revision 1.1.1.1 1993/07/03 18:58:49 mike
21 * Revision 1.2 1992/12/17 02:48:01 mike
22 * 1.1.2d changes for DOS
24 * Revision 1.1 1992/12/05 22:38:41 mike
30 /***********************************************************/
32 /* prototypes for reargv */
34 /***********************************************************/
36 void *malloc(unsigned) ;
37 char * basename ( char * );
38 char *strcpy(char* , char*) ;
41 /***********************************************************/
43 /* reargv reset argc/argv from environment for MKS shell */
45 /***********************************************************/
48 void reargv ( int *argcp, char *** argvp ) {
53 extern char **environ ;
54 register char **pe = environ;
56 /* MKS Command line args are in the first n lines of the environment */
57 /* each arg is preceded with a tilde (~)*/
59 while ( **(pe++) == '~' )
62 /* if no tilde found then not running under MKS */
66 /* malloc space for array of char pointers */
68 if ( ! ( v = ( char ** ) malloc (( i + 1 ) * sizeof ( char* ))) )
71 /* set argc to number of args in environ */
75 /* set char pointers to each command line arg */
76 /* jump over the tilde which is the first char in each string */
78 for ( i = 0; i < cnt ; i++ )
81 /*set last arg to null*/
85 /*strip leading directory stuff from argv[0] */
87 v[0] = basename(v[0]);
93 /***********************************************************/
97 /***********************************************************/
99 static char * basename ( char * s ) {
104 /* find the last occurrence of ':' '\\' or '/' */
105 p = s ; last = (char *) 0 ;
107 if ( *p == ':' || *p == '\\' || *p == '/' ) last = p ;
111 return last ? last+1 : s ;