2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2007 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 * ========================================================================
16 * very short, very specialized
24 #define HELP_KEY_MAX 64 /* maximum length of a key */
27 char key
[HELP_KEY_MAX
]; /* name of help section */
28 long offset
; /* where help text starts */
29 short lines
; /* how many lines there are */
33 main(int argc
, char **argv
)
42 *hip
, /* help index ptr */
43 *hhp
; /* help header ptr */
48 "usage: helpindx <help_file> <index_file> <header_file>\n");
52 if((hp
= fopen(argv
[1], "rb")) == NULL
){ /* problems */
57 if((hip
= fopen(argv
[2], "wb")) == NULL
){ /* problems */
62 if((hhp
= fopen(argv
[3], "w")) == NULL
){ /* problems */
67 fprintf(hhp
,"/*\n * Alpine Help text header file\n */\n");
68 fprintf(hhp
,"\n#ifndef PITH_HELPTEXT_INCLUDED\n#define PITH_HELPTEXT_INCLUDED\n");
69 fprintf(hhp
,"\n#define\tHELP_KEY_MAX\t%d\n", HELP_KEY_MAX
);
70 fprintf(hhp
,"\ntypedef\tshort\tHelpType;\n");
71 fprintf(hhp
,"\n#define\tNO_HELP\t(-1)\n");
72 fprintf(hhp
,"struct hindx {\n char key[HELP_KEY_MAX];");
73 fprintf(hhp
,"\t\t/* name of help section */\n");
74 fprintf(hhp
," long offset;\t\t\t/* where help text starts */\n");
75 fprintf(hhp
," short lines;\t\t\t/* how many lines there are */\n");
76 fprintf(hhp
,"};\n\n\n/*\n * defs for help section titles\n */\n");
81 while(fgets(s
, sizeof(s
) - 1, hp
) != NULL
){
84 if(s
[0] == '='){ /* new section? */
86 while((s
[i
] == '=' || isspace((unsigned char)s
[i
])) && i
< len
)
90 fwrite(&irec
, sizeof(struct hindx
), 1, hip
);
92 irec
.offset
= index
+ (long)i
; /* save where name starts */
94 p
= &irec
.key
[0]; /* save name field */
95 while(!isspace((unsigned char)s
[i
]) && i
< len
)
99 if(irec
.key
[0] == '\0'){
100 fprintf(stderr
,"Invalid help line %d: %s", line
, s
);
104 fprintf(hhp
, "#define\t%s\t%d\n", irec
.key
, section
++);
107 else if(s
[0] == '#' && section
){
108 fprintf(stderr
,"Comments not allowed in help text: line %d", line
);
117 if(section
) /* write last entry */
118 fwrite(&irec
, sizeof(struct hindx
), 1, hip
);
120 fprintf(hhp
, "#define\tLASTHELP\t%d\n", section
);
122 fprintf(hhp
,"\n#endif /* PITH_HELPTEXT_INCLUDED */\n");