#include <signal.h>
#include <setjmp.h>
-#ifdef HAVE_NCURSES_H
-# include <ncurses.h>
+#if defined(HAVE_NCURSESW_NCURSES_H)
+# include <ncursesw/ncurses.h>
#elif defined(HAVE_NCURSES_NCURSES_H)
# include <ncurses/ncurses.h>
+#elif defined(HAVE_NCURSES_H)
+# include <ncurses.h>
#endif
-#include <term.h>
+#if defined(HAVE_NCURSESW_TERM_H)
+# include <ncursesw/term.h>
+#elif defined(HAVE_NCURSES_TERM_H)
+# include <ncurses/term.h>
+#elif defined(HAVE_TERM_H)
+# include <term.h>
+#endif
#include "nls.h"
#include "xalloc.h"
}
/* Usage message and similar routines. */
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] [+line] [+/pattern/] [files]\n"),
fputs(_(" +/pattern/ start at the line containing pattern\n"), out);
fputs(USAGE_SEPARATOR, out);
- fputs(USAGE_HELP, out);
- fputs(USAGE_VERSION, out);
+ printf(USAGE_HELP_OPTIONS(16));
- fprintf(out, USAGE_MAN_TAIL("pg(1)"));
- quit(out == stderr ? 2 : 0);
+ printf(USAGE_MAN_TAIL("pg(1)"));
+ exit(0);
}
static void __attribute__((__noreturn__)) needarg(const char *s)
{
warnx(_("option requires an argument -- %s"), s);
- usage(stderr);
+ errtryhelp(2);
}
static void __attribute__((__noreturn__)) invopt(const char *s)
{
warnx(_("illegal option -- %s"), s);
- usage(stderr);
+ errtryhelp(2);
}
#ifdef HAVE_WIDECHAR
break;
case SEARCH_FIN:
state = SEARCH;
- /* FALLTHRU */
+ /* fallthrough */
case SEARCH:
if (cmd.cmdline[cmd.cmdlen - 1] == '\\') {
escape = 1;
continue;
}
state = COUNT;
- /* FALLTHRU */
+ /* fallthrough */
case COUNT:
break;
case ADDON_FIN:
*b = '\0';
dline = pagelen;
break;
- } else {
- if (nobuf)
- fseeko(f, fpos, SEEK_SET);
- canjump = 1;
- p = fgets(b, READBUF, f);
- if (nobuf)
- if ((fpos = ftello(f)) == -1)
- warn("%s", name);
- canjump = 0;
}
+
+ if (nobuf)
+ fseeko(f, fpos, SEEK_SET);
+ canjump = 1;
+ p = fgets(b, READBUF, f);
+ if (nobuf)
+ if ((fpos = ftello(f)) == -1)
+ warn("%s", name);
+ canjump = 0;
+
if (p == NULL || *b == '\0') {
if (ferror(f))
warn("%s", name);
eofline = fline;
eof = 1;
break;
- } else {
- if (!nobuf)
- fputs(b, fbuf);
- fwrite_all(&pos, sizeof pos, 1, find);
- if (!fflag) {
- oldpos = pos;
- p = b;
- while (*(p = endline(ttycols,
- p))
- != '\0') {
- pos = oldpos + (p - b);
- fwrite_all(&pos,
- sizeof pos,
- 1, find);
- fline++;
- bline++;
- }
+ }
+
+ if (!nobuf)
+ fputs(b, fbuf);
+ fwrite_all(&pos, sizeof pos, 1, find);
+ if (!fflag) {
+ oldpos = pos;
+ p = b;
+ while (*(p = endline(ttycols,
+ p))
+ != '\0') {
+ pos = oldpos + (p - b);
+ fwrite_all(&pos,
+ sizeof pos,
+ 1, find);
+ fline++;
+ bline++;
}
- fline++;
}
+ fline++;
} while (line > bline++);
} else {
/* eofline != 0 */
skip(1);
}
continue;
- } else if (eof) {
+ }
+
+ if (eof) {
/* We are not searching. */
line = bline;
} else if (*b != '\0') {
my_sigset(SIGTERM, oldterm);
execl(sh, sh, "-c",
cmd.cmdline + 1, NULL);
- warn(_("failed to execute %s"), sh);
- _exit(0177);
- /* NOTREACHED */
+ errexec(sh);
+ break;
}
case -1:
mesg(_("fork() failed, "
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
if (tcgetattr(STDOUT_FILENO, &otio) == 0) {
ontty = 1;
argc--;
if (!strcmp(argv[arg], "--help")) {
- usage(stdout);
+ usage();
}
if (!strcmp(argv[arg], "--version")) {
- printf(UTIL_LINUX_VERSION);
+ print_version(EXIT_SUCCESS);
return EXIT_SUCCESS;
}
case 's':
sflag = 1;
break;
+
case 'h':
- usage(stdout);
+ usage();
case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
+ print_version(EXIT_SUCCESS);
default:
invopt(&argv[arg][i]);
}