* clear out some warnings by gcc 9.3.1.
[alpine.git] / pith / help.c
blobe0f3477d99c3b8fa6df1f6ba0b3e423e9a551aae
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: help.c 900 2008-01-05 01:13:26Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2006-2008 University of Washington
8 * Copyright 2013-2020 Eduardo Chappa
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include "../pith/headers.h"
20 #include "../pith/help.h"
21 #include "../pith/flag.h"
22 #include "../pith/conf.h"
23 #include "../pith/sort.h"
26 REV_MSG_S rmjoarray[RMJLEN]; /* For regular journal */
27 REV_MSG_S rmloarray[RMLLEN]; /* debug 0-4 */
28 REV_MSG_S rmhiarray[RMHLEN]; /* debug 5-9 */
29 int rmjofirst = -1, rmjolast = -1;
30 int rmlofirst = -1, rmlolast = -1;
31 int rmhifirst = -1, rmhilast = -1;
32 int rm_not_right_now;
36 HelpType
37 help_name2section(char *url, int url_len)
39 char name[256];
40 HelpType newhelp = NO_HELP;
41 struct help_texts *t;
43 snprintf(name, sizeof(name), "%.*s", (int) MIN(url_len,sizeof(name)), url);
45 for(t = h_texts; t->help_text != NO_HELP; t++)
46 if(!strucmp(t->tag, name)){
47 newhelp = t->help_text;
48 break;
51 return(newhelp);
55 char *
56 get_alpine_revision_string(char *buf, size_t nbuf)
58 char ourbuf[100], *p;
59 char *rev = NULL;
61 buf[0] = '\0';
62 ourbuf[0] = '\0';
64 /* HelpType (the type of h_revision) is assumed to be char ** */
65 if(h_revision && h_revision[0] && h_revision[0][0]){
66 strncpy(ourbuf, h_revision[0], sizeof(ourbuf)-1);
67 ourbuf[sizeof(ourbuf)-1] = '\0';
70 if(ourbuf[0]){
71 /* move to revision number */
72 for(p = ourbuf; *p && !isdigit((unsigned char) (*p)); p++)
75 if(*p)
76 rev = p;
78 if(rev){
79 /* skip to following space */
80 for(; *p && !isspace((unsigned char) (*p)); p++)
83 /* skip whitespace */
84 for(; *p && isspace((unsigned char) (*p)); p++)
87 /* skip over date to following space */
88 for(; *p && !isspace((unsigned char) (*p)); p++)
91 strncpy(buf, rev, MIN(p-rev, nbuf-1));
92 buf[MIN(p-rev,nbuf-1)] = '\0';
96 return(buf);
100 char *
101 get_alpine_revision_number(char *buf, size_t nbuf)
103 char ourbuf[100], *p;
104 char *rev = NULL;
106 buf[0] = '\0';
107 ourbuf[0] = '\0';
109 /* HelpType (the type of h_revision) is assumed to be char ** */
110 if(h_revision && h_revision[0] && h_revision[0][0]){
111 strncpy(ourbuf, h_revision[0], sizeof(ourbuf)-1);
112 ourbuf[sizeof(ourbuf)-1] = '\0';
115 if(ourbuf[0]){
116 /* move to revision number */
117 for(p = ourbuf; *p && !isdigit((unsigned char) (*p)); p++)
120 if(*p)
121 rev = p;
123 if(rev){
124 /* skip to following space */
125 for(; *p && !isspace((unsigned char) (*p)); p++)
128 strncpy(buf, rev, MIN(p-rev, nbuf-1));
129 buf[MIN(p-rev,nbuf-1)] = '\0';
133 return(buf);
137 #ifdef DEBUG
139 void
140 debugjournal_to_file(FILE *dfile)
142 int donejo, donelo, donehi, jo, lo, hi;
143 RMCat rmcat;
145 if(dfile && (rmjofirst >= 0 || rmlofirst >= 0 || rmhifirst >= 0)
146 && rmjofirst < RMJLEN && rmjolast < RMJLEN
147 && rmlofirst < RMLLEN && rmlolast < RMLLEN
148 && rmhifirst < RMHLEN && rmhilast < RMHLEN
149 && (rmjofirst < 0 || rmjolast >= 0)
150 && (rmlofirst < 0 || rmlolast >= 0)
151 && (rmhifirst < 0 || rmhilast >= 0)){
153 donejo = donehi = donelo = 0;
154 jo = rmjofirst;
155 if(jo < 0)
156 donejo = 1;
158 lo = rmlofirst;
159 if(lo < 0)
160 donelo = 1;
162 hi = rmhifirst;
163 if(hi < 0)
164 donehi = 1;
166 while(!(donejo && donelo && donehi)){
167 REV_MSG_S *pjo, *plo, *phi, *p;
169 if(!donejo)
170 pjo = &rmjoarray[jo];
171 else
172 pjo = NULL;
174 if(!donelo)
175 plo = &rmloarray[lo];
176 else
177 plo = NULL;
179 if(!donehi)
180 phi = &rmhiarray[hi];
181 else
182 phi = NULL;
184 if(pjo && (!plo || pjo->seq <= plo->seq)
185 && (!phi || pjo->seq <= phi->seq))
186 rmcat = Jo;
187 else if(plo && (!phi || plo->seq <= phi->seq))
188 rmcat = Lo;
189 else if(phi)
190 rmcat = Hi;
191 else
192 rmcat = No;
194 if(rmcat == Jo){
195 p = pjo;
196 if(jo == rmjofirst &&
197 (((rmjolast + 1) % RMJLEN) == rmjofirst) &&
198 fputs("*** Level -1 entries prior to this are deleted", dfile) == EOF)
199 break;
201 else if(rmcat == Lo){
202 p = plo;
203 if(lo == rmlofirst &&
204 (((rmlolast + 1) % RMLLEN) == rmlofirst) &&
205 fputs("*** Level 0-4 entries prior to this are deleted", dfile) == EOF)
206 break;
208 else if(rmcat == Hi){
209 p = phi;
210 if(hi == rmhifirst &&
211 (((rmhilast + 1) % RMHLEN) == rmhifirst) &&
212 fputs("*** Level 5-9 entries prior to this are deleted", dfile) == EOF)
213 break;
215 else if(rmcat == No){
216 p = NULL;
219 if(p != NULL){
220 if(p->timestamp && p->timestamp[0]
221 && (fputs(p->timestamp, dfile) == EOF
222 || fputs(": ", dfile) == EOF))
223 break;
225 if(p->message && p->message[0]
226 && (fputs(p->message, dfile) == EOF
227 || fputs("\n", dfile) == EOF))
228 break;
231 switch(rmcat){
232 case Jo:
233 if(jo == rmjolast)
234 donejo++;
235 else
236 jo = (jo + 1) % RMJLEN;
238 break;
240 case Lo:
241 if(lo == rmlolast)
242 donelo++;
243 else
244 lo = (lo + 1) % RMLLEN;
246 break;
248 case Hi:
249 if(hi == rmhilast)
250 donehi++;
251 else
252 hi = (hi + 1) % RMHLEN;
254 break;
256 default:
257 donejo++;
258 donelo++;
259 donehi++;
260 break;
266 #endif /* DEBUG */
269 /*----------------------------------------------------------------------
270 Add a message to the circular status message review buffer
272 Args: message -- The message to add
273 -----*/
274 void
275 add_review_message(char *message, int level)
277 int next_is_continuation = 0, cur_is_continuation = 0;
278 char *p, *q;
279 static unsigned long rmseq = 0L;
281 if(rm_not_right_now || !(message && *message))
282 return;
285 * Debug output can have newlines in it, so split up each newline piece
286 * by hand and make them separate messages.
288 rm_not_right_now = 1;
289 for(p = message; *p; p = (*q && !next_is_continuation) ? q+1 : q){
290 for(q = p; *q && *q != '\n' && (q-p) < RMMSGLEN; q++)
293 if(p == q)
294 continue;
296 cur_is_continuation = next_is_continuation;
298 if((q-p) == RMMSGLEN && *q && *q != '\n')
299 next_is_continuation = 1;
300 else
301 next_is_continuation = 0;
303 if(level < 0){
304 if(rmjofirst < 0){
305 rmjofirst = 0;
306 rmjolast = 0;
308 else{
309 rmjolast = (rmjolast + 1) % RMJLEN;
310 if(rmjolast == rmjofirst)
311 rmjofirst = (rmjofirst + 1) % RMJLEN;
314 rmjoarray[rmjolast].level = (short) level;
315 rmjoarray[rmjolast].seq = rmseq++;
316 rmjoarray[rmjolast].continuation = cur_is_continuation ? 1 : 0;
317 memset(rmjoarray[rmjolast].message, 0, (RMMSGLEN+1)*sizeof(char));
318 strncpy(rmjoarray[rmjolast].message, p, MIN(q-p,RMMSGLEN));
319 #ifdef DEBUG
320 memset(rmjoarray[rmjolast].timestamp, 0, (RMTIMLEN+1)*sizeof(char));
321 strncpy(rmjoarray[rmjolast].timestamp, debug_time(0,1,ps_global->signal_in_progress), RMTIMLEN);
322 #endif
324 else if(level <= 4){
325 if(rmlofirst < 0){
326 rmlofirst = 0;
327 rmlolast = 0;
329 else{
330 rmlolast = (rmlolast + 1) % RMLLEN;
331 if(rmlolast == rmlofirst)
332 rmlofirst = (rmlofirst + 1) % RMLLEN;
335 rmloarray[rmlolast].level = (short) level;
336 rmloarray[rmlolast].seq = rmseq++;
337 rmloarray[rmlolast].continuation = cur_is_continuation ? 1 : 0;
338 memset(rmloarray[rmlolast].message, 0, (RMMSGLEN+1)*sizeof(char));
339 strncpy(rmloarray[rmlolast].message, p, MIN(q-p,RMMSGLEN));
340 #ifdef DEBUG
341 memset(rmloarray[rmlolast].timestamp, 0, (RMTIMLEN+1)*sizeof(char));
342 strncpy(rmloarray[rmlolast].timestamp, debug_time(0,1,ps_global->signal_in_progress), RMTIMLEN);
343 #endif
345 else{
346 if(rmhifirst < 0){
347 rmhifirst = 0;
348 rmhilast = 0;
350 else{
351 rmhilast = (rmhilast + 1) % RMHLEN;
352 if(rmhilast == rmhifirst)
353 rmhifirst = (rmhifirst + 1) % RMHLEN;
356 rmhiarray[rmhilast].level = (short) level;
357 rmhiarray[rmhilast].seq = rmseq++;
358 rmhiarray[rmhilast].continuation = cur_is_continuation ? 1 : 0;
359 memset(rmhiarray[rmhilast].message, 0, (RMMSGLEN+1)*sizeof(char));
360 strncpy(rmhiarray[rmhilast].message, p, MIN(q-p,RMMSGLEN));
361 #ifdef DEBUG
362 memset(rmhiarray[rmhilast].timestamp, 0, (RMTIMLEN+1)*sizeof(char));
363 strncpy(rmhiarray[rmhilast].timestamp, debug_time(0,1,ps_global->signal_in_progress), RMTIMLEN);
364 #endif
368 rm_not_right_now = 0;