📄 main.c
字号:
/****************************************************************Copyright 1990 - 1994 by AT&T Bell Laboratories and Bellcore.Permission to use, copy, modify, and distribute this softwareand its documentation for any purpose and without fee is herebygranted, provided that the above copyright notice appear in allcopies and that both that the copyright notice and thispermission notice and warranty disclaimer appear in supportingdocumentation, and that the names of AT&T Bell Laboratories orBellcore or any of their entities not be used in advertising orpublicity pertaining to distribution of the software withoutspecific, written prior permission.AT&T and Bellcore disclaim all warranties with regard to thissoftware, including all implied warranties of merchantabilityand fitness. In no event shall AT&T or Bellcore be liable forany special, indirect or consequential damages or any damageswhatsoever resulting from loss of use, data or profits, whetherin an action of contract, negligence or other tortious action,arising out of or in connection with the use or performance ofthis software.****************************************************************/extern char F2C_version[];#include "defs.h"#include "parse.h"int complex_seen, dcomplex_seen;LOCAL int Max_ftn_files;char **ftn_files;int current_ftn_file = 0;flag ftn66flag = NO;flag nowarnflag = NO;flag noextflag = NO;flag no66flag = NO; /* Must also set noextflag to this same value */flag zflag = YES; /* recognize double complex intrinsics */flag debugflag = NO;flag onetripflag = NO;flag shiftcase = YES;flag undeftype = NO;flag checksubs = NO;flag r8flag = NO;flag use_bs = YES;flag keepsubs = NO;#ifdef TYQUADflag use_tyquad = YES;#endifint tyreal = TYREAL;int tycomplex = TYCOMPLEX;int maxregvar = MAXREGVAR; /* if maxregvar > MAXREGVAR, error */int maxequiv = MAXEQUIV;int maxext = MAXEXT;int maxstno = MAXSTNO;int maxctl = MAXCTL;int maxhash = MAXHASH;int maxliterals = MAXLITERALS;int maxcontin = MAXCONTIN;int maxlablist = MAXLABLIST;int extcomm, ext1comm, useauto;int can_include = YES; /* so we can disable includes for netlib */static char *def_i2 = "";static int useshortints = NO; /* YES => tyint = TYSHORT */static int uselongints = NO; /* YES => tyint = TYLONG */int addftnsrc = NO; /* Include ftn source in output */int usedefsforcommon = NO; /* Use #defines for common reference */int forcedouble = YES; /* force real functions to double */int Ansi = NO;int def_equivs = YES;int tyioint = TYLONG;int szleng = SZLENG;int inqmask = M(TYLONG)|M(TYLOGICAL);int wordalign = NO;int forcereal = NO;int warn72 = NO;static int skipC, skipversion;char *file_name, *filename0, *parens;int Castargs = 1;static int Castargs1;static int typedefs = 0;int chars_per_wd, gflag, protostatus;int infertypes = 1;char used_rets[TYSUBR+1];extern char *tmpdir;static int h0align = 0;char *halign, *ohalign;int krparens = NO;int hsize; /* for padding under -h */int htype; /* for wr_equiv_init under -h */chainp Iargs;#define f2c_entry(swit,count,type,store,size) \ p_entry ("-", swit, 0, count, type, store, size)static arg_info table[] = { f2c_entry ("w66", P_NO_ARGS, P_INT, &ftn66flag, YES), f2c_entry ("w", P_NO_ARGS, P_INT, &nowarnflag, YES), f2c_entry ("66", P_NO_ARGS, P_INT, &no66flag, YES), f2c_entry ("1", P_NO_ARGS, P_INT, &onetripflag, YES), f2c_entry ("onetrip", P_NO_ARGS, P_INT, &onetripflag, YES), f2c_entry ("I2", P_NO_ARGS, P_INT, &useshortints, YES), f2c_entry ("I4", P_NO_ARGS, P_INT, &uselongints, YES), f2c_entry ("U", P_NO_ARGS, P_INT, &shiftcase, NO), f2c_entry ("u", P_NO_ARGS, P_INT, &undeftype, YES), f2c_entry ("O", P_ONE_ARG, P_INT, &maxregvar, 0), f2c_entry ("C", P_NO_ARGS, P_INT, &checksubs, YES), f2c_entry ("Nq", P_ONE_ARG, P_INT, &maxequiv, 0), f2c_entry ("Nx", P_ONE_ARG, P_INT, &maxext, 0), f2c_entry ("Ns", P_ONE_ARG, P_INT, &maxstno, 0), f2c_entry ("Nc", P_ONE_ARG, P_INT, &maxctl, 0), f2c_entry ("Nn", P_ONE_ARG, P_INT, &maxhash, 0), f2c_entry ("NL", P_ONE_ARG, P_INT, &maxliterals, 0), f2c_entry ("NC", P_ONE_ARG, P_INT, &maxcontin, 0), f2c_entry ("Nl", P_ONE_ARG, P_INT, &maxlablist, 0), f2c_entry ("c", P_NO_ARGS, P_INT, &addftnsrc, YES), f2c_entry ("p", P_NO_ARGS, P_INT, &usedefsforcommon, YES), f2c_entry ("R", P_NO_ARGS, P_INT, &forcedouble, NO), f2c_entry ("!R", P_NO_ARGS, P_INT, &forcedouble, YES), f2c_entry ("A", P_NO_ARGS, P_INT, &Ansi, YES), f2c_entry ("ext", P_NO_ARGS, P_INT, &noextflag, YES), f2c_entry ("z", P_NO_ARGS, P_INT, &zflag, NO), f2c_entry ("a", P_NO_ARGS, P_INT, &useauto, YES), f2c_entry ("r8", P_NO_ARGS, P_INT, &r8flag, YES), f2c_entry ("i2", P_NO_ARGS, P_INT, &tyioint, NO), f2c_entry ("w8", P_NO_ARGS, P_INT, &wordalign, YES), f2c_entry ("!I", P_NO_ARGS, P_INT, &can_include, NO), f2c_entry ("W", P_ONE_ARG, P_INT, &chars_per_wd, 0), f2c_entry ("g", P_NO_ARGS, P_INT, &gflag, YES), f2c_entry ("T", P_ONE_ARG, P_STRING, &tmpdir, 0), f2c_entry ("E", P_NO_ARGS, P_INT, &extcomm, 1), f2c_entry ("e1c", P_NO_ARGS, P_INT, &ext1comm, 1), f2c_entry ("ec", P_NO_ARGS, P_INT, &ext1comm, 2), f2c_entry ("C++", P_NO_ARGS, P_INT, &Ansi, 2), f2c_entry ("P", P_NO_ARGS, P_INT, &Castargs, 3), f2c_entry ("Ps", P_NO_ARGS, P_INT, &protostatus, 1), f2c_entry ("!P", P_NO_ARGS, P_INT, &Castargs, 0), f2c_entry ("!c", P_NO_ARGS, P_INT, &skipC, 1), f2c_entry ("!it", P_NO_ARGS, P_INT, &infertypes, 0), f2c_entry ("h", P_NO_ARGS, P_INT, &h0align, 1), f2c_entry ("hd", P_NO_ARGS, P_INT, &h0align, 2), f2c_entry ("kr", P_NO_ARGS, P_INT, &krparens, 1), f2c_entry ("krd", P_NO_ARGS, P_INT, &krparens, 2), f2c_entry ("!bs", P_NO_ARGS, P_INT, &use_bs, NO), f2c_entry ("r", P_NO_ARGS, P_INT, &forcereal, YES), f2c_entry ("72", P_NO_ARGS, P_INT, &warn72, 1), f2c_entry ("f", P_NO_ARGS, P_INT, &warn72, 2), f2c_entry ("s", P_NO_ARGS, P_INT, &keepsubs, 1), f2c_entry ("d", P_ONE_ARG, P_STRING, &outbuf, 0),#ifdef TYQUAD f2c_entry ("!i8", P_NO_ARGS, P_INT, &use_tyquad, NO),#endif /* options omitted from man pages */ /* -ev ==> implement equivalence with initialized pointers */ f2c_entry ("ev", P_NO_ARGS, P_INT, &def_equivs, NO), /* -!it used to be the default when -it was more agressive */ f2c_entry ("it", P_NO_ARGS, P_INT, &infertypes, 1), /* -Pd is similar to -P, but omits :ref: lines */ f2c_entry ("Pd", P_NO_ARGS, P_INT, &Castargs, 2), /* -t ==> emit typedefs (under -A or -C++) for procedure argument types used. This is meant for netlib's f2c service, so -A and -C++ will work with older versions of f2c.h */ f2c_entry ("t", P_NO_ARGS, P_INT, &typedefs, 1), /* -!V ==> omit version msg (to facilitate using diff in regression testing) */ f2c_entry ("!V", P_NO_ARGS, P_INT, &skipversion, 1), /* -Dnnn = debug level nnn */ f2c_entry ("D", P_ONE_ARG, P_INT, &debugflag, YES)}; /* table */extern char *c_functions; /* "c_functions" */extern char *coutput; /* "c_output" */extern char *initfname; /* "raw_data" */extern char *blkdfname; /* "block_data" */extern char *p1_file; /* "p1_file" */extern char *p1_bakfile; /* "p1_file.BAK" */extern char *sortfname; /* "init_file" */extern char *proto_fname; /* "proto_file" */FILE *protofile; voidset_externs(Void){ static char *hset[3] = { 0, "integer", "doublereal" };/* Adjust the global flags according to the command line parameters */ if (chars_per_wd > 0) { typesize[TYADDR] = typesize[TYLONG] = typesize[TYREAL] = typesize[TYLOGICAL] = chars_per_wd; typesize[TYINT1] = typesize[TYLOGICAL1] = 1; typesize[TYDREAL] = typesize[TYCOMPLEX] = chars_per_wd << 1; typesize[TYDCOMPLEX] = chars_per_wd << 2; typesize[TYSHORT] = typesize[TYLOGICAL2] = chars_per_wd >> 1; typesize[TYCILIST] = 5*chars_per_wd; typesize[TYICILIST] = 6*chars_per_wd; typesize[TYOLIST] = 9*chars_per_wd; typesize[TYCLLIST] = 3*chars_per_wd; typesize[TYALIST] = 2*chars_per_wd; typesize[TYINLIST] = 26*chars_per_wd; } if (wordalign) typealign[TYDREAL] = typealign[TYDCOMPLEX] = typealign[TYREAL]; if (!tyioint) { tyioint = TYSHORT; szleng = typesize[TYSHORT]; def_i2 = "#define f2c_i2 1\n"; inqmask = M(TYSHORT)|M(TYLOGICAL2); goto checklong; } else szleng = typesize[TYLONG]; if (useshortints) { /* inqmask = M(TYLONG); */ /* used to disallow LOGICAL in INQUIRE under -I2 */ checklong: protorettypes[TYLOGICAL] = "shortlogical"; casttypes[TYLOGICAL] = "K_fp"; if (uselongints) err ("Can't use both long and short ints"); else { tyint = tylogical = TYSHORT; tylog = TYLOGICAL2; } } else if (uselongints) tyint = TYLONG; if (h0align) { if (tyint == TYLONG && wordalign) h0align = 1; ohalign = halign = hset[h0align]; htype = h0align == 1 ? tyint : TYDREAL; hsize = typesize[htype]; } if (no66flag) noextflag = no66flag; if (noextflag) zflag = 0; if (r8flag) { tyreal = TYDREAL; tycomplex = TYDCOMPLEX; r8fix(); } if (forcedouble) { protorettypes[TYREAL] = "E_f"; casttypes[TYREAL] = "E_fp"; } if (maxregvar > MAXREGVAR) { warni("-O%d: too many register variables", maxregvar); maxregvar = MAXREGVAR; } /* if maxregvar > MAXREGVAR *//* Check the list of input files */ { int bad, i, cur_max = Max_ftn_files; for (i = bad = 0; i < cur_max && ftn_files[i]; i++) if (ftn_files[i][0] == '-') { errstr ("Invalid flag '%s'", ftn_files[i]); bad++; } if (bad) exit(1); } /* block */} /* set_externs */ static intcomm2dcl(Void){ Extsym *ext; if (ext1comm) for(ext = extsymtab; ext < nextext; ext++) if (ext->extstg == STGCOMMON && !ext->extinit) return ext1comm; return 0; } static void#ifdef KR_headerswrite_typedefs(outfile) FILE *outfile;#elsewrite_typedefs(FILE *outfile)#endif{ register int i; register char *s, *p = 0; static char st[4] = { TYREAL, TYCOMPLEX, TYDCOMPLEX, TYCHAR }; static char stl[4] = { 'E', 'C', 'Z', 'H' }; for(i = 0; i <= TYSUBR; i++) if (s = usedcasts[i]) { if (!p) { p = Ansi == 1 ? "()" : "(...)"; nice_printf(outfile, "/* Types for casting procedure arguments: */\\n\n#ifndef F2C_proc_par_types\n"); if (i == 0) { nice_printf(outfile, "typedef int /* Unknown procedure type */ (*%s)%s;\n", s, p); continue; } } nice_printf(outfile, "typedef %s (*%s)%s;\n", c_type_decl(i,1), s, p); } for(i = !forcedouble; i < 4; i++) if (used_rets[st[i]]) nice_printf(outfile, "typedef %s %c_f; /* %s function */\n", p = i ? "VOID" : "doublereal",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -