home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / f2csrc.zip / f2csrc / src / io.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  32KB  |  1,504 lines

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