use syslog instead of writing directly to stderr
[unix-history] / usr / src / bin / sh / bltin / echo.c
CommitLineData
7f473204
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * %sccs.include.redist.c%
9 *
10 * @(#)echo.c 5.1 (Berkeley) %G%
11 */
12
13/*
14 * Echo command.
15 */
16
17#define main echocmd
18
19#include "bltin.h"
20
21#define EOF (-1)
22
23main(argc, argv)
24 char **argv;
25{
26 register char *p;
27 register char c;
28 int count;
29 int nflag = 0;
30 int eflag = 0;
31 extern char *optarg;
32 extern int optind, opterr;
33 int ch;
34
35 opterr = 0;
36 while ((ch = getopt(argc, argv, "ne")) != EOF)
37 switch((char)ch) {
38 case 'n':
39 nflag++;
40 break;
41 case 'e':
42 eflag++;
43 break;
44 case '?':
45 default:
46 error("usage: %s [-ne] [arg]...", *argv);
47 return 0;
48 }
49 argc -= optind;
50 argv += optind;
51
52 if (!eflag) {
53 while (p = *argv++) {
54 while (*p) {
55 putchar(*p);
56 p++;
57 }
58 if (*argv) putchar(' ');
59 }
60 } else {
61 while (p = *argv++) {
62 while (c = *p++) {
63 if (c == '\\') {
64 switch (*p++) {
65 case 'b': c = '\b'; break;
66 case 'c': return 0; /* exit */
67 case 'f': c = '\f'; break;
68 case 'n': c = '\n'; break;
69 case 'r': c = '\r'; break;
70 case 't': c = '\t'; break;
71 case 'v': c = '\v'; break;
72 case '\\': break; /* c = '\\' */
73 case '0': /* should be [0-7] */
74 c = 0;
75 count = 3;
76 while (--count >= 0 && (unsigned)(*p - '0') < 8)
77 c = (c << 3) + (*p++ - '0');
78 break;
79 default:
80 p--;
81 break;
82 }
83 }
84 putchar(c);
85 }
86 if (*argv) putchar(' ');
87 }
88 }
89 if (!nflag)
90 putchar('\n');
91 return 0;
92}
93
94#ifndef SHELL
95void
96error(f, a)
97{
98 _doprnt(f, &a, stderr);
99}
100#endif