2 * ========================================================================
3 * Copyright 2006-2007 University of Washington
4 * Copyright 2013-2022 Eduardo Chappa
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 * ========================================================================
21 typedef struct helplist
{
23 struct helplist
*next
;
27 HELPLIST_S
*help_list
;
30 void preamble(FILE *ofp
);
31 void body(FILE *ifp
, FILE *ofp
);
32 char *quote_clean(char *rawline
);
33 int only_tags(char *line
);
34 int append_to_help_list(HELPLIST_S
**, char *new);
35 void print_help_list(HELPLIST_S
*, FILE *fp
);
39 main(int argc
, char **argv
)
50 fprintf(ofp
, "\n\t\t/*\n");
51 fprintf(ofp
, "\t\t * AUTOMATICALLY GENERATED FILE!\n");
52 fprintf(ofp
, "\t\t * DO NOT EDIT!!\n");
53 fprintf(ofp
, "\t\t * See help_c_gen.c.\n\t\t */\n\n\n");
54 fprintf(ofp
, "#include <stdio.h>\n#include \"headers.h\"\n#include \"helptext.h\"\n\n");
59 body(FILE *ifp
, FILE *ofp
)
65 int in_text
= 0, new_topic
= 0, first_one
= 1, justtags
;
67 while(fgets(rawline
, sizeof(rawline
), ifp
) != NULL
){
71 line
= quote_clean(rawline
);
75 * Put errors in result so that it will cause a compile
76 * error and be noticed.
78 fprintf(ofp
, "Error: quote_clean returns NULL for help line\n %s\n", rawline
);
83 if(!strncmp(line
, "====", 4)){
85 /* skip to first space */
86 while(*p
&& *p
!= SPACE
)
90 fprintf(ofp
, "Error: help input line\n %s\n No space after ====\n", rawline
);
95 while(*p
&& *p
== SPACE
)
99 fprintf(ofp
, "Error: help input line\n %s\n Missing helpname after ====\n", rawline
);
105 /* skip to next space */
106 while(*p
&& *p
!= SPACE
)
109 *p
= '\0'; /* tie off helpname */
111 /* finish previous one */
113 fprintf(ofp
, "NULL\n};\n\n\n");
115 in_text
= new_topic
= 1;
117 fprintf(ofp
, "char *%s[] = {\n", helpname
);
119 if(append_to_help_list(&help_list
, helpname
) < 0){
120 fprintf(ofp
, "Error: Can't allocate memory for help_list after line\n %s\n", rawline
);
124 else if(line
[0] == '\0'){
126 fprintf(ofp
, "\" \",\n"); /* why the space? */
128 else if(only_tags(line
)){
130 fprintf(ofp
, "\"%s\",\n", line
);
135 if(line
[0] && line
[0] != '='){
136 if(in_text
&& !justtags
){
139 fprintf(ofp
, "/*\n");
140 fprintf(ofp
, "TRANSLATORS: The translation strings for pith/helptext.c\n");
141 fprintf(ofp
, "are automatically generated by a script from the help\n");
142 fprintf(ofp
, "text in pith/pine.hlp. This means that the translation job for\n");
143 fprintf(ofp
, "the help text is particularly difficult.\n");
144 fprintf(ofp
, "This is HTML source so please leave the text inside HTML tags untranslated.\n");
145 fprintf(ofp
, "HTML tags like <LI> or <TITLE> should, of course, be left untranslated.\n");
146 fprintf(ofp
, "Special HTML characters like < (less than character) should be left alone.\n");
147 fprintf(ofp
, "Alpine option names are short phrases with the words separated by\n");
148 fprintf(ofp
, "dashes. An example of an option name is Quell-Extra-Post-Prompt.\n");
149 fprintf(ofp
, "Option names should not be translated.\n");
150 fprintf(ofp
, "The file pith/helptext.c contains many separate help topics.\n");
151 fprintf(ofp
, "Some of them are very short and some are long. If left unsorted the\n");
152 fprintf(ofp
, "text for a single topic is together in the translation file. The start\n");
153 fprintf(ofp
, "of each new topic is marked by the comment\n");
154 fprintf(ofp
, "TRANSLATORS: Start of new help topic.\n");
155 fprintf(ofp
, "*/\n");
159 fprintf(ofp
, "/* TRANSLATORS: Start of new help topic. */\n");
162 fprintf(ofp
, "N_(\"%s\"),\n", line
);
165 ; /* skip leading cruft */
171 fprintf(ofp
, "NULL\n};\n\n\n");
173 print_help_list(help_list
, ofp
);
178 quote_clean(char *rawline
)
180 char *p
, *q
, *cleaned
= NULL
;
184 len
= strlen(rawline
);
185 cleaned
= (char *) malloc((2*len
+1) * sizeof(char));
191 while(*p
&& *p
!= '\n'){
192 if(*p
== '"' && !(p
> rawline
&& *(p
-1) == '\\'))
207 only_tags(char *line
)
210 int is_tags
= 1; /* only tags seen so far */
217 while(is_tags
&& *p
){
218 /* leading space before a tag */
219 while(*p
&& isspace(*p
))
224 /* skip through interior of tag */
225 while(*p
&& *p
!= '<' && *p
!= '>')
230 /* trailing space after tag */
231 while(*p
&& isspace(*p
))
246 append_to_help_list(HELPLIST_S
**head
, char *name
)
251 if(!(name
&& *name
&& head
))
254 new = (HELPLIST_S
*) malloc(sizeof(*new));
258 memset(new, 0, sizeof(*new));
260 new->name
= (char *) malloc((len
+1) * sizeof(char));
261 strncpy(new->name
, name
, len
);
262 new->name
[len
] = '\0';
265 for(h
= *head
; h
->next
; h
= h
->next
)
278 print_help_list(HELPLIST_S
*head
, FILE *fp
)
283 fprintf(fp
, "struct help_texts h_texts[] = {\n");
285 for(h
= head
; h
; h
= h
->next
)
286 if(h
->name
&& h
->name
[0])
287 fprintf(fp
, "{%s,\"%s\"},\n", h
->name
, h
->name
);
289 fprintf(fp
, "{NO_HELP, NULL}\n};\n");