void SavePrefToDB() { int i; for( i=0; i < N_DPY_PREFS; i++ ) XrmPutStringResource( &pref_db.db, pref_db.dpyPrefs[i].name, BoolToStr(pref_db.dpyPrefs[i].value ) ); for( i=0; i < N_CLI_PREFS; i++ ) XrmPutStringResource( &pref_db.db, pref_db.cliPrefs[i].name, BoolToStr(pref_db.cliPrefs[i].value ) ); for( i=0; i < N_WIN_PREFS; i++ ) XrmPutStringResource( &pref_db.db, pref_db.winPrefs[i].name, BoolToStr(pref_db.winPrefs[i].value ) ); for( i=0; i < N_PROP_PREFS; i++ ) XrmPutStringResource( &pref_db.db, pref_db.propPrefs[i].name, BoolToStr(pref_db.propPrefs[i].value ) ); for( i=0; i < N_TREE_PREFS; i++ ) XrmPutStringResource( &pref_db.db, pref_db.treePrefs[i].name, BoolToStr(pref_db.treePrefs[i].value ) ); }
/* ** CreatePreferencesDatabase ** ** Process a preferences file and the command line options pertaining to ** the X resources used to set those preferences. Create an X database ** of the results. The reason for this odd set of functionality is ** to process command line options before XtDisplayInitialize reads them ** into the application database that the toolkit attaches to the display. ** This allows command line arguments to properly override values specified ** in the preferences file. ** ** fileName Name only of the preferences file to be found ** in the user's home directory ** appName Application name to use in reading the preference ** resources ** opTable Xrm command line option table for the resources ** used in the preferences file ONLY. Command line ** options for other X resources should be processed ** by XtDisplayInitialize. ** nOptions Number of items in opTable ** argcInOut Address of argument count. This will be altered ** to remove the command line options that are ** recognized in the option table. ** argvInOut Argument vector. Will be altered as argcInOut. */ XrmDatabase CreatePreferencesDatabase(const char *fullName, const char *appName, XrmOptionDescList opTable, int nOptions, unsigned int *argcInOut, char **argvInOut) { XrmDatabase db; int argcCopy; char **argvCopy; char *fileString; static XrmOptionDescRec xrmOnlyTable[] = {{"-xrm", NULL, XrmoptionResArg, (caddr_t)NULL}}; /* read the preferences file into an X database. On failure prefDB will be NULL. */ if (NULL == fullName) { db = NULL; } else { fileString = ReadAnyTextFile(fullName, False); if (NULL == fileString) { db = NULL; } else { char* rsrcName; db = XrmGetStringDatabase(fileString); XtFree(fileString); /* Add a resource to the database which remembers that the file is read, so that NEdit will know it. */ rsrcName = (char*) XtMalloc(strlen(appName) + 14); sprintf(rsrcName, "%s.prefFileRead", appName); XrmPutStringResource(&db, rsrcName, "True"); XtFree(rsrcName); } } /* parse the command line, storing results in the preferences database */ XrmParseCommand(&db, opTable, nOptions, appName, (int *)argcInOut, argvInOut); /* process -xrm (resource setting by resource name) arguments so those pertaining to preference resources will be included in the database. Don't remove -xrm arguments from the argument vector, however, so XtDisplayInitialize can still read the non-preference resources */ argvCopy = (char**)XtMalloc(sizeof(char *) * *argcInOut); memcpy(argvCopy, argvInOut, sizeof(char *) * *argcInOut); argcCopy = *argcInOut; XrmParseCommand(&db, xrmOnlyTable, XtNumber(xrmOnlyTable), appName, &argcCopy, argvCopy); XtFree((char *)argvCopy); return db; }
bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) { char buffer[500]; (void) GetIniFile (buffer, file); XrmDatabase database; wxNode *node = wxResourceCache.Find (buffer); if (node) database = (XrmDatabase) node->Data (); else { database = XrmGetFileDatabase (buffer); wxResourceCache.Append (buffer, (wxObject *) database); } char resName[300]; strcpy (resName, section.c_str()); strcat (resName, "."); strcat (resName, entry.c_str()); XrmPutStringResource (&database, resName, value); return true; }
/* * Merge the resource `name' with a value specified by `fmt' into * the database `db' (if db == NULL, use m_user_db). */ void store_preference(XrmDatabase *db, const char *name, const char *fmt, ...) { size_t offset = strlen("xdvi."); size_t name_len = strlen(name); char *name_buf = xmalloc(name_len + offset + 1); char *buf = NULL; XrmDatabase tmp_db = NULL; if (db == NULL) db = &m_user_db; XDVI_GET_STRING_ARGP(buf, fmt); memcpy(name_buf, "xdvi.", offset); strcpy(name_buf + offset, name); TRACE_GUI((stderr, "storing resource: `%s: %s'", name_buf, buf)); XrmPutStringResource(&tmp_db, name_buf, buf); XrmMergeDatabases(tmp_db, db); free(buf); free(name_buf); }