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