aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:00:59 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:00:59 +0000
commitfa6966ce2412a35c576cc0cd99efcdf9be9156fb (patch)
tree4b3ee1a26b3baa56162602ecfebb6abdcadd85a3 /utils
parent666c11696c2674af4e765ba20e33d04bf01a1770 (diff)
downloadsg3_utils-fa6966ce2412a35c576cc0cd99efcdf9be9156fb.tar.gz
Load sg3_utils-1.09 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@43 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'utils')
-rw-r--r--utils/hxascdmp.c155
1 files changed, 92 insertions, 63 deletions
diff --git a/utils/hxascdmp.c b/utils/hxascdmp.c
index 467e3a7c..dedeae80 100644
--- a/utils/hxascdmp.c
+++ b/utils/hxascdmp.c
@@ -1,3 +1,32 @@
+/*
+ * Copyright (c) 2004 Douglas Gilbert.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -23,21 +52,21 @@ static void dStrHex(const char* str, int len, long start)
long a = start;
const int bpstart = BINARY_START_COL;
const int cpstart = BINARY_START_COL +
- ((CHARS_PER_HEX_BYTE * bytes_per_line) + 1) + 5;
+ ((CHARS_PER_HEX_BYTE * bytes_per_line) + 1) + 5;
int cpos = cpstart;
int bpos = bpstart;
int midline_space = (bytes_per_line / 2) + 1;
int i, k, line_length;
if (len <= 0)
- return;
+ return;
line_length = BINARY_START_COL +
- (bytes_per_line * (1 + CHARS_PER_HEX_BYTE)) + 7;
+ (bytes_per_line * (1 + CHARS_PER_HEX_BYTE)) + 7;
if (line_length >= MAX_LINE_LENGTH)
{
- fprintf(stderr, "bytes_per_line causes maximum line length of %d "
- "to be exceeded\n", MAX_LINE_LENGTH);
- return;
+ fprintf(stderr, "bytes_per_line causes maximum line length of %d "
+ "to be exceeded\n", MAX_LINE_LENGTH);
+ return;
}
memset(buff, ' ', line_length);
buff[line_length] = '\0';
@@ -79,11 +108,11 @@ static void usage()
fprintf(stderr, " Sends hex ASCII dump of stdin/file to stdout\n");
fprintf(stderr, " where:\n");
fprintf(stderr, " -b=<n> bytes per line to display "
- "(def: 16)\n");
+ "(def: 16)\n");
fprintf(stderr, " -h print this usage message\n");
fprintf(stderr, " -? print this usage message\n");
fprintf(stderr, " file reads file(s) and outputs it "
- "as hex ASCII\n");
+ "as hex ASCII\n");
fprintf(stderr, " if no files reads stdin\n");
}
@@ -93,79 +122,79 @@ int main(int argc, const char ** argv)
int num = 8192;
long start = 0;
int res, k, u;
- int inFile = 0; /* stdin */
+ int inFile = 0; /* stdin */
int doHelp = 0;
int hasFilename = 0;
for (k = 1; k < argc; k++)
{
- if (0 == strncmp("-b=", argv[k], 3))
- {
- res = sscanf(argv[k] + 3, "%d", &u);
- if ((1 != res) || (u < 1))
- {
- printf("Bad value after '-b' switch\n");
- usage();
- return 1;
- }
- bytes_per_line = u;
- }
- else if (0 == strcmp("-h", argv[k]))
- doHelp = 1;
- else if (0 == strcmp("-?", argv[k]))
- doHelp = 1;
- else if (*argv[k] == '-')
- {
- fprintf(stderr, "unknown switch: %s\n", argv[k]);
- usage();
- return 1;
- }
- else
- {
- hasFilename = 1;
- break;
- }
+ if (0 == strncmp("-b=", argv[k], 3))
+ {
+ res = sscanf(argv[k] + 3, "%d", &u);
+ if ((1 != res) || (u < 1))
+ {
+ printf("Bad value after '-b' switch\n");
+ usage();
+ return 1;
+ }
+ bytes_per_line = u;
+ }
+ else if (0 == strcmp("-h", argv[k]))
+ doHelp = 1;
+ else if (0 == strcmp("-?", argv[k]))
+ doHelp = 1;
+ else if (*argv[k] == '-')
+ {
+ fprintf(stderr, "unknown switch: %s\n", argv[k]);
+ usage();
+ return 1;
+ }
+ else
+ {
+ hasFilename = 1;
+ break;
+ }
}
if (doHelp)
{
- usage();
- return 0;
+ usage();
+ return 0;
}
/* Make sure num to fetch is integral multiple of bytes_per_line */
if (0 != (num % bytes_per_line))
- num = (num / bytes_per_line) * bytes_per_line;
+ num = (num / bytes_per_line) * bytes_per_line;
if (hasFilename)
{
- for ( ; k < argc; k++)
- {
- inFile = open(argv[k], O_RDONLY);
- if (inFile < 0)
- {
- fprintf(stderr, "Couldn't open file: %s\n", argv[k]);
- }
- else
- {
- start = 0;
- printf("ASCII hex dump of file: %s\n", argv[k]);
- while ((res = read(inFile, buff, num)) > 0)
- {
- dStrHex(buff, res, start);
- start += (long)res;
- }
- }
- close(inFile);
- printf("\n");
- }
+ for ( ; k < argc; k++)
+ {
+ inFile = open(argv[k], O_RDONLY);
+ if (inFile < 0)
+ {
+ fprintf(stderr, "Couldn't open file: %s\n", argv[k]);
+ }
+ else
+ {
+ start = 0;
+ printf("ASCII hex dump of file: %s\n", argv[k]);
+ while ((res = read(inFile, buff, num)) > 0)
+ {
+ dStrHex(buff, res, start);
+ start += (long)res;
+ }
+ }
+ close(inFile);
+ printf("\n");
+ }
}
else
{
- while ((res = read(inFile, buff, num)) > 0)
- {
- dStrHex(buff, res, start);
- start += (long)res;
- }
+ while ((res = read(inFile, buff, num)) > 0)
+ {
+ dStrHex(buff, res, start);
+ start += (long)res;
+ }
}
return 0;
}