10 #ifndef WIN32 // Goober5000
36 #define PROFILE_NAME "fs2_open.ini"
38 #define DEFAULT_SECTION "Default"
66 static char *read_line_from_file(FILE *
fp)
68 char *
buf, *buf_start;
81 if (fgets(buf_start, 80, fp) == NULL) {
82 if (buf_start == buf) {
91 len = strlen(buf_start);
93 if (buf_start[len-1] ==
'\n') {
102 buf_start = buf+(buflen-80)-(buflen/80)+1;
109 static char *trim_string(
char *str)
118 ptr = strchr(str,
';');
121 ptr = strchr(str,
'#');
131 while ((ptr > str) && isspace(*ptr)) {
141 while (*ptr && isspace(*ptr)) {
148 static Profile *profile_read(
char *file)
156 fp = fopen(fullname,
"rt");
169 while ((str = read_line_from_file(fp)) != NULL) {
170 char *ptr = trim_string(str);
175 char *pend = strchr(ptr,
']');
189 sp_ptr = &(sp->
next);
191 kvp_ptr = &(sp->
pairs);
199 ptr = strchr(ptr,
'=');
207 if (key && *key && value ) {
217 kvp_ptr = &(kvp->
next);
231 static void profile_free(
Profile *profile)
241 while (kvp != NULL) {
260 static Profile *profile_update(
Profile *profile,
const char *section,
const char *key,
const char *value)
262 if (profile == NULL) {
274 if (strcmp(section, sp->
name) == 0) {
278 while (kvp != NULL) {
279 if (strcmp(key, kvp->
key) == 0) {
283 *kvp_ptr = kvp->
next;
295 kvp_ptr = &(kvp->
next);
313 sp_ptr = &(sp->
next);
334 static char *profile_get_value(
Profile *profile,
const char *section,
const char *key)
342 if (strcmp(section, sp->
name) == 0) {
345 while (kvp != NULL) {
346 if (strcmp(key, kvp->
key) == 0) {
360 static void profile_save(
Profile *profile,
char *file)
372 fp = fopen(fullname,
"wt");
384 while (kvp != NULL) {
400 static char szCompanyName[128];
401 static char szAppName[128];
402 static char szAppVersion[128];
430 static char tmp_string_data[1024];
434 nprintf((
"Registry",
"os_config_read_string(): section = \"%s\", name = \"%s\", default value: \"%s\"\n",
435 (section) ? section :
DEFAULT_SECTION, name, (default_value) ? default_value :
NOX(
"NULL") ));
442 char *ptr = profile_get_value(p, section, name);
445 strncpy(tmp_string_data, ptr, 1023);
446 default_value = tmp_string_data;
451 return default_value;
461 char *ptr = profile_get_value(p, section, name);
464 default_value = atoi(ptr);
469 return default_value;
479 p = profile_update(p, section, name, value);
488 snprintf(buf, 20,
"%u", value);
495 p = profile_update(p, section, name, buf);
500 #endif // Goober5000 - #ifndef WIN32
const char * Osreg_app_name
GLsizei const GLfloat * value
const char * Osreg_user_dir
const char * Osreg_company_name
const char * detect_home(void)
GLenum GLuint GLenum GLsizei const GLchar * buf
const char * os_config_read_string(const char *section, const char *name, const char *default_value)
#define DIR_SEPARATOR_STR
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
void os_config_write_uint(const char *section, const char *name, unsigned int value)
const char * Osreg_class_name
GLuint const GLchar * name
#define vm_realloc(ptr, size)
unsigned int os_config_read_uint(const char *section, const char *name, unsigned int default_value)
void os_init_registry_stuff(const char *company, const char *app, const char *version)
void os_config_write_string(const char *section, const char *name, const char *value)
struct Section * sections