#include "copyright.h"
#include "config.h"
#include "help.h"
Include dependency graph for mkindx.c:
Go to the source code of this file.
Defines | |
#define | MKINDX |
Functions | |
int | main (int argc, char *argv[]) |
Variables | |
char | line [LINE_SIZE] |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 12 of file mkindx.c.
References help_indx::len, line, LINE_SIZE, help_indx::pos, help_indx::topic, and TOPIC_NAME_LEN.
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 }
char line[LINE_SIZE] |
Definition at line 11 of file mkindx.c.
Referenced by colourize_tac_map(), help_write(), load_template(), and main().