void Blackbox::timeout(bt::Timer *) { XrmDatabase new_blackboxrc = (XrmDatabase) 0; std::string style = "session.styleFile: "; style += _resource.styleFilename(); XrmPutLineResource(&new_blackboxrc, style.c_str()); XrmDatabase old_blackboxrc = XrmGetFileDatabase(_resource.rcFilename()); XrmMergeDatabases(new_blackboxrc, &old_blackboxrc); XrmPutFileDatabase(old_blackboxrc, _resource.rcFilename()); if (old_blackboxrc) XrmDestroyDatabase(old_blackboxrc); std::for_each(menuTimestamps.begin(), menuTimestamps.end(), bt::PointerAssassin()); menuTimestamps.clear(); std::for_each(screen_list, screen_list + screen_list_count, std::mem_fun(&BScreen::reconfigure)); bt::Font::clearCache(); bt::PixmapCache::clearCache(); bt::Pen::clearCache(); // clear the color cache here to allow the pen cache to deallocate // all unused colors bt::Color::clearCache(); }
void wxFlushResources (void) { char nameBuffer[512]; wxNode *node = wxResourceCache.First (); while (node) { const char *file = node->GetKeyString(); // If file doesn't exist, create it first. (void)GetResourcePath(nameBuffer, file, true); XrmDatabase database = (XrmDatabase) node->Data (); XrmPutFileDatabase (database, nameBuffer); XrmDestroyDatabase (database); wxNode *next = node->Next (); delete node; node = next; } }
void SavePrefDBtoFile() { /* printf( "options saved\n" ); */ SavePrefToDB(); XrmPutFileDatabase( pref_db.db, rcfile ); }
/*-------------------------------------------------------------------------*/ int main( int argc, char **argv ) { Widget StartupWindow = 0; Arg args[10]; Cardinal ac = 0; #ifdef L10N char *lang; #endif /* static char app_name[1024]; */ int i; XrmDatabase qmon_database; static char progname[256]; DENTER_MAIN(TOP_LAYER, "qmon_main"); #ifndef L10N setlocale(LC_ALL, "C"); putenv("LANG=C"); putenv("LC_ALL=C"); #endif /* INSTALL SIGNAL HANDLER */ qmonInstSignalHandler(); strcpy(progname, argv[0]); /* GENERAL SGE SETUP */ if (!(argc > 1 && !strcmp(argv[1], "-help"))) { qmonInitSge(&ctx, progname, 0); } else { /* -help */ qmonInitSge(&ctx, progname, 1); } SGE_ROOT = ctx->get_sge_root(ctx); /* ** Attention !!! Change the XtMalloc() above if you add additional args */ ac = 0; XtSetArg(args[ac], XmtNconfigDir, SGE_ROOT); ac++; XtSetArg(args[ac], XmtNconfigPath, "%R/locale/%L/%N%S:%R/locale/%l/%N%S:%R/locale/%l_%t.%c/%N%S:%R/qmon/%N%S"); ac++; /* XtSetArg(args[ac], XmtNpixmapFilePath, "%R/qmon/PIXMAPS/%N.xpm"); ac++; */ /* XtSetArg(args[ac], XmtNcontextHelpFile, "qmon_help"); ac++; */ XtSetArg(args[ac], XtNtitle, "QMON +++ Main Control"); ac++; /* ** SETUP XMT, here qmon_version is checked, ** so here an exit is possible */ AppShell = XmtInitialize( &AppContext, APP_NAME, NULL, 0, &argc, argv, qmon_fallbacks, args, ac); sigint_id = XtAppAddSignal(AppContext, sigint_callback, NULL); #if 0 /* ** protocoll the actions performed by qmon */ XtAppAddActionHook(AppContext, TraceActions, NULL); #endif #ifdef L10N /* ** Internationalization: ** The qmon_messages.ad file is installed under ** $SGE_ROOT/qmon/locale/<LANG>/qmon_messages.ad ** Read in the _Messages_ catalogue */ if (((lang = getenv("LC_MESSAGES")) || (lang = getenv("LC_ALL")) || (lang = getenv("LANG"))) && lang && strcasecmp(lang, "POSIX") && strcasecmp(lang, "C")) { DPRINTF(("lang: '%s'\n", lang)); if (!strcasecmp(lang, "relabel")) lang = "C"; XmtLoadResourceFile(AppShell, "qmon_messages", False, True); } #endif #if 0 strcpy(app_name, "QMON +++ Main Control"); if (strcmp(uti_state_get_default_cell(), "default")) { strcat(app_name, " @ "); strncat(app_name, uti_state_get_default_cell(), 1000); } XtVaSetValues(AppShell, XtNtitle, XmtLocalize(AppShell, app_name, "QMON +++ Main Control"), NULL); #endif XtVaSetValues(AppShell, XtNtitle, XmtLocalize(AppShell, "QMON +++ Main Control", "QMON +++ Main Control"), NULL); /* ** we must shift the usage here for internationalization */ if (helpset) { qmonUsage(AppShell); qmonExitFunc(0); } /* ** get the dialog resource files, they override any settings from the ** Qmon app default file concerning dialogue descriptions */ qmon_database = XtDatabase(XtDisplay(AppShell)); for (i=0; qmon_dialogs[i]; i++) { XrmPutLineResource(&qmon_database, qmon_dialogs[i]); } #if 0 /* ** Debugging: ** write contents of Resource DB to file DB.TXT in cwd */ XrmPutFileDatabase(qmon_database, "DB.TXT"); #endif /* ** read qmon preferences file ~/.qmon_preferences, it contains ** customization info for Queue and Job Control dialogues */ qmonReadPreferences(); /* ** display of startup screen ? */ if (!nologo) { /* show the user we're starting up */ StartupWindow = qmonStartupWindow(AppShell); } /* ** INITIALIZE Graphics Contexts */ qmonCreateGC(AppShell); /* ** Allocate Pixel values */ qmonAllocColor(AppShell); /* ** Cache all Icons */ qmonLoadIcons(); /* ** set the close button callback ** cause the close button to call the qmonExitCB() ** set the icon and iconName after qmonLoadIcons() */ XmtCreatePixmapIcon(AppShell, qmonGetIcon("mcicon"), None); XtVaSetValues(AppShell, XtNiconName, "qmon:Main Control", NULL); XmtAddDeleteCallback(AppShell, XmDO_NOTHING, qmonExitCB, NULL); /* ** CREATE MainControl */ MainControl = qmonCreateMainControl(AppShell); /* ** install context help */ XmtHelpInstallContextHelp(AppShell, XmtHelpContextHelpCallback, NULL); /* XmtHelpParseFile(AppShell, "qmon_help"); */ /* ** initialize QmonMirrorList entries */ qmonMirrorListInit(); /* ** setup timers */ qmonStartPolling(AppContext); #ifdef HAS_EDITRES /* ** Plug in editres protocol handler */ XtAddEventHandler (AppShell, (EventMask)0, True, _XEditResCheckMessages, (XtPointer)NULL); #endif /* ** Popdown startup screen and destroy it */ if (!nologo) { sleep(1); XtDestroyWidget(StartupWindow); } XtRealizeWidget(AppShell); XtAppMainLoop(AppContext); return 0; }
/* Save user preferences to ~/.xdvirc. If `backup_only' is True, it only writes to ~/.xdvirc.tmp and does not remove this temporary file (this is used for synchronization between several xdvi instances). */ Boolean save_user_preferences(Boolean full_save) { char testbuf[1024]; char *xdvirc_name; char *tmpname; FILE *from_fp, *to_fp; int fd; if (resource.no_init_file || m_user_db == NULL) /* nothing to do */ return True; if (resource.remember_windowsize) save_geometry(); xdvirc_name = get_xdvirc_path(xdvirc_filename); if ((to_fp = fopen(xdvirc_name, "r")) != NULL) { TRACE_GUI((stderr, "~/.xdvirc exists, checking file contents ...")); if (fgets(testbuf, 1024, to_fp) != NULL && memcmp(testbuf, xdvirc_signature_line, strlen(xdvirc_signature_line)) != 0) { popup_message(globals.widgets.top_level, MSG_WARN, "Xdvi uses the file ~/.xdvirc to save the preferences set via " "the menu bar or the preferences dialog (in the Motif version only). " "To avoid overwriting files created by the user, the first line of the " "file is compared with a special signature line. If that signature line " "is not found, the preferences won't be written. Your file doesn't seem " "to contain that signature line. You should move the file to a safe location, " "and then try to quit xdvi again.", /* message */ "The file `%s' was apparently not written by xdvi(k). " "Please move or delete this file first, then try to exit xdvi again. ", xdvirc_name); return False; } fclose(to_fp); } /* don't use xdvi_temp_fd here, since XrmPutFileDatabase() closes the FILE*, creating a temp race */ tmpname = xstrdup(xdvirc_name); tmpname = xstrcat(tmpname, ".tmp"); /* since XrmPutFileDatabase doesn't give a useful error message if it fails, check that creating the file works beforehand. The file is created with 0600 permissions. */ if ((fd = try_open_mode(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for writing failed: %s", tmpname, strerror(errno))); return True; } close(fd); XrmPutFileDatabase(m_user_db, tmpname); if (full_save) { if ((from_fp = try_fopen(tmpname, "r")) == NULL) { XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for reading failed: %s", tmpname, strerror(errno))); return True; } /* again, create the file with 600 permissions */ if ((fd = try_open_mode(xdvirc_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) { XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for writing failed: %s", xdvirc_name, strerror(errno))); return True; } if ((to_fp = fdopen(fd, "w")) == NULL) { XDVI_ERROR((stderr, "Could not save preferences!\nfdopen for %s for writing failed: %s", xdvirc_name, strerror(errno))); return True; } if (fputs(xdvirc_signature_line, to_fp) == EOF || fputs(xdvirc_header, to_fp) == EOF || !copy_fp(from_fp, to_fp)) { XDVI_ERROR((stderr, "Could not save preferences!\nError writing to %s: %s", xdvirc_name, strerror(errno))); } fclose(from_fp); fclose(to_fp); } free(xdvirc_name); if (full_save) unlink(tmpname); free(tmpname); return True; }