| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | hexdump.c |
* Crossposted in area PUBLIC_DOMAIN, ED_CODE
/*
* HEXDUMP.C - Dump a file.
*
* This Program Written By Paul Edwards w/ modifications by Bob Stout
* Aditional modifications by Andrew Clarke
* Released to the public domain
*/
#include
#include
#include
#include
void skipb(FILE * fp, long start)
{
long x = 0;
while (x < start) {
fgetc(fp);
x++;
}
}
void dodump(FILE * fp, long start, long count)
{
int c, pos1, pos2;
long x = 0L;
char prtln[100];
while (((c = fgetc(fp)) != EOF) && (x != count)) {
if (x % 16 == 0) {
memset(prtln, ' ', sizeof prtln);
sprintf(prtln, "%0.6X ", start + x);
pos1 = 8;
pos2 = 60;
}
sprintf(prtln + pos1, "%0.2X", c);
if (isprint(c))
sprintf(prtln + pos2, "%c", c);
else
sprintf(prtln + pos2, ".");
pos1 += 2;
*(prtln + pos1) = ' ';
pos1++;
pos2++;
if (x % 4 == 3)
*(prtln + pos1++) = ' ';
if (x % 16 == 15)
printf("%s\n", prtln);
x++;
}
if (x % 16 != 0)
printf("%s\n", prtln);
}
int main(int argc, char **argv)
{
FILE *fp;
long start, count;
if (argc < 2) {
puts("Usage: HEXDUMP file_name [start] [length]");
return EXIT_FAILURE;
}
if (argc > 2)
start = strtol(*(argv + 2), NULL, 0);
else
start = 0L;
if (argc > 3)
count = strtol(*(argv + 3), NULL, 0);
else
count = -1L;
fp = fopen(*(argv + 1), "rb");
if (fp == NULL) {
printf("unable to open file %s for input\n", *(argv + 1));
return EXIT_FAILURE;
}
skipb(fp, start);
dodump(fp, start, count);
return EXIT_SUCCESS;
}
Regards
Andrew
--- Msgedsq/2 3.30
* Origin: This one HAS to be original X (3:635/727.4{at}fidonet)SEEN-BY: 50/99 78/0 635/309 503 544 727 640/230 690/718 711/401 410 413 430 SEEN-BY: 711/808 809 934 712/610 713/888 800/1 7877/2809 @PATH: 635/727 544 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.