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/fwwd.c 92.3 09/29/99 19:50:24"
00039
00040 #include <errno.h>
00041 #include <fortran.h>
00042 #include <liberrno.h>
00043 #include <cray/nassert.h>
00044 #include "fio.h"
00045 #ifdef _ABSOFT
00046 #include "ac_sysdep.h"
00047 #else
00048
00049 #if defined(_LITTLE_ENDIAN) && !defined(__sv2)
00050 #ifndef FILE_FLAG
00051 #define FILE_FLAG(__f) (__f)->_flags
00052 #endif
00053
00054 #ifndef IOREAD
00055 #define IOREAD = _IO_CURRENTLY_APPENDING
00056 #endif
00057 #ifndef IORW
00058 #define IORW = _IO_TIED_PUTGET
00059 #endif
00060
00061 #else
00062
00063
00064 #ifndef FILE_FLAG
00065 #define FILE_FLAG(__f) (__f)->_flag
00066 #endif
00067
00068 #endif
00069 #endif
00070
00071 #define TBFSZ (4096 * sizeof(long))
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 long
00089 _fwwd(
00090 unit *cup,
00091 void *uda,
00092 type_packet *tip,
00093 int mode,
00094 int *ubcret,
00095
00096
00097
00098 long *unused_6,
00099 int *status)
00100 {
00101 register int buflim;
00102 register int fdsize;
00103 register int padbyts;
00104 register long elsize;
00105 register long items;
00106 register ftype_t type;
00107 register size_t breq;
00108 register ssize_t ret;
00109 int padubc;
00110 int padval;
00111 int ubc;
00112 FILE *fptr;
00113
00114
00115
00116 #ifdef _UNICOS
00117 assert ( _numargs() == 7);
00118 #endif
00119 assert ( mode == FULL || mode == PARTIAL );
00120 assert ( tip != NULL );
00121 assert ( status != NULL );
00122
00123
00124
00125
00126
00127
00128 if (cup->uend && !cup->umultfil) {
00129 errno = FEWRAFEN;
00130 return(IOERR);
00131 }
00132
00133 type = tip->type90;
00134 elsize = tip->elsize;
00135 items = tip->count;
00136 breq = elsize * items;
00137 padbyts = 0;
00138 padubc = 0;
00139 ubc = 0;
00140
00141 if (ubcret != NULL) {
00142
00143 if ((*ubcret % 8) != 0 && cup->ufs != FS_FDC) {
00144 errno = FEUBCINV;
00145 return (IOERR);
00146 }
00147
00148 if (type != DVTYPE_TYPELESS) {
00149 errno = FEINTUNK;
00150 return (IOERR);
00151 }
00152
00153
00154
00155 breq = breq - (*ubcret >> 3);
00156 ubc = *ubcret % 8;
00157 }
00158 #if NUMERIC_DATA_CONVERSION_ENABLED
00159 else {
00160
00161
00162
00163
00164
00165
00166 if ((cup->urecpos & cup->ualignmask) != 0 &&
00167 type != DVTYPE_ASCII &&
00168 items > 0 &&
00169 #if defined(__mips) || defined(_LITTLE_ENDIAN)
00170 elsize > 2 )
00171 #else
00172 elsize > 4 )
00173 #endif
00174 COMPADD(cup, padbyts, padubc, padval);
00175 }
00176 #endif
00177
00178 cup->ulastyp = type;
00179
00180 if (mode == FULL) {
00181 cup->ulastyp = DVTYPE_TYPELESS;
00182 cup->urecpos = 0;
00183 }
00184
00185
00186
00187
00188 *status = CNT;
00189
00190 switch ( cup->ufs ) {
00191
00192 case FS_FDC:
00193
00194
00195
00196
00197
00198 if (cup->uend == LOGICAL_ENDFILE) {
00199 if (XRCALL(cup->ufp.fdc, weofrtn)cup->ufp.fdc,
00200 &cup->uffsw) < 0){
00201 errno = cup->uffsw.sw_error;
00202 return(IOERR);
00203 }
00204 }
00205
00206 cup->uend = BEFORE_ENDFILE;
00207
00208
00209
00210 if (items == 0) {
00211 if (mode == FULL) {
00212 long end;
00213
00214 ret = XRCALL(cup->ufp.fdc, writertn)
00215 cup->ufp.fdc,
00216 CPTR2BP(&end), 0, &cup->uffsw,
00217 mode, &ubc);
00218
00219 if (ret < 0) {
00220 errno = cup->uffsw.sw_error;
00221 return(IOERR);
00222 }
00223
00224 *status = EOR;
00225 }
00226
00227
00228
00229 return(EOR);
00230 }
00231
00232
00233
00234 if (padbyts > 0) {
00235
00236 ret = XRCALL(cup->ufp.fdc, writertn) cup->ufp.fdc,
00237 CPTR2BP(&padval),
00238 padbyts, &cup->uffsw, PARTIAL, &padubc);
00239
00240 if (ret < 0) {
00241 errno = cup->uffsw.sw_error;
00242 return(IOERR);
00243 }
00244 if (mode != FULL)
00245 cup->urecpos += ((uint64)ret << 3) - padubc;
00246 }
00247
00248
00249
00250 if (tip->cnvindx == 0) {
00251
00252 ubc = 0;
00253
00254 ret = XRCALL(cup->ufp.fdc, writertn) cup->ufp.fdc,
00255 CPTR2BP(uda),
00256 breq, &cup->uffsw, mode, &ubc);
00257
00258 if (ret < 0) {
00259 errno = cup->uffsw.sw_error;
00260 return(IOERR);
00261 }
00262
00263 if (mode == FULL)
00264 *status = EOR;
00265 else
00266 cup->urecpos += ((uint64)ret << 3) - ubc;
00267
00268 return(items);
00269 }
00270
00271 #if NUMERIC_DATA_CONVERSION_ENABLED
00272
00273
00274
00275
00276 {
00277 register int uoff;
00278 register int64 bits;
00279 register int64 totbits;
00280 unsigned char tbuf[TBFSZ], *tp;
00281 _f_int dctype;
00282 int (* cvt_fun)();
00283
00284 cvt_fun = __fndc_ncfunc[tip->cnvindx].to_foreign;
00285
00286 #if !defined(__mips) && !defined(_LITTLE_ENDIAN)
00287 if (!_loaded(cvt_fun)) {
00288 errno = FELDDCNV;
00289 return(IOERR);
00290 }
00291 #endif
00292
00293 fdsize = tip->extlen;
00294 dctype = tip->cnvtype;
00295
00296 if (fdsize == 0) {
00297 errno = FDC_ERR_NCVRT;
00298 return(IOERR);
00299 }
00300
00301 tp = tbuf;
00302 buflim = ((TBFSZ << 3) / fdsize) * fdsize;
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 totbits = (items * fdsize) - ubc;
00314
00315 if (type == DVTYPE_ASCII)
00316 totbits = totbits * elsize;
00317
00318 bits = 0;
00319 uoff = 0;
00320
00321 while (bits < totbits) {
00322 register int slice;
00323 register _f_int numerr;
00324 int locubc;
00325 int locmode;
00326 _f_int icount;
00327 const _f_int bitoff = 0;
00328 const _f_int stride = 1;
00329 #ifdef _CRAY
00330 _fcd craychr;
00331 #endif
00332
00333 slice = totbits - bits;
00334 locmode = mode;
00335
00336 if (slice > buflim) {
00337 slice = buflim;
00338 locmode = PARTIAL;
00339 }
00340
00341
00342
00343 breq = (slice + 7) >> 3;
00344 locubc = (breq << 3) - slice;
00345
00346
00347
00348
00349 icount = slice / fdsize;
00350
00351 #ifdef _CRAY
00352 craychr = _cptofcd((char *)uda + uoff, icount);
00353 #endif
00354
00355 if (tip->newfunc) {
00356 _f_int flen;
00357 _f_int nlen;
00358
00359 flen = fdsize;
00360 nlen = tip->intlen;
00361
00362 numerr = cvt_fun(&dctype, &icount, (void *)tp,
00363 &bitoff, (char *)uda + uoff,
00364 &stride, &nlen, &flen,
00365 #ifdef _CRAY
00366 craychr);
00367 #else
00368 (char *) uda + uoff, icount);
00369 #endif
00370 }
00371 else
00372 numerr = cvt_fun(&dctype, &icount, (void *)tp,
00373 &bitoff, (char *)uda + uoff,
00374 &stride,
00375 #ifdef _CRAY
00376 craychr);
00377 #else
00378 (char *) uda + uoff, icount);
00379 #endif
00380
00381 if (numerr != 0) {
00382 errno = (numerr < 0) ? FEINTUNK : FDC_ERR_NCVRT;
00383 return(IOERR);
00384 }
00385
00386
00387
00388 ret = XRCALL(cup->ufp.fdc, writertn) cup->ufp.fdc,
00389 CPTR2BP(tp), breq, &cup->uffsw,
00390 locmode, &locubc);
00391
00392 if (ret < 0) {
00393 errno = cup->uffsw.sw_error;
00394 return(IOERR);
00395 }
00396
00397 bits = bits + slice;
00398 uoff = uoff + (icount * elsize);
00399 }
00400
00401 if (mode == FULL)
00402 *status = EOR;
00403
00404 cup->urecpos = cup->urecpos + totbits;
00405
00406 break;
00407
00408 }
00409 #endif
00410
00411 case STD:
00412 {
00413
00414 fptr = cup->ufp.std;
00415
00416
00417
00418 #if !defined(_LITTLE_ENDIAN) || (defined(_LITTLE_ENDIAN) && defined(__sv2))
00419 if ((FILE_FLAG(fptr) & (_IOREAD | _IORW)) == (_IOREAD | _IORW) )
00420 (void) fseek(fptr, 0, SEEK_CUR);
00421 #endif
00422
00423
00424
00425 if (items == 0)
00426 return(EOR);
00427
00428
00429
00430 if (padbyts > 0) {
00431
00432 ret = fwrite(" ", 1, padbyts, fptr);
00433
00434 if (ret <= 0) {
00435 if (errno == 0)
00436 errno = FESTIOER;
00437 return(IOERR);
00438 }
00439
00440 cup->urecpos += (uint64)ret << 3;
00441 }
00442
00443
00444
00445
00446
00447
00448 ret = fwrite(uda, 1, breq, fptr);
00449
00450 if (ret != breq) {
00451 if (ret > 0 || errno == 0)
00452 errno = FESTIOER;
00453 return(IOERR);
00454 }
00455
00456 cup->urecpos += (uint64)ret << 3;
00457
00458 }
00459 break;
00460
00461 case FS_AUX:
00462 errno = FEMIXAUX;
00463 return (IOERR);
00464 default:
00465 errno = FEINTFST;
00466 return (IOERR);
00467 }
00468
00469
00470
00471 if (mode == FULL)
00472 cup->urecpos = 0;
00473
00474 return(items);
00475 }