Debian Codegraph @

vars.c

raw
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 "extend.h"
10 #include "vars.h"
11
12 /* included for variable declarations */
13 #include "abbrev.h"
14 #include "ask.h"
15 #include "c.h"
16 #include "jctype.h"
17 #include "disp.h"
18 #include "insert.h"
19 #include "iproc.h"
20 #include "mac.h"
21 #include "mouse.h"
22 #include "para.h"
23 #include "proc.h"
24 #include "re.h"
25 #include "reapp.h"
26 #include "rec.h"
27 #include "screen.h"
28 #include "term.h"
29 #include "ttystate.h"
30 #include "wind.h"
31
32 #define VAR(v) (v), sizeof(v)
33 #include "vars.tab"
34
35 const char *
36 getvar(const char *name, char *vbuf, size_t vbufsize)
37 {
38 ZXchar c;
39 const struct variable
40 *vp, *which = NULL;
41 size_t vlen = strlen(name);
42 int ic;
43
44 vbuf[0] = '\0';
45 /* look it up (in the reduced search space) */
46 c = ZXC(name[0]);
47 ic = IDX(c);
48 if (ic >= 0 && ic <= IDXSZ
49 && (vp = varidx[ic]) != NULL) {
50 for (; vp->Name != NULL && vp->Name[0] == name[0]; vp++) {
51 if (strncmp(vp->Name, name, vlen) == 0) {
52 if (vp->Name[vlen] != '\0' &&
53 which != NULL) {
54 complain("[\"%s\" ambiguous]", name);
55 /* NOTREACHED */
56 }
57 which = vp;
58 if (vp->Name[vlen] == '\0')
59 break;
60 }
61 }
62 }
63 if (which == NULL) {
64 complain("[variable \"%s\" unknown]", name);
65 /* NOTREACHED */
66 }
67 vpr_aux(vp, vbuf, vbufsize);
68 return vbuf;
69 }
70
71 const data_obj *
72 findvar(const char *prompt)
73 {
74 static const char *strings[elemsof(variables)];
75 static int last = -1;
76
77 if (strings[0] == NULL) {
78 const char **strs = strings;
79 const struct variable *v = variables;
80
81 for (; v->Name; v++)
82 *strs++ = v->Name;
83 *strs = NULL;
84 }
85
86 last = complete(strings, last >= 0? strings[last] : (char *)NULL,
87 prompt, ALLOW_OLD);
88 return (data_obj *) &variables[last];
89 }