home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / ms_dos / update / optarg.c < prev    next >
Text File  |  1990-06-14  |  1KB  |  56 lines

  1. /*
  2.  *    optarg.c
  3.  *    separate option argument('-...' or '/...') in command line
  4.  *    (C) 1989 Sey
  5.  *    int optarg(int ac,char **av,int *oac,char ***oav,int *xac,char ***xav
  6.  *        ,char *optchr)
  7.  *        returns 1 for error, 0 for success
  8.  *    for Turbo C 1.5
  9.  *    1989/1/31
  10.  */
  11. #include    <stddef.h>
  12. #include    <alloc.h>
  13.  
  14. int
  15. optarg(int ac,char **av,int *oac,char ***oav,int *xac,char ***xav,char *optchr)
  16.     {
  17.     int    j;
  18.     char    *p;
  19.  
  20.     if( (*oav = (char **)malloc(sizeof(char *) * ac)) == NULL )
  21.         return(1);
  22.     if( (*xav = (char **)malloc(sizeof(char *) * ac)) == NULL )
  23.         return(1);
  24.     for( j = 0,*oac = *xac = 0; j < ac; j++ )
  25.         {
  26.         for( p = optchr; *p; p++ )
  27.             if( *p == av[j][0] )
  28.                 {
  29.                 (*oav)[(*oac)++] = av[j];
  30.                 break;
  31.                 }
  32.         if( *p == '\0' )
  33.             (*xav)[(*xac)++] = av[j];
  34.         }
  35.     return(0);
  36.     }
  37. /* end optarg */
  38.  
  39. #ifdef TEST
  40. main(int ac,char **av)
  41.     {
  42.         int    oac,xac,j;
  43.     char    **oav,**xav;
  44.  
  45.     if( optarg(ac,av,&oac,&oav,&xac,&xav,"-/") )
  46.         exit(1);
  47.     for( j = 0; j < oac; j++ )
  48.         printf("%s ",oav[j]);
  49.     printf("\n");
  50.     for( j = 0; j < xac; j++ )
  51.         printf("%s ",xav[j]);
  52.     }
  53. #endif
  54.  
  55.  
  56.