home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / LES177AS.ZIP / OPTTBL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  6.5 KB  |  267 lines

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