home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / flscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  6.9 KB  |  254 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: flscan.c,v 1.9 1995/10/25 23:46:00 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    flscan.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    24 Jul 1984
  9.  * Last update:
  10.  *        25 Oct 1995, use dds_while to show animated "working" message
  11.  *        18 Mar 1995, prototypes
  12.  *        27 Jul 1985, make 'flscan_set'..'flscan_off' common routines to
  13.  *                 use in tests of real directory entries against our
  14.  *                 picture in 'filelist[]'.
  15.  *        24 Jul 1985, use 'dirent_chk2' in front of 'dirent_nul' in case
  16.  *                 the file really should be marked "deleted".
  17.  *        20 Jul 1985, use 'dirent_nul' instead of 'dirent_dlet' to mark
  18.  *                 entries in 'filelist[]' "deleted" when they are
  19.  *                 not found in the read-list.
  20.  *        04 Jul 1985, cleanup 'filelist' definition.
  21.  *        14 Jun 1985, prune files which are not date-selected.
  22.  *        05 Feb 1985, altered call on 'dirseek_spec', which now can
  23.  *                 test for implicit (full-list) pathnames.
  24.  *        31 Jan 1985, use 'dirread' to maintain read-list
  25.  *        05 Jan 1985, use DCLARG-filespec argument on 'dirfind'
  26.  *        24 Dec 1984, added 'unfind' argument to 'dirfind'.
  27.  *        14 Dec 1984, added nam-argument to 'dirent_chop'
  28.  *        06 Dec 1984, changed 'readlist' to TEXTLINK structure
  29.  *        17 Nov 1984, added 'INSPECT' code.
  30.  *        02 Sep 1984, use "import"
  31.  *        16 Aug 1984, use 'dirent_misc'
  32.  *        31 Jul 1984
  33.  *
  34.  * Function:    This module performs the VERIFY function for "FLIST".  VERIFY
  35.  *        tests each entry in 'filelist[]' to verify that it still
  36.  *        exists.  Unlike READ, it does not re-read the date, size, etc.,
  37.  *        so it can operate (relatively) rapidly.
  38.  *
  39.  *        If no arguments are given, VERIFY examines the entire list.
  40.  *        If arguments are given, VERIFY uses the 'FIND' function to
  41.  *        locate each element which is currently in the list, and then
  42.  *        does a lookup on those elements.  (Note that in the latter
  43.  *        case warning messages may be emitted via 'flfind()).
  44.  *
  45.  *         If file is currently locked, we also do 'dirent_chk2(j)' to
  46.  *        do the reverse type of update.
  47.  *
  48.  *        No attempt is made to append new filenames to the 'filelist[]'
  49.  *        array.  This would be difficult to make consistent with the
  50.  *        use of 'readlist'.
  51.  *
  52.  *        If no list is given to 'flscan', its global search may remove
  53.  *        from the list certain filenames which were added dynamically
  54.  *        (e.g., new files created with COPY and RENAME).
  55.  *
  56.  *        INSPECT (also coded here) is similar to VERIFY, but with two
  57.  *        differences:
  58.  *
  59.  *        - It inspects each file (reads a block) to determine if it is
  60.  *          human-readable text.  If so, a "*" flag is appended to the
  61.  *          format-display field.
  62.  *        - If no arguments are given, INSPECT assumes only the current
  63.  *          filename entry, rather than the entire list.
  64.  *
  65.  * Patch:    This code should be redone for the full-list case to avoid
  66.  *        the N-squared effect of the search in 'flscan_all'.
  67.  *
  68.  *        The '.ftext' flag is not maintained in the rest of FLIST.
  69.  *        In particular, a READ will clear this flag.
  70.  */
  71.  
  72. #include    <string.h>
  73.  
  74. #include    <rmsdef.h>
  75.  
  76. #include    "flist.h"
  77.  
  78. #include    "dircmd.h"
  79. #include    "dirent.h"
  80. #include    "dirfind.h"
  81. #include    "dirread.h"
  82. #include    "dirseek.h"
  83. #include    "dds.h"
  84.  
  85. extern    int    inspect (char *filespec, int toscan);
  86.  
  87. static    void    flscan_all (char *spec, int len, unsigned status);
  88. static    void    flscan_clr (void);
  89. static    void    flscan_off (int j, int *unused);
  90. static    void    flscan_on  (int j);
  91. static    void    flscan_set (void);
  92.  
  93. import(filelist); import(numfiles);
  94. import(conv_list);
  95.  
  96. static    int    clarified,    /* Flag set if 'inspect' altered data    */
  97.         do_inspect;    /* TRUE if we also call 'inspect'    */
  98.  
  99. #define    BIT_2    2        /* Use this '.fmisc' bit via dirent_misc */
  100.  
  101. tDIRCMD(flscan)
  102. {
  103.     int    j,
  104.         k    = 0,
  105.         do_args    = FALSE;
  106.     DCLARG    *d_, *spec_;
  107.     char    fbfr[MAX_PATH];
  108.  
  109.     clarified = FALSE;
  110.     do_inspect = FALSE;    /* Assume VERIFY    */
  111.     if (xdcl_)
  112.     {
  113.         do_args = (dclinx(xdcl_, 1, 0) != 0);
  114.         do_inspect = (xdcl_->dcl_text[0] == 'I');
  115.     }
  116.  
  117.     /*
  118.      * Process the entries which the user selects in 'filelist[]' for
  119.      * verification:
  120.      */
  121.  
  122.     /*
  123.      * If the user gave a specific list of files, initialize '.fmisc'
  124.      * to FALSE only where the list does intersect 'filelist[]'.  Else,
  125.      * there is nothing to initialize.
  126.      */
  127.     dds_while (nullC);
  128.     if (do_args)
  129.     {
  130.         flscan_set ();
  131.         for (d_ = xdcl_->dcl_next; d_; d_ = d_->dcl_next)
  132.             dirfind (0, TRUE, d_, flscan_off, FALSE, FALSE);
  133.         for (k = 0; spec_ = dclinx2 (xdcl_, 1, k); k++)
  134.             dirseek_spec (spec_, TRUE, flscan_all);
  135.     }
  136.     else if (do_inspect)
  137.     {
  138.         flscan_set ();
  139.         dirent_glue (fbfr, FK_(*curfile_));
  140.         dirseek_spec2 (fbfr, flscan_all);
  141.     }
  142.     else    /* Leave only files found in 'read-list'    */
  143.     {
  144.         flscan_clr ();
  145.         for (k = 0; dirread_get(fbfr, k); k++)
  146.             dirseek_spec2 (fbfr, flscan_all);
  147.     }
  148.  
  149.     /*
  150.      * Now, go back over the list of files in 'filelist[]', checking off
  151.      * those which were not found (and must be assumed to have been
  152.      * deleted).  We must be careful not to mark a file deleted more than
  153.      * once, since 'dirent_nul' counts the total number of deletions to
  154.      * update the display.
  155.      *
  156.      * Re-check the file data for any files which were locked.
  157.      */
  158.     for (j = 0; j < numfiles; j++)
  159.     {
  160.         dds_while(nullC);
  161.         if (FK(j).fmisc & BIT_2)    /* File found ?    */
  162.         {
  163.             if (LOCKED(j))        /* ...if so, check locked-files */
  164.                 dirent_chk2 (j);
  165.         }
  166.         else if (! DELETED(j))        /* Make it look deleted    */
  167.         {
  168.             if (dirent_chk2(j))    dirent_nul(j);
  169.         }
  170.     }
  171.  
  172.     /*
  173.      * If 'inspect' altered any of the normal-text (.ftext) flags, then
  174.      * we may have to repaint the screen anyway.  Do this only if the
  175.      * FORMAT-display is active:
  176.      */
  177.     if (strchr(conv_list, 'f') && clarified)
  178.         dds_all (crt_top(), *curfile_);
  179. }
  180.  
  181. static
  182. void    flscan_set (void)    /* Set bit everywhere    */
  183. {
  184.     dirent_misc (-2, BIT_2);
  185. }
  186.  
  187. static
  188. void    flscan_clr (void)    /* Clear bit everywhere    */
  189. {
  190.     dirent_misc (-1, BIT_2);
  191. }
  192.  
  193. static
  194. void    flscan_on  (int j)    /* Set particular bit    */
  195. {
  196.     dirent_misc (j,  BIT_2);
  197. }
  198.  
  199. /*
  200.  * Reset a flag to indicate intersection between the user's argument list and
  201.  * the contents of 'filelist[]'.  If not subsequently verified by finding the
  202.  * file in the real directory, 'flscan' will remove it from 'filelist[]'.
  203.  */
  204. static
  205. void    flscan_off (int j, int *unused)
  206. {
  207.     FK(j).fmisc &= (~BIT_2);
  208. }
  209.  
  210. /*
  211.  * This procedure is called from 'dirseek_spec' after each file-spec is found.
  212.  * Reset the corresponding bit in the '.fmisc' component (which are set TRUE
  213.  * only where a specific file-spec was found).
  214.  */
  215. static
  216. void    flscan_all (char *spec, int len, unsigned status)
  217. {
  218.     FILENT    z2;
  219.     int    j;
  220.     char    spec2[MAX_PATH];
  221.  
  222.     dds_while(nullC);
  223.     if (status == RMS$_NORMAL)
  224.     {
  225.         strncpy (spec2, spec, len);
  226.         spec2[len] = EOS;
  227.         dirent_chop (&z2, spec2, 0);
  228.  
  229.         for (j = 0; j < numfiles; j++)
  230.         {
  231.             dds_while(nullC);
  232.             if (DELETED(j))
  233.                 continue;
  234.             if (! dirent__datechek (FK_(j)))
  235.                 continue;
  236.             if (memcmp (&z2, FK_(j), FILENT_name_size) == 0)
  237.             {
  238.                 flscan_on (j);
  239.                 if (do_inspect)
  240.                 {
  241.                 int    old = FK(j).ftext,
  242.                     new = inspect (spec2, 512);
  243.                     if (old != new)
  244.                     {
  245.                         FK(j).ftext = new;
  246.                         clarified = TRUE;
  247.                     }
  248.                 }
  249.                 break;
  250.             }
  251.         }
  252.     }
  253. }
  254.