seq + ruler patch for coreutils seq.c v1.2
von linuxCowboy- SNIPPET_DESC:
- diff -u seq.c.org seq.c
- SNIPPET_CREATION_TIME:
- 03.09.2015 21:10:31
- SNIPPET_PRUNE_TIME:
- Unendlich
- SNIPPET_TEXT:
-
- --- seq.c.org 2015-08-22 11:03:42.000000000 +0200
- +++ seq.c 2015-09-03 14:42:44.000000000 +0200
- @@ -20,6 +20,7 @@
- #include <getopt.h>
- #include <stdio.h>
- #include <sys/types.h>
- +#include <sys/ioctl.h>
- #include "system.h"
- #include "c-strtod.h"
- @@ -48,11 +49,19 @@
- Usually "\n" or "\0". */
- static char const terminator[] = "\n";
- +/* print a ruler */
- +static bool ruler;
- +
- +/* true for alphabetic: A-Z a-z */
- +static bool alpha;
- +
- static struct option const long_options[] =
- {
- { "equal-width", no_argument, NULL, 'w'},
- { "format", required_argument, NULL, 'f'},
- { "separator", required_argument, NULL, 's'},
- + { "ruler", no_argument, NULL, 'r'},
- + { "alpha", no_argument, NULL, 'a'},
- {GETOPT_HELP_OPTION_DECL},
- {GETOPT_VERSION_OPTION_DECL},
- { NULL, 0, NULL, 0}
- @@ -80,6 +89,8 @@
- -f, --format=FORMAT use printf style floating-point FORMAT\n\
- -s, --separator=STRING use STRING to separate numbers (default: \\n)\n\
- -w, --equal-width equalize width by padding with leading zeroes\n\
- + -a, --alpha alphabetic: A-Z a-z\n\
- + -r, --ruler print a ruler\n\
- "), stdout);
- fputs (HELP_OPTION_DESCRIPTION, stdout);
- fputs (VERSION_OPTION_DESCRIPTION, stdout);
- @@ -555,7 +566,7 @@
- break;
- }
- - optc = getopt_long (argc, argv, "+f:s:w", long_options, NULL);
- + optc = getopt_long (argc, argv, "+af:rs:w", long_options, NULL);
- if (optc == -1)
- break;
- @@ -573,6 +584,14 @@
- equal_width = true;
- break;
- + case 'a':
- + alpha = true;
- + break;
- +
- + case 'r':
- + ruler = true;
- + break;
- +
- case_GETOPT_HELP_CHAR;
- case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
- @@ -582,6 +601,19 @@
- }
- }
- + if (ruler) {
- + char *p = "012345678_";
- + struct winsize w;
- +
- + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
- +
- + for (int i = 1; i <= (w.ws_col > 0 && w.ws_col < 256 ? w.ws_col : 80); ++i)
- + printf("%c", i % 10 ? p[i % 10] : i / 10 % 10 + 48);
- +
- + fputs (terminator, stdout);
- + return EXIT_SUCCESS;
- + }
- +
- unsigned int n_args = argc - optind;
- if (n_args < 1)
- {
- @@ -595,6 +627,34 @@
- usage (EXIT_FAILURE);
- }
- + if (alpha) {
- + unsigned char last = *argv[argc - 1];
- +
- + if (! ((last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z')))
- + error(EXIT_FAILURE, 0, _("ascii letter only!"));
- +
- + int incr = n_args == 3 ? atoi(argv[argc - 2]) : 1;
- +
- + if (! (incr && incr >= -25 && incr <= +25))
- + error(EXIT_FAILURE, 0, _("bad increment!"));
- +
- + unsigned char first = n_args == 3 ? *argv[argc - 3] : n_args == 2 ? *argv[argc - 2] : last <= 'Z' ? 'A' : 'a';
- +
- + if (! ((first >= 'A' && first <= 'Z') || (first >= 'a' && first <= 'z')))
- + error(EXIT_FAILURE, 0, _("ascii letter only!"));
- +
- + if (! ((first <= 'Z' && last <= 'Z') || (first >= 'a' && last >= 'a')))
- + error(EXIT_FAILURE, 0, _("bad range!"));
- +
- + for (int i = first; incr > 0 && i <= last || incr < 0 && i >= last; i += incr) {
- + i == first || fputs (separator, stdout);
- + fputc(i, stdout);
- + }
- + fputs (terminator, stdout);
- +
- + return EXIT_SUCCESS;
- + }
- +
- if (format_str)
- format_str = long_double_format (format_str, &layout);
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN