8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / echo / echo.c
blobebd8e3868b53f44f67d032b345c8c169635768f6
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <wchar.h>
32 #include <string.h>
33 #include <locale.h>
35 int
36 main(int argc, char *argv[])
39 register char *cp;
40 register int i, wd;
41 int j;
42 wchar_t wc;
43 int b_len;
44 char *ep;
46 (void) setlocale(LC_ALL, "");
48 if (--argc == 0) {
49 (void) putchar('\n');
50 if (fflush(stdout) != 0)
51 return (1);
52 return (0);
55 for (i = 1; i <= argc; i++) {
56 for (cp = argv[i], ep = cp + (int)strlen(cp);
57 cp < ep; cp += b_len) {
58 if ((b_len = mbtowc(&wc, cp, MB_CUR_MAX)) <= 0) {
59 (void) putchar(*cp);
60 b_len = 1;
61 continue;
64 if (wc != '\\') {
65 (void) putwchar(wc);
66 continue;
69 cp += b_len;
70 b_len = 1;
71 switch (*cp) {
72 case 'a': /* alert - XCU4 */
73 (void) putchar('\a');
74 continue;
76 case 'b':
77 (void) putchar('\b');
78 continue;
80 case 'c':
81 if (fflush(stdout) != 0)
82 return (1);
83 return (0);
85 case 'f':
86 (void) putchar('\f');
87 continue;
89 case 'n':
90 (void) putchar('\n');
91 continue;
93 case 'r':
94 (void) putchar('\r');
95 continue;
97 case 't':
98 (void) putchar('\t');
99 continue;
101 case 'v':
102 (void) putchar('\v');
103 continue;
105 case '\\':
106 (void) putchar('\\');
107 continue;
108 case '0':
109 j = wd = 0;
110 while ((*++cp >= '0' && *cp <= '7') &&
111 j++ < 3) {
112 wd <<= 3;
113 wd |= (*cp - '0');
115 (void) putchar(wd);
116 --cp;
117 continue;
119 default:
120 cp--;
121 (void) putchar(*cp);
124 (void) putchar(i == argc? '\n': ' ');
125 if (fflush(stdout) != 0)
126 return (1);
128 return (0);