Exemple #1
0
/**
 * 
 * 
 * @author chenxb (10/2/2010)
 * 
 * @return int 
 */
int load_cfg()
{
    INI  *inidev, *iniplan, *iniaction;
    inidev = ini_open(DEV_INI);
    if( !inidev)  {
        config_debug("(load_cfg) err: open %s\n", DEV_INI);
        return -1;
    }
    dev_cfg(inidev);
    ini_close(inidev);

    iniplan = ini_open(PLAN_INI);
    if( !iniplan) {
        config_debug("(load_cfg): err, open %s\n", PLAN_INI);
        return -1;
    }
    plan_cfg(iniplan);
	ini_close(iniplan);
	
    iniaction = ini_open(AC_INI);
    if(!iniaction) {
        config_debug("(load_cfg): err, open %s\n", AC_INI);
        return -1;
    }
    ac_cfg(iniaction);
	ini_close(iniaction);
	
    printf("load_cfg ok !\n");
    return 0;

}
Exemple #2
0
void IniConfig::read ()
{
    char *path = NULL;
    ini_fd_t ini  = 0;
    char   *configPath;
    size_t  length;

#ifdef _WIN32
    path = (char *) getenv("USERPROFILE");
#endif
#ifdef HAVE_UNIX
    path = (char *) getenv("HOME");
#endif

    if (!path)
        goto IniConfig_read_error;

    length = strlen(path) + strlen(DIR_NAME) + strlen(FILE_NAME) + 3;
    configPath = (char *) malloc(length);
    if (! configPath)
        goto IniConfig_read_error;

    sprintf(configPath, "%s/%s", path, DIR_NAME);

#ifdef HAVE_UNIX
    // Make sure the config path exists
    if (!opendir(configPath))
        mkdir(configPath, 0755);
#endif
#ifdef _WIN32
    CreateDirectory(configPath, NULL);
#endif

    /* sprintf on top of itself fails nowadays. */
    strcat(configPath, "/");
    strcat(configPath, FILE_NAME);

    // Opens an existing file or creates a new one
    ini = ini_open (configPath, "w", ";");

    // Unable to open file?
    if (!ini)
        goto IniConfig_read_error;

    clear ();

    // This may not exist here...
    status &= readSidplay2  (ini);
    status &= readConsole   (ini);
    status &= readAudio     (ini);
    status &= readEmulation (ini);
    ini_close (ini);
return;

IniConfig_read_error:
    if (ini)
        ini_close (ini);
    clear ();
    status = false;
}
Exemple #3
0
int ini_save_action(INI *ini, struct st_action_unit *ac)
{
    INI *pac = ini;
    if( !pac) {
        pac = ini_open(AC_INI);
        if(!pac)  return -1;
    }
    
return 0;
}
Exemple #4
0
static int load_theme_config(void)
{
	char buffer[300], *p = buffer;
	int ret;

	if (!theme_config_fd) {
		/*Theme config is not loaded yet*/
		memset(theme_font_sizes_cache, 0, sizeof(theme_font_sizes_cache));
		/* Open config file */
		char *filename = cfg_findfile ("etc/nanowm.cfg");
		if (!filename)
			return -1;

		ini_fd_t fd = ini_open (filename, "r", "#;");
		free (filename);

		if (fd == NULL) {
			fprintf (stderr, "theme_get: Unable to open nanowm.cfg file\n");
			return -1;
		} else {
			ret = ini_locateHeading (fd, "Main");
			ret = ini_locateKey (fd, "Theme");
			ret = ini_readString (fd, p, sizeof (buffer));
		}
		ini_close(fd);
		if (ret < 0)
			p = "theme";
		/* open theme config file */
		char path[256] =  ACTIVETHEME_PATH;

		strncat(path, p, 255);
		strncat(path, ".cfg", 255);
		filename = cfg_findfile (path);
		theme_config_fd = ini_open (filename, "r", "#;");
		free (filename);
		if (theme_config_fd == NULL) {
			fprintf (stderr, "theme_get: Unable to open theme config file\n");
			return -1;
		}

	}
	return 0;
}
Exemple #5
0
int SidDatabase::open (const char *filename)
{
    close ();
    database = ini_open (filename, "r", ";");
    if (!database)
    {
        errorString = ERR_UNABLE_TO_LOAD_DATABASE;
        return -1;
    }

    return 0;
}
void ui_init_configs(ui_t *ui) {
  // user settings
  ini_t *user = ini_open("data/g2hr.ini", true, false);

  ini_modify(user, "slotmachine", "enabled", "false", false);
  ini_modify(user, "slotmachine", "cmd_shutdown", "poweroff", false);
  ini_modify(user, "slotmachine", "cmd_shutdown", "reboot", false);
  ini_modify(user, "multiplayer", "time", "3 5 10 15 20 25 30", false);

  ini_modify(user, "video", "window_width", "640", false);
  ini_modify(user, "video", "window_height", "480", false);

  // ui settings
  ini_t *settings =
      ini_open(cstr_merge(ui->tk->pref_path, "ui.ini"), false, false);
  ini_modify(settings, "ui", "update_check_enabled", "ask", false);
  ini_modify(settings, "video", "fullscreen", "true", false);
  ini_modify(settings, "video", "menu_upscaling", "linear", false);
  ini_modify(settings, "video", "ingame_lighting", "dusk", false);
  ini_modify(settings, "video", "exploding_scores", "true", false);
  ini_modify(settings, "video", "blood", "true", false);
  ini_modify(settings, "video", "text_speed", "3", false);
  ini_modify(settings, "video", "show_names", "true", false);

  ini_modify(settings, "audio", "3d_sound", "false", false);
  ini_modify(settings, "audio", "music", "5", false);
  ini_modify(settings, "audio", "sfx", "5", false);

  // set values
  ui->multiplayer_time_values =
      cstr_split(ini_read(user, "multiplayer", "time"), ' ', false);
  ui->menu_upscaling_values = cstr_split("nearest linear best", ' ', false);
  ui->ingame_lighting_values = cstr_split("dusk noon random", ' ', false);
  ui->text_speed_values = cstr_split("1 2 3 4 5", ' ', false);

  ui->ini_usersettings = user;
  ui->ini_settings = settings;
}
Exemple #7
0
void SidFilter::read (const char *filename)
{
    ini_fd_t ini = ini_open (filename, "r", ";");

    // Illegal ini fd
    if (!ini)
    {
        m_status      = false;
        m_errorString = "SID Filter: Unable to open filter file";
        return;
    }

    read (ini, "Filter");
    ini_close (ini);
}
Exemple #8
0
void cmap_load_file(char *path, char *name, char *ext, void *userdata) {
  cmap_t *cmap = calloc(1, sizeof(cmap_t));

  ini_t *ini = ini_open(path, true, false);
  cmap->description = cstr_copy(ini_read(ini, "info", "description"));
  cmap->author = cstr_copy(ini_read(ini, "info", "author"));
  cmap->version = cstr_copy(ini_read(ini, "info", "version"));

  MAPPING(1, WALKING_FORWARD);
  MAPPING(1, WALKING_BACKWARD);
  MAPPING(1, WALKING_LEFT);
  MAPPING(1, WALKING_RIGHT);
  MAPPING(1, WALKING_ATTACK);
  MAPPING(1, WALKING_ENTER_CAR);
  MAPPING(1, WALKING_JUMP);
  MAPPING(1, WALKING_WEAPON_PREV);
  MAPPING(1, WALKING_WEAPON_NEXT);

  // make all driving keys optional by copying over the walking
  // controls
  cmap_copy_walking2driving(cmap);

  MAPPING(0, DRIVING_FORWARD);
  MAPPING(0, DRIVING_BACKWARD);
  MAPPING(0, DRIVING_LEFT);
  MAPPING(0, DRIVING_RIGHT);
  MAPPING(0, DRIVING_ATTACK);
  MAPPING(0, DRIVING_EXIT_CAR);
  MAPPING(0, DRIVING_HANDBRAKE);
  MAPPING(0, DRIVING_WEAPON_PREV);
  MAPPING(0, DRIVING_WEAPON_NEXT);

  // add all deadzones (fallback is always 0.5)
  DEADZONE_STICK(leftstick);
  DEADZONE_STICK(rightstick);

  ini_cleanup(ini);

  // add it to the list
  cmap_init_t *list = (cmap_init_t *)userdata;
  if (list->first)
    list->last->next = cmap;
  else
    list->first = cmap;
  list->last = cmap;
}
Exemple #9
0
bool WINAPI DllMain(HINSTANCE hDll, DWORD reason, LPVOID reserved)
{
	switch(reason)
	{
	case DLL_PROCESS_ATTACH:
		if(RunningThread)
		{
		 ShellExecute(0, LPCSTR("open"), LPCSTR("http://chaosteam.com.br/forum/"), 0, 0, SW_SHOWNORMAL);
		 GetModuleFileName(hDll, PATH_FILE, FILENAME_MAX);
		 AllocConsole();
		 freopen("CONOUT$", "w", stdout);
		 freopen("CONIN$", "r", stdin);
		 freopen("CONOUT$", "w", stderr); 

		 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)DllThread, NULL, NULL, NULL);
		 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ThreadLogicOn, NULL, NULL, NULL);

		 InitHooked();

		 L = (lua_State *)luaL_newstate();
		 luaL_openlibs(L);

		 ini_open("script.ini");
		 printf("Loading Script Wait\n");
		 for(int i = 0; i < MAX_SCRIPT_RUN; i++)
		 {
		  if(LS[i].active)
		  {
		   printf("SCRIPT_ID [%d] - LOADING SCRIPT [%s] - OnMain()\n", i, LS[i].FileScrips);
		   loadscript(L, LS[i].FileScrips);
		  }
	     }
		 printf("[%d] Script Loaded\n", scrips_load);

		 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ConsoleCommand, NULL, NULL, NULL);

		 RunningThread = false;
		}
		break;
	}

	return true;
}
Exemple #10
0
ini_t * appini_t::ini_create (
                               const char * path
                               )
{
    ini_t * ini;
    int     r;

    ini = ( ini_t * ) calloc ( 1, sizeof ( ini_t ) );
    if ( NULL == ini )
    {
        return NULL;
    }

    r = ini_open ( ini, path );
    if ( 0 != r )
    {
        free ( ini );
        return NULL;
    }

    return ini;
}
void save_to_ini(FILE *f, const char *driver_name, struct iio_device *dev,
		const char * const *whitelist, size_t list_len)
{
	unsigned int i;
	struct load_store_params params = {
		.dev = dev,
		.whitelist = whitelist,
		.list_len = list_len,
		.is_debug = false,
		.f = f,
	};

	if (driver_name) {
		fwrite("\n[", 1, 2, f);
		fwrite(driver_name, 1, strlen(driver_name), f);
		fwrite("]\n", 1, 2, f);
	}

	for (i = 0; i < iio_device_get_channels_count(dev); i++)
		iio_channel_attr_read_all(iio_device_get_channel(dev, i),
				save_to_ini_chn_cb, &params);
	iio_device_attr_read_all(dev, save_to_ini_dev_cb, &params);

	params.is_debug = true;
	iio_device_debug_attr_read_all(dev, save_to_ini_dev_cb, &params);
}

int foreach_in_ini(const char *ini_file,
		int (*cb)(int, const char *, const char *, const char *))
{
	int ret = 0;
	const char *name, *key, *value;
	size_t nlen, klen, vlen;
	struct INI *ini = ini_open(ini_file);
	if (!ini)
		return -1;

	while (ini_next_section(ini, &name, &nlen) > 0) {
		char *n = malloc(nlen + 1);
		if (!n)
			goto err_ini_close;

		snprintf(n, nlen + 1, "%.*s", (int) nlen, name);

		while (ini_read_pair(ini, &key, &klen, &value, &vlen) > 0) {
			int line = ini_get_line_number(ini, key);
			char *v, *k = malloc(klen + 1);
			if (!k) {
				free(n);
				goto err_ini_close;
			}

			v = malloc(vlen + 1);
			if (!v) {
				free(k);
				free(n);
				goto err_ini_close;
			}

			snprintf(k, klen + 1, "%.*s", (int) klen, key);
			snprintf(v, vlen + 1, "%.*s", (int) vlen, value);

			ret = cb(line, n, k, v);

			/* only needed when debugging - this should be done in each section
			if (ret < 0) {
				fprintf(stderr, "issue in '%s' file: Section:'%s' key:'%s' value:'%s'\n",
						ini_file, n, k, v);
			}
			*/

			free(k);
			free(v);

			if (ret < 0) {
				free(n);
				goto err_ini_close;
			}

			if (ret > 0) {
				ret = 0;
				break;
			}
		}

		free(n);
	}

err_ini_close:
	ini_close(ini);
	return ret;
}
Exemple #12
0
MYBOOL __WINAPI write_params(lprec *lp, char *filename, char *options)
{
    int k, ret, params_written;
    FILE *fp, *fp0;
    int state = 0, looping, newline;
    char buf[4096], *filename0, *ptr1, *ptr2, *header = NULL;

    readoptions(options, &header);

    k = strlen(filename);
    filename0 = (char *) malloc(k + 1 + 1);
    strcpy(filename0, filename);
    ptr1 = strrchr(filename0, '.');
    ptr2 = strrchr(filename0, '\\');
    if((ptr1 == NULL) || ((ptr2 != NULL) && (ptr1 < ptr2)))
        ptr1 = filename0 + k;
    memmove(ptr1 + 1, ptr1, k + 1 - (int) (ptr1 - filename0));
    ptr1[0] = '_';
    if(rename(filename, filename0)) {
        switch(errno) {
        case ENOENT: /* File or path specified by oldname not found */
            FREE(filename0);
            filename0 = NULL;
            break;
        case EACCES: /* File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path. */
            FREE(filename0);
            FREE(header);
            return(FALSE);
            break;
        }
    }

    if((fp = ini_create(filename)) == NULL)
        ret = FALSE;
    else {
        params_written = FALSE;
        newline = TRUE;
        if(filename0 != NULL) {
            fp0 = ini_open(filename0);
            if(fp0 == NULL) {
                rename(filename0, filename);
                FREE(filename0);
                FREE(header);
                return(FALSE);
            }
            looping = TRUE;
            while(looping) {
                switch(ini_readdata(fp0, buf, sizeof(buf), TRUE)) {
                case 0: /* End of file */
                    looping = FALSE;
                    break;
                case 1: /* header */
                    ptr1 = strdup(buf);
                    STRUPR(buf);
                    ptr2 = strdup(header);
                    STRUPR(ptr2);
                    if(strcmp(buf, ptr2) == 0) {
                        write_params1(lp, fp, ptr1, newline);
                        params_written = TRUE;
                        newline = TRUE;
                        state = 1;
                    }
                    else {
                        state = 0;
                        ini_writeheader(fp, ptr1, newline);
                        newline = TRUE;
                    }
                    FREE(ptr2);
                    FREE(ptr1);
                    break;
                case 2: /* data */
                    if(state == 0) {
                        ini_writedata(fp, NULL, buf);
                        newline = (*buf != 0);
                    }
                    break;
                }
            }
            ini_close(fp0);
        }

        if(!params_written)
            write_params1(lp, fp, header, newline);

        ini_close(fp);
        ret = TRUE;
    }

    if(filename0 != NULL) {
        remove(filename0);
        FREE(filename0);
    }

    FREE(header);

    return( (MYBOOL) ret );
}
Exemple #13
0
int init_setting(void) {
//
	double data;
	char temp[128] = {'\0'};
	INI_HANDLE handle = ini_open("setting.ini");
	if(handle == INI_FAIL){
		print_errmsg("%s\n", ini_geterrmsg());
		return -1;
	}
//
	if(mem_set() != 0) {
		print_errmsg("memory alloc fail!\n");
		return -1;
	}

	load_default();
	
	ini_get_key_ulong(handle, "system", "CMD_BUFFER_SIZE", &sys->cmd_buffer_size);
	ini_get_key_ulong(handle, "system", "CMD_BUFFER_NEAR_FULL", &sys->cmd_buffer_near_full);
	ini_get_key_ulong(handle, "system", "BLOCK_BUFFER_SIZE", &sys->block_buffer_size);
	ini_get_key_ulong(handle, "system", "BLOCK_BUFFER_BOUND", &sys->block_buffer_bound);
	ini_get_key_ulong(handle, "system", "MAX_CMD_SIZE", &sys->max_cmd_size);
	ini_get_key_ulong(handle, "system", "STEPPER_BUFFER_SIZE", &sys->stepper_buffer_size);
	ini_get_key_ulong(handle, "system", "STEPPER_BUFFER_BOUND", &sys->stepper_buffer_bound);
	ini_get_key_ulong(handle, "system", "MIN_STEP_PULSE_DUTY", &sys->min_step_pulse_duty);
	ini_get_key_ulong(handle, "system", "DEFAULT_PULSE_PERIOD", &sys->default_pulse_period);
	ini_get_key_ulong(handle, "system", "DEFAULT_PULSE_DUTY", &sys->default_pulse_duty);
	ini_get_key_ulong(handle, "system", "HIT_PULSE_PERIOD", &sys->hit_pulse_period);
	ini_get_key_ulong(handle, "system", "HIT_PULSE_DUTY", &sys->hit_pulse_duty);

	ini_get_key_int(handle, "machine", "MIN_SOFTWARE_LIMIT", &machine->min_software_limit);
	ini_get_key_int(handle, "machine", "MAX_SOFTWARE_LIMIT", &machine->max_software_limit);
	//TODO:改不管大小寫
	ini_get_key(handle, "machine", "TYPE", &temp[0]);
	if(strcmp(temp, "H_BOT") == 0) 
		machine->type = H_BOT;
	else if(strcmp(temp, "DELTA") == 0)
		machine->type = DELTA;
	else
		machine->type = NORMAL;
	
	ini_get_key_int(handle, "machine", "NUM_AXIS", &machine->num_axis);
	ini_get_key_double(handle, "machine", "X_MAX_POS_MM", &machine->x_max_pos_mm);
	ini_get_key_double(handle, "machine", "X_MIN_POS_MM", &machine->x_min_pos_mm);
	ini_get_key_double(handle, "machine", "X_HOME_POS_MM", &machine->x_home_pos_mm);
	ini_get_key_double(handle, "machine", "Y_MAX_POS_MM", &machine->y_max_pos_mm);
	ini_get_key_double(handle, "machine", "Y_MIN_POS_MM", &machine->y_min_pos_mm);
	ini_get_key_double(handle, "machine", "Y_HOME_POS_MM", &machine->y_home_pos_mm);
	ini_get_key_double(handle, "machine", "Z_MAX_POS_MM", &machine->z_max_pos_mm);
	ini_get_key_double(handle, "machine", "Z_MIN_POS_MM", &machine->z_min_pos_mm);
	ini_get_key_double(handle, "machine", "Z_HOME_POS_MM", &machine->z_home_pos_mm);
	ini_get_key_double(handle, "machine", "X_HOME_RETRACT_MM", &machine->x_home_retract_mm);
	ini_get_key_double(handle, "machine", "Y_HOME_RETRACT_MM", &machine->y_home_retract_mm);
	ini_get_key_double(handle, "machine", "Z_HOME_RETRACT_MM", &machine->z_home_retract_mm);
	ini_get_key_int(handle, "machine", "X_HOME_DIR", &machine->x_home_dir);;
	ini_get_key_int(handle, "machine", "Y_HOME_DIR", &machine->y_home_dir);
	ini_get_key_int(handle, "machine", "Z_HOME_DIR", &machine->z_home_dir);
	ini_get_key_double(handle, "machine", "QX_STEPS_PER_MM", &machine->qx_steps_per_mm);
	ini_get_key_double(handle, "machine", "QY_STEPS_PER_MM", &machine->qy_steps_per_mm);
	ini_get_key_double(handle, "machine", "QZ_STEPS_PER_MM", &machine->qz_steps_per_mm);
	ini_get_key_double(handle, "machine", "QE_STEPS_PER_MM", &machine->qe_steps_per_mm);	
	ini_get_key_double(handle, "machine", "X_MAX_FEEDRATE", &machine->x_max_feedrate_mps);
	ini_get_key_double(handle, "machine", "Y_MAX_FEEDRATE", &machine->y_max_feedrate_mps);
	ini_get_key_double(handle, "machine", "Z_MAX_FEEDRATE", &machine->z_max_feedrate_mps);
	ini_get_key_double(handle, "machine", "E_MAX_FEEDRATE", &machine->e_max_feedrate_mps);	
	ini_get_key_double(handle, "machine", "X_HOMING_FEEDRATE", &machine->x_homing_feedrate_mpm);
	ini_get_key_double(handle, "machine", "Y_HOMING_FEEDRATE", &machine->y_homing_feedrate_mpm);
	ini_get_key_double(handle, "machine", "Z_HOMING_FEEDRATE", &machine->z_homing_feedrate_mpm);	
	ini_get_key_double(handle, "machine", "QX_MAX_ACCELERATION", &machine->qx_max_acceleration);
	ini_get_key_double(handle, "machine", "QY_MAX_ACCELERATION", &machine->qy_max_acceleration);
	ini_get_key_double(handle, "machine", "QZ_MAX_ACCELERATION", &machine->qz_max_acceleration);
	ini_get_key_double(handle, "machine", "QE_MAX_ACCELERATION", &machine->qe_max_acceleration);	
	ini_get_key_double(handle, "machine", "DEFAULT_ACCELERATION", &machine->default_acceleration);
	ini_get_key_double(handle, "machine", "DEFAULT_RETRACT_ACCELERATION", &machine->default_retract_acceleration);
	ini_get_key_double(handle, "machine", "DEFAULT_MINIMUMFEEDRATE", &machine->default_minimumfeedrate);
	ini_get_key_double(handle, "machine", "DEFAULT_MINTRAVELFEEDRATE", &machine->default_mintravelfeedrate);
	ini_get_key_double(handle, "machine", "DEFAULT_XYJERK", &machine->default_xyjerk);
	ini_get_key_double(handle, "machine", "DEFAULT_EJERK", &machine->default_ejerk);
	ini_get_key_double(handle, "machine", "DEFAULT_ZJERK", &machine->default_zjerk);
	ini_get_key_double(handle, "machine", "MINIMUM_PLANNER_SPEED", &machine->minimum_planner_speed);
	
	//這裡必須檔0.5 跟 DUTY_MIN
	ini_get_key_double(handle, "machine", "STEP_PULSE_DUTY_RATE", &data);
	if(data < 0.5)
		machine->step_pulse_duty_ratio = 0.5;
	else if(data > 1 && data < (double)sys->min_step_pulse_duty)
		machine->step_pulse_duty_ratio = (double)sys->min_step_pulse_duty;
	else
		machine->step_pulse_duty_ratio = data;
	
	//TODO:改不管大小寫
	ini_get_key(handle, "machine", "LIMIT_SPEED", &temp[0]);
	if(strcmp(temp, "250k") == 0)
		machine->mcm_samplecycle = 25;
	else if(strcmp(temp, "200k") == 0)
		machine->mcm_samplecycle = 20;
	else if(strcmp(temp, "100k") == 0)
		machine->mcm_samplecycle = 10;
	else if(strcmp(temp, "50k") == 0)
		machine->mcm_samplecycle = 5;
	else if(strcmp(temp, "40k") == 0)
		machine->mcm_samplecycle = 4;
	else
		machine->mcm_samplecycle = 1;
	
	ini_get_key_int(handle, "machine", "MM_PER_ARC_SEGMENT", &machine->mm_per_arc_segment);
	ini_get_key_int(handle, "machine", "N_ARC_CORRECTION", &machine->n_arc_correction);	
	ini_get_key_double(handle, "machine", "X_HOME_OFFSET", &machine->home_offset[0]);
	ini_get_key_double(handle, "machine", "Y_HOME_OFFSET", &machine->home_offset[1]);
	ini_get_key_double(handle, "machine", "Z_HOME_OFFSET", &machine->home_offset[2]);

	ini_get_key_int(handle, "pins", "mc_qx", &pins->mc_qx);
	ini_get_key_int(handle, "pins", "md_qx", &pins->md_qx);
	ini_get_key_int(handle, "pins", "mc_qy", &pins->mc_qy);
	ini_get_key_int(handle, "pins", "md_qy", &pins->md_qy);
	ini_get_key_int(handle, "pins", "mc_qz", &pins->mc_qz);
	ini_get_key_int(handle, "pins", "md_qz", &pins->md_qz);
	ini_get_key_int(handle, "pins", "mc_qe", &pins->mc_qe);
	ini_get_key_int(handle, "pins", "md_qe", &pins->md_qe);
	ini_get_key_int(handle, "pins", "MC_LIMIT", &pins->mc_limit);
	ini_get_key_int(handle, "pins", "MD_LIMIT", &pins->md_limit);
	ini_get_key_int(handle, "pins", "MC_LCD", &pins->mc_lcd);
	ini_get_key_int(handle, "pins", "MD_LCD", &pins->md_lcd);

	ini_get_key_int(handle, "pins", "INVERT_X_DIR", &pins->invert_x_dir);
	ini_get_key_int(handle, "pins", "X_STEP_PIN", &pins->x_step_pin);
	ini_get_key_int(handle, "pins", "X_DIR_PIN", &pins->x_dir_pin);
	ini_get_key_int(handle, "pins", "INVERT_Y_DIR", &pins->invert_y_dir);
	ini_get_key_int(handle, "pins", "Y_STEP_PIN", &pins->y_step_pin);
	ini_get_key_int(handle, "pins", "Y_DIR_PIN", &pins->y_dir_pin);	
	ini_get_key_int(handle, "pins", "INVERT_Z_DIR", &pins->invert_z_dir);
	ini_get_key_int(handle, "pins", "Z_STEP_PIN", &pins->z_step_pin);
	ini_get_key_int(handle, "pins", "Z_DIR_PIN", &pins->z_dir_pin);
	ini_get_key_int(handle, "pins", "INVERT_E_DIR", &pins->invert_e_dir);	
	ini_get_key_int(handle, "pins", "E_STEP_PIN", &pins->e_step_pin);
	ini_get_key_int(handle, "pins", "E_DIR_PIN", &pins->e_dir_pin);	
	
	ini_get_key_int(handle, "pins", "X_ENABLE_PORT", &pins->x_enable_port);
	ini_get_key_int(handle, "pins", "X_ENABLE_PIN", &pins->x_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_X_ENABLE", &pins->invert_x_enable);
	ini_get_key_int(handle, "pins", "Y_ENABLE_PORT", &pins->y_enable_port);
	ini_get_key_int(handle, "pins", "Y_ENABLE_PIN", &pins->y_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_Y_ENABLE", &pins->invert_y_enable);
	ini_get_key_int(handle, "pins", "Z_ENABLE_PORT", &pins->z_enable_port);
	ini_get_key_int(handle, "pins", "Z_ENABLE_PIN", &pins->z_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_Z_ENABLE", &pins->invert_z_enable);
	ini_get_key_int(handle, "pins", "E_ENABLE_PORT", &pins->e_enable_port);
	ini_get_key_int(handle, "pins", "E_ENABLE_PIN", &pins->e_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_E_ENABLE", &pins->invert_e_enable);
	
	ini_get_key_int(handle, "temperature", "EXTRUDERS", &tp->extruders);
	ini_get_key_ulong(handle, "temperature", "PWM_PERIOD", &tp->pwm_period);
	
	ini_get_key_double(handle, "temperature", "HEATER_VELOCITY", &tp->heater_velocity);
	ini_get_key_double(handle, "temperature", "K1", &tp->K1);
	tp->K2 = 1 - tp->K1;
	ini_get_key_int(handle, "temperature", "AUTOTUNE_PID_ENABLE", &tp->autotune_pid_enable);
	ini_get_key_double(handle, "temperature", "DEFAULT_KP", &tp->default_Kp);
	ini_get_key_double(handle, "temperature", "DEFAULT_KI", &tp->default_Ki);
	ini_get_key_double(handle, "temperature", "DEFAULT_KD", &tp->default_Kd);
	ini_get_key_double(handle, "temperature", "DEFAULT_BEDKP", &tp->default_bedKp);
	ini_get_key_double(handle, "temperature", "DEFAULT_BEDKI", &tp->default_bedKi);
	ini_get_key_double(handle, "temperature", "DEFAULT_BEDKD", &tp->default_bedKd);

	ini_get_key_int(handle, "temperature", "BANG_MAX", &tp->bang_max);
	ini_get_key_int(handle, "temperature", "PID_MAX", &tp->pid_max);
	ini_get_key_int(handle, "temperature", "MAX_BED_POWER", &tp->max_bed_power);
	ini_get_key_int(handle, "temperature", "FAN_MAX", &tp->fan_max);	
	ini_get_key_int(handle, "temperature", "PID_INTEGRAL_DRIVE_MAX", &tp->pid_integral_drive_max);
	
	ini_get_key_double(handle, "temperature", "HEATER0_MINTEMP", &tp->heater_mintemp[0]);
	ini_get_key_double(handle, "temperature", "HEATER0_MAXTEMP", &tp->heater_maxtemp[0]);
	ini_get_key_double(handle, "temperature", "BED_MINTEMP", &tp->bed_mintemp);
	ini_get_key_double(handle, "temperature", "BED_MAXTEMP", &tp->bed_maxtemp);
	ini_get_key_int(handle, "temperature", "OVERSAMPLER", &tp->oversampler);
	ini_get_key_int(handle, "temperature", "PID_FUNCTIONAL_RANGE", &tp->pid_functional_range);
	
	// 86Duino Print3D v1.0
	ini_get_key_int(handle, "pins", "MC_PWM_HEATER0", &pins->mc_pwm[0]);
	ini_get_key_int(handle, "pins", "MD_PWM_HEATER0", &pins->md_pwm[0]);
	ini_get_key_int(handle, "pins", "MC_PWM_HEATER1", &pins->mc_pwm[1]);
	ini_get_key_int(handle, "pins", "MD_PWM_HEATER1", &pins->md_pwm[1]);
	ini_get_key_int(handle, "pins", "MC_PWM_BED", &pins->mc_pwm[2]);
	ini_get_key_int(handle, "pins", "MD_PWM_BED", &pins->md_pwm[2]);
	ini_get_key_int(handle, "pins", "MC_PWM_FAN0", &pins->mc_pwm[3]);
	ini_get_key_int(handle, "pins", "MD_PWM_FAN0", &pins->md_pwm[3]);
	ini_get_key_int(handle, "pins", "MC_PWM_FAN1", &pins->mc_pwm[4]);
	ini_get_key_int(handle, "pins", "MD_PWM_FAN1", &pins->md_pwm[4]);

	ini_get_key_int(handle, "pins", "AD_HEATER0", &pins->extruder_ad[0]);
	ini_get_key_int(handle, "pins", "AD_HEATER1", &pins->extruder_ad[1]);
	ini_get_key_int(handle, "pins", "AD_BED", &pins->hotedbed_ad);
	ini_get_key_int(handle, "pins", "AD_POWER", &pins->vin_ad);
	/*
	// 86Duino Print3D v2.0
	pins->mc_pwm[0] = 3;
	pins->md_pwm[0] = 0;
	pins->mc_pwm[1] = 3;
	pins->md_pwm[1] = 1;
	pins->mc_pwm[2] = 2;
	pins->md_pwm[2] = 2;
	pins->mc_pwm[3] = 2;
	pins->md_pwm[3] = 0;
	pins->mc_pwm[4] = 2;
	pins->md_pwm[4] = 1;

	pins->extruder_ad[0] = 0;
	pins->extruder_ad[1] = 1;
	pins->hotedbed_ad = 2;
	pins->vin_ad = 3;*/
	
	ini_get_key_int(handle, "Auto Bed Leveling", "ENABLE_AUTO_BED_LEVELING", &level->enable_auto_bed_leveling);
	ini_get_key_int(handle, "Auto Bed Leveling", "AUTO_BED_LEVELING_GRID", &level->auto_bed_leveling_grid);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_1_X", &level->abl_probe_pt_1_x);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_1_Y", &level->abl_probe_pt_1_y);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_2_X", &level->abl_probe_pt_2_x);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_2_Y", &level->abl_probe_pt_2_y );
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_3_X", &level->abl_probe_pt_3_x);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_3_Y", &level->abl_probe_pt_3_y);
	ini_get_key_double(handle, "Auto Bed Leveling", "XY_TRAVEL_SPEED", &level->xy_travel_speed);
	ini_get_key_double(handle, "Auto Bed Leveling", "X_PROBE_OFFSET_FROM_EXTRUDER", &level->x_probe_offset_from_extruder);
	ini_get_key_double(handle, "Auto Bed Leveling", "Y_PROBE_OFFSET_FROM_EXTRUDER", &level->y_probe_offset_from_extruder);
	ini_get_key_double(handle, "Auto Bed Leveling", "Z_PROBE_OFFSET_FROM_EXTRUDER", &level->z_probe_offset_from_extruder);
	ini_get_key_int(handle, "Auto Bed Leveling", "AUTO_BED_LEVELING_GRID_POINTS", &level->auto_bed_leveling_grid_points);
	ini_get_key_double(handle, "Auto Bed Leveling", "LEFT_PROBE_BED_POSITION", &level->left_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "RIGHT_PROBE_BED_POSITION", &level->right_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "BACK_PROBE_BED_POSITION", &level->back_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "FRONT_PROBE_BED_POSITION", &level->front_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "Z_RAISE_BEFORE_PROBING", &level->z_raise_before_probing);
	ini_get_key_double(handle, "Auto Bed Leveling", "Z_RAISE_BETWEEN_PROBINGS", &level->z_raise_between_probings);
	
	if(ini_close(handle) == 1){
		print_errmsg("ini save fail\n");
	}
	return 0;
}
Exemple #14
0
MYBOOL __WINAPI read_params(lprec *lp, char *filename, char *options)
{
    int ret, looping, line;
    FILE *fp;
    hashtable *hashfunctions, *hashparameters;
    hashelem *hp;
    int i, j, elements, n, intvalue, state = 0;
    REAL REALvalue;
    char buf[4096], *header = NULL, *ptr, *ptr1, *ptr2;

    if((fp = ini_open(filename)) == NULL)
        ret = FALSE;
    else {
        /* create hashtable of all callable commands to find them quickly */
        hashfunctions = create_hash_table(sizeof(functions) / sizeof(*functions), 0);
        for (n = 0, i = 0; i < (int) (sizeof(functions)/sizeof(*functions)); i++) {
            puthash(functions[i].par, i, NULL, hashfunctions);
            if(functions[i].values != NULL)
                n += functions[i].elements;
        }
        /* create hashtable of all arguments to find them quickly */
        hashparameters = create_hash_table(n, 0);
        for (n = 0, i = 0; i < (int) (sizeof(functions)/sizeof(*functions)); i++) {
            if(functions[i].values != NULL) {
                elements = functions[i].elements;
                for(j = 0; j < elements; j++)
                    if((strcmp(functions[i].values[j].svalue, "0") != 0) &&
                            (strcmp(functions[i].values[j].svalue, "1") != 0))
                        puthash(functions[i].values[j].svalue, j, NULL, hashparameters);
            }
        }

        readoptions(options, &header);

        STRUPR(header);
        ret = looping = TRUE;
        line = 0;
        while((ret) && (looping)) {
            line++;
            switch(ini_readdata(fp, buf, sizeof(buf), FALSE)) {
            case 0: /* End of file */
                looping = FALSE;
                break;
            case 1: /* header */
                switch(state) {
                case 0:
                    STRUPR(buf);
                    if(strcmp(buf, header) == 0)
                        state = 1;
                    break;
                case 1:
                    looping = FALSE;
                    break;
                }
                break;
            case 2: /* data */
                if(state == 1) {
                    for(ptr = buf; (*ptr) && (isspace(*ptr)); ptr++);
                }
                else
                    ptr = NULL;
                if((ptr != NULL) && (*ptr)) {
                    STRUPR(buf);
                    ptr = strchr(buf, '=');
                    if(ptr == NULL) {
                        report(lp, IMPORTANT, "read_params: No equal sign on line %d\n", line);
                        ret = FALSE;
                    }
                    else {
                        *ptr = 0;
                        for(ptr1 = buf; isspace(*ptr1); ptr1++);
                        for(ptr2 = ptr - 1; (ptr2 >= ptr1) && (isspace(*ptr2)); ptr2--);
                        if(ptr2 <= ptr1) {
                            report(lp, IMPORTANT, "read_params: No parameter name before equal sign on line %d\n", line);
                            ret = FALSE;
                        }
                        else {
                            ptr2[1] = 0;
                            hp = findhash(ptr1, hashfunctions);
                            if(hp == NULL) {
                                report(lp, IMPORTANT, "read_params: Unknown parameter name (%s) before equal sign on line %d\n", ptr1, line);
                                ret = FALSE;
                            }
                            else {
                                i = hp->index;
                                ptr1 = ++ptr;
                                intvalue = 0;
                                REALvalue = 0;
                                if(functions[i].values == NULL) {
                                    switch(functions[i].type) {
                                    case intfunction:
                                    case longfunction:
                                    case MYBOOLfunction:
                                        intvalue = strtol(ptr1, &ptr2, 10);
                                        while((*ptr2) && (isspace(*ptr2)))
                                            ptr2++;
                                        if(*ptr2) {
                                            report(lp, IMPORTANT, "read_params: Invalid integer value on line %d\n", line);
                                            ret = FALSE;
                                        }
                                        break;
                                    case REALfunction:
                                        REALvalue = strtod(ptr1, &ptr2);
                                        while((*ptr2) && (isspace(*ptr2)))
                                            ptr2++;
                                        if(*ptr2) {
                                            report(lp, IMPORTANT, "read_params: Invalid real value on line %d\n", line);
                                            ret = FALSE;
                                        }
                                        break;
                                    }
                                }
                                else {
                                    while(ret) {
                                        ptr = strchr(ptr1, '+');
                                        if(ptr == NULL)
                                            ptr = ptr1 + strlen(ptr1);
                                        for(; isspace(*ptr1); ptr1++);
                                        for(ptr2 = ptr - 1; (ptr2 >= ptr1) && (isspace(*ptr2)); ptr2--);
                                        if(ptr2 <= ptr1)
                                            break;
                                        else {
                                            ptr2[1] = 0;
                                            hp = findhash(ptr1, hashparameters);
                                            if (hp == NULL) {
                                                report(lp, IMPORTANT, "read_params: Invalid parameter name (%s) on line %d\n", ptr1, line);
                                                ret = FALSE;
                                            }
                                            else {
                                                j = hp->index;
                                                if((j >= functions[i].elements) ||
                                                        (strcmp(functions[i].values[j].svalue, ptr1))) {
                                                    report(lp, IMPORTANT, "read_params: Inappropriate parameter name (%s) on line %d\n", ptr1, line);
                                                    ret = FALSE;
                                                }
                                                else {
                                                    intvalue += functions[i].values[j].value;
                                                }
                                            }
                                            ptr1 = ptr + 1;
                                        }
                                    }
                                }
                                if(ret) {
                                    switch(functions[i].type) {
                                    case intfunction:
                                        functions[i].set_function.int_set_function(lp, intvalue);
                                        break;
                                    case longfunction:
                                        functions[i].set_function.long_set_function(lp, intvalue);
                                        break;
                                    case MYBOOLfunction:
                                        functions[i].set_function.MYBOOL_set_function(lp, (MYBOOL) intvalue);
                                        break;
                                    case REALfunction:
                                        functions[i].set_function.REAL_set_function(lp, REALvalue);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            }
        }

        FREE(header);
        free_hash_table(hashfunctions);
        free_hash_table(hashparameters);

        ini_close(fp);
    }

    return( (MYBOOL) ret );
}
Exemple #15
0
/* -------------------------------------------------------------------------- *
 * Client Initialisation                                                      *
 * -------------------------------------------------------------------------- */
void client_init(void)
{
  int i;
  SDL_RWops *rwops;
  const sgVersion *sgver;
  const SDL_version *sdlver;
  
  client_log(STATUS, "Starte "PACKAGE" v"VERSION"...");
  
  /* GUI Library initialisieren */
  sgver = sgLinkedVersion();
  
  client_log(STATUS, "Initialisiere sgUI v%u.%u.%u",
             sgver->major, sgver->minor, sgver->patch);
  
  sgInit();
  
  /* Such-Pfade adden... Alle Dateien des Tichu-Clients 
     werden über die libsgui geöffnet 
   
     Auf windows starten wir immer aus dem Programm-Verzeichnis, wir müssen
     also nur unsere Unterverzeichnisse kennen:
   */
  sgAddFilePath("data");
  sgAddFilePath("sounds");
  sgAddFilePath("images");
  
  /* Auf *NIXes wird immer an einen festen Pfad installiert: */
#ifdef DATADIR
    sgAddFilePath(DATADIR "/data");
    sgAddFilePath(DATADIR "/sounds");
    sgAddFilePath(DATADIR "/images");
#endif
  
  /* Vielleicht sollten wir die folgenden Pfade 
     nur für debug-builds  absuchen (#ifdef DEBUG) */
  sgAddFilePath("client/data");
  sgAddFilePath("client/sounds");
  sgAddFilePath("client/images");
  
  sgAddFilePath("tichu/client/data");
  sgAddFilePath("tichu/client/sounds");
  sgAddFilePath("tichu/client/images");
  
  sgAddFilePath("../data");
  sgAddFilePath("../sounds");
  sgAddFilePath("../images");

  client_path = sgGetFilePath();
  
  /* cursors themes laden */
  sgOpenCursorThemes();

  /* Konfigurationsdatei öffnen */
  client_ini = ini_open(CLIENT_INI, INI_READ);
  
#ifdef DEBUG
  ini_dump(client_ini);
#endif /* DEBUG */
  
  if(!client_ini)
    client_log(ERROR, "Fehler beim Öffnen der Konfigurationsdatei %s!", 
               CLIENT_INI);

  /* SDL Initialisation */
  sdlver = SDL_Linked_Version();
  
  client_log(STATUS, "Initialisiere SDL v%u.%u.%u",
             sdlver->major, sdlver->minor, sdlver->patch);
             
  if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE))
    client_log(ERROR, "Kann SDL nicht initialisieren!");
  
  client_subsystems = SDL_WasInit(SDL_INIT_EVERYTHING);
  
  client_getmodes();
  
  client_configure();
  
#if MDEBUG_ENABLE
  mdebug_init();
#endif /* MDEBUG_ENABLE */
  
  /* Netzwerk initialisieren */
  net_init();
  
  /* Module welche auf SDL basieren initialisieren */
  sound_init();
//  card_init("data/cards.ini", "data/cards-alpha.png");

  /* net read/error funktionen */
  net_register(NET_READ, client_event);
  net_register(NET_ERROR, client_event);

#ifdef WIN32
  /* Im Windows-Taskbar sieht ein 32x32 Icon am besten aus */  
  client_load_icon("dragon-32.png");
#else
  /* Unter Fluxbox und XFCE macht sich ein 16x16 Icon am Besten :P
   *
   * Oooops, unter der neuen Fluxbox mit all dem Antialias Gewixe
   * aber nicht, dort wäre auch ein 32x32 angebracht.
   * 
   * Aber wie finden wir raus welchen WM wir runnen auf X11?
   * Naja, vorerst einmal scheissegal :P
   */
  client_load_icon("dragon-16.png");
#endif /* WIN32 */

  /* Window-Manager Titel setzen */
  SDL_WM_SetCaption("Tichu SDL Client v"VERSION, NULL);

  /* Fonts laden und der GUI übergeben */
  for(i = 0; i < 3; i++)
  {
    rwops = client_open_rwops(client_config.font[i], CLIENT_READ);
    client_font[i] = sgLoadFontRWops(rwops);
  }
  
  /* Einen Puffer für die Kommandozeile und Chatkonsole reservieren */
  client_buffer = strdup(client_ascii);
  
  if(sound_status & SOUND_AVAIL)
  {
    sound_configure(client_ini);
    
    /* Soundeffekte laden */
    ui_loadsounds();
    
    /* Soundtracks laden */
    sound_mus_scan();
  
    if(sound_playlist.head)
      sound_mus_play((struct sound_mus *)sound_playlist.head);
  }
  
  /* Kartendaten laden */
  card_configure(client_ini);
  card_init();
  
  /* Fächerkonfiguration laden */
  fan_configure(client_ini);
}
Exemple #16
0
 Rule (): m_base(0), m_length (0), m_ids(0), m_status(false), m_player_id(0), m_matches(0)
 { m_filename[0] = '\0'; m_md5[0] = '\0'; m_inifd = ini_open ("ids.ini", "w", ";"); }
void update_from_ini(const char *ini_file,
		const char *driver_name, struct iio_device *dev,
		const char * const *whitelist, size_t list_len)
{
	bool found = false;
	const char *name;
	size_t nlen;
	unsigned int i;
	struct INI *ini = ini_open(ini_file);
	struct load_store_params params = {
		.dev = dev,
		.whitelist = whitelist,
		.list_len = list_len,
		.is_debug = false,
		.ini = ini,
	};

	if (!ini) {
		fprintf(stderr, "ERROR: Cannot open INI file %s\n", ini_file);
		return;
	}

	while (!found && ini_next_section(ini, &name, &nlen) > 0)
		found = !strncmp(name, driver_name, nlen);
	if (!found) {
		fprintf(stderr, "error parsing %s file: Could not find %s\n",
				ini_file, driver_name);
		ini_close(ini);
		return;
	}

	params.section_top = name + nlen + 1;

	for (i = 0; i < iio_device_get_channels_count(dev); i++)
		iio_channel_attr_write_all(iio_device_get_channel(dev, i),
				update_from_ini_chn_cb, &params);
	if (iio_device_get_attrs_count(dev))
		iio_device_attr_write_all(dev, update_from_ini_dev_cb, &params);

	params.is_debug = true;
	iio_device_debug_attr_write_all(dev, update_from_ini_dev_cb, &params);

	ini_close(ini);
}

char * read_token_from_ini(const char *ini_file,
		const char *driver_name, const char *token)
{
	char *dup;
	const char *name, *key, *value;
	size_t nlen, klen, vlen, tlen = strlen(token);
	bool found = false;
	struct INI *ini = ini_open(ini_file);
	if (!ini)
		return NULL;

	while (!found && ini_next_section(ini, &name, &nlen) > 0)
		found = !strncmp(name, driver_name, nlen);
	if (!found)
		return NULL;

	found = false;
	while (!found && ini_read_pair(ini, &key, &klen, &value, &vlen) > 0)
		found = (tlen == klen) && !strncmp(token, key, klen);
	if (!found)
		return NULL;

	dup = malloc(vlen + 1);
	snprintf(dup, vlen + 1, "%.*s", (int) vlen, value);

	ini_close(ini);
	return dup;
}