home *** CD-ROM | disk | FTP | other *** search
- /*
- * optarg.c
- * separate option argument('-...' or '/...') in command line
- * (C) 1989 Sey
- * int optarg(int ac,char **av,int *oac,char ***oav,int *xac,char ***xav
- * ,char *optchr)
- * returns 1 for error, 0 for success
- * for Turbo C 1.5
- * 1989/1/31
- */
- #include <stddef.h>
- #include <alloc.h>
-
- int
- optarg(int ac,char **av,int *oac,char ***oav,int *xac,char ***xav,char *optchr)
- {
- int j;
- char *p;
-
- if( (*oav = (char **)malloc(sizeof(char *) * ac)) == NULL )
- return(1);
- if( (*xav = (char **)malloc(sizeof(char *) * ac)) == NULL )
- return(1);
- for( j = 0,*oac = *xac = 0; j < ac; j++ )
- {
- for( p = optchr; *p; p++ )
- if( *p == av[j][0] )
- {
- (*oav)[(*oac)++] = av[j];
- break;
- }
- if( *p == '\0' )
- (*xav)[(*xac)++] = av[j];
- }
- return(0);
- }
- /* end optarg */
-
- #ifdef TEST
- main(int ac,char **av)
- {
- int oac,xac,j;
- char **oav,**xav;
-
- if( optarg(ac,av,&oac,&oav,&xac,&xav,"-/") )
- exit(1);
- for( j = 0; j < oac; j++ )
- printf("%s ",oav[j]);
- printf("\n");
- for( j = 0; j < xac; j++ )
- printf("%s ",xav[j]);
- }
- #endif
-
-