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

  1. /*
  2.  *    exargs.c
  3.  *    to extend wild cards in arguments
  4.  *    for Turbo C
  5.  *    1988/4/10    Sey
  6.  */
  7. #include    <dir.h>
  8. #include    <dos.h>
  9. #define    _SUBLVLMAX_    1
  10. #include    <gosub.h>
  11. #include    <string.h>
  12. #include    <stdlib.h>
  13.  
  14. int
  15. exargs(int argc,char *argv[],char *xargv[],int maxarg)
  16.     {
  17.         struct    ffblk    ffblk;
  18.     int    n,done,flags;
  19.     char    drive[MAXDRIVE],dir[MAXDIR],name[MAXFILE],ext[MAXEXT];
  20.     static    int    nx = 0;
  21.  
  22.     for(n = 1 ;n < argc ;n++ )
  23.         {
  24.             jfnsplit(argv[n],drive,dir,name,ext);
  25.                if(done = findfirst(argv[n],&ffblk,0))
  26.             gosub(appendargv);
  27.         while(!done)
  28.             {
  29.                            gosub(appendfound);
  30.             done = findnext(&ffblk);
  31.             }
  32.         }
  33.         return(nx);
  34.  
  35.     appendfound:
  36.         {
  37.         char    *p;
  38.  
  39.         if( nx >= maxarg )
  40.             fatal("too many files");
  41.         if( (p = (char *)malloc(strlen(drive)+strlen(dir)+
  42.                     strlen(ffblk.ff_name)+1 )) == NULL)
  43.             fatal("out of memory");
  44.         strcpy(p,drive);
  45.         strcat(p,dir);
  46.         strcat(p,ffblk.ff_name);
  47.         xargv[nx] = p;
  48.                 nx++;
  49.         retsub;
  50.         }
  51.  
  52.     appendargv:
  53.         {
  54.         char    *p;
  55.  
  56.         if( nx >= maxarg )
  57.             fatal("too many matched files");
  58.         if( (p = (char *)malloc(strlen(argv[n])+1)) == NULL)
  59.             fatal("out of memory");
  60.         strcpy(p,argv[n]);
  61.         xargv[nx] = p;
  62.                 nx++;
  63.         retsub;
  64.         }
  65.         }
  66. /* end exargs */