home *** CD-ROM | disk | FTP | other *** search
- /* atvar.c -- Administrator Translator Variables
-
- Copyright (c) 1983 by James F. Gimpel
- Copyright (c) 1983, 1984, 1985 by JMI Software Consultants, Inc.
-
- This module allows tailoring of the Basic to C
- translator to allow for version peculiarities.
- Modification of variables can take place prior to
- compilation or at run-time as the result of user
- options (see u_opt this module).
- */
- #include "com.h"
-
- /* Global variables
- */
-
- GLOBAL FLAG bcomm = 0 ; /*
- -----
- * a flag to indicate whether to incorporate the
- * original Basic statements as comments in the
- * C program.
- */
-
- GLOBAL FLAG bv_blt = 1 ; /*
- ------
- * indicates that a blank will terminate basic
- * variables. Normally blanks are ignored.
- */
-
- GLOBAL FLAG bv_kwpr = 1 ; /*
- -------
- * KeyWord PRefix -- if on (1) this allows identifiers
- * to have a keyword (reserved word) as a prefix such as
- * ENDOFFILE or TOWN. If on, keywords may not be followed
- * by alphanumerics without intervening blanks.
- */
-
- GLOBAL INT bv_mxa = 0 ; /*
- ------
- * the maximum number of leading alphabetic characters
- * in an identifier. For minimal Basic, this should be
- * 1. If 0, there is no limit but then, to avoid keywords
- * from being sucked up, turn bv_blt on.
- */
-
- GLOBAL INT bv_mxc = 0 ; /*
- ------
- * the maximum number of characters in a Basic variable
- * exclusive of trailing $ or other type-specifying
- * characters. If = 0, there is no limit. If nonzero,
- * it must be no less than bv_mxa.
- */
-
- GLOBAL FLAG bv_rkch = 0 ; /*
- -------
- * Repeated Key-word CHeck -- causes a check for a keyword
- * (reserved word) at each point within a user identifier
- * and if one is found the identifier is assumed terminated.
- * This is usually necessary if blanks do not terminate
- * identifiers (see bv_blt).
- */
-
- GLOBAL INT chs_len = 3000 ; /*
- -------
- * length in chars. of short-term character storage
- * (everything used just for a single statement)
- */
-
- GLOBAL TEXT cmp_dir = '%' ; /*
- -------
- * Compiler-Directive Character:
- * Appearance of this character at the beginning a line
- * indicates the beginning of a compiler directive.
- */
-
- GLOBAL TEXT cmtch = '\'' ; /*
- -----
- * Comment character -- introduces a comment in mid-line.
- * Has no effect in a REMark or in a quoted string.
- * This has precedence over the character-type declaration
- * in atbls.c (array char_type).
- * A zero value can be used if no comment character is wanted.
- */
-
- GLOBAL TEXT con_ch = '\\' ; /*
- ------
- * Continuation Character: Appearance of this char.
- * as the last character of a line causes the next line
- * to be annexed as part of the current line with the
- * con_ch replaced by blank. Appearances of con_ch other
- * than as the last char. of a line are not affected by this
- * declaration.
- */
-
- GLOBAL FLAG crflag = 1 ; /*
- ------
- * A flag to indicate that CR/LF pairs occur at the
- * end of each input line, and should be output at
- * the end of each output line. If zero, input and
- * output lines end with a LF.
- */
-
- GLOBAL FLAG def_fn = 0 ; /*
- ------
- * A flag to indicate whether "FN" is a required
- * prefix for DEFined functions
- */
-
- GLOBAL FLAG def_oa = 1 ; /*
- ------
- * A flag to indicate whether arguments are optional
- * on the DEF statement
- */
-
-
- GLOBAL TEXT ebuf[MAXEBUF] = {0} ; /*
-
- * A buffer that is used to store the current line of BASIC
- * code that is being translated
- */
-
- GLOBAL INT endebuf = MAXEBUF ; /*
-
- * Maximum size of storage used for BASIC statement
- */
-
- GLOBAL FLAG eflag = 0 ; /*
- -------
- * quickerer everything flag -- all BASIC variables that are
- * not decalred as integer (end in %) yet never use any
- * floating point operations (including explicitly set
- * variables and input variables) are declared as integers
- * when this flag is set.
- */
-
- GLOBAL FLAG end_end = 0 ; /*
- -------
- * A flag to indicate whether an END statement will end the
- * program text or merely cause a termination when executed.
- * An END as a part of a then clause never is taken as an
- * end to program text.
- */
-
- GLOBAL STRING erprfx = "E_" ; /*
- ------
- * Error Label Prefix --
- * Error labels are generated when ON ERROR GOTOs
- * occur in the program. One label is generated
- * for each BASIC statement. The prefix is followed
- * by a numeric string.
- */
-
-
- GLOBAL STRING fbprfx = "FB" ; /*
- ------
- * Begin FOR Loop Label Prefix --
- * FOR loop labels are generated when FOR-NEXT statements
- * can not be translated into a for(;;) statement. This
- * occurs when the NEXT occurs at a different level of
- * nesting within IF-THEN-ELSE statements than the FOR
- * statement it corresponds to.
- */
-
- GLOBAL STRING feprfx = "FE" ; /*
- ------
- * End FOR Loop Label Prefix --
- * FOR loop labels are generated when FOR-NEXT statements
- * can not be translated into a for(;;) statement. This
- * occurs when the NEXT occurs at a different level of
- * nesting within IF-THEN-ELSE statements than the FOR
- * statement it corresponds to.
- */
-
-
- GLOBAL INT idlimit = 7 ; /*
- -------
- * Maximum discrimination on identifiers for C.
- * It is presumed that the target language can support
- * identifiers to an unlimited length and that it
- * imploys the first 'idlimit' of these for comparisons.
- */
-
- GLOBAL STRING lbprfx = "l_" ; /*
- ------
- * Label Prefix -- The string prepended to Basic
- * labels to form C labels
- */
-
- GLOBAL FLAG main_prog = 1 ; /*
- ---------
- * If this flag is on (the default case) the Basic program
- * is presumed to be a main program. Otherwise it is assumed
- * to be a sub-program with the first label indicating the
- * entry point. If proc is on other entry points may also
- * exist.
- */
-
- GLOBAL STRING mlprfx = "ml_" ; /*
- ------
- * Multipliers for dynamic arrays are constructed by
- * prepending this prefix to a generated integer.
- */
-
- GLOBAL INT mstmlen = 2000 ; /*
- -------
- * Maximum Statement Length
- */
-
- GLOBAL TEXT mxposint[] = "32767" ; /*
- --------
- * Maximum Positive Integer (as a text string)
- * Numbers in the input BASIC program that
- * are larger than this, are represented as
- * floating point numbers
- */
-
- GLOBAL FLAG neediv = 0 ;
- /* ------
- * Need Initial Value for defined variables
- * With some compilers, notably Whitesmiths', defined
- * variables need initializers.
- */
-
- GLOBAL FLAG optlet = 1 ; /*
- ------
- * a flag to indicate whether LET is optional
- * in Basic assignment statements.
- */
-
- GLOBAL FLAG proc = 1 ; /*
- ----
- * If on (=1), the translator will attempt to create
- * procedures from GOSUB segments. Without this
- * flag, the translator produces one long program.
- * If on, inter-GOSUB GOTO's are prohibited.
- */
-
- GLOBAL STRING prprfx = "pr_" ; /*
- ------
- * procedure names are constructed by appending
- * a label to the prefix (the procedure prefix)
- */
-
-
- GLOBAL FLAG qflag = 0 ; /*
- -------
- * quickerer flag -- all BASIC variables that are
- * not decalred as integer (end in %) yet never use any
- * floating point operations (excluding explicitly set
- * variables and input variables) are declared as integers
- * when this flag is set.
- */
-
- GLOBAL FLAG sflag = 0 ; /*
- * speed flag -- invoke code optimizations (eg. ++x, etc.)
- */
-
-
- GLOBAL FLAG st_flag = 1 ; /*
- -------
- * static flag -- all BASIC variables are defined as static
- * (and hence can not be referenced from other source files).
- * Otherwise, all variables are globally defined (and may
- * conflict library function names)
- */
-
- GLOBAL TEXT stmsep = ':' ; /*
- ------
- * Statement Separator; This character allows
- * multiple Basic statements to be
- * placed on the same line (with a single label).
- */
-
- GLOBAL STRING stndtp = "float" ; /*
- ------
- * Standard Type for arithmetic variables;
- * may be "float" or "double".
- */
-
- GLOBAL FLAG strace = 0 ; /*
- ------
- * Statement Trace -- a flag that controls the insertion
- * into the C code of a message-producing call on each
- * statement label.
- */
-
-
- GLOBAL INT strlpfx = 1; /*
- -------
- * String Length Prefix
- * Determines the numbe of bytes used to represent the
- * length of a BASIC string variable. A value of zero
- * means strings can have unlimited length, but can not
- * have embedded null characters (binary zero bytes).
- * A value of one allows strings of up to 255 charaters.
- * A value of two allows strings of up to 65535 characters.
- */
-
- GLOBAL COUNT systabs = 8; /*
- -------
- * System Tab Stops
- * Indicates the number of spaces that the host operating
- * system translates tab characters into. This is used to
- * produce uniformly indented C code on all systems. See
- * the description of the tabstops variable (below) for
- * more information.
- */
-
- GLOBAL COUNT tabstops = 4; /*
- --------
- * Tab Stops
- * This value determines the amount of leading whitespace
- * for each indent level in the output C code. It is used
- * in conjunction with the systabs value to output a
- * combination of tabs and spaces at the beginning of each
- * output line.
- */
-
- GLOBAL STRING tlprfx = "g_" ; /*
- ------
- * Temporary Label Prefix --
- * A so-called temporary label, better named generated
- * label, is one generated by the translator, usually
- * for the purpose of receiving control back from a call
- */
-
- GLOBAL STRING tiprfx = "it_" ; /*
- ------
- * Temporary Integer Prefix --
- * Integer Temporaries are denoted by identifiers
- * consisting of this prefix followed by some numeral
- */
-
- GLOBAL STRING tfprfx = "ft_" ; /*
- ------
- * Temporary Float Prefix --
- * Same as tiprfx except for Float
- */
-
- GLOBAL STRING tdprfx = "dt_" ; /*
- ------
- * Temporary Double Prefix --
- * Same as tiprfx except for Double
- */
-
- GLOBAL STRING tsprfx = "st_" ; /*
- ------
- * Temporary String Prefix --
- * String Temporaries are denoted by identifiers
- * consisting of this prefix followed by some numeral
- */
-
- GLOBAL FLAG vflag = 0 ; /*
- -------
- * quickerer verify flag -- all BASIC variables that are
- * not decalred as integer (end in %) yet never use any
- * floating point operations (including explicitly set
- * variables and input variables) are declared as integers,
- * if the user specifies them to be integer when the
- * program interactively queries the user,
- * when this flag is set.
- */
-
- /* u_opt() allows the administrator to set his options
- based on flags provided by the end user.
- Arguments are exactly the same as provided to the
- main program. This routine is called after bfinit() but
- in time to allow parameters such as chs_len to
- be reset.
- */
-
- GLOBAL STRING infile = NULL; /* name of input file */
- GLOBAL STRING outfile = NULL; /* name of output file */
-
- VOID u_opt(argc, argv)
- COUNT argc;
- STRING *argv;
- {
- #ifdef TRACE
- IMPORT TRBITS trace;
- #endif
- IMPORT INT strlpfx;
- IMPORT FLAG bcomm, bv_blt, bv_kwpr, bv_rkch,
- main_prog, proc, st_flag, qflag, vflag, eflag, sflag;
- EXFUNC LONG cvt_sh();
- EXFUNC VOID err_cat(), err_gen();
- EXFUNC XCHAR to_low();
- IMPORT TEXT *infile, *outfile;
- TEXT *s;
- BOOL oflag;
-
- oflag = NO;
- while (--argc > 0)
- {
- if (*(s = *(++argv)) == '-')
- while (*++s)
- switch (*s)
- {
- case 'b': /* blank-oriented scanning */
- case 'B':
- bv_blt = 1 - bv_blt;
- bv_kwpr = 1 - bv_kwpr;
- bv_rkch = 1 - bv_rkch;
- break;
- case 'c': /* insert BASIC statements as comments */
- case 'C':
- bcomm = 1;
- break;
- case 'e': /* optimize all variables whenever possible*/
- case 'E':
- eflag = 1;
- break;
- case 'f': /* translate a function */
- case 'F':
- main_prog = 0;
- break;
- case 'g': /* make all variables global */
- case 'G':
- st_flag = 0;
- break;
- case 'm': /* make one monolithic function */
- case 'M':
- proc = 0;
- break;
- case 'n': /* make null terminated strings */
- case 'N':
- strlpfx = 0;
- break;
- case 'o': /* next argument is output file name */
- case 'O':
- oflag = YES;
- break;
- case 'q': /* optimize variables */
- case 'Q':
- qflag = 1;
- break;
- case 's': /* invoke code optimizations */
- case 'S':
- sflag = YES;
- break;
- case 't': /* enable statement execution tracing */
- case 'T':
- strace = YES;
- break;
- case 'v': /* optimize to INTS but verify */
- case 'V':
- vflag = 1;
- break;
- #ifdef TRACE
- case 'x': /* refers to tracing the internals of BASTOC */
- case 'X':
- if (s[1])
- trace = cvt_sh(s + 1);
- else
- trace = ~0L; /* turn everything on */
- break;
- #endif
- default:
- err_gen("flag ignored $s\n", s);
- break;
- }
- else if (oflag && outfile == NULL)
- outfile = s;
- else if (infile == NULL)
- infile = s;
- else if (outfile == NULL)
- outfile = s;
- else
- err_cat("redundant argument: $s\n", s);
- }
- }