nl.c
来自「早期freebsd实现」· C语言 代码 · 共 872 行 · 第 1/2 页
C
872 行
/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)nl.c 8.1 (Berkeley) 6/6/93";#endif /* not lint */#include "whoami.h"#include "0.h"#ifdef PI#include "opcode.h"#include "objfmt.h"/* * NAMELIST SEGMENT DEFINITIONS */struct nls { struct nl *nls_low; struct nl *nls_high;} ntab[MAXNL], *nlact;struct nl nl[INL];struct nl *nlp = nl;struct nls *nlact = ntab; /* * all these strings must be places where people can find them * since lookup only looks at the string pointer, not the chars. * see, for example, pTreeInit. */ /* * built in constants */char *in_consts[] = { "true" , "false" , "TRUE", "FALSE", "minint" , "maxint" , "minchar" , "maxchar" , "bell" , "tab" , 0 }; /* * built in simple types */char *in_types[] = { "boolean", "char", "integer", "real", "_nil", /* dummy name */ 0 };int in_rclasses[] = { TINT , TINT , TINT , TCHAR , TBOOL , TDOUBLE , 0 };long in_ranges[] = { -128L , 127L , -32768L , 32767L , -2147483648L , 2147483647L , 0L , 127L , 0L , 1L , 0L , 0L /* fake for reals */ }; /* * built in constructed types */char *in_ctypes[] = { "Boolean" , "intset" , "alfa" , "text" , 0 }; /* * built in variables */char *in_vars[] = { "input" , "output" , 0 }; /* * built in functions */char *in_funcs[] = { "abs" , "arctan" , "card" , "chr" , "clock" , "cos" , "eof" , "eoln" , "eos" , "exp" , "expo" , "ln" , "odd" , "ord" , "pred" , "round" , "sin" , "sqr" , "sqrt" , "succ" , "trunc" , "undefined" , /* * Extensions */ "argc" , "random" , "seed" , "wallclock" , "sysclock" , 0 }; /* * Built-in procedures */char *in_procs[] = { "assert", "date" , "dispose" , "flush" , "get" , "getseg" , "halt" , "linelimit" , "message" , "new" , "pack" , "page" , "put" , "putseg" , "read" , "readln" , "remove" , "reset" , "rewrite" , "time" , "unpack" , "write" , "writeln" , /* * Extensions */ "argv" , "null" , "stlimit" , 0 };#ifndef PI0 /* * and their opcodes */int in_fops[] = { O_ABS2, O_ATAN, O_CARD|NSTAND, O_CHR2, O_CLCK|NSTAND, O_COS, O_EOF, O_EOLN, 0, O_EXP, O_EXPO|NSTAND, O_LN, O_ODD2, O_ORD2, O_PRED2, O_ROUND, O_SIN, O_SQR2, O_SQRT, O_SUCC2, O_TRUNC, O_UNDEF|NSTAND, /* * Extensions */ O_ARGC|NSTAND, O_RANDOM|NSTAND, O_SEED|NSTAND, O_WCLCK|NSTAND, O_SCLCK|NSTAND }; /* * Built-in procedures */int in_pops[] = { O_ASRT|NSTAND, O_DATE|NSTAND, O_DISPOSE, O_FLUSH|NSTAND, O_GET, 0, O_HALT|NSTAND, O_LLIMIT|NSTAND, O_MESSAGE|NSTAND, O_NEW, O_PACK, O_PAGE, O_PUT, 0, O_READ4, O_READLN, O_REMOVE|NSTAND, O_RESET, O_REWRITE, O_TIME|NSTAND, O_UNPACK, O_WRITEF, O_WRITLN, /* * Extensions */ O_ARGV|NSTAND, O_ABORT|NSTAND, O_STLIM|NSTAND };#endif/* * Initnl initializes the first namelist segment and then * initializes the name list for block 0. */initnl() { register char **cp; register struct nl *np; struct nl *fp; int *ip; long *lp;#ifdef DEBUG if ( hp21mx ) { MININT = -32768.; MAXINT = 32767.;#ifndef PI0#ifdef OBJ genmx();#endif OBJ#endif }#endif ntab[0].nls_low = nl; ntab[0].nls_high = &nl[INL]; (void) defnl ( (char *) 0 , 0 , NLNIL , 0 ); /* * Types */ for ( cp = in_types ; *cp != 0 ; cp ++ ) (void) hdefnl ( *cp , TYPE , nlp , 0 ); /* * Ranges */ lp = in_ranges; for ( ip = in_rclasses ; *ip != 0 ; ip ++ ) { np = defnl ( (char *) 0 , RANGE , nl+(*ip) , 0 ); nl[*ip].type = np; np -> range[0] = *lp ++ ; np -> range[1] = *lp ++ ; }; /* * built in constructed types */ cp = in_ctypes; /* * Boolean = boolean; */ (void) hdefnl ( *cp++ , TYPE , (struct nl *) (nl+T1BOOL) , 0 ); /* * intset = set of 0 .. 127; */ intset = ((struct nl *) *cp++); (void) hdefnl( (char *) intset , TYPE , nlp+1 , 0 ); (void) defnl ( (char *) 0 , SET , nlp+1 , 0 ); np = defnl ( (char *) 0 , RANGE , nl+TINT , 0 ); np -> range[0] = 0L; np -> range[1] = 127L; /* * alfa = array [ 1 .. 10 ] of char; */ np = defnl ( (char *) 0 , RANGE , nl+TINT , 0 ); np -> range[0] = 1L; np -> range[1] = 10L; defnl ( (char *) 0 , ARRAY , nl+T1CHAR , 1 ) -> chain = np; (void) hdefnl ( *cp++ , TYPE , nlp-1 , 0 ); /* * text = file of char; */ (void) hdefnl ( *cp++ , TYPE , nlp+1 , 0 ); np = defnl ( (char *) 0 , FILET , nl+T1CHAR , 0 ); np -> nl_flags |= NFILES; /* * input,output : text; */ cp = in_vars;# ifndef PI0 input = hdefnl ( *cp++ , VAR , np , INPUT_OFF ); output = hdefnl ( *cp++ , VAR , np , OUTPUT_OFF );# else input = hdefnl ( *cp++ , VAR , np , 0 ); output = hdefnl ( *cp++ , VAR , np , 0 );# endif# ifdef PC input -> extra_flags |= NGLOBAL; output -> extra_flags |= NGLOBAL;# endif PC /* * built in constants */ cp = in_consts; np = hdefnl ( *cp++ , CONST , nl + TBOOL , 1 ); fp = hdefnl ( *cp++ , CONST , nl + TBOOL , 0 ); (nl + TBOOL)->chain = fp; fp->chain = np; np = hdefnl ( *cp++ , CONST , nl + TBOOL , 1 ); fp = hdefnl ( *cp++ , CONST , nl + TBOOL , 0 ); fp->chain = np; if (opt('s')) (nl + TBOOL)->chain = fp; hdefnl ( *cp++ , CONST , nl + T4INT , 0 ) -> range[0] = MININT; hdefnl ( *cp++ , CONST , nl + T4INT , 0 ) -> range[0] = MAXINT; (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , 0 ); (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , 127 ); (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , '\007' ); (void) hdefnl ( *cp++ , CONST , nl + T1CHAR , '\t' ); /* * Built-in functions and procedures */#ifndef PI0 ip = in_fops; for ( cp = in_funcs ; *cp != 0 ; cp ++ ) (void) hdefnl ( *cp , FUNC , NLNIL , * ip ++ ); ip = in_pops; for ( cp = in_procs ; *cp != 0 ; cp ++ ) (void) hdefnl ( *cp , PROC , NLNIL , * ip ++ );#else for ( cp = in_funcs ; *cp != 0 ; cp ++ ) (void) hdefnl ( *cp , FUNC , NLNIL , 0 ); for ( cp = in_procs ; *cp != 0 , cp ++ ) (void) hdefnl ( *cp , PROC , NLNIL , 0 );#endif# ifdef PTREE pTreeInit();# endif }struct nl *hdefnl(sym, cls, typ, val) char *sym; int cls; struct nl *typ; int val;{ register struct nl *p;#ifndef PI1 if (sym) (void) hash(sym, 0);#endif p = defnl(sym, cls, typ, val);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?