run a bit of indent over it

not really suitable tho
This commit is contained in:
tg
2005-06-08 22:22:24 +00:00
parent 521da70fc8
commit d518ab0023
2 changed files with 256 additions and 262 deletions

89
edit.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/edit.c,v 1.6 2005/06/08 21:51:20 tg Exp $ */ /** $MirOS: src/bin/mksh/edit.c,v 1.7 2005/06/08 22:22:23 tg Exp $ */
/* $OpenBSD: edit.c,v 1.29 2005/04/13 02:33:08 deraadt Exp $ */ /* $OpenBSD: edit.c,v 1.29 2005/04/13 02:33:08 deraadt Exp $ */
/* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */ /* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */
/* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */
@ -10,7 +10,7 @@
#include <ctype.h> #include <ctype.h>
#include <libgen.h> #include <libgen.h>
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.6 2005/06/08 21:51:20 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.7 2005/06/08 22:22:23 tg Exp $");
#define BEL 0x07 #define BEL 0x07
@ -70,7 +70,8 @@ x_init(void)
/* default value for deficient systems */ /* default value for deficient systems */
edchars.werase = 027; /* ^W */ edchars.werase = 027; /* ^W */
if (setsig(&sigtraps[SIGWINCH], x_sigwinch, SS_RESTORE_ORIG|SS_SHTRAP)) if (setsig(&sigtraps[SIGWINCH], x_sigwinch,
SS_RESTORE_ORIG | SS_SHTRAP))
sigtraps[SIGWINCH].flags |= TF_SHELL_USES; sigtraps[SIGWINCH].flags |= TF_SHELL_USES;
check_sigwinch(); /* force initial check */ check_sigwinch(); /* force initial check */
@ -247,7 +248,6 @@ promptlen(const char *cp, const char **spp)
delimiter = *cp; delimiter = *cp;
cp += 2; cp += 2;
} }
for (; *cp; cp++) { for (; *cp; cp++) {
if (indelimit && *cp != delimiter) if (indelimit && *cp != delimiter)
; ;
@ -380,7 +380,6 @@ x_print_expansions(int nwords, char *const *words, int is_command)
XPput(l, NULL); XPput(l, NULL);
} }
} }
/* /*
* Enumerate expansions * Enumerate expansions
*/ */
@ -427,7 +426,8 @@ x_file_glob(int flags __attribute__((unused)), const char *str,
toglob[idx] = toglob[i]; toglob[idx] = toglob[i];
idx++; idx++;
if (escaping) escaping = 0; if (escaping)
escaping = 0;
} }
toglob[idx] = '\0'; toglob[idx] = '\0';
@ -534,7 +534,6 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
XPfree(w); XPfree(w);
return 0; return 0;
} }
/* Sort entries */ /* Sort entries */
if (flags & XCF_FULLPATH) { if (flags & XCF_FULLPATH) {
/* Sort by basename, then path order */ /* Sort by basename, then path order */
@ -635,7 +634,6 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
} }
*is_commandp = iscmd; *is_commandp = iscmd;
} }
*startp = start; *startp = start;
return end - start; return end - start;
@ -666,7 +664,6 @@ x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp,
*wordsp = NULL; *wordsp = NULL;
return 0; return 0;
} }
if (is_commandp) if (is_commandp)
*is_commandp = is_command; *is_commandp = is_command;
*wordsp = words; *wordsp = words;
@ -701,7 +698,7 @@ add_glob(const char *str, int slen)
if (*s == '\\' && s[1]) if (*s == '\\' && s[1])
s++; s++;
else if (*s == '*' || *s == '[' || *s == '?' || *s == '$' else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
|| (s[1] == '(' /*)*/ && strchr("*+?@!", *s))) || (s[1] == '(' && strchr("*+?@!", *s)))
break; break;
else if (*s == '/') else if (*s == '/')
saw_slash = true; saw_slash = true;
@ -710,7 +707,6 @@ add_glob(const char *str, int slen)
toglob[slen] = '*'; toglob[slen] = '*';
toglob[slen + 1] = '\0'; toglob[slen + 1] = '\0';
} }
return toglob; return toglob;
} }
@ -880,7 +876,6 @@ x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t))
rval = -1; rval = -1;
break; break;
} }
putbuf_func("\\", 1); putbuf_func("\\", 1);
putbuf_func(&s[add], 1); putbuf_func(&s[add], 1);
@ -1315,7 +1310,6 @@ x_emacs(char *buf, size_t len)
x_load_hist(histptr - off); x_load_hist(histptr - off);
x_nextcmd = -1; x_nextcmd = -1;
} }
while (1) { while (1) {
x_flush(); x_flush();
if ((c = x_e_getc()) < 0) if ((c = x_e_getc()) < 0)
@ -1325,7 +1319,6 @@ x_emacs(char *buf, size_t len)
c = META(c); c = META(c);
x_curprefix = 1; x_curprefix = 1;
} }
f = x_curprefix == -1 ? XFUNC_insert : f = x_curprefix == -1 ? XFUNC_insert :
x_tab[x_curprefix][c & CHARMASK]; x_tab[x_curprefix][c & CHARMASK];
@ -1395,7 +1388,6 @@ x_do_ins(const char *cp, int len)
x_e_putc(BEL); x_e_putc(BEL);
return -1; return -1;
} }
memmove(xcp + len, xcp, xep - xcp + 1); memmove(xcp + len, xcp, xep - xcp + 1);
memmove(xcp, cp, len); memmove(xcp, cp, len);
xcp += len; xcp += len;
@ -1424,7 +1416,6 @@ x_ins(char *s)
for (cp = xlp; cp > xcp; ) for (cp = xlp; cp > xcp; )
x_bs(*--cp); x_bs(*--cp);
} }
x_adj_ok = 1; x_adj_ok = 1;
return 0; return 0;
} }
@ -1488,7 +1479,6 @@ x_delete(int nc, int push)
else else
xmp -= nc; xmp -= nc;
} }
/* /*
* This lets us yank a word we have deleted. * This lets us yank a word we have deleted.
*/ */
@ -2290,7 +2280,6 @@ x_bind( const char *a1, const char *a2,
bi_errorf("cannot bind, not a tty"); bi_errorf("cannot bind, not a tty");
return 1; return 1;
} }
/* List function names */ /* List function names */
if (list) { if (list) {
for (f = 0; f < NELEM(x_ftab); f++) for (f = 0; f < NELEM(x_ftab); f++)
@ -2299,7 +2288,6 @@ x_bind( const char *a1, const char *a2,
shprintf("%s\n", x_ftab[f].xf_name); shprintf("%s\n", x_ftab[f].xf_name);
return 0; return 0;
} }
if (a1 == NULL) { if (a1 == NULL) {
for (prefix = 0; prefix < X_NTABS; prefix++) for (prefix = 0; prefix < X_NTABS; prefix++)
for (key = 0; key < X_TABSZ; key++) { for (key = 0; key < X_TABSZ; key++) {
@ -2311,7 +2299,6 @@ x_bind( const char *a1, const char *a2,
} }
return 0; return 0;
} }
m1 = x_mapin(a1); m1 = x_mapin(a1);
prefix = key = 0; prefix = key = 0;
for (;; m1++) { for (;; m1++) {
@ -2328,7 +2315,6 @@ x_bind( const char *a1, const char *a2,
x_print(prefix, key); x_print(prefix, key);
return 0; return 0;
} }
if (*a2 == 0) if (*a2 == 0)
f = XFUNC_insert; f = XFUNC_insert;
else if (!macro) { else if (!macro) {
@ -2569,7 +2555,6 @@ x_expand(int c __attribute__((unused)))
x_e_putc(BEL); x_e_putc(BEL);
return KSTD; return KSTD;
} }
x_goto(xbuf + start); x_goto(xbuf + start);
x_delete(end - start, false); x_delete(end - start, false);
for (i = 0; i < nwords;) { for (i = 0; i < nwords;) {
@ -2602,14 +2587,12 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
x_e_putc(BEL); x_e_putc(BEL);
return; return;
} }
if (type == CT_LIST) { if (type == CT_LIST) {
x_print_expansions(nwords, words, is_command); x_print_expansions(nwords, words, is_command);
x_redraw(0); x_redraw(0);
x_free_words(nwords, words); x_free_words(nwords, words);
return; return;
} }
olen = end - start; olen = end - start;
nlen = x_longest_prefix(nwords, words); nlen = x_longest_prefix(nwords, words);
/* complete */ /* complete */
@ -2625,12 +2608,10 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
x_ins(space); x_ins(space);
completed = 1; completed = 1;
} }
if (type == CT_COMPLIST && !completed) { if (type == CT_COMPLIST && !completed) {
x_print_expansions(nwords, words, is_command); x_print_expansions(nwords, words, is_command);
completed = 1; completed = 1;
} }
if (completed) if (completed)
x_redraw(0); x_redraw(0);
@ -3127,7 +3108,9 @@ struct macro_state {
}; };
static struct macro_state macro; static struct macro_state macro;
enum expand_mode { NONE, EXPAND, COMPLETE, PRINT }; enum expand_mode {
NONE, EXPAND, COMPLETE, PRINT
};
static enum expand_mode expanded = NONE; /* last input was expanded */ static enum expand_mode expanded = NONE; /* last input was expanded */
int int
@ -3177,7 +3160,9 @@ x_vi(char *buf, size_t len)
x_flush(); x_flush();
} }
x_putc('\r'); x_putc('\n'); x_flush(); x_putc('\r');
x_putc('\n');
x_flush();
if (c == -1 || (ssize_t)len <= es->linelen) if (c == -1 || (ssize_t)len <= es->linelen)
return -1; return -1;
@ -3694,14 +3679,16 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
case 'a': case 'a':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
if (es->linelen != 0) if (es->linelen != 0)
es->cursor++; es->cursor++;
insert = INSERT; insert = INSERT;
break; break;
case 'A': case 'A':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
del_range(0, 0); del_range(0, 0);
es->cursor = es->linelen; es->cursor = es->linelen;
insert = INSERT; insert = INSERT;
@ -3710,7 +3697,8 @@ vi_cmd(int argcnt, const char *cmd)
case 'S': case 'S':
es->cursor = domove(1, "^", 1); es->cursor = domove(1, "^", 1);
del_range(es->cursor, es->linelen); del_range(es->cursor, es->linelen);
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
insert = INSERT; insert = INSERT;
break; break;
@ -3752,13 +3740,15 @@ vi_cmd(int argcnt, const char *cmd)
es->cursor = c1; es->cursor = c1;
} }
if (*cmd == 'c') { if (*cmd == 'c') {
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
insert = INSERT; insert = INSERT;
} }
break; break;
case 'p': case 'p':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
if (es->linelen != 0) if (es->linelen != 0)
es->cursor++; es->cursor++;
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0) while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
@ -3770,7 +3760,8 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
case 'P': case 'P':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
any = 0; any = 0;
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0) while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
any = 1; any = 1;
@ -3781,7 +3772,8 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
case 'C': case 'C':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
del_range(es->cursor, es->linelen); del_range(es->cursor, es->linelen);
insert = INSERT; insert = INSERT;
break; break;
@ -3811,12 +3803,14 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
case 'i': case 'i':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
insert = INSERT; insert = INSERT;
break; break;
case 'I': case 'I':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
es->cursor = domove(1, "^", 1); es->cursor = domove(1, "^", 1);
insert = INSERT; insert = INSERT;
break; break;
@ -3846,7 +3840,8 @@ vi_cmd(int argcnt, const char *cmd)
case 'r': case 'r':
if (es->linelen == 0) if (es->linelen == 0)
return -1; return -1;
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
if (cmd[1] == 0) if (cmd[1] == 0)
vi_error(); vi_error();
else { else {
@ -3861,14 +3856,16 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
case 'R': case 'R':
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
insert = REPLACE; insert = REPLACE;
break; break;
case 's': case 's':
if (es->linelen == 0) if (es->linelen == 0)
return -1; return -1;
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
if (es->cursor + argcnt > es->linelen) if (es->cursor + argcnt > es->linelen)
argcnt = es->linelen - es->cursor; argcnt = es->linelen - es->cursor;
del_range(es->cursor, es->cursor + argcnt); del_range(es->cursor, es->cursor + argcnt);
@ -3897,7 +3894,8 @@ vi_cmd(int argcnt, const char *cmd)
case 'x': case 'x':
if (es->linelen == 0) if (es->linelen == 0)
return -1; return -1;
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
if (es->cursor + argcnt > es->linelen) if (es->cursor + argcnt > es->linelen)
argcnt = es->linelen - es->cursor; argcnt = es->linelen - es->cursor;
yank_range(es->cursor, es->cursor + argcnt); yank_range(es->cursor, es->cursor + argcnt);
@ -3906,7 +3904,8 @@ vi_cmd(int argcnt, const char *cmd)
case 'X': case 'X':
if (es->cursor > 0) { if (es->cursor > 0) {
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
if (es->cursor < argcnt) if (es->cursor < argcnt)
argcnt = es->cursor; argcnt = es->cursor;
yank_range(es->cursor - argcnt, es->cursor); yank_range(es->cursor - argcnt, es->cursor);
@ -4860,7 +4859,8 @@ expand_word(int cmd)
i = buf->cursor - end; i = buf->cursor - end;
if (rval == 0 && i > 0) if (rval == 0 && i > 0)
es->cursor += i; es->cursor += i;
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
insert = INSERT; insert = INSERT;
lastac = 0; lastac = 0;
refresh(0); refresh(0);
@ -4964,7 +4964,8 @@ complete_word(int cmd, int count)
} }
x_free_words(nwords, words); x_free_words(nwords, words);
modified = 1; hnum = hlast; modified = 1;
hnum = hlast;
insert = INSERT; insert = INSERT;
lastac = 0; /* prevent this from being redone... */ lastac = 0; /* prevent this from being redone... */
refresh(0); refresh(0);

15
main.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/main.c,v 1.11 2005/06/08 21:51:21 tg Exp $ */ /** $MirOS: src/bin/mksh/main.c,v 1.12 2005/06/08 22:22:24 tg Exp $ */
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
@ -13,7 +13,7 @@
#include <time.h> #include <time.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.11 2005/06/08 21:51:21 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.12 2005/06/08 22:22:24 tg Exp $");
const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/06/08"; const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/06/08";
@ -254,7 +254,8 @@ main(int argc, char *argv[])
} else if (argi < argc && !Flag(FSTDIN)) { } else if (argi < argc && !Flag(FSTDIN)) {
s = pushs(SFILE, ATEMP); s = pushs(SFILE, ATEMP);
s->file = kshname = argv[argi++]; s->file = kshname = argv[argi++];
s->u.shf = shf_open(s->file, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC); s->u.shf = shf_open(s->file, O_RDONLY, 0,
SHF_MAPHI | SHF_CLEXEC);
if (s->u.shf == NULL) { if (s->u.shf == NULL) {
exstat = 127; /* POSIX */ exstat = 127; /* POSIX */
errorf("%s: %s", s->file, strerror(errno)); errorf("%s: %s", s->file, strerror(errno));
@ -315,7 +316,6 @@ main(int argc, char *argv[])
include(substitute("$HOME/.profile", 0), 0, include(substitute("$HOME/.profile", 0), 0,
NULL, 1); NULL, 1);
} }
if (Flag(FPRIVILEGED)) if (Flag(FPRIVILEGED))
include("/etc/suid_profile", 0, NULL, 1); include("/etc/suid_profile", 0, NULL, 1);
else { else {
@ -483,7 +483,6 @@ shell(Source *volatile s, volatile int toplevel)
/*NOREACHED*/ /*NOREACHED*/
} }
} }
while (1) { while (1) {
if (trap) if (trap)
runtraps(0); runtraps(0);
@ -494,12 +493,10 @@ shell(Source *volatile s, volatile int toplevel)
else else
s->flags &= ~SF_ECHO; s->flags &= ~SF_ECHO;
} }
if (interactive) { if (interactive) {
j_notify(); j_notify();
set_prompt(PS1, s); set_prompt(PS1, s);
} }
t = compile(s); t = compile(s);
if (t != NULL && t->type == TEOF) { if (t != NULL && t->type == TEOF) {
if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { if (wastty && Flag(FIGNOREEOF) && --attempts > 0) {
@ -520,7 +517,6 @@ shell(Source *volatile s, volatile int toplevel)
break; break;
} }
} }
if (t && (!Flag(FNOEXEC) || (s->flags & SF_TTY))) if (t && (!Flag(FNOEXEC) || (s->flags & SF_TTY)))
exstat = execute(t, 0); exstat = execute(t, 0);
@ -600,7 +596,6 @@ quitenv(struct shf *shf)
if (ep->savefd[2]) /* Clear any write errors */ if (ep->savefd[2]) /* Clear any write errors */
shf_reopen(2, SHF_WR, shl_out); shf_reopen(2, SHF_WR, shl_out);
} }
/* Bottom of the stack. /* Bottom of the stack.
* Either main shell is exiting or cleanup_parents_env() was called. * Either main shell is exiting or cleanup_parents_env() was called.
*/ */
@ -736,7 +731,6 @@ tty_init(int init_ttystate)
strerror(errno)); strerror(errno));
} }
} }
if (tfd < 0) { if (tfd < 0) {
do_close = 0; do_close = 0;
if (isatty(0)) if (isatty(0))
@ -1230,7 +1224,6 @@ tenter(struct table *tp, const char *n, unsigned int h)
texpand(tp, 2 * tp->size); texpand(tp, 2 * tp->size);
goto Search; goto Search;
} }
/* create new tbl entry */ /* create new tbl entry */
len = strlen(n) + 1; len = strlen(n) + 1;
p = (struct tbl *)alloc(offsetof(struct tbl, name[0])+len, p = (struct tbl *)alloc(offsetof(struct tbl, name[0])+len,