5 static struct option longopts[] = {
6 {"arithmetic", no_argument, NULL, 'a'},
7 {"logical", no_argument, NULL, 'l'},
8 {"help", no_argument, NULL, 'h'},
12 int main(int argc, char *argv[])
17 const char *usage = "Usage: %s [-alh] WORD\n";
20 while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) {
26 fprintf(stdout, usage, argv[0]);
29 fprintf(stderr, usage, argv[0]);
34 if(argv[optind] == NULL) {
35 fprintf(stderr, usage, argv[0]);
38 if(*argv[optind] == '-' || strlen(argv[optind]) > 4) {
39 setcerr(116, argv[optind]); /* out of hex range */
42 w = (WORD)strtol(argv[optind], &check, 16);
44 setcerr(115, argv[optind]); /* not hex */
47 fprintf(stderr, "Dumpword Error - %d: %s\n", cerrno, cerrmsg);
50 if(logicalmode == true) {
51 fprintf(stdout, "%4s: %6d = #%04X = %s\n", argv[optind], w, w, word2bit(w));
53 fprintf(stdout, "%4s: %6d = #%04X = %s\n", argv[optind], (short)w, w, word2bit(w));