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
00041
00042 #include <cmplrs/fio.h>
00043 #include "cmplrs/host.h"
00044 #include "fmt.h"
00045 #include "iomode.h"
00046 #include "wsfe.h"
00047 #include "wrtfmt.h"
00048 #include "idxio.h"
00049 #include "err.h"
00050 #include "sfe.h"
00051 #include "util.h"
00052 #include "uio.h"
00053 #include "rsfe.h"
00054 #include "bcompat.h"
00055 #include <string.h>
00056
00057 extern int lnblnk_ (char *s, int len);
00058
00059 #if 11
00060 int32 wsfe (cilist64 *a, unit **fu, int f90sw)
00061 #else
00062 int32 wsfe (cilist *a, unit **fu, int f90sw)
00063 #endif
00064 {
00065 int32 n;
00066 unit *ftnunit;
00067
00068 if (!f77init)
00069 f_init ();
00070
00071 if (n = c_sfe (a, fu))
00072 return n;
00073
00074 ftnunit = *fu;
00075 if (ftnunit->uacc == DIRECT)
00076 errret(a->cierr, 171, "sequential write");
00077
00078 ftnunit->f77cursor = ftnunit->f77recpos = ftnunit->f77recend = 0;
00079 ftnunit->f77cplus = 0;
00080 ftnunit->f77scale = 0;
00081 #ifdef I90
00082 ftnunit->f90sw = f90sw;
00083 if (!f90sw) ftnunit->f77recpos = ftnunit->f77recend = 0;
00084
00085
00086 #else
00087 ftnunit->f77recpos = ftnunit->f77recend = 0;
00088 #endif
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->f77fmtbuf = a->cifmt;
00095 if (ftnunit->uacc == KEYED) {
00096 ftnunit->f77idxlist.cimatch = a->cimatch;
00097 ftnunit->f77idxlist.cikeytype = a->cikeytype;
00098 ftnunit->f77idxlist.cikeyval.cicharval = a->cikeyval.cicharval;
00099 ftnunit->f77idxlist.cikeyid = a->cikeyid;
00100 ftnunit->f77idxlist.cinml = a->cinml;
00101 ftnunit->f77idxlist.cikeyvallen = a->cikeyvallen;
00102 }
00103 if (pars_f (ftnunit, ftnunit->f77fmtbuf) < 0)
00104 errret(a->cierr, 100, "startio");
00105 ftnunit->f77putn = x_putc;
00106 ftnunit->f77ungetn = x_ungetc;
00107 ftnunit->f77doed = w_ed;
00108 ftnunit->f77doned = w_ned;
00109 ftnunit->f77doend = xw_end;
00110 ftnunit->f77dorevert = xw_rev;
00111 ftnunit->f77donewrec = x_wSL;
00112 fmt_bg (ftnunit);
00113 ftnunit->f77cblank = ftnunit->ublnk;
00114 if (ftnunit->url > ftnunit->f77fio_size)
00115 check_buflen( ftnunit, ftnunit->url > FIO_ALLOC ? ftnunit->url : FIO_ALLOC );
00116 return 0;
00117 }
00118
00119 #if 11
00120 static int32 s_wsfe_com (cilist64 *a, unit **fu)
00121 #else
00122 static int32 s_wsfe_com (cilist *a, unit **fu)
00123 #endif
00124 {
00125 unit *ftnunit;
00126 int n = wsfe(a, fu, 0);
00127
00128 ftnunit = *fu;
00129 if (n)
00130 return n;
00131 if (ftnunit->uacc != KEYED) {
00132 if (f77nowwriting (ftnunit))
00133 errret(a->cierr, 160, "startwrt");
00134 }
00135
00136 #ifdef I90
00137 ftnunit->f90sw = 0;
00138 ftnunit->f90nadv = 0;
00139 ftnunit->f77recpos = 0;
00140 ftnunit->f77recend = 0;
00141 #endif
00142 ftnunit->dowrite = x_wEND;
00143 return (0);
00144 }
00145
00146 int32 s_wsfe (cilist *a)
00147 {
00148
00149 #if 11
00150 cilist64 dst;
00151 get_cilist64(&dst, a);
00152 return s_wsfe_com(&dst, &f77curunit);
00153 #else
00154 return( s_wsfe_com( a, &f77curunit ) );
00155 #endif
00156 }
00157
00158 int32 s_wsfe_mp (cilist *a, unit **fu)
00159 {
00160 #if 11
00161 cilist64 dst;
00162 get_cilist64(&dst, a);
00163 return s_wsfe_com(&dst, fu);
00164 #else
00165 return( s_wsfe_com( a, fu ) );
00166 #endif
00167 }
00168
00169 #if 11
00170 int s_wsfe64 (cilist64 *a)
00171 {
00172 return( s_wsfe_com( a, &f77curunit ) );
00173 }
00174
00175 int s_wsfe64_mp (cilist64 *a, unit **fu)
00176 {
00177 return( s_wsfe_com( a, fu ) );
00178 }
00179 #endif
00180
00181
00182
00183 int
00184 x_putc (register unit *ftnunit, register XINT count, char con, char *buf)
00185 {
00186 register char *iobuf;
00187 XINT new_size;
00188
00189
00190
00191
00192
00193 if (((new_size = ftnunit->f77recpos + count)) > ftnunit->f77fio_size)
00194 check_buflen( ftnunit, new_size + FIO_ALLOC );
00195
00196 iobuf = ftnunit->f77fio_buf + ftnunit->f77recpos;
00197 ftnunit->f77recpos = new_size;
00198
00199
00200
00201
00202 if (buf)
00203 memcpy (iobuf, buf, count);
00204 else {
00205 if (con)
00206 while (count--)
00207 *(iobuf++) = con;
00208 else if ((count = ftnunit->f77recpos - ftnunit->f77recend) > 0) {
00209 iobuf = ftnunit->f77fio_buf + ftnunit->f77recend;
00210 while (count--)
00211 *(iobuf++) = ' ';
00212 }
00213 }
00214
00215 if (ftnunit->f77recpos > ftnunit->f77recend)
00216 ftnunit->f77recend = ftnunit->f77recpos;
00217 return (0);
00218 }
00219
00220 int32
00221 x_wSL (unit *ftnunit)
00222 {
00223 int rslt;
00224 int nadv = ftnunit->f90nadv;
00225 ftnunit->f90nadv = 0;
00226 rslt = (int)((*ftnunit->dowrite) (ftnunit));
00227 ftnunit->f90nadv = nadv;
00228 return rslt;
00229 }
00230
00231 int32
00232 x_wEND (unit *ftnunit)
00233 {
00234 register char *abuf, cc;
00235 register XINT count;
00236 register int n;
00237
00238 if (ftnunit->uacc == KEYED) {
00239 if (n = idxwrite (ftnunit)) return n;
00240 ftnunit->f77nonl = ftnunit->f77recpos = ftnunit->f77recend = ftnunit->f77cursor = 0;
00241 } else if (ftnunit->ufmt == 2) {
00242 return 0;
00243 } else {
00244 ftnunit->f77recpos = 0;
00245 if (ftnunit->ucc == CC_FORTRAN) {
00246 cc = (char) ((ftnunit->f77recpos < ftnunit->f77recend)
00247 ? ftnunit->f77fio_buf[ftnunit->f77recpos++] : ' ');
00248 switch (cc) {
00249 case '1':
00250 putc ('\f', ftnunit->ufd);
00251 break;
00252 case '0':
00253 putc ('\n', ftnunit->ufd);
00254 case '$':
00255 default:
00256 if (ftnunit->ucchar)
00257 putc (ftnunit->ucchar, ftnunit->ufd);
00258 case '+':
00259 case '\0':
00260 break;
00261 }
00262 }
00263 count = ftnunit->f77recend - ftnunit->f77recpos;
00264 abuf = ftnunit->f77fio_buf + ftnunit->f77recpos;
00265 while (count--)
00266 putc (*abuf++, ftnunit->ufd);
00267 if (ftnunit->ucc == CC_FORTRAN) {
00268 ftnunit->ucchar = '\0';
00269 switch (cc) {
00270 case '+':
00271 default:
00272 if (ftnunit->f77nonl)
00273 break;
00274 case '0':
00275 case '1':
00276 putc ('\r', ftnunit->ufd);
00277 if (ftnunit->ufd == stdout)
00278 fflush (stdout);
00279 ftnunit->ucchar = '\n';
00280 case '$':
00281 case '\0':
00282 break;
00283 }
00284 }
00285 if ( ftnunit->ucc == CC_LIST
00286 && !ftnunit->f77nonl
00287 #ifdef I90
00288 && ftnunit->f90nadv == 0
00289 #endif
00290 ) putc ('\n', ftnunit->ufd);
00291
00292 ftnunit->f77nonl = ftnunit->f77recpos = ftnunit->f77recend = 0;
00293 #ifdef I90
00294 if (ftnunit->f90nadv == 0) {
00295 ftnunit->f77cursor = 0;
00296 }
00297 #else
00298 ftnunit->f77cursor = 0;
00299 #endif
00300
00301 if (ftnunit->ufd && ferror (ftnunit->ufd))
00302 return errno;
00303 else
00304 return 0;
00305 }
00306 return 0;
00307 }
00308
00309 int32
00310 xw_end (unit *ftnunit)
00311 {
00312 int n =(*ftnunit->dowrite)(ftnunit);
00313
00314 return n == 1 ? 0 : n;
00315 }
00316
00317 int32
00318 xw_rev (unit *ftnunit)
00319 {
00320 if (ftnunit->f77workdone)
00321 x_wSL (ftnunit);
00322 return ((int) (ftnunit->f77workdone = 0));
00323 }