From: Rafał Długołęcki Date: Sun, 21 Jul 2013 20:02:27 +0000 (+0200) Subject: vlp-10 using coding style in standard.c X-Git-Tag: 3.1~27 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=20e297153dc19ff9ff66f7a0ed8d115f816b8ca2;p=vlp.git vlp-10 using coding style in standard.c --- diff --git a/src/int/standard.c b/src/int/standard.c index 74a67d7..e865220 100644 --- a/src/int/standard.c +++ b/src/int/standard.c @@ -34,426 +34,474 @@ or Andrzej Salwicki #include "process.h" #include "intproto.h" -#include -#include +#include +#include /* Call standard procedure */ -void standard(nrproc) /* Process call to a standard proc. */ -word nrproc; +/* Process call to a standard proc. */ +void standard(word nrproc) { - word t1, t2, t3, t5, t6; - double r; - bool absent; - int ch, n; - long tim; - char *cp; - FILE *fp; - char s[80]; - - absent = FALSE; + word t1, t2, t3, t5, t6; + double r; + bool absent; + int ch, n; + long tim; + char *cp; + FILE *fp; + char s[80]; + + absent = FALSE; #ifdef TRACE - fprintf( stderr, "standard procedure %d\n", nrproc ); + fprintf(stderr, "standard procedure %d\n", nrproc); #endif - switch ((int) nrproc) - { - case 1 : /* new array */ - newarry(param[ 1 ].xword, param[ 0 ].xword, param[ 2 ].xword, - ¶m[ 3 ].xvirt, ¶m[ 4 ].xword); + switch ((int) nrproc) { + /* new array */ + case 1: + newarry(param[1]. xword, param[0].xword, param[2].xword, + ¶m[3].xvirt, ¶m[4].xword); + break; + + /* rew */ + case 2: + /* avf */ + case 3: + /* bsf */ + case 4: + /* weo */ + case 5: + /* putrec */ + case 6: + /* getrec */ + case 7: + /* ass */ + case 8: + /* assin */ + case 9: + /* assout */ + case 10: + absent = TRUE; break; - case 2 : /* rew */ - case 3 : /* avf */ - case 4 : /* bsf */ - case 5 : /* weo */ - case 6 : /* putrec */ - case 7 : /* getrec */ - case 8 : /* ass */ - case 9 : /* assin */ - case 10 : /* assout */ - absent = TRUE; - break; - - case 11 : /* unpack:function(s:string):arrayof char */ - t1 = strings+param[ 0 ].xword+1; - t6 = M[ t1-1 ]; /* length of the string */ - if (t6 > 0) /* string not null */ - { - newarry((word) 1, t6, (word) AINT, ¶m[ 1 ].xvirt, &t5); - t5 += 3; - cp = (char *) &M[ t1 ]; - while (t6-- > 0) M[ t5++ ] = *cp++; - } - else /* null string */ - { - param[ 1 ].xvirt.addr = 0; - param[ 1 ].xvirt.mark = 0; + /* unpack:function(s:string):arrayof char */ + case 11: + t1 = strings+param[0].xword+1; + /* length of the string */ + t6 = M[t1 - 1]; + /* string not null */ + if (t6 > 0) { + newarry((word) 1, t6, (word)AINT, ¶m[1].xvirt, &t5); + t5 += 3; + cp = (char *) &M[t1]; + while (t6-- > 0) { + M[t5++] = *cp++; + } + } else { + /* null string */ + param[1].xvirt.addr = 0; + param[1].xvirt.mark = 0; } break; - - case 12 : /* random:function:real */ - param[ 0 ].xreal = (real)prandom(); + /* random:function:real */ + case 12: + param[0].xreal = (real)prandom(); break; - - case 13 : /* time:function:integer */ + /* time:function:integer */ + case 13: time(&tim); - param[ 0 ].xword = tim; + param[0].xword = tim; break; - - case 14 : /* sqrt:function(x:real):real */ - param[ 1 ].xreal = (real)sqrt((double) param[ 0 ].xreal); + /* sqrt:function(x:real):real */ + case 14: + param[1].xreal = (real)sqrt((double) param[0].xreal); break; - - case 15 : /* entier:function(x:real):integer */ - param[ 1 ].xword = entier((double) param[ 0 ].xreal); + /* entier:function(x:real):integer */ + case 15: + param[1].xword = entier((double) param[0].xreal); break; - - case 16 : /* round:function(x:real):integer */ - param[ 1 ].xword = entier((double) (param[ 0 ].xreal+0.5)); + /* round:function(x:real):integer */ + case 16: + param[1].xword = entier((double) (param[0].xreal + 0.5)); break; - - case 17 : /* unused */ - case 18 : /* intrinsic procedure */ + /* unused */ + case 17: + /* intrinsic procedure */ + case 18: absent = TRUE; break; - - case 19 : /* imin:function(x, y:integer):integer */ - param[ 2 ].xword = min(param[ 0 ].xword, param[ 1 ].xword); - break; - - case 20 : /* imax:function(x, y:integer):integer */ - param[ 2 ].xword = max(param[ 0 ].xword, param[ 1 ].xword); - break; - - case 21 : /* imin3:function(x, y, z:integer):integer */ - t1 = min(param[ 0 ].xword, param[ 1 ].xword); - param[ 3 ].xword = min(t1, param[ 2 ].xword); - break; - - case 22 : /* imax3:function(x, y, z:integer):integer */ - t1 = max(param[ 0 ].xword, param[ 1 ].xword); - param[ 3 ].xword = max(t1, param[ 2 ].xword); - break; - - case 23 : /* sin:function(x:real):real */ - param[ 1 ].xreal = (real)sin((double) param[ 0 ].xreal); - break; - - case 24 : /* cos:function(x:real):real */ - param[ 1 ].xreal = (real)cos((double) param[ 0 ].xreal); - break; - - case 25 : /* tan:function(x:real):real */ - r = cos((double) param[ 0 ].xreal); - if (r == 0.0) errsignal(RTEDIVBZ); - param[ 1 ].xreal = (real)sin((double) param[ 0 ].xreal) / r; - break; - - case 26 : /* exp:function(x:real):real */ - param[ 1 ].xreal = (real)exp((double) param[ 0 ].xreal); - break; - - case 27 : /* ln:function(x:real):real */ - param[ 1 ].xreal = (real)log((double) param[ 0 ].xreal); - break; - - case 28 : /* atan:function(x:real):real */ - param[ 1 ].xreal = (real)atan((double) param[ 0 ].xreal); - break; - - case 29 : /* endrun:procedure */ + /* imin:function(x, y:integer):integer */ + case 19: + param[2].xword = min(param[0].xword, param[1].xword); + break; + /* imax:function(x, y:integer):integer */ + case 20: + param[2].xword = max(param[0].xword, param[1].xword); + break; + /* imin3:function(x, y, z:integer):integer */ + case 21: + t1 = min(param[0].xword, param[1].xword); + param[3].xword = min(t1, param[2].xword); + break; + /* imax3:function(x, y, z:integer):integer */ + case 22: + t1 = max(param[0].xword, param[1].xword); + param[3].xword = max(t1, param[2].xword); + break; + /* sin:function(x:real):real */ + case 23: + param[1].xreal = (real)sin((double) param[0].xreal); + break; + /* cos:function(x:real):real */ + case 24: + param[1].xreal = (real)cos((double) param[0].xreal); + break; + /* tan:function(x:real):real */ + case 25: + r = cos((double) param[0].xreal); + if (r == 0.0) + errsignal(RTEDIVBZ); + param[1].xreal = (real)sin((double) param[0].xreal) / r; + break; + /* exp:function(x:real):real */ + case 26: + param[1].xreal = (real)exp((double) param[0].xreal); + break; + /* ln:function(x:real):real */ + case 27: + param[1].xreal = (real)log((double) param[0].xreal); + break; + /* atan:function(x:real):real */ + case 28: + param[1].xreal = (real)atan((double) param[0].xreal); + break; + /* endrun:procedure */ + case 29: endrun(0); break; - - case 30 : /* ranset:procedure(x:real) */ + /* ranset:procedure(x:real) */ + case 30: ranset(); break; - - case 31 : /* clock */ - case 32 : /* option */ - case 33 : /* lock */ - case 34 : /* unlock */ - case 35 : /* sched, boy! */ - case 36 : /* date */ - case 37 : /* execpar */ - case 38 : /* test&set */ + /* clock */ + case 31: + /* option */ + case 32: + /* lock */ + case 33: + /* unlock */ + case 34: + /* sched, boy! */ + case 35: + /* date */ + case 36: + /* execpar */ + case 37: + /* test&set */ + case 38: absent = TRUE; break; - - case 39 : /* eof */ - param[ 0 ].xbool = lbool(testeof(stdin)); + /* eof */ + case 39: + param[0].xbool = lbool(testeof(stdin)); break; - - case 40 : /* eof(f) */ + /* eof(f) */ + case 40: loadfile((word) UNKNOWN, &t1, &t2, &fp); - t3 = M[ t2+FSTAT ]; + t3 = M[t2 + FSTAT]; if (t3 == READING || t3 == UPDATING) - param[ 0 ].xbool = lbool(testeof(fp)); - else errsignal(RTEILLIO); + param[0].xbool = lbool(testeof(fp)); + else + errsignal(RTEILLIO); break; - - case 41 : /* readln */ + /* readln */ + case 41: readln(stdin); break; - - case 42 : /* readln(f) */ + /* readln(f) */ + case 42: loadfile((word) READING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); + if (t1 != TEXTF) + errsignal(RTEILLIO); readln(fp); break; - - case 43 : /* readchar */ - param[ 0 ].xword = read_char(); + /* readchar */ + case 43: + param[0].xword = read_char(); break; - - case 44 : /* readchar(f) */ + /* readchar(f) */ + case 44: loadfile((word) READING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - if ((ch = getc(fp)) == EOF) errsignal(RTEIOERR); - param[ 0 ].xword = ch; + if (t1 != TEXTF) + errsignal(RTEILLIO); + if ((ch = getc(fp)) == EOF) + errsignal(RTEIOERR); + param[0].xword = ch; + break; + /* readint */ + case 45: + read_str(s); + param[0].xword = atoi(s); break; - - case 45 : /* readint */ - read_str(s); - param[ 0 ].xword = atoi(s); - break; - case 46 : /* readint(f) */ + case 46: /* readint(f) */ loadfile((word) READING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - param[ 0 ].xword = readint(fp); + if (t1 != TEXTF) + errsignal(RTEILLIO); + param[0].xword = readint(fp); break; - - case 47 : /* readreal */ - read_str(s); - param[ 0 ].xreal = (real)atof(s); + /* readreal */ + case 47: + read_str(s); + param[0].xreal = (real)atof(s); break; - - case 48 : /* readreal(f) */ + /* readreal(f) */ + case 48: loadfile((word) READING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - param[ 0 ].xreal = (real)readreal(fp); + if (t1 != TEXTF) + errsignal(RTEILLIO); + param[0].xreal = (real)readreal(fp); break; - - case 49 : /* getchar(f) */ + /* getchar(f) */ + case 49: loadfile((word) READING, &t1, &t2, &fp); - if (t1 != CHARF) errsignal(RTEILLIO); - if ((ch = getc(fp)) == EOF) errsignal(RTEIOERR); - param[ 0 ].xword = ch; - break; - - case 50 : /* getint(f) */ + if (t1 != CHARF) + errsignal(RTEILLIO); + if ((ch = getc(fp)) == EOF) + errsignal(RTEIOERR); + param[0].xword = ch; + break; + /* getint(f) */ + case 50: loadfile((word) READING, &t1, &t2, &fp); - if (t1 != INTF) errsignal(RTEILLIO); + if (t1 != INTF) + errsignal(RTEILLIO); n = fread((char *) ¶m[ 0 ].xword, sizeof(word), 1, fp); - if (n != 1) errsignal(RTEIOERR); + if (n != 1) + errsignal(RTEIOERR); break; - - case 51 : /* getreal(f) */ + /* getreal(f) */ + case 51: loadfile((word) READING, &t1, &t2, &fp); - if (t1 != REALF) errsignal(RTEILLIO); - n = fread((char *) ¶m[ 0 ].xreal, sizeof(real), 1, fp); - if (n != 1) errsignal(RTEIOERR); - break; - - case 52 : /* getobject(f) */ + if (t1 != REALF) + errsignal(RTEILLIO); + n = fread((char *) ¶m[0].xreal, sizeof(real), 1, fp); + if (n != 1) + errsignal(RTEIOERR); + break; + /* getobject(f) */ + case 52: absent = TRUE; break; - - case 53 : /* putchar(f) */ + /* putchar(f) */ + case 53: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != CHARF) errsignal(RTEILLIO); + if (t1 != CHARF) + errsignal(RTEILLIO); ch = (char) param[ 0 ].xword; - if (putc(ch, fp) == EOF) errsignal(RTEIOERR); + if (putc(ch, fp) == EOF) + errsignal(RTEIOERR); break; - - case 54 : /* putint(f) */ + /* putint(f) */ + case 54: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != INTF) errsignal(RTEILLIO); + if (t1 != INTF) + errsignal(RTEILLIO); n = fwrite((char *) ¶m[ 0 ].xword, sizeof(word), 1, fp); - if (n != 1) errsignal(RTEIOERR); + if (n != 1) + errsignal(RTEIOERR); break; - - case 55 : /* putreal(f) */ + /* putreal(f) */ + case 55: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != REALF) errsignal(RTEILLIO); + if (t1 != REALF) + errsignal(RTEILLIO); n = fwrite((char *) ¶m[ 0 ].xreal, sizeof(real), 1, fp); - if (n != 1) errsignal(RTEIOERR); + if (n != 1) + errsignal(RTEIOERR); break; - - case 56 : /* putobject(f) */ - case 57 : /* putstring(f) */ + /* putobject(f) */ + case 56: + /* putstring(f) */ + case 57: absent = TRUE; break; - - case 58 : /* writeln(f) */ + /* writeln(f) */ + case 58: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - if (putc('\n', fp) == EOF) errsignal(RTEIOERR); - if (fflush(fp)) errsignal(RTEIOERR); - break; - - case 59 : /* writeln */ + if (t1 != TEXTF) + errsignal(RTEILLIO); + if (putc('\n', fp) == EOF) + errsignal(RTEIOERR); + if (fflush(fp)) + errsignal(RTEIOERR); + break; + /* writeln */ + case 59: write_str("\n"); break; - - case 60 : /* writechar(f) */ + /* writechar(f) */ + case 60: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - if (putc((char) param[ 0 ].xword, fp) == EOF) - errsignal(RTEIOERR); + if (t1 != TEXTF) + errsignal(RTEILLIO); + if (putc((char) param[0].xword, fp) == EOF) + errsignal(RTEIOERR); break; - - case 61 : /* writechar */ - write_char((char) param[ 0 ].xword); + /* writechar */ + case 61: + write_char((char) param[0].xword); break; - - case 62 : /* writeint(f) */ + /* writeint(f) */ + case 62: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - writeint(param[ 0 ].xword, param[ 1 ].xword, fp); - break; - - case 63 : /* writeint */ - writeint(param[ 0 ].xword, param[ 1 ].xword, stdout); - break; - - case 64 : /* writereal0(f) */ - case 66 : /* writereal1(f) */ - case 68 : /* writereal2(f) */ + if (t1 != TEXTF) + errsignal(RTEILLIO); + writeint(param[0].xword, param[1].xword, fp); + break; + /* writeint */ + case 63: + writeint(param[0].xword, param[1].xword, stdout); + break; + /* writereal0(f) */ + case 64: + /* writereal1(f) */ + case 66: + /* writereal2(f) */ + case 68: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - writereal((double) param[ 0 ].xreal, param[ 1 ].xword, - param[ 2 ].xword, fp); - break; - - case 65 : /* writereal0 */ - case 67 : /* writereal1 */ - case 69 : /* writereal2 */ - writereal((double) param[ 0 ].xreal, param[ 1 ].xword, - param[ 2 ].xword, stdout); - break; - - case 70 : /* writestring(f) */ + if (t1 != TEXTF) + errsignal(RTEILLIO); + writereal((double) param[0].xreal, param[1].xword, + param[2].xword, fp); + break; + /* writereal0 */ + case 65: + /* writereal1 */ + case 67: + /* writereal2 */ + case 69: + writereal((double) param[0].xreal, param[1].xword, + param[2].xword, stdout); + break; + /* writestring(f) */ + case 70: loadfile((word) WRITING, &t1, &t2, &fp); - if (t1 != TEXTF) errsignal(RTEILLIO); - writestring(param[ 0 ].xword, param[ 1 ].xword, fp); - break; - - case 71 : /* writestring */ - writestring(param[ 0 ].xword, param[ 1 ].xword, stdout); - break; - - case 72 : /* open temporary file */ - genfileobj(TRUE , param[ 1 ].xword, tempfilename(), - ¶m[ 0 ].xvirt, &t1); - break; - - case 73 : /* open external file */ - genfileobj(FALSE, param[ 1 ].xword, asciiz(¶m[ 2 ].xvirt), - ¶m[ 0 ].xvirt, &t1); - break; - - case 74 : /* eoln */ - param[ 0 ].xbool = lbool(testeoln(stdin)); - break; - - case 75 : /* eoln(f) */ + if (t1 != TEXTF) + errsignal(RTEILLIO); + writestring(param[0].xword, param[1].xword, fp); + break; + /* writestring */ + case 71: + writestring(param[0].xword, param[1].xword, stdout); + break; + /* open temporary file */ + case 72: + genfileobj(TRUE, param[1].xword, tempfilename(), + ¶m[0].xvirt, &t1); + break; + /* open external file */ + case 73: + genfileobj(FALSE, param[1].xword, asciiz(¶m[2].xvirt), + ¶m[0].xvirt, &t1); + break; + /* eoln */ + case 74: + param[0].xbool = lbool(testeoln(stdin)); + break; + /* eoln(f) */ + case 75: loadfile((word) READING, &t1, &t2, &fp); if (t1 != TEXTF) errsignal(RTEILLIO); - param[ 0 ].xbool = lbool(testeoln(fp)); - break; - - case 76 : /* this coroutine */ - loadvirt(param[ 0 ].xvirt, - thisp->prochead+M[ thisp->prochead ]+CHD); - break; - - case 77 : /* this process */ - { - procaddr p; - virtaddr v; - p.node = ournode; - p.pix = thispix; - p.mark = thisp->mark; - mess2obj( thisp, &p, &v ); - param[ 0 ].xvirt = v; - } - break; - - case 78 : /* reset:procedure(f:file) */ - if (member(¶m[ 0 ].xvirt, &t2)) - reset(t2); - else errsignal(RTEREFTN); + param[0].xbool = lbool(testeoln(fp)); break; - - case 79 : /* rewrite:procedure(f:file) */ - if (member(¶m[ 0 ].xvirt, &t2)) - rewrite(t2); - else errsignal(RTEREFTN); + /* this coroutine */ + case 76: + loadvirt(param[0].xvirt, + thisp->prochead + M[thisp->prochead] + CHD); break; - - case 80 : /* unlink:procedure(f:file) */ - delete(¶m[ 0 ].xvirt); + /* this process */ + case 77: + { + procaddr p; + virtaddr v; + p.node = ournode; + p.pix = thispix; + p.mark = thisp->mark; + mess2obj(thisp, &p, &v); + param[0].xvirt = v; + } break; - - case 81 : /* seek:procedure(f:file, offset, base:integer) */ - storevirt(param[ 0 ].xvirt, currfile); + /* reset:procedure(f:file) */ + case 78: + if (member(¶m[0].xvirt, &t2)) + reset(t2); + else + errsignal(RTEREFTN); + break; + /* rewrite:procedure(f:file) */ + case 79: + if (member(¶m[0].xvirt, &t2)) + rewrite(t2); + else + errsignal(RTEREFTN); + break; + /* unlink:procedure(f:file) */ + case 80: + delete(¶m[0].xvirt); + break; + /* seek:procedure(f:file, offset, base:integer) */ + case 81: + storevirt(param[0].xvirt, currfile); loadfile((word) UPDATING, &t1, &t2, &fp); - if (t1 != DIRECT) errsignal(RTEILLIO); - if (fseek(fp, (long) param[ 1 ].xword, (int) param[ 2 ].xword)) - errsignal(RTEIOERR); + if (t1 != DIRECT) + errsignal(RTEILLIO); + if (fseek(fp, (long) param[1].xword, (int) param[2].xword)) + errsignal(RTEIOERR); break; - - case 82 : /* getrec(f, a, n) */ + /* getrec(f, a, n) */ + case 82: loadfile((word) UPDATING, &t1, &t2, &fp); - if (t1 != DIRECT) errsignal(RTEILLIO); - param[ 1 ].xword = directio( - ¶m[ 0 ].xvirt, - param[ 1 ].xword, - (int (*)())fread, - fp - ); + if (t1 != DIRECT) + errsignal(RTEILLIO); + param[1].xword = directio(¶m[0].xvirt, param[1].xword, + (int (*)())fread, fp); break; - - case 83 : /* putrec(f, a, n) */ + /* putrec(f, a, n) */ + case 83: loadfile((word) UPDATING, &t1, &t2, &fp); if (t1 != DIRECT) errsignal(RTEILLIO); - param[ 1 ].xword = directio( - ¶m[ 0 ].xvirt, - param[ 1 ].xword, - (int (*)())fwrite, - fp - ); + param[1].xword = directio(¶m[0].xvirt, param[1].xword, + (int (*)())fwrite, fp); break; - - case 84 : /* position:function(f:file):real */ - storevirt(param[ 0 ].xvirt, currfile); + /* position:function(f:file):real */ + case 84: + storevirt(param[0].xvirt, currfile); loadfile((word) UPDATING, &t1, &t2, &fp); - if (t1 != DIRECT) errsignal(RTEILLIO); - param[ 1 ].xword =(int) ftell(fp); - break; - - case 98 : /* memavail:function:integer */ - param[ 0 ].xword = memavail(); - break; - - case 99 : /* exec:function(c:arrayof char):integer */ - cp = asciiz(¶m[ 0 ].xvirt); - param[ 1 ].xword = system(cp); + if (t1 != DIRECT) + errsignal(RTEILLIO); + param[1].xword =(int) ftell(fp); + break; + /* memavail:function:integer */ + case 98: + param[0].xword = memavail(); + break; + /* exec:function(c:arrayof char):integer */ + case 99: + cp = asciiz(¶m[0].xvirt); + param[1].xword = system(cp); free(cp); break; - default : + default: nonstandard(nrproc); break; - } -# if TRACE - fflush( stdout ); -# endif - if (absent) errsignal(RTEUNSTP); + } +#if TRACE + fflush(stdout); +#endif + if (absent) + errsignal(RTEUNSTP); } -