示例#1
0
文件: lab.c 项目: a1an1in/libcutils
int lab()
{
    if(check_endian()) {
        dbg_str(DBG_DETAIL,"little endian");
    } else {
        dbg_str(DBG_DETAIL,"big endian");
    }
}
示例#2
0
void bsd_init( bsd_ctx_t *ctx) {
  check_endian( & sendian);
  ctx->read = 0;
  ctx->broken = 0;
  ctx->stacksize = 0;
  ctx->stack[0].kind = BS_FTOP;
  ctx->stack[0].ctxid = BS_CTXID_GLOBAL;
  ctx->stack[0].missing = -1;
  bs_classcoll_init( &ctx->classcoll);
}
int main(int argc, char** argv)
{
    int endian;
    endian = check_endian();
    
    if(endian == LITTLE)
	    printf("Little endian\n");
    else
	    printf("Big endian\n");

    return 0;
}
示例#4
0
文件: native.c 项目: apuder/TRS-80
static void init_xtrs(JNIEnv* env, jint model, jstring romFile, Ushort entryAddr, jstring xtrsCassette,
                      jstring xtrsDisk0, jstring xtrsDisk1, jstring xtrsDisk2, jstring xtrsDisk3) {
    int debug = FALSE;

    program_name = "xtrs";
    check_endian();
    trs_model = model;
    init_emulator();

    const char* path = (*env)->GetStringUTFChars(env, romFile, NULL);
    char* dest = NULL;
    switch(model) {
    case 1:
        dest = romfile;
        break;
    case 3:
        dest = romfile3;
        break;
    case 4:
    case 5:
        dest = romfile4p;
        break;
    }
    strncpy(dest, path, FILENAME_MAX);
    (*env)->ReleaseStringUTFChars(env, romFile, path);
    trs_autodelay = 1;
    trs_emtsafe = 1;
    trs_show_led = 0;
    timer_overclock = 0;
    grafyx_set_microlabs(0);
    trs_disk_doubler = TRSDISK_BOTH;
    trs_disk_truedam = 0;
    trs_uart_name = "UART";
    trs_uart_switches = 0;
    trs_kb_bracket(0);
    mem_init();
    trs_rom_init();
    trs_screen_init();
    trs_timer_init();
    trs_reset(1);
    // Cassette
    trs_cassette_remove();
    if (xtrsCassette != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsCassette, NULL);
        trs_cassette_insert((char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsCassette, path);
    }
    // Disk 0
    trs_disk_remove(0);
    if (xtrsDisk0 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk0, NULL);
        if (ends_with(path, ".cmd")) {
            FILE* f = fopen(path, "rb");
            load_cmd(f, memory, NULL, 0, NULL, -1, NULL, &entryAddr, 1);
            fclose(f);
        } else {
            trs_disk_insert(0, (char *) path);
        }
        (*env)->ReleaseStringUTFChars(env, xtrsDisk0, path);
    }
    // Disk 1
    trs_disk_remove(1);
    if (xtrsDisk1 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk1, NULL);
        trs_disk_insert(1, (char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsDisk1, path);
    }
    // Disk 2
    trs_disk_remove(2);
    if (xtrsDisk2 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk2, NULL);
        trs_disk_insert(2, (char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsDisk2, path);
    }
    // Disk 3
    trs_disk_remove(3);
    if (xtrsDisk3 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk3, NULL);
        trs_disk_insert(3, (char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsDisk3, path);
    }

    trs_disk_init(1);
    z80_state.pc.word = entryAddr;
    clear_paste_string();
}
void
load_city (char *cname)
{
    unsigned long q;
    int i, x, y, z, n, p;
    int num_pbars, pbar_data_size;
    int pbar_tmp;
    int dummy;
    gzFile gzfile;
    char s[256];
    gzfile = gzopen( cname, "rb" ); 
    if ( gzfile == NULL) {
	    printf (_("Can't open <%s> (gzipped)"), cname);
	    do_error ("Can't open it!");
    }
    /* Add version to shared global variables for playing/saving games without waterwell */
    sscanf( gzgets( gzfile, s, 256 ), "%d", &ldsv_version);
    if (ldsv_version < MIN_LOAD_VERSION) {
	    ok_dial_box ("too-old.mes", BAD, 0L);
	    gzclose( gzfile );
	return;
    }

    fprintf(stderr," ldsv_version = %i \n", ldsv_version);
    if (ldsv_version < MIN_WATERWELL_VERSION) {
	/* ok_dial_box ("no-waterwell.mes", GOOD, 0L);*/
	use_waterwell=false;
    } else {
    	use_waterwell=true; 
	/* needed until it is written in the saved file
	 * in case of load after having played an old game
	 */
    }

    init_pbars();
    num_pbars = NUM_PBARS;
    pbar_data_size = PBAR_DATA_SIZE;

    init_inventory();
    
    print_time_for_year();
    q = (unsigned long) sizeof (Map_Point_Info);
    prog_box (_("Loading scene"), 0);

    for (x = 0; x < WORLD_SIDE_LEN; x++) {
	for (y = 0; y < WORLD_SIDE_LEN; y++) {
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).population) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).flags) + z) = n;
	    }
	    for (z = 0; z < sizeof(unsigned short); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z) = n;
	    }
	    for (z = 0; z < sizeof(unsigned short); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_1) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_2) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_3) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_4) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_5) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_6) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_7) + z) = n;
	    }
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
	    MP_POL(x,y) = (unsigned short) n;
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &n);
	    MP_TYPE(x,y) = (short) n;

	    if (get_group_of_type(MP_TYPE(x,y)) == GROUP_MARKET)
		inventory(x,y);
	}
	if (((93 * x) / WORLD_SIDE_LEN) % 3 == 0)
	    prog_box ("", (93 * x) / WORLD_SIDE_LEN);
    }
    check_endian ();
    set_map_groups ();

    sscanf( gzgets( gzfile, s, 256 ), "%d", &main_screen_originx);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &main_screen_originy);
    if (main_screen_originx > WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1)
	main_screen_originx = WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1;

    if (main_screen_originy > WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1)
	main_screen_originy = WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1;

    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_time);
    if (ldsv_version <= MM_MS_C_VER)
	i = OLD_MAX_NUMOF_SUBSTATIONS;
    else
	i = MAX_NUMOF_SUBSTATIONS;
    for (x = 0; x < i; x++)
    {
	sscanf( gzgets( gzfile, s, 256 ), "%d", &substationx[x]);
	sscanf( gzgets( gzfile, s, 256 ), "%d", &substationy[x]);
    }
    prog_box ("", 92);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &numof_substations);
    if (ldsv_version <= MM_MS_C_VER)
	i = OLD_MAX_NUMOF_MARKETS;
    else
	i = MAX_NUMOF_MARKETS;
    for (x = 0; x < i; x++)
    {
	sscanf( gzgets( gzfile, s, 256 ), "%d", &marketx[x]);
	sscanf( gzgets( gzfile, s, 256 ), "%d", &markety[x]);
    }
    prog_box ("", 94);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &numof_markets);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &people_pool);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_money);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &income_tax_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_tax_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &dole_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &transport_cost_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &goods_tax_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &export_tax);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &export_tax_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &import_cost);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &import_cost_rate);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &tech_level);
    if (tech_level > MODERN_WINDMILL_TECH)
	modern_windmill_flag = 1;
    sscanf( gzgets( gzfile, s, 256 ), "%d", &tpopulation);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &tstarving_population);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &tunemployed_population);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &x);  /* waste_goods obsolete */
    sscanf( gzgets( gzfile, s, 256 ), "%d", &power_made);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &power_used);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_made);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_used);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &goods_made);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &goods_used);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &ore_made);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &ore_used);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diff_old_population */

    /* Update variables calculated from those above */
    housed_population = tpopulation / NUMOF_DAYS_IN_MONTH;

    prog_box ("", 96);
    /* Get size of monthgraph array */
    if (ldsv_version <= MG_C_VER) {
	i = 120;
    } else {
	sscanf( gzgets( gzfile, s, 256 ), "%d", &i);
    }
    for (x = 0; x < i; x++) {
	/* If more entries in file than will fit on screen, 
	   then we need to skip past them. */
	if (x >= monthgraph_size) {
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_pop[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_starve[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_nojobs[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_ppool[x] */
	} else {
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_pop[x]);
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_starve[x]);
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_nojobs[x]);
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_ppool[x]);
	}
	/* If our save file is old, skip past obsolete diffgraph entries */
	if (ldsv_version <= MG_C_VER) {
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_power[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_coal[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_goods[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_ore[x] */
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_population[x] */
	}
    }
    /* If screen bigger than number of entries in file, pad with zeroes */
    while (x < monthgraph_size) {
	monthgraph_pop[x] = 0;
	monthgraph_starve[x] = 0;
	monthgraph_nojobs[x] = 0;
	monthgraph_ppool[x] = 0;
	x++;
    }
    prog_box ("", 98);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &rockets_launched);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &rockets_launched_success);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_survey_done);
    
    for (x = 0; x < pbar_data_size; x++) {
	for (p = 0; p < num_pbars; p++) {
	    sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbar_tmp));
	    update_pbar(p,pbar_tmp,1);
/*	    sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbars[p].data[x])); */
	}
    }

    for (p = 0; p < num_pbars; p++)
	pbars[p].data_size = pbar_data_size;

    prog_box ("", 99);

    for (p = 0; p < num_pbars; p++) {
	sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbars[p].oldtot));
	sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbars[p].diff));
    }


    sscanf( gzgets( gzfile, s, 256 ), "%d", &cheat_flag);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_pollution_deaths);
    sscanf( gzgets( gzfile, s, 256 ), "%f", &pollution_deaths_history);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_starve_deaths);
    sscanf( gzgets( gzfile, s, 256 ), "%f", &starve_deaths_history);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_unemployed_years);
    sscanf( gzgets( gzfile, s, 256 ), "%f", &unemployed_history);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &max_pop_ever);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_evacuated);
    sscanf( gzgets( gzfile, s, 256 ), "%d", &total_births);
    for (x = 0; x < NUMOF_MODULES; x++)
	sscanf( gzgets( gzfile, s, 256 ), "%d", &(module_help_flag[x]));
    sscanf( gzgets( gzfile, s, 256 ), "%d", &x);	/* just dummy reads */
    sscanf( gzgets( gzfile, s, 256 ), "%d", &x);	/* for backwards compatibility. */

    /* 10 dummy strings, for missed out things, have been put in save. */
    /* Input from this point uses them. */
    /* XXX: WCK: Huh? Missed out things? */

    sscanf( gzgets( gzfile, s, 256 ), "%128s", given_scene);
    if (strncmp (given_scene, "dummy", 5) == 0 || strlen (given_scene) < 3)
	given_scene[0] = 0;
    sscanf( gzgets( gzfile, s, 256 ), "%128s", s);
    if (strncmp (given_scene, "dummy", 5) != 0)
	sscanf (s, "%d", &highest_tech_level);
    else
	highest_tech_level = 0;
    gzgets( gzfile, s, 80 );		/* this is the CR */

    if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d"
		,&sust_dig_ore_coal_count, &sust_port_count
		,&sust_old_money_count, &sust_old_population_count
		,&sust_old_tech_count, &sust_fire_count
		,&sust_old_money, &sust_old_population, &sust_old_tech
		,&sustain_flag) == 10)
    {
	sust_dig_ore_coal_tip_flag = sust_port_flag = 1;
	/* GCS FIX: Check after loading file if screen is drawn OK */
	/* draw_sustainable_window (); */
    }
    else
	sustain_flag = sust_dig_ore_coal_count = sust_port_count
		= sust_old_money_count = sust_old_population_count
		= sust_old_tech_count = sust_fire_count
		= sust_old_money = sust_old_population = sust_old_tech = 0;
    if (use_waterwell == true) {
    }
    gzclose( gzfile );

    numof_shanties = count_groups (GROUP_SHANTY);
    numof_communes = count_groups (GROUP_COMMUNE);
    prog_box ("", 100);

    /* set up the university intake. */
    x = count_groups (GROUP_UNIVERSITY);
    if (x > 0) {
	university_intake_rate
		= (count_groups (GROUP_SCHOOL) * 20) / x;
	if (university_intake_rate > 100)
	    university_intake_rate = 100;
    }
    else
	university_intake_rate = 50;

    /*Al1 : What is this ? This does nothing, the value are saved in MP_INFO.int_ 
     * for (x = 0; x < WORLD_SIDE_LEN; x++)
     *   for (y = 0; y < WORLD_SIDE_LEN; y++)
     *     update_tech_dep (x, y);
     */

    unhighlight_module_button (selected_module);
    selected_module = sbut[7];	/* 7 is track.  Watch out though! */
    highlight_module_button (selected_module);
    set_selected_module (CST_TRACK_LR);

    print_total_money ();
    reset_animation_times ();
    /* update tech dep for compatibility with old games */
    for (x = 0; x < WORLD_SIDE_LEN; x++)
	for (y = 0; y < WORLD_SIDE_LEN; y++) {
            switch (MP_GROUP(x,y)) {
            case (GROUP_WINDMILL): 	 
                MP_INFO(x,y).int_1 = (int)(WINDMILL_POWER 	 
                        + (((double) MP_INFO(x,y).int_2 * WINDMILL_POWER)
                                / MAX_TECH_LEVEL));
                break;
            case (GROUP_COAL_POWER): 	 
                MP_INFO(x,y).int_1 = (int)(POWERS_COAL_OUTPUT 	 
                        + (((double) MP_INFO(x,y).int_4 * POWERS_COAL_OUTPUT) 
                                / MAX_TECH_LEVEL)); 	 
                break; 	 
            case (GROUP_SOLAR_POWER): 	 
                MP_INFO(x,y).int_1 = (int)(POWERS_SOLAR_OUTPUT 	 
                        + (((double) MP_INFO(x,y).int_2 * POWERS_SOLAR_OUTPUT) 	 
                                / MAX_TECH_LEVEL)); 	 
                break; 	 
            }
    }
 
    map_power_grid(true); /* WCK:  Is this safe to do here?
                           * AL1: No, in NG_1.1
                           * In case of error message with ok_dial_box
                           *    the dialog cannot appear because the screen
                           *    is not set up => crash.
                           * FIXME: move all initialisation elsewhere, in 
                           *    engine.cpp or simulate.cpp.
                           */
                                
}
void
save_city_raw (char *cname)
{
    int x, y, z, q, n, p;
    gzFile ofile = gzopen(cname, "wb");
    if (ofile == NULL) {
	printf (_("Save file <%s> - "), cname);
	do_error (_("Can't open save file!"));
    }
    /* save without waterwell are in NG 1.1 format, eg scenario good_time is ver 98 when loaded */
    if (ldsv_version < VERSION_INT)
    	ldsv_version = VERSION_INT;

    gzprintf (ofile, "%d\n", ldsv_version);
    q = sizeof (Map_Point_Info);
    prog_box (_("Saving scene"), 0);
    check_endian ();
    for (x = 0; x < WORLD_SIDE_LEN; x++) {
	for (y = 0; y < WORLD_SIDE_LEN; y++) {
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).population) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).flags) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(unsigned short); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(unsigned short); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_1) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_2) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_3) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_4) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_5) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_6) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    for (z = 0; z < sizeof(int); z++) {
		n = *(((unsigned char *) &MP_INFO(x,y).int_7) + z);
		gzprintf (ofile, "%d\n", n);
	    }
	    gzprintf (ofile, "%d\n", (int) MP_POL(x,y));
	    gzprintf (ofile, "%d\n", (int) MP_TYPE(x,y));
	}
	prog_box ("", (90 * x) / WORLD_SIDE_LEN);
    }
    check_endian ();		/* we have to put the byte order back. */

    gzprintf (ofile, "%d\n", main_screen_originx);
    gzprintf (ofile, "%d\n", main_screen_originy);
    gzprintf (ofile, "%d\n", total_time);
    for (x = 0; x < MAX_NUMOF_SUBSTATIONS; x++)
    {
	gzprintf (ofile, "%d\n", substationx[x]);
	gzprintf (ofile, "%d\n", substationy[x]);
    }
    prog_box ("", 92);
    gzprintf (ofile, "%d\n", numof_substations);
    for (x = 0; x < MAX_NUMOF_MARKETS; x++)
    {
	gzprintf (ofile, "%d\n", marketx[x]);
	gzprintf (ofile, "%d\n", markety[x]);
    }
    prog_box ("", 94);
    gzprintf (ofile, "%d\n", numof_markets);
    gzprintf (ofile, "%d\n", people_pool);
    gzprintf (ofile, "%d\n", total_money);
    gzprintf (ofile, "%d\n", income_tax_rate);
    gzprintf (ofile, "%d\n", coal_tax_rate);
    gzprintf (ofile, "%d\n", dole_rate);
    gzprintf (ofile, "%d\n", transport_cost_rate);
    gzprintf (ofile, "%d\n", goods_tax_rate);
    gzprintf (ofile, "%d\n", export_tax);
    gzprintf (ofile, "%d\n", export_tax_rate);
    gzprintf (ofile, "%d\n", import_cost);
    gzprintf (ofile, "%d\n", import_cost_rate);
    gzprintf (ofile, "%d\n", tech_level);
    gzprintf (ofile, "%d\n", tpopulation);
    gzprintf (ofile, "%d\n", tstarving_population);
    gzprintf (ofile, "%d\n", tunemployed_population);
    gzprintf (ofile, "%d\n", 0); /* waste_goods is obsolete */
    gzprintf (ofile, "%d\n", power_made);
    gzprintf (ofile, "%d\n", power_used);
    gzprintf (ofile, "%d\n", coal_made);
    gzprintf (ofile, "%d\n", coal_used);
    gzprintf (ofile, "%d\n", goods_made);
    gzprintf (ofile, "%d\n", goods_used);
    gzprintf (ofile, "%d\n", ore_made);
    gzprintf (ofile, "%d\n", ore_used);
    gzprintf (ofile, "%d\n", 0); /* Removed diff_old_population, version 1.12 */

    prog_box ("", 96);
    /* Changed, version 1.12 */
    gzprintf (ofile, "%d\n", monthgraph_size);
    for (x = 0; x < monthgraph_size; x++) {
	gzprintf (ofile, "%d\n", monthgraph_pop[x]);
	gzprintf (ofile, "%d\n", monthgraph_starve[x]);
	gzprintf (ofile, "%d\n", monthgraph_nojobs[x]);
	gzprintf (ofile, "%d\n", monthgraph_ppool[x]);
    }
    prog_box ("", 98);
    gzprintf (ofile, "%d\n", rockets_launched);
    gzprintf (ofile, "%d\n", rockets_launched_success);
    gzprintf (ofile, "%d\n", coal_survey_done);
    for (x = 0; x < PBAR_DATA_SIZE; x++)
	for (p = 0; p < NUM_PBARS; p++)
	    gzprintf(ofile, "%d\n", pbars[p].data[x]);

    prog_box ("", 99);

    for (p = 0; p < NUM_PBARS; p++) {
	gzprintf(ofile, "%d\n", pbars[p].oldtot);
	gzprintf(ofile, "%d\n", pbars[p].diff);
    }

    gzprintf (ofile, "%d\n", cheat_flag);
    gzprintf (ofile, "%d\n", total_pollution_deaths);
    gzprintf (ofile, "%f\n", pollution_deaths_history);
    gzprintf (ofile, "%d\n", total_starve_deaths);
    gzprintf (ofile, "%f\n", starve_deaths_history);
    gzprintf (ofile, "%d\n", total_unemployed_years);
    gzprintf (ofile, "%f\n", unemployed_history);
    gzprintf (ofile, "%d\n", max_pop_ever);
    gzprintf (ofile, "%d\n", total_evacuated);
    gzprintf (ofile, "%d\n", total_births);
    for (x = 0; x < NUMOF_MODULES; x++)
	gzprintf (ofile, "%d\n", module_help_flag[x]);
    gzprintf (ofile, "%d\n", 0);	/* dummy values */

    gzprintf (ofile, "%d\n", 0);	/* backward compatibility */

    if (strlen (given_scene) > 1)
	gzprintf (ofile, "%s\n", given_scene);
    else
	gzprintf (ofile, "dummy\n");	/* 1 */

    gzprintf (ofile, "%d\n", highest_tech_level);	/* 2 */

    gzprintf (ofile, "sust %d %d %d %d %d %d %d %d %d %d\n"
	     ,sust_dig_ore_coal_count, sust_port_count
	     ,sust_old_money_count, sust_old_population_count
	     ,sust_old_tech_count, sust_fire_count
	     ,sust_old_money, sust_old_population, sust_old_tech
	     ,sustain_flag);	/* 3 */

    if (use_waterwell == true) {
    } else {
	    gzprintf (ofile, "dummy\n");	/* 4 */
    }
    gzprintf (ofile, "dummy\n");	/* 5 */

    gzprintf (ofile, "dummy\n");	/* 6 */

    gzprintf (ofile, "dummy\n");	/* 7 */

    gzprintf (ofile, "dummy\n");	/* 8 */

    gzprintf (ofile, "dummy\n");	/* 9 */

    gzprintf (ofile, "dummy\n");	/* 10 */

    gzclose (ofile);
    prog_box ("", 100);
}
示例#7
0
文件: main.c 项目: RetroPie/sdltrs
int SDLmain(int argc, char *argv[])
{
    int debug = FALSE;
    struct stat st;

    /* program_name must be set first because the error
     * printing routines use it. */
    program_name = strrchr(argv[0], '/');
    if (program_name == NULL) {
      program_name = argv[0];
    } else {
      program_name++;
    }

    check_endian();

#ifndef MACOSX
    putenv("SDL_VIDEO_CENTERED=1");
#endif	
    
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) { 
        fprintf(stderr, "Failed to initialize SDL library");
  	    exit(1);
    }
        
    /* Enable Unicode key translations */
    SDL_EnableUNICODE(TRUE); 

    argc = trs_parse_command_line(argc, argv, &debug);
    if (argc > 1) {
      fprintf(stderr, "%s: erroneous argument %s\n", program_name, argv[1]);
      exit(1);
    }
    
    trs_set_keypad_joystick();    
    trs_open_joystick();
    
    if (stat(trs_disk_dir, &st) < 0) {
      strcpy(trs_disk_dir,".");
    }                   
    if (stat(trs_hard_dir, &st) < 0) {
      strcpy(trs_hard_dir,".");
    }                   
    if (stat(trs_cass_dir, &st) < 0) {
      strcpy(trs_cass_dir,".");
    }                   
    if (stat(trs_state_dir, &st) < 0) {
      strcpy(trs_state_dir,".");
    }                   
    if (stat(trs_disk_set_dir, &st) < 0) {
      strcpy(trs_disk_set_dir,".");
    }                   
    if (stat(trs_printer_dir, &st) < 0) {
      strcpy(trs_printer_dir,".");
    }                   
 
    mem_init();
    trs_disk_init(0);
    trs_rom_init();
    trs_screen_init();
    screen_init();
    trs_timer_init();

    trs_reset(1);
    if (init_state_file[0] != 0) {
      trs_state_load(init_state_file);
      trs_screen_init();
      trs_screen_refresh();
      }
#ifdef MACOSX
	TrsOriginSet();
#endif
	
    if (!debug || fullscreen) {
      /* Run continuously until exit or request to enter debugger */
      z80_run(TRUE);
    }
    printf("Entering debugger.\n");
    debug_init();
    debug_shell();
    printf("Quitting.\n");
#ifdef MACOSX
    trs_mac_save_defaults();
#endif
    exit(0);
}
示例#8
0
文件: qcndemo.cpp 项目: happyj/qcn
int main(int argc, char** argv)
{
    enum e_os ge_os;
    e_endian g_endian = check_endian(); // coped from util/qcn_util.cpp -- g_endian is global to all procs, i.e. the sac file I/O utils can now use it
    const char strMain[] = {"qcn"};
    memset(strReply, 0x00, iLenReply * sizeof(char));

    char strPath[_MAX_PATH];
    memset(strCWD, 0x00, _MAX_PATH * sizeof(char));
    
    ///Users/carlc/qcn/client/test/qcndemo
    char* strEnd = strrchr(argv[0], 'q');  // the first q found at the end should be our program
    if (strEnd) {
       strncpy(strCWD, argv[0], strEnd - argv[0]);
#ifdef _WIN32
       chdir(strCWD);
#else
       _chdir(strCWD);
#endif
	}
    fprintf(stdout, "Current directory is [%s]\n", strCWD);

#ifdef __APPLE_CC__
    if (g_endian == ENDIAN_BIG) { // powerpc
        ge_os = OS_MAC_PPC;
        sprintf(strSuffix, "_%s_powerpc-apple-darwin9.7.0", QCN_VERSION_STRING);
    }
    else {
        ge_os = OS_MAC_INTEL;
        sprintf(strSuffix, "_%s_i686-apple-darwin9.7.0", QCN_VERSION_STRING);
    }    
#else
#ifdef _WIN32
        ge_os = OS_WINDOWS;
#ifdef _DEBUG
        sprintf(strSuffix, "d.exe");
#else
        sprintf(strSuffix, "_%s_%s.exe", QCN_VERSION_STRING, BOINC_WIN_SUFFIX);
#endif
#else // Linux
        ge_os = OS_LINUX;
        sprintf(strSuffix, "_%s_i686-pc-linux-gnu", QCN_VERSION_STRING);
#endif
#endif
   

    int bStatus;
    fprintf(stdout, "Getting latest earthquake list...");
    fflush(stdout);
#ifdef _WIN32
	bStatus = runit("projects\\qcn.edu_qcn\\curl.exe -s http://qcn.stanford.edu/qcnalpha/download/qcn-quake.xml > slots/0/qcn-quake.xml");
#else
	bStatus = runit("curl -s http://qcn.stanford.edu/qcnalpha/download/qcn-quake.xml > slots/0/qcn-quake.xml");
#endif
    if (!bStatus)  {
#ifdef _WIN32
       bStatus = runit("type slots\\0\\init.1 slots\\0\\qcn-quake.xml slots\\0\\init.2 > slots\\0\\init_data.xml");
#else
       bStatus = runit( "cat slots/0/init.1 slots/0/qcn-quake.xml slots/0/init.2 > slots/0/init_data.xml");
#endif
    }
    else  {
       fprintf(stdout, "Error:\n%s\n", strReply);
       fflush(stdout);
    }

    // do any OS specific stuff, i.e. copy over ntpdate
    switch (ge_os) {
       case OS_WINDOWS:
            runit( "copy slots\\0\\ntpdate.win32 slots\\0\\ntpdate");
            break;
       case OS_MAC_PPC:
            runit( "cp slots/0/ntpdate.mac-ppc slots/0/ntpdate");
            break;
       case OS_MAC_INTEL:
            runit( "cp slots/0/ntpdate.mac-intel slots/0/ntpdate");
            break;
       default:
            break;
    }

#ifdef _WIN32
       runit("del /q /s /f projects\\qcn.edu_qcn\\triggers");
       runit("del /q /s /f slots\\0\\qcnprefs.xml slots\\0\\stderr.txt slots\\0\\boinc_quake_0 slots\\0\\trick*.xml");
#ifdef _WIN32
       chdir("slots\\0");
#else
       _chdir("slots\\0");
#endif
	   sprintf(strPath, "%s%s%s", "..\\..\\projects\\qcn.edu_qcn\\", strMain, strSuffix);
#else
       runit("rm -rf projects/qcn.edu_qcn/triggers");
       runit("rm -f slots/0/qcnprefs.xml slots/0/stderr.txt slots/0/boinc_quake_0 slots/0/trick*.xml");
       _chdir("slots/0");
       sprintf(strPath, "%s%s%s", "../../projects/qcn.edu_qcn/", strMain, strSuffix);
#endif

       LaunchGraphicsThread();

       fprintf(stdout, "Launching %s...\n", strPath);
       fprintf(stdout, "SAC file output in sac/\n");
       fprintf(stdout, "QCN Sensor output in qcndemo.txt\n");
       fprintf(stdout, "Press Ctrl+C to Quit\n");
       fflush(stdout);

       char strExec[_MAX_PATH];
#ifdef _WIN32
       sprintf(strExec, "%s --demo>..\\..\\qcndemo.txt", strPath);
#else
       sprintf(strExec, "%s --demo>../../qcndemo.txt", strPath);
#endif
       runit(strExec);

}
void
load_city (char *cname)
{
    unsigned long q;
    int i, x, y, z, n, p, ver;
    int num_pbars, pbar_data_size;
    int pbar_tmp;
    int dummy;
    FILE *ofile;
    char s[256];
    if ((ofile = fopen_read_gzipped (cname)) == NULL) {
	printf (_("Can't open <%s> (gzipped)"), cname);
	do_error ("Can't open it!");
    }
    fscanf (ofile, "%d", &ver);
    if (ver < MIN_LOAD_VERSION) {
	ok_dial_box ("too-old.mes", BAD, 0L);
	fclose_read_gzipped (ofile);
	return;
    }

    init_pbars();
    num_pbars = NUM_PBARS;
    pbar_data_size = PBAR_DATA_SIZE;

    init_inventory();
    
    print_time_for_year();
    q = (unsigned long) sizeof (Map_Point_Info);
    prog_box (_("Loading scene"), 0);

    for (x = 0; x < WORLD_SIDE_LEN; x++) {
	for (y = 0; y < WORLD_SIDE_LEN; y++) {
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).population) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).flags) + z) = n;
	    }
	    for (z = 0; z < sizeof(unsigned short); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z) = n;
	    }
	    for (z = 0; z < sizeof(unsigned short); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_1) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_2) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_3) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_4) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_5) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_6) + z) = n;
	    }
	    for (z = 0; z < sizeof(int); z++) {
		fscanf (ofile, "%d", &n);
		*(((unsigned char *) &MP_INFO(x,y).int_7) + z) = n;
	    }
	    fscanf (ofile, "%d", &n);
	    MP_POL(x,y) = (unsigned short) n;
	    fscanf (ofile, "%d", &n);
	    MP_TYPE(x,y) = (short) n;

	    if (get_group_of_type(MP_TYPE(x,y)) == GROUP_MARKET)
		inventory(x,y);
	}
	if (((93 * x) / WORLD_SIDE_LEN) % 3 == 0)
	    prog_box ("", (93 * x) / WORLD_SIDE_LEN);
    }
    check_endian ();
    set_map_groups ();

    fscanf (ofile, "%d", &main_screen_originx);
    fscanf (ofile, "%d", &main_screen_originy);
    if (main_screen_originx > WORLD_SIDE_LEN - scr.main_win.w / 16 - 1)
	main_screen_originx = WORLD_SIDE_LEN - scr.main_win.w / 16 - 1;

    if (main_screen_originy > WORLD_SIDE_LEN - scr.main_win.h / 16 - 1)
	main_screen_originy = WORLD_SIDE_LEN - scr.main_win.h / 16 - 1;

    fscanf (ofile, "%d", &total_time);
    if (ver <= MM_MS_C_VER)
	i = OLD_MAX_NUMOF_SUBSTATIONS;
    else
	i = MAX_NUMOF_SUBSTATIONS;
    for (x = 0; x < i; x++)
    {
	fscanf (ofile, "%d", &substationx[x]);
	fscanf (ofile, "%d", &substationy[x]);
    }
    prog_box ("", 92);
    fscanf (ofile, "%d", &numof_substations);
    if (ver <= MM_MS_C_VER)
	i = OLD_MAX_NUMOF_MARKETS;
    else
	i = MAX_NUMOF_MARKETS;
    for (x = 0; x < i; x++)
    {
	fscanf (ofile, "%d", &marketx[x]);
	fscanf (ofile, "%d", &markety[x]);
    }
    prog_box ("", 94);
    fscanf (ofile, "%d", &numof_markets);
    fscanf (ofile, "%d", &people_pool);
    fscanf (ofile, "%d", &total_money);
    fscanf (ofile, "%d", &income_tax_rate);
    fscanf (ofile, "%d", &coal_tax_rate);
    fscanf (ofile, "%d", &dole_rate);
    fscanf (ofile, "%d", &transport_cost_rate);
    fscanf (ofile, "%d", &goods_tax_rate);
    fscanf (ofile, "%d", &export_tax);
    fscanf (ofile, "%d", &export_tax_rate);
    fscanf (ofile, "%d", &import_cost);
    fscanf (ofile, "%d", &import_cost_rate);
    fscanf (ofile, "%d", &tech_level);
    if (tech_level > MODERN_WINDMILL_TECH)
	modern_windmill_flag = 1;
    fscanf (ofile, "%d", &tpopulation);
    fscanf (ofile, "%d", &tstarving_population);
    fscanf (ofile, "%d", &tunemployed_population);
    fscanf (ofile, "%d", &x);  /* waste_goods obsolete */
    fscanf (ofile, "%d", &power_made);
    fscanf (ofile, "%d", &power_used);
    fscanf (ofile, "%d", &coal_made);
    fscanf (ofile, "%d", &coal_used);
    fscanf (ofile, "%d", &goods_made);
    fscanf (ofile, "%d", &goods_used);
    fscanf (ofile, "%d", &ore_made);
    fscanf (ofile, "%d", &ore_used);
    fscanf (ofile, "%d", &dummy); /* &diff_old_population */

    /* Update variables calculated from those above */
    housed_population = tpopulation / NUMOF_DAYS_IN_MONTH;

    prog_box ("", 96);
    /* Get size of monthgraph array */
    if (ver <= MG_C_VER) {
	i = 120;
    } else {
	fscanf (ofile, "%d", &i);
    }
    for (x = 0; x < i; x++) {
	/* If more entries in file than will fit on screen, 
	   then we need to skip past them. */
	if (x >= monthgraph_size) {
	    fscanf (ofile, "%d", &dummy); /* &monthgraph_pop[x] */
	    fscanf (ofile, "%d", &dummy); /* &monthgraph_starve[x] */
	    fscanf (ofile, "%d", &dummy); /* &monthgraph_nojobs[x] */
	    fscanf (ofile, "%d", &dummy); /* &monthgraph_ppool[x] */
	} else {
	    fscanf (ofile, "%d", &monthgraph_pop[x]);
	    fscanf (ofile, "%d", &monthgraph_starve[x]);
	    fscanf (ofile, "%d", &monthgraph_nojobs[x]);
	    fscanf (ofile, "%d", &monthgraph_ppool[x]);
	}
	/* If our save file is old, skip past obsolete diffgraph entries */
	if (ver <= MG_C_VER) {
	    fscanf (ofile, "%d", &dummy); /* &diffgraph_power[x] */
	    fscanf (ofile, "%d", &dummy); /* &diffgraph_coal[x] */
	    fscanf (ofile, "%d", &dummy); /* &diffgraph_goods[x] */
	    fscanf (ofile, "%d", &dummy); /* &diffgraph_ore[x] */
	    fscanf (ofile, "%d", &dummy); /* &diffgraph_population[x] */
	}
    }
    /* If screen bigger than number of entries in file, pad with zeroes */
    while (x < monthgraph_size) {
	monthgraph_pop[x] = 0;
	monthgraph_starve[x] = 0;
	monthgraph_nojobs[x] = 0;
	monthgraph_ppool[x] = 0;
	x++;
    }
    prog_box ("", 98);
    fscanf (ofile, "%d", &rockets_launched);
    fscanf (ofile, "%d", &rockets_launched_success);
    fscanf (ofile, "%d", &coal_survey_done);
    
    for (x = 0; x < pbar_data_size; x++) {
	for (p = 0; p < num_pbars; p++) {
	    fscanf (ofile, "%d", &(pbar_tmp));
	    update_pbar(p,pbar_tmp,1);
/*	    fscanf (ofile, "%d", &(pbars[p].data[x])); */
	}
    }

    for (p = 0; p < num_pbars; p++)
	pbars[p].data_size = pbar_data_size;

    prog_box ("", 99);

    for (p = 0; p < num_pbars; p++) {
	fscanf (ofile, "%d", &(pbars[p].oldtot));
	fscanf (ofile, "%d", &(pbars[p].diff));
    }


    fscanf (ofile, "%d", &cheat_flag);
    fscanf (ofile, "%d", &total_pollution_deaths);
    fscanf (ofile, "%f", &pollution_deaths_history);
    fscanf (ofile, "%d", &total_starve_deaths);
    fscanf (ofile, "%f", &starve_deaths_history);
    fscanf (ofile, "%d", &total_unemployed_years);
    fscanf (ofile, "%f", &unemployed_history);
    fscanf (ofile, "%d", &max_pop_ever);
    fscanf (ofile, "%d", &total_evacuated);
    fscanf (ofile, "%d", &total_births);
    for (x = 0; x < NUMOF_MODULES; x++)
	fscanf (ofile, "%d", &(module_help_flag[x]));
    fscanf (ofile, "%d", &x);	/* just dummy reads */
    fscanf (ofile, "%d", &x);	/* for backwards compatibility. */

    /* 10 dummy strings, for missed out things, have been put in save. */
    /* Input from this point uses them. */
    /* XXX: WCK: Huh? Missed out things? */

    fscanf (ofile, "%128s", given_scene);
    if (strncmp (given_scene, "dummy", 5) == 0 || strlen (given_scene) < 3)
	given_scene[0] = 0;
    fscanf (ofile, "%128s", s);
    if (strncmp (given_scene, "dummy", 5) != 0)
	sscanf (s, "%d", &highest_tech_level);
    else
	highest_tech_level = 0;
    fgets (s, 80, ofile);		/* this is the CR */

    fgets (s, 80, ofile);
    if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d"
		,&sust_dig_ore_coal_count, &sust_port_count
		,&sust_old_money_count, &sust_old_population_count
		,&sust_old_tech_count, &sust_fire_count
		,&sust_old_money, &sust_old_population, &sust_old_tech
		,&sustain_flag) == 10)
    {
	sust_dig_ore_coal_tip_flag = sust_port_flag = 1;
	/* GCS FIX: Check after loading file if screen is drawn OK */
	/* draw_sustainable_window (); */
    }
    else
	sustain_flag = sust_dig_ore_coal_count = sust_port_count
		= sust_old_money_count = sust_old_population_count
		= sust_old_tech_count = sust_fire_count
		= sust_old_money = sust_old_population = sust_old_tech = 0;
    fclose_read_gzipped (ofile);

    numof_shanties = count_groups (GROUP_SHANTY);
    numof_communes = count_groups (GROUP_COMMUNE);
    prog_box ("", 100);

    /* set up the university intake. */
    x = count_groups (GROUP_UNIVERSITY);
    if (x > 0) {
	university_intake_rate
		= (count_groups (GROUP_SCHOOL) * 20) / x;
	if (university_intake_rate > 100)
	    university_intake_rate = 100;
    }
    else
	university_intake_rate = 50;
    for (x = 0; x < WORLD_SIDE_LEN; x++)
    {
	for (y = 0; y < WORLD_SIDE_LEN; y++)
	{
	    update_tech_dep (x, y);
	}
    }

    unhighlight_module_button (selected_module);
    selected_module = sbut[7];	/* 7 is track.  Watch out though! */
    highlight_module_button (selected_module);
    set_selected_module (CST_TRACK_LR);

    print_total_money ();
    reset_animation_times ();
    map_power_grid (); /* WCK:  Is this safe to do here? */
}
示例#10
0
文件: uconv.c 项目: andreiw/polaris
int
uconv_u16tou8(const uint16_t *u16s, size_t *utf16len,
    uchar_t *u8s, size_t *utf8len, int flag)
{
	int inendian;
	int outendian;
	size_t u16l;
	size_t u8l;
	uint32_t hi;
	uint32_t lo;
	boolean_t do_not_ignore_null;

	if (u16s == NULL || utf16len == NULL)
		return (EILSEQ);

	if (u8s == NULL || utf8len == NULL)
		return (E2BIG);

	if (check_endian(flag, &inendian, &outendian) != 0)
		return (EBADF);

	u16l = u8l = 0;
	hi = 0;
	do_not_ignore_null = ((flag & UCONV_IGNORE_NULL) == 0);

	if ((flag & UCONV_IN_ACCEPT_BOM) &&
	    check_bom16(u16s, *utf16len, &inendian))
		u16l++;

	inendian &= UCONV_IN_NAT_ENDIAN;

	for (; u16l < *utf16len; u16l++) {
		if (u16s[u16l] == 0 && do_not_ignore_null)
			break;

		lo = (uint32_t)((inendian) ? u16s[u16l] : BSWAP_16(u16s[u16l]));

		if (lo >= UCONV_U16_HI_MIN && lo <= UCONV_U16_HI_MAX) {
			if (hi)
				return (EILSEQ);
			hi = lo;
			continue;
		} else if (lo >= UCONV_U16_LO_MIN && lo <= UCONV_U16_LO_MAX) {
			if (! hi)
				return (EILSEQ);
			lo = (((hi - UCONV_U16_HI_MIN) * UCONV_U16_BIT_SHIFT +
				lo - UCONV_U16_LO_MIN) & UCONV_U16_BIT_MASK)
				+ UCONV_U16_START;
			hi = 0;
		} else if (hi) {
			return (EILSEQ);
		}

		/*
		 * Now we convert a UTF-32 character into a UTF-8 character.
		 * Unicode coding space is between U+0000 and U+10FFFF;
		 * anything bigger is an illegal character.
		 */
		if (lo <= UCONV_U8_ONE_BYTE) {
			if (u8l >= *utf8len)
				return (E2BIG);
			u8s[u8l++] = (uchar_t)lo;
		} else if (lo <= UCONV_U8_TWO_BYTES) {
			if ((u8l + 1) >= *utf8len)
				return (E2BIG);
			u8s[u8l++] = (uchar_t)(0xc0 | ((lo & 0x07c0) >> 6));
			u8s[u8l++] = (uchar_t)(0x80 |  (lo & 0x003f));
		} else if (lo <= UCONV_U8_THREE_BYTES) {
			if ((u8l + 2) >= *utf8len)
				return (E2BIG);
			u8s[u8l++] = (uchar_t)(0xe0 | ((lo & 0x0f000) >> 12));
			u8s[u8l++] = (uchar_t)(0x80 | ((lo & 0x00fc0) >> 6));
			u8s[u8l++] = (uchar_t)(0x80 |  (lo & 0x0003f));
		} else if (lo <= UCONV_U8_FOUR_BYTES) {
示例#11
0
文件: uconv.c 项目: andreiw/polaris
int
uconv_u16tou32(const uint16_t *u16s, size_t *utf16len,
    uint32_t *u32s, size_t *utf32len, int flag)
{
	int inendian;
	int outendian;
	size_t u16l;
	size_t u32l;
	uint32_t hi;
	uint32_t lo;
	boolean_t do_not_ignore_null;

	/*
	 * Do preliminary validity checks on parameters and collect info on
	 * endians.
	 */
	if (u16s == NULL || utf16len == NULL)
		return (EILSEQ);

	if (u32s == NULL || utf32len == NULL)
		return (E2BIG);

	if (check_endian(flag, &inendian, &outendian) != 0)
		return (EBADF);

	/*
	 * Initialize input and output parameter buffer indices and
	 * temporary variables.
	 */
	u16l = u32l = 0;
	hi = 0;
	do_not_ignore_null = ((flag & UCONV_IGNORE_NULL) == 0);

	/*
	 * Check on the BOM at the beginning of the input buffer if required
	 * and if there is indeed one, process it.
	 */
	if ((flag & UCONV_IN_ACCEPT_BOM) &&
	    check_bom16(u16s, *utf16len, &inendian))
		u16l++;

	/*
	 * Reset inendian and outendian so that after this point, those can be
	 * used as condition values.
	 */
	inendian &= UCONV_IN_NAT_ENDIAN;
	outendian &= UCONV_OUT_NAT_ENDIAN;

	/*
	 * If there is something in the input buffer and if necessary and
	 * requested, save the BOM at the output buffer.
	 */
	if (*utf16len > 0 && *utf32len > 0 && (flag & UCONV_OUT_EMIT_BOM))
		u32s[u32l++] = (outendian) ? UCONV_BOM_NORMAL :
			UCONV_BOM_SWAPPED_32;

	/*
	 * Do conversion; if encounter a surrogate pair, assemble high and
	 * low pair values to form a UTF-32 character. If a half of a pair
	 * exists alone, then, either it is an illegal (EILSEQ) or
	 * invalid (EINVAL) value.
	 */
	for (; u16l < *utf16len; u16l++) {
		if (u16s[u16l] == 0 && do_not_ignore_null)
			break;

		lo = (uint32_t)((inendian) ? u16s[u16l] : BSWAP_16(u16s[u16l]));

		if (lo >= UCONV_U16_HI_MIN && lo <= UCONV_U16_HI_MAX) {
			if (hi)
				return (EILSEQ);
			hi = lo;
			continue;
		} else if (lo >= UCONV_U16_LO_MIN && lo <= UCONV_U16_LO_MAX) {
			if (! hi)
				return (EILSEQ);
			lo = (((hi - UCONV_U16_HI_MIN) * UCONV_U16_BIT_SHIFT +
				lo - UCONV_U16_LO_MIN) & UCONV_U16_BIT_MASK)
				+ UCONV_U16_START;
			hi = 0;
		} else if (hi) {
			return (EILSEQ);
		}

		if (u32l >= *utf32len)
			return (E2BIG);

		u32s[u32l++] = (outendian) ? lo : BSWAP_32(lo);
	}

	/*
	 * If high half didn't see low half, then, it's most likely the input
	 * parameter is incomplete.
	 */
	if (hi)
		return (EINVAL);

	/*
	 * Save the number of consumed and saved characters. They do not
	 * include terminating NULL character (U+0000) at the end of
	 * the input buffer (even when UCONV_IGNORE_NULL isn't specified and
	 * the input buffer length is big enough to include the terminating
	 * NULL character).
	 */
	*utf16len = u16l;
	*utf32len = u32l;

	return (0);
}
示例#12
0
int luaopen_luatobin(lua_State* L) {
    check_endian(&sendian);
    luaL_register(L, "luatobin", R);
    return 1;
}