home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / a192_1 / decaof / c / main < prev    next >
Encoding:
Text File  |  1992-11-20  |  2.5 KB  |  129 lines

  1. /*                      
  2.  * main function
  3.  *
  4.  * Andy Duplain, BT Customer Systems, Brighton, UK.  duplain@btcs.bt.co.uk
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include "decaof.h"
  10. #include "cproto.h"
  11. #include "io.h"
  12. #include "misc.h"
  13. #include "error.h"
  14.  
  15. char *ourname;            /* program name */
  16. char **files;            /* list of files to decode */
  17. int nfiles;            /* number of files in **files */
  18.  
  19. short area_contents = 0;    /* print area contents in hex (-a) */
  20. short area_dec = 0;        /* print area declarations (-d) */
  21. short reloc_dir = 0;        /* print relocation directives (-r) */
  22. short debug = 0;        /* print debugging areas (-g) */
  23. short symtab = 0;        /* print symbol table (-s) */
  24. short strtab = 0;        /* print string table (-t) */
  25.  
  26. static int gotarg = 0;        /* non-zero if some flags where entered */
  27.  
  28. static void usage P__((void));
  29.  
  30. int
  31. main(argc, argv)
  32.     int argc;
  33.     char **argv;
  34. {
  35.     ourname = basename(*argv++);
  36.     argc--;
  37.  
  38.     /*
  39.      * parse args (can't use getopt() 'cos not all C libraries have it)
  40.      */
  41.     while(argc) {
  42.         int donext = 0;
  43.         char *arg = *argv;
  44.         if (*arg == '-') {
  45.             char c;
  46.             while (!donext && !isspace(c = *++arg) && c) {
  47.                 switch(c) {
  48.                 case 'b':
  49.                     area_dec++;
  50.                     area_contents = 0;
  51.                     debug = 0;
  52.                     reloc_dir = 0;
  53.                     symtab = 0;
  54.                     strtab = 0;
  55.                     gotarg++;
  56.                     break;
  57.                 case 'a':
  58.                     area_contents++;
  59.                     area_dec++;
  60.                     gotarg++;
  61.                     break;
  62.                 case 'd':
  63.                     area_dec++;
  64.                     gotarg++;
  65.                     break;
  66.                 case 'r':
  67.                     area_dec++;
  68.                     reloc_dir++;
  69.                     gotarg++;
  70.                     break;
  71.                 case 'g':
  72.                     debug++;
  73.                     gotarg++;
  74.                     break;
  75.                 case 's':
  76.                     symtab++;
  77.                     gotarg++;
  78.                     break;
  79.                 case 't':
  80.                     strtab++;
  81.                     gotarg++;
  82.                     break;
  83.                 default:
  84.                     error("unknown option '%c'", c);
  85.                     exit(1);
  86.                 }
  87.             }
  88.             argv++;
  89.             argc--;
  90.         } else
  91.             break;
  92.     }
  93.  
  94.     if (!argc)
  95.         usage();
  96.         
  97.     files = argv;
  98.     nfiles = argc;
  99.  
  100.     if (!gotarg) {
  101.         /* set-up default arguments */
  102.         area_dec++;
  103.         symtab++;
  104.         strtab++;
  105.     }
  106.  
  107.     return(decode());
  108. }
  109.  
  110.  
  111. /*
  112.  * display program usage and exit
  113.  */
  114. static void
  115. usage()
  116. {
  117.     fprintf(stderr, "usage: %s [options] [file ... file]\n",
  118.         ourname);
  119.     fprintf(stderr, "       where options are:\n");
  120.     fprintf(stderr, "       -b print only the area declarations\n");
  121.     fprintf(stderr, "       -a print area contents in hex\n");
  122.     fprintf(stderr, "       -d print area declarations\n");
  123.     fprintf(stderr, "       -r print relocation directives\n");
  124.     fprintf(stderr, "       -g print debugging areas\n");
  125.     fprintf(stderr, "       -s print symbol table\n");
  126.     fprintf(stderr, "       -t print string table\n");
  127.     exit(1);
  128. }
  129.