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