* NTLM authentication support with the ntlm library, in Unix systems.
[alpine.git] / pith / helpindx.c
blob2be8eae42d42f8af37c9af7e036d54aadaee1779
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: helpindx.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2017 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
26 #include "system.h"
28 #define HELP_KEY_MAX 64 /* maximum length of a key */
30 struct hindx {
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 */
36 int
37 main(int argc, char **argv)
39 char *p, s[1024];
40 long index;
41 int section,
42 len,
43 line,
44 i;
45 FILE *hp,
46 *hip, /* help index ptr */
47 *hhp; /* help header ptr */
48 struct hindx irec;
50 if(argc < 4){
51 fprintf(stderr,
52 "usage: helpindx <help_file> <index_file> <header_file>\n");
53 exit(-1);
56 if((hp = fopen(argv[1], "rb")) == NULL){ /* problems */
57 perror(argv[1]);
58 exit(-1);
61 if((hip = fopen(argv[2], "wb")) == NULL){ /* problems */
62 perror(argv[2]);
63 exit(-1);
66 if((hhp = fopen(argv[3], "w")) == NULL){ /* problems */
67 perror(argv[3]);
68 exit(-1);
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");
82 index = 0L;
83 line = section = 0;
85 while(fgets(s, sizeof(s) - 1, hp) != NULL){
86 line++;
87 len = strlen(s);
88 if(s[0] == '='){ /* new section? */
89 i = 0;
90 while((s[i] == '=' || isspace((unsigned char)s[i])) && i < len)
91 i++;
93 if(section)
94 fwrite(&irec, sizeof(struct hindx), 1, hip);
96 irec.offset = index + (long)i; /* save where name starts */
97 irec.lines = 0;
98 p = &irec.key[0]; /* save name field */
99 while(!isspace((unsigned char)s[i]) && i < len)
100 *p++ = s[i++];
101 *p = '\0';
103 if(irec.key[0] == '\0'){
104 fprintf(stderr,"Invalid help line %d: %s", line, s);
105 exit(-1);
107 else
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);
113 exit(-1);
115 else{
116 irec.lines++;
118 index += len;
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");
128 fclose(hp);
129 fclose(hip);
130 fclose(hhp);
131 exit(0);