home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / dirchk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-04  |  3.6 KB  |  128 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: dirchk.c,v 1.6 1995/06/04 19:44:26 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    dirchk.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    28 Jun 1984
  9.  * Last update:
  10.  *        19 Feb 1995, prototyped
  11.  *        19 Sep 1985, added tests for non-DCL syntax
  12.  *        26 Dec 1984, changed call on 'dclwild'.
  13.  *        25 Aug 1984, cleanup of buffer sizes
  14.  *        20 Jul 1984, added flag to make warning optional
  15.  *        30 Jun 1984
  16.  *
  17.  * Function:    This module checks the parsed command line (from 'dirarg')
  18.  *        for FLIST.  It checks for the proper number of filespecs,
  19.  *        and the absence (or presence) of options.  A status word is
  20.  *        used to check for permissible min/max argument lists (see
  21.  *        symbols "v_???").  This check routine can handle the following
  22.  *        cases:
  23.  *
  24.  *        (a)    one file (assumed both input, output)
  25.  *        (b)    one file in, one file out
  26.  *        (c)    one file in, many files out
  27.  *        (d)    many files in, many files out
  28.  *        (e)    many files in, one file out
  29.  *
  30.  * Parameters:    cmd_    => string which was parsed to make DCLARG-list,
  31.  *        dcl_    => parsed form of command (DCLARG-list).
  32.  *        state    =  (DIRCMD2.h) bit-vector defining command requirements
  33.  *        flg    =  TRUE iff errors should be reported via 'warn'.
  34.  *
  35.  * Returns:    TRUE if no errors are found.  If an error is found, an
  36.  *        appropriate message is emitted via 'warn'.
  37.  */
  38.  
  39. #include    <stdio.h>
  40. #include    <ctype.h>
  41.  
  42. #include    <rms.h>
  43.  
  44. #include    "flist.h"
  45. #include    "names.h"
  46. #include    "dircmd.h"
  47.  
  48. int    dirchk (char *cmd_, DCLARG *dcl_, int state, int flg)
  49. {
  50. DCLARG    *d_;
  51. int    numinp    = 0,        /* number of items in subfield-1    */
  52.     numout    = 0,        /* number of items in subfield-2    */
  53.     numopt    = 0,        /* number of option-fields found    */
  54.  
  55.     wldinp    = 0,        /* number of inputs with wildcards    */
  56.     wldout    = 0,        /* number of outputs with wildcards    */
  57.  
  58.     nummax    = 0,        /* number of parmeters past output    */
  59.     numcmd    = 0;        /* should be 1, if larger have extra ","*/
  60. char    *msg_    = nullC,    /* set iff warning message formed    */
  61.     msgbfr    [MAX_PATH];
  62.  
  63.     /*
  64.      * See what is in the argument list, and then check the result
  65.      * for adherence to the desired state.
  66.      */
  67.     for (d_ = dcl_; d_; d_ = d_->dcl_next)
  68.     {
  69.         char    *s_ = d_->dcl_text;
  70.         if (isopt(*s_))
  71.             numopt++;
  72.         else switch (d_->dcl_mfld)
  73.         {
  74.         case 0:    numcmd++;        /* have a comma in command? */
  75.             break;
  76.         case 1:    numinp++;
  77.             if (dclwild(d_))    wldinp++;
  78.             break;
  79.         case 2:    numout++;
  80.             if (dclwild(d_))    wldout++;
  81.             break;
  82.         default:nummax++;        /* too many parameters */
  83.         }
  84.     }
  85.  
  86. #define    MODE(m)    (state & (m))
  87. #define    ONE_IN    MODE(v_1_IN)
  88. #define    ONE_OUT    MODE(v_1_OUT)
  89.  
  90. #define    ANY_IN    MODE(v_1_IN  + v_M_IN)
  91. #define    ANY_OUT    MODE(v_1_OUT + v_M_OUT)
  92.  
  93. #define    FREE    MODE(v_FREE)
  94.  
  95. #define    NONE(t)    sprintf (msg_ = msgbfr, "%s uses no t", dcl_->dcl_text);
  96.  
  97.     if (MODE(v_nonDCL))
  98.     {
  99.         if (isopt(dcl_->dcl_text[0]))    numopt--, numcmd++;
  100.         if (!MODE(v_ARGS)
  101.         &&  ((numout + numinp) > 0 || numcmd > 1 || numopt > 0))
  102.             NONE(arguments);
  103.     }
  104.     else if (numcmd > 1)
  105.         msg_ = "extraneous ',' in command field";
  106.     else if (numinp > 1 && ONE_IN)
  107.         msg_ = "too many input fields";
  108.     else if (numinp <= 0 && ANY_IN && !FREE)
  109.         msg_ = "need a filespec";
  110.     else if (nummax > 0
  111.     ||     (numout > 0 && !ANY_OUT)
  112.     ||     (numinp > 0 && !ANY_IN) )
  113.         msg_ = "too many parameters";
  114.     else if (numout > 1 && ONE_OUT)
  115.         msg_ = "too many output fields";
  116.     else if (numout <= 0 && ANY_OUT && !FREE)
  117.         msg_ = "need an output filespec";
  118.     else if (wldinp && !(state & v_W_IN))
  119.         msg_ = "no wildcard permitted in input spec";
  120.     else if (wldout && !(state & v_W_OUT))
  121.         msg_ = "no wildcard permitted in output spec";
  122.     else if (numopt > 0 && !(state & v_OPTS))
  123.         NONE(options);
  124.  
  125.     if (msg_ && flg)        warn (msg_);
  126.     return (msg_ == nullC);
  127. }
  128.