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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <fset.h>
include <finfo.h>
include <error.h>
include "../help.h"
include "xhelp.h"
# XH_HELP -- Get the requested help topic and send the result to the GUI.
procedure xh_help (xh, topic, curpack, opt)
pointer xh #i task struct pointer
char topic[ARB] #i help topic
char curpack[ARB] #i current package
char opt[ARB] #i help option
pointer helpstr
int ip, fdi
long fsize
char ch, fname[SZ_FNAME], err[SZ_LINE]
long fstatl()
char getc()
int open()
bool strne()
begin
# Get a temp file name.
call mktemp ("tmp$xhelpi", fname, SZ_FNAME)
# Open a temp file with the help information found.
fdi = open (fname, NEW_FILE, TEXT_FILE)
call xh_get_help (fdi, topic, curpack, "", HF_HTML, HELPDB(xh),
"all", opt)
call close (fdi)
# Open the results file for reading.
fdi = open (fname, READ_ONLY, TEXT_FILE)
fsize = fstatl (fdi, F_FILESIZE)
# If no results try using the topic name as a curpack param.
if (fsize == 0) {
call close (fdi) # clean up from before
call delete (fname)
# Open a temp file with the help information found.
fdi = open (fname, NEW_FILE, TEXT_FILE)
call xh_get_help (fdi, topic, topic, "", HF_HTML, HELPDB(xh),
"all", opt)
call close (fdi)
# Open the results file for reading.
fdi = open (fname, READ_ONLY, TEXT_FILE)
fsize = fstatl (fdi, F_FILESIZE)
# If we still have nothing then punt...
if (fsize == 0 && topic[1] != EOS) {
if (strne (opt, "help")) {
call sprintf (err, SZ_LINE,
"No '%s' option help available\n for `%s'.")
call pargstr (opt)
call pargstr (topic)
} else {
call sprintf (err, SZ_LINE, "No help available for\n`%s'.")
call pargstr (topic)
}
call gmsg (XH_GP(xh), "alert", err)
call close (fdi)
call delete (fname)
return
}
}
# Now filter the file to escape the curly braces so they pass thru
# to the Tcl cleanly. Put the result in the string sent to the GUI.
call calloc (helpstr, fsize + SZ_LINE, TY_CHAR)
ip = helpstr
repeat {
ch = getc (fdi, ch)
if (ch == '{' || ch == '}') {
Memc[ip] = '\\'
ip = ip + 1
}
Memc[ip] = ch
ip = ip + 1
} until (ch == EOF)
Memc[ip-1] = EOS
# Clean up.
call close (fdi)
call delete (fname)
# Send the help text to the GUI who will display it.
call gmsg (XH_GP(xh), "helpres", Memc[helpstr])
call mfree (helpstr, TY_CHAR)
end
# XH_GET_HELP -- The main work procedure, i.e. a rip-off of the t_help()
# procedure. Decode the option string, set up the control structure, and
# finally call process_template to expand the module template and process
# the help text for each module. The output is written to a temp file
# opened by the calling procedure which may optionally sort it or display
# it as is.
procedure xh_get_help (fd, topic, curpack, file, format, helpdb, section, opt)
int fd #i file descriptor of result
char topic[ARB] #i topic
char curpack[ARB] #i current package
char file[ARB] #i file template
int format #i output format (text|html|ps)
char helpdb[ARB] #i help database
char section[ARB] #i section on which to get help
char opt[ARB] #i type of help
int list
long fi[LEN_FINFO], db_ctime
pointer sp, ctrl, optn, db, fname
long clktime()
pointer hdb_open()
bool strne(), streq()
int stridxs(), finfo(), fntopnb(), fntgfnb(), get_option()
errchk hdb_open
data db_ctime /0/
define forms_ 91
begin
call smark (sp)
call salloc (ctrl, LEN_CTRLSTRUCT, TY_STRUCT)
call salloc (optn, SZ_FNAME, TY_CHAR)
call salloc (fname, SZ_PATHNAME, TY_CHAR)
# If we were called without any arguments, do not query for the
# template, just set it to null and help will be given for the
# current package.
call aclri (Memi[ctrl], LEN_CTRLSTRUCT)
if (topic[1] == EOS) {
if (file[1] == EOS) {
H_OPTION(ctrl) = O_MENU
H_TEMPLATE(ctrl) = EOS
H_PARNAME(ctrl) = EOS
H_SECNAME(ctrl) = EOS
} else
call strcpy (file, H_TEMPLATE(ctrl), SZ_LINE)
} else {
call strcpy (topic, H_TEMPLATE(ctrl), SZ_LINE)
}
# Check to see if any of the files in the list are newer than the
# time of the last hdb_open. The first time the process runs we open
# and read in the database. The database remains in memory between
# calls to HELP, provided the process does not shutdown, provided
# the name of the database to be used does not change, and provided
# a new help database is not created.
if (db_ctime > 0) {
list = fntopnb (helpdb, YES)
while (fntgfnb (list, Memc[fname], SZ_PATHNAME) != EOF) {
if (finfo (Memc[fname], fi) != ERR) {
if (db != NULL && FI_CTIME(fi) > db_ctime) {
call hdb_close (db)
db = NULL
break
}
}
}
call fntclsb (list)
} else
db = NULL
# Reopen the help database if in-core copy is out of date.
if (db == NULL) {
db = hdb_open (helpdb)
db_ctime = clktime (long(0))
}
# Fetch the value of the ALL switch. This determines whether help
# will stop after processing the first module matching the template,
# or process all modules in the database which match the template.
# Explicit use of a pattern matching character anywhere in the template
# enable allmodoules.
if (stridxs ("*?[],", H_TEMPLATE(ctrl)) > 0)
H_ALLMODULES(ctrl) = YES
else
H_ALLMODULES(ctrl) = NO
# If the FILTER_INPUT flag is set, only part of the input text will be
# processed. Filtering is only done if printing a single section or
# parameter.
H_FILTER_INPUT(ctrl) = NO
# Determine whether or not text for a single section or parameter
# is to be output. If the value of one of these strings is "all",
# all sections or all parameters are to be output. If the "all"
# default is in effect, null the string as a flag to lower level
# code that all help text is to be processed.
if (H_OPTION(ctrl) == NULL) {
call strcpy (section, H_SECNAME(ctrl), SZ_SECNAME)
if (streq (H_SECNAME(ctrl), "all")) {
H_SECNAME(ctrl) = EOS
H_PARNAME(ctrl) = EOS
}
if (H_SECNAME(ctrl) != EOS || H_PARNAME(ctrl) != EOS)
H_FILTER_INPUT(ctrl) = YES
}
# Fetch and decode option string; abbreviations are permitted.
if (H_OPTION(ctrl) != O_MENU) {
call strcpy (opt, Memc[optn], SZ_FNAME)
call strlwr (Memc[optn])
iferr (H_OPTION(ctrl) = get_option (Memc[optn])) {
H_OPTION(ctrl) = O_HELP
call erract (EA_WARN)
}
}
forms_
# Pause between screens of output text only if the standard output
# is not redirected, and if enabled by the user.
H_IN(ctrl) = ERR
H_OUT(ctrl) = fd
H_NLINES(ctrl) = -1
H_STATE(ctrl) = BOF
H_EOF(ctrl) = NO
H_QUIT(ctrl) = NO
# If the standard output is not redirected, i.e., if writing to the
# terminal, determine whether or not output is to be paginated (pause
# between pages). If output is redirected, the pagination flag
# and help option controls whether or not manpage style output is
# enabled. Manpage output formatting is desirable only when formatting
# help text or printing named files.
H_RAWOUT(ctrl) = YES
H_MANPAGE(ctrl) = NO
H_PAGINATE(ctrl) = NO
H_SOFLAG(ctrl) = NO
H_FORMAT(ctrl) = format
# We don't produce output to a screen so shut off the tty.
H_TTY(ctrl) = NULL
# Set left and right margins for output text format.
H_LMARGIN(ctrl) = 1
H_RMARGIN(ctrl) = 72
# Copy the current package to the control struct.
if (strne(curpack,"Home") && strne(curpack,""))
call strcpy (curpack, H_CURPACK(ctrl), SZ_CURPACK)
# Initialization is completed, control structure is completed.
# Format and output the help text. If we have a module name template
# process the template against the help database, otherwise work
# directly out of the named files.
if (file[1] == EOS)
call do_module_template (db, H_TEMPLATE(ctrl), ctrl)
else
call do_file_template (H_TEMPLATE(ctrl), ctrl)
call sfree (sp)
end
|