mirror of
				git://git.code.sf.net/p/zsh/code
				synced 2025-10-31 18:10:56 +01:00 
			
		
		
		
	34641: make it possible to alias tokens
This commit is contained in:
		
							parent
							
								
									42e5f591f5
								
							
						
					
					
						commit
						0ac87e3f59
					
				
					 2 changed files with 44 additions and 30 deletions
				
			
		
							
								
								
									
										71
									
								
								Src/lex.c
									
										
									
									
									
								
							
							
						
						
									
										71
									
								
								Src/lex.c
									
										
									
									
									
								
							|  | @ -1728,13 +1728,48 @@ gotword(void) | |||
|     } | ||||
| } | ||||
| 
 | ||||
| /* Check if current lex text matches an alias: 1 if so, else 0 */ | ||||
| 
 | ||||
| static int | ||||
| checkalias(void) | ||||
| { | ||||
|     Alias an; | ||||
| 
 | ||||
|     if (!noaliases && isset(ALIASESOPT) && | ||||
| 	(!isset(POSIXALIASES) || | ||||
| 	 !reswdtab->getnode(reswdtab, zshlextext))) { | ||||
| 	char *suf; | ||||
| 
 | ||||
| 	an = (Alias) aliastab->getnode(aliastab, zshlextext); | ||||
| 	if (an && !an->inuse && | ||||
| 	    ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) { | ||||
| 	    inpush(an->text, INP_ALIAS, an); | ||||
| 	    if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL)) | ||||
| 		aliasspaceflag = 1; | ||||
| 	    lexstop = 0; | ||||
| 	    return 1; | ||||
| 	} | ||||
| 	if ((suf = strrchr(zshlextext, '.')) && suf[1] && | ||||
| 	    suf > zshlextext && suf[-1] != Meta && | ||||
| 	    (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && | ||||
| 	    !an->inuse && incmdpos) { | ||||
| 	    inpush(dupstring(zshlextext), INP_ALIAS, NULL); | ||||
| 	    inpush(" ", INP_ALIAS, NULL); | ||||
| 	    inpush(an->text, INP_ALIAS, an); | ||||
| 	    lexstop = 0; | ||||
| 	    return 1; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| /* expand aliases and reserved words */ | ||||
| 
 | ||||
| /**/ | ||||
| int | ||||
| exalias(void) | ||||
| { | ||||
|     Alias an; | ||||
|     Reswd rw; | ||||
| 
 | ||||
|     hwend(); | ||||
|  | @ -1746,7 +1781,7 @@ exalias(void) | |||
|     if (!tokstr) { | ||||
| 	zshlextext = tokstrings[tok]; | ||||
| 
 | ||||
| 	return 0; | ||||
| 	return checkalias(); | ||||
|     } else { | ||||
| 	VARARR(char, copy, (strlen(tokstr) + 1)); | ||||
| 
 | ||||
|  | @ -1772,34 +1807,10 @@ exalias(void) | |||
| 
 | ||||
| 	if (tok == STRING) { | ||||
| 	    /* Check for an alias */ | ||||
| 	    if (!noaliases && isset(ALIASESOPT) && | ||||
| 		(!isset(POSIXALIASES) || | ||||
| 		 !reswdtab->getnode(reswdtab, zshlextext))) { | ||||
| 		char *suf; | ||||
| 
 | ||||
| 		an = (Alias) aliastab->getnode(aliastab, zshlextext); | ||||
| 		if (an && !an->inuse && | ||||
| 		    ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) { | ||||
| 		    inpush(an->text, INP_ALIAS, an); | ||||
| 		    if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL)) | ||||
| 			aliasspaceflag = 1; | ||||
| 		    lexstop = 0; | ||||
| 		    if (zshlextext == copy) | ||||
| 			zshlextext = tokstr; | ||||
| 		    return 1; | ||||
| 		} | ||||
| 		if ((suf = strrchr(zshlextext, '.')) && suf[1] && | ||||
| 		    suf > zshlextext && suf[-1] != Meta && | ||||
| 		    (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && | ||||
| 		    !an->inuse && incmdpos) { | ||||
| 		    inpush(dupstring(zshlextext), INP_ALIAS, NULL); | ||||
| 		    inpush(" ", INP_ALIAS, NULL); | ||||
| 		    inpush(an->text, INP_ALIAS, an); | ||||
| 		    lexstop = 0; | ||||
| 		    if (zshlextext == copy) | ||||
| 			zshlextext = tokstr; | ||||
| 		    return 1; | ||||
| 		} | ||||
| 	    if (checkalias()) { | ||||
| 		if (zshlextext == copy) | ||||
| 		    zshlextext = tokstr; | ||||
| 		return 1; | ||||
| 	    } | ||||
| 
 | ||||
| 	    /* Then check for a reserved word */ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue