home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
xdev_118.arj
/
INDEXER.C
next >
Wrap
C/C++ Source or Header
|
1992-01-18
|
5KB
|
226 lines
/*
*
* Prompt file indexer for XBBS
* revised for speed and sysop error checking 01/17/92
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dir.h>
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
char * pascal fgetsx (char *str,int num,int handle);
int main (void) {
int hfp,idxfp;
unsigned int last = 0;
struct stat f;
char lineh[513],bell = 0;
char s[33],*p,*fn,ofn[133];
register unsigned int x;
long pos,line = 0L;
fn = searchpath("XBBS.TXT");
if (!fn || stat (fn,&f)) {
fputs("\nCan't find XBBS.TXT\n",stdout);
return(1);
}
strcpy(ofn,fn);
if (f.st_size < 1L) {
fputs("\nXBBS.TXT is null length\n",stdout);
return(1);
}
if ((hfp = _open(ofn,O_RDONLY | O_TEXT | O_DENYNONE)) == -1) {
fputs("\nCan't open XBBS.TXT\n",stdout);
return(1);
}
fn = searchpath("XBBS.IDX");
if(fn) unlink(fn);
else {
p = strrchr(ofn,'\\');
if(p) {
p++;
*p = 0;
}
strcat(ofn,"XBBS.IDX");
fn = ofn;
}
if ((idxfp = creat(fn,S_IWRITE)) == -1) {
fputs("\nCan't create XBBS.IDX\n",stdout);
_close(hfp);
return(1);
}
fputs("\nIndexing XBBS.TXT...\n",stdout);
if (fgetsx(lineh,513,hfp) == NULL) strcpy(lineh,"\01 END");
line++;
x = 0;
for(;;) {
if (strncmp(lineh,"\01 END",5) == 0) break;
if (*lineh != '\01') {
continue;
}
last = atoi(&lineh[1]);
if((!last && lineh[1] != '0') || (last != x)) {
if(!bell) {
putchar('\07');
bell++;
}
fputs("\nWarning: possible grunging in prompt file, line #",stderr);
fputs(ltoa(line,s,10),stderr);
fputs(", last prompt #",stderr);
fputs(itoa(x,s,10),stderr);
fputs("\n",stderr);
fputs(lineh,stderr);
}
pos = tell(hfp);
_write(idxfp,&pos,sizeof(long));
if (fgetsx(lineh,513,hfp) == NULL) strcpy(lineh,"\01 END");
line++;
while(*lineh != '\01') {
if (fgetsx(lineh,513,hfp) == NULL) strcpy(lineh,"\01 END");
line++;
}
if(!(x % 5)) {
fputs(itoa(x,s,10),stdout);
putchar('\r');
}
x++;
}
_close(hfp);
_close(idxfp);
bell = 0;
line = 0L;
fn = searchpath("XBBS.GXT");
if (!fn || stat (fn,&f)) {
fputs("\nCan't find XBBS.GXT\n",stdout);
return(0);
}
strcpy(ofn,fn);
if (f.st_size < 1L) {
fputs("\nXBBS.GXT is null length\n",stdout);
return(0);
}
if ((hfp = _open(ofn,O_RDONLY | O_TEXT | O_DENYNONE))==-1) {
fputs("\nCan't open XBBS.GXT\n",stdout);
return(0);
}
fn = searchpath("XBBS.GDX");
if(fn) unlink(fn);
else {
p = strrchr(ofn,'\\');
if(p) {
p++;
*p = 0;
}
strcat(ofn,"XBBS.GDX");
fn = ofn;
}
if ((idxfp = creat(fn,S_IWRITE)) == -1) {
fputs("\nCan't create XBBS.GDX\n",stdout);
_close(hfp);
return(0);
}
fputs("\nIndexing XBBS.GXT...\n",stdout);
if (fgetsx(lineh,513,hfp) == NULL) strcpy(lineh,"\01 END");
line++;
x = 0;
for(;;) {
if (strncmp(lineh,"\x1 END",5) == 0) break;
if (*lineh != '\01') {
continue;
}
last = atoi(&lineh[1]);
if((!last && lineh[1] != '0') || (last != x)) {
if(!bell) {
putchar('\07');
bell++;
}
fputs("\nWarning: possible grunging in prompt file, line #",stderr);
fputs(ltoa(line,s,10),stderr);
fputs(", last prompt #",stderr);
fputs(itoa(x,s,10),stderr);
fputs("\n",stderr);
fputs(lineh,stderr);
}
pos = tell(hfp);
_write(idxfp,&pos,sizeof(long));
if (fgetsx(lineh,513,hfp) == NULL) strcpy(lineh,"\01 END");
line++;
while(*lineh != '\01') {
if (fgetsx(lineh,513,hfp) == NULL) strcpy(lineh,"\01 END");
line++;
}
if(!(x % 5)) {
fputs(itoa(x,s,10),stdout);
putchar('\r');
}
x++;
}
_close(hfp);
_close(idxfp);
return 0;
}
char * pascal fgetsx (char *str,int num,int handle) {
static char *p;
static long pos;
static int x;
if (eof(handle)) {
*str = 0;
return NULL;
}
pos = tell(handle);
x = _read(handle,str,num - 1);
if (x < 1) {
*str = 0;
return NULL;
}
str[x] = 0;
p = str;
while(*p && *p != '\r' && *p != '\n') p++;
if(!*p) return str;
if(*p == '\r') {
*p = '\n';
if (p[1] == '\n') {
p++;
*p = 0;
}
}
p++;
*p = 0;
lseek(handle,pos + ((long)((unsigned int)p - (unsigned int)str)),SEEK_SET);
return str;
}