Beispiel #1
0
/*
 * load_dump --
 *	Load from the WiredTiger dump format.
 */
static int
load_dump(WT_SESSION *session)
{
	WT_CURSOR *cursor;
	WT_DECL_RET;
	int hex, tret;
	char **list, **tlist, *uri, config[64];

	cursor = NULL;
	list = NULL;		/* -Wuninitialized */
	hex = 0;		/* -Wuninitialized */
	uri = NULL;

	/* Read the metadata file. */
	if ((ret = config_read(&list, &hex)) != 0)
		return (ret);

	/* Reorder and check the list. */
	if ((ret = config_reorder(list)) != 0)
		goto err;

	/* Update the config based on any command-line configuration. */
	if ((ret = config_update(session, list)) != 0)
		goto err;

	uri = list[0];
	/* Create the items in the list. */
	if ((ret = config_exec(session, list)) != 0)
		goto err;

	/* Open the insert cursor. */
	(void)snprintf(config, sizeof(config),
	    "dump=%s%s%s",
	    hex ? "hex" : "print",
	    append ? ",append" : "", no_overwrite ? ",overwrite=false" : "");
	if ((ret = session->open_cursor(
	    session, uri, NULL, config, &cursor)) != 0) {
		ret = util_err(ret, "%s: session.open", uri);
		goto err;
	}

	/*
	 * Check the append flag (it only applies to objects where the primary
	 * key is a record number).
	 */
	if (append && strcmp(cursor->key_format, "r") != 0) {
		fprintf(stderr,
		    "%s: %s: -a option illegal unless the primary key is a "
		    "record number\n",
		    progname, uri);
		ret = 1;
	} else
		ret = insert(cursor, uri);

err:	/*
	 * Technically, we don't have to close the cursor because the session
	 * handle will do it for us, but I'd like to see the flush to disk and
	 * the close succeed, it's better to fail early when loading files.
	 */
	if (cursor != NULL && (tret = cursor->close(cursor)) != 0) {
		tret = util_err(tret, "%s: cursor.close", uri);
		if (ret == 0)
			ret = tret;
	}
	if (ret == 0)
		ret = util_flush(session, uri);

	for (tlist = list; *tlist != NULL; ++tlist)
		free(*tlist);
	free(list);

	return (ret == 0 ? 0 : 1);
}
Beispiel #2
0
int main( int argc, char *arvg[] ) {
	int quit = 0;
	int config_status = 0;
	int event;

#ifdef __WIN32__
	freopen( "cabrio.out", "w", stdout );
	freopen( "cabrio.err", "w", stderr );
#endif

	config_status = config_open( NULL );
	if( config_status == -1 )
		return -1;

	if( sdl_init() != 0 )
		bail();

	if( ogl_init() != 0 )
		bail();
	
	/* Clear the screen as soon as we can. This avoids graphics
	 * glitches which can occur with some SDL implementations. */
	ogl_clear();
	sdl_swap();

	if( event_init() != 0 )
		bail();

	if( font_init() != 0 )
		bail();

	if( config_status == 1 ) {
		/* Config file didn't exist, so run the setup utility */
		if( setup() != 0 )
			return -1;
		config_update();
		if( config_create() != 0 )
			return -1;
	}

	location_init();

	/* If config or location results in a new font, it'll be loaded here. */
	font_free();
	font_init();

	/* Large game lists take a while to initialise,
	 * so show the background while we wait... */
	bg_init();
	bg_clear();
	bg_draw();
	sdl_swap();

	if( platform_init() != 0 )
		bail();

	if( category_init() != 0 )
		bail();

	if( game_sel_init() != 0 )
		bail();

	if( hint_init() != 0 )
		bail();

	if( snap_init() != 0 )
		bail();
	
	if( game_list_create() != 0 )
		bail();

	if( menu_init() != 0 )
		bail();

	if( submenu_init() != 0 )
		bail();

	sound_init();
	video_init();
	
	event_flush();

	if( !config_get()->iface.theme.menu.auto_hide )
		menu_show();
		
	focus_set( FOCUS_GAMESEL );

	while( !quit ) {
		ogl_clear();
		bg_draw();
		snap_draw();
		if (!config_get()->iface.hide_buttons)
			hint_draw();
		menu_draw();
		submenu_draw();
		game_sel_draw();
		sdl_swap();
		if (Mix_PlayingMusic() != 1 && config_get()->iface.theme_sound && reader_running == 0) 
			playmusic();
		if (( event = event_poll() )) {
			if( supress_wait == 0 ) {
				if( event == EVENT_QUIT ) {
					quit = 1;
				}
				else {
					supress();
					event_process( event );
				}
			}
		}
		if( supress_wait > 0 )
			supress_wait--;
		
		sdl_frame_delay();
	}
	clean_up();
	return 0;
}
Beispiel #3
0
void RecordVideo::run()
{
// Number of frames for user to know about.
	gui->reset_video();

// Wait for trigger
	trigger_lock->lock("RecordVideo::run");

	while( !done && !write_result ) {
		if( recording_paused ) {
			pause_record_lock->unlock();
			record_paused_lock->lock();
		}
		if( done ) break;
		VideoDevice *vdevice = record->vdevice;
		VFrame *capture_frame = get_buffer();
		vdevice->set_field_order(record->reverse_interlace);
// Capture a frame
		grab_result = read_buffer(capture_frame);
		if( done ) break;
		if( vdevice->config_updated() ) {
			flush_buffer();
			delete_buffer();
			config_update();
			gui->reset_video();
			record->record_monitor->reconfig();
			continue;
		}
		if( grab_result ) {
			Timer::delay(250);
			continue;
		}
		decompress_buffer(capture_frame);
		record->resync();
		write_buffer();
		if( record->monitor_video && capture_frame->get_data() )
			if( !writing_file || !record->is_behind() )
				record->record_monitor->update(capture_frame);
		if( writing_file && record->fill_underrun_frames ) {
			VFrame *last_frame = capture_frame;
			int fill = record->dropped;
			while( --fill >= 0 ) {
				capture_frame = get_buffer();
				capture_frame->copy_from(last_frame);
				last_frame = capture_frame;
				write_buffer();
			}
		}
		else
			record->written_frames += record->dropped;
		if( record->single_frame ) {
			record->single_frame = 0;
			record->stop_writing_file();
		}
		if( done ) break;
		if( !done ) done = write_result;
		if( done ) break;
		record->check_batch_complete();
	}

SET_TRACE
	flush_buffer();
	delete_buffer();
SET_TRACE
//TRACE("RecordVideo::run 2");
	if( write_result ) {
		ErrorBox error_box(PROGRAM_NAME ": Error",
			mwindow->gui->get_abs_cursor_x(1),
			mwindow->gui->get_abs_cursor_y(1));
			error_box.create_objects(_("No space left on disk."));
		error_box.run_window();
	}
SET_TRACE
}
Beispiel #4
0
/*
 * load_dump --
 *	Load from the WiredTiger dump format.
 */
static int
load_dump(WT_SESSION *session)
{
    WT_CURSOR *cursor;
    WT_DECL_RET;
    int hex, tret;
    char **entry, **list, *p, **tlist, *uri, config[64];

    cursor = NULL;
    list = NULL;		/* -Wuninitialized */
    hex = 0;		/* -Wuninitialized */
    uri = NULL;

    /* Read the metadata file. */
    if ((ret = config_read(&list, &hex)) != 0)
        return (ret);

    /*
     * Search for a table name -- if we find one, then it's table dump,
     * otherwise, it's a single file dump.
     */
    for (entry = list; *entry != NULL; ++entry)
        if (WT_PREFIX_MATCH(*entry, "table:"))
            break;
    if (*entry == NULL) {
        /*
         * Single file dumps can only have two lines, the file name and
         * the configuration information.
         */
        if ((list[0] == NULL || list[1] == NULL || list[2] != NULL) ||
                (WT_PREFIX_MATCH(list[0], "file:") &&
                 WT_PREFIX_MATCH(list[0], "lsm:"))) {
            ret = format();
            goto err;
        }

        entry = list;
    }

    /*
     * Make sure the table key/value pair comes first, then we can just
     * run through the array in order.  (We already checked that we had
     * a multiple of 2 entries, so this is safe.)
     */
    if (entry != list) {
        p = list[0];
        list[0] = entry[0];
        entry[0] = p;
        p = list[1];
        list[1] = entry[1];
        entry[1] = p;
    }

    /* Update the config based on any command-line configuration. */
    if ((ret = config_update(session, list)) != 0)
        goto err;

    uri = list[0];
    for (entry = list; *entry != NULL; entry += 2)
        if ((ret = session->create(session, entry[0], entry[1])) != 0) {
            ret = util_err(ret, "%s: session.create", entry[0]);
            goto err;
        }

    /* Open the insert cursor. */
    (void)snprintf(config, sizeof(config),
                   "dump=%s%s%s",
                   hex ? "hex" : "print",
                   append ? ",append" : "", no_overwrite ? ",overwrite=false" : "");
    if ((ret = session->open_cursor(
                   session, uri, NULL, config, &cursor)) != 0) {
        ret = util_err(ret, "%s: session.open", uri);
        goto err;
    }

    /*
     * Check the append flag (it only applies to objects where the primary
     * key is a record number).
     */
    if (append && strcmp(cursor->key_format, "r") != 0) {
        fprintf(stderr,
                "%s: %s: -a option illegal unless the primary key is a "
                "record number\n",
                progname, uri);
        ret = 1;
    } else
        ret = insert(cursor, uri);

err:	/*
	 * Technically, we don't have to close the cursor because the session
	 * handle will do it for us, but I'd like to see the flush to disk and
	 * the close succeed, it's better to fail early when loading files.
	 */
    if (cursor != NULL && (tret = cursor->close(cursor)) != 0) {
        tret = util_err(tret, "%s: cursor.close", uri);
        if (ret == 0)
            ret = tret;
    }
    if (ret == 0)
        ret = util_flush(session, uri);

    for (tlist = list; *tlist != NULL; ++tlist)
        free(*tlist);
    free(list);

    return (ret == 0 ? 0 : 1);
}
/*
 * json_data --
 *	Parse the data portion of the JSON input, and insert all
 *	values.
 */
static int
json_data(WT_SESSION *session, JSON_INPUT_STATE *ins, CONFIG_LIST *clp,
    uint32_t flags)
{
	WT_CURSOR *cursor;
	WT_DECL_RET;
	char config[64], *endp, *uri;
	const char *keyformat;
	int isrec, nfield, nkeys, toktype, tret;
	size_t keystrlen;
	ssize_t gotnolen;
	uint64_t gotno, recno;

	cursor = NULL;
	uri = NULL;

	/* Reorder and check the list. */
	if ((ret = config_reorder(clp->list)) != 0)
		goto err;

	/* Update config based on command-line configuration. */
	if ((ret = config_update(session, clp->list)) != 0)
		goto err;

	/* Create the items collected. */
	if ((ret = config_exec(session, clp->list)) != 0)
		goto err;

	uri = clp->list[0];
	(void)snprintf(config, sizeof(config),
	    "dump=json%s%s",
	    LF_ISSET(LOAD_JSON_APPEND) ? ",append" : "",
	    LF_ISSET(LOAD_JSON_NO_OVERWRITE) ? ",overwrite=false" : "");
	if ((ret = session->open_cursor(
	    session, uri, NULL, config, &cursor)) != 0) {
		ret = util_err(ret, "%s: session.open", uri);
		goto err;
	}
	keyformat = cursor->key_format;
	isrec = (strcmp(keyformat, "r") == 0);
	for (nkeys = 0; *keyformat; keyformat++)
		if (!isdigit(*keyformat))
			nkeys++;

	recno = 0;
	while (json_peek(session, ins) == '{') {
		nfield = 0;
		JSON_EXPECT(session, ins, '{');
		if (ins->kvraw == NULL) {
			if ((ins->kvraw = (char *)malloc(1)) == NULL) {
				ret = util_err(errno, NULL);
				goto err;
			}
		}
		ins->kvraw[0] = '\0';
		ins->kvrawstart = JSON_INPUT_POS(ins);
		keystrlen = 0;
		while (json_peek(session, ins) == 's') {
			JSON_EXPECT(session, ins, 's');
			JSON_EXPECT(session, ins, ':');
			toktype = json_peek(session, ins);
			JSON_EXPECT(session, ins, toktype);
			if (isrec && nfield == 0) {
				/* Verify the dump has recnos in order. */
				recno++;
				gotno = __wt_strtouq(ins->tokstart, &endp, 0);
				gotnolen = (endp - ins->tokstart);
				if (recno != gotno ||
				    ins->toklen != (size_t)gotnolen) {
					ret = util_err(0,
					    "%s: recno out of order", uri);
					goto err;
				}
			}
			if (++nfield == nkeys) {
				size_t curpos = JSON_INPUT_POS(ins);
				if ((ret = json_kvraw_append(ins,
				    (char *)ins->line.mem + ins->kvrawstart,
				    curpos - ins->kvrawstart)) != 0)
					goto err;
				ins->kvrawstart = curpos;
				keystrlen = strlen(ins->kvraw);
			}
			if (json_peek(session, ins) != ',')
				break;
			JSON_EXPECT(session, ins, ',');
			if (json_peek(session, ins) != 's')
				goto err;
		}
		if (json_kvraw_append(ins, ins->line.mem, JSON_INPUT_POS(ins)))
			goto err;

		ins->kvraw[keystrlen] = '\0';
		if (!LF_ISSET(LOAD_JSON_APPEND))
			cursor->set_key(cursor, ins->kvraw);
		/* skip over inserted space and comma */
		cursor->set_value(cursor, &ins->kvraw[keystrlen+2]);
		if ((ret = cursor->insert(cursor)) != 0) {
			ret = util_err(ret, "%s: cursor.insert", uri);
			goto err;
		}

		JSON_EXPECT(session, ins, '}');
		if (json_peek(session, ins) != ',')
			break;
		JSON_EXPECT(session, ins, ',');
		if (json_peek(session, ins) != '{')
			goto err;
	}
	if (0) {
err:		if (ret == 0)
			ret = EINVAL;
	}
	/*
	 * Technically, we don't have to close the cursor because the session
	 * handle will do it for us, but I'd like to see the flush to disk and
	 * the close succeed, it's better to fail early when loading files.
	 */
	if (cursor != NULL && (tret = cursor->close(cursor)) != 0) {
		tret = util_err(tret, "%s: cursor.close", uri);
		if (ret == 0)
			ret = tret;
	}
	if (ret == 0)
		ret = util_flush(session, uri);
	return (ret);
}
Beispiel #6
0
/**
 * Load options from command line and then decide whenever there should be
 * attempt to load them from confguration file too. Merge those two together and
 * store into global configuration storage.
 *
 * \param argc number of arguments
 * \param argv array of arguments
 * \param index pointer to int where the position of first non-option argument
 * in list is to be stored
 * \return OK on success
 */
RCode config_load(int argc, char** argv, int *index) {
	int flags = 0;
	ConfigStorage *file = NULL;
	ConfigStorage *cmd = NULL;
	char* filename = NULL;
	char* profile = NULL;
	char buffer[4096] = "";

	cmd = config_from_cmdline(argc, argv, &flags, index);
	if ( NULL == cmd ) {
		ERROR_NOTE("Command line parsing failed");
		return FAIL;
	}

	// check if filename was supplied or use default
	if ( NULL != cmd->filename ) {
		filename = cmd->filename;
	} else {
		char* directory = getenv("HOME");
		if ( NULL != directory ) {
			filename = buffer;
			filename = strcat(filename, directory);
			filename = strcat(filename, "/");
			filename = strcat(filename, CONFIG_DEFAULT_FILE);
		}
	}

	// check if profile was supplied or use default
	if ( NULL != cmd->profile ) {
		profile = cmd->profile;
	} else {
		profile = "default";
	}

	// check if we have both filename and profile. if not, use only
	// configuration from command line
	if ( NULL == profile || NULL == filename ) {
		config = cmd;
		return OK;
	}

	// load configuration from file and merge it with command line config
	file = config_from_file(filename, profile);
	if ( NULL != file ) {
		if ( FAIL == config_update( file, cmd, flags ) ) {
			ERROR_NOTE("Can't merge command line and file '%s' configuration",
					filename
				);
			config_destroy(cmd);
			config_destroy(file);
			return FAIL;
		}

		// this structure is no longer needed
		config_destroy( cmd );
		config = file;

	} else {
		config = cmd;
	}

	return OK;
}