Mercurial > hg > toybox
comparison toys/od.c @ 612:1121e0f42132
Some refactoring, shouldn't affect the generated code.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 26 Jun 2012 20:45:14 -0500 |
parents | c9865aadb9fc |
children | 4601e408223b |
comparison
equal
deleted
inserted
replaced
611:c9865aadb9fc | 612:1121e0f42132 |
---|---|
152 if (TT.jump_bytes) { | 152 if (TT.jump_bytes) { |
153 xlseek(fd, TT.jump_bytes, SEEK_SET); | 153 xlseek(fd, TT.jump_bytes, SEEK_SET); |
154 offset = TT.jump_bytes; | 154 offset = TT.jump_bytes; |
155 } | 155 } |
156 | 156 |
157 do { | 157 for (;;) { |
158 int len; | 158 int len; |
159 int max_len = OD_BLOCK_SIZE; | 159 int max_len = OD_BLOCK_SIZE; |
160 if ((toys.optflags & FLAG_N) && | 160 if ((toys.optflags & FLAG_N) && offset + OD_BLOCK_SIZE > TT.max_count) |
161 offset + OD_BLOCK_SIZE > TT.max_count) | |
162 max_len = TT.max_count - offset; | 161 max_len = TT.max_count - offset; |
163 len = xread(fd, block[index], max_len); | 162 len = xread(fd, block[index], max_len); |
164 if (!len) | 163 if (!len) break; |
165 break; | |
166 | 164 |
167 memset(&block[index][len], 0, OD_BLOCK_SIZE - len); | 165 memset(&block[index][len], 0, OD_BLOCK_SIZE - len); |
168 | 166 |
169 if (!(toys.optflags & FLAG_v) && | 167 if (!(toys.optflags & FLAG_v) && offset > 0 && |
170 offset > 0 && | 168 memcmp(block[0], block[1], OD_BLOCK_SIZE) == 0) |
171 memcmp(block[0], block[1], OD_BLOCK_SIZE) == 0) { | 169 { |
172 if (!last_match) | 170 if (!last_match) puts("*"); |
173 puts("*"); | |
174 last_match = 1; | 171 last_match = 1; |
175 } else { | 172 } else { |
176 display_line(offset, block[index], len); | 173 display_line(offset, block[index], len); |
177 last_match = 0; | 174 last_match = 0; |
178 } | 175 } |
179 offset += len; | 176 offset += len; |
180 index = !index; | 177 index = !index; |
181 | 178 |
182 if (len != OD_BLOCK_SIZE) | 179 if (len != OD_BLOCK_SIZE) break; |
183 break; | 180 } |
184 } while (1); | |
185 | 181 |
186 if (!(toys.optflags & FLAG_N) && offset != TT.max_count) | 182 if (!(toys.optflags & FLAG_N) && offset != TT.max_count) |
187 display_line(offset, NULL, 0); | 183 display_line(offset, NULL, 0); |
188 } | 184 } |
189 | 185 |
209 case 'a': | 205 case 'a': |
210 if (width != 1) | 206 if (width != 1) |
211 error_exit("invalid width for ascii base"); | 207 error_exit("invalid width for ascii base"); |
212 break; | 208 break; |
213 case 'd': case 'x': case 'o': case'u': | 209 case 'd': case 'x': case 'o': case'u': |
214 if (width != 1 && width != 2 && | 210 if (width != 1 && width != 2 && width != 4 && width != 8) |
215 width != 4 && width != 8) | 211 error_exit("this system doesn't provide a %d-byte type", width); |
216 error_exit("this system doesn't provide a %d-byte type", | |
217 width); | |
218 break; | 212 break; |
219 case 'f': | 213 case 'f': |
220 if (width != 4 && width != 8) | 214 if (width != 4 && width != 8) |
221 error_exit("this system doesn't provide a %d-byte floating point type", | 215 error_exit("this system doesn't provide a %d-byte floating point type", |
222 width); | 216 width); |
229 }; | 223 }; |
230 } | 224 } |
231 | 225 |
232 void od_main(void) | 226 void od_main(void) |
233 { | 227 { |
234 if (!TT.address_base) | 228 if (!TT.address_base) TT.address_base = "o"; |
235 TT.address_base = "o"; | 229 if (toys.optflags & FLAG_b) append_base("o1"); |
236 if (toys.optflags & FLAG_b) | 230 if (toys.optflags & FLAG_d) append_base("u2"); |
237 append_base("o1"); | 231 if (toys.optflags & FLAG_o) append_base("o2"); |
238 if (toys.optflags & FLAG_d) | 232 if (toys.optflags & FLAG_s) append_base("d2"); |
239 append_base("u2"); | 233 if (toys.optflags & FLAG_x) append_base("x2"); |
240 if (toys.optflags & FLAG_o) | 234 if (!TT.output_base) append_base("o2"); |
241 append_base("o2"); | |
242 if (toys.optflags & FLAG_s) | |
243 append_base("d2"); | |
244 if (toys.optflags & FLAG_x) | |
245 append_base("x2"); | |
246 if (!TT.output_base) | |
247 append_base("o2"); | |
248 valid_bases(); | 235 valid_bases(); |
249 loopfiles(toys.optargs, do_od); | 236 loopfiles(toys.optargs, do_od); |
250 } | 237 } |