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 <stdio.h>
00041 #include <cmplrs/fio.h>
00042 #include "fmt.h"
00043 #include "iomode.h"
00044 #include "vmsflags.h"
00045 #include "idxio.h"
00046 #include "rsfe.h"
00047 #include "rdfmt.h"
00048 #include "err.h"
00049 #include "uio.h"
00050 #include "sfe.h"
00051 #include "util.h"
00052 #include "bcompat.h"
00053 #include <string.h>
00054
00055 #define NOADVANCE_AT_REV 2
00056
00057 extern int lnblnk_ (char *s, int len);
00058
00059 static
00060 #if 11
00061 int s_rsfe_com (cilist64 *a, unit **fu)
00062 #else
00063 int s_rsfe_com (cilist *a, unit **fu)
00064 #endif
00065 {
00066 int n;
00067 unit *ftnunit;
00068
00069 if (!f77init)
00070 f_init ();
00071 if (n = c_sfe (a, fu))
00072 return (n);
00073 ftnunit = *fu;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 if (ftnunit->ufd == stdout && isatty (fileno (ftnunit->ufd)))
00088 errret(a->cierr, 173, "startio");
00089 ftnunit->f77errlist.cierr = a->cierr;
00090 ftnunit->f77errlist.ciend = a->ciend;
00091 ftnunit->f77errlist.cieor = a->cieor;
00092 ftnunit->f77errlist.cisize = a->cisize;
00093 ftnunit->f77errlist.iciunit = 0;
00094 ftnunit->f77scale = 0;
00095 ftnunit->f77fmtbuf = a->cifmt;
00096 if (ftnunit->uacc == KEYED) {
00097 ftnunit->f77idxlist.cimatch = a->cimatch;
00098 ftnunit->f77idxlist.cikeytype = a->cikeytype;
00099 ftnunit->f77idxlist.cikeyval.cicharval = a->cikeyval.cicharval;
00100 ftnunit->f77idxlist.cikeyid = a->cikeyid;
00101 ftnunit->f77idxlist.cinml = a->cinml;
00102 ftnunit->f77idxlist.cikeyvallen = a->cikeyvallen;
00103 }
00104 else {
00105 if (ftnunit->uacc == DIRECT)
00106 errret(a->cierr, 171, "sequential read");
00107 if (ftnunit->ualias->ucc == CC_FORTRAN &&
00108 ftnunit->ualias->ucchar) {
00109 putc (ftnunit->ualias->ucchar, ftnunit->ualias->ufd);
00110 ftnunit->ualias->ucchar = '\0';
00111 } else if (ftnunit->ucc == CC_FORTRAN && ftnunit->ucchar) {
00112 putc (ftnunit->ucchar, ftnunit->ufd);
00113 ftnunit->ucchar = '\0';
00114 }
00115 }
00116 #ifdef I90
00117 ftnunit->f90sw = 0;
00118 ftnunit->f90nadv = 0;
00119 #endif
00120 if (pars_f (ftnunit, ftnunit->f77fmtbuf) < 0)
00121 errret(a->cierr, 100, "startio");
00122 ftnunit->f77getn = x_getc;
00123 ftnunit->f77gets = x_gets;
00124 ftnunit->f77ungetn = x_ungetc;
00125 ftnunit->f77doed = rd_ed;
00126 ftnunit->f77doned = rd_ned;
00127 fmt_bg (ftnunit);
00128 ftnunit->f77doend = x_endp;
00129 ftnunit->f77donewrec = xrd_SL;
00130 ftnunit->f77dorevert = x_rev;
00131 ftnunit->f77cblank = ftnunit->ublnk;
00132 ftnunit->f77cplus = 0;
00133
00134 if (ftnunit->ufd == stdin && feof (ftnunit->ufd) && f77vms_flag_[VMS_IN])
00135 clearerr(ftnunit->ufd);
00136 (void) f77nowreading (ftnunit);
00137 check_buflen( ftnunit, ftnunit->url > FIO_ALLOC ? ftnunit->url : FIO_ALLOC );
00138
00139 #ifdef I90
00140 if (ftnunit->uaction == WRITEONLY )
00141 errret(ftnunit->f77errlist.cierr,180,"startread");
00142 ftnunit->f77recpos = 0;
00143 ftnunit->f77recend = 0;
00144 #endif
00145
00146 n = xrd_SL (ftnunit);
00147 if (n > 0) {
00148 errret(a->cierr, n, "s_rsfe");
00149 } else if (n < 0) {
00150 errret(a->ciend, n, "s_rsfe");
00151 } else
00152 return(0);
00153 }
00154
00155 int
00156 s_rsfe (cilist *a)
00157 {
00158 #if 11
00159 cilist64 dst;
00160 get_cilist64(&dst, a);
00161 return s_rsfe_com(&dst, &f77curunit);
00162 #else
00163 return( s_rsfe_com( a, &f77curunit) );
00164 #endif
00165 }
00166
00167
00168 int
00169 s_rsfe_mp (cilist *a, unit **fu)
00170 {
00171 #if 11
00172 cilist64 dst;
00173 get_cilist64(&dst, a);
00174 return s_rsfe_com(&dst, fu);
00175 #else
00176 return( s_rsfe_com( a, fu) );
00177 #endif
00178 }
00179
00180 #if 11
00181
00182 int
00183 s_rsfe64 (cilist64 *a)
00184 {
00185 return( s_rsfe_com( a, &f77curunit) );
00186 }
00187
00188 int
00189 s_rsfe64_mp (cilist64 *a, unit **fu)
00190 {
00191 return( s_rsfe_com( a, fu) );
00192 }
00193
00194 #endif
00195
00196
00197 int
00198 xrd_SL (unit *ftnunit)
00199 {
00200 int n;
00201
00202
00203 if (ftnunit->uacc == KEYED) {
00204 if (n = idxread(ftnunit))
00205 return n;
00206 } else {
00207 if (ftnunit->ufmt == 2) {
00208 if (fread ((char *) &ftnunit->f77recend, sizeof (int), 1, ftnunit->ufd) != 1) {
00209 clearerr(ftnunit->ufd);
00210 return (errno);
00211 }
00212
00213 check_buflen (ftnunit, ftnunit->f77recend + (int) sizeof(int));
00214 if (fread (ftnunit->f77fio_buf, ftnunit->f77recend + sizeof (int), 1, ftnunit->ufd) != 1) {
00215 clearerr(ftnunit->ufd);
00216 return (errno);
00217 }
00218 ftnunit->f77cursor = ftnunit->f77recpos = 0;
00219 return (0);
00220 }
00221
00222 #ifdef I90
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 if (ftnunit->f90nadv != NOADVANCE_AT_REV) {
00233 #endif
00234 ftnunit->f77recend = 0;
00235 while ((n = getc (ftnunit->ufd)) != EOF && n != '\n') {
00236 ftnunit->f77fio_buf[ftnunit->f77recend] = (char) n;
00237 if (++ftnunit->f77recend == ftnunit->f77fio_size)
00238 ftnunit->f77fio_buf = realloc (ftnunit->f77fio_buf, ftnunit->f77fio_size += FIO_ALLOC);
00239 }
00240 #ifdef I90
00241 }
00242 #endif
00243 ftnunit->f77fio_buf[ftnunit->f77recend] = '\0';
00244 if (n == EOF && ftnunit->f77recend == 0) {
00245 ftnunit->uend = 1;
00246 return (EOF);
00247 }
00248 }
00249 ftnunit->f77cursor = ftnunit->f77recpos = 0;
00250 return (0);
00251 }
00252
00253 int
00254 x_ungetc (unit *ftnunit, int i)
00255 {
00256 ftnunit->f77recpos--;
00257 return (i);
00258 }
00259
00260 int
00261 x_gets (unit *ftnunit, char *s, int w, char c)
00262 {
00263 register int n;
00264 register char *t;
00265
00266
00267
00268 if (ftnunit->uend && !ftnunit->uistty)
00269 return (EOF);
00270 if (f77vms_flag_[VMS_EF] && ftnunit->f77recend == 1 && ftnunit->f77fio_buf[0] == '\032')
00271 return (EOF);
00272 n = ftnunit->f77recend - ftnunit->f77recpos;
00273 t = ftnunit->f77fio_buf + ftnunit->f77recpos;
00274 w = n < w ? n : w;
00275 if (ftnunit->ufmt == 2) {
00276 memcpy (s, t, w);
00277 ftnunit->f77recpos += w;
00278 return (w);
00279 } else
00280 for (n = 0; n < w; n++) {
00281 if (*t == c) {
00282 ftnunit->f77recpos++;
00283 break;
00284 }
00285 *(s++) = *(t++);
00286 }
00287 ftnunit->f77recpos += n;
00288 return (n);
00289 }
00290
00291 int
00292 x_getc (unit *ftnunit)
00293 {
00294 if (f77vms_flag_[VMS_EF] && ftnunit->f77recend == 1 && ftnunit->f77fio_buf[0] == '\032')
00295 return (EOF);
00296 if (ftnunit->f77recpos < ftnunit->f77recend)
00297 return (ftnunit->f77fio_buf[ftnunit->f77recpos++]);
00298 return ((int)'\n');
00299 }
00300
00301 int
00302 x_endp (unit *ftnunit)
00303 {
00304 #ifdef I90
00305 if (ftnunit->f90sw)
00306 if (ftnunit->f90nadv == 0 || ftnunit->f90eor != 0 ) {
00307 ftnunit->f77recpos = ftnunit->f77cursor = ftnunit->f77recend = 0;
00308 }
00309 #endif
00310 return (0);
00311 }
00312
00313 int
00314 x_rev (unit *ftnunit)
00315 {
00316 int n;
00317 int save_f90nadv = ftnunit->f90nadv;
00318 XINT save_recpos = ftnunit->f77recpos;
00319
00320 if (ftnunit->f90nadv) ftnunit->f90nadv = NOADVANCE_AT_REV;
00321 n = xrd_SL(ftnunit);
00322 if (save_f90nadv) {
00323 ftnunit->f90nadv = save_f90nadv;
00324 ftnunit->f77recpos = save_recpos;
00325 }
00326 return n;
00327 }