예제 #1
0
파일: main.cpp 프로젝트: grafin/my_shell
int main( int argc, char** argv) {

    int ch = 0;
    char buf[STR_SIZE] = {};
    char* hisBuf = NULL;
    char str[STR_SIZE] = {};
    char historyArr[HISTORY_SIZE][STR_SIZE] = {};
    int inHistory = 0;
    int cmd = -1;

    List_t* list = new_list( );
    while( true) {
        getcwd( str, STR_SIZE);
        printf( "%s> ", str);

        fgets( buf, STR_SIZE, stdin);
        if( feof( stdin)) {
            printf( "logout\n");
            break;
        }
        if( buf[0] == '\n')
            continue;

        parse_program( list, buf);

        if( (cmd = commands( list->head->next->program)) >= 0) {
            switch( cmd) {
                case logout:
                    goto finish;
                    break;
                case cd:
                    if( chdir( list->head->next->program->arguments[0]) < 0)
                        warn( "Error while changing dir");
                    break;
                case history:
                    if( list->head->next->program->arguments[0][0]) {
                        hisBuf = get_history( historyArr, atoi( list->head->next->program->arguments[0]), inHistory);
                        if( hisBuf) {
                            strcpy( buf, hisBuf);
                            clear_list( list);
                            parse_program( list, buf);
                            printf( "%s\n", buf);
                            execute( list);
                        }
                    } else
                        dump_history( historyArr, inHistory);
                    break;
            }
        } else
            execute( list);
        if( cmd != history)
            inHistory = add_in_history( historyArr, buf, inHistory);
        clear_list( list);
    }

finish:
    destroy_list( list);
    return 0;
}
예제 #2
0
void add_decoration_callback(Sprite *s) {
   Sprite *sprite = (Sprite *) s;
   Room *room = (Room *) sprite->pointer_to_background();
   sprite->remove_from_floor();
   room->add_decoration(sprite,TRUE,FALSE); // FALSE to see text and number pads on rocket wall
   update_slot_ids(FALSE);
   if (return_puzzle_status() != WAITING_TO_VERIFY_SOLUTION) { // conditional added on 051199 since might be waiting on nest and dump will destroy it (and leave a copy)
		dump_history(TRUE); // in case of a crash then rocket wall shows all prior solutions
	};
};
예제 #3
0
파일: solve.c 프로젝트: cygy/pbnsolve
int solve(Puzzle *puz, Solution *sol)
{
    Cell *cell;
    line_t besti, bestj;
    color_t bestc;
    int bestnleft;
    int rc;
    int sprint_clock= 0, plod_clock= PLOD_INIT;

    /* One color puzzles are already solved */
    if (puz->ncolor < 2)
    {
        puz->nsolved= puz->ncells;
        return 1;
    }

    /* Start bookkeeping, if we need it */
    if (mayprobe)
        probe_init(puz,sol);
    else
        bookkeeping_on(puz,sol);

    while (1)
    {
        /* Always start with logical solving */
        if (VA) printf("A: LINE SOLVING\n");
        rc= logic_solve(puz, sol, 0);

        if (rc > 0) return 1;   /* Exit if the puzzle is complete */

        if (rc == 0)
        {
            /* Logical solving has stalled. */

            if (VA)
            {
                printf("A: STUCK - Line solving failed\n");
                print_solution(stdout,puz,sol);
            }

            if (maycontradict)
            {
                /* Try a depth-limited search for logical contradictions */
                if (VA) printf("A: SEARCHING FOR CONTRADICTIONS\n");
                rc= contradict(puz,sol);

                if (rc > 0) return 1; /* puzzle complete - stop */

                if (rc < 0) continue; /* found some - resume logic solving */

                /* otherwise, try something else */
            }

            /* Stop if no guessing is allowed */
            if (!maybacktrack) return 1;

            if (hintlog)
            {
                printf("STARTING SEARCH: EXPLANATION SHUTTING DOWN...\n");
                hintlog= 0;
            }

            /* Shut down the exhaustive search once we start searching */
            if (maylinesolve) mayexhaust= 0;

            /* Turn on caching when we first start searching */
            if (maycache && !cachelines)
            {
                cachelines= 1;
                init_cache(puz);
            }

            if (mayprobe && (!mayguess || sprint_clock <= 0))
            {
                /* Do probing to find best guess to make */
                if (VA) printf("A: PROBING\n");
                rc= probe(puz, sol, &besti, &bestj, &bestc);

                if (rc > 0)
                    return 1; /* Stop if accidentally completed the puzzle */
                if (rc < 0)
                    continue; /* Resume logic solving if found contradiction */

                /* Otherwise, use the guess returned from the probe */
                cell= sol->line[0][besti][bestj];
                if (VA)
                {
                    printf("A: PROBING SELECTED ");
                    print_coord(stdout,puz,cell);
                    printf(" COLOR %d\n",bestc);
                }

                /* If a lot of probes have not been finding contradictions,
                 * consider triggering sprint mode
                 */
                if (mayguess && --plod_clock <= 0)
                {
                    float rate= probe_rate();
                    if (rate >= .12)
                    {
                        /* More than 10% have failed to find contradiction,
                         * so try heuristic searching for a while */
                        bookkeeping_on(puz,sol);
                        sprint_clock= SPRINT_LENGTH;
                        nsprint++;
                        /*printf("STARTING SPRINT - probe rate=%.4f\n",rate);*/
                    }
                    else
                    {
                        /* Success rate of probing is still high. Keep on
                         * trucking. */
                        plod_clock= PLOD_LENGTH;
                        nplod++;
                        /*printf("CONTINUING PLOD - probe rate=%.4f\n", rate);*/
                    }
                }
            }
            else
            {
                /* Old guessing algorithm.  Use heuristics to make a guess */
                cell= pick_a_cell(puz, sol);
                if (cell == NULL)
                    return 0;

                bestc= (*pick_color)(puz,sol,cell);
                if (VA || WC(cell->line[0],cell->line[1]))
                {
                    printf("A: GUESSING SELECTED ");
                    print_coord(stdout,puz,cell);
                    printf(" COLOR %d\n",bestc);
                }

                if (mayprobe && --sprint_clock <= 0)
                {
                    /* If we have reached the end of our sprint, try plodding
                     * again.  */
                    probe_init(puz,sol);
                    plod_clock= PLOD_LENGTH;
                    nplod++;
                    /*printf("ENDING SPRINT\n");*/
                }
            }
            guess_cell(puz, sol, cell, bestc);
            guesses++;
        }
        else
        {
            /* We have hit a contradiction - try backtracking */
            if (VA) printf("A: STUCK ON CONTRADICTION - BACKTRACKING\n");

            guesses++;

            /* Back up to last guess point, and invert that guess */
            if (backtrack(puz,sol))
                /* Nothing to backtrack to - puzzle has no solution */
                return 0;
            if (VB) print_solution(stdout,puz,sol);
            if (VB) dump_history(stdout, puz, VV);
        }
    }
}
예제 #4
0
파일: ui-player.c 프로젝트: angband/angband
/**
 * Write a character dump
 */
void write_character_dump(ang_file *fff)
{
	int i, x, y;

	int a;
	wchar_t c;

	struct store *home = &stores[STORE_HOME];
	struct object **home_list = mem_zalloc(sizeof(struct object *) *
										   z_info->store_inven_max);
	char o_name[80];

	char buf[1024];
	char *p;

	/* Begin dump */
	file_putf(fff, "  [%s Character Dump]\n\n", buildid);

	/* Display player */
	display_player(0);

	/* Dump part of the screen */
	for (y = 1; y < 23; y++) {
		p = buf;
		/* Dump each row */
		for (x = 0; x < 79; x++) {
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		file_putf(fff, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fff, "\n");

	/* Display player */
	display_player(1);

	/* Dump part of the screen */
	for (y = 11; y < 20; y++) {
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++) {
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		file_putf(fff, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fff, "\n");

	/* Dump part of the screen */
	for (y = 11; y < 20; y++) {
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++) {
			/* Get the attr/char */
			(void)(Term_what(x + 40, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		file_putf(fff, "%s\n", buf);
	}

	/* Skip some lines */
	file_putf(fff, "\n\n");


	/* If dead, dump last messages -- Prfnoff */
	if (player->is_dead) {
		i = messages_num();
		if (i > 15) i = 15;
		file_putf(fff, "  [Last Messages]\n\n");
		while (i-- > 0)
		{
			file_putf(fff, "> %s\n", message_str((s16b)i));
		}
		file_putf(fff, "\nKilled by %s.\n\n", player->died_from);
	}


	/* Dump the equipment */
	file_putf(fff, "  [Character Equipment]\n\n");
	for (i = 0; i < player->body.count; i++) {
		struct object *obj = slot_object(player, i);
		if (!obj) continue;

		object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
		file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name);
		object_info_chardump(fff, obj, 5, 72);
	}
	file_putf(fff, "\n\n");

	/* Dump the inventory */
	file_putf(fff, "\n\n  [Character Inventory]\n\n");
	for (i = 0; i < z_info->pack_size; i++) {
		struct object *obj = player->upkeep->inven[i];
		if (!obj) break;

		object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
		file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name);
		object_info_chardump(fff, obj, 5, 72);
	}
	file_putf(fff, "\n\n");

	/* Dump the quiver */
	file_putf(fff, "\n\n  [Character Quiver]\n\n");
	for (i = 0; i < z_info->quiver_size; i++) {
		struct object *obj = player->upkeep->quiver[i];
		if (!obj) continue;

		object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
		file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name);
		object_info_chardump(fff, obj, 5, 72);
	}
	file_putf(fff, "\n\n");

	/* Dump the Home -- if anything there */
	store_stock_list(home, home_list, z_info->store_inven_max);
	if (home->stock_num) {
		/* Header */
		file_putf(fff, "  [Home Inventory]\n\n");

		/* Dump all available items */
		for (i = 0; i < z_info->store_inven_max; i++) {
			struct object *obj = home_list[i];
			if (!obj) break;
			object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL);
			file_putf(fff, "%c) %s\n", I2A(i), o_name);

			object_info_chardump(fff, obj, 5, 72);
		}

		/* Add an empty line */
		file_putf(fff, "\n\n");
	}

	/* Dump character history */
	dump_history(fff);
	file_putf(fff, "\n\n");

	/* Dump options */
	file_putf(fff, "  [Options]\n\n");

	/* Dump options */
	for (i = 0; i < OP_MAX; i++) {
		int opt;
		const char *title = "";
		switch (i) {
			case OP_INTERFACE: title = "User interface"; break;
			case OP_BIRTH: title = "Birth"; break;
		    default: continue;
		}

		file_putf(fff, "  [%s]\n\n", title);
		for (opt = 0; opt < OPT_MAX; opt++) {
			if (option_type(opt) != i) continue;

			file_putf(fff, "%-45s: %s (%s)\n",
			        option_desc(opt),
			        player->opts.opt[opt] ? "yes" : "no ",
			        option_name(opt));
		}

		/* Skip some lines */
		file_putf(fff, "\n");
	}

	mem_free(home_list);
}
예제 #5
0
파일: console.c 프로젝트: srodrig1/lk
static int cmd_history(int argc, const cmd_args *argv)
{
    dump_history();
    return 0;
}
예제 #6
0
파일: files.c 프로젝트: essarrdee/angband
/*
 * Hack -- Dump a character description file
 *
 * XXX XXX XXX Allow the "full" flag to dump additional info,
 * and trigger its usage from various places in the code.
 */
errr file_character(const char *path, bool full)
{
	int i, x, y;

	int a;
	wchar_t c;

	ang_file *fp;

	struct store *st_ptr = &stores[STORE_HOME];

	char o_name[80];

	char buf[1024];
	char *p;

	/* Unused parameter */
	(void)full;


	/* Open the file for writing */
	fp = file_open(path, MODE_WRITE, FTYPE_TEXT);
	if (!fp) return (-1);

	/* Begin dump */
	file_putf(fp, "  [%s Character Dump]\n\n", buildid);


	/* Display player */
	display_player(0);

	/* Dump part of the screen */
	for (y = 1; y < 23; y++)
	{
		p = buf;
		/* Dump each row */
		for (x = 0; x < 79; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		x_file_putf(fp, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Display player */
	display_player(1);

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		x_file_putf(fp, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		p = buf;
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x + 40, y, &a, &c));

			/* Dump it */
			p += wctomb(p, c);
		}

		/* Back up over spaces */
		while ((p > buf) && (p[-1] == ' ')) --p;

		/* Terminate */
		*p = '\0';

		/* End the row */
		x_file_putf(fp, "%s\n", buf);
	}

	/* Skip some lines */
	file_putf(fp, "\n\n");


	/* If dead, dump last messages -- Prfnoff */
	if (p_ptr->is_dead)
	{
		i = messages_num();
		if (i > 15) i = 15;
		file_putf(fp, "  [Last Messages]\n\n");
		while (i-- > 0)
		{
			x_file_putf(fp, "> %s\n", message_str((s16b)i));
		}
		x_file_putf(fp, "\nKilled by %s.\n\n", p_ptr->died_from);
	}


	/* Dump the equipment */
	file_putf(fp, "  [Character Equipment]\n\n");
	for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++)
	{
		if (i == INVEN_TOTAL)
		{
			file_putf(fp, "\n\n  [Character Quiver]\n\n");
			continue;
		}
		object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i],
				ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name);
		if (p_ptr->inventory[i].kind)
			object_info_chardump(fp, &p_ptr->inventory[i], 5, 72);
	}

	/* Dump the inventory */
	file_putf(fp, "\n\n  [Character Inventory]\n\n");
	for (i = 0; i < INVEN_PACK; i++)
	{
		if (!p_ptr->inventory[i].kind) break;

		object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i],
					ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name);
		object_info_chardump(fp, &p_ptr->inventory[i], 5, 72);
	}
	file_putf(fp, "\n\n");


	/* Dump the Home -- if anything there */
	if (st_ptr->stock_num)
	{
		/* Header */
		file_putf(fp, "  [Home Inventory]\n\n");

		/* Dump all available items */
		for (i = 0; i < st_ptr->stock_num; i++)
		{
			object_desc(o_name, sizeof(o_name), &st_ptr->stock[i],
						ODESC_PREFIX | ODESC_FULL);
			x_file_putf(fp, "%c) %s\n", I2A(i), o_name);

			object_info_chardump(fp, &st_ptr->stock[i], 5, 72);
		}

		/* Add an empty line */
		file_putf(fp, "\n\n");
	}

	/* Dump character history */
	dump_history(fp);
	file_putf(fp, "\n\n");

	/* Dump options */
	file_putf(fp, "  [Options]\n\n");

	/* Dump options */
	for (i = 0; i < OPT_PAGE_MAX - 1; i++) {
		int j;
		const char *title = "";
		switch (i) {
			case 0: title = "Interface"; break;
			case 1: title = "Warning"; break;
			case 2: title = "Birth"; break;
		}

		file_putf(fp, "  [%s]\n\n", title);
		for (j = 0; j < OPT_PAGE_PER; j++) {
			int opt = option_page[i][j];
			if (!option_name(opt)) continue;

			file_putf(fp, "%-45s: %s (%s)\n",
			        option_desc(opt),
			        op_ptr->opt[opt] ? "yes" : "no ",
			        option_name(opt));
		}

		/* Skip some lines */
		file_putf(fp, "\n");
	}

	file_close(fp);


	/* Success */
	return (0);
}
예제 #7
0
파일: files.c 프로젝트: jobjingjo/csangband
/*
 * Hack -- Dump a character description file
 *
 * XXX XXX XXX Allow the "full" flag to dump additional info,
 * and trigger its usage from various places in the code.
 */
errr file_character(const char *path, bool full)
{
	int i, x, y;

	byte a;
	char c;

	ang_file *fp;

	struct store *st_ptr = &stores[STORE_HOME];

	char o_name[80];

	byte (*old_xchar_hook)(byte c) = Term.xchar_hook;

	char buf[1024];

	/* We use either ascii or system-specific encoding */
 	int encoding = OPT(xchars_to_file) ? SYSTEM_SPECIFIC : ASCII;

	/* Unused parameter */
	(void)full;


	/* Open the file for writing */
	fp = file_open(path, MODE_WRITE, FTYPE_TEXT);
	if (!fp) return (-1);

	/* Display the requested encoding -- ASCII or system-specific */
 	if (!OPT(xchars_to_file)) Term.xchar_hook = null;

	/* Begin dump */
	file_putf(fp, "  [%s Character Dump]\n\n", buildid);


	/* Display player */
	display_player(0);

	/* Dump part of the screen */
	for (y = 1; y < 23; y++)
	{
		/* Dump each row */
		for (x = 0; x < 79; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			buf[x] = c;
		}

		/* Back up over spaces */
		while ((x > 0) && (buf[x-1] == ' ')) --x;

		/* Terminate */
		buf[x] = '\0';

		/* End the row */
		x_file_putf(fp, encoding, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Display player */
	display_player(1);

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x, y, &a, &c));

			/* Dump it */
			buf[x] = c;
		}

		/* Back up over spaces */
		while ((x > 0) && (buf[x-1] == ' ')) --x;

		/* Terminate */
		buf[x] = '\0';

		/* End the row */
		x_file_putf(fp, encoding, "%s\n", buf);
	}

	/* Skip a line */
	file_putf(fp, "\n");

	/* Dump part of the screen */
	for (y = 11; y < 20; y++)
	{
		/* Dump each row */
		for (x = 0; x < 39; x++)
		{
			/* Get the attr/char */
			(void)(Term_what(x + 40, y, &a, &c));

			/* Dump it */
			buf[x] = c;
		}

		/* Back up over spaces */
		while ((x > 0) && (buf[x-1] == ' ')) --x;

		/* Terminate */
		buf[x] = '\0';

		/* End the row */
		x_file_putf(fp, encoding, "%s\n", buf);
	}

	/* Skip some lines */
	file_putf(fp, "\n\n");


	/* If dead, dump last messages -- Prfnoff */
	if (p_ptr.is_dead)
	{
		i = messages_num();
		if (i > 15) i = 15;
		file_putf(fp, "  [Last Messages]\n\n");
		while (i-- > 0)
		{
			x_file_putf(fp, encoding, "> %s\n", message_str((s16b)i));
		}
		x_file_putf(fp, encoding, "\nKilled by %s.\n\n", p_ptr.died_from);
	}


	/* Dump the equipment */
	file_putf(fp, "  [Character Equipment]\n\n");
	for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++)
	{
		if (i == INVEN_TOTAL)
		{
			file_putf(fp, "\n\n  [Character Quiver]\n\n");
			continue;
		}
		object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i],
				ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name);
		if (p_ptr.inventory[i].kind)
			object_info_chardump(fp, &p_ptr.inventory[i], 5, 72);
	}

	/* Dump the inventory */
	file_putf(fp, "\n\n  [Character Inventory]\n\n");
	for (i = 0; i < INVEN_PACK; i++)
	{
		if (!p_ptr.inventory[i].kind) break;

		object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i],
					ODESC_PREFIX | ODESC_FULL);

		x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name);
		object_info_chardump(fp, &p_ptr.inventory[i], 5, 72);
	}
	file_putf(fp, "\n\n");


	/* Dump the Home -- if anything there */
	if (st_ptr.stock_num)
	{
		/* Header */
		file_putf(fp, "  [Home Inventory]\n\n");

		/* Dump all available items */
		for (i = 0; i < st_ptr.stock_num; i++)
		{
			object_desc(o_name, sizeof(o_name), &st_ptr.stock[i],
						ODESC_PREFIX | ODESC_FULL);
			x_file_putf(fp, encoding, "%c) %s\n", I2A(i), o_name);

			object_info_chardump(fp, &st_ptr.stock[i], 5, 72);
		}

		/* Add an empty line */
		file_putf(fp, "\n\n");
	}

	/* Dump character history */
	dump_history(fp);
	file_putf(fp, "\n\n");

	/* Dump options */
	file_putf(fp, "  [Options]\n\n");

	/* Dump options */
	for (i = OPT_BIRTH; i < OPT_BIRTH + N_OPTS_BIRTH; i++)
	{
		if (option_name(i))
		{
			file_putf(fp, "%-45s: %s (%s)\n",
			        option_desc(i),
			        op_ptr.opt[i] ? "yes" : "no ",
			        option_name(i));
		}
	}

	/* Skip some lines */
	file_putf(fp, "\n\n");

	/* Return to standard display */
 	Term.xchar_hook = old_xchar_hook;

	file_close(fp);


	/* Success */
	return (0);
}
예제 #8
0
void debug_dump_history(struct debug_q* q)
{
    dump_history(q);
}
예제 #9
0
static errval_t debug_enqueue(struct devq* q, regionid_t rid, 
                              genoffset_t offset, genoffset_t length,
                              genoffset_t valid_data, genoffset_t valid_length,
                              uint64_t flags)
{
    assert(length > 0);
    DEBUG("enqueue offset %"PRIu64" \n", offset);
    errval_t err;
    struct debug_q* que = (struct debug_q*) q;

    // find region
    struct memory_list* region = NULL;

    err = find_region(que, &region, rid);
    if (err_is_fail(err)){
        return err;
    }
    
    check_consistency(region);

    // find the buffer 
    struct memory_ele* buffer = region->buffers;
    
    if (region->buffers == NULL) {
        return DEVQ_ERR_BUFFER_ALREADY_IN_USE;
    }    

    // the only buffer
    if (buffer->next == NULL) {
        if (buffer_in_bounds(offset, length,
                             buffer->offset, buffer->length)) {
            err = que->q->f.enq(que->q, rid, offset, length, valid_data,
                                valid_length, flags);
            if (err_is_fail(err)) {
                return err;
            }   

            remove_split_buffer(que, region, buffer, offset, length);
            return SYS_ERR_OK;          
        } else {
            printf("Bounds check failed only buffer offset=%lu length=%lu " 
                  " buf->offset=%lu buf->len=%lu\n", offset, length,
                  buffer->offset, buffer->length);
            dump_history(que);
            dump_list(region);
            return DEVQ_ERR_INVALID_BUFFER_ARGS;
        }
    }


    // more than one buffer
    while (buffer != NULL) {
        if (buffer_in_bounds(offset, length, 
                             buffer->offset, buffer->length)){
            err = que->q->f.enq(que->q, rid, offset, length, valid_data,
                                valid_length, flags);
            if (err_is_fail(err)) {
                return err;
            }   

            remove_split_buffer(que, region, buffer, offset, length);
            return SYS_ERR_OK;          
        }
        buffer = buffer->next;
    }  
    
    printf("Did not find region offset=%ld length=%ld \n", offset, length);
    dump_history(que);
    dump_list(region);

    return DEVQ_ERR_INVALID_BUFFER_ARGS;
}