コード例 #1
0
ファイル: xcutsel.c プロジェクト: aosm/X11
int 
main(int argc, char *argv[])
{
    char label[100];
    Widget box, button;
    XtAppContext appcon;
    Widget shell;
    XrmDatabase rdb;

    XtSetLanguageProc(NULL, NULL, NULL);

    shell =
	XtAppInitialize( &appcon, "XCutsel", optionDesc, XtNumber(optionDesc),
			 &argc, argv, NULL, NULL, 0 );
    rdb = XtDatabase(XtDisplay(shell));

    if (argc != 1) Syntax(argv[0]);

    XtGetApplicationResources( shell, (XtPointer)&options,
			       resources, XtNumber(resources),
			       NULL, ZERO );

    options.value = NULL;
    XmuInternStrings( XtDisplay(shell), &options.selection_name, ONE,
		      &options.selection );

    box = XtCreateManagedWidget("box", boxWidgetClass, shell, NULL, ZERO);

    button =
	XtCreateManagedWidget("quit", commandWidgetClass, box, NULL, ZERO);
	XtAddCallback( button, XtNcallback, Quit, NULL );

    /* %%% hack alert... */
    sprintf(label, "*label:copy %s to %d",
	    options.selection_name,
	    options.buffer);
    XrmPutLineResource( &rdb, label );

    button =
	XtCreateManagedWidget("sel-cut", commandWidgetClass, box, NULL, ZERO);
	XtAddCallback( button, XtNcallback, GetSelection, NULL );

    sprintf(label, "*label:copy %d to %s",
	    options.buffer,
	    options.selection_name);
    XrmPutLineResource( &rdb, label );

    button =
	XtCreateManagedWidget("cut-sel", commandWidgetClass, box, NULL, ZERO);
	XtAddCallback( button, XtNcallback, GetBuffer, (XtPointer)&state );
 	state.button = button;
	state.is_on = False;
   
    XtRealizeWidget(shell);
    XtAppMainLoop(appcon);
    exit(0);
}
コード例 #2
0
ファイル: Prefs.c プロジェクト: brettatoms/xqs
void InitPreferenceDB()
{    
  int i;
  char *hdir;
  XrmDatabase db;

  pref_db.dpyPrefs = dpyPrefs;
  pref_db.winPrefs = winPrefs;
  pref_db.cliPrefs = cliPrefs;
  pref_db.propPrefs = propPrefs;
  pref_db.treePrefs = treePrefs;
  

  /* 
   * if an .xqsrc rcfile doesnt exist in the users home directory create one
   */
  hdir = getenv( "HOME" );
  rcfile = XtMalloc( strlen(hdir) + strlen(RCFILE) + 1 );
  sprintf( rcfile, "%s/%s", hdir, RCFILE );

  db = XtDatabase( XtDisplay(appshell) ); 
  for( i=0; i<XtNumber(MiscRes); i++ ) 
       XrmPutLineResource( &db, MiscRes[i] );

  pref_db.db = XrmGetFileDatabase( rcfile );
  GetPrefFromDB();  

}
コード例 #3
0
ファイル: utils.cpp プロジェクト: BackupTheBerlios/wxbeos-svn
/*
* Not yet used but may be useful.
*
*/
void
wxSetDefaultResources (const Widget w, const char **resourceSpec, const char *name)
{
    int i;
    Display *dpy = XtDisplay (w);    // Retrieve the display pointer

    XrmDatabase rdb = NULL;    // A resource data base

    // Create an empty resource database
    rdb = XrmGetStringDatabase ("");

    // Add the Component resources, prepending the name of the component

    i = 0;
    while (resourceSpec[i] != NULL)
    {
        char buf[1000];

        sprintf (buf, "*%s%s", name, resourceSpec[i++]);
        XrmPutLineResource (&rdb, buf);
    }

    // Merge them into the Xt database, with lowest precendence

    if (rdb)
    {
#if (XlibSpecificationRelease>=5)
        XrmDatabase db = XtDatabase (dpy);
        XrmCombineDatabase (rdb, &db, False);
#else
        XrmMergeDatabases (dpy->db, &rdb);
        dpy->db = rdb;
#endif
    }
}
コード例 #4
0
void MotifUI::SetDefaultResources(const Widget,
			          const String *resources)
{
   XrmDatabase rdb = NULL;
   int         i;

   rdb = XrmGetStringDatabase("");

   i = 0;
   while (resources[i])
    {
      char *buf = new char[1000];

      sprintf(buf, "%s%s", _name, resources[i]);
      XrmPutLineResource(&rdb, buf);
      i++;

      delete [] buf;
    }
   if (rdb)
    {
      XrmMergeDatabases(XtDatabase(display), &rdb);
      XrmSetDatabase(display, rdb);
    }
}
コード例 #5
0
ファイル: resources.C プロジェクト: aidanfarrow/GC_tidy
// Return a database of default settings
XrmDatabase app_defaults(Display *display)
{
    static XrmDatabase db = NULL;
    if (db != NULL)
	return db;

    // Add builtin fallback defaults.
    int i = 0;
    while (ddd_fallback_resources[i] != 0)
	XrmPutLineResource(&db, ddd_fallback_resources[i++]);

    // Add app-defaults file, overriding fallback defaults.
    static String app_name  = 0;
    static String app_class = 0;

    if (app_name == 0)
	XtGetApplicationNameAndClass(display, &app_name, &app_class);

    String app_defaults_file = 
	XtResolvePathname(display, NULL, app_class, NULL, NULL, NULL, 0, NULL);
    if (app_defaults_file != NULL)
    {
	XrmDatabase db2 = XrmGetFileDatabase(app_defaults_file);
	if (db2 != 0)
	    XrmMergeDatabases(db2, &db);
    }

    return db;
}
コード例 #6
0
ファイル: XsComponent.C プロジェクト: beanhome/dev
void XsComponent::_setResources (Widget w, const String *resources)
{
   assert (w != 0);
   
   XrmDatabase rdb = 0;
   const int bufSize = 200;
   char  buffer[bufSize];
   int   loop;

// Create an empty resource database

   rdb = XrmGetStringDatabase ("");

// Add the component resources

   loop = 0;
   while (resources[loop] != 0)
   {
      sprintf (buffer, "*%s%s\n", _name, resources[loop++]);
      assert (strlen (buffer) < bufSize);
      XrmPutLineResource (&rdb, buffer);
   }
   
// Merge these resources into the database

   if (rdb != 0)
   {
      XrmDatabase db = XtDatabase (XtDisplay (w));
      XrmCombineDatabase (rdb, &db, FALSE);
   }
}
コード例 #7
0
char *
GetResourceValueForSetValues(WNode *node, unsigned short *size)
{
    Arg args[1];
    char *ptr, *temp;
    XrmDatabase db = NULL;
    XrmValue value;

    XtSetArg(args[0], XtNstring, &ptr);
    XtGetValues(node->resources->res_box->value_wid, args, ONE);

    /*
     * This makes sure that exactly the same thing happens during a set
     * values, that would happend of we were to insert this value into
     * the resource database.
     */

    temp = XtMalloc(sizeof(char) * (strlen(ptr) + strlen(RESOURCE_NAME) + 2));
    sprintf(temp, "%s:%s", RESOURCE_NAME, ptr);
    XrmPutLineResource(&db, temp);
    XtFree(temp);

    XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value);

    ptr = XtMalloc(sizeof(char) * value.size);
    memmove( ptr, value.addr, value.size);
    XrmDestroyDatabase(db);
    
    *size = (unsigned short) value.size;
    return(ptr);
}
コード例 #8
0
ファイル: blackbox.cpp プロジェクト: burzumishi/blackbox
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();
}
コード例 #9
0
void XsComponent::_setResources (Widget w, const String *resources)
{
   assert (w != 0);
   
   XrmDatabase rdb = 0;
   const int bufSize = 200;
   char  buffer[bufSize];
   int   loop;

// Create an empty resource database

   rdb = XrmGetStringDatabase ("");

// Add the component resources

   loop = 0;
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
   while (resources[loop] != 0)
   {
      sprintf (buffer, "*%s%s\n", _name, resources[loop++]);
      assert (strlen (buffer) < bufSize);
      XrmPutLineResource (&rdb, buffer);
   }
   
// Merge these resources into the database

   if (rdb != 0)
   {
      XrmDatabase db = XtDatabase (XtDisplay (w));
      XrmCombineDatabase (rdb, &db, FALSE);
   }
}
コード例 #10
0
XrmDatabase XtScreenDatabase(
    Screen *screen)
{
    int scrno;
    Bool doing_def;
    XrmDatabase db, olddb;
    XtPerDisplay pd;
    Status do_fallback;
    char *scr_resources;
    Display *dpy = DisplayOfScreen(screen);
    DPY_TO_APPCON(dpy);

    LOCK_APP(app);
    LOCK_PROCESS;
    if (screen == DefaultScreenOfDisplay(dpy)) {
	scrno = DefaultScreen(dpy);
	doing_def = True;
    } else {
	scrno = XScreenNumberOfScreen(screen);
	doing_def = False;
    }
    pd = _XtGetPerDisplay(dpy);
    if ((db = pd->per_screen_db[scrno])) {
	UNLOCK_PROCESS;
	UNLOCK_APP(app);
	return (doing_def ? XrmGetDatabase(dpy) : db);
    }
    scr_resources = XScreenResourceString(screen);

    if (ScreenCount(dpy) == 1) {
	db = pd->cmd_db;
	pd->cmd_db = NULL;
    } else {
	db = CopyDB(pd->cmd_db);
    }
    {   /* Environment defaults */
	char	filenamebuf[PATH_MAX];
	char	*filename;

	if (!(filename = getenv("XENVIRONMENT"))) {
	    int len;
#ifdef __MINGW32__
	    const char *slashDotXdefaultsDash = "/Xdefaults-";
#else
	    const char *slashDotXdefaultsDash = "/.Xdefaults-";
#endif

	    (void) GetRootDirName(filename = filenamebuf,
			PATH_MAX - strlen (slashDotXdefaultsDash) - 1);
	    (void) strcat(filename, slashDotXdefaultsDash);
	    len = strlen(filename);
	    GetHostname (filename+len, PATH_MAX-len);
	}
	(void)XrmCombineFileDatabase(filename, &db, False);
    }
    if (scr_resources)
    {   /* Screen defaults */
	XrmCombineDatabase(XrmGetStringDatabase(scr_resources), &db, False);
	XFree(scr_resources);
    }
    /* Server or host defaults */
    if (!pd->server_db)
	CombineUserDefaults(dpy, &db);
    else {
	(void) XrmCombineDatabase(pd->server_db, &db, False);
	pd->server_db = NULL;
    }

    if (!db)
	db = XrmGetStringDatabase("");
    pd->per_screen_db[scrno] = db;
    olddb = XrmGetDatabase(dpy);
    /* set database now, for XtResolvePathname to use */
    XrmSetDatabase(dpy, db);
    CombineAppUserDefaults(dpy, &db);
    do_fallback = 1;
    {   /* System app-defaults */
	char	*filename;

	if ((filename = XtResolvePathname(dpy, "app-defaults",
					 NULL, NULL, NULL, NULL, 0, NULL))) {
	    do_fallback = !XrmCombineFileDatabase(filename, &db, False);
	    XtFree(filename);
	}
    }
    /* now restore old database, if need be */
    if (!doing_def)
	XrmSetDatabase(dpy, olddb);
    if (do_fallback && pd->appContext->fallback_resources)
    {   /* Fallback defaults */
        XrmDatabase fdb = NULL;
	String *res;

	for (res = pd->appContext->fallback_resources; *res; res++)
	    XrmPutLineResource(&fdb, *res);
	(void)XrmCombineDatabase(fdb, &db, False);
    }
    UNLOCK_PROCESS;
    UNLOCK_APP(app);
    return db;
}
コード例 #11
0
ファイル: qmon_main.c プロジェクト: HPCKP/gridengine
/*-------------------------------------------------------------------------*/
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;
}
コード例 #12
0
ファイル: setvalues.c プロジェクト: idunham/dtextra
/* Function Name:
 *   brGetResourceValueForSetValues
 *
 * Description:
 *   Returns the value that should be sent to SetValues.
 *
 * Arguments:
 *   res_value - value to set to the resource
 *   size - length of the string returned
 *
 * Returns:
 *   value - allocated value.
 *
 * Calls:
 *   Xrm- and Xt-stuff
 */
char
*brGetResourceValueForSetValues(char *res_value, unsigned short *size)
{
  static char      *temp = NULL;
  static Cardinal  tempSize = 0;
  static char      *ptr = NULL;
  static Cardinal  ptrSize = 0;

  Arg              args[1];
  XrmDatabase      db = NULL;
  XrmValue         value;
  char             *type;


  /*
   * This makes sure that exactly the same thing happens during a set
   * values, that would happend of we were to insert this value into
   * the resource database.
   */
  if (tempSize < sizeof(char) * (strlen(res_value) + strlen(RESOURCE_NAME) + 2))
    {
      tempSize = (sizeof(char) * (strlen(res_value) + strlen(RESOURCE_NAME) + 2));
      if ( (temp = XtRealloc(temp, tempSize)) == NULL )
	{
	  fprintf(stderr, "XtRealloc failed!\n");
	  exit(EXIT_FAILURE);
	}
    }

  sprintf(temp,
	  "%s:%s",
	  RESOURCE_NAME,
	  res_value);

  XrmPutLineResource(&db,
		     temp);

  XrmGetResource(db,
		 RESOURCE_NAME,
		 RESOURCE_CLASS,
		 &type,
		 &value);

  if (ptrSize < sizeof(char) * value.size)
    {
      ptrSize = sizeof(char) * value.size;
      if ( (ptr = XtRealloc(ptr, ptrSize)) == NULL )
	{
	  fprintf(stderr, "XtRealloc failed!\n");
	  exit(EXIT_FAILURE);
	}
    }

  memmove (ptr,
	   value.addr,
	   value.size);
  XrmDestroyDatabase(db);

  *size = (unsigned short) value.size;

  return(ptr);

}   /* brGetResourceValueForSetValues() */