42
42
#include <stdlib.h>
45
46
#include "widechar.h"
48
51
COLRM removes unwanted columns from a file
49
52
Jeff Schriebman UC Berkeley 11-74
53
main(int argc, char **argv)
55
register int ct, first, last;
55
static void __attribute__ ((__noreturn__)) usage(FILE * out)
57
fprintf(out, _("\nUsage:\n"
58
" %s [startcol [endcol]]\n"),
59
program_invocation_short_name);
61
fprintf(out, _("\nOptions:\n"
62
" -V, --version output version information and exit\n"
63
" -h, --help display this help and exit\n\n"));
65
fprintf(out, _("%s reads from standard input and writes to standard output\n\n"),
66
program_invocation_short_name);
68
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
71
int process_input(unsigned long first, unsigned long last)
60
setlocale(LC_ALL, "");
65
first = atoi(*++argv);
76
w = ((ct + 8) & ~7) - ct;
78
w = (ct ? ct - 1 : 0) - ct;
89
if (!first || ct < first) {
93
for (i = ct-w+1; i < first; i++)
84
w = ((ct + 8) & ~7) - ct;
86
w = (ct ? ct - 1 : 0) - ct;
99
if (!first || ct < first) {
106
for (i = ct - w + 1; i < first; i++)
94
107
putwc(' ', stdout);
96
/* Loop getting rid of characters */
109
/* Loop getting rid of characters */
97
110
while (!last || ct < last) {
102
115
putwc(c, stdout);
106
119
ct = (ct + 8) & ~7;
119
/* Output last of the line */
132
/* Output last of the line */
121
134
c = getwc(stdin);
125
138
putwc(c, stdout);
128
141
if (padding == 0 && last < ct) {
129
for (i = last; i <ct; i++)
142
for (i = last; i < ct; i++)
130
143
putwc(' ', stdout);
133
146
putwc(c, stdout);
151
int main(int argc, char **argv)
153
unsigned long first = 0, last = 0;
156
static const struct option longopts[] = {
157
{"version", no_argument, 0, 'V'},
158
{"help", no_argument, 0, 'h'},
162
setlocale(LC_ALL, "");
163
bindtextdomain(PACKAGE, LOCALEDIR);
167
getopt_long(argc, argv, "bfhl:pxVH", longopts,
171
printf(_("%s from %s\n"),
172
program_invocation_short_name,
182
first = strtoul_or_err(*++argv, _("first argument"));
184
last = strtoul_or_err(*++argv, _("second argument"));
186
while (process_input(first, last))
137
190
if (ferror(stdout) || fclose(stdout))