diff options
| author | Andrea Adami <andrea.adami@gmail.com> | 2012-02-21 00:21:53 +0000 |
|---|---|---|
| committer | Koen Kooi <koen@dominion.thruhere.net> | 2012-02-22 09:40:24 +0100 |
| commit | 25c2e973e02ecc2a0aff4ccea8c53c42519ff5e3 (patch) | |
| tree | e30b37fbe42d536c34b55bb6364e5f1ccde80108 /meta-initramfs/recipes-devtools/klibc/klibc-1.5.25/wc.patch | |
| parent | 59c8231315753b91a4ded9a615a3c855ef5e77de (diff) | |
| download | meta-openembedded-25c2e973e02ecc2a0aff4ccea8c53c42519ff5e3.tar.gz | |
meta-initramfs: import klibc recipe and bbclass from meta-oe
Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Diffstat (limited to 'meta-initramfs/recipes-devtools/klibc/klibc-1.5.25/wc.patch')
| -rw-r--r-- | meta-initramfs/recipes-devtools/klibc/klibc-1.5.25/wc.patch | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/meta-initramfs/recipes-devtools/klibc/klibc-1.5.25/wc.patch b/meta-initramfs/recipes-devtools/klibc/klibc-1.5.25/wc.patch new file mode 100644 index 0000000000..28705fd7aa --- /dev/null +++ b/meta-initramfs/recipes-devtools/klibc/klibc-1.5.25/wc.patch | |||
| @@ -0,0 +1,245 @@ | |||
| 1 | Patch was imported from the OpenEmbedded git server | ||
| 2 | (git://git.openembedded.org/openembedded) | ||
| 3 | as of commit id acb6fa33fccf7196c86a3a28f927d4fa441d05eb | ||
| 4 | |||
| 5 | klibc: add wc to tools | ||
| 6 | * for use with uniboot | ||
| 7 | |||
| 8 | Signed-off-by: Thomas Kunze <thommycheck@gmx.de> | ||
| 9 | |||
| 10 | diff --git a/usr/utils/Kbuild b/usr/utils/Kbuild | ||
| 11 | index a52ea61..7c8ccfb 100644 | ||
| 12 | --- a/usr/utils/Kbuild | ||
| 13 | +++ b/usr/utils/Kbuild | ||
| 14 | @@ -3,7 +3,7 @@ | ||
| 15 | # | ||
| 16 | |||
| 17 | progs := chroot dd mkdir mkfifo mknod mount pivot_root umount | ||
| 18 | -progs += true false sleep ln mv nuke minips cat ls losetup | ||
| 19 | +progs += true false sleep ln mv nuke minips cat ls losetup wc | ||
| 20 | progs += uname halt kill readlink cpio sync dmesg modprobe | ||
| 21 | |||
| 22 | static-y := $(addprefix static/, $(progs)) | ||
| 23 | @@ -62,6 +62,8 @@ static/losetup-y := losetup.o | ||
| 24 | shared/losetup-y := losetup.o | ||
| 25 | static/modprobe-y := modprobe.o | ||
| 26 | shared/modprobe-y := modprobe.o | ||
| 27 | +static/wc-y := wc.o | ||
| 28 | +shared/wc-y := wc.o | ||
| 29 | |||
| 30 | # Additionally linked targets | ||
| 31 | always := static/reboot static/poweroff shared/reboot shared/poweroff | ||
| 32 | diff --git a/usr/utils/wc.c b/usr/utils/wc.c | ||
| 33 | new file mode 100644 | ||
| 34 | index 0000000..f5059fc | ||
| 35 | --- /dev/null | ||
| 36 | +++ b/usr/utils/wc.c | ||
| 37 | @@ -0,0 +1,208 @@ | ||
| 38 | +/* vi: set sw=4 ts=4: */ | ||
| 39 | +/* | ||
| 40 | + * wc implementation for busybox | ||
| 41 | + * | ||
| 42 | + * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | ||
| 43 | + * | ||
| 44 | + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 45 | + */ | ||
| 46 | + | ||
| 47 | +/* BB_AUDIT SUSv3 _NOT_ compliant -- option -m is not currently supported. */ | ||
| 48 | +/* http://www.opengroup.org/onlinepubs/007904975/utilities/wc.html */ | ||
| 49 | + | ||
| 50 | +/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
| 51 | + * | ||
| 52 | + * Rewritten to fix a number of problems and do some size optimizations. | ||
| 53 | + * Problems in the previous busybox implementation (besides bloat) included: | ||
| 54 | + * 1) broken 'wc -c' optimization (read note below) | ||
| 55 | + * 2) broken handling of '-' args | ||
| 56 | + * 3) no checking of ferror on EOF returns | ||
| 57 | + * 4) isprint() wasn't considered when word counting. | ||
| 58 | + * | ||
| 59 | + * TODO: | ||
| 60 | + * | ||
| 61 | + * When locale support is enabled, count multibyte chars in the '-m' case. | ||
| 62 | + * | ||
| 63 | + * NOTES: | ||
| 64 | + * | ||
| 65 | + * The previous busybox wc attempted an optimization using stat for the | ||
| 66 | + * case of counting chars only. I omitted that because it was broken. | ||
| 67 | + * It didn't take into account the possibility of input coming from a | ||
| 68 | + * pipe, or input from a file with file pointer not at the beginning. | ||
| 69 | + * | ||
| 70 | + * To implement such a speed optimization correctly, not only do you | ||
| 71 | + * need the size, but also the file position. Note also that the | ||
| 72 | + * file position may be past the end of file. Consider the example | ||
| 73 | + * (adapted from example in gnu wc.c) | ||
| 74 | + * | ||
| 75 | + * echo hello > /tmp/testfile && | ||
| 76 | + * (dd ibs=1k skip=1 count=0 &> /dev/null; wc -c) < /tmp/testfile | ||
| 77 | + * | ||
| 78 | + * for which 'wc -c' should output '0'. | ||
| 79 | + */ | ||
| 80 | +#include <stdio.h> | ||
| 81 | +#include <stdlib.h> | ||
| 82 | +#include <string.h> | ||
| 83 | +#include <unistd.h> | ||
| 84 | +#undef isspace | ||
| 85 | +#undef isprint | ||
| 86 | +#define isspace(c) ((((c) == ' ') || (((unsigned int)((c) - 9)) <= (13 - 9)))) | ||
| 87 | +#define isprint(c) (((unsigned int)((c) - 0x20)) <= (0x7e - 0x20)) | ||
| 88 | +#define isspace_given_isprint(c) ((c) == ' ') | ||
| 89 | + | ||
| 90 | +#define COUNT_T unsigned long | ||
| 91 | +#define COUNT_FMT "u" | ||
| 92 | +#define optind 1 | ||
| 93 | +FILE *fopen_or_warn_stdin(const char *filename) | ||
| 94 | +{ | ||
| 95 | + FILE *fp = stdin; | ||
| 96 | + | ||
| 97 | + if (filename[0]) { | ||
| 98 | + fp = fopen(filename, "r"); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + return fp; | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +enum { | ||
| 105 | + WC_LINES = 0, | ||
| 106 | + WC_WORDS = 1, | ||
| 107 | + WC_CHARS = 2, | ||
| 108 | + WC_LENGTH = 3 | ||
| 109 | +}; | ||
| 110 | + | ||
| 111 | +int main(int argc, char **argv) | ||
| 112 | +{ | ||
| 113 | + FILE *fp; | ||
| 114 | + const char *s, *arg; | ||
| 115 | + const char *start_fmt = "%9"COUNT_FMT; | ||
| 116 | + const char *fname_fmt = " %s\n"; | ||
| 117 | + COUNT_T *pcounts; | ||
| 118 | + COUNT_T counts[4]; | ||
| 119 | + COUNT_T totals[4]; | ||
| 120 | + unsigned linepos; | ||
| 121 | + unsigned u; | ||
| 122 | + int num_files = 0; | ||
| 123 | + int c; | ||
| 124 | + signed char status = EXIT_SUCCESS; | ||
| 125 | + signed char in_word; | ||
| 126 | + unsigned print_type; | ||
| 127 | + | ||
| 128 | + print_type = getopt(argc, argv, "lwcL"); | ||
| 129 | + | ||
| 130 | + if (print_type == 0) { | ||
| 131 | + print_type = (1 << WC_LINES) | (1 << WC_WORDS) | (1 << WC_CHARS); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + argv += optind; | ||
| 135 | + if (!argv[0]) { | ||
| 136 | + *--argv = (char *) "wc"; | ||
| 137 | + fname_fmt = "\n"; | ||
| 138 | + if (!((print_type-1) & print_type)) /* exactly one option? */ | ||
| 139 | + start_fmt = "%"COUNT_FMT; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + memset(totals, 0, sizeof(totals)); | ||
| 143 | + | ||
| 144 | + pcounts = counts; | ||
| 145 | + | ||
| 146 | + while ((arg = *argv++) != 0) { | ||
| 147 | + ++num_files; | ||
| 148 | + fp = fopen_or_warn_stdin(arg); | ||
| 149 | + if (!fp) { | ||
| 150 | + status = EXIT_FAILURE; | ||
| 151 | + continue; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + memset(counts, 0, sizeof(counts)); | ||
| 155 | + linepos = 0; | ||
| 156 | + in_word = 0; | ||
| 157 | + | ||
| 158 | + do { | ||
| 159 | + /* Our -w doesn't match GNU wc exactly... oh well */ | ||
| 160 | + | ||
| 161 | + ++counts[WC_CHARS]; | ||
| 162 | + c = getc(fp); | ||
| 163 | + if (isprint(c)) { | ||
| 164 | + ++linepos; | ||
| 165 | + if (!isspace_given_isprint(c)) { | ||
| 166 | + in_word = 1; | ||
| 167 | + continue; | ||
| 168 | + } | ||
| 169 | + } else if (((unsigned int)(c - 9)) <= 4) { | ||
| 170 | + /* \t 9 | ||
| 171 | + * \n 10 | ||
| 172 | + * \v 11 | ||
| 173 | + * \f 12 | ||
| 174 | + * \r 13 | ||
| 175 | + */ | ||
| 176 | + if (c == '\t') { | ||
| 177 | + linepos = (linepos | 7) + 1; | ||
| 178 | + } else { /* '\n', '\r', '\f', or '\v' */ | ||
| 179 | + DO_EOF: | ||
| 180 | + if (linepos > counts[WC_LENGTH]) { | ||
| 181 | + counts[WC_LENGTH] = linepos; | ||
| 182 | + } | ||
| 183 | + if (c == '\n') { | ||
| 184 | + ++counts[WC_LINES]; | ||
| 185 | + } | ||
| 186 | + if (c != '\v') { | ||
| 187 | + linepos = 0; | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + } else if (c == EOF) { | ||
| 191 | +/* if (ferror(fp)) { | ||
| 192 | + status = EXIT_FAILURE; | ||
| 193 | + } | ||
| 194 | +*/ --counts[WC_CHARS]; | ||
| 195 | + goto DO_EOF; /* Treat an EOF as '\r'. */ | ||
| 196 | + } else { | ||
| 197 | + continue; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + counts[WC_WORDS] += in_word; | ||
| 201 | + in_word = 0; | ||
| 202 | + if (c == EOF) { | ||
| 203 | + break; | ||
| 204 | + } | ||
| 205 | + } while (1); | ||
| 206 | + | ||
| 207 | + if (totals[WC_LENGTH] < counts[WC_LENGTH]) { | ||
| 208 | + totals[WC_LENGTH] = counts[WC_LENGTH]; | ||
| 209 | + } | ||
| 210 | + totals[WC_LENGTH] -= counts[WC_LENGTH]; | ||
| 211 | + | ||
| 212 | + if(fp != stdin) | ||
| 213 | + fclose(fp); | ||
| 214 | + | ||
| 215 | + OUTPUT: | ||
| 216 | + /* coreutils wc tries hard to print pretty columns | ||
| 217 | + * (saves results for all files, find max col len etc...) | ||
| 218 | + * we won't try that hard, it will bloat us too much */ | ||
| 219 | + s = start_fmt; | ||
| 220 | + u = 0; | ||
| 221 | + do { | ||
| 222 | + if (print_type & (1 << u)) { | ||
| 223 | + printf(s, pcounts[u]); | ||
| 224 | + s = " %9"COUNT_FMT; /* Ok... restore the leading space. */ | ||
| 225 | + } | ||
| 226 | + totals[u] += pcounts[u]; | ||
| 227 | + } while (++u < 4); | ||
| 228 | + printf(fname_fmt, arg); | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + /* If more than one file was processed, we want the totals. To save some | ||
| 232 | + * space, we set the pcounts ptr to the totals array. This has the side | ||
| 233 | + * effect of trashing the totals array after outputting it, but that's | ||
| 234 | + * irrelavent since we no longer need it. */ | ||
| 235 | + if (num_files > 1) { | ||
| 236 | + num_files = 0; /* Make sure we don't get here again. */ | ||
| 237 | + arg = "total"; | ||
| 238 | + pcounts = totals; | ||
| 239 | + --argv; | ||
| 240 | + goto OUTPUT; | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + fflush(stdout); | ||
| 244 | + exit(status); | ||
| 245 | +} | ||
