diff -u -N -r coreutils-6.9.orig/doc/Makefile.am coreutils-6.9/doc/Makefile.am --- coreutils-6.9.orig/doc/Makefile.am 2007-03-18 22:36:43.000000000 +0100 +++ coreutils-6.9/doc/Makefile.am 2007-08-19 13:45:25.000000000 +0200 @@ -32,10 +32,10 @@ # old systems. AM_MAKEINFOFLAGS = --no-split -constants.texi: $(top_srcdir)/src/tail.c +constants.texi: $(top_srcdir)/src/tail.h LC_ALL=C \ sed -n -e 's/^#define \(DEFAULT_MAX[_A-Z]*\) \(.*\)/@set \1 \2/p' \ - $(top_srcdir)/src/tail.c > t-$@ + $(top_srcdir)/src/tail.h > t-$@ mv t-$@ $@ MAINTAINERCLEANFILES = constants.texi diff -u -N -r coreutils-6.9.orig/doc/Makefile.in coreutils-6.9/doc/Makefile.in --- coreutils-6.9.orig/doc/Makefile.in 2007-03-22 22:20:21.000000000 +0100 +++ coreutils-6.9/doc/Makefile.in 2007-08-19 13:46:04.000000000 +0200 @@ -937,10 +937,10 @@ uninstall-ps-am -constants.texi: $(top_srcdir)/src/tail.c +constants.texi: $(top_srcdir)/src/tail.h LC_ALL=C \ sed -n -e 's/^#define \(DEFAULT_MAX[_A-Z]*\) \(.*\)/@set \1 \2/p' \ - $(top_srcdir)/src/tail.c > t-$@ + $(top_srcdir)/src/tail.h > t-$@ mv t-$@ $@ $(DVIS): $(EXTRA_DIST) diff -u -N -r coreutils-6.9.orig/src/ls.c coreutils-6.9/src/ls.c --- coreutils-6.9.orig/src/ls.c 2007-03-18 22:36:43.000000000 +0100 +++ coreutils-6.9/src/ls.c 2007-08-26 19:58:20.000000000 +0200 @@ -76,7 +76,6 @@ # define SA_RESTART 0 #endif -#include "system.h" #include #include "acl.h" @@ -90,7 +89,6 @@ #include "human.h" #include "filemode.h" #include "inttostr.h" -#include "ls.h" #include "lstat.h" #include "mbswidth.h" #include "mpsort.h" @@ -104,6 +102,7 @@ #include "wcwidth.h" #include "xstrtol.h" #include "xreadlink.h" +#include "ls-clp.h" #define PROGRAM_NAME (ls_mode == LS_LS ? "ls" \ : (ls_mode == LS_MULTI_COL \ @@ -246,7 +245,6 @@ bool command_line_arg); static void sort_files (void); static void parse_ls_color (void); -void usage (int status); /* The name this program was run with. */ char *program_name; @@ -708,91 +706,6 @@ static int exit_status; -/* Exit statuses. */ -enum - { - /* "ls" had a minor problem (e.g., it could not stat a directory - entry). */ - LS_MINOR_PROBLEM = 1, - - /* "ls" had more serious trouble. */ - LS_FAILURE = 2 - }; - -/* For long options that have no equivalent short option, use a - non-character as a pseudo short option, starting with CHAR_MAX + 1. */ -enum -{ - AUTHOR_OPTION = CHAR_MAX + 1, - BLOCK_SIZE_OPTION, - COLOR_OPTION, - DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION, - FILE_TYPE_INDICATOR_OPTION, - FORMAT_OPTION, - FULL_TIME_OPTION, - GROUP_DIRECTORIES_FIRST_OPTION, - HIDE_OPTION, - INDICATOR_STYLE_OPTION, - - /* FIXME: --kilobytes is deprecated (but not -k); remove in late 2006 */ - KILOBYTES_LONG_OPTION, - - QUOTING_STYLE_OPTION, - SHOW_CONTROL_CHARS_OPTION, - SI_OPTION, - SORT_OPTION, - TIME_OPTION, - TIME_STYLE_OPTION -}; - -static struct option const long_options[] = -{ - {"all", no_argument, NULL, 'a'}, - {"escape", no_argument, NULL, 'b'}, - {"directory", no_argument, NULL, 'd'}, - {"dired", no_argument, NULL, 'D'}, - {"full-time", no_argument, NULL, FULL_TIME_OPTION}, - {"group-directories-first", no_argument, NULL, - GROUP_DIRECTORIES_FIRST_OPTION}, - {"human-readable", no_argument, NULL, 'h'}, - {"inode", no_argument, NULL, 'i'}, - {"kilobytes", no_argument, NULL, KILOBYTES_LONG_OPTION}, - {"numeric-uid-gid", no_argument, NULL, 'n'}, - {"no-group", no_argument, NULL, 'G'}, - {"hide-control-chars", no_argument, NULL, 'q'}, - {"reverse", no_argument, NULL, 'r'}, - {"size", no_argument, NULL, 's'}, - {"width", required_argument, NULL, 'w'}, - {"almost-all", no_argument, NULL, 'A'}, - {"ignore-backups", no_argument, NULL, 'B'}, - {"classify", no_argument, NULL, 'F'}, - {"file-type", no_argument, NULL, FILE_TYPE_INDICATOR_OPTION}, - {"si", no_argument, NULL, SI_OPTION}, - {"dereference-command-line", no_argument, NULL, 'H'}, - {"dereference-command-line-symlink-to-dir", no_argument, NULL, - DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION}, - {"hide", required_argument, NULL, HIDE_OPTION}, - {"ignore", required_argument, NULL, 'I'}, - {"indicator-style", required_argument, NULL, INDICATOR_STYLE_OPTION}, - {"dereference", no_argument, NULL, 'L'}, - {"literal", no_argument, NULL, 'N'}, - {"quote-name", no_argument, NULL, 'Q'}, - {"quoting-style", required_argument, NULL, QUOTING_STYLE_OPTION}, - {"recursive", no_argument, NULL, 'R'}, - {"format", required_argument, NULL, FORMAT_OPTION}, - {"show-control-chars", no_argument, NULL, SHOW_CONTROL_CHARS_OPTION}, - {"sort", required_argument, NULL, SORT_OPTION}, - {"tabsize", required_argument, NULL, 'T'}, - {"time", required_argument, NULL, TIME_OPTION}, - {"time-style", required_argument, NULL, TIME_STYLE_OPTION}, - {"color", optional_argument, NULL, COLOR_OPTION}, - {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION}, - {"author", no_argument, NULL, AUTHOR_OPTION}, - {GETOPT_HELP_OPTION_DECL}, - {GETOPT_VERSION_OPTION_DECL}, - {NULL, 0, NULL, 0} -}; - static char const *const format_args[] = { "verbose", "long", "commas", "horizontal", "across", @@ -1385,6 +1298,7 @@ { int c; char *time_style_option = NULL; + struct arg_t cmdline; /* Record whether there is an option specifying sort type. */ bool sort_type_specified = false; @@ -1513,313 +1427,277 @@ } } - while ((c = getopt_long (argc, argv, - "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UX1", - long_options, NULL)) != -1) - { - switch (c) - { - case 'a': - ignore_mode = IGNORE_MINIMAL; - break; + Cmdline(&cmdline, argc, argv); - case 'b': - set_quoting_style (NULL, escape_quoting_style); - break; + if (cmdline.all) + ignore_mode = IGNORE_MINIMAL; - case 'c': - time_type = time_ctime; - break; + if (cmdline.escape) + set_quoting_style (NULL, escape_quoting_style); - case 'd': - immediate_dirs = true; - break; + if (cmdline.c) + time_type = time_ctime; - case 'f': - /* Same as enabling -a -U and disabling -l -s. */ - ignore_mode = IGNORE_MINIMAL; - sort_type = sort_none; - sort_type_specified = true; - /* disable -l */ - if (format == long_format) - format = (isatty (STDOUT_FILENO) ? many_per_line : one_per_line); - print_block_size = false; /* disable -s */ - print_with_color = false; /* disable --color */ - break; + immediate_dirs = cmdline.directory; - case FILE_TYPE_INDICATOR_OPTION: /* --file-type */ - indicator_style = file_type; - break; + if (cmdline.f) + { + /* Same as enabling -a -U and disabling -l -s. */ + ignore_mode = IGNORE_MINIMAL; + sort_type = sort_none; + sort_type_specified = true; + /* disable -l */ + if (format == long_format) + format = (isatty (STDOUT_FILENO) ? many_per_line : one_per_line); + print_block_size = false; /* disable -s */ + print_with_color = false; /* disable --color */ + } - case 'g': - format = long_format; - print_owner = false; - break; + if (cmdline.file_type) + indicator_style = file_type; - case 'h': - human_output_opts = human_autoscale | human_SI | human_base_1024; - file_output_block_size = output_block_size = 1; - break; + if (cmdline.g) + { + format = long_format; + print_owner = false; + } - case 'i': - print_inode = true; - break; + if (cmdline.human_readable) + { + human_output_opts = human_autoscale | human_SI | human_base_1024; + file_output_block_size = output_block_size = 1; + } - case KILOBYTES_LONG_OPTION: - error (0, 0, - _("the --kilobytes option is deprecated; use -k instead")); - /* fall through */ - case 'k': - human_output_opts = 0; - file_output_block_size = output_block_size = 1024; - break; + print_inode = cmdline.inode; - case 'l': - format = long_format; - break; + if (cmdline.kilobytes || cmdline.k) + { + if (cmdline.kilobytes) + error (0, 0, + _("the --kilobytes option is deprecated; use -k instead")); + human_output_opts = 0; + file_output_block_size = output_block_size = 1024; + } - case 'm': - format = with_commas; - break; + if (cmdline.l) + format = long_format; - case 'n': - numeric_ids = true; - format = long_format; - break; + if (cmdline.m) + format = with_commas; - case 'o': /* Just like -l, but don't display group info. */ - format = long_format; - print_group = false; - break; + if (cmdline.numeric_uid_gid) + { + numeric_ids = true; + format = long_format; + } - case 'p': - indicator_style = slash; - break; + if (cmdline.o) + { + format = long_format; + print_group = false; + } - case 'q': - qmark_funny_chars = true; - break; + if (cmdline.p) + indicator_style = slash; - case 'r': - sort_reverse = true; - break; + qmark_funny_chars = cmdline.hide_control_chars; - case 's': - print_block_size = true; - break; + sort_reverse = cmdline.reverse; - case 't': - sort_type = sort_time; - sort_type_specified = true; - break; + print_block_size = cmdline.size; - case 'u': - time_type = time_atime; - break; + if (cmdline.t) + { + sort_type = sort_time; + sort_type_specified = true; + } - case 'v': - sort_type = sort_version; - sort_type_specified = true; - break; + if (cmdline.u) + time_type = time_atime; - case 'w': - { - unsigned long int tmp_ulong; - if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK - || ! (0 < tmp_ulong && tmp_ulong <= SIZE_MAX)) - error (LS_FAILURE, 0, _("invalid line width: %s"), - quotearg (optarg)); - line_length = tmp_ulong; - break; - } + if (cmdline.v) + { + sort_type = sort_version; + sort_type_specified = true; + } - case 'x': - format = horizontal; - break; + if (cmdline.width != NULL) + { + unsigned long int tmp_ulong; + if (xstrtoul (cmdline.width, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK + || ! (0 < tmp_ulong && tmp_ulong <= SIZE_MAX)) + error (LS_FAILURE, 0, _("invalid line width: %s"), + quotearg (cmdline.width)); + line_length = tmp_ulong; + } - case 'A': - if (ignore_mode == IGNORE_DEFAULT) - ignore_mode = IGNORE_DOT_AND_DOTDOT; - break; + if (cmdline.x) + format = horizontal; - case 'B': - add_ignore_pattern ("*~"); - add_ignore_pattern (".*~"); - break; + if (cmdline.almost_all) + if (ignore_mode == IGNORE_DEFAULT) + ignore_mode = IGNORE_DOT_AND_DOTDOT; - case 'C': - format = many_per_line; - break; + if (cmdline.ignore_backups) + { + add_ignore_pattern ("*~"); + add_ignore_pattern (".*~"); + } - case 'D': - dired = true; - break; + if (cmdline.C) + format = many_per_line; - case 'F': - indicator_style = classify; - break; + dired = cmdline.dired; - case 'G': /* inhibit display of group info */ - print_group = false; - break; + if (cmdline.classify) + indicator_style = classify; - case 'H': - dereference = DEREF_COMMAND_LINE_ARGUMENTS; - break; + if (cmdline.no_group) + print_group = false; - case DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION: - dereference = DEREF_COMMAND_LINE_SYMLINK_TO_DIR; - break; + if (cmdline.dereference_command_line) + dereference = DEREF_COMMAND_LINE_ARGUMENTS; - case 'I': - add_ignore_pattern (optarg); - break; + if (cmdline.dereference_command_line_symlink_to_dir) + dereference = DEREF_COMMAND_LINE_SYMLINK_TO_DIR; - case 'L': - dereference = DEREF_ALWAYS; - break; + if (cmdline.ignore != NULL) + add_ignore_pattern (cmdline.ignore); - case 'N': - set_quoting_style (NULL, literal_quoting_style); - break; + if (cmdline.dereference) + dereference = DEREF_ALWAYS; - case 'Q': - set_quoting_style (NULL, c_quoting_style); - break; + if (cmdline.literal) + set_quoting_style (NULL, literal_quoting_style); - case 'R': - recursive = true; - break; + if (cmdline.quote_name) + set_quoting_style (NULL, c_quoting_style); - case 'S': - sort_type = sort_size; - sort_type_specified = true; - break; + recursive = cmdline.recursive; - case 'T': - { - unsigned long int tmp_ulong; - if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK - || SIZE_MAX < tmp_ulong) - error (LS_FAILURE, 0, _("invalid tab size: %s"), - quotearg (optarg)); - tabsize = tmp_ulong; - break; - } + if (cmdline.S) + { + sort_type = sort_size; + sort_type_specified = true; + } - case 'U': - sort_type = sort_none; - sort_type_specified = true; - break; + if (cmdline.tabsize != NULL) + { + unsigned long int tmp_ulong; + if (xstrtoul (cmdline.tabsize, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK + || SIZE_MAX < tmp_ulong) + error (LS_FAILURE, 0, _("invalid tab size: %s"), + quotearg (cmdline.tabsize)); + tabsize = tmp_ulong; + } - case 'X': - sort_type = sort_extension; - sort_type_specified = true; - break; + if (cmdline.U) + { + sort_type = sort_none; + sort_type_specified = true; + } - case '1': - /* -1 has no effect after -l. */ - if (format != long_format) - format = one_per_line; - break; + if (cmdline.X) + { + sort_type = sort_extension; + sort_type_specified = true; + } - case AUTHOR_OPTION: - print_author = true; - break; + if (cmdline._1) + /* -1 has no effect after -l. */ + if (format != long_format) + format = one_per_line; - case HIDE_OPTION: - { - struct ignore_pattern *hide = xmalloc (sizeof *hide); - hide->pattern = optarg; - hide->next = hide_patterns; - hide_patterns = hide; - } - break; + print_author = cmdline.author; - case SORT_OPTION: - sort_type = XARGMATCH ("--sort", optarg, sort_args, sort_types); - sort_type_specified = true; - break; + if (cmdline.hide != NULL) + { + struct ignore_pattern *hide = xmalloc (sizeof *hide); + hide->pattern = cmdline.hide; + hide->next = hide_patterns; + hide_patterns = hide; + } - case GROUP_DIRECTORIES_FIRST_OPTION: - directories_first = true; - break; + if (cmdline.sort != NULL) + { + sort_type = XARGMATCH ("--sort", cmdline.sort, sort_args, sort_types); + sort_type_specified = true; + } - case TIME_OPTION: - time_type = XARGMATCH ("--time", optarg, time_args, time_types); - break; + directories_first = cmdline.group_directories_first; - case FORMAT_OPTION: - format = XARGMATCH ("--format", optarg, format_args, format_types); - break; + if (cmdline.time != NULL) + time_type = XARGMATCH ("--time", cmdline.time, time_args, time_types); + + if (cmdline.format != NULL) + format = XARGMATCH ("--format", cmdline.format, format_args, format_types); - case FULL_TIME_OPTION: - format = long_format; - time_style_option = "full-iso"; - break; + if (cmdline.full_time) + { + format = long_format; + time_style_option = "full-iso"; + } - case COLOR_OPTION: - { - int i; - if (optarg) - i = XARGMATCH ("--color", optarg, color_args, color_types); - else - /* Using --color with no argument is equivalent to using - --color=always. */ - i = color_always; - - print_with_color = (i == color_always - || (i == color_if_tty - && isatty (STDOUT_FILENO))); + if (cmdline.color_flag) + { + int i; + if (cmdline.color) + i = XARGMATCH ("--color", cmdline.color, color_args, color_types); + else + /* Using --color with no argument is equivalent to using + --color=always. */ + i = color_always; - if (print_with_color) - { - /* Don't use TAB characters in output. Some terminal - emulators can't handle the combination of tabs and - color codes on the same line. */ - tabsize = 0; - } - break; - } + print_with_color = (i == color_always + || (i == color_if_tty + && isatty (STDOUT_FILENO))); - case INDICATOR_STYLE_OPTION: - indicator_style = XARGMATCH ("--indicator-style", optarg, - indicator_style_args, - indicator_style_types); - break; + if (print_with_color) + { + /* Don't use TAB characters in output. Some terminal + emulators can't handle the combination of tabs and + color codes on the same line. */ + tabsize = 0; + } + } - case QUOTING_STYLE_OPTION: - set_quoting_style (NULL, - XARGMATCH ("--quoting-style", optarg, - quoting_style_args, - quoting_style_vals)); - break; + if (cmdline.indicator_style != NULL) + indicator_style = XARGMATCH ("--indicator-style", cmdline.indicator_style, + indicator_style_args, + indicator_style_types); - case TIME_STYLE_OPTION: - time_style_option = optarg; - break; + if (cmdline.quoting_style != NULL) + set_quoting_style (NULL, + XARGMATCH ("--quoting-style", cmdline.quoting_style, + quoting_style_args, + quoting_style_vals)); - case SHOW_CONTROL_CHARS_OPTION: - qmark_funny_chars = false; - break; + if (cmdline.time_style != NULL) + time_style_option = cmdline.time_style; - case BLOCK_SIZE_OPTION: - human_output_opts = human_options (optarg, true, &output_block_size); - file_output_block_size = output_block_size; - break; + if (cmdline.show_control_chars) + qmark_funny_chars = false; - case SI_OPTION: - human_output_opts = human_autoscale | human_SI; - file_output_block_size = output_block_size = 1; - break; + if (cmdline.block_size != NULL) + { + human_output_opts = human_options (cmdline.block_size, true, &output_block_size); + file_output_block_size = output_block_size; + } - case_GETOPT_HELP_CHAR; + if (cmdline.si) + { + human_output_opts = human_autoscale | human_SI; + file_output_block_size = output_block_size = 1; + } - case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + if (cmdline.help) + usage (EXIT_SUCCESS, program_name); - default: - usage (LS_FAILURE); - } + if (cmdline.version) + { + version_etc (stdout, PROGRAM_NAME, GNU_PACKAGE, VERSION, AUTHORS, + (char *) NULL); + exit (EXIT_SUCCESS); } max_idx = MAX (1, line_length / MIN_COLUMN_WIDTH); @@ -4265,166 +4143,129 @@ return cols; } -void -usage (int status) -{ - if (status != EXIT_SUCCESS) - fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); - else - { - printf (_("Usage: %s [OPTION]... [FILE]...\n"), program_name); - fputs (_("\ -List information about the FILEs (the current directory by default).\n\ -Sort entries alphabetically if none of -cftuvSUX nor --sort.\n\ -\n\ -"), stdout); - fputs (_("\ -Mandatory arguments to long options are mandatory for short options too.\n\ -"), stdout); - fputs (_("\ - -a, --all do not ignore entries starting with .\n\ - -A, --almost-all do not list implied . and ..\n\ - --author with -l, print the author of each file\n\ - -b, --escape print octal escapes for nongraphic characters\n\ -"), stdout); - fputs (_("\ - --block-size=SIZE use SIZE-byte blocks\n\ - -B, --ignore-backups do not list implied entries ending with ~\n\ - -c with -lt: sort by, and show, ctime (time of last\n\ - modification of file status information)\n\ - with -l: show ctime and sort by name\n\ - otherwise: sort by ctime\n\ -"), stdout); - fputs (_("\ - -C list entries by columns\n\ - --color[=WHEN] control whether color is used to distinguish file\n\ - types. WHEN may be `never', `always', or `auto'\n\ - -d, --directory list directory entries instead of contents,\n\ - and do not dereference symbolic links\n\ - -D, --dired generate output designed for Emacs' dired mode\n\ -"), stdout); - fputs (_("\ - -f do not sort, enable -aU, disable -ls --color\n\ - -F, --classify append indicator (one of */=>@|) to entries\n\ - --file-type likewise, except do not append `*'\n\ - --format=WORD across -x, commas -m, horizontal -x, long -l,\n\ - single-column -1, verbose -l, vertical -C\n\ - --full-time like -l --time-style=full-iso\n\ -"), stdout); - fputs (_("\ - -g like -l, but do not list owner\n\ -"), stdout); - fputs (_("\ - --group-directories-first\n\ - group directories before files\n\ -"), stdout); - fputs (_("\ - -G, --no-group in a long listing, don't print group names\n\ - -h, --human-readable with -l, print sizes in human readable format\n\ - (e.g., 1K 234M 2G)\n\ - --si likewise, but use powers of 1000 not 1024\n\ -"), stdout); - fputs (_("\ - -H, --dereference-command-line\n\ - follow symbolic links listed on the command line\n\ - --dereference-command-line-symlink-to-dir\n\ - follow each command line symbolic link\n\ - that points to a directory\n\ - --hide=PATTERN do not list implied entries matching shell PATTERN\n\ - (overridden by -a or -A)\n\ -"), stdout); - fputs (_("\ - --indicator-style=WORD append indicator with style WORD to entry names:\n\ - none (default), slash (-p),\n\ - file-type (--file-type), classify (-F)\n\ - -i, --inode print the index number of each file\n\ - -I, --ignore=PATTERN do not list implied entries matching shell PATTERN\n\ - -k like --block-size=1K\n\ -"), stdout); - fputs (_("\ - -l use a long listing format\n\ - -L, --dereference when showing file information for a symbolic\n\ - link, show information for the file the link\n\ - references rather than for the link itself\n\ - -m fill width with a comma separated list of entries\n\ -"), stdout); - fputs (_("\ - -n, --numeric-uid-gid like -l, but list numeric user and group IDs\n\ - -N, --literal print raw entry names (don't treat e.g. control\n\ - characters specially)\n\ - -o like -l, but do not list group information\n\ - -p, --indicator-style=slash\n\ - append / indicator to directories\n\ -"), stdout); - fputs (_("\ - -q, --hide-control-chars print ? instead of non graphic characters\n\ - --show-control-chars show non graphic characters as-is (default\n\ - unless program is `ls' and output is a terminal)\n\ - -Q, --quote-name enclose entry names in double quotes\n\ - --quoting-style=WORD use quoting style WORD for entry names:\n\ - literal, locale, shell, shell-always, c, escape\n\ -"), stdout); - fputs (_("\ - -r, --reverse reverse order while sorting\n\ - -R, --recursive list subdirectories recursively\n\ - -s, --size print the size of each file, in blocks\n\ -"), stdout); - fputs (_("\ - -S sort by file size\n\ - --sort=WORD sort by WORD instead of name: none -U,\n\ - extension -X, size -S, time -t, version -v\n\ - --time=WORD with -l, show time as WORD instead of modification\n\ - time: atime -u, access -u, use -u, ctime -c,\n\ - or status -c; use specified time as sort key\n\ - if --sort=time\n\ -"), stdout); - fputs (_("\ - --time-style=STYLE with -l, show times using style STYLE:\n\ - full-iso, long-iso, iso, locale, +FORMAT.\n\ - FORMAT is interpreted like `date'; if FORMAT is\n\ - FORMAT1FORMAT2, FORMAT1 applies to\n\ - non-recent files and FORMAT2 to recent files;\n\ - if STYLE is prefixed with `posix-', STYLE\n\ - takes effect only outside the POSIX locale\n\ -"), stdout); - fputs (_("\ - -t sort by modification time\n\ - -T, --tabsize=COLS assume tab stops at each COLS instead of 8\n\ -"), stdout); - fputs (_("\ - -u with -lt: sort by, and show, access time\n\ - with -l: show access time and sort by name\n\ - otherwise: sort by access time\n\ - -U do not sort; list entries in directory order\n\ - -v sort by version\n\ -"), stdout); - fputs (_("\ - -w, --width=COLS assume screen width instead of current value\n\ - -x list entries by lines instead of by columns\n\ - -X sort alphabetically by entry extension\n\ - -1 list one file per line\n\ -"), stdout); - fputs (HELP_OPTION_DESCRIPTION, stdout); - fputs (VERSION_OPTION_DESCRIPTION, stdout); - fputs (_("\n\ -SIZE may be (or may be an integer optionally followed by) one of following:\n\ -kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.\n\ -"), stdout); - fputs (_("\ -\n\ -By default, color is not used to distinguish types of files. That is\n\ -equivalent to using --color=none. Using the --color option without the\n\ -optional WHEN argument is equivalent to using --color=always. With\n\ ---color=auto, color codes are output only if standard output is connected\n\ -to a terminal (tty). The environment variable LS_COLORS can influence the\n\ -colors, and can be set easily by the dircolors command.\n\ -"), stdout); - fputs (_("\ -\n\ -Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble.\n\ -"), stdout); - printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); - } - exit (status); -} +/* Extract the following section an process it with genparse + (see http://genparse.sourceforge.net) in order to generate a parser + for the command line arguments and a usage function for printing a help + screen. */ + +/* genparse file starts here +#include +#include "system.h" +#include "ls.h" + +#exit_value LS_FAILURE + +a / all flag "do not ignore entries starting with ." +A / almost-all flag "do not list implied . and .." +NONE / author flag "with -l, print the author of each file" +b / escape flag "print octal escapes for nongraphic characters" +NONE / block-size=SIZE string "use SIZE-byte blocks" +B / ignore-backups flag "do not list implied entries ending with ~" +c flag "with -lt: sort by, and show, ctime (time of last" + " modification of file status information)" + " with -l: show ctime and sort by name" + " otherwise: sort by ctime" +C flag "list entries by columns" +NONE / color*[=WHEN] string "control whether color is used to distinguish file" + " types. WHEN may be `never', `always', or `auto'" +d / directory flag "list directory entries instead of contents," + " and do not dereference symbolic links" +D / dired flag "generate output designed for Emacs' dired mode" +f flag "do not sort, enable -aU, disable -ls --color" +F / classify flag "append indicator (one of /=*>@|) to entries" +NONE / file-type flag "likewise, except do not append `*'" +NONE / format=WORD string "across -x, commas -m, horizontal -x, long -l," + " single-column -1, verbose -l, vertical -C" +NONE / full-time flag "like -l --time-style=full-iso" +g flag "like -l, but do not list owner" +NONE / group-directories-first flag "" + "group directories before files" +G / no-group flag "in a long listing, don't print group names" +h / human-readable flag "with -l, print sizes in human readable format" + " (e.g., 1K 234M 2G)" +NONE / si flag "likewise, but use powers of 1000 not 1024" +H / dereference-command-line flag "" + "follow symbolic links listed on the command line" +NONE / dereference-command-line-symlink-to-dir flag "" + "follow each command line symbolic link" + "that points to a directory" +NONE / hide=PATTERN string "do not list implied entries matching shell PATTERN" + " (overridden by -a or -A)" +NONE / indicator-style=WORD string " append indicator with style WORD to entry names:" + " none (default), slash (-p)," + " file-type (--file-type), classify (-F)" +i / inode flag "print the index number of each file" +I / ignore=PATTERN string "do not list implied entries matching shell PATTERN" +k flag "like --block-size=1K" +NONE / kilobytes flag "__DO_NOT_DOCUMENT__" +l flag "use a long listing format" +L / dereference flag "when showing file information for a symbolic" + " link, show information for the file the link" + " references rather than for the link itself" +m flag "fill width with a comma separated list of entries" +n / numeric-uid-gid flag "like -l, but list numeric user and group IDs" +N / literal flag "print raw entry names (don't treat e.g. control" + " characters specially)" +o flag "like -l, but do not list group information" +p flag "like --indicator-style=slash" + " append / indicator to directories" +q / hide-control-chars flag "print ? instead of non graphic characters" +NONE / show-control-chars flag "show non graphic characters as-is (default" + "unless program is `ls' and output is a terminal)" +Q / quote-name flag "enclose entry names in double quotes" +NONE / quoting-style=WORD string "use quoting style WORD for entry names:" + " literal, locale, shell, shell-always, c, escape" +r / reverse flag "reverse order while sorting" +R / recursive flag "list subdirectories recursively" +s / size flag "print the size of each file, in blocks" +S flag "sort by file size" +NONE / sort=WORD string "sort by WORD instead of name: none -U," + "extension -X, size -S, time -t, version -v" +NONE / time=WORD string "with -l, show time as WORD instead of modification" + "time: atime -u, access -u, use -u, ctime -c," + "or status -c; use specified time as sort key" + "if --sort=time" +NONE / time-style=STYLE string "with -l, show times using style STYLE:" + "full-iso, long-iso, iso, locale, +FORMAT." + "FORMAT is interpreted like `date'; if FORMAT is" + "FORMAT1FORMAT2, FORMAT1 applies to" + "non-recent files and FORMAT2 to recent files;" + "if STYLE is prefixed with `posix-', STYLE" + "takes effect only outside the POSIX locale" +t flag "sort by modification time" +T / tabsize=COLS string "assume tab stops at each COLS instead of 8" +u flag "with -lt: sort by, and show, access time" + " with -l: show access time and sort by name" + " otherwise: sort by access time" +U flag "do not sort; list entries in directory order" +v flag "sort by version" +w / width=COLS string "assume screen width instead of current value" +x flag "list entries by lines instead of by columns" +X flag "sort alphabetically by entry extension" +1 flag "list one file per line" +NONE / help flag "display this help and exit" +NONE / version flag "output version information and exit" + +#usage_begin +Usage: __PROGRAM_NAME__ [OPTION]... [FILE]... +List information about the FILEs (the current directory by default). +Sort entries alphabetically if none of -cftuvSUX nor --sort. + +Mandatory arguments to long options are mandatory for short options too. +__GLOSSARY_GNU__(29) + +SIZE may be (or may be an integer optionally followed by) one of following: +kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y. + +By default, color is not used to distinguish types of files. That is +equivalent to using --color=none. Using the --color option without the +optional WHEN argument is equivalent to using --color=always. With +--color=auto, color codes are output only if standard output is connected +to a terminal (tty). The environment variable LS_COLORS can influence the +colors, and can be set easily by the dircolors command. + +Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble. + +Report bugs to <__STRING__(PACKAGE_BUGREPORT)>. +#usage_end +genparse file ends here */ diff -u -N -r coreutils-6.9.orig/src/ls.h coreutils-6.9/src/ls.h --- coreutils-6.9.orig/src/ls.h 2007-03-18 22:36:43.000000000 +0100 +++ coreutils-6.9/src/ls.h 2007-08-26 11:28:29.000000000 +0200 @@ -8,3 +8,14 @@ #define LS_LONG_FORMAT 3 extern int ls_mode; + +/* Exit statuses. */ +enum + { + /* "ls" had a minor problem (e.g., it could not stat a directory + entry). */ + LS_MINOR_PROBLEM = 1, + + /* "ls" had more serious trouble. */ + LS_FAILURE = 2 + }; diff -u -N -r coreutils-6.9.orig/src/Makefile.am coreutils-6.9/src/Makefile.am --- coreutils-6.9.orig/src/Makefile.am 2007-03-20 08:24:27.000000000 +0100 +++ coreutils-6.9/src/Makefile.am 2007-08-26 16:08:34.000000000 +0200 @@ -48,7 +48,7 @@ EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \ groups.sh wheel-gen.pl extract-magic c99-to-c89.diff BUILT_SOURCES = -CLEANFILES = $(SCRIPTS) su +CLEANFILES = $(SCRIPTS) su *.gp *-clp.c *-clp.h AM_CPPFLAGS = -I$(top_srcdir)/lib @@ -185,14 +185,16 @@ __SOURCES = lbracket.c cp_SOURCES = cp.c copy.c cp-hash.c -dir_SOURCES = ls.c ls-dir.c -vdir_SOURCES = ls.c ls-vdir.c -ls_SOURCES = ls.c ls-ls.c +dir_SOURCES = ls.c ls-dir.c ls-clp.c ls-clp.h +vdir_SOURCES = ls.c ls-vdir.c ls-clp.c ls-clp.h +ls_SOURCES = ls.c ls-ls.c ls-clp.c ls-clp.h chown_SOURCES = chown.c chown-core.c chgrp_SOURCES = chgrp.c chown-core.c mv_SOURCES = mv.c copy.c cp-hash.c remove.c rm_SOURCES = rm.c remove.c +tail_SOURCES = tail.c tail-clp.c +wc_SOURCES = wc.c wc-clp.c md5sum_SOURCES = md5sum.c md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS) @@ -363,3 +365,17 @@ | grep -Ev -f $$t && \ { echo 'the above variables should have static scope' 1>&2; \ exit 1; } || : + +# make doesn't detect the following dependencies automatically because +# %-clp.h doesn't yet exist during initial dependency scan +ls.c: ls-clp.h +tail.c: tail-clp.h +wc.c: wc-clp.h + +%-clp.c %-clp.h: %.gp + genparse --longmembers --internationalize -o $(*F)-clp $< + +# %.gp depends on %.c but this would introduce a circular dependency +%.gp: + sed -n -e '/genparse file starts here/,/genparse file ends here/p' < $(*F).c | \ + sed -e '/genparse file ends here/d' -n -e '2,$$p' > $@ diff -u -N -r coreutils-6.9.orig/src/Makefile.in coreutils-6.9/src/Makefile.in --- coreutils-6.9.orig/src/Makefile.in 2007-03-22 22:23:20.000000000 +0100 +++ coreutils-6.9/src/Makefile.in 2007-08-26 16:10:24.000000000 +0200 @@ -281,7 +281,7 @@ df_LDADD = $(LDADD) df_DEPENDENCIES = ../lib/libcoreutils.a $(am__DEPENDENCIES_1) \ ../lib/libcoreutils.a -am_dir_OBJECTS = ls.$(OBJEXT) ls-dir.$(OBJEXT) +am_dir_OBJECTS = ls.$(OBJEXT) ls-dir.$(OBJEXT) ls-clp.$(OBJEXT) dir_OBJECTS = $(am_dir_OBJECTS) dir_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) @@ -390,7 +390,7 @@ logname_LDADD = $(LDADD) logname_DEPENDENCIES = ../lib/libcoreutils.a $(am__DEPENDENCIES_1) \ ../lib/libcoreutils.a -am_ls_OBJECTS = ls.$(OBJEXT) ls-ls.$(OBJEXT) +am_ls_OBJECTS = ls.$(OBJEXT) ls-ls.$(OBJEXT) ls-clp.$(OBJEXT) ls_OBJECTS = $(am_ls_OBJECTS) ls_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) @@ -569,8 +569,8 @@ tac_LDADD = $(LDADD) tac_DEPENDENCIES = ../lib/libcoreutils.a $(am__DEPENDENCIES_1) \ ../lib/libcoreutils.a -tail_SOURCES = tail.c -tail_OBJECTS = tail.$(OBJEXT) +am_tail_OBJECTS = tail.$(OBJEXT) tail-clp.$(OBJEXT) +tail_OBJECTS = $(am_tail_OBJECTS) tail_DEPENDENCIES = $(am__DEPENDENCIES_3) tee_SOURCES = tee.c tee_OBJECTS = tee.$(OBJEXT) @@ -632,12 +632,12 @@ users_LDADD = $(LDADD) users_DEPENDENCIES = ../lib/libcoreutils.a $(am__DEPENDENCIES_1) \ ../lib/libcoreutils.a -am_vdir_OBJECTS = ls.$(OBJEXT) ls-vdir.$(OBJEXT) +am_vdir_OBJECTS = ls.$(OBJEXT) ls-vdir.$(OBJEXT) ls-clp.$(OBJEXT) vdir_OBJECTS = $(am_vdir_OBJECTS) vdir_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) -wc_SOURCES = wc.c -wc_OBJECTS = wc.$(OBJEXT) +am_wc_OBJECTS = wc.$(OBJEXT) wc-clp.$(OBJEXT) +wc_OBJECTS = $(am_wc_OBJECTS) wc_LDADD = $(LDADD) wc_DEPENDENCIES = ../lib/libcoreutils.a $(am__DEPENDENCIES_1) \ ../lib/libcoreutils.a @@ -677,10 +677,10 @@ rmdir.c seq.c setuidgid.c $(sha1sum_SOURCES) \ $(sha224sum_SOURCES) $(sha256sum_SOURCES) $(sha384sum_SOURCES) \ $(sha512sum_SOURCES) shred.c shuf.c sleep.c sort.c split.c \ - stat.c stty.c su.c sum.c sync.c tac.c tail.c tee.c test.c \ - touch.c tr.c true.c tsort.c tty.c uname.c unexpand.c uniq.c \ - unlink.c uptime.c users.c $(vdir_SOURCES) wc.c who.c whoami.c \ - yes.c + stat.c stty.c su.c sum.c sync.c tac.c $(tail_SOURCES) tee.c \ + test.c touch.c tr.c true.c tsort.c tty.c uname.c unexpand.c \ + uniq.c unlink.c uptime.c users.c $(vdir_SOURCES) $(wc_SOURCES) \ + who.c whoami.c yes.c DIST_SOURCES = $(__SOURCES) base64.c basename.c cat.c $(chgrp_SOURCES) \ chmod.c $(chown_SOURCES) chroot.c cksum.c comm.c $(cp_SOURCES) \ csplit.c cut.c date.c dd.c df.c $(dir_SOURCES) dircolors.c \ @@ -693,10 +693,10 @@ rmdir.c seq.c setuidgid.c $(sha1sum_SOURCES) \ $(sha224sum_SOURCES) $(sha256sum_SOURCES) $(sha384sum_SOURCES) \ $(sha512sum_SOURCES) shred.c shuf.c sleep.c sort.c split.c \ - stat.c stty.c su.c sum.c sync.c tac.c tail.c tee.c test.c \ - touch.c tr.c true.c tsort.c tty.c uname.c unexpand.c uniq.c \ - unlink.c uptime.c users.c $(vdir_SOURCES) wc.c who.c whoami.c \ - yes.c + stat.c stty.c su.c sum.c sync.c tac.c $(tail_SOURCES) tee.c \ + test.c touch.c tr.c true.c tsort.c tty.c uname.c unexpand.c \ + uniq.c unlink.c uptime.c users.c $(vdir_SOURCES) $(wc_SOURCES) \ + who.c whoami.c yes.c HEADERS = $(noinst_HEADERS) ETAGS = etags CTAGS = ctags @@ -1019,7 +1019,7 @@ groups.sh wheel-gen.pl extract-magic c99-to-c89.diff BUILT_SOURCES = dircolors.h wheel-size.h wheel.h fs.h -CLEANFILES = $(SCRIPTS) su +CLEANFILES = $(SCRIPTS) su *.gp *-clp.c *-clp.h AM_CPPFLAGS = -I$(top_srcdir)/lib # Sometimes, the expansion of $(LIBINTL) includes -lc which may @@ -1094,13 +1094,15 @@ # This is for the '[' program. Automake transliterates '[' to '_'. __SOURCES = lbracket.c cp_SOURCES = cp.c copy.c cp-hash.c -dir_SOURCES = ls.c ls-dir.c -vdir_SOURCES = ls.c ls-vdir.c -ls_SOURCES = ls.c ls-ls.c +dir_SOURCES = ls.c ls-dir.c ls-clp.c ls-clp.h +vdir_SOURCES = ls.c ls-vdir.c ls-clp.c ls-clp.h +ls_SOURCES = ls.c ls-ls.c ls-clp.c ls-clp.h chown_SOURCES = chown.c chown-core.c chgrp_SOURCES = chgrp.c chown-core.c mv_SOURCES = mv.c copy.c cp-hash.c remove.c rm_SOURCES = rm.c remove.c +tail_SOURCES = tail.c tail-clp.c +wc_SOURCES = wc.c wc-clp.c md5sum_SOURCES = md5sum.c md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS) sha1sum_SOURCES = md5sum.c @@ -1200,7 +1202,7 @@ done clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) > /dev/null 2>&1 || /bin/rm -f $(bin_PROGRAMS) + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) clean-noinstPROGRAMS: -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) @@ -1558,6 +1560,7 @@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @@ -1601,6 +1604,7 @@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @@ -1615,6 +1619,7 @@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@ @@ -2060,6 +2065,20 @@ | grep -Ev -f $$t && \ { echo 'the above variables should have static scope' 1>&2; \ exit 1; } || : + +# make doesn't detect the following dependencies automatically because +# %-clp.h doesn't yet exist during initial dependency scan +ls.c: ls-clp.h +tail.c: tail-clp.h +wc.c: wc-clp.h + +%-clp.c %-clp.h: %.gp + genparse --longmembers --internationalize -o $(*F)-clp $< + +# %.gp depends on %.c but this would introduce a circular dependency +%.gp: + sed -n -e '/genparse file starts here/,/genparse file ends here/p' < $(*F).c | \ + sed -e '/genparse file ends here/d' -n -e '2,$$p' > $@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff -u -N -r coreutils-6.9.orig/src/tail.c coreutils-6.9/src/tail.c --- coreutils-6.9.orig/src/tail.c 2007-03-18 22:36:43.000000000 +0100 +++ coreutils-6.9/src/tail.c 2007-08-26 19:58:23.000000000 +0200 @@ -31,7 +31,6 @@ #include #include -#include "system.h" #include "argmatch.h" #include "c-strtod.h" #include "error.h" @@ -45,6 +44,7 @@ #include "xnanosleep.h" #include "xstrtol.h" #include "xstrtod.h" +#include "tail-clp.h" /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "tail" @@ -52,9 +52,6 @@ #define AUTHORS \ "Paul Rubin", "David MacKenzie, Ian Lance Taylor", "Jim Meyering" -/* Number of items to tail. */ -#define DEFAULT_N_LINES 10 - /* Special values for dump_remainder's N_BYTES parameter. */ #define COPY_TO_EOF UINTMAX_MAX #define COPY_A_BUFFER (UINTMAX_MAX - 1) @@ -151,12 +148,6 @@ multiple_files, always, never }; -/* When tailing a file by name, if there have been this many consecutive - iterations for which the file has not changed, then open/fstat - the file to determine if that file name is still associated with the - same device/inode-number pair as before. This option is meaningful only - when following by name. --max-unchanged-stats=N */ -#define DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS 5 static uintmax_t max_n_unchanged_stats_between_opens = DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS; @@ -175,118 +166,6 @@ more expensive) code unconditionally. Intended solely for testing. */ static bool presume_input_pipe; -/* For long options that have no equivalent short option, use a - non-character as a pseudo short option, starting with CHAR_MAX + 1. */ -enum -{ - RETRY_OPTION = CHAR_MAX + 1, - MAX_UNCHANGED_STATS_OPTION, - PID_OPTION, - PRESUME_INPUT_PIPE_OPTION, - LONG_FOLLOW_OPTION -}; - -static struct option const long_options[] = -{ - {"bytes", required_argument, NULL, 'c'}, - {"follow", optional_argument, NULL, LONG_FOLLOW_OPTION}, - {"lines", required_argument, NULL, 'n'}, - {"max-unchanged-stats", required_argument, NULL, MAX_UNCHANGED_STATS_OPTION}, - {"pid", required_argument, NULL, PID_OPTION}, - {"-presume-input-pipe", no_argument, NULL, - PRESUME_INPUT_PIPE_OPTION}, /* do not document */ - {"quiet", no_argument, NULL, 'q'}, - {"retry", no_argument, NULL, RETRY_OPTION}, - {"silent", no_argument, NULL, 'q'}, - {"sleep-interval", required_argument, NULL, 's'}, - {"verbose", no_argument, NULL, 'v'}, - {GETOPT_HELP_OPTION_DECL}, - {GETOPT_VERSION_OPTION_DECL}, - {NULL, 0, NULL, 0} -}; - -void -usage (int status) -{ - if (status != EXIT_SUCCESS) - fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); - else - { - printf (_("\ -Usage: %s [OPTION]... [FILE]...\n\ -"), - program_name); - printf (_("\ -Print the last %d lines of each FILE to standard output.\n\ -With more than one FILE, precede each with a header giving the file name.\n\ -With no FILE, or when FILE is -, read standard input.\n\ -\n\ -"), DEFAULT_N_LINES); - fputs (_("\ -Mandatory arguments to long options are mandatory for short options too.\n\ -"), stdout); - fputs (_("\ - --retry keep trying to open a file even if it is\n\ - inaccessible when tail starts or if it becomes\n\ - inaccessible later; useful when following by name,\n\ - i.e., with --follow=name\n\ - -c, --bytes=N output the last N bytes; alternatively, use +N to\n\ - output bytes starting with the Nth of each file\n\ -"), stdout); - fputs (_("\ - -f, --follow[={name|descriptor}]\n\ - output appended data as the file grows;\n\ - -f, --follow, and --follow=descriptor are\n\ - equivalent\n\ - -F same as --follow=name --retry\n\ -"), stdout); - printf (_("\ - -n, --lines=N output the last N lines, instead of the last %d;\n\ - or use +N to output lines starting with the Nth\n\ - --max-unchanged-stats=N\n\ - with --follow=name, reopen a FILE which has not\n\ - changed size after N (default %d) iterations\n\ - to see if it has been unlinked or renamed\n\ - (this is the usual case of rotated log files)\n\ -"), - DEFAULT_N_LINES, - DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS - ); - fputs (_("\ - --pid=PID with -f, terminate after process ID, PID dies\n\ - -q, --quiet, --silent never output headers giving file names\n\ - -s, --sleep-interval=S with -f, sleep for approximately S seconds\n\ - (default 1.0) between iterations.\n\ - -v, --verbose always output headers giving file names\n\ -"), stdout); - fputs (HELP_OPTION_DESCRIPTION, stdout); - fputs (VERSION_OPTION_DESCRIPTION, stdout); - fputs (_("\ -\n\ -If the first character of N (the number of bytes or lines) is a `+',\n\ -print beginning with the Nth item from the start of each file, otherwise,\n\ -print the last N items in the file. N may have a multiplier suffix:\n\ -b 512, k 1024, m 1024*1024.\n\ -\n\ -"), stdout); - fputs (_("\ -With --follow (-f), tail defaults to following the file descriptor, which\n\ -means that even if a tail'ed file is renamed, tail will continue to track\n\ -its end. \ -"), stdout); - fputs (_("\ -This default behavior is not desirable when you really want to\n\ -track the actual name of the file, not the file descriptor (e.g., log\n\ -rotation). Use --follow=name in that case. That causes tail to track the\n\ -named file by reopening it periodically to see if it has been removed and\n\ -recreated by some other program.\n\ -"), stdout); - printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); - } - exit (status); -} - static bool valid_file_spec (struct File_spec const *f) { @@ -1446,122 +1325,129 @@ return true; } +void param_lines_or_bytes(bool lines, char *arg_str, uintmax_t *n_units) +{ + count_lines = lines; + if (*arg_str == '+') + from_start = true; + else if (*arg_str == '-') + ++arg_str; + + { + strtol_error s_err; + s_err = xstrtoumax (arg_str, NULL, 10, n_units, "bkm"); + if (s_err != LONGINT_OK) + { + error (EXIT_FAILURE, 0, "%s: %s", arg_str, + (lines + ? _("invalid number of lines") + : _("invalid number of bytes"))); + } + } +} + static void parse_options (int argc, char **argv, uintmax_t *n_units, enum header_mode *header_mode, double *sleep_interval) { int c; + struct arg_t cmdline; - while ((c = getopt_long (argc, argv, "c:n:fFqs:v0123456789", - long_options, NULL)) - != -1) - { - switch (c) - { - case 'F': - forever = true; - follow_mode = Follow_name; - reopen_inaccessible_files = true; - break; - - case 'c': - case 'n': - count_lines = (c == 'n'); - if (*optarg == '+') - from_start = true; - else if (*optarg == '-') - ++optarg; + Cmdline(&cmdline, argc, argv); - { - strtol_error s_err; - s_err = xstrtoumax (optarg, NULL, 10, n_units, "bkm"); - if (s_err != LONGINT_OK) - { - error (EXIT_FAILURE, 0, "%s: %s", optarg, - (c == 'n' - ? _("invalid number of lines") - : _("invalid number of bytes"))); - } - } - break; + if (cmdline.lines != NULL) + param_lines_or_bytes(true, cmdline.lines, n_units); - case 'f': - case LONG_FOLLOW_OPTION: - forever = true; - if (optarg == NULL) - follow_mode = DEFAULT_FOLLOW_MODE; - else - follow_mode = XARGMATCH ("--follow", optarg, - follow_mode_string, follow_mode_map); - break; + if (cmdline.bytes != NULL) + param_lines_or_bytes(false, cmdline.bytes, n_units); - case RETRY_OPTION: - reopen_inaccessible_files = true; - break; + if (cmdline.follow_flag) + { + forever = true; + if (cmdline.follow == NULL) + follow_mode = DEFAULT_FOLLOW_MODE; + else + follow_mode = XARGMATCH ("--follow", cmdline.follow, + follow_mode_string, follow_mode_map); + } - case MAX_UNCHANGED_STATS_OPTION: - /* --max-unchanged-stats=N */ - if (xstrtoumax (optarg, NULL, 10, - &max_n_unchanged_stats_between_opens, - "") - != LONGINT_OK) - { - error (EXIT_FAILURE, 0, - _("%s: invalid maximum number of unchanged stats between opens"), - optarg); - } - break; + if (cmdline.F) + { + forever = true; + follow_mode = Follow_name; + reopen_inaccessible_files = true; + } - case PID_OPTION: - { - strtol_error s_err; - unsigned long int tmp_ulong; - s_err = xstrtoul (optarg, NULL, 10, &tmp_ulong, ""); - if (s_err != LONGINT_OK || tmp_ulong > PID_T_MAX) - { - error (EXIT_FAILURE, 0, _("%s: invalid PID"), optarg); - } - pid = tmp_ulong; - } - break; + reopen_inaccessible_files = cmdline.retry; - case PRESUME_INPUT_PIPE_OPTION: - presume_input_pipe = true; - break; + if (cmdline.max_unchanged_stats != NULL) + { + /* --max-unchanged-stats=N */ + if (xstrtoumax (cmdline.max_unchanged_stats, NULL, 10, + &max_n_unchanged_stats_between_opens, + "") + != LONGINT_OK) + { + error (EXIT_FAILURE, 0, + _("%s: invalid maximum number of unchanged stats between opens"), + cmdline.max_unchanged_stats); + } + } - case 'q': - *header_mode = never; - break; + if (cmdline.pid != NULL) + { + strtol_error s_err; + unsigned long int tmp_ulong; + s_err = xstrtoul (cmdline.pid, NULL, 10, &tmp_ulong, ""); + if (s_err != LONGINT_OK || tmp_ulong > PID_T_MAX) + { + error (EXIT_FAILURE, 0, _("%s: invalid PID"), cmdline.pid); + } + pid = tmp_ulong; + } - case 's': - { - double s; - if (! (xstrtod (optarg, NULL, &s, c_strtod) && 0 <= s)) - error (EXIT_FAILURE, 0, - _("%s: invalid number of seconds"), optarg); - *sleep_interval = s; - } - break; + presume_input_pipe = cmdline._presume_input_pipe; - case 'v': - *header_mode = always; - break; + if (cmdline.quiet) + *header_mode = never; - case_GETOPT_HELP_CHAR; + if (cmdline.sleep_interval != NULL) + { + double s; + if (! (xstrtod (cmdline.sleep_interval, NULL, &s, c_strtod) && 0 <= s)) + error (EXIT_FAILURE, 0, + _("%s: invalid number of seconds"), cmdline.sleep_interval); + *sleep_interval = s; + } - case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + if (cmdline.verbose) + *header_mode = always; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - error (EXIT_FAILURE, 0, - _("option used in invalid context -- %c"), c); + if (cmdline.help) + usage (EXIT_SUCCESS, program_name); - default: - usage (EXIT_FAILURE); - } + if (cmdline.version) + { + version_etc (stdout, PROGRAM_NAME, GNU_PACKAGE, VERSION, AUTHORS, + (char *) NULL); + exit (EXIT_SUCCESS); } + c = 0; + if (cmdline._0) c = '0'; + if (cmdline._1) c = '1'; + if (cmdline._2) c = '2'; + if (cmdline._3) c = '3'; + if (cmdline._4) c = '4'; + if (cmdline._5) c = '5'; + if (cmdline._6) c = '6'; + if (cmdline._7) c = '7'; + if (cmdline._8) c = '8'; + if (cmdline._9) c = '9'; + if (c) + error (EXIT_FAILURE, 0, _("option used in invalid context -- %c"), c); + if (reopen_inaccessible_files && follow_mode != Follow_name) error (0, 0, _("warning: --retry is useful mainly when following by name")); @@ -1695,3 +1581,77 @@ error (EXIT_FAILURE, errno, "-"); exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); } + +/* Extract the following section an process it with genparse + (see http://genparse.sourceforge.net) in order to generate a parser + for the command line arguments and a usage function for printing a help + screen. */ + +/* genparse file starts here +#include +#include "system.h" +#include "tail.h" + +NONE / retry flag "keep trying to open a file even if it is" + "inaccessible when tail starts or if it becomes" + "inaccessible later; useful when following by name," + "i.e., with --follow=name" +c / bytes=N string "output the last N bytes; alternatively, use +N to" + "output bytes starting with the Nth of each file" +f! / follow*[={name|descriptor}] string "" + "output appended data as the file grows;" + "-f, --follow, and --follow=descriptor are" + "equivalent" +F flag "same as --follow=name --retry" +n / lines=N string "output the last N lines, instead of the last __INT__(DEFAULT_N_LINES);" + "or use +N to output lines starting with the Nth" +NONE / max-unchanged-stats=N string "" + "with --follow=name, reopen a FILE which has not" + "changed size after N (default __INT__(DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS)) iterations" + "to see if it has been unlinked or renamed" + "(this is the usual case of rotated log files)" +NONE / pid=PID string "with -f, terminate after process ID, PID dies" +q / quiet flag "never output headers giving file names" +NONE / silent flag "same as --quiet" +s / sleep-interval=S string "with -f, sleep for approximately S seconds" + "(default 1.0) between iterations." +v / verbose flag "always output headers giving file names" +NONE / help flag "display this help and exit" +NONE / version flag "output version information and exit" +NONE / -presume-input-pipe flag "__DO_NOT_DOCUMENT__" +0 flag "__DO_NOT_DOCUMENT__" +1 flag "__DO_NOT_DOCUMENT__" +2 flag "__DO_NOT_DOCUMENT__" +3 flag "__DO_NOT_DOCUMENT__" +4 flag "__DO_NOT_DOCUMENT__" +5 flag "__DO_NOT_DOCUMENT__" +6 flag "__DO_NOT_DOCUMENT__" +7 flag "__DO_NOT_DOCUMENT__" +8 flag "__DO_NOT_DOCUMENT__" +9 flag "__DO_NOT_DOCUMENT__" + +#usage_begin +Usage: __PROGRAM_NAME__ [OPTION]... [FILE]... +Print the last __INT__(DEFAULT_N_LINES) lines of each FILE to standard output. +With more than one FILE, precede each with a header giving the file name. +With no FILE, or when FILE is -, read standard input. +Mandatory arguments to long options are mandatory for short options too. + +__GLOSSARY_GNU__(27) + +If the first character of N (the number of bytes or lines) is a `+', +print beginning with the Nth item from the start of each file, otherwise, +print the last N items in the file. N may have a multiplier suffix: +b 512, k 1024, m 1024*1024. + +With --follow (-f), tail defaults to following the file descriptor, which +means that even if a tail'ed file is renamed, tail will continue to track +its end. This default behavior is not desirable when you really want to +track the actual name of the file, not the file descriptor (e.g., log +rotation). Use --follow=name in that case. That causes tail to track the +named file by reopening it periodically to see if it has been removed and +recreated by some other program. + +Report bugs to <__STRING__(PACKAGE_BUGREPORT)>. +#usage_end +genparse file ends here */ diff -u -N -r coreutils-6.9.orig/src/tail.h coreutils-6.9/src/tail.h --- coreutils-6.9.orig/src/tail.h 1970-01-01 01:00:00.000000000 +0100 +++ coreutils-6.9/src/tail.h 2007-08-19 13:47:42.000000000 +0200 @@ -0,0 +1,9 @@ +/* Number of items to tail. */ +#define DEFAULT_N_LINES 10 + +/* When tailing a file by name, if there have been this many consecutive + iterations for which the file has not changed, then open/fstat + the file to determine if that file name is still associated with the + same device/inode-number pair as before. This option is meaningful only + when following by name. --max-unchanged-stats=N */ +#define DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS 5 diff -u -N -r coreutils-6.9.orig/src/wc.c coreutils-6.9/src/wc.c --- coreutils-6.9.orig/src/wc.c 2007-03-18 22:36:43.000000000 +0100 +++ coreutils-6.9/src/wc.c 2007-08-26 19:58:25.000000000 +0200 @@ -24,13 +24,13 @@ #include #include -#include "system.h" #include "error.h" #include "inttostr.h" #include "quote.h" #include "readtokens0.h" #include "safe-read.h" #include "wcwidth.h" +#include "wc-clp.h" #if !defined iswspace && !HAVE_ISWSPACE # define iswspace(wc) \ @@ -77,60 +77,6 @@ struct stat st; }; -/* For long options that have no equivalent short option, use a - non-character as a pseudo short option, starting with CHAR_MAX + 1. */ -enum -{ - FILES0_FROM_OPTION = CHAR_MAX + 1 -}; - -static struct option const longopts[] = -{ - {"bytes", no_argument, NULL, 'c'}, - {"chars", no_argument, NULL, 'm'}, - {"lines", no_argument, NULL, 'l'}, - {"words", no_argument, NULL, 'w'}, - {"files0-from", required_argument, NULL, FILES0_FROM_OPTION}, - {"max-line-length", no_argument, NULL, 'L'}, - {GETOPT_HELP_OPTION_DECL}, - {GETOPT_VERSION_OPTION_DECL}, - {NULL, 0, NULL, 0} -}; - -void -usage (int status) -{ - if (status != EXIT_SUCCESS) - fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); - else - { - printf (_("\ -Usage: %s [OPTION]... [FILE]...\n\ - or: %s [OPTION]... --files0-from=F\n\ -"), - program_name, program_name); - fputs (_("\ -Print newline, word, and byte counts for each FILE, and a total line if\n\ -more than one FILE is specified. With no FILE, or when FILE is -,\n\ -read standard input.\n\ - -c, --bytes print the byte counts\n\ - -m, --chars print the character counts\n\ - -l, --lines print the newline counts\n\ -"), stdout); - fputs (_("\ - --files0-from=F read input from the files specified by\n\ - NUL-terminated names in file F\n\ - -L, --max-line-length print the length of the longest line\n\ - -w, --words print the word counts\n\ -"), stdout); - fputs (HELP_OPTION_DESCRIPTION, stdout); - fputs (VERSION_OPTION_DESCRIPTION, stdout); - printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); - } - exit (status); -} - /* FILE is the name of the file (or NULL for standard input) associated with the specified counters. */ static void @@ -580,6 +526,7 @@ char *files_from = NULL; struct fstatus *fstatus; struct Tokens tok; + struct arg_t cmdline; initialize_main (&argc, &argv); program_name = argv[0]; @@ -589,44 +536,25 @@ atexit (close_stdout); - print_lines = print_words = print_chars = print_bytes = false; - print_linelength = false; total_lines = total_words = total_chars = total_bytes = max_line_length = 0; - while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1) - switch (optc) - { - case 'c': - print_bytes = true; - break; - - case 'm': - print_chars = true; - break; - - case 'l': - print_lines = true; - break; - - case 'w': - print_words = true; - break; - - case 'L': - print_linelength = true; - break; - - case FILES0_FROM_OPTION: - files_from = optarg; - break; - - case_GETOPT_HELP_CHAR; - - case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); - - default: - usage (EXIT_FAILURE); - } + Cmdline(&cmdline, argc, argv); + print_bytes = cmdline.bytes; + print_chars = cmdline.chars; + print_lines = cmdline.lines; + print_words = cmdline.words; + print_linelength = cmdline.max_line_length; + files_from = cmdline.files0_from; + + if (cmdline.help) + usage (EXIT_SUCCESS, program_name); + + if (cmdline.version) + { + version_etc (stdout, PROGRAM_NAME, GNU_PACKAGE, VERSION, AUTHORS, + (char *) NULL); + exit (EXIT_SUCCESS); + } if (! (print_lines | print_words | print_chars | print_bytes | print_linelength)) @@ -643,7 +571,7 @@ error (0, 0, _("extra operand %s"), quote (argv[optind])); fprintf (stderr, "%s\n", _("File operands cannot be combined with --files0-from.")); - usage (EXIT_FAILURE); + usage (EXIT_FAILURE, program_name); } if (STREQ (files_from, "-")) @@ -702,3 +630,35 @@ exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); } + +/* Extract the following section an process it with genparse + (see http://genparse.sourceforge.net) in order to generate a parser + for the command line arguments and a usage function for printing a help + screen. */ + +/* genparse file starts here +#include +#include "system.h" + +c / bytes flag "print the byte counts" +m / chars flag "print the character counts" +l / lines flag "print the newline counts" +NONE / files0-from=F string "read input from the files specified by" + " NUL-terminated names in file F" +L / max-line-length flag "print the length of the longest line" +w / words flag "print the word counts" +NONE / help flag "display this help and exit" +NONE / version flag "output version information and exit" + +#usage_begin +Usage: __PROGRAM_NAME__ [OPTION]... [FILE]... + or: __PROGRAM_NAME__ [OPTION]... --files0-from=F +Print newline, word, and byte counts for each FILE, and a total line if +more than one FILE is specified. With no FILE, or when FILE is -, +read standard input. + +__GLOSSARY_GNU__(25) + +Report bugs to <__STRING__(PACKAGE_BUGREPORT)>. +#usage_end +genparse file ends here */