int losetup_main(int argc, char **argv) { unsigned opt; char *opt_o; unsigned long long offset = 0; opt = getopt32(argc, argv, "do:", &opt_o); argc -= optind; argv += optind; if (opt == 0x3) // -d + -o (illegal) bb_show_usage(); if (opt == 0x1) { // -d /* detach takes exactly one argument */ if (argc != 1) bb_show_usage(); if (!del_loop(argv[0])) return EXIT_SUCCESS; bb_perror_nomsg_and_die(); } if (opt == 0x2) // -o offset = xatoull(opt_o); /* -o or no option */ if (argc == 2) { if (set_loop(&argv[0], argv[1], offset) < 0) bb_perror_nomsg_and_die(); } else if (argc == 1) { char *s = query_loop(argv[0]); if (!s) bb_perror_nomsg_and_die(); printf("%s: %s\n", argv[0], s); if (ENABLE_FEATURE_CLEAN_UP) free(s); } else { char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0"; char c; for (c = '0'; c <= '9'; ++c) { char *s; dev[sizeof(LOOP_NAME"0")-2] = c; s = query_loop(dev); if (s) { printf("%s: %s\n", dev, s); if (ENABLE_FEATURE_CLEAN_UP) free(s); } } } return EXIT_SUCCESS; }
static int pl_break1(atom_t goal) { GET_LD int rc = TRUE; int old_level = LD->break_level; IOSTREAM *inSave = Scurin; IOSTREAM *outSave = Scurout; intptr_t skipSave = debugstatus.skiplevel; int suspSave = debugstatus.suspendTrace; int traceSave; debug_type debugSave; tracemode(FALSE, &traceSave); debugmode(DBG_OFF, &debugSave); Scurin = Sinput; Scurout = Soutput; LD->break_level++; if ( LD->break_level > 0 ) { rc = printMessage(ATOM_informational, PL_FUNCTOR, FUNCTOR_break2, PL_ATOM, ATOM_begin, PL_INT, LD->break_level); } rc = rc && (query_loop(goal, TRUE) == TRUE); if ( LD->break_level > 0 ) { rc = rc && printMessage(ATOM_informational, PL_FUNCTOR, FUNCTOR_break2, PL_ATOM, ATOM_end, PL_INT, LD->break_level); } LD->break_level = old_level; debugstatus.suspendTrace = suspSave; debugstatus.skiplevel = skipSave; tracemode(traceSave, NULL); debugmode(debugSave, NULL); Scurout = outSave; Scurin = inSave; return rc; }
int main(int argc, char** argv) { romaji *object, *hira2kata, *han2zen, *zen2han; char *word = NULL; object = romaji_open(); hira2kata = romaji_open(); han2zen = romaji_open(); zen2han = romaji_open(); romaji_set_verbose(zen2han, 1); while (*++argv) { if (0) ; else if (argv[1] && (!strcmp("--word", *argv) || !strcmp("-w", *argv))) word = *++argv; } if (object && hira2kata && han2zen && zen2han) { int retval = 0; retval = romaji_load(object, DICT_ROMA2HIRA); printf("romaji_load(%s)=%d\n", DICT_ROMA2HIRA, retval); retval = romaji_load(hira2kata, DICT_HIRA2KATA); printf("romaji_load(%s)=%d\n", DICT_HIRA2KATA, retval); retval = romaji_load(han2zen, DICT_HAN2ZEN); printf("romaji_load(%s)=%d\n", DICT_HAN2ZEN, retval); retval = romaji_load(zen2han, DICT_ZEN2HAN); printf("romaji_load(%s)=%d\n", DICT_HAN2ZEN, retval); if (word) query_one(object, hira2kata, han2zen, zen2han, word); else query_loop(object, hira2kata, han2zen, zen2han); } if (han2zen) romaji_close(han2zen); if (hira2kata) romaji_close(hira2kata); if (object) romaji_close(object); return 0; }
int losetup_main (int argc, char **argv) { int offset = 0; /* This will need a "while(getopt()!=-1)" loop when we can have more than one option, but for now we can't. */ switch(getopt(argc,argv, "do:")) { case 'd': /* detach takes exactly one argument */ if(optind+1!=argc) bb_show_usage(); if(!del_loop(argv[optind])) return EXIT_SUCCESS; die_failed: bb_perror_msg_and_die("%s",argv[optind]); case 'o': offset = bb_xparse_number (optarg, NULL); /* Fall through to do the losetup */ case -1: /* losetup takes two argument:, loop_device and file */ if(optind+2==argc) { if(set_loop(&argv[optind], argv[optind + 1], offset)>=0) return EXIT_SUCCESS; else goto die_failed; } if(optind+1==argc) { char *s=query_loop(argv[optind]); if (!s) goto die_failed; printf("%s: %s\n",argv[optind],s); if(ENABLE_FEATURE_CLEAN_UP) free(s); return EXIT_SUCCESS; } break; } bb_show_usage(); return EXIT_FAILURE; }
int losetup_main(int argc, char **argv) { char dev[] = LOOP_NAME"0"; unsigned opt; char *opt_o; char *s; unsigned long long offset = 0; /* max 2 args, all opts are mutually exclusive */ opt_complementary = "?2:d--of:o--df:f-do"; opt = getopt32(argv, "do:f", &opt_o); argc -= optind; argv += optind; if (opt == 0x2) // -o offset = xatoull(opt_o); if (opt == 0x4 && argc) // -f does not take any argument bb_show_usage(); if (opt == 0x1) { // -d /* detach takes exactly one argument */ if (argc != 1) bb_show_usage(); if (del_loop(argv[0])) bb_simple_perror_msg_and_die(argv[0]); return EXIT_SUCCESS; } if (argc == 2) { /* -o or no option */ if (set_loop(&argv[0], argv[1], offset) < 0) bb_simple_perror_msg_and_die(argv[0]); return EXIT_SUCCESS; } if (argc == 1) { /* -o or no option */ s = query_loop(argv[0]); if (!s) bb_simple_perror_msg_and_die(argv[0]); printf("%s: %s\n", argv[0], s); if (ENABLE_FEATURE_CLEAN_UP) free(s); return EXIT_SUCCESS; } /* -o, -f or no option */ while (1) { s = query_loop(dev); if (!s) { if (opt == 0x4) { puts(dev); return EXIT_SUCCESS; } } else { if (opt != 0x4) printf("%s: %s\n", dev, s); if (ENABLE_FEATURE_CLEAN_UP) free(s); } if (++dev[sizeof(dev) - 2] > '9') break; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { #define MAX_RCVBUF 127*1024 #define MIN_RCVBUF 4*1024 int ch, bsize, soc; char *p, *tmp_ptr, *options, *value, delim; const char *result; in_addr_t netaddr, netmask; int on; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEXT" #endif /* ! TEXT_DOMAIN */ (void) textdomain(TEXT_DOMAIN); OMSG.rip_nets[0].n_dst = RIP_DEFAULT; OMSG.rip_nets[0].n_family = RIP_AF_UNSPEC; OMSG.rip_nets[0].n_metric = htonl(HOPCNT_INFINITY); if ((pgmname = argv[0]) == NULL) pgmname = "rtquery"; while ((ch = getopt(argc, argv, "np1w:r:t:a:")) != -1) switch (ch) { case 'n': not_trace = _B_TRUE; nflag = _B_TRUE; break; case 'p': not_trace = _B_TRUE; pflag = _B_TRUE; break; case '1': ripv2 = _B_FALSE; break; case 'w': not_trace = _B_TRUE; wtime = (int)strtoul(optarg, &p, 0); if (*p != '\0' || wtime <= 0 || p == optarg) usage(); break; case 'r': not_trace = _B_TRUE; if (rflag) usage(); rflag = getnet(optarg, &netaddr, &netmask); if (rflag) { OMSG.rip_nets[0].n_dst = htonl(netaddr); OMSG.rip_nets[0].n_family = RIP_AF_INET; OMSG.rip_nets[0].n_mask = htonl(netmask); } else { struct hostent *hp = gethostbyname(optarg); if (hp == NULL) { (void) fprintf(stderr, "%s: %s: %s\n", pgmname, optarg, hstrerror(h_errno)); exit(EXIT_FAILURE); } (void) memcpy(&OMSG.rip_nets[0].n_dst, hp->h_addr, sizeof (OMSG.rip_nets[0].n_dst)); OMSG.rip_nets[0].n_family = RIP_AF_INET; OMSG.rip_nets[0].n_mask = INADDR_BROADCAST; rflag = _B_TRUE; } break; case 't': trace = _B_TRUE; options = optarg; while (*options != '\0') { /* messy complications to make -W -Wall happy */ static char on_str[] = "on"; static char more_str[] = "more"; static char off_str[] = "off"; static char dump_str[] = "dump"; static char *traceopts[] = { #define TRACE_ON 0 on_str, #define TRACE_MORE 1 more_str, #define TRACE_OFF 2 off_str, #define TRACE_DUMP 3 dump_str, 0 }; result = ""; switch (getsubopt(&options, traceopts, &value)) { case TRACE_ON: OMSG.rip_cmd = RIPCMD_TRACEON; if (value == NULL || strlen(value) > MAXPATHLEN) usage(); result = value; break; case TRACE_MORE: if (value != NULL) usage(); OMSG.rip_cmd = RIPCMD_TRACEON; break; case TRACE_OFF: if (value != NULL) usage(); OMSG.rip_cmd = RIPCMD_TRACEOFF; break; case TRACE_DUMP: if (value != NULL) usage(); OMSG.rip_cmd = RIPCMD_TRACEON; result = "dump/../table"; break; default: usage(); } (void) strlcpy((char *)OMSG.rip_tracefile, result, MAXPATHLEN); omsg_len += strlen(result) - sizeof (OMSG.ripun); } break; case 'a': not_trace = _B_TRUE; p = strchr(optarg, '='); if (p == NULL) usage(); *p++ = '\0'; if (0 == strcasecmp("passwd", optarg)) auth_type = RIP_AUTH_PW; else if (0 == strcasecmp("md5_passwd", optarg)) auth_type = RIP_AUTH_MD5; else usage(); if (0 > parse_quote(&p, "|", &delim, passwd, sizeof (passwd))) usage(); if (auth_type == RIP_AUTH_MD5 && delim == '|') { tmp_ptr = p+1; keyid = strtoul(p+1, &p, 0); if (keyid > 255 || *p != '\0' || p == tmp_ptr) usage(); } else if (delim != '\0') { usage(); } break; default: usage(); } argv += optind; argc -= optind; if (not_trace && trace) usage(); if (argc == 0) { argc = 1; argv = default_argv; } soc = socket(PF_INET, SOCK_DGRAM, 0); if (soc < 0) { perror("rtquery: socket"); exit(EXIT_FAILURE); } on = 1; if (setsockopt(soc, IPPROTO_IP, IP_RECVIF, &on, sizeof (on))) perror("rtquery: setsockopt IP_RECVIF"); /* be prepared to receive a lot of routes */ for (bsize = MAX_RCVBUF; ; bsize -= 1024) { if (setsockopt(soc, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof (bsize)) == 0) break; if (bsize <= MIN_RCVBUF) { perror("rtquery: setsockopt SO_RCVBUF"); break; } } if (trace) trace_loop(argv, soc); else query_loop(argv, argc, soc); /* NOTREACHED */ return (0); }