upgrade ngmakeidx to support build in a sparate directory

This commit is contained in:
rlar 2011-07-03 09:46:39 +00:00
parent 24e80f5013
commit 3f018a9c77
3 changed files with 51 additions and 30 deletions

View File

@ -1,3 +1,8 @@
2011-07-03 Robert Larice
* src/Makefile.am ,
* src/makeidx.c :
upgrade ngmakeidx to support build in a sparate directory
2011-07-02 Robert Larice 2011-07-02 Robert Larice
* src/main.c : * src/main.c :
main.c, a series of cleanups concerning SETJMP processing main.c, a series of cleanups concerning SETJMP processing

View File

@ -275,8 +275,8 @@ ngmakeidx_SOURCES = makeidx.c
## create index for online help: ## create index for online help:
ngspice.idx: ngmakeidx$(EXEEXT) ngspice.idx: ngmakeidx$(EXEEXT) $(srcdir)/ngspice.txt
./ngmakeidx$(EXEEXT) $(srcdir)/ngspice.txt ./ngmakeidx$(EXEEXT) -o ngspice.idx $(srcdir)/ngspice.txt
endif !WINDOWS endif !WINDOWS

View File

@ -13,46 +13,62 @@ Copyright 1990 Regents of the University of California. All rights reserved.
#define BSIZE_SP 512 #define BSIZE_SP 512
int
main(int argc, char **argv)
{
static void
makeidx(const char *dst, const char *src)
{
FILE *fp; FILE *fp;
FILE *wfp; FILE *wfp;
char buf[BSIZE_SP]; char buf[BSIZE_SP];
long fpos; long fpos;
char subject[BSIZE_SP]; char subject[BSIZE_SP];
struct hlp_index indexitem; struct hlp_index indexitem;
char *pos;
if (!(fp = fopen(src, "r"))) {
perror(src);
return;
}
while (--argc) { if (!(wfp = fopen(dst, "wb"))) {
if (!(fp = fopen(argv[argc], "r"))) { perror(dst);
perror(argv[argc]); return;
continue; }
}
strcpy(buf, argv[argc]); fpos = 0;
if (((pos =strrchr(buf, '.')) == 0) || while (fgets(buf, sizeof(buf), fp)) {
strcmp(pos, ".txt")) {
fprintf(stderr, "%s does not end in .txt\n", buf);
continue;
}
*++pos = 'i'; *++pos = 'd'; *++pos = 'x';
if (!(wfp = fopen(buf, "wb"))) {
perror(buf);
continue;
}
fpos = 0;
while (fgets(buf, sizeof(buf), fp)) {
if (!strncmp(buf, "SUBJECT: ", 9)) { if (!strncmp(buf, "SUBJECT: ", 9)) {
strcpy(subject, &buf[9]); strcpy(subject, &buf[9]);
subject[strlen(subject) - 1] = '\0'; /* get rid of '\n' */ subject[strlen(subject) - 1] = '\0'; /* get rid of '\n' */
strncpy(indexitem.subject, subject, 64); /* zero out end */ strncpy(indexitem.subject, subject, 64); /* zero out end */
indexitem.fpos = fpos; indexitem.fpos = fpos;
fwrite(&indexitem, sizeof(struct hlp_index), 1, wfp); fwrite(&indexitem, sizeof(struct hlp_index), 1, wfp);
} }
fpos = ftell(fp); fpos = ftell(fp);
}
} }
}
int
main(int argc, char **argv)
{
if(argc == 4 && !strcmp(argv[1], "-o")) {
makeidx(argv[2], argv[3]);
exit(0);
}
while (--argc) {
char buf[BSIZE_SP];
char *pos;
strcpy(buf, argv[argc]);
if (!(pos = strrchr(buf, '.')) || strcmp(pos, ".txt")) {
fprintf(stderr, "%s does not end in .txt\n", buf);
continue;
}
*++pos = 'i'; *++pos = 'd'; *++pos = 'x';
makeidx(buf, argv[argc]);
}
exit(0); exit(0);
} }