2
* ========================================================================
3
* Copyright 2006-2007 University of Washington
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* ========================================================================
18
typedef struct helplist {
20
struct helplist *next;
24
HELPLIST_S *help_list;
27
void preamble(FILE *ofp);
28
void body(FILE *ifp, FILE *ofp);
29
char *quote_clean(char *rawline);
30
int only_tags(char *line);
31
int append_to_help_list(HELPLIST_S **, char *new);
32
void print_help_list(HELPLIST_S *, FILE *fp);
36
main(int argc, char **argv)
46
fprintf(ofp, "\n\t\t/*\n");
47
fprintf(ofp, "\t\t * AUTMATICALLY GENERATED FILE!\n");
48
fprintf(ofp, "\t\t * DO NOT EDIT!!\n");
49
fprintf(ofp, "\t\t * See help_c_gen.c.\n\t\t */\n\n\n");
50
fprintf(ofp, "#include <stdio.h>\n#include \"headers.h\"\n#include \"helptext.h\"\n\n");
55
body(FILE *ifp, FILE *ofp)
62
int in_text = 0, new_topic = 0, first_one = 1, justtags;
64
while(fgets(rawline, sizeof(rawline), ifp) != NULL){
68
line = quote_clean(rawline);
72
* Put errors in result so that it will cause a compile
73
* error and be noticed.
75
fprintf(ofp, "Error: quote_clean returns NULL for help line\n %s\n", rawline);
80
if(!strncmp(line, "====", 4)){
82
/* skip to first space */
83
while(*p && *p != SPACE)
87
fprintf(ofp, "Error: help input line\n %s\n No space after ====\n", rawline);
92
while(*p && *p == SPACE)
96
fprintf(ofp, "Error: help input line\n %s\n Missing helpname after ====\n", rawline);
102
/* skip to next space */
103
while(*p && *p != SPACE)
106
*p = '\0'; /* tie off helpname */
108
/* finish previous one */
110
fprintf(ofp, "NULL\n};\n\n\n");
112
in_text = new_topic = 1;
114
fprintf(ofp, "char *%s[] = {\n", helpname);
116
if(append_to_help_list(&help_list, helpname) < 0){
117
fprintf(ofp, "Error: Can't allocate memory for help_list after line\n %s\n", rawline);
121
else if(line[0] == '\0'){
123
fprintf(ofp, "\" \",\n"); /* why the space? */
125
else if(only_tags(line)){
127
fprintf(ofp, "\"%s\",\n", line);
132
if(line[0] && line[0] != '='){
133
if(in_text && !justtags){
136
fprintf(ofp, "/*\n");
137
fprintf(ofp, "TRANSLATORS: The translation strings for pith/helptext.c\n");
138
fprintf(ofp, "are automatically generated by a script from the help\n");
139
fprintf(ofp, "text in pith/pine.hlp. This means that the translation job for\n");
140
fprintf(ofp, "the help text is particularly difficult.\n");
141
fprintf(ofp, "This is HTML source so please leave the text inside HTML tags untranslated.\n");
142
fprintf(ofp, "HTML tags like <LI> or <TITLE> should, of course, be left untranslated.\n");
143
fprintf(ofp, "Special HTML characters like < (less than character) should be left alone.\n");
144
fprintf(ofp, "Alpine option names are short phrases with the words separated by\n");
145
fprintf(ofp, "dashes. An example of an option name is Quell-Extra-Post-Prompt.\n");
146
fprintf(ofp, "Option names should not be translated.\n");
147
fprintf(ofp, "The file pith/helptext.c contains many separate help topics.\n");
148
fprintf(ofp, "Some of them are very short and some are long. If left unsorted the\n");
149
fprintf(ofp, "text for a single topic is together in the translation file. The start\n");
150
fprintf(ofp, "of each new topic is marked by the comment\n");
151
fprintf(ofp, "TRANSLATORS: Start of new help topic.\n");
152
fprintf(ofp, "*/\n");
156
fprintf(ofp, "/* TRANSLATORS: Start of new help topic. */\n");
159
fprintf(ofp, "N_(\"%s\"),\n", line);
162
; /* skip leading cruft */
168
fprintf(ofp, "NULL\n};\n\n\n");
170
print_help_list(help_list, ofp);
175
quote_clean(char *rawline)
177
char *p, *q, *cleaned = NULL;
181
len = strlen(rawline);
182
cleaned = (char *) malloc((2*len+1) * sizeof(char));
188
while(*p && *p != '\n'){
189
if(*p == '"' && !(p > rawline && *(p-1) == '\\'))
204
only_tags(char *line)
207
int is_tags = 1; /* only tags seen so far */
214
while(is_tags && *p){
215
/* leading space before a tag */
216
while(*p && isspace(*p))
221
/* skip through interior of tag */
222
while(*p && *p != '<' && *p != '>')
227
/* trailing space after tag */
228
while(*p && isspace(*p))
243
append_to_help_list(HELPLIST_S **head, char *name)
248
if(!(name && *name && head))
251
new = (HELPLIST_S *) malloc(sizeof(*new));
255
memset(new, 0, sizeof(*new));
257
new->name = (char *) malloc((len+1) * sizeof(char));
258
strncpy(new->name, name, len);
259
new->name[len] = '\0';
262
for(h = *head; h->next; h = h->next)
275
print_help_list(HELPLIST_S *head, FILE *fp)
280
fprintf(fp, "struct help_texts h_texts[] = {\n");
282
for(h = head; h; h = h->next)
283
if(h->name && h->name[0])
284
fprintf(fp, "{%s,\"%s\"},\n", h->name, h->name);
286
fprintf(fp, "{NO_HELP, NULL}\n};\n");