]>
cygwin.com Git - cygwin-apps/cygutils.git/blob - src/rev/rev.c
2 * Copyright (c) 1987, 1992 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Modified for Linux by Charles Hannum (mycroft@gnu.ai.mit.edu)
30 * and Brian Koehmstedt (bpk@gnu.ai.mit.edu)
32 * Wed Sep 14 22:26:00 1994: Patch from bjdouma <bjdouma@xs4all.nl> to handle
33 * last line that has no newline correctly.
34 * 3-Jun-1998: Patched by Nicolai Langfeldt to work better on Linux:
35 * Handle any-length-lines. Code copied from util-linux' setpwnam.c
36 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
37 * added Native Language Support
38 * 1999-09-19 Bruno Haible <haible@clisp.cons.org>
39 * modified to work correctly in multi-byte locales
40 * 2002-07-12 Charles Wilson <cwilson@ece.gatech.edu>
41 * modified to work on cygwin; integrated into cygutils package
50 /* included by common.h *//*
52 #include <sys/types.h>
60 #define LOCALEDIR "/usr/share/locale"
67 # undef setlocale(a, b)
68 # define setlocale(a, b) /* empty */
73 # define _(Text) gettext (Text)
75 # define N_(String) gettext_noop (String)
77 # define N_(String) (String)
80 # undef bindtextdomain
81 # define bindtextdomain(Domain, Directory) /* empty */
83 # define textdomain(Domain) /* empty */
84 # define _(Text) (Text)
85 # define N_(Text) (Text)
91 void warn(const char *, ...);
94 main(int argc
, char *argv
[])
96 register char *filename
;
99 wchar_t *p
= malloc(buflen
*sizeof(wchar_t));
104 setlocale(LC_ALL
, "");
105 bindtextdomain(PACKAGE
, LOCALEDIR
);
108 while ((ch
= getopt(argc
, argv
, "")) != EOF
)
123 if ((fp
= fopen(*argv
, "r")) == NULL
) {
124 warn("%s: %s", *argv
, strerror(errno
));
132 while (fgetws(p
, buflen
, fp
)) {
136 /* This is my hack from setpwnam.c -janl */
137 while (p
[len
-1] != '\n' && !feof(fp
)) {
138 /* Extend input buffer if it failed getting the whole line */
140 /* So now we double the buffer size */
143 p
= realloc(p
, buflen
*sizeof(wchar_t));
145 fprintf(stderr
,_("Unable to allocate bufferspace\n"));
149 /* And fill the rest of the buffer */
150 if (fgetws(&p
[len
], buflen
/2, fp
) == NULL
) break;
154 /* That was a lot of work for nothing. Gimme perl! */
157 t
= p
+ len
- 1 - (*(p
+len
-1)=='\r' || *(p
+len
-1)=='\n');
165 warn("%s: %s", filename
, strerror(errno
));
175 warn(const char *fmt
, ...)
179 (void)fprintf(stderr
, "rev: ");
180 (void)vfprintf(stderr
, fmt
, ap
);
182 (void)fprintf(stderr
, "\n");
188 (void)fprintf(stderr
, _("usage: rev [file ...]\n"));
This page took 0.041877 seconds and 5 git commands to generate.