"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Support code for the hexdump and od applets, |
| 4 | * based on code from util-linux v 2.11l |
| 5 | * |
| 6 | * Copyright (c) 1989 |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 7 | * The Regents of the University of California. All rights reserved. |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 8 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 10 | * |
| 11 | * Original copyright notice is retained at the end of this file. |
| 12 | */ |
| 13 | |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 14 | #include "libbb.h" |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 15 | #include "dump.h" |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 16 | |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 17 | static const char index_str[] ALIGN1 = ".#-+ 0123456789"; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 18 | |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 19 | static const char size_conv_str[] ALIGN1 = |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 20 | "\x1\x4\x4\x4\x4\x4\x4\x8\x8\x8\x8\010cdiouxXeEfgG"; |
| 21 | |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 22 | static const char lcc[] ALIGN1 = "diouxX"; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 23 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 24 | |
| 25 | typedef struct priv_dumper_t { |
| 26 | dumper_t pub; |
| 27 | |
| 28 | char **argv; |
| 29 | FU *endfu; |
| 30 | off_t savaddress; /* saved address/offset in stream */ |
| 31 | off_t eaddress; /* end address */ |
| 32 | off_t address; /* address/offset in stream */ |
| 33 | int blocksize; |
| 34 | smallint exitval; /* final exit value */ |
| 35 | |
| 36 | /* former statics */ |
| 37 | smallint next__done; |
| 38 | smallint get__ateof; // = 1; |
| 39 | unsigned char *get__curp; |
| 40 | unsigned char *get__savp; |
| 41 | } priv_dumper_t; |
| 42 | |
| 43 | dumper_t* FAST_FUNC alloc_dumper(void) |
| 44 | { |
| 45 | priv_dumper_t *dumper = xzalloc(sizeof(*dumper)); |
| 46 | dumper->pub.dump_length = -1; |
| 47 | dumper->pub.dump_vflag = FIRST; |
| 48 | dumper->get__ateof = 1; |
| 49 | return &dumper->pub; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | static NOINLINE int bb_dump_size(FS *fs) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 54 | { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 55 | FU *fu; |
| 56 | int bcnt, cur_size; |
| 57 | char *fmt; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 58 | const char *p; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 59 | int prec; |
| 60 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 61 | /* figure out the data block bb_dump_size needed for each format unit */ |
| 62 | for (cur_size = 0, fu = fs->nextfu; fu; fu = fu->nextfu) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 63 | if (fu->bcnt) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 64 | cur_size += fu->bcnt * fu->reps; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 65 | continue; |
| 66 | } |
| 67 | for (bcnt = prec = 0, fmt = fu->fmt; *fmt; ++fmt) { |
| 68 | if (*fmt != '%') |
| 69 | continue; |
| 70 | /* |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 71 | * skip any special chars -- save precision in |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 72 | * case it's a %s format. |
| 73 | */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 74 | while (strchr(index_str + 1, *++fmt)); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 75 | if (*fmt == '.' && isdigit(*++fmt)) { |
| 76 | prec = atoi(fmt); |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 77 | while (isdigit(*++fmt)) |
| 78 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 79 | } |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 80 | p = strchr(size_conv_str + 12, *fmt); |
| 81 | if (!p) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 82 | if (*fmt == 's') { |
| 83 | bcnt += prec; |
| 84 | } else if (*fmt == '_') { |
| 85 | ++fmt; |
| 86 | if ((*fmt == 'c') || (*fmt == 'p') || (*fmt == 'u')) { |
| 87 | bcnt += 1; |
| 88 | } |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 89 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 90 | } else { |
| 91 | bcnt += size_conv_str[p - (size_conv_str + 12)]; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 94 | cur_size += bcnt * fu->reps; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 95 | } |
Denis Vlasenko | d9e15f2 | 2006-11-27 16:49:55 +0000 | [diff] [blame] | 96 | return cur_size; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Denys Vlasenko | a7bb3c1 | 2009-10-08 12:28:08 +0200 | [diff] [blame] | 99 | static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 100 | { |
| 101 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 102 | PR *pr, **nextpr = NULL; |
| 103 | FU *fu; |
| 104 | char *p1, *p2, *p3; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 105 | char savech, *fmtp; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 106 | const char *byte_count_str; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 107 | int nconv, prec = 0; |
| 108 | |
| 109 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { |
| 110 | /* |
| 111 | * break each format unit into print units; each |
| 112 | * conversion character gets its own. |
| 113 | */ |
| 114 | for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { |
| 115 | /* NOSTRICT */ |
Denis Vlasenko | d02db89 | 2008-03-17 09:05:21 +0000 | [diff] [blame] | 116 | /* DBU:[dvae@cray.com] zalloc so that forward ptrs start out NULL*/ |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 117 | pr = xzalloc(sizeof(PR)); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 118 | if (!fu->nextpr) |
| 119 | fu->nextpr = pr; |
Eric Andersen | 4a11e0f | 2003-04-19 23:18:35 +0000 | [diff] [blame] | 120 | /* ignore nextpr -- its unused inside the loop and is |
Bernhard Reutner-Fischer | a985d30 | 2008-02-11 11:44:38 +0000 | [diff] [blame] | 121 | * uninitialized 1st time through. |
Eric Andersen | 4a11e0f | 2003-04-19 23:18:35 +0000 | [diff] [blame] | 122 | */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 123 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 124 | /* skip preceding text and up to the next % sign */ |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 125 | for (p1 = fmtp; *p1 && *p1 != '%'; ++p1) |
| 126 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 127 | |
| 128 | /* only text in the string */ |
| 129 | if (!*p1) { |
| 130 | pr->fmt = fmtp; |
| 131 | pr->flags = F_TEXT; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * get precision for %s -- if have a byte count, don't |
| 137 | * need it. |
| 138 | */ |
| 139 | if (fu->bcnt) { |
| 140 | sokay = USEBCNT; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 141 | /* skip to conversion character */ |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 142 | for (++p1; strchr(index_str, *p1); ++p1) |
| 143 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 144 | } else { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 145 | /* skip any special chars, field width */ |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 146 | while (strchr(index_str + 1, *++p1)) |
| 147 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 148 | if (*p1 == '.' && isdigit(*++p1)) { |
| 149 | sokay = USEPREC; |
| 150 | prec = atoi(p1); |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 151 | while (isdigit(*++p1)) |
| 152 | continue; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 153 | } else |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 154 | sokay = NOTOKAY; |
| 155 | } |
| 156 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 157 | p2 = p1 + 1; /* set end pointer */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * figure out the byte count for each conversion; |
| 161 | * rewrite the format as necessary, set up blank- |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 162 | * pbb_dump_adding for end of data. |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 163 | */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 164 | if (*p1 == 'c') { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 165 | pr->flags = F_CHAR; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 166 | DO_BYTE_COUNT_1: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 167 | byte_count_str = "\001"; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 168 | DO_BYTE_COUNT: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 169 | if (fu->bcnt) { |
| 170 | do { |
| 171 | if (fu->bcnt == *byte_count_str) { |
| 172 | break; |
| 173 | } |
| 174 | } while (*++byte_count_str); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 175 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 176 | /* Unlike the original, output the remainder of the format string. */ |
| 177 | if (!*byte_count_str) { |
Denis Vlasenko | d3d004d | 2006-10-27 09:02:31 +0000 | [diff] [blame] | 178 | bb_error_msg_and_die("bad byte count for conversion character %s", p1); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 179 | } |
| 180 | pr->bcnt = *byte_count_str; |
| 181 | } else if (*p1 == 'l') { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 182 | ++p2; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 183 | ++p1; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 184 | DO_INT_CONV: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 185 | { |
| 186 | const char *e; |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 187 | e = strchr(lcc, *p1); |
| 188 | if (!e) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 189 | goto DO_BAD_CONV_CHAR; |
| 190 | } |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 191 | pr->flags = F_INT; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 192 | if (e > lcc + 1) { |
| 193 | pr->flags = F_UINT; |
| 194 | } |
| 195 | byte_count_str = "\004\002\001"; |
| 196 | goto DO_BYTE_COUNT; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 197 | } |
| 198 | /* NOTREACHED */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 199 | } else if (strchr(lcc, *p1)) { |
| 200 | goto DO_INT_CONV; |
| 201 | } else if (strchr("eEfgG", *p1)) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 202 | pr->flags = F_DBL; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 203 | byte_count_str = "\010\004"; |
| 204 | goto DO_BYTE_COUNT; |
| 205 | } else if (*p1 == 's') { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 206 | pr->flags = F_STR; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 207 | if (sokay == USEBCNT) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 208 | pr->bcnt = fu->bcnt; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 209 | } else if (sokay == USEPREC) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 210 | pr->bcnt = prec; |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 211 | } else { /* NOTOKAY */ |
Denis Vlasenko | d3d004d | 2006-10-27 09:02:31 +0000 | [diff] [blame] | 212 | bb_error_msg_and_die("%%s requires a precision or a byte count"); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 213 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 214 | } else if (*p1 == '_') { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 215 | ++p2; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 216 | switch (p1[1]) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 217 | case 'A': |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 218 | dumper->endfu = fu; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 219 | fu->flags |= F_IGNORE; |
| 220 | /* FALLTHROUGH */ |
| 221 | case 'a': |
| 222 | pr->flags = F_ADDRESS; |
| 223 | ++p2; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 224 | if ((p1[2] != 'd') && (p1[2] != 'o') && (p1[2] != 'x')) { |
| 225 | goto DO_BAD_CONV_CHAR; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 226 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 227 | *p1 = p1[2]; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 228 | break; |
| 229 | case 'c': |
| 230 | pr->flags = F_C; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 231 | /* *p1 = 'c'; set in conv_c */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 232 | goto DO_BYTE_COUNT_1; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 233 | case 'p': |
| 234 | pr->flags = F_P; |
| 235 | *p1 = 'c'; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 236 | goto DO_BYTE_COUNT_1; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 237 | case 'u': |
| 238 | pr->flags = F_U; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 239 | /* *p1 = 'c'; set in conv_u */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 240 | goto DO_BYTE_COUNT_1; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 241 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 242 | goto DO_BAD_CONV_CHAR; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 243 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 244 | } else { |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 245 | DO_BAD_CONV_CHAR: |
Denis Vlasenko | d3d004d | 2006-10-27 09:02:31 +0000 | [diff] [blame] | 246 | bb_error_msg_and_die("bad conversion character %%%s", p1); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* |
| 250 | * copy to PR format string, set conversion character |
| 251 | * pointer, update original. |
| 252 | */ |
| 253 | savech = *p2; |
| 254 | p1[1] = '\0'; |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 255 | pr->fmt = xstrdup(fmtp); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 256 | *p2 = savech; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 257 | //Too early! xrealloc can move pr->fmt! |
| 258 | //pr->cchar = pr->fmt + (p1 - fmtp); |
Eric Andersen | 4a11e0f | 2003-04-19 23:18:35 +0000 | [diff] [blame] | 259 | |
| 260 | /* DBU:[dave@cray.com] w/o this, trailing fmt text, space is lost. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 261 | * Skip subsequent text and up to the next % sign and tack the |
| 262 | * additional text onto fmt: eg. if fmt is "%x is a HEX number", |
Eric Andersen | 4a11e0f | 2003-04-19 23:18:35 +0000 | [diff] [blame] | 263 | * we lose the " is a HEX number" part of fmt. |
| 264 | */ |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 265 | for (p3 = p2; *p3 && *p3 != '%'; p3++) |
| 266 | continue; |
| 267 | if (p3 > p2) { |
Eric Andersen | 4a11e0f | 2003-04-19 23:18:35 +0000 | [diff] [blame] | 268 | savech = *p3; |
| 269 | *p3 = '\0'; |
Denis Vlasenko | deeed59 | 2008-07-08 05:14:36 +0000 | [diff] [blame] | 270 | pr->fmt = xrealloc(pr->fmt, strlen(pr->fmt) + (p3-p2) + 1); |
Eric Andersen | 4a11e0f | 2003-04-19 23:18:35 +0000 | [diff] [blame] | 271 | strcat(pr->fmt, p2); |
| 272 | *p3 = savech; |
| 273 | p2 = p3; |
| 274 | } |
| 275 | |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 276 | pr->cchar = pr->fmt + (p1 - fmtp); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 277 | fmtp = p2; |
| 278 | |
| 279 | /* only one conversion character if byte count */ |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 280 | if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) { |
Denis Vlasenko | d3d004d | 2006-10-27 09:02:31 +0000 | [diff] [blame] | 281 | bb_error_msg_and_die("byte count with multiple conversion characters"); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | /* |
| 285 | * if format unit byte count not specified, figure it out |
| 286 | * so can adjust rep count later. |
| 287 | */ |
| 288 | if (!fu->bcnt) |
| 289 | for (pr = fu->nextpr; pr; pr = pr->nextpr) |
| 290 | fu->bcnt += pr->bcnt; |
| 291 | } |
| 292 | /* |
| 293 | * if the format string interprets any data at all, and it's |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 294 | * not the same as the blocksize, and its last format unit |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 295 | * interprets any data at all, and has no iteration count, |
| 296 | * repeat it as necessary. |
| 297 | * |
| 298 | * if, rep count is greater than 1, no trailing whitespace |
| 299 | * gets output from the last iteration of the format unit. |
| 300 | */ |
Denis Vlasenko | 15f2fdb | 2008-08-23 23:15:48 +0000 | [diff] [blame] | 301 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 302 | if (!fu->nextfu && fs->bcnt < dumper->blocksize |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 303 | && !(fu->flags & F_SETREP) && fu->bcnt |
| 304 | ) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 305 | fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 306 | } |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 307 | if (fu->reps > 1) { |
| 308 | for (pr = fu->nextpr;; pr = pr->nextpr) |
| 309 | if (!pr->nextpr) |
| 310 | break; |
| 311 | for (p1 = pr->fmt, p2 = NULL; *p1; ++p1) |
| 312 | p2 = isspace(*p1) ? p1 : NULL; |
| 313 | if (p2) |
| 314 | pr->nospace = p2; |
| 315 | } |
| 316 | if (!fu->nextfu) |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 321 | static void do_skip(priv_dumper_t *dumper, const char *fname, int statok) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 322 | { |
| 323 | struct stat sbuf; |
| 324 | |
| 325 | if (statok) { |
Denys Vlasenko | 8d3e225 | 2010-08-31 12:42:06 +0200 | [diff] [blame] | 326 | xfstat(STDIN_FILENO, &sbuf, fname); |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 327 | if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode)) |
| 328 | && dumper->pub.dump_skip >= sbuf.st_size |
| 329 | ) { |
| 330 | /* If bb_dump_size valid and pub.dump_skip >= size */ |
| 331 | dumper->pub.dump_skip -= sbuf.st_size; |
| 332 | dumper->address += sbuf.st_size; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 333 | return; |
| 334 | } |
| 335 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 336 | if (fseek(stdin, dumper->pub.dump_skip, SEEK_SET)) { |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 337 | bb_simple_perror_msg_and_die(fname); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 338 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 339 | dumper->address += dumper->pub.dump_skip; |
| 340 | dumper->savaddress = dumper->address; |
| 341 | dumper->pub.dump_skip = 0; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 344 | static NOINLINE int next(priv_dumper_t *dumper) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 345 | { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 346 | int statok; |
| 347 | |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 348 | for (;;) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 349 | if (*dumper->argv) { |
Denys Vlasenko | 6aca76d | 2010-02-06 13:53:21 +0100 | [diff] [blame] | 350 | dumper->next__done = statok = 1; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 351 | if (!(freopen(*dumper->argv, "r", stdin))) { |
| 352 | bb_simple_perror_msg(*dumper->argv); |
| 353 | dumper->exitval = 1; |
| 354 | ++dumper->argv; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 355 | continue; |
| 356 | } |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 357 | } else { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 358 | if (dumper->next__done) |
Denys Vlasenko | 6aca76d | 2010-02-06 13:53:21 +0100 | [diff] [blame] | 359 | return 0; /* no next file */ |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 360 | dumper->next__done = 1; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 361 | statok = 0; |
| 362 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 363 | if (dumper->pub.dump_skip) |
| 364 | do_skip(dumper, statok ? *dumper->argv : "stdin", statok); |
| 365 | if (*dumper->argv) |
| 366 | ++dumper->argv; |
| 367 | if (!dumper->pub.dump_skip) |
Denis Vlasenko | 079f8af | 2006-11-27 16:49:31 +0000 | [diff] [blame] | 368 | return 1; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 369 | } |
| 370 | /* NOTREACHED */ |
| 371 | } |
| 372 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 373 | static unsigned char *get(priv_dumper_t *dumper) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 374 | { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 375 | int n; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 376 | int need, nread; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 377 | int blocksize = dumper->blocksize; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 378 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 379 | if (!dumper->get__curp) { |
| 380 | dumper->address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/ |
| 381 | dumper->get__curp = xmalloc(blocksize); |
Denis Vlasenko | 2f86d13 | 2008-07-29 00:00:14 +0000 | [diff] [blame] | 382 | dumper->get__savp = xzalloc(blocksize); /* need to be initialized */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 383 | } else { |
Denis Vlasenko | 2f86d13 | 2008-07-29 00:00:14 +0000 | [diff] [blame] | 384 | unsigned char *tmp = dumper->get__curp; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 385 | dumper->get__curp = dumper->get__savp; |
Denis Vlasenko | 2f86d13 | 2008-07-29 00:00:14 +0000 | [diff] [blame] | 386 | dumper->get__savp = tmp; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 387 | dumper->savaddress += blocksize; |
| 388 | dumper->address = dumper->savaddress; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 389 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 390 | need = blocksize; |
| 391 | nread = 0; |
| 392 | while (1) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 393 | /* |
| 394 | * if read the right number of bytes, or at EOF for one file, |
| 395 | * and no other files are available, zero-pad the rest of the |
| 396 | * block and set the end flag. |
| 397 | */ |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 398 | if (!dumper->pub.dump_length || (dumper->get__ateof && !next(dumper))) { |
| 399 | if (need == blocksize) { |
Denis Vlasenko | d9e15f2 | 2006-11-27 16:49:55 +0000 | [diff] [blame] | 400 | return NULL; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 401 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 402 | if (dumper->pub.dump_vflag != ALL && !memcmp(dumper->get__curp, dumper->get__savp, nread)) { |
| 403 | if (dumper->pub.dump_vflag != DUP) { |
Denis Vlasenko | d9e15f2 | 2006-11-27 16:49:55 +0000 | [diff] [blame] | 404 | puts("*"); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 405 | } |
Denis Vlasenko | d9e15f2 | 2006-11-27 16:49:55 +0000 | [diff] [blame] | 406 | return NULL; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 407 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 408 | memset(dumper->get__curp + nread, 0, need); |
| 409 | dumper->eaddress = dumper->address + nread; |
| 410 | return dumper->get__curp; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 411 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 412 | n = fread(dumper->get__curp + nread, sizeof(unsigned char), |
| 413 | dumper->pub.dump_length == -1 ? need : MIN(dumper->pub.dump_length, need), stdin); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 414 | if (!n) { |
| 415 | if (ferror(stdin)) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 416 | bb_simple_perror_msg(dumper->argv[-1]); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 417 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 418 | dumper->get__ateof = 1; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 419 | continue; |
| 420 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 421 | dumper->get__ateof = 0; |
| 422 | if (dumper->pub.dump_length != -1) { |
| 423 | dumper->pub.dump_length -= n; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 424 | } |
Denis Vlasenko | 931de89 | 2007-06-21 12:43:45 +0000 | [diff] [blame] | 425 | need -= n; |
| 426 | if (!need) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 427 | if (dumper->pub.dump_vflag == ALL || dumper->pub.dump_vflag == FIRST |
| 428 | || memcmp(dumper->get__curp, dumper->get__savp, blocksize) |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 429 | ) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 430 | if (dumper->pub.dump_vflag == DUP || dumper->pub.dump_vflag == FIRST) { |
| 431 | dumper->pub.dump_vflag = WAIT; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 432 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 433 | return dumper->get__curp; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 434 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 435 | if (dumper->pub.dump_vflag == WAIT) { |
Denis Vlasenko | d9e15f2 | 2006-11-27 16:49:55 +0000 | [diff] [blame] | 436 | puts("*"); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 437 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 438 | dumper->pub.dump_vflag = DUP; |
| 439 | dumper->savaddress += blocksize; |
| 440 | dumper->address = dumper->savaddress; |
| 441 | need = blocksize; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 442 | nread = 0; |
| 443 | } else { |
| 444 | nread += n; |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 449 | static void bpad(PR *pr) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 450 | { |
Rob Landley | a6e6037 | 2006-06-28 14:36:50 +0000 | [diff] [blame] | 451 | char *p1, *p2; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * remove all conversion flags; '-' is the only one valid |
| 455 | * with %s, and it's not useful here. |
| 456 | */ |
| 457 | pr->flags = F_BPAD; |
| 458 | *pr->cchar = 's'; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 459 | for (p1 = pr->fmt; *p1 != '%'; ++p1) |
| 460 | continue; |
Rob Landley | a6e6037 | 2006-06-28 14:36:50 +0000 | [diff] [blame] | 461 | for (p2 = ++p1; *p1 && strchr(" -0+#", *p1); ++p1) |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 462 | if (pr->nospace) |
| 463 | pr->nospace--; |
| 464 | while ((*p2++ = *p1++) != 0) |
| 465 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 468 | static const char conv_str[] ALIGN1 = |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 469 | "\0\\0\0" |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 470 | "\007\\a\0" /* \a */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 471 | "\b\\b\0" |
| 472 | "\f\\b\0" |
| 473 | "\n\\n\0" |
| 474 | "\r\\r\0" |
| 475 | "\t\\t\0" |
| 476 | "\v\\v\0" |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 477 | ; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 478 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 479 | |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 480 | static void conv_c(PR *pr, unsigned char *p) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 481 | { |
| 482 | const char *str = conv_str; |
| 483 | char buf[10]; |
| 484 | |
| 485 | do { |
| 486 | if (*p == *str) { |
| 487 | ++str; |
| 488 | goto strpr; |
| 489 | } |
| 490 | str += 4; |
| 491 | } while (*str); |
| 492 | |
Denys Vlasenko | 8684cbb | 2009-11-18 11:34:43 +0100 | [diff] [blame] | 493 | if (isprint_asciionly(*p)) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 494 | *pr->cchar = 'c'; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 495 | printf(pr->fmt, *p); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 496 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 497 | sprintf(buf, "%03o", (int) *p); |
| 498 | str = buf; |
Denys Vlasenko | 8684cbb | 2009-11-18 11:34:43 +0100 | [diff] [blame] | 499 | strpr: |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 500 | *pr->cchar = 's'; |
| 501 | printf(pr->fmt, str); |
| 502 | } |
| 503 | } |
| 504 | |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 505 | static void conv_u(PR *pr, unsigned char *p) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 506 | { |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 507 | static const char list[] ALIGN1 = |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 508 | "nul\0soh\0stx\0etx\0eot\0enq\0ack\0bel\0" |
| 509 | "bs\0_ht\0_lf\0_vt\0_ff\0_cr\0_so\0_si\0_" |
| 510 | "dle\0dcl\0dc2\0dc3\0dc4\0nak\0syn\0etb\0" |
| 511 | "can\0em\0_sub\0esc\0fs\0_gs\0_rs\0_us"; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 512 | |
| 513 | /* od used nl, not lf */ |
| 514 | if (*p <= 0x1f) { |
| 515 | *pr->cchar = 's'; |
Glenn L McGrath | eeb06bf | 2004-07-23 01:35:41 +0000 | [diff] [blame] | 516 | printf(pr->fmt, list + (4 * (int)*p)); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 517 | } else if (*p == 0x7f) { |
| 518 | *pr->cchar = 's'; |
| 519 | printf(pr->fmt, "del"); |
Denys Vlasenko | 8684cbb | 2009-11-18 11:34:43 +0100 | [diff] [blame] | 520 | } else if (*p < 0x7f) { /* isprint() */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 521 | *pr->cchar = 'c'; |
| 522 | printf(pr->fmt, *p); |
| 523 | } else { |
| 524 | *pr->cchar = 'x'; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 525 | printf(pr->fmt, (int) *p); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 529 | static void display(priv_dumper_t* dumper) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 530 | { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 531 | FS *fs; |
| 532 | FU *fu; |
| 533 | PR *pr; |
| 534 | int cnt; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 535 | unsigned char *bp, *savebp; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 536 | off_t saveaddress; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 537 | unsigned char savech = '\0'; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 538 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 539 | while ((bp = get(dumper)) != NULL) { |
| 540 | fs = dumper->pub.fshead; |
| 541 | savebp = bp; |
| 542 | saveaddress = dumper->address; |
| 543 | for (; fs; fs = fs->nextfs, bp = savebp, dumper->address = saveaddress) { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 544 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 545 | if (fu->flags & F_IGNORE) { |
| 546 | break; |
| 547 | } |
| 548 | for (cnt = fu->reps; cnt; --cnt) { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 549 | for (pr = fu->nextpr; pr; dumper->address += pr->bcnt, |
| 550 | bp += pr->bcnt, pr = pr->nextpr) { |
| 551 | if (dumper->eaddress && dumper->address >= dumper->eaddress |
| 552 | && !(pr->flags & (F_TEXT | F_BPAD)) |
| 553 | ) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 554 | bpad(pr); |
| 555 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 556 | if (cnt == 1 && pr->nospace) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 557 | savech = *pr->nospace; |
| 558 | *pr->nospace = '\0'; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 559 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 560 | /* PRINT; */ |
| 561 | switch (pr->flags) { |
| 562 | case F_ADDRESS: |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 563 | printf(pr->fmt, (unsigned) dumper->address); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 564 | break; |
| 565 | case F_BPAD: |
| 566 | printf(pr->fmt, ""); |
| 567 | break; |
| 568 | case F_C: |
| 569 | conv_c(pr, bp); |
| 570 | break; |
| 571 | case F_CHAR: |
| 572 | printf(pr->fmt, *bp); |
| 573 | break; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 574 | case F_DBL: { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 575 | double dval; |
| 576 | float fval; |
| 577 | |
| 578 | switch (pr->bcnt) { |
| 579 | case 4: |
Denis Vlasenko | 3eb4466 | 2008-11-16 22:21:23 +0000 | [diff] [blame] | 580 | memcpy(&fval, bp, sizeof(fval)); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 581 | printf(pr->fmt, fval); |
| 582 | break; |
| 583 | case 8: |
Denis Vlasenko | 3eb4466 | 2008-11-16 22:21:23 +0000 | [diff] [blame] | 584 | memcpy(&dval, bp, sizeof(dval)); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 585 | printf(pr->fmt, dval); |
| 586 | break; |
| 587 | } |
| 588 | break; |
| 589 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 590 | case F_INT: { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 591 | int ival; |
| 592 | short sval; |
| 593 | |
| 594 | switch (pr->bcnt) { |
| 595 | case 1: |
| 596 | printf(pr->fmt, (int) *bp); |
| 597 | break; |
| 598 | case 2: |
Denis Vlasenko | 3eb4466 | 2008-11-16 22:21:23 +0000 | [diff] [blame] | 599 | memcpy(&sval, bp, sizeof(sval)); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 600 | printf(pr->fmt, (int) sval); |
| 601 | break; |
| 602 | case 4: |
Denis Vlasenko | 3eb4466 | 2008-11-16 22:21:23 +0000 | [diff] [blame] | 603 | memcpy(&ival, bp, sizeof(ival)); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 604 | printf(pr->fmt, ival); |
| 605 | break; |
| 606 | } |
| 607 | break; |
| 608 | } |
| 609 | case F_P: |
Denys Vlasenko | 8684cbb | 2009-11-18 11:34:43 +0100 | [diff] [blame] | 610 | printf(pr->fmt, isprint_asciionly(*bp) ? *bp : '.'); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 611 | break; |
| 612 | case F_STR: |
| 613 | printf(pr->fmt, (char *) bp); |
| 614 | break; |
| 615 | case F_TEXT: |
| 616 | printf(pr->fmt); |
| 617 | break; |
| 618 | case F_U: |
| 619 | conv_u(pr, bp); |
| 620 | break; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 621 | case F_UINT: { |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 622 | unsigned ival; |
Eric Andersen | 0f56de6 | 2004-01-30 22:52:27 +0000 | [diff] [blame] | 623 | unsigned short sval; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 624 | |
| 625 | switch (pr->bcnt) { |
| 626 | case 1: |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 627 | printf(pr->fmt, (unsigned) *bp); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 628 | break; |
| 629 | case 2: |
Denis Vlasenko | 3eb4466 | 2008-11-16 22:21:23 +0000 | [diff] [blame] | 630 | memcpy(&sval, bp, sizeof(sval)); |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 631 | printf(pr->fmt, (unsigned) sval); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 632 | break; |
| 633 | case 4: |
Denis Vlasenko | 3eb4466 | 2008-11-16 22:21:23 +0000 | [diff] [blame] | 634 | memcpy(&ival, bp, sizeof(ival)); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 635 | printf(pr->fmt, ival); |
| 636 | break; |
| 637 | } |
| 638 | break; |
| 639 | } |
| 640 | } |
| 641 | if (cnt == 1 && pr->nospace) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 642 | *pr->nospace = savech; |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 649 | if (dumper->endfu) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 650 | /* |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 651 | * if eaddress not set, error or file size was multiple |
| 652 | * of blocksize, and no partial block ever found. |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 653 | */ |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 654 | if (!dumper->eaddress) { |
| 655 | if (!dumper->address) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 656 | return; |
| 657 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 658 | dumper->eaddress = dumper->address; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 659 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 660 | for (pr = dumper->endfu->nextpr; pr; pr = pr->nextpr) { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 661 | switch (pr->flags) { |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 662 | case F_ADDRESS: |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 663 | printf(pr->fmt, (unsigned) dumper->eaddress); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 664 | break; |
| 665 | case F_TEXT: |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 666 | printf(pr->fmt); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 667 | break; |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 673 | #define dumper ((priv_dumper_t*)pub_dumper) |
| 674 | int FAST_FUNC bb_dump_dump(dumper_t *pub_dumper, char **argv) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 675 | { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 676 | FS *tfs; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 677 | int blocksize; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 678 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 679 | /* figure out the data block bb_dump_size */ |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 680 | blocksize = 0; |
| 681 | tfs = dumper->pub.fshead; |
| 682 | while (tfs) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 683 | tfs->bcnt = bb_dump_size(tfs); |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 684 | if (blocksize < tfs->bcnt) { |
| 685 | blocksize = tfs->bcnt; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 686 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 687 | tfs = tfs->nextfs; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 688 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 689 | dumper->blocksize = blocksize; |
| 690 | |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 691 | /* rewrite the rules, do syntax checking */ |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 692 | for (tfs = dumper->pub.fshead; tfs; tfs = tfs->nextfs) { |
| 693 | rewrite(dumper, tfs); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 696 | dumper->argv = argv; |
| 697 | display(dumper); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 698 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 699 | return dumper->exitval; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 702 | void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 703 | { |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 704 | const char *p; |
| 705 | char *p1; |
| 706 | char *p2; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 707 | FS *tfs; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 708 | FU *tfu, **nextfupp; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 709 | const char *savep; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 710 | |
| 711 | /* start new linked list of format units */ |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 712 | tfs = xzalloc(sizeof(FS)); /*DBU:[dave@cray.com] start out NULL */ |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 713 | if (!dumper->pub.fshead) { |
| 714 | dumper->pub.fshead = tfs; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 715 | } else { |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 716 | FS *fslast = dumper->pub.fshead; |
| 717 | while (fslast->nextfs) |
| 718 | fslast = fslast->nextfs; |
| 719 | fslast->nextfs = tfs; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 720 | } |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 721 | nextfupp = &tfs->nextfu; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 722 | |
| 723 | /* take the format string and break it up into format units */ |
Denis Vlasenko | 15f2fdb | 2008-08-23 23:15:48 +0000 | [diff] [blame] | 724 | p = fmt; |
| 725 | for (;;) { |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 726 | p = skip_whitespace(p); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 727 | if (!*p) { |
| 728 | break; |
| 729 | } |
| 730 | |
| 731 | /* allocate a new format unit and link it in */ |
| 732 | /* NOSTRICT */ |
Denis Vlasenko | d02db89 | 2008-03-17 09:05:21 +0000 | [diff] [blame] | 733 | /* DBU:[dave@cray.com] zalloc so that forward pointers start out NULL */ |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 734 | tfu = xzalloc(sizeof(FU)); |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 735 | *nextfupp = tfu; |
| 736 | nextfupp = &tfu->nextfu; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 737 | tfu->reps = 1; |
| 738 | |
| 739 | /* if leading digit, repetition count */ |
| 740 | if (isdigit(*p)) { |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 741 | for (savep = p; isdigit(*p); ++p) |
| 742 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 743 | if (!isspace(*p) && *p != '/') { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 744 | bb_error_msg_and_die("bad format {%s}", fmt); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 745 | } |
| 746 | /* may overwrite either white space or slash */ |
| 747 | tfu->reps = atoi(savep); |
| 748 | tfu->flags = F_SETREP; |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 749 | /* skip trailing white space */ |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 750 | p = skip_whitespace(++p); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 753 | /* skip slash and trailing white space */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 754 | if (*p == '/') { |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 755 | p = skip_whitespace(++p); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /* byte count */ |
| 759 | if (isdigit(*p)) { |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 760 | // TODO: use bb_strtou |
| 761 | savep = p; |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 762 | while (isdigit(*++p)) |
| 763 | continue; |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 764 | if (!isspace(*p)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 765 | bb_error_msg_and_die("bad format {%s}", fmt); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 766 | } |
| 767 | tfu->bcnt = atoi(savep); |
Denis Vlasenko | 55f7912 | 2008-07-16 11:00:16 +0000 | [diff] [blame] | 768 | /* skip trailing white space */ |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 769 | p = skip_whitespace(++p); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* format */ |
| 773 | if (*p != '"') { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 774 | bb_error_msg_and_die("bad format {%s}", fmt); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 775 | } |
| 776 | for (savep = ++p; *p != '"';) { |
| 777 | if (*p++ == 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 778 | bb_error_msg_and_die("bad format {%s}", fmt); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 779 | } |
| 780 | } |
Denis Vlasenko | bd9874d | 2008-07-16 07:22:14 +0000 | [diff] [blame] | 781 | tfu->fmt = xstrndup(savep, p - savep); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 782 | /* escape(tfu->fmt); */ |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 783 | |
| 784 | p1 = tfu->fmt; |
| 785 | |
| 786 | /* alphabetic escape sequences have to be done in place */ |
| 787 | for (p2 = p1;; ++p1, ++p2) { |
| 788 | if (!*p1) { |
| 789 | *p2 = *p1; |
| 790 | break; |
| 791 | } |
| 792 | if (*p1 == '\\') { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 793 | const char *cs = conv_str + 4; |
| 794 | ++p1; |
| 795 | *p2 = *p1; |
| 796 | do { |
| 797 | if (*p1 == cs[2]) { |
| 798 | *p2 = cs[0]; |
| 799 | break; |
| 800 | } |
| 801 | cs += 4; |
| 802 | } while (*cs); |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
| 806 | p++; |
| 807 | } |
| 808 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 809 | |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 810 | /* |
| 811 | * Copyright (c) 1989 The Regents of the University of California. |
| 812 | * All rights reserved. |
| 813 | * |
| 814 | * Redistribution and use in source and binary forms, with or without |
| 815 | * modification, are permitted provided that the following conditions |
| 816 | * are met: |
| 817 | * 1. Redistributions of source code must retain the above copyright |
| 818 | * notice, this list of conditions and the following disclaimer. |
| 819 | * 2. Redistributions in binary form must reproduce the above copyright |
| 820 | * notice, this list of conditions and the following disclaimer in the |
| 821 | * documentation and/or other materials provided with the distribution. |
Aaron Lehmann | 69d4178 | 2002-06-23 22:25:24 +0000 | [diff] [blame] | 822 | * 3. Neither the name of the University nor the names of its contributors |
Glenn L McGrath | 6028111 | 2001-11-02 11:39:46 +0000 | [diff] [blame] | 823 | * may be used to endorse or promote products derived from this software |
| 824 | * without specific prior written permission. |
| 825 | * |
| 826 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 827 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 828 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 829 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 830 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 831 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 832 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 833 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 834 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 835 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 836 | * SUCH DAMAGE. |
| 837 | */ |