source: trunk/minix/commands/ash/bltin/echo.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1/*
2 * Echo command.
3 *
4 * Copyright (C) 1989 by Kenneth Almquist. All rights reserved.
5 * This file is part of ash, which is distributed under the terms specified
6 * by the Ash General Public License. See the file named LICENSE.
7 */
8
9#define main echocmd
10
11#include "bltin.h"
12
13#undef eflag
14
15
16main(argc, argv) char **argv; {
17 register char **ap;
18 register char *p;
19 register char c;
20 int count;
21 int nflag = 0;
22#ifndef eflag
23 int eflag = 0;
24#endif
25
26 ap = argv;
27 if (argc)
28 ap++;
29 if ((p = *ap) != NULL) {
30 if (equal(p, "--")) {
31 ap++;
32 }
33 if (equal(p, "-n")) {
34 nflag++;
35 ap++;
36 } else if (equal(p, "-e")) {
37#ifndef eflag
38 eflag++;
39#endif
40 ap++;
41 }
42 }
43 while ((p = *ap++) != NULL) {
44 while ((c = *p++) != '\0') {
45 if (c == '\\' && eflag) {
46 switch (*p++) {
47 case 'b': c = '\b'; break;
48 case 'c': return 0; /* exit */
49 case 'f': c = '\f'; break;
50 case 'n': c = '\n'; break;
51 case 'r': c = '\r'; break;
52 case 't': c = '\t'; break;
53 case 'v': c = '\v'; break;
54 case '\\': break; /* c = '\\' */
55 case '0':
56 c = 0;
57 count = 3;
58 while (--count >= 0 && (unsigned)(*p - '0') < 8)
59 c = (c << 3) + (*p++ - '0');
60 break;
61 default:
62 p--;
63 break;
64 }
65 }
66 putchar(c);
67 }
68 if (*ap)
69 putchar(' ');
70 }
71 if (! nflag)
72 putchar('\n');
73 return 0;
74}
Note: See TracBrowser for help on using the repository browser.