http://www.ousob.com --- Legacy Redefined #include <stdio.h> #include <stdlib.h> #include <string.h> #include <io.h> #include <extend50.h> #define open _topen #define close _tclose #define lseek _tlseek #define read _tread #define write _twrite #define create _tcreat extern int _topen( char*, int); extern int _tclose( int ); extern long _tlseek( int, long, int); extern int _tread( int, char*, int); extern int _twrite( int, char*, int); extern int _tcreat( char*, int); #define O_WRONLY 0x0001 /* open for writing only */ #define O_RDWR 0x0002 /* open for reading and writing */ #define O_APPEND 0x0008 /* writes done at eof */ #define O_RDONLY 0x0000 /* open for reading only */ #define O_BINARY 0x8000 /* file mode is binary (untranslated) */ #define O_TEXT 0x4000 /* file mode is text (translated) */ #define O_CREAT 0x0100 /* create and open file */ #define O_TRUNC 0x0200 /* open and truncate */ #define O_EXCL 0x0400 /* open only if file doesn't already exist */ #define SH_COMPAT 0x00 /* compatibility mode */ #define SH_DENYRW 0x10 /* deny read/write mode */ #define SH_DENYWR 0x20 /* deny write mode */ #define SH_DENYRD 0x30 /* deny read mode */ #define SH_DENYNO 0x40 /* deny none mode */ #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 */ #define WORD unsigned int #define BYTE unsigned char #define DOUBLE_WORD long CLIPPER b_search() { char buffr[2048]; char *rslt; char *rslt2; long recNumber = 0; int bytesRead = 0; int handle = 0; BYTE idByte = 0; DOUBLE_WORD numRecs = 0; WORD lenOfRecStru = 0; WORD recLength = 0; long fileSize = 0; char *theDbf = _parc(1); char *lookFor = _parc(2); if( PCOUNT != 2 && !ISCHAR(1) && !ISCHAR(2) ){ _retni(-1); /* wrong parameters */ return; } if( (handle = open(theDbf, O_BINARY | O_RDONLY | SH_DENYNO)) == -1 ){ _retni(-2); /* unable to open/ find file */ return; } read(handle,(char *)&idByte,1); if( (idByte != 0x03) && (idByte != 0x83) ){ close(handle); _retni(-3); /* not a database file */ return; } lseek(handle,0L,SEEK_END); fileSize = tell(handle); lseek(handle,4L,SEEK_SET); read(handle,(char *)&numRecs,4); /* 4 - 7 */ read(handle,(char *)&lenOfRecStru,2); /* 8 - 9 */ read(handle,(char *)&recLength,2); /* 10 - 11 */ if( ((fileSize - lenOfRecStru) / recLength) != numRecs ){ close(handle); _retni(-4); /* record count does not match file size */ return; } lseek(handle,(long)lenOfRecStru,SEEK_SET); do{ buffr[0] = NULL; bytesRead = read(handle,buffr,recLength); recNumber++; buffr[bytesRead] = NULL; if( (rslt = strstr(buffr,lookFor)) != NULL ){ /* text found */ break; } }while( !eof(handle) ); close(handle); _retnl(recNumber); }