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/rnly.c 92.1 06/21/99 10:37:55"
00039
00040 #include <stdio.h>
00041 #include <errno.h>
00042 #include <liberrno.h>
00043 #include <ctype.h>
00044 #include <foreign.h>
00045 #include <fortran.h>
00046 #include <memory.h>
00047 #include <values.h>
00048 #include <malloc.h>
00049 #include <cray/fmtconv.h>
00050 #include "fio.h"
00051 #include "fmt.h"
00052 #include "rnl.h"
00053
00054 #define BLANK ((int) ' ')
00055 #define NULLC ((int) '\0')
00056
00057 #define OCTAL 1
00058 #define HEX 2
00059 #define SKIPMSG " - Skipped record named: "
00060 #define UNITSTR " On Unit: "
00061
00062 struct Echoinfo {
00063 unum_t eunit;
00064 int rnlecho;
00065
00066 };
00067
00068 static void _rnlecho(unum_t _Un, struct Inpinfo *_Ip);
00069
00070 static int _rnl_fillrec(unit *_Cu, struct Echoinfo *_Ec, struct Inpinfo
00071 *_Ip);
00072
00073 static void fmt_unit(char *_Str, void *_U);
00074
00075 static int g_charstr(long _P, int _Cn, char _C, unit *_Cu, struct
00076 Echoinfo *_Ec, struct Inpinfo *_Ip, int _Lc,
00077 int _Sz);
00078
00079 static int g_complx(int _Ty, unit *_Cu, struct Echoinfo *_Ec, struct
00080 Inpinfo *_Ip, long *_Lv);
00081
00082 static int g_number(int _Ty, unit *_Cu, long *_Lv, struct Inpinfo *_Ip);
00083
00084 static int g_octhex(int _Ty, unit *_Cu, struct Echoinfo *_Ec, struct
00085 Inpinfo *_Ip, long *_Lv, int _Base);
00086
00087 static int get_holl(char _Ho, int _Cn, int _Ty, unit *_Cu, struct
00088 Echoinfo *_Ec, struct Inpinfo *_Ip, long *_Lv);
00089
00090 static int get_quoholl(char _Cd, int _Ty, unit *_Cu, struct
00091 Echoinfo *_Ec, struct Inpinfo *_Ip, long *_Lv);
00092
00093 static int isholl(long *_Hp, struct Inpinfo *_Ip);
00094
00095 static int l_convert(long *_Val, int _Ty, long _Stat);
00096
00097 static Nlentry *n_findn(char *_Key, Nlentry *_List);
00098
00099 static int n_getn(char *_S, char *_Lc, unit *_Cu, struct Echoinfo *_Ec,
00100 struct Inpinfo *_Ip);
00101
00102 static int n_getv(Nlentry *_Nlent, char *_Lc, Namelist *_Nlbase,
00103 unit *_Cu, struct Echoinfo *_Ec, struct Inpinfo *_Ip);
00104
00105 static int n_indx(int *_Of, Nlentry *_Nlent, Namelist *_Nlbase,
00106 unit *_Cu, struct Echoinfo *_Ec, struct Inpinfo *_Ip);
00107
00108 static int nex_data(int _Ty, long _Pt, int _Cn, int _In, char _La,
00109 unit *_Cu, struct Echoinfo *_Ec, struct Inpinfo *_Ip,
00110 long *_Lv, int *_Lc, int _Sz);
00111
00112 static int nl_read(long _P, int _Cn, int _In, int _Ty, char *_Lc,
00113 unit *_Cu, struct Echoinfo *_Ec, struct Inpinfo *_Ip,
00114 int _Sz);
00115
00116 static void pr_msg(char *_Str);
00117
00118 static void to_upper(char *_Str);
00119
00120
00121
00122
00123
00124 #define TONICV(value) { \
00125 inptr->inptr--; \
00126 inptr->incnt++; \
00127 oldp = inptr->inptr; \
00128 (void) NICONV(oldp, &zero, &zero, &zero, &mode, \
00129 value, &inptr->inptr, &stat); \
00130 inptr->incnt -= inptr->inptr - oldp; \
00131 }
00132
00133
00134
00135
00136
00137
00138 #define GETSTR() { \
00139 if (inptr->incnt == 1) { \
00140 LGET(ch); \
00141 } \
00142 LGET(ch); \
00143 if (ch == enddelim) { \
00144 eos = -1; \
00145 LGET(ch);\
00146 if (ch == enddelim) \
00147 eos = 0; \
00148 else { \
00149 inptr->inptr--; \
00150 inptr->incnt++; \
00151 } \
00152 } \
00153 }
00154
00155
00156 static int zero = 0;
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 @RNL(
00183 _f_int *unump,
00184 Namelist *nl,
00185 int errf,
00186 int endf
00187 )
00188 {
00189 unum_t unum;
00190 int errn;
00191 int i;
00192 int ss;
00193 long stat;
00194 long *hlptr;
00195 Nlentry *nlent;
00196 char buf[MAXNAML + 1], c;
00197 char skipmsg[sizeof(SKIPMSG) + sizeof(UNITSTR) + MAXNAML + 8 + 2];
00198 char tmpbuf[MXUNITSZ];
00199 unit *cup;
00200 FIOSPTR css;
00201 struct Echoinfo echoinfo;
00202 struct Echoinfo *echoptr;
00203 struct Inpinfo ininfo;
00204 struct Inpinfo *inptr;
00205
00206
00207 echoptr = &echoinfo;
00208 unum = *unump;
00209
00210 GET_FIOS_PTR(css);
00211 STMT_BEGIN(unum, 0, T_RNL, NULL, css, cup);
00212
00213 if (cup == NULL) {
00214 cup = _imp_open77(css, SEQ, FMT, unum, errf, &errn);
00215
00216
00217
00218
00219 if (cup == NULL)
00220 RERR(css, errn);
00221 }
00222
00223
00224
00225 cup->uflag = (errf != 0 ? _UERRF : 0) | (endf != 0 ? _UENDF : 0);
00226 cup->uwrt = 0;
00227
00228 if (cup->useq == 0)
00229 RERR(css, FESEQTIV);
00230
00231 if (!cup->ufmt)
00232 RERR(css, FEFMTTIV);
00233
00234 #if DEBUG
00235 {
00236 int i;
00237 Nlentry *nz;
00238
00239 printf("\n@RNL: ENTER \n");
00240 printf(" group %s\n", nl->nlname);
00241
00242 nz = nl->nlvnames;
00243
00244 for (i = 0; i < 50; i++, nz++) {
00245 if (!nz->varname[0])
00246 break;
00247 printf("\n %s: \n", nz->varname);
00248 printf("type:%d (%d) nels:%d ndims:%d taskcm:%d lmf:%d \n",
00249 nz->na.type, _old_namelist_to_f77_type_cnvt[nz->na.type],
00250 nz->na.nels, nz->na.ndims, nz->na.taskcm, nz->na.lmf);
00251 printf("stkf:%d offdim:%o \n", nz->na.stkf, nz->na.offdim);
00252 #ifdef _ADDR64
00253 printf("varaddr:%o\n", nz->va.varaddr);
00254 #else
00255 printf("lmaddr:%o varaddr:%o\n", nz->va.lmaddr,
00256 nz->va.varaddr);
00257 #endif
00258 if (_old_namelist_to_f77_type_cnvt[nz->na.type] == DT_CHAR) {
00259 _fcd *kaddr;
00260 printf("Character variable!,");
00261 kaddr = (_fcd *) (nz->va.varaddr + (long)nl);
00262 printf("length = %d, waddr = %o, charptr = %o\n",
00263 _fcdlen(*kaddr), kaddr, _fcdtocp(*kaddr));
00264 }
00265 }
00266 }
00267 #endif
00268
00269 inptr = &ininfo;
00270 inptr->inbuff = cup->ulinebuf;
00271 inptr->inbuff[0]= (long) ' ';
00272 inptr->incnt = 0;
00273 inptr->inptr = inptr->inbuff + 1;
00274 inptr->instart = inptr->inptr;
00275
00276 (void) strcpy(skipmsg, SKIPMSG);
00277
00278
00279
00280 if (_OUT_UNIT < 0) {
00281 echoinfo.eunit = 101;
00282 echoinfo.rnlecho = 0;
00283 }
00284 else {
00285 echoinfo.eunit = _OUT_UNIT;
00286 echoinfo.rnlecho = 1;
00287 }
00288
00289 if ((cup->uaction & OS_READ) == 0) {
00290 RERR(css, FENOREAD);
00291 }
00292
00293 if (cup->uwrt) {
00294 RERR(css, FERDAFWR);
00295 }
00296
00297 fill:
00298 ss = _rnl_fillrec(cup, &echoinfo, inptr);
00299
00300 if (ss != 0)
00301 goto err_eof;
00302
00303 fill1:
00304 do {
00305 MAINCMNTLGET(c)
00306 } while (ISSPTB(c));
00307
00308 if (!MATCH(c, _MASKS, MRNLDELIM))
00309 goto fill;
00310
00311 MAINLGET(c);
00312
00313 ss = n_getn(buf, &c, cup, &echoinfo, inptr);
00314
00315 if (ss != 0)
00316 goto err_eof;
00317
00318 to_upper(buf);
00319
00320 if (strcmp(nl->nlname, buf)) {
00321 if (_SKP_MESS > 0) {
00322
00323
00324
00325 (void) strcpy(&skipmsg[sizeof(SKIPMSG)-1], buf);
00326 (void) strcat(skipmsg, UNITSTR);
00327 fmt_unit(tmpbuf, unump);
00328
00329
00330
00331
00332
00333
00334 (void) strncat(skipmsg, tmpbuf, sizeof(long) - 1);
00335 (void) strcat(skipmsg, "\n");
00336 pr_msg(skipmsg);
00337 }
00338 else if (_SKP_MESS < 0) {
00339
00340 RERR(css, FENLIVGN);
00341 }
00342 del_look:
00343
00344
00345 while (!MATCH(c, _MASKS, MRNLDELIM) && c!= '/') {
00346
00347 if (c == '\'' || c == '"') {
00348 char qchar;
00349
00350 qchar = c;
00351 rquote:
00352 do {
00353 MAINLGET(c);
00354 } while (c != qchar);
00355
00356 MAINLGET(c);
00357
00358 if (c == qchar)
00359 goto rquote;
00360 }
00361 else {
00362 MAINCMNTLGET(c);
00363 }
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373 hlptr = inptr->inptr - 2;
00374
00375
00376
00377
00378
00379
00380
00381 for (i = 0; i < 8 && hlptr > &inptr->inbuff[2]; i++, hlptr--) {
00382 switch((char) *hlptr) {
00383 case 'h':
00384 case 'H':
00385 case 'l':
00386 case 'L':
00387 case 'r':
00388 case 'R':
00389 if (isholl(hlptr, inptr)) {
00390 MAINCMNTLGET(c);
00391 goto del_look;
00392 }
00393 break;
00394
00395 default:
00396 break;
00397 }
00398 }
00399 goto fill1;
00400 }
00401
00402
00403
00404
00405
00406
00407 while (!MATCH(c, _MASKS, MRNLDELIM) && (c != '/')) {
00408 int sepcnt;
00409
00410 ss = n_getn(buf, &c, cup, &echoinfo, inptr);
00411
00412 if (ss != 0)
00413 goto err_eof;
00414
00415 to_upper(buf);
00416
00417 if (!(nlent = n_findn(buf, nl->nlvnames)))
00418 if (strlen(buf) > 0) {
00419 RERR2(css, FENLNREC, buf);
00420 }
00421 else {
00422 Nreturn(IO_OKAY);
00423 }
00424
00425
00426
00427
00428
00429 ss = n_getv(nlent, &c, nl, cup, &echoinfo, inptr);
00430
00431 if (ss != 0)
00432 goto err_eof;
00433
00434 sepcnt = 0;
00435
00436 for ( ; ; ) {
00437
00438 if (!(ISSPTB(c))) {
00439
00440 if ((MATCH(c, _MASKS, MRNLSEP)) &&
00441 (sepcnt == 0))
00442 sepcnt++;
00443 else
00444 break;
00445 }
00446
00447 MAINCMNTLGET(c);
00448 }
00449 }
00450
00451 ret:
00452
00453 STMT_END(cup, T_RNL, NULL, css);
00454
00455 return(CFT77_RETVAL(ss));
00456
00457 err_eof:
00458
00459 if (ss == EOF) {
00460 NEND(css, FERDNLEF);
00461 }
00462 else {
00463 if (errno == FENLTYPI) {
00464 RERR3(css, errno, nlent->varname,
00465 _f77_type_name[_old_namelist_to_f77_type_cnvt[nlent->na.type]]);
00466 }
00467 else
00468 RERR(css, errno);
00469 }
00470
00471 goto ret;
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 static int
00492 n_getn(
00493 char *s,
00494 char *lastc,
00495 unit *cup,
00496 struct Echoinfo *echoptr,
00497 struct Inpinfo *inptr
00498 )
00499 {
00500 char *p, c;
00501 int n;
00502 int ss;
00503
00504 n = MAXNAML;
00505 p = s;
00506 c = *lastc;
00507
00508 while (ISSPTB(c))
00509 CMNTLGET(c);
00510
00511
00512
00513
00514
00515
00516
00517 while (!(ISSPTB(c)) && c != '(' && !(MATCH(c, _MASKS, MRNLREP)) &&
00518 !(MATCH(c, _MASKS, MRNLDELIM))) {
00519
00520 *p++ = c;
00521
00522 CMNTLGET(c);
00523
00524 if (n-- == 0) {
00525 RNLERROR(FENLLONG);
00526 }
00527 }
00528
00529 *lastc = c;
00530 *p = '\0';
00531
00532 return (0);
00533 }
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543 static Nlentry
00544 *n_findn(
00545 char *key,
00546 Nlentry *list
00547 )
00548 {
00549 while (strlen(list->varname) > 0) {
00550 if (!strcmp(key, list->varname))
00551 return (list);
00552 else
00553 list++;
00554 }
00555
00556 return (NULL);
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 static int
00577 n_getv(
00578 Nlentry *nlent,
00579 char *lastc,
00580 Namelist *nlbase,
00581 unit *cup,
00582 struct Echoinfo *echoptr,
00583 struct Inpinfo *inptr
00584 )
00585 {
00586 long ss, cnt;
00587 long stat;
00588 int offset, size, ret;
00589 char *cp;
00590 long vaddr;
00591
00592
00593
00594
00595 if (*lastc == '(') {
00596
00597 ret = n_indx(&offset, nlent, nlbase, cup, echoptr, inptr);
00598
00599 if (ret != 0)
00600 return(ret);
00601 }
00602 else {
00603 offset = 0;
00604
00605 while (ISSPTB(*lastc)) {
00606 CMNTLGET(*lastc);
00607 }
00608
00609 if (!(MATCH(*lastc, _MASKS, MRNLREP))) {
00610 RNLERROR(FENLNOVL);
00611 }
00612 }
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 if (nlent->na.offdim == 0)
00626 cnt = 1;
00627 else
00628 cnt = nlent->na.nels - offset;
00629
00630 if (_old_namelist_to_f77_type_cnvt[nlent->na.type] == DT_CHAR) {
00631 _fcd f;
00632
00633
00634 f = *(_fcd *) ((unsigned long) nlent->va.varaddr +
00635 (long) nlbase);
00636
00637 size = _fcdlen(f);
00638
00639 cp = _fcdtocp(f) + (offset * size);
00640 f = _cptofcd(cp, size);
00641
00642 vaddr = (long) cp;
00643 }
00644 else {
00645 size = _f77_type_len[_old_namelist_to_f77_type_cnvt[nlent->na.type]] >> 3;
00646 vaddr = (long)nlent->va.varaddr + offset * size;
00647 }
00648
00649 ss = nl_read(vaddr, cnt, 1, _old_namelist_to_f77_type_cnvt[nlent->na.type],
00650 lastc, cup, echoptr, inptr, size);
00651
00652 return(ss);
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 static int
00671 n_indx(
00672 int *offset,
00673 Nlentry *nlent,
00674 Namelist *nlbase,
00675 unit *cup,
00676 struct Echoinfo *echoptr,
00677 struct Inpinfo *inptr
00678 )
00679 {
00680 long subs[MAXDIMS];
00681 long *oldp, *newp;
00682 long mode, ss;
00683 long offs, mult;
00684 char c;
00685 Dims *p;
00686 int i, j;
00687 long stat;
00688 long vaddr;
00689
00690
00691
00692 mode = 0;
00693
00694 for (i = 0; i < MAXDIMS; ) {
00695 long dummy;
00696
00697 do {
00698 LGET(c);
00699 } while (ISSPTB(c));
00700
00701 if (c == ')')
00702 break;
00703
00704 inptr->incnt++;
00705 inptr->inptr--;
00706
00707
00708
00709 oldp = inptr->inptr;
00710
00711 #if 0
00712 dummy = 0;
00713
00714 (void) NICONV(oldp, &dummy, &dummy, &dummy, &mode, &subs[i],
00715 &newp, &stat);
00716
00717 if (stat != NV32I) {
00718 RNLERROR(FENLBNDY);
00719 }
00720 #else
00721
00722 for (j = 0; j < inptr->incnt; j++) {
00723
00724 c = (char) oldp[j];
00725
00726 if (c == ')' || c == ',')
00727 break;
00728 }
00729
00730 newp = oldp + j;
00731
00732 (void) _iu2s(oldp, &inptr->incnt, &newp, &mode, &subs[i],
00733 &stat, &dummy, &dummy);
00734
00735 if (stat < 0) {
00736 RNLERROR(FENLBNDY);
00737 }
00738
00739 #if defined(_CRAY1) || defined(_WORD32)
00740 if (stat != EX_INTS) {
00741 RNLERROR(FENLBNDY);
00742 }
00743 #endif
00744
00745 #endif
00746
00747 inptr->inptr = newp;
00748 inptr->incnt = inptr->incnt - (newp - oldp);
00749
00750 i++;
00751
00752 do {
00753 LGET(c);
00754 } while (ISSPTB(c));
00755
00756 if (c == ')')
00757 break;
00758
00759 if (c != ',') {
00760 RNLERROR(FENLIOER);
00761 }
00762 }
00763
00764 if (i == 0) {
00765 RNLERROR(FENLIOER);
00766 }
00767
00768 while (!(MATCH(c, _MASKS, MRNLREP))) {
00769 LGET(c);
00770 }
00771
00772
00773
00774
00775
00776 p = (Dims *)(nlent->na.offdim + (long)nlbase);
00777 mult = 1;
00778
00779 offs = subs[0] - p[0].lower;
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793 if (i > nlent->na.ndims) {
00794 RNLERROR(FENLBNDY);
00795 }
00796
00797 for (j = 1; j < i; j++) {
00798 mult = mult * p[j-1].span;
00799 offs = offs + ((subs[j] - p[j].lower) * mult);
00800 }
00801
00802
00803
00804 if (offs >= nlent->na.nels) {
00805 RNLERROR(FENLBNDY);
00806 }
00807
00808 *offset = offs;
00809
00810 return(0);
00811 }
00812
00813
00814
00815
00816
00817 static void
00818 _rnlecho(
00819 unum_t eunit,
00820 struct Inpinfo *inptr
00821 )
00822 {
00823 unit *echoup;
00824 FIOSPTR css;
00825 GET_FIOS_PTR(css);
00826
00827 echoup = _get_cup(eunit);
00828
00829 if (echoup == NULL) {
00830 unit *cupsave;
00831
00832 cupsave = css->f_cu;
00833 echoup = _imp_open77(css, SEQ, FMT, eunit, 1, NULL);
00834 css->f_cu = cupsave;
00835
00836 if (echoup == NULL)
00837 return;
00838 }
00839 else {
00840
00841 if (echoup->ufmt == 0)
00842 _ferr(css, FEFMTTIV);
00843
00844 if (echoup->useq == 0)
00845 _ferr(css, FESEQTIV);
00846 }
00847
00848
00849
00850
00851
00852
00853 (void) _fwch(echoup, inptr->inbuff, inptr->incnt + 1, FULL);
00854
00855 (void) _release_cup(echoup);
00856
00857 return;
00858 }
00859
00860
00861
00862
00863
00864 static void
00865 fmt_unit(
00866 char *string,
00867 void *u
00868 )
00869 {
00870 register unum_t unum;
00871
00872 if (_is_file_name(*((long *)u)))
00873 (void) strncpy(string, (char *)u, sizeof(long) - 1);
00874 else {
00875 unum = *((unum_t *)u);
00876 (void) sprintf(string, "%lld", unum);
00877 }
00878
00879 return;
00880 }
00881
00882
00883
00884
00885
00886 static void
00887 to_upper(char *buf)
00888 {
00889 char c;
00890
00891 while ((c = *buf) != '\0') {
00892 *buf++ = toupper(c);
00893 }
00894
00895 return;
00896 }
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907 static int
00908 nl_read(
00909 long ptr,
00910 int count,
00911 int inc,
00912 int type,
00913 char *lastc,
00914
00915
00916 unit *cup,
00917 struct Echoinfo *echoptr,
00918 struct Inpinfo *inptr,
00919 int elsize
00920 )
00921 {
00922 int ss;
00923 int cntp;
00924 int nullvlu;
00925 char *cp;
00926 long stat;
00927 long lval[3];
00928 int lcount;
00929
00930 if ((type < 0) || (type >= DT_MAX))
00931 RNLERROR(FEINTDTY);
00932
00933 if (type == DT_CMPLX || type == DT_DBLE)
00934 inc = inc + inc;
00935
00936 CMNTLGET(*lastc);
00937
00938 lcount = 0;
00939 cntp = count;
00940
00941 while (cntp > 0) {
00942
00943 if (cup->uend)
00944 return(EOF);
00945
00946
00947
00948 nullvlu = nex_data(type, ptr, cntp, inc, *lastc, cup, echoptr,
00949 inptr, lval, &lcount, elsize);
00950
00951 if (nullvlu == RNL_ERROR) {
00952 return(RNL_ERROR);
00953 }
00954 else if (nullvlu == 2) {
00955 lcount = 0;
00956 cntp = 0;
00957 }
00958
00959 if (type == DT_CHAR) {
00960
00961
00962
00963
00964
00965 if (lcount > cntp)
00966 RNLERROR(FENLTOOM);
00967
00968
00969
00970
00971 cp = (char *) ptr;
00972 cntp = cntp - lcount;
00973
00974 cp = cp + (lcount * elsize);
00975 ptr = (long) cp;
00976
00977 }
00978
00979 else {
00980 int move;
00981
00982 move = MIN(cntp, lcount);
00983
00984
00985
00986 while (move != 0) {
00987 if (!nullvlu) {
00988 *(long *)ptr = lval[0];
00989 if ((type == DT_DBLE) ||
00990 (type == DT_CMPLX))
00991 *((long *)ptr+1) = lval[1];
00992 }
00993
00994 ptr = ptr + inc;
00995 move = move - 1;
00996 cntp = cntp - 1;
00997 lcount = lcount - 1;
00998 }
00999
01000 if (lcount)
01001 RNLERROR(FENLTOOM);
01002 }
01003
01004
01005
01006
01007
01008
01009
01010 do {
01011 CMNTLGET(*lastc);
01012 } while (ISSPTB(*lastc));
01013
01014 if (MATCH(*lastc, _MASKS, MRNLSEP)) {
01015 do {
01016 CMNTLGET(*lastc);
01017 } while (ISSPTB(*lastc));
01018 }
01019 }
01020
01021 return(0);
01022 }
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037 static int
01038 nex_data(
01039 int type,
01040 long ptr,
01041 int cnt,
01042 int inc,
01043 char lastc,
01044 unit *cup,
01045 struct Echoinfo *echoptr,
01046 struct Inpinfo *inptr,
01047 long *lval,
01048 int *lcount,
01049 int elsize
01050 )
01051 {
01052 char c, oc;
01053 int ocnt, ss;
01054 long *optr;
01055 int holcnt;
01056 long stat;
01057 char newc;
01058
01059 c = lastc;
01060
01061 while (ISSPTB(c)) {
01062 CMNTLGET(c);
01063 }
01064
01065 *lcount = 1;
01066
01067 if (isdigit((int) c)) {
01068
01069
01070
01071
01072
01073
01074 *lcount = c - '0';
01075 ocnt = inptr->incnt;
01076 optr = inptr->inptr;
01077 oc = c;
01078
01079 for (;;) {
01080
01081 LGET(c);
01082
01083 if (isdigit((int) c))
01084 *lcount = (*lcount * 10) + c - '0';
01085 else
01086 break;
01087 }
01088
01089
01090
01091
01092
01093
01094 switch (c) {
01095
01096 case '*':
01097 CMNTLGET(c);
01098
01099 if (isdigit((int) c)) {
01100
01101
01102
01103
01104 holcnt = c - '0';
01105 ocnt = inptr->incnt;
01106 optr = inptr->inptr;
01107 oc = c;
01108
01109 for (;;) {
01110
01111 LGET(c);
01112
01113 if (isdigit((int) c))
01114 holcnt = (holcnt * 10) +
01115 c - '0';
01116 else
01117 break;
01118 }
01119
01120 switch (c) {
01121 case 'H':
01122 case 'h':
01123 case 'R':
01124 case 'r':
01125 case 'L':
01126 case 'l':
01127 return(get_holl(c,
01128 holcnt, type,
01129 cup, echoptr,
01130 inptr, lval));
01131
01132 default:
01133
01134 inptr->inptr = optr;
01135
01136 inptr->incnt = ocnt;
01137 c = oc;
01138 ocnt = 1;
01139 break;
01140
01141 }
01142 }
01143 break;
01144
01145 case 'H':
01146 case 'h':
01147 case 'R':
01148 case 'r':
01149 case 'L':
01150 case 'l':
01151
01152
01153
01154 holcnt = *lcount;
01155 *lcount = 1;
01156
01157 return(get_holl(c, holcnt, type, cup, echoptr,
01158 inptr, lval));
01159
01160 default:
01161
01162 inptr->inptr = optr;
01163 inptr->incnt = ocnt;
01164 c = oc;
01165 ocnt = 1;
01166 *lcount = 1;
01167 break;
01168 }
01169 }
01170
01171
01172
01173
01174
01175
01176
01177 if (MATCH(c, _MASKS, MRNLSEP)) {
01178 inptr->inptr--;
01179 inptr->incnt++;
01180 return(1);
01181 }
01182 else if (ISSPTB(c)) {
01183 return(1);
01184 }
01185
01186 else
01187 if (MATCH(c, _MASKS, MRNLCOMM)) {
01188
01189
01190
01191
01192
01193 *lval = *(lval+1) = 0;
01194 inptr->incnt++;
01195 inptr->inptr--;
01196 return(1);
01197 }
01198 else
01199 if (MATCH(c, _MASKS, MRNLDELIM)) {
01200 inptr->inptr--;
01201 inptr->incnt++;
01202 return(2);
01203 }
01204
01205
01206
01207
01208
01209
01210 if (type == DT_LOG) {
01211
01212
01213
01214
01215
01216
01217
01218 if (c == '.') {
01219
01220 LGET(c);
01221
01222 if ((c == 'T') || (c == 't')) {
01223
01224 *lval = (long) TRUE;
01225 }
01226 else if ((c == 'F') || (c == 'f')) {
01227
01228 *lval = (long) FALSE;
01229 }
01230 else
01231 RNLERROR(FENLIVLG);
01232 }
01233
01234 else {
01235
01236
01237
01238
01239
01240
01241
01242
01243 ocnt = inptr->incnt;
01244 optr = inptr->inptr;
01245 newc = *optr++;
01246 ocnt--;
01247
01248 while (!(ISSPTB(newc))) {
01249 if (MATCH(newc, _MASKS, MRNLSEP) ||
01250 MATCH(newc, _MASKS, MRNLDELIM))
01251 break;
01252 if (MATCH(newc, _MASKS, MRNLREP) ||
01253 (newc == '(')) {
01254
01255
01256
01257
01258 inptr->inptr--;
01259 inptr->incnt++;
01260 return(2);
01261 }
01262 newc = *optr++;
01263 ocnt--;
01264 }
01265
01266 while ((ISSPTB(newc)) && ocnt-- > 0)
01267 newc = *optr++;
01268
01269 if (MATCH(newc, _MASKS, MRNLREP)) {
01270
01271
01272
01273
01274 inptr->inptr--;
01275 inptr->incnt++;
01276 return(2);
01277 }
01278
01279 if ((c == 'T') || (c == 't')) {
01280 *lval = (long) TRUE;
01281 }
01282 else if ((c == 'F') || (c == 'f')) {
01283 *lval = (long) FALSE;
01284 }
01285 else if (ISSPTB(c) || (MATCH(c, _MASKS, MRNLSEP))) {
01286 return(1);
01287 }
01288 else {
01289 RNLERROR(FENLIVLG);
01290 }
01291 }
01292
01293
01294
01295
01296
01297 while ( !(ISSPTB(c))) {
01298
01299 CMNTLGET(c);
01300
01301 if (MATCH(c, _MASKS, MRNLDELIM) ||
01302 MATCH(c, _MASKS, MRNLSEP)) {
01303
01304
01305
01306
01307 inptr->inptr--;
01308 inptr->incnt++;
01309
01310 return(0);
01311 }
01312
01313 }
01314 return(0);
01315
01316 }
01317
01318 if (type == DT_CHAR)
01319 return (g_charstr(ptr, cnt, c, cup, echoptr, inptr, *lcount, elsize));
01320
01321
01322
01323
01324
01325 if (isdigit((int) c) || c == '+' || c == '-' || c == '.') {
01326
01327 if (type == DT_CMPLX)
01328 RNLERROR(FENLIVCX);
01329
01330 return(g_number(type, cup, lval, inptr));
01331 }
01332
01333
01334
01335
01336
01337
01338
01339 if (c == '(') {
01340 return(g_complx(type, cup, echoptr, inptr, lval));
01341 }
01342 else if ((c == '\'') || (c == '"')) {
01343 return(get_quoholl(c, type, cup, echoptr, inptr, lval));
01344 }
01345
01346 else if (c == 'O' || c == 'o') {
01347 return(g_octhex(type, cup, echoptr, inptr, lval, OCTAL));
01348 }
01349 else if (c == 'Z' || c == 'z') {
01350 return(g_octhex(type, cup, echoptr, inptr, lval, HEX));
01351 }
01352 else {
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363 inptr->inptr--;
01364 inptr->incnt++;
01365
01366 return(2);
01367 }
01368 }
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379 static int
01380 g_complx(
01381 int type,
01382 unit *cup,
01383 struct Echoinfo *echoptr,
01384 struct Inpinfo *inptr,
01385 long *lval
01386 )
01387 {
01388 char c;
01389 long *oldp;
01390 long mode, stat;
01391 int ss, i;
01392
01393
01394
01395
01396
01397
01398 if (type != DT_CMPLX) {
01399 RNLERROR(FENLTYPI);
01400 }
01401
01402 mode = 0;
01403
01404
01405
01406
01407
01408
01409 if (_BLNKSEP == 0)
01410 mode |= MBN;
01411
01412
01413
01414 for (i = 0; i < 2; i++) {
01415
01416 do {
01417 LGET(c);
01418 } while (ISSPTB(c));
01419
01420 TONICV(lval + i);
01421
01422 if (l_convert(lval + i, DT_REAL, stat))
01423 RNLERROR(FENLTYPI);
01424
01425 do {
01426 LGET(c);
01427 } while (ISSPTB(c));
01428
01429 if ((c != ',') && (i == 0)) {
01430 RNLERROR(FENLIVCX);
01431
01432 }
01433 }
01434
01435 if ( c != ')') {
01436 RNLERROR(FENLIVCX);
01437 }
01438
01439 return(0);
01440 }
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450 static int
01451 g_number(
01452 int type,
01453 unit *cup,
01454 long *lval,
01455 struct Inpinfo *inptr
01456 )
01457 {
01458 long *oldp;
01459 long mode, stat;
01460 int ss;
01461
01462 mode = 0;
01463
01464 if (type == DT_DBLE)
01465 mode |= MD;
01466
01467
01468
01469
01470
01471
01472 if (_BLNKSEP == 0)
01473 mode |= MBN;
01474
01475 TONICV(lval);
01476
01477 if (l_convert(lval, type, stat)) {
01478 RNLERROR(FENLTYPI);
01479 }
01480
01481 return(0);
01482 }
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493 static int
01494 l_convert(
01495 long *val,
01496 int type,
01497 long stat
01498 )
01499 {
01500 short sval;
01501 long lval;
01502 union {
01503 long l;
01504 double f;
01505 } uval;
01506
01507 if (stat <= 0 || stat > NVDOUB)
01508 return(RNL_ERROR);
01509
01510
01511
01512
01513
01514 switch (stat) {
01515
01516 case NV32I:
01517 case NV64I:
01518
01519
01520
01521 switch (type) {
01522 case DT_SINT:
01523 case DT_INT:
01524 break;
01525
01526 case DT_REAL:
01527 case DT_DBLE:
01528 if (!_TYP_CONV)
01529 return(RNL_ERROR);
01530
01531 uval.f = (double) *val;
01532 *val = uval.l;
01533 break;
01534
01535 case DT_LOG:
01536 default:
01537
01538 return(RNL_ERROR);
01539 }
01540 break;
01541
01542 case NVREAL:
01543 case NVDOUB:
01544
01545
01546
01547 uval.l = *val;
01548
01549 switch (type) {
01550 case DT_SINT:
01551 if (!_TYP_CONV)
01552 return(RNL_ERROR);
01553
01554 sval = (short) uval.f;
01555 *val = sval;
01556 break;
01557
01558 case DT_INT:
01559 if (!_TYP_CONV)
01560 return(RNL_ERROR);
01561
01562 lval = (long) uval.f;
01563 *val = lval;
01564 break;
01565
01566 case DT_REAL:
01567 case DT_DBLE:
01568 break;
01569
01570 case DT_LOG:
01571 default:
01572 return(RNL_ERROR);
01573
01574 }
01575 }
01576
01577 return(0);
01578 }
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591 static int
01592 g_charstr(
01593 long p,
01594 int cnt,
01595 char c,
01596 unit *cup,
01597 struct Echoinfo *echoptr,
01598 struct Inpinfo *inptr,
01599 int lcount,
01600 int elsize
01601 )
01602 {
01603 int eos;
01604 int i, ch;
01605 unsigned int len77;
01606 char *cp;
01607 long stat;
01608 char enddelim;
01609 char c1;
01610 int repcount;
01611 char *cpold;
01612 int ss;
01613 long *optr;
01614 int ocnt;
01615 _fcd fchp;
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648 eos = 0;
01649 len77 = elsize;
01650
01651 if (len77 != 0) {
01652
01653
01654 cp = (char *) p;
01655 repcount = MIN(lcount,cnt);
01656
01657
01658
01659
01660
01661
01662 if ((c == '\'') || (c == '"')) {
01663 enddelim = c;
01664
01665
01666
01667 for (i = 0; i < len77 && eos == 0; i++) {
01668 GETSTR();
01669 if (eos == 0)
01670 *cp++ = ch;
01671 }
01672
01673 if (eos == -1)
01674 i--;
01675
01676 i = len77 - i;
01677
01678 (void) memset(cp, BLANK, i);
01679
01680 cp = cp + i;
01681
01682 while (eos != -1) {
01683
01684
01685
01686
01687
01688 GETSTR();
01689 }
01690
01691 while (--repcount) {
01692
01693
01694
01695
01696
01697
01698 cpold = (char *) p;
01699 (void) memcpy(cp, cpold, len77);
01700 cp = cp + len77;
01701 }
01702
01703 }
01704 else {
01705
01706
01707
01708
01709
01710
01711
01712
01713 if (lcount > 1)
01714 RNLERROR(FENLNOVL);
01715
01716
01717
01718
01719
01720
01721 ocnt = inptr->incnt;
01722 optr = inptr->inptr;
01723 c1 = *optr++;
01724 ocnt--;
01725
01726 while (!(ISSPTB(c1))) {
01727
01728 if (MATCH(c1, _MASKS, MRNLSEP) ||
01729 MATCH(c1, _MASKS, MRNLDELIM))
01730 break;
01731
01732 if (MATCH(c1, _MASKS, MRNLREP) || c1 == '(' ) {
01733
01734
01735
01736
01737 inptr->inptr--;
01738 inptr->incnt++;
01739
01740 return(2);
01741 }
01742
01743 c1 = *optr++;
01744 ocnt--;
01745 }
01746
01747 while ((ISSPTB(c1)) && ocnt-- > 0)
01748 c1 = *optr++;
01749
01750 if (MATCH(c1, _MASKS, MRNLREP) || (c1 == '(')) {
01751
01752
01753
01754
01755 inptr->inptr--;
01756 inptr->incnt++;
01757 return(2);
01758 }
01759
01760 i = 0;
01761 c1 = c;
01762
01763 while (!(ISSPTB(c1))) {
01764
01765 if (i < len77) {
01766 *cp++ = c1;
01767 i++;
01768 }
01769
01770 LGET(c1);
01771
01772 if (MATCH(c1, _MASKS, MRNLSEP) ||
01773 MATCH(c1, _MASKS, MRNLCOMM)) {
01774
01775 inptr->inptr--;
01776 inptr->incnt++;
01777 break;
01778 }
01779 }
01780
01781
01782
01783 i = len77 - i;
01784 (void) memset(cp, BLANK, i);
01785 cp = cp + i;
01786 }
01787
01788 }
01789 else {
01790 RNLERROR(FENLIOER);
01791 }
01792
01793 return(0);
01794 }
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804 static int
01805 get_holl(
01806 char holltype,
01807 int count,
01808 int type,
01809 unit *cup,
01810 struct Echoinfo *echoptr,
01811 struct Inpinfo *inptr,
01812 long *lval
01813 )
01814 {
01815 int i;
01816 char *holbufptr;
01817 char c;
01818 long stat;
01819 int ss;
01820 int fill;
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837 if (type == DT_CMPLX || type == DT_DBLE || type == DT_CHAR)
01838 RNLERROR(FENLTYPI);
01839
01840 if (count > sizeof(long)) {
01841 RNLERROR(FENLIOER);
01842 }
01843
01844 fill = BLANK;
01845 holbufptr = (char *)lval;
01846
01847 if (holltype == 'R' || holltype == 'r') {
01848
01849 fill = NULLC;
01850 holbufptr = holbufptr + (sizeof(long) - count);
01851 }
01852 else
01853 if (holltype == 'L' || holltype == 'l')
01854 fill = NULLC;
01855
01856
01857
01858
01859
01860
01861 for (i = 0; i < count && (inptr->incnt > 1) ; i++) {
01862 LGET(c);
01863
01864 *holbufptr++ = c;
01865 }
01866
01867 if (i == count) {
01868
01869 if (holltype == 'R' || holltype == 'r')
01870 holbufptr = (char *)lval;
01871
01872 (void) memset(holbufptr, fill, sizeof(long) - count);
01873 }
01874 else {
01875
01876
01877
01878
01879
01880 RNLERROR(FENLIOER);
01881 }
01882
01883 return(0);
01884 }
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895 static int
01896 get_quoholl(
01897 char cdelim,
01898 int type,
01899 unit *cup,
01900 struct Echoinfo *echoptr,
01901 struct Inpinfo *inptr,
01902 long *lval
01903 )
01904 {
01905 int numchar;
01906 int j;
01907 int fill;
01908 long holbuf;
01909
01910 char *holbufptr;
01911 char c;
01912 long stat;
01913 char *lvalcharptr;
01914 int ss;
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929 if (type == DT_CMPLX || type == DT_DBLE || type == DT_CHAR)
01930 RNLERROR(FENLTYPI);
01931
01932 lvalcharptr = (char *)lval;
01933 holbufptr = (char *) &holbuf;
01934
01935
01936
01937
01938
01939
01940 numchar = 0;
01941
01942 for (;;) {
01943
01944 LGET(c);
01945
01946 if (c == cdelim) {
01947
01948
01949
01950 LGET(c);
01951
01952 if (c != cdelim)
01953 break;
01954
01955
01956
01957
01958 }
01959
01960 if (++numchar > sizeof(long))
01961 RNLERROR(FENLIOER);
01962
01963 *holbufptr++ = c;
01964
01965
01966
01967
01968
01969 if (inptr->incnt <= 1) {
01970 RNLERROR(FENLIOER);
01971 }
01972
01973 }
01974
01975
01976 if (c == 'L' || c == 'l')
01977 fill = NULLC;
01978 else if (c == 'R' || c == 'r') {
01979
01980
01981
01982 holbufptr = holbufptr - 1;
01983 lvalcharptr = lvalcharptr + (sizeof(long) - 1);
01984 j = sizeof(long) - numchar;
01985
01986 while (numchar-- > 0)
01987 *lvalcharptr-- = *holbufptr--;
01988
01989
01990
01991 while (j-- > 0)
01992 *lvalcharptr-- = '\0';
01993
01994 return(0);
01995 }
01996 else {
01997
01998 fill = BLANK;
01999
02000 if (c != 'H' && c != 'h') {
02001
02002
02003 inptr->inptr--;
02004 inptr->incnt++;
02005 }
02006 }
02007
02008
02009
02010 (void) memset(holbufptr, fill, sizeof(long) - numchar);
02011
02012 *lval = holbuf;
02013
02014 return(0);
02015 }
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035 static int
02036 g_octhex(
02037 int type,
02038 unit *cup,
02039 struct Echoinfo *echoptr,
02040 struct Inpinfo *inptr,
02041 long *lval,
02042 int base
02043 )
02044 {
02045 char c;
02046 long stat;
02047 char strbuf[2];
02048 int ss;
02049
02050 if (*inptr->inptr != '\'') {
02051
02052 inptr->inptr--;
02053 inptr->incnt++;
02054
02055 return(2);
02056 }
02057
02058
02059
02060
02061
02062 if (type == DT_CMPLX || type == DT_DBLE) {
02063 RNLERROR(FENLTYPI);
02064 }
02065
02066 LGET(c);
02067 LGET(c);
02068 *lval = 0;
02069 strbuf[1] = '\0';
02070
02071 while (!(ISSPTB(c)) && c != '\'') {
02072
02073 if (base == OCTAL) {
02074
02075 if ((!isdigit((int) c)) || (c == '9') ||
02076 (*lval >> 61)) {
02077 RNLERROR(FENICVIC);
02078 }
02079
02080 *lval = (*lval * 8) + c - '0';
02081 }
02082 else {
02083
02084 if ((!isxdigit(c)) || (*lval >> 60)) {
02085 RNLERROR(FENICVIC);
02086 }
02087
02088 strbuf[0] = c;
02089 *lval = (*lval * 16) +
02090 (int) strtol(strbuf, (char **)NULL, 16);
02091 }
02092
02093 CMNTLGET(c);
02094
02095 if (MATCH(c, _MASKS, MRNLSEP)) {
02096 inptr->inptr--;
02097 inptr->incnt++;
02098 break;
02099 }
02100 }
02101
02102 return(0);
02103 }
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115 static int
02116 _rnl_fillrec(
02117 unit *cup,
02118 struct Echoinfo *echoptr,
02119 struct Inpinfo *inptr
02120 )
02121 {
02122 long stat;
02123 int ss;
02124
02125 inptr->incnt = _frch(cup, inptr->instart, cup->urecsize, 1, &stat);
02126
02127 if (inptr->incnt < 0 || stat != EOR) {
02128 if (stat == EOF) {
02129 inptr->incnt = 1;
02130 cup->uend = PHYSICAL_ENDFILE;
02131 return(EOF);
02132 }
02133 else if (stat == EOD) {
02134 inptr->incnt = 1;
02135 if (cup->uend == 0)
02136 cup->uend = LOGICAL_ENDFILE;
02137 return(EOF);
02138 }
02139 else if (stat == CNT) {
02140 errno = FENLRECL;
02141 return(RNL_ERROR);
02142 }
02143
02144 if (inptr->incnt < 0) {
02145 return(RNL_ERROR);
02146 }
02147 }
02148
02149 cup->uend = 0;
02150
02151 if (inptr->incnt == 0)
02152 inptr->incnt = 1;
02153
02154
02155
02156 *(inptr->instart+inptr->incnt) = (long) ' ';
02157
02158 if ((echoptr->rnlecho) ||
02159 (MATCH(*inptr->instart, _MASKS, MRNLFLAG))) {
02160
02161 echoptr->rnlecho = 1;
02162 _rnlecho(echoptr->eunit, inptr);
02163 }
02164
02165
02166
02167
02168 inptr->inptr = inptr->instart + 1;
02169
02170 return(0);
02171 }
02172
02173 static void
02174 pr_msg(char *string)
02175 {
02176 (void) write(fileno(errfile), string, strlen(string));
02177
02178 return;
02179 }
02180
02181
02182
02183
02184
02185
02186
02187 static int
02188 isholl(
02189 long *hlptr,
02190 struct Inpinfo *inptr
02191 )
02192 {
02193 char hlval;
02194
02195 hlval = (char) *(hlptr - 1);
02196
02197 if (isdigit(hlval) && ((hlval - '0') <= 8) && ((hlval - '0') > 0)) {
02198
02199
02200
02201
02202 if (((hlval - '0') + hlptr) >= (inptr->inptr - 1)) {
02203
02204
02205
02206 if (hlptr > &inptr->inbuff[3]) {
02207
02208 hlval = (char) *(hlptr - 2);
02209
02210 if (!ISSPTB(hlval) && hlval != '*' &&
02211 !MATCH(hlval, _MASKS, MRNLREP) &&
02212 !MATCH(hlval, _MASKS, MRNLSEP) )
02213 return(0);
02214 }
02215
02216 return(1);
02217
02218 }
02219
02220 return(0);
02221
02222 }
02223
02224 return(0);
02225 }