aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Makefile.am8
-rw-r--r--dmstools.xcodeproj/project.pbxproj2
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/bindump.c361
-rw-r--r--src/bindump.mak7
6 files changed, 381 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index fe889a1..5972bdf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
2DMS Tools and Utilities 2DMS Tools and Utilities
3Copyright (C) 2008, 2009 David M. Syzdek <david@syzdek.net> 3Copyright (C) 2008, 2009 David M. Syzdek <david@syzdek.net>
4 4
50.9
6 - Adding bindump utility (syzdek)
7
50.8 2009/12/31 (syzdek) 80.8 2009/12/31 (syzdek)
6 - Adding typedef-info utility (syzdek) 9 - Adding typedef-info utility (syzdek)
7 - Adding bitcopy utility (syzdek) 10 - Adding bitcopy utility (syzdek)
diff --git a/Makefile.am b/Makefile.am
index 40c03b3..1cc1bc1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,11 +39,17 @@ DEFS = -DLOCALEDIR="\"$(localedir)\"" @DEFS@
39 39
40 40
41# automake targets 41# automake targets
42bin_PROGRAMS = src/bitcopy src/bitops src/numconvert src/typedef-info 42bin_PROGRAMS = src/bindump src/bitcopy src/bitops src/numconvert src/typedef-info
43noinst_PROGRAMS = 43noinst_PROGRAMS =
44noinst_HEADERS = src/common.h 44noinst_HEADERS = src/common.h
45man_MANS = doc/codetagger.1 45man_MANS = doc/codetagger.1
46 46
47# macros for src/bindump
48src_bindump_DEPENDENCIES = $(lib_LTLIBRARIES) Makefile
49src_bindump_CPPFLAGS = -DPROGRAM_NAME="\"bindump\"" $(AM_CPPFLAGS)
50src_bindump_SOURCES = $(noinst_HEADERS) \
51 src/bindump.c
52
47# macros for src/bitops 53# macros for src/bitops
48src_bitcopy_DEPENDENCIES = $(lib_LTLIBRARIES) Makefile 54src_bitcopy_DEPENDENCIES = $(lib_LTLIBRARIES) Makefile
49src_bitcopy_CPPFLAGS = -DPROGRAM_NAME="\"bitcopy\"" $(AM_CPPFLAGS) 55src_bitcopy_CPPFLAGS = -DPROGRAM_NAME="\"bitcopy\"" $(AM_CPPFLAGS)
diff --git a/dmstools.xcodeproj/project.pbxproj b/dmstools.xcodeproj/project.pbxproj
index ecc73ef..c747f49 100644
--- a/dmstools.xcodeproj/project.pbxproj
+++ b/dmstools.xcodeproj/project.pbxproj
@@ -29,6 +29,7 @@
29 A051283C10D987300013335E /* bitcopy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bitcopy.c; sourceTree = "<group>"; }; 29 A051283C10D987300013335E /* bitcopy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bitcopy.c; sourceTree = "<group>"; };
30 A07BC6F10F0210CF00219629 /* bitops.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bitops.c; sourceTree = "<group>"; }; 30 A07BC6F10F0210CF00219629 /* bitops.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bitops.c; sourceTree = "<group>"; };
31 A0AE375510EAAA3C006B1ADB /* typedef-info.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "typedef-info.c"; sourceTree = "<group>"; }; 31 A0AE375510EAAA3C006B1ADB /* typedef-info.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "typedef-info.c"; sourceTree = "<group>"; };
32 A0AF031210F540EB00CBC28C /* bindump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bindump.c; sourceTree = "<group>"; };
32 A0B6D45D1033A3BA004E87EE /* numconvert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = numconvert.c; sourceTree = "<group>"; }; 33 A0B6D45D1033A3BA004E87EE /* numconvert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = numconvert.c; sourceTree = "<group>"; };
33 A0B6D4911033B0E0004E87EE /* POTFILES.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = POTFILES.in; sourceTree = "<group>"; }; 34 A0B6D4911033B0E0004E87EE /* POTFILES.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = POTFILES.in; sourceTree = "<group>"; };
34 A0C7059E10EFEFE4002DA805 /* Makevars */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = Makevars; sourceTree = "<group>"; usesTabs = 1; }; 35 A0C7059E10EFEFE4002DA805 /* Makevars */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = Makevars; sourceTree = "<group>"; usesTabs = 1; };
@@ -62,6 +63,7 @@
62 A00422710E0E396200B0ED60 /* src */ = { 63 A00422710E0E396200B0ED60 /* src */ = {
63 isa = PBXGroup; 64 isa = PBXGroup;
64 children = ( 65 children = (
66 A0AF031210F540EB00CBC28C /* bindump.c */,
65 A051283C10D987300013335E /* bitcopy.c */, 67 A051283C10D987300013335E /* bitcopy.c */,
66 A07BC6F10F0210CF00219629 /* bitops.c */, 68 A07BC6F10F0210CF00219629 /* bitops.c */,
67 A004228B0E0E3C4200B0ED60 /* codetagger.c */, 69 A004228B0E0E3C4200B0ED60 /* codetagger.c */,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 71d128d..2d0cfa4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,4 +1,5 @@
1# List of source files which contain translatable strings. 1# List of source files which contain translatable strings.
2src/bindump.c
2src/bitcopy.c 3src/bitcopy.c
3src/bitops.c 4src/bitops.c
4src/codetagger.c 5src/codetagger.c
diff --git a/src/bindump.c b/src/bindump.c
new file mode 100644
index 0000000..5b06eb8
--- /dev/null
+++ b/src/bindump.c
@@ -0,0 +1,361 @@
1/*
2 * DMS Tools and Utilities
3 * Copyright (C) 2010 David M. Syzdek <david@syzdek.net>.
4 *
5 * @SYZDEK_LICENSE_HEADER_START@
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * @SYZDEK_LICENSE_HEADER_END@
21 */
22/**
23 * @file src/bindump.c simple utility for quick bitwise operations
24 */
25/*
26 * Simple Build:
27 * gcc -W -Wall -O2 -c bindump.c
28 * gcc -W -Wall -O2 -o bindump bindump.o
29 *
30 * GNU Libtool Build:
31 * libtool --mode=compile gcc -W -Wall -g -O2 -c bindump.c
32 * libtool --mode=link gcc -W -Wall -g -O2 -o bindump bindump.lo
33 *
34 * GNU Libtool Install:
35 * libtool --mode=install install -c bindump /usr/local/bin/bindump
36 *
37 * GNU Libtool Clean:
38 * libtool --mode=clean rm -f bindump.lo bindump
39 */
40#define _SCT_SRC_BINDUMP_C 1
41
42///////////////
43// //
44// Headers //
45// //
46///////////////
47
48#ifdef HAVE_CONFIG_H
49#include <config.h>
50#endif
51
52#include <stdio.h>
53#include <inttypes.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57#include <getopt.h>
58#include <sys/types.h>
59#include <sys/uio.h>
60#include <fcntl.h>
61
62
63///////////////////
64// //
65// i18l Support //
66// //
67///////////////////
68
69#ifdef HAVE_GETTEXT
70# include <gettext.h>
71# include <libintl.h>
72# define _(String) gettext (String)
73# define gettext_noop(String) String
74# define N_(String) gettext_noop (String)
75#else
76# define _(String) (String)
77# define N_(String) String
78# define textdomain(Domain)
79# define bindtextdomain(Package, Directory)
80#endif
81
82
83///////////////////
84// //
85// Definitions //
86// //
87///////////////////
88
89#ifndef PROGRAM_NAME
90#define PROGRAM_NAME "bindump"
91#endif
92#ifndef PACKAGE_BUGREPORT
93#define PACKAGE_BUGREPORT "david@syzdek.net"
94#endif
95#ifndef PACKAGE_COPYRIGHT
96#define PACKAGE_COPYRIGHT ""
97#endif
98#ifndef PACKAGE_NAME
99#define PACKAGE_NAME ""
100#endif
101#ifndef PACKAGE_VERSION
102#define PACKAGE_VERSION ""
103#endif
104
105#ifndef PARAMS
106#define PARAMS(protos) protos
107#endif
108
109
110//////////////////
111// //
112// Prototypes //
113// //
114//////////////////
115
116// main statement
117int main(int argc, char * argv[]);
118
119//displays usage information
120void my_usage();
121
122// displays version information
123void my_version(void);
124
125// displays data in binary notation
126char * my_byte2str(uint8_t data, char * buff);
127
128
129//////////////////
130// //
131// Prototypes //
132// //
133//////////////////
134
135/// main statement
136/// @param[in] argc number of arguments
137/// @param[in] argv array of arguments
138int main(int argc, char * argv[])
139{
140 int c;
141 int opt_index;
142 int fd;
143 char buff[9];
144 size_t offset;
145 size_t s;
146 size_t pos;
147 size_t len;
148 ssize_t code;
149 uint8_t data;
150 uint32_t verbose;
151 const char * file;
152
153 // getopt options
154 static char short_opt[] = "hl:o:vV";
155 static struct option long_opt[] =
156 {
157 {"help", no_argument, 0, 'h'},
158 {"verbose", no_argument, 0, 'v'},
159 {"version", no_argument, 0, 'V'},
160 {NULL, 0, 0, 0 }
161 };
162
163 len = 0;
164 offset = 0;
165 verbose = 0;
166 file = "-";
167
168 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
169 {
170 switch(c)
171 {
172 case -1: /* no more arguments */
173 case 0: /* long options toggles */
174 break;
175 case 'h':
176 my_usage();
177 return(0);
178 case 'l':
179 len = strtoul(optarg, NULL, 0);
180 break;
181 case 'o':
182 offset = strtoul(optarg, NULL, 0);
183 break;
184 case 'V':
185 my_version();
186 return(0);
187 case 'v':
188 verbose++;
189 break;
190 case '?':
191 fprintf(stderr, _("Try `%s --help' for more information.\n"), PROGRAM_NAME);
192 return(1);
193 default:
194 fprintf(stderr, _("%s: unrecognized option `--%c'\n"
195 "Try `%s --help' for more information.\n"
196 ), PROGRAM_NAME, c, PROGRAM_NAME
197 );
198 return(1);
199 };
200 };
201
202 // determines file to process (or STDIN)
203 if ((optind+1) == argc)
204 file = argv[optind];
205 else if (optind == argc)
206 file = "-";
207 else
208 {
209 fprintf(stderr, _("%s: missing required argument\n"
210 "Try `%s --help' for more information.\n"
211 ), PROGRAM_NAME, PROGRAM_NAME
212 );
213 return(1);
214 };
215
216 // show them who we are
217 if (verbose > 1)
218 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION);
219
220 // open file for reading or set to STDIN
221 if (!(strcmp(file, "-")))
222 {
223 if (verbose > 2)
224 printf("using stdin...\n");
225 fd = STDIN_FILENO;
226 } else {
227 if (verbose > 2)
228 printf("opening %s...\n", file);
229 if ((fd = open(file, O_RDONLY)) == -1)
230 {
231 perror(PROGRAM_NAME ": open()");
232 return(1);
233 };
234 };
235
236 // mark the starting position
237 pos = 0;
238
239 // move to the specified offset
240 if (fd != STDIN_FILENO)
241 {
242 if ((verbose > 2) && (offset))
243 printf("offsetting by %zi bytes...\n", offset);
244 if ((lseek(fd, (off_t)offset, SEEK_SET) == -1))
245 {
246 perror(PROGRAM_NAME ": lseek()");
247 if (verbose)
248 printf("closing file...\n");
249 close(fd);
250 return(1);
251 };
252 pos += offset;
253 } else if (offset) {
254 fprintf(stderr, PROGRAM_NAME ": unable to specify an offset with STDIN\n");
255 return(1);
256 };
257
258 // fill in white space so the offset markings align with the position in the file
259 if (verbose > 2)
260 printf("reading data...\n");
261 printf("offset 00 01 02 03 04 05 06 07 \n");
262 if (pos % 8)
263 {
264 printf("0%04zo0:", (pos/8));
265 for(s = 0; s < (pos % 8); s++)
266 printf(" ");
267 };
268
269 // read data from file handle
270 while((code = read(fd, &data, 1)) > 0)
271 {
272 if ((pos % 8) == 0)
273 printf("0%04zo0:", (pos/8));
274 printf(" %s", my_byte2str(data, buff));
275 pos += code;
276 if (!(pos % 8))
277 printf("\n");
278 if ( ((pos-offset) >= len) && (len))
279 break;
280 if ( (!(pos % 8)) && (!(pos % (8 * 23))) )
281 printf("offset 00 01 02 03 04 05 06 07 \n");
282 };
283 if (pos % 8)
284 printf("\n");
285 if (code == -1)
286 {
287 perror(PROGRAM_NAME ": read()");
288 if (verbose > 2)
289 printf("closing file...\n");
290 if (verbose > 0)
291 printf("read %zu bytes\n", (pos-offset));
292 close(fd);
293 return(1);
294 };
295
296 // close file and finish up
297 if (fd != STDIN_FILENO)
298 {
299 if (verbose > 2)
300 printf("closing file...\n");
301 close(fd);
302 };
303 if (verbose > 0)
304 printf("read %zu bytes\n", (pos-offset));
305 printf("\n");
306
307 return(0);
308}
309
310
311/// displays usage information
312void my_usage()
313{
314 // TRANSLATORS: The following strings provide usage for command. These
315 // strings are displayed if the program is passed `--help' on the command
316 // line. The two strings referenced are: PROGRAM_NAME, and
317 // PACKAGE_BUGREPORT
318 printf(_("Usage: %s [options] file\n"
319 " -h, --help print this help and exit\n"
320 " -l bytes length of data to display\n"
321 " -o bytes offset to start reading data\n"
322 " -V, --version print verbose messages\n"
323 " -v, --verbose print version number and exit\n"
324 "\n"
325 "Report bugs to <%s>.\n"
326 ), PROGRAM_NAME, PACKAGE_BUGREPORT
327 );
328 return;
329}
330
331
332/// displays version information
333void my_version(void)
334{
335 // TRANSLATORS: The following strings provide version and copyright
336 // information if the program is passed --version on the command line.
337 // The three strings referenced are: PROGRAM_NAME, PACKAGE_NAME,
338 // PACKAGE_VERSION.
339 printf(_("%s (%s) %s\n"
340 "Written by David M. Syzdek.\n"
341 "\n"
342 "%s\n"
343 "This is free software; see the source for copying conditions. There is NO\n"
344 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
345 ), PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_COPYRIGHT
346 );
347 return;
348}
349
350
351// displays a byte in binary notation
352char * my_byte2str(uint8_t data, char * buff)
353{
354 uint32_t b;
355 for(b = 0; b < 8; b++)
356 buff[b] = (data & (0x01 << b)) ? '1' : '0';
357 buff[b] = '\0';
358 return(buff);
359}
360
361// end of source file
diff --git a/src/bindump.mak b/src/bindump.mak
new file mode 100644
index 0000000..3bba54c
--- /dev/null
+++ b/src/bindump.mak
@@ -0,0 +1,7 @@
1bindump: Makefile bindump.c bindump.mak
2 $(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) -c bindump.c
3 $(LIBTOOL) --mode=link --tag=CC $(CC) $(CFLAGS) -o bindump bindump.lo
4
5bindump-clean:
6 $(LIBTOOL) --mode=clean rm -f bindump.lo bindump
7