[comp.windows.x] XGetDefault for use by daemons and others

jmsellens@watdragon.waterloo.edu.UUCP (02/22/87)

I was fooling with a comsat (mail notification) daemon for use with X,
and observed that the author had had to set up a dummy environment
variable so that the daemon could read from the mail recipient's
.Xdefaults file.  So I hacked XGetDefault.c to add a new routine
XGetDefaultHome() (for lack of a better name) that allows you to
give the routine the home directory to read the .Xdefaults file
from.  The following is a context diff of what I did.  Trivial
changes actually ...

John Sellens -- Logic Programming and Artificial Intelligence Group

{decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdragon!jmsellens
jmsellens@dragon.waterloo.{edu,CDN} jsellens@watmta.BITNET
jmsellens%dragon@waterloo.csnet


*** XGetDefault.c.orig	Mon Dec  1 19:04:53 1986
--- XGetDefault.c	Fri Feb 20 16:19:04 1987
***************
*** 31,37 ****
--- 31,67 ----
  	char bal;			/* for avl use			*/
  } *head;
  
+ 
+ #ifdef waterloo
+ 
+ static char *XGetDefaultInternal();
+ static ReadFile();
+ static insert();
+ 
+ 
+ char *
+ XGetDefault( prog, name )
+ char *prog, *name;
+ {
+ 	return( XGetDefaultInternal( (char *)NULL, prog, name ) );
+ }
+ 
+ char *
+ XGetDefaultHome( home, prog, name )
+ char *home, *prog, *name;
+ {
+ 	return( XGetDefaultInternal( home, prog, name ) );
+ }
+ 
+ #endif
+ 
+ 
+ #ifdef waterloo
+ static char *XGetDefaultInternal(home, prog, name)
+ 	char *home;			/* place to look for the file */
+ #else
  char *XGetDefault(prog, name)
+ #endif
  	register char *name;		/* name of option program wants */
  	char *prog;			/* name of program for option	*/
  {					/* to get, for example, "font"  */
***************
*** 47,53 ****
--- 77,87 ----
  		pv++;
  	}
  	if (nent == -1)
+ #ifdef waterloo
+ 		nent = ReadFile(home,prog);/* if not, parse the file.*/
+ #else
  		nent = ReadFile(prog);/* if not, parse the file.*/
+ #endif
  	if (nent == 0)
  		return(NULL);
  	cur = head;
***************
*** 59,65 ****
--- 93,104 ----
  	return(NULL);			/* if no match, let him know	*/
  }
  
+ #ifdef waterloo
+ static ReadFile(home,prog)
+ 	char *home;
+ #else
  static ReadFile(prog)
+ #endif
  	char *prog;			/* program name to match 	    */
  {
  	register char *point,*colon;	/* where in the line the keys are   */
***************
*** 72,78 ****
--- 111,122 ----
  	char fname[BUFSIZ];		/* longer than any conceivable size */
  	char line[BUFSIZ];		/* line buffer for each line of file*/
  	char *getenv();
+ #ifndef waterloo
  	char *home = getenv("HOME");
+ #else
+ 	if ( home == (char *)NULL )
+ 		home = getenv( "HOME" );
+ #endif
  
  	if ((pv = rindex(prog,'/')) != NULL)
  		prog = pv + 1;	/* if full path, get last component */