From owner-svn-src-all@FreeBSD.ORG Wed Feb 3 21:06:14 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 117B11065670; Wed, 3 Feb 2010 21:06:14 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0079C8FC0A; Wed, 3 Feb 2010 21:06:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o13L6ENc007913; Wed, 3 Feb 2010 21:06:14 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o13L6DZ8007906; Wed, 3 Feb 2010 21:06:13 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201002032106.o13L6DZ8007906@svn.freebsd.org> From: Gabor Kovesdan Date: Wed, 3 Feb 2010 21:06:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203443 - in head/usr.bin: bc dc X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2010 21:06:14 -0000 Author: gabor Date: Wed Feb 3 21:06:13 2010 New Revision: 203443 URL: http://svn.freebsd.org/changeset/base/203443 Log: - style(9) Approved by: delphij (mentor) Modified: head/usr.bin/bc/bc.y head/usr.bin/bc/scan.l head/usr.bin/dc/bcode.c head/usr.bin/dc/bcode.h head/usr.bin/dc/dc.c head/usr.bin/dc/inout.c head/usr.bin/dc/mem.c head/usr.bin/dc/stack.c Modified: head/usr.bin/bc/bc.y ============================================================================== --- head/usr.bin/bc/bc.y Wed Feb 3 20:54:04 2010 (r203442) +++ head/usr.bin/bc/bc.y Wed Feb 3 21:06:13 2010 (r203443) @@ -60,11 +60,11 @@ extern char *yytext; extern FILE *yyin; struct tree { - ssize_t index; union { char *astr; const char *cstr; } u; + ssize_t index; }; int yyparse(void); @@ -143,10 +143,10 @@ const struct option long_options[] = %start program %union { - ssize_t node; struct lvalue lvalue; const char *str; char *astr; + ssize_t node; } %token COMMA SEMICOLON LPAR RPAR LBRACE RBRACE LBRACKET RBRACKET DOT @@ -299,7 +299,7 @@ statement : expression } | QUIT { - sigset_t mask; + sigset_t mask; putchar('q'); fflush(stdout); @@ -321,7 +321,7 @@ statement : expression opt_relational_expression SEMICOLON opt_expression RPAR opt_statement pop_nesting { - ssize_t n; + ssize_t n; if (st_has_continue) n = node($10, cs("M"), $8, cs("s."), @@ -351,7 +351,7 @@ statement : expression | WHILE LPAR alloc_macro relational_expression RPAR opt_statement pop_nesting { - ssize_t n; + ssize_t n; if (st_has_continue) n = node($6, cs("M"), $4, $3, END_NODE); @@ -766,8 +766,8 @@ print_expression static void grow(void) { - struct tree *p; - size_t newsize; + struct tree *p; + size_t newsize; if (current == instr_sz) { newsize = instr_sz * 2 + 1; @@ -784,6 +784,7 @@ grow(void) static ssize_t cs(const char *str) { + grow(); instructions[current].index = CONST_STRING; instructions[current].u.cstr = str; @@ -793,6 +794,7 @@ cs(const char *str) static ssize_t as(const char *str) { + grow(); instructions[current].index = ALLOC_STRING; instructions[current].u.astr = strdup(str); @@ -804,8 +806,8 @@ as(const char *str) static ssize_t node(ssize_t arg, ...) { - va_list ap; - ssize_t ret; + va_list ap; + ssize_t ret; va_start(ap, arg); @@ -826,6 +828,7 @@ node(ssize_t arg, ...) static void emit(ssize_t i) { + if (instructions[i].index >= 0) while (instructions[i].index != END_NODE) emit(instructions[i++].index); @@ -836,6 +839,7 @@ emit(ssize_t i) static void emit_macro(int nodeidx, ssize_t code) { + putchar('['); emit(code); printf("]s%s\n", instructions[nodeidx].u.cstr); @@ -845,7 +849,7 @@ emit_macro(int nodeidx, ssize_t code) static void free_tree(void) { - ssize_t i; + ssize_t i; for (i = 0; i < current; i++) if (instructions[i].index == ALLOC_STRING) @@ -856,7 +860,7 @@ free_tree(void) static ssize_t numnode(int num) { - const char *p; + const char *p; if (num < 10) p = str_table['0' + num]; @@ -871,9 +875,9 @@ numnode(int num) static ssize_t lookup(char * str, size_t len, char type) { - ENTRY entry, *found; - u_short num; - u_char *p; + ENTRY entry, *found; + u_char *p; + u_short num; /* The scanner allocated an extra byte already */ if (str[len-1] != type) { @@ -908,7 +912,7 @@ lookup(char * str, size_t len, char type static ssize_t letter_node(char *str) { - size_t len; + size_t len; len = strlen(str); if (len == 1 && str[0] != '_') @@ -920,7 +924,7 @@ letter_node(char *str) static ssize_t array_node(char *str) { - size_t len; + size_t len; len = strlen(str); if (len == 1 && str[0] != '_') @@ -932,7 +936,7 @@ array_node(char *str) static ssize_t function_node(char *str) { - size_t len; + size_t len; len = strlen(str); if (len == 1 && str[0] != '_') @@ -944,6 +948,7 @@ function_node(char *str) static void add_par(ssize_t n) { + prologue = node(cs("S"), n, prologue, END_NODE); epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE); } @@ -951,6 +956,7 @@ add_par(ssize_t n) static void add_local(ssize_t n) { + prologue = node(cs("0S"), n, prologue, END_NODE); epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE); } @@ -958,8 +964,8 @@ add_local(ssize_t n) void yyerror(const char *s) { - char *str, *p; - int n; + char *p, *str; + int n; if (yyin != NULL && feof(yyin)) n = asprintf(&str, "%s: %s:%d: %s: unexpected EOF", @@ -987,19 +993,21 @@ yyerror(const char *s) void fatal(const char *s) { + errx(1, "%s:%d: %s", filename, lineno, s); } static void warning(const char *s) { + warnx("%s:%d: %s", filename, lineno, s); } static void init(void) { - unsigned int i; + unsigned int i; for (i = 0; i < UCHAR_MAX; i++) { str_table[i][0] = i; @@ -1013,6 +1021,7 @@ init(void) static void usage(void) { + fprintf(stderr, "usage: %s [-chlqv] [-e expression] [file ...]\n", __progname); exit(1); @@ -1021,7 +1030,7 @@ usage(void) static char * escape(const char *str) { - char *ret, *p; + char *p, *ret; ret = malloc(strlen(str) + 1); if (ret == NULL) @@ -1077,8 +1086,8 @@ escape(const char *str) void sigchld(int signo) { - pid_t pid; - int status; + pid_t pid; + int status; switch (signo) { default: @@ -1100,9 +1109,9 @@ sigchld(int signo) int main(int argc, char *argv[]) { - int i, ch; - int p[2]; - char *q; + char *q; + int p[2]; + int ch, i; init(); setlinebuf(stdout); Modified: head/usr.bin/bc/scan.l ============================================================================== --- head/usr.bin/bc/scan.l Wed Feb 3 20:54:04 2010 (r203442) +++ head/usr.bin/bc/scan.l Wed Feb 3 21:06:13 2010 (r203443) @@ -193,6 +193,7 @@ ALPHANUM [a-z_0-9] static void init_strbuf(void) { + if (strbuf == NULL) { strbuf = malloc(strbuf_sz); if (strbuf == NULL) @@ -204,7 +205,7 @@ init_strbuf(void) static void add_str(const char *str) { - size_t arglen; + size_t arglen; arglen = strlen(str); @@ -228,8 +229,8 @@ add_str(const char *str) void abort_line(int sig) { - static const char str[] = "[\n]P\n"; - int save_errno; + static const char str[] = "[\n]P\n"; + int save_errno; switch (sig) { default: @@ -243,8 +244,8 @@ abort_line(int sig) int yywrap(void) { - static int state; - static YY_BUFFER_STATE buf; + static YY_BUFFER_STATE buf; + static int state; if (fileindex == 0 && sargc > 0 && strcmp(sargv[0], _PATH_LIBB) == 0) { filename = sargv[fileindex++]; @@ -285,4 +286,3 @@ yywrap(void) } return (1); } - Modified: head/usr.bin/dc/bcode.c ============================================================================== --- head/usr.bin/dc/bcode.c Wed Feb 3 20:54:04 2010 (r203442) +++ head/usr.bin/dc/bcode.c Wed Feb 3 21:06:13 2010 (r203443) @@ -41,17 +41,17 @@ BIGNUM zero; #define REG_ARRAY_SIZE_BIG (UCHAR_MAX + 1 + USHRT_MAX + 1) struct bmachine { + struct source *readstack; + struct stack *reg; struct stack stack; + volatile sig_atomic_t interrupted; u_int scale; u_int obase; u_int ibase; size_t readsp; - bool extended_regs; size_t reg_array_size; - struct stack *reg; - volatile sig_atomic_t interrupted; - struct source *readstack; size_t readstack_sz; + bool extended_regs; }; static struct bmachine bmachine; @@ -236,7 +236,7 @@ sighandler(int ignored) void init_bmachine(bool extended_registers) { - unsigned int i; + unsigned int i; bmachine.extended_regs = extended_registers; bmachine.reg_array_size = bmachine.extended_regs ? @@ -280,7 +280,7 @@ reset_bmachine(struct source *src) static __inline int readch(void) { - struct source *src = &bmachine.readstack[bmachine.readsp]; + struct source *src = &bmachine.readstack[bmachine.readsp]; return (src->vtable->readchar(src)); } @@ -288,7 +288,7 @@ readch(void) static __inline void unreadch(void) { - struct source *src = &bmachine.readstack[bmachine.readsp]; + struct source *src = &bmachine.readstack[bmachine.readsp]; src->vtable->unreadchar(src); } @@ -296,7 +296,7 @@ unreadch(void) static __inline char * readline(void) { - struct source *src = &bmachine.readstack[bmachine.readsp]; + struct source *src = &bmachine.readstack[bmachine.readsp]; return (src->vtable->readline(src)); } @@ -304,7 +304,7 @@ readline(void) static __inline void src_free(void) { - struct source *src = &bmachine.readstack[bmachine.readsp]; + struct source *src = &bmachine.readstack[bmachine.readsp]; src->vtable->free(src); } @@ -313,7 +313,7 @@ src_free(void) void pn(const char *str, const struct number *n) { - char *p = BN_bn2dec(n->number); + char *p = BN_bn2dec(n->number); if (p == NULL) err(1, "BN_bn2dec failed"); @@ -325,7 +325,7 @@ pn(const char *str, const struct number void pbn(const char *str, const BIGNUM *n) { - char *p = BN_bn2dec(n); + char *p = BN_bn2dec(n); if (p == NULL) err(1, "BN_bn2dec failed"); @@ -351,7 +351,7 @@ static unsigned long factors[] = { void scale_number(BIGNUM *n, int s) { - unsigned int abs_scale; + unsigned int abs_scale; if (s == 0) return; @@ -364,8 +364,8 @@ scale_number(BIGNUM *n, int s) else BN_div_word(n, factors[abs_scale]); } else { - BIGNUM *a, *p; - BN_CTX *ctx; + BIGNUM *a, *p; + BN_CTX *ctx; a = BN_new(); bn_checkp(a); @@ -390,7 +390,7 @@ scale_number(BIGNUM *n, int s) void split_number(const struct number *n, BIGNUM *i, BIGNUM *f) { - u_long rem; + u_long rem; bn_checkp(BN_copy(i, n->number)); @@ -510,7 +510,7 @@ print_stack(void) static __inline void print_tos(void) { - struct value *value = tos(); + struct value *value = tos(); if (value != NULL) { print_value(stdout, value, "", bmachine.obase); @@ -523,7 +523,7 @@ print_tos(void) static void pop_print(void) { - struct value *value = pop(); + struct value *value = pop(); if (value != NULL) { switch (value->type) { @@ -546,7 +546,7 @@ pop_print(void) static void pop_printn(void) { - struct value *value = pop(); + struct value *value = pop(); if (value != NULL) { print_value(stdout, value, "", bmachine.obase); @@ -572,7 +572,7 @@ swap(void) static void drop(void) { - struct value *v = pop(); + struct value *v = pop(); if (v != NULL) stack_free_value(v); } @@ -580,7 +580,7 @@ drop(void) static void get_scale(void) { - struct number *n; + struct number *n; n = new_number(); bn_check(BN_set_word(n->number, bmachine.scale)); @@ -590,8 +590,8 @@ get_scale(void) static void set_scale(void) { - struct number *n; - u_long scale; + struct number *n; + u_long scale; n = pop_number(); if (n != NULL) { @@ -611,7 +611,7 @@ set_scale(void) static void get_obase(void) { - struct number *n; + struct number *n; n = new_number(); bn_check(BN_set_word(n->number, bmachine.obase)); @@ -621,8 +621,8 @@ get_obase(void) static void set_obase(void) { - struct number *n; - u_long base; + struct number *n; + u_long base; n = pop_number(); if (n != NULL) { @@ -638,7 +638,7 @@ set_obase(void) static void get_ibase(void) { - struct number *n; + struct number *n; n = new_number(); bn_check(BN_set_word(n->number, bmachine.ibase)); @@ -648,8 +648,8 @@ get_ibase(void) static void set_ibase(void) { - struct number *n; - u_long base; + struct number *n; + u_long base; n = pop_number(); if (n != NULL) { @@ -666,8 +666,8 @@ set_ibase(void) static void stackdepth(void) { - size_t i; - struct number *n; + struct number *n; + size_t i; i = stack_size(&bmachine.stack); n = new_number(); @@ -678,10 +678,9 @@ stackdepth(void) static void push_scale(void) { - struct value *value; - u_int scale = 0; - struct number *n; - + struct number *n; + struct value *value; + u_int scale = 0; value = pop(); if (value != NULL) { @@ -704,8 +703,8 @@ push_scale(void) static u_int count_digits(const struct number *n) { - struct number *int_part, *fract_part; - u_int i; + struct number *int_part, *fract_part; + u_int i; if (BN_is_zero(n->number)) return (1); @@ -728,9 +727,9 @@ count_digits(const struct number *n) static void num_digits(void) { - struct value *value; - size_t digits; - struct number *n = NULL; + struct number *n = NULL; + struct value *value; + size_t digits; value = pop(); if (value != NULL) { @@ -756,9 +755,9 @@ num_digits(void) static void to_ascii(void) { - char str[2]; - struct value *value; - struct number *n; + struct number *n; + struct value *value; + char str[2]; value = pop(); if (value != NULL) { @@ -785,7 +784,7 @@ to_ascii(void) static int readreg(void) { - int idx, ch1, ch2; + int ch1, ch2, idx; idx = readch(); if (idx == 0xff && bmachine.extended_regs) { @@ -807,9 +806,10 @@ readreg(void) static void load(void) { - int idx; - struct value *v, copy; - struct number *n; + struct number *n; + struct value *v; + struct value copy; + int idx; idx = readreg(); if (idx >= 0) { @@ -826,8 +826,8 @@ load(void) static void store(void) { - int idx; - struct value *val; + struct value *val; + int idx; idx = readreg(); if (idx >= 0) { @@ -842,9 +842,9 @@ store(void) static void load_stack(void) { - int idx; - struct stack *stack; - struct value *value; + struct stack *stack; + struct value *value; + int idx; idx = readreg(); if (idx >= 0) { @@ -864,8 +864,8 @@ load_stack(void) static void store_stack(void) { - int idx; - struct value *value; + struct value *value; + int idx; idx = readreg(); if (idx >= 0) { @@ -879,11 +879,12 @@ store_stack(void) static void load_array(void) { - int reg; - struct number *inumber, *n; - u_long idx; - struct stack *stack; - struct value *v, copy; + struct number *inumber, *n; + struct stack *stack; + struct value *v; + struct value copy; + u_long idx; + int reg; reg = readreg(); if (reg >= 0) { @@ -913,11 +914,11 @@ load_array(void) static void store_array(void) { - int reg; - struct number *inumber; - u_long idx; - struct value *value; - struct stack *stack; + struct number *inumber; + struct value *value; + struct stack *stack; + u_long idx; + int reg; reg = readreg(); if (reg >= 0) { @@ -969,8 +970,7 @@ bexec(char *line) static void badd(void) { - struct number *a, *b; - struct number *r; + struct number *a, *b, *r; a = pop_number(); if (a == NULL) { @@ -997,8 +997,7 @@ badd(void) static void bsub(void) { - struct number *a, *b; - struct number *r; + struct number *a, *b, *r; a = pop_number(); if (a == NULL) { @@ -1026,7 +1025,7 @@ bsub(void) void bmul_number(struct number *r, struct number *a, struct number *b) { - BN_CTX *ctx; + BN_CTX *ctx; /* Create copies of the scales, since r might be equal to a or b */ u_int ascale = a->scale; @@ -1048,8 +1047,7 @@ bmul_number(struct number *r, struct num static void bmul(void) { - struct number *a, *b; - struct number *r; + struct number *a, *b, *r; a = pop_number(); if (a == NULL) { @@ -1072,10 +1070,9 @@ bmul(void) static void bdiv(void) { - struct number *a, *b; - struct number *r; - u_int scale; - BN_CTX *ctx; + struct number *a, *b, *r; + BN_CTX *ctx; + u_int scale; a = pop_number(); if (a == NULL) { @@ -1110,10 +1107,9 @@ bdiv(void) static void bmod(void) { - struct number *a, *b; - struct number *r; - u_int scale; - BN_CTX *ctx; + struct number *a, *b, *r; + BN_CTX *ctx; + u_int scale; a = pop_number(); if (a == NULL) { @@ -1148,10 +1144,9 @@ bmod(void) static void bdivmod(void) { - struct number *a, *b; - struct number *rdiv, *rmod; - u_int scale; - BN_CTX *ctx; + struct number *a, *b, *rdiv, *rmod; + BN_CTX *ctx; + u_int scale; a = pop_number(); if (a == NULL) { @@ -1190,10 +1185,9 @@ bdivmod(void) static void bexp(void) { - struct number *a, *p; - struct number *r; - bool neg; - u_int scale; + struct number *a, *p, *r; + u_int scale; + bool neg; p = pop_number(); if (p == NULL) { @@ -1216,8 +1210,8 @@ bexp(void) scale = bmachine.scale; } else { /* Posix bc says min(a.scale * b, max(a.scale, scale) */ - u_long b; - u_int m; + u_long b; + u_int m; b = BN_get_word(p->number); m = max(a->scale, bmachine.scale); @@ -1249,8 +1243,8 @@ bexp(void) } if (neg) { - BN_CTX *ctx; - BIGNUM *one; + BN_CTX *ctx; + BIGNUM *one; one = BN_new(); bn_checkp(one); @@ -1273,8 +1267,8 @@ bexp(void) static bool bsqrt_stop(const BIGNUM *x, const BIGNUM *y, u_int *onecount) { - BIGNUM *r; - bool ret; + BIGNUM *r; + bool ret; r = BN_new(); bn_checkp(r); @@ -1289,11 +1283,10 @@ bsqrt_stop(const BIGNUM *x, const BIGNUM static void bsqrt(void) { - struct number *n; - struct number *r; - BIGNUM *x, *y; - u_int scale, onecount; - BN_CTX *ctx; + struct number *n, *r; + BIGNUM *x, *y; + BN_CTX *ctx; + u_int onecount, scale; onecount = 0; n = pop_number(); @@ -1337,7 +1330,7 @@ bsqrt(void) static void not(void) { - struct number *a; + struct number *a; a = pop_number(); if (a == NULL) { @@ -1358,7 +1351,7 @@ equal(void) static void equal_numbers(void) { - struct number *a, *b, *r; + struct number *a, *b, *r; a = pop_number(); if (a == NULL) { @@ -1378,7 +1371,7 @@ equal_numbers(void) static void less_numbers(void) { - struct number *a, *b, *r; + struct number *a, *b, *r; a = pop_number(); if (a == NULL) { @@ -1398,7 +1391,7 @@ less_numbers(void) static void lesseq_numbers(void) { - struct number *a, *b, *r; + struct number *a, *b, *r; a = pop_number(); if (a == NULL) { @@ -1432,6 +1425,7 @@ less(void) static void not_compare(void) { + switch (readch()) { case '<': not_less(); @@ -1473,8 +1467,8 @@ not_greater(void) static bool compare_numbers(enum bcode_compare type, struct number *a, struct number *b) { - u_int scale; - int cmp; + u_int scale; + int cmp; scale = max(a->scale, b->scale); @@ -1508,10 +1502,10 @@ compare_numbers(enum bcode_compare type, static void compare(enum bcode_compare type) { - int idx, elseidx; - struct number *a, *b; - bool ok; - struct value *v; + struct number *a, *b; + struct value *v; + int idx, elseidx; + bool ok; elseidx = NO_ELSE; idx = readreg(); @@ -1558,11 +1552,13 @@ compare(enum bcode_compare type) static void nop(void) { + } static void quit(void) { + if (bmachine.readsp < 2) exit(0); src_free(); @@ -1574,8 +1570,8 @@ quit(void) static void quitN(void) { - struct number *n; - u_long i; + struct number *n; + u_long i; n = pop_number(); if (n == NULL) @@ -1597,8 +1593,8 @@ quitN(void) static void skipN(void) { - struct number *n; - u_long i; + struct number *n; + u_long i; n = pop_number(); if (n == NULL) @@ -1687,7 +1683,7 @@ unknown(void) static void eval_string(char *p) { - int ch; + int ch; if (bmachine.readsp > 0) { /* Check for tail call. Do not recurse in that case. */ @@ -1716,8 +1712,8 @@ static void eval_line(void) { /* Always read from stdin */ - struct source in; - char *p; + struct source in; + char *p; clearerr(stdin); src_setstream(&in, stdin); @@ -1728,7 +1724,7 @@ eval_line(void) static void eval_tos(void) { - char *p; + char *p; p = pop_string(); if (p == NULL) @@ -1739,7 +1735,7 @@ eval_tos(void) void eval(void) { - int ch; + int ch; for (;;) { ch = readch(); Modified: head/usr.bin/dc/bcode.h ============================================================================== --- head/usr.bin/dc/bcode.h Wed Feb 3 20:54:04 2010 (r203442) +++ head/usr.bin/dc/bcode.h Wed Feb 3 21:06:13 2010 (r203443) @@ -58,8 +58,8 @@ struct array { struct stack { struct value *stack; - ssize_t sp; ssize_t size; + ssize_t sp; }; struct source; @@ -72,14 +72,14 @@ struct vtable { }; struct source { - struct vtable *vtable; union { - FILE *stream; struct { u_char *buf; size_t pos; } string; + FILE *stream; } u; + struct vtable *vtable; int lastchar; }; Modified: head/usr.bin/dc/dc.c ============================================================================== --- head/usr.bin/dc/dc.c Wed Feb 3 20:54:04 2010 (r203442) +++ head/usr.bin/dc/dc.c Wed Feb 3 21:06:13 2010 (r203443) @@ -59,8 +59,8 @@ usage(void) static void procfile(char *fname) { - FILE *file; - struct stat st; + struct stat st; + FILE *file; file = fopen(fname, "r"); if (file == NULL) *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***