1 /**********
2 Copyright 1990 Regents of the University of California. All rights reserved.
3 **********/
4
5 /* from FILENAME.txt, make FILENAME.idx */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "ngspice/cpdefs.h"
11 #include "ngspice/hlpdefs.h"
12 #include "ngspice/suffix.h"
13
14 #define BSIZE_SP 512
15
16
17 static void
makeidx(const char * dst,const char * src)18 makeidx(const char *dst, const char *src)
19 {
20 FILE *fp;
21 FILE *wfp;
22 char buf[BSIZE_SP];
23 long fpos;
24 char subject[BSIZE_SP];
25 struct hlp_index indexitem;
26
27 if (!(fp = fopen(src, "r"))) {
28 perror(src);
29 return;
30 }
31
32 if (!(wfp = fopen(dst, "wb"))) {
33 perror(dst);
34 return;
35 }
36
37 fpos = 0;
38 while (fgets(buf, sizeof(buf), fp)) {
39 if (!strncmp(buf, "SUBJECT: ", 9)) {
40 strcpy(subject, &buf[9]);
41 subject[strlen(subject) - 1] = '\0'; /* get rid of '\n' */
42 strncpy(indexitem.subject, subject, 64); /* zero out end */
43 indexitem.fpos = fpos;
44 fwrite(&indexitem, sizeof(struct hlp_index), 1, wfp);
45 }
46 fpos = ftell(fp);
47 }
48 }
49
50
51 int
main(int argc,char ** argv)52 main(int argc, char **argv)
53 {
54 if(argc == 4 && !strcmp(argv[1], "-o")) {
55 makeidx(argv[2], argv[3]);
56 exit(0);
57 }
58
59 while (--argc) {
60
61 char buf[BSIZE_SP];
62 char *pos;
63
64 strcpy(buf, argv[argc]);
65 if (!(pos = strrchr(buf, '.')) || strcmp(pos, ".txt")) {
66 fprintf(stderr, "%s does not end in .txt\n", buf);
67 continue;
68 }
69 *++pos = 'i'; *++pos = 'd'; *++pos = 'x';
70 makeidx(buf, argv[argc]);
71 }
72
73 exit(0);
74 }
75