[BACK]Return to opttbl.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Annotation of src/usr.bin/less/opttbl.c, Revision 1.1.1.4

1.1       etheisen    1: /*
1.1.1.4 ! shadchin    2:  * Copyright (C) 1984-2012  Mark Nudelman
1.1       etheisen    3:  *
1.1.1.2   millert     4:  * You may distribute under the terms of either the GNU General Public
                      5:  * License or the Less License, as specified in the README file.
1.1       etheisen    6:  *
1.1.1.4 ! shadchin    7:  * For more information, see the README file.
1.1       etheisen    8:  */
                      9:
                     10:
                     11: /*
                     12:  * The option table.
                     13:  */
                     14:
                     15: #include "less.h"
                     16: #include "option.h"
                     17:
                     18: /*
                     19:  * Variables controlled by command line options.
                     20:  */
                     21: public int quiet;              /* Should we suppress the audible bell? */
                     22: public int how_search;         /* Where should forward searches start? */
                     23: public int top_scroll;         /* Repaint screen from top?
                     24:                                   (alternative is scroll from bottom) */
                     25: public int pr_type;            /* Type of prompt (short, medium, long) */
                     26: public int bs_mode;            /* How to process backspaces */
                     27: public int know_dumb;          /* Don't complain about dumb terminals */
                     28: public int quit_at_eof;                /* Quit after hitting end of file twice */
1.1.1.2   millert    29: public int quit_if_one_screen; /* Quit if EOF on first screen */
1.1       etheisen   30: public int squeeze;            /* Squeeze multiple blank lines into one */
1.1.1.4 ! shadchin   31: public int be_helpful;         /* more(1) style -d */
1.1       etheisen   32: public int tabstop;            /* Tab settings */
                     33: public int back_scroll;                /* Repaint screen on backwards movement */
                     34: public int forw_scroll;                /* Repaint screen on forward movement */
                     35: public int caseless;           /* Do "caseless" searches */
                     36: public int linenums;           /* Use line numbers */
                     37: public int autobuf;            /* Automatically allocate buffers as needed */
1.1.1.2   millert    38: public int bufspace;           /* Max buffer space per file (K) */
1.1       etheisen   39: public int ctldisp;            /* Send control chars to screen untranslated */
                     40: public int force_open;         /* Open the file even if not regular file */
                     41: public int swindow;            /* Size of scrolling window */
                     42: public int jump_sline;         /* Screen line of "jump target" */
1.1.1.3   shadchin   43: public long jump_sline_fraction = -1;
                     44: public long shift_count_fraction = -1;
1.1       etheisen   45: public int chopline;           /* Truncate displayed lines at screen width */
                     46: public int no_init;            /* Disable sending ti/te termcap strings */
1.1.1.2   millert    47: public int no_keypad;          /* Disable sending ks/ke termcap strings */
                     48: public int twiddle;             /* Show tildes after EOF */
                     49: public int show_attn;          /* Hilite first unread line */
                     50: public int shift_count;                /* Number of positions to shift horizontally */
                     51: public int status_col;         /* Display a status column */
                     52: public int use_lessopen;       /* Use the LESSOPEN filter */
1.1.1.3   shadchin   53: public int quit_on_intr;       /* Quit on interrupt */
                     54: public int follow_mode;                /* F cmd Follows file desc or file name? */
                     55: public int oldbot;             /* Old bottom of screen behavior {{REMOVE}} */
1.1.1.4 ! shadchin   56: public int opt_use_backslash;  /* Use backslash escaping in option parsing */
1.1       etheisen   57: #if HILITE_SEARCH
                     58: public int hilite_search;      /* Highlight matched search patterns? */
                     59: #endif
                     60:
1.1.1.3   shadchin   61: public int less_is_more = 0;   /* Make compatible with POSIX more */
                     62:
1.1       etheisen   63: /*
1.1.1.2   millert    64:  * Long option names.
                     65:  */
1.1.1.4 ! shadchin   66: #if GNU_OPTIONS
1.1.1.2   millert    67: static struct optname a_optname      = { "search-skip-screen",   NULL };
                     68: static struct optname b_optname      = { "buffers",              NULL };
                     69: static struct optname B__optname     = { "auto-buffers",         NULL };
                     70: static struct optname c_optname      = { "clear-screen",         NULL };
                     71: static struct optname d_optname      = { "dumb",                 NULL };
                     72: #if MSDOS_COMPILER
                     73: static struct optname D__optname     = { "color",                NULL };
                     74: #endif
                     75: static struct optname e_optname      = { "quit-at-eof",          NULL };
                     76: static struct optname f_optname      = { "force",                NULL };
                     77: static struct optname F__optname     = { "quit-if-one-screen",   NULL };
                     78: #if HILITE_SEARCH
                     79: static struct optname g_optname      = { "hilite-search",        NULL };
                     80: #endif
                     81: static struct optname h_optname      = { "max-back-scroll",      NULL };
                     82: static struct optname i_optname      = { "ignore-case",          NULL };
                     83: static struct optname j_optname      = { "jump-target",          NULL };
                     84: static struct optname J__optname     = { "status-column",        NULL };
                     85: #if USERFILE
                     86: static struct optname k_optname      = { "lesskey-file",         NULL };
                     87: #endif
1.1.1.3   shadchin   88: static struct optname K__optname     = { "quit-on-intr",         NULL };
1.1.1.2   millert    89: static struct optname L__optname     = { "no-lessopen",          NULL };
                     90: static struct optname m_optname      = { "long-prompt",          NULL };
                     91: static struct optname n_optname      = { "line-numbers",         NULL };
                     92: #if LOGFILE
                     93: static struct optname o_optname      = { "log-file",             NULL };
                     94: static struct optname O__optname     = { "LOG-FILE",             NULL };
                     95: #endif
                     96: static struct optname p_optname      = { "pattern",              NULL };
                     97: static struct optname P__optname     = { "prompt",               NULL };
                     98: static struct optname q2_optname     = { "silent",               NULL };
                     99: static struct optname q_optname      = { "quiet",                &q2_optname };
                    100: static struct optname r_optname      = { "raw-control-chars",    NULL };
                    101: static struct optname s_optname      = { "squeeze-blank-lines",  NULL };
                    102: static struct optname S__optname     = { "chop-long-lines",      NULL };
                    103: #if TAGS
                    104: static struct optname t_optname      = { "tag",                  NULL };
                    105: static struct optname T__optname     = { "tag-file",             NULL };
                    106: #endif
                    107: static struct optname u_optname      = { "underline-special",    NULL };
                    108: static struct optname V__optname     = { "version",              NULL };
                    109: static struct optname w_optname      = { "hilite-unread",        NULL };
                    110: static struct optname x_optname      = { "tabs",                 NULL };
                    111: static struct optname X__optname     = { "no-init",              NULL };
                    112: static struct optname y_optname      = { "max-forw-scroll",      NULL };
                    113: static struct optname z_optname      = { "window",               NULL };
                    114: static struct optname quote_optname  = { "quotes",               NULL };
                    115: static struct optname tilde_optname  = { "tilde",                NULL };
                    116: static struct optname query_optname  = { "help",                 NULL };
                    117: static struct optname pound_optname  = { "shift",                NULL };
                    118: static struct optname keypad_optname = { "no-keypad",            NULL };
1.1.1.3   shadchin  119: static struct optname oldbot_optname = { "old-bot",              NULL };
                    120: static struct optname follow_optname = { "follow-name",          NULL };
1.1.1.4 ! shadchin  121: static struct optname use_backslash_optname = { "use-backslash", NULL };
        !           122: #else
        !           123: static struct optname fake_optname   = { "fake",                 NULL };
        !           124: #define a_optname      fake_optname
        !           125: #define b_optname      fake_optname
        !           126: #define B__optname     fake_optname
        !           127: #define c_optname      fake_optname
        !           128: #define d_optname      fake_optname
        !           129: #if MSDOS_COMPILER
        !           130: #define D__optname     fake_optname
        !           131: #endif
        !           132: #define e_optname      fake_optname
        !           133: #define f_optname      fake_optname
        !           134: #define F__optname     fake_optname
        !           135: #if HILITE_SEARCH
        !           136: #define g_optname      fake_optname
        !           137: #endif
        !           138: #define h_optname      fake_optname
        !           139: #define i_optname      fake_optname
        !           140: #define j_optname      fake_optname
        !           141: #define J__optname     fake_optname
        !           142: #if USERFILE
        !           143: #define k_optname      fake_optname
        !           144: #endif
        !           145: #define K__optname     fake_optname
        !           146: #define L__optname     fake_optname
        !           147: #define m_optname      fake_optname
        !           148: #define n_optname      fake_optname
        !           149: #if LOGFILE
        !           150: #define o_optname      fake_optname
        !           151: #define O__optname     fake_optname
        !           152: #endif
        !           153: #define p_optname      fake_optname
        !           154: #define P__optname     fake_optname
        !           155: #define q2_optname     fake_optname
        !           156: #define q_optname      fake_optname
        !           157: #define r_optname      fake_optname
        !           158: #define s_optname      fake_optname
        !           159: #define S__optname     fake_optname
        !           160: #if TAGS
        !           161: #define t_optname      fake_optname
        !           162: #define T__optname     fake_optname
        !           163: #endif
        !           164: #define u_optname      fake_optname
        !           165: #define V__optname     fake_optname
        !           166: #define w_optname      fake_optname
        !           167: #define x_optname      fake_optname
        !           168: #define X__optname     fake_optname
        !           169: #define y_optname      fake_optname
        !           170: #define z_optname      fake_optname
        !           171: #define quote_optname  fake_optname
        !           172: #define tilde_optname  fake_optname
        !           173: #define query_optname  fake_optname
        !           174: #define pound_optname  fake_optname
        !           175: #define keypad_optname fake_optname
        !           176: #define oldbot_optname fake_optname
        !           177: #define follow_optname fake_optname
        !           178: #define use_backslash_optname  fake_optname
        !           179: #endif
1.1.1.2   millert   180:
                    181:
                    182: /*
1.1       etheisen  183:  * Table of all options and their semantics.
1.1.1.2   millert   184:  *
                    185:  * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are
                    186:  * the description of the option when set to 0, 1 or 2, respectively.
                    187:  * For NUMBER options, odesc[0] is the prompt to use when entering
                    188:  * a new value, and odesc[1] is the description, which should contain
                    189:  * one %d which is replaced by the value of the number.
                    190:  * For STRING options, odesc[0] is the prompt to use when entering
                    191:  * a new value, and odesc[1], if not NULL, is the set of characters
                    192:  * that are valid in the string.
1.1       etheisen  193:  */
1.1.1.2   millert   194: static struct loption option[] =
1.1       etheisen  195: {
1.1.1.2   millert   196:        { 'a', &a_optname,
1.1.1.3   shadchin  197:                TRIPLE, OPT_ONPLUS, &how_search, NULL,
1.1.1.2   millert   198:                {
                    199:                        "Search includes displayed screen",
                    200:                        "Search skips displayed screen",
1.1.1.3   shadchin  201:                        "Search includes all of displayed screen"
1.1.1.2   millert   202:                }
                    203:        },
                    204:
                    205:        { 'b', &b_optname,
                    206:                NUMBER|INIT_HANDLER, 64, &bufspace, opt_b,
                    207:                {
                    208:                        "Max buffer space per file (K): ",
                    209:                        "Max buffer space per file: %dK",
                    210:                        NULL
                    211:                }
                    212:        },
                    213:        { 'B', &B__optname,
                    214:                BOOL, OPT_ON, &autobuf, NULL,
                    215:                {
                    216:                        "Don't automatically allocate buffers",
                    217:                        "Automatically allocate buffers when needed",
                    218:                        NULL
                    219:                }
                    220:        },
                    221:        { 'c', &c_optname,
1.1.1.4 ! shadchin  222:                TRIPLE, OPT_ON, &top_scroll, NULL,
1.1.1.2   millert   223:                {
                    224:                        "Repaint by scrolling from bottom of screen",
1.1.1.3   shadchin  225:                        "Repaint by painting from top of screen",
1.1.1.2   millert   226:                        "Repaint by painting from top of screen"
                    227:                }
                    228:        },
                    229:        { 'd', &d_optname,
                    230:                BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL,
                    231:                {
                    232:                        "Assume intelligent terminal",
                    233:                        "Assume dumb terminal",
                    234:                        NULL
                    235:                }
                    236:        },
                    237: #if MSDOS_COMPILER
                    238:        { 'D', &D__optname,
                    239:                STRING|REPAINT|NO_QUERY, 0, NULL, opt_D,
                    240:                {
                    241:                        "color desc: ",
                    242:                        "Ddknsu0123456789.",
                    243:                        NULL
                    244:                }
                    245:        },
                    246: #endif
                    247:        { 'e', &e_optname,
                    248:                TRIPLE, OPT_OFF, &quit_at_eof, NULL,
                    249:                {
                    250:                        "Don't quit at end-of-file",
                    251:                        "Quit at end-of-file",
                    252:                        "Quit immediately at end-of-file"
                    253:                }
                    254:        },
                    255:        { 'f', &f_optname,
                    256:                BOOL, OPT_OFF, &force_open, NULL,
                    257:                {
                    258:                        "Open only regular files",
                    259:                        "Open even non-regular files",
                    260:                        NULL
                    261:                }
                    262:        },
                    263:        { 'F', &F__optname,
                    264:                BOOL, OPT_OFF, &quit_if_one_screen, NULL,
                    265:                {
                    266:                        "Don't quit if end-of-file on first screen",
                    267:                        "Quit if end-of-file on first screen",
                    268:                        NULL
                    269:                }
1.1       etheisen  270:        },
                    271: #if HILITE_SEARCH
1.1.1.2   millert   272:        { 'g', &g_optname,
                    273:                TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL,
                    274:                {
                    275:                        "Don't highlight search matches",
                    276:                        "Highlight matches for previous search only",
                    277:                        "Highlight all matches for previous search pattern",
                    278:                }
                    279:        },
                    280: #endif
                    281:        { 'h', &h_optname,
                    282:                NUMBER, -1, &back_scroll, NULL,
                    283:                {
                    284:                        "Backwards scroll limit: ",
                    285:                        "Backwards scroll limit is %d lines",
                    286:                        NULL
                    287:                }
                    288:        },
                    289:        { 'i', &i_optname,
                    290:                TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i,
                    291:                {
                    292:                        "Case is significant in searches",
                    293:                        "Ignore case in searches",
                    294:                        "Ignore case in searches and in patterns"
                    295:                }
                    296:        },
                    297:        { 'j', &j_optname,
1.1.1.3   shadchin  298:                STRING, 0, NULL, opt_j,
1.1.1.2   millert   299:                {
                    300:                        "Target line: ",
1.1.1.3   shadchin  301:                        "0123456789.-",
1.1.1.2   millert   302:                        NULL
                    303:                }
                    304:        },
                    305:        { 'J', &J__optname,
                    306:                BOOL|REPAINT, OPT_OFF, &status_col, NULL,
                    307:                {
                    308:                        "Don't display a status column",
                    309:                        "Display a status column",
                    310:                        NULL
                    311:                }
1.1       etheisen  312:        },
                    313: #if USERFILE
1.1.1.2   millert   314:        { 'k', &k_optname,
                    315:                STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
                    316:                { NULL, NULL, NULL }
1.1       etheisen  317:        },
                    318: #endif
1.1.1.3   shadchin  319:        { 'K', &K__optname,
                    320:                BOOL, OPT_OFF, &quit_on_intr, NULL,
                    321:                {
                    322:                        "Interrupt (ctrl-C) returns to prompt",
                    323:                        "Interrupt (ctrl-C) exits less",
                    324:                        NULL
                    325:                }
1.1.1.2   millert   326:        },
                    327:        { 'L', &L__optname,
                    328:                BOOL, OPT_ON, &use_lessopen, NULL,
                    329:                {
                    330:                        "Don't use the LESSOPEN filter",
                    331:                        "Use the LESSOPEN filter",
                    332:                        NULL
                    333:                }
                    334:        },
                    335:        { 'm', &m_optname,
                    336:                TRIPLE, OPT_OFF, &pr_type, NULL,
                    337:                {
                    338:                        "Short prompt",
                    339:                        "Medium prompt",
                    340:                        "Long prompt"
                    341:                }
                    342:        },
                    343:        { 'n', &n_optname,
                    344:                TRIPLE|REPAINT, OPT_ON, &linenums, NULL,
                    345:                {
                    346:                        "Don't use line numbers",
                    347:                        "Use line numbers",
                    348:                        "Constantly display line numbers"
                    349:                }
1.1       etheisen  350:        },
                    351: #if LOGFILE
1.1.1.2   millert   352:        { 'o', &o_optname,
                    353:                STRING, 0, NULL, opt_o,
                    354:                { "log file: ", NULL, NULL }
                    355:        },
                    356:        { 'O', &O__optname,
                    357:                STRING, 0, NULL, opt__O,
                    358:                { "Log file: ", NULL, NULL }
1.1       etheisen  359:        },
                    360: #endif
1.1.1.2   millert   361:        { 'p', &p_optname,
                    362:                STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p,
                    363:                { NULL, NULL, NULL }
                    364:        },
                    365:        { 'P', &P__optname,
                    366:                STRING, 0, NULL, opt__P,
                    367:                { "prompt: ", NULL, NULL }
                    368:        },
                    369:        { 'q', &q_optname,
                    370:                TRIPLE, OPT_OFF, &quiet, NULL,
                    371:                {
                    372:                        "Ring the bell for errors AND at eof/bof",
                    373:                        "Ring the bell for errors but not at eof/bof",
                    374:                        "Never ring the bell"
                    375:                }
                    376:        },
                    377:        { 'r', &r_optname,
                    378:                TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL,
                    379:                {
                    380:                        "Display control characters as ^X",
                    381:                        "Display control characters directly",
                    382:                        "Display control characters directly, processing ANSI sequences"
                    383:                }
                    384:        },
                    385:        { 's', &s_optname,
                    386:                BOOL|REPAINT, OPT_OFF, &squeeze, NULL,
                    387:                {
                    388:                        "Display all blank lines",
                    389:                        "Squeeze multiple blank lines",
                    390:                        NULL
                    391:                }
                    392:        },
                    393:        { 'S', &S__optname,
                    394:                BOOL|REPAINT, OPT_OFF, &chopline, NULL,
                    395:                {
                    396:                        "Fold long lines",
                    397:                        "Chop long lines",
                    398:                        NULL
                    399:                }
1.1       etheisen  400:        },
                    401: #if TAGS
1.1.1.2   millert   402:        { 't', &t_optname,
                    403:                STRING|NO_QUERY, 0, NULL, opt_t,
                    404:                { "tag: ", NULL, NULL }
                    405:        },
                    406:        { 'T', &T__optname,
                    407:                STRING, 0, NULL, opt__T,
                    408:                { "tags file: ", NULL, NULL }
1.1       etheisen  409:        },
                    410: #endif
1.1.1.2   millert   411:        { 'u', &u_optname,
                    412:                TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL,
                    413:                {
                    414:                        "Display underlined text in underline mode",
                    415:                        "Backspaces cause overstrike",
                    416:                        "Print backspace as ^H"
                    417:                }
                    418:        },
                    419:        { 'V', &V__optname,
                    420:                NOVAR, 0, NULL, opt__V,
                    421:                { NULL, NULL, NULL }
                    422:        },
                    423:        { 'w', &w_optname,
                    424:                TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL,
                    425:                {
                    426:                        "Don't highlight first unread line",
                    427:                        "Highlight first unread line after forward-screen",
                    428:                        "Highlight first unread line after any forward movement",
                    429:                }
                    430:        },
                    431:        { 'x', &x_optname,
                    432:                STRING|REPAINT, 0, NULL, opt_x,
                    433:                {
                    434:                        "Tab stops: ",
                    435:                        "0123456789,",
                    436:                        NULL
                    437:                }
                    438:        },
                    439:        { 'X', &X__optname,
                    440:                BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL,
                    441:                {
                    442:                        "Send init/deinit strings to terminal",
                    443:                        "Don't use init/deinit strings",
                    444:                        NULL
                    445:                }
                    446:        },
                    447:        { 'y', &y_optname,
                    448:                NUMBER, -1, &forw_scroll, NULL,
                    449:                {
                    450:                        "Forward scroll limit: ",
                    451:                        "Forward scroll limit is %d lines",
                    452:                        NULL
                    453:                }
                    454:        },
                    455:        { 'z', &z_optname,
                    456:                NUMBER, -1, &swindow, NULL,
                    457:                {
                    458:                        "Scroll window size: ",
                    459:                        "Scroll window size is %d lines",
                    460:                        NULL
                    461:                }
                    462:        },
                    463:        { '"', &quote_optname,
                    464:                STRING, 0, NULL, opt_quote,
                    465:                { "quotes: ", NULL, NULL }
                    466:        },
                    467:        { '~', &tilde_optname,
                    468:                BOOL|REPAINT, OPT_ON, &twiddle, NULL,
                    469:                {
                    470:                        "Don't show tildes after end of file",
                    471:                        "Show tildes after end of file",
                    472:                        NULL
                    473:                }
                    474:        },
                    475:        { '?', &query_optname,
                    476:                NOVAR, 0, NULL, opt_query,
                    477:                { NULL, NULL, NULL }
                    478:        },
                    479:        { '#', &pound_optname,
1.1.1.3   shadchin  480:                STRING, 0, NULL, opt_shift,
1.1.1.2   millert   481:                {
                    482:                        "Horizontal shift: ",
1.1.1.3   shadchin  483:                        "0123456789.",
1.1.1.2   millert   484:                        NULL
                    485:                }
                    486:        },
1.1.1.3   shadchin  487:        { OLETTER_NONE, &keypad_optname,
1.1.1.2   millert   488:                BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL,
                    489:                {
                    490:                        "Use keypad mode",
                    491:                        "Don't use keypad mode",
                    492:                        NULL
                    493:                }
1.1       etheisen  494:        },
1.1.1.3   shadchin  495:        { OLETTER_NONE, &oldbot_optname,
                    496:                BOOL, OPT_OFF, &oldbot, NULL,
                    497:                {
                    498:                        "Use new bottom of screen behavior",
                    499:                        "Use old bottom of screen behavior",
                    500:                        NULL
                    501:                }
                    502:        },
                    503:        { OLETTER_NONE, &follow_optname,
                    504:                BOOL, FOLLOW_DESC, &follow_mode, NULL,
                    505:                {
                    506:                        "F command follows file descriptor",
                    507:                        "F command follows file name",
                    508:                        NULL
                    509:                }
                    510:        },
1.1.1.4 ! shadchin  511:        { OLETTER_NONE, &use_backslash_optname,
        !           512:                BOOL, OPT_OFF, &opt_use_backslash, NULL,
        !           513:                {
        !           514:                        "Use backslash escaping in command line parameters",
        !           515:                        "Don't use backslash escaping in command line parameters",
        !           516:                        NULL
        !           517:                }
        !           518:        },
1.1.1.2   millert   519:        { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } }
1.1       etheisen  520: };
                    521:
                    522:
                    523: /*
                    524:  * Initialize each option to its default value.
                    525:  */
                    526:        public void
                    527: init_option()
                    528: {
1.1.1.2   millert   529:        register struct loption *o;
1.1.1.3   shadchin  530:        char *p;
                    531:
                    532:        p = lgetenv("LESS_IS_MORE");
                    533:        if (p != NULL && *p != '\0')
                    534:                less_is_more = 1;
1.1       etheisen  535:
                    536:        for (o = option;  o->oletter != '\0';  o++)
                    537:        {
                    538:                /*
1.1.1.4 ! shadchin  539:                 * Replace less's -d option if invoked as more
        !           540:                 */
        !           541:                if (less_is_more && o->oletter == 'd')
        !           542:                {
        !           543:                        o->onames = NULL;
        !           544:                        o->otype = BOOL;
        !           545:                        o->odefault = OPT_OFF;
        !           546:                        o->ovar = &be_helpful;
        !           547:                        o->ofunc = NULL;
        !           548:                        o->odesc[0] = "Be less helpful in prompts";
        !           549:                        o->odesc[1] = "Be helpful in prompts";
        !           550:                        o->odesc[2] = NULL;
        !           551:                }
        !           552:
        !           553:                /*
1.1       etheisen  554:                 * Set each variable to its default.
                    555:                 */
                    556:                if (o->ovar != NULL)
                    557:                        *(o->ovar) = o->odefault;
1.1.1.2   millert   558:                if (o->otype & INIT_HANDLER)
                    559:                        (*(o->ofunc))(INIT, (char *) NULL);
1.1       etheisen  560:        }
                    561: }
                    562:
                    563: /*
1.1.1.2   millert   564:  * Find an option in the option table, given its option letter.
1.1       etheisen  565:  */
1.1.1.2   millert   566:        public struct loption *
1.1       etheisen  567: findopt(c)
                    568:        int c;
                    569: {
1.1.1.2   millert   570:        register struct loption *o;
1.1       etheisen  571:
                    572:        for (o = option;  o->oletter != '\0';  o++)
                    573:        {
                    574:                if (o->oletter == c)
                    575:                        return (o);
1.1.1.3   shadchin  576:                if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c)
1.1       etheisen  577:                        return (o);
                    578:        }
                    579:        return (NULL);
1.1.1.2   millert   580: }
                    581:
                    582: /*
                    583:  *
                    584:  */
                    585:        static int
                    586: is_optchar(c)
                    587:        char c;
                    588: {
1.1.1.3   shadchin  589:        if (ASCII_IS_UPPER(c))
1.1.1.2   millert   590:                return 1;
1.1.1.3   shadchin  591:        if (ASCII_IS_LOWER(c))
1.1.1.2   millert   592:                return 1;
                    593:        if (c == '-')
                    594:                return 1;
                    595:        return 0;
                    596: }
                    597:
1.1.1.4 ! shadchin  598: #if GNU_OPTIONS
1.1.1.2   millert   599: /*
                    600:  * Find an option in the option table, given its option name.
                    601:  * p_optname is the (possibly partial) name to look for, and
                    602:  * is updated to point after the matched name.
                    603:  * p_oname if non-NULL is set to point to the full option name.
                    604:  */
                    605:        public struct loption *
                    606: findopt_name(p_optname, p_oname, p_err)
                    607:        char **p_optname;
                    608:        char **p_oname;
                    609:        int *p_err;
                    610: {
                    611:        char *optname = *p_optname;
                    612:        register struct loption *o;
                    613:        register struct optname *oname;
                    614:        register int len;
                    615:        int uppercase;
                    616:        struct loption *maxo = NULL;
                    617:        struct optname *maxoname = NULL;
                    618:        int maxlen = 0;
                    619:        int ambig = 0;
                    620:        int exact = 0;
                    621:
                    622:        /*
                    623:         * Check all options.
                    624:         */
                    625:        for (o = option;  o->oletter != '\0';  o++)
                    626:        {
                    627:                /*
                    628:                 * Check all names for this option.
                    629:                 */
                    630:                for (oname = o->onames;  oname != NULL;  oname = oname->onext)
                    631:                {
                    632:                        /*
                    633:                         * Try normal match first (uppercase == 0),
                    634:                         * then, then if it's a TRIPLE option,
                    635:                         * try uppercase match (uppercase == 1).
                    636:                         */
                    637:                        for (uppercase = 0;  uppercase <= 1;  uppercase++)
                    638:                        {
                    639:                                len = sprefix(optname, oname->oname, uppercase);
                    640:                                if (len <= 0 || is_optchar(optname[len]))
                    641:                                {
                    642:                                        /*
                    643:                                         * We didn't use all of the option name.
                    644:                                         */
                    645:                                        continue;
                    646:                                }
                    647:                                if (!exact && len == maxlen)
                    648:                                        /*
                    649:                                         * Already had a partial match,
                    650:                                         * and now there's another one that
                    651:                                         * matches the same length.
                    652:                                         */
                    653:                                        ambig = 1;
                    654:                                else if (len > maxlen)
                    655:                                {
                    656:                                        /*
                    657:                                         * Found a better match than
                    658:                                         * the one we had.
                    659:                                         */
                    660:                                        maxo = o;
                    661:                                        maxoname = oname;
                    662:                                        maxlen = len;
                    663:                                        ambig = 0;
                    664:                                        exact = (len == (int)strlen(oname->oname));
                    665:                                }
                    666:                                if (!(o->otype & TRIPLE))
                    667:                                        break;
                    668:                        }
                    669:                }
                    670:        }
                    671:        if (ambig)
                    672:        {
                    673:                /*
                    674:                 * Name matched more than one option.
                    675:                 */
                    676:                if (p_err != NULL)
                    677:                        *p_err = OPT_AMBIG;
                    678:                return (NULL);
                    679:        }
                    680:        *p_optname = optname + maxlen;
                    681:        if (p_oname != NULL)
                    682:                *p_oname = maxoname == NULL ? NULL : maxoname->oname;
                    683:        return (maxo);
1.1       etheisen  684: }
1.1.1.4 ! shadchin  685: #endif