home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 036 / less232.zip / OPTTBL.C < prev    next >
C/C++ Source or Header  |  1994-08-24  |  7KB  |  278 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994  Mark Nudelman
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice in the documentation and/or other materials provided with 
  12.  *    the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  15.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  17.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
  20.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
  24.  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26.  
  27.  
  28. /*
  29.  * The option table.
  30.  */
  31.  
  32. #include "less.h"
  33. #include "option.h"
  34.  
  35. #define    toupper(c)    ((c)-'a'+'A')
  36.  
  37. /*
  38.  * Variables controlled by command line options.
  39.  */
  40. public int quiet;        /* Should we suppress the audible bell? */
  41. public int how_search;        /* Where should forward searches start? */
  42. public int top_scroll;        /* Repaint screen from top?
  43.                    (alternative is scroll from bottom) */
  44. public int pr_type;        /* Type of prompt (short, medium, long) */
  45. public int bs_mode;        /* How to process backspaces */
  46. public int know_dumb;        /* Don't complain about dumb terminals */
  47. public int quit_at_eof;        /* Quit after hitting end of file twice */
  48. public int squeeze;        /* Squeeze multiple blank lines into one */
  49. public int tabstop;        /* Tab settings */
  50. public int back_scroll;        /* Repaint screen on backwards movement */
  51. public int forw_scroll;        /* Repaint screen on forward movement */
  52. public int twiddle;        /* Display "~" for lines after EOF */
  53. public int caseless;        /* Do "caseless" searches */
  54. public int linenums;        /* Use line numbers */
  55. public int cbufs;        /* Current number of buffers */
  56. public int autobuf;        /* Automatically allocate buffers as needed */
  57. public int nohelp;        /* Disable the HELP command */
  58. public int ctldisp;        /* Send control chars to screen untranslated */
  59. public int force_open;        /* Open the file even if not regular file */
  60. public int swindow;        /* Size of scrolling window */
  61. public int jump_sline;        /* Screen line of "jump target" */
  62. public int chopline;        /* Truncate displayed lines at screen width */
  63. public int no_init;        /* Disable sending ti/te termcap strings */
  64. #if HILITE_SEARCH
  65. public int hilite_search;    /* Highlight matched search patterns? */
  66. #endif
  67.  
  68. /*
  69.  * Table of all options and their semantics.
  70.  */
  71. static struct option option[] =
  72. {
  73.     { 'a', BOOL, 0, &how_search, NULL,
  74.         "Search includes displayed screen",
  75.         "Search skips displayed screen",
  76.         NULL
  77.     },
  78.     { 'b', NUMBER, 10, &cbufs, opt_b, 
  79.         "Buffers: ",
  80.         "%d buffers",
  81.         NULL
  82.     },
  83.     { 'B', BOOL, 1, &autobuf, NULL,
  84.         "Don't automatically allocate buffers",
  85.         "Automatically allocate buffers when needed",
  86.         NULL
  87.     },
  88.     { 'c', TRIPLE, 0, &top_scroll, NULL,
  89.         "Repaint by scrolling from bottom of screen",
  90.         "Repaint by clearing each line",
  91.         "Repaint by painting from top of screen"
  92.     },
  93.     { 'd', BOOL|NO_TOGGLE, 0, &know_dumb, NULL,
  94.         "Assume intelligent terminal",
  95.         "Assume dumb terminal",
  96.         NULL
  97.     },
  98. #if MSOFTC
  99.     { 'D', STRING|REPAINT, 0, NULL, opt_D,
  100.         "color desc: ", NULL, NULL
  101.     },
  102. #endif
  103.     { 'e', TRIPLE, 0, &quit_at_eof, NULL,
  104.         "Don't quit at end-of-file",
  105.         "Quit at end-of-file",
  106.         "Quit immediately at end-of-file"
  107.     },
  108.     { 'f', BOOL, 0, &force_open, NULL,
  109.         "Open only regular files",
  110.         "Open even non-regular files",
  111.         NULL
  112.     },
  113. #if HILITE_SEARCH
  114.     { 'F', BOOL|REPAINT, 1, &hilite_search, NULL,
  115.         "Don't highlight matches for previous search pattern",
  116.         "Highlight all matches for previous search pattern",
  117.         NULL
  118.     },
  119. #endif
  120.     { 'h', NUMBER, -1, &back_scroll, NULL,
  121.         "Backwards scroll limit: ",
  122.         "Backwards scroll limit is %d lines",
  123.         NULL
  124.     },
  125.     { 'H', BOOL|NO_TOGGLE, 0, &nohelp, NULL,
  126.         "Allow help command",
  127.         "Don't allow help command",
  128.         NULL
  129.     },
  130.     { 'i', BOOL|REPAINT, 0, &caseless, opt_i,
  131.         "Case is significant in searches",
  132.         "Ignore case in searches",
  133.         NULL
  134.     },
  135.     { 'j', NUMBER, 1, &jump_sline, NULL,
  136.         "Target line: ",
  137.         "Position target at screen line %d",
  138.         NULL
  139.     },
  140. #if USERFILE
  141.     { 'k', STRING|NO_TOGGLE, 0, NULL, opt_k,
  142.         NULL, NULL, NULL
  143.     },
  144. #endif
  145. #if LOGFILE
  146.     { 'l', STRING|NO_TOGGLE, 0, NULL, opt_l,
  147.         NULL, NULL, NULL
  148.     },
  149.     { 'L', STRING, 0, NULL, opt__L,
  150.         NULL, NULL, NULL
  151.     },
  152. #endif
  153.     { 'm', TRIPLE, 0, &pr_type, NULL,
  154.         "Short prompt",
  155.         "Medium prompt",
  156.         "Long prompt"
  157.     },
  158.     { 'n', TRIPLE|REPAINT, 1, &linenums, NULL,
  159.         "Don't use line numbers",
  160.         "Use line numbers",
  161.         "Constantly display line numbers"
  162.     },
  163. #if LOGFILE
  164.     { 'o', STRING, 0, NULL, opt_o,
  165.         "log file: ", NULL, NULL
  166.     },
  167.     { 'O', STRING, 0, NULL, opt__O,
  168.         "Log file: ", NULL, NULL
  169.     },
  170. #endif
  171.     { 'p', STRING|NO_TOGGLE, 0, NULL, opt_p,
  172.         NULL, NULL, NULL
  173.     },
  174.     { 'P', STRING, 0, NULL, opt__P,
  175.         "prompt: ", NULL, NULL
  176.     },
  177.     { 'q', TRIPLE, 0, &quiet, NULL,
  178.         "Ring the bell for errors AND at eof/bof",
  179.         "Ring the bell for errors but not at eof/bof",
  180.         "Never ring the bell"
  181.     },
  182.     { 'r', BOOL|REPAINT, 1, &ctldisp, NULL,
  183.         "Display control characters directly",
  184.         "Display control characters as ^X",
  185.         NULL
  186.     },
  187.     { 's', BOOL|REPAINT, 0, &squeeze, NULL,
  188.         "Display all blank lines",
  189.         "Squeeze multiple blank lines",
  190.         NULL
  191.     },
  192.     { 'S', BOOL|REPAINT, 0, &chopline, NULL,
  193.         "Fold long lines",
  194.         "Chop long lines",
  195.         NULL
  196.     },
  197. #if TAGS
  198.     { 't', STRING, 0, NULL, opt_t,
  199.         "tag: ", NULL, NULL
  200.     },
  201.     { 'T', STRING, 0, NULL, opt__T,
  202.         "tags file: ", NULL, NULL
  203.     },
  204. #endif
  205.     { 'u', TRIPLE|REPAINT, 0, &bs_mode, NULL,
  206.         "Display underlined text in underline mode",
  207.         "Backspaces cause overstrike",
  208.         "Print backspace as ^H"
  209.     },
  210.     { 'w', BOOL|REPAINT, 1, &twiddle, NULL,
  211.         "Display nothing for lines after end-of-file",
  212.         "Display ~ for lines after end-of-file",
  213.         NULL
  214.     },
  215.     { 'x', NUMBER|REPAINT, 8, &tabstop, NULL,
  216.         "Tab stops: ",
  217.         "Tab stops every %d spaces", 
  218.         NULL
  219.     },
  220.     { 'X', BOOL|NO_TOGGLE, 0, &no_init, NULL,
  221.         "Send init/deinit strings to terminal",
  222.         "Don't use init/deinit strings",
  223.         NULL
  224.     },
  225.     { 'y', NUMBER, -1, &forw_scroll, NULL,
  226.         "Forward scroll limit: ",
  227.         "Forward scroll limit is %d lines",
  228.         NULL
  229.     },
  230.     { 'z', NUMBER, -1, &swindow, NULL,
  231.         "Scroll window size: ",
  232.         "Scroll window size is %d lines",
  233.         NULL
  234.     },
  235.     { '?', NOVAR, 0, NULL, opt_query,
  236.         NULL, NULL, NULL
  237.     },
  238.     { '\0' }
  239. };
  240.  
  241.  
  242. /*
  243.  * Initialize each option to its default value.
  244.  */
  245.     public void
  246. init_option()
  247. {
  248.     register struct option *o;
  249.  
  250.     for (o = option;  o->oletter != '\0';  o++)
  251.     {
  252.         /*
  253.          * Set each variable to its default.
  254.          */
  255.         if (o->ovar != NULL)
  256.             *(o->ovar) = o->odefault;
  257.     }
  258. }
  259.  
  260. /*
  261.  * Find an option in the option table.
  262.  */
  263.     public struct option *
  264. findopt(c)
  265.     int c;
  266. {
  267.     register struct option *o;
  268.  
  269.     for (o = option;  o->oletter != '\0';  o++)
  270.     {
  271.         if (o->oletter == c)
  272.             return (o);
  273.         if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
  274.             return (o);
  275.     }
  276.     return (NULL);
  277. }
  278.