home *** CD-ROM | disk | FTP | other *** search
- /* Prompt file indexer for XBBS */
-
- #include "stdio.h"
- #include "io.h"
- #include "fcntl.h"
- #include "stdlib.h"
- #include "dir.h"
-
- #define S_IFMT 0170000 /* file type mask */
- #define S_IFDIR 0040000 /* directory */
- #define S_IFCHR 0020000 /* character special */
- #define S_IFREG 0100000 /* regular */
- #define S_IREAD 0000400 /* read permission, owner */
- #define S_IWRITE 0000200 /* write permission, owner */
- #define S_IEXEC 0000100 /* execute/search permission, owner */
-
- static void pascal getline (char *);
- char * pascal fgetsx (char *,int,int);
-
- int fp;
-
- void main (void) {
-
- int idxfp;
- struct ffblk f;
- char lineh[256];
- char s[18];
- register unsigned int x;
- long pos;
-
- if (findfirst ("XBBS.TXT",&f,0)) {
- fputs("\nCan't find XBBS.TXT\n",stdout);
- exit(1);
- }
-
- if (f.ff_fsize<1) {
- fputs("\nXBBS.TXT is null length\n",stdout);
- exit(1);
- }
-
- if ((fp=_open("XBBS.TXT",O_RDONLY | O_TEXT | O_DENYNONE))==-1) {
- fputs("\nCan't open XBBS.TXT\n",stdout);
- exit(1);
- }
-
- unlink("XBBS.IDX");
-
- if ((idxfp=_open("XBBS.IDX",O_RDWR | O_TEXT | O_DENYWRITE))==-1)
- if ((idxfp=creat("XBBS.IDX",S_IWRITE))==-1) {
- fputs("\nCan't open XBBS.IDX\n",stdout);
- exit(1);
- }
-
- fputs("\nIndexing XBBS.TXT...\n",stdout);
-
- getline(lineh);
- x=0;
- while (1) {
- if (strncmp(lineh,"\x1 END",5)==0) break;
- if (*lineh!='\x1') {
- continue;
- }
- pos=tell(fp);
- _write(idxfp,&pos,sizeof(long));
- getline(lineh);
- while(*lineh!='\x1') {
- getline(lineh);
- }
- x++;
- fputs(itoa(x,s,10),stdout);
- fputs(" \r",stdout);
- }
- _close(fp);
- _close(idxfp);
-
- if (findfirst ("XBBS.GXT",&f,0)) {
- fputs("\nCan't find XBBS.GXT\n",stdout);
- exit(0);
- }
-
- if (f.ff_fsize<1) {
- fputs("\nXBBS.GXT is null length\n",stdout);
- exit(0);
- }
-
- if ((fp=_open("XBBS.GXT",O_RDONLY | O_TEXT | O_DENYNONE))==-1) {
- fputs("\nCan't open XBBS.GXT\n",stdout);
- exit(0);
- }
-
- unlink("XBBS.GDX");
-
- if ((idxfp=_open("XBBS.GDX",O_RDWR | O_TEXT | O_DENYWRITE))==-1)
- if ((idxfp=creat("XBBS.GDX",S_IWRITE))==-1) {
- fputs("\nCan't open XBBS.GDX\n",stdout);
- exit(0);
- }
-
- fputs("\nIndexing XBBS.GXT...\n",stdout);
-
- getline(lineh);
- x=0;
- while (1) {
- if (strncmp(lineh,"\x1 END",5)==0) break;
- if (*lineh!='\x1') {
- continue;
- }
- pos=tell(fp);
- _write(idxfp,&pos,sizeof(long));
- getline(lineh);
- while(*lineh!='\x1') {
- getline(lineh);
- }
- x++;
- fputs(itoa(x,s,10),stdout);
- fputs(" \r",stdout);
- }
- _close(fp);
- _close(idxfp);
- }
-
-
- static void pascal getline (char *lineh) {
-
- if (fgetsx(lineh,256,fp)==NULL) strcpy(lineh,"\x1 END");
- }
-
-
-
- char * pascal fgetsx (char *str,int num,int handle) {
-
- static char *p;
- static long pos;
- static long len;
- 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;
- if (!(p=(char *)strchr(str,'\r'))) return str;
- *p='\n';
- if (!p[1]) lseek(handle,1L,SEEK_CUR);
- else {
- p[1]=0;
- len=(long)((int)p-(int)str);
- lseek(handle,pos+len+2L,SEEK_SET);
- }
- return str;
- }
-