]> git.ipfire.org Git - thirdparty/util-linux.git/blob - text-utils/line.c
misc: cosmetics, remove argument from usage(FILE*)
[thirdparty/util-linux.git] / text-utils / line.c
1 /*
2 * line - read one line
3 *
4 * Gunnar Ritter, Freiburg i. Br., Germany, December 2000.
5 *
6 * Public Domain.
7 */
8
9 /*
10 * This command is deprecated. The utility is in maintenance mode,
11 * meaning we keep them in source tree for backward compatibility
12 * only. Do not waste time making this command better, unless the
13 * fix is about security or other very critical issue.
14 *
15 * See Documentation/deprecated.txt for more information.
16 */
17
18 #include <getopt.h>
19 #include <stdio.h>
20 #include <unistd.h>
21
22 #include "c.h"
23 #include "closestream.h"
24 #include "nls.h"
25 #include "widechar.h"
26
27 static void __attribute__((__noreturn__)) usage(void)
28 {
29 FILE *out = stdout;
30 fputs(USAGE_HEADER, out);
31 fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
32
33 fputs(USAGE_SEPARATOR, out);
34 fputs(_("Read one line.\n"), out);
35
36 fputs(USAGE_OPTIONS, out);
37 fputs(USAGE_HELP, out);
38 fputs(USAGE_VERSION, out);
39 fprintf(out, USAGE_MAN_TAIL("line(1)"));
40 exit(EXIT_SUCCESS);
41 }
42
43 int main(int argc, char **argv)
44 {
45 wint_t c;
46 int opt;
47 int status = EXIT_SUCCESS;
48
49 static const struct option longopts[] = {
50 {"version", no_argument, NULL, 'V'},
51 {"help", no_argument, NULL, 'h'},
52 {NULL, 0, NULL, 0}
53 };
54
55 setlocale(LC_ALL, "");
56 bindtextdomain(PACKAGE, LOCALEDIR);
57 textdomain(PACKAGE);
58 atexit(close_stdout);
59
60 while ((opt = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
61 switch (opt) {
62 case 'V':
63 printf(UTIL_LINUX_VERSION);
64 return EXIT_SUCCESS;
65 case 'h':
66 usage();
67 default:
68 errtryhelp(EXIT_FAILURE);
69 }
70
71 setvbuf(stdin, NULL, _IONBF, 0);
72 for (;;) {
73 c = getwchar();
74 if (c == WEOF) {
75 status = EXIT_FAILURE;
76 break;
77 }
78 if (c == '\n')
79 break;
80 putwchar(c);
81 }
82 putwchar(L'\n');
83
84 return status;
85 }