From: joeyh Date: Wed, 8 Mar 2006 03:19:40 +0000 (+0000) Subject: * Indentation improvements. X-Git-Tag: 0.5~3 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8c8aa26cb9f1f4bd411056ad3049ed0357ae3e4;p=moreutils * Indentation improvements. --- diff --git a/check-isutf8 b/check-isutf8 index 92d3933..036f909 100755 --- a/check-isutf8 +++ b/check-isutf8 @@ -5,15 +5,14 @@ # Lars Wirzenius check() { - printf "$2" | ./isutf8 -q - ret=$? - if [ $ret != $1 ] - then - echo "Failure:" - echo " input: $2" - echo " expected: $1" - echo " got: $ret" - fi + printf "$2" | ./isutf8 -q + ret=$? + if [ $ret != $1 ]; then + echo "Failure:" + echo " input: $2" + echo " expected: $1" + echo " got: $ret" + fi } check 0 '' diff --git a/debian/changelog b/debian/changelog index f40b9b5..2c84fca 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ moreutils (0.5) UNRELEASED; urgency=low * Made ifdata support -h and print usage on unknown options. * Cleaned up ifdata's behavior when asked to print info for nonexistant devices. Still needs improvement. + * Indentation improvements. -- Joey Hess Tue, 7 Mar 2006 21:54:45 -0500 diff --git a/ifdata.docbook b/ifdata.docbook index 42d0855..405d28a 100644 --- a/ifdata.docbook +++ b/ifdata.docbook @@ -26,240 +26,252 @@ with this program; if not, write to the Free Software Foundation, Inc., - - - Joey - Hess - - 2006-03-07 - + + + Joey + Hess + + 2006-03-07 + - - ifdata - 1 - + + ifdata + 1 + - - ifdata - get network interface info without parsing ifconfig output - + + ifdata + get network interface info without + parsing ifconfig output + - - - ifdata - options - iface - - + + + ifdata + options + iface + + - - DESCRIPTION - - ifdata can be used to check for the existence - of a network interface, or to get information abut the interface, such - as its IP address. Unlike ifconfig or ip, - ifdata has simple to parse output that is designed - to be easily used by a shell script. - - + + DESCRIPTION + + + ifdata can be used to check for + the existence of a network interface, or to get + information abut the interface, such as its IP + address. Unlike ifconfig or + ip, ifdata + has simple to parse output that is designed to be + easily used by a shell script. + + + - - OPTIONS - - - - - - - Print out a help summary. - - - - - - - Test to see if the interface exists. ifdata will exit - nonzero if the interface does not exist. - - - - - - - Prints out the whole configuration of the interface. - - + + OPTIONS + + + + + + + Print out a help summary. + + - - - - Prints "yes" or "no" if the interface exists or not. - - - - - - - Prints the IPv4 address of the interface. - - + + + + Test to see if the interface exists, + exit nonzero if it does not. + + + + + + + Prints out the whole configuration of + the interface. + + - - - - Prints the netmask of the interface. - - + + + + Prints "yes" or "no" if the interface + exists or not. + + - - - - Prints the network address of the interface. - - + + + + Prints the IPv4 address of the + interface. + + - - - - Prints the broadcast address of the interface. - - + + + + Prints the netmask of the + interface. + + - - - - Prints the MTU of the interface. - - + + + + Prints the network address of the + interface. + + + + + + + Prints the broadcast address of the + interface. + + + + + + + Prints the MTU of the interface. + + - - - - Prints the flags of the interface. - - + + + + Prints the flags of the + interface. + + - - - - Prints out all the input statistics of the interface. - - + + + + Prints out all the input statistics + of the interface. + + - - - - Prints the number of input packets. - - + + + + Prints the number of input packets. + + - - - - Prints the number of input bytes. - - + + + + Prints the number of input bytes. + + - - - - Prints the number of input errors. - - + + + + Prints the number of input errors. + + - - - - Prints the number of input drops. - - + + + + Prints the number of input drops. + + - - - - Prints the number of input fifo overruns. - - + + + + Prints the number of input fifo overruns. + + - - - - Print the number of input compress. - - + + + + Print the number of input compress. + + - - - - Prints the number of input multicast. - - + + + + Prints the number of input multicast. + + - - - - Prints out all the output statistics of the interface. - - + + + + Prints out all the output statistics + of the interface. + + - - - - Prints the number of output packets. - - + + + + Prints the number of output packets. + + - - - - Prints the number of output bytes. - - + + + + Prints the number of output bytes. + + - - - - Prints the number of output errors. - - + + + + Prints the number of output errors. + + - - - - Prints the number of output drops. - - + + + + Prints the number of output drops. + + - - - - Prints the number of output fifo overruns. - - + + + + Prints the number of output fifo overruns. + + - - - - Print the number of output collisions. - - + + + + Print the number of output collisions. + + - - - - Prints the number of output carrier loss. - - + + + + Prints the number of output carrier loss. + + - - - - Prints the number of output multicast. - - + + + + Prints the number of output multicast. + + - - - - + + diff --git a/isutf8.c b/isutf8.c index 88bb38b..59749c0 100644 --- a/isutf8.c +++ b/isutf8.c @@ -30,117 +30,113 @@ * I'm pretty sure there is a fancy trick to do this without a loop, * but I'm too tired to figure it out now. --liw */ -static int high_ones(int c) -{ - int n; +static int high_ones(int c) { + int n; - for (n = 0; (c & 0x80) == 0x80; c <<= 1) - ++n; - return n; + for (n = 0; (c & 0x80) == 0x80; c <<= 1) + ++n; + return n; } -static int is_utf8_byte_stream(FILE *file, char *filename, int quiet) -{ - int c, n, remaining_bytes; - unsigned long line, col; - - remaining_bytes = 0; - line = 1; - col = 1; - while ((c = getc(file)) != EOF) { - n = high_ones(c); - if (remaining_bytes > 0) { - if (n == 1) { - --remaining_bytes; - if (remaining_bytes == 0) - ++col; - } else - goto error; - } else if (n == 0) { - /* 7-bit character, skip, but adjust position */ - if (c == '\n') { - ++line; - col = 1; - } else - ++col; - } else if (n == 1) - goto error; /* wrong place for continuation byte */ - else - remaining_bytes = n - 1; /* start of multi-byte sequence */ - } - if (remaining_bytes > 0) - goto error; - return 1; - +static int is_utf8_byte_stream(FILE *file, char *filename, int quiet) { + int c, n, remaining_bytes; + unsigned long line, col; + + remaining_bytes = 0; + line = 1; + col = 1; + while ((c = getc(file)) != EOF) { + n = high_ones(c); + if (remaining_bytes > 0) { + if (n == 1) { + --remaining_bytes; + if (remaining_bytes == 0) + ++col; + } else + goto error; + } else if (n == 0) { + /* 7-bit character, skip, but adjust position */ + if (c == '\n') { + ++line; + col = 1; + } else + ++col; + } else if (n == 1) + goto error; /* wrong place for continuation byte */ + else + remaining_bytes = n - 1; /* start of multi-byte sequence */ + } + if (remaining_bytes > 0) + goto error; + return 1; + error: - if (!quiet) { - printf("%s: line %lu, col %lu: invalid UTF-8 code\n", - filename, line, col); - } - return 0; + if (!quiet) { + printf("%s: line %lu, col %lu: invalid UTF-8 code\n", + filename, line, col); + } + return 0; } -static void usage(const char *program_name) -{ - printf("Usage: %s [-hq] [--help] [--quiet] [file ...]\n", program_name); - printf("Check whether input files are valid UTF-8.\n"); - printf("This is version %s.\n", VERSION); +static void usage(const char *program_name) { + printf("Usage: %s [-hq] [--help] [--quiet] [file ...]\n", program_name); + printf("Check whether input files are valid UTF-8.\n"); + printf("This is version %s.\n", VERSION); } -int main(int argc, char **argv) -{ - int i, ok; - FILE *file; +int main(int argc, char **argv) { + int i, ok; + FILE *file; - int quiet; - struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "quiet", no_argument, &quiet, 1 }, - }; - int opt; - - quiet = 0; - - while ((opt = getopt_long(argc, argv, "hq", options, NULL)) != -1) { - switch (opt) { - case 0: - break; - - case 'h': - usage(argv[0]); - exit(0); - break; - - case 'q': - quiet = 1; - break; + int quiet; + struct option options[] = { + { "help", no_argument, NULL, 'h' }, + { "quiet", no_argument, &quiet, 1 }, + }; + int opt; + + quiet = 0; + + while ((opt = getopt_long(argc, argv, "hq", options, NULL)) != -1) { + switch (opt) { + case 0: + break; + + case 'h': + usage(argv[0]); + exit(0); + break; + + case 'q': + quiet = 1; + break; - case '?': - exit(EXIT_FAILURE); + case '?': + exit(EXIT_FAILURE); - default: - abort(); - } - } + default: + abort(); + } + } - if (optind == argc) - ok = is_utf8_byte_stream(stdin, "stdin", quiet); - else { - ok = 1; - for (i = optind; i < argc; ++i) { - file = fopen(argv[i], "r"); - if (file == NULL) { - fprintf(stderr, "isutf8: %s: error %d: %s\n", - argv[i], errno, strerror(errno)); - ok = 0; - } else { - ok = is_utf8_byte_stream(file, argv[i], quiet) && ok; - (void) fclose(file); - } - } - } - - if (ok) - exit(0); - exit(EXIT_FAILURE); + if (optind == argc) + ok = is_utf8_byte_stream(stdin, "stdin", quiet); + else { + ok = 1; + for (i = optind; i < argc; ++i) { + file = fopen(argv[i], "r"); + if (file == NULL) { + fprintf(stderr, "isutf8: %s: error %d: %s\n", + argv[i], errno, strerror(errno)); + ok = 0; + } else { + ok = is_utf8_byte_stream(file, argv[i], quiet) && ok; + (void) fclose(file); + } + } + } + + if (ok) + exit(0); + exit(EXIT_FAILURE); } diff --git a/isutf8.docbook b/isutf8.docbook index ef8ef9d..f9c9eb5 100644 --- a/isutf8.docbook +++ b/isutf8.docbook @@ -25,95 +25,93 @@ with this program; if not, write to the Free Software Foundation, Inc., []> + +
+ liw@iki.fi +
+ + Lars + Wirzenius + + 2006-02-19 +
- -
- liw@iki.fi -
- - Lars - Wirzenius - - 2006-02-19 -
+ + isutf8 + 1 + - - isutf8 - 1 - - - - isutf8 - check whether files are valid UTF-8 - - - - - isutf8 - - - - - file - - - - - - DESCRIPTION - - isutf8 checks whether files are - syntactically valid UTF-8. Input is either files named on the - command line, or the standard input. Notices about files with - invalid UTF-8 are printed to standard output. - - - - - OPTIONS - - - - - - - - Print out a help summary. - - - - - - - - Don't print messages telling which files are - invalid UTF-8, merely indicate it with the exit - status. - - - - - - - - - EXIT STATUS - - If the file is valid UTF-8, the exit status is zero. If the - file is not valid UTF-8, or there is some error, the exit status is - non-zero. - - - - - SEE ALSO - - - - utf87 - - - - + + isutf8 + check whether files are valid UTF-8 + + + + isutf8 + + + + + file + + + + + + DESCRIPTION + + isutf8 checks whether files are + syntactically valid UTF-8. Input is either files named on the + command line, or the standard input. Notices about files with + invalid UTF-8 are printed to standard output. + + + + + OPTIONS + + + + + + + + Print out a help summary. + + + + + + + + Don't print messages telling which files are + invalid UTF-8, merely indicate it with the exit + status. + + + + + + + + + EXIT STATUS + + If the file is valid UTF-8, the exit status is zero. + If the file is not valid UTF-8, or there is some + error, the exit status is non-zero. + + + + + SEE ALSO + + + + utf87 + + + +
diff --git a/sponge.c b/sponge.c index db5e04e..59952ea 100644 --- a/sponge.c +++ b/sponge.c @@ -30,62 +30,62 @@ #include void usage() { - printf("sponge : suck in all input from stdin and write it to "); - exit(0); + printf("sponge : suck in all input from stdin and write it to "); + exit(0); } int main(int argc, char **argv) { - char *buf, *bufstart; - size_t bufsize = 8192; - size_t bufused = 0; - ssize_t i = 0; - int outfd; - if (argc != 2) { - usage(); - } + char *buf, *bufstart; + size_t bufsize = 8192; + size_t bufused = 0; + ssize_t i = 0; + int outfd; + + if (argc != 2) { + usage(); + } - bufstart = buf = malloc(bufsize); - if (!buf) { - perror("malloc"); - exit(1); - } + bufstart = buf = malloc(bufsize); + if (!buf) { + perror("malloc"); + exit(1); + } - while ((i = read(0, buf, bufsize - bufused)) > 0) { - bufused = bufused+i; - if (bufused == bufsize) { - bufsize *= 2; - bufstart = realloc(bufstart, bufsize); - if (!bufstart) { - perror("realloc"); - exit(1); - } + while ((i = read(0, buf, bufsize - bufused)) > 0) { + bufused = bufused+i; + if (bufused == bufsize) { + bufsize *= 2; + bufstart = realloc(bufstart, bufsize); + if (!bufstart) { + perror("realloc"); + exit(1); + } - buf = bufstart + bufused; - } - } - if (i == -1) { - perror("read"); - exit(1); - } + buf = bufstart + bufused; + } + } + if (i == -1) { + perror("read"); + exit(1); + } - outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, - 0666); - if (outfd == -1) { - fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno)); - exit(1); - } + outfd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666); + if (outfd == -1) { + fprintf(stderr, "Can't open %s: %s\n", argv[1], strerror(errno)); + exit(1); + } - i = write(outfd, bufstart, bufused); - if (i == -1) { - perror("write"); - exit(1); - } + i = write(outfd, bufstart, bufused); + if (i == -1) { + perror("write"); + exit(1); + } - i = close(outfd); - if (i == -1) { - perror("close"); - exit(1); - } + i = close(outfd); + if (i == -1) { + perror("close"); + exit(1); + } - return 0; + return 0; } diff --git a/sponge.docbook b/sponge.docbook index 39bf77e..674ef05 100644 --- a/sponge.docbook +++ b/sponge.docbook @@ -2,7 +2,7 @@