* Copyright (c) 1988 Mark Nudleman
* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Mark Nudleman and the University of California, Berkeley. The
* name of Mark Nudleman or the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)decode.c 5.6 (Berkeley) %G%";
* Routines to decode user commands.
* This is all table driven.
* A command table is a sequence of command descriptors.
* Each command descriptor is a sequence of bytes with the following format:
* <c1><c2>...<cN><0><action>
* The characters c1,c2,...,cN are the command string; that is,
* the characters which the user must type.
* It is terminated by a null <0> byte.
* The byte after the null byte is the action code associated
* with the command string.
* The default commands are described by cmdtable.
* Command table is ordered roughly according to expected
* frequency of use, so the common commands are near the beginning.
#define CONTROL(c) ((c)&037)
static char cmdtable
[] = {
CONTROL('D'),0, A_F_SCROLL
,
CONTROL('U'),0, A_B_SCROLL
,
CONTROL('F'),0, A_F_SCREEN
,
CONTROL('B'),0, A_B_SCREEN
,
CONTROL('L'),0, A_REPAINT
,
char *cmdendtable
= cmdtable
+ sizeof(cmdtable
);
static char kbuf
[MAX_CMDLEN
+1];
* Indicate that we're not in a prefix command
* by resetting the command buffer pointer.
* Decode a command character and return the associated action.
register int action
= A_INVALID
;
* Append the new command character to the command string in kbuf.
action
= cmd_search(cmdtable
, cmdendtable
);
/* This is not a prefix character. */
* Search a command table for the current command string (in kbuf).
cmd_search(table
, endtable
)
for (p
= table
, q
= kbuf
; p
< endtable
; p
++, q
++) {
* Current characters match.
* If we're at the end of the string, we've found it.
* Return the action code, which is the character
* after the null at the end of the string
* Hit the end of the user's command,
* but not the end of the string in the command table.
* The user's command is incomplete.
* Skip ahead to the next command in the
* command table, and reset the pointer
* No match found in the entire command table.