📄 dcalc.c
字号:
errcod = 14; goto synerr; }++as;*as = psym;goto gettok;synerr:#if INTHELPprintf( "%s ", intmsg[errcod] );#endifprintf( " error %d\n", errcod );abmac(); /* flush the command line */goto getcmd;} /* end of program *//* parser() *//* Get token from input string and identify it. */static char number[128];struct symbol *parser( ){register struct symbol *psym;register char *pline;struct varent *pvar;struct strent *pstr;char *cp, *plc, *pn;long lnc;int i;double tem;/* reference for old Whitesmiths compiler: *//* *extern FILE *stdout; */pline = interl; /* get current location in command string *//* If at beginning of string, must ask for more input */if( pline == line ) { if( maccnt > 0 ) { --maccnt; cp = maclin; plc = pline; while( (*plc++ = *cp++) != 0 ) ; goto mstart; } if( takptr < 0 ) { /* no take file active: prompt keyboard input */ printf("* "); }/* Various ways of typing in a command line. *//* * Old Whitesmiths call to print "*" immediately * use RT11 .GTLIN to get command string * from command file or terminal *//* * fflush(stdout); * gtlin(line); */ zgets( line, TRUE ); /* keyboard input for other systems: */mstart: uposs = 1; /* unary operators possible at start of line */ }ignore:/* Skip over spaces */while( *pline == ' ' ) ++pline;/* unary minus after operator */if( uposs && (*pline == '-') ) { psym = &oprtbl[2]; /* UMINUS */ ++pline; goto pdon3; } /* COMP *//*if( uposs && (*pline == '~') ) { psym = &oprtbl[3]; ++pline; goto pdon3; }*/if( uposs && (*pline == '+') ) /* ignore leading plus sign */ { ++pline; goto ignore; }/* end of null terminated input */if( (*pline == '\n') || (*pline == '\0') || (*pline == '\r') ) { pline = line; goto endlin; }if( *pline == ';' ) { ++pline;endlin: psym = &oprtbl[1]; /* EOL */ goto pdon2; }/* parser() *//* Test for numeric input */if( (ISDIGIT(*pline)) || (*pline == '.') ) { lnc = 0; /* initialize numeric input to zero */ qnc = 0.0; if( *pline == '0' ) { /* leading "0" may mean octal or hex radix */ ++pline; if( *pline == '.' ) goto decimal; /* 0.ddd */ /* leading "0x" means hexadecimal radix */ if( (*pline == 'x') || (*pline == 'X') ) { ++pline; while( ISXDIGIT(*pline) ) { i = *pline++ & 0xff; if( i >= 'a' ) i -= 047; if( i >= 'A' ) i -= 07; i -= 060; lnc = (lnc << 4) + i; qnc = lnc; } goto numdon; } else { while( ISOCTAL( *pline ) ) { i = ((*pline++) & 0xff) - 060; lnc = (lnc << 3) + i; qnc = lnc; } goto numdon; } } else { /* no leading "0" means decimal radix *//******/decimal: pn = number; while( (ISDIGIT(*pline)) || (*pline == '.') ) *pn++ = *pline++;/* get possible exponent field */ if( (*pline == 'e') || (*pline == 'E') ) *pn++ = *pline++; else goto numcvt; if( (*pline == '-') || (*pline == '+') ) *pn++ = *pline++; while( ISDIGIT(*pline) ) *pn++ = *pline++;numcvt: *pn++ = ' '; *pn++ = 0;#if 0#if NE == 6 asctoe64( number, &qnc );#else asctoe113( number, &qnc );#endif#endif sscanf( number, "%le", &qnc ); }/* output the number */numdon: /* search the symbol table of constants */ pvar = &contbl[0]; for( i=0; i<NCONST; i++ ) { if( (pvar->attrib & BUSY) == 0 ) goto confnd; tem = *pvar->value; if( tem == qnc ) { psym = (struct symbol *)pvar; goto pdon2; } ++pvar; } printf( "no room for constant\n" ); psym = (struct symbol *)&contbl[0]; goto pdon2;confnd: pvar->spel= contbl[0].spel; pvar->attrib = CONST | BUSY; *pvar->value = qnc; psym = (struct symbol *)pvar; goto pdon2; }/* check for operators */psym = &oprtbl[3];for( i=0; i<NOPR; i++ ) { if( *pline == *(psym->spel) ) goto pdon1; ++psym; }/* if quoted, it is a string variable */if( *pline == '"' ) { /* find an empty slot for the string */ pstr = strtbl; /* string table */ for( i=0; i<NSTRNG-1; i++ ) { if( (pstr->attrib & BUSY) == 0 ) goto fndstr; ++pstr; } printf( "No room for string\n" ); pstr->attrib |= ILLEG; psym = (struct symbol *)pstr; goto pdon0;fndstr: pstr->attrib |= BUSY; plc = pstr->string; ++pline; for( i=0; i<39; i++ ) { *plc++ = *pline; if( (*pline == '\n') || (*pline == '\0') || (*pline == '\r') ) {illstr: pstr = &strtbl[NSTRNG-1]; pstr->attrib |= ILLEG; printf( "Missing string terminator\n" ); psym = (struct symbol *)pstr; goto pdon0; } if( *pline++ == '"' ) goto finstr; } goto illstr; /* no terminator found */finstr: --plc; *plc = '\0'; psym = (struct symbol *)pstr; goto pdon2; }/* If none of the above, search function and symbol tables: *//* copy character string to array lc[] */plc = &lc[0];while( ISALPHA(*pline) ) { /* convert to lower case characters */ if( ISUPPER( *pline ) ) *pline += 040; *plc++ = *pline++; }*plc = 0; /* Null terminate the output string *//* parser() */psym = (struct symbol *)menstk[menptr]; /* function table */plc = &lc[0];cp = psym->spel;do { if( strcmp( plc, cp ) == 0 ) goto pdon3; /* following unary minus is possible */ ++psym; cp = psym->spel; }while( *cp != '\0' );psym = (struct symbol *)&indtbl[0]; /* indirect symbol table */plc = &lc[0];cp = psym->spel;do { if( strcmp( plc, cp ) == 0 ) goto pdon2; ++psym; cp = psym->spel; }while( *cp != '\0' );pdon0:pline = line; /* scrub line if illegal symbol */goto pdon2;pdon1:++pline;if( (psym->attrib & 0xf) == RPAREN )pdon2: uposs = 0;elsepdon3: uposs = 1;interl = pline;return( psym );} /* end of parser *//* exit from current menu */double cmdex(){if( menptr == 0 ) { printf( "Main menu is active.\n" ); }else --menptr;cmdh();return(0.0);}/* gets() */void zgets( gline, echo )char *gline;int echo;{register char *pline;register int i;scrub:pline = gline;getsl: if( (pline - gline) >= LINLEN ) { printf( "\nLine too long\n *" ); goto scrub; } if( takptr < 0 ) { /* get character from keyboard *//*if DECPDP gtlin( gline ); return(0);else*/ *pline = getchar();/*endif*/ } else { /* get a character from take file */ i = fgetc( takstk[takptr] ); if( i == -1 ) { /* end of take file */ if( takptr >= 0 ) { /* close file and bump take stack */ fclose( takstk[takptr] ); takptr -= 1; } if( takptr < 0 ) /* no more take files: */ printf( "*" ); /* prompt keyboard input */ goto scrub; /* start a new input line */ } *pline = i; } *pline &= 0x7f; /* xon or xoff characters need filtering out. */ if ( *pline == XON || *pline == XOFF ) goto getsl; /* control U or control C */ if( (*pline == 025) || (*pline == 03) ) { printf( "\n" ); goto scrub; } /* Backspace or rubout */ if( (*pline == 010) || (*pline == 0177) ) { pline -= 1; if( pline >= gline ) { if ( echo ) printf( "\010\040\010" ); goto getsl; } else goto scrub; } if ( echo ) printf( "%c", *pline ); if( (*pline != '\n') && (*pline != '\r') ) { ++pline; goto getsl; } *pline = 0; if ( echo ) printf( "%c", '\n' ); /* \r already echoed */}/* help function */double cmdhlp(){printf( "%s", idterp );printf( "\nFunctions:\n" );prhlst( &funtbl[0] );printf( "\nVariables:\n" );prhlst( &indtbl[0] );printf( "\nOperators:\n" );prhlst( &oprtbl[2] );printf("\n");return(0.0);}double cmdh(){prhlst( menstk[menptr] );printf( "\n" );return(0.0);}/* print keyword spellings */double prhlst(vps)void *vps;{register int j, k;int m;register struct symbol *ps = vps;j = 0;while( *(ps->spel) != '\0' ) { k = strlen( ps->spel ) - 1;/* size of a tab field is 2**3 chars */ m = ((k >> 3) + 1) << 3; j += m; if( j > 72 ) { printf( "\n" ); j = m; } printf( "%s\t", ps->spel ); ++ps; }return(0.0);}#if SALONEdouble init(){/* Set coprocessor to double precision. */dprec();return 0.0;}#endif/* macro commands *//* define macro */double cmddm(){zgets( maclin, TRUE );return(0.0);}/* type (i.e., display) macro */double cmdtm(){printf( "%s\n", maclin );return 0.0;}/* execute macro # times */double cmdem( arg )double arg;{double f;long n;f = floor(arg);n = f;if( n <= 0 ) n = 1;maccnt = n;return(0.0);}/* open a take file */double take( fname )char *fname;{FILE *f;while( *fname == ' ' ) fname += 1;f = fopen( fname, "r" );if( f == 0 ) { printf( "Can't open take file %s\n", fname ); takptr = -1; /* terminate all take file input */ return 0.0; }takptr += 1;takstk[ takptr ] = f;printf( "Running %s\n", fname );return(0.0);}/* abort macro execution */double abmac(){maccnt = 0;interl = line;return(0.0);}/* display integer part in hex, octal, and decimal */double hex(qx)double qx;{double f;long z;f = floor(qx);z = f;printf( "0%lo 0x%lx %ld.\n", z, z, z );return(qx);}#define NASC 16double bits( x )double x;{union { double d; short i[4]; } du;union { float f; short i[2]; } df;int i;du.d = x;printf( "double: " );for( i=0; i<4; i++ ) printf( "0x%04x,", du.i[i] & 0xffff );printf( "\n" );df.f = (float) x;printf( "float: " );for( i=0; i<2; i++ ) printf( "0x%04x,", df.i[i] & 0xffff );printf( "\n" );return(x);}/* Exit to monitor. */double mxit(){exit(0);return(0.0);}double cmddig( x )double x;{double f;long lx;f = floor(x);lx = f;ndigits = lx;if( ndigits <= 0 ) ndigits = DEFDIS;return(f);}double csys(x)char *x;{system( x+1 );cmdh();return(0.0);}double ifrac(x)double x;{unsigned long lx;long double y, z;z = floor(x);lx = z;y = x - z;printf( " int = %lx\n", lx );return(y);}double xcmpl(x,y)double x,y;{double ans;ans = -2.0;if( x == y ) { printf( "x == y " ); ans = 0.0; }if( x < y ) { printf( "x < y" ); ans = -1.0; }if( x > y ) { printf( "x > y" ); ans = 1.0; }return( ans );}extern double INFINITY, NAN;double makenan(x)double x;{return(NAN);}double makeinfinity(x)double x;{return(INFINITY);}double zfrexp(x)double x;{double y;int e;y = frexp(x, &e);printf("exponent = %d, significand = ", e );return(y);}double zldexp(x,e)double x, e;{double y;int i;i = e;y = ldexp(x,i);return(y);}double hexinput(a, b)double a,b;{union { double d; unsigned short i[4]; } u;unsigned long l;#ifdef IBMPCl = a;u.i[3] = l >> 16;u.i[2] = l;l = b;u.i[1] = l >> 16;u.i[0] = l;#endif#ifdef DECl = a;u.i[3] = l >> 16;u.i[2] = l;l = b;u.i[1] = l >> 16;u.i[0] = l;#endif#ifdef MIEEEl = a;u.i[0] = l >> 16;u.i[1] = l;l = b;u.i[2] = l >> 16;u.i[3] = l;#endif#ifdef UNKl = a;u.i[0] = l >> 16;u.i[1] = l;l = b;u.i[2] = l >> 16;u.i[3] = l;#endifreturn(u.d);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -