static int check_term_format(const char *term, const char *orig_term) { int res; char *new_term = xstrfmt("refs/bisect/%s", term); res = check_refname_format(new_term, 0); free(new_term); if (res) return error(_("'%s' is not a valid term"), term); if (one_of(term, "help", "start", "skip", "next", "reset", "visualize", "view", "replay", "log", "run", "terms", NULL)) return error(_("can't use the builtin command '%s' as a term"), term); /* * In theory, nothing prevents swapping completely good and bad, * but this situation could be confusing and hasn't been tested * enough. Forbid it for now. */ if ((strcmp(orig_term, "bad") && one_of(term, "bad", "new", NULL)) || (strcmp(orig_term, "good") && one_of(term, "good", "old", NULL))) return error(_("can't change the meaning of the term '%s'"), term); return 0; }
static int check_and_set_terms(struct bisect_terms *terms, const char *cmd) { int has_term_file = !is_empty_or_missing_file(git_path_bisect_terms()); if (one_of(cmd, "skip", "start", "terms", NULL)) return 0; if (has_term_file && strcmp(cmd, terms->term_bad) && strcmp(cmd, terms->term_good)) return error(_("Invalid command: you're currently in a " "%s/%s bisect"), terms->term_bad, terms->term_good); if (!has_term_file) { if (one_of(cmd, "bad", "good", NULL)) { set_terms(terms, "bad", "good"); return write_terms(terms->term_bad, terms->term_good); } if (one_of(cmd, "new", "old", NULL)) { set_terms(terms, "new", "old"); return write_terms(terms->term_bad, terms->term_good); } } return 0; }
int main() { std::srand( std::time(nullptr) ) ; for( int i=0 ; i < 10 ; ++i ) std::cout << one_of( 1, 2, 3, one_of( 4, "five", one_of( 6, "seven", 8 ) ), 9 ) << ' ' << one_of( "one", one_of(1,2,3) ) << ' ' << one_of( "six", one_of(7,8,9) ) << '\n' ; }
// month := ('0' | '1') digit_09 . // range: 01..12 void month() { Scanner::size_type p0 = scan.pos(); one_of("01"); digit_09(); if (is_digit_09(scan.get())) throw exception(scan, __FUNCTION__); result.month = strtoul(scan.sub(p0, scan.pos()).c_str(), 0, 10); range(result.month, 1, 12); }
// hour := ('0' | '1' | '2' | '3' | '4' | '5') digit_09 . // range: 00..59 void second() { Scanner::size_type p0 = scan.pos(); one_of("012345"); digit_09(); if (is_digit_09(scan.get())) throw exception(scan, __FUNCTION__); result.sec = strtoul(scan.sub(p0, scan.pos()).c_str(), 0, 10); range(result.sec, 0, 59); }
// hour := ('0' | '1' | '2') digit_09 . // range: 00..23 void hour() { Scanner::size_type p0 = scan.pos(); one_of("012"); digit_09(); if (is_digit_09(scan.get())) throw exception(scan, __FUNCTION__); result.hour = strtoul(scan.sub(p0, scan.pos()).c_str(), 0, 10); range(result.hour, 0, 23); }
bool read_sign(InputIterator &first, InputIterator &last, const OutputCallback &callback) { if ((first != last) && one_of(*first, '+', '-')) { callback(*first); ++first; return true; } return false; }
bool read_decimal_point(InputIterator &first, InputIterator &last, const OutputCallback &callback) { if ((first != last) && one_of(*first, '.')) { callback(*first); ++first; return true; } return false; }
bool read_exponent_symbol(InputIterator &first, InputIterator &last, const OutputCallback &callback) { if ((first != last) && one_of(*first, 'e', 'E')) { callback(*first); ++first; return true; } return false; }
int op_3(char **strarray, long N) { long perm; scanf("%li", &perm); int i, j; int inceput; int stare = 0; //0-nu suntem in cuvant 1-suntem in cuvant for (i = 0 ; i < N ; i++) { for (j = 0 ; j <= strlen(strarray[i]) ; j++) { // <= pt ca luam si backslash 0 if (stare == 0) { if ( ! (one_of(&strarray[i][j])) ) { //daca am ajuns la un cuvant; inceput = j; stare = 1; } } else //daca stare==1 { if (one_of(&strarray[i][j])) { stare = 0; rot_word(strarray[i], inceput, j, perm); } } } } printare(strarray, N); return 0; }
static int bisect_terms(struct bisect_terms *terms, const char *option) { if (get_terms(terms)) return error(_("no terms defined")); if (option == NULL) { printf(_("Your current terms are %s for the old state\n" "and %s for the new state.\n"), terms->term_good, terms->term_bad); return 0; } if (one_of(option, "--term-good", "--term-old", NULL)) printf("%s\n", terms->term_good); else if (one_of(option, "--term-bad", "--term-new", NULL)) printf("%s\n", terms->term_bad); else return error(_("invalid argument %s for 'git bisect terms'.\n" "Supported options are: " "--term-good|--term-old and " "--term-bad|--term-new."), option); return 0; }
std::tuple<Float, InputIterator> parse_exponent(InputIterator first, InputIterator last, const char *function) { Float sign = 0; Float value = 0; if ((first != last) && one_of(*first, 'e', 'E')) { ++first; std::tie(sign, first) = parse_sign<Float>(first, last, function); std::tie(value, first) = parse_integer<Float>(first, last, function); } return std::make_tuple(sign * value, first); }
static int bisect_write(const char *state, const char *rev, const struct bisect_terms *terms, int nolog) { struct strbuf tag = STRBUF_INIT; struct object_id oid; struct commit *commit; FILE *fp = NULL; int retval = 0; if (!strcmp(state, terms->term_bad)) { strbuf_addf(&tag, "refs/bisect/%s", state); } else if (one_of(state, terms->term_good, "skip", NULL)) { strbuf_addf(&tag, "refs/bisect/%s-%s", state, rev); } else { retval = error(_("Bad bisect_write argument: %s"), state); goto finish; } if (get_oid(rev, &oid)) { retval = error(_("couldn't get the oid of the rev '%s'"), rev); goto finish; } if (update_ref(NULL, tag.buf, &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR)) { retval = -1; goto finish; } fp = fopen(git_path_bisect_log(), "a"); if (!fp) { retval = error_errno(_("couldn't open the file '%s'"), git_path_bisect_log()); goto finish; } commit = lookup_commit_reference(the_repository, &oid); log_commit(fp, "%s", state, commit); if (!nolog) fprintf(fp, "git bisect %s %s\n", state, rev); finish: if (fp) fclose(fp); strbuf_release(&tag); return retval; }
std::tuple<Float, InputIterator> parse_decimal(InputIterator first, InputIterator last, const char *function) { Float value = 0; if ((first != last) && one_of(*first, '.')) { ++first; assert_non_empty(first, last, function); assert_has_digit(first, last, function); while ((first != last) && std::isdigit(*first)) { value /= 10; value += (*first) - '0'; ++first; } } return std::make_tuple(value / 10, first); }
// // A thing is trying to open us - true on success // static bool open (gh_thing_registration_args *args) { GH_FUNCTION() gh_thing *door = args->me; gh_thing *thing = args->initiator; gh_level *level = door->level; bool ret; vector<string> messages; if (door->is_open) { // // Try to close it // if (gh_thing_gfx_can_touch(door, thing)) { // // Is the thing in the way of closing it? // door->cant_see_past = true; door->is_open = true; door->is_closed = false; door->is_destroyable = false; messages.push_back("the " + door->name + " wont shut; you're in the way"); ret = false; } else { door->cant_see_past = false; door->is_open = false; door->is_closed = true; door->is_destroyable = true; if (thing->is_hero) { thing->play("Door_Slam_001"); } // // Put a new key back onto the level if we had one. // On the *other side* of the door 8) // if (MY_CONTEXT(door)) { gh_thing *key; key = new gh_thing(level, "treasure/keys/1", MY_CONTEXT(door)->key_source, NULL /* template thing */); level->map.push(key); key->decref(GH_THING_REF_FIRST); delete MY_CONTEXT(door); door->context = NULL; } ret = true; } } else { if (!thing->keys) { messages.push_back(thing->name + string(" has no keys; can't open the ") + door->name); ret = false; } else { // // Try to open it // if (!MY_CONTEXT(door)) { door->context = new gh_thing_door(); } MY_CONTEXT(door)->key_source = thing->at; thing->keys--; door->cant_see_past = true; door->is_open = true; door->is_closed = false; door->is_destroyable = false; ret = true; if (thing->is_hero) { thing->play("Door_Latch_002"); } } } // // open/close all other joining doors // list <gh_thing *> other_doors = level->map.find_all_touching_things_in_adjoining_squares(door); list <gh_thing *>::iterator o; for (o = other_doors.begin(); o != other_doors.end(); o++) { gh_thing *other_door = *o; other_door->is_open = door->is_open; other_door->is_closed = door->is_closed; other_door->is_destroyable = door->is_destroyable; other_door->cant_see_past = door->cant_see_past; other_door->get_dir_and_mode(&other_door->dir, &other_door->mode); } if (messages.size()) { if (thing->is_hero) { level->game->new_message(one_of(messages)); } } return (ret); }
static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *n) { int ret; __u8 encoding_sa = 0xff; __u32 window = -1; struct cipher_args cipher = {0}; enum macsec_validation_type validate; bool es = false, scb = false, send_sci = false; int replay_protect = -1; struct sci sci = { 0 }; ret = get_sci_portaddr(&sci, &argc, &argv, true, true); if (ret < 0) { fprintf(stderr, "expected sci\n"); return -1; } if (ret > 0) { if (sci.sci) addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_SCI, &sci.sci, sizeof(sci.sci)); else addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_PORT, &sci.port, sizeof(sci.port)); } while (argc > 0) { if (strcmp(*argv, "cipher") == 0) { NEXT_ARG(); if (cipher.id) duparg("cipher", *argv); if (strcmp(*argv, "default") == 0 || strcmp(*argv, "gcm-aes-128") == 0 || strcmp(*argv, "GCM-AES-128") == 0) cipher.id = MACSEC_DEFAULT_CIPHER_ID; else invarg("expected: default or gcm-aes-128", *argv); } else if (strcmp(*argv, "icvlen") == 0) { NEXT_ARG(); if (cipher.icv_len) duparg("icvlen", *argv); get_icvlen(&cipher.icv_len, *argv); } else if (strcmp(*argv, "encrypt") == 0) { NEXT_ARG(); int i; ret = one_of("encrypt", *argv, values_on_off, ARRAY_SIZE(values_on_off), &i); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCRYPT, i); } else if (strcmp(*argv, "send_sci") == 0) { NEXT_ARG(); int i; ret = one_of("send_sci", *argv, values_on_off, ARRAY_SIZE(values_on_off), &i); if (ret != 0) return ret; send_sci = i; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_INC_SCI, send_sci); } else if (strcmp(*argv, "end_station") == 0) { NEXT_ARG(); int i; ret = one_of("end_station", *argv, values_on_off, ARRAY_SIZE(values_on_off), &i); if (ret != 0) return ret; es = i; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ES, es); } else if (strcmp(*argv, "scb") == 0) { NEXT_ARG(); int i; ret = one_of("scb", *argv, values_on_off, ARRAY_SIZE(values_on_off), &i); if (ret != 0) return ret; scb = i; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb); } else if (strcmp(*argv, "protect") == 0) { NEXT_ARG(); int i; ret = one_of("protect", *argv, values_on_off, ARRAY_SIZE(values_on_off), &i); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i); } else if (strcmp(*argv, "replay") == 0) { NEXT_ARG(); int i; ret = one_of("replay", *argv, values_on_off, ARRAY_SIZE(values_on_off), &i); if (ret != 0) return ret; replay_protect = !!i; } else if (strcmp(*argv, "window") == 0) { NEXT_ARG(); ret = get_u32(&window, *argv, 0); if (ret) invarg("expected replay window size", *argv); } else if (strcmp(*argv, "validate") == 0) { NEXT_ARG(); ret = one_of("validate", *argv, validate_str, ARRAY_SIZE(validate_str), (int *)&validate); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_VALIDATION, validate); } else if (strcmp(*argv, "encodingsa") == 0) { if (encoding_sa != 0xff) duparg2("encodingsa", "encodingsa"); NEXT_ARG(); ret = get_an(&encoding_sa, *argv); if (ret) invarg("expected an { 0..3 }", *argv); } else { fprintf(stderr, "macsec: unknown command \"%s\"?\n", *argv); usage(stderr); return -1; } argv++; argc--; } if (!check_txsc_flags(es, scb, send_sci)) { fprintf(stderr, "invalid combination of send_sci/end_station/scb\n"); return -1; } if (window != -1 && replay_protect == -1) { fprintf(stderr, "replay window set, but replay protection not enabled. did you mean 'replay on window %u'?\n", window); return -1; } else if (window == -1 && replay_protect == 1) { fprintf(stderr, "replay protection enabled, but no window set. did you mean 'replay on window VALUE'?\n"); return -1; } if (cipher.id) addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_CIPHER_SUITE, &cipher.id, sizeof(cipher.id)); if (cipher.icv_len) addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ICV_LEN, &cipher.icv_len, sizeof(cipher.icv_len)); if (replay_protect != -1) { addattr32(n, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window); addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT, replay_protect); } if (encoding_sa != 0xff) { addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCODING_SA, &encoding_sa, sizeof(encoding_sa)); } return 0; }
static int bisect_start(struct bisect_terms *terms, int no_checkout, const char **argv, int argc) { int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0; int flags, pathspec_pos, retval = 0; struct string_list revs = STRING_LIST_INIT_DUP; struct string_list states = STRING_LIST_INIT_DUP; struct strbuf start_head = STRBUF_INIT; struct strbuf bisect_names = STRBUF_INIT; struct object_id head_oid; struct object_id oid; const char *head; if (is_bare_repository()) no_checkout = 1; /* * Check for one bad and then some good revisions */ for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "--")) { has_double_dash = 1; break; } } for (i = 0; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(argv[i], "--")) { break; } else if (!strcmp(arg, "--no-checkout")) { no_checkout = 1; } else if (!strcmp(arg, "--term-good") || !strcmp(arg, "--term-old")) { must_write_terms = 1; free((void *) terms->term_good); terms->term_good = xstrdup(argv[++i]); } else if (skip_prefix(arg, "--term-good=", &arg) || skip_prefix(arg, "--term-old=", &arg)) { must_write_terms = 1; free((void *) terms->term_good); terms->term_good = xstrdup(arg); } else if (!strcmp(arg, "--term-bad") || !strcmp(arg, "--term-new")) { must_write_terms = 1; free((void *) terms->term_bad); terms->term_bad = xstrdup(argv[++i]); } else if (skip_prefix(arg, "--term-bad=", &arg) || skip_prefix(arg, "--term-new=", &arg)) { must_write_terms = 1; free((void *) terms->term_bad); terms->term_bad = xstrdup(arg); } else if (starts_with(arg, "--") && !one_of(arg, "--term-good", "--term-bad", NULL)) { return error(_("unrecognized option: '%s'"), arg); } else { char *commit_id = xstrfmt("%s^{commit}", arg); if (get_oid(commit_id, &oid) && has_double_dash) die(_("'%s' does not appear to be a valid " "revision"), arg); string_list_append(&revs, oid_to_hex(&oid)); free(commit_id); } } pathspec_pos = i; /* * The user ran "git bisect start <sha1> <sha1>", hence did not * explicitly specify the terms, but we are already starting to * set references named with the default terms, and won't be able * to change afterwards. */ if (revs.nr) must_write_terms = 1; for (i = 0; i < revs.nr; i++) { if (bad_seen) { string_list_append(&states, terms->term_good); } else { bad_seen = 1; string_list_append(&states, terms->term_bad); } } /* * Verify HEAD */ head = resolve_ref_unsafe("HEAD", 0, &head_oid, &flags); if (!head) if (get_oid("HEAD", &head_oid)) return error(_("bad HEAD - I need a HEAD")); /* * Check if we are bisecting */ if (!is_empty_or_missing_file(git_path_bisect_start())) { /* Reset to the rev from where we started */ strbuf_read_file(&start_head, git_path_bisect_start(), 0); strbuf_trim(&start_head); if (!no_checkout) { struct argv_array argv = ARGV_ARRAY_INIT; argv_array_pushl(&argv, "checkout", start_head.buf, "--", NULL); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { retval = error(_("checking out '%s' failed." " Try 'git bisect start " "<valid-branch>'."), start_head.buf); goto finish; } } } else { /* Get the rev from where we start. */ if (!get_oid(head, &head_oid) && !starts_with(head, "refs/heads/")) { strbuf_reset(&start_head); strbuf_addstr(&start_head, oid_to_hex(&head_oid)); } else if (!get_oid(head, &head_oid) && skip_prefix(head, "refs/heads/", &head)) { /* * This error message should only be triggered by * cogito usage, and cogito users should understand * it relates to cg-seek. */ if (!is_empty_or_missing_file(git_path_head_name())) return error(_("won't bisect on cg-seek'ed tree")); strbuf_addstr(&start_head, head); } else { return error(_("bad HEAD - strange symbolic ref")); } } /* * Get rid of any old bisect state. */ if (bisect_clean_state()) return -1; /* * In case of mistaken revs or checkout error, or signals received, * "bisect_auto_next" below may exit or misbehave. * We have to trap this to be able to clean up using * "bisect_clean_state". */ /* * Write new start state */ write_file(git_path_bisect_start(), "%s\n", start_head.buf); if (no_checkout) { get_oid(start_head.buf, &oid); if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR)) { retval = -1; goto finish; } } if (pathspec_pos < argc - 1) sq_quote_argv(&bisect_names, argv + pathspec_pos); write_file(git_path_bisect_names(), "%s\n", bisect_names.buf); for (i = 0; i < states.nr; i++) if (bisect_write(states.items[i].string, revs.items[i].string, terms, 1)) { retval = -1; goto finish; } if (must_write_terms && write_terms(terms->term_bad, terms->term_good)) { retval = -1; goto finish; } retval = bisect_append_log_quoted(argv); if (retval) retval = -1; finish: string_list_clear(&revs, 0); string_list_clear(&states, 0); strbuf_release(&start_head); strbuf_release(&bisect_names); return retval; }
constexpr bool one_of(T &&x, U &&y, Args&&... args) { return (x == y) ? true : one_of(x, std::forward<Args>(args)...); }
int op_2(char **strarray, long N) { char *cuvant1 = (char *)malloc(1000 * sizeof(char)); char *cuvant2 = (char *)malloc(1000 * sizeof(char)); if (cuvant1 == NULL || cuvant2 == NULL) return 1; scanf("%s", cuvant1); scanf("%s", cuvant2); int i; char *gasit = NULL; char *buffer = NULL; char *temp = NULL; char *offset = NULL; for (i = 0 ; i < N ; i++) { offset = strarray[i]; do { gasit = strstr(offset, cuvant1); if (gasit != NULL) { if (one_of(gasit-1) && one_of(gasit + strlen(cuvant1))) { //daca e cuvant(incadrat de necifre si nelitere) buffer = (char *)malloc(16000 * sizeof(char)); if (buffer == NULL) return 1; //ia toate caracterele pana la primul gasit memcpy(buffer, strarray[i], gasit-strarray[i]); //baga cuvantu 2 memcpy(buffer + (gasit - strarray[i]), cuvant2, strlen(cuvant2)); //ia toate caracterele dupa cuvantul 1 strcpy(buffer + (gasit-strarray[i]) + strlen(cuvant2), gasit + strlen(cuvant1)); strarray[i] = realloc(buffer, strlen(buffer) * sizeof(char) + 1); if (strarray[i] == NULL) return 1; // reincepem cautarile de la inceput offset = strarray[i]; } else { //daca e gasit dar nu e cuvant if (offset < strarray[i] + strlen(strarray[i])) { offset++; //mergem cu cautarea mai departe } } } } while (gasit); } printare(strarray, N); return 0; }