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

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: dirseek.c,v 1.7 1995/10/21 18:41:14 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    dirseek.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    16 Jul 1984
  9.  * Last update:
  10.  *        19 Feb 1995, prototyped
  11.  *        15 Jun 1985, typed 'dirread_path'.  Reference 'for_each' as
  12.  *                 '(*for_each)' to make CC2.0 happy.
  13.  *        05 Feb 1985, use DCLARG-argument in 'dirseek_spec' instead of
  14.  *                 string, to support explicit-pathname code.
  15.  *        09 Sep 1984, use "rmsinit"
  16.  *        26 Aug 1984, cleanup buffer sizes
  17.  *        31 Jul 1984, added 'dirseek_spec' entry
  18.  *        26 Jul 1984, added 'need' option
  19.  *        16 Jul 1984
  20.  *
  21.  * Function:    This procedure is used by FLIST to verify the existence of a
  22.  *        list of files, used as arguments in an input list.  A simple
  23.  *        search is used rather than checking (additionally) the read
  24.  *        access due to the long time required if a wildcard is given.
  25.  *
  26.  *        The filenames which are tested are assumed to be syntactically
  27.  *        correct.
  28.  *
  29.  * Parameters:    cmd_    => original command text (for nicer messages).
  30.  *        d_    => DCLARG-list to test. (Options are ignored.)
  31.  *        mfld    =  parameter number to test (e.g., 1=input, 2=output)
  32.  *        need    =  TRUE if a warning message is emitted when one or
  33.  *               files is not found.
  34.  *
  35.  * Returns:    TRUE if all filespec's are found. If not, and if 'need' is set,
  36.  *        a warning message is generated.
  37.  */
  38.  
  39. #include    <starlet.h>
  40. #include    <stdio.h>
  41. #include    <rms.h>
  42.  
  43. #include    "flist.h"
  44. #include    "dclarg.h"
  45. #include    "dirfind.h"
  46. #include    "dirread.h"
  47. #include    "dirseek.h"
  48.  
  49. #include    "rmsinit.h"
  50.  
  51. #define    RMS_STUFF    struct    FAB    fab;\
  52.             struct    NAM    nam;\
  53.             unsigned status;\
  54.             char    rsa[NAM$C_MAXRSS],    /* resultant     */\
  55.                 esa[NAM$C_MAXRSS]    /* expanded (search)*/
  56.  
  57. int    dirseek ( char *cmd_, DCLARG *d_, int mfld, int need)
  58. {
  59.     static    char    sFMT1[]    = "File(s) not found: %%.%ds";
  60.     static    char    format    [sizeof(sFMT1)+6];
  61.  
  62.     for (; d_; d_ = d_->dcl_next)
  63.     {
  64.         if (isopt (d_->dcl_text[0]))    continue;
  65.         else if (d_->dcl_mfld != mfld)    continue;
  66.  
  67.         if (! dirseek_spec (d_, FALSE, 0))
  68.         {
  69.             if (need)
  70.             {
  71.                 sprintf (format, sFMT1, d_->dcl_size);
  72.                 warn (format, &cmd_[d_->dcl_from]);
  73.             }
  74.             return (FALSE);
  75.         }
  76.     }
  77.     return (TRUE);
  78. }
  79.  
  80. /* <dirseek_spec>:
  81.  * Seek all occurrences of a particular filespec.  (This is a common procedure,
  82.  * shared with 'flscan').
  83.  */
  84. int    dirseek_spec (DCLARG *spec, int implicit, tDIRSEEK)
  85. {
  86.     RMS_STUFF;
  87.     int    inx, rcode;
  88.     char    *p_;
  89.  
  90.     /*
  91.      * If the 'implicit' argument is set on entry, check the pathname to
  92.      * see if it was explicit (i.e., if any part was given).  If no pathname
  93.      * was given, then any pathname from the read-list will match the
  94.      * pathname in this search.  Otherwise, we restrict ourselves to a
  95.      * (normal VMS-style) search within the specified set of directories.
  96.      *
  97.      * Note that matching against the read-list pathnames is still an
  98.      * approximation, but one which should be a superset of the display-
  99.      * list.
  100.      *
  101.      * The 'toname' index is required to kill off the current default
  102.      * directory (supplied by sys-parse in the dclarg-table building phase.
  103.      */
  104.     if (implicit)    implicit = dirfind_notexp (spec);
  105.  
  106.     if (implicit)
  107.     {
  108.         for (inx = 0; p_ = dirread_path (&inx); inx++)
  109.         {
  110.         int    toname    = spec->dcl$b_node
  111.                 + spec->dcl$b_dev
  112.                 + spec->dcl$b_dir;
  113.             rmsinit_fab (&fab, &nam, p_, &spec->dcl_text[toname]);
  114.             rmsinit_nam (&nam, rsa, esa);
  115.             if ((status = sys$parse(&fab)) == RMS$_NORMAL)
  116.             {
  117.                 esa[nam.nam$b_esl] = EOS;
  118.                 if (!(rcode = dirseek_spec2 (esa, for_each)))
  119.                     break;
  120.             }
  121.         }
  122.     }
  123.     else
  124.         rcode = dirseek_spec2 (spec->dcl_text, for_each);
  125.     return (rcode);
  126. }
  127.  
  128. /* <dirseek_spec2>:
  129.  * Seek all occurrences of a particular filespec.  (This is a common procedure,
  130.  * shared with 'flscan').
  131.  */
  132. int    dirseek_spec2 (char *spec, tDIRSEEK)
  133. {
  134.     RMS_STUFF;
  135.  
  136.     rmsinit_fab (&fab, &nam, 0, spec);
  137.     rmsinit_nam (&nam, rsa, esa);
  138.  
  139.     if ((status = sys$parse(&fab)) == RMS$_NORMAL)
  140.     {
  141.         for (;;)
  142.         {
  143.             status = sys$search(&fab);
  144.             if (for_each != 0)
  145.                 (*for_each) (rsa, nam.nam$b_rsl, status);
  146.             if (status == RMS$_NMF)
  147.                 return (TRUE);
  148.             else if (status != RMS$_NORMAL)
  149.                 break;
  150.         }
  151.     }
  152.     return (FALSE);        /* Common return if any error    */
  153. }
  154.