home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / f2csrc.zip / f2csrc / src / names.c < prev    next >
C/C++ Source or Header  |  1994-03-05  |  22KB  |  817 lines

  1. /****************************************************************
  2. Copyright 1990, 1992 - 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. #include "defs.h"
  25. #include "output.h"
  26. #include "names.h"
  27. #include "iob.h"
  28.  
  29.  
  30. /* Names generated by the translator are guaranteed to be unique from the
  31.    Fortan names because Fortran does not allow underscores in identifiers,
  32.    and all of the system generated names do have underscores.  The various
  33.    naming conventions are outlined below:
  34.  
  35.     FORMAT        APPLICATION
  36.    ----------------------------------------------------------------------
  37.     io_#        temporaries generated by IO calls; these will
  38.             contain the device number (e.g. 5, 6, 0)
  39.     ret_val        function return value, required for complex and
  40.             character functions.
  41.     ret_val_len    length of the return value in character functions
  42.  
  43.     ssss_len    length of character argument "ssss"
  44.  
  45.     c_#        member of the literal pool, where # is an
  46.             arbitrary label assigned by the system
  47.     cs_#        short integer constant in the literal pool
  48.     t_#        expression temporary, # is the depth of arguments
  49.             on the stack.
  50.     L#        label "#", given by user in the Fortran program.
  51.             This is unique because Fortran labels are numeric
  52.     pad_#        label on an init field required for alignment
  53.     xxx_init    label on a common block union, if a block data
  54.             requires a separate declaration
  55. */
  56.  
  57. /* generate variable references */
  58.  
  59.  char *
  60. #ifdef KR_headers
  61. c_type_decl(type, is_extern)
  62.     int type;
  63.     int is_extern;
  64. #else
  65. c_type_decl(int type, int is_extern)
  66. #endif
  67. {
  68.     static char buff[100];
  69.  
  70.     switch (type) {
  71.     case TYREAL:    if (!is_extern || !forcedouble)
  72.                 { strcpy (buff, "real");break; }
  73.     case TYDREAL:    strcpy (buff, "doublereal");    break;
  74.     case TYCOMPLEX:    if (is_extern)
  75.                 strcpy (buff, "/* Complex */ VOID");
  76.             else
  77.                 strcpy (buff, "complex");
  78.             break;
  79.     case TYDCOMPLEX:if (is_extern)
  80.                 strcpy (buff, "/* Double Complex */ VOID");
  81.             else
  82.                 strcpy (buff, "doublecomplex");
  83.             break;
  84.     case TYADDR:
  85.     case TYINT1:
  86.     case TYSHORT:
  87.     case TYLONG:
  88. #ifdef TYQUAD
  89.     case TYQUAD:
  90. #endif
  91.     case TYLOGICAL1:
  92.     case TYLOGICAL2:
  93.     case TYLOGICAL:    strcpy(buff, typename[type]);
  94.             break;
  95.     case TYCHAR:    if (is_extern)
  96.                 strcpy (buff, "/* Character */ VOID");
  97.             else
  98.                 strcpy (buff, "char");
  99.             break;
  100.  
  101.         case TYUNKNOWN:    strcpy (buff, "UNKNOWN");
  102.  
  103. /* If a procedure's type is unknown, assume it's a subroutine */
  104.  
  105.             if (!is_extern)
  106.                 break;
  107.  
  108. /* Subroutines must return an INT, because they might return a label
  109.    value.  Even if one doesn't, the caller will EXPECT it to. */
  110.  
  111.     case TYSUBR:    strcpy (buff, "/* Subroutine */ int");
  112.                             break;
  113.     case TYERROR:    strcpy (buff, "ERROR");        break;
  114.     case TYVOID:    strcpy (buff, "void");        break;
  115.     case TYCILIST:    strcpy (buff, "cilist");    break;
  116.     case TYICILIST:    strcpy (buff, "icilist");    break;
  117.     case TYOLIST:    strcpy (buff, "olist");        break;
  118.     case TYCLLIST:    strcpy (buff, "cllist");    break;
  119.     case TYALIST:    strcpy (buff, "alist");        break;
  120.     case TYINLIST:    strcpy (buff, "inlist");    break;
  121.     case TYFTNLEN:    strcpy (buff, "ftnlen");    break;
  122.     default:    sprintf (buff, "BAD DECL '%d'", type);
  123.                             break;
  124.     } /* switch */
  125.  
  126.     return buff;
  127. } /* c_type_decl */
  128.  
  129.  
  130.  char *
  131. new_func_length(Void)
  132. { return "ret_val_len"; }
  133.  
  134.  char *
  135. #ifdef KR_headers
  136. new_arg_length(arg)
  137.     Namep arg;
  138. #else
  139. new_arg_length(Namep arg)
  140. #endif
  141. {
  142.     static char buf[64];
  143.     sprintf (buf, "%s_len", arg->fvarname);
  144.  
  145.     return buf;
  146. } /* new_arg_length */
  147.  
  148.  
  149. /* declare_new_addr -- Add a new local variable to the function, given a
  150.    pointer to an Addrblock structure (which must have the uname_tag set)
  151.    This list of idents will be printed in reverse (i.e., chronological)
  152.    order */
  153.  
  154.  void
  155. #ifdef KR_headers
  156. declare_new_addr(addrp)
  157.     struct Addrblock *addrp;
  158. #else
  159. declare_new_addr(struct Addrblock *addrp)
  160. #endif
  161. {
  162.     extern chainp new_vars;
  163.  
  164.     new_vars = mkchain((char *)cpexpr((expptr)addrp), new_vars);
  165. } /* declare_new_addr */
  166.  
  167.  
  168.  void
  169. #ifdef KR_headers
  170. wr_nv_ident_help(outfile, addrp)
  171.     FILE *outfile;
  172.     struct Addrblock *addrp;
  173. #else
  174. wr_nv_ident_help(FILE *outfile, struct Addrblock *addrp)
  175. #endif
  176. {
  177.     int eltcount = 0;
  178.  
  179.     if (addrp == (struct Addrblock *) NULL)
  180.     return;
  181.  
  182.     if (addrp -> isarray) {
  183.     frexpr (addrp -> memoffset);
  184.     addrp -> memoffset = ICON(0);
  185.     eltcount = addrp -> ntempelt;
  186.     addrp -> ntempelt = 0;
  187.     addrp -> isarray = 0;
  188.     } /* if */
  189.     out_addr (outfile, addrp);
  190.     if (eltcount)
  191.     nice_printf (outfile, "[%d]", eltcount);
  192. } /* wr_nv_ident_help */
  193.  
  194.  int
  195. #ifdef KR_headers
  196. nv_type_help(addrp)
  197.     struct Addrblock *addrp;
  198. #else
  199. nv_type_help(struct Addrblock *addrp)
  200. #endif
  201. {
  202.     if (addrp == (struct Addrblock *) NULL)
  203.     return -1;
  204.  
  205.     return addrp -> vtype;
  206. } /* nv_type_help */
  207.  
  208.  
  209. /* lit_name -- returns a unique identifier for the given literal.  Make
  210.    the label useful, when possible.  For example:
  211.  
  212.     1 -> c_1        (constant 1)
  213.     2 -> c_2        (constant 2)
  214.     1000 -> c_1000        (constant 1000)
  215.     1000000 -> c_b<memno>    (big constant number)
  216.     1.2 -> c_1_2        (constant 1.2)
  217.     1.234345 -> c_b<memno>    (big constant number)
  218.     -1 -> c_n1        (constant -1)
  219.     -1.0 -> c_n1_0        (constant -1.0)
  220.     .true. -> c_true    (constant true)
  221.     .false. -> c_false    (constant false)
  222.     default -> c_b<memno>    (default label)
  223. */
  224.  
  225.  char *
  226. #ifdef KR_headers
  227. lit_name(litp)
  228.     struct Literal *litp;
  229. #else
  230. lit_name(struct Literal *litp)
  231. #endif
  232. {
  233.     static char buf[CONST_IDENT_MAX];
  234.     ftnint val;
  235.  
  236.     if (litp == (struct Literal *) NULL)
  237.         return NULL;
  238.  
  239.     switch (litp -> littype) {
  240.     case TYINT1:
  241.         val = litp -> litval.litival;
  242.         if (val >= 256 || val < -255)
  243.             sprintf (buf, "c_b%d", litp -> litnum);
  244.         else if (val < 0)
  245.             sprintf (buf, "ci1_n%ld", -val);
  246.         else
  247.             sprintf(buf, "ci1__%ld", val);
  248.         case TYSHORT:
  249.         val = litp -> litval.litival;
  250.         if (val >= 32768 || val <= -32769)
  251.             sprintf (buf, "c_b%d", litp -> litnum);
  252.         else if (val < 0)
  253.             sprintf (buf, "cs_n%ld", -val);
  254.         else
  255.             sprintf (buf, "cs__%ld", val);
  256.         break;
  257.     case TYLONG:
  258. #ifdef TYQUAD
  259.     case TYQUAD:
  260. #endif
  261.         val = litp -> litval.litival;
  262.         if (val >= 100000 || val <= -10000)
  263.             sprintf (buf, "c_b%d", litp -> litnum);
  264.         else if (val < 0)
  265.             sprintf (buf, "c_n%ld", -val);
  266.         else
  267.             sprintf (buf, "c__%ld", val);
  268.         break;
  269.     case TYLOGICAL1:
  270.     case TYLOGICAL2:
  271.     case TYLOGICAL:
  272.         sprintf (buf, "c_%s", (litp -> litval.litival
  273.                     ? "true" : "false"));
  274.         break;
  275.     case TYREAL:
  276.     case TYDREAL:
  277.         /* Given a limit of 6 or 8 character on external names,    */
  278.         /* few f.p. values can be meaningfully encoded in the    */
  279.         /* constant name.  Just going with the default cb_#    */
  280.         /* seems to be the best course for floating-point    */
  281.         /* constants.    */
  282.     case TYCHAR:
  283.         /* Shouldn't be any of these */
  284.     case TYADDR:
  285.     case TYCOMPLEX:
  286.     case TYDCOMPLEX:
  287.     case TYSUBR:
  288.     default:
  289.         sprintf (buf, "c_b%d", litp -> litnum);
  290.     } /* switch */
  291.     return buf;
  292. } /* lit_name */
  293.  
  294.  
  295.  
  296.  char *
  297. #ifdef KR_headers
  298. comm_union_name(count)
  299.     int count;
  300. #else
  301. comm_union_name(int count)
  302. #endif
  303. {
  304.     static char buf[12];
  305.  
  306.     sprintf(buf, "%d", count);
  307.     return buf;
  308.     }
  309.  
  310.  
  311.  
  312.  
  313. /* wr_globals -- after every function has been translated, we need to
  314.    output the global declarations, such as the static table of constant
  315.    values */
  316.  
  317.  void
  318. #ifdef KR_headers
  319. wr_globals(outfile)
  320.     FILE *outfile;
  321. #else
  322. wr_globals(FILE *outfile)
  323. #endif
  324. {
  325.     struct Literal *litp, *lastlit;
  326.     extern int hsize;
  327.     char *litname;
  328.     int did_one, t;
  329.     struct Constblock cb;
  330.     ftnint x, y;
  331.  
  332.     if (nliterals == 0)
  333.     return;
  334.  
  335.     lastlit = litpool + nliterals;
  336.     did_one = 0;
  337.     for (litp = litpool; litp < lastlit; litp++) {
  338.     if (!litp->lituse)
  339.         continue;
  340.     litname = lit_name(litp);
  341.     if (!did_one) {
  342.         margin_printf(outfile, "/* Table of constant values */\n\n");
  343.         did_one = 1;
  344.         }
  345.     cb.vtype = litp->littype;
  346.     if (litp->littype == TYCHAR) {
  347.         x = litp->litval.litival2[0] + litp->litval.litival2[1];
  348.         if (y = x % hsize)
  349.             x += y = hsize - y;
  350.         nice_printf(outfile,
  351.             "static struct { %s fill; char val[%ld+1];", halign, x);
  352.         nice_printf(outfile, " char fill2[%ld];", hsize - 1);
  353.         nice_printf(outfile, " } %s_st = { 0,", litname);
  354.         cb.vleng = ICON(litp->litval.litival2[0]);
  355.         cb.Const.ccp = litp->cds[0];
  356.         cb.Const.ccp1.blanks = litp->litval.litival2[1] + y;
  357.         cb.vtype = TYCHAR;
  358.         out_const(outfile, &cb);
  359.         frexpr(cb.vleng);
  360.         nice_printf(outfile, " };\n");
  361.         nice_printf(outfile, "#define %s %s_st.val\n", litname, litname);
  362.         continue;
  363.         }
  364.     nice_printf(outfile, "static %s %s = ",
  365.         c_type_decl(litp->littype,0), litname);
  366.  
  367.     t = litp->littype;
  368.     if (ONEOF(t, MSKREAL|MSKCOMPLEX)) {
  369.         cb.vstg = 1;
  370.         cb.Const.cds[0] = litp->cds[0];
  371.         cb.Const.cds[1] = litp->cds[1];
  372.         }
  373.     else {
  374.         memcpy((char *)&cb.Const, (char *)&litp->litval,
  375.             sizeof(cb.Const));
  376.         cb.vstg = 0;
  377.         }
  378.     out_const(outfile, &cb);
  379.  
  380.     nice_printf (outfile, ";\n");
  381.     } /* for */
  382.     if (did_one)
  383.         nice_printf (outfile, "\n");
  384. } /* wr_globals */
  385.  
  386.  ftnint
  387. #ifdef KR_headers
  388. commlen(vl)
  389.     register chainp vl;
  390. #else
  391. commlen(register chainp vl)
  392. #endif
  393. {
  394.     ftnint size;
  395.     int type;
  396.     struct Dimblock *t;
  397.     Namep v;
  398.  
  399.     while(vl->nextp)
  400.         vl = vl->nextp;
  401.     v = (Namep)vl->datap;
  402.     type = v->vtype;
  403.     if (type == TYCHAR)
  404.         size = v->vleng->constblock.Const.ci;
  405.     else
  406.         size = typesize[type];
  407.     if ((t = v->vdim) && ISCONST(t->nelt))
  408.         size *= t->nelt->constblock.Const.ci;
  409.     return size + v->voffset;
  410.     }
  411.  
  412.  static void    /* Pad common block if an EQUIVALENCE extended it. */
  413. #ifdef KR_headers
  414. pad_common(c)
  415.     Extsym *c;
  416. #else
  417. pad_common(Extsym *c)
  418. #endif
  419. {
  420.     register chainp cvl;
  421.     register Namep v;
  422.     long L = c->maxleng;
  423.     int type;
  424.     struct Dimblock *t;
  425.     int szshort = typesize[TYSHORT];
  426.  
  427.     for(cvl = c->allextp; cvl; cvl = cvl->nextp)
  428.         if (commlen((chainp)cvl->datap) >= L)
  429.             return;
  430.     v = ALLOC(Nameblock);
  431.     v->vtype = type = L % szshort ? TYCHAR
  432.                       : type_choice[L/szshort % 4];
  433.     v->vstg = STGCOMMON;
  434.     v->vclass = CLVAR;
  435.     v->tag = TNAME;
  436.     v->vdim = t = ALLOC(Dimblock);
  437.     t->ndim = 1;
  438.     t->dims[0].dimsize = ICON(L / typesize[type]);
  439.     v->fvarname = v->cvarname = "eqv_pad";
  440.     if (type == TYCHAR)
  441.         v->vleng = ICON(1);
  442.     c->allextp = mkchain((char *)mkchain((char *)v, CHNULL), c->allextp);
  443.     }
  444.  
  445.  
  446. /* wr_common_decls -- outputs the common declarations in one of three
  447.    formats.  If all references to a common block look the same (field
  448.    names and types agree), only one actual declaration will appear.
  449.    Otherwise, the same block will require many structs.  If there is no
  450.    block data, these structs will be union'ed together (so the linker
  451.    knows the size of the largest one).  If there IS a block data, only
  452.    that version will be associated with the variable, others will only be
  453.    defined as types, so the pointer can be cast to it.  e.g.
  454.  
  455.     FORTRAN                C
  456. ----------------------------------------------------------------------
  457.     common /com1/ a, b, c        struct { real a, b, c; } com1_;
  458.  
  459.     common /com1/ a, b, c        union {
  460.     common /com1/ i, j, k            struct { real a, b, c; } _1;
  461.                         struct { integer i, j, k; } _2;
  462.                     } com1_;
  463.  
  464.     common /com1/ a, b, c        struct com1_1_ { real a, b, c; };
  465.     block data            struct { integer i, j, k; } com1_ =
  466.     common /com1/ i, j, k          { 1, 2, 3 };
  467.     data i/1/, j/2/, k/3/
  468.  
  469.  
  470.    All of these versions will be followed by #defines, since the code in
  471.    the function bodies can't know ahead of time which of these options
  472.    will be taken */
  473.  
  474. /* Macros for deciding the output type */
  475.  
  476. #define ONE_STRUCT 1
  477. #define UNION_STRUCT 2
  478. #define INIT_STRUCT 3
  479.  
  480.  void
  481. #ifdef KR_headers
  482. wr_common_decls(outfile)
  483.     FILE *outfile;
  484. #else
  485. wr_common_decls(FILE *outfile)
  486. #endif
  487. {
  488.     Extsym *ext;
  489.     extern int extcomm;
  490.     static char *Extern[4] = {"", "Extern ", "extern "};
  491.     char *E, *E0 = Extern[extcomm];
  492.     int did_one = 0;
  493.  
  494.     for (ext = extsymtab; ext < nextext; ext++) {
  495.     if (ext -> extstg == STGCOMMON && ext->allextp) {
  496.         chainp comm;
  497.         int count = 1;
  498.         int which;            /* which display to use;
  499.                        ONE_STRUCT, UNION or INIT */
  500.  
  501.         if (!did_one)
  502.         nice_printf (outfile, "/* Common Block Declarations */\n\n");
  503.  
  504.         pad_common(ext);
  505.  
  506. /* Construct the proper, condensed list of structs; eliminate duplicates
  507.    from the initial list   ext -> allextp   */
  508.  
  509.         comm = ext->allextp = revchain(ext->allextp);
  510.  
  511.         if (ext -> extinit)
  512.         which = INIT_STRUCT;
  513.         else if (comm->nextp) {
  514.         which = UNION_STRUCT;
  515.         nice_printf (outfile, "%sunion {\n", E0);
  516.         next_tab (outfile);
  517.         E = "";
  518.         }
  519.         else {
  520.         which = ONE_STRUCT;
  521.         E = E0;
  522.         }
  523.  
  524.         for (; comm; comm = comm -> nextp, count++) {
  525.  
  526.         if (which == INIT_STRUCT)
  527.             nice_printf (outfile, "struct %s%d_ {\n",
  528.                 ext->cextname, count);
  529.         else
  530.             nice_printf (outfile, "%sstruct {\n", E);
  531.  
  532.         next_tab (c_file);
  533.  
  534.         wr_struct (outfile, (chainp) comm -> datap);
  535.  
  536.         prev_tab (c_file);
  537.         if (which == UNION_STRUCT)
  538.             nice_printf (outfile, "} _%d;\n", count);
  539.         else if (which == ONE_STRUCT)
  540.             nice_printf (outfile, "} %s;\n", ext->cextname);
  541.         else
  542.             nice_printf (outfile, "};\n");
  543.         } /* for */
  544.  
  545.         if (which == UNION_STRUCT) {
  546.         prev_tab (c_file);
  547.         nice_printf (outfile, "} %s;\n", ext->cextname);
  548.         } /* if */
  549.         did_one = 1;
  550.         nice_printf (outfile, "\n");
  551.  
  552.         for (count = 1, comm = ext -> allextp; comm;
  553.             comm = comm -> nextp, count++) {
  554.         def_start(outfile, ext->cextname,
  555.             comm_union_name(count), "");
  556.         switch (which) {
  557.             case ONE_STRUCT:
  558.                 extern_out (outfile, ext);
  559.                 break;
  560.             case UNION_STRUCT:
  561.                 nice_printf (outfile, "(");
  562.             extern_out (outfile, ext);
  563.             nice_printf(outfile, "._%d)", count);
  564.                 break;
  565.             case INIT_STRUCT:
  566.             nice_printf (outfile, "(*(struct ");
  567.             extern_out (outfile, ext);
  568.             nice_printf (outfile, "%d_ *) &", count);
  569.             extern_out (outfile, ext);
  570.             nice_printf (outfile, ")");
  571.                 break;
  572.         } /* switch */
  573.         nice_printf (outfile, "\n");
  574.         } /* for count = 1, comm = ext -> allextp */
  575.         nice_printf (outfile, "\n");
  576.     } /* if ext -> extstg == STGCOMMON */
  577.     } /* for ext = extsymtab */
  578. } /* wr_common_decls */
  579.  
  580.  void
  581. #ifdef KR_headers
  582. wr_struct(outfile, var_list)
  583.     FILE *outfile;
  584.     chainp var_list;
  585. #else
  586. wr_struct(FILE *outfile, chainp var_list)
  587. #endif
  588. {
  589.     int last_type = -1;
  590.     int did_one = 0;
  591.     chainp this_var;
  592.  
  593.     for (this_var = var_list; this_var; this_var = this_var -> nextp) {
  594.     Namep var = (Namep) this_var -> datap;
  595.     int type;
  596.     char *comment = NULL;
  597.  
  598.     if (var == (Namep) NULL)
  599.         err ("wr_struct:  null variable");
  600.     else if (var -> tag != TNAME)
  601.         erri ("wr_struct:  bad tag on variable '%d'",
  602.             var -> tag);
  603.  
  604.     type = var -> vtype;
  605.  
  606.     if (last_type == type && did_one)
  607.         nice_printf (outfile, ", ");
  608.     else {
  609.         if (did_one)
  610.         nice_printf (outfile, ";\n");
  611.         nice_printf (outfile, "%s ",
  612.             c_type_decl (type, var -> vclass == CLPROC));
  613.     } /* else */
  614.  
  615. /* Character type is really a string type.  Put out a '*' for parameters
  616.    with unknown length and functions returning character */
  617.  
  618.     if (var -> vtype == TYCHAR && (!ISICON ((var -> vleng))
  619.         || var -> vclass == CLPROC))
  620.         nice_printf (outfile, "*");
  621.  
  622.     var -> vstg = STGAUTO;
  623.     out_name (outfile, var);
  624.     if (var -> vclass == CLPROC)
  625.         nice_printf (outfile, "()");
  626.     else if (var -> vdim)
  627.         comment = wr_ardecls(outfile, var->vdim,
  628.                 var->vtype == TYCHAR && ISICON(var->vleng)
  629.                 ? var->vleng->constblock.Const.ci : 1L);
  630.     else if (var -> vtype == TYCHAR && var -> vclass != CLPROC &&
  631.         ISICON ((var -> vleng)))
  632.         nice_printf (outfile, "[%ld]",
  633.             var -> vleng -> constblock.Const.ci);
  634.  
  635.     if (comment)
  636.         nice_printf (outfile, "%s", comment);
  637.     did_one = 1;
  638.     last_type = type;
  639.     } /* for this_var */
  640.  
  641.     if (did_one)
  642.     nice_printf (outfile, ";\n");
  643. } /* wr_struct */
  644.  
  645.  
  646.  char *
  647. #ifdef KR_headers
  648. user_label(stateno)
  649.     ftnint stateno;
  650. #else
  651. user_label(ftnint stateno)
  652. #endif
  653. {
  654.     static char buf[USER_LABEL_MAX + 1];
  655.     static char *Lfmt[2] = { "L_%ld", "L%ld" };
  656.  
  657.     if (stateno >= 0)
  658.         sprintf(buf, Lfmt[shiftcase], stateno);
  659.     else
  660.         sprintf(buf, "L_%s", extsymtab[-1-stateno].fextname);
  661.     return buf;
  662. } /* user_label */
  663.  
  664.  
  665.  char *
  666. #ifdef KR_headers
  667. temp_name(starter, num, storage)
  668.     char *starter;
  669.     int num;
  670.     char *storage;
  671. #else
  672. temp_name(char *starter, int num, char *storage)
  673. #endif
  674. {
  675.     static char buf[IDENT_LEN];
  676.     char *pointer = buf;
  677.     char *prefix = "t";
  678.  
  679.     if (storage)
  680.     pointer = storage;
  681.  
  682.     if (starter && *starter)
  683.     prefix = starter;
  684.  
  685.     sprintf (pointer, "%s__%d", prefix, num);
  686.     return pointer;
  687. } /* temp_name */
  688.  
  689.  
  690.  char *
  691. #ifdef KR_headers
  692. equiv_name(memno, store)
  693.     int memno;
  694.     char *store;
  695. #else
  696. equiv_name(int memno, char *store)
  697. #endif
  698. {
  699.     static char buf[IDENT_LEN];
  700.     char *pointer = buf;
  701.  
  702.     if (store)
  703.     pointer = store;
  704.  
  705.     sprintf (pointer, "%s_%d", EQUIV_INIT_NAME, memno);
  706.     return pointer;
  707. } /* equiv_name */
  708.  
  709.  void
  710. #ifdef KR_headers
  711. def_commons(of)
  712.     FILE *of;
  713. #else
  714. def_commons(FILE *of)
  715. #endif
  716. {
  717.     Extsym *ext;
  718.     int c, onefile, Union;
  719.     chainp comm;
  720.     extern int ext1comm;
  721.     FILE *c_filesave = c_file;
  722.  
  723.     if (ext1comm == 1) {
  724.         onefile = 1;
  725.         c_file = of;
  726.         fprintf(of, "/*>>>'/dev/null'<<<*/\n\
  727. #ifdef Define_COMMONs\n\
  728. /*<<</dev/null>>>*/\n");
  729.         }
  730.     else
  731.         onefile = 0;
  732.     for(ext = extsymtab; ext < nextext; ext++)
  733.         if (ext->extstg == STGCOMMON
  734.         && !ext->extinit && (comm = ext->allextp)) {
  735.             sprintf(outbtail, "%scom.c", ext->cextname);
  736.             if (onefile)
  737.                 fprintf(of, "/*>>>'%s'<<<*/\n",
  738.                     outbtail);
  739.             else {
  740.                 c_file = of = fopen(outbuf,textwrite);
  741.                 if (!of)
  742.                     fatalstr("can't open %s", outbuf);
  743.                 }
  744.             fprintf(of, "#include \"f2c.h\"\n");
  745.             if (comm->nextp) {
  746.                 Union = 1;
  747.                 nice_printf(of, "union {\n");
  748.                 next_tab(of);
  749.                 }
  750.             else
  751.                 Union = 0;
  752.             for(c = 1; comm; comm = comm->nextp) {
  753.                 nice_printf(of, "struct {\n");
  754.                 next_tab(of);
  755.                 wr_struct(of, (chainp)comm->datap);
  756.                 prev_tab(of);
  757.                 if (Union)
  758.                     nice_printf(of, "} _%d;\n", c++);
  759.                 }
  760.             if (Union)
  761.                 prev_tab(of);
  762.             nice_printf(of, "} %s;\n", ext->cextname);
  763.             if (onefile)
  764.                 fprintf(of, "/*<<<%s>>>*/\n", outbtail);
  765.             else
  766.                 fclose(of);
  767.             }
  768.     if (onefile)
  769.         fprintf(of, "/*>>>'/dev/null'<<<*/\n#endif\n\
  770. /*<<</dev/null>>>*/\n");
  771.     c_file = c_filesave;
  772.     }
  773.  
  774. /* C Language keywords.  Needed to filter unwanted fortran identifiers like
  775.  * "int", etc.  Source:  Kernighan & Ritchie, eds. 1 and 2; Stroustrup.
  776.  * Also includes C++ keywords and types used for I/O in f2c.h .
  777.  * These keywords must be in alphabetical order (as defined by strcmp()).
  778.  */
  779.  
  780. char *c_keywords[] = {
  781.     "Long", "Multitype", "Namelist", "Vardesc",
  782.     "abs", "acos", "address", "alist", "asin", "asm",
  783.     "atan", "atan2", "auto", "break",
  784.     "case", "catch", "char", "cilist", "class", "cllist",
  785.     "complex", "const", "continue", "cos", "cosh",
  786.     "dabs", "default", "defined", "delete",
  787.     "dmax", "dmin", "do", "double", "doublecomplex", "doublereal",
  788.     "else", "entry", "enum", "exp", "extern",
  789.     "flag", "float", "for", "friend", "ftnint", "ftnlen", "goto",
  790.     "icilist", "if", "include", "inline", "inlist", "int", "integer",
  791.     "integer1", "log", "logical", "logical1", "long", "longint",
  792.     "max", "min", "new",
  793.     "olist", "operator", "overload", "private", "protected", "public",
  794.     "real", "register", "return",
  795.     "short", "shortint", "shortlogical", "signed", "sin", "sinh",
  796.     "sizeof", "sqrt", "static", "struct", "switch",
  797.     "tan", "tanh", "template", "this", "try", "typedef",
  798.     "union", "unsigned", "virtual", "void", "volatile", "while"
  799. }; /* c_keywords */
  800.  
  801. int n_keywords = sizeof(c_keywords)/sizeof(char *);
  802.  
  803. char *st_fields[] = {
  804.     "addr", "aerr", "aunit", "c", "cerr", "ciend", "cierr",
  805.     "cifmt", "cirec", "ciunit", "csta", "cunit", "d", "dims",
  806.     "h", "i", "iciend", "icierr", "icifmt", "icirlen",
  807.     "icirnum", "iciunit", "inacc", "inacclen", "inblank",
  808.     "inblanklen", "indir", "indirlen", "inerr", "inex",
  809.     "infile", "infilen", "infmt", "infmtlen", "inform",
  810.     "informlen", "inname", "innamed", "innamlen", "innrec",
  811.     "innum", "inopen", "inrecl", "inseq", "inseqlen", "inunf",
  812.     "inunflen", "inunit", "name", "nvars", "oacc", "oblnk",
  813.     "oerr", "ofm", "ofnm", "ofnmlen", "orl", "osta", "ounit",
  814.     "r", "type", "vars", "z"
  815.     };
  816. int n_st_fields = sizeof(st_fields)/sizeof(char *);
  817.