give dumptree an dumpioact helper
This commit is contained in:
parent
dd8925a475
commit
4af399bd8d
14
funcs.c
14
funcs.c
|
@ -38,7 +38,7 @@
|
||||||
#endif
|
#endif
|
||||||
#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
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
|
@ -547,7 +547,7 @@ c_whence(const char **wp)
|
||||||
Talias);
|
Talias);
|
||||||
if (!iam_whence && !vflag)
|
if (!iam_whence && !vflag)
|
||||||
shprintf("%s %s=", Talias, id);
|
shprintf("%s %s=", Talias, id);
|
||||||
print_value_quoted(tp->val.s);
|
print_value_quoted(shl_stdout, tp->val.s);
|
||||||
break;
|
break;
|
||||||
case CFUNC:
|
case CFUNC:
|
||||||
if (vflag) {
|
if (vflag) {
|
||||||
|
@ -921,7 +921,7 @@ c_typeset(const char **wp)
|
||||||
INTEGER)
|
INTEGER)
|
||||||
shf_puts(s, shl_stdout);
|
shf_puts(s, shl_stdout);
|
||||||
else
|
else
|
||||||
print_value_quoted(s);
|
print_value_quoted(shl_stdout, s);
|
||||||
}
|
}
|
||||||
shf_putc('\n', shl_stdout);
|
shf_putc('\n', shl_stdout);
|
||||||
if (vp->flag & ARRAY)
|
if (vp->flag & ARRAY)
|
||||||
|
@ -953,7 +953,7 @@ c_typeset(const char **wp)
|
||||||
INTEGER)
|
INTEGER)
|
||||||
shf_puts(s, shl_stdout);
|
shf_puts(s, shl_stdout);
|
||||||
else
|
else
|
||||||
print_value_quoted(s);
|
print_value_quoted(shl_stdout, s);
|
||||||
}
|
}
|
||||||
shf_putc('\n', shl_stdout);
|
shf_putc('\n', shl_stdout);
|
||||||
}
|
}
|
||||||
|
@ -1053,7 +1053,7 @@ c_alias(const char **wp)
|
||||||
shf_puts(ap->name, shl_stdout);
|
shf_puts(ap->name, shl_stdout);
|
||||||
if (prefix != '+') {
|
if (prefix != '+') {
|
||||||
shf_putc('=', shl_stdout);
|
shf_putc('=', shl_stdout);
|
||||||
print_value_quoted(ap->val.s);
|
print_value_quoted(shl_stdout, ap->val.s);
|
||||||
}
|
}
|
||||||
shf_putc('\n', shl_stdout);
|
shf_putc('\n', shl_stdout);
|
||||||
}
|
}
|
||||||
|
@ -1078,7 +1078,7 @@ c_alias(const char **wp)
|
||||||
shf_puts(ap->name, shl_stdout);
|
shf_puts(ap->name, shl_stdout);
|
||||||
if (prefix != '+') {
|
if (prefix != '+') {
|
||||||
shf_putc('=', shl_stdout);
|
shf_putc('=', shl_stdout);
|
||||||
print_value_quoted(ap->val.s);
|
print_value_quoted(shl_stdout, ap->val.s);
|
||||||
}
|
}
|
||||||
shf_putc('\n', shl_stdout);
|
shf_putc('\n', shl_stdout);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2225,7 +2225,7 @@ c_trap(const char **wp)
|
||||||
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
|
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
|
||||||
if (p->trap != NULL) {
|
if (p->trap != NULL) {
|
||||||
shf_puts("trap -- ", shl_stdout);
|
shf_puts("trap -- ", shl_stdout);
|
||||||
print_value_quoted(p->trap);
|
print_value_quoted(shl_stdout, p->trap);
|
||||||
shprintf(" %s\n", p->name);
|
shprintf(" %s\n", p->name);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
28
misc.c
28
misc.c
|
@ -29,7 +29,7 @@
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#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 */
|
/* type bits for unsigned char */
|
||||||
unsigned char chtypes[UCHAR_MAX + 1];
|
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.
|
* No trailing newline is printed.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
print_value_quoted(const char *s)
|
print_value_quoted(struct shf *shf, const char *s)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
const unsigned char *p = (const unsigned char *)s;
|
const unsigned char *p = (const unsigned char *)s;
|
||||||
|
@ -1047,7 +1047,7 @@ print_value_quoted(const char *s)
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
if (inquote) {
|
if (inquote) {
|
||||||
/* nope, use the shortcut */
|
/* nope, use the shortcut */
|
||||||
shf_puts(s, shl_stdout);
|
shf_puts(s, shf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,29 +1060,29 @@ print_value_quoted(const char *s)
|
||||||
* this way than when simply substituting
|
* this way than when simply substituting
|
||||||
*/
|
*/
|
||||||
if (inquote) {
|
if (inquote) {
|
||||||
shf_putc('\'', shl_stdout);
|
shf_putc('\'', shf);
|
||||||
inquote = false;
|
inquote = false;
|
||||||
}
|
}
|
||||||
shf_putc('\\', shl_stdout);
|
shf_putc('\\', shf);
|
||||||
} else if (!inquote) {
|
} else if (!inquote) {
|
||||||
shf_putc('\'', shl_stdout);
|
shf_putc('\'', shf);
|
||||||
inquote = true;
|
inquote = true;
|
||||||
}
|
}
|
||||||
shf_putc(c, shl_stdout);
|
shf_putc(c, shf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned int wc;
|
unsigned int wc;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
/* use $'...' quote format */
|
/* use $'...' quote format */
|
||||||
shf_putc('$', shl_stdout);
|
shf_putc('$', shf);
|
||||||
shf_putc('\'', shl_stdout);
|
shf_putc('\'', shf);
|
||||||
while ((c = *p) != 0) {
|
while ((c = *p) != 0) {
|
||||||
if (c >= 0xC2) {
|
if (c >= 0xC2) {
|
||||||
n = utf_mbtowc(&wc, (const char *)p);
|
n = utf_mbtowc(&wc, (const char *)p);
|
||||||
if (n != (size_t)-1) {
|
if (n != (size_t)-1) {
|
||||||
p += n;
|
p += n;
|
||||||
shf_fprintf(shl_stdout, "\\u%04X", wc);
|
shf_fprintf(shf, "\\u%04X", wc);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1122,7 +1122,7 @@ print_value_quoted(const char *s)
|
||||||
c = 'E';
|
c = 'E';
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case '\\':
|
case '\\':
|
||||||
shf_putc('\\', shl_stdout);
|
shf_putc('\\', shf);
|
||||||
|
|
||||||
if (0)
|
if (0)
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
|
@ -1130,18 +1130,18 @@ print_value_quoted(const char *s)
|
||||||
if (c < 32 || c > 0x7E) {
|
if (c < 32 || c > 0x7E) {
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case '\'':
|
case '\'':
|
||||||
shf_fprintf(shl_stdout, "\\x%02X", c);
|
shf_fprintf(shf, "\\x%02X", c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
shf_putc(c, shl_stdout);
|
shf_putc(c, shf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inquote = true;
|
inquote = true;
|
||||||
}
|
}
|
||||||
if (inquote)
|
if (inquote)
|
||||||
shf_putc('\'', shl_stdout);
|
shf_putc('\'', shf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
5
sh.h
5
sh.h
|
@ -151,7 +151,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R40 2011/12/16"
|
#define MKSH_VERSION "R40 2011/12/16"
|
||||||
|
|
||||||
|
@ -1748,7 +1748,7 @@ int has_globbing(const char *, const char *);
|
||||||
int xstrcmp(const void *, const void *);
|
int xstrcmp(const void *, const void *);
|
||||||
void ksh_getopt_reset(Getopt *, int);
|
void ksh_getopt_reset(Getopt *, int);
|
||||||
int ksh_getopt(const char **, Getopt *, const char *);
|
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 *);
|
char *quote_value(const char *);
|
||||||
void print_columns(struct shf *, int,
|
void print_columns(struct shf *, int,
|
||||||
char *(*)(char *, size_t, int, const void *),
|
char *(*)(char *, size_t, int, const void *),
|
||||||
|
@ -1818,6 +1818,7 @@ void tfree(struct op *, Area *);
|
||||||
void dumpchar(struct shf *, int);
|
void dumpchar(struct shf *, int);
|
||||||
void dumptree(struct shf *, struct op *);
|
void dumptree(struct shf *, struct op *);
|
||||||
void dumpwdvar(struct shf *, const char *);
|
void dumpwdvar(struct shf *, const char *);
|
||||||
|
void dumpioact(struct shf *shf, struct op *t);
|
||||||
void vistree(char *, size_t, struct op *)
|
void vistree(char *, size_t, struct op *)
|
||||||
MKSH_A_BOUNDED(__string__, 1, 2);
|
MKSH_A_BOUNDED(__string__, 1, 2);
|
||||||
void fpFUNCTf(struct shf *, int, bool, const char *, struct op *);
|
void fpFUNCTf(struct shf *, int, bool, const char *, struct op *);
|
||||||
|
|
65
tree.c
65
tree.c
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "sh.h"
|
#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
|
#define INDENT 8
|
||||||
|
|
||||||
|
@ -829,6 +829,65 @@ dumpwdvar(struct shf *shf, const char *wp)
|
||||||
dumpwdvar_i(shf, wp, 0);
|
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
|
void
|
||||||
dumptree(struct shf *shf, struct op *t)
|
dumptree(struct shf *shf, struct op *t)
|
||||||
{
|
{
|
||||||
|
@ -845,6 +904,7 @@ dumptree(struct shf *shf, struct op *t)
|
||||||
name = "(null)";
|
name = "(null)";
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
dumpioact(shf, t);
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
#define OPEN(x) case x: name = #x; shf_puts(" {" #x ":", shf); /*}*/
|
#define OPEN(x) case x: name = #x; shf_puts(" {" #x ":", shf); /*}*/
|
||||||
|
|
||||||
|
@ -948,6 +1008,7 @@ dumptree(struct shf *shf, struct op *t)
|
||||||
++w;
|
++w;
|
||||||
}
|
}
|
||||||
shf_putc(')', shf);
|
shf_putc(')', shf);
|
||||||
|
dumpioact(shf, t);
|
||||||
shf_putc('\n', shf);
|
shf_putc('\n', shf);
|
||||||
dumptree(shf, t1->left);
|
dumptree(shf, t1->left);
|
||||||
shf_fprintf(shf, " ;%c/%d]", t1->u.charflag, i++);
|
shf_fprintf(shf, " ;%c/%d]", t1->u.charflag, i++);
|
||||||
|
@ -974,6 +1035,7 @@ dumptree(struct shf *shf, struct op *t)
|
||||||
shf_putc('\n', shf);
|
shf_putc('\n', shf);
|
||||||
dumptree(shf, t->left);
|
dumptree(shf, t->left);
|
||||||
t = t->right;
|
t = t->right;
|
||||||
|
dumpioact(shf, t);
|
||||||
if (t->left != NULL) {
|
if (t->left != NULL) {
|
||||||
shf_puts(" /TTHEN:\n", shf);
|
shf_puts(" /TTHEN:\n", shf);
|
||||||
dumptree(shf, t->left);
|
dumptree(shf, t->left);
|
||||||
|
@ -981,6 +1043,7 @@ dumptree(struct shf *shf, struct op *t)
|
||||||
if (t->right && t->right->type == TELIF) {
|
if (t->right && t->right->type == TELIF) {
|
||||||
shf_puts(" /TELIF:", shf);
|
shf_puts(" /TELIF:", shf);
|
||||||
t = t->right;
|
t = t->right;
|
||||||
|
dumpioact(shf, t);
|
||||||
goto dumpif;
|
goto dumpif;
|
||||||
}
|
}
|
||||||
if (t->right != NULL) {
|
if (t->right != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue