Add support for tab-completion when selecting by rule
[alpine.git] / pith / helpindx.c
blobeb32236d874f7db4e7c6772f667ed89aec05dd35
1 /*
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
22 #include "system.h"
24 #define HELP_KEY_MAX 64 /* maximum length of a key */
26 struct hindx {
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 */
32 int
33 main(int argc, char **argv)
35 char *p, s[1024];
36 long index;
37 int section,
38 len,
39 line,
40 i;
41 FILE *hp,
42 *hip, /* help index ptr */
43 *hhp; /* help header ptr */
44 struct hindx irec;
46 if(argc < 4){
47 fprintf(stderr,
48 "usage: helpindx <help_file> <index_file> <header_file>\n");
49 exit(-1);
52 if((hp = fopen(argv[1], "rb")) == NULL){ /* problems */
53 perror(argv[1]);
54 exit(-1);
57 if((hip = fopen(argv[2], "wb")) == NULL){ /* problems */
58 perror(argv[2]);
59 exit(-1);
62 if((hhp = fopen(argv[3], "w")) == NULL){ /* problems */
63 perror(argv[3]);
64 exit(-1);
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");
78 index = 0L;
79 line = section = 0;
81 while(fgets(s, sizeof(s) - 1, hp) != NULL){
82 line++;
83 len = strlen(s);
84 if(s[0] == '='){ /* new section? */
85 i = 0;
86 while((s[i] == '=' || isspace((unsigned char)s[i])) && i < len)
87 i++;
89 if(section)
90 fwrite(&irec, sizeof(struct hindx), 1, hip);
92 irec.offset = index + (long)i; /* save where name starts */
93 irec.lines = 0;
94 p = &irec.key[0]; /* save name field */
95 while(!isspace((unsigned char)s[i]) && i < len)
96 *p++ = s[i++];
97 *p = '\0';
99 if(irec.key[0] == '\0'){
100 fprintf(stderr,"Invalid help line %d: %s", line, s);
101 exit(-1);
103 else
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);
109 exit(-1);
111 else{
112 irec.lines++;
114 index += len;
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");
124 fclose(hp);
125 fclose(hip);
126 fclose(hhp);
127 exit(0);