give dumptree an dumpioact helper

This commit is contained in:
tg 2011-12-29 22:54:22 +00:00
parent dd8925a475
commit 4af399bd8d
4 changed files with 88 additions and 24 deletions

14
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.205 2011/12/16 20:03:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.206 2011/12/29 22:54:19 tg Exp $");
#if HAVE_KILLPG
/*
@ -547,7 +547,7 @@ c_whence(const char **wp)
Talias);
if (!iam_whence && !vflag)
shprintf("%s %s=", Talias, id);
print_value_quoted(tp->val.s);
print_value_quoted(shl_stdout, tp->val.s);
break;
case CFUNC:
if (vflag) {
@ -921,7 +921,7 @@ c_typeset(const char **wp)
INTEGER)
shf_puts(s, shl_stdout);
else
print_value_quoted(s);
print_value_quoted(shl_stdout, s);
}
shf_putc('\n', shl_stdout);
if (vp->flag & ARRAY)
@ -953,7 +953,7 @@ c_typeset(const char **wp)
INTEGER)
shf_puts(s, shl_stdout);
else
print_value_quoted(s);
print_value_quoted(shl_stdout, s);
}
shf_putc('\n', shl_stdout);
}
@ -1053,7 +1053,7 @@ c_alias(const char **wp)
shf_puts(ap->name, shl_stdout);
if (prefix != '+') {
shf_putc('=', shl_stdout);
print_value_quoted(ap->val.s);
print_value_quoted(shl_stdout, ap->val.s);
}
shf_putc('\n', shl_stdout);
}
@ -1078,7 +1078,7 @@ c_alias(const char **wp)
shf_puts(ap->name, shl_stdout);
if (prefix != '+') {
shf_putc('=', shl_stdout);
print_value_quoted(ap->val.s);
print_value_quoted(shl_stdout, ap->val.s);
}
shf_putc('\n', shl_stdout);
} else {
@ -2225,7 +2225,7 @@ c_trap(const char **wp)
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
if (p->trap != NULL) {
shf_puts("trap -- ", shl_stdout);
print_value_quoted(p->trap);
print_value_quoted(shl_stdout, p->trap);
shprintf(" %s\n", p->name);
}
return (0);

28
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.179 2011/12/03 00:03:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.180 2011/12/29 22:54:20 tg Exp $");
/* type bits for unsigned char */
unsigned char chtypes[UCHAR_MAX + 1];
@ -1030,7 +1030,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
* No trailing newline is printed.
*/
void
print_value_quoted(const char *s)
print_value_quoted(struct shf *shf, const char *s)
{
unsigned char c;
const unsigned char *p = (const unsigned char *)s;
@ -1047,7 +1047,7 @@ print_value_quoted(const char *s)
if (c == 0) {
if (inquote) {
/* nope, use the shortcut */
shf_puts(s, shl_stdout);
shf_puts(s, shf);
return;
}
@ -1060,29 +1060,29 @@ print_value_quoted(const char *s)
* this way than when simply substituting
*/
if (inquote) {
shf_putc('\'', shl_stdout);
shf_putc('\'', shf);
inquote = false;
}
shf_putc('\\', shl_stdout);
shf_putc('\\', shf);
} else if (!inquote) {
shf_putc('\'', shl_stdout);
shf_putc('\'', shf);
inquote = true;
}
shf_putc(c, shl_stdout);
shf_putc(c, shf);
}
} else {
unsigned int wc;
size_t n;
/* use $'...' quote format */
shf_putc('$', shl_stdout);
shf_putc('\'', shl_stdout);
shf_putc('$', shf);
shf_putc('\'', shf);
while ((c = *p) != 0) {
if (c >= 0xC2) {
n = utf_mbtowc(&wc, (const char *)p);
if (n != (size_t)-1) {
p += n;
shf_fprintf(shl_stdout, "\\u%04X", wc);
shf_fprintf(shf, "\\u%04X", wc);
continue;
}
}
@ -1122,7 +1122,7 @@ print_value_quoted(const char *s)
c = 'E';
/* FALLTHROUGH */
case '\\':
shf_putc('\\', shl_stdout);
shf_putc('\\', shf);
if (0)
/* FALLTHROUGH */
@ -1130,18 +1130,18 @@ print_value_quoted(const char *s)
if (c < 32 || c > 0x7E) {
/* FALLTHROUGH */
case '\'':
shf_fprintf(shl_stdout, "\\x%02X", c);
shf_fprintf(shf, "\\x%02X", c);
break;
}
shf_putc(c, shl_stdout);
shf_putc(c, shf);
break;
}
}
inquote = true;
}
if (inquote)
shf_putc('\'', shl_stdout);
shf_putc('\'', shf);
}
/*

5
sh.h
View File

@ -151,7 +151,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.512 2011/12/16 20:03:27 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.513 2011/12/29 22:54:21 tg Exp $");
#endif
#define MKSH_VERSION "R40 2011/12/16"
@ -1748,7 +1748,7 @@ int has_globbing(const char *, const char *);
int xstrcmp(const void *, const void *);
void ksh_getopt_reset(Getopt *, int);
int ksh_getopt(const char **, Getopt *, const char *);
void print_value_quoted(const char *);
void print_value_quoted(struct shf *, const char *);
char *quote_value(const char *);
void print_columns(struct shf *, int,
char *(*)(char *, size_t, int, const void *),
@ -1818,6 +1818,7 @@ void tfree(struct op *, Area *);
void dumpchar(struct shf *, int);
void dumptree(struct shf *, struct op *);
void dumpwdvar(struct shf *, const char *);
void dumpioact(struct shf *shf, struct op *t);
void vistree(char *, size_t, struct op *)
MKSH_A_BOUNDED(__string__, 1, 2);
void fpFUNCTf(struct shf *, int, bool, const char *, struct op *);

65
tree.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.52 2011/10/25 22:36:39 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.53 2011/12/29 22:54:22 tg Exp $");
#define INDENT 8
@ -829,6 +829,65 @@ dumpwdvar(struct shf *shf, const char *wp)
dumpwdvar_i(shf, wp, 0);
}
void
dumpioact(struct shf *shf, struct op *t)
{
struct ioword **ioact, *iop;
if ((ioact = t->ioact) == NULL)
return;
shf_puts("{IOACT", shf);
while ((iop = *ioact++) != NULL) {
int type = iop->flag & IOTYPE;
#define DT(x) case x: shf_puts(#x, shf); break;
#define DB(x) if (iop->flag & x) shf_puts("|" #x, shf);
shf_putc(';', shf);
switch (type) {
DT(IOREAD)
DT(IOWRITE)
DT(IORDWR)
DT(IOHERE)
DT(IOCAT)
DT(IODUP)
default:
shf_fprintf(shf, "unk%d", type);
}
DB(IOEVAL)
DB(IOSKIP)
DB(IOCLOB)
DB(IORDUP)
DB(IONAMEXP)
DB(IOBASH)
DB(IOHERESTR)
DB(IONDELIM)
shf_fprintf(shf, ",unit=%d", iop->unit);
if (iop->delim) {
shf_puts(",delim<", shf);
dumpwdvar(shf, iop->delim);
shf_putc('>', shf);
}
if (iop->name) {
if (iop->flag & IONAMEXP) {
shf_puts(",name=", shf);
print_value_quoted(shf, iop->name);
} else {
shf_puts(",name<", shf);
dumpwdvar(shf, iop->name);
shf_putc('>', shf);
}
}
if (iop->heredoc) {
shf_puts(",heredoc=", shf);
print_value_quoted(shf, iop->heredoc);
}
#undef DT
#undef DB
}
shf_putc('}', shf);
}
void
dumptree(struct shf *shf, struct op *t)
{
@ -845,6 +904,7 @@ dumptree(struct shf *shf, struct op *t)
name = "(null)";
goto out;
}
dumpioact(shf, t);
switch (t->type) {
#define OPEN(x) case x: name = #x; shf_puts(" {" #x ":", shf); /*}*/
@ -948,6 +1008,7 @@ dumptree(struct shf *shf, struct op *t)
++w;
}
shf_putc(')', shf);
dumpioact(shf, t);
shf_putc('\n', shf);
dumptree(shf, t1->left);
shf_fprintf(shf, " ;%c/%d]", t1->u.charflag, i++);
@ -974,6 +1035,7 @@ dumptree(struct shf *shf, struct op *t)
shf_putc('\n', shf);
dumptree(shf, t->left);
t = t->right;
dumpioact(shf, t);
if (t->left != NULL) {
shf_puts(" /TTHEN:\n", shf);
dumptree(shf, t->left);
@ -981,6 +1043,7 @@ dumptree(struct shf *shf, struct op *t)
if (t->right && t->right->type == TELIF) {
shf_puts(" /TELIF:", shf);
t = t->right;
dumpioact(shf, t);
goto dumpif;
}
if (t->right != NULL) {