/******************************************************************************* * hdump.c * Dump the contents of a file in hex and/or ASCII format. * * Notes * Define 'EBCDIC' when compiling on a system that uses EBCDIC as its * native character set (e.g., IBM OS/390). * * Define 'FSEARCH' if the fsearch libraries are available. * * Ported to * MS-DOS 2.x+, Microsoft C 4.0. * MS/Windows, Win32, Microsoft C 5.0+. * HP-UX. * IBM OS/390. * IBM AIX. * * Notice * Copyright ©1985,2003 by David R. Tribble, all rights reserved. * * This source code is copyrighted. Distribution of this source code is * granted, provided that this copyright notice remains attached to the * source code, and that adequate acknowledgement is given to the original * author. * *------------------------------------------------------------------------------- * History * * 1.00 1985-04-14 drt. * First cut. * 2.00 1986-07-31 drt. * Added more options and cleaned up old ones. * 2.01 1986-08-02 drt. * Reformatted output. * 2.02 1986-08-11 drt. * More options. * 2.03 1986-08-16 drt. * Fixed `--' option. * 2.04 1986-08-18 drt. * Added `-l', `-s', `-e' options. * 2.05 1986-09-09 drt. * Added stat() call in header(). * 2.06 1986-12-01 drt. * Fixed -s, -e option syntax. * 2.07 1987-03-05 drt. * Changed address output format from FFFFFFFF to FFFF.FFFF. * 2.08 1987-04-01 drt. * Added time and date to header(). * 2.09 1987-04-08 drt. * Reversed meaning of -7 option. * 2.10 1987-04-24 drt. * Prettied-up header output. * 2.11 1987-05-11 drt. * Added wildcard searching on filenames. * Added setvbuf() usage. * 2.12 1987-08-10 drt. * Added -E (EBCDIC) option. * 2.13 1987-08-28 drt. * Removed #ifdef MICROSOFT stuff. * 2.14 1987-12-17 drt. * Uses fpsearch functions. * 2.15 1991-02-11 drt. * Standard code style. * 2.16a 1995-07-11 drt. * Fixed portability problems. * 2.16b 1995-06-27 drt. * Fixed porting bugs. * 2.17 1999-05-11 drt. * Added ASCII/EBCDIC tables. * Added -A (ASCII) option. * 2.18 2001-09-24 drt. * Fixed minor 16/32-bit bugs. * Converted function definitions to ISO prototypes. * 2.19 2002-03-08 drt. * Fixes for porting to Unix. * 2.20 2002-12-24 drt. * Removed use of 'isatty()'. * Added 'fstat()' call to 'header()'. * * @(#)drt/src/cmd/hdump.c $Revision: 3.1 $ $Date: 2003/01/05 00:59:34 $ *------------------------------------------------------------------------------- */ /* Identification */ #define PROG "hdump" #define SRCFILE "drt/src/cmd/hdump.c" #define VERSION "$Revision: 3.1 $ $Date: 2003/01/05 00:59:34 $" static const char * prog = PROG; static const char notice[] = "@(#)" SRCFILE " " VERSION; static const char built[] = "@(#)" "Built: " __DATE__ " " __TIME__; static const char revno[] = "$Revision: 3.1 $"; static const char revdate[] = "$Date: 2003/01/05 00:59:34 $"; /* System includes */ #define NO_EXT_KEYS #define LINT_ARGS #include #include #include #include #include #include #include #ifdef __MSDOS__ #include #endif #include #include /* Local includes */ #ifdef FSEARCH #include "fsearch.h" #endif #define fisatty(fp) isatty(fileno(fp)) /* Local constants and types */ #define FBUFSZ (32*1024) /* Input file buffer size */ #define PAGESZ 32 /* Lines per output page */ #define TRUE 1 #define FALSE 0 typedef char bool; struct option { bool input; /* Read from stdin */ bool loc; /* Print location */ bool chars; /* Character output only */ bool bit7; /* Treat bit 7 as zero */ bool ebcdic; /* EBCDIC characters */ bool ascii; /* ASCII characters */ bool ctrl; /* Output control code as is */ bool word; /* Word data */ bool contents; /* Print file contents */ bool rev; /* Reverse right to left data */ bool intel; /* Intel format */ char radix; /* Data radix */ unsigned long start; /* Start address */ unsigned long end; /* End address */ }; /* ASCII constants */ #define BEL 0x07 #define CR 0x0D #define SP 0x20 #define DEL 0x7F /* Radix codes */ #define OCT 'o' #define DEC 'd' #define HEX 'h' /* Local function macros */ #define itoc(d) ((d) + '0') /* Local variables */ static char fbuf[FBUFSZ]; /* Input file buffer */ /******************************************************************************* * atoe_1047[] * ASCII to EBCDIC character translation table. * This table is based on ISO-88591-1 (Latin-1) and IBM-1047 code pages. */ const unsigned char atoe_1047[0x100] = { /* 0x00-0x07 */ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F, /* 0x08-0x0F */ 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 0x10-0x17 */ 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26, /* 0x18-0x1F */ 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F, /* 0x20-0x27 */ 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D, /* 0x28-0x2F */ 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61, /* 0x30-0x37 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, /* 0x38-0x3F */ 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F, /* 0x40-0x47 */ 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, /* 0x48-0x4F */ 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, /* 0x50-0x57 */ 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, /* 0x58-0x5F */ 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D, /* 0x60-0x67 */ 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 0x68-0x6F */ 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* 0x70-0x77 */ 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, /* 0x78-0x7F */ 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07, /* 0x80-0x87 */ 0x04, 0x06, 0x08, 0x09, 0x0A, 0x14, 0x17, 0x1A, /* 0x88-0x8F */ 0x1B, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x28, /* 0x90-0x97 */ 0x29, 0x2A, 0x2B, 0x2C, 0x30, 0x31, 0x33, 0x34, /* 0x98-0x9F */ 0x35, 0x36, 0x38, 0x39, 0x3A, 0x3B, 0x3E, 0xFF, /* 0xA0-0xA7 */ 0x41, 0xAA, 0x4A, 0xB1, 0x9F, 0xB2, 0x6A, 0xB5, /* 0xA8-0xAF */ 0xBB, 0xB4, 0x9A, 0x8A, 0xB0, 0xCA, 0xAF, 0xBC, /* 0xB0-0xB7 */ 0x90, 0x8F, 0xEA, 0xFA, 0xBE, 0xA0, 0xB6, 0xB3, /* 0xB8-0xBF */ 0x9D, 0xDA, 0x9B, 0x8B, 0xB7, 0xB8, 0xB9, 0xAB, /* 0xC0-0xC7 */ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9E, 0x68, /* 0xC8-0xCF */ 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* 0xD0-0xD7 */ 0xAC, 0x69, 0xED, 0xEE, 0xEB, 0xEF, 0xEC, 0xBF, /* 0xD8-0xDF */ 0x80, 0xFD, 0xFE, 0xFB, 0xFC, 0xBA, 0xAE, 0x59, /* 0xE0-0xE7 */ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9C, 0x48, /* 0xE8-0xEF */ 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* 0xF0-0xF7 */ 0x8C, 0x49, 0xCD, 0xCE, 0xCB, 0xCF, 0xCC, 0xE1, /* 0xF8-0xFF */ 0x70, 0xDD, 0xDE, 0xDB, 0xDC, 0x8D, 0x8E, 0xDF, }; /******************************************************************************* * etoa_1047[] * EBCDIC to ASCII character translation table. * This table is based on ISO-88591-1 (Latin-1) and IBM-1047 code pages. */ const unsigned char etoa_1047[0x100] = { /* 0x00-0x07 */ 0x00, 0x01, 0x02, 0x03, 0x80, 0x09, 0x81, 0x7F, /* 0x08-0x0F */ 0x82, 0x83, 0x84, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 0x10-0x17 */ 0x10, 0x11, 0x12, 0x13, 0x85, 0x0A, 0x08, 0x86, /* 0x18-0x1F */ 0x18, 0x19, 0x87, 0x88, 0x1C, 0x1D, 0x1E, 0x1F, /* 0x20-0x27 */ 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x17, 0x1B, /* 0x28-0x2F */ 0x8F, 0x90, 0x91, 0x92, 0x93, 0x05, 0x06, 0x07, /* 0x30-0x37 */ 0x94, 0x95, 0x16, 0x96, 0x97, 0x98, 0x99, 0x04, /* 0x38-0x3F */ 0x9A, 0x9B, 0x9C, 0x9D, 0x14, 0x15, 0x9E, 0x1A, /* 0x40-0x47 */ 0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, /* 0x48-0x4F */ 0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C, /* 0x50-0x57 */ 0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, /* 0x58-0x5F */ 0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E, /* 0x60-0x67 */ 0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, /* 0x68-0x6F */ 0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, /* 0x70-0x77 */ 0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, /* 0x78-0x7F */ 0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, /* 0x80-0x87 */ 0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x88-0x8F */ 0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1, /* 0x90-0x97 */ 0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, /* 0x98-0x9F */ 0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4, /* 0xA0-0xA7 */ 0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* 0xA8-0xAF */ 0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0x5B, 0xDE, 0xAE, /* 0xB0-0xB7 */ 0xAC, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, /* 0xB8-0xBF */ 0xBD, 0xBE, 0xDD, 0xA8, 0xAF, 0x5D, 0xB4, 0xD7, /* 0xC0-0xC7 */ 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0xC8-0xCF */ 0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5, /* 0xD0-0xD7 */ 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, /* 0xD8-0xDF */ 0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF, /* 0xE0-0xE7 */ 0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* 0xE8-0xEF */ 0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5, /* 0xF0-0xF7 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0xF8-0xFF */ 0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F, }; /******************************************************************************* * printline() * Print data line. * Print size bytes in numeric and ASCII representation to * file out. */ static int printline(FILE *out, const struct option *opt, unsigned char buf[], int linesz, int size, unsigned long byteno) { int i, j; /* Counter */ int half; unsigned char uc; /* Character byte */ unsigned int v; /* Data byte/word value */ const char * rad; const char * rsp; /* Print line location */ if (opt->loc) printf("%04X.%04X ", (unsigned int)((byteno >> 16) & 0xFFFF), (unsigned int)(byteno & 0xFFFF)); /* Print data representation of line */ if (!opt->chars) { switch (opt->radix) { case OCT: rad = (opt->word ? "%06o " : "%03o "); rsp = (opt->word ? "...... " : "... "); break; case DEC: rad = (opt->word ? "%5u " : "%3u "); rsp = (opt->word ? "..... " : "... "); break; case HEX: rad = (opt->word ? "%04X " : "%02X "); rsp = (opt->word ? ".... " : ".. "); break; } half = 8 - 1; /* Write spaces (first line) */ i = 0; if (byteno < opt->start) { for (; i < opt->start - byteno; ++i) { if (opt->word) ++i; fprintf(out, rsp); if ((i & half) == half) putc(' ', out); } if (i > opt->start - byteno) --i; } /* Write data bytes */ buf[size] = 0x00; for (; i < size; ++i) { if (opt->word) { v = buf[i] + buf[i+1] * 0x100; ++i; } else v = buf[i]; fprintf(out, rad, v); if ((i & half) == half) putc(' ', out); } /* Write spaces (last line) */ for (; i < linesz; ++i) { if (opt->word) ++i; fprintf(out, rsp); if ((i & half) == half) putc(' ', out); } } /* Write character representation of line */ i = 0; if (byteno < opt->start) { for (; i < opt->start - byteno; ++i) putc(' ', out); } for (; i < size; ++i) { uc = buf[i]; if (opt->ebcdic) uc = etoa_1047[uc]; else if (opt->ascii) uc = atoe_1047[uc]; if (opt->bit7) uc &= 0x7F; #ifndef EBCDIC if (uc == DEL) uc = '.'; else if (opt->ctrl) { if (uc >= BEL && uc <= CR) uc = '.'; } else #endif if (uc < 0x20 || uc >= 0x7F && uc < 0xA0) uc = '.'; putc(uc, out); } putc('\n', out); return TRUE; } /******************************************************************************* * readline() * Read file line. * Read count bytes from file in, returning number of * bytes actually read, or zero on end of file. */ static int readline(FILE *in, unsigned char *buf, int count) { int size; int c; #ifdef This_is_another_way_to_do_it size = fread(buf, sizeof(char), count, in); return size; #else /* Read a line of data from input file */ for (size = 0; size < count; ++size) { c = getc(in); if (c == EOF) break; buf[size] = c; } /* size == length of input line */ return size; #endif } /******************************************************************************* * printn() * Print number. * Print number n to string s, in format: * "Z,ZZZ,ZZZ,ZZZ" */ static char * prn(char *s, unsigned long n, int lev) { int d; d = n % 10; /* Low order digit of n */ n /= 10; /* n sans low digit */ if (n != 0) { s = prn(s, n, lev+1); /* Recursive */ if (lev % 3 == 2) *s++ = ','; } *s++ = itoc(d); *s = '\0'; return s; } static void printn(char *s, unsigned long n) { *s = '\0'; prn(s, n, 0); } /******************************************************************************* * ptime() * Print time. * Print time_t value timeval to stream out, in the format: * "Sun 16 Sep 1978 01:23 pm" */ static void ptime(FILE *out, const time_t *timeval) { struct tm tm; const char * at; int hr; /* asctime: "Sun Sep 16 01:23:23 1978no" */ /* -0123456789.123456789.12345- */ /* Printed: "Sun 16 Sep 1978 01:23 pm" */ tm = *localtime(timeval); at = asctime(&tm); hr = tm.tm_hour; fprintf(out, "%.4s%.3s%.4s%.4s %2d:%.2s %cm", at+0, at+8, at+4, at+20, (hr > 12 ? hr-12 : (hr == 0 ? 12 : hr)), at+14, (hr > 12 ? 'p' : 'a')); } /******************************************************************************* * header() * Print header. * Print file header info for file in to output file out. * Input filename is 'name'. */ static void header(FILE *out, FILE *in, const char *name) { struct stat info; /* File inode info */ time_t t; int i; char buf[80]; /* Print full file name */ if (name != NULL) fprintf(out, "%s", name); /* Print file info */ buf[0] = '\0'; if (name != NULL && stat(name, &info) == 0 || name == NULL && fstat(fileno(in), &info) == 0) { /* Print file's last modification date */ if (info.st_mtime > 0) { if (name != NULL) { for (i = strlen(name)/8 + 1; i < 7; ++i) fprintf(out, "\t"); } else fprintf(out, "\t\t\t\t\t\t"); if (info.st_mtime > 0) ptime(out, &info.st_mtime); fprintf(out, "\n"); } if ((info.st_mode & S_IFDIR) != 0) fprintf(out, "\tdirectory\n"); /* Print file size */ fprintf(out, "\t"); printn(buf, info.st_size); sprintf(buf+strlen(buf), " (%04lXh) bytes", info.st_size); fputs(buf, out); } /* Print current time and date */ for (i = strlen(buf)/8 + 1; i < 6; ++i) fprintf(out, "\t"); time(&t); ptime(out, &t); fprintf(out, "\n\n"); } /******************************************************************************* * dump() * Dump file. * Print a data/ASCII dump of file in to file out. * Input file has name filename. */ void dump(FILE *in, const char *filename, FILE *out, const struct option *opt) { unsigned char buf[128 + 1]; /* Input line buffer */ int linesz; /* Line buffer length */ int size; /* Actual line size */ unsigned long byteno; /* Current file byte number */ int lineno; /* Line counter */ /* Print file header info */ header(out, in, filename); if (!opt->contents) return; /* Set output line size */ if (opt->radix == OCT && opt->loc) linesz = 8; else if (opt->radix == DEC && opt->loc) linesz = 8; else linesz = 16; if (opt->chars) linesz = 64; /* Seek to start byte in input file */ if (opt->start > opt->end) return; byteno = (opt->start / linesz) * linesz; /* To nearest line */ fseek(in, byteno, SEEK_SET); /* Dump file contents */ lineno = 0; while (byteno < opt->end) { size = readline(in, buf, linesz); if (size == 0) break; if (byteno + size > opt->end) size = opt->end - byteno + 1; ++lineno; if (lineno > PAGESZ) { lineno = 1; #if 0 /* Disabled */ putc('\n', out); #endif } printline(out, opt, buf, linesz, size, byteno); byteno += size; } } /******************************************************************************* * locspec() * Location specifier. * Convert `-s' or `-e' location arg into numeric value `val'. * If an error occurs, `val' is left unchanged. */ static void locspec(unsigned long *val, char *arg) { char * radix; /* Radix scanf string */ unsigned long unit; /* Unit size */ char c; /* Suffix char */ /* Interpret unit suffix */ c = arg[strlen(arg) - 1]; arg[strlen(arg) - 1] = '\0'; switch (tolower(c)) { case 'b': /* 512-byte block */ unit = 512; break; case 'k': /* Kilobyte */ unit = 1024; break; case 's': /* 128-byte sector */ unit = 128; break; default: /* No unit suffix */ unit = 1; arg[strlen(arg)] = c; } /* Interpret radix suffix */ c = arg[strlen(arg) - 1]; arg[strlen(arg) - 1] = '\0'; switch (tolower(c)) { case 'h': /* Hex address */ case 'x': radix = "%lx"; break; case 'o': radix = "%lo"; break; default: /* No radix suffix */ radix = "%lu"; arg[strlen(arg)] = c; } sscanf(arg, radix, val); *val *= unit; } static const char * usage_m[] = { "Options:", " - Read from standard input", " -7 Treat high bit (bit 7) as zero", " -a Character data only", " -A Print ASCII characters converted from EBCDIC (IBM-1047)", " -c Echo control codes as is", " -d Decimal format", " -eA End address", " -E Print EBCDIC (IBM-1047) characters converted from ASCII", " -h File header only", #ifdef INCOMPLETE " -I Intel standard output", #endif " -l Suppress line addresses", " -o Octal format", #ifdef INCOMPLETE " -p Printer format", #endif #ifdef INCOMPLETE " -r Reverse data right to left", #endif " -sA Start address", " -w Data words, not bytes", "", "where 'A' is a number with an optional radix suffix:", " h Hexadecimal number", " o Octal number", "and an optional unit suffix:", " b 512-byte block", " k Kilobyte", " s 128-byte sector", NULL }; /******************************************************************************* * main() */ int main(int argc, char **argv) { FILE * fp; /* File var */ int i; /* Arg counter */ char * cp; /* Option char */ struct option opt; /* Options flags */ int fcount; /* File counter */ /* Initialize options */ opt.start = 0L; opt.end = -1L; opt.radix = HEX; opt.input = FALSE; opt.loc = TRUE; opt.chars = FALSE; opt.bit7 = FALSE; opt.ebcdic = FALSE; opt.ascii = FALSE; opt.ctrl = FALSE; opt.word = FALSE; opt.contents = TRUE; opt.rev = FALSE; opt.intel = FALSE; /* Extract options, if any */ /*prog = argv[0];*/ while (++argv, --argc > 0) { if (**argv != '-') break; cp = *argv; if (cp[1] != '\0') cp++; for ( ; *cp != '\0'; cp++) { switch (*cp) { case '-': /* Take input from stdin */ opt.input = TRUE; break; case '7': /* Don't treat bit 7 as zero */ opt.bit7 = TRUE; break; case 'a': /* Print only char values */ opt.chars = TRUE; break; case 'A': /* Print ASCII chars */ opt.ascii = TRUE; break; case 'E': /* Print EBCDIC chars */ opt.ebcdic = TRUE; break; case 'd': /* Decimal radix */ case 'o': /* Octal radix */ opt.radix = *cp; break; case 'c': /* Echo control chars as is */ opt.ctrl = TRUE; break; case 'h': /* File header only */ opt.contents = FALSE; break; #ifdef INCOMPLETE case 'I': /* Intel standard output */ opt.intel = TRUE; break; #endif case 'l': /* Suppress location output */ opt.loc = FALSE; break; #ifdef INCOMPLETE case 'r': /* Reverse right to left */ opt.rev = TRUE; break; #endif case 's': /* Start location */ case 'e': /* End location */ if (*(cp+1) == '\0') goto usage; locspec((*cp == 's' ? &opt.start : &opt.end), cp+1); goto nextarg; case 'w': /* Data words, not bytes */ opt.word = TRUE; break; default: goto usage; } } nextarg: NULL; } /* Check command usage */ if (argc < 1 && !opt.input) goto usage; fcount = 0; if (opt.input) { fp = stdin; #ifdef O_BINARY if (setmode(fileno(fp), O_BINARY) >= 0) { setvbuf(fp, fbuf, _IOFBF, FBUFSZ); } else { fprintf(stderr, "%s: Can't set binary mode on standard input, error %d,\n %s\n", prog, errno, strerror(errno)); return EXIT_FAILURE; } #endif dump(fp, NULL, stdout, &opt); /* fclose(fp); */ ++fcount; } else { /* Process filename args */ for (i = 0; i < argc; ++i) { #ifndef FSEARCH fp = fopen(argv[i], "rb"); if (fp != NULL) { #if REMOVED_OLD_CODE if (!fisatty(stdout)) { fprintf(stderr, "%s\n", argv[i]); fflush(stderr); } #endif if (fcount > 0 && opt.contents) { if (fisatty(stdout)) putchar('\n'); else putchar('\f'); } setvbuf(fp, fbuf, _IOFBF, FBUFSZ); dump(fp, argv[i], stdout, &opt); fclose(fp); ++fcount; } else fprintf(stderr, "%s: Can't read '%s', error %d,\n %s\n", prog, argv[i], errno, strerror(errno)); #else /* FSEARCH */ if (!fpstart(argv[i], NULL, _A_NORMAL)) { fprintf(stderr, "%s: Can't find '%s'\n", prog, argv[i]); continue; } while (fpnext(NULL, NULL, 1)) { fp = fopen(fps_name, "rb"); if (fp != NULL) { #if REMOVED_OLD_CODE if (!fisatty(stdout)) { fprintf(stderr, "%s\n", fps_name); fflush(stderr); } #endif if (fcount > 0 && opt.contents) { if (fisatty(stdout)) putchar('\n'); else putchar('\f'); } setvbuf(fp, fbuf, _IOFBF, FBUFSZ); dump(fp, fps_name, stdout, &opt); fclose(fp); ++fcount; } else fprintf(stderr, "%s: Can't read '%s',\n %s\n", prog, fps_name, errno, strerror(errno)); } #endif /* FSEARCH */ } } return EXIT_SUCCESS; usage: /* Display a usage message */ fprintf(stderr, "[%s, %.4s %.10s]\n", prog, revno+11, revdate+7); fprintf(stderr, "Dump the contents of one or more files.\n\n"); fprintf(stderr, "usage: %s [-option...] filename...\n", prog); fprintf(stderr, " %s [-option...] -