Ejemplo n.º 1
0
void simple_menu_select_game::inkey_select(const event *menu_event)
{
	const game_driver *driver = (const game_driver *)menu_event->itemref;

	// special case for configure inputs
	if ((FPTR)driver == 1)
		menu::stack_push<menu_game_options>(ui(), container());
	// anything else is a driver
	else
	{
		// audit the game first to see if we're going to work
		driver_enumerator enumerator(machine().options(), *driver);
		enumerator.next();
		media_auditor auditor(enumerator);
		media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST);

		// if everything looks good, schedule the new driver
		if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE || summary == media_auditor::NONE_NEEDED)
		{
			mame_machine_manager::instance()->schedule_new_driver(*driver);
			machine().schedule_hard_reset();
			stack_reset();
		}

		// otherwise, display an error
		else
		{
			reset(reset_options::REMEMBER_REF);
			m_error = true;
		}
	}
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
  char *buf, line[BUFSIZ + 1];

  if (argc > 1 && strcmp(argv[1], "-v") == 0) {
    fprintf(stderr, "::Stack dumps enabled::\n");
    verbose = 2;
  }

  stackptr = &opstack[0]; /* initialize stack */

  /* If stdin has data, hit it and quit it */
  if (!isatty(fileno(stdin))) {
    fgets(line, BUFSIZ, stdin);
    parse_expression(line);
    freopen(ctermid(NULL), "r", stdin);
    return 0;
  }

  /* going interactive. fire up readline */
  using_history();

  while ((buf = readline("> ")) != NULL) {
    add_history(buf);
    strcpy(line, buf);
    parse_expression(line);
    stack_reset();
    free(buf);
  }
  putchar('\n');

  clear_history();

  return 0;
}
Ejemplo n.º 3
0
int powaur_crawl(alpm_list_t *targets)
{
    int ret = 0;
    char cwd[PATH_MAX];
    if (!getcwd(cwd, PATH_MAX)) {
        return error(PW_ERR_GETCWD);
    }

    if (chdir(powaur_dir)) {
        return error(PW_ERR_CHDIR, powaur_dir);
    }

    struct pw_hashdb *hashdb = build_hashdb();
    if (!hashdb) {
        pw_fprintf(PW_LOG_ERROR, stderr, "Unable to build hash database!\n");
        ret = -1;
    }

    alpm_list_t *i, *target_pkgs;
    struct graph *graph;
    struct stack *topost = stack_new(sizeof(int));
    int have_cycles;
    for (i = targets; i; i = i->next) {
        stack_reset(topost);
        graph = NULL;
        target_pkgs = alpm_list_add(NULL, i->data);
        build_dep_graph(&graph, hashdb, target_pkgs, RESOLVE_THOROUGH);
        if (have_cycles) {
            printf("Cyclic dependencies for package \"%s\"\n", i->data);
        }

        graph_toposort(graph, topost);
        if (stack_empty(topost)) {
            printf("Package \"%s\" has no dependencies.\n", i->data);
        } else {
            printf("\n");
            pw_printf(PW_LOG_INFO, "\"%s\" topological order: ", i->data);
            print_topo_order(graph, topost);
        }

        graph_free(graph);
        alpm_list_free(target_pkgs);
    }

    stack_free(topost);
    hashdb_free(hashdb);

    if (chdir(cwd)) {
        return error(PW_ERR_RESTORECWD);
    }
    return ret;
}
Ejemplo n.º 4
0
static void jq_reset(jq_state *jq) {
  while (stack_restore(jq)) {}

  assert(jq->stk_top == 0);
  assert(jq->fork_top == 0);
  assert(jq->curr_frame == 0);
  stack_reset(&jq->stk);

  if (jv_get_kind(jq->path) != JV_KIND_INVALID)
    jv_free(jq->path);
  jq->path = jv_null();
  jq->subexp_nest = 0;
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {

    char buf[256];
    regex_t regex_value, regex_operation;
    regcomp(&regex_value, "[0-9]+\\.?[0-9]*", REG_EXTENDED | REG_NOSUB);
    regcomp(&regex_operation, "[\\+\\-\\*\\/\\^]", REG_EXTENDED | REG_NOSUB);

    while(1) {
        stack_reset();
        putchar('>');
        fgets(buf, 256, stdin);

        for(char* token = strtok(buf, " "); token != NULL; token = strtok(NULL, " ")) {
            if(regexec(&regex_value, token, 0, NULL, 0) == 0) {
                stack_push(strtod(token, NULL));
            } else if(regexec(&regex_operation, token, 0, NULL, 0) == 0) {
                double rhs = stack_pop();
                double lhs = stack_pop();
                switch(token[0]) {
                    case '+': stack_push(lhs+rhs); break;
                    case '-': stack_push(lhs-rhs); break;
                    case '*': stack_push(lhs*rhs); break;
                    case '/': stack_push(lhs/rhs); break;
                    case '^': stack_push(pow(lhs,rhs)); break;
                }
            } else {
                printf("Giving Up: Unrecognised input: %s\n", token);
                stack_reset();
                break;
            }
        }
        if(stack_size() > 0) {
            printf(">> %f\n", stack_pop());
        }
    }
    return 0;
}
Ejemplo n.º 6
0
static char * test_initial_state() {
  stack_reset();
  /* test multiple braces */
  sprintf(msg, "ERROR: %d: init_state: should not be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: init_state: should not be full", __LINE__);
  mu_assert(msg, ! stack_is_full());

  push(1);
  sprintf(msg, "ERROR: %d: init_state: should not be empty", __LINE__);
  mu_assert(msg, ! stack_is_empty());
  sprintf(msg, "ERROR: %d: init_state: should not be full", __LINE__);
  mu_assert(msg, ! stack_is_full());

  return EXIT_SUCCESS;
}
Ejemplo n.º 7
0
static char * test_push_till_full() {
  int i = 0;

  stack_reset();

  for (i = 0; i < MAX_INTSTACK - 1; i++) {
    push(i);
    sprintf(msg, "ERROR: %d: iter %d: push_till_full: should not be full", __LINE__, i);
    mu_assert(msg, ! stack_is_full());
    sprintf(msg, "ERROR: %d: iter %d: push_till_full: should not be full", __LINE__, i);
    mu_assert(msg, ! stack_is_empty());
  }

  push(INT_MAX);

  sprintf(msg, "ERROR: %d: push_till_full: should not be empty", __LINE__);
  mu_assert(msg, ! stack_is_empty());
  sprintf(msg, "ERROR: %d: push_till_full: should be full", __LINE__);
  mu_assert(msg, stack_is_full());

  return EXIT_SUCCESS;
}
Ejemplo n.º 8
0
static char * test_peek() {
  stack_reset();

  // peek should return INT_MIN (with warning) when intstack is empty
  sprintf(msg, "ERROR: %d: peek should return INT_MIN when empty", __LINE__);
  mu_assert(msg, peek() == INT_MIN);
  
  push(55);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);

  push(56);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 56);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 56);

  sprintf(msg, "ERROR: %d: push_till_full: should not be empty", __LINE__);
  mu_assert(msg, ! stack_is_empty());
  sprintf(msg, "ERROR: %d: push_till_full: should not be full", __LINE__);
  mu_assert(msg, ! stack_is_full());

  pop();
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);

  pop();
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == INT_MIN);

  return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
int dp_can_connect_str(str *domain, int rec_level) {
    struct rdata* head;
    struct rdata* l;
    struct naptr_rdata* naptr;
    struct naptr_rdata* next_naptr;
    int	   ret;
    str	   newdomain;
    char   uri[MAX_URI_SIZE];
    struct avp_stack stack;
    int    last_order = -1;
    int    failed = 0;
    int    found_anything = 0;

    str pattern, replacement, result;

    stack_reset(&stack);
    /* If we're in a recursive call, set the domain-replacement */
    if ( rec_level > 0 ) {
	stack_push(&stack, domain_replacement_name.s.s, domain->s);
	stack.succeeded = 0;
    }

    if (rec_level > MAX_DDDS_RECURSIONS) {
    	LM_ERR("too many indirect NAPTRs. Aborting at %.*s.\n", domain->len,
				ZSW(domain->s));
		return(DP_DDDS_RET_DNSERROR);
    }

    LM_INFO("looking up Domain itself: %.*s\n",domain->len, ZSW(domain->s));
    ret = check_rule(domain,"D2P+sip:dom", 11, &stack);

    if (ret == 1) {
	LM_INFO("found a match on domain itself\n");
	stack_to_avp(&stack);
	return(DP_DDDS_RET_POSITIVE);
    } else if (ret == 0) {
	LM_INFO("no match on domain itself.\n");
	stack_reset(&stack);
	/* If we're in a recursive call, set the domain-replacement */
	if ( rec_level > 0 ) {
	    stack_push(&stack, domain_replacement_name.s.s, (char *) domain->s);
	    stack.succeeded = 0;
	}
    } else {
	return(DP_DDDS_RET_DNSERROR);	/* actually: DB error */
    }

    LM_INFO("doing DDDS with %.*s\n",domain->len, ZSW(domain->s));
    head = get_record(domain->s, T_NAPTR, RES_ONLY_TYPE);
    if (head == 0) {
    	LM_NOTICE("no NAPTR record found for %.*s.\n", 
				domain->len, ZSW(domain->s));
    	return(DP_DDDS_RET_NOTFOUND);
    }

    LM_DBG("found the following NAPTRs: \n");
    for (l = head; l; l = l->next) {
	if (l->type != T_NAPTR) {
	    LM_DBG("found non-NAPTR record.\n");
	    continue; /*should never happen*/
	}
	naptr = (struct naptr_rdata*)l->rdata;
	if (naptr == 0) {
		LM_CRIT("null rdata\n");
		continue;
	}
	LM_DBG("order %u, pref %u, flen %u, flags '%.*s', slen %u, "
	    "services '%.*s', rlen %u, regexp '%.*s', repl '%s'\n", 
		naptr->order, naptr->pref,
	    naptr->flags_len, (int)(naptr->flags_len), ZSW(naptr->flags),
	    naptr->services_len,
	    (int)(naptr->services_len), ZSW(naptr->services), naptr->regexp_len,
	    (int)(naptr->regexp_len), ZSW(naptr->regexp),
	    ZSW(naptr->repl)
	    );
    }


    LM_DBG("sorting...\n");
    naptr_sort(&head);

    for (l = head; l; l = l->next) {

	if (l->type != T_NAPTR) continue; /*should never happen*/
	naptr = (struct naptr_rdata*)l->rdata;
	if (naptr == 0) {
		LM_CRIT("null rdata\n");
		continue;
	}

	LM_DBG("considering order %u, pref %u, flen %u, flags '%.*s', slen %u, "
	    "services '%.*s', rlen %u, regexp '%.*s', repl '%s'\n", 
		naptr->order, naptr->pref,
	    naptr->flags_len, (int)(naptr->flags_len), ZSW(naptr->flags),
	    naptr->services_len,
	    (int)(naptr->services_len), ZSW(naptr->services), naptr->regexp_len,
	    (int)(naptr->regexp_len), ZSW(naptr->regexp),
	    ZSW(naptr->repl)
	    );

	/*
	 * New order? then we check whether the had success during the last one.
	 * If yes, we can leave the loop.
	 */
	if (last_order != naptr->order) {
	    	last_order = naptr->order;
		failed = 0;

		if (stack_succeeded(&stack)) {
    		LM_INFO("we don't need to consider further orders "
						"(starting with %d).\n",last_order);
		    break;
		}
	} else if (failed) {
	    LM_INFO("order %d has already failed.\n",last_order);
	    continue;
	}


	/*
	 * NAPTRs we don't care about
	 */
	if (!IS_D2PNAPTR(naptr)) 
	    continue;

	/*
	 * once we've been here, don't return DP_DDDS_RET_NOTFOUND
	 */
	found_anything = 1;

	next_naptr = NULL;
	if (l->next && (l->next->type == T_NAPTR)) {
	     next_naptr = (struct naptr_rdata*)l->next->rdata;
	}

	/*
	 * Non-terminal?
	 */
	if ((naptr->services_len == 7) && !strncasecmp("D2P+SIP", naptr->services,7) && (naptr->flags_len == 0)){
	    LM_INFO("found non-terminal NAPTR\n");

	    /*
	     * This needs to be the only record with this order.
	     */
	    if (next_naptr && (next_naptr->order == naptr->order) && IS_D2PNAPTR(next_naptr)) {
	    	LM_ERR("non-terminal NAPTR needs to be the only one "
					"with this order %.*s.\n", domain->len, ZSW(domain->s));

		return(DP_DDDS_RET_DNSERROR);
	    }

	    newdomain.s = naptr->repl;
	    newdomain.len = strlen(naptr->repl);

	    ret = dp_can_connect_str(&newdomain, rec_level + 1);

	    if (ret == DP_DDDS_RET_POSITIVE)	/* succeeded, we're done. */
		return(ret);

	    if (ret == DP_DDDS_RET_NEGATIVE)	/* found rules, did not work */
		continue;			/* look for more rules */

	    if (ret == DP_DDDS_RET_DNSERROR)	/* errors during lookup */
		return(ret);			/* report them */

	    if (ret == DP_DDDS_RET_NOTFOUND)	/* no entries in linked domain? */
		return(ret);			/* ok, fine. go with that */

	    continue; /* not reached */
	}

	/*
	 * wrong kind of terminal
	 */
	if ((naptr->flags_len != 1) || (tolower(naptr->flags[0]) != 'u')) {
	    LM_ERR("terminal NAPTR needs flag = 'u' and not '%.*s'.\n",
					(int)naptr->flags_len, ZSW(naptr->flags));
		/*
		 * It's not that clear what we should do now: Ignore this records or regard it as failed.
		 * We go with "ignore" for now.
		 */
		continue;
	}

	if (parse_naptr_regexp(&(naptr->regexp[0]), naptr->regexp_len,
			       &pattern, &replacement) < 0) {
		LM_ERR("parsing of NAPTR regexp failed\n");
		continue;
	}
	result.s = &(uri[0]);
	result.len = MAX_URI_SIZE;

	/* Avoid making copies of pattern and replacement */
	pattern.s[pattern.len] = (char)0;
	replacement.s[replacement.len] = (char)0;
	if (reg_replace(pattern.s, replacement.s, domain->s,
			&result) < 0) {
		pattern.s[pattern.len] = '!';
		replacement.s[replacement.len] = '!';
		LM_ERR("regexp replace failed\n");
		continue;
	}
	LM_INFO("resulted in replacement: '%.*s'\n", result.len, ZSW(result.s));
	pattern.s[pattern.len] = '!';
	replacement.s[replacement.len] = '!';

	ret = check_rule(&result,naptr->services,naptr->services_len, &stack);

	if (ret == 1) {
	    LM_INFO("positive return\n");
	} else if (ret == 0) {
	    LM_INFO("check_rule failed.\n");
	    stack_reset(&stack);
	    /* If we're in a recursive call, set the domain-replacement */
	    if ( rec_level > 0 ) {
		stack_push(&stack, domain_replacement_name.s.s, (char *) domain->s);
		stack.succeeded = 0;
	    }
	    failed = 1;
	} else {
	    return(DP_DDDS_RET_DNSERROR);
    	}
    }

    if (stack_succeeded(&stack)) {
        LM_INFO("calling stack_to_avp.\n");
		stack_to_avp(&stack);
		return(DP_DDDS_RET_POSITIVE);
    }

    LM_INFO("returning %d.\n", 
	    (found_anything ? DP_DDDS_RET_NEGATIVE : DP_DDDS_RET_NOTFOUND));
    return(  found_anything ? DP_DDDS_RET_NEGATIVE : DP_DDDS_RET_NOTFOUND );
}
Ejemplo n.º 10
0
static char * test_push_pop() {
  int i;

  stack_reset();

  /* push one, pop one */
  push(INT_MAX);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MAX);
  sprintf(msg, "ERROR: %d: should be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: should pop INT_MIN when empty", __LINE__);
  mu_assert(msg, pop() == INT_MIN);
  sprintf(msg, "ERROR: %d: should pop INT_MIN when empty", __LINE__);
  mu_assert(msg, pop() == INT_MIN);
  

  /* push three, pop two */
  push(INT_MAX);
  push(-1);
  push(44);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 44);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == -1);
  
  /* push three, pop one */
  push(1);
  push(2);
  push(3);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 3);

  /* should have three on intstack - add till full */
  for (i = 30; ! stack_is_full(); i++) {
    push(i);
  }

  sprintf(msg, "ERROR: %d: should be full", __LINE__);
  mu_assert(msg, stack_is_full());

  /* now pop all remaining and test values */
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 36);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 35);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 34);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 33);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 32);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 31);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 30);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 2);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 1);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MAX);
  sprintf(msg, "ERROR: %d: should be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MIN);


  return EXIT_SUCCESS;
}