Support historical syntax in head(1) and tail(1).

This commit is contained in:
Juhani Krekelä 2021-08-16 22:08:54 +03:00
parent 89b02af091
commit 79799b0084
1 changed files with 14 additions and 2 deletions

View File

@ -20,6 +20,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <ctype.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
@ -348,14 +349,25 @@ int main(int argc, char* argv[])
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int opt;
#ifndef HEAD #ifndef HEAD
const char* opts = "c:fFn:qv"; const char* opts = "c:fFn:qv";
#else #else
const char* opts = "c:n:qv"; const char* opts = "c:n:qv";
#endif #endif
while ( (opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1 ) while ( true )
{ {
// Handle the historical but still widely used -num option format.
if ( optind < argc && argv[optind][0] == '-' &&
isdigit((unsigned char) argv[optind][1]) )
{
parse_number(&argv[optind][1]);
optind++;
continue;
}
int opt = getopt_long(argc, argv, opts, longopts, NULL);
if ( opt == -1 )
break;
switch ( opt ) switch ( opt )
{ {
case 'c': case 'c':