From: Rafał Długołęcki Date: Sun, 21 Jul 2013 20:10:34 +0000 (+0200) Subject: vlp-10 using coding style in util.c X-Git-Tag: 3.1~26 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=5b51cebeb8fb6e9b8c3c9bba009a4dc01a7901b1;p=vlp.git vlp-10 using coding style in util.c --- diff --git a/src/int/util.c b/src/int/util.c index f272016..96d6885 100644 --- a/src/int/util.c +++ b/src/int/util.c @@ -44,19 +44,19 @@ or Andrzej Salwicki */ word entier(double x) { - word i; - - if (x >= 0.0) - { - i = (word)x; - return(i); - } - else - { - i = (word)(-x); - i = -i; - if ((double)i <= x) return(i); else return(i-1); - } + word i; + + if (x >= 0.0) { + i = (word)x; + return i; + } else { + i = (word)(-x); + i = -i; + if ((double)i <= x) + return i; + else + return i - 1; + } } /** @@ -64,9 +64,12 @@ word entier(double x) */ word shift(word x, word n) { - if (n == 0) return (x); - if (n > 0) return (x << n); - else return ( (x >> -n) & ~(~(word)0 << (8*sizeof(word)+n)) ); + if (n == 0) + return (x); + if (n > 0) + return (x << n); + else + return ((x >> -n) & ~(~(word)0 << (8 * sizeof(word) + n))); } @@ -75,20 +78,30 @@ word shift(word x, word n) */ char *asciiz(virtaddr *virt) { - word am; - int len, i; - char *cp; - - if (member(virt, &am)) - { - len = M[ am ]-3; /* length of the string */ - cp = ballocate(len+1); /* allocate buffer for the string */ - if (cp == NULL) errsignal(RTEMEMOV); - for (i = 0; i < len; i++) cp[ i ] = (char) M[ am+3+i ]; - cp[ len ] = '\0'; /* terminate string with 0 byte */ - return (cp); - } - else errsignal(RTEREFTN); /* reference to none */ + word am; + int len, i; + char *cp; + + if (member(virt, &am)) { + /* length of the string */ + len = M[am] - 3; + /* allocate buffer for the string */ + cp = ballocate(len + 1); + + if (cp == NULL) + errsignal(RTEMEMOV); + + for (i = 0; i < len; i++) + cp[i] = (char) M[am + 3 + i]; + + /* terminate string with 0 byte */ + cp[len] = '\0'; + return cp; + } + else { + /* reference to none */ + errsignal(RTEREFTN); + } } /** @@ -96,11 +109,12 @@ char *asciiz(virtaddr *virt) */ void addext(char *fname, char *ext) { - char *cp; + char *cp; - cp = fname; - while (*cp != '\0' && *cp != '.') cp++; - strcpy(cp, ext); + cp = fname; + while (*cp != '\0' && *cp != '.') + cp++; + strcpy(cp, ext); } void usage() @@ -112,9 +126,9 @@ void usage() */ void abend(char *msg) { - fprintf(stderr, "Error: %s\n", msg); - exit(8); -} /* end abend */ + fprintf(stderr, "Error: %s\n", msg); + exit(8); +} /* Pseudo random number generator */ @@ -126,12 +140,12 @@ static int ranpat1 = 7, ranpat2 = 503, ranpat3 = 15661; */ void ranset() { - long tim; + long tim; - time(&tim); - ranpat1 = tim % 30269; - ranpat2 = tim % 30307; - ranpat3 = tim % 30323; + time(&tim); + ranpat1 = tim % 30269; + ranpat2 = tim % 30307; + ranpat3 = tim % 30323; } /** @@ -139,18 +153,26 @@ void ranset() */ double prandom() { - int i; - double r; - - ranpat1 = 171*(ranpat1 % 177)- 2*(ranpat1 / 177); - if (ranpat1 < 0) ranpat1 += 30269; - ranpat2 = 172*(ranpat2 % 176)-35*(ranpat2 / 176); - if (ranpat2 < 0) ranpat2 += 30307; - ranpat3 = 170*(ranpat3 % 178)-63*(ranpat3 / 178); - if (ranpat3 < 0) ranpat3 += 30323; - r = ranpat1/30269.0 + ranpat2/30307.0 + ranpat3/30323.0; - i = (int)r; - return (r-i); + int i; + double r; + + ranpat1 = 171 * (ranpat1 % 177) - 2 * (ranpat1 / 177); + if (ranpat1 < 0) + ranpat1 += 30269; + + ranpat2 = 172 * (ranpat2 % 176) - 35 * (ranpat2 / 176); + + if (ranpat2 < 0) + ranpat2 += 30307; + + ranpat3 = 170 * (ranpat3 % 178) - 63 * (ranpat3 / 178); + + if (ranpat3 < 0) + ranpat3 += 30323; + + r = ranpat1 / 30269.0 + ranpat2 / 30307.0 + ranpat3 / 30323.0; + i = (int)r; + return r - i; } /** @@ -165,23 +187,20 @@ void moveblock(char *from, char *to, word len) /************************************************************** -#define LINE 10 -void dump(pix, from, len) -word pix, from; -int len; +#define LINE 10 +void dump(word pix, word from, int len) { - int i; - memory M; - - M = process[ pix ].M; - while (len > 0) - { - printf("%6ld: ", (long) from); - for (i = 0; i < LINE; i++) printf("%7ld", (long)M[from++]); - putchar('\n'); - len -= LINE; - } + int i; + memory M; + + M = process[pix].M; + while (len > 0) { + printf("%6ld: ", (long) from); + for (i = 0; i < LINE; i++) + printf("%7ld", (long)M[from++]); + putchar('\n'); + len -= LINE; + } } - **************************************************************/