/* =====> SIN_OUT.C */ /* TIPC Scheme '84 Runtime Support - File Input/Output Support (C) Copyright 1985 by Texas Instruments Incorporated. All rights reserved. Author: John C. Jensen Installation: Texas Instruments Incorporated, Dallas, Texas Division: Central Research Laboratories Cost Center: Computer Science Laboratory Project: Computer Architecture Branch Date Written: 4 February 1985 Last Modification: 14 Jan 1987 - dbs Modified to allow for random i/o. 16 Mar 1987 - tc Dos I/O errors call DOS-ERR now. */ #include "scheme.h" #include "sport.h" #include "slist.h" #define FILE_NOT_FOUND 2 /* MS-DOS error code */ #define NON_RESTART 1 /* Operation not restartable */ char *getmem(); /* Lattice C's memory allocation support */ /************************************************************************/ /* Open a Port */ /************************************************************************/ spopen(file, mode) int file[2]; /* pathname, 'console, nil, or # */ int mode[2]; /* 'read, 'write, 'append */ { extern int prn_handle;/* handle assigned to printer *** JHAO ***/ /*%%char buffer[BUFFSIZE];/* read buffer for positioning at end of file */*/ int direction; /* 'read, 'write, 'append code */ int disp; /* displacement component of a pointer */ int handle; /* handle assigned to file by open */ int hsize; /* high word of file size - dbs */ int lsize; /* low word of file size - dbs */ int i; /* our old favorite index variable */ int len; /* length of file's pathname (plus 1) */ /*%%int length; /* number of characters read */*/ int page; /* page number component of a pointer */ int p_flags; /* port flags */ int retstat = 0; /* the return status */ int stat; /* status returned from open request */ char *string; /* file pathname buffer pointer */ float fsize; /* file size - dbs */ ENTER(spopen); /* identify mode value */ if ((direction = get_mode(mode)) == -1) goto src_err; page = CORRPAGE(file[C_PAGE]); disp = file[C_DISP]; switch(ptype[page]) { case STRTYPE*2: len = get_word(page, disp+1); if (len < 0) /* Adjust for small string */ len = len + BLK_OVHD; else len = len - BLK_OVHD; if (!(string = getmem(len+1))) getmem_error(rtn_name); get_str(string, page, disp); string[len] = '\0'; for (i=0; i