1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: helpindx.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2016 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 * ========================================================================
20 * very short, very specialized
28 #define HELP_KEY_MAX 64 /* maximum length of a key */
31 char key
[HELP_KEY_MAX
]; /* name of help section */
32 long offset
; /* where help text starts */
33 short lines
; /* how many lines there are */
37 main(int argc
, char **argv
)
46 *hip
, /* help index ptr */
47 *hhp
; /* help header ptr */
52 "usage: helpindx <help_file> <index_file> <header_file>\n");
56 if((hp
= fopen(argv
[1], "rb")) == NULL
){ /* problems */
61 if((hip
= fopen(argv
[2], "wb")) == NULL
){ /* problems */
66 if((hhp
= fopen(argv
[3], "w")) == NULL
){ /* problems */
71 fprintf(hhp
,"/*\n * Alpine Help text header file\n */\n");
72 fprintf(hhp
,"\n#ifndef PITH_HELPTEXT_INCLUDED\n#define PITH_HELPTEXT_INCLUDED\n");
73 fprintf(hhp
,"\n#define\tHELP_KEY_MAX\t%d\n", HELP_KEY_MAX
);
74 fprintf(hhp
,"\ntypedef\tshort\tHelpType;\n");
75 fprintf(hhp
,"\n#define\tNO_HELP\t(-1)\n");
76 fprintf(hhp
,"struct hindx {\n char key[HELP_KEY_MAX];");
77 fprintf(hhp
,"\t\t/* name of help section */\n");
78 fprintf(hhp
," long offset;\t\t\t/* where help text starts */\n");
79 fprintf(hhp
," short lines;\t\t\t/* how many lines there are */\n");
80 fprintf(hhp
,"};\n\n\n/*\n * defs for help section titles\n */\n");
85 while(fgets(s
, sizeof(s
) - 1, hp
) != NULL
){
88 if(s
[0] == '='){ /* new section? */
90 while((s
[i
] == '=' || isspace((unsigned char)s
[i
])) && i
< len
)
94 fwrite(&irec
, sizeof(struct hindx
), 1, hip
);
96 irec
.offset
= index
+ (long)i
; /* save where name starts */
98 p
= &irec
.key
[0]; /* save name field */
99 while(!isspace((unsigned char)s
[i
]) && i
< len
)
103 if(irec
.key
[0] == '\0'){
104 fprintf(stderr
,"Invalid help line %d: %s", line
, s
);
108 fprintf(hhp
, "#define\t%s\t%d\n", irec
.key
, section
++);
111 else if(s
[0] == '#' && section
){
112 fprintf(stderr
,"Comments not allowed in help text: line %d", line
);
121 if(section
) /* write last entry */
122 fwrite(&irec
, sizeof(struct hindx
), 1, hip
);
124 fprintf(hhp
, "#define\tLASTHELP\t%d\n", section
);
126 fprintf(hhp
,"\n#endif /* PITH_HELPTEXT_INCLUDED */\n");