예제 #1
0
파일: mullib.cpp 프로젝트: serpis/uoc
static void stat(int offset, int length, ml_art **art)
{
    const char *end;
    const char *p = file_map("files/art.mul", &end);

    assert(offset >= 0);
    assert(length >= 0);
    assert(p + offset + length <= end);

    // do stuff...
    parse_stat(p + offset, p + offset + length, art);

    file_unmap(p, end);
}
예제 #2
0
/** Parse statement block.
 *
 * @param parse		Parser object.
 * @return		New syntax tree node.
 */
static stree_block_t *parse_block(parse_t *parse)
{
	stree_block_t *block;
	stree_stat_t *stat;

	block = stree_block_new();
	list_init(&block->stats);

	/* Avoid peeking if there is an error condition. */
	if (parse_is_error(parse))
		return block;

	while (terminates_block(lcur_lc(parse)) != b_true &&
	    !parse_is_error(parse)) {

		stat = parse_stat(parse);
		list_append(&block->stats, stat);
	}

	return block;
}
예제 #3
0
파일: gmcpubar.c 프로젝트: vmj/gmbar
static int
get_stat(buffer* stat,
         const char* field,
         unsigned int *kern,
         unsigned int *user,
         unsigned int *nice,
         unsigned int *idle)
{
        int err = 0;

        *kern = *user = *nice = *idle = 0;

        /* reuse all the space */
        stat->len = 0;

        err = readfile("/proc/stat", &stat->buf, &stat->len, &stat->max);
        if (err)
        {
                return err;
        }

        err = parse_stat(stat->buf, stat->len, field, kern, user, nice, idle);
        return err;
}
예제 #4
0
파일: cpu.c 프로젝트: tijko/dashboard
char *get_thread_count(char *pid)
{
    char *threads = parse_stat(pid, THREADS);

    return threads;
}
예제 #5
0
파일: cpu.c 프로젝트: tijko/dashboard
char *get_state(char *pid)
{
    char *state = parse_stat(pid, STATE);

    return state;
}
예제 #6
0
/** Run in interactive mode.
 *
 * Repeatedly read in statements from the user and execute them.
 */
void imode_run(void)
{
	input_t *input;
	lex_t lex;
	parse_t parse;
	stree_program_t *program;
	stree_stat_t *stat;
	stree_proc_t *proc;
	stree_fun_t *fun;
	stree_symbol_t *fun_sym;
	stype_t stype;
	stype_block_vr_t *block_vr;
	list_node_t *bvr_n;
	rdata_item_t *rexpr;
	rdata_item_t *rexpr_vi;

	run_t run;
	run_proc_ar_t *proc_ar;

	bool_t quit_im;

	/* Create an empty program. */
	program = stree_program_new();
	program->module = stree_module_new();

	/* Declare builtin symbols. */
	builtin_declare(program);

	/* Process the library. */
	if (program_lib_process(program) != EOK)
		exit(1);

	/* Resolve ancestry. */
	ancr_module_process(program, program->module);

	/* Bind internal interpreter references to symbols. */
	builtin_bind(program->builtin);

	/* Resolve ancestry. */
	ancr_module_process(program, program->module);

	/* Construct typing context. */
	stype.program = program;
	stype.proc_vr = stype_proc_vr_new();
	list_init(&stype.proc_vr->block_vr);
	stype.current_csi = NULL;
	proc = stree_proc_new();

	fun = stree_fun_new();
	fun_sym = stree_symbol_new(sc_fun);
	fun_sym->u.fun = fun;
	fun->name = stree_ident_new();
	fun->name->sid = strtab_get_sid("$imode");
	fun->sig = stree_fun_sig_new();

	stype.proc_vr->proc = proc;
	fun->symbol = fun_sym;
	proc->outer_symbol = fun_sym;

	/* Create block visit record. */
	block_vr = stype_block_vr_new();
	intmap_init(&block_vr->vdecls);

	/* Add block visit record to the stack. */
	list_append(&stype.proc_vr->block_vr, block_vr);

	/* Construct run context. */
	run_gdata_init(&run);

	run.thread_ar = run_thread_ar_new();
	list_init(&run.thread_ar->proc_ar);
	run_proc_ar_create(&run, run.gdata, proc, &proc_ar);
	list_append(&run.thread_ar->proc_ar, proc_ar);

	printf("SBI interactive mode. ");
	os_input_disp_help();

	quit_im = b_false;
	while (quit_im != b_true) {
		parse.error = b_false;
		stype.error = b_false;
		run.thread_ar->exc_payload = NULL;
		run.thread_ar->bo_mode = bm_none;

		input_new_interactive(&input);

		/* Parse input. */
		lex_init(&lex, input);
		parse_init(&parse, program, &lex);

		if (lcur_lc(&parse) == lc_eof)
			break;

		stat = parse_stat(&parse);

		if (parse.error != b_false)
			continue;

		/* Type statement. */
		stype_stat(&stype, stat, b_true);

		if (stype.error != b_false)
			continue;

		/* Run statement. */
		run_init(&run);
		run.program = program;
		run_stat(&run, stat, &rexpr);

		/* Check for unhandled exceptions. */
		run_exc_check_unhandled(&run);

		if (rexpr != NULL) {
			/* Convert expression result to value item. */
			run_cvt_value_item(&run, rexpr, &rexpr_vi);
			rdata_item_destroy(rexpr);

			/* Check for unhandled exceptions. */
			run_exc_check_unhandled(&run);
		} else {
			rexpr_vi = NULL;
		}

		/*
		 * rexpr_vi can be NULL if either repxr was null or
		 * if the conversion to value item raised an exception.
		 */
		if (rexpr_vi != NULL) {
			assert(rexpr_vi->ic == ic_value);

			/* Print result. */
			printf("Result: ");
			rdata_value_print(rexpr_vi->u.value);
			printf("\n");

			rdata_item_destroy(rexpr_vi);
		}
	}

	run_proc_ar_destroy(&run, proc_ar);

	/* Remove block visit record from the stack, */
	bvr_n = list_last(&stype.proc_vr->block_vr);
	assert(list_node_data(bvr_n, stype_block_vr_t *) == block_vr);
	list_remove(&stype.proc_vr->block_vr, bvr_n);

	printf("\nBye!\n");
}