-static void usage(void)
+static void usage(int status)
{
- fprintf(stderr, "Usage: %s [vrzd] [-p <abs-pic-file>] [-s stack-size] "
- "[-o <output-file>] <elf-file>\n\n"
- " -v : verbose operation\n"
- " -r : force load to RAM\n"
- " -k : enable kernel trace on load (for debug)\n"
- " -z : compress code/data/relocs\n"
- " -d : compress data/relocs\n"
- " -a : use existing symbol references\n"
- " instead of recalculating from\n"
- " relocation info\n"
- " -R reloc-file : read relocations from a separate file\n"
- " -p abs-pic-file : GOT/PIC processing with files\n"
- " -s stacksize : set application stack size\n"
- " -o output-file : output file name\n\n",
- elf2flt_progname);
- fprintf(stderr, "Compiled for " ARCH " architecture\n\n");
- exit(2);
+ fprintf(status ? stderr : stdout,
+ "Usage: %s [vrzd] [-p <abs-pic-file>] [-s stack-size] "
+ "[-o <output-file>] <elf-file>\n\n"
+ " -v : verbose operation\n"
+ " -r : force load to RAM\n"
+ " -k : enable kernel trace on load (for debug)\n"
+ " -z : compress code/data/relocs\n"
+ " -d : compress data/relocs\n"
+ " -a : use existing symbol references\n"
+ " instead of recalculating from\n"
+ " relocation info\n"
+ " -R reloc-file : read relocations from a separate file\n"
+ " -p abs-pic-file : GOT/PIC processing with files\n"
+ " -s stacksize : set application stack size\n"
+ " -o output-file : output file name\n\n"
+ "Compiled for " ARCH " architecture\n\n",
+ elf2flt_progname);
+ exit(status);
}
xmalloc_set_program_name(elf2flt_progname);
if (argc < 2)
- usage();
+ usage(1);
if (sizeof(hdr) != 64)
fatal(
stack = 0x2020;
#endif
- while ((opt = getopt(argc, argv, "avzdrkp:s:o:R:")) != -1) {
+ while ((opt = getopt(argc, argv, "havzdrkp:s:o:R:")) != -1) {
switch (opt) {
case 'v':
verbose++;
case 's':
if (sscanf(optarg, "%i", &stack) != 1) {
fprintf(stderr, "%s invalid stack size %s\n", argv[0], optarg);
- usage();
+ usage(1);
}
break;
case 'R':
rel_file = optarg;
break;
+ case 'h':
+ usage(0);
+ break;
default:
fprintf(stderr, "%s Unknown option\n", argv[0]);
- usage();
+ usage(1);
break;
}
}
void
usage(const char *s)
{
+ FILE *out = s ? stderr : stdout;
if (s)
- fprintf(stderr, "%s\n", s);
- fprintf(stderr, "usage: %s [options] flat-file\n", elf2flt_progname);
- fprintf(stderr, " Allows you to change an existing flat file\n\n");
- fprintf(stderr, " -p : print current settings\n");
- fprintf(stderr, " -P : print relocations\n");
- fprintf(stderr, " -z : compressed flat file\n");
- fprintf(stderr, " -d : compressed data-only flat file\n");
- fprintf(stderr, " -Z : un-compressed flat file\n");
- fprintf(stderr, " -r : ram load\n");
- fprintf(stderr, " -R : do not RAM load\n");
- fprintf(stderr, " -k : kernel traced load (for debug)\n");
- fprintf(stderr, " -K : normal non-kernel traced load\n");
- fprintf(stderr, " -u : place stack in L1 scratchpad memory\n");
- fprintf(stderr, " -U : place stack in normal SDRAM memory\n");
- fprintf(stderr, " -s size : stack size\n");
- fprintf(stderr, " -o file : output-file\n"
- " (default is to modify input file)\n");
- exit(1);
+ fprintf(out, "%s\n", s);
+ fprintf(out,
+ "Usage: %s [options] flat-file\n"
+ " Allows you to change an existing flat file\n\n"
+ " -p : print current settings\n"
+ " -P : print relocations\n"
+ " -z : compressed flat file\n"
+ " -d : compressed data-only flat file\n"
+ " -Z : un-compressed flat file\n"
+ " -r : ram load\n"
+ " -R : do not RAM load\n"
+ " -k : kernel traced load (for debug)\n"
+ " -K : normal non-kernel traced load\n"
+ " -u : place stack in L1 scratchpad memory\n"
+ " -U : place stack in normal SDRAM memory\n"
+ " -s size : stack size\n"
+ " -o file : output-file\n"
+ " (default is to modify input file)\n",
+ elf2flt_progname);
+ exit(s ? 1 : 0);
}
/****************************************************************************/
elf2flt_progname = argv[0];
noargs = 1;
- while ((c = getopt(argc, argv, "pPdzZrRuUkKs:o:")) != EOF) {
+ while ((c = getopt(argc, argv, "hpPdzZrRuUkKs:o:")) != EOF) {
switch (c) {
case 'p': print = 1; break;
case 'P': print_relocs = 1; break;
if (sscanf(optarg, "%i", &stacksize) != 1)
usage("invalid stack size");
break;
+ case 'h':
+ usage(NULL);
+ break;
default:
usage("invalid option");
break;