expand.c (c3aac50f284c6cca5b4f2eb46aaa13812cb8b630) | expand.c (a2995dd0f18385befabdabe59b9eab79ab2d0c6c) |
---|---|
1/* 2 * Copyright (c) 1980, 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 --- 26 unchanged lines hidden (view full) --- 35static const char copyright[] = 36"@(#) Copyright (c) 1980, 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 42static char sccsid[] = "@(#)expand.c 8.1 (Berkeley) 6/9/93"; | 1/* 2 * Copyright (c) 1980, 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 --- 26 unchanged lines hidden (view full) --- 35static const char copyright[] = 36"@(#) Copyright (c) 1980, 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 42static char sccsid[] = "@(#)expand.c 8.1 (Berkeley) 6/9/93"; |
43#else 44static const char rcsid[] = 45 "$FreeBSD$"; | |
46#endif | 43#endif |
44static const char rcsid[] = 45 "$FreeBSD$"; |
|
47#endif /* not lint */ 48 49#include <ctype.h> | 46#endif /* not lint */ 47 48#include <ctype.h> |
49#include <err.h> |
|
50#include <stdio.h> | 50#include <stdio.h> |
51#include <stdlib.h> | |
52#include <unistd.h> 53 54/* 55 * expand - expand tabs to equivalent spaces 56 */ 57int nstops; 58int tabstops[100]; 59 --- 25 unchanged lines hidden (view full) --- 85 /* NOTREACHED */ 86 } 87 } 88 argc -= optind; 89 argv += optind; 90 91 do { 92 if (argc > 0) { | 51#include <unistd.h> 52 53/* 54 * expand - expand tabs to equivalent spaces 55 */ 56int nstops; 57int tabstops[100]; 58 --- 25 unchanged lines hidden (view full) --- 84 /* NOTREACHED */ 85 } 86 } 87 argc -= optind; 88 argv += optind; 89 90 do { 91 if (argc > 0) { |
93 if (freopen(argv[0], "r", stdin) == NULL) { 94 perror(argv[0]); 95 exit(1); 96 } | 92 if (freopen(argv[0], "r", stdin) == NULL) 93 errx(1, "%s", argv[0]); |
97 argc--, argv++; 98 } 99 column = 0; 100 while ((c = getchar()) != EOF) { 101 switch (c) { 102 case '\t': 103 if (nstops == 0) { 104 do { --- 50 unchanged lines hidden (view full) --- 155{ 156 register int i; 157 158 nstops = 0; 159 for (;;) { 160 i = 0; 161 while (*cp >= '0' && *cp <= '9') 162 i = i * 10 + *cp++ - '0'; | 94 argc--, argv++; 95 } 96 column = 0; 97 while ((c = getchar()) != EOF) { 98 switch (c) { 99 case '\t': 100 if (nstops == 0) { 101 do { --- 50 unchanged lines hidden (view full) --- 152{ 153 register int i; 154 155 nstops = 0; 156 for (;;) { 157 i = 0; 158 while (*cp >= '0' && *cp <= '9') 159 i = i * 10 + *cp++ - '0'; |
163 if (i <= 0 || i > 256) { 164bad: 165 fprintf(stderr, "Bad tab stop spec\n"); 166 exit(1); 167 } | 160 if (i <= 0 || i > 256) 161 errx(1, "bad tab stop spec"); |
168 if (nstops > 0 && i <= tabstops[nstops-1]) | 162 if (nstops > 0 && i <= tabstops[nstops-1]) |
169 goto bad; | 163 errx(1, "bad tab stop spec"); |
170 tabstops[nstops++] = i; 171 if (*cp == 0) 172 break; 173 if (*cp != ',' && *cp != ' ') | 164 tabstops[nstops++] = i; 165 if (*cp == 0) 166 break; 167 if (*cp != ',' && *cp != ' ') |
174 goto bad; | 168 errx(1, "bad tab stop spec"); |
175 cp++; 176 } 177} 178 179static void 180usage() 181{ 182 (void)fprintf (stderr, "usage: expand [-t tablist] [file ...]\n"); 183 exit(1); 184} | 169 cp++; 170 } 171} 172 173static void 174usage() 175{ 176 (void)fprintf (stderr, "usage: expand [-t tablist] [file ...]\n"); 177 exit(1); 178} |