//------------------------------------------------------------------------------ int settings_save(settings_t* s, const char* file) { int i; FILE* out; // Open settings file. out = fopen(file, "wt"); if (out == NULL) { return 0; } // Iterate over each setting and write it out to the file. for (i = 0; i < s->count; ++i) { const setting_decl_t* decl; decl = s->decls + i; fprintf(out, "# name: %s\n", decl->friendly_name); fprintf(out, "# type: %s\n", g_type_names[decl->type]); wrapped_write(out, "# ", decl->description, 78); fprintf(out, "%s = %s\n\n", decl->name, s->values[i]); } fclose(out); return 1; }
//------------------------------------------------------------------------------ static int print_value(const char* key) { const setting_decl_t* decl = settings_get_decl_by_name(g_settings, key); if (decl == NULL) { printf("ERROR: Setting '%s' not found.\n", key); return 1; } printf(" Name: %s\n", decl->name); printf("Friendly name: %s\n", decl->friendly_name); printf("Current value: %s\n", settings_get_str(g_settings, key)); puts(""); wrapped_write(stdout, "", decl->description, 78); return 0; }