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 #pragma ident "@(#) libf/fio/wf90.c 92.4 06/18/99 10:01:44"
00039
00040 #include <stdio.h>
00041 #include <cray/format.h>
00042 #include <cray/nassert.h>
00043 #include "fio.h"
00044 #include "f90io.h"
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 int
00078 _FWF(ControlListType *cilist, iolist_header *iolist, void *stck)
00079 {
00080 register int errf;
00081 register int errn;
00082 register int iost;
00083 register int retval;
00084 register recn_t errarg;
00085 register unum_t unum;
00086 xfer_func *xfunc;
00087 unit *cup;
00088 FIOSPTR css;
00089
00090
00091
00092
00093
00094
00095 assert ( cilist->stksize >= sizeof(struct fiostate)/sizeof(long) );
00096
00097
00098
00099 assert ( cilist->eorflag == 0 );
00100
00101
00102
00103 assert ( cilist->size_spec == NULL );
00104
00105
00106
00107 assert( ! (cilist->advcode != CI_ADVYES && cilist->internal != 0));
00108
00109
00110
00111 assert( ! (cilist->advcode != CI_ADVYES && cilist->fmt == CI_LISTDIR));
00112
00113 css = stck;
00114 errn = 0;
00115 errarg = 0;
00116 retval = IO_OKAY;
00117 xfunc = (cilist->fmt == CI_LISTDIR) ? _ld_write : _wrfmt;
00118
00119 if (iolist->iolfirst == 0) {
00120 cup = css->f_cu;
00121
00122
00123
00124 cup->uflag = (cilist->errflag ? _UERRF : 0) |
00125 (cilist->iostat_spec != NULL ? _UIOSTF : 0);
00126 goto data_transfer;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 errf = (cilist->errflag || cilist->iostatflg);
00136
00137 if (cilist->fmt == CI_LISTDIR)
00138 iost = T_WLIST;
00139 else if (cilist->dflag)
00140 iost = T_WDF;
00141 else
00142 iost = T_WSF;
00143
00144 css->u.fmt.freefmtbuf = 0;
00145 css->u.fmt.freepfmt = 0;
00146 css->u.fmt.tempicp = NULL;
00147
00148
00149
00150 if (cilist->internal) {
00151 STMT_BEGIN(-1, 1, iost, NULL, css, cup);
00152 cup->uft90 = 1;
00153 #if !defined(__mips)
00154 cup->ufcompat = 2;
00155 cup->ufunilist = 0;
00156 cup->ufcomsep = 0;
00157 cup->ufcomplen = 0;
00158 cup->ufrptcnt = 0;
00159 cup->ufnegzero = 1;
00160 #elif defined(_LITTLE_ENDIAN)
00161 cup->ufcompat = 0;
00162 cup->ufunilist = 0;
00163 cup->ufcomsep = 0;
00164 cup->ufcomplen = 0;
00165 cup->ufrptcnt = 0;
00166 cup->ufnegzero = 1;
00167 #else
00168 cup->ufcompat = 4;
00169 cup->ufunilist = 0;
00170 cup->ufcomsep = 0;
00171 cup->ufcomplen = 0;
00172 cup->ufrptcnt = 0;
00173 cup->ufnegzero = 1;
00174 #endif
00175 }
00176 else {
00177 if (cilist->uflag == CI_UNITASTERK)
00178 unum = STDOUT_U;
00179 else
00180 unum = *cilist->unit.wa;
00181
00182 STMT_BEGIN(unum, 0, iost, NULL, css, cup);
00183
00184 if (cup == NULL) {
00185 int stat;
00186
00187 cup = _imp_open( css,
00188 (cilist->dflag ? DIR : SEQ),
00189 FMT,
00190 unum,
00191 errf,
00192 &stat);
00193
00194
00195
00196
00197
00198 if (cup == NULL) {
00199 errn = stat;
00200 goto handle_exception;
00201 }
00202 }
00203 }
00204
00205
00206
00207 assert (cup != NULL);
00208
00209
00210
00211
00212 cup->uflag = (cilist->errflag ? _UERRF : 0) |
00213 (cilist->iostat_spec != NULL ? _UIOSTF : 0);
00214
00215
00216
00217 css->u.fmt.icp = NULL;
00218 css->u.fmt.nonl = 0;
00219
00220
00221
00222 if (cilist->fmt != CI_LISTDIR) {
00223 register int stat;
00224
00225 css->u.fmt.u.fe.fmtbuf = NULL;
00226 css->u.fmt.u.fe.fmtnum = 0;
00227 css->u.fmt.u.fe.fmtcol = 0;
00228 css->u.fmt.u.fe.scale = 0;
00229 css->u.fmt.cplus = 0;
00230
00231 errn = setup_format(css, cup, cilist);
00232
00233 if (errn == 0) {
00234
00235 stat = _is_nonadv(cilist);
00236
00237 if (stat < 0)
00238 errn = FEADVSPC;
00239 }
00240
00241 if (errn != 0)
00242 goto handle_exception;
00243
00244 css->u.fmt.nonadv = stat;
00245 }
00246 else {
00247 css->u.fmt.u.le.ldwinit = 1;
00248 css->u.fmt.nonadv = 0;
00249 }
00250
00251
00252
00253 if (cilist->dflag) {
00254
00255 if (!cup->ok_wr_dir_fmt)
00256 errn = _get_mismatch_error(errf, iost, cup, css);
00257 else {
00258 recn_t recn;
00259
00260 recn = (recn_t) *cilist->rec_spec;
00261 errarg = recn;
00262 errn = _unit_seek(cup, recn, iost);
00263 }
00264
00265 cup->uend = BEFORE_ENDFILE;
00266 cup->ulinecnt = 0;
00267 cup->ulinemax = 0;
00268 cup->ulineptr = cup->ulinebuf;
00269 css->u.fmt.endrec = _dw_endrec;
00270 }
00271 else {
00272
00273 if (!cup->ok_wr_seq_fmt) {
00274 errn = _get_mismatch_error(errf, iost, cup, css);
00275 goto handle_exception;
00276 }
00277
00278 if (cilist->internal) {
00279
00280 cup->ulinecnt = 0;
00281 cup->ulinemax = 0;
00282
00283 css->u.fmt.endrec = _iw_endrec;
00284
00285 if (cilist->uflag == CI_UNITCHAR) {
00286 css->u.fmt.iiae = 1;
00287 css->u.fmt.icp = _fcdtocp(cilist->unit.fcd);
00288 css->u.fmt.icl = _fcdlen (cilist->unit.fcd);
00289 }
00290 else {
00291 DopeVectorType *dv = cilist->unit.dv;
00292 void *newar;
00293 int nocontig = 0;
00294 long extent = 0;
00295 long nbytes = 0;
00296
00297 css->u.fmt.icp = _fcdtocp(dv->base_addr.charptr);
00298 css->u.fmt.icl = _fcdlen (dv->base_addr.charptr);
00299
00300
00301
00302
00303 newar = (void *) NULL;
00304
00305 if (dv->p_or_a && (dv->assoc == 0))
00306 errn = FEUNOTAL;
00307 else
00308 errn = _cntig_chk(dv, &newar, &nocontig,
00309 &extent, &nbytes);
00310 if (errn > 0)
00311 goto handle_exception;
00312
00313 css->u.fmt.iiae = extent;
00314
00315 if (nocontig) {
00316 css->u.fmt.icp = newar;
00317 css->u.fmt.tempicp = newar;
00318 }
00319 }
00320
00321 cup->uldwsize = css->u.fmt.icl;
00322
00323
00324
00325
00326
00327
00328
00329 if (css->u.fmt.icl > cup->urecsize) {
00330
00331 cup->ulinebuf = (long *)realloc(cup->ulinebuf,
00332 sizeof(long) * (css->u.fmt.icl +
00333 1));
00334
00335 if (cup->ulinebuf == NULL)
00336 errn = FENOMEMY;
00337 }
00338
00339 cup->urecsize = css->u.fmt.icl;
00340 cup->ulineptr = cup->ulinebuf;
00341 }
00342 else {
00343
00344 if (cup->uend != BEFORE_ENDFILE) {
00345
00346
00347
00348
00349
00350 if (!cup->umultfil && !cup->uspcproc) {
00351 errn = FEWRAFEN;
00352 goto handle_exception;
00353 }
00354
00355
00356
00357
00358
00359
00360
00361 if ((cup->uend == LOGICAL_ENDFILE) &&
00362 !(cup->uspcproc)) {
00363 struct ffsw fst;
00364
00365 if (XRCALL(cup->ufp.fdc, weofrtn)
00366 cup->ufp.fdc, &fst) < 0) {
00367 errn = fst.sw_error;
00368 goto handle_exception;
00369 }
00370 }
00371
00372 cup->uend = BEFORE_ENDFILE;
00373 }
00374
00375 if (cup->pnonadv && cup->uwrt == 0) {
00376 register int offset;
00377
00378
00379
00380
00381
00382
00383
00384
00385 offset = cup->ulineptr - cup->ulinebuf;
00386 cup->ulinemax = offset + cup->ulinecnt;
00387 cup->ulinecnt = offset;
00388 cup->uflshptr = cup->ulinebuf;
00389 errn = _unit_bksp(cup);
00390
00391 if (errn != 0)
00392 goto handle_exception;
00393 }
00394 else if (cup->pnonadv == 0) {
00395
00396
00397
00398
00399
00400 cup->ulinecnt = 0;
00401 cup->ulinemax = 0;
00402 cup->ulineptr = cup->ulinebuf;
00403 cup->uflshptr = cup->ulinebuf;
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413 if (cup->pnonadv && cilist->fmt == CI_LISTDIR)
00414 errn = _lw_after_nonadv(css, cup,
00415 cup->uldwsize, 0);
00416
00417 css->u.fmt.endrec = _sw_endrec;
00418 cup->pnonadv = css->u.fmt.nonadv;
00419 }
00420 }
00421
00422 if (errn != 0)
00423 goto handle_exception;
00424
00425 css->u.fmt.leftablim = cup->ulineptr;
00426 cup->uwrt = 1;
00427
00428
00429
00430
00431
00432
00433 data_transfer:
00434
00435 assert (cup != NULL);
00436
00437 errn = _xfer_iolist(css, cup, iolist, xfunc);
00438
00439 if (errn != 0)
00440 goto handle_exception;
00441
00442 if (! iolist->iollast)
00443 return (IO_OKAY);
00444
00445
00446
00447
00448
00449
00450 finalization:
00451
00452
00453 assert ( cup != NULL );
00454
00455
00456
00457
00458
00459
00460
00461 if (errn == 0) {
00462 errn = xfunc(css, cup, (void *) NULL, &__tip_null, 0L);
00463
00464 if (errn != 0)
00465 goto handle_exception;
00466
00467 if (css->u.fmt.nonadv)
00468 errn = _nonadv_partrec(css, cup);
00469 else
00470 errn = (*css->u.fmt.endrec)(css, cup, 1);
00471
00472 if (errn != 0)
00473 goto handle_exception;
00474 }
00475
00476 if (cilist->fmt != CI_LISTDIR)
00477 if (css->u.fmt.freepfmt || css->u.fmt.freefmtbuf) {
00478
00479
00480
00481 if (css->u.fmt.freepfmt && css->u.fmt.u.fe.pfmt != NULL)
00482 free(css->u.fmt.u.fe.pfmt);
00483
00484
00485
00486
00487
00488 if (css->u.fmt.freefmtbuf &&
00489 css->u.fmt.u.fe.fmtbuf != NULL)
00490 free(css->u.fmt.u.fe.fmtbuf);
00491 }
00492
00493
00494
00495
00496
00497
00498
00499 if (cilist->internal && css->u.fmt.tempicp != NULL) {
00500 (void) _unpack_arry (css->u.fmt.tempicp, cilist->unit.dv);
00501 free(css->u.fmt.tempicp);
00502 }
00503
00504 out_a_here:
00505
00506
00507
00508 if (cilist->iostat_spec != NULL)
00509 *(cilist->iostat_spec) = errn;
00510
00511 STMT_END(cup, TF_WRITE, NULL, css);
00512
00513
00514
00515 return (retval);
00516
00517
00518
00519
00520
00521
00522 handle_exception:
00523 retval = IO_ERR;
00524
00525 if (! cilist->errflag && ! cilist->iostatflg)
00526 _ferr(css, errn, errarg);
00527
00528 if (cup == NULL)
00529 goto out_a_here;
00530
00531 goto finalization;
00532 }