home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / fortran / f2c-9510.000 / f2c-9510 / f2c-951007-libs-1.1 / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-07  |  17.6 KB  |  675 lines

  1. /****************************************************************
  2. Copyright 1990 - 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. extern char F2C_version[];
  25.  
  26. #include "defs.h"
  27. #include "parse.h"
  28.  
  29. int complex_seen, dcomplex_seen;
  30.  
  31. LOCAL int Max_ftn_files;
  32.  
  33. char **ftn_files;
  34. int current_ftn_file = 0;
  35.  
  36. flag ftn66flag = NO;
  37. flag nowarnflag = NO;
  38. flag noextflag = NO;
  39. flag  no66flag = NO;        /* Must also set noextflag to this
  40.                        same value */
  41. flag zflag = YES;        /* recognize double complex intrinsics */
  42. flag debugflag = NO;
  43. flag onetripflag = NO;
  44. flag shiftcase = YES;
  45. flag undeftype = NO;
  46. flag checksubs = NO;
  47. flag r8flag = NO;
  48. flag use_bs = YES;
  49. flag keepsubs = NO;
  50. #ifdef TYQUAD
  51. flag use_tyquad = YES;
  52. #endif
  53. int tyreal = TYREAL;
  54. int tycomplex = TYCOMPLEX;
  55.  
  56. int maxregvar = MAXREGVAR;    /* if maxregvar > MAXREGVAR, error */
  57. int maxequiv = MAXEQUIV;
  58. int maxext = MAXEXT;
  59. int maxstno = MAXSTNO;
  60. int maxctl = MAXCTL;
  61. int maxhash = MAXHASH;
  62. int maxliterals = MAXLITERALS;
  63. int maxcontin = MAXCONTIN;
  64. int maxlablist = MAXLABLIST;
  65. int extcomm, ext1comm, useauto;
  66. int can_include = YES;    /* so we can disable includes for netlib */
  67.  
  68. static char *def_i2 = "";
  69.  
  70. static int useshortints = NO;    /* YES => tyint = TYSHORT */
  71. static int uselongints = NO;    /* YES => tyint = TYLONG */
  72. int addftnsrc = NO;        /* Include ftn source in output */
  73. int usedefsforcommon = NO;    /* Use #defines for common reference */
  74. int forcedouble = YES;        /* force real functions to double */
  75. int Ansi = NO;
  76. int def_equivs = YES;
  77. int tyioint = TYLONG;
  78. int szleng = SZLENG;
  79. int inqmask = M(TYLONG)|M(TYLOGICAL);
  80. int wordalign = NO;
  81. int forcereal = NO;
  82. int warn72 = NO;
  83. static int skipC, skipversion;
  84. char *file_name, *filename0, *parens;
  85. int Castargs = 1;
  86. static int Castargs1;
  87. static int typedefs = 0;
  88. int chars_per_wd, gflag, protostatus;
  89. int infertypes = 1;
  90. char used_rets[TYSUBR+1];
  91. extern char *tmpdir;
  92. static int h0align = 0;
  93. char *halign, *ohalign;
  94. int krparens = NO;
  95. int hsize;    /* for padding under -h */
  96. int htype;    /* for wr_equiv_init under -h */
  97. chainp Iargs;
  98.  
  99. #define f2c_entry(swit,count,type,store,size) \
  100.     p_entry ("-", swit, 0, count, type, store, size)
  101.  
  102. static arg_info table[] = {
  103.     f2c_entry ("w66", P_NO_ARGS, P_INT, &ftn66flag, YES),
  104.     f2c_entry ("w", P_NO_ARGS, P_INT, &nowarnflag, YES),
  105.     f2c_entry ("66", P_NO_ARGS, P_INT, &no66flag, YES),
  106.     f2c_entry ("1", P_NO_ARGS, P_INT, &onetripflag, YES),
  107.     f2c_entry ("onetrip", P_NO_ARGS, P_INT, &onetripflag, YES),
  108.     f2c_entry ("I2", P_NO_ARGS, P_INT, &useshortints, YES),
  109.     f2c_entry ("I4", P_NO_ARGS, P_INT, &uselongints, YES),
  110.     f2c_entry ("U", P_NO_ARGS, P_INT, &shiftcase, NO),
  111.     f2c_entry ("u", P_NO_ARGS, P_INT, &undeftype, YES),
  112.     f2c_entry ("O", P_ONE_ARG, P_INT, &maxregvar, 0),
  113.     f2c_entry ("C", P_NO_ARGS, P_INT, &checksubs, YES),
  114.     f2c_entry ("Nq", P_ONE_ARG, P_INT, &maxequiv, 0),
  115.     f2c_entry ("Nx", P_ONE_ARG, P_INT, &maxext, 0),
  116.     f2c_entry ("Ns", P_ONE_ARG, P_INT, &maxstno, 0),
  117.     f2c_entry ("Nc", P_ONE_ARG, P_INT, &maxctl, 0),
  118.     f2c_entry ("Nn", P_ONE_ARG, P_INT, &maxhash, 0),
  119.     f2c_entry ("NL", P_ONE_ARG, P_INT, &maxliterals, 0),
  120.     f2c_entry ("NC", P_ONE_ARG, P_INT, &maxcontin, 0),
  121.     f2c_entry ("Nl", P_ONE_ARG, P_INT, &maxlablist, 0),
  122.     f2c_entry ("c", P_NO_ARGS, P_INT, &addftnsrc, YES),
  123.     f2c_entry ("p", P_NO_ARGS, P_INT, &usedefsforcommon, YES),
  124.     f2c_entry ("R", P_NO_ARGS, P_INT, &forcedouble, NO),
  125.     f2c_entry ("!R", P_NO_ARGS, P_INT, &forcedouble, YES),
  126.     f2c_entry ("A", P_NO_ARGS, P_INT, &Ansi, YES),
  127.     f2c_entry ("ext", P_NO_ARGS, P_INT, &noextflag, YES),
  128.     f2c_entry ("z", P_NO_ARGS, P_INT, &zflag, NO),
  129.     f2c_entry ("a", P_NO_ARGS, P_INT, &useauto, YES),
  130.     f2c_entry ("r8", P_NO_ARGS, P_INT, &r8flag, YES),
  131.     f2c_entry ("i2", P_NO_ARGS, P_INT, &tyioint, NO),
  132.     f2c_entry ("w8", P_NO_ARGS, P_INT, &wordalign, YES),
  133.     f2c_entry ("!I", P_NO_ARGS, P_INT, &can_include, NO),
  134.     f2c_entry ("W", P_ONE_ARG, P_INT, &chars_per_wd, 0),
  135.     f2c_entry ("g", P_NO_ARGS, P_INT, &gflag, YES),
  136.     f2c_entry ("T", P_ONE_ARG, P_STRING, &tmpdir, 0),
  137.     f2c_entry ("E", P_NO_ARGS, P_INT, &extcomm, 1),
  138.     f2c_entry ("e1c", P_NO_ARGS, P_INT, &ext1comm, 1),
  139.     f2c_entry ("ec", P_NO_ARGS, P_INT, &ext1comm, 2),
  140.     f2c_entry ("C++", P_NO_ARGS, P_INT, &Ansi, 2),
  141.     f2c_entry ("P", P_NO_ARGS, P_INT, &Castargs, 3),
  142.     f2c_entry ("Ps", P_NO_ARGS, P_INT, &protostatus, 1),
  143.     f2c_entry ("!P", P_NO_ARGS, P_INT, &Castargs, 0),
  144.     f2c_entry ("!c", P_NO_ARGS, P_INT, &skipC, 1),
  145.     f2c_entry ("!it", P_NO_ARGS, P_INT, &infertypes, 0),
  146.     f2c_entry ("h", P_NO_ARGS, P_INT, &h0align, 1),
  147.     f2c_entry ("hd", P_NO_ARGS, P_INT, &h0align, 2),
  148.     f2c_entry ("kr", P_NO_ARGS, P_INT, &krparens, 1),
  149.     f2c_entry ("krd", P_NO_ARGS, P_INT, &krparens, 2),
  150.     f2c_entry ("!bs", P_NO_ARGS, P_INT, &use_bs, NO),
  151.     f2c_entry ("r", P_NO_ARGS, P_INT, &forcereal, YES),
  152.     f2c_entry ("72", P_NO_ARGS, P_INT, &warn72, 1),
  153.     f2c_entry ("f", P_NO_ARGS, P_INT, &warn72, 2),
  154.     f2c_entry ("s", P_NO_ARGS, P_INT, &keepsubs, 1),
  155.     f2c_entry ("d", P_ONE_ARG, P_STRING, &outbuf, 0),
  156. #ifdef TYQUAD
  157.     f2c_entry ("!i8", P_NO_ARGS, P_INT, &use_tyquad, NO),
  158. #endif
  159.  
  160.     /* options omitted from man pages */
  161.  
  162.     /* -ev ==> implement equivalence with initialized pointers */
  163.     f2c_entry ("ev", P_NO_ARGS, P_INT, &def_equivs, NO),
  164.  
  165.     /* -!it used to be the default when -it was more agressive */
  166.  
  167.     f2c_entry ("it", P_NO_ARGS, P_INT, &infertypes, 1),
  168.  
  169.     /* -Pd is similar to -P, but omits :ref: lines */
  170.     f2c_entry ("Pd", P_NO_ARGS, P_INT, &Castargs, 2),
  171.  
  172.     /* -t ==> emit typedefs (under -A or -C++) for procedure
  173.         argument types used.  This is meant for netlib's
  174.         f2c service, so -A and -C++ will work with older
  175.         versions of f2c.h
  176.         */
  177.     f2c_entry ("t", P_NO_ARGS, P_INT, &typedefs, 1),
  178.  
  179.     /* -!V ==> omit version msg (to facilitate using diff in
  180.         regression testing)
  181.         */
  182.     f2c_entry ("!V", P_NO_ARGS, P_INT, &skipversion, 1),
  183.  
  184.     /* -Dnnn = debug level nnn */
  185.  
  186.     f2c_entry ("D", P_ONE_ARG, P_INT, &debugflag, YES)
  187. }; /* table */
  188.  
  189. extern char *c_functions;    /* "c_functions"    */
  190. extern char *coutput;        /* "c_output"        */
  191. extern char *initfname;        /* "raw_data"        */
  192. extern char *blkdfname;        /* "block_data"        */
  193. extern char *p1_file;        /* "p1_file"        */
  194. extern char *p1_bakfile;    /* "p1_file.BAK"    */
  195. extern char *sortfname;        /* "init_file"        */
  196. extern char *proto_fname;    /* "proto_file"        */
  197. FILE *protofile;
  198.  
  199.  void
  200. set_externs(Void)
  201. {
  202.     static char *hset[3] = { 0, "integer", "doublereal" };
  203.  
  204. /* Adjust the global flags according to the command line parameters */
  205.  
  206.     if (chars_per_wd > 0) {
  207.     typesize[TYADDR] = typesize[TYLONG] = typesize[TYREAL] =
  208.         typesize[TYLOGICAL] = chars_per_wd;
  209.     typesize[TYINT1] = typesize[TYLOGICAL1] = 1;
  210.     typesize[TYDREAL] = typesize[TYCOMPLEX] = chars_per_wd << 1;
  211.     typesize[TYDCOMPLEX] = chars_per_wd << 2;
  212.     typesize[TYSHORT] = typesize[TYLOGICAL2] = chars_per_wd >> 1;
  213.     typesize[TYCILIST] = 5*chars_per_wd;
  214.     typesize[TYICILIST] = 6*chars_per_wd;
  215.     typesize[TYOLIST] = 9*chars_per_wd;
  216.     typesize[TYCLLIST] = 3*chars_per_wd;
  217.     typesize[TYALIST] = 2*chars_per_wd;
  218.     typesize[TYINLIST] = 26*chars_per_wd;
  219.     }
  220.  
  221.     if (wordalign)
  222.     typealign[TYDREAL] = typealign[TYDCOMPLEX] = typealign[TYREAL];
  223.     if (!tyioint) {
  224.     tyioint = TYSHORT;
  225.     szleng = typesize[TYSHORT];
  226.     def_i2 = "#define f2c_i2 1\n";
  227.     inqmask = M(TYSHORT)|M(TYLOGICAL2);
  228.     goto checklong;
  229.     }
  230.     else
  231.     szleng = typesize[TYLONG];
  232.     if (useshortints) {
  233.     /* inqmask = M(TYLONG); */
  234.     /* used to disallow LOGICAL in INQUIRE under -I2 */
  235.  checklong:
  236.     protorettypes[TYLOGICAL] = "shortlogical";
  237.     casttypes[TYLOGICAL] = "K_fp";
  238.     if (uselongints)
  239.         err ("Can't use both long and short ints");
  240.     else {
  241.         tyint = tylogical = TYSHORT;
  242.         tylog = TYLOGICAL2;
  243.         }
  244.     }
  245.     else if (uselongints)
  246.     tyint = TYLONG;
  247.  
  248.     if (h0align) {
  249.     if (tyint == TYLONG && wordalign)
  250.         h0align = 1;
  251.         ohalign = halign = hset[h0align];
  252.     htype = h0align == 1 ? tyint : TYDREAL;
  253.     hsize = typesize[htype];
  254.     }
  255.  
  256.     if (no66flag)
  257.     noextflag = no66flag;
  258.     if (noextflag)
  259.     zflag = 0;
  260.  
  261.     if (r8flag) {
  262.     tyreal = TYDREAL;
  263.     tycomplex = TYDCOMPLEX;
  264.     r8fix();
  265.     }
  266.     if (forcedouble) {
  267.     protorettypes[TYREAL] = "E_f";
  268.     casttypes[TYREAL] = "E_fp";
  269.     }
  270.  
  271.     if (maxregvar > MAXREGVAR) {
  272.     warni("-O%d: too many register variables", maxregvar);
  273.     maxregvar = MAXREGVAR;
  274.     } /* if maxregvar > MAXREGVAR */
  275.  
  276. /* Check the list of input files */
  277.  
  278.     {
  279.     int bad, i, cur_max = Max_ftn_files;
  280.  
  281.     for (i = bad = 0; i < cur_max && ftn_files[i]; i++)
  282.         if (ftn_files[i][0] == '-') {
  283.         errstr ("Invalid flag '%s'", ftn_files[i]);
  284.         bad++;
  285.         }
  286.     if (bad)
  287.         exit(1);
  288.  
  289.     } /* block */
  290. } /* set_externs */
  291.  
  292.  
  293.  static int
  294. comm2dcl(Void)
  295. {
  296.     Extsym *ext;
  297.     if (ext1comm)
  298.         for(ext = extsymtab; ext < nextext; ext++)
  299.             if (ext->extstg == STGCOMMON && !ext->extinit)
  300.                 return ext1comm;
  301.     return 0;
  302.     }
  303.  
  304.  static void
  305. #ifdef KR_headers
  306. write_typedefs(outfile)
  307.     FILE *outfile;
  308. #else
  309. write_typedefs(FILE *outfile)
  310. #endif
  311. {
  312.     register int i;
  313.     register char *s, *p = 0;
  314.     static char st[4] = { TYREAL, TYCOMPLEX, TYDCOMPLEX, TYCHAR };
  315.     static char stl[4] = { 'E', 'C', 'Z', 'H' };
  316.  
  317.     for(i = 0; i <= TYSUBR; i++)
  318.         if (s = usedcasts[i]) {
  319.             if (!p) {
  320.                 p = Ansi == 1 ? "()" : "(...)";
  321.                 nice_printf(outfile,
  322.                 "/* Types for casting procedure arguments: */\
  323. \n\n#ifndef F2C_proc_par_types\n");
  324.                 if (i == 0) {
  325.                     nice_printf(outfile,
  326.             "typedef int /* Unknown procedure type */ (*%s)%s;\n",
  327.                          s, p);
  328.                     continue;
  329.                     }
  330.                 }
  331.             nice_printf(outfile, "typedef %s (*%s)%s;\n",
  332.                     c_type_decl(i,1), s, p);
  333.             }
  334.     for(i = !forcedouble; i < 4; i++)
  335.         if (used_rets[st[i]])
  336.             nice_printf(outfile,
  337.                 "typedef %s %c_f; /* %s function */\n",
  338.                 p = i ? "VOID" : "doublereal",
  339.                 stl[i], ftn_types[st[i]]);
  340.     if (p)
  341.         nice_printf(outfile, "#endif\n\n");
  342.     }
  343.  
  344.  static void
  345. #ifdef KR_headers
  346. commonprotos(outfile)
  347.     register FILE *outfile;
  348. #else
  349. commonprotos(register FILE *outfile)
  350. #endif
  351. {
  352.     register Extsym *e, *ee;
  353.     register Argtypes *at;
  354.     Atype *a, *ae;
  355.     int k;
  356.     extern int proc_protochanges;
  357.  
  358.     if (!outfile)
  359.         return;
  360.     for (e = extsymtab, ee = nextext; e < ee; e++)
  361.         if (e->extstg == STGCOMMON && e->allextp)
  362.             nice_printf(outfile, "/* comlen %s %ld */\n",
  363.                 e->cextname, e->maxleng);
  364.     if (Castargs1 < 3)
  365.         return;
  366.  
  367.     /* -Pr: special comments conveying current knowledge
  368.         of external references */
  369.  
  370.     k = proc_protochanges;
  371.     for (e = extsymtab, ee = nextext; e < ee; e++)
  372.         if (e->extstg == STGEXT
  373.         && e->cextname != e->fextname)    /* not a library function */
  374.             if (at = e->arginfo) {
  375.             if ((!e->extinit || at->changes & 1)
  376.                 /* not defined here or
  377.                     changed since definition */
  378.             && at->nargs >= 0) {
  379.                 nice_printf(outfile, "/*:ref: %s %d %d",
  380.                     e->cextname, e->extype, at->nargs);
  381.                 a = at->atypes;
  382.                 for(ae = a + at->nargs; a < ae; a++)
  383.                     nice_printf(outfile, " %d", a->type);
  384.                 nice_printf(outfile, " */\n");
  385.                 if (at->changes & 1)
  386.                     k++;
  387.                 }
  388.             }
  389.             else if (e->extype)
  390.             /* typed external, never invoked */
  391.             nice_printf(outfile, "/*:ref: %s %d :*/\n",
  392.                 e->cextname, e->extype);
  393.     if (k) {
  394.         nice_printf(outfile,
  395.     "/* Rerunning f2c -P may change prototypes or declarations. */\n");
  396.         if (nerr)
  397.             return;
  398.         if (protostatus)
  399.             done(4);
  400.         if (protofile != stdout) {
  401.             fprintf(diagfile,
  402.     "Rerunning \"f2c -P ... %s %s\" may change prototypes or declarations.\n",
  403.                 filename0, proto_fname);
  404.             fflush(diagfile);
  405.             }
  406.         }
  407.     }
  408.  
  409.  static int
  410. #ifdef KR_headers
  411. I_args(argc, a)
  412.     int argc;
  413.     char **a;
  414. #else
  415. I_args(int argc, char **a)
  416. #endif
  417. {
  418.     char **a0, **a1, **ae, *s;
  419.  
  420.     ae = a + argc;
  421.     a0 = a;
  422.     for(a1 = ++a; a < ae; a++) {
  423.         if (!(s = *a))
  424.             break;
  425.         if (*s == '-' && s[1] == 'I' && s[2]
  426.           && (s[3] || s[2] != '2' && s[2] != '4'))
  427.             Iargs = mkchain(s+2, Iargs);
  428.         else
  429.             *a1++ = s;
  430.         }
  431.     Iargs = revchain(Iargs);
  432.     *a1 = 0;
  433.     return a1 - a0;
  434.     }
  435.  
  436.  int retcode = 0;
  437.  
  438.  int
  439. #ifdef KR_headers
  440. main(argc, argv)
  441.     int argc;
  442.     char **argv;
  443. #else
  444. main(int argc, char **argv)
  445. #endif
  446. {
  447.     int c2d, k;
  448.     FILE *c_output;
  449.     char *cdfilename;
  450.     static char stderrbuf[BUFSIZ];
  451.     extern char **dfltproc, *dflt1proc[];
  452.     extern char link_msg[];
  453.  
  454.     diagfile = stderr;
  455.     setbuf(stderr, stderrbuf);    /* arrange for fast error msgs */
  456.  
  457.     argc = I_args(argc, argv);    /* extract -I args */
  458.     Max_ftn_files = argc - 1;
  459.     ftn_files = (char **)ckalloc((argc+1)*sizeof(char *));
  460.  
  461.     parse_args (argc, argv, table, sizeof(table)/sizeof(arg_info),
  462.         ftn_files, Max_ftn_files);
  463.     if (keepsubs && checksubs) {
  464.         warn("-C suppresses -s\n");
  465.         keepsubs = 0;
  466.         }
  467.     if (!can_include && ext1comm == 2)
  468.         ext1comm = 1;
  469.     if (ext1comm && !extcomm)
  470.         extcomm = 2;
  471.     if (protostatus)
  472.         Castargs = 3;
  473.     Castargs1 = Castargs;
  474.     if (!Ansi) {
  475.         Castargs = 0;
  476.         parens = "()";
  477.         }
  478.     else if (!Castargs)
  479.         parens = Ansi == 1 ? "()" : "(...)";
  480.     else
  481.         dfltproc = dflt1proc;
  482.  
  483.     outbuf_adjust();
  484.     set_externs();
  485.     fileinit();
  486.     read_Pfiles(ftn_files);
  487.  
  488.     for(k = 1; ftn_files[k]; k++)
  489.         if (dofork())
  490.             break;
  491.     filename0 = file_name = ftn_files[current_ftn_file = k - 1];
  492.  
  493.     set_tmp_names();
  494.     sigcatch(0);
  495.  
  496.     c_file   = opf(c_functions, textwrite);
  497.     pass1_file=opf(p1_file, binwrite);
  498.     initkey();
  499.     if (file_name && *file_name) {
  500.         cdfilename = coutput;
  501.         if (debugflag != 1) {
  502.             coutput = c_name(file_name,'c');
  503.             cdfilename = copys(outbtail);
  504.             if (Castargs1 >= 2)
  505.                 proto_fname = c_name(file_name,'P');
  506.             }
  507.         if (skipC)
  508.             coutput = 0;
  509.         else if (!(c_output = fopen(coutput, textwrite))) {
  510.             file_name = coutput;
  511.             coutput = 0;    /* don't delete read-only .c file */
  512.             fatalstr("can't open %.86s", file_name);
  513.             }
  514.  
  515.         if (Castargs1 >= 2
  516.         && !(protofile = fopen(proto_fname, textwrite)))
  517.             fatalstr("Can't open %.84s\n", proto_fname);
  518.         }
  519.     else {
  520.         file_name = "";
  521.         cdfilename = "f2c_out.c";
  522.         c_output = stdout;
  523.         coutput = 0;
  524.         if (Castargs1 >= 2) {
  525.             protofile = stdout;
  526.             if (!skipC)
  527.                 printf("#ifdef P_R_O_T_O_T_Y_P_E_S\n");
  528.             }
  529.         }
  530.  
  531.     if(inilex( copys(file_name) ))
  532.         done(1);
  533.     if (filename0) {
  534.         fprintf(diagfile, "%s:\n", file_name);
  535.         fflush(diagfile);
  536.         }
  537.  
  538.     procinit();
  539.     if(k = yyparse())
  540.     {
  541.         fprintf(diagfile, "Bad parse, return code %d\n", k);
  542.         done(1);
  543.     }
  544.  
  545.     commonprotos(protofile);
  546.     if (protofile == stdout && !skipC)
  547.         printf("#endif\n\n");
  548.  
  549.     if (nerr || skipC)
  550.         goto C_skipped;
  551.  
  552.  
  553. /* Write out the declarations which are global to this file */
  554.  
  555.     if ((c2d = comm2dcl()) == 1)
  556.         nice_printf(c_output, "/*>>>'/dev/null'<<<*/\n\n\
  557. /* Split this into several files by piping it through\n\n\
  558. sed \"s/^\\/\\*>>>'\\(.*\\)'<<<\\*\\/\\$/cat >'\\1' <<'\\/*<<<\\1>>>*\\/'/\" | /bin/sh\n\
  559.  */\n\
  560. /*<<</dev/null>>>*/\n\
  561. /*>>>'%s'<<<*/\n", cdfilename);
  562.     if (gflag)
  563.         nice_printf (c_output, "#line 1 \"%s\"\n", file_name);
  564.     if (!skipversion) {
  565.         nice_printf (c_output, "/* %s -- translated by f2c ", file_name);
  566.         nice_printf (c_output, "(version %s).\n", F2C_version);
  567.         nice_printf (c_output,
  568.     "   You must link the resulting object file with the libraries:\n\
  569.     %s   (in that order)\n*/\n\n", link_msg);
  570.         }
  571.     if (Ansi == 2)
  572.         nice_printf(c_output,
  573.             "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
  574.     nice_printf (c_output, "%s#include \"f2c.h\"\n\n", def_i2);
  575.     if (gflag)
  576.         nice_printf (c_output, "#line 1 \"%s\"\n", file_name);
  577.     if (Castargs && typedefs)
  578.         write_typedefs(c_output);
  579.     nice_printf (c_file, "\n");
  580.     fclose (c_file);
  581.     c_file = c_output;        /* HACK to get the next indenting
  582.                        to work */
  583.     wr_common_decls (c_output);
  584.     if (blkdfile)
  585.         list_init_data(&blkdfile, blkdfname, c_output);
  586.     wr_globals (c_output);
  587.     if ((c_file = fopen (c_functions, textread)) == (FILE *) NULL)
  588.         Fatal("main - couldn't reopen c_functions");
  589.     ffilecopy (c_file, c_output);
  590.     if (*main_alias) {
  591.         nice_printf (c_output, "/* Main program alias */ ");
  592.         nice_printf (c_output, "int %s () { MAIN__ ();%s }\n",
  593.             main_alias, Ansi ? " return 0;" : "");
  594.         }
  595.     if (Ansi == 2)
  596.         nice_printf(c_output,
  597.             "#ifdef __cplusplus\n\t}\n#endif\n");
  598.     if (c2d) {
  599.         if (c2d == 1)
  600.             fprintf(c_output, "/*<<<%s>>>*/\n", cdfilename);
  601.         else
  602.             fclose(c_output);
  603.         def_commons(c_output);
  604.         }
  605.     if (c2d != 2)
  606.         fclose (c_output);
  607.  
  608.  C_skipped:
  609.     if(parstate != OUTSIDE)
  610.         {
  611.         warn("missing final end statement");
  612.         endproc();
  613.         }
  614.     done(nerr ? 1 : 0);
  615.     /* NOT REACHED */ return 0;
  616. }
  617.  
  618.  
  619.  FILEP
  620. #ifdef KR_headers
  621. opf(fn, mode)
  622.     char *fn;
  623.     char *mode;
  624. #else
  625. opf(char *fn, char *mode)
  626. #endif
  627. {
  628.     FILEP fp;
  629.     if( fp = fopen(fn, mode) )
  630.         return(fp);
  631.  
  632.     fatalstr("cannot open intermediate file %s", fn);
  633.     /* NOT REACHED */ return 0;
  634. }
  635.  
  636.  
  637.  void
  638. #ifdef KR_headers
  639. clf(p, what, quit)
  640.     FILEP *p;
  641.     char *what;
  642.     int quit;
  643. #else
  644. clf(FILEP *p, char *what, int quit)
  645. #endif
  646. {
  647.     if(p!=NULL && *p!=NULL && *p!=stdout)
  648.     {
  649.         if(ferror(*p)) {
  650.             fprintf(stderr, "I/O error on %s\n", what);
  651.             if (quit)
  652.                 done(3);
  653.             retcode = 3;
  654.             }
  655.         fclose(*p);
  656.     }
  657.     *p = NULL;
  658. }
  659.  
  660.  
  661.  void
  662. #ifdef KR_headers
  663. done(k)
  664.     int k;
  665. #else
  666. done(int k)
  667. #endif
  668. {
  669.     clf(&initfile, "initfile", 0);
  670.     clf(&c_file, "c_file", 0);
  671.     clf(&pass1_file, "pass1_file", 0);
  672.     Un_link_all(k);
  673.     exit(k|retcode);
  674. }
  675.