home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 216_01 / scanfils.lst < prev    next >
Encoding:
File List  |  1979-12-31  |  13.1 KB  |  360 lines

  1.  
  2.  
  3.                                                                        PAGE   1
  4.                                                                        10-23-86
  5.                                                                        23:01:46
  6.  
  7.   Line#  Source Line                       Microsoft C Compiler Version 3.00.17
  8.  
  9.       1  /*    scanfils.c
  10.       2   *
  11.       3   *    Read in two directory listings that have been run through the SORT
  12.       4   *    utility.  Files names that have a changed date/time or that are in the
  13.       5   *    new directory listing but not the old have a COPY command generated
  14.       6   *    in an output file.
  15.       7   *    Note that files that appear in the old listing but not the new must have
  16.       8   *    been deleted between the 2 listings.  Although an ERASE statement could
  17.       9   *    be generated, that's kinda dangerous, so an ECHO is generated instead.
  18.      10   *
  19.      11   *    Example of usage:
  20.      12   *        dir | sort >glopold
  21.      13   *        ... other processing ...
  22.      14   *        dir | sort >glopnew
  23.      15   *        scanfils glopold glopnew d: >savefils.bat
  24.      16   *        savefils
  25.      17   *
  26.      18   *    Suppose the directory originally contained files A, B, C, D, E, and F.
  27.      19   *    Other procesing is done.  Now the directory contains files A, C, D, E,
  28.      20   *    and G.    In addition, file A was updated.
  29.      21   *    SCANFILS will generate the following statements in its output:
  30.      22   *        copy A d:
  31.      23   *        echo B
  32.      24   *        echo F
  33.      25   *        copy G d:
  34.      26   *    (The "d:" cones from the command line, see example invocation above).
  35.      27   *    Note that the filenames that are input to this utility on the command
  36.      28   *    line will be ignored insofar as generating any output lines (but only
  37.      29   *    if the names are simple, ie don't contain drive or directory).    This
  38.      30   *    means that when used in the example above, no COPY will be generated
  39.      31   *    for GLOPOLD or GLOPNEW even though they will appear in the directory
  40.      32   *    listing.
  41.      33   *    In addition, "X files added, Y files deleted, Z files changed" will
  42.      34   *    appear on the standard ERROR output as a report.
  43.      35   *
  44.      36   */
  45.      37  
  46.      38  #include "stdio.h"
  47.      39  #include "process.h"        /* For exit () */
  48.      40  #include "stdlib.h"        /* For perror () */
  49.      41  #include "memory.h"        /* For memcmp, et al */
  50.      42  #include "string.h"        /* For strcmp, et al */
  51.      43  
  52.      44  char odir[12], ndir[12];
  53.      45  
  54.      46  main (argc, argv, envp)
  55.      47  
  56.      48  int argc;
  57.      49  char *argv[];
  58.      50  char *envp[];
  59.      51  
  60.      52  {
  61.      53      void usage ();
  62.      54      void rl ();
  63.  
  64.  
  65.                                                                        PAGE   2
  66.                                                                        10-23-86
  67.                                                                        23:01:46
  68.  
  69.   Line#  Source Line                       Microsoft C Compiler Version 3.00.17
  70.  
  71.      55      void gcopy (), gecho ();
  72.      56      FILE *old, *new;
  73.      57      int added = 0, changed = 0, deleted = 0;
  74.      58      char lold[80], lnew[80];
  75.      59      int cresult;
  76.      60      char *p;
  77.      61  
  78.      62      if (argc != 4)
  79.      63          usage ();
  80.      64  
  81.      65      if (! (old = fopen (argv[1], "r"))) {
  82.      66          perror ("scanfils: Unable to open \"old\" directory file");
  83.      67          exit (1);
  84.      68      }
  85.      69  
  86.      70      if (! (new = fopen (argv[2], "r"))) {
  87.      71          perror ("scanfils: Unable to open \"new\" directory file");
  88.      72          exit (1);
  89.      73      }
  90.      74  
  91.      75      /* Generate filenames in "dir" format for both old and new files */
  92.      76      memset (odir, ' ', 12);
  93.      77      if (! strpbrk (argv[1], "/\:")) {
  94.      78          if (p = strchr (argv[1], '.')) {
  95.      79              memcpy (odir, argv[1], p-argv[1]);
  96.      80              memcpy (odir+9, p+1, strlen (p+1));
  97.      81          } else {
  98.      82              memcpy (odir, argv[1], strlen (argv[1]));
  99.      83          }
  100.      84      }
  101.      85      for (p = odir; p < odir+12; p++)
  102.      86          *p = toupper (*p);
  103. ***** i:scanfils.c(86) : warning 51: data conversion
  104.      87  
  105.      88      memset (ndir, ' ', 12);
  106.      89      if (! strpbrk (argv[2], "/\:")) {
  107.      90          if (p = strchr (argv[2], '.')) {
  108.      91              memcpy (ndir, argv[2], p-argv[2]);
  109.      92              memcpy (ndir+9, p+1, strlen (p+1));
  110.      93          } else {
  111.      94              memcpy (ndir, argv[2], strlen (argv[2]));
  112.      95          }
  113.      96      }
  114.      97      for (p = ndir; p < ndir+12; p++)
  115.      98          *p = toupper (*p);
  116. ***** i:scanfils.c(98) : warning 51: data conversion
  117.      99  
  118.     100      /* Prime the comparison arrays */
  119.     101      rl (old, lold, sizeof (lold));
  120.     102      rl (new, lnew, sizeof (lnew));
  121.     103  
  122.     104      /* Go thru the files until eof on both */
  123.     105      while (lold[0] != '\177' && lnew[0] != '\177') {
  124.     106          cresult = memcmp (lold, lnew, 12);
  125.  
  126.  
  127.                                                                        PAGE   3
  128.                                                                        10-23-86
  129.                                                                        23:01:46
  130.  
  131.   Line#  Source Line                       Microsoft C Compiler Version 3.00.17
  132.  
  133.     107          if (cresult < 0) {        /* old file deleted */
  134.     108              ++deleted;
  135.     109              gecho (lold);
  136.     110              rl (old, lold, sizeof (lold));
  137.     111          } else if (cresult == 0) {    /* same file names */
  138.     112              if (strcmp (lold, lnew)) { /* ... different attr */
  139.     113                  ++changed;
  140.     114                  gcopy (lnew, argv[3]);
  141.     115              }
  142.     116              rl (old, lold, sizeof (lold));
  143.     117              rl (new, lnew, sizeof (lnew));
  144.     118          } else {            /* new file added */
  145.     119              ++added;
  146.     120              gcopy (lnew, argv[3]);
  147.     121              rl (new, lnew, sizeof (lnew));
  148.     122          }
  149.     123      }
  150.     124  
  151.     125      /* Display summary */
  152.     126      fprintf (stderr, "scanfils:  %d added, %d deleted, %d changed", added,
  153.     127          deleted, changed);
  154.     128      return (0);
  155.  
  156. main  Local Symbols
  157.  
  158. Name                            Class    Offset    Register
  159.  
  160. changed . . . . . . . . . . . . auto      -00ae    
  161. lold. . . . . . . . . . . . . . auto      -00ac    
  162. lnew. . . . . . . . . . . . . . auto      -005c    
  163. added . . . . . . . . . . . . . auto      -000c    
  164. p . . . . . . . . . . . . . . . auto      -000a    
  165. deleted . . . . . . . . . . . . auto      -0008    
  166. old . . . . . . . . . . . . . . auto      -0006    
  167. new . . . . . . . . . . . . . . auto      -0004    
  168. cresult . . . . . . . . . . . . auto      -0002    
  169. argc. . . . . . . . . . . . . . param      0004    
  170. argv. . . . . . . . . . . . . . param      0006    
  171. envp. . . . . . . . . . . . . . param      0008    
  172.  
  173.     129  }
  174.     130  
  175.     131  /*    gcopy
  176.     132   *
  177.     133   *    Generate a COPY command to the standard output.
  178.     134   */
  179.     135  
  180.     136  void    gcopy (s, d)
  181.     137  
  182.     138  char *s;        /* string containing filename (dir listing fmt) */
  183.     139  char *d;        /* string containing name of destination drive */
  184.     140  
  185.     141  {
  186.     142      char *p;
  187.  
  188.  
  189.                                                                        PAGE   4
  190.                                                                        10-23-86
  191.                                                                        23:01:46
  192.  
  193.   Line#  Source Line                       Microsoft C Compiler Version 3.00.17
  194.  
  195.     143  
  196.     144      p = strchr (s, ' ');
  197.     145      *p = '\0';
  198.     146      *(s+12) = '\0';
  199.     147      if (memcmp (s+9, "   ", 3))        /* if extension present */
  200.     148          printf ("COPY %s.%s %s\n", s, s+9, d);
  201.     149      else
  202.     150          printf ("COPY %s %s\n", s, d);
  203.     151      *p = ' ';
  204.     152      *(s+12) = ' ';
  205.     153      return;
  206.  
  207. gcopy  Local Symbols
  208.  
  209. Name                            Class    Offset    Register
  210.  
  211. p . . . . . . . . . . . . . . . auto      -0002    
  212. s . . . . . . . . . . . . . . . param      0004    
  213. d . . . . . . . . . . . . . . . param      0006    
  214.  
  215.     154  }
  216.     155  
  217.     156  /*    gecho
  218.     157   *
  219.     158   *    Generate an ECHO command to the standard output.
  220.     159   */
  221.     160  
  222.     161  void    gecho (s, d)
  223.     162  
  224.     163  char *s;        /* string containing filename (dir listing fmt) */
  225.     164  
  226.     165  {
  227.     166      char *p;
  228.     167  
  229.     168      p = strchr (s, ' ');
  230.     169      *p = '\0';
  231.     170      *(s+12) = '\0';
  232.     171      if (memcmp (s+9, "   ", 3))        /* if extension present */
  233.     172          printf ("ECHO %s.%s\n", s, s+9);
  234.     173      else
  235.     174          printf ("ECHO %s\n", s);
  236.     175      *p = ' ';
  237.     176      *(s+12) = ' ';
  238.     177      return;
  239.  
  240. gecho  Local Symbols
  241.  
  242. Name                            Class    Offset    Register
  243.  
  244. p . . . . . . . . . . . . . . . auto      -0002    
  245. s . . . . . . . . . . . . . . . param      0004    
  246. d . . . . . . . . . . . . . . . param      0006    
  247.  
  248.     178  }
  249.  
  250.  
  251.                                                                        PAGE   5
  252.                                                                        10-23-86
  253.                                                                        23:01:46
  254.  
  255.   Line#  Source Line                       Microsoft C Compiler Version 3.00.17
  256.  
  257.     179  
  258.     180  /*    rl
  259.     181   *
  260.     182   *    Read a line from the input file specified.
  261.     183   *    If at end of file, a byte of 0xFF is put in the first byte.
  262.     184   *    Lines beginning with spaces are skipped (Lines in the directory
  263.     185   *    listing that we're uninterested in start with a space!)
  264.     186   *    Ditto for lines beginning with a period.
  265.     187   *    Ditto for lines that match either the "old" or "new" filenames.
  266.     188   */
  267.     189  
  268.     190  void rl (stream, s, len)
  269.     191  
  270.     192  FILE *stream;
  271.     193  char *s;
  272.     194  int len;
  273.     195  
  274.     196  {
  275.     197      char *p;
  276.     198  
  277.     199      do {
  278.     200          if (feof (stream))
  279.     201               *s = '\177';
  280.     202          else
  281.     203              if (! fgets (s, len, stream))
  282.     204                  *s = '\177';
  283.     205      } while (*s <= ' ' || *s == '.' || !memcmp (odir, s, 12) ||
  284.     206          !memcmp (ndir, s, 12));
  285.     207      return;
  286.  
  287. rl  Local Symbols
  288.  
  289. Name                            Class    Offset    Register
  290.  
  291. p . . . . . . . . . . . . . . . auto      -0002    
  292. stream. . . . . . . . . . . . . param      0004    
  293. s . . . . . . . . . . . . . . . param      0006    
  294. len . . . . . . . . . . . . . . param      0008    
  295.  
  296.     208  }
  297.     209  
  298.     210  /*    usage
  299.     211   *
  300.     212   *    Display usage message and exit
  301.     213   */
  302.     214  
  303.     215  void usage ()
  304.     216  
  305.     217  {
  306.     218      printf ("scanfils usage:  olist nlist drive >output\n");
  307.     219      printf ("\n");
  308.     220      printf ("where olist:    Sorted old directory listing\n");
  309.     221      printf ("      nlist:    Sorted new directory listing\n");
  310.     222      printf ("      drive:    Output drive in generated COPY commands\n");
  311.  
  312.  
  313.                                                                        PAGE   6
  314.                                                                        10-23-86
  315.                                                                        23:01:46
  316.  
  317.   Line#  Source Line                       Microsoft C Compiler Version 3.00.17
  318.  
  319.     223      printf ("\n");
  320.     224      printf ("Sorted directory listings may be generated via DIR | SORT");
  321.     225      printf (" >GLOP\n");
  322.     226  
  323.     227      exit (1);
  324.     228  }
  325.  
  326.  
  327.  
  328. Global Symbols
  329.  
  330. Name                            Type             Size    Class    Offset
  331.  
  332. _iob. . . . . . . . . . . . . . struct/array      160    extern      ***
  333. exit. . . . . . . . . . . . . . near function     ***    extern      ***
  334. fgets . . . . . . . . . . . . . near function     ***    extern      ***
  335. fopen . . . . . . . . . . . . . near function     ***    extern      ***
  336. fprintf . . . . . . . . . . . . near function     ***    extern      ***
  337. gcopy . . . . . . . . . . . . . near function     ***    global     0296
  338. gecho . . . . . . . . . . . . . near function     ***    global     030e
  339. main. . . . . . . . . . . . . . near function     ***    global     0000
  340. memcmp. . . . . . . . . . . . . near function     ***    extern      ***
  341. memcpy. . . . . . . . . . . . . near function     ***    extern      ***
  342. memset. . . . . . . . . . . . . near function     ***    extern      ***
  343. ndir. . . . . . . . . . . . . . struct/array       12    common      ***
  344. odir. . . . . . . . . . . . . . struct/array       12    common      ***
  345. perror. . . . . . . . . . . . . near function     ***    extern      ***
  346. printf. . . . . . . . . . . . . near function     ***    extern      ***
  347. rl. . . . . . . . . . . . . . . near function     ***    global     0380
  348. strchr. . . . . . . . . . . . . near function     ***    extern      ***
  349. strcmp. . . . . . . . . . . . . near function     ***    extern      ***
  350. strlen. . . . . . . . . . . . . near function     ***    extern      ***
  351. strpbrk . . . . . . . . . . . . near function     ***    extern      ***
  352. toupper . . . . . . . . . . . . near function     ***    extern      ***
  353. usage . . . . . . . . . . . . . near function     ***    global     03e5
  354.  
  355. Code size = 0448 (1096)
  356. Data size = 01c8 (456)
  357. Bss size  = 0000 (0)
  358.  
  359. No errors detected
  360.