00001
00002
00003
00004
00005 #include "copyright.h"
00006 #include "config.h"
00007
00008 #define MKINDX
00009 #include "help.h"
00010
00011 char line[LINE_SIZE];
00012 int main(int argc, char *argv[])
00013 {
00014 long pos;
00015 int i, n, lineno, ntopics;
00016 char *s, *topic;
00017 help_indx entry;
00018 FILE *rfp, *wfp;
00019
00020 if(argc < 2 || argc > 3) {
00021 printf
00022 ("Usage:\tmkindx <file_to_be_indexed> <output_index_filename>\n");
00023 exit(-1);
00024 }
00025 if((rfp = fopen(argv[1], "r")) == NULL) {
00026 fprintf(stderr, "can't open %s for reading\n", argv[1]);
00027 exit(-1);
00028 }
00029 if((wfp = fopen(argv[2], "w")) == NULL) {
00030 fprintf(stderr, "can't open %s for writing\n", argv[2]);
00031 exit(-1);
00032 }
00033 pos = 0L;
00034 lineno = 0;
00035 ntopics = 0;
00036 while (fgets(line, LINE_SIZE, rfp) != NULL) {
00037 ++lineno;
00038
00039 n = strlen(line);
00040 if(line[n - 1] != '\n') {
00041 fprintf(stderr, "line %d: line too long\n", lineno);
00042 }
00043 if(line[0] == '&') {
00044 ++ntopics;
00045
00046 if(ntopics > 1) {
00047 entry.len = (int) (pos - entry.pos);
00048 if(fwrite(&entry, sizeof(help_indx), 1, wfp) < 1) {
00049 fprintf(stderr, "error writing %s\n", argv[2]);
00050 exit(-1);
00051 }
00052 }
00053 for(topic = &line[1];
00054 (*topic == ' ' || *topic == '\t') && *topic != '\0'; topic++);
00055 for(i = -1, s = topic; *s != '\n' && *s != '\0'; s++) {
00056 if(i >= TOPIC_NAME_LEN - 1)
00057 break;
00058 if(*s != ' ' || entry.topic[i] != ' ')
00059 entry.topic[++i] = *s;
00060 }
00061 entry.topic[++i] = '\0';
00062 entry.pos = pos + (long) n;
00063 }
00064 pos += n;
00065 }
00066 entry.len = (int) (pos - entry.pos);
00067 if(fwrite(&entry, sizeof(help_indx), 1, wfp) < 1) {
00068 fprintf(stderr, "error writing %s\n", argv[2]);
00069 exit(-1);
00070 }
00071 fclose(rfp);
00072 fclose(wfp);
00073
00074 printf("%d topics indexed\n", ntopics);
00075 exit(0);
00076 }