1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: help.c 900 2008-01-05 01:13:26Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2006-2008 University of Washington
8 * Copyright 2013-2021 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;
37 help_name2section(char *url
, int url_len
)
40 HelpType newhelp
= NO_HELP
;
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
;
56 get_alpine_revision_string(char *buf
, size_t nbuf
)
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';
71 /* move to revision number */
72 for(p
= ourbuf
; *p
&& !isdigit((unsigned char) (*p
)); p
++)
79 /* skip to following space */
80 for(; *p
&& !isspace((unsigned char) (*p
)); p
++)
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';
101 get_alpine_revision_number(char *buf
, size_t nbuf
)
103 char ourbuf
[100], *p
;
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';
116 /* move to revision number */
117 for(p
= ourbuf
; *p
&& !isdigit((unsigned char) (*p
)); p
++)
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';
140 debugjournal_to_file(FILE *dfile
)
142 int donejo
, donelo
, donehi
, jo
, lo
, hi
;
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;
166 while(!(donejo
&& donelo
&& donehi
)){
167 REV_MSG_S
*pjo
, *plo
, *phi
, *p
;
170 pjo
= &rmjoarray
[jo
];
175 plo
= &rmloarray
[lo
];
180 phi
= &rmhiarray
[hi
];
184 if(pjo
&& (!plo
|| pjo
->seq
<= plo
->seq
)
185 && (!phi
|| pjo
->seq
<= phi
->seq
))
187 else if(plo
&& (!phi
|| plo
->seq
<= phi
->seq
))
196 if(jo
== rmjofirst
&&
197 (((rmjolast
+ 1) % RMJLEN
) == rmjofirst
) &&
198 fputs("*** Level -1 entries prior to this are deleted", dfile
) == EOF
)
201 else if(rmcat
== Lo
){
203 if(lo
== rmlofirst
&&
204 (((rmlolast
+ 1) % RMLLEN
) == rmlofirst
) &&
205 fputs("*** Level 0-4 entries prior to this are deleted", dfile
) == EOF
)
208 else if(rmcat
== Hi
){
210 if(hi
== rmhifirst
&&
211 (((rmhilast
+ 1) % RMHLEN
) == rmhifirst
) &&
212 fputs("*** Level 5-9 entries prior to this are deleted", dfile
) == EOF
)
215 else if(rmcat
== No
){
220 if(p
->timestamp
&& p
->timestamp
[0]
221 && (fputs(p
->timestamp
, dfile
) == EOF
222 || fputs(": ", dfile
) == EOF
))
225 if(p
->message
&& p
->message
[0]
226 && (fputs(p
->message
, dfile
) == EOF
227 || fputs("\n", dfile
) == EOF
))
236 jo
= (jo
+ 1) % RMJLEN
;
244 lo
= (lo
+ 1) % RMLLEN
;
252 hi
= (hi
+ 1) % RMHLEN
;
269 /*----------------------------------------------------------------------
270 Add a message to the circular status message review buffer
272 Args: message -- The message to add
275 add_review_message(char *message
, int level
)
277 int next_is_continuation
= 0, cur_is_continuation
= 0;
279 static unsigned long rmseq
= 0L;
281 if(rm_not_right_now
|| !(message
&& *message
))
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
++)
296 cur_is_continuation
= next_is_continuation
;
298 if((q
-p
) == RMMSGLEN
&& *q
&& *q
!= '\n')
299 next_is_continuation
= 1;
301 next_is_continuation
= 0;
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
));
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
);
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
));
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
);
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
));
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
);
368 rm_not_right_now
= 0;