diff -u -N -r coreutils.orig/doc/Makefile.am coreutils/doc/Makefile.am --- coreutils.orig/doc/Makefile.am 2007-07-23 20:41:09.000000000 +0200 +++ coreutils/doc/Makefile.am 2007-09-22 13:21:50.000000000 +0200 @@ -30,10 +30,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.orig/Makefile.maint coreutils/Makefile.maint --- coreutils.orig/Makefile.maint 2007-08-24 15:26:34.000000000 +0200 +++ coreutils/Makefile.maint 2007-09-22 13:21:50.000000000 +0200 @@ -435,7 +435,8 @@ po-check: if test -f po/POTFILES.in; then \ grep -E -v '^(#|$$)' po/POTFILES.in \ - | grep -v '^src/false\.c$$' | sort > address@hidden; \ + | grep -v '^src/false\.c$$' \ + | grep -v '\-clp\.c$$' | sort > address@hidden; \ files=; \ for file in $$($(CVS_LIST_EXCEPT)) lib/*.[ch]; do \ case $$file in \ diff -u -N -r coreutils.orig/po/POTFILES.in coreutils/po/POTFILES.in --- coreutils.orig/po/POTFILES.in 2007-08-20 17:04:47.000000000 +0200 +++ coreutils/po/POTFILES.in 2007-09-22 13:21:50.000000000 +0200 @@ -70,6 +70,7 @@ src/ln.c src/logname.c src/ls.c +src/ls-clp.c src/md5sum.c src/mkdir.c src/mkfifo.c @@ -108,6 +109,7 @@ src/tac-pipe.c src/tac.c src/tail.c +src/tail-clp.c src/tee.c src/test.c src/touch.c @@ -122,6 +124,7 @@ src/uptime.c src/users.c src/wc.c +src/wc-clp.c src/who.c src/whoami.c src/yes.c diff -u -N -r coreutils.orig/src/help_version.gp coreutils/src/help_version.gp --- coreutils.orig/src/help_version.gp 1970-01-01 01:00:00.000000000 +0100 +++ coreutils/src/help_version.gp 2007-09-22 13:21:50.000000000 +0200 @@ -0,0 +1,2 @@ +NONE / help flag "display this help and exit__NEW_PRINT__" +NONE / version flag "output version information and exit__NEW_PRINT__" diff -u -N -r coreutils.orig/src/ls.c coreutils/src/ls.c --- coreutils.orig/src/ls.c 2007-08-28 11:58:57.000000000 +0200 +++ coreutils/src/ls.c 2007-09-22 13:21:50.000000000 +0200 @@ -77,7 +77,7 @@ # define SA_RESTART 0 #endif -#include "system.h" +#include "ls-clp.h" #include #include "acl.h" @@ -92,7 +92,6 @@ #include "filemode.h" #include "idcache.h" #include "inttostr.h" -#include "ls.h" #include "lstat.h" #include "mbswidth.h" #include "mpsort.h" @@ -240,7 +239,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; @@ -701,87 +699,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, - 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'}, - {"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}, - {"context", no_argument, 0, 'Z'}, - {"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", @@ -1374,6 +1291,7 @@ decode_switches (int argc, char **argv) { char *time_style_option = NULL; + struct arg_t cmdline; /* Record whether there is an option specifying sort type. */ bool sort_type_specified = false; @@ -1503,323 +1421,285 @@ } } - for (;;) - { - int oi = -1; - int c = getopt_long (argc, argv, - "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1", - long_options, &oi); - if (c == -1) - break; + Cmdline(&cmdline, argc, argv); - switch (c) - { - case 'a': - ignore_mode = IGNORE_MINIMAL; - break; + if (cmdline.all) + ignore_mode = IGNORE_MINIMAL; - case 'b': - set_quoting_style (NULL, escape_quoting_style); - break; + if (cmdline.escape) + set_quoting_style (NULL, escape_quoting_style); - case 'c': - time_type = time_ctime; - break; + if (cmdline.c) + time_type = time_ctime; - case 'd': - immediate_dirs = true; - break; + immediate_dirs = cmdline.directory; - 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; + 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 FILE_TYPE_INDICATOR_OPTION: /* --file-type */ - indicator_style = file_type; - break; + if (cmdline.file_type) + indicator_style = file_type; - case 'g': - format = long_format; - print_owner = false; - break; + if (cmdline.g) + { + format = long_format; + print_owner = false; + } - case 'h': - human_output_opts = human_autoscale | human_SI | human_base_1024; - file_output_block_size = output_block_size = 1; - break; + if (cmdline.human_readable) + { + human_output_opts = human_autoscale | human_SI | human_base_1024; + file_output_block_size = output_block_size = 1; + } - case 'i': - print_inode = true; - break; + print_inode = cmdline.inode; - case 'k': - human_output_opts = 0; - file_output_block_size = output_block_size = 1024; - 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 'l': - format = long_format; - break; + if (cmdline.l) + format = long_format; - case 'm': - format = with_commas; - break; + if (cmdline.m) + format = with_commas; - case 'n': - numeric_ids = true; - format = long_format; - break; + if (cmdline.numeric_uid_gid) + { + numeric_ids = true; + format = long_format; + } - case 'o': /* Just like -l, but don't display group info. */ - format = long_format; - print_group = false; - break; + if (cmdline.o) + { + format = long_format; + print_group = false; + } - case 'p': - indicator_style = slash; - break; + if (cmdline.p) + indicator_style = slash; - case 'q': - qmark_funny_chars = true; - break; + qmark_funny_chars = cmdline.hide_control_chars; - case 'r': - sort_reverse = true; - break; + sort_reverse = cmdline.reverse; - case 's': - print_block_size = true; - break; + print_block_size = cmdline.size; - case 't': - sort_type = sort_time; - sort_type_specified = true; - break; + if (cmdline.t) + { + sort_type = sort_time; + sort_type_specified = true; + } - case 'u': - time_type = time_atime; - break; + if (cmdline.u) + time_type = time_atime; - case 'v': - sort_type = sort_version; - sort_type_specified = true; - break; + if (cmdline.v) + { + sort_type = sort_version; + sort_type_specified = true; + } - 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.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 'x': - format = horizontal; - break; + if (cmdline.x) + format = horizontal; - case 'A': - if (ignore_mode == IGNORE_DEFAULT) - ignore_mode = IGNORE_DOT_AND_DOTDOT; - break; + if (cmdline.almost_all) + if (ignore_mode == IGNORE_DEFAULT) + ignore_mode = IGNORE_DOT_AND_DOTDOT; - case 'B': - add_ignore_pattern ("*~"); - add_ignore_pattern (".*~"); - break; + if (cmdline.ignore_backups) + { + add_ignore_pattern ("*~"); + add_ignore_pattern (".*~"); + } - case 'C': - format = many_per_line; - break; + if (cmdline.C) + format = many_per_line; - case 'D': - dired = true; - break; + dired = cmdline.dired; - case 'F': - indicator_style = classify; - break; + if (cmdline.classify) + indicator_style = classify; - case 'G': /* inhibit display of group info */ - print_group = false; - break; + if (cmdline.no_group) + print_group = false; - case 'H': - dereference = DEREF_COMMAND_LINE_ARGUMENTS; - break; + if (cmdline.dereference_command_line) + dereference = DEREF_COMMAND_LINE_ARGUMENTS; - case DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION: - dereference = DEREF_COMMAND_LINE_SYMLINK_TO_DIR; - break; + if (cmdline.dereference_command_line_symlink_to_dir) + dereference = DEREF_COMMAND_LINE_SYMLINK_TO_DIR; - case 'I': - add_ignore_pattern (optarg); - break; + if (cmdline.ignore != NULL) + add_ignore_pattern (cmdline.ignore); - case 'L': - dereference = DEREF_ALWAYS; - break; + if (cmdline.dereference) + dereference = DEREF_ALWAYS; - case 'N': - set_quoting_style (NULL, literal_quoting_style); - break; + if (cmdline.literal) + set_quoting_style (NULL, literal_quoting_style); - case 'Q': - set_quoting_style (NULL, c_quoting_style); - break; + if (cmdline.quote_name) + set_quoting_style (NULL, c_quoting_style); - case 'R': - recursive = true; - break; + recursive = cmdline.recursive; - case 'S': - sort_type = sort_size; - sort_type_specified = true; - break; + if (cmdline.S) + { + sort_type = sort_size; + sort_type_specified = true; + } - 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.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 'U': - sort_type = sort_none; - sort_type_specified = true; - break; + if (cmdline.U) + { + sort_type = sort_none; + sort_type_specified = true; + } - case 'X': - sort_type = sort_extension; - sort_type_specified = true; - break; + if (cmdline.X) + { + sort_type = sort_extension; + sort_type_specified = true; + } - case '1': - /* -1 has no effect after -l. */ - if (format != long_format) - format = one_per_line; - break; + if (cmdline.context) + print_scontext = 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); - case FULL_TIME_OPTION: - format = long_format; - time_style_option = "full-iso"; - break; + if (cmdline.format != NULL) + format = XARGMATCH ("--format", cmdline.format, format_args, format_types); - 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.full_time) + { + format = long_format; + time_style_option = "full-iso"; + } - 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; - } + 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; - case INDICATOR_STYLE_OPTION: - indicator_style = XARGMATCH ("--indicator-style", optarg, - indicator_style_args, - indicator_style_types); - break; + print_with_color = (i == color_always + || (i == color_if_tty + && isatty (STDOUT_FILENO))); - case QUOTING_STYLE_OPTION: - set_quoting_style (NULL, - XARGMATCH ("--quoting-style", optarg, - quoting_style_args, - quoting_style_vals)); - 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 TIME_STYLE_OPTION: - time_style_option = optarg; - break; + if (cmdline.indicator_style != NULL) + indicator_style = XARGMATCH ("--indicator-style", cmdline.indicator_style, + indicator_style_args, + indicator_style_types); - case SHOW_CONTROL_CHARS_OPTION: - qmark_funny_chars = false; - break; + if (cmdline.quoting_style != NULL) + set_quoting_style (NULL, + XARGMATCH ("--quoting-style", cmdline.quoting_style, + quoting_style_args, + quoting_style_vals)); - case BLOCK_SIZE_OPTION: - { - enum strtol_error e = human_options (optarg, &human_output_opts, - &output_block_size); - if (e != LONGINT_OK) - xstrtol_fatal (e, oi, 0, long_options, optarg); - file_output_block_size = output_block_size; - } - break; + if (cmdline.time_style != NULL) + time_style_option = cmdline.time_style; - case SI_OPTION: - human_output_opts = human_autoscale | human_SI; - file_output_block_size = output_block_size = 1; - break; + if (cmdline.show_control_chars) + qmark_funny_chars = false; - case 'Z': - print_scontext = true; - break; + if (cmdline.block_size != NULL) + { + enum strtol_error e = human_options (cmdline.block_size, &human_output_opts, + &output_block_size); + if (e != LONGINT_OK) + { + xstrtol_fatal (e, cmdline.block_size_li, 0, get_long_options(), cmdline.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, PACKAGE_NAME, VERSION, AUTHORS, + (char *) NULL); + exit (EXIT_SUCCESS); } max_idx = MAX (1, line_length / MIN_COLUMN_WIDTH); @@ -4318,167 +4198,131 @@ 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\ - -Z, --context print any SELinux security context of each file\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); - emit_bug_reporting_address (); - } - 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 +#include "system.h" +#include "ls.h" + +#exit_value LS_FAILURE + +#export_long_options + +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__NEW_PRINT__" +NONE / block-size=SIZE string "use SIZE-byte blocks" #store_longindex +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__NEW_PRINT__" +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__NEW_PRINT__" +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__NEW_PRINT__" +g flag "like -l, but do not list owner__NEW_PRINT__" +NONE / group-directories-first flag "" + "group directories before files__NEW_PRINT__" +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__NEW_PRINT__" +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)__NEW_PRINT__" +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__NEW_PRINT__" +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__NEW_PRINT__" +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__NEW_PRINT__" +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__NEW_PRINT__" +r / reverse flag "reverse order while sorting" +R / recursive flag "list subdirectories recursively" +s / size flag "print the size of each file, in blocks__NEW_PRINT__" +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__NEW_PRINT__" +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__NEW_PRINT__" +t flag "sort by modification time" +T / tabsize=COLS string "assume tab stops at each COLS instead of 8__NEW_PRINT__" +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__NEW_PRINT__" +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" +Z / context flag "print any SELinux security context of each file" +1 flag "list one file per line__NEW_PRINT__" +#gp_include help_version.gp + +#usage_begin +Usage: __PROGRAM_NAME__ [OPTION]... [FILE]...__NEW_PRINT__ +List information about the FILEs (the current directory by default). +Sort entries alphabetically if none of -cftuvSUX nor --sort. +__NEW_PRINT__ +Mandatory arguments to long options are mandatory for short options too.__NEW_PRINT__ +__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.__NEW_PRINT__ + +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.__NEW_PRINT__ + +Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble. +__COMMAND__(emit_bug_reporting_address ()) +#usage_end +genparse file ends here */ diff -u -N -r coreutils.orig/src/ls.h coreutils/src/ls.h --- coreutils.orig/src/ls.h 1993-06-16 17:24:58.000000000 +0200 +++ coreutils/src/ls.h 2007-09-22 13:21:50.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.orig/src/Makefile.am coreutils/src/Makefile.am --- coreutils.orig/src/Makefile.am 2007-08-30 17:19:58.000000000 +0200 +++ coreutils/src/Makefile.am 2007-09-22 13:21:50.000000000 +0200 @@ -55,6 +55,7 @@ ls.h \ remove.h \ system.h \ + tail.h \ wheel-size.h \ wheel.h \ uname.h @@ -62,7 +63,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 AM_CPPFLAGS = -I$(top_srcdir)/lib @@ -213,15 +214,17 @@ __SOURCES = lbracket.c cp_SOURCES = cp.c $(copy_sources) -dir_SOURCES = ls.c ls-dir.c -vdir_SOURCES = ls.c ls-vdir.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 ln_SOURCES = ln.c -ls_SOURCES = ls.c ls-ls.c +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 remove.c $(copy_sources) rm_SOURCES = rm.c remove.c +tail_SOURCES = tail.c tail-clp.c tail-clp.h +wc_SOURCES = wc.c wc-clp.c wc-clp.h uname_SOURCES = uname.c uname-uname.c arch_SOURCES = uname.c uname-arch.c @@ -276,6 +279,22 @@ @chmod a-w address@hidden mv address@hidden $@ +BUILT_SOURCES += ls-clp.c ls-clp.h +ls.$(OBJEXT): ls-clp.c ls-clp.h + +BUILT_SOURCES += tail-clp.c tail-clp.h +tail.$(OBJEXT): tail-clp.c tail-clp.h + +BUILT_SOURCES += wc-clp.c wc-clp.h +wc.$(OBJEXT): wc-clp.c wc-clp.h + +%-clp.c %-clp.h: %.gp help_version.gp + genparse --longmembers --internationalize --static-headers -o $(*F)-clp $< + +%.gp: %.c + 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' > $@ + MAINTAINERCLEANFILES = $(BUILT_SOURCES) # Sort in traditional ASCII order, regardless of the current locale; @@ -381,16 +400,16 @@ # and relies on tools that not everyone has. # Most functions in src/*.c should have static scope. -# Any that don't must be marked with `extern', but `main' -# and `usage' are exceptions. They're always extern, but -# don't need to be marked. +# Any that don't must be marked with `extern', but `main', +# `usage', get_long_options and `Cmdline' are exceptions. +# They're always extern, but don't need to be marked. # # The second nm|grep checks for file-scope variables with `extern' scope. .PHONY: sc_tight_scope sc_tight_scope: $(all_programs) @t=exceptions-$$$$; \ trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15; \ - ( printf '^main$$\n^usage$$\n'; \ + ( printf '^main$$\n^usage$$\n^get_long_options$$\n^Cmdline$$\n';\ grep -h -A1 '^extern .*[^;]$$' $(SOURCES) \ | grep -vE '^(extern |--)' |sed 's/^/^/;s/ .*/$$/' ) > $$t; \ nm -e *.$(OBJEXT) \ diff -u -N -r coreutils.orig/src/tail.c coreutils/src/tail.c --- coreutils.orig/src/tail.c 2007-07-23 20:41:20.000000000 +0200 +++ coreutils/src/tail.c 2007-09-22 13:21:50.000000000 +0200 @@ -30,7 +30,7 @@ #include #include -#include "system.h" +#include "tail-clp.h" #include "argmatch.h" #include "c-strtod.h" #include "error.h" @@ -51,9 +51,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) @@ -150,12 +147,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; @@ -174,119 +165,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, kB 1000, K 1024, MB 1000*1000, M 1024*1024,\n\ -GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.\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); - emit_bug_reporting_address (); - } - exit (status); -} - static bool valid_file_spec (struct File_spec const *f) { @@ -1446,122 +1324,129 @@ return true; } +static 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, "bkKmMGTPEZY0"); + 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, "bkKmMGTPEZY0"); - 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, PACKAGE_NAME, 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 +1580,76 @@ 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 +#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__NEW_PRINT__" +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__NEW_PRINT__" +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)__NEW_PRINT__" +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__NEW_PRINT__" +#gp_include help_version.gp +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.__NEW_PRINT__ +Mandatory arguments to long options are mandatory for short options too.__NEW_PRINT__ +__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, kB 1000, K 1024, MB 1000*1000, M 1024*1024, +GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.__NEW_PRINT__ + +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. __NEW_PRINT__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. +__COMMAND__(emit_bug_reporting_address ()) +#usage_end +genparse file ends here */ diff -u -N -r coreutils.orig/src/tail.h coreutils/src/tail.h --- coreutils.orig/src/tail.h 1970-01-01 01:00:00.000000000 +0100 +++ coreutils/src/tail.h 2007-09-22 13:21:50.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.orig/src/wc.c coreutils/src/wc.c --- coreutils.orig/src/wc.c 2007-07-23 20:41:21.000000000 +0200 +++ coreutils/src/wc.c 2007-09-22 13:21:50.000000000 +0200 @@ -25,7 +25,7 @@ #include #include -#include "system.h" +#include "wc-clp.h" #include "error.h" #include "inttostr.h" #include "quote.h" @@ -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); - emit_bug_reporting_address (); - } - exit (status); -} - /* FILE is the name of the file (or NULL for standard input) associated with the specified counters. */ static void @@ -565,12 +511,12 @@ { int i; bool ok; - int optc; int nfiles; char **files; char *files_from = NULL; struct fstatus *fstatus; struct Tokens tok; + struct arg_t cmdline; initialize_main (&argc, &argv); program_name = argv[0]; @@ -580,44 +526,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, PACKAGE_NAME, VERSION, AUTHORS, + (char *) NULL); + exit (EXIT_SUCCESS); + } if (! (print_lines | print_words | print_chars | print_bytes | print_linelength)) @@ -634,7 +561,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, "-")) @@ -693,3 +620,33 @@ 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 +#include "system.h" + +c / bytes flag "print the byte counts" +m / chars flag "print the character counts" +l / lines flag "print the newline counts__NEW_PRINT__" +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__NEW_PRINT__" +#gp_include help_version.gp + +#usage_begin +Usage: __PROGRAM_NAME__ [OPTION]... [FILE]... + or: __PROGRAM_NAME__ [OPTION]... --files0-from=F__NEW_PRINT__ +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) +__COMMAND__(emit_bug_reporting_address ()) +#usage_end +genparse file ends here */