/****************************************************************************** * * * sortfile.c version 1.0 of 1 Januari 1989 (C) L.J.M. de Wit 1989 * * * * This software may be used and distributed freely if not used commercially * * and the originator (me) is mentioned in the source (just leave this 9 line * * header intact). * * * ****************************************************************************** * * sortfile.c: stdio replacement for Atari ST * * This replacement is added both to speed up the normal stdio offered by * Lattice C, and to repair a bug with open() (fopen() ?) that is in the * standard library (version 3.03: try opening & closing 20 files, your * program bombs when you try to open a new file, even though the old ones * have been closed). * * Note that this package is not complete (no flushbuf, filbuf, printf etc.) * but this wasn't the intent anyway; furthermore, the allocation of buffers * takes place when a file is opened, rather than when it is first read/written * (as in a standard stdio package). */ #include #include #include #include "sortmain.h" #include "sortfile.h" #undef Fwrite #define Fwrite fixwrite /* Fix for Fwrite bug */ static int buflen; /* Default buffer length */ static int lopen(); static int fixwrite(); #ifdef BESTIO void bestio(size) /* Initializes stdin/stdout */ int size; { char *iobuffer[2]; /* stdin/stdout buffer ptrs */ buflen = size; iobuffer[0] = (char *)Malloc(buflen); iobuffer[1] = (char *)Malloc(buflen); if (iobuffer[0] == (char *)-1 || iobuffer[1] == (char *)-1) { error("memory allocation failed\n",(char *)0); } stdin->_ptr = stdin->_base = iobuffer[0]; stdin->_rcnt = buflen; stdin->_flag = _IOREAD; stdin->_file = 0; stdin->_size = buflen; stdout->_ptr = stdout->_base = iobuffer[1]; stdout->_wcnt = buflen; stdout->_flag = _IOWRT; stdout->_file = 1; stdout->_size = buflen; } void exit(code) /* Replaces standard exit */ int code; { int i; for (i = 0; i < _NFILE; i++) { if (_iob[i]._flag != 0) { /* Stclose any open files */ stclose(_iob+i); } } _exit(code); /* and _exit */ } #else NOT BESTIO int _fmode = 0x8000; /* No translation, for speed*/ #endif BESTIO FILE *stopen(filename,mode) /* Replaces fopen() */ char *filename, *mode; { FILE *fp; /ÏÏςωˆ @pÏÏÏςψŽ@pÏÏÏςς@pðÏÏÏψ€ÏÂOÀOÇÀO‚OÁÏ€,BSNËà‘eeIð ù /* Find first free entry */ if (_iob[i]._flag == 0) { break; } } if (i < _NFILE) { /ÏÀè ô Τ í,™ø ðH ùùùùùùùùùùùùùùùùùùùùùùùùùøó@€9ñ‘ ùùùùùùùùùùùùùùøùùùð ñ0 ðùùùùùùùð‘0øsB3 øHø ùùùùùùùùùùùùùùùùùùùùùùøóÀ09ð€ðVB¢ð¢Р¢ Œü<à@HÀ|8˜„ÈÌ$$øüüüüüüüüüüüüüüüüüüüü ù˜„üÈÌ øH „üüüüüüüüüü  üüüüüüüø˜€@Äüøx€ 8ˆ €à„I  ÀIàH Ä$ üüüüüüüøˆà„üø!H üüüøø€@„ø 1A ›£“kCk{#)a‘IIÙece,buf); } return total; }