2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2008 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include "../pith/headers.h"
16 #include "../pith/help.h"
17 #include "../pith/flag.h"
18 #include "../pith/conf.h"
19 #include "../pith/sort.h"
22 REV_MSG_S rmjoarray
[RMJLEN
]; /* For regular journal */
23 REV_MSG_S rmloarray
[RMLLEN
]; /* debug 0-4 */
24 REV_MSG_S rmhiarray
[RMHLEN
]; /* debug 5-9 */
25 int rmjofirst
= -1, rmjolast
= -1;
26 int rmlofirst
= -1, rmlolast
= -1;
27 int rmhifirst
= -1, rmhilast
= -1;
33 help_name2section(char *url
, int url_len
)
36 HelpType newhelp
= NO_HELP
;
39 snprintf(name
, sizeof(name
), "%.*s", (int) MIN(url_len
,sizeof(name
)), url
);
41 for(t
= h_texts
; t
->help_text
!= NO_HELP
; t
++)
42 if(!strucmp(t
->tag
, name
)){
43 newhelp
= t
->help_text
;
52 get_alpine_revision_string(char *buf
, size_t nbuf
)
60 /* HelpType (the type of h_revision) is assumed to be char ** */
61 if(h_revision
&& h_revision
[0] && h_revision
[0][0]){
62 strncpy(ourbuf
, h_revision
[0], sizeof(ourbuf
)-1);
63 ourbuf
[sizeof(ourbuf
)-1] = '\0';
67 /* move to revision number */
68 for(p
= ourbuf
; *p
&& !isdigit((unsigned char) (*p
)); p
++)
75 /* skip to following space */
76 for(; *p
&& !isspace((unsigned char) (*p
)); p
++)
80 for(; *p
&& isspace((unsigned char) (*p
)); p
++)
83 /* skip over date to following space */
84 for(; *p
&& !isspace((unsigned char) (*p
)); p
++)
87 strncpy(buf
, rev
, MIN(p
-rev
, nbuf
-1));
88 buf
[MIN(p
-rev
,nbuf
-1)] = '\0';
97 get_alpine_revision_number(char *buf
, size_t nbuf
)
105 /* HelpType (the type of h_revision) is assumed to be char ** */
106 if(h_revision
&& h_revision
[0] && h_revision
[0][0]){
107 strncpy(ourbuf
, h_revision
[0], sizeof(ourbuf
)-1);
108 ourbuf
[sizeof(ourbuf
)-1] = '\0';
112 /* move to revision number */
113 for(p
= ourbuf
; *p
&& !isdigit((unsigned char) (*p
)); p
++)
120 /* skip to following space */
121 for(; *p
&& !isspace((unsigned char) (*p
)); p
++)
124 strncpy(buf
, rev
, MIN(p
-rev
, nbuf
-1));
125 buf
[MIN(p
-rev
,nbuf
-1)] = '\0';
136 debugjournal_to_file(FILE *dfile
)
138 int donejo
, donelo
, donehi
, jo
, lo
, hi
;
141 if(dfile
&& (rmjofirst
>= 0 || rmlofirst
>= 0 || rmhifirst
>= 0)
142 && rmjofirst
< RMJLEN
&& rmjolast
< RMJLEN
143 && rmlofirst
< RMLLEN
&& rmlolast
< RMLLEN
144 && rmhifirst
< RMHLEN
&& rmhilast
< RMHLEN
145 && (rmjofirst
< 0 || rmjolast
>= 0)
146 && (rmlofirst
< 0 || rmlolast
>= 0)
147 && (rmhifirst
< 0 || rmhilast
>= 0)){
149 donejo
= donehi
= donelo
= 0;
162 while(!(donejo
&& donelo
&& donehi
)){
163 REV_MSG_S
*pjo
, *plo
, *phi
, *p
;
166 pjo
= &rmjoarray
[jo
];
171 plo
= &rmloarray
[lo
];
176 phi
= &rmhiarray
[hi
];
180 if(pjo
&& (!plo
|| pjo
->seq
<= plo
->seq
)
181 && (!phi
|| pjo
->seq
<= phi
->seq
))
183 else if(plo
&& (!phi
|| plo
->seq
<= phi
->seq
))
192 if(jo
== rmjofirst
&&
193 (((rmjolast
+ 1) % RMJLEN
) == rmjofirst
) &&
194 fputs("*** Level -1 entries prior to this are deleted", dfile
) == EOF
)
197 else if(rmcat
== Lo
){
199 if(lo
== rmlofirst
&&
200 (((rmlolast
+ 1) % RMLLEN
) == rmlofirst
) &&
201 fputs("*** Level 0-4 entries prior to this are deleted", dfile
) == EOF
)
204 else if(rmcat
== Hi
){
206 if(hi
== rmhifirst
&&
207 (((rmhilast
+ 1) % RMHLEN
) == rmhifirst
) &&
208 fputs("*** Level 5-9 entries prior to this are deleted", dfile
) == EOF
)
211 else if(rmcat
== No
){
216 if(p
->timestamp
&& p
->timestamp
[0]
217 && (fputs(p
->timestamp
, dfile
) == EOF
218 || fputs(": ", dfile
) == EOF
))
221 if(p
->message
&& p
->message
[0]
222 && (fputs(p
->message
, dfile
) == EOF
223 || fputs("\n", dfile
) == EOF
))
232 jo
= (jo
+ 1) % RMJLEN
;
240 lo
= (lo
+ 1) % RMLLEN
;
248 hi
= (hi
+ 1) % RMHLEN
;
265 /*----------------------------------------------------------------------
266 Add a message to the circular status message review buffer
268 Args: message -- The message to add
271 add_review_message(char *message
, int level
)
273 int next_is_continuation
= 0, cur_is_continuation
= 0;
275 static unsigned long rmseq
= 0L;
277 if(rm_not_right_now
|| !(message
&& *message
))
281 * Debug output can have newlines in it, so split up each newline piece
282 * by hand and make them separate messages.
284 rm_not_right_now
= 1;
285 for(p
= message
; *p
; p
= (*q
&& !next_is_continuation
) ? q
+1 : q
){
286 for(q
= p
; *q
&& *q
!= '\n' && (q
-p
) < RMMSGLEN
; q
++)
292 cur_is_continuation
= next_is_continuation
;
294 if((q
-p
) == RMMSGLEN
&& *q
&& *q
!= '\n')
295 next_is_continuation
= 1;
297 next_is_continuation
= 0;
305 rmjolast
= (rmjolast
+ 1) % RMJLEN
;
306 if(rmjolast
== rmjofirst
)
307 rmjofirst
= (rmjofirst
+ 1) % RMJLEN
;
310 rmjoarray
[rmjolast
].level
= (short) level
;
311 rmjoarray
[rmjolast
].seq
= rmseq
++;
312 rmjoarray
[rmjolast
].continuation
= cur_is_continuation
? 1 : 0;
313 memset(rmjoarray
[rmjolast
].message
, 0, (RMMSGLEN
+1)*sizeof(char));
314 strncpy(rmjoarray
[rmjolast
].message
, p
, MIN(q
-p
,RMMSGLEN
));
316 memset(rmjoarray
[rmjolast
].timestamp
, 0, (RMTIMLEN
+1)*sizeof(char));
317 strncpy(rmjoarray
[rmjolast
].timestamp
, debug_time(0,1,ps_global
->signal_in_progress
), RMTIMLEN
);
326 rmlolast
= (rmlolast
+ 1) % RMLLEN
;
327 if(rmlolast
== rmlofirst
)
328 rmlofirst
= (rmlofirst
+ 1) % RMLLEN
;
331 rmloarray
[rmlolast
].level
= (short) level
;
332 rmloarray
[rmlolast
].seq
= rmseq
++;
333 rmloarray
[rmlolast
].continuation
= cur_is_continuation
? 1 : 0;
334 memset(rmloarray
[rmlolast
].message
, 0, (RMMSGLEN
+1)*sizeof(char));
335 strncpy(rmloarray
[rmlolast
].message
, p
, MIN(q
-p
,RMMSGLEN
));
337 memset(rmloarray
[rmlolast
].timestamp
, 0, (RMTIMLEN
+1)*sizeof(char));
338 strncpy(rmloarray
[rmlolast
].timestamp
, debug_time(0,1,ps_global
->signal_in_progress
), RMTIMLEN
);
347 rmhilast
= (rmhilast
+ 1) % RMHLEN
;
348 if(rmhilast
== rmhifirst
)
349 rmhifirst
= (rmhifirst
+ 1) % RMHLEN
;
352 rmhiarray
[rmhilast
].level
= (short) level
;
353 rmhiarray
[rmhilast
].seq
= rmseq
++;
354 rmhiarray
[rmhilast
].continuation
= cur_is_continuation
? 1 : 0;
355 memset(rmhiarray
[rmhilast
].message
, 0, (RMMSGLEN
+1)*sizeof(char));
356 strncpy(rmhiarray
[rmhilast
].message
, p
, MIN(q
-p
,RMMSGLEN
));
358 memset(rmhiarray
[rmhilast
].timestamp
, 0, (RMTIMLEN
+1)*sizeof(char));
359 strncpy(rmhiarray
[rmhilast
].timestamp
, debug_time(0,1,ps_global
->signal_in_progress
), RMTIMLEN
);
364 rm_not_right_now
= 0;