| 1 |
/************************************************************************** |
| 2 |
* This program is Copyright (C) 1986-2002 by Jonathan Payne. JOVE is * |
| 3 |
* provided by Jonathan and Jovehacks without charge and without * |
| 4 |
* warranty. You may copy, modify, and/or distribute JOVE, provided that * |
| 5 |
* this notice is included in all the source files and documentation. * |
| 6 |
**************************************************************************/ |
| 7 |
|
| 8 |
#include "jove.h" |
| 9 |
#include "jctype.h" |
| 10 |
#include "extend.h" |
| 11 |
#include "macros.h" |
| 12 |
#include "mouse.h" |
| 13 |
|
| 14 |
/* included for command routine declarationss */ |
| 15 |
#include "abbrev.h" |
| 16 |
#include "c.h" |
| 17 |
#include "case.h" |
| 18 |
#include "commands.h" |
| 19 |
#include "delete.h" |
| 20 |
#include "disp.h" |
| 21 |
#include "fmt.h" |
| 22 |
#include "insert.h" |
| 23 |
#include "iproc.h" |
| 24 |
#include "marks.h" |
| 25 |
#include "misc.h" |
| 26 |
#include "move.h" |
| 27 |
#include "para.h" |
| 28 |
#include "proc.h" |
| 29 |
#include "reapp.h" |
| 30 |
#include "wind.h" |
| 31 |
|
| 32 |
#define PROC(p) (p) |
| 33 |
#include "commands.tab" |
| 34 |
|
| 35 |
const data_obj *LastCmd; |
| 36 |
const char *ProcFmt = ": %f "; |
| 37 |
|
| 38 |
const data_obj * |
| 39 |
findcom(const char *prompt) |
| 40 |
{ |
| 41 |
if (InJoverc) { |
| 42 |
/* For faster rc file processing on startup, read until a space |
| 43 |
* or a tab or a newline character is reached, and then do a |
| 44 |
* semi-indexedlookup on that string. This should be much faster |
| 45 |
* than minibuffer completion for each line. |
| 46 |
*/ |
| 47 |
char cmdbuf[128], |
| 48 |
*cp = cmdbuf; |
| 49 |
const struct cmd *cmd, |
| 50 |
*which = NULL; |
| 51 |
ZXchar c; |
| 52 |
size_t cmdlen; |
| 53 |
int ic; |
| 54 |
|
| 55 |
#ifdef MAC |
| 56 |
/* ??? Is this necessary? The input is comming from a file! */ |
| 57 |
menus_off(); /* Block menu choices during input */ |
| 58 |
#endif |
| 59 |
/* gather the cmd name */ |
| 60 |
while (jisprint(c = getch()) && c != ' ') { |
| 61 |
*cp++ = CharDowncase(c); |
| 62 |
if (cp == &cmdbuf[sizeof(cmdbuf)]) { |
| 63 |
complain("command too long"); |
| 64 |
/* NOTREACHED */ |
| 65 |
} |
| 66 |
} |
| 67 |
*cp = '\0'; |
| 68 |
cmdlen = cp - cmdbuf; |
| 69 |
|
| 70 |
jdbg("findcom lookup \"%s\"\n", cmdbuf); |
| 71 |
/* look it up (in the reduced search space) */ |
| 72 |
c = ZXC(cmdbuf[0]); |
| 73 |
ic = IDX(c); |
| 74 |
if (ic >= 0 && ic <= IDXSZ |
| 75 |
&& (cmd = cmdidx[ic]) != NULL) { |
| 76 |
for (; cmd->Name != NULL && cmd->Name[0] == cmdbuf[0]; cmd++) { |
| 77 |
if (strncmp(cmd->Name, cmdbuf, cmdlen) == 0) { |
| 78 |
if (cmd->Name[cmdlen] == '\0') |
| 79 |
return (data_obj *) cmd; |
| 80 |
|
| 81 |
if (which != NULL) { |
| 82 |
complain("[cmd \"%s\" ambiguous]", cmdbuf); |
| 83 |
/* NOTREACHED */ |
| 84 |
} |
| 85 |
which = cmd; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
if (which == NULL) { |
| 90 |
complain("[\"%s\" unknown]", cmdbuf); |
| 91 |
/* NOTREACHED */ |
| 92 |
} |
| 93 |
return (data_obj *) which; |
| 94 |
} else { |
| 95 |
static const char *strings[elemsof(commands)]; |
| 96 |
static int last = -1; |
| 97 |
|
| 98 |
if (strings[0] == NULL) { |
| 99 |
const char **strs = strings; |
| 100 |
const struct cmd *c = commands; |
| 101 |
|
| 102 |
do {} while ((*strs++ = (*c++).Name) != NULL); |
| 103 |
} |
| 104 |
last = complete(strings, last >= 0? strings[last] : (char *)NULL, |
| 105 |
prompt, CASEIND | ALLOW_OLD); |
| 106 |
return (data_obj *) &commands[last]; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
const struct cmd * |
| 111 |
FindCmd(cmdproc_t proc) |
| 112 |
{ |
| 113 |
const struct cmd *cp; |
| 114 |
|
| 115 |
for (cp = commands; cp->Name; cp++) |
| 116 |
if (cp->c_proc == proc) |
| 117 |
return cp; |
| 118 |
return NULL; |
| 119 |
} |
| 120 |
|
| 121 |
void |
| 122 |
ExecCmd(const data_obj *cp) |
| 123 |
{ |
| 124 |
LastCmd = cp; |
| 125 |
jdprintf("ExecCmd \"%s\" 0x%x\n", cp->Name?cp->Name:"(NULL)", cp->Type); |
| 126 |
if (cp->Type & MAJOR_MODE) { |
| 127 |
SetMajor((cp->Type >> MAJOR_SHIFT)); |
| 128 |
} else if (cp->Type & MINOR_MODE) { |
| 129 |
TogMinor((cp->Type >> MAJOR_SHIFT)); |
| 130 |
} else switch (cp->Type&TYPEMASK) { |
| 131 |
case MACRO: |
| 132 |
do_macro((struct macro *) cp); |
| 133 |
break; |
| 134 |
|
| 135 |
case COMMAND: |
| 136 |
{ |
| 137 |
struct cmd *cmd = (struct cmd *) cp; |
| 138 |
|
| 139 |
if (cmd->c_proc != NULL) { |
| 140 |
if ((cmd->Type & MODIFIER) |
| 141 |
&& BufMinorMode(curbuf, BReadOnly)) |
| 142 |
{ |
| 143 |
rbell(); |
| 144 |
message("[Buffer is read-only]"); |
| 145 |
} else { |
| 146 |
(*cmd->c_proc)(); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
break; |
| 151 |
} |
| 152 |
} |