forked from jhenin/spiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.c
191 lines (176 loc) · 3.15 KB
/
command.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* Copyright (c) 1988 Bellcore
** All Rights Reserved
** Permission is granted to copy or use this program, EXCEPT that it
** may not be sold for profit, the copyright notice must be reproduced
** on copies, and credit should be given to Bellcore where it is due.
** BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
*/
#ifndef lint
static char rcsid[]= "$Header: command.c,v 1.1 88/09/15 11:33:58 daniel Rel $";
#endif
#include "misc.h"
#include "tol.h"
#include "comment.h"
#include "command.h"
#include "strings.h"
#include "parse.h"
/*
** storage for the string that signals an embedded command
*/
static char _C_cmdword[Z_WORDLEN];
/*
** storage for the command script
*/
static int _C_nextcmd = 0;
static char *_C_cmds[_C_CMDMAX];
/*
** add a string to the command buffer
*/
void
C_addcmd(str)
char *str;
{
S_savestr(&_C_cmds[_C_nextcmd++],str);
return;
}
/*
** execute a single command
*/
static void
_C_do_a_cmd(str)
char *str;
{
/*
** place holder for the beginning of the string
*/
char *beginning = str;
S_skipspace(&str);
/*
** set the command string to allow embedded commands
*/
if (!S_wordcmp(str,"command"))
{
S_nextword(&str);
if (strlen(str) >= Z_WORDLEN)
{
Z_fatal("command word is too long");
}
S_wordcpy(_C_cmdword,str);
}
/*
** set the tolerances
*/
else if (!S_wordcmp(str,"tol"))
{
S_nextword(&str);
T_tolline(str);
}
/*
** add a comment specification
*/
else if (!S_wordcmp(str,"comment"))
{
S_nextword(&str);
if (strlen(str) >= Z_WORDLEN)
{
Z_fatal("command word is too long");
}
W_addcom(str,0);
}
else if (!S_wordcmp(str,"nestcom"))
{
S_nextword(&str);
if (strlen(str) >= Z_WORDLEN)
{
Z_fatal("command word is too long");
}
W_addcom(str,1);
}
/*
** add a literal string specification
*/
else if (!S_wordcmp(str,"literal"))
{
S_nextword(&str);
if (strlen(str) >= Z_WORDLEN)
{
Z_fatal("command word is too long");
}
W_addlit(str);
}
else if (!S_wordcmp(str,"resetcomments"))
{
W_clearcoms();
}
else if (!S_wordcmp(str,"resetliterals"))
{
W_clearlits();
}
else if (!S_wordcmp(str,"beginchar"))
{
S_nextword(&str);
W_setbolchar(*str);
}
else if (!S_wordcmp(str,"endchar"))
{
S_nextword(&str);
W_seteolchar(*str);
}
else if (!S_wordcmp(str,"addalpha"))
{
S_nextword(&str);
P_addalpha(str);
}
else if ((0 == strlen(str)) || !S_wordcmp(str,"rem")
|| ('#' == *str))
{
/* do nothing */
}
else
{
(void) sprintf(Z_err_buf,
"don't understand command %s\n",
beginning);
Z_fatal(Z_err_buf);
}
return;
}
/*
** execute the commands in the command buffer
*/
void
C_docmds()
{
int i;
for (i=0;i<_C_nextcmd;i++)
{
_C_do_a_cmd(_C_cmds[i]);
}
return;
}
/*
** disable embedded command key word recognition
*/
void
C_clear_cmd()
{
_C_cmdword[0] = '\0';
return;
}
int
C_is_cmd(char *inlin)
{
char *ptr;
/*
** see if this is a command line
** and if so, do the command right away
*/
if (('\0' != _C_cmdword[0]) && (!S_wordcmp(inlin,_C_cmdword)))
{
ptr = inlin;
S_nextword(&ptr);
_C_do_a_cmd(ptr);
return(1);
}
return(0);
}