tr.c (1c8af8787354e20c2b38cab5801698133ff8b403) | tr.c (af647767ed8f2ec38251e8185ef0b6adb35529e6) |
---|---|
1/* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint | 1/* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint |
35static char copyright[] = | 35static const char copyright[] = |
36"@(#) Copyright (c) 1988, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint | 36"@(#) Copyright (c) 1988, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint |
41#if 0 |
|
41static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; | 42static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; |
43#endif 44static const char rcsid[] = 45 "$Id$"; |
|
42#endif /* not lint */ 43 44#include <locale.h> 45#include <sys/types.h> 46 | 46#endif /* not lint */ 47 48#include <locale.h> 49#include <sys/types.h> 50 |
51#include <err.h> |
|
47#include <stdio.h> 48#include <stdlib.h> 49#include <string.h> 50#include <unistd.h> 51 52#include "extern.h" 53 54static int string1[NCHARS] = { --- 142 unchanged lines hidden (view full) --- 197 s1.str = argv[0]; 198 s2.str = argv[1]; 199 200 if (cflag) 201 for (cnt = NCHARS, p = string1; cnt--;) 202 *p++ = OOBCH; 203 204 if (!next(&s2)) | 52#include <stdio.h> 53#include <stdlib.h> 54#include <string.h> 55#include <unistd.h> 56 57#include "extern.h" 58 59static int string1[NCHARS] = { --- 142 unchanged lines hidden (view full) --- 202 s1.str = argv[0]; 203 s2.str = argv[1]; 204 205 if (cflag) 206 for (cnt = NCHARS, p = string1; cnt--;) 207 *p++ = OOBCH; 208 209 if (!next(&s2)) |
205 err("empty string2"); | 210 errx(1, "empty string2"); |
206 207 /* If string2 runs out of characters, use the last one specified. */ 208 if (sflag) 209 while (next(&s1)) { 210 string1[s1.lastch] = ch = s2.lastch; 211 string2[ch] = 1; 212 (void)next(&s2); 213 } --- 37 unchanged lines hidden (view full) --- 251 if (cflag) 252 for (p = string, cnt = NCHARS; cnt--; ++p) 253 *p = !*p; 254} 255 256static void 257usage() 258{ | 211 212 /* If string2 runs out of characters, use the last one specified. */ 213 if (sflag) 214 while (next(&s1)) { 215 string1[s1.lastch] = ch = s2.lastch; 216 string2[ch] = 1; 217 (void)next(&s2); 218 } --- 37 unchanged lines hidden (view full) --- 256 if (cflag) 257 for (p = string, cnt = NCHARS; cnt--; ++p) 258 *p = !*p; 259} 260 261static void 262usage() 263{ |
259 (void)fprintf(stderr, "usage: tr [-cs] string1 string2\n"); 260 (void)fprintf(stderr, " tr [-c] -d string1\n"); 261 (void)fprintf(stderr, " tr [-c] -s string1\n"); 262 (void)fprintf(stderr, " tr [-c] -ds string1 string2\n"); | 264 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", 265 "usage: tr [-cs] string1 string2", 266 " tr [-c] -d string1", 267 " tr [-c] -s string1", 268 " tr [-c] -ds string1 string2"); |
263 exit(1); 264} | 269 exit(1); 270} |
265 266#if __STDC__ 267#include <stdarg.h> 268#else 269#include <varargs.h> 270#endif 271 272void 273#if __STDC__ 274err(const char *fmt, ...) 275#else 276err(fmt, va_alist) 277 char *fmt; 278 va_dcl 279#endif 280{ 281 va_list ap; 282#if __STDC__ 283 va_start(ap, fmt); 284#else 285 va_start(ap); 286#endif 287 (void)fprintf(stderr, "tr: "); 288 (void)vfprintf(stderr, fmt, ap); 289 va_end(ap); 290 (void)fprintf(stderr, "\n"); 291 exit(1); 292 /* NOTREACHED */ 293} | |