/*************************************************************************** * Read and process output from the application ***************************************************************************/ void get_token() { unsigned int c; /* magic token GCC_NULL is 0x100 so need an int*/ /* somewhat changed. Matthias */ /* Wait for something to do! */ c = get_com_char(0); do { /* Got a character. Figure out what to do with it. */ if(c>=' ' || c == '\n' || c == '\r' || c == '\t') read_string(); else { switch(c) { case 0: /* NUL does nothing */ break; case EOF: clean_exit(0); break; case 5: cprintf("\033[?1;2c");/* I'm a VT100 w/ advanced video options */ break; case 0xb: scr_index(1); break; case 0xc: scr_index(1); break; case ESC: process_escape_sequence(); break; case '\b' : scr_backspace(); break; case '\007' : /* bell */ #ifdef MAPALERT if (map_alert) XMapWindow(display,main_win); #endif XBell(display,0); break; case '\016': scr_choose_charset(1); break; case '\017': scr_choose_charset(0); break; } } c = get_com_char(1); }while(c != (unsigned int) GCC_NULL); }
static int do_echo(struct command *cmdtp, int argc, char *argv[]) { int i, optind = 1; int fd = stdout, opt, newline = 1; char *file = NULL; int oflags = O_WRONLY | O_CREAT; #ifdef CONFIG_CMD_ECHO_E char str[CONFIG_CBSIZE]; int process_escape = 0; #endif /* We can't use getopt() here because we want to * echo all things we don't understand. */ while (optind < argc && *argv[optind] == '-') { if (!*(argv[optind] + 1) || *(argv[optind] + 2)) break; opt = *(argv[optind] + 1); switch (opt) { case 'n': newline = 0; break; case 'a': oflags |= O_APPEND; if (optind + 1 < argc) file = argv[optind + 1]; else goto no_optarg_out; optind++; break; case 'o': oflags |= O_TRUNC; file = argv[optind + 1]; if (optind + 1 < argc) file = argv[optind + 1]; else goto no_optarg_out; optind++; break; #ifdef CONFIG_CMD_ECHO_E case 'e': process_escape = 1; break; #endif default: goto exit_parse; } optind++; } exit_parse: if (file) { fd = open(file, oflags); if (fd < 0) { perror("open"); return 1; } } for (i = optind; i < argc; i++) { if (i > optind) fputc(fd, ' '); #ifdef CONFIG_CMD_ECHO_E if (process_escape) { process_escape_sequence(argv[i], str, CONFIG_CBSIZE); fputs(fd, str); } else #endif fputs(fd, argv[i]); } if (newline) fputc(fd, '\n'); if (file) close(fd); return 0; no_optarg_out: printf("option requires an argument -- %c\n", opt); return 1; }