home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / less3292.zip / opttbl.c < prev    next >
C/C++ Source or Header  |  1996-10-15  |  7KB  |  271 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994,1995,1996  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. /*
  36.  * Variables controlled by command line options.
  37.  */
  38. public int quiet;        /* Should we suppress the audible bell? */
  39. public int how_search;        /* Where should forward searches start? */
  40. public int top_scroll;        /* Repaint screen from top?
  41.                    (alternative is scroll from bottom) */
  42. public int pr_type;        /* Type of prompt (short, medium, long) */
  43. public int bs_mode;        /* How to process backspaces */
  44. public int know_dumb;        /* Don't complain about dumb terminals */
  45. public int quit_at_eof;        /* Quit after hitting end of file twice */
  46. public int squeeze;        /* Squeeze multiple blank lines into one */
  47. public int tabstop;        /* Tab settings */
  48. public int back_scroll;        /* Repaint screen on backwards movement */
  49. public int forw_scroll;        /* Repaint screen on forward movement */
  50. public int twiddle;        /* Display "~" for lines after EOF */
  51. public int caseless;        /* Do "caseless" searches */
  52. public int linenums;        /* Use line numbers */
  53. public int cbufs;        /* Current number of buffers */
  54. public int autobuf;        /* Automatically allocate buffers as needed */
  55. public int ctldisp;        /* Send control chars to screen untranslated */
  56. public int force_open;        /* Open the file even if not regular file */
  57. public int swindow;        /* Size of scrolling window */
  58. public int jump_sline;        /* Screen line of "jump target" */
  59. public int chopline;        /* Truncate displayed lines at screen width */
  60. public int no_init;        /* Disable sending ti/te termcap strings */
  61. #if HILITE_SEARCH
  62. public int hilite_search;    /* Highlight matched search patterns? */
  63. #endif
  64.  
  65. /*
  66.  * Table of all options and their semantics.
  67.  */
  68. static struct option option[] =
  69. {
  70.     { 'a', BOOL, OPT_OFF, &how_search, NULL,
  71.         "Search includes displayed screen",
  72.         "Search skips displayed screen",
  73.         NULL
  74.     },
  75.     { 'b', NUMBER, 10, &cbufs, opt_b, 
  76.         "Buffers: ",
  77.         "%d buffers",
  78.         NULL
  79.     },
  80.     { 'B', BOOL, OPT_ON, &autobuf, NULL,
  81.         "Don't automatically allocate buffers",
  82.         "Automatically allocate buffers when needed",
  83.         NULL
  84.     },
  85.     { 'c', TRIPLE, OPT_OFF, &top_scroll, NULL,
  86.         "Repaint by scrolling from bottom of screen",
  87.         "Repaint by clearing each line",
  88.         "Repaint by painting from top of screen"
  89.     },
  90.     { 'd', BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
  91.         "Assume intelligent terminal",
  92.         "Assume dumb terminal",
  93.         NULL
  94.     },
  95. #if MSDOS_COMPILER
  96.     { 'D', STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
  97.         "color desc: ", NULL, NULL
  98.     },
  99. #endif
  100.     { 'e', TRIPLE, OPT_OFF, &quit_at_eof, NULL,
  101.         "Don't quit at end-of-file",
  102.         "Quit at end-of-file",
  103.         "Quit immediately at end-of-file"
  104.     },
  105.     { 'f', BOOL, OPT_OFF, &force_open, NULL,
  106.         "Open only regular files",
  107.         "Open even non-regular files",
  108.         NULL
  109.     },
  110. #if HILITE_SEARCH
  111.     { 'g', TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
  112.         "Don't highlight search matches",
  113.         "Highlight matches for previous search only",
  114.         "Highlight all matches for previous search pattern",
  115.     },
  116. #endif
  117.     { 'h', NUMBER, -1, &back_scroll, NULL,
  118.         "Backwards scroll limit: ",
  119.         "Backwards scroll limit is %d lines",
  120.         NULL
  121.     },
  122.     { 'i', TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
  123.         "Case is significant in searches",
  124.         "Ignore case in searches",
  125.         "Ignore case in searches and in patterns"
  126.     },
  127.     { 'j', NUMBER, 1, &jump_sline, NULL,
  128.         "Target line: ",
  129.         "Position target at screen line %d",
  130.         NULL
  131.     },
  132. #if USERFILE
  133.     { 'k', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
  134.         NULL, NULL, NULL
  135.     },
  136. #endif
  137.     { 'l', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_l,
  138.         NULL, NULL, NULL
  139.     },
  140.     { 'm', TRIPLE, OPT_OFF, &pr_type, NULL,
  141.         "Short prompt",
  142.         "Medium prompt",
  143.         "Long prompt"
  144.     },
  145.     { 'n', TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
  146.         "Don't use line numbers",
  147.         "Use line numbers",
  148.         "Constantly display line numbers"
  149.     },
  150. #if LOGFILE
  151.     { 'o', STRING, 0, NULL, opt_o,
  152.         "log file: ", NULL, NULL
  153.     },
  154.     { 'O', STRING, 0, NULL, opt__O,
  155.         "Log file: ", NULL, NULL
  156.     },
  157. #endif
  158.     { 'p', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
  159.         NULL, NULL, NULL
  160.     },
  161.     { 'P', STRING, 0, NULL, opt__P,
  162.         "prompt: ", NULL, NULL
  163.     },
  164.     { 'q', TRIPLE, OPT_OFF, &quiet, NULL,
  165.         "Ring the bell for errors AND at eof/bof",
  166.         "Ring the bell for errors but not at eof/bof",
  167.         "Never ring the bell"
  168.     },
  169.     { 'r', BOOL|REPAINT, OPT_ON, &ctldisp, NULL,
  170.         "Display control characters directly",
  171.         "Display control characters as ^X",
  172.         NULL
  173.     },
  174.     { 's', BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
  175.         "Display all blank lines",
  176.         "Squeeze multiple blank lines",
  177.         NULL
  178.     },
  179.     { 'S', BOOL|REPAINT, OPT_OFF, &chopline, NULL,
  180.         "Fold long lines",
  181.         "Chop long lines",
  182.         NULL
  183.     },
  184. #if TAGS
  185.     { 't', STRING|NO_QUERY, 0, NULL, opt_t,
  186.         "tag: ", NULL, NULL
  187.     },
  188.     { 'T', STRING, 0, NULL, opt__T,
  189.         "tags file: ", NULL, NULL
  190.     },
  191. #endif
  192.     { 'u', TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
  193.         "Display underlined text in underline mode",
  194.         "Backspaces cause overstrike",
  195.         "Print backspace as ^H"
  196.     },
  197.     { 'V', NOVAR, 0, NULL, opt__V,
  198.         NULL, NULL, NULL
  199.     },
  200.     { 'w', BOOL|REPAINT, OPT_ON, &twiddle, NULL,
  201.         "Display nothing for lines after end-of-file",
  202.         "Display ~ for lines after end-of-file",
  203.         NULL
  204.     },
  205.     { 'x', NUMBER|REPAINT, 8, &tabstop, NULL,
  206.         "Tab stops: ",
  207.         "Tab stops every %d spaces", 
  208.         NULL
  209.     },
  210.     { 'X', BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
  211.         "Send init/deinit strings to terminal",
  212.         "Don't use init/deinit strings",
  213.         NULL
  214.     },
  215.     { 'y', NUMBER, -1, &forw_scroll, NULL,
  216.         "Forward scroll limit: ",
  217.         "Forward scroll limit is %d lines",
  218.         NULL
  219.     },
  220.     { 'z', NUMBER, -1, &swindow, NULL,
  221.         "Scroll window size: ",
  222.         "Scroll window size is %d lines",
  223.         NULL
  224.     },
  225.     { '"', STRING, 0, NULL, opt_quote,
  226.         "quotes: ", NULL, NULL
  227.     },
  228.     { '?', NOVAR, 0, NULL, opt_query,
  229.         NULL, NULL, NULL
  230.     },
  231.     { '\0' }
  232. };
  233.  
  234.  
  235. /*
  236.  * Initialize each option to its default value.
  237.  */
  238.     public void
  239. init_option()
  240. {
  241.     register struct option *o;
  242.  
  243.     for (o = option;  o->oletter != '\0';  o++)
  244.     {
  245.         /*
  246.          * Set each variable to its default.
  247.          */
  248.         if (o->ovar != NULL)
  249.             *(o->ovar) = o->odefault;
  250.     }
  251. }
  252.  
  253. /*
  254.  * Find an option in the option table.
  255.  */
  256.     public struct option *
  257. findopt(c)
  258.     int c;
  259. {
  260.     register struct option *o;
  261.  
  262.     for (o = option;  o->oletter != '\0';  o++)
  263.     {
  264.         if (o->oletter == c)
  265.             return (o);
  266.         if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
  267.             return (o);
  268.     }
  269.     return (NULL);
  270. }
  271.