1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)c_iio.c 5.3 (Berkeley) 04/12/91"; 10 #endif /* not lint */ 11 12 /* 13 * internal (character array) i/o: common portions 14 */ 15 16 #include "fio.h" 17 #include "lio.h" 18 19 LOCAL icilist *svic; /* active internal io list */ 20 LOCAL lio_nl; 21 22 int z_wnew(); 23 24 z_getc() 25 { 26 if(formatted == LISTDIRECTED ) 27 { 28 if( lio_nl == YES ) 29 { 30 recnum++; 31 recpos = 0; 32 } 33 else if (recpos == svic->icirlen) 34 { 35 lio_nl = YES; 36 return('\n'); 37 } 38 lio_nl = NO; 39 } 40 41 if(icptr >= icend && !recpos) /* new rec beyond eof */ 42 { leof = EOF; 43 return(EOF); 44 } 45 if(recpos++ < svic->icirlen) return(*icptr++); 46 return(' '); 47 } 48 49 z_putc(c) char c; 50 { 51 if(icptr < icend) 52 { if(c=='\n') return(z_wnew()); 53 if(recpos++ < svic->icirlen) 54 { *icptr++ = c; 55 return(OK); 56 } 57 else err(errflag,F_EREREC,"iio") 58 } 59 leof = EOF; 60 #ifndef KOSHER 61 err(endflag,EOF,"iio") /* NOT STANDARD, end-of-file on writes */ 62 #endif 63 #ifdef KOSHER 64 err(errflag,F_EREREC,"iio") 65 #endif 66 } 67 68 z_ungetc(ch,cf) char ch; 69 { 70 if( lio_nl == YES ) 71 { 72 lio_nl = NO; 73 return(OK); 74 } 75 if(ch==EOF || --recpos >= svic->icirlen) return(OK); 76 if(--icptr < svic->iciunit || recpos < 0) err(errflag,F_ERBREC,"ilio") 77 *icptr = ch; 78 return(OK); 79 } 80 81 LOCAL 82 c_fi(a) icilist *a; 83 { 84 fmtbuf=a->icifmt; 85 formatted = FORMATTED; 86 external = NO; 87 cblank=cplus=NO; 88 scale=cursor=0; 89 radix = 10; 90 signit = YES; 91 elist = YES; 92 svic = a; 93 recpos=reclen=0; 94 icend = a->iciunit + a->icirnum*a->icirlen; 95 errflag = a->icierr; 96 endflag = a->iciend; 97 return(OK); 98 } 99 100 c_si(a) icilist *a; 101 { 102 sequential = YES; 103 recnum = 0; 104 icptr = a->iciunit; 105 return(c_fi(a)); 106 } 107 108 c_di(a) icilist *a; 109 { 110 sequential = NO; 111 recnum = a->icirec - 1; 112 icptr = a->iciunit + recnum*a->icirlen; 113 return(c_fi(a)); 114 } 115 116 z_rnew() 117 { 118 icptr = svic->iciunit + (++recnum)*svic->icirlen; 119 recpos = reclen = cursor = 0; 120 return(OK); 121 } 122 123 z_wnew() 124 { 125 if(reclen > recpos) 126 { icptr += (reclen - recpos); 127 recpos = reclen; 128 } 129 while(recpos < svic->icirlen) (*putn)(' '); 130 recpos = reclen = cursor = 0; 131 recnum++; 132 return(OK); 133 } 134 135 z_tab() 136 { int n; 137 if(reclen < recpos) reclen = recpos; 138 if((recpos + cursor) < 0) cursor = -recpos; /* to BOR */ 139 n = reclen - recpos; 140 if(!reading && (cursor-n) > 0) 141 { icptr += n; 142 recpos = reclen; 143 cursor -= n; 144 while(cursor--) if(n=(*putn)(' ')) return(n); 145 } 146 else 147 { icptr += cursor; 148 recpos += cursor; 149 } 150 return(cursor=0); 151 } 152 153 c_li(a) icilist *a; 154 { 155 fmtbuf="int list io"; 156 sequential = YES; 157 formatted = LISTDIRECTED; 158 external = NO; 159 elist = YES; 160 svic = a; 161 recnum = recpos = 0; 162 cplus = cblank = NO; 163 lio_nl = NO; 164 icptr = a->iciunit; 165 icend = icptr + a->icirlen * a->icirnum; 166 errflag = a->icierr; 167 endflag = a->iciend; 168 leof = NO; 169 return(OK); 170 } 171