static void command_indented_print (int indent, command_t c) { switch (c->type) { case AND_COMMAND: case SEQUENCE_COMMAND: case OR_COMMAND: case PIPE_COMMAND: { //printf("IN PRINT COMMAND 1: %d\n", c->type); command_indented_print (indent + 2 * (c->u.command[0]->type != c->type), c->u.command[0]); //printf("IN PRINT COMMAND 3: %d\n", c->type); if (c->u.command[1] != NULL) { //printf("IN PRINT COMMAND 4\n"); static char const command_label[][3] = { "&&", ";", "||", "|" }; printf (" \\\n%*s%s\n", indent, "", command_label[c->type]); command_indented_print (indent + 2 * (c->u.command[1]->type != c->type), c->u.command[1]); } //printf("IN PRINT COMMAND 2\n"); break; } case SIMPLE_COMMAND: { //printf("IN SIMPLE_PRINT 1\n"); char **w = c->u.word; printf ("%*s%s", indent, "", *w); while (*++w) { printf (" %s", *w); } //printf("IN SIMPLE_PRINT 2\n"); break; } case SUBSHELL_COMMAND: printf ("%*s(\n", indent, ""); command_indented_print (indent + 1, c->u.subshell_command); printf ("\n%*s)", indent, ""); break; default: abort (); } if (c->input) printf ("<%s", c->input); if (c->output) printf (">%s", c->output); }
static void command_indented_print (int indent, command_t c) { switch (c->type) { case AND_COMMAND: case SEQUENCE_COMMAND: case OR_COMMAND: case PIPE_COMMAND: { command_indented_print (indent + 2 * (c->u.command[0]->type != c->type), c->u.command[0]); static char const command_label[][3] = { "&&", ";", "||", "|" }; printf (" \\\n%*s%s\n", indent, "", command_label[c->type]); command_indented_print (indent + 2 * (c->u.command[1]->type != c->type), c->u.command[1]); break; } case SIMPLE_COMMAND: { char **w = c->u.word; printf ("%*s%s", indent, "", *w); while (*++w) printf (" %s", *w); break; } case SUBSHELL_COMMAND: printf ("%*s(\n", indent, ""); command_indented_print (indent + 1, c->u.subshell_command); printf ("\n%*s)", indent, ""); break; default: abort (); } if (c->input) printf ("<%s", c->input); if (c->output) printf (">%s", c->output); if (c->input2) printf ("<&%s", c->input2); if (c->output2) printf (">&%s", c->output2); if (c->open) printf ("<>%s", c->open); if (c->append) printf (">>%s", c->append); if (c->output_c) printf (">|%s", c->output_c); }
void print_command (command_t c) { command_indented_print (2, c); //printf("IN PRINT_COMMAND\n"); putchar ('\n'); }
void print_command (command_t c) { command_indented_print (2, c); putchar ('\n'); }
static void command_indented_print (int indent, command_t c) { switch (c->type) { case IF_COMMAND: case UNTIL_COMMAND: case WHILE_COMMAND: { printf ("%*s%sn", indent, "", (c->type == IF_COMMAND ? "if" : c->type == UNTIL_COMMAND ? "until" : "while")); command_indented_print (indent + 2, c->u.command[0]); printf ("n%*s%sn", indent, "", c->type == IF_COMMAND ? "then" : "do"); command_indented_print (indent + 2, c->u.command[1]); if (c->type == IF_COMMAND && c->u.command[2]) { printf ("n%*selsen", indent, ""); command_indented_print (indent + 2, c->u.command[2]); } printf ("n%*s%s", indent, "", c->type == IF_COMMAND ? "fi" : "done"); break; } case SEQUENCE_COMMAND: case PIPE_COMMAND: { command_indented_print (indent + 2 * (c->u.command[0]->type != c->type), c->u.command[0]); char separator = c->type == SEQUENCE_COMMAND ? ';' : '|'; printf (" \n%*s%cn", indent, "", separator); command_indented_print (indent + 2 * (c->u.command[1]->type != c->type), c->u.command[1]); break; } case SIMPLE_COMMAND: { char **w = c->u.word; printf ("%*s%s", indent, "", *w); while (*++w) printf (" %s", *w); break; } case SUBSHELL_COMMAND: { printf ("%*s(n", indent, ""); command_indented_print (indent + 1, c->u.command[0]); printf ("n%*s)", indent, ""); break; } default: abort(); } if (c->input) printf ("<%s", c->input); if (c->output) printf (">%s", c->output); }