home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / less-321-src.tgz / tar.out / fsf / less / decode.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  15KB  |  712 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.  * Routines to decode user commands.
  30.  *
  31.  * This is all table driven.
  32.  * A command table is a sequence of command descriptors.
  33.  * Each command descriptor is a sequence of bytes with the following format:
  34.  *    <c1><c2>...<cN><0><action>
  35.  * The characters c1,c2,...,cN are the command string; that is,
  36.  * the characters which the user must type.
  37.  * It is terminated by a null <0> byte.
  38.  * The byte after the null byte is the action code associated
  39.  * with the command string.
  40.  * If an action byte is OR-ed with A_EXTRA, this indicates
  41.  * that the option byte is followed by an extra string.
  42.  *
  43.  * There may be many command tables.
  44.  * The first (default) table is built-in.
  45.  * Other tables are read in from "lesskey" files.
  46.  * All the tables are linked together and are searched in order.
  47.  */
  48.  
  49. #include "less.h"
  50. #include "cmd.h"
  51. #include "lesskey.h"
  52.  
  53. extern int erase_char, kill_char;
  54. extern int secure;
  55.  
  56. /*
  57.  * Command table is ordered roughly according to expected
  58.  * frequency of use, so the common commands are near the beginning.
  59.  */
  60. static unsigned char cmdtable[] =
  61. {
  62.     '\r',0,                A_F_LINE,
  63.     '\n',0,                A_F_LINE,
  64.     'e',0,                A_F_LINE,
  65.     'j',0,                A_F_LINE,
  66.     CONTROL('E'),0,            A_F_LINE,
  67.     CONTROL('N'),0,            A_F_LINE,
  68.     'k',0,                A_B_LINE,
  69.     'y',0,                A_B_LINE,
  70.     CONTROL('Y'),0,            A_B_LINE,
  71.     CONTROL('K'),0,            A_B_LINE,
  72.     CONTROL('P'),0,            A_B_LINE,
  73.     'J',0,                A_FF_LINE,
  74.     'K',0,                A_BF_LINE,
  75.     'Y',0,                A_BF_LINE,
  76.     'd',0,                A_F_SCROLL,
  77.     CONTROL('D'),0,            A_F_SCROLL,
  78.     'u',0,                A_B_SCROLL,
  79.     CONTROL('U'),0,            A_B_SCROLL,
  80.     ' ',0,                A_F_SCREEN,
  81.     'f',0,                A_F_SCREEN,
  82.     CONTROL('F'),0,            A_F_SCREEN,
  83.     CONTROL('V'),0,            A_F_SCREEN,
  84.     'b',0,                A_B_SCREEN,
  85.     CONTROL('B'),0,            A_B_SCREEN,
  86.     ESC,'v',0,            A_B_SCREEN,
  87.     'z',0,                A_F_WINDOW,
  88.     'w',0,                A_B_WINDOW,
  89.     ESC,' ',0,            A_FF_SCREEN,
  90.     'F',0,                A_F_FOREVER,
  91.     'R',0,                A_FREPAINT,
  92.     'r',0,                A_REPAINT,
  93.     CONTROL('R'),0,            A_REPAINT,
  94.     CONTROL('L'),0,            A_REPAINT,
  95.     ESC,'u',0,            A_UNDO_SEARCH,
  96.     'g',0,                A_GOLINE,
  97.     '<',0,                A_GOLINE,
  98.     ESC,'<',0,            A_GOLINE,
  99.     'p',0,                A_PERCENT,
  100.     '%',0,                A_PERCENT,
  101.     ESC,'[',0,            A_LSHIFT,
  102.     ESC,']',0,            A_RSHIFT,
  103.     '{',0,                A_F_BRACKET|A_EXTRA,    '{','}',0,
  104.     '}',0,                A_B_BRACKET|A_EXTRA,    '{','}',0,
  105.     '(',0,                A_F_BRACKET|A_EXTRA,    '(',')',0,
  106.     ')',0,                A_B_BRACKET|A_EXTRA,    '(',')',0,
  107.     '[',0,                A_F_BRACKET|A_EXTRA,    '[',']',0,
  108.     ']',0,                A_B_BRACKET|A_EXTRA,    '[',']',0,
  109.     ESC,CONTROL('F'),0,        A_F_BRACKET,
  110.     ESC,CONTROL('B'),0,        A_B_BRACKET,
  111.     'G',0,                A_GOEND,
  112.     ESC,'>',0,            A_GOEND,
  113.     '>',0,                A_GOEND,
  114.     'P',0,                A_GOPOS,
  115.  
  116.     '0',0,                A_DIGIT,
  117.     '1',0,                A_DIGIT,
  118.     '2',0,                A_DIGIT,
  119.     '3',0,                A_DIGIT,
  120.     '4',0,                A_DIGIT,
  121.     '5',0,                A_DIGIT,
  122.     '6',0,                A_DIGIT,
  123.     '7',0,                A_DIGIT,
  124.     '8',0,                A_DIGIT,
  125.     '9',0,                A_DIGIT,
  126.  
  127.     '=',0,                A_STAT,
  128.     CONTROL('G'),0,            A_STAT,
  129.     ':','f',0,            A_STAT,
  130.     '/',0,                A_F_SEARCH,
  131.     '?',0,                A_B_SEARCH,
  132.     ESC,'/',0,            A_F_SEARCH|A_EXTRA,    '*',0,
  133.     ESC,'?',0,            A_B_SEARCH|A_EXTRA,    '*',0,
  134.     'n',0,                A_AGAIN_SEARCH,
  135.     ESC,'n',0,            A_T_AGAIN_SEARCH,
  136.     'N',0,                A_REVERSE_SEARCH,
  137.     ESC,'N',0,            A_T_REVERSE_SEARCH,
  138.     'm',0,                A_SETMARK,
  139.     '\'',0,                A_GOMARK,
  140.     CONTROL('X'),CONTROL('X'),0,    A_GOMARK,
  141.     'E',0,                A_EXAMINE,
  142.     ':','e',0,            A_EXAMINE,
  143.     CONTROL('X'),CONTROL('V'),0,    A_EXAMINE,
  144.     ':','n',0,            A_NEXT_FILE,
  145.     ':','p',0,            A_PREV_FILE,
  146.     ':','x',0,            A_INDEX_FILE,
  147.     '-',0,                A_OPT_TOGGLE,
  148.     ':','t',0,            A_OPT_TOGGLE|A_EXTRA,    't',0,
  149.     's',0,                A_OPT_TOGGLE|A_EXTRA,    'o',0,
  150.     '_',0,                A_DISP_OPTION,
  151.     '|',0,                A_PIPE,
  152.     'v',0,                A_VISUAL,
  153.     '!',0,                A_SHELL,
  154.     '+',0,                A_FIRSTCMD,
  155.  
  156.     'H',0,                A_HELP,
  157.     'h',0,                A_HELP,
  158.     'V',0,                A_VERSION,
  159.     'q',0,                A_QUIT,
  160.     'Q',0,                A_QUIT,
  161.     ':','q',0,            A_QUIT,
  162.     ':','Q',0,            A_QUIT,
  163.     'Z','Z',0,            A_QUIT
  164. };
  165.  
  166. static unsigned char edittable[] =
  167. {
  168.     '\t',0,                EC_F_COMPLETE,    /* TAB */
  169.     '\17',0,        EC_B_COMPLETE,    /* BACKTAB */
  170.     '\14',0,        EC_EXPAND,    /* CTRL-L */
  171.     CONTROL('V'),0,        EC_LITERAL,    /* BACKSLASH */
  172.     CONTROL('A'),0,        EC_LITERAL,    /* BACKSLASH */
  173.        ESC,'l',0,        EC_RIGHT,    /* ESC l */
  174.     ESC,'h',0,        EC_LEFT,    /* ESC h */
  175.     ESC,'b',0,        EC_W_LEFT,    /* ESC b */
  176.     ESC,'w',0,        EC_W_RIGHT,    /* ESC w */
  177.     ESC,'i',0,        EC_INSERT,    /* ESC i */
  178.     ESC,'x',0,        EC_DELETE,    /* ESC x */
  179.     ESC,'X',0,        EC_W_DELETE,    /* ESC X */
  180.     ESC,'\b',0,        EC_W_BACKSPACE,    /* ESC BACKSPACE */
  181.     ESC,'0',0,        EC_HOME,    /* ESC 0 */
  182.     ESC,'$',0,        EC_END,        /* ESC $ */
  183.     ESC,'k',0,        EC_UP,        /* ESC k */
  184.     ESC,'j',0,        EC_DOWN,    /* ESC j */
  185.     ESC,'\t',0,        EC_B_COMPLETE    /* ESC TAB */
  186. };
  187.  
  188. /*
  189.  * Structure to support a list of command tables.
  190.  */
  191. struct tablelist
  192. {
  193.     struct tablelist *t_next;
  194.     char *t_start;
  195.     char *t_end;
  196. };
  197.  
  198. /*
  199.  * List of command tables and list of line-edit tables.
  200.  */
  201. static struct tablelist *list_fcmd_tables = NULL;
  202. static struct tablelist *list_ecmd_tables = NULL;
  203. static struct tablelist *list_var_tables = NULL;
  204.  
  205.  
  206. /*
  207.  * Initialize the command lists.
  208.  */
  209.     public void
  210. init_cmds()
  211. {
  212.     /*
  213.      * Add the default command tables.
  214.      */
  215.     add_fcmd_table((char*)cmdtable, sizeof(cmdtable));
  216.     add_ecmd_table((char*)edittable, sizeof(edittable));
  217.     get_editkeys();
  218. #if USERFILE
  219.     /*
  220.      * Try to add the tables in the standard lesskey file "$HOME/.less".
  221.      */
  222.     add_hometable();
  223. #endif
  224. }
  225.  
  226. /*
  227.  * 
  228.  */
  229.     static int
  230. add_cmd_table(tlist, buf, len)
  231.     struct tablelist **tlist;
  232.     char *buf;
  233.     int len;
  234. {
  235.     register struct tablelist *t;
  236.  
  237.     if (len == 0)
  238.         return (0);
  239.     /*
  240.      * Allocate a tablelist structure, initialize it, 
  241.      * and link it into the list of tables.
  242.      */
  243.     if ((t = (struct tablelist *) 
  244.             calloc(1, sizeof(struct tablelist))) == NULL)
  245.     {
  246.         return (-1);
  247.     }
  248.     t->t_start = buf;
  249.     t->t_end = buf + len;
  250.     t->t_next = *tlist;
  251.     *tlist = t;
  252.     return (0);
  253. }
  254.  
  255. /*
  256.  * Add a command table.
  257.  */
  258.     public void
  259. add_fcmd_table(buf, len)
  260.     char *buf;
  261.     int len;
  262. {
  263.     if (add_cmd_table(&list_fcmd_tables, buf, len) < 0)
  264.         error("Warning: some commands disabled", NULL_PARG);
  265. }
  266.  
  267. /*
  268.  * Add an editing command table.
  269.  */
  270.     public void
  271. add_ecmd_table(buf, len)
  272.     char *buf;
  273.     int len;
  274. {
  275.     if (add_cmd_table(&list_ecmd_tables, buf, len) < 0)
  276.         error("Warning: some edit commands disabled", NULL_PARG);
  277. }
  278.  
  279. /*
  280.  * Add an environment variable table.
  281.  */
  282.     public void
  283. add_var_table(buf, len)
  284.     char *buf;
  285.     int len;
  286. {
  287.     if (add_cmd_table(&list_var_tables, buf, len) < 0)
  288.         error("Warning: environment variables from lesskey file unavailable", NULL_PARG);
  289. }
  290.  
  291. /*
  292.  * Search a single command table for the command string in cmd.
  293.  */
  294.     public int
  295. cmd_search(cmd, table, endtable, sp)
  296.     char *cmd;
  297.     char *table;
  298.     char *endtable;
  299.     char **sp;
  300. {
  301.     register char *p;
  302.     register char *q;
  303.     register int a;
  304.  
  305.     for (p = table, q = cmd;  p < endtable;  p++, q++)
  306.     {
  307.         if (*p == *q)
  308.         {
  309.             /*
  310.              * Current characters match.
  311.              * If we're at the end of the string, we've found it.
  312.              * Return the action code, which is the character
  313.              * after the null at the end of the string
  314.              * in the command table.
  315.              */
  316.             if (*p == '\0')
  317.             {
  318.                 a = *++p & 0377;
  319.                 if (a == A_END_LIST)
  320.                 {
  321.                     /*
  322.                      * We get here only if the original
  323.                      * cmd string passed in was empty ("").
  324.                      * I don't think that can happen,
  325.                      * but just in case ...
  326.                      */
  327.                     return (A_UINVALID);
  328.                 }
  329.                 /*
  330.                  * Check for an "extra" string.
  331.                  */
  332.                 if (a & A_EXTRA)
  333.                 {
  334.                     *sp = ++p;
  335.                     a &= ~A_EXTRA;
  336.                 } else
  337.                     *sp = NULL;
  338.                 return (a);
  339.             }
  340.         } else if (*q == '\0')
  341.         {
  342.             /*
  343.              * Hit the end of the user's command,
  344.              * but not the end of the string in the command table.
  345.              * The user's command is incomplete.
  346.              */
  347.             return (A_PREFIX);
  348.         } else
  349.         {
  350.             /*
  351.              * Not a match.
  352.              * Skip ahead to the next command in the
  353.              * command table, and reset the pointer
  354.              * to the beginning of the user's command.
  355.              */
  356.             if (*p == '\0' && p[1] == A_END_LIST)
  357.             {
  358.                 /*
  359.                  * A_END_LIST is a special marker that tells 
  360.                  * us to abort the cmd search.
  361.                  */
  362.                 return (A_UINVALID);
  363.             }
  364.             while (*p++ != '\0') ;
  365.             if (*p & A_EXTRA)
  366.                 while (*++p != '\0') ;
  367.             q = cmd-1;
  368.         }
  369.     }
  370.     /*
  371.      * No match found in the entire command table.
  372.      */
  373.     return (A_INVALID);
  374. }
  375.  
  376. /*
  377.  * Decode a command character and return the associated action.
  378.  * The "extra" string, if any, is returned in sp.
  379.  */
  380.     static int
  381. cmd_decode(tlist, cmd, sp)
  382.     struct tablelist *tlist;
  383.     char *cmd;
  384.     char **sp;
  385. {
  386.     register struct tablelist *t;
  387.     register int action = A_INVALID;
  388.  
  389.     /*
  390.      * Search thru all the command tables.
  391.      * Stop when we find an action which is not A_INVALID.
  392.      */
  393.     for (t = tlist;  t != NULL;  t = t->t_next)
  394.     {
  395.         action = cmd_search(cmd, t->t_start, t->t_end, sp);
  396.         if (action != A_INVALID)
  397.             break;
  398.     }
  399.     return (action);
  400. }
  401.  
  402. /*
  403.  * Decode a command from the cmdtables list.
  404.  */
  405.     public int
  406. fcmd_decode(cmd, sp)
  407.     char *cmd;
  408.     char **sp;
  409. {
  410.     return (cmd_decode(list_fcmd_tables, cmd, sp));
  411. }
  412.  
  413. /*
  414.  * Decode a command from the edittables list.
  415.  */
  416.     public int
  417. ecmd_decode(cmd, sp)
  418.     char *cmd;
  419.     char **sp;
  420. {
  421.     return (cmd_decode(list_ecmd_tables, cmd, sp));
  422. }
  423.  
  424. /*
  425.  * Get the value of an environment variable.
  426.  * Looks first in the lesskey file, then in the real environment.
  427.  */
  428.     public char *
  429. lgetenv(var)
  430.     char *var;
  431. {
  432.     int a;
  433.     char *s;
  434.  
  435.     a = cmd_decode(list_var_tables, var, &s);
  436.     if (a == EV_OK)
  437.         return (s);
  438.     return (getenv(var));
  439. }
  440.  
  441. #if USERFILE
  442. /*
  443.  * Get an "integer" from a lesskey file.
  444.  * Integers are stored in a funny format: 
  445.  * two bytes, low order first, in radix KRADIX.
  446.  */
  447.     static int
  448. gint(sp)
  449.     char **sp;
  450. {
  451.     int n;
  452.  
  453.     n = *(*sp)++;
  454.     n += *(*sp)++ * KRADIX;
  455.     return (n);
  456. }
  457.  
  458. /*
  459.  * Process an old (pre-v241) lesskey file.
  460.  */
  461.     static int
  462. old_lesskey(buf, len)
  463.     char *buf;
  464.     int len;
  465. {
  466.     /*
  467.      * Old-style lesskey file.
  468.      * The file must end with either 
  469.      *     ...,cmd,0,action
  470.      * or  ...,cmd,0,action|A_EXTRA,string,0
  471.      * So the last byte or the second to last byte must be zero.
  472.      */
  473.     if (buf[len-1] != '\0' && buf[len-2] != '\0')
  474.         return (-1);
  475.     add_fcmd_table(buf, len);
  476.     return (0);
  477. }
  478.  
  479. /* 
  480.  * Process a new (post-v241) lesskey file.
  481.  */
  482.     static int
  483. new_lesskey(buf, len)
  484.     char *buf;
  485.     int len;
  486. {
  487.     char *p;
  488.     register int c;
  489.     register int n;
  490.  
  491.     /*
  492.      * New-style lesskey file.
  493.      * Extract the pieces.
  494.      */
  495.     if (buf[len-3] != C0_END_LESSKEY_MAGIC ||
  496.         buf[len-2] != C1_END_LESSKEY_MAGIC ||
  497.         buf[len-1] != C2_END_LESSKEY_MAGIC)
  498.         return (-1);
  499.     p = buf + 4;
  500.     for (;;)
  501.     {
  502.         c = *p++;
  503.         switch (c)
  504.         {
  505.         case CMD_SECTION:
  506.             n = gint(&p);
  507.             add_fcmd_table(p, n);
  508.             p += n;
  509.             break;
  510.         case EDIT_SECTION:
  511.             n = gint(&p);
  512.             add_ecmd_table(p, n);
  513.             p += n;
  514.             break;
  515.         case VAR_SECTION:
  516.             n = gint(&p);
  517.             add_var_table(p, n);
  518.             p += n;
  519.             break;
  520.         case END_SECTION:
  521.             return (0);
  522.         default:
  523.             /*
  524.              * Unrecognized section type.
  525.              */
  526.             return (-1);
  527.         }
  528.     }
  529. }
  530.  
  531. /*
  532.  * Set up a user command table, based on a "lesskey" file.
  533.  */
  534.     public int
  535. lesskey(filename)
  536.     char *filename;
  537. {
  538.     register char *buf;
  539.     register POSITION len;
  540.     register long n;
  541.     register int f;
  542.  
  543.     if (secure)
  544.         return (1);
  545.     /*
  546.      * Try to open the lesskey file.
  547.      */
  548.     f = open(filename, OPEN_READ);
  549.     if (f < 0)
  550.         return (1);
  551.  
  552.     /*
  553.      * Read the file into a buffer.
  554.      * We first figure out the size of the file and allocate space for it.
  555.      * {{ Minimal error checking is done here.
  556.      *    A garbage .less file will produce strange results.
  557.      *    To avoid a large amount of error checking code here, we
  558.      *    rely on the lesskey program to generate a good .less file. }}
  559.      */
  560.     len = filesize(f);
  561.     if (len == NULL_POSITION || len < 3)
  562.     {
  563.         /*
  564.          * Bad file (valid file must have at least 3 chars).
  565.          */
  566.         close(f);
  567.         return (-1);
  568.     }
  569.     if ((buf = (char *) calloc((int)len, sizeof(char))) == NULL)
  570.     {
  571.         close(f);
  572.         return (-1);
  573.     }
  574.     if (lseek(f, (off_t)0, 0) == BAD_LSEEK)
  575.     {
  576.         free(buf);
  577.         close(f);
  578.         return (-1);
  579.     }
  580.     n = read(f, buf, (unsigned int) len);
  581.     close(f);
  582.     if (n != len)
  583.     {
  584.         free(buf);
  585.         return (-1);
  586.     }
  587.  
  588.     /*
  589.      * Figure out if this is an old-style (before version 241)
  590.      * or new-style lesskey file format.
  591.      */
  592.     if (buf[0] != C0_LESSKEY_MAGIC || buf[1] != C1_LESSKEY_MAGIC ||
  593.         buf[2] != C2_LESSKEY_MAGIC || buf[3] != C3_LESSKEY_MAGIC)
  594.         return (old_lesskey(buf, (int)len));
  595.     return (new_lesskey(buf, (int)len));
  596. }
  597.  
  598. /*
  599.  * Add the standard lesskey file "$HOME/.less"
  600.  */
  601.     public void
  602. add_hometable()
  603. {
  604.     char *filename;
  605.     PARG parg;
  606.  
  607.     if ((filename = lgetenv("LESSKEY")) == NULL)
  608.         filename = homefile(LESSKEYFILE);
  609.     if (filename == NULL)
  610.         return;
  611.     if (lesskey(filename) < 0)
  612.     {
  613.         parg.p_string = filename;
  614.         error("Cannot use lesskey file \"%s\"", &parg);
  615.     }
  616.     free(filename);
  617. }
  618. #endif
  619.  
  620. /*
  621.  * See if a char is a special line-editing command.
  622.  */
  623.     public int
  624. editchar(c, flags)
  625.     int c;
  626.     int flags;
  627. {
  628.     int action;
  629.     int nch;
  630.     char *s;
  631.     char usercmd[MAX_CMDLEN+1];
  632.     
  633.     /*
  634.      * An editing character could actually be a sequence of characters;
  635.      * for example, an escape sequence sent by pressing the uparrow key.
  636.      * To match the editing string, we use the command decoder
  637.      * but give it the edit-commands command table
  638.      * This table is constructed to match the user's keyboard.
  639.      */
  640.     if (c == erase_char)
  641.         return (EC_BACKSPACE);
  642.     if (c == kill_char)
  643.         return (EC_LINEKILL);
  644.         
  645.     /*
  646.      * Collect characters in a buffer.
  647.      * Start with the one we have, and get more if we need them.
  648.      */
  649.     nch = 0;
  650.     do {
  651.           if (nch > 0)
  652.             c = getcc();
  653.         usercmd[nch] = c;
  654.         usercmd[nch+1] = '\0';
  655.         nch++;
  656.         action = ecmd_decode(usercmd, &s);
  657.     } while (action == A_PREFIX);
  658.     
  659. #if CMD_HISTORY
  660.     if (flags & EC_NOHISTORY) 
  661.     {
  662.         /*
  663.          * The caller says there is no history list.
  664.          * Reject any history-manipulation action.
  665.          */
  666.         switch (action)
  667.         {
  668.         case EC_UP:
  669.         case EC_DOWN:
  670.             action = A_INVALID;
  671.             break;
  672.         }
  673.     }
  674. #endif
  675. #if TAB_COMPLETE_FILENAME
  676.     if (flags & EC_NOCOMPLETE) 
  677.     {
  678.         /*
  679.          * The caller says we don't want any filename completion cmds.
  680.          * Reject them.
  681.          */
  682.         switch (action)
  683.         {
  684.         case EC_F_COMPLETE:
  685.         case EC_B_COMPLETE:
  686.         case EC_EXPAND:
  687.             action = A_INVALID;
  688.             break;
  689.         }
  690.     }
  691. #endif
  692.     if ((flags & EC_PEEK) || action == A_INVALID)
  693.     {
  694.         /*
  695.          * We're just peeking, or we didn't understand the command.
  696.          * Unget all the characters we read in the loop above.
  697.          * This does NOT include the original character that was 
  698.          * passed in as a parameter.
  699.          */
  700.         while (nch > 1) 
  701.         {
  702.             ungetcc(usercmd[--nch]);
  703.         }
  704.     } else
  705.     {
  706.         if (s != NULL)
  707.             ungetsc(s);
  708.     }
  709.     return action;
  710. }
  711.  
  712.