home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / fileutil / stuff2.arj / DOARG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  2.5 KB  |  92 lines

  1. /*
  2. Stuff 2.0.
  3.  
  4. Checksum: 3171002767 (verify with "brik")
  5.  
  6. (C) Copyright 1988 Rahul Dhesi.  Permission is granted to copy and
  7. distribute this file in modified or unmodified form, whether for
  8. noncommercial or commercial use, provided (a) this copyright notice
  9. is preserved, (b) no attempt is made to restrict redistribution of
  10. this file, and (c) this file is not distributed as part of any
  11. collection whose redistribution is restricted by a compilation
  12. copyright.
  13. */
  14.  
  15. /*
  16. Deals with a single argument
  17. */
  18.  
  19. #include <stdio.h>
  20.  
  21. #include <dir.h>
  22. #include <dos.h>
  23. #include <string.h>
  24. #include <stddef.h>
  25. #include <errno.h>
  26. #include "stuff.h"
  27.  
  28. #include <conio.h> /* for kbhit() only */
  29.  
  30. struct file_info file_info;
  31.  
  32. void doarg (char *pathname)
  33. {
  34.    struct ffblk ffblk;
  35.    int done;
  36.    name_pt this_path;
  37.    name_pt newname;
  38.    char *p;
  39.    
  40.    kbhit();
  41.  
  42.    strcpy (this_path, pathname);
  43.    assert (strlen(this_path) != 0);
  44.  
  45.    forceslash (this_path);    /* redundant but just being sure */
  46.  
  47.    if (STRCMP(this_path,==,".") || STRCMP(this_path,==,".."))
  48.       strcat(this_path,"/*.*");
  49.    if (findlast(this_path,":\\/") == lastptr(this_path))  /* trailing : / \ */
  50.       strcat(this_path,"*.*");
  51.  
  52.    /* if not a pathname or disk name, add leading ./ to it */
  53.    if (findlast(this_path,":/") == NULL) {
  54.       strcpy (newname, "./");
  55.       strcat (newname, this_path);
  56.       strcpy (this_path, newname);
  57.    }
  58.  
  59.    done = findfirst (this_path, &ffblk, FA_DIREC);
  60.    if (done) {
  61.       fprintf (stderr, "%s: not found\n", this_path);
  62.       return;
  63.    }
  64.    file_info.utime = mstonix (ffblk.ff_fdate, ffblk.ff_ftime);
  65.    file_info.size  = ffblk.ff_fsize;
  66.    file_info.attrib = ffblk.ff_attrib;
  67.  
  68.    /* now we remove any trailing filename component from this_path */
  69.    p = findlast (this_path, "/\\:");   
  70.    if (p != NULL)
  71.       *(p+1) = '\0';
  72.  
  73.    while (!done) {
  74.       if (ffblk.ff_attrib & FA_DIREC) {
  75.          if (ffblk.ff_name[0] != '.') {
  76.             strcpy (newname, this_path);
  77.             strcat (newname, ffblk.ff_name);
  78.             strcat (newname, "/*.*");
  79.             doarg (newname);
  80.          }
  81.       } else {
  82.          strcpy (newname, this_path);
  83.          strcat (newname, ffblk.ff_name);
  84.          dopath (newname, &file_info);
  85.       }
  86.       done = findnext (&ffblk);
  87.       file_info.utime = mstonix (ffblk.ff_fdate, ffblk.ff_ftime);
  88.       file_info.size  = ffblk.ff_fsize;
  89.       file_info.attrib = ffblk.ff_attrib;
  90.    }  
  91. }
  92.