-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.c
294 lines (283 loc) · 6.76 KB
/
help.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
*
* This file is part of ED.
*
* ED is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation.
*
* ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with ED
* (see the file COPYING). If not, write to the Free Software Foundation, 675
* Mass Ave, Cambridge, MA 02139, USA.
*/
#include "opsys.h"
#include <stdio.h>
#include <string.h>
#include "memory.h"
#include "ctyp_dec.h"
#include "rec.h"
#include "window.h"
#include "ed_dec.h"
#include "library.h"
static topic_ptr base = NULL;
extern Char *exefile();
extern Char *filename();
/******************************************************************************\
|Routine: help_disp
|Callby: help
|Purpose: Displays help text.
|Arguments:
| cur is the topic containing the text to be displayed.
\******************************************************************************/
void help_disp(cur)
topic_ptr cur;
{
Int i;
Char *p,*q;
Schar key;
next();
putz(cur->topic);
next();
i = 3;
p = (char *)cur->text;
while((q = strchr(p,'\n')))
{
*q = '\0';
putz(p);
next();
*q = '\n';
if(!*(p = ++q))
return;
if(++i >= NROW)
{
reverse();
putz(" ==<space> to continue,b to back up,q to quit==> ");
normal();
get_next_key(&key);
cr();
ers_end();
if(tolower(key) == 'q' || key == 3 || key == 25) /* emulate more quit command */
return;
if(tolower(key) == 'b') /* emulate more backup command */
{
q = p;
for(i = NROW * 5 / 3;i--;)
{
if(q == (Char *)cur->text)
break;
q--;
while(*--q != '\n')
if(q == (Char *)cur->text)
break;
if(q == (Char *)cur->text)
break;
q++;
}
p = q;
}
i = 1;
}
}
}
/******************************************************************************\
|Routine: help_keywords
|Callby: help
|Purpose: Displays the keywords of additional topics that are available.
|Arguments:
| cur is the topic for which additional subtopics might be displayed.
\******************************************************************************/
void help_keywords(cur)
topic_ptr cur;
{
Char buf[512],*p;
Int col,i,l,size;
subtopic_ptr scan;
col = 0;
for(scan = cur->first;scan != 0;scan = scan->next)
{
if(!col)
{
putz("Additional information available:");
next();
next();
}
l = strlen(scan->keyword);
if(l <= 10)
size = 12;
else
size = 24;
if(col + size >= NCOL)
{
putz(buf);
next();
col = 0;
}
sprintf(buf + col," %s",scan->keyword);
for(i = 0,p = buf + col + l + 2;i < size - (l + 2);i++)
*p++ = ' ';
*p++ = '\0';
col += size;
}
if(col != 0)
{
putz(buf);
next();
}
next();
}
/******************************************************************************\
|Routine: help
|Callby: command
|Purpose: Implements VMS-style online help.
|Arguments:
| token is a string that may contain keywords to be searched for.
\******************************************************************************/
void help(token)
Char *token;
{
FILE *fp;
Int j,k,l,ncom,hits,save_botrow;
topic_ptr cur,temp;
subtopic_ptr scan;
Char *c;
Char helpfile[512],prompt[256],buf[512],tok[128],commands[64][5],hit[128]; /* no more than 128 subtopics are allowed */
/* load the help file if it isn't already loaded */
if(!base)
{
strcpy(helpfile,exefile());
strcpy(filename(helpfile),"ed.hlp");
if(!(fp = fopen(helpfile,"r")))
{
sprintf(buf,"Unable to open the help file '%s'.",helpfile);
slip_message(buf);
wait_message();
return;
}
help_load(fp,&base);
fclose(fp);
}
if(!base)
return;
/* remove trailing whitespace */
for(c = token + strlen(token);isspace(*--c);)
if(c == token)
{
c--;
break;
}
*++c = '\0';
/* prepare for search */
marge(1,NROW);
move(NROW,1);
save_botrow = BOTROW;
BOTROW = NROW;
next();
putout();
cur = base;
if(!*token)
{
help_disp(cur); /* display help text for this node in tree */
help_keywords(cur); /* display keywords for additional info */
}
while(1)
{
if(!cur->first) /* no additional exploration possible from here, pop up in tree */
{
cur = cur->parent;
continue;
}
if(!*token) /* if no more input is in the buffer, ask for more */
{
c = prompt + (sizeof(prompt) - sizeof("subtopic? ") - 1); /* build the prompt string backwards */
strcpy(c,"subtopic? ");
for(temp = cur;temp;temp = temp->parent)
{
*--c = ' ';
l = strlen(temp->topic);
c -= l;
memcpy(c,temp->topic,l);
}
l = inquire(c,buf,sizeof(buf),1); /* get user keyword prompt response */
token = buf;
}
/* parse the next token from whichever input */
while(isspace(*token))
token++;
c = tok;
while(!isspace(*token) && *token)
*c++ = *token++;
*c = '\0';
l = c - tok;
while(isspace(*token)) /* this is so we can decide whether to display help yet below */
token++;
/* no input means pop up or out */
if(!l)
{
if(!(cur = cur->parent)) /* he hits return, go up in tree or exit if at root */
{
marge(TOPROW,BOTROW = save_botrow);
ref_display();
return;
}
continue;
}
/* redisplay keywords if they enter ? */
c = tok; /* this is expected in the keyword comparisons below */
if(*c == '?')
{
help_keywords(cur); /* display keywords for additional info */
continue;
}
/* load all the keywords at this level into the array */
for(ncom = 0,scan = cur->first;scan != 0;scan = scan->next)
{
memcpy(commands[ncom],scan->keyword,4);
commands[ncom++][4] = '\0';
}
memset(hit,1,ncom);
for(j = 0;j < 4;j++) /* examine four columns in command array */
{
for(k = 0;k < ncom;k++) /* knock out mismatches */
if(tolower(commands[k][j]) != tolower(*c))
hit[k] = 0;
for(hits = k = 0;k < ncom;k++) /* count remaining matches */
hits += hit[k];
if(!hits)
{
sprintf(buf,"'%s' doesn't match any of the choices.",tok);
putz(buf);
next();
next();
help_keywords(cur);
*token = '\0';
break;
}
else if(hits == 1)
{
for(scan = cur->first,c = hit;!*c++;scan = scan->next); /* find the entry for their keyword */
cur = scan->child;
if(!*token)
{
help_disp(cur); /* display help text for this node in tree */
help_keywords(cur); /* display keywords for additional info */
}
break;
}
c++;
if(!*c || isspace(*c))
{
sprintf(buf,"'%s' is ambiguous, please supply more characters.",tok);
putz(buf);
next();
next();
help_keywords(cur);
*token = '\0';
break;
}
}
}
}