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