sh: Reduce size of builtins table.
This commit is contained in:
parent
c6f9988dbb
commit
00310b91de
@ -439,12 +439,14 @@ success:
|
||||
int
|
||||
find_builtin(const char *name, int *special)
|
||||
{
|
||||
const struct builtincmd *bp;
|
||||
const unsigned char *bp;
|
||||
size_t len;
|
||||
|
||||
for (bp = builtincmd ; bp->name ; bp++) {
|
||||
if (*bp->name == *name && equal(bp->name, name)) {
|
||||
*special = bp->special;
|
||||
return bp->code;
|
||||
len = strlen(name);
|
||||
for (bp = builtincmd ; *bp ; bp += 2 + bp[0]) {
|
||||
if (bp[0] == len && memcmp(bp + 2, name, len) == 0) {
|
||||
*special = (bp[1] & BUILTIN_SPECIAL) != 0;
|
||||
return bp[1] & ~BUILTIN_SPECIAL;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
@ -62,17 +62,16 @@ echo 'int (*const builtinfunc[])(int, char **) = {'
|
||||
awk '/^[^#]/ { printf "\t%s,\n", $1}' $temp
|
||||
echo '};
|
||||
|
||||
const struct builtincmd builtincmd[] = {'
|
||||
const unsigned char builtincmd[] = {'
|
||||
awk '{ for (i = 2 ; i <= NF ; i++) {
|
||||
if ($i == "-s") {
|
||||
spc = 1;
|
||||
} else {
|
||||
printf "\t{ \"%s\", %d, %d },\n", $i, NR-1, spc
|
||||
printf "\t\"\\%03o\\%03o%s\"\n", length($i), (spc ? 128 : 0) + NR-1, $i
|
||||
spc = 0;
|
||||
}
|
||||
}}' $temp
|
||||
echo ' { NULL, 0, 0 }
|
||||
};'
|
||||
echo '};'
|
||||
|
||||
exec > builtins.h
|
||||
cat <<\!
|
||||
@ -85,14 +84,10 @@ cat <<\!
|
||||
tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
|
||||
awk '{ printf "#define %s %d\n", $1, NR-1}'
|
||||
echo '
|
||||
struct builtincmd {
|
||||
const char *name;
|
||||
int code;
|
||||
int special;
|
||||
};
|
||||
#define BUILTIN_SPECIAL 0x80
|
||||
|
||||
extern int (*const builtinfunc[])(int, char **);
|
||||
extern const struct builtincmd builtincmd[];
|
||||
extern const unsigned char builtincmd[];
|
||||
'
|
||||
awk '{ printf "int %s(int, char **);\n", $1}' $temp
|
||||
rm -f $temp
|
||||
|
Loading…
x
Reference in New Issue
Block a user