display.c (100359) | display.c (102944) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 23 unchanged lines hidden (view full) --- 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93"; 37#endif 38#endif /* not lint */ 39#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 23 unchanged lines hidden (view full) --- 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93"; 37#endif 38#endif /* not lint */ 39#include <sys/cdefs.h> |
40__FBSDID("$FreeBSD: head/usr.bin/hexdump/display.c 100359 2002-07-19 14:12:27Z markm $"); | 40__FBSDID("$FreeBSD: head/usr.bin/hexdump/display.c 102944 2002-09-04 23:29:10Z dwmalone $"); |
41 42#include <sys/param.h> 43#include <sys/stat.h> 44 45#include <ctype.h> 46#include <err.h> 47#include <stdio.h> 48#include <stdlib.h> --- 4 unchanged lines hidden (view full) --- 53enum _vflag vflag = FIRST; 54 55static off_t address; /* address/offset in stream */ 56static off_t eaddress; /* end address */ 57 58static __inline void print(PR *, u_char *); 59 60void | 41 42#include <sys/param.h> 43#include <sys/stat.h> 44 45#include <ctype.h> 46#include <err.h> 47#include <stdio.h> 48#include <stdlib.h> --- 4 unchanged lines hidden (view full) --- 53enum _vflag vflag = FIRST; 54 55static off_t address; /* address/offset in stream */ 56static off_t eaddress; /* end address */ 57 58static __inline void print(PR *, u_char *); 59 60void |
61display() | 61display(void) |
62{ | 62{ |
63 extern FU *endfu; 64 register FS *fs; 65 register FU *fu; 66 register PR *pr; 67 register int cnt; 68 register u_char *bp; | 63 FS *fs; 64 FU *fu; 65 PR *pr; 66 int cnt; 67 u_char *bp; |
69 off_t saveaddress; 70 u_char savech, *savebp; 71 72 while ((bp = get())) 73 for (fs = fshead, savebp = bp, saveaddress = address; fs; 74 fs = fs->nextfs, bp = savebp, address = saveaddress) 75 for (fu = fs->nextfu; fu; fu = fu->nextfu) { 76 if (fu->flags&F_IGNORE) --- 31 unchanged lines hidden (view full) --- 108 case F_TEXT: 109 (void)printf("%s", pr->fmt); 110 break; 111 } 112 } 113} 114 115static __inline void | 68 off_t saveaddress; 69 u_char savech, *savebp; 70 71 while ((bp = get())) 72 for (fs = fshead, savebp = bp, saveaddress = address; fs; 73 fs = fs->nextfs, bp = savebp, address = saveaddress) 74 for (fu = fs->nextfu; fu; fu = fu->nextfu) { 75 if (fu->flags&F_IGNORE) --- 31 unchanged lines hidden (view full) --- 107 case F_TEXT: 108 (void)printf("%s", pr->fmt); 109 break; 110 } 111 } 112} 113 114static __inline void |
116print(pr, bp) 117 PR *pr; 118 u_char *bp; | 115print(PR *pr, u_char *bp) |
119{ 120 long double ldbl; 121 double f8; 122 float f4; 123 int16_t s2; 124 int8_t s8; 125 int32_t s4; 126 u_int16_t u2; --- 80 unchanged lines hidden (view full) --- 207 (void)printf(pr->fmt, u8); 208 break; 209 } 210 break; 211 } 212} 213 214void | 116{ 117 long double ldbl; 118 double f8; 119 float f4; 120 int16_t s2; 121 int8_t s8; 122 int32_t s4; 123 u_int16_t u2; --- 80 unchanged lines hidden (view full) --- 204 (void)printf(pr->fmt, u8); 205 break; 206 } 207 break; 208 } 209} 210 211void |
215bpad(pr) 216 PR *pr; | 212bpad(PR *pr) |
217{ 218 static char const *spec = " -0+#"; | 213{ 214 static char const *spec = " -0+#"; |
219 register char *p1, *p2; | 215 char *p1, *p2; |
220 221 /* 222 * Remove all conversion flags; '-' is the only one valid 223 * with %s, and it's not useful here. 224 */ 225 pr->flags = F_BPAD; 226 pr->cchar[0] = 's'; 227 pr->cchar[1] = '\0'; 228 for (p1 = pr->fmt; *p1 != '%'; ++p1); 229 for (p2 = ++p1; *p1 && index(spec, *p1); ++p1); 230 while ((*p2++ = *p1++)); 231} 232 233static char **_argv; 234 235u_char * | 216 217 /* 218 * Remove all conversion flags; '-' is the only one valid 219 * with %s, and it's not useful here. 220 */ 221 pr->flags = F_BPAD; 222 pr->cchar[0] = 's'; 223 pr->cchar[1] = '\0'; 224 for (p1 = pr->fmt; *p1 != '%'; ++p1); 225 for (p2 = ++p1; *p1 && index(spec, *p1); ++p1); 226 while ((*p2++ = *p1++)); 227} 228 229static char **_argv; 230 231u_char * |
236get() | 232get(void) |
237{ 238 static int ateof = 1; 239 static u_char *curp, *savp; | 233{ 234 static int ateof = 1; 235 static u_char *curp, *savp; |
240 register int n; | 236 int n; |
241 int need, nread; 242 int valid_save = 0; 243 u_char *tmpp; 244 245 if (!curp) { 246 if ((curp = calloc(1, blocksize)) == NULL) 247 err(1, NULL); 248 if ((savp = calloc(1, blocksize)) == NULL) --- 54 unchanged lines hidden (view full) --- 303 nread = 0; 304 } 305 else 306 nread += n; 307 } 308} 309 310int | 237 int need, nread; 238 int valid_save = 0; 239 u_char *tmpp; 240 241 if (!curp) { 242 if ((curp = calloc(1, blocksize)) == NULL) 243 err(1, NULL); 244 if ((savp = calloc(1, blocksize)) == NULL) --- 54 unchanged lines hidden (view full) --- 299 nread = 0; 300 } 301 else 302 nread += n; 303 } 304} 305 306int |
311next(argv) 312 char **argv; | 307next(char **argv) |
313{ | 308{ |
314 extern int exitval; | |
315 static int done; 316 int statok; 317 318 if (argv) { 319 _argv = argv; 320 return(1); 321 } 322 for (;;) { --- 16 unchanged lines hidden (view full) --- 339 ++_argv; 340 if (!skip) 341 return(1); 342 } 343 /* NOTREACHED */ 344} 345 346void | 309 static int done; 310 int statok; 311 312 if (argv) { 313 _argv = argv; 314 return(1); 315 } 316 for (;;) { --- 16 unchanged lines hidden (view full) --- 333 ++_argv; 334 if (!skip) 335 return(1); 336 } 337 /* NOTREACHED */ 338} 339 340void |
347doskip(fname, statok) 348 const char *fname; 349 int statok; | 341doskip(const char *fname, int statok) |
350{ | 342{ |
351 register int cnt; | 343 int cnt; |
352 struct stat sb; 353 354 if (statok) { 355 if (fstat(fileno(stdin), &sb)) 356 err(1, "%s", fname); 357 if (S_ISREG(sb.st_mode) && skip >= sb.st_size) { 358 address += sb.st_size; 359 skip -= sb.st_size; --- 16 unchanged lines hidden --- | 344 struct stat sb; 345 346 if (statok) { 347 if (fstat(fileno(stdin), &sb)) 348 err(1, "%s", fname); 349 if (S_ISREG(sb.st_mode) && skip >= sb.st_size) { 350 address += sb.st_size; 351 skip -= sb.st_size; --- 16 unchanged lines hidden --- |