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

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: flcols.c,v 1.10 1995/10/24 10:42:50 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    flcols.c
  7.  * Author:    T.E.Dickey
  8.  * Created:    01 Sep 1984
  9.  * Last update:
  10.  *        24 Oct 1995, added "USER" column
  11.  *        18 Mar 1995, prototypes
  12.  *        04 Nov 1988, added expired-date
  13.  *        05 Oct 1985, added 'flcols_132' entrypoint.
  14.  *        24 Aug 1985, if no argument for /CWIDTH, reset entire list
  15.  *        01 Jul 1985, recoded /CWIDTH to use 'scanint' rather than
  16.  *                 'sscanf' to bypass bug in CC2.0
  17.  *        19 May 1985, do nn.nn decoding as /CWIDTH command
  18.  *        18 May 1985, added nn.nn decoding to set name.type widths
  19.  *        22 Mar 1985, added IDENTIFIER, LENGTH (of record)
  20.  *        10 Jan 1985, had wrong default for '/OWNER' qualifier
  21.  *        08 Jan 1985, nailed down column-permission better
  22.  *        22 Dec 1984, added 'ALLOC' (renamed 'ATTRIBUTE' to 'XAB').
  23.  *                 If "*" given, copy old list at that point.
  24.  *        05 Dec 1984, added 'PATH' type.
  25.  *        17 Nov 1984, added 'ATTRIBUTE', 'FORMAT' types.
  26.  *
  27.  * Function:    Alter the FLIST display format by modifying the 'conv_list'
  28.  *        string.  DIRCMD passes the DCL-list as a series of lower-
  29.  *        cased tokens which we must match against the table of
  30.  *        permissible keys.
  31.  */
  32.  
  33. #include    <stdio.h>
  34. #include    <string.h>
  35. #include    <ctype.h>
  36.  
  37. #include    "bool.h"
  38. #include    "flist.h"
  39. #include    "dds.h"
  40. #include    "dircmd.h"
  41. #include    "dirent.h"
  42.  
  43. #include    "strutils.h"
  44.  
  45. import(A_opt);    import(D_opt);    import(M_opt);    import(O_opt);
  46. import(pcolumns);
  47. import(conv_list);
  48.  
  49. /*
  50.  * Table of full-length keywords used for display-columns.  They are all in
  51.  * uppercase to make messages with them more readable.  The order of the
  52.  * date subtypes corresponds to the permissible values of 'D_opt' (1:4 if set).
  53.  */
  54. static
  55. char    *keys[]    = {
  56.         "DATE",
  57.         "CREATED",    "BACKUP",    "REVISED",    "EXPIRED",
  58.         /* end subtype */
  59.         "ALLOC",    "FORMAT",    "IDENTIFIER",    "LENGTH",
  60.         "MASK",
  61.         "OWNER",    "PATH",        "SIZE",        "USER",
  62.         "XAB"};
  63.  
  64. static    int    max_keys = sizeof(keys) / sizeof(keys[0]);
  65.  
  66. static    int    flcols__add (char *out_, char c);
  67. static    char *    flcols__key (char c);
  68.  
  69. /*
  70.  * Decode a list of column-keywords to set/reset the display format:
  71.  */
  72. tDIRCMD(flcols)
  73. {
  74.     register
  75.     int    j;
  76.     char    new_list[sizeof(conv_list)];
  77.     register
  78.     char    *k_,
  79.         *text_;
  80.  
  81.     new_list[0] = '\0';
  82.     if (xdcl_ = xdcl_->dcl_next)    /* Point to first argument    */
  83.     {
  84.         for (; xdcl_; xdcl_ = xdcl_->dcl_next)
  85.         {
  86.         text_ = xdcl_->dcl_text;
  87.         if (strcmp(text_, "*") == 0)
  88.         {
  89.             for (k_ = conv_list; *k_; k_++)
  90.             if (flcols__add (new_list, *k_))    return;
  91.         }
  92.         else
  93.         {
  94.             for (j = 0, k_ = nullC; j < max_keys; j++)
  95.             {
  96.             if (strabbr (text_, keys[j], strlen(text_),1))
  97.             {
  98.                 k_ = keys[j];
  99.                 break;
  100.             }
  101.             }
  102.             if (k_)
  103.             {
  104.             if (flcols__add (new_list, _tolower(*text_)))
  105.                 return;
  106.             }
  107.             else
  108.             {
  109.             warn ("Unknown keyword: %s", text_);
  110.             return;
  111.             }
  112.         }
  113.         }
  114.         strcpy (conv_list, new_list);
  115.     }
  116.     else
  117.         flcols_init ();
  118.  
  119.     dds_all (dds_fast(DDS_U_C), *curfile_);
  120. }
  121.  
  122. /* <__key>:
  123.  * Return a pointer to a specific key-word, given the first character.
  124.  */
  125. static
  126. char    *flcols__key (char c)
  127. {
  128.     int    j;
  129.     for (j = 0, c = _toupper(c); j < max_keys; j++)
  130.     {
  131.         if (c == *keys[j])        return (keys[j]);
  132.     }
  133.     return ("?");
  134. }
  135.  
  136. /* <__add>:
  137.  * Add a new character to the (temporary) conversion list.  Return TRUE if
  138.  * an error was discovered.
  139.  */
  140. static
  141. int    flcols__add (char *out_, char c)
  142. {
  143.     if (    (strchr("bcdre", c) && !D_opt)
  144.     ||    (strchr("m", c)    && !M_opt)
  145.     ||    (strchr("o", c)    && !O_opt)
  146.     ||    (strchr("as", c)   && !A_opt) )
  147.     {
  148.         warn ("Display type %s is not applicable", flcols__key(c));
  149.         return (TRUE);
  150.     }
  151.     if (strchr(out_, c))
  152.     {
  153.         warn ("Repeated display-field: %s", flcols__key(c));
  154.         return (TRUE);
  155.     }
  156.     sprintf (out_ + strlen(out_), "%c", c);
  157.     return (FALSE);
  158. }
  159.  
  160. /* <init>:
  161.  * (Re)initialize 'conv_list', based on the current settings of FLIST's
  162.  * option flags.
  163.  */
  164. void    flcols_init (void)
  165. {
  166.     char    *c_ = conv_list;
  167.  
  168.     if (A_opt)    *c_++ = 's';
  169.     if (D_opt)    *c_++ = 'd';
  170.     if (M_opt)    *c_++ = 'm';
  171.     *c_ = EOS;
  172. }
  173.  
  174. /* <show>:
  175.  * Show the current contents of 'conv_list', in the summary line:
  176.  */
  177. void    flcols_show (void)
  178. {
  179.     int    j;
  180.     char    *c_ = conv_list,
  181.         c,
  182.         bfr[CRT_COLS];
  183.  
  184.     bfr[0] = EOS;
  185.     while (c = *c_++)
  186.     {
  187.         if (bfr[0])    strcat (bfr, ", ");
  188.         strcat (bfr, flcols__key(c));
  189.         if (c == 'd')
  190.             sprintf (strnull(bfr), " (%s)", keys[D_opt]);
  191.     }
  192.     flist_tell ("Display columns: %s", bfr);
  193. }
  194.  
  195. /* <left>:
  196.  * Rotate the display-list to the left.
  197.  */
  198. tDIRCMD(flcols_left)
  199. {
  200.     char    c = conv_list[0];
  201.  
  202.     if (conv_list[1])
  203.     {
  204.         sprintf (conv_list, "%s%c", &conv_list[1], c);
  205.         dds_all (dds_fast(DDS_U_C), *curfile_);
  206.     }
  207. }
  208.  
  209. /* <right>:
  210.  * Rotate the display-list to the right.
  211.  */
  212. tDIRCMD(flcols_right)
  213. {
  214.     int    len    = strlen(conv_list)-1;
  215.     char    old_list[sizeof(conv_list)],
  216.         c    = conv_list[len];
  217.  
  218.     if (len > 0)
  219.     {
  220.         strcpy (old_list, conv_list);
  221.         old_list[len] = EOS;
  222.         sprintf (conv_list, "%c%s", c, old_list);
  223.         dds_all (dds_fast(DDS_U_C), *curfile_);
  224.     }
  225. }
  226.  
  227. /* <width>:
  228.  * Decode a token of the form "n.t" where both parts are optional; specify the
  229.  * maximum number of columns to permit for the display of filename and filetype,
  230.  * respectively.
  231.  */
  232. tDIRCMD(flcols_width)
  233. {
  234.     int    nlen    = -1,
  235.         tlen    = -1;
  236.     register
  237.     int    set_width = 0;
  238.     register
  239.     char    *text_;
  240.  
  241.     if (xdcl_ = xdcl_->dcl_next)    /* Point to first argument    */
  242.     {
  243.         if (xdcl_->dcl_next)
  244.         {
  245.             warn ("Only one argument expected");
  246.         return;
  247.         }
  248.         else
  249.         {
  250.         text_ = xdcl_->dcl_text;
  251.         if (isdigit(*text_))    /* "nn" or "nn.nn"    */
  252.         {
  253.             text_ = scanint (text_, &nlen);
  254.             set_width++;
  255.         }
  256.         if (*text_)
  257.         {
  258.             if (*text_++ == '.')
  259.             {
  260.             if (isdigit(*text_))
  261.             {
  262.                 text_ = scanint (text_, &tlen);
  263.                 if (*text_ && *text_ != ';' && *text_ != '.')
  264.                 set_width = -1;
  265.                 else
  266.                 set_width++;
  267.             }
  268.             else if (*text_)
  269.                 set_width = -1;
  270.             }
  271.             else
  272.             set_width = -1;
  273.         }
  274.         if (set_width < 0 ||
  275.             nlen == 0 || nlen > MAX_NAME ||
  276.             tlen == 0 || tlen > MAX_TYPE)
  277.         {
  278.             warn ("Illegal column-width: %s", xdcl_->dcl_text);
  279.             return;
  280.         }
  281.         }
  282.         if (set_width)
  283.         {
  284.         pcolumns[0] = (nlen > 0) ? nlen : 0;
  285.         pcolumns[1] = (tlen > 0) ? tlen : 0;
  286.         }
  287.     }
  288.     else
  289.     {
  290.         pcolumns[0] = pcolumns[1] = 0;
  291.         dirent_width ((FILENT *)0);
  292.     }
  293.  
  294.     dds_all (dds_fast(DDS_U_C), *curfile_);
  295. }
  296.  
  297. /* <132>:
  298.  * Provide 80/132 column switch on VT100-compatible terminals with AVO (or
  299.  * equivalent).  If an argument is given, set a specific terminal-width.
  300.  */
  301. #define    WIDEST    132
  302. #define    NARROW    80
  303.  
  304. tDIRCMD(flcols_132)
  305. {
  306.     int    width,
  307.         length;
  308.     char    *text_;
  309.  
  310.     termsize (FALSE, &width, &length); /* Find current terminal-size */
  311.     if (xdcl_ = xdcl_->dcl_next)    /* Point to first argument    */
  312.     {
  313.         if (xdcl_->dcl_next)
  314.         {
  315.             warn ("Only one argument expected");
  316.         return;
  317.         }
  318.         else
  319.         {
  320.         text_ = scanint (xdcl_->dcl_text, &width);
  321.         if (*text_ || width <= 0)
  322.         {
  323.             warn ("Illegal argument: %d", xdcl_->dcl_text);
  324.             return;
  325.         }
  326.         }
  327.     }
  328.     else
  329.     {
  330.         if (width <= NARROW)    width = WIDEST;
  331.         else            width = NARROW;
  332.     }
  333.  
  334.     if (termsize (TRUE, &width, &length))
  335.     {
  336.         crt_refresh ();        /* Readjust CRT-module, repaint screen    */
  337.         dds_all (dds_fast(DDS_U_C), *curfile_);    /* Fill in any new text */
  338.     }
  339.     else
  340.         warn ("SET TERMINAL failed");
  341. }
  342.