io.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  1. /****************************************************************
  2. Copyright 1990, 1991, 1993, 1994, 1996, 2000 by AT&T, Lucent Technologies and Bellcore.
  3. Permission to use, copy, modify, and distribute this software
  4. and its documentation for any purpose and without fee is hereby
  5. granted, provided that the above copyright notice appear in all
  6. copies and that both that the copyright notice and this
  7. permission notice and warranty disclaimer appear in supporting
  8. documentation, and that the names of AT&T, Bell Laboratories,
  9. Lucent or Bellcore or any of their entities not be used in
  10. advertising or publicity pertaining to distribution of the
  11. software without specific, written prior permission.
  12. AT&T, Lucent and Bellcore disclaim all warranties with regard to
  13. this software, including all implied warranties of
  14. merchantability and fitness. In no event shall AT&T, Lucent or
  15. Bellcore be liable for any special, indirect or consequential
  16. damages or any damages whatsoever resulting from loss of use,
  17. data or profits, whether in an action of contract, negligence or
  18. other tortious action, arising out of or in connection with the
  19. use or performance of this software.
  20. ****************************************************************/
  21. /* Routines to generate code for I/O statements.
  22. Some corrections and improvements due to David Wasley, U. C. Berkeley
  23. */
  24. /* TEMPORARY */
  25. #define TYIOINT TYLONG
  26. #define SZIOINT SZLONG
  27. #include "defs.h"
  28. #include "names.h"
  29. #include "iob.h"
  30. extern int byterev, inqmask;
  31. static void dofclose Argdcl((void));
  32. static void dofinquire Argdcl((void));
  33. static void dofmove Argdcl((char*));
  34. static void dofopen Argdcl((void));
  35. static void doiolist Argdcl((chainp));
  36. static void ioset Argdcl((int, int, expptr));
  37. static void ioseta Argdcl((int, Addrp));
  38. static void iosetc Argdcl((int, expptr));
  39. static void iosetip Argdcl((int, int));
  40. static void iosetlc Argdcl((int, int, int));
  41. static void putio Argdcl((expptr, expptr));
  42. static void putiocall Argdcl((expptr));
  43. iob_data *iob_list;
  44. Addrp io_structs[9];
  45. LOCAL char ioroutine[12];
  46. LOCAL long ioendlab;
  47. LOCAL long ioerrlab;
  48. LOCAL int endbit;
  49. LOCAL int errbit;
  50. LOCAL long jumplab;
  51. LOCAL long skiplab;
  52. LOCAL int ioformatted;
  53. LOCAL int statstruct = NO;
  54. LOCAL struct Labelblock *skiplabel;
  55. Addrp ioblkp;
  56. #define UNFORMATTED 0
  57. #define FORMATTED 1
  58. #define LISTDIRECTED 2
  59. #define NAMEDIRECTED 3
  60. #define V(z) ioc[z].iocval
  61. #define IOALL 07777
  62. LOCAL struct Ioclist
  63. {
  64. char *iocname;
  65. int iotype;
  66. expptr iocval;
  67. }
  68. ioc[ ] =
  69. {
  70. { "", 0 },
  71. { "unit", IOALL },
  72. { "fmt", M(IOREAD) | M(IOWRITE) },
  73. { "err", IOALL },
  74. { "end", M(IOREAD) },
  75. { "iostat", IOALL },
  76. { "rec", M(IOREAD) | M(IOWRITE) },
  77. { "recl", M(IOOPEN) | M(IOINQUIRE) },
  78. { "file", M(IOOPEN) | M(IOINQUIRE) },
  79. { "status", M(IOOPEN) | M(IOCLOSE) },
  80. { "access", M(IOOPEN) | M(IOINQUIRE) },
  81. { "form", M(IOOPEN) | M(IOINQUIRE) },
  82. { "blank", M(IOOPEN) | M(IOINQUIRE) },
  83. { "exist", M(IOINQUIRE) },
  84. { "opened", M(IOINQUIRE) },
  85. { "number", M(IOINQUIRE) },
  86. { "named", M(IOINQUIRE) },
  87. { "name", M(IOINQUIRE) },
  88. { "sequential", M(IOINQUIRE) },
  89. { "direct", M(IOINQUIRE) },
  90. { "formatted", M(IOINQUIRE) },
  91. { "unformatted", M(IOINQUIRE) },
  92. { "nextrec", M(IOINQUIRE) },
  93. { "nml", M(IOREAD) | M(IOWRITE) }
  94. };
  95. #define NIOS (sizeof(ioc)/sizeof(struct Ioclist) - 1)
  96. /* #define IOSUNIT 1 */
  97. /* #define IOSFMT 2 */
  98. #define IOSERR 3
  99. #define IOSEND 4
  100. #define IOSIOSTAT 5
  101. #define IOSREC 6
  102. #define IOSRECL 7
  103. #define IOSFILE 8
  104. #define IOSSTATUS 9
  105. #define IOSACCESS 10
  106. #define IOSFORM 11
  107. #define IOSBLANK 12
  108. #define IOSEXISTS 13
  109. #define IOSOPENED 14
  110. #define IOSNUMBER 15
  111. #define IOSNAMED 16
  112. #define IOSNAME 17
  113. #define IOSSEQUENTIAL 18
  114. #define IOSDIRECT 19
  115. #define IOSFORMATTED 20
  116. #define IOSUNFORMATTED 21
  117. #define IOSNEXTREC 22
  118. #define IOSNML 23
  119. #define IOSTP V(IOSIOSTAT)
  120. /* offsets in generated structures */
  121. #define SZFLAG SZIOINT
  122. /* offsets for external READ and WRITE statements */
  123. #define XERR 0
  124. #define XUNIT SZFLAG
  125. #define XEND SZFLAG + SZIOINT
  126. #define XFMT 2*SZFLAG + SZIOINT
  127. #define XREC 2*SZFLAG + SZIOINT + SZADDR
  128. /* offsets for internal READ and WRITE statements */
  129. #define XIUNIT SZFLAG
  130. #define XIEND SZFLAG + SZADDR
  131. #define XIFMT 2*SZFLAG + SZADDR
  132. #define XIRLEN 2*SZFLAG + 2*SZADDR
  133. #define XIRNUM 2*SZFLAG + 2*SZADDR + SZIOINT
  134. #define XIREC 2*SZFLAG + 2*SZADDR + 2*SZIOINT
  135. /* offsets for OPEN statements */
  136. #define XFNAME SZFLAG + SZIOINT
  137. #define XFNAMELEN SZFLAG + SZIOINT + SZADDR
  138. #define XSTATUS SZFLAG + 2*SZIOINT + SZADDR
  139. #define XACCESS SZFLAG + 2*SZIOINT + 2*SZADDR
  140. #define XFORMATTED SZFLAG + 2*SZIOINT + 3*SZADDR
  141. #define XRECLEN SZFLAG + 2*SZIOINT + 4*SZADDR
  142. #define XBLANK SZFLAG + 3*SZIOINT + 4*SZADDR
  143. /* offset for CLOSE statement */
  144. #define XCLSTATUS SZFLAG + SZIOINT
  145. /* offsets for INQUIRE statement */
  146. #define XFILE SZFLAG + SZIOINT
  147. #define XFILELEN SZFLAG + SZIOINT + SZADDR
  148. #define XEXISTS SZFLAG + 2*SZIOINT + SZADDR
  149. #define XOPEN SZFLAG + 2*SZIOINT + 2*SZADDR
  150. #define XNUMBER SZFLAG + 2*SZIOINT + 3*SZADDR
  151. #define XNAMED SZFLAG + 2*SZIOINT + 4*SZADDR
  152. #define XNAME SZFLAG + 2*SZIOINT + 5*SZADDR
  153. #define XNAMELEN SZFLAG + 2*SZIOINT + 6*SZADDR
  154. #define XQACCESS SZFLAG + 3*SZIOINT + 6*SZADDR
  155. #define XQACCLEN SZFLAG + 3*SZIOINT + 7*SZADDR
  156. #define XSEQ SZFLAG + 4*SZIOINT + 7*SZADDR
  157. #define XSEQLEN SZFLAG + 4*SZIOINT + 8*SZADDR
  158. #define XDIRECT SZFLAG + 5*SZIOINT + 8*SZADDR
  159. #define XDIRLEN SZFLAG + 5*SZIOINT + 9*SZADDR
  160. #define XFORM SZFLAG + 6*SZIOINT + 9*SZADDR
  161. #define XFORMLEN SZFLAG + 6*SZIOINT + 10*SZADDR
  162. #define XFMTED SZFLAG + 7*SZIOINT + 10*SZADDR
  163. #define XFMTEDLEN SZFLAG + 7*SZIOINT + 11*SZADDR
  164. #define XUNFMT SZFLAG + 8*SZIOINT + 11*SZADDR
  165. #define XUNFMTLEN SZFLAG + 8*SZIOINT + 12*SZADDR
  166. #define XQRECL SZFLAG + 9*SZIOINT + 12*SZADDR
  167. #define XNEXTREC SZFLAG + 9*SZIOINT + 13*SZADDR
  168. #define XQBLANK SZFLAG + 9*SZIOINT + 14*SZADDR
  169. #define XQBLANKLEN SZFLAG + 9*SZIOINT + 15*SZADDR
  170. LOCAL char *cilist_names[] = {
  171. "cilist",
  172. "cierr",
  173. "ciunit",
  174. "ciend",
  175. "cifmt",
  176. "cirec"
  177. };
  178. LOCAL char *icilist_names[] = {
  179. "icilist",
  180. "icierr",
  181. "iciunit",
  182. "iciend",
  183. "icifmt",
  184. "icirlen",
  185. "icirnum"
  186. };
  187. LOCAL char *olist_names[] = {
  188. "olist",
  189. "oerr",
  190. "ounit",
  191. "ofnm",
  192. "ofnmlen",
  193. "osta",
  194. "oacc",
  195. "ofm",
  196. "orl",
  197. "oblnk"
  198. };
  199. LOCAL char *cllist_names[] = {
  200. "cllist",
  201. "cerr",
  202. "cunit",
  203. "csta"
  204. };
  205. LOCAL char *alist_names[] = {
  206. "alist",
  207. "aerr",
  208. "aunit"
  209. };
  210. LOCAL char *inlist_names[] = {
  211. "inlist",
  212. "inerr",
  213. "inunit",
  214. "infile",
  215. "infilen",
  216. "inex",
  217. "inopen",
  218. "innum",
  219. "innamed",
  220. "inname",
  221. "innamlen",
  222. "inacc",
  223. "inacclen",
  224. "inseq",
  225. "inseqlen",
  226. "indir",
  227. "indirlen",
  228. "infmt",
  229. "infmtlen",
  230. "inform",
  231. "informlen",
  232. "inunf",
  233. "inunflen",
  234. "inrecl",
  235. "innrec",
  236. "inblank",
  237. "inblanklen"
  238. };
  239. LOCAL char **io_fields;
  240. #define zork(n,t) n, sizeof(n)/sizeof(char *) - 1, t
  241. LOCAL io_setup io_stuff[] = {
  242. zork(cilist_names, TYCILIST), /* external read/write */
  243. zork(inlist_names, TYINLIST), /* inquire */
  244. zork(olist_names, TYOLIST), /* open */
  245. zork(cllist_names, TYCLLIST), /* close */
  246. zork(alist_names, TYALIST), /* rewind */
  247. zork(alist_names, TYALIST), /* backspace */
  248. zork(alist_names, TYALIST), /* endfile */
  249. zork(icilist_names,TYICILIST), /* internal read */
  250. zork(icilist_names,TYICILIST) /* internal write */
  251. };
  252. #undef zork
  253. int
  254. #ifdef KR_headers
  255. fmtstmt(lp)
  256. register struct Labelblock *lp;
  257. #else
  258. fmtstmt(register struct Labelblock *lp)
  259. #endif
  260. {
  261. if(lp == NULL)
  262. {
  263. execerr("unlabeled format statement" , CNULL);
  264. return(-1);
  265. }
  266. if(lp->labtype == LABUNKNOWN)
  267. {
  268. lp->labtype = LABFORMAT;
  269. lp->labelno = (int)newlabel();
  270. }
  271. else if(lp->labtype != LABFORMAT)
  272. {
  273. execerr("bad format number", CNULL);
  274. return(-1);
  275. }
  276. return(lp->labelno);
  277. }
  278. void
  279. #ifdef KR_headers
  280. setfmt(lp)
  281. struct Labelblock *lp;
  282. #else
  283. setfmt(struct Labelblock *lp)
  284. #endif
  285. {
  286. char *s, *s0, *sc, *se, *t;
  287. int k, n, parity;
  288. s0 = s = lexline(&n);
  289. se = t = s + n;
  290. /* warn of trivial errors, e.g. " 11 CONTINUE" (one too few spaces) */
  291. /* following FORMAT... */
  292. if (n <= 0)
  293. warn("No (...) after FORMAT");
  294. else if (*s != '(')
  295. warni("%c rather than ( after FORMAT", *s);
  296. else if (se[-1] != ')') {
  297. *se = 0;
  298. while(--t > s && *t != ')') ;
  299. if (t <= s)
  300. warn("No ) at end of FORMAT statement");
  301. else if (se - t > 30)
  302. warn1("Extraneous text at end of FORMAT: ...%s", se-12);
  303. else
  304. warn1("Extraneous text at end of FORMAT: %s", t+1);
  305. t = se;
  306. }
  307. /* fix MYQUOTES (\002's) and \\'s */
  308. parity = 1;
  309. str_fmt['%'] = "%";
  310. while(s < se) {
  311. k = *(unsigned char *)s++;
  312. if (k == 2) {
  313. if ((parity ^= 1) && *s == 2) {
  314. t -= 2;
  315. ++s;
  316. }
  317. else
  318. t += 3;
  319. }
  320. else {
  321. sc = str_fmt[k];
  322. while(*++sc)
  323. t++;
  324. }
  325. }
  326. s = s0;
  327. parity = 1;
  328. if (lp) {
  329. lp->fmtstring = t = mem((int)(t - s + 1), 0);
  330. while(s < se) {
  331. k = *(unsigned char *)s++;
  332. if (k == 2) {
  333. if ((parity ^= 1) && *s == 2)
  334. s++;
  335. else {
  336. t[0] = '\\';
  337. t[1] = '0';
  338. t[2] = '0';
  339. t[3] = '2';
  340. t += 4;
  341. }
  342. }
  343. else {
  344. sc = str_fmt[k];
  345. do *t++ = *sc++;
  346. while(*sc);
  347. }
  348. }
  349. *t = 0;
  350. }
  351. str_fmt['%'] = "%%";
  352. flline();
  353. }
  354. void
  355. #ifdef KR_headers
  356. startioctl()
  357. #else
  358. startioctl()
  359. #endif
  360. {
  361. register int i;
  362. inioctl = YES;
  363. nioctl = 0;
  364. ioformatted = UNFORMATTED;
  365. for(i = 1 ; i<=NIOS ; ++i)
  366. V(i) = NULL;
  367. }
  368. static long
  369. newiolabel(Void) {
  370. long rv;
  371. rv = ++lastiolabno;
  372. skiplabel = mklabel(rv);
  373. skiplabel->labdefined = 1;
  374. return rv;
  375. }
  376. void
  377. endioctl(Void)
  378. {
  379. int i;
  380. expptr p;
  381. struct io_setup *ios;
  382. inioctl = NO;
  383. /* set up for error recovery */
  384. ioerrlab = ioendlab = skiplab = jumplab = 0;
  385. if(p = V(IOSEND))
  386. if(ISICON(p))
  387. execlab(ioendlab = p->constblock.Const.ci);
  388. else
  389. err("bad end= clause");
  390. if(p = V(IOSERR))
  391. if(ISICON(p))
  392. execlab(ioerrlab = p->constblock.Const.ci);
  393. else
  394. err("bad err= clause");
  395. if(IOSTP)
  396. if(IOSTP->tag!=TADDR || ! ISINT(IOSTP->addrblock.vtype) )
  397. {
  398. err("iostat must be an integer variable");
  399. frexpr(IOSTP);
  400. IOSTP = NULL;
  401. }
  402. if(iostmt == IOREAD)
  403. {
  404. if(IOSTP)
  405. {
  406. if(ioerrlab && ioendlab && ioerrlab==ioendlab)
  407. jumplab = ioerrlab;
  408. else
  409. skiplab = jumplab = newiolabel();
  410. }
  411. else {
  412. if(ioerrlab && ioendlab && ioerrlab!=ioendlab)
  413. {
  414. IOSTP = (expptr) mktmp(TYINT, ENULL);
  415. skiplab = jumplab = newiolabel();
  416. }
  417. else
  418. jumplab = (ioerrlab ? ioerrlab : ioendlab);
  419. }
  420. }
  421. else if(iostmt == IOWRITE)
  422. {
  423. if(IOSTP && !ioerrlab)
  424. skiplab = jumplab = newiolabel();
  425. else
  426. jumplab = ioerrlab;
  427. }
  428. else
  429. jumplab = ioerrlab;
  430. endbit = IOSTP!=NULL || ioendlab!=0; /* for use in startrw() */
  431. errbit = IOSTP!=NULL || ioerrlab!=0;
  432. if (jumplab && !IOSTP)
  433. IOSTP = (expptr) mktmp(TYINT, ENULL);
  434. if(iostmt!=IOREAD && iostmt!=IOWRITE)
  435. {
  436. ios = io_stuff + iostmt;
  437. io_fields = ios->fields;
  438. ioblkp = io_structs[iostmt];
  439. if(ioblkp == NULL)
  440. io_structs[iostmt] = ioblkp =
  441. autovar(1, ios->type, ENULL, "");
  442. ioset(TYIOINT, XERR, ICON(errbit));
  443. }
  444. switch(iostmt)
  445. {
  446. case IOOPEN:
  447. dofopen();
  448. break;
  449. case IOCLOSE:
  450. dofclose();
  451. break;
  452. case IOINQUIRE:
  453. dofinquire();
  454. break;
  455. case IOBACKSPACE:
  456. dofmove("f_back");
  457. break;
  458. case IOREWIND:
  459. dofmove("f_rew");
  460. break;
  461. case IOENDFILE:
  462. dofmove("f_end");
  463. break;
  464. case IOREAD:
  465. case IOWRITE:
  466. startrw();
  467. break;
  468. default:
  469. fatali("impossible iostmt %d", iostmt);
  470. }
  471. for(i = 1 ; i<=NIOS ; ++i)
  472. if(i!=IOSIOSTAT && V(i)!=NULL)
  473. frexpr(V(i));
  474. }
  475. int
  476. iocname(Void)
  477. {
  478. register int i;
  479. int found, mask;
  480. found = 0;
  481. mask = M(iostmt);
  482. for(i = 1 ; i <= NIOS ; ++i)
  483. if(!strcmp(ioc[i].iocname, token))
  484. if(ioc[i].iotype & mask)
  485. return(i);
  486. else {
  487. found = i;
  488. break;
  489. }
  490. if(found) {
  491. if (iostmt == IOOPEN && !strcmp(ioc[i].iocname, "name")) {
  492. NOEXT("open with \"name=\" treated as \"file=\"");
  493. for(i = 1; strcmp(ioc[i].iocname, "file"); i++);
  494. return i;
  495. }
  496. errstr("invalid control %s for statement", ioc[found].iocname);
  497. }
  498. else
  499. errstr("unknown iocontrol %s", token);
  500. return(IOSBAD);
  501. }
  502. void
  503. #ifdef KR_headers
  504. ioclause(n, p)
  505. register int n;
  506. register expptr p;
  507. #else
  508. ioclause(register int n, register expptr p)
  509. #endif
  510. {
  511. struct Ioclist *iocp;
  512. ++nioctl;
  513. if(n == IOSBAD)
  514. return;
  515. if(n == IOSPOSITIONAL)
  516. {
  517. n = nioctl;
  518. if (n == IOSFMT) {
  519. if (iostmt == IOOPEN) {
  520. n = IOSFILE;
  521. NOEXT("file= specifier omitted from open");
  522. }
  523. else if (iostmt < IOREAD)
  524. goto illegal;
  525. }
  526. else if(n > IOSFMT)
  527. {
  528. illegal:
  529. err("illegal positional iocontrol");
  530. return;
  531. }
  532. }
  533. else if (n == IOSNML)
  534. n = IOSFMT;
  535. if(p == NULL)
  536. {
  537. if(n == IOSUNIT)
  538. p = (expptr) (iostmt==IOREAD ? IOSTDIN : IOSTDOUT);
  539. else if(n != IOSFMT)
  540. {
  541. err("illegal * iocontrol");
  542. return;
  543. }
  544. }
  545. if(n == IOSFMT)
  546. ioformatted = (p==NULL ? LISTDIRECTED : FORMATTED);
  547. iocp = & ioc[n];
  548. if(iocp->iocval == NULL)
  549. {
  550. if(n!=IOSFMT && ( n!=IOSUNIT || (p && p->headblock.vtype!=TYCHAR) ) )
  551. p = fixtype(p);
  552. else if (p && p->tag == TPRIM
  553. && p->primblock.namep->vclass == CLUNKNOWN) {
  554. /* kludge made necessary by attempt to infer types
  555. * for untyped external parameters: given an error
  556. * in calling sequences, an integer argument might
  557. * tentatively be assumed TYCHAR; this would otherwise
  558. * be corrected too late in startrw after startrw
  559. * had decided this to be an internal file.
  560. */
  561. vardcl(p->primblock.namep);
  562. p->primblock.vtype = p->primblock.namep->vtype;
  563. }
  564. iocp->iocval = p;
  565. }
  566. else
  567. errstr("iocontrol %s repeated", iocp->iocname);
  568. }
  569. /* io list item */
  570. void
  571. #ifdef KR_headers
  572. doio(list)
  573. chainp list;
  574. #else
  575. doio(chainp list)
  576. #endif
  577. {
  578. if(ioformatted == NAMEDIRECTED)
  579. {
  580. if(list)
  581. err("no I/O list allowed in NAMELIST read/write");
  582. }
  583. else
  584. {
  585. doiolist(list);
  586. ioroutine[0] = 'e';
  587. if (skiplab)
  588. jumplab = 0;
  589. putiocall( call0(TYINT, ioroutine) );
  590. }
  591. }
  592. LOCAL void
  593. #ifdef KR_headers
  594. doiolist(p0)
  595. chainp p0;
  596. #else
  597. doiolist(chainp p0)
  598. #endif
  599. {
  600. chainp p;
  601. register tagptr q;
  602. register expptr qe;
  603. register Namep qn;
  604. Addrp tp;
  605. int range;
  606. extern char *ohalign;
  607. for (p = p0 ; p ; p = p->nextp)
  608. {
  609. q = (tagptr)p->datap;
  610. if(q->tag == TIMPLDO)
  611. {
  612. exdo(range = (int)newlabel(), (Namep)0,
  613. q->impldoblock.impdospec);
  614. doiolist(q->impldoblock.datalist);
  615. enddo(range);
  616. free( (charptr) q);
  617. }
  618. else {
  619. if(q->tag==TPRIM && q->primblock.argsp==NULL
  620. && q->primblock.namep->vdim!=NULL)
  621. {
  622. vardcl(qn = q->primblock.namep);
  623. if(qn->vdim->nelt) {
  624. putio( fixtype(cpexpr(qn->vdim->nelt)),
  625. (expptr)mkscalar(qn) );
  626. qn->vlastdim = 0;
  627. }
  628. else
  629. err("attempt to i/o array of unknown size");
  630. }
  631. else if(q->tag==TPRIM && q->primblock.argsp==NULL &&
  632. (qe = (expptr) memversion(q->primblock.namep)) )
  633. putio(ICON(1),qe);
  634. else if (ISCONST(q) && q->constblock.vtype == TYCHAR) {
  635. halign = 0;
  636. putio(ICON(1), qe = fixtype(cpexpr(q)));
  637. halign = ohalign;
  638. }
  639. else if(((qe = fixtype(cpexpr(q)))->tag==TADDR &&
  640. (qe->addrblock.uname_tag != UNAM_CONST ||
  641. !ISCOMPLEX(qe -> addrblock.vtype))) ||
  642. (qe -> tag == TCONST && !ISCOMPLEX(qe ->
  643. headblock.vtype))) {
  644. if (qe -> tag == TCONST)
  645. qe = (expptr) putconst((Constp)qe);
  646. putio(ICON(1), qe);
  647. }
  648. else if(qe->headblock.vtype != TYERROR)
  649. {
  650. if(iostmt == IOWRITE)
  651. {
  652. expptr qvl;
  653. qvl = NULL;
  654. if( ISCHAR(qe) )
  655. {
  656. qvl = (expptr)
  657. cpexpr(qe->headblock.vleng);
  658. tp = mktmp(qe->headblock.vtype,
  659. ICON(lencat(qe)));
  660. }
  661. else
  662. tp = mktmp(qe->headblock.vtype,
  663. qe->headblock.vleng);
  664. puteq( cpexpr((expptr)tp), qe);
  665. if(qvl) /* put right length on block */
  666. {
  667. frexpr(tp->vleng);
  668. tp->vleng = qvl;
  669. }
  670. putio(ICON(1), (expptr)tp);
  671. }
  672. else
  673. err("non-left side in READ list");
  674. }
  675. frexpr(q);
  676. }
  677. }
  678. frchain( &p0 );
  679. }
  680. int iocalladdr = TYADDR; /* for fixing TYADDR in saveargtypes */
  681. int typeconv[TYERROR+1] = {
  682. #ifdef TYQUAD
  683. 0, 1, 11, 2, 3, 14, 4, 5, 6, 7, 12, 13, 8, 9, 10, 15
  684. #else
  685. 0, 1, 11, 2, 3, 4, 5, 6, 7, 12, 13, 8, 9, 10, 14
  686. #endif
  687. };
  688. LOCAL void
  689. #ifdef KR_headers
  690. putio(nelt, addr)
  691. expptr nelt;
  692. register expptr addr;
  693. #else
  694. putio(expptr nelt, register expptr addr)
  695. #endif
  696. {
  697. int type;
  698. register expptr q;
  699. register Addrp c = 0;
  700. type = addr->headblock.vtype;
  701. if(ioformatted!=LISTDIRECTED && ISCOMPLEX(type) )
  702. {
  703. nelt = mkexpr(OPSTAR, ICON(2), nelt);
  704. type -= (TYCOMPLEX-TYREAL);
  705. }
  706. /* pass a length with every item. for noncharacter data, fake one */
  707. if(type != TYCHAR)
  708. {
  709. if( ISCONST(addr) )
  710. addr = (expptr) putconst((Constp)addr);
  711. c = ALLOC(Addrblock);
  712. c->tag = TADDR;
  713. c->vtype = TYLENG;
  714. c->vstg = STGAUTO;
  715. c->ntempelt = 1;
  716. c->isarray = 1;
  717. c->memoffset = ICON(0);
  718. c->uname_tag = UNAM_IDENT;
  719. c->charleng = 1;
  720. sprintf(c->user.ident, "(ftnlen)sizeof(%s)", Typename[type]);
  721. addr = mkexpr(OPCHARCAST, addr, ENULL);
  722. }
  723. nelt = fixtype( mkconv(tyioint,nelt) );
  724. if(ioformatted == LISTDIRECTED) {
  725. expptr mc = mkconv(tyioint, ICON(typeconv[type]));
  726. q = c ? call4(TYINT, "do_lio", mc, nelt, addr, (expptr)c)
  727. : call3(TYINT, "do_lio", mc, nelt, addr);
  728. }
  729. else {
  730. char *s = (char*)(ioformatted==FORMATTED ? "do_fio"
  731. : !byterev ? "do_uio"
  732. : ONEOF(type, M(TYCHAR)|M(TYINT1)|M(TYLOGICAL1))
  733. ? "do_ucio" : "do_unio");
  734. q = c ? call3(TYINT, s, nelt, addr, (expptr)c)
  735. : call2(TYINT, s, nelt, addr);
  736. }
  737. iocalladdr = TYCHAR;
  738. putiocall(q);
  739. iocalladdr = TYADDR;
  740. }
  741. void
  742. endio(Void)
  743. {
  744. if(skiplab)
  745. {
  746. if (ioformatted != NAMEDIRECTED)
  747. p1_label((long)(skiplabel - labeltab));
  748. if(ioendlab) {
  749. exif( mkexpr(OPLT, cpexpr(IOSTP), ICON(0)));
  750. exgoto(execlab(ioendlab));
  751. exendif();
  752. }
  753. if(ioerrlab) {
  754. exif( mkexpr(iostmt==IOREAD||iostmt==IOWRITE
  755. ? OPGT : OPNE,
  756. cpexpr(IOSTP), ICON(0)));
  757. exgoto(execlab(ioerrlab));
  758. exendif();
  759. }
  760. }
  761. if(IOSTP)
  762. frexpr(IOSTP);
  763. }
  764. LOCAL void
  765. #ifdef KR_headers
  766. putiocall(q)
  767. register expptr q;
  768. #else
  769. putiocall(register expptr q)
  770. #endif
  771. {
  772. int tyintsave;
  773. tyintsave = tyint;
  774. tyint = tyioint; /* for -I2 and -i2 */
  775. if(IOSTP)
  776. {
  777. q->headblock.vtype = TYINT;
  778. q = fixexpr((Exprp)mkexpr(OPASSIGN, cpexpr(IOSTP), q));
  779. }
  780. putexpr(q);
  781. if(jumplab) {
  782. exif(mkexpr(OPNE, cpexpr(IOSTP), ICON(0)));
  783. exgoto(execlab(jumplab));
  784. exendif();
  785. }
  786. tyint = tyintsave;
  787. }
  788. void
  789. #ifdef KR_headers
  790. fmtname(np, q)
  791. Namep np;
  792. register Addrp q;
  793. #else
  794. fmtname(Namep np, register Addrp q)
  795. #endif
  796. {
  797. register int k;
  798. register char *s, *t;
  799. extern chainp assigned_fmts;
  800. if (!np->vfmt_asg) {
  801. np->vfmt_asg = 1;
  802. assigned_fmts = mkchain((char *)np, assigned_fmts);
  803. }
  804. k = strlen(s = np->fvarname);
  805. if (k < IDENT_LEN - 4) {
  806. q->uname_tag = UNAM_IDENT;
  807. t = q->user.ident;
  808. }
  809. else {
  810. q->uname_tag = UNAM_CHARP;
  811. q->user.Charp = t = mem(k + 5,0);
  812. }
  813. sprintf(t, "%s_fmt", s);
  814. }
  815. LOCAL Addrp
  816. #ifdef KR_headers
  817. asg_addr(p)
  818. union Expression *p;
  819. #else
  820. asg_addr(union Expression *p)
  821. #endif
  822. {
  823. register Addrp q;
  824. if (p->tag != TPRIM)
  825. badtag("asg_addr", p->tag);
  826. q = ALLOC(Addrblock);
  827. q->tag = TADDR;
  828. q->vtype = TYCHAR;
  829. q->vstg = STGAUTO;
  830. q->ntempelt = 1;
  831. q->isarray = 0;
  832. q->memoffset = ICON(0);
  833. fmtname(p->primblock.namep, q);
  834. return q;
  835. }
  836. void
  837. startrw(Void)
  838. {
  839. register expptr p;
  840. register Namep np;
  841. register Addrp unitp, fmtp, recp;
  842. register expptr nump;
  843. int iostmt1;
  844. flag intfile, sequential, ok, varfmt;
  845. struct io_setup *ios;
  846. /* First look at all the parameters and determine what is to be done */
  847. ok = YES;
  848. statstruct = YES;
  849. intfile = NO;
  850. if(p = V(IOSUNIT))
  851. {
  852. if( ISINT(p->headblock.vtype) ) {
  853. int_unit:
  854. unitp = (Addrp) cpexpr(p);
  855. }
  856. else if(p->headblock.vtype == TYCHAR)
  857. {
  858. if (nioctl == 1 && iostmt == IOREAD) {
  859. /* kludge to recognize READ(format expr) */
  860. V(IOSFMT) = p;
  861. V(IOSUNIT) = p = (expptr) IOSTDIN;
  862. ioformatted = FORMATTED;
  863. goto int_unit;
  864. }
  865. intfile = YES;
  866. if(p->tag==TPRIM && p->primblock.argsp==NULL &&
  867. (np = p->primblock.namep)->vdim!=NULL)
  868. {
  869. vardcl(np);
  870. if(nump = np->vdim->nelt)
  871. {
  872. nump = fixtype(cpexpr(nump));
  873. if( ! ISCONST(nump) ) {
  874. statstruct = NO;
  875. np->vlastdim = 0;
  876. }
  877. }
  878. else
  879. {
  880. err("attempt to use internal unit array of unknown size");
  881. ok = NO;
  882. nump = ICON(1);
  883. }
  884. unitp = mkscalar(np);
  885. }
  886. else {
  887. nump = ICON(1);
  888. unitp = (Addrp /*pjw */) fixtype(cpexpr(p));
  889. }
  890. if(! isstatic((expptr)unitp) )
  891. statstruct = NO;
  892. }
  893. else {
  894. err("unit specifier not of type integer or character");
  895. ok = NO;
  896. }
  897. }
  898. else
  899. {
  900. err("bad unit specifier");
  901. ok = NO;
  902. }
  903. sequential = YES;
  904. if(p = V(IOSREC))
  905. if( ISINT(p->headblock.vtype) )
  906. {
  907. recp = (Addrp) cpexpr(p);
  908. sequential = NO;
  909. }
  910. else {
  911. err("bad REC= clause");
  912. ok = NO;
  913. }
  914. else
  915. recp = NULL;
  916. varfmt = YES;
  917. fmtp = NULL;
  918. if(p = V(IOSFMT))
  919. {
  920. if(p->tag==TPRIM && p->primblock.argsp==NULL)
  921. {
  922. np = p->primblock.namep;
  923. if(np->vclass == CLNAMELIST)
  924. {
  925. ioformatted = NAMEDIRECTED;
  926. fmtp = (Addrp) fixtype(p);
  927. V(IOSFMT) = (expptr)fmtp;
  928. if (skiplab)
  929. jumplab = 0;
  930. goto endfmt;
  931. }
  932. vardcl(np);
  933. if(np->vdim)
  934. {
  935. if( ! ONEOF(np->vstg, MSKSTATIC) )
  936. statstruct = NO;
  937. fmtp = mkscalar(np);
  938. goto endfmt;
  939. }
  940. if( ISINT(np->vtype) ) /* ASSIGNed label */
  941. {
  942. statstruct = NO;
  943. varfmt = YES;
  944. fmtp = asg_addr(p);
  945. goto endfmt;
  946. }
  947. }
  948. p = V(IOSFMT) = fixtype(p);
  949. if(p->headblock.vtype == TYCHAR
  950. /* Since we allow write(6,n) */
  951. /* we may as well allow write(6,n(2)) */
  952. || p->tag == TADDR && ISINT(p->addrblock.vtype))
  953. {
  954. if( ! isstatic(p) )
  955. statstruct = NO;
  956. fmtp = (Addrp) cpexpr(p);
  957. }
  958. else if( ISICON(p) )
  959. {
  960. struct Labelblock *lp;
  961. lp = mklabel(p->constblock.Const.ci);
  962. if (fmtstmt(lp) > 0)
  963. {
  964. fmtp = (Addrp)mkaddcon(lp->stateno);
  965. /* lp->stateno for names fmt_nnn */
  966. lp->fmtlabused = 1;
  967. varfmt = NO;
  968. }
  969. else
  970. ioformatted = UNFORMATTED;
  971. }
  972. else {
  973. err("bad format descriptor");
  974. ioformatted = UNFORMATTED;
  975. ok = NO;
  976. }
  977. }
  978. else
  979. fmtp = NULL;
  980. endfmt:
  981. if(intfile) {
  982. if (ioformatted==UNFORMATTED) {
  983. err("unformatted internal I/O not allowed");
  984. ok = NO;
  985. }
  986. if (recp) {
  987. err("direct internal I/O not allowed");
  988. ok = NO;
  989. }
  990. }
  991. if(!sequential && ioformatted==LISTDIRECTED)
  992. {
  993. err("direct list-directed I/O not allowed");
  994. ok = NO;
  995. }
  996. if(!sequential && ioformatted==NAMEDIRECTED)
  997. {
  998. err("direct namelist I/O not allowed");
  999. ok = NO;
  1000. }
  1001. if( ! ok ) {
  1002. statstruct = NO;
  1003. return;
  1004. }
  1005. /*
  1006. Now put out the I/O structure, statically if all the clauses
  1007. are constants, dynamically otherwise
  1008. */
  1009. if (intfile) {
  1010. ios = io_stuff + iostmt;
  1011. iostmt1 = IOREAD;
  1012. }
  1013. else {
  1014. ios = io_stuff;
  1015. iostmt1 = 0;
  1016. }
  1017. io_fields = ios->fields;
  1018. if(statstruct)
  1019. {
  1020. ioblkp = ALLOC(Addrblock);
  1021. ioblkp->tag = TADDR;
  1022. ioblkp->vtype = ios->type;
  1023. ioblkp->vclass = CLVAR;
  1024. ioblkp->vstg = STGINIT;
  1025. ioblkp->memno = ++lastvarno;
  1026. ioblkp->memoffset = ICON(0);
  1027. ioblkp -> uname_tag = UNAM_IDENT;
  1028. new_iob_data(ios,
  1029. temp_name("io_", lastvarno, ioblkp->user.ident)); }
  1030. else if(!(ioblkp = io_structs[iostmt1]))
  1031. io_structs[iostmt1] = ioblkp =
  1032. autovar(1, ios->type, ENULL, "");
  1033. ioset(TYIOINT, XERR, ICON(errbit));
  1034. if(iostmt == IOREAD)
  1035. ioset(TYIOINT, (intfile ? XIEND : XEND), ICON(endbit) );
  1036. if(intfile)
  1037. {
  1038. ioset(TYIOINT, XIRNUM, nump);
  1039. ioset(TYIOINT, XIRLEN, cpexpr(unitp->vleng) );
  1040. ioseta(XIUNIT, unitp);
  1041. }
  1042. else
  1043. ioset(TYIOINT, XUNIT, (expptr) unitp);
  1044. if(recp)
  1045. ioset(TYIOINT, /* intfile ? XIREC : */ XREC, (expptr) recp);
  1046. if(varfmt)
  1047. ioseta( intfile ? XIFMT : XFMT , fmtp);
  1048. else
  1049. ioset(TYADDR, intfile ? XIFMT : XFMT, (expptr) fmtp);
  1050. ioroutine[0] = 's';
  1051. ioroutine[1] = '_';
  1052. ioroutine[2] = iostmt==IOREAD ? 'r' : 'w';
  1053. ioroutine[3] = "ds"[sequential];
  1054. ioroutine[4] = "ufln"[ioformatted];
  1055. ioroutine[5] = "ei"[intfile];
  1056. ioroutine[6] = '\0';
  1057. putiocall( call1(TYINT, ioroutine, cpexpr((expptr)ioblkp) ));
  1058. if(statstruct)
  1059. {
  1060. frexpr((expptr)ioblkp);
  1061. statstruct = NO;
  1062. ioblkp = 0; /* unnecessary */
  1063. }
  1064. }
  1065. LOCAL void
  1066. dofopen(Void)
  1067. {
  1068. register expptr p;
  1069. if( (p = V(IOSUNIT)) && ISINT(p->headblock.vtype) )
  1070. ioset(TYIOINT, XUNIT, cpexpr(p) );
  1071. else
  1072. err("bad unit in open");
  1073. if( (p = V(IOSFILE)) )
  1074. if(p->headblock.vtype == TYCHAR)
  1075. ioset(TYIOINT, XFNAMELEN, cpexpr(p->headblock.vleng) );
  1076. else
  1077. err("bad file in open");
  1078. iosetc(XFNAME, p);
  1079. if(p = V(IOSRECL))
  1080. if( ISINT(p->headblock.vtype) )
  1081. ioset(TYIOINT, XRECLEN, cpexpr(p) );
  1082. else
  1083. err("bad recl");
  1084. else
  1085. ioset(TYIOINT, XRECLEN, ICON(0) );
  1086. iosetc(XSTATUS, V(IOSSTATUS));
  1087. iosetc(XACCESS, V(IOSACCESS));
  1088. iosetc(XFORMATTED, V(IOSFORM));
  1089. iosetc(XBLANK, V(IOSBLANK));
  1090. putiocall( call1(TYINT, "f_open", cpexpr((expptr)ioblkp) ));
  1091. }
  1092. LOCAL void
  1093. dofclose(Void)
  1094. {
  1095. register expptr p;
  1096. if( (p = V(IOSUNIT)) && ISINT(p->headblock.vtype) )
  1097. {
  1098. ioset(TYIOINT, XUNIT, cpexpr(p) );
  1099. iosetc(XCLSTATUS, V(IOSSTATUS));
  1100. putiocall( call1(TYINT, "f_clos", cpexpr((expptr)ioblkp)) );
  1101. }
  1102. else
  1103. err("bad unit in close statement");
  1104. }
  1105. LOCAL void
  1106. dofinquire(Void)
  1107. {
  1108. register expptr p;
  1109. if(p = V(IOSUNIT))
  1110. {
  1111. if( V(IOSFILE) )
  1112. err("inquire by unit or by file, not both");
  1113. ioset(TYIOINT, XUNIT, cpexpr(p) );
  1114. }
  1115. else if( ! V(IOSFILE) )
  1116. err("must inquire by unit or by file");
  1117. iosetlc(IOSFILE, XFILE, XFILELEN);
  1118. iosetip(IOSEXISTS, XEXISTS);
  1119. iosetip(IOSOPENED, XOPEN);
  1120. iosetip(IOSNUMBER, XNUMBER);
  1121. iosetip(IOSNAMED, XNAMED);
  1122. iosetlc(IOSNAME, XNAME, XNAMELEN);
  1123. iosetlc(IOSACCESS, XQACCESS, XQACCLEN);
  1124. iosetlc(IOSSEQUENTIAL, XSEQ, XSEQLEN);
  1125. iosetlc(IOSDIRECT, XDIRECT, XDIRLEN);
  1126. iosetlc(IOSFORM, XFORM, XFORMLEN);
  1127. iosetlc(IOSFORMATTED, XFMTED, XFMTEDLEN);
  1128. iosetlc(IOSUNFORMATTED, XUNFMT, XUNFMTLEN);
  1129. iosetip(IOSRECL, XQRECL);
  1130. iosetip(IOSNEXTREC, XNEXTREC);
  1131. iosetlc(IOSBLANK, XQBLANK, XQBLANKLEN);
  1132. putiocall( call1(TYINT, "f_inqu", cpexpr((expptr)ioblkp) ));
  1133. }
  1134. LOCAL void
  1135. #ifdef KR_headers
  1136. dofmove(subname)
  1137. char *subname;
  1138. #else
  1139. dofmove(char *subname)
  1140. #endif
  1141. {
  1142. register expptr p;
  1143. if( (p = V(IOSUNIT)) && ISINT(p->headblock.vtype) )
  1144. {
  1145. ioset(TYIOINT, XUNIT, cpexpr(p) );
  1146. putiocall( call1(TYINT, subname, cpexpr((expptr)ioblkp) ));
  1147. }
  1148. else
  1149. err("bad unit in I/O motion statement");
  1150. }
  1151. static int ioset_assign = OPASSIGN;
  1152. LOCAL void
  1153. #ifdef KR_headers
  1154. ioset(type, offset, p)
  1155. int type;
  1156. int offset;
  1157. register expptr p;
  1158. #else
  1159. ioset(int type, int offset, register expptr p)
  1160. #endif
  1161. {
  1162. offset /= SZLONG;
  1163. if(statstruct && ISCONST(p)) {
  1164. register char *s;
  1165. switch(type) {
  1166. case TYADDR: /* stmt label */
  1167. s = "fmt_";
  1168. break;
  1169. case TYIOINT:
  1170. s = "";
  1171. break;
  1172. default:
  1173. badtype("ioset", type);
  1174. }
  1175. iob_list->fields[offset] =
  1176. string_num(s, p->constblock.Const.ci);
  1177. frexpr(p);
  1178. }
  1179. else {
  1180. register Addrp q;
  1181. q = ALLOC(Addrblock);
  1182. q->tag = TADDR;
  1183. q->vtype = type;
  1184. q->vstg = STGAUTO;
  1185. q->ntempelt = 1;
  1186. q->isarray = 0;
  1187. q->memoffset = ICON(0);
  1188. q->uname_tag = UNAM_IDENT;
  1189. sprintf(q->user.ident, "%s.%s",
  1190. statstruct ? iob_list->name : ioblkp->user.ident,
  1191. io_fields[offset + 1]);
  1192. if (type == TYADDR && p->tag == TCONST
  1193. && p->constblock.vtype == TYADDR) {
  1194. /* kludge */
  1195. register Addrp p1;
  1196. p1 = ALLOC(Addrblock);
  1197. p1->tag = TADDR;
  1198. p1->vtype = type;
  1199. p1->vstg = STGAUTO; /* wrong, but who cares? */
  1200. p1->ntempelt = 1;
  1201. p1->isarray = 0;
  1202. p1->memoffset = ICON(0);
  1203. p1->uname_tag = UNAM_IDENT;
  1204. sprintf(p1->user.ident, "fmt_%ld",
  1205. p->constblock.Const.ci);
  1206. frexpr(p);
  1207. p = (expptr)p1;
  1208. }
  1209. if (type == TYADDR && p->headblock.vtype == TYCHAR)
  1210. q->vtype = TYCHAR;
  1211. putexpr(mkexpr(ioset_assign, (expptr)q, p));
  1212. }
  1213. }
  1214. LOCAL void
  1215. #ifdef KR_headers
  1216. iosetc(offset, p)
  1217. int offset;
  1218. register expptr p;
  1219. #else
  1220. iosetc(int offset, register expptr p)
  1221. #endif
  1222. {
  1223. if(p == NULL)
  1224. ioset(TYADDR, offset, ICON(0) );
  1225. else if(p->headblock.vtype == TYCHAR) {
  1226. p = putx(fixtype((expptr)putchop(cpexpr(p))));
  1227. ioset(TYADDR, offset, addrof(p));
  1228. }
  1229. else
  1230. err("non-character control clause");
  1231. }
  1232. LOCAL void
  1233. #ifdef KR_headers
  1234. ioseta(offset, p)
  1235. int offset;
  1236. register Addrp p;
  1237. #else
  1238. ioseta(int offset, register Addrp p)
  1239. #endif
  1240. {
  1241. char *s, *s1;
  1242. static char who[] = "ioseta";
  1243. expptr e, mo;
  1244. Namep np;
  1245. ftnint ci;
  1246. int k;
  1247. char buf[24], buf1[24];
  1248. Extsym *comm;
  1249. extern int usedefsforcommon;
  1250. if(statstruct)
  1251. {
  1252. if (!p)
  1253. return;
  1254. if (p->tag != TADDR)
  1255. badtag(who, p->tag);
  1256. offset /= SZLONG;
  1257. switch(p->uname_tag) {
  1258. case UNAM_NAME:
  1259. mo = p->memoffset;
  1260. if (mo->tag != TCONST)
  1261. badtag("ioseta/memoffset", mo->tag);
  1262. np = p->user.name;
  1263. np->visused = 1;
  1264. ci = mo->constblock.Const.ci - np->voffset;
  1265. if (np->vstg == STGCOMMON
  1266. && !np->vcommequiv
  1267. && !usedefsforcommon) {
  1268. comm = &extsymtab[np->vardesc.varno];
  1269. sprintf(buf, "%d.", comm->curno);
  1270. k = strlen(buf) + strlen(comm->cextname)
  1271. + strlen(np->cvarname);
  1272. if (ci) {
  1273. sprintf(buf1, "+%ld", ci);
  1274. k += strlen(buf1);
  1275. }
  1276. else
  1277. buf1[0] = 0;
  1278. s = mem(k + 1, 0);
  1279. sprintf(s, "%s%s%s%s", comm->cextname, buf,
  1280. np->cvarname, buf1);
  1281. }
  1282. else if (ci) {
  1283. sprintf(buf,"%ld", ci);
  1284. s1 = p->user.name->cvarname;
  1285. k = strlen(buf) + strlen(s1);
  1286. sprintf(s = mem(k+2,0), "%s+%s", s1, buf);
  1287. }
  1288. else
  1289. s = cpstring(np->cvarname);
  1290. break;
  1291. case UNAM_CONST:
  1292. s = tostring(p->user.Const.ccp1.ccp0,
  1293. (int)p->vleng->constblock.Const.ci);
  1294. break;
  1295. default:
  1296. badthing("uname_tag", who, p->uname_tag);
  1297. }
  1298. /* kludge for Hollerith */
  1299. if (p->vtype != TYCHAR) {
  1300. s1 = mem(strlen(s)+10,0);
  1301. sprintf(s1, "(char *)%s%s", p->isarray ? "" : "&", s);
  1302. s = s1;
  1303. }
  1304. iob_list->fields[offset] = s;
  1305. }
  1306. else {
  1307. if (!p)
  1308. e = ICON(0);
  1309. else if (p->vtype != TYCHAR) {
  1310. NOEXT("non-character variable as format or internal unit");
  1311. e = mkexpr(OPCHARCAST, (expptr)p, ENULL);
  1312. }
  1313. else
  1314. e = addrof((expptr)p);
  1315. ioset(TYADDR, offset, e);
  1316. }
  1317. }
  1318. LOCAL void
  1319. #ifdef KR_headers
  1320. iosetip(i, offset)
  1321. int i;
  1322. int offset;
  1323. #else
  1324. iosetip(int i, int offset)
  1325. #endif
  1326. {
  1327. register expptr p;
  1328. if(p = V(i))
  1329. if(p->tag==TADDR &&
  1330. ONEOF(p->addrblock.vtype, inqmask) ) {
  1331. ioset_assign = OPASSIGNI;
  1332. ioset(TYADDR, offset, addrof(cpexpr(p)) );
  1333. ioset_assign = OPASSIGN;
  1334. }
  1335. else
  1336. errstr("impossible inquire parameter %s", ioc[i].iocname);
  1337. else
  1338. ioset(TYADDR, offset, ICON(0) );
  1339. }
  1340. LOCAL void
  1341. #ifdef KR_headers
  1342. iosetlc(i, offp, offl)
  1343. int i;
  1344. int offp;
  1345. int offl;
  1346. #else
  1347. iosetlc(int i, int offp, int offl)
  1348. #endif
  1349. {
  1350. register expptr p;
  1351. if( (p = V(i)) && p->headblock.vtype==TYCHAR)
  1352. ioset(TYIOINT, offl, cpexpr(p->headblock.vleng) );
  1353. iosetc(offp, p);
  1354. }