File cmdXResource.c

 ** ** Module Header ******************************************************* **
 ** 									     **
 **   Modules Revision 3.0						     **
 **   Providing a flexible user environment				     **
 ** 									     **
 **   File:		cmdXResource.c					     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Authors:	John Furlan, jlf@behere.com				     **
 **		Leif Hedstrom<hedstrom"@boot.org>			     **
 **		Jens Hamisch, jens@Strawberry.COM			     **
 ** 									     **
 **   Description:	Module command to merge/remove resources from the X11**
 **			resource manager. The database is update internally, **
 **			ie. its not done at evaluation of string modulecmd   **
 **			returns. It will do something like "xrdb -merge"     **
 **			using the default display ($DISPLAY).		     **
 ** 									     **
 **   Exports:		xresourceFinish					     **
 **			cmdXResource					     **
 ** 									     **
 **   Notes:		Fragments of this code are from the original xrdb    **
 **			source, Copyright 1987 & 1991 by DIGITAL EQUIPMENT   **
 **			CORPORATION. Xrdb was written and modified by:	     **
 ** 									     **
 **				Jim Gettys, August 28, 1987		     **
 **				Phil Karlton, January 5, 1987		     **
 **				Bob Scheifler, February, 1991		     **
 ** 									     **
 **   ToDo/Bugs:	+ The command only handles screen independant re-    **
 **                       sources.                                           **
 ** ************************************************************************ **
References Variables: IdcmdXResource.c

Included Files


Preprocessor definitions

#define MAXHOSTNAME 255

#define Resolution( pixels, mm )


Typedef ResourceDB

typedef struct _ResourceDB ResourceDB
struct _ResourceDB 
   { 
     Tcl_HashTable* data; 
     Window root; 
     Atom prop; 
   } 

Local Variables

Id
static char Id[]
Used in:  cmdXResource.c

UseId
static void* UseId[]

module_name
static char module_name[]
Used in: cmdXResource()
  getEntries()
  getOld()
  initBuffers()
  readFile()

dpy
static Display* dpy
Used in: doDisplayDefines()
  doScreenDefines()
  getOld()
  initBuffers()
  storeResProp()
  xresourceFinish()

defines
static char* defines
Used in: addDef()
  cmdXResource()
  initBuffers()

def_base
static int def_base
Used in: initBuffers()

buffer
static Tcl_DString* buffer
Used in: cmdXResource()
  initBuffers()
  readFile()
  storeResProp()
  xresourceFinish()

resDB
static ResourceDB resDB
Used in: cmdXResource()
  getOld()
  initBuffers()
  xresourceFinish()


Global Function cmdXResource()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:	 	cmdXResource					     **
 ** 									     **
 **   Description:	Callback function for 'x-ressource'. The function    **
 **			sets up a hash table containing all ressources to be **
 **			passed to the X server. This hash table will be	     **
 **			flushed whenever the function xresourceFinish is cal-**
 **			led.						     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	ClientData	 client_data			     **
 **			Tcl_Interp	*interp		According Tcl interp.**
 **			int		 argc		Number of arguments  **
 **			char		*argv[]		Argument array	     **
 ** 									     **
 **   Result:		int	TCL_OK		Successfull completion	     **
 **				TCL_ERROR	Any error		     **
 ** 									     **
 **   Attached Globals:	g_flags		These are set up accordingly before  **
 **					this function is called in order to  **
 **					control everything		     **
 ** 									     **
 ** ************************************************************************ **
int cmdXResource ( ClientData client_data, Tcl_Interp* interp, int argc, char* argv[] )
Prototyped in: modules_def.h
Calls: Module_Error()error.c
  getEntries()cmdXResource.c
  initBuffers()cmdXResource.c
  readFile()cmdXResource.c
  Tcl_DStringAppend(), access(), fopen(), fprintf(), popen(), strcat(), strcmp()
Used in: InitializeModuleCommands()init.c
References Variables: buffercmdXResource.c
  definescmdXResource.c
  g_flagsmain.c
  module_namecmdXResource.c
  resDBcmdXResource.c

Global Function xresourceFinish()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		xresourceFinish					     **
 ** 									     **
 **   Description:	Update the resource property if everything is ok.    **
 **			This routine should be called when all properies have**
 **			been defines or updated. Remember that this routine  **
 **			always will be called, even if there was no 	     **
 **			"x-resource" command in the module!		     **
 ** 									     **
 **   First Edition:    91/10/23                                             **
 **                                                                          **
 **   Parameters:                                                            **
 **                                                                          **
 **   Result:                                                                **
 **                                                                          **
 **   Attached Globals: -                                                    **
 **                                                                          **
 ** ************************************************************************ **
void xresourceFinish ( int no_errors )
Prototyped in: modules_def.h
Calls: storeResProp()cmdXResource.c
  Tcl_DStringFree(), XCloseDisplay()
Called by: main()main.c
References Variables: buffercmdXResource.c
  dpycmdXResource.c
  resDBcmdXResource.c

Local Function addDef()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		addDef, addNum					     **
 ** 									     **
 **   Description:	Adds DEFINES to the define buffer. This code is main-**
 **			ly the same as in the original xrdb.c		     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	char	*title		Name of the ressource	     **
 **			char	*value		and its value		     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	defines		Buffer for all DEFINES which will be **
 **					written here in command lien syntax: **
 **					   -D <titel>=<value>		     **
 ** 									     **
 ** ************************************************************************ **
static void addDef ( char* title, char* value )
Prototyped in: cmdXResource.c
Calls: strcat(), strchr()
Called by: addNum()cmdXResource.c
  doDisplayDefines()cmdXResource.c
  doScreenDefines()cmdXResource.c
References Variables: definescmdXResource.c

Local Function addNum()

static void addNum ( char* title, int value )
Prototyped in: cmdXResource.c
Calls: addDef()cmdXResource.c
  sprintf()
Called by: doDisplayDefines()cmdXResource.c
  doScreenDefines()cmdXResource.c

Local Function doDisplayDefines()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		doDisplayDefines				     **
 ** 									     **
 **   Description:	Put the client and server specific defines on the    **
 **			define buffer					     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	-						     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	dpy		For seeking the name of the display  **
 **			defines		(via addDef and addNum)	  	     **
 ** 									     **
 ** ************************************************************************ **
static void doDisplayDefines ( void )
Prototyped in: cmdXResource.c
Calls: addDef()cmdXResource.c
  addNum()cmdXResource.c
  XDisplayName(), XmuGetHostname(), strchr(), strcpy()
Called by: initBuffers()cmdXResource.c
References Variables: dpycmdXResource.c

Local Function doScreenDefines()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		doScreenDefines					     **
 ** 									     **
 **   Description:	Put the screen specific defines on the define buffer **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	int	scrno	Screen number			     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	dpy		For seeking the name of the display  **
 **			defines		(via addDef and addNum)	  	     **
 ** 									     **
 ** ************************************************************************ **
static void doScreenDefines ( int scrno )
Prototyped in: cmdXResource.c
Calls: addDef()cmdXResource.c
  addNum()cmdXResource.c
Called by: initBuffers()cmdXResource.c
References Variables: dpycmdXResource.c

Local Function getEntries()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		getEntries					     **
 ** 									     **
 **   Description:	Updates the ressources database (which is a Tcl hash **
 **			table) with the ressources passed in the buffer. The **
 **			buffer contains a X ressource lookalike text image.  **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		According Tcl interp.**
 **			Tcl_HashTable	*data	The hash tables holding the  **
 **						ressource data		     **
 **			register char	*buf	The buffer containing the    **
 **						ressources to be modified in **
 **						X ressource syntax	     **
 **			int		 remove	Remove or add ressources     **
 ** 									     **
 **   Result:		ErrType	NO_ERR		Success			     **
 **				ERR_PARSE	Parse error		     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static ErrType getEntries ( Tcl_Interp* interp, Tcl_HashTable* data, char* buf, int remove )
Prototyped in: cmdXResource.c
Calls: Module_Error()error.c
  Tcl_DeleteHashEntry(), Tcl_RegExpCompile(), Tcl_RegExpExec(), Tcl_RegExpRange(), strdup()
Called by: cmdXResource()cmdXResource.c
  initBuffers()cmdXResource.c
References Variables: module_namecmdXResource.c

Local Function getOld()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		getOld						     **
 ** 									     **
 **   Description:	First, we have to find the resources already loaded  **
 **			into the X11 resource property. This routine current-**
 **			ly only handles one screen, the default screen for   **
 **			the DISPLAY. This routine should only be called if   **
 **			resDB.data is NULL.				     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	register char	**buf	Buffer for the old ressource **
 **						database		     **
 ** 									     **
 **   Result:		ErrType	ERR_PARAM	resDB.data != NULL	     **
 **				ERR_ALLOC	out of memory		     **
 **				NO_ERR		Success			     **
 ** 									     **
 **   Attached Globals:	resDB		The data area will be installed as a **
 **					Tcl hash table			     **
 **			dpy		The current display		     **
 ** 									     **
 ** ************************************************************************ **
static ErrType getOld ( char** buf )
Prototyped in: cmdXResource.c
Calls: Module_Error()error.c
  Tcl_InitHashTable(), XResourceManagerString(), malloc()
Called by: initBuffers()cmdXResource.c
References Variables: dpycmdXResource.c
  module_namecmdXResource.c
  resDBcmdXResource.c

Local Function initBuffers()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		initBuffers					     **
 ** 									     **
 **   Description:	Initilize buffers if not already done, or reinitia-  **
 **			lize some variables if buffers already exists.	     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		According Tcl interp.**
 **   			register int is_file	Differs between a single X   **
 **						ressource to be modified or  **
 **						a ressource file to be merged**
 ** 									     **
 **   Result:		ErrType	ERR_DISPLAY	Cannot open DISPLAY	     **
 **				ERR_ALLOC	ALLOC failure		     **
 **				ERR_EXTRACT				     **
 **				NO_ERR		Success			     **
 ** 									     **
 **   Attached Globals:	dpy		Display will be openend		     **
 **			resDB		Ressource database will be filled up **
 **					with the current setup		     **
 **			defines						     **
 ** 									     **
 ** ************************************************************************ **
static ErrType initBuffers ( Tcl_Interp* interp, int is_file )
Prototyped in: cmdXResource.c
Calls: Module_Error()error.c
  doDisplayDefines()cmdXResource.c
  doScreenDefines()cmdXResource.c
  getEntries()cmdXResource.c
  getOld()cmdXResource.c
  Tcl_DStringInit(), Tcl_DStringSetLength(), XOpenDisplay(), malloc(), strcat(), strcpy(), strlen()
Called by: cmdXResource()cmdXResource.c
References Variables: buffercmdXResource.c
  def_basecmdXResource.c
  definescmdXResource.c
  dpycmdXResource.c
  module_namecmdXResource.c
  resDBcmdXResource.c

Local Function readFile()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		readFile					     **
 ** 									     **
 **   Description:	Read resource from a file, which normally is a pipe  **
 **			opened with popen.				     **
 **			The file will be closed, when reading is finished    **
 **									     **
 **   Note:		This routine uses the global variable 'line', declar-**
 **			ed in another file!!!				     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	register FILE	*input	The stream to be read from   **
 **			int		 do_cpp	Differs betweem a pipe or a  **
 **						file being assigned to input **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	line		Buffer for a line to be read	     **
 **			buffer		Buffer for the whole ressource file  **
 **					image				     **
 ** 									     **
 ** ************************************************************************ **
static int readFile ( FILE* input, int do_cpp )
Prototyped in: cmdXResource.c
Calls: Module_Error()error.c
  Tcl_DStringAppend(), fclose(), feof(), fread(), pclose()
Called by: cmdXResource()cmdXResource.c
References Variables: buffercmdXResource.c
  linemain.c
  module_namecmdXResource.c

Local Function storeResProp()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		storeResProp					     **
 ** 									     **
 **   Description:	Update the X11 resource property, adding new resour- **
 **			ces.						     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	register ResourceDB *rdb	Ressource database   **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static void storeResProp ( ResourceDB* rdb )
Prototyped in: cmdXResource.c
Calls: Tcl_DStringAppend(), Tcl_DStringSetLength(), Tcl_FirstHashEntry(), Tcl_NextHashEntry(), XChangeProperty(), XGrabServer(), XMaxRequestSize(), XUngrabServer()
Called by: xresourceFinish()cmdXResource.c
References Variables: buffercmdXResource.c
  dpycmdXResource.c