diff --git a/edit.c b/edit.c index 2a95c0c..5e3765f 100644 --- a/edit.c +++ b/edit.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.164 2009/05/16 16:59:33 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.165 2009/06/08 20:06:44 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -115,7 +115,7 @@ x_read(char *buf, size_t len) i = -1; /* internal error */ x_mode(false); change_winsz(); - return i; + return (i); } /* tty I/O */ @@ -158,7 +158,7 @@ x_do_comment(char *buf, int bsize, int *lenp) int i, j, len = *lenp; if (len == 0) - return 1; /* somewhat arbitrary - it's what at&t ksh does */ + return (1); /* somewhat arbitrary - it's what at&t ksh does */ /* Already commented? */ if (buf[0] == '#') { @@ -170,7 +170,7 @@ x_do_comment(char *buf, int bsize, int *lenp) saw_nl = buf[i] == '\n'; } *lenp = j; - return 0; + return (0); } else { int n = 1; @@ -179,7 +179,7 @@ x_do_comment(char *buf, int bsize, int *lenp) if (buf[i] == '\n') n++; if (len + n >= bsize) - return -1; + return (-1); /* Now add them... */ for (i = len, j = len + n; --i >= 0; ) { if (buf[i] == '\n') @@ -188,7 +188,7 @@ x_do_comment(char *buf, int bsize, int *lenp) } buf[0] = '#'; *lenp += n; - return 1; + return (1); } } @@ -255,7 +255,7 @@ x_file_glob(int flags __unused, const char *str, int slen, char ***wordsp) struct source *s, *sold; if (slen < 0) - return 0; + return (0); toglob = add_glob(str, slen); @@ -287,7 +287,7 @@ x_file_glob(int flags __unused, const char *str, int slen, char ***wordsp) if (yylex(ONEWORD | LQCHAR) != LWORD) { source = sold; internal_warningf("fileglob: substitute error"); - return 0; + return (0); } source = sold; XPinit(w, 32); @@ -320,7 +320,7 @@ x_file_glob(int flags __unused, const char *str, int slen, char ***wordsp) if ((*wordsp = nwords ? words : NULL) == NULL && words != NULL) x_free_words(nwords, words); - return nwords; + return (nwords); } /* Data structure used in x_command_glob() */ @@ -339,7 +339,7 @@ path_order_cmp(const void *aa, const void *bb) int t; t = strcmp(a->word + a->base, b->word + b->base); - return t ? t : a->path_order - b->path_order; + return (t ? t : a->path_order - b->path_order); } static int @@ -351,7 +351,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) struct block *l; if (slen < 0) - return 0; + return (0); toglob = add_glob(str, slen); @@ -376,7 +376,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) if (!nwords) { *wordsp = NULL; XPfree(w); - return 0; + return (0); } /* Sort entries */ if (flags & XCF_FULLPATH) { @@ -386,7 +386,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) int i, path_order = 0; info = (struct path_order_info *) - alloc(nwords * sizeof (struct path_order_info), ATEMP); + alloc(nwords * sizeof(struct path_order_info), ATEMP); for (i = 0; i < nwords; i++) { info[i].word = words[i]; info[i].base = x_basename(words[i], NULL); @@ -407,7 +407,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) char **words = (char **)XPptrv(w); int i, j; - qsort(words, nwords, sizeof (void *), xstrcmp); + qsort(words, nwords, sizeof(void *), xstrcmp); for (i = j = 0; i < nwords - 1; i++) { if (strcmp(words[i], words[i + 1])) words[j++] = words[i]; @@ -422,7 +422,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) XPput(w, NULL); *wordsp = (char **)XPclose(w); - return nwords; + return (nwords); } #define IS_WORDC(c) (!ctype(c, C_LEX1) && (c) != '\'' && (c) != '"' && \ @@ -438,7 +438,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp, if (pos < 0 || pos > buflen) { *startp = pos; *is_commandp = false; - return 0; + return (0); } /* The case where pos == buflen happens to take care of itself... */ @@ -477,7 +477,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp, } *startp = start; - return end - start; + return (end - start); } static int @@ -496,21 +496,21 @@ x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp, * useful, so allow these. */ if (len == 0 && is_command) - return 0; + return (0); nwords = is_command ? x_command_glob(flags, buf + *startp, len, &words) : x_file_glob(flags, buf + *startp, len, &words); if (nwords == 0) { *wordsp = NULL; - return 0; + return (0); } if (is_commandp) *is_commandp = is_command; *wordsp = words; *endp = *startp + len; - return nwords; + return (nwords); } /* Given a string, copy it and possibly add a '*' to the end. The @@ -523,7 +523,7 @@ add_glob(const char *str, int slen) bool saw_slash = false; if (slen < 0) - return NULL; + return (NULL); strndupx(toglob, str, slen + 1, ATEMP); /* + 1 for "*" */ toglob[slen] = '\0'; @@ -547,7 +547,7 @@ add_glob(const char *str, int slen) toglob[slen] = '*'; toglob[slen + 1] = '\0'; } - return toglob; + return (toglob); } /* @@ -560,7 +560,7 @@ x_longest_prefix(int nwords, char * const * words) char *p; if (nwords <= 0) - return 0; + return (0); prefix_len = strlen(words[0]); for (i = 1; i < nwords; i++) @@ -569,7 +569,7 @@ x_longest_prefix(int nwords, char * const * words) prefix_len = j; break; } - return prefix_len; + return (prefix_len); } static void @@ -600,7 +600,7 @@ x_basename(const char *s, const char *se) if (se == NULL) se = s + strlen(s); if (s == se) - return 0; + return (0); /* Skip trailing slashes */ for (p = se - 1; p > s && *p == '/'; p--) @@ -610,7 +610,7 @@ x_basename(const char *s, const char *se) if (*p == '/' && p + 1 < se) p++; - return p - s; + return (p - s); } /* @@ -1462,7 +1462,7 @@ x_emacs(char *buf, size_t len) while (1) { x_flush(); if ((c = x_e_getc()) < 0) - return 0; + return (0); f = x_curprefix == -1 ? XFUNC_insert : x_tab[x_curprefix][c]; @@ -1490,7 +1490,7 @@ x_emacs(char *buf, size_t len) break; case KEOL: i = xep - xbuf; - return i; + return (i); case KINTR: /* special case for interrupt */ trapsig(SIGINT); x_mode(false); @@ -1514,7 +1514,7 @@ x_insert(int c) invmbs: left = 0; x_e_putc2(7); - return KSTD; + return (KSTD); } if (UTFMODE) { if (((c & 0xC0) == 0x80) && left) { @@ -1555,7 +1555,7 @@ x_insert(int c) str[1] = '\0'; while (x_arg--) x_ins(str); - return KSTD; + return (KSTD); } static int @@ -1566,7 +1566,7 @@ x_ins_string(int c) * we no longer need to bother checking if macroptr is * not NULL but first char is NUL; x_e_getc() does it */ - return KSTD; + return (KSTD); } static int @@ -1574,14 +1574,14 @@ x_do_ins(const char *cp, size_t len) { if (xep + len >= xend) { x_e_putc2(7); - return -1; + return (-1); } memmove(xcp + len, xcp, xep - xcp + 1); memmove(xcp, cp, len); xcp += len; xep += len; x_modified(); - return 0; + return (0); } static int @@ -1591,7 +1591,7 @@ x_ins(const char *s) int adj = x_adj_done; if (x_do_ins(s, strlen(s)) < 0) - return -1; + return (-1); /* * x_zots() may result in a call to x_adjust() * we want xcp to reflect the new position. @@ -1609,7 +1609,7 @@ x_ins(const char *s) if (xlp == xep - 1) x_redraw(xx_cols); x_adj_ok = 1; - return 0; + return (0); } static int @@ -1625,7 +1625,7 @@ x_del_back(int c __unused) x_goto(xcp - 1); } while ((++i < x_arg) && (xcp != xbuf)); x_delete(i, false); - return KSTD; + return (KSTD); } static int @@ -1645,10 +1645,10 @@ x_del_char(int c __unused) if (!i) { x_e_putc2(7); - return KSTD; + return (KSTD); } x_delete(i, false); - return KSTD; + return (KSTD); } /* Delete nc chars to the right of the cursor (including cursor position) */ @@ -1724,28 +1724,28 @@ static int x_del_bword(int c __unused) { x_delete(x_bword(), true); - return KSTD; + return (KSTD); } static int x_mv_bword(int c __unused) { x_bword(); - return KSTD; + return (KSTD); } static int x_mv_fword(int c __unused) { x_fword(1); - return KSTD; + return (KSTD); } static int x_del_fword(int c __unused) { x_delete(x_fword(0), true); - return KSTD; + return (KSTD); } static int @@ -1756,7 +1756,7 @@ x_bword(void) if (cp == xbuf) { x_e_putc2(7); - return 0; + return (0); } while (x_arg--) { while (cp != xbuf && is_mfs(cp[-1])) { @@ -1771,7 +1771,7 @@ x_bword(void) x_goto(cp); for (cp = xcp; cp < (xcp + nb); ++nc) cp += utf_ptradj(cp); - return nc; + return (nc); } static int @@ -1782,7 +1782,7 @@ x_fword(int move) if (cp == xep) { x_e_putc2(7); - return 0; + return (0); } while (x_arg--) { while (cp != xep && is_mfs(*cp)) @@ -1794,7 +1794,7 @@ x_fword(int move) cp2 += utf_ptradj(cp2); if (move) x_goto(cp); - return nc; + return (nc); } static void @@ -1837,7 +1837,7 @@ x_size_str(char *cp) int size = 0; while (*cp) size += x_size2(cp, &cp); - return size; + return (size); } static int @@ -1850,10 +1850,10 @@ x_size2(char *cp, char **dcp) if (dcp) *dcp = cp + 1; if (c == '\t') - return 4; /* Kludge, tabs are always four spaces. */ + return (4); /* Kludge, tabs are always four spaces. */ if (c < ' ' || c == 0x7f) - return 2; /* control unsigned char */ - return 1; + return (2); /* control unsigned char */ + return (1); } static void @@ -1901,14 +1901,14 @@ x_mv_back(int c __unused) { if (xcp == xbuf) { x_e_putc2(7); - return KSTD; + return (KSTD); } while (x_arg--) { x_goto(xcp - 1); if (xcp == xbuf) break; } - return KSTD; + return (KSTD); } static int @@ -1918,7 +1918,7 @@ x_mv_forw(int c __unused) if (xcp == xep) { x_e_putc2(7); - return KSTD; + return (KSTD); } while (x_arg--) { utf_ptradjx(cp, cp2); @@ -1927,7 +1927,7 @@ x_mv_forw(int c __unused) cp = cp2; } x_goto(cp); - return KSTD; + return (KSTD); } static int @@ -1939,17 +1939,17 @@ x_search_char_forw(int c __unused) *xep = '\0'; if (x_e_getmbc(tmp) < 0) { x_e_putc2(7); - return KSTD; + return (KSTD); } while (x_arg--) { if ((cp = (cp == xep) ? NULL : strstr(cp + 1, tmp)) == NULL && (cp = strstr(xbuf, tmp)) == NULL) { x_e_putc2(7); - return KSTD; + return (KSTD); } } x_goto(cp); - return KSTD; + return (KSTD); } static int @@ -1960,7 +1960,7 @@ x_search_char_back(int c __unused) if (x_e_getmbc(tmp) < 0) { x_e_putc2(7); - return KSTD; + return (KSTD); } for (; x_arg--; cp = p) for (p = cp; ; ) { @@ -1968,7 +1968,7 @@ x_search_char_back(int c __unused) p = xep; if (p == cp) { x_e_putc2(7); - return KSTD; + return (KSTD); } if ((tmp[1] && ((p+1) > xep)) || (tmp[2] && ((p+2) > xep))) @@ -1984,7 +1984,7 @@ x_search_char_back(int c __unused) break; } x_goto(cp); - return KSTD; + return (KSTD); } static int @@ -1994,7 +1994,7 @@ x_newline(int c __unused) x_e_putc2('\n'); x_flush(); *xep++ = '\n'; - return KEOL; + return (KEOL); } static int @@ -2004,35 +2004,35 @@ x_end_of_text(int c __unused) x_putc('\r'); x_putc('\n'); x_flush(); - return KEOL; + return (KEOL); } static int x_beg_hist(int c __unused) { x_load_hist(history); - return KSTD; + return (KSTD); } static int x_end_hist(int c __unused) { x_load_hist(histptr); - return KSTD; + return (KSTD); } static int x_prev_com(int c __unused) { x_load_hist(x_histp - x_arg); - return KSTD; + return (KSTD); } static int x_next_com(int c __unused) { x_load_hist(x_histp + x_arg); - return KSTD; + return (KSTD); } /* Goto a particular history number obtained from argument. @@ -2046,7 +2046,7 @@ x_goto_hist(int c __unused) x_load_hist(history); else x_load_hist(histptr + x_arg - source->line); - return KSTD; + return (KSTD); } static void @@ -2067,7 +2067,7 @@ x_load_hist(char **hp) x_histp = hp; oldsize = x_size_str(xbuf); if (modified) - strlcpy(holdbuf, xbuf, sizeof (holdbuf)); + strlcpy(holdbuf, xbuf, sizeof(holdbuf)); strlcpy(xbuf, sp, xend - xbuf); xbp = xbuf; xep = xcp = xbuf + strlen(xbuf); @@ -2112,12 +2112,12 @@ x_search_hist(int c) } x_flush(); if ((c = x_e_getc()) < 0) - return KSTD; + return (KSTD); f = x_tab[0][c]; if (c == MKCTRL('[')) { if ((f & 0x7F) == XFUNC_meta1) { if ((c = x_e_getc()) < 0) - return KSTD; + return (KSTD); f = x_tab[1][c] & 0x7F; if (f == XFUNC_meta1 || f == XFUNC_meta2) x_meta1(MKCTRL('[')); @@ -2173,7 +2173,7 @@ x_search_hist(int c) } if (offset < 0) x_redraw(-1); - return KSTD; + return (KSTD); } /* search backward from current line */ @@ -2190,12 +2190,12 @@ x_search(char *pat, int sameline, int offset) x_e_putc2('\n'); x_load_hist(hp); x_goto(xbuf + i + strlen(pat) - (*pat == '^')); - return i; + return (i); } } x_e_putc2(7); x_histp = histptr; - return -1; + return (-1); } /* anchored search up from current line */ @@ -2235,10 +2235,10 @@ static int x_match(char *str, char *pat) { if (*pat == '^') { - return (strncmp(str, pat + 1, strlen(pat + 1)) == 0) ? 0 : -1; + return ((strncmp(str, pat + 1, strlen(pat + 1)) == 0) ? 0 : -1); } else { char *q = strstr(str, pat); - return (q == NULL) ? -1 : q - str; + return ((q == NULL) ? -1 : q - str); } } @@ -2258,28 +2258,28 @@ x_del_line(int c __unused) xmp = NULL; x_redraw(j); x_modified(); - return KSTD; + return (KSTD); } static int x_mv_end(int c __unused) { x_goto(xep); - return KSTD; + return (KSTD); } static int x_mv_begin(int c __unused) { x_goto(xbuf); - return KSTD; + return (KSTD); } static int x_draw_line(int c __unused) { x_redraw(-1); - return KSTD; + return (KSTD); } static int @@ -2389,11 +2389,11 @@ x_transpose(int c __unused) */ if (xcp == xbuf) { x_e_putc2(7); - return KSTD; + return (KSTD); } else if (xcp == xep || Flag(FGMACS)) { if (xcp - xbuf == 1) { x_e_putc2(7); - return KSTD; + return (KSTD); } /* Gosling/Unipress emacs style: Swap two characters before the * cursor, do not change cursor position @@ -2401,12 +2401,12 @@ x_transpose(int c __unused) x_bs3(&xcp); if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) { x_e_putc2(7); - return KSTD; + return (KSTD); } x_bs3(&xcp); if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) { x_e_putc2(7); - return KSTD; + return (KSTD); } utf_wctomb(xcp, tmpa); x_zotc3(&xcp); @@ -2418,12 +2418,12 @@ x_transpose(int c __unused) */ if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) { x_e_putc2(7); - return KSTD; + return (KSTD); } x_bs3(&xcp); if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) { x_e_putc2(7); - return KSTD; + return (KSTD); } utf_wctomb(xcp, tmpa); x_zotc3(&xcp); @@ -2431,28 +2431,28 @@ x_transpose(int c __unused) x_zotc3(&xcp); } x_modified(); - return KSTD; + return (KSTD); } static int x_literal(int c __unused) { x_curprefix = -1; - return KSTD; + return (KSTD); } static int x_meta1(int c __unused) { x_curprefix = 1; - return KSTD; + return (KSTD); } static int x_meta2(int c __unused) { x_curprefix = 2; - return KSTD; + return (KSTD); } static int @@ -2472,7 +2472,7 @@ x_kill(int c __unused) ndel = -ndel; } x_delete(ndel, true); - return KSTD; + return (KSTD); } static void @@ -2498,11 +2498,11 @@ x_yank(int c __unused) if (killstack[killtp] == 0) { x_e_puts("\nnothing to yank"); x_redraw(-1); - return KSTD; + return (KSTD); } xmp = xcp; x_ins(killstack[killtp]); - return KSTD; + return (KSTD); } static int @@ -2515,7 +2515,7 @@ x_meta_yank(int c __unused) killtp = killsp; x_e_puts("\nyank something first"); x_redraw(-1); - return KSTD; + return (KSTD); } len = strlen(killstack[killtp]); x_goto(xcp - len); @@ -2527,7 +2527,7 @@ x_meta_yank(int c __unused) killtp--; } while (killstack[killtp] == 0); x_ins(killstack[killtp]); - return KSTD; + return (KSTD); } static int @@ -2538,14 +2538,14 @@ x_abort(int c __unused) xlp_valid = true; *xcp = 0; x_modified(); - return KINTR; + return (KINTR); } static int x_error(int c __unused) { x_e_putc2(7); - return KSTD; + return (KSTD); } static char * @@ -2571,7 +2571,7 @@ x_mapin(const char *cp, Area *ap) } *op = '\0'; - return new; + return (new); } static void @@ -2663,7 +2663,7 @@ x_bind(const char *a1, const char *a2, char msg[256] = "key sequence '"; const char *c = a1; m1 = msg + strlen(msg); - while (*c && m1 < (msg + sizeof (msg) - 3)) + while (*c && m1 < (msg + sizeof(msg) - 3)) x_mapout2(*c++, &m1); bi_errorf("%s' too long", msg); return (1); @@ -2716,7 +2716,7 @@ x_init_emacs(void) ainit(AEDIT); x_nextcmd = -1; - x_tab = alloc(X_NTABS * sizeof (*x_tab), AEDIT); + x_tab = alloc(X_NTABS * sizeof(*x_tab), AEDIT); for (j = 0; j < X_TABSZ; j++) x_tab[0][j] = XFUNC_insert; for (i = 1; i < X_NTABS; i++) @@ -2726,7 +2726,7 @@ x_init_emacs(void) x_tab[x_defbindings[i].xdb_tab][x_defbindings[i].xdb_char] = x_defbindings[i].xdb_func; - x_atab = alloc(X_NTABS * sizeof (*x_atab), AEDIT); + x_atab = alloc(X_NTABS * sizeof(*x_atab), AEDIT); for (i = 1; i < X_NTABS; i++) for (j = 0; j < X_TABSZ; j++) x_atab[i][j] = NULL; @@ -2747,7 +2747,7 @@ static int x_set_mark(int c __unused) { xmp = xcp; - return KSTD; + return (KSTD); } static int @@ -2758,7 +2758,7 @@ x_kill_region(int c __unused) if (xmp == NULL) { x_e_putc2(7); - return KSTD; + return (KSTD); } if (xmp > xcp) { rsize = xmp - xcp; @@ -2770,7 +2770,7 @@ x_kill_region(int c __unused) x_goto(xr); x_delete(rsize, true); xmp = xr; - return KSTD; + return (KSTD); } static int @@ -2780,18 +2780,18 @@ x_xchg_point_mark(int c __unused) if (xmp == NULL) { x_e_putc2(7); - return KSTD; + return (KSTD); } tmp = xmp; xmp = xcp; x_goto(tmp); - return KSTD; + return (KSTD); } static int x_noop(int c __unused) { - return KSTD; + return (KSTD); } /* @@ -2801,49 +2801,49 @@ static int x_comp_comm(int c __unused) { do_complete(XCF_COMMAND, CT_COMPLETE); - return KSTD; + return (KSTD); } static int x_list_comm(int c __unused) { do_complete(XCF_COMMAND, CT_LIST); - return KSTD; + return (KSTD); } static int x_complete(int c __unused) { do_complete(XCF_COMMAND_FILE, CT_COMPLETE); - return KSTD; + return (KSTD); } static int x_enumerate(int c __unused) { do_complete(XCF_COMMAND_FILE, CT_LIST); - return KSTD; + return (KSTD); } static int x_comp_file(int c __unused) { do_complete(XCF_FILE, CT_COMPLETE); - return KSTD; + return (KSTD); } static int x_list_file(int c __unused) { do_complete(XCF_FILE, CT_LIST); - return KSTD; + return (KSTD); } static int x_comp_list(int c __unused) { do_complete(XCF_COMMAND_FILE, CT_COMPLIST); - return KSTD; + return (KSTD); } static int @@ -2858,7 +2858,7 @@ x_expand(int c __unused) if (nwords == 0) { x_e_putc2(7); - return KSTD; + return (KSTD); } x_goto(xbuf + start); x_delete(end - start, false); @@ -2866,12 +2866,12 @@ x_expand(int c __unused) if (x_escape(words[i], strlen(words[i]), x_do_ins) < 0 || (++i < nwords && x_ins(" ") < 0)) { x_e_putc2(7); - return KSTD; + return (KSTD); } } x_adjust(); - return KSTD; + return (KSTD); } /* type == 0 for list, 1 for complete and 2 for complete-list */ @@ -3089,7 +3089,7 @@ x_set_arg(int c) x_arg = n; x_arg_defaulted = 0; } - return KSTD; + return (KSTD); } /* Comment or uncomment the current line. */ @@ -3109,9 +3109,9 @@ x_comment(int c __unused) xcp = xbp = xbuf; x_redraw(oldsize); if (ret > 0) - return x_newline('\n'); + return (x_newline('\n')); } - return KSTD; + return (KSTD); } static int @@ -3138,13 +3138,13 @@ x_version(int c __unused) x_redraw(vlen); if (c < 0) - return KSTD; + return (KSTD); /* This is what at&t ksh seems to do... Very bizarre */ if (c != ' ') x_e_ungetc(c); afree(v, ATEMP); - return KSTD; + return (KSTD); } static int @@ -3240,28 +3240,28 @@ x_prev_histword(int c __unused) *rcp = ch; } modified = m + 1; - return KSTD; + return (KSTD); } /* Uppercase N(1) words */ static int x_fold_upper(int c __unused) { - return x_fold_case('U'); + return (x_fold_case('U')); } /* Lowercase N(1) words */ static int x_fold_lower(int c __unused) { - return x_fold_case('L'); + return (x_fold_case('L')); } /* Lowercase N(1) words */ static int x_fold_capitalise(int c __unused) { - return x_fold_case('C'); + return (x_fold_case('C')); } /* NAME: @@ -3281,7 +3281,7 @@ x_fold_case(int c) if (cp == xep) { x_e_putc2(7); - return KSTD; + return (KSTD); } while (x_arg--) { /* @@ -3313,7 +3313,7 @@ x_fold_case(int c) } x_goto(cp); x_modified(); - return KSTD; + return (KSTD); } /* NAME: @@ -3363,7 +3363,7 @@ x_mode(bool onoff) bool prev; if (x_cur_mode == onoff) - return x_cur_mode; + return (x_cur_mode); prev = x_cur_mode; x_cur_mode = onoff; @@ -3426,7 +3426,7 @@ x_mode(bool onoff) } else tcsetattr(tty_fd, TCSADRAIN, &tty_state); - return prev; + return (prev); } #ifndef MKSH_NOVI @@ -3692,14 +3692,14 @@ x_vi(char *buf, size_t len) x_flush(); if (c == -1 || (ssize_t)len <= es->linelen) - return -1; + return (-1); if (es->cbuf != buf) memmove(buf, es->cbuf, es->linelen); buf[es->linelen++] = '\n'; - return es->linelen; + return (es->linelen); } static int @@ -3729,11 +3729,11 @@ vi_hook(int ch) refresh(insert != 0); break; case 1: - return 1; + return (1); } } else { if (ch == '\r' || ch == '\n') - return 1; + return (1); cmdlen = 0; argc1 = 0; if (ch >= '1' && ch <= '9') { @@ -3748,9 +3748,9 @@ vi_hook(int ch) es->linelen = 0; if (ch == '/') { if (putbuf("/", 1, 0) != 0) - return -1; + return (-1); } else if (putbuf("?", 1, 0) != 0) - return -1; + return (-1); refresh(0); } if (state == VVERSION) { @@ -3795,7 +3795,7 @@ vi_hook(int ch) if (ch >= '1' && ch <= '9') { argc2 = ch - '0'; state = VARG2; - return 0; + return (0); } else { curcmd[cmdlen++] = ch; if (ch == curcmd[0]) @@ -3843,11 +3843,11 @@ vi_hook(int ch) vi_error(); state = VNORMAL; refresh(0); - return 0; + return (0); } } else { locpat[srchlen] = '\0'; - (void)strlcpy(srchpat, locpat, sizeof srchpat); + (void)strlcpy(srchpat, locpat, sizeof(srchpat)); } state = VCMD; } else if (ch == edchars.erase || ch == Ctrl('h')) { @@ -3856,7 +3856,7 @@ vi_hook(int ch) es->linelen -= char_len((unsigned char)locpat[srchlen]); es->cursor = es->linelen; refresh(0); - return 0; + return (0); } restore_cbuf(); state = VNORMAL; @@ -3866,7 +3866,7 @@ vi_hook(int ch) es->linelen = 1; es->cursor = 1; refresh(0); - return 0; + return (0); } else if (ch == edchars.werase) { int i; int n = srchlen; @@ -3880,7 +3880,7 @@ vi_hook(int ch) srchlen = n; es->cursor = es->linelen; refresh(0); - return 0; + return (0); } else { if (srchlen == SRCHLEN - 1) vi_error(); @@ -3899,7 +3899,7 @@ vi_hook(int ch) es->cursor = es->linelen; refresh(0); } - return 0; + return (0); } break; } @@ -3919,10 +3919,10 @@ vi_hook(int ch) break; case 1: refresh(0); - return 1; + return (1); case 2: /* back from a 'v' command - don't redraw the screen */ - return 1; + return (1); } break; @@ -3950,7 +3950,7 @@ vi_hook(int ch) break; case 1: refresh(0); - return 1; + return (1); case 2: /* back from a 'v' command - can't happen */ break; @@ -3962,26 +3962,26 @@ vi_hook(int ch) vi_error(); break; } - return 0; + return (0); } static int nextstate(int ch) { if (is_extend(ch)) - return VEXTCMD; + return (VEXTCMD); else if (is_srch(ch)) - return VSEARCH; + return (VSEARCH); else if (is_long(ch)) - return VXCH; + return (VXCH); else if (ch == '.') - return VREDO; + return (VREDO); else if (ch == Ctrl('v')) - return VVERSION; + return (VVERSION); else if (is_cmd(ch)) - return VCMD; + return (VCMD); else - return VFAIL; + return (VFAIL); } static int @@ -3993,7 +3993,7 @@ vi_insert(int ch) if (insert == REPLACE) { if (es->cursor == undo->cursor) { vi_error(); - return 0; + return (0); } if (inslen > 0) inslen--; @@ -4004,7 +4004,7 @@ vi_insert(int ch) es->cbuf[es->cursor] = undo->cbuf[es->cursor]; } else { if (es->cursor == 0) - return 0; + return (0); if (inslen > 0) inslen--; es->cursor--; @@ -4013,7 +4013,7 @@ vi_insert(int ch) es->linelen - es->cursor + 1); } expanded = NONE; - return 0; + return (0); } if (ch == edchars.kill) { if (es->cursor != 0) { @@ -4024,7 +4024,7 @@ vi_insert(int ch) es->cursor = 0; } expanded = NONE; - return 0; + return (0); } if (ch == edchars.werase) { if (es->cursor != 0) { @@ -4039,7 +4039,7 @@ vi_insert(int ch) es->cursor = tcursor; } expanded = NONE; - return 0; + return (0); } /* If any chars are entered before escape, trash the saved insert * buffer (if user inserts & deletes char, ibuf gets trashed and @@ -4049,11 +4049,11 @@ vi_insert(int ch) saved_inslen = 0; switch (ch) { case '\0': - return -1; + return (-1); case '\r': case '\n': - return 1; + return (1); case Ctrl('['): expanded = NONE; @@ -4061,16 +4061,16 @@ vi_insert(int ch) first_insert = 0; if (inslen == 0) { inslen = saved_inslen; - return redo_insert(0); + return (redo_insert(0)); } lastcmd[0] = 'a'; lastac = 1; } if (lastcmd[0] == 's' || lastcmd[0] == 'c' || lastcmd[0] == 'C') - return redo_insert(0); + return (redo_insert(0)); else - return redo_insert(lastac - 1); + return (redo_insert(lastac - 1)); /* { Begin nonstandard vi commands */ case Ctrl('x'): @@ -4095,7 +4095,7 @@ vi_insert(int ch) default: if (es->linelen >= es->cbufsize - 1) - return -1; + return (-1); ibuf[inslen++] = ch; if (insert == INSERT) { memmove(&es->cbuf[es->cursor + 1], &es->cbuf[es->cursor], @@ -4107,7 +4107,7 @@ vi_insert(int ch) es->linelen++; expanded = NONE; } - return 0; + return (0); } static int @@ -4127,7 +4127,7 @@ vi_cmd(int argcnt, const char *cmd) cur--; es->cursor = cur; } else - return -1; + return (-1); } else { /* Don't save state in middle of macro.. */ if (is_undoable(*cmd) && !macro.p) { @@ -4156,12 +4156,12 @@ vi_cmd(int argcnt, const char *cmd) alias[1] = cmd[1]; ap = ktsearch(&aliases, alias, hash(alias)); if (!cmd[1] || !ap || !(ap->flag & ISSET)) - return -1; + return (-1); /* check if this is a recursive call... */ if ((p = (char *)macro.p)) while ((p = strchr(p, '\0')) && p[1]) if (*++p == cmd[1]) - return -1; + return (-1); /* insert alias into macro buffer */ nlen = strlen(ap->val.s) + 1; olen = !macro.p ? 2 : @@ -4216,10 +4216,10 @@ vi_cmd(int argcnt, const char *cmd) c1 = *cmd == 'c' ? domove(1, "^", 1) : 0; c2 = es->linelen; } else if (!is_move(cmd[1])) - return -1; + return (-1); else { if ((ncursor = domove(argcnt, &cmd[1], 1)) < 0) - return -1; + return (-1); if (*cmd == 'c' && (cmd[1] == 'w' || cmd[1] == 'W') && !ksh_isspace(es->cbuf[es->cursor])) { @@ -4261,7 +4261,7 @@ vi_cmd(int argcnt, const char *cmd) if (es->cursor != 0) es->cursor--; if (argcnt != 0) - return -1; + return (-1); break; case 'P': @@ -4273,7 +4273,7 @@ vi_cmd(int argcnt, const char *cmd) if (any && es->cursor != 0) es->cursor--; if (argcnt != 0) - return -1; + return (-1); break; case 'C': @@ -4300,7 +4300,7 @@ vi_cmd(int argcnt, const char *cmd) else argcnt = hlast - (source->line - argcnt); if (grabhist(modified, argcnt - 1) < 0) - return -1; + return (-1); else { modified = 0; hnum = argcnt - 1; @@ -4324,7 +4324,7 @@ vi_cmd(int argcnt, const char *cmd) case '+': case Ctrl('n'): if (grabhist(modified, hnum + argcnt) < 0) - return -1; + return (-1); else { modified = 0; hnum += argcnt; @@ -4335,7 +4335,7 @@ vi_cmd(int argcnt, const char *cmd) case '-': case Ctrl('p'): if (grabhist(modified, hnum - argcnt) < 0) - return -1; + return (-1); else { modified = 0; hnum -= argcnt; @@ -4344,7 +4344,7 @@ vi_cmd(int argcnt, const char *cmd) case 'r': if (es->linelen == 0) - return -1; + return (-1); modified = 1; hnum = hlast; if (cmd[1] == 0) @@ -4353,7 +4353,7 @@ vi_cmd(int argcnt, const char *cmd) int n; if (es->cursor + argcnt > es->linelen) - return -1; + return (-1); for (n = 0; n < argcnt; ++n) es->cbuf[es->cursor + n] = cmd[1]; es->cursor += n - 1; @@ -4368,7 +4368,7 @@ vi_cmd(int argcnt, const char *cmd) case 's': if (es->linelen == 0) - return -1; + return (-1); modified = 1; hnum = hlast; if (es->cursor + argcnt > es->linelen) @@ -4380,7 +4380,7 @@ vi_cmd(int argcnt, const char *cmd) case 'v': if (!argcnt) { if (es->linelen == 0) - return -1; + return (-1); if (modified) { es->cbuf[es->linelen] = '\0'; histsave(&source->line, es->cbuf, true, @@ -4398,11 +4398,11 @@ vi_cmd(int argcnt, const char *cmd) "fc -e ${VISUAL:-${EDITOR:-vi}} --", es->cbufsize); es->linelen = strlen(es->cbuf); - return 2; + return (2); case 'x': if (es->linelen == 0) - return -1; + return (-1); modified = 1; hnum = hlast; if (es->cursor + argcnt > es->linelen) @@ -4421,7 +4421,7 @@ vi_cmd(int argcnt, const char *cmd) del_range(es->cursor - argcnt, es->cursor); es->cursor -= argcnt; } else - return -1; + return (-1); break; case 'u': @@ -4432,9 +4432,9 @@ vi_cmd(int argcnt, const char *cmd) case 'U': if (!modified) - return -1; + return (-1); if (grabhist(modified, ohnum) < 0) - return -1; + return (-1); modified = 0; hnum = ohnum; break; @@ -4451,7 +4451,7 @@ vi_cmd(int argcnt, const char *cmd) case 'n': case 'N': if (lastsearch == ' ') - return -1; + return (-1); if (lastsearch == '?') c1 = 1; else @@ -4464,7 +4464,7 @@ vi_cmd(int argcnt, const char *cmd) restore_cbuf(); refresh(0); } - return -1; + return (-1); } else { modified = 0; hnum = c2; @@ -4477,7 +4477,7 @@ vi_cmd(int argcnt, const char *cmd) char *p, *sp; if (histnum(-1) < 0) - return -1; + return (-1); p = *histpos(); #define issp(c) (ksh_isspace(c) || (c) == '\n') if (argcnt) { @@ -4490,7 +4490,7 @@ vi_cmd(int argcnt, const char *cmd) p++; } if (!*p) - return -1; + return (-1); sp = p; } else { sp = p; @@ -4521,7 +4521,7 @@ vi_cmd(int argcnt, const char *cmd) if (argcnt < 0) { if (es->cursor != 0) es->cursor--; - return -1; + return (-1); } insert = INSERT; } @@ -4533,7 +4533,7 @@ vi_cmd(int argcnt, const char *cmd) int i; if (es->linelen == 0) - return -1; + return (-1); for (i = 0; i < argcnt; i++) { p = &es->cbuf[es->cursor]; if (ksh_islower(*p)) { @@ -4557,7 +4557,7 @@ vi_cmd(int argcnt, const char *cmd) &es->linelen); if (ret >= 0) es->cursor = 0; - return ret; + return (ret); } case '=': /* at&t ksh */ @@ -4568,13 +4568,13 @@ vi_cmd(int argcnt, const char *cmd) case Ctrl('i'): /* Nonstandard vi/ksh */ if (!Flag(FVITABCOMPLETE)) - return -1; + return (-1); complete_word(1, argcnt); break; case Ctrl('['): /* some annoying at&t kshs */ if (!Flag(FVIESCCOMPLETE)) - return -1; + return (-1); case '\\': /* at&t ksh */ case Ctrl('f'): /* Nonstandard vi/ksh */ complete_word(1, argcnt); @@ -4589,7 +4589,7 @@ vi_cmd(int argcnt, const char *cmd) if (insert == 0 && es->cursor != 0 && es->cursor >= es->linelen) es->cursor--; } - return 0; + return (0); } static int @@ -4601,19 +4601,19 @@ domove(int argcnt, const char *cmd, int sub) switch (*cmd) { case 'b': if (!sub && es->cursor == 0) - return -1; + return (-1); ncursor = backword(argcnt); break; case 'B': if (!sub && es->cursor == 0) - return -1; + return (-1); ncursor = Backword(argcnt); break; case 'e': if (!sub && es->cursor + 1 >= es->linelen) - return -1; + return (-1); ncursor = endword(argcnt); if (sub && ncursor < es->linelen) ncursor++; @@ -4621,7 +4621,7 @@ domove(int argcnt, const char *cmd, int sub) case 'E': if (!sub && es->cursor + 1 >= es->linelen) - return -1; + return (-1); ncursor = Endword(argcnt); if (sub && ncursor < es->linelen) ncursor++; @@ -4638,13 +4638,13 @@ domove(int argcnt, const char *cmd, int sub) case ',': case ';': if (fsavecmd == ' ') - return -1; + return (-1); i = fsavecmd == 'f' || fsavecmd == 'F'; t = fsavecmd > 'a'; if (*cmd == ',') t = !t; if ((ncursor = findch(fsavech, argcnt, t, i)) < 0) - return -1; + return (-1); if (sub && t) ncursor++; break; @@ -4652,7 +4652,7 @@ domove(int argcnt, const char *cmd, int sub) case 'h': case Ctrl('h'): if (!sub && es->cursor == 0) - return -1; + return (-1); ncursor = es->cursor - argcnt; if (ncursor < 0) ncursor = 0; @@ -4661,7 +4661,7 @@ domove(int argcnt, const char *cmd, int sub) case ' ': case 'l': if (!sub && es->cursor + 1 >= es->linelen) - return -1; + return (-1); if (es->linelen != 0) { ncursor = es->cursor + argcnt; if (ncursor > es->linelen) @@ -4671,13 +4671,13 @@ domove(int argcnt, const char *cmd, int sub) case 'w': if (!sub && es->cursor + 1 >= es->linelen) - return -1; + return (-1); ncursor = forwword(argcnt); break; case 'W': if (!sub && es->cursor + 1 >= es->linelen) - return -1; + return (-1); ncursor = Forwword(argcnt); break; @@ -4713,15 +4713,15 @@ domove(int argcnt, const char *cmd, int sub) (i = bracktype(es->cbuf[ncursor])) == 0) ncursor++; if (ncursor == es->linelen) - return -1; + return (-1); bcount = 1; do { if (i > 0) { if (++ncursor >= es->linelen) - return -1; + return (-1); } else { if (--ncursor < 0) - return -1; + return (-1); } t = bracktype(es->cbuf[ncursor]); if (t == i) @@ -4734,9 +4734,9 @@ domove(int argcnt, const char *cmd, int sub) break; default: - return -1; + return (-1); } - return ncursor; + return (ncursor); } static int @@ -4744,11 +4744,11 @@ redo_insert(int count) { while (count-- > 0) if (putbuf(ibuf, inslen, insert == REPLACE) != 0) - return -1; + return (-1); if (es->cursor > 0) es->cursor--; insert = 0; - return 0; + return (0); } static void @@ -4765,25 +4765,25 @@ bracktype(int ch) switch (ch) { case '(': - return 1; + return (1); case '[': - return 2; + return (2); case '{': - return 3; + return (3); case ')': - return -1; + return (-1); case ']': - return -2; + return (-2); case '}': - return -3; + return (-3); default: - return 0; + return (0); } } @@ -4813,14 +4813,14 @@ save_edstate(struct edstate *old) { struct edstate *new; - new = alloc(sizeof (struct edstate), APERM); + new = alloc(sizeof(struct edstate), APERM); new->cbuf = alloc(old->cbufsize, APERM); memcpy(new->cbuf, old->cbuf, old->linelen); new->cbufsize = old->cbufsize; new->linelen = old->linelen; new->cursor = old->cursor; new->winleft = old->winleft; - return new; + return (new); } static void @@ -4846,29 +4846,29 @@ free_edstate(struct edstate *old) static int x_vi_putbuf(const char *s, size_t len) { - return putbuf(s, len, 0); + return (putbuf(s, len, 0)); } static int putbuf(const char *buf, int len, int repl) { if (len == 0) - return 0; + return (0); if (repl) { if (es->cursor + len >= es->cbufsize) - return -1; + return (-1); if (es->cursor + len > es->linelen) es->linelen = es->cursor + len; } else { if (es->linelen + len >= es->cbufsize) - return -1; + return (-1); memmove(&es->cbuf[es->cursor + len], &es->cbuf[es->cursor], es->linelen - es->cursor); es->linelen += len; } memmove(&es->cbuf[es->cursor], buf, len); es->cursor += len; - return 0; + return (0); } static void @@ -4885,16 +4885,16 @@ findch(int ch, int cnt, int forw, int incl) int ncursor; if (es->linelen == 0) - return -1; + return (-1); ncursor = es->cursor; while (cnt--) { do { if (forw) { if (++ncursor == es->linelen) - return -1; + return (-1); } else { if (--ncursor < 0) - return -1; + return (-1); } } while (es->cbuf[ncursor] != ch); } @@ -4904,7 +4904,7 @@ findch(int ch, int cnt, int forw, int incl) else ncursor++; } - return ncursor; + return (ncursor); } static int @@ -4927,7 +4927,7 @@ forwword(int argcnt) ncursor < es->linelen) ncursor++; } - return ncursor; + return (ncursor); } static int @@ -4952,7 +4952,7 @@ backword(int argcnt) ncursor++; } } - return ncursor; + return (ncursor); } static int @@ -4978,7 +4978,7 @@ endword(int argcnt) ncursor--; } } - return ncursor; + return (ncursor); } static int @@ -4995,7 +4995,7 @@ Forwword(int argcnt) ncursor < es->linelen) ncursor++; } - return ncursor; + return (ncursor); } static int @@ -5013,7 +5013,7 @@ Backword(int argcnt) ncursor--; ncursor++; } - return ncursor; + return (ncursor); } static int @@ -5033,7 +5033,7 @@ Endword(int argcnt) ncursor--; } } - return ncursor; + return (ncursor); } static int @@ -5042,16 +5042,16 @@ grabhist(int save, int n) char *hptr; if (n < 0 || n > hlast) - return -1; + return (-1); if (n == hlast) { restore_cbuf(); ohnum = n; - return 0; + return (0); } (void)histnum(n); if ((hptr = *histpos()) == NULL) { internal_warningf("grabhist: bad history array"); - return -1; + return (-1); } if (save) save_cbuf(); @@ -5060,7 +5060,7 @@ grabhist(int save, int n) memmove(es->cbuf, hptr, es->linelen); es->cursor = 0; ohnum = n; - return 0; + return (0); } static int @@ -5071,7 +5071,7 @@ grabsearch(int save, int start, int fwd, char *pat) int anchored; if ((start == 0 && fwd == 0) || (start >= hlast - 1 && fwd == 1)) - return -1; + return (-1); if (fwd) start++; else @@ -5082,9 +5082,9 @@ grabsearch(int save, int start, int fwd, char *pat) /* XXX should strcmp be strncmp? */ if (start != 0 && fwd && strcmp(holdbuf, pat) >= 0) { restore_cbuf(); - return 0; + return (0); } else - return -1; + return (-1); } if (save) save_cbuf(); @@ -5094,7 +5094,7 @@ grabsearch(int save, int start, int fwd, char *pat) es->linelen = es->cbufsize - 1; memmove(es->cbuf, hptr, es->linelen); es->cursor = 0; - return hist; + return (hist); } static void @@ -5130,14 +5130,14 @@ outofwin(void) int cur, col; if (es->cursor < es->winleft) - return 1; + return (1); col = 0; cur = es->winleft; while (cur < es->cursor) col = newcol((unsigned char)es->cbuf[cur++], col); if (col >= winwidth) - return 1; - return 0; + return (1); + return (0); } static void @@ -5168,8 +5168,8 @@ static int newcol(int ch, int col) { if (ch == '\t') - return (col | 7) + 1; - return col + char_len(ch); + return ((col | 7) + 1); + return (col + char_len(ch)); } static void @@ -5295,7 +5295,7 @@ expand_word(int cmd) restore_edstate(es, buf); buf = 0; expanded = NONE; - return 0; + return (0); } if (buf) { free_edstate(buf); @@ -5307,7 +5307,7 @@ expand_word(int cmd) &start, &end, &words, NULL); if (nwords == 0) { vi_error(); - return -1; + return (-1); } buf = save_edstate(es); @@ -5332,7 +5332,7 @@ expand_word(int cmd) insert = INSERT; lastac = 0; refresh(0); - return rval; + return (rval); } static int @@ -5348,13 +5348,13 @@ complete_word(int cmd, int count) if (cmd == 0 && expanded == COMPLETE && buf) { print_expansions(buf, 0); expanded = PRINT; - return 0; + return (0); } if (cmd == 0 && expanded == PRINT && buf) { restore_edstate(es, buf); buf = 0; expanded = NONE; - return 0; + return (0); } if (buf) { free_edstate(buf); @@ -5369,7 +5369,7 @@ complete_word(int cmd, int count) &start, &end, &words, &is_command); if (nwords == 0) { vi_error(); - return -1; + return (-1); } if (count) { int i; @@ -5380,7 +5380,7 @@ complete_word(int cmd, int count) x_print_expansions(nwords, words, is_command); x_free_words(nwords, words); redraw_line(0); - return -1; + return (-1); } /* * Expand the count'th word to its basename @@ -5434,7 +5434,7 @@ complete_word(int cmd, int count) lastac = 0; /* prevent this from being redone... */ refresh(0); - return rval; + return (rval); } static int @@ -5449,12 +5449,12 @@ print_expansions(struct edstate *est, int cmd __unused) &start, &end, &words, &is_command); if (nwords == 0) { vi_error(); - return -1; + return (-1); } x_print_expansions(nwords, words, is_command); x_free_words(nwords, words); redraw_line(0); - return 0; + return (0); } /* Similar to x_zotc(emacs.c), but no tab weirdness */ diff --git a/eval.c b/eval.c index 063951e..76dde63 100644 --- a/eval.c +++ b/eval.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.57 2009/05/16 18:40:05 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.58 2009/06/08 20:06:45 tg Exp $"); #ifdef MKSH_SMALL #define MKSH_NOPWNAM @@ -115,7 +115,7 @@ substitute(const char *cp, int f) internal_errorf("substitute"); source = sold; afree(s, ATEMP); - return evalstr(yylval.cp, f); + return (evalstr(yylval.cp, f)); } /* @@ -137,7 +137,7 @@ eval(const char **ap, int f) while (*ap != NULL) expand(*ap++, &w, f); XPput(w, NULL); - return (char **) XPclose(w) + 1; + return ((char **)XPclose(w) + 1); } /* @@ -346,7 +346,7 @@ expand(const char *cp, /* input word */ if (!st->next) { SubType *newst; - newst = alloc(sizeof (SubType), ATEMP); + newst = alloc(sizeof(SubType), ATEMP); newst->next = NULL; newst->prev = st; st->next = newst; @@ -916,7 +916,7 @@ varsub(Expand *xp, const char *sp, const char *word, struct tbl *vp; if (sp[0] == '\0') /* Bad variable name */ - return -1; + return (-1); xp->var = NULL; @@ -926,7 +926,7 @@ varsub(Expand *xp, const char *sp, const char *word, /* Can't have any modifiers for ${#...} */ if (*word != CSUBST) - return -1; + return (-1); sp++; /* Check for size of array */ if ((p = cstrchr(sp, '[')) && (p[1] == '*' || p[1] == '@') && @@ -951,7 +951,7 @@ varsub(Expand *xp, const char *sp, const char *word, errorf("%s: parameter not set", sp); *stypep = 0; /* unqualified variable/string substitution */ xp->str = shf_smprintf("%lu", (unsigned long)c); - return XSUB; + return (XSUB); } /* Check for qualifiers in word part */ @@ -982,9 +982,9 @@ varsub(Expand *xp, const char *sp, const char *word, slen += 2; } } else if (stype) /* : is not ok */ - return -1; + return (-1); if (!stype && *word != CSUBST) - return -1; + return (-1); *stypep = stype; *slenp = slen; @@ -994,7 +994,7 @@ varsub(Expand *xp, const char *sp, const char *word, case '=': /* can't assign to a vector */ case '%': /* can't trim a vector (yet) */ case '#': - return -1; + return (-1); } if (e->loc->argc == 0) { xp->str = null; @@ -1016,7 +1016,7 @@ varsub(Expand *xp, const char *sp, const char *word, case '%': /* can't trim a vector (yet) */ case '#': case '?': - return -1; + return (-1); } XPinit(wv, 32); vp = global(arrayname(sp)); @@ -1040,7 +1040,7 @@ varsub(Expand *xp, const char *sp, const char *word, /* Can't assign things like $! or $1 */ if ((stype & 0x7f) == '=' && ctype(*sp, C_VAR1 | C_DIGIT)) - return -1; + return (-1); xp->var = global(sp); xp->str = str_val(xp->var); state = XSUB; @@ -1056,7 +1056,7 @@ varsub(Expand *xp, const char *sp, const char *word, if (Flag(FNOUNSET) && xp->str == null && (ctype(c, C_SUBOP2) || (state != XBASE && c != '+'))) errorf("%s: parameter not set", sp); - return state; + return (state); } /* @@ -1077,7 +1077,7 @@ comsub(Expand *xp, const char *cp) source = sold; if (t == NULL) - return XBASE; + return (XBASE); if (t != NULL && t->type == TCOM && /* $(args == NULL && *t->vars == NULL && t->ioact != NULL) { @@ -1108,7 +1108,7 @@ comsub(Expand *xp, const char *cp) } xp->u.shf = shf; - return XCOM; + return (XCOM); } /* @@ -1127,7 +1127,7 @@ trimsub(char *str, char *pat, int how) c = *p; *p = '\0'; if (gmatchx(str, pat, false)) { *p = c; - return p; + return (p); } *p = c; } @@ -1137,7 +1137,7 @@ trimsub(char *str, char *pat, int how) c = *p; *p = '\0'; if (gmatchx(str, pat, false)) { *p = c; - return p; + return (p); } *p = c; } @@ -1157,7 +1157,7 @@ trimsub(char *str, char *pat, int how) break; } - return str; /* no match, return string */ + return (str); /* no match, return string */ } /* @@ -1175,7 +1175,7 @@ glob(char *cp, XPtrV *wp, int markdirs) XPput(*wp, debunk(cp, cp, strlen(cp) + 1)); else qsort(XPptrv(*wp) + oldsize, XPsize(*wp) - oldsize, - sizeof (void *), xstrcmp); + sizeof(void *), xstrcmp); } #define GF_NONE 0 @@ -1197,7 +1197,7 @@ glob_str(char *cp, XPtrV *wp, int markdirs) globit(&xs, &xp, cp, wp, markdirs ? GF_MARKDIR : GF_NONE); Xfree(xs, xp); - return XPsize(*wp) - oldsize; + return (XPsize(*wp) - oldsize); } static void @@ -1337,7 +1337,7 @@ debunk(char *dp, const char *sp, size_t dlen) if ((s = cstrchr(sp, MAGIC))) { if (s - sp >= (ssize_t)dlen) - return dp; + return (dp); memcpy(dp, sp, s - sp); for (d = dp + (s - sp); *s && (d - dp < (ssize_t)dlen); s++) if (!ISMAGIC(*s) || !(*++s & 0x80) || @@ -1353,7 +1353,7 @@ debunk(char *dp, const char *sp, size_t dlen) *d = '\0'; } else if (dp != sp) strlcpy(dp, sp, dlen); - return dp; + return (dp); } /* Check if p is an unquoted name, possibly followed by a / or :. If so @@ -1390,7 +1390,7 @@ maybe_expand_tilde(const char *p, XString *dsp, char **dpp, int isassign) *dpp = dp; r = p; } - return r; + return (r); } /* @@ -1436,11 +1436,11 @@ homedir(char *name) pw = getpwnam(name); if (pw == NULL) - return NULL; + return (NULL); strdupx(ap->val.s, pw->pw_dir, APERM); ap->flag |= DEFINED|ISSET|ALLOC; } - return ap->val.s; + return (ap->val.s); } #endif diff --git a/exec.c b/exec.c index 66411a6..c0bd00b 100644 --- a/exec.c +++ b/exec.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.56 2009/05/16 18:40:05 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.57 2009/06/08 20:06:45 tg Exp $"); static int comexec(struct op *, struct tbl *volatile, const char **, int volatile, volatile int *); @@ -54,7 +54,7 @@ execute(struct op *volatile t, struct tbl *tp = NULL; if (t == NULL) - return 0; + return (0); /* Caller doesn't care if XERROK should propagate. */ if (xerrok == NULL) @@ -62,7 +62,7 @@ execute(struct op *volatile t, if ((flags&XFORK) && !(flags&XEXEC) && t->type != TPIPE) /* run in sub-process */ - return exchild(t, flags & ~XTIME, xerrok, -1); + return (exchild(t, flags & ~XTIME, xerrok, -1)); newenv(E_EXEC); if (trap) @@ -98,9 +98,9 @@ execute(struct op *volatile t, flags &= ~XTIME; if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) { - e->savefd = alloc(NUFILE * sizeof (short), ATEMP); + e->savefd = alloc(NUFILE * sizeof(short), ATEMP); /* initialise to not redirected */ - memset(e->savefd, 0, NUFILE * sizeof (short)); + memset(e->savefd, 0, NUFILE * sizeof(short)); } /* do redirection, to be restored in quitenv() */ @@ -391,7 +391,7 @@ execute(struct op *volatile t, if (Flag(FERREXIT)) unwind(LERROR); } - return rv; + return (rv); } /* @@ -693,7 +693,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, exstat = rv; unwind(LLEAVE); } - return rv; + return (rv); } static void @@ -718,20 +718,20 @@ scriptexec(struct op *tp, const char **ap) #ifndef MKSH_SMALL if ((fd = open(tp->str, O_RDONLY)) >= 0) { /* read first MAXINTERP octets from file */ - if (read(fd, buf, sizeof (buf)) <= 0) + if (read(fd, buf, sizeof(buf)) <= 0) /* read error -> no good */ buf[0] = '\0'; close(fd); /* scan for newline (or CR) or NUL _before_ end of buffer */ cp = (unsigned char *)buf; - while ((char *)cp < (buf + sizeof (buf))) + while ((char *)cp < (buf + sizeof(buf))) if (*cp == '\0' || *cp == '\n' || *cp == '\r') { *cp = '\0'; break; } else ++cp; /* if the shebang line is longer than MAXINTERP, bail out */ - if ((char *)cp >= (buf + sizeof (buf))) + if ((char *)cp >= (buf + sizeof(buf))) goto noshebang; /* skip UTF-8 Byte Order Mark, if present */ cp = (unsigned char *)buf; @@ -820,7 +820,7 @@ findfunc(const char *name, unsigned int h, int create) break; } } - return tp; + return (tp); } /* @@ -864,7 +864,7 @@ define(const char *name, struct op *t) if (t->u.ksh_func) tp->flag |= FKSH; - return 0; + return (0); } /* @@ -981,7 +981,7 @@ findcom(const char *name, int flags) tp->u.fpath = npath.ro; } } - return tp; + return (tp); } /* @@ -1012,7 +1012,7 @@ search_access(const char *lpath, int mode, struct stat statb; if (stat(lpath, &statb) < 0) - return -1; + return (-1); ret = access(lpath, mode); if (ret < 0) err = errno; /* File exists, but we can't access it */ @@ -1024,7 +1024,7 @@ search_access(const char *lpath, int mode, } if (err && errnop && !*errnop) *errnop = err; - return ret; + return (ret); } /* @@ -1045,7 +1045,7 @@ search(const char *name, const char *lpath, if (vstrchr(name, '/')) { if (search_access(name, mode, errnop) == 0) return (name); - return NULL; + return (NULL); } namelen = strlen(name) + 1; @@ -1066,12 +1066,12 @@ search(const char *name, const char *lpath, XcheckN(xs, xp, namelen); memcpy(xp, name, namelen); if (search_access(Xstring(xs, xp), mode, errnop) == 0) - return Xclose(xs, xp + namelen); + return (Xclose(xs, xp + namelen)); if (*sp++ == '\0') sp = NULL; } Xfree(xs, xp); - return NULL; + return (NULL); } static int @@ -1089,7 +1089,7 @@ call_builtin(struct tbl *tp, const char **wp) shl_stdout_ok = 0; builtin_flag = 0; builtin_argv0 = NULL; - return rv; + return (rv); } /* @@ -1161,10 +1161,10 @@ iosetup(struct ioword *iop, struct tbl *tp) &emsg)) < 0) { warningf(true, "%s: %s", snptreef(NULL, 32, "%R", &iotmp), emsg); - return -1; + return (-1); } if (u == iop->unit) - return 0; /* "dup from" == "dup to" */ + return (0); /* "dup from" == "dup to" */ break; } } @@ -1172,7 +1172,7 @@ iosetup(struct ioword *iop, struct tbl *tp) if (do_open) { if (Flag(FRESTRICTED) && (flags & O_CREAT)) { warningf(true, "%s: restricted", cp); - return -1; + return (-1); } u = open(cp, flags, 0666); } @@ -1185,7 +1185,7 @@ iosetup(struct ioword *iop, struct tbl *tp) (iotype == IOREAD || iotype == IOHERE) ? "open" : "create", cp, strerror(u)); } - return -1; + return (-1); } /* Do not save if it has already been redirected (i.e. "cat >x >y"). */ if (e->savefd[iop->unit] == 0) { @@ -1215,7 +1215,7 @@ iosetup(struct ioword *iop, struct tbl *tp) strerror(ev)); if (iotype != IODUP) close(u); - return -1; + return (-1); } if (iotype != IODUP) close(u); @@ -1231,7 +1231,7 @@ iosetup(struct ioword *iop, struct tbl *tp) } if (u == 2) /* Clear any write errors */ shf_reopen(2, SHF_WR, shl_out); - return 0; + return (0); } /* @@ -1250,7 +1250,7 @@ herein(const char *content, int sub) /* ksh -c 'cat << EOF' can cause this... */ if (content == NULL) { warningf(true, "here document missing"); - return -2; /* special to iosetup(): don't print error */ + return (-2); /* special to iosetup(): don't print error */ } /* Create temp file to hold content (done before newenv so temp @@ -1264,7 +1264,7 @@ herein(const char *content, int sub) h->name, strerror(fd)); if (shf) shf_close(shf); - return -2 /* special to iosetup(): don't print error */; + return (-2 /* special to iosetup(): don't print error */); } osource = source; @@ -1274,7 +1274,7 @@ herein(const char *content, int sub) source = osource; quitenv(shf); close(fd); - return -2; /* special to iosetup(): don't print error */ + return (-2); /* special to iosetup(): don't print error */ } if (sub) { /* Do substitutions on the content of heredoc */ @@ -1296,10 +1296,10 @@ herein(const char *content, int sub) fd = errno; warningf(true, "error writing %s: %s, %s", h->name, strerror(i), strerror(fd)); - return -2; /* special to iosetup(): don't print error */ + return (-2); /* special to iosetup(): don't print error */ } - return fd; + return (fd); } /* @@ -1327,11 +1327,11 @@ do_selectargs(const char **ap, bool print_menu) pr_menu(ap); shellf("%s", str_val(global("PS3"))); if (call_builtin(findcom("read", FC_BI), read_args)) - return NULL; + return (NULL); s = str_val(global("REPLY")); if (*s) { getn(s, &i); - return (i >= 1 && i <= argct) ? ap[i - 1] : null; + return ((i >= 1 && i <= argct) ? ap[i - 1] : null); } print_menu = 1; } @@ -1354,7 +1354,7 @@ select_fmt_entry(const void *arg, int i, char *buf, int buflen) shf_snprintf(buf, buflen, "%*d) %s", smi->num_width, i + 1, smi->args[i]); - return buf; + return (buf); } /* @@ -1395,7 +1395,7 @@ pr_menu(const char *const *ap) print_columns(shl_out, n, select_fmt_entry, (void *)&smi, dwidth + nwidth + 2, 1); - return n; + return (n); } /* XXX: horrible kludge to fit within the framework */ @@ -1406,7 +1406,7 @@ static char * plain_fmt_entry(const void *arg, int i, char *buf, int buflen) { shf_snprintf(buf, buflen, "%s", ((char *const *)arg)[i]); - return buf; + return (buf); } int @@ -1422,7 +1422,7 @@ pr_list(char *const *ap) print_columns(shl_out, n, plain_fmt_entry, (const void *)ap, nwidth + 1, 0); - return n; + return (n); } /* @@ -1441,7 +1441,7 @@ dbteste_isa(Test_env *te, Test_meta meta) const char *p; if (!*te->pos.wp) - return meta == TM_END; + return (meta == TM_END); /* unquoted word? */ for (p = *te->pos.wp; *p == CHAR; p += 2) @@ -1468,7 +1468,7 @@ dbteste_isa(Test_env *te, Test_meta meta) if (ret) te->pos.wp++; - return ret; + return (ret); } static const char * @@ -1477,19 +1477,19 @@ dbteste_getopnd(Test_env *te, Test_op op, bool do_eval) const char *s = *te->pos.wp; if (!s) - return NULL; + return (NULL); te->pos.wp++; if (!do_eval) - return null; + return (null); if (op == TO_STEQL || op == TO_STNEQ) s = evalstr(s, DOTILDE | DOPAT); else s = evalstr(s, DOTILDE); - return s; + return (s); } static void diff --git a/expr.c b/expr.c index 33c6d41..1e543d0 100644 --- a/expr.c +++ b/expr.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.26 2009/05/16 16:59:35 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.27 2009/06/08 20:06:45 tg Exp $"); /* The order of these enums is constrained by the order of opinfo[] */ enum token { @@ -603,7 +603,7 @@ tempvar(void) { struct tbl *vp; - vp = alloc(sizeof (struct tbl), ATEMP); + vp = alloc(sizeof(struct tbl), ATEMP); vp->flag = ISSET|INTEGER; vp->type = 0; vp->areap = ATEMP; diff --git a/funcs.c b/funcs.c index 7b8d9c5..f6498da 100644 --- a/funcs.c +++ b/funcs.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.109 2009/05/21 14:28:33 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.110 2009/06/08 20:06:46 tg Exp $"); /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -172,13 +172,13 @@ c_cd(const char **wp) physical = true; break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; if (Flag(FRESTRICTED)) { bi_errorf("restricted shell - can't cd"); - return 1; + return (1); } pwd_s = global("PWD"); @@ -188,7 +188,7 @@ c_cd(const char **wp) /* No arguments - go home */ if ((dir = str_val(global("HOME"))) == null) { bi_errorf("no home directory (HOME not set)"); - return 1; + return (1); } } else if (!wp[1]) { /* One argument: - or dir */ @@ -199,7 +199,7 @@ c_cd(const char **wp) dir = str_val(oldpwd_s); if (dir == null) { bi_errorf("no OLDPWD"); - return 1; + return (1); } printpath = true; } @@ -210,7 +210,7 @@ c_cd(const char **wp) if (!current_wd[0]) { bi_errorf("don't know current directory"); - return 1; + return (1); } /* substitute arg1 for arg2 in current path. * if the first substitution fails because the cd fails @@ -219,7 +219,7 @@ c_cd(const char **wp) */ if ((cp = strstr(current_wd, wp[0])) == NULL) { bi_errorf("bad substitution"); - return 1; + return (1); } ilen = cp - current_wd; olen = strlen(wp[0]); @@ -232,7 +232,7 @@ c_cd(const char **wp) printpath = true; } else { bi_errorf("too many arguments"); - return 1; + return (1); } XinitN(xs, PATH_MAX, ATEMP); @@ -254,7 +254,7 @@ c_cd(const char **wp) else bi_errorf("%s - %s", try, strerror(errno)); afree(allocd, ATEMP); - return 1; + return (1); } /* Clear out tracked aliases with relative paths */ @@ -288,7 +288,7 @@ c_cd(const char **wp) shprintf("%s\n", pwd); afree(allocd, ATEMP); - return 0; + return (0); } int @@ -307,13 +307,13 @@ c_pwd(const char **wp) physical = true; break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; if (wp[0]) { bi_errorf("too many arguments"); - return 1; + return (1); } p = current_wd[0] ? (physical ? get_phys_path(current_wd) : current_wd) : NULL; @@ -325,7 +325,7 @@ c_pwd(const char **wp) } shprintf("%s\n", p); afree(allocd, ATEMP); - return 0; + return (0); } int @@ -399,7 +399,7 @@ c_print(const char **wp) case 'p': if ((fd = coproc_getfd(W_OK, &emsg)) < 0) { bi_errorf("-p: %s", emsg); - return 1; + return (1); } break; case 'r': @@ -413,11 +413,11 @@ c_print(const char **wp) fd = 0; else if ((fd = check_fd(s, W_OK, &emsg)) < 0) { bi_errorf("-u: %s: %s", s, emsg); - return 1; + return (1); } break; case '?': - return 1; + return (1); } if (!(builtin_opt.info & GI_MINUSMINUS)) { /* treat a lone - like -- */ @@ -560,7 +560,7 @@ c_print(const char **wp) opipe = block_pipe(); continue; } - return 1; + return (1); } s += n; len -= n; @@ -569,7 +569,7 @@ c_print(const char **wp) restore_pipe(opipe); } - return 0; + return (0); } int @@ -594,7 +594,7 @@ c_whence(const char **wp) Vflag = true; break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; @@ -684,7 +684,7 @@ c_whence(const char **wp) if (vflag || !rv) shf_putc('\n', shl_stdout); } - return rv; + return (rv); } /* Deal with command -vV - command -p dealt with in comexec() */ @@ -694,7 +694,7 @@ c_command(const char **wp) /* Let c_whence do the work. Note that c_command() must be * a distinct function from c_whence() (tested in comexec()). */ - return c_whence(wp); + return (c_whence(wp)); } /* typeset, export, and readonly */ @@ -791,7 +791,7 @@ c_typeset(const char **wp) flag = EXPORT; break; case '?': - return 1; + return (1); } if (builtin_opt.info & GI_PLUS) { fclr |= flag; @@ -806,10 +806,10 @@ c_typeset(const char **wp) field = 0; if (fieldstr && !bi_getn(fieldstr, &field)) - return 1; + return (1); base = 0; if (basestr && !bi_getn(basestr, &base)) - return 1; + return (1); if (!(builtin_opt.info & GI_MINUSMINUS) && wp[builtin_opt.optind] && (wp[builtin_opt.optind][0] == '-' || @@ -821,7 +821,7 @@ c_typeset(const char **wp) if (func && ((fset|fclr) & ~(TRACE|UCASEV_AL|EXPORT))) { bi_errorf("only -t, -u and -x options may be used with -f"); - return 1; + return (1); } if (wp[builtin_opt.optind]) { /* Take care of exclusions. @@ -871,10 +871,10 @@ c_typeset(const char **wp) "%s() %T\n", wp[i], f->val.t); } else if (!typeset(wp[i], fset, fclr, field, base)) { bi_errorf("%s: not identifier", wp[i]); - return 1; + return (1); } } - return rv; + return (rv); } /* list variables and attributes */ @@ -1011,7 +1011,7 @@ c_typeset(const char **wp) } } } - return 0; + return (0); } int @@ -1054,7 +1054,7 @@ c_alias(const char **wp) xflag = EXPORT; break; case '?': - return 1; + return (1); } } wp += builtin_opt.optind; @@ -1076,10 +1076,10 @@ c_alias(const char **wp) if (!tflag || *wp) { shf_puts("alias: -r flag can only be used with -t" " and without arguments\n", shl_stdout); - return 1; + return (1); } ksh_getopt_reset(&builtin_opt, GF_ERROR); - return c_unalias(args); + return (c_unalias(args)); } if (*wp == NULL) { @@ -1150,7 +1150,7 @@ c_alias(const char **wp) afree(xalias, ATEMP); } - return rv; + return (rv); } int @@ -1177,7 +1177,7 @@ c_unalias(const char **wp) t = &taliases; break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; @@ -1206,7 +1206,7 @@ c_unalias(const char **wp) } } - return rv; + return (rv); } int @@ -1224,7 +1224,7 @@ c_let(const char **wp) break; } else rv = val == 0; - return rv; + return (rv); } int @@ -1247,7 +1247,7 @@ c_jobs(const char **wp) nflag = -1; break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; if (!*wp) { @@ -1258,7 +1258,7 @@ c_jobs(const char **wp) if (j_jobs(*wp, flag, nflag)) rv = 1; } - return rv; + return (rv); } #ifndef MKSH_UNEMPLOYED @@ -1270,17 +1270,17 @@ c_fgbg(const char **wp) if (!Flag(FMONITOR)) { bi_errorf("job control not enabled"); - return 1; + return (1); } if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); wp += builtin_opt.optind; if (*wp) for (; *wp; wp++) rv = j_resume(*wp, bg); else rv = j_resume("%%", bg); - return bg ? 0 : rv; + return (bg ? 0 : rv); } #endif @@ -1295,7 +1295,7 @@ kill_fmt_entry(const void *arg, int i, char *buf, int buflen) ki->num_width, i, ki->name_width, sigtraps[i].name, sigtraps[i].mess); - return buf; + return (buf); } int @@ -1311,7 +1311,7 @@ c_kill(const char **wp) ksh_isupper(p[1]))) { if (!(t = gettrap(p + 1, true))) { bi_errorf("bad signal '%s'", p + 1); - return 1; + return (1); } i = (wp[2] && strcmp(wp[2], "--") == 0) ? 3 : 2; } else { @@ -1326,11 +1326,11 @@ c_kill(const char **wp) if (!(t = gettrap(builtin_opt.optarg, true))) { bi_errorf("bad signal '%s'", builtin_opt.optarg); - return 1; + return (1); } break; case '?': - return 1; + return (1); } i = builtin_opt.optind; } @@ -1341,14 +1341,14 @@ c_kill(const char **wp) "\tkill -l [exit_status ...]\n", shl_out); #endif bi_errorfz(); - return 1; + return (1); } if (lflag) { if (wp[i]) { for (; wp[i]; i++) { if (!bi_getn(wp[i], &n)) - return 1; + return (1); if (n > 128 && n < 128 + NSIG) n -= 128; if (n > 0 && n < NSIG) @@ -1377,7 +1377,7 @@ c_kill(const char **wp) kill_fmt_entry, (void *)&ki, ki.num_width + ki.name_width + mess_width + 3, 1); } - return 0; + return (0); } rv = 0; sig = t ? t->signal : SIGTERM; @@ -1399,7 +1399,7 @@ c_kill(const char **wp) } } } - return rv; + return (rv); } void @@ -1420,28 +1420,28 @@ c_getopts(const char **wp) struct tbl *vq, *voptarg; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); wp += builtin_opt.optind; opts = *wp++; if (!opts) { bi_errorf("missing options argument"); - return 1; + return (1); } var = *wp++; if (!var) { bi_errorf("missing name argument"); - return 1; + return (1); } if (!*var || *skip_varname(var, true)) { bi_errorf("%s: is not an identifier", var); - return 1; + return (1); } if (e->loc->next == NULL) { internal_warningf("c_getopts: no argv"); - return 1; + return (1); } /* Which arguments are we parsing... */ if (*wp == NULL) @@ -1456,7 +1456,7 @@ c_getopts(const char **wp) (user_opt.p != 0 && user_opt.p > strlen(wp[user_opt.optind - 1]))) { bi_errorf("arguments changed since last call"); - return 1; + return (1); } user_opt.optarg = NULL; @@ -1502,7 +1502,7 @@ c_getopts(const char **wp) if (Flag(FEXPORT)) typeset(var, EXPORT, 0, 0, 0); - return optc < 0 ? 1 : rv; + return (optc < 0 ? 1 : rv); } int @@ -1522,7 +1522,7 @@ c_bind(const char **wp) macro = true; break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; @@ -1541,14 +1541,14 @@ c_bind(const char **wp) afree(up, ATEMP); } - return rv; + return (rv); } /* :, false and true */ int c_label(const char **wp) { - return wp[0][0] == 'f' ? 1 : 0; + return (wp[0][0] == 'f' ? 1 : 0); } int @@ -1560,7 +1560,7 @@ c_shift(const char **wp) const char *arg; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); arg = wp[builtin_opt.optind]; if (arg) { @@ -1579,7 +1579,7 @@ c_shift(const char **wp) l->argv[n] = l->argv[0]; l->argv += n; l->argc -= n; - return 0; + return (0); } int @@ -1596,7 +1596,7 @@ c_umask(const char **wp) symbolic = true; break; case '?': - return 1; + return (1); } cp = wp[builtin_opt.optind]; if (cp == NULL) { @@ -1628,7 +1628,7 @@ c_umask(const char **wp) new_umask = new_umask * 8 + (*cp - '0'); if (*cp) { bi_errorf("bad number"); - return 1; + return (1); } } else { /* symbolic format */ @@ -1699,7 +1699,7 @@ c_umask(const char **wp) } if (*cp) { bi_errorf("bad mask"); - return 1; + return (1); } new_umask = ~new_umask; } @@ -1751,7 +1751,7 @@ c_wait(const char **wp) int rv = 0, sig; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); wp += builtin_opt.optind; if (*wp == NULL) { while (waitfor(NULL, &sig) >= 0) @@ -1763,7 +1763,7 @@ c_wait(const char **wp) if (rv < 0) rv = sig ? sig : 127; /* magic exit code: bad job-id */ } - return rv; + return (rv); } int @@ -1783,7 +1783,7 @@ c_read(const char **wp) case 'p': if ((fd = coproc_getfd(R_OK, &emsg)) < 0) { bi_errorf("-p: %s", emsg); - return 1; + return (1); } break; case 'r': @@ -1797,11 +1797,11 @@ c_read(const char **wp) fd = 0; else if ((fd = check_fd(cp, R_OK, &emsg)) < 0) { bi_errorf("-u: %s: %s", cp, emsg); - return 1; + return (1); } break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; @@ -1912,14 +1912,14 @@ c_read(const char **wp) shf_flush(shf); bi_errorf("%s is read only", *wp); afree(wpalloc, ATEMP); - return 1; + return (1); } if (Flag(FEXPORT)) typeset(*wp, EXPORT, 0, 0, 0); if (!setstr(vp, Xstring(cs, ccp), KSH_RETURN_ERROR)) { shf_flush(shf); afree(wpalloc, ATEMP); - return 1; + return (1); } } @@ -1937,7 +1937,7 @@ c_read(const char **wp) coproc_read_close(fd); afree(wpalloc, ATEMP); - return ecode ? ecode : c == EOF; + return (ecode ? ecode : c == EOF); } int @@ -1948,7 +1948,7 @@ c_eval(const char **wp) int rv; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); s = pushs(SWORDS, ATEMP); s->u.strv = wp + builtin_opt.optind; @@ -1995,7 +1995,7 @@ c_trap(const char **wp) Trap *p; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); wp += builtin_opt.optind; if (*wp == NULL) { @@ -2005,7 +2005,7 @@ c_trap(const char **wp) print_value_quoted(p->trap); shprintf(" %s\n", p->name); } - return 0; + return (0); } /* @@ -2022,11 +2022,11 @@ c_trap(const char **wp) p = gettrap(*wp++, true); if (p == NULL) { bi_errorf("bad signal %s", wp[-1]); - return 1; + return (1); } settrap(p, s); } - return 0; + return (0); } int @@ -2036,7 +2036,7 @@ c_exitreturn(const char **wp) const char *arg; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); arg = wp[builtin_opt.optind]; if (arg) { @@ -2077,18 +2077,18 @@ c_brkcont(const char **wp) const char *arg; if (ksh_getopt(wp, &builtin_opt, null) == '?') - return 1; + return (1); arg = wp[builtin_opt.optind]; if (!arg) n = 1; else if (!bi_getn(arg, &n)) - return 1; + return (1); quit = n; if (quit <= 0) { /* at&t ksh does this for non-interactive shells only - weird */ bi_errorf("%s: bad value", arg); - return 1; + return (1); } /* Stop at E_NONE, E_PARSE, E_FUNC, or E_INCL */ @@ -2107,7 +2107,7 @@ c_brkcont(const char **wp) */ if (n == quit) { warningf(true, "%s: cannot %s", wp[0], wp[0]); - return 0; + return (0); } /* POSIX says if n is too big, the last enclosing loop * shall be used. Doesn't say to print an error but we @@ -2132,12 +2132,12 @@ c_set(const char **wp) if (wp[1] == NULL) { static const char *args [] = { "set", "-", NULL }; - return c_typeset(args); + return (c_typeset(args)); } argi = parse_args(wp, OF_SET, &setargs); if (argi < 0) - return 1; + return (1); /* set $# and $* */ if (setargs) { owp = wp += argi - 1; @@ -2145,7 +2145,7 @@ c_set(const char **wp) while (*++wp != NULL) strdupx(*wp, *wp, &l->area); l->argc = wp - owp - 1; - l->argv = alloc((l->argc + 2) * sizeof (char *), &l->area); + l->argv = alloc((l->argc + 2) * sizeof(char *), &l->area); for (wp = l->argv; (*wp++ = *owp++) != NULL; ) ; } @@ -2155,7 +2155,7 @@ c_set(const char **wp) * (subst_exstat is cleared in execute() so that it will be 0 * if there are no command substitutions). */ - return subst_exstat; + return (subst_exstat); } int @@ -2221,7 +2221,7 @@ c_times(const char **wp __unused) p_time(shl_stdout, false, usage.ru_stime.tv_sec, usage.ru_stime.tv_usec, 0, null, "\n"); - return 0; + return (0); } /* @@ -2346,7 +2346,7 @@ c_exec(const char **wp __unused) } e->savefd = NULL; } - return 0; + return (0); } #if HAVE_MKNOD @@ -2443,7 +2443,7 @@ c_mknod(const char **wp) int c_builtin(const char **wp __unused) { - return 0; + return (0); } /* test(1) accepts the following grammar: @@ -2487,7 +2487,7 @@ c_test(const char **wp) if (strcmp(wp[0], "[") == 0) { if (strcmp(wp[--argc], "]") != 0) { bi_errorf("missing ]"); - return T_ERR_EXIT; + return (T_ERR_EXIT); } } @@ -2507,7 +2507,7 @@ c_test(const char **wp) while (--argc >= 0) { if ((*te.isa)(&te, TM_END)) - return !0; + return (!0); if (argc == 3) { opnd1 = (*te.getopnd)(&te, TO_NONOP, 1); if ((op = (*te.isa)(&te, TM_BINOP))) { @@ -2515,10 +2515,10 @@ c_test(const char **wp) res = (*te.eval)(&te, op, opnd1, opnd2, 1); if (te.flags & TEF_ERROR) - return T_ERR_EXIT; + return (T_ERR_EXIT); if (invert & 1) res = !res; - return !res; + return (!res); } /* back up to opnd1 */ te.pos.wp--; @@ -2531,7 +2531,7 @@ c_test(const char **wp) NULL, 1); if (invert & 1) res = !res; - return !res; + return (!res); } if ((*te.isa)(&te, TM_NOT)) { invert++; @@ -2541,7 +2541,7 @@ c_test(const char **wp) te.pos.wp = owp + 1; } - return test_parse(&te); + return (test_parse(&te)); } /* @@ -2559,9 +2559,9 @@ test_isop(Test_meta meta, const char *s) sc1 = s[1]; for (; tbl->op_text[0]; tbl++) if (sc1 == tbl->op_text[1] && !strcmp(s, tbl->op_text)) - return tbl->op_num; + return (tbl->op_num); } - return TO_NONOP; + return (TO_NONOP); } int @@ -2574,16 +2574,16 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, mksh_ari_t v1, v2; if (!do_eval) - return 0; + return (0); switch ((int)op) { /* * Unary Operators */ case TO_STNZE: /* -n */ - return *opnd1 != '\0'; + return (*opnd1 != '\0'); case TO_STZER: /* -z */ - return *opnd1 == '\0'; + return (*opnd1 == '\0'); case TO_OPTION: /* -o */ if ((i = *opnd1 == '!')) opnd1++; @@ -2594,47 +2594,47 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, if (i) k = !k; } - return k; + return (k); case TO_FILRD: /* -r */ - return test_eaccess(opnd1, R_OK) == 0; + return (test_eaccess(opnd1, R_OK) == 0); case TO_FILWR: /* -w */ - return test_eaccess(opnd1, W_OK) == 0; + return (test_eaccess(opnd1, W_OK) == 0); case TO_FILEX: /* -x */ - return test_eaccess(opnd1, X_OK) == 0; + return (test_eaccess(opnd1, X_OK) == 0); case TO_FILAXST: /* -a */ case TO_FILEXST: /* -e */ - return stat(opnd1, &b1) == 0; + return (stat(opnd1, &b1) == 0); case TO_FILREG: /* -r */ - return stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode); + return (stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode)); case TO_FILID: /* -d */ - return stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode); + return (stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode)); case TO_FILCDEV: /* -c */ - return stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode); + return (stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode)); case TO_FILBDEV: /* -b */ - return stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode); + return (stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode)); case TO_FILFIFO: /* -p */ - return stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode); + return (stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode)); case TO_FILSYM: /* -h -L */ - return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode); + return (lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode)); case TO_FILSOCK: /* -S */ - return stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode); + return (stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode)); case TO_FILCDF:/* -H HP context dependent files (directories) */ - return 0; + return (0); case TO_FILSETU: /* -u */ - return stat(opnd1, &b1) == 0 && - (b1.st_mode & S_ISUID) == S_ISUID; + return (stat(opnd1, &b1) == 0 && + (b1.st_mode & S_ISUID) == S_ISUID); case TO_FILSETG: /* -g */ - return stat(opnd1, &b1) == 0 && - (b1.st_mode & S_ISGID) == S_ISGID; + return (stat(opnd1, &b1) == 0 && + (b1.st_mode & S_ISGID) == S_ISGID); case TO_FILSTCK: /* -k */ #ifdef S_ISVTX - return stat(opnd1, &b1) == 0 && - (b1.st_mode & S_ISVTX) == S_ISVTX; + return (stat(opnd1, &b1) == 0 && + (b1.st_mode & S_ISVTX) == S_ISVTX); #else return (0); #endif case TO_FILGZ: /* -s */ - return stat(opnd1, &b1) == 0 && b1.st_size > 0L; + return (stat(opnd1, &b1) == 0 && b1.st_size > 0L); case TO_FILTT: /* -t */ if (opnd1 && !bi_getn(opnd1, &i)) { te->flags |= TEF_ERROR; @@ -2643,24 +2643,24 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, i = isatty(opnd1 ? i : 0); return (i); case TO_FILUID: /* -O */ - return stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid; + return (stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid); case TO_FILGID: /* -G */ - return stat(opnd1, &b1) == 0 && b1.st_gid == getegid(); + return (stat(opnd1, &b1) == 0 && b1.st_gid == getegid()); /* * Binary Operators */ case TO_STEQL: /* = */ if (te->flags & TEF_DBRACKET) - return gmatchx(opnd1, opnd2, false); - return strcmp(opnd1, opnd2) == 0; + return (gmatchx(opnd1, opnd2, false)); + return (strcmp(opnd1, opnd2) == 0); case TO_STNEQ: /* != */ if (te->flags & TEF_DBRACKET) - return !gmatchx(opnd1, opnd2, false); - return strcmp(opnd1, opnd2) != 0; + return (!gmatchx(opnd1, opnd2, false)); + return (strcmp(opnd1, opnd2) != 0); case TO_STLT: /* < */ - return strcmp(opnd1, opnd2) < 0; + return (strcmp(opnd1, opnd2) < 0); case TO_STGT: /* > */ - return strcmp(opnd1, opnd2) > 0; + return (strcmp(opnd1, opnd2) > 0); case TO_INTEQ: /* -eq */ case TO_INTNE: /* -ne */ case TO_INTGE: /* -ge */ @@ -2671,7 +2671,7 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, !evaluate(opnd2, &v2, KSH_RETURN_ERROR, false)) { /* error already printed.. */ te->flags |= TEF_ERROR; - return 1; + return (1); } switch ((int)op) { case TO_INTEQ: @@ -2691,22 +2691,22 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, /* ksh88/ksh93 succeed if file2 can't be stated * (subtly different from 'does not exist'). */ - return stat(opnd1, &b1) == 0 && + return (stat(opnd1, &b1) == 0 && (((s = stat(opnd2, &b2)) == 0 && - b1.st_mtime > b2.st_mtime) || s < 0); + b1.st_mtime > b2.st_mtime) || s < 0)); case TO_FILOT: /* -ot */ /* ksh88/ksh93 succeed if file1 can't be stated * (subtly different from 'does not exist'). */ - return stat(opnd2, &b2) == 0 && + return (stat(opnd2, &b2) == 0 && (((s = stat(opnd1, &b1)) == 0 && - b1.st_mtime < b2.st_mtime) || s < 0); + b1.st_mtime < b2.st_mtime) || s < 0)); case TO_FILEQ: /* -ef */ - return stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 && - b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino; + return (stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 && + b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino); } (*te->error)(te, 0, "internal error: unknown op"); - return 1; + return (1); } /* On most/all unixen, access() says everything is executable for root... */ @@ -2726,7 +2726,7 @@ test_eaccess(const char *pathl, int mode) rv = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ? 0 : -1; } - return rv; + return (rv); } int @@ -2739,7 +2739,7 @@ test_parse(Test_env *te) if (!(te->flags & TEF_ERROR) && !(*te->isa)(te, TM_END)) (*te->error)(te, 0, "unexpected operator/operand"); - return (te->flags & TEF_ERROR) ? T_ERR_EXIT : !rv; + return ((te->flags & TEF_ERROR) ? T_ERR_EXIT : !rv); } static int @@ -2750,8 +2750,8 @@ test_oexpr(Test_env *te, bool do_eval) if ((rv = test_aexpr(te, do_eval))) do_eval = false; if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_OR)) - return test_oexpr(te, do_eval) || rv; - return rv; + return (test_oexpr(te, do_eval) || rv); + return (rv); } static int @@ -2762,16 +2762,16 @@ test_aexpr(Test_env *te, bool do_eval) if (!(rv = test_nexpr(te, do_eval))) do_eval = false; if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_AND)) - return test_aexpr(te, do_eval) && rv; - return rv; + return (test_aexpr(te, do_eval) && rv); + return (rv); } static int test_nexpr(Test_env *te, bool do_eval) { if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_NOT)) - return !test_nexpr(te, do_eval); - return test_primary(te, do_eval); + return (!test_nexpr(te, do_eval)); + return (test_primary(te, do_eval)); } static int @@ -2782,16 +2782,16 @@ test_primary(Test_env *te, bool do_eval) Test_op op; if (te->flags & TEF_ERROR) - return 0; + return (0); if ((*te->isa)(te, TM_OPAREN)) { rv = test_oexpr(te, do_eval); if (te->flags & TEF_ERROR) - return 0; + return (0); if (!(*te->isa)(te, TM_CPAREN)) { (*te->error)(te, 0, "missing closing paren"); - return 0; + return (0); } - return rv; + return (rv); } /* * Binary should have precedence over unary in this case @@ -2804,28 +2804,28 @@ test_primary(Test_env *te, bool do_eval) opnd1 = (*te->getopnd)(te, op, do_eval); if (!opnd1) { (*te->error)(te, -1, "missing argument"); - return 0; + return (0); } - return (*te->eval)(te, op, opnd1, NULL, do_eval); + return ((*te->eval)(te, op, opnd1, NULL, do_eval)); } } opnd1 = (*te->getopnd)(te, TO_NONOP, do_eval); if (!opnd1) { (*te->error)(te, 0, "expression expected"); - return 0; + return (0); } if ((op = (*te->isa)(te, TM_BINOP))) { /* binary expression */ opnd2 = (*te->getopnd)(te, op, do_eval); if (!opnd2) { (*te->error)(te, -1, "missing second argument"); - return 0; + return (0); } - return (*te->eval)(te, op, opnd1, opnd2, do_eval); + return ((*te->eval)(te, op, opnd1, opnd2, do_eval)); } - return (*te->eval)(te, TO_STNZE, opnd1, NULL, do_eval); + return ((*te->eval)(te, TO_STNZE, opnd1, NULL, do_eval)); } /* @@ -2846,7 +2846,7 @@ ptest_isa(Test_env *te, Test_meta meta) int rv; if (te->pos.wp >= te->wp_end) - return meta == TM_END; + return (meta == TM_END); if (meta == TM_UNOP || meta == TM_BINOP) rv = test_isop(meta, *te->pos.wp); @@ -2859,15 +2859,15 @@ ptest_isa(Test_env *te, Test_meta meta) if (rv) te->pos.wp++; - return rv; + return (rv); } static const char * ptest_getopnd(Test_env *te, Test_op op, bool do_eval __unused) { if (te->pos.wp >= te->wp_end) - return op == TO_FILTT ? "1" : NULL; - return *te->pos.wp++; + return (op == TO_FILTT ? "1" : NULL); + return (*te->pos.wp++); } static void diff --git a/histrap.c b/histrap.c index d0000f5..7174dd4 100644 --- a/histrap.c +++ b/histrap.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.82 2009/05/27 09:58:22 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.83 2009/06/08 20:06:46 tg Exp $"); /*- * MirOS: This is the default mapping type, and need not be specified. @@ -79,7 +79,7 @@ c_fc(const char **wp) if (!Flag(FTALKING_I)) { bi_errorf("history functions not available"); - return 1; + return (1); } while ((optc = ksh_getopt(wp, &builtin_opt, @@ -122,11 +122,11 @@ c_fc(const char **wp) last = p; else { bi_errorf("too many arguments"); - return 1; + return (1); } break; case '?': - return 1; + return (1); } wp += builtin_opt.optind; @@ -136,7 +136,7 @@ c_fc(const char **wp) if (editor || lflag || nflag || rflag) { bi_errorf("can't use -e, -l, -n, -r with -s (-e -)"); - return 1; + return (1); } /* Check for pattern replacement argument */ @@ -151,19 +151,19 @@ c_fc(const char **wp) wp++; if (last || *wp) { bi_errorf("too many arguments"); - return 1; + return (1); } hp = first ? hist_get(first, false, false) : hist_get_newest(false); if (!hp) - return 1; - return hist_replace(hp, pat, rep, gflag); + return (1); + return (hist_replace(hp, pat, rep, gflag)); } if (editor && (lflag || nflag)) { bi_errorf("can't use -l, -n with -e"); - return 1; + return (1); } if (!first && (first = *wp)) @@ -172,13 +172,13 @@ c_fc(const char **wp) wp++; if (*wp) { bi_errorf("too many arguments"); - return 1; + return (1); } if (!first) { hfirst = lflag ? hist_get("-16", true, true) : hist_get_newest(false); if (!hfirst) - return 1; + return (1); /* can't fail if hfirst didn't fail */ hlast = hist_get_newest(false); } else { @@ -189,11 +189,11 @@ c_fc(const char **wp) hfirst = hist_get(first, (lflag || last) ? true : false, lflag ? true : false); if (!hfirst) - return 1; + return (1); hlast = last ? hist_get(last, true, lflag ? true : false) : (lflag ? hist_get_newest(false) : hfirst); if (!hlast) - return 1; + return (1); } if (hfirst > hlast) { char **temp; @@ -223,7 +223,7 @@ c_fc(const char **wp) shf_fprintf(shl_stdout, "%s\n", s); } shf_flush(shl_stdout); - return 0; + return (0); } /* Run editor on selected lines, then run resulting commands */ @@ -232,14 +232,14 @@ c_fc(const char **wp) if (!(shf = tf->shf)) { bi_errorf("cannot create temp file %s - %s", tf->name, strerror(errno)); - return 1; + return (1); } for (hp = rflag ? hlast : hfirst; hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1) shf_fprintf(shf, "%s\n", *hp); if (shf_close(shf) == EOF) { bi_errorf("error writing temporary file - %s", strerror(errno)); - return 1; + return (1); } /* Ignore setstr errors here (arbitrary) */ @@ -253,7 +253,7 @@ c_fc(const char **wp) ret = command(editor ? editor : "${FCEDIT:-/bin/ed} $_"); source = sold; if (ret) - return ret; + return (ret); } { @@ -264,7 +264,7 @@ c_fc(const char **wp) if (!(shf = shf_open(tf->name, O_RDONLY, 0, 0))) { bi_errorf("cannot open temp file %s", tf->name); - return 1; + return (1); } n = stat(tf->name, &statb) < 0 ? 128 : statb.st_size + 1; @@ -278,12 +278,12 @@ c_fc(const char **wp) bi_errorf("error reading temp file %s - %s", tf->name, strerror(shf_errno(shf))); shf_close(shf); - return 1; + return (1); } shf_close(shf); *xp = '\0'; strip_nuls(Xstring(xs, xp), Xlength(xs, xp)); - return hist_execute(Xstring(xs, xp)); + return (hist_execute(Xstring(xs, xp))); } } @@ -320,7 +320,7 @@ hist_execute(char *cmd) sold = source; ret = command(cmd); source = sold; - return ret; + return (ret); } static int @@ -352,7 +352,7 @@ hist_replace(char **hp, const char *pat, const char *rep, int globr) } if (!any_subst) { bi_errorf("substitution failed"); - return 1; + return (1); } len = strlen(s) + 1; XcheckN(xs, xp, len); @@ -360,7 +360,7 @@ hist_replace(char **hp, const char *pat, const char *rep, int globr) xp += len; line = Xclose(xs, xp); } - return hist_execute(line); + return (hist_execute(line)); } /* @@ -402,7 +402,7 @@ hist_get(const char *str, int approx, int allow_cur) else hp = &history[n]; } - return hp; + return (hp); } /* Return a pointer to the newest command in the history */ @@ -411,7 +411,7 @@ hist_get_newest(int allow_cur) { if (histptr < history || (!allow_cur && histptr == history)) { bi_errorf("no history (yet)"); - return NULL; + return (NULL); } return (allow_cur ? histptr : histptr - 1); } @@ -422,9 +422,9 @@ hist_get_oldest(void) { if (histptr <= history) { bi_errorf("no history (yet)"); - return NULL; + return (NULL); } - return history; + return (history); } /******************************/ @@ -449,7 +449,7 @@ histbackup(void) char ** histpos(void) { - return current; + return (current); } int @@ -459,10 +459,10 @@ histnum(int n) if (n < 0 || n >= last) { current = histptr; - return last; + return (last); } else { current = &history[n]; - return n; + return (n); } } @@ -486,9 +486,9 @@ findhist(int start, int fwd, const char *str, int anchored) for (; hp >= history && hp <= histptr; hp += incr) if ((anchored && strncmp(*hp, str, len) == 0) || (!anchored && strstr(*hp, str))) - return hp - history; + return (hp - history); - return -1; + return (-1); } int @@ -500,15 +500,15 @@ findhistrel(const char *str) getn(str, &rec); if (rec == 0) - return -1; + return (-1); if (rec > 0) { if (rec > maxhist) - return -1; - return rec - 1; + return (-1); + return (rec - 1); } if (rec > maxhist) - return -1; - return start + rec + 1; + return (-1); + return (start + rec + 1); } /* @@ -527,7 +527,7 @@ sethistsize(int n) cursize = n; } - history = aresize(history, n * sizeof (char *), APERM); + history = aresize(history, n * sizeof(char *), APERM); histsize = n; histptr = history + cursize; @@ -578,7 +578,7 @@ init_histvec(void) { if (history == (char **)NULL) { histsize = HISTORYSIZE; - history = alloc(histsize * sizeof (char *), APERM); + history = alloc(histsize * sizeof(char *), APERM); histptr = history - 1; } } @@ -772,7 +772,7 @@ hist_count_lines(unsigned char *base, int bytes) } base++; } - return lines; + return (lines); } /* @@ -789,9 +789,9 @@ hist_shrink(unsigned char *oldbase, int oldbytes) nbase = hist_skip_back(nbase, &nbytes, histsize); if (nbase == NULL) - return 1; + return (1); if (nbase == oldbase) - return 0; + return (0); /* * create temp file @@ -845,10 +845,10 @@ hist_skip_back(unsigned char *base, int *bytes, int no) break; if (++lines == no) { *bytes = *bytes - ((char *)ep - (char *)base); - return ep; + return (ep); } } - return NULL; + return (NULL); } /* @@ -999,7 +999,7 @@ sprinkle(int fd) { static const unsigned char mag[] = { HMAGIC1, HMAGIC2 }; - return(write(fd, mag, 2) != 2); + return (write(fd, mag, 2) != 2); } #endif @@ -1174,8 +1174,8 @@ fatal_trap_check(void) for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->set && (p->flags & (TF_DFL_INTR|TF_FATAL))) /* return value is used as an exit code */ - return 128 + p->signal; - return 0; + return (128 + p->signal); + return (0); } /* Returns the signal number of any pending traps: ie, a signal which has @@ -1191,8 +1191,8 @@ trap_pending(void) for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->set && ((p->trap && p->trap[0]) || ((p->flags & (TF_DFL_INTR|TF_FATAL)) && !p->trap))) - return p->signal; - return 0; + return (p->signal); + return (0); } /* @@ -1352,7 +1352,7 @@ block_pipe(void) setsig(p, SIG_IGN, SS_RESTORE_CURR); restore_dfl = 1; /* restore to SIG_DFL */ } - return restore_dfl; + return (restore_dfl); } /* Called by c_print() to undo whatever block_pipe() did */ @@ -1372,7 +1372,7 @@ setsig(Trap *p, sig_t f, int flags) struct sigaction sigact; if (p->signal == SIGEXIT_ || p->signal == SIGERR_) - return 1; + return (1); /* First time setting this signal? If so, get and note the current * setting. @@ -1390,7 +1390,7 @@ setsig(Trap *p, sig_t f, int flags) */ if ((p->flags & TF_ORIG_IGN) && !(flags & SS_FORCE) && (!(flags & SS_USER) || !Flag(FTALKING))) - return 0; + return (0); setexecsig(p, flags & SS_RESTORE_MASK); @@ -1413,7 +1413,7 @@ setsig(Trap *p, sig_t f, int flags) sigaction(p->signal, &sigact, NULL); } - return 1; + return (1); } /* control what signal is set to before an exec() */ diff --git a/jobs.c b/jobs.c index 5b0336a..60981bb 100644 --- a/jobs.c +++ b/jobs.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.53 2009/05/16 16:59:36 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.54 2009/06/08 20:06:47 tg Exp $"); /* Order important! */ #define PRUNNING 0 @@ -346,7 +346,7 @@ exchild(struct op *t, int flags, /* Clear XFORK|XPCLOSE|XCCLOSE|XCOPROC|XPIPEO|XPIPEI|XXCOM|XBGND * (also done in another execute() below) */ - return execute(t, flags & (XEXEC | XERROK), xerrok); + return (execute(t, flags & (XEXEC | XERROK), xerrok)); /* no SIGCHLDs while messing with job and process lists */ sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); @@ -514,7 +514,7 @@ exchild(struct op *t, int flags, sigprocmask(SIG_SETMASK, &omask, NULL); - return rv; + return (rv); } /* start the last job: only used for $(command) jobs */ @@ -550,14 +550,14 @@ waitlast(void) else internal_warningf("waitlast: not started"); sigprocmask(SIG_SETMASK, &omask, NULL); - return 125; /* not so arbitrary, non-zero value */ + return (125); /* not so arbitrary, non-zero value */ } rv = j_waitj(j, JW_NONE, "jw:waitlast"); sigprocmask(SIG_SETMASK, &omask, NULL); - return rv; + return (rv); } /* wait for child, interruptable. */ @@ -584,20 +584,20 @@ waitfor(const char *cp, int *sigp) break; if (!j) { sigprocmask(SIG_SETMASK, &omask, NULL); - return -1; + return (-1); } } else if ((j = j_lookup(cp, &ecode))) { /* don't report normal job completion */ flags &= ~JW_ASYNCNOTIFY; if (j->ppid != procpid) { sigprocmask(SIG_SETMASK, &omask, NULL); - return -1; + return (-1); } } else { sigprocmask(SIG_SETMASK, &omask, NULL); if (ecode != JL_NOSUCH) bi_errorf("%s: %s", cp, lookup_msgs[ecode]); - return -1; + return (-1); } /* at&t ksh will wait for stopped jobs - we don't */ @@ -608,7 +608,7 @@ waitfor(const char *cp, int *sigp) if (rv < 0) /* we were interrupted */ *sigp = 128 + -rv; - return rv; + return (rv); } /* kill (built-in) a job */ @@ -625,7 +625,7 @@ j_kill(const char *cp, int sig) if ((j = j_lookup(cp, &ecode)) == NULL) { sigprocmask(SIG_SETMASK, &omask, NULL); bi_errorf("%s: %s", cp, lookup_msgs[ecode]); - return 1; + return (1); } if (j->pgrp == 0) { /* started when !Flag(FMONITOR) */ @@ -646,7 +646,7 @@ j_kill(const char *cp, int sig) sigprocmask(SIG_SETMASK, &omask, NULL); - return rv; + return (rv); } #ifndef MKSH_UNEMPLOYED @@ -666,13 +666,13 @@ j_resume(const char *cp, int bg) if ((j = j_lookup(cp, &ecode)) == NULL) { sigprocmask(SIG_SETMASK, &omask, NULL); bi_errorf("%s: %s", cp, lookup_msgs[ecode]); - return 1; + return (1); } if (j->pgrp == 0) { sigprocmask(SIG_SETMASK, &omask, NULL); bi_errorf("job not job-controlled"); - return 1; + return (1); } if (bg) @@ -716,7 +716,7 @@ j_resume(const char *cp, int bg) (int) ((j->flags & JF_SAVEDTTYPGRP) ? j->saved_ttypgrp : j->pgrp), strerror(rv)); - return 1; + return (1); } } j->flags |= JF_FG; @@ -740,7 +740,7 @@ j_resume(const char *cp, int bg) sigprocmask(SIG_SETMASK, &omask, NULL); bi_errorf("cannot continue job %s: %s", cp, strerror(err)); - return 1; + return (1); } if (!bg) { if (ttypgrp_ok) { @@ -749,7 +749,7 @@ j_resume(const char *cp, int bg) rv = j_waitj(j, JW_NONE, "jw:resume"); } sigprocmask(SIG_SETMASK, &omask, NULL); - return rv; + return (rv); } #endif @@ -774,10 +774,10 @@ j_stopped_running(void) which & 1 ? "stopped" : "", which == 3 ? " and " : "", which & 2 ? "running" : ""); - return 1; + return (1); } - return 0; + return (0); } int @@ -792,7 +792,7 @@ j_njobs(void) nj++; sigprocmask(SIG_SETMASK, &omask, NULL); - return nj; + return (nj); } @@ -818,7 +818,7 @@ j_jobs(const char *cp, int slp, if ((j = j_lookup(cp, &ecode)) == NULL) { sigprocmask(SIG_SETMASK, &omask, NULL); bi_errorf("%s: %s", cp, lookup_msgs[ecode]); - return 1; + return (1); } } else j = job_list; @@ -840,7 +840,7 @@ j_jobs(const char *cp, int slp, remove_job(j, "jobs"); } sigprocmask(SIG_SETMASK, &omask, NULL); - return 0; + return (0); } /* list jobs for top-level notification */ @@ -884,7 +884,7 @@ j_async(void) sigprocmask(SIG_SETMASK, &omask, NULL); - return async_pid; + return (async_pid); } /* Make j the last async process @@ -977,7 +977,7 @@ j_waitj(Job *j, } if ((flags & JW_INTERRUPT) && (rv = trap_pending())) { j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); - return -rv; + return (-rv); } } j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); @@ -1070,7 +1070,7 @@ j_waitj(Job *j, (!Flag(FMONITOR) || !(flags & JW_ASYNCNOTIFY))) remove_job(j, where); - return rv; + return (rv); } /* SIGCHLD handler to reap children and update job states @@ -1290,17 +1290,17 @@ j_print(Job *j, int how, struct shf *shf) coredumped = 0; switch (p->state) { case PRUNNING: - strlcpy(buf, "Running", sizeof buf); + strlcpy(buf, "Running", sizeof(buf)); break; case PSTOPPED: strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess, - sizeof buf); + sizeof(buf)); break; case PEXITED: if (how == JP_SHORT) buf[0] = '\0'; else if (WEXITSTATUS(p->status) == 0) - strlcpy(buf, "Done", sizeof buf); + strlcpy(buf, "Done", sizeof(buf)); else shf_snprintf(buf, sizeof(buf), "Done (%d)", WEXITSTATUS(p->status)); @@ -1319,7 +1319,7 @@ j_print(Job *j, int how, struct shf *shf) buf[0] = '\0'; } else strlcpy(buf, sigtraps[WTERMSIG(p->status)].mess, - sizeof buf); + sizeof(buf)); break; } @@ -1380,32 +1380,32 @@ j_lookup(const char *cp, int *ecodep) /* Look for last_proc->pid (what $! returns) first... */ for (j = job_list; j != NULL; j = j->next) if (j->last_proc && j->last_proc->pid == job) - return j; + return (j); /* ...then look for process group (this is non-POSIX, * but should not break anything */ for (j = job_list; j != NULL; j = j->next) if (j->pgrp && j->pgrp == job) - return j; + return (j); if (ecodep) *ecodep = JL_NOSUCH; - return NULL; + return (NULL); } if (*cp != '%') { if (ecodep) *ecodep = JL_INVALID; - return NULL; + return (NULL); } switch (*++cp) { case '\0': /* non-standard */ case '+': case '%': if (job_list != NULL) - return job_list; + return (job_list); break; case '-': if (job_list != NULL && job_list->next) - return job_list->next; + return (job_list->next); break; case '0': case '1': case '2': case '3': case '4': @@ -1413,7 +1413,7 @@ j_lookup(const char *cp, int *ecodep) getn(cp, &job); for (j = job_list; j != NULL; j = j->next) if (j->job == job) - return j; + return (j); break; case '?': /* %?string */ @@ -1424,12 +1424,12 @@ j_lookup(const char *cp, int *ecodep) if (last_match) { if (ecodep) *ecodep = JL_AMBIG; - return NULL; + return (NULL); } last_match = j; } if (last_match) - return last_match; + return (last_match); break; default: /* %string */ @@ -1440,17 +1440,17 @@ j_lookup(const char *cp, int *ecodep) if (last_match) { if (ecodep) *ecodep = JL_AMBIG; - return NULL; + return (NULL); } last_match = j; } if (last_match) - return last_match; + return (last_match); break; } if (ecodep) *ecodep = JL_NOSUCH; - return NULL; + return (NULL); } static Job *free_jobs; @@ -1470,7 +1470,7 @@ new_job(void) newj = free_jobs; free_jobs = free_jobs->next; } else - newj = alloc(sizeof (Job), APERM); + newj = alloc(sizeof(Job), APERM); /* brute force method */ for (i = 1; ; i++) { @@ -1481,7 +1481,7 @@ new_job(void) } newj->job = i; - return newj; + return (newj); } /* Allocate new process struct @@ -1497,9 +1497,9 @@ new_proc(void) p = free_procs; free_procs = free_procs->next; } else - p = alloc(sizeof (Proc), APERM); + p = alloc(sizeof(Proc), APERM); - return p; + return (p); } /* Take job out of job_list and put old structures into free list. @@ -1592,5 +1592,5 @@ kill_job(Job *j, int sig) if (p->pid != 0) if (kill(p->pid, sig) < 0) rval = -1; - return rval; + return (rval); } diff --git a/lex.c b/lex.c index 299e4c8..e43cbf1 100644 --- a/lex.c +++ b/lex.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.85 2009/05/27 19:52:36 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.86 2009/06/08 20:06:47 tg Exp $"); /* * states while lexing word @@ -791,7 +791,7 @@ yylex(int cf) dp = Xstring(ws, wp); if ((c == '<' || c == '>' || c == '&') && state == SBASE) { - struct ioword *iop = alloc(sizeof (struct ioword), ATEMP); + struct ioword *iop = alloc(sizeof(struct ioword), ATEMP); if (Xlength(ws, wp) == 0) iop->unit = c == '<' ? 0 : 1; @@ -842,7 +842,7 @@ yylex(int cf) iop->heredoc = NULL; Xfree(ws, wp); /* free word */ yylval.iop = iop; - return REDIR; + return (REDIR); no_iop: ; } @@ -879,7 +879,7 @@ yylex(int cf) yylval.cp = Xclose(ws, wp); if (state == SWORD || state == SLETPAREN || state == SLETARRAY) /* ONEWORD? */ - return LWORD; + return (LWORD); last_terminal_was_bracket = c == '('; ungetsc(c); /* unget terminator */ @@ -910,7 +910,7 @@ yylex(int cf) if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) && (!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}')) { afree(yylval.cp, ATEMP); - return p->val.i; + return (p->val.i); } if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) && (p->flag & ISSET)) { @@ -922,7 +922,7 @@ yylex(int cf) while (s->flags & SF_HASALIAS) if (s->u.tblp == p) - return LWORD; + return (LWORD); else s = s->next; /* push alias expansion */ @@ -943,7 +943,7 @@ yylex(int cf) } } - return LWORD; + return (LWORD); } static void @@ -1057,7 +1057,7 @@ pushs(int type, Area *areap) { Source *s; - s = alloc(sizeof (Source), areap); + s = alloc(sizeof(Source), areap); s->type = type; s->str = null; s->start = NULL; @@ -1071,7 +1071,7 @@ pushs(int type, Area *areap) XinitN(s->xs, 256, s->areap); else memset(&s->xs, 0, sizeof(s->xs)); - return s; + return (s); } static int @@ -1086,7 +1086,7 @@ getsc__(void) switch (s->type) { case SEOF: s->str = null; - return 0; + return (0); case SSTDIN: case SFILE: @@ -1165,7 +1165,7 @@ getsc__(void) if (s->str == NULL) { s->type = SEOF; s->start = s->str = null; - return '\0'; + return ('\0'); } if (s->flags & SF_ECHO) { shf_puts(s->str, shl_out); @@ -1183,7 +1183,7 @@ getsc__(void) goto getsc_again; } } - return c; + return (c); } static void @@ -1467,7 +1467,7 @@ get_brace_var(XString *wsp, char *wp) Xcheck(*wsp, wp); *wp++ = c; } - return wp; + return (wp); } /* @@ -1498,7 +1498,7 @@ arraysub(char **strp) *wp++ = '\0'; *strp = Xclose(ws, wp); - return depth == 0 ? 1 : 0; + return (depth == 0 ? 1 : 0); } /* Unget a char: handles case when we are already at the start of the buffer */ @@ -1509,7 +1509,7 @@ ungetsc(int c) backslash_skip--; /* Don't unget eof... */ if (source->str == null && c == '\0') - return source->str; + return (source->str); if (source->str > source->start) source->str--; else { @@ -1521,7 +1521,7 @@ ungetsc(int c) s->next = source; source = s; } - return source->str; + return (source->str); } @@ -1532,11 +1532,11 @@ getsc_bn(void) int c, c2; if (ignore_backslash_newline) - return getsc_(); + return (getsc_()); if (backslash_skip == 1) { backslash_skip = 2; - return getsc_(); + return (getsc_()); } backslash_skip = 0; @@ -1550,19 +1550,19 @@ getsc_bn(void) ungetsc(c2); backslash_skip = 1; } - return c; + return (c); } } static Lex_state * push_state_(State_info *si, Lex_state *old_end) { - Lex_state *new = alloc(STATE_BSIZE * sizeof (Lex_state), ATEMP); + Lex_state *new = alloc(STATE_BSIZE * sizeof(Lex_state), ATEMP); new[0].ls_info.base = old_end; si->base = &new[0]; si->end = &new[STATE_BSIZE]; - return &new[1]; + return (&new[1]); } static Lex_state * @@ -1575,5 +1575,5 @@ pop_state_(State_info *si, Lex_state *old_end) afree(old_base, ATEMP); - return si->base + STATE_BSIZE - 1; + return (si->base + STATE_BSIZE - 1); } diff --git a/main.c b/main.c index 9c5b046..81510c1 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.130 2009/06/07 22:28:04 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.131 2009/06/08 20:06:47 tg Exp $"); extern char **environ; @@ -423,7 +423,7 @@ main(int argc, const char *argv[]) Flag(FTRACKALL) = 1; /* set after ENV */ shell(s, true); /* doesn't return */ - return 0; + return (0); } int @@ -437,7 +437,7 @@ include(const char *name, int argc, const char **argv, int intr_ok) shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC); if (shf == NULL) - return -1; + return (-1); if (argv) { old_argv = e->loc->argv; @@ -457,13 +457,13 @@ include(const char *name, int argc, const char **argv, int intr_ok) switch (i) { case LRETURN: case LERROR: - return exstat & 0xff; /* see below */ + return (exstat & 0xff); /* see below */ case LINTR: /* intr_ok is set if we are including .profile or $ENV. * If user ^Cs out, we don't want to kill the shell... */ if (intr_ok && (exstat - 128) != SIGTERM) - return 1; + return (1); /* FALLTHRU */ case LEXIT: case LLEAVE: @@ -488,7 +488,7 @@ include(const char *name, int argc, const char **argv, int intr_ok) e->loc->argv = old_argv; e->loc->argc = old_argc; } - return i & 0xff; /* & 0xff to ensure value not -1 */ + return (i & 0xff); /* & 0xff to ensure value not -1 */ } int @@ -498,7 +498,7 @@ command(const char *comm) s = pushs(SSTRING, ATEMP); s->start = s->str = comm; - return shell(s, false); + return (shell(s, false)); } /* @@ -603,7 +603,7 @@ shell(Source * volatile s, volatile int toplevel) } quitenv(NULL); source = old_source; - return exstat; + return (exstat); } /* return to closest error handler or shell(), exit if none found */ @@ -648,7 +648,7 @@ newenv(int type) * struct env includes ALLOC_ITEM for alignment constraints * so first get the actually used memory, then assign it */ - cp = alloc(sizeof (struct env) - ALLOC_SIZE, ATEMP); + cp = alloc(sizeof(struct env) - ALLOC_SIZE, ATEMP); ep = (void *)(cp - ALLOC_SIZE); /* undo what alloc() did */ /* initialise public members of struct env (not the ALLOC_ITEM) */ ainit(&ep->area); @@ -982,8 +982,8 @@ can_seek(int fd) { struct stat statb; - return fstat(fd, &statb) == 0 && !S_ISREG(statb.st_mode) ? - SHF_UNBUF : 0; + return (fstat(fd, &statb) == 0 && !S_ISREG(statb.st_mode) ? + SHF_UNBUF : 0); } struct shf shf_iob[3]; @@ -1025,7 +1025,7 @@ savefd(int fd) if (fd < FDBASE && (nfd = fcntl(fd, F_DUPFD, FDBASE)) < 0 && errno == EBADF) - return -1; + return (-1); if (nfd < 0 || nfd > SHRT_MAX) errorf("too many files open in shell"); fcntl(nfd, F_SETFD, FD_CLOEXEC); @@ -1159,10 +1159,10 @@ coproc_getfd(int mode, const char **emsgp) int fd = (mode & R_OK) ? coproc.read : coproc.write; if (fd >= 0) - return fd; + return (fd); if (emsgp) *emsgp = "no coprocess"; - return -1; + return (-1); } /* called to close file descriptors related to the coprocess (if any) @@ -1204,7 +1204,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist) pathname = tempnam(dir, "mksh."); len = ((pathname == NULL) ? 0 : strlen(pathname)) + 1; #endif - tp = alloc(sizeof (struct temp) + len, ap); + tp = alloc(sizeof(struct temp) + len, ap); tp->name = (char *)&tp[1]; #if !HAVE_MKSTEMP if (pathname == NULL) @@ -1228,7 +1228,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist) tp->next = *tlist; *tlist = tp; - return tp; + return (tp); } #define INIT_TBLS 8 /* initial table size (power of 2) */ @@ -1243,7 +1243,7 @@ hash(const char *n) while (*n != '\0') h = 2*h + *n++; - return h * 32821; /* scatter bits */ + return (h * 32821); /* scatter bits */ } void @@ -1264,7 +1264,7 @@ texpand(struct table *tp, int nsize) struct tbl **ntblp, **otblp = tp->tbls; int osize = tp->size; - ntblp = alloc(nsize * sizeof (struct tbl *), tp->areap); + ntblp = alloc(nsize * sizeof(struct tbl *), tp->areap); for (i = 0; i < nsize; i++) ntblp[i] = NULL; tp->size = nsize; @@ -1297,18 +1297,18 @@ ktsearch(struct table *tp, const char *n, unsigned int h) struct tbl **pp, *p; if (tp->size == 0) - return NULL; + return (NULL); /* search for name in hashed table */ for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) { if (*p->name == *n && strcmp(p->name, n) == 0 && (p->flag & DEFINED)) - return p; + return (p); if (pp == tp->tbls) /* wrap */ pp += tp->size; } - return NULL; + return (NULL); } /* table */ @@ -1326,7 +1326,7 @@ ktenter(struct table *tp, const char *n, unsigned int h) /* search for name in hashed table */ for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) { if (*p->name == *n && strcmp(p->name, n) == 0) - return p; /* found */ + return (p); /* found */ if (pp == tp->tbls) /* wrap */ pp += tp->size; } @@ -1348,7 +1348,7 @@ ktenter(struct table *tp, const char *n, unsigned int h) /* enter in tp->tbls */ tp->nfree--; *pp = p; - return p; + return (p); } void @@ -1364,9 +1364,9 @@ ktnext(struct tstate *ts) while (--ts->left >= 0) { struct tbl *p = *ts->next++; if (p != NULL && (p->flag & DEFINED)) - return p; + return (p); } - return NULL; + return (NULL); } static int @@ -1384,14 +1384,14 @@ ktsort(struct table *tp) size_t i; struct tbl **p, **sp, **dp; - p = alloc((tp->size + 1) * sizeof (struct tbl *), ATEMP); + p = alloc((tp->size + 1) * sizeof(struct tbl *), ATEMP); sp = tp->tbls; /* source */ dp = p; /* dest */ for (i = 0; i < (size_t)tp->size; i++) if ((*dp = *sp++) != NULL && (((*dp)->flag & DEFINED) || ((*dp)->flag & ARRAY))) dp++; - qsort(p, (i = dp - p), sizeof (void *), tnamecmp); + qsort(p, (i = dp - p), sizeof(void *), tnamecmp); p[i] = NULL; - return p; + return (p); } diff --git a/misc.c b/misc.c index bb00899..882bff2 100644 --- a/misc.c +++ b/misc.c @@ -29,7 +29,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.108 2009/05/31 15:10:07 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.109 2009/06/08 20:06:48 tg Exp $"); #undef USE_CHVT #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) @@ -95,7 +95,7 @@ Xcheck_grow_(XString *xsp, const char *xp, unsigned int more) xsp->len += more > xsp->len ? more : xsp->len; xsp->beg = aresize(xsp->beg, xsp->len + 8, xsp->areap); xsp->end = xsp->beg + xsp->len; - return xsp->beg + (xp - old_beg); + return (xsp->beg + (xp - old_beg)); } const struct shoption options[] = { @@ -187,7 +187,7 @@ options_fmt_entry(const void *arg, int i, char *buf, int buflen) shf_snprintf(buf, buflen, "%-*s %s", oi->opt_width, options[oi->opts[i]].name, Flag(oi->opts[i]) ? "on" : "off"); - return buf; + return (buf); } static void @@ -402,7 +402,7 @@ parse_args(const char **argv, #endif case '?': - return -1; + return (-1); default: if (what == OF_FIRSTTIME) @@ -438,12 +438,12 @@ parse_args(const char **argv, if (arrayset && (!*array || *skip_varname(array, false))) { bi_errorf("%s: is not an identifier", array); - return -1; + return (-1); } if (sortargs) { for (i = go.optind; argv[i]; i++) ; - qsort(&argv[go.optind], i - go.optind, sizeof (void *), + qsort(&argv[go.optind], i - go.optind, sizeof(void *), xstrcmp); } if (arrayset) { @@ -452,7 +452,7 @@ parse_args(const char **argv, ; } - return go.optind; + return (go.optind); } /* parse a decimal number: returns 0 if string isn't a number, 1 otherwise */ @@ -516,7 +516,7 @@ gmatchx(const char *s, const char *p, bool isfile) const char *se, *pe; if (s == NULL || p == NULL) - return 0; + return (0); se = s + strlen(s); pe = p + strlen(p); @@ -528,10 +528,10 @@ gmatchx(const char *s, const char *p, bool isfile) char tbuf[64]; char *t = len <= sizeof(tbuf) ? tbuf : alloc(len, ATEMP); debunk(t, p, len); - return !strcmp(t, s); + return (!strcmp(t, s)); } - return do_gmatch((const unsigned char *) s, (const unsigned char *) se, - (const unsigned char *) p, (const unsigned char *) pe); + return (do_gmatch((const unsigned char *) s, (const unsigned char *) se, + (const unsigned char *) p, (const unsigned char *) pe)); } /* Returns if p is a syntacticly correct globbing pattern, false @@ -578,7 +578,7 @@ has_globbing(const char *xp, const char *xpe) } else if (c == ']') { if (in_bracket) { if (bnest) /* [a*(b]) */ - return 0; + return (0); in_bracket = 0; } } else if ((c & 0x80) && vstrchr("*+?@! ", c & 0x7f)) { @@ -589,18 +589,18 @@ has_globbing(const char *xp, const char *xpe) nest++; } else if (c == '|') { if (in_bracket && !bnest) /* *(a[foo|bar]) */ - return 0; + return (0); } else if (c == /*(*/ ')') { if (in_bracket) { if (!bnest--) /* *(a[b)c] */ - return 0; + return (0); } else if (nest) nest--; } /* else must be a MAGIC-MAGIC, or MAGIC-!, MAGIC--, MAGIC-] MAGIC-{, MAGIC-,, MAGIC-} */ } - return saw_glob && !in_bracket && !nest; + return (saw_glob && !in_bracket && !nest); } /* Function must return either 0 or 1 (assumed by code for 0x80|'!') */ @@ -613,36 +613,36 @@ do_gmatch(const unsigned char *s, const unsigned char *se, const unsigned char *srest; if (s == NULL || p == NULL) - return 0; + return (0); while (p < pe) { pc = *p++; sc = s < se ? *s : '\0'; s++; if (!ISMAGIC(pc)) { if (sc != pc) - return 0; + return (0); continue; } switch (*p++) { case '[': if (sc == 0 || (p = cclass(p, sc)) == NULL) - return 0; + return (0); break; case '?': if (sc == 0) - return 0; + return (0); break; case '*': if (p == pe) - return 1; + return (1); s--; do { if (do_gmatch(s, se, p, pe)) - return 1; + return (1); } while (s++ < se); - return 0; + return (0); /* * [*+?@!](pattern|pattern|..) @@ -651,12 +651,12 @@ do_gmatch(const unsigned char *s, const unsigned char *se, case 0x80|'+': /* matches one or more times */ case 0x80|'*': /* matches zero or more times */ if (!(prest = pat_scan(p, pe, 0))) - return 0; + return (0); s--; /* take care of zero matches */ if (p[-1] == (0x80 | '*') && do_gmatch(s, se, prest, pe)) - return 1; + return (1); for (psub = p; ; psub = pnext) { pnext = pat_scan(psub, pe, 1); for (srest = s; srest <= se; srest++) { @@ -664,39 +664,39 @@ do_gmatch(const unsigned char *s, const unsigned char *se, (do_gmatch(srest, se, prest, pe) || (s != srest && do_gmatch(srest, se, p - 2, pe)))) - return 1; + return (1); } if (pnext == prest) break; } - return 0; + return (0); case 0x80|'?': /* matches zero or once */ case 0x80|'@': /* matches one of the patterns */ case 0x80|' ': /* simile for @ */ if (!(prest = pat_scan(p, pe, 0))) - return 0; + return (0); s--; /* Take care of zero matches */ if (p[-1] == (0x80 | '?') && do_gmatch(s, se, prest, pe)) - return 1; + return (1); for (psub = p; ; psub = pnext) { pnext = pat_scan(psub, pe, 1); srest = prest == pe ? se : s; for (; srest <= se; srest++) { if (do_gmatch(s, srest, psub, pnext - 2) && do_gmatch(srest, se, prest, pe)) - return 1; + return (1); } if (pnext == prest) break; } - return 0; + return (0); case 0x80|'!': /* matches none of the patterns */ if (!(prest = pat_scan(p, pe, 0))) - return 0; + return (0); s--; for (srest = s; srest <= se; srest++) { int matched = 0; @@ -713,17 +713,17 @@ do_gmatch(const unsigned char *s, const unsigned char *se, } if (!matched && do_gmatch(srest, se, prest, pe)) - return 1; + return (1); } - return 0; + return (0); default: if (sc != p[-1]) - return 0; + return (0); break; } } - return s == se; + return (s == se); } static const unsigned char * @@ -747,7 +747,7 @@ cclass(const unsigned char *p, int sub) } if (c == '\0') /* No closing ] - act as if the opening [ was quoted */ - return sub == '[' ? orig_p : NULL; + return (sub == '[' ? orig_p : NULL); if (ISMAGIC(p[0]) && p[1] == '-' && (!ISMAGIC(p[2]) || p[3] != ']')) { p += 2; /* MAGIC- */ @@ -759,14 +759,14 @@ cclass(const unsigned char *p, int sub) } /* POSIX says this is an invalid expression */ if (c > d) - return NULL; + return (NULL); } else d = c; if (c == sub || (c <= sub && sub <= d)) found = 1; } while (!(ISMAGIC(p[0]) && p[1] == ']')); - return (found != not) ? p+2 : NULL; + return ((found != not) ? p+2 : NULL); } /* Look for next ) or | (if match_sep) in *(foo|bar) pattern */ @@ -844,14 +844,14 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) go->optind++; go->p = 0; go->info |= GI_MINUSMINUS; - return -1; + return (-1); } if (arg == NULL || ((flag != '-' ) && /* neither a - nor a + (if + allowed) */ (!(go->flags & GF_PLUSOPT) || flag != '+')) || (c = arg[1]) == '\0') { go->p = 0; - return -1; + return (-1); } go->optind++; go->info &= ~(GI_MINUS|GI_PLUS); @@ -870,7 +870,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) if (go->flags & GF_ERROR) bi_errorfz(); } - return '?'; + return ('?'); } /* : means argument must be present, may be part of option argument * or the next argument @@ -888,14 +888,14 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) if (optionsp[0] == ':') { go->buf[0] = c; go->optarg = go->buf; - return ':'; + return (':'); } warningf(true, "%s%s-'%c' requires argument", (go->flags & GF_NONAME) ? "" : argv[0], (go->flags & GF_NONAME) ? "" : ": ", c); if (go->flags & GF_ERROR) bi_errorfz(); - return '?'; + return ('?'); } go->p = 0; } else if (*o == ',') { @@ -921,7 +921,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) go->optarg = NULL; } } - return c; + return (c); } /* print variable/alias value using necessary quotes @@ -1061,7 +1061,7 @@ blocking_read(int fd, char *buf, int nbytes) } break; } - return ret; + return (ret); } /* Reset the non-blocking flag on the specified file descriptor. @@ -1074,13 +1074,13 @@ reset_nonblock(int fd) int flags; if ((flags = fcntl(fd, F_GETFL, 0)) < 0) - return -1; + return (-1); if (!(flags & O_NONBLOCK)) - return 0; + return (0); flags &= ~O_NONBLOCK; if (fcntl(fd, F_SETFL, flags) < 0) - return -1; - return 1; + return (-1); + return (1); } @@ -1098,7 +1098,7 @@ ksh_get_wd(size_t *dlen) if (dlen) *dlen = len; - return ret; + return (ret); } /* @@ -1183,7 +1183,7 @@ make_path(const char *cwd, const char *file, if (!use_cdpath) *cdpathp = NULL; - return rval; + return (rval); } /* @@ -1287,13 +1287,13 @@ get_phys_path(const char *pathl) xp = do_phys_path(&xs, xp, pathl); if (!xp) - return NULL; + return (NULL); if (Xlength(xs, xp) == 0) Xput(xs, xp, '/'); Xput(xs, xp, '\0'); - return Xclose(xs, xp); + return (Xclose(xs, xp)); } static char * @@ -1359,7 +1359,7 @@ chvt(const char *fn) int fd; if (*fn == '-') { - memcpy(dv, "-/dev/null", sizeof ("-/dev/null")); + memcpy(dv, "-/dev/null", sizeof("-/dev/null")); fn = dv + 1; } else { if (stat(fn, &sb)) { @@ -1415,9 +1415,9 @@ chvt(const char *fn) #ifdef DEBUG -char longsizes_are_okay[sizeof (long) == sizeof (unsigned long) ? 1 : -1]; -char arisize_is_okay[sizeof (mksh_ari_t) == 4 ? 1 : -1]; -char uarisize_is_okay[sizeof (mksh_uari_t) == 4 ? 1 : -1]; +char longsizes_are_okay[sizeof(long) == sizeof(unsigned long) ? 1 : -1]; +char arisize_is_okay[sizeof(mksh_ari_t) == 4 ? 1 : -1]; +char uarisize_is_okay[sizeof(mksh_uari_t) == 4 ? 1 : -1]; char * strchr(char *p, int ch) diff --git a/sh.h b/sh.h index 5d46cb2..4f1a07c 100644 --- a/sh.h +++ b/sh.h @@ -122,7 +122,7 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.306 2009/06/07 22:28:05 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.307 2009/06/08 20:06:48 tg Exp $"); #endif #define MKSH_VERSION "R38 2009/06/07" @@ -301,7 +301,7 @@ extern int __cdecl setegid(gid_t); # define EXTERN_DEFINED #endif -#define NELEM(a) (sizeof (a) / sizeof ((a)[0])) +#define NELEM(a) (sizeof(a) / sizeof((a)[0])) #define BIT(i) (1 << (i)) /* define bit in flag */ /* Table flag type - needs > 16 and < 32 bits */ @@ -445,7 +445,7 @@ struct lalloc { /* 2. sizes */ #define ALLOC_ITEM struct lalloc -#define ALLOC_SIZE (sizeof (ALLOC_ITEM)) +#define ALLOC_SIZE (sizeof(ALLOC_ITEM)) /* 3. group structure (only the same for lalloc.c) */ typedef struct lalloc Area; @@ -1187,7 +1187,7 @@ typedef struct XPtrV { #define XPinit(x, n) do { \ void **vp__; \ - vp__ = alloc((n) * sizeof (void *), ATEMP); \ + vp__ = alloc((n) * sizeof(void *), ATEMP); \ (x).cur = (x).beg = vp__; \ (x).end = vp__ + (n); \ } while (/* CONSTCOND */ 0) @@ -1196,7 +1196,7 @@ typedef struct XPtrV { if ((x).cur >= (x).end) { \ size_t n = XPsize(x); \ (x).beg = aresize((x).beg, \ - n * 2 * sizeof (void *), ATEMP); \ + n * 2 * sizeof(void *), ATEMP); \ (x).cur = (x).beg + n; \ (x).end = (x).cur + n; \ } \ @@ -1205,7 +1205,7 @@ typedef struct XPtrV { #define XPptrv(x) ((x).beg) #define XPsize(x) ((x).cur - (x).beg) -#define XPclose(x) aresize((x).beg, XPsize(x) * sizeof (void *), ATEMP) +#define XPclose(x) aresize((x).beg, XPsize(x) * sizeof(void *), ATEMP) #define XPfree(x) afree((x).beg, ATEMP) #define IDENT 64 diff --git a/shf.c b/shf.c index e01674f..24400e1 100644 --- a/shf.c +++ b/shf.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.28 2009/05/16 16:59:40 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.29 2009/06/08 20:06:49 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -49,7 +49,7 @@ shf_open(const char *name, int oflags, int mode, int sflags) int fd; /* Done before open so if alloca fails, fd won't be lost. */ - shf = alloc(sizeof (struct shf) + bsize, ATEMP); + shf = alloc(sizeof(struct shf) + bsize, ATEMP); shf->areap = ATEMP; shf->buf = (unsigned char *)&shf[1]; shf->bsize = bsize; @@ -59,7 +59,7 @@ shf_open(const char *name, int oflags, int mode, int sflags) fd = open(name, oflags, mode); if (fd < 0) { afree(shf, shf->areap); - return NULL; + return (NULL); } if ((sflags & SHF_MAPHI) && fd < FDBASE) { int nfd; @@ -68,7 +68,7 @@ shf_open(const char *name, int oflags, int mode, int sflags) close(fd); if (nfd < 0) { afree(shf, shf->areap); - return NULL; + return (NULL); } fd = nfd; } @@ -76,7 +76,7 @@ shf_open(const char *name, int oflags, int mode, int sflags) sflags |= (oflags & O_ACCMODE) == O_RDONLY ? SHF_RD : ((oflags & O_ACCMODE) == O_WRONLY ? SHF_WR : SHF_RDWR); - return shf_reopen(fd, sflags, shf); + return (shf_reopen(fd, sflags, shf)); } /* Set up the shf structure for a file descriptor. Doesn't fail. */ @@ -117,7 +117,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf) } else shf->buf = NULL; } else { - shf = alloc(sizeof (struct shf) + bsize, ATEMP); + shf = alloc(sizeof(struct shf) + bsize, ATEMP); shf->buf = (unsigned char *)&shf[1]; sflags |= SHF_ALLOCS; } @@ -133,7 +133,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf) shf->bsize = bsize; if (sflags & SHF_CLEXEC) fcntl(fd, F_SETFD, FD_CLOEXEC); - return shf; + return (shf); } /* Set up an existing shf (and buffer) to use the given fd */ @@ -180,7 +180,7 @@ shf_reopen(int fd, int sflags, struct shf *shf) shf->errno_ = 0; if (sflags & SHF_CLEXEC) fcntl(fd, F_SETFD, FD_CLOEXEC); - return shf; + return (shf); } /* Open a string for reading or writing. If reading, bsize is the number @@ -199,7 +199,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf) internal_errorf("shf_sopen: flags 0x%x", sflags); if (!shf) { - shf = alloc(sizeof (struct shf), ATEMP); + shf = alloc(sizeof(struct shf), ATEMP); sflags |= SHF_ALLOCS; } shf->areap = ATEMP; @@ -219,7 +219,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf) shf->errno_ = 0; shf->bsize = bsize; - return shf; + return (shf); } /* Flush and close file descriptor, free the shf structure */ @@ -238,7 +238,7 @@ shf_close(struct shf *shf) else if (shf->flags & SHF_ALLOCB) afree(shf->buf, shf->areap); - return ret; + return (ret); } /* Flush and close file descriptor, don't free file structure */ @@ -257,7 +257,7 @@ shf_fdclose(struct shf *shf) shf->fd = -1; } - return ret; + return (ret); } /* Close a string - if it was opened for writing, it is null terminated; @@ -276,7 +276,7 @@ shf_sclose(struct shf *shf) } if (shf->flags & SHF_ALLOCS) afree(shf, shf->areap); - return (char *) s; + return ((char *)s); } /* Un-read what has been read but not examined, or write what has been @@ -286,14 +286,14 @@ int shf_flush(struct shf *shf) { if (shf->flags & SHF_STRING) - return (shf->flags & SHF_WR) ? EOF : 0; + return ((shf->flags & SHF_WR) ? EOF : 0); if (shf->fd < 0) internal_errorf("shf_flush: no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; - return EOF; + return (EOF); } if (shf->flags & SHF_READING) { @@ -303,11 +303,11 @@ shf_flush(struct shf *shf) shf->rnleft = 0; shf->rp = shf->buf; } - return 0; + return (0); } else if (shf->flags & SHF_WRITING) - return shf_emptybuf(shf, 0); + return (shf_emptybuf(shf, 0)); - return 0; + return (0); } /* Write out any buffered data. If currently reading, flushes the read @@ -323,12 +323,12 @@ shf_emptybuf(struct shf *shf, int flags) if (shf->flags & SHF_ERROR) { errno = shf->errno_; - return EOF; + return (EOF); } if (shf->flags & SHF_READING) { if (flags & EB_READSW) /* doesn't happen */ - return 0; + return (0); ret = shf_flush(shf); shf->flags &= ~SHF_READING; } @@ -340,7 +340,7 @@ shf_emptybuf(struct shf *shf, int flags) */ if (!(flags & EB_GROW) || !(shf->flags & SHF_DYNAMIC) || !(shf->flags & SHF_ALLOCB)) - return EOF; + return (EOF); /* allocate more space for buffer */ nbuf = aresize(shf->buf, 2 * shf->wbsize, shf->areap); shf->rp = nbuf + (shf->rp - shf->buf); @@ -371,7 +371,7 @@ shf_emptybuf(struct shf *shf, int flags) ntowrite); shf->wp = shf->buf + ntowrite; } - return EOF; + return (EOF); } buf += n; ntowrite -= n; @@ -380,7 +380,7 @@ shf_emptybuf(struct shf *shf, int flags) shf->wp = shf->buf; shf->wnleft = 0; shf->flags &= ~SHF_WRITING; - return 0; + return (0); } } shf->wp = shf->buf; @@ -388,7 +388,7 @@ shf_emptybuf(struct shf *shf, int flags) } shf->flags |= SHF_WRITING; - return ret; + return (ret); } /* Fill up a read buffer. Returns EOF for a read error, 0 otherwise. */ @@ -396,7 +396,7 @@ static int shf_fillbuf(struct shf *shf) { if (shf->flags & SHF_STRING) - return 0; + return (0); if (shf->fd < 0) internal_errorf("shf_fillbuf: no fd"); @@ -404,11 +404,11 @@ shf_fillbuf(struct shf *shf) if (shf->flags & (SHF_EOF | SHF_ERROR)) { if (shf->flags & SHF_ERROR) errno = shf->errno_; - return EOF; + return (EOF); } if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF) - return EOF; + return (EOF); shf->flags |= SHF_READING; @@ -427,11 +427,11 @@ shf_fillbuf(struct shf *shf) shf->errno_ = errno; shf->rnleft = 0; shf->rp = shf->buf; - return EOF; + return (EOF); } shf->flags |= SHF_EOF; } - return 0; + return (0); } /* Read a buffer from shf. Returns the number of bytes read into buf, @@ -464,8 +464,8 @@ shf_read(char *buf, int bsize, struct shf *shf) shf->rnleft -= ncopy; } /* Note: fread(3S) returns 0 for errors - this doesn't */ - return orig_bsize == bsize ? (shf_error(shf) ? EOF : 0) : - orig_bsize - bsize; + return (orig_bsize == bsize ? (shf_error(shf) ? EOF : 0) : + orig_bsize - bsize); } /* Read up to a newline or EOF. The newline is put in buf; buf is always @@ -483,16 +483,16 @@ shf_getse(char *buf, int bsize, struct shf *shf) internal_errorf("shf_getse: flags %x", shf->flags); if (bsize <= 0) - return NULL; + return (NULL); --bsize; /* save room for null */ do { if (shf->rnleft == 0) { if (shf_fillbuf(shf) == EOF) - return NULL; + return (NULL); if (shf->rnleft == 0) { *buf = '\0'; - return buf == orig_buf ? NULL : buf; + return (buf == orig_buf ? NULL : buf); } } end = (unsigned char *)memchr((char *) shf->rp, '\n', @@ -507,7 +507,7 @@ shf_getse(char *buf, int bsize, struct shf *shf) bsize -= ncopy; } while (!end && bsize); *buf = '\0'; - return buf; + return (buf); } /* Returns the char read. Returns EOF for error and end of file. */ @@ -518,9 +518,9 @@ shf_getchar(struct shf *shf) internal_errorf("shf_getchar: flags %x", shf->flags); if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0)) - return EOF; + return (EOF); --shf->rnleft; - return *shf->rp++; + return (*shf->rp++); } /* Put a character back in the input stream. Returns the character if @@ -534,10 +534,10 @@ shf_ungetc(int c, struct shf *shf) if ((shf->flags & SHF_ERROR) || c == EOF || (shf->rp == shf->buf && shf->rnleft)) - return EOF; + return (EOF); if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF) - return EOF; + return (EOF); if (shf->rp == shf->buf) shf->rp = shf->buf + shf->rbsize; @@ -546,16 +546,16 @@ shf_ungetc(int c, struct shf *shf) * don't want to modify a string. */ if (shf->rp[-1] != c) - return EOF; + return (EOF); shf->flags &= ~SHF_EOF; shf->rp--; shf->rnleft++; - return c; + return (c); } shf->flags &= ~SHF_EOF; *--(shf->rp) = c; shf->rnleft++; - return c; + return (c); } /* Write a character. Returns the character if successful, EOF if @@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf) internal_errorf("shf_putchar: flags %x", shf->flags); if (c == EOF) - return EOF; + return (EOF); if (shf->flags & SHF_UNBUF) { unsigned char cc = (unsigned char)c; @@ -578,7 +578,7 @@ shf_putchar(int c, struct shf *shf) internal_errorf("shf_putchar: no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; - return EOF; + return (EOF); } while ((n = write(shf->fd, &cc, 1)) != 1) if (n < 0) { @@ -587,17 +587,17 @@ shf_putchar(int c, struct shf *shf) continue; shf->flags |= SHF_ERROR; shf->errno_ = errno; - return EOF; + return (EOF); } } else { /* Flush deals with strings and sticky errors */ if (shf->wnleft == 0 && shf_emptybuf(shf, EB_GROW) == EOF) - return EOF; + return (EOF); shf->wnleft--; *shf->wp++ = c; } - return c; + return (c); } /* Write a string. Returns the length of the string if successful, EOF if @@ -607,9 +607,9 @@ int shf_puts(const char *s, struct shf *shf) { if (!s) - return EOF; + return (EOF); - return shf_write(s, strlen(s), shf); + return (shf_write(s, strlen(s), shf)); } /* Write a buffer. Returns nbytes if successful, EOF if there is an error. */ @@ -638,7 +638,7 @@ shf_write(const char *buf, int nbytes, struct shf *shf) if (nbytes > 0) { /* Flush deals with strings and sticky errors */ if (shf_emptybuf(shf, EB_GROW) == EOF) - return EOF; + return (EOF); if (nbytes > shf->wbsize) { ncopy = nbytes; if (shf->wbsize) @@ -655,7 +655,7 @@ shf_write(const char *buf, int nbytes, struct shf *shf) shf->wnleft = 0; /* Note: fwrite(3S) returns 0 for * errors - this doesn't */ - return EOF; + return (EOF); } buf += n; ncopy -= n; @@ -668,7 +668,7 @@ shf_write(const char *buf, int nbytes, struct shf *shf) } } - return orig_nbytes; + return (orig_nbytes); } int @@ -681,7 +681,7 @@ shf_fprintf(struct shf *shf, const char *fmt, ...) n = shf_vfprintf(shf, fmt, args); va_end(args); - return n; + return (n); } int @@ -699,7 +699,7 @@ shf_snprintf(char *buf, int bsize, const char *fmt, ...) n = shf_vfprintf(&shf, fmt, args); va_end(args); shf_sclose(&shf); /* null terminates */ - return n; + return (n); } char * @@ -712,7 +712,7 @@ shf_smprintf(const char *fmt, ...) va_start(args, fmt); shf_vfprintf(&shf, fmt, args); va_end(args); - return shf_sclose(&shf); /* null terminates */ + return (shf_sclose(&shf)); /* null terminates */ } #undef FP /* if you want floating point stuff */ @@ -747,12 +747,12 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) int tmp = 0, field, precision, len, flags; unsigned long lnum; /* %#o produces the longest output */ - char numbuf[(8 * sizeof (long) + 2) / 3 + 1]; + char numbuf[(8 * sizeof(long) + 2) / 3 + 1]; /* this stuff for dealing with the buffer */ int nwritten = 0; if (!fmt) - return 0; + return (0); while ((c = *fmt++)) { if (c != '%') { @@ -853,7 +853,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) case 'u': case 'x': flags |= FL_NUMBER; - cp = numbuf + sizeof (numbuf); + cp = numbuf + sizeof(numbuf); /*- * XXX any better way to do this? * XXX hopefully the compiler optimises this out @@ -865,7 +865,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) */ if (flags & FL_LONG) lnum = va_arg(args, unsigned long); - else if ((sizeof (int) < sizeof (long)) && (c == 'd')) + else if ((sizeof(int) < sizeof(long)) && (c == 'd')) lnum = (long)va_arg(args, int); else lnum = va_arg(args, unsigned int); @@ -921,7 +921,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) } } } - len = numbuf + sizeof (numbuf) - (s = cp); + len = numbuf + sizeof(numbuf) - (s = cp); if (flags & FL_DOT) { if (precision > len) { field = precision; @@ -1011,7 +1011,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) } } - return shf_error(shf) ? EOF : nwritten; + return (shf_error(shf) ? EOF : nwritten); } #ifdef MKSH_SMALL diff --git a/syn.c b/syn.c index b24a8ec..90d4855 100644 --- a/syn.c +++ b/syn.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.35 2009/05/16 16:59:41 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.36 2009/06/08 20:06:49 tg Exp $"); struct nesting_state { int start_token; /* token than began nesting (eg, FOR) */ @@ -156,7 +156,7 @@ c_list(int multi) break; } REJECT; - return t; + return (t); } static struct ioword * @@ -191,7 +191,7 @@ synio(int cf) if (iop->flag & IOBASH) { char *cp; - nextiop = alloc(sizeof (*iop), ATEMP); + nextiop = alloc(sizeof(*iop), ATEMP); nextiop->name = cp = alloc(5, ATEMP); if (iop->unit > 9) { @@ -233,7 +233,7 @@ get_command(int cf) XPtrV args, vars; struct nesting_state old_nesting; - iops = alloc((NUFILE + 1) * sizeof (struct ioword *), ATEMP); + iops = alloc((NUFILE + 1) * sizeof(struct ioword *), ATEMP); XPinit(args, 16); XPinit(vars, 16); @@ -244,7 +244,7 @@ get_command(int cf) afree(iops, ATEMP); XPfree(args); XPfree(vars); - return NULL; /* empty line */ + return (NULL); /* empty line */ case LWORD: case REDIR: @@ -464,7 +464,7 @@ get_command(int cf) t->ioact = NULL; } else { iops[iopn++] = NULL; - iops = aresize(iops, iopn * sizeof (struct ioword *), ATEMP); + iops = aresize(iops, iopn * sizeof(struct ioword *), ATEMP); t->ioact = iops; } @@ -478,7 +478,7 @@ get_command(int cf) XPfree(vars); } - return t; + return (t); } static struct op * @@ -501,7 +501,7 @@ dogroup(void) syntaxerr(NULL); list = c_list(true); musthave(c, KEYWORD|ALIAS); - return list; + return (list); } static struct op * @@ -538,7 +538,7 @@ elsepart(void) default: REJECT; } - return NULL; + return (NULL); } static struct op * @@ -639,20 +639,20 @@ function_body(char *name, * be used as input), we pretend there is a colon here. */ t->left = newtp(TCOM); - t->left->args = alloc(2 * sizeof (char *), ATEMP); + t->left->args = alloc(2 * sizeof(char *), ATEMP); t->left->args[0] = tv = alloc(3, ATEMP); tv[0] = CHAR; tv[1] = ':'; tv[2] = EOS; t->left->args[1] = NULL; - t->left->vars = alloc(sizeof (char *), ATEMP); + t->left->vars = alloc(sizeof(char *), ATEMP); t->left->vars[0] = NULL; t->left->lineno = 1; } if (!old_func_parse) e->flags &= ~EF_FUNC_PARSE; - return t; + return (t); } static char ** @@ -666,7 +666,7 @@ wordlist(void) if ((c = token(CONTIN|KEYWORD|ALIAS)) != IN) { if (c != ';') /* non-POSIX, but at&t ksh accepts a ; here */ REJECT; - return NULL; + return (NULL); } while ((c = token(0)) == LWORD) XPput(args, yylval.cp); @@ -674,10 +674,10 @@ wordlist(void) syntaxerr(NULL); if (XPsize(args) == 0) { XPfree(args); - return NULL; + return (NULL); } else { XPput(args, NULL); - return (char **) XPclose(args); + return ((char **)XPclose(args)); } } @@ -822,7 +822,7 @@ newtp(int type) { struct op *t; - t = alloc(sizeof (struct op), ATEMP); + t = alloc(sizeof(struct op), ATEMP); t->type = type; t->u.evalflags = 0; t->args = NULL; @@ -841,7 +841,7 @@ compile(Source *s) herep = heres; source = s; yyparse(); - return outtree; + return (outtree); } /* This kludge exists to take care of sh/at&t ksh oddity in which @@ -858,11 +858,11 @@ static int assign_command(char *s) { if (!*s) - return 0; - return (strcmp(s, "alias") == 0) || + return (0); + return ((strcmp(s, "alias") == 0) || (strcmp(s, "export") == 0) || (strcmp(s, "readonly") == 0) || - (strcmp(s, "typeset") == 0); + (strcmp(s, "typeset") == 0)); } /* Check if we are in the middle of reading an alias */ @@ -871,8 +871,8 @@ inalias(struct source *s) { for (; s && s->type == SALIAS; s = s->next) if (!(s->flags & SF_ALIASEND)) - return 1; - return 0; + return (1); + return (0); } @@ -936,7 +936,7 @@ dbtestp_isa(Test_env *te, Test_meta meta) if (save) XPput(*te->pos.av, save); } - return ret; + return (ret); } static const char * @@ -945,12 +945,12 @@ dbtestp_getopnd(Test_env *te, Test_op op __unused, bool do_eval __unused) int c = tpeek(ARRAYVAR); if (c != LWORD) - return NULL; + return (NULL); ACCEPT; XPput(*te->pos.av, yylval.cp); - return null; + return (null); } static int @@ -958,7 +958,7 @@ dbtestp_eval(Test_env *te __unused, Test_op op __unused, const char *opnd1 __unused, const char *opnd2 __unused, bool do_eval __unused) { - return 1; + return (1); } static void diff --git a/tree.c b/tree.c index d27c5be..416c07c 100644 --- a/tree.c +++ b/tree.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.26 2009/05/16 16:59:41 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.27 2009/06/08 20:06:49 tg Exp $"); #define INDENT 4 @@ -440,9 +440,9 @@ tcopy(struct op *t, Area *ap) char **rw; if (t == NULL) - return NULL; + return (NULL); - r = alloc(sizeof (struct op), ap); + r = alloc(sizeof(struct op), ap); r->type = t->type; r->u.evalflags = t->u.evalflags; @@ -458,7 +458,7 @@ tcopy(struct op *t, Area *ap) for (tw = (const char **)t->vars; *tw++ != NULL; ) ; rw = r->vars = alloc((tw - (const char **)t->vars + 1) * - sizeof (*tw), ap); + sizeof(*tw), ap); for (tw = (const char **)t->vars; *tw != NULL; ) *rw++ = wdcopy(*tw++, ap); *rw = NULL; @@ -470,7 +470,7 @@ tcopy(struct op *t, Area *ap) for (tw = t->args; *tw++ != NULL; ) ; r->args = (const char **)(rw = alloc((tw - t->args + 1) * - sizeof (*tw), ap)); + sizeof(*tw), ap)); for (tw = t->args; *tw != NULL; ) *rw++ = wdcopy(*tw++, ap); *rw = NULL; @@ -482,14 +482,14 @@ tcopy(struct op *t, Area *ap) r->right = tcopy(t->right, ap); r->lineno = t->lineno; - return r; + return (r); } char * wdcopy(const char *wp, Area *ap) { size_t len = wdscan(wp, EOS) - wp; - return memcpy(alloc(len, ap), wp, len); + return (memcpy(alloc(len, ap), wp, len)); } /* return the position of prefix c in wp plus 1 */ @@ -567,7 +567,7 @@ wdstrip(const char *wp, bool keepq, bool make_magic) while (1) switch (*wp++) { case EOS: - return shf_sclose(&shf); /* null terminates */ + return (shf_sclose(&shf)); /* null terminates */ case ADELIM: case CHAR: c = *wp++; @@ -639,13 +639,13 @@ iocopy(struct ioword **iow, Area *ap) for (ior = iow; *ior++ != NULL; ) ; - ior = alloc((ior - iow + 1) * sizeof (struct ioword *), ap); + ior = alloc((ior - iow + 1) * sizeof(struct ioword *), ap); for (i = 0; iow[i] != NULL; i++) { struct ioword *p, *q; p = iow[i]; - q = alloc(sizeof (struct ioword), ap); + q = alloc(sizeof(struct ioword), ap); ior[i] = q; *q = *p; if (p->name != NULL) @@ -657,7 +657,7 @@ iocopy(struct ioword **iow, Area *ap) } ior[i] = NULL; - return ior; + return (ior); } /* diff --git a/var.c b/var.c index 3458eab..7bb278f 100644 --- a/var.c +++ b/var.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.72 2009/05/16 16:59:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.73 2009/06/08 20:06:50 tg Exp $"); /* * Variables @@ -57,7 +57,7 @@ newblock(void) struct block *l; static const char *empty[] = { null }; - l = alloc(sizeof (struct block), ATEMP); + l = alloc(sizeof(struct block), ATEMP); l->flags = 0; ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */ if (!e->loc) { @@ -159,7 +159,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp) *valp = (uint32_t)rval; afree(sub, ATEMP); } - return n; + return (n); } /* @@ -194,11 +194,11 @@ global(const char *n) /* setstr can't fail here */ setstr(vp, l->argv[c], KSH_RETURN_ERROR); vp->flag |= RDONLY; - return vp; + return (vp); } vp->flag |= RDONLY; if (n[1] != '\0') - return vp; + return (vp); vp->flag |= ISSET|INTEGER; switch (c) { case '$': @@ -222,15 +222,15 @@ global(const char *n) default: vp->flag &= ~(ISSET|INTEGER); } - return vp; + return (vp); } for (l = e->loc; ; l = l->next) { vp = ktsearch(&l->vars, n, h); if (vp != NULL) { if (array) - return arraysearch(vp, val); + return (arraysearch(vp, val)); else - return vp; + return (vp); } if (l->next == NULL) break; @@ -241,7 +241,7 @@ global(const char *n) vp->flag |= DEFINED; if (special(n)) vp->flag |= SPECIAL; - return vp; + return (vp); } /* @@ -264,7 +264,7 @@ local(const char *n, bool copy) vp->flag = DEFINED|RDONLY; vp->type = 0; vp->areap = ATEMP; - return vp; + return (vp); } vp = ktenter(&l->vars, n, h); if (copy && !(vp->flag & DEFINED)) { @@ -287,7 +287,7 @@ local(const char *n, bool copy) vp->flag |= DEFINED; if (special(n)) vp->flag |= SPECIAL; - return vp; + return (vp); } /* get variable string value */ @@ -305,7 +305,7 @@ str_val(struct tbl *vp) else { /* integer source */ /* worst case number length is when base=2, so use BITS(long) */ /* minus base # number NUL */ - char strbuf[1 + 2 + 1 + 8 * sizeof (mksh_uari_t) + 1]; + char strbuf[1 + 2 + 1 + 8 * sizeof(mksh_uari_t) + 1]; const char *digits = (vp->flag & UCASEV_AL) ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -349,7 +349,7 @@ str_val(struct tbl *vp) else strdupx(s, s, ATEMP); } - return s; + return (s); } /* get variable integer value, with error checking */ @@ -378,7 +378,7 @@ setstr(struct tbl *vq, const char *s, int error_ok) warningf(true, "%s: is read only", vq->name); if (!error_ok) errorfz(); - return 0; + return (0); } if (!(vq->flag&INTEGER)) { /* string dest */ if ((vq->flag&ALLOC)) { @@ -442,10 +442,10 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith) getspec(vp); /* XXX is it possible for ISSET to be set and val.s to be 0? */ if (!(vp->flag&ISSET) || (!(vp->flag&INTEGER) && vp->val.s == NULL)) - return -1; + return (-1); if (vp->flag&INTEGER) { *nump = vp->val.i; - return vp->type; + return (vp->type); } s = vp->val.s + vp->type; if (s == NULL) /* redundant given initial test */ @@ -493,15 +493,15 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith) else if (ksh_isupper(c)) c -= 'A' - 10; else - return -1; + return (-1); if (c < 0 || c >= base) - return -1; + return (-1); num = num * base + c; } if (neg) num = -num; *nump = num; - return base; + return (base); } /* convert variable vq to integer variable, setting its value from vp @@ -514,7 +514,7 @@ setint_v(struct tbl *vq, struct tbl *vp, bool arith) mksh_ari_t num; if ((base = getint(vp, &num, arith)) == -1) - return NULL; + return (NULL); if (!(vq->flag & INTEGER) && (vq->flag & ALLOC)) { vq->flag &= ~ALLOC; afree(vq->val.s, vq->areap); @@ -525,7 +525,7 @@ setint_v(struct tbl *vq, struct tbl *vp, bool arith) vq->flag |= ISSET|INTEGER; if (vq->flag&SPECIAL) setspec(vq); - return vq; + return (vq); } static char * @@ -601,7 +601,7 @@ formatstr(struct tbl *vp, const char *s) *q = ksh_tolower(*q); } - return p; + return (p); } /* @@ -642,13 +642,13 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) /* check for valid variable name, search for value */ val = skip_varname(var, false); if (val == var) - return NULL; + return (NULL); if (*val == '[') { int len; len = array_ref_len(val); if (len == 0) - return NULL; + return (NULL); /* IMPORT is only used when the shell starts up and is * setting up its environment. Allow only simple array * references at this time since parameter/command substitution @@ -659,7 +659,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) int i; for (i = 1; i < len - 1; i++) if (!ksh_isdigit(val[i])) - return NULL; + return (NULL); } val += len; } @@ -668,7 +668,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) else { /* Importing from original environment: must have an = */ if (set & IMPORT) - return NULL; + return (NULL); strdupx(tvar, var, ATEMP); val = NULL; } @@ -772,7 +772,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) vpbase->type == 0) export(vpbase, (vpbase->flag&ISSET) ? vpbase->val.s : null); - return vp; + return (vp); } /* Unset a variable. array_ref is set if there was an array reference in @@ -858,7 +858,7 @@ is_wdvarname(const char *s, int aok) { const char *p = skip_wdvarname(s, aok); - return p != s && p[0] == EOS; + return (p != s && p[0] == EOS); } /* Check if coded string s is a variable assignment */ @@ -867,7 +867,7 @@ is_wdvarassign(const char *s) { const char *p = skip_wdvarname(s, true); - return p != s && p[0] == CHAR && p[1] == '='; + return (p != s && p[0] == CHAR && p[1] == '='); } /* @@ -945,10 +945,10 @@ rnd_get(void) if (Flag(FARC4RANDOM)) { if (rnd_cache[0] || rnd_cache[1]) #if HAVE_ARC4RANDOM_PUSHB - rv = arc4random_pushb(rnd_cache, sizeof (rnd_cache)); + rv = arc4random_pushb(rnd_cache, sizeof(rnd_cache)); #else arc4random_addrandom((void *)rnd_cache, - sizeof (rnd_cache)); + sizeof(rnd_cache)); #endif rnd_cache[0] = rnd_cache[1] = 0; return (( @@ -967,9 +967,9 @@ rnd_set(unsigned long newval) { #if HAVE_ARC4RANDOM && defined(MKSH_SMALL) #if HAVE_ARC4RANDOM_PUSHB - arc4random_pushb(&newval, sizeof (newval)); + arc4random_pushb(&newval, sizeof(newval)); #else - arc4random_addrandom((void *)&newval, sizeof (newval)); + arc4random_addrandom((void *)&newval, sizeof(newval)); #endif #else #if HAVE_ARC4RANDOM @@ -1027,7 +1027,7 @@ special(const char *name) struct tbl *tp; tp = ktsearch(&specials, name, hash(name)); - return tp && (tp->flag & ISSET) ? tp->type : V_NONE; + return (tp && (tp->flag & ISSET) ? tp->type : V_NONE); } /* Make a variable non-special */ @@ -1244,7 +1244,7 @@ arraysearch(struct tbl *vp, uint32_t val) vp->index = 0; /* The table entry is always [0] */ if (val == 0) - return vp; + return (vp); prev = vp; curr = vp->u.array; while (curr && curr->index < val) { @@ -1253,11 +1253,11 @@ arraysearch(struct tbl *vp, uint32_t val) } if (curr && curr->index == val) { if (curr->flag&ISSET) - return curr; + return (curr); else new = curr; } else - new = alloc(sizeof (struct tbl) + namelen, vp->areap); + new = alloc(sizeof(struct tbl) + namelen, vp->areap); strlcpy(new->name, vp->name, namelen); new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL); new->type = vp->type; @@ -1268,7 +1268,7 @@ arraysearch(struct tbl *vp, uint32_t val) prev->u.array = new; new->u.array = curr; } - return new; + return (new); } /* Return the length of an array reference (eg, [1+2]) - cp is assumed @@ -1286,8 +1286,8 @@ array_ref_len(const char *cp) if (c == '[') depth++; if (!c) - return 0; - return s - cp; + return (0); + return (s - cp); } /*