** ** 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. **
** ************************************************************************ **
Included Files
- #include "modules_def.h"
- #include <stdio.h>
- #include <tcl.h>
- #include "config.h"
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <ctype.h>
- #include <sys/stat.h>
- #include <sys/termios.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <dirent.h>
- #include <errno.h>
- #include <X11/Xmu/SysUtil.h>
Preprocessor definitions
#define MAXHOSTNAME 255
#define Resolution( pixels, mm )
typedef struct _ResourceDB ResourceDB
struct _ResourceDB |
|
{ |
|
Tcl_HashTable* data; |
|
Window root; |
|
Atom prop; |
|
} |
|
Local Variables
Id
static char Id[]
UseId
static void* UseId[]
module_name
static char module_name[]
dpy
static Display* dpy
defines
static char* defines
def_base
static int def_base
buffer
static Tcl_DString* buffer
resDB
static ResourceDB resDB
** ** 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[] )
** ** 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 )
** ** 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 )
static void addNum ( char* title, int value )
** ** 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 )
** ** 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 )
** ** 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 )
** ** 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 )
** ** 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 )
** ** 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 )
** ** 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 )