$save nolist /* *============================================================================ * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE * * Permission to use for any purpose, modify, copy, and make enhancements * and derivative works of the software is granted if attribution is given to * R.M. Gillmore, dba the ACME Software Deli, as the author * * While the ACME Software Deli does not work for money, there is nonetheless * a significant amount of work involved. The ACME Software Deli maintains the * rights to all code written, though it may be used and distributed as long as * the following conditions are maintained. * * 1. The copyright statement at the top of each code block is maintained in * your distribution. * 2. You do not identify yourself as the ACME Software Deli * 3. Any changes made to the software are sent to the ACME Software Deli *============================================================================ */ /* * $Id: fileIO.ext 1157 2025-05-05 00:35:39Z rmgillmore $ */ $if not FILEIO_EXT_INCLUDED $set (FILEIO_EXT_INCLUDED) $include (..\lib\comnDefs.ext) $include (..\lib\sysCalls.ext) /* * standard names for the pre-defined file handles */ declare stdin literally '0', stdout literally '1', stderr literally '2', stdaux literally '3', stdprn literally '4'; declare InsertActive literally '80h', CapsLockActive literally '40h', NumLockActive literally '20h', ScrollLockActive literally '10h', AltKeyActive literally '08h', CtrlKeyActive literally '04h', LeftShiftKeyActive literally '02h', RightShiftKeyActive literally '01h'; $if not keyInSource ci: procedure integer external; end ci; kbhit: procedure boolean external; end kbhit; getch: procedure integer external; end getch; pause: procedure external; end pause; /* * bit # meaning * 7 Insert active * 6 CapsLock active * 5 NumLock active * 4 ScrollLock active * 3 Alt key pressed (either Alt on 101/102-key keyboards) * 2 Ctrl key pressed (either Ctrl on 101/102-key keyboards) * 1 left shift key pressed * 0 right shift key pressed */ keyboardStatus: procedure byte external; end keyboardStatus; $endif $if not charOutSource putch: procedure ( charToWrite ) external; declare charToWrite char; end putch; $endif $if not lfnModule lfnSupported: procedure boolean external; end lfnSupported; $endif $if not flushDiskBufsSource flushDiskBuffers: procedure external; end flushDiskBuffers; $endif $if not fopenSource fopen: procedure ( fileNameString, openTypeString ) word external; declare fileNameString pointer, openTypeString pointer; end fopen; $endif $if not fileHandleValidSource fileHandleValid: procedure ( fileHandle ) boolean external; declare fileHandle word; end fileHandleValid; $endif $if not feofSource feof: procedure ( fileHandle ) boolean external; declare fileHandle word; end feof; $endif $if not fcloseSource fclose: procedure ( fileHandle ) external; declare fileHandle word; end fclose; $endif $if not freadSource fread: procedure ( fileHandle, byteArray, byteArrayLength ) word external; declare fileHandle word, byteArray pointer, byteArrayLength word; end fread; $endif /* * fgets() reads characters from stream and stores them as a string into charArray * until (charArrayLength-1) characters have been read, a newline has been read, * or the end-of-file is reached, whichever happens first. * * A newline character makes fgets() stop reading, but it is considered a valid * character by the function and included in the string copied to charArray. */ $if not fgetsSource fgets: procedure ( fileHandle, charArray, charArrayLength ) pointer external; declare fileHandle word, charArray pointer, charArrayLength word; end fgets; $endif $if not fwriteSource fwrite: procedure ( fileHandle, byteArray, byteArrayLength ) word external; declare fileHandle word, byteArray pointer, byteArrayLength word; end fwrite; $endif /* * with fseek(), to what file position does the offset apply */ declare FROM_END_OF_FILE literally '2', FROM_BEGINNING_OF_FILE literally '0', FROM_CURRENT_POSITION literally '1'; $if not fseekSource fseek: procedure ( fileHandle, seekType, filePosition ) external; declare fileHandle word, seekType byte, filePosition dword; end fseek; $endif $if not ftellSource ftell: procedure ( fileHandle ) dword external; declare fileHandle word; end ftell; $endif $if not printStringSource printString: procedure ( stringPtr, stringLength ) external; declare stringPtr pointer, stringLength word; end printString; printStringAsciiZ: procedure ( stringPtr ) external; declare stringPtr pointer; end printStringAsciiZ; $endif /* * NOTE - NOTE - NOTE * for reasons that are not yet understood, these functions do not work when * called from reentrant procedures ... when I get some more time, that MAY * be something that gets some work * END NOTE * * the printf, cprintf, fprintf, and sprintf procedures are variadic. there * has been a conscious effort to make the interface for these functions as * close to the C counterparts as possible * * printf is called thusly: * call printf( formatString, ... ); * * cprintf is called thusly: * call cprintf( videoAttribute, formatString, ... ); * * fprintf is called thusly: * call fprintf( fileHandle, formatString, ... ); * * sprintf is called thusly: * call sprintf( returnString, formatString, ... ); * * Description of format string formatters * \a - replace with the BELL (ASCII) character * \b - replace with the BACKSPACE (ASCII) character * \f - replace with the FORMFEED (ASCII) character * \n - replace with the new-line sequence (CR/LF) * \r - replace with the CARRIAGE RETURN (ASCII) character * \t - replace with the TAB (ASCII) character * * There are two other ways to insert raw values into a string. The value is * limited to a char (byte) size, and may be specified in one of two ways: * * \0xxx - interpret as octal (the value is interpreted as a maximum of * 3 octal digits following the first zero) * * \hxx - interpret the two digits following the \h as hexadecimal digits * (the case of the hex digit is not significant => A is a, c is C) * * Description of format string modifiers * %x - using as many hex digits as necessary, insert the 16-bit value * %lx - using as many hex digits as necessary, insert the 32-bit value * %bx - using as many hex digits as necessary, insert the 8-bit value * %d - using as many decimal digits as necessary, insert the SIGNED 16-bit value * %ld - using as many decimal digits as necessary, insert the SIGNED 32-bit value * %bd - using as many decimal digits as necessary, insert the SIGNED 8-bit value * %ud - using as many decimal digits as necessary, insert the UNSIGNED 16-bit value * %uld - using as many decimal digits as necessary, insert the UNSIGNED 32-bit value * %ubd - using as many decimal digits as necessary, insert the UNSIGNED 8-bit value * %c - insert the character * %s - insert the NUL terminated string * %p - insert the pointer value * %t - insert the "T"/"F" boolean indicator * %T - insert the "True"/"False" boolean indicator */ $if not sprintfSource declare sprintf pointer external data; $endif $if not fprintfSource declare fprintf pointer external data; $endif $if not cprintfSource declare cprintf pointer external data; $endif $if not printfSource declare printf pointer external data; $endif $endif $restore