zsh-workers
 help / color / mirror / code / Atom feed
* Remove option union initialisation hack
@ 1997-01-01 20:13 Zoltan Hidvegi
  0 siblings, 0 replies; only message in thread
From: Zoltan Hidvegi @ 1997-01-01 20:13 UTC (permalink / raw)
  To: Zsh hacking and development

This patch removes the union from struct optname.  It uses int optno.  Note
that because of allignment short here would not save memory.  The patch
also changes option aliases to use optno instead of the option string.
This should be applied to zsh-3.1.1-test1.

There are still some assumptions about the machines in the code.  It is
assumed that int is at least 32 bit wide (that's not really a big
assumption), and dupstruct and freestruct assumes that sizeof(void*) is a
multiple of sizeof(int), and if sizeof(void*) > sizeof(int) and a void*
element comes after an int in a struct, the pointer is alligned to
sizeof(void*). I.e. when sizeof(int) == 4 and sizeof(void*) == 8 then
struct { int i; void *p; } and struct { int i,j; void *p; } has the same
size.  That's at least true on Alpha.

Zoltan


*** Src/options.c	1996/12/30 21:09:35	3.1.1.7
--- Src/options.c	1997/01/01 19:49:44
***************
*** 39,48 ****
      HashNode next;		/* next in hash chain */
      char *nam;			/* hash data */
      int flags;
!     union {
! 	char *text;		/* alias text if OPT_ALIAS */
! 	long optno;		/* option number */
!     } u;
  };
  
  HashTable optiontab;
--- 39,45 ----
      HashNode next;		/* next in hash chain */
      char *nam;			/* hash data */
      int flags;
!     int optno;			/* option number */
  };
  
  HashTable optiontab;
***************
*** 66,77 ****
  
  #define defset(X) (!!((X)->flags & emulation))
  
! static struct {
!     HashNode next;
!     char *nam;
!     int flags;
!     long optno;
! } optns[] = {
  {NULL, "allexport",	      0,			 ALLEXPORT},
  {NULL, "alwayslastprompt",    OPT_ALL,			 ALWAYSLASTPROMPT},
  {NULL, "alwaystoend",	      0,			 ALWAYSTOEND},
--- 63,69 ----
  
  #define defset(X) (!!((X)->flags & emulation))
  
! static struct optname optns[] = {
  {NULL, "allexport",	      0,			 ALLEXPORT},
  {NULL, "alwayslastprompt",    OPT_ALL,			 ALWAYSLASTPROMPT},
  {NULL, "alwaystoend",	      0,			 ALWAYSTOEND},
***************
*** 176,194 ****
  {NULL, "verbose",	      0,			 VERBOSE},
  {NULL, "xtrace",	      0,			 XTRACE},
  {NULL, "zle",		      OPT_SPECIAL,		 USEZLE},
! {NULL, NULL, 0, 0}
! };
! static struct {
!     HashNode next;
!     char *nam;
!     int flags;
!     char *text;
! } optals[] = {
! /* ksh compatibility option aliases */
! {NULL, "braceexpand",	OPT_ALIAS, "noignorebraces"},
! {NULL, "physical",	OPT_ALIAS, "chaselinks"},
! {NULL, "stdin",		OPT_ALIAS, "shinstdin"},
! {NULL, "trackall",	OPT_ALIAS, "hashcmds"},
  {NULL, NULL, 0, 0}
  };
  
--- 168,177 ----
  {NULL, "verbose",	      0,			 VERBOSE},
  {NULL, "xtrace",	      0,			 XTRACE},
  {NULL, "zle",		      OPT_SPECIAL,		 USEZLE},
! {NULL, "braceexpand",	      OPT_ALIAS,		 -IGNOREBRACES},
! {NULL, "physical",	      OPT_ALIAS,		 CHASELINKS},
! {NULL, "stdin",		      OPT_ALIAS,		 SHINSTDIN},
! {NULL, "trackall",	      OPT_ALIAS,		 HASHCMDS},
  {NULL, NULL, 0, 0}
  };
  
***************
*** 377,385 ****
      optiontab->freenode    = NULL;
      optiontab->printnode   = printoptionnode;
  
!     for (on = (Optname) optns; on->nam; on++)
! 	optiontab->addnode(optiontab, on->nam, on);
!     for (on = (Optname) optals; on->nam; on++)
  	optiontab->addnode(optiontab, on->nam, on);
  }
  
--- 360,366 ----
      optiontab->freenode    = NULL;
      optiontab->printnode   = printoptionnode;
  
!     for (on = optns; on->nam; on++)
  	optiontab->addnode(optiontab, on->nam, on);
  }
  
***************
*** 387,402 ****
  printoptionnode(HashNode hn, int set)
  {
      Optname on = (Optname) hn;
  
!     if (on->flags & OPT_ALIAS)
! 	printf("%s is an alias to %s\n", on->nam, on->u.text);
!     else if (isset(KSHOPTIONPRINT)) {
  	if (defset(on))
! 	    printf("no%-20s%s\n", on->nam, isset(on->u.optno) ? "off" : "on");
  	else
! 	    printf("%-22s%s\n", on->nam, isset(on->u.optno) ? "on" : "off");
!     } else if (set == (isset(on->u.optno) ^ defset(on))) {
! 	if (set ^ isset(on->u.optno))
  	    fputs("no", stdout);
  	puts(on->nam);
      }
--- 368,384 ----
  printoptionnode(HashNode hn, int set)
  {
      Optname on = (Optname) hn;
+     int optno = on->optno;
  
!     if (optno < 0)
! 	optno = -optno;
!     if (isset(KSHOPTIONPRINT)) {
  	if (defset(on))
! 	    printf("no%-20s%s\n", on->nam, isset(optno) ? "off" : "on");
  	else
! 	    printf("%-22s%s\n", on->nam, isset(optno) ? "on" : "off");
!     } else if (set == (isset(optno) ^ defset(on))) {
! 	if (set ^ isset(optno))
  	    fputs("no", stdout);
  	puts(on->nam);
      }
***************
*** 435,441 ****
      if (!(on->flags & OPT_ALIAS) &&
  	((fully && !(on->flags & OPT_SPECIAL)) ||
  	 (on->flags & OPT_EMULATE)))
! 	opts[on->u.optno] = defset(on);
  }
  
  /* setopt, unsetopt */
--- 417,423 ----
      if (!(on->flags & OPT_ALIAS) &&
  	((fully && !(on->flags & OPT_SPECIAL)) ||
  	 (on->flags & OPT_EMULATE)))
! 	opts[on->optno] = defset(on);
  }
  
  /* setopt, unsetopt */
***************
*** 524,533 ****
  static void
  setoption(HashNode hn, int value)
  {
!     Optname on = (Optname) hn;
! 
!     dosetopt(on->flags & OPT_ALIAS ? optlookup(on->u.text) : on->u.optno,
! 	     value, 0);
  }
  
  /* Identify an option name */
--- 506,512 ----
  static void
  setoption(HashNode hn, int value)
  {
!     dosetopt(((Optname) hn)->optno, value, 0);
  }
  
  /* Identify an option name */
***************
*** 553,563 ****
      /* look up name in the table */
      if (s[0] == 'n' && s[1] == 'o' &&
  	(n = (Optname) optiontab->getnode(optiontab, s + 2))) {
! 	return n->flags & OPT_ALIAS ? -optlookup(n->u.text) : -n->u.optno;
      } else if ((n = (Optname) optiontab->getnode(optiontab, s)))
! 	return n->flags & OPT_ALIAS ? optlookup(n->u.text) : n->u.optno;
      else
! 	return 0;
  }
  
  /* Identify an option letter */
--- 532,542 ----
      /* look up name in the table */
      if (s[0] == 'n' && s[1] == 'o' &&
  	(n = (Optname) optiontab->getnode(optiontab, s + 2))) {
! 	return -n->optno;
      } else if ((n = (Optname) optiontab->getnode(optiontab, s)))
! 	return n->optno;
      else
! 	return OPT_INVALID;
  }
  
  /* Identify an option letter */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-01-01 20:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-01 20:13 Remove option union initialisation hack Zoltan Hidvegi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).