Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

dump.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdarg.h>
00003 
00004 #include "srec.h"
00005 
00006 void
00007 fatal (char *fmt, ...)
00008 {
00009     va_list arglist;
00010     va_start(arglist, fmt);
00011     vfprintf(stderr, fmt, arglist);
00012     va_end(arglist);
00013     exit(1);
00014 }
00015 
00016 int
00017 main (int argc, char **argv)
00018 {
00019     FILE *file;
00020     char buf[256];
00021     int line = 0;
00022     srec_t srec;
00023 
00024     if (argc != 2) 
00025         fatal("usage: %s filename\n", argv[0]);
00026 
00027     if (!(file = fopen(argv[1], "r")))
00028         fatal("%s: couldn't open\n", argv[1]);
00029 
00030     while (fgets(buf, sizeof(buf), file)) {
00031         int error;
00032         line++;
00033         if ((error = srec_decode(&srec, buf)) < 0) {
00034             if (error != S_INVALID_CKSUM) {
00035                 fatal("%s: %s on line %d\n",
00036                       argv[1], srec_strerror(error), line);
00037             }
00038         }
00039         if (srec.type == 0) {
00040             srec.data[srec.count] = '\0';
00041             printf("S0: %s\n", srec.data);
00042         }
00043     }
00044 }
00045 
00046 
00047     

Generated on Fri Feb 25 08:02:40 2005 for brickos by  doxygen 1.3.9.1