/* x2index for grepping x2ftp.oulu.fi:/pub/msdos/programming/00index.all Copyright (c) Jouni Miettunen 1995. All Rights Reserved. I wrote it and have copyrighted to prevent anyone else from doing it. You may use it freely for both commercial and non-commercial purposes, but please do not distribute modified versions. If you update this or wish some changes or additions, please contact me (jon@stekt.oulu.fi). 1.0 first release by Jouni Miettunen 6 May 1995 */ #include #include #include #include int main( int argc, char **argv ) { char *a,*c,*s, workbuf[80], dirbuf[80], linebuf[128]; FILE *fp; if (argc<2) exit(1); a = s = argv[1]; *dirbuf = 0; /* case insensitive search: search string lowercase */ while (*a) { *a = ( isupper(*a) ? tolower(*a) : *a ); a++; } fp = fopen("00index.all","rb"); if (fp) { while ((c = fgets(workbuf,80,fp)) != NULL) { if (*c == '#') { memcpy(dirbuf,workbuf,80); /* store directory name */ continue; } memcpy(linebuf,workbuf,80); /* case insensitive search: index line lowercase */ a = c; while (*a) { *a = ( isupper(*a) ? tolower(*a) : *a ); a++; } a = strstr(c,s); if (c && a) { if (*dirbuf != 0) { puts(""); fputs("x2ftp.oulu.fi:/pub/msdos/programming/", stdout); /* jump over ## Directory (TAB or many spaces) */ a = dirbuf + 10; while (!isspace(*a)) a++; while (isspace(*a)) a++; fputs(a,stdout); *dirbuf = 0; } fputs(linebuf,stdout); } } } return (0); }