void trace(_Stream& _stream) const { _stream << (LPCTSTR)shift(1) << (LPCTSTR)to_str(m_dwMetaData) << std::endl; _stream << (LPCTSTR)shift(1) << _T("size = ") << m_size << std::endl; output_hex(_stream,m_pdata,m_size,1); _stream << std::endl; }
void sys_conf_init(void *init_parameters) { confword_t * words = (confword_t*) init_parameters; if (verbose_boot) { output_string("* reading configuration from 0x", 2); output_hex(words, 2); output_char(',', 2); } if (*words < 0x10000) { if (verbose_boot) output_string(" old style: only place info found.\n", 2); mgconf_layout_data = init_parameters; } else { if (verbose_boot) output_string(" new style:\n", 2); // new style microgrid, configuration blocks // are available, see MGSystem.cpp for values while (*words != 0) { unsigned tag = *words >> 16; unsigned size = *words & 0xffff; confword_t *data = words + 1; if (verbose_boot) { output_string(" at 0x", 2); output_hex(words, 2); output_string(", tag ", 2); output_uint(tag, 2); output_string(", ", 2); output_int(size, 2); output_string(" words: ", 2); } if (tag > (sizeof(parsers) / sizeof(parsers[0])) || !parsers[tag]) { if (verbose_boot) output_string("unknown tag\n", 2); } else parsers[tag](data); words += size + 1; } } }
void sys_heap_init(void) { if (!verbose_boot) return; output_string("* heap at 0x", 2); output_hex(brk_p, 2); output_char(',', 2); output_char(' ', 2); output_uint(HEAP_SIZE, 2); output_string(" bytes.\n", 2); }
int main(int argc, char **argv) { int32 length; int c, block = 1, last_type = ASCII; ifp = stdin; ofp = stdout; print_banner(); if (argc > 3) usage(); /* possibly open input & output files */ if (argc >= 2) { ifp = fopen(argv[1], "r"); if (!ifp) { fprintf(stderr, "error: cannot open %s for reading\n", argv[1]); exit(1); } } if (argc == 3) { ofp = fopen(argv[2], "w"); if (!ofp) { fprintf(stderr, "error: cannot open %s for writing\n", argv[2]); exit(1); } } #ifdef _MSDOS /* As we are processing a PFB (binary) input */ /* file, we must set its file mode to binary. */ _setmode(_fileno(ifp), _O_BINARY); #endif /* main loop through blocks */ for (;;) { c = fgetc(ifp); if (c == EOF) { break; } if (c != MARKER) { fprintf(stderr, "error: missing marker (128) at beginning of block %d", block); exit(1); } switch (c = fgetc(ifp)) { case ASCII: if (last_type != ASCII) fputc('\n', ofp); last_type = ASCII; for (length = read_length(); length > 0; length--) if ((c = fgetc(ifp)) == '\r') fputc('\n', ofp); else fputc(c, ofp); break; case BINARY: last_type = BINARY; for (length = read_length(); length > 0; length--) output_hex(fgetc(ifp)); break; case DONE: /* nothing to be done --- will exit at top of loop with EOF */ break; default: fprintf(stderr, "error: bad block type %d in block %d\n", c, block); break; } block++; } fclose(ifp); fclose(ofp); syncfs("/"); return 0; }
int main (int argc, char* argv[]) { int next_option; struct arcfilt filt; struct dataset ds; int r; int verbose = 0; char ** nlist; int nn; int format, do_tar, do_gzip; /* A string listing valid short options letters. */ const char* const short_options = "ho:r:s:e:f:tzv"; /* An array describing valid long options. */ const struct option long_options[] = { { "help", 0, NULL, 'h' }, { "output", 1, NULL, 'o' }, { "register", 1, NULL, 'r' }, { "start", 1, NULL, 's' }, { "end", 1, NULL, 'e' }, { "format", 1, NULL, 'f' }, { "tar", 0, NULL, 't' }, { "gzip", 0, NULL, 'z' }, { "verbose", 0, NULL, 'v' }, { NULL, 0, NULL, 0 } /* Required at end of array. */ }; /* The name of the file to receive program output, or NULL for standard output. */ const char* output_filename = NULL; /* Remember the name of the program, to incorporate in messages. The name is stored in argv[0]. */ program_name = argv[0]; filt.use_utc = 0; filt.t1[0] = 0; filt.t1[1] = 0; filt.t2[0] = 0 - 1; /* Max uint32_t */ filt.t2[1] = 0; if (argc > 0) nlist = malloc (argc * sizeof (char *)); else nlist = NULL; nn = 0; format = OUTFORMAT_DIRFILE; do_tar = 1; do_gzip = 1; do { next_option = getopt_long (argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': /* -h or --help */ /* User has requested usage information. Print it to standard output, and exit with exit code zero (normal termination). */ print_usage (stdout, 0); case 'o': /* -o or --output */ /* This option takes an argument, the name of the output file. */ output_filename = optarg; break; case 's': /* -s or --start */ /* This option takes an argument, the starting UTC time. */ r = txt2utc (optarg, filt.t1); filt.use_utc = 1; if (r != 0) { printf ("could not parse UTC starting time!"); return -1; } break; case 'e': /* -e or --end */ /* This option takes an argument, the ending UTC time. */ r = txt2utc (optarg, filt.t2); filt.use_utc = 1; if (r != 0) { printf ("could not parse UTC ending time!"); return -1; } break; case 'r': /* -r or --register */ /* This option takes an argument, the register specification. */ /* It can be used multiple times. */ nlist[nn] = optarg; nn++; break; case 't': /* -t or --tar */ do_tar = 1; break; case 'z': /* -z or --gzip */ do_gzip = 1; break; case 'f': /* -f or --format */ if (!strcasecmp (optarg, "dir") || !strcasecmp (optarg, "dirfile")) format = OUTFORMAT_DIRFILE; else if (!strcasecmp (optarg, "txt") || !strcasecmp (optarg, "text")) format = OUTFORMAT_TXT; else if (!strcasecmp (optarg, "hex") || !strcasecmp (optarg, "dump")) format = OUTFORMAT_HEX; else { printf ("Unrecognized format type %s.\n", optarg); return -1; } break; case 'v': /* -v or --verbose */ verbose = 1; break; case '?': /* The user specified an invalid option. */ /* Print usage information to standard error, and exit with exit code one (indicating abnormal termination). */ print_usage (stderr, 1); case -1: /* Done with options. */ break; default: /* Something else: unexpected. */ abort (); } } while (next_option != -1); /* Done with options. OPTIND points to first non-option argument. */ if (nn>0) create_namelist (nn, nlist, &(filt.nl)); else { filt.nl.n = 0; filt.nl.s = 0; } if (argc > 0) free (nlist); for (int i = optind; i < argc; ++i) { char * use_output_fname; filt.fname = argv[i]; DEBUG ("Number of register name specifications = %d.\n", filt.nl.n); DEBUG ("Calling readarc.\n"); r = readarc (&filt, &ds); if (r != 0) { free_namelist (&(filt.nl)); return r; } DEBUG ("Returned %d.\n", r); use_output_fname = output_filename; if (use_output_fname == NULL) guess_output_filename (filt.fname, &use_output_fname, format, do_tar, do_gzip); switch (format) { case OUTFORMAT_TXT: r = output_txt (&ds); break; case OUTFORMAT_HEX: r = output_hex (&ds); break; case OUTFORMAT_DIRFILE: if (!do_tar) r = output_dirball (use_output_fname, &ds, 0); else if (!do_gzip) r = output_dirball (use_output_fname, &ds, 1); else r = output_dirball (use_output_fname, &ds, 2); break; default: printf ("Unknown output type code %d.\n", format); } if ((use_output_fname != NULL) && (use_output_fname != output_filename)) free (use_output_fname); free_dataset (&ds); } free_namelist (&(filt.nl)); return 0; }