mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	Refactor new b_hash(); better hash table clear (re: d8428a83)
The b_hash() function duplicated much of its code from b_alias(), while b_alias() retained some code to support being called as 'hash'. There is no reason why 'hash' and 'alias' can't be handled with a single function, as is the case several other builtins. Note that option parsing can easily be made dependent on the name the command was invoked with (in this case, argv[0]=='h'). The new hash builtin's -r option cleared the hash table by assigning to PATH its existing value, triggering its associated discipline function (put_restricted() in init.c) which then actually cleared the hash table. That's a bit of a hack. It's nicer if we can just do that directly. This requires taking a static handler function rehash() from init.c, which invalidates one hash table entry, and making it available to the builtin. src/cmd/ksh93/bltins/typeset.c, src/cmd/ksh93/include/builtins.h, src/cmd/ksh93/include/nval.h, src/cmd/ksh93/sh/init.c, src/cmd/ksh93/sh/name.c: - Merge b_hash() into b_alias(). - The -x option was still uselessly setting the NV_EXPORT flag. Exported aliases were in ksh88 but were removed in ksh93. - Rename rehash() handler function from init.c to nv_rehash (avoiding a possible conflict with another rehash() in cd_pwd.c) and move it to name.c just above nv_scan(), which it's meant to be used with. Make it an extern so typeset.c can use it. - b_alias(): Replace the PATH assignment by an nv_scan() call to clear the hash table directly using the nv_rehash() handler. src/cmd/ksh93/data/builtins.c: - POSIX compliance fix: Remove BLT_SPC (special builtin) flag from "alias" definition. 'alias' is specified as a regular builtin. - sh_optalias[]: Fix uninformative -t option documentation. - sh_opthash[]: Edit for conciseness and clarity. src/cmd/ksh93/sh.1: - Edit the 'alias -t' and 'hash' documentation. - Remove the -- prefix from the 'alias' entry, which indicated that it was supposed to be a declaration builtin like 'typeset', with assignment-arguments expanding tildes and not being subject to field splitting. However, my testing shows that 'alias' has never actually behaved that way on ksh93. Even adding the BLT_DCL flag in data/builtins.c doesn't seem to change that. (cherry picked from commit afa68dca5c786daa13213973e8b0f9bf3a1dadf6)
This commit is contained in:
		
							parent
							
								
									74b4162178
								
							
						
					
					
						commit
						80d9ae2b1c
					
				
					 8 changed files with 68 additions and 98 deletions
				
			
		| 
						 | 
				
			
			@ -85,7 +85,6 @@ extern int b_builtin(int, char*[],Shbltin_t*);
 | 
			
		|||
extern int b_cd(int, char*[],Shbltin_t*);
 | 
			
		||||
extern int b_command(int, char*[],Shbltin_t*);
 | 
			
		||||
extern int b_getopts(int, char*[],Shbltin_t*);
 | 
			
		||||
extern int b_hash(int, char*[],Shbltin_t*);
 | 
			
		||||
extern int b_hist(int, char*[],Shbltin_t*);
 | 
			
		||||
extern int b_let(int, char*[],Shbltin_t*);
 | 
			
		||||
extern int b_read(int, char*[],Shbltin_t*);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -281,6 +281,7 @@ extern Namval_t		*nv_open(const char*,Dt_t*,int);
 | 
			
		|||
extern void 		nv_putval(Namval_t*,const char*,int);
 | 
			
		||||
extern void 		nv_putv(Namval_t*,const char*,int,Namfun_t*);
 | 
			
		||||
extern int		nv_rename(Namval_t*,int);
 | 
			
		||||
extern void		nv_rehash(Namval_t*,void*);
 | 
			
		||||
extern int		nv_scan(Dt_t*,void(*)(Namval_t*,void*),void*,int,int);
 | 
			
		||||
extern char 		*nv_setdisc(Namval_t*,const char*,Namval_t*,Namfun_t*);
 | 
			
		||||
extern void		nv_setref(Namval_t*, Dt_t*,int);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,4 +17,4 @@
 | 
			
		|||
*                  David Korn <dgk@research.att.com>                   *
 | 
			
		||||
*                                                                      *
 | 
			
		||||
***********************************************************************/
 | 
			
		||||
#define SH_RELEASE	"93u+m 2020-06-08"
 | 
			
		||||
#define SH_RELEASE	"93u+m 2020-06-10"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue