1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* David Korn <dgk@research.att.com> * 1N/A***********************************************************************/ 1N/A * string processing routines for Korn shell 1N/A * Table lookup routine 1N/A * <table> is searched for string <sp> and corresponding value is returned 1N/A * This is only used for small tables and is used to save non-sharable memory 1N/A * shtab_options lookup routine 1N/A#
define sep(c) ((c)==
'-'||(c)==
'_')
1N/A register const char *s, *t, *
sw, *
tw;
1N/A if(*
sp==
'n' && *(
sp+
1)==
'o' && (*(
sp+
2)!=
't' || *(
sp+
3)!=
'i'))
1N/A if(
no = *t==
'n' && *(t+
1)==
'o' && *(t+
2)!=
't')
1N/A * look for the substring <oldsp> in <string> and replace with <newsp> 1N/A * The new string is put on top of the stack 1N/A assume string!=NULL && oldsp!=NULL && newsp!=NULL; 1N/A return x satisfying x==NULL || 1N/A strlen(x)==(strlen(in string)+strlen(in newsp)-strlen(in oldsp)); 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A /* skip to first character which matches start of oldsp */ 1N/A /* skip a whole character at a time */ 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A /* copy rest of string */ 1N/A * Remove escape characters from characters in <sp> and eliminate quoted nulls. 1N/A promise strlen(in sp) <= in strlen(sp); 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A * copy <str1> to <str2> changing upper case to lower case 1N/A * <str2> must be big enough to hold <str1> 1N/A * <str1> and <str2> may point to the same place. 1N/A assume str1!=0 && str2!=0 1N/A return x satisfying strlen(in str1)==strlen(in str2); 1N/A * print <str> quoting chars so that it can be read by the shell 1N/A * puts null terminated result on stack, but doesn't freeze it 1N/A if(c==0 || c==
'#' || c==
'~')
1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A case (
'a'==
97?
'\033':
39):
1N/A case '\\':
case '\'':
1N/A * print <str> quoting chars so that it can be read by the shell 1N/A * puts null terminated result on stack, but doesn't freeze it 1N/A * single!=0 limits quoting to '...' 1N/A * fold>0 prints raw newlines and inserts appropriately 1N/A * escaped newlines every (fold-x) chars 1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A case (
'a'==
97?
'\033':
39):
1N/A if ((n -= q +
1) <= 0)
1N/A else if (n && --n <= 0)
1N/A else if (n ==
1 && *
cp ==
'\'')
1N/A if (n && (n -=
4) <= 0)
1N/A#
endif /* SHOPT_MULTIBYTE */ 1N/A * change '['identifier']' to identifier 1N/A * character before <str> must be a '[' 1N/A * returns pointer to last character 1N/A register unsigned char *
cp = (
unsigned char*)
str;
1N/A register unsigned char *v =
cp;
1N/A /* eliminate [ and ] */