00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <cmplrs/fio.h>
00041 #include <mutex.h>
00042 #include <string.h>
00043 #include "fmt.h"
00044 #include "vmsflags.h"
00045 #include "iio.h"
00046 #include "iomode.h"
00047 #include "err.h"
00048 #include "wrtfmt.h"
00049
00050 extern vfmt_struct f77vfmt_com_;
00051 extern char *icptr, *icend;
00052
00053 int
00054 z_ungetc (unit *ftnunit, int ch)
00055 {
00056 if (ch != '\n') {
00057 if (icptr <= ftnunit->f77errlist.iciunit)
00058 return (-1);
00059 icptr--;
00060 ftnunit->f77recpos--;
00061 icpos--;
00062 } else {
00063 if (icnum > 0)
00064 icnum--;
00065 icpos = ftnunit->f77errlist.icirlen;
00066 }
00067 return (0);
00068 }
00069
00070 int
00071 z_getc (unit *ftnunit)
00072 {
00073 if (icptr >= icend && icpos == 0)
00074 err (ftnunit->f77errlist.ciend, (EOF), "endfile");
00075 if (icpos++ < ftnunit->f77errlist.icirlen) {
00076 ftnunit->f77recpos++;
00077 return (*icptr++);
00078 } else {
00079 z_rnew (ftnunit);
00080 return ('\n');
00081 }
00082 }
00083
00084 int
00085 z_gets (unit *ftnunit, char *s, int w, char c)
00086 {
00087 register int n;
00088
00089
00090
00091
00092
00093
00094 n = ftnunit->f77errlist.icirlen - ftnunit->f77recpos;
00095 w = n < w ? n : w;
00096 for (n = 0; n < w; n++) {
00097
00098 if (*icptr == c && c != '\n') {
00099 icptr++;
00100 ftnunit->f77recpos++;
00101 break;
00102 }
00103 *(s++) = *(icptr++);
00104 }
00105 ftnunit->f77recpos += n;
00106 return (n);
00107 }
00108
00109 int
00110 z_putc (unit *ftnunit, XINT count, char con, char *buf)
00111 {
00112 register XINT i = count;
00113
00114 if ((icptr + count) > icend)
00115 err (ftnunit->f77errlist.cierr, 110, "inwrite");
00116 if (buf) {
00117 memcpy (icptr, buf, count);
00118 icptr += count;
00119 } else {
00120 if (con == '\n') {
00121 while (i--) z_wnew (ftnunit);
00122 return(0);
00123 } else if (con) {
00124 while (i--) *(icptr++) = con;
00125 } else if ((ftnunit->f77recpos + count) > ftnunit->f77recend) {
00126 icptr += (ftnunit->f77recend - ftnunit->f77recpos);
00127 i -= (ftnunit->f77recend - ftnunit->f77recpos);
00128 while (i--) *(icptr++) = ' ';
00129 }
00130 else icptr += count;
00131 }
00132
00133 if ((icpos += count) > ftnunit->f77errlist.icirlen)
00134 ftnunit->f77recend = ftnunit->f77cursor = ftnunit->f77recpos = icpos = icpos % ftnunit->f77errlist.icirlen;
00135 else if ((ftnunit->f77recpos += count) > ftnunit->f77recend)
00136 ftnunit->f77recend = ftnunit->f77recpos;
00137 return 0;
00138 }
00139
00140 int
00141 z_wnew (unit *ftnunit)
00142 {
00143 while (icpos < ftnunit->f77errlist.icirlen && icptr < icend) {
00144 *icptr++ = ' ';
00145 icpos++;
00146 }
00147 icptr = ftnunit->f77errlist.iciunit + (++icnum) * ftnunit->f77errlist.icirlen;
00148 ftnunit->f77cursor = ftnunit->f77recpos = ftnunit->f77recend = icpos = 0;
00149 return (0);
00150 }
00151
00152 int
00153 z_rnew (unit *ftnunit)
00154 {
00155 icptr = ftnunit->f77errlist.iciunit +
00156 (++icnum) * ftnunit->f77errlist.icirlen;
00157 ftnunit->f77cursor = ftnunit->f77recpos = icpos = 0;
00158 return 0;
00159 }
00160
00161 int s_wsfi (icilist *a)
00162 {
00163 return( s_wsfi_mp( a, &f77curunit ) );
00164 }
00165
00166 #if 11
00167 int s_wsfi64 (icilist64 *a)
00168 {
00169 return( s_wsfi64_mp( a, &f77curunit ) );
00170 }
00171
00172 int s_wsfi_mp (icilist *a, unit** fu)
00173 {
00174 icilist64 a64;
00175 a64.icierr = a->icierr;
00176 a64.iciunit = a->iciunit;
00177 a64.iciend = a->iciend;
00178 a64.icifmt = a->icifmt;
00179 a64.icirlen = a->icirlen;
00180 a64.icirnum = a->icirnum;
00181 return( s_wsfi64_mp( &a64, fu ) );
00182 }
00183
00184 int s_wsfi64_mp (icilist64 *a, unit** fu)
00185 #else
00186 int s_wsfi_mp (icilist *a, unit** fu)
00187 #endif
00188 {
00189 int n;
00190 unit *ftnunit;
00191
00192 if (!f77init)
00193 f_init ();
00194 ftnunit = *fu = Internal_File;
00195
00196 while (fu != &f77curunit && test_and_set( &ftnunit->lock_unit, 1L ))
00197 ;
00198 #ifdef I90
00199 ftnunit->f90sw = 0;
00200 #endif
00201 if (n = c_si (a, ftnunit)) {
00202 return (n);
00203 }
00204 ftnunit->uwrt |= WR_OP;
00205 ftnunit->f77doed = w_ed;
00206 ftnunit->f77doned = w_ned;
00207 ftnunit->f77putn = z_putc;
00208 ftnunit->f77ungetn = z_ungetc;
00209 ftnunit->f77donewrec = z_wSL;
00210 ftnunit->f77dorevert = ftnunit->f77doend = z_wnew;
00211 return (0);
00212 }
00213
00214 #if 11
00215 int
00216 c_si (icilist64 *a, unit *ftnunit)
00217 #else
00218 int
00219 c_si (icilist *a, unit *ftnunit)
00220 #endif
00221 {
00222 ftnunit->f77fmtbuf = a->icifmt;
00223 if (f77vfmt_com_.PFI != NULL) {
00224
00225
00226
00227
00228
00229
00230 ftnunit->vfmt = f77vfmt_com_.PFI;
00231 ftnunit->vfmtfp = f77vfmt_com_.static_link;
00232 } else {
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 ftnunit->vfmt = a->icivfmt;
00249 ftnunit->vfmtfp = a->icivfmtfp;
00250 }
00251 ftnunit->f77cblank = ftnunit->f77cplus = ftnunit->f77scale = 0;
00252 ftnunit->f77errlist.cierr = a->icierr;
00253 ftnunit->f77errlist.ciend = a->iciend;
00254 ftnunit->f77errlist.cieor = 0;
00255 ftnunit->f77errlist.cisize = 0;
00256 ftnunit->f77errlist.iciunit = a->iciunit;
00257 ftnunit->f77errlist.icirlen = a->icirlen;
00258 ftnunit->f77errlist.icirnum = a->icirnum;
00259 ftnunit->f77errlist.iciunit = a->iciunit;
00260 ftnunit->f77recpos = ftnunit->f77recend = icnum = icpos = 0;
00261 if (pars_f (ftnunit, ftnunit->f77fmtbuf) < 0)
00262 errret(a->icierr, 100, "startint");
00263 fmt_bg (ftnunit);
00264 icptr = ftnunit->f77errlist.iciunit;
00265 icend = icptr + ftnunit->f77errlist.icirlen * ftnunit->f77errlist.icirnum;
00266 return (0);
00267 }
00268
00269 int
00270 z_rSL (unit *ftnunit)
00271 {
00272 z_rnew (ftnunit);
00273 return (0);
00274 }
00275
00276 int
00277 z_wSL (unit *ftnunit)
00278 {
00279 z_wnew (ftnunit);
00280 return (0);
00281 }
00282
00283 #pragma weak e_rsfi64 = e_rsfi
00284
00285 int e_rsfi ()
00286 {
00287 return( e_rsfi_mp( &f77curunit ) );
00288 }
00289
00290 #pragma weak e_rsfi64_mp = e_rsfi_mp
00291
00292 int e_rsfi_mp (unit **fu)
00293 {
00294 int n;
00295
00296 n = en_fio (fu);
00297
00298 (*fu)->lock_unit = 0;
00299 return (0);
00300 }
00301
00302 #pragma weak e_wsfi64 = e_wsfi
00303
00304 int e_wsfi ()
00305 {
00306 return( e_wsfi_mp( &f77curunit ) );
00307 }
00308
00309 #pragma weak e_wsfi64_mp = e_wsfi_mp
00310
00311 int e_wsfi_mp (unit **fu)
00312 {
00313 int n;
00314
00315 n = en_fio (fu);
00316
00317
00318
00319
00320
00321
00322 (*fu)->lock_unit = 0;
00323 return (n);
00324 }
00325
00326 int
00327 y_ierr (unit *ftnunit)
00328 {
00329 err (ftnunit->f77errlist.cierr, 110, "iio");
00330 }