From e960fabf6363017928322fa242ae7a283a5e4813 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 11 Jan 2007 00:32:31 +0000 Subject: [PATCH] expand ~foo to getpwnam("foo")->dir only #if !defined(MKSH_SMALL) this makes it possible to build a (small) mksh on glibc systems statically --- check.t | 4 ++-- eval.c | 8 +++++++- funcs.c | 10 +++++++++- main.c | 4 +++- sh.h | 6 ++++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/check.t b/check.t index dd135f6..9591d47 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.78 2007/01/06 17:08:14 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.79 2007/01/11 00:32:30 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -7,7 +7,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R29 2007/01/06 + @(#)MIRBSD KSH R29 2007/01/11 description: Check version of shell. category: pdksh diff --git a/eval.c b/eval.c index d6dc2b7..d38dab2 100644 --- a/eval.c +++ b/eval.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.19 2006/11/12 14:58:14 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.20 2007/01/11 00:32:30 tg Exp $"); /* * string expansion @@ -43,7 +43,11 @@ static void glob(char *, XPtrV *, int); static void globit(XString *, char **, char *, XPtrV *, int); static char *maybe_expand_tilde(char *, XString *, char **, int); static char *tilde(char *); +#ifndef MKSH_SMALL static char *homedir(char *); +#else +#define homedir(x) null +#endif static void alt_expand(XPtrV *, char *, char *, char *, int); /* compile and expand word */ @@ -1171,6 +1175,7 @@ tilde(char *cp) return dp; } +#ifndef MKSH_SMALL /* * map userid to user's home directory. * note that 4.3's getpw adds more than 6K to the shell, @@ -1195,6 +1200,7 @@ homedir(char *name) } return ap->val.s; } +#endif static void alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo) diff --git a/funcs.c b/funcs.c index c4315e0..a99b506 100644 --- a/funcs.c +++ b/funcs.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.39 2006/12/06 13:41:23 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.40 2007/01/11 00:32:31 tg Exp $"); int c_cd(char **wp) @@ -815,7 +815,11 @@ c_alias(char **wp) prefix = builtin_opt.info & GI_PLUS ? '+' : '-'; switch (optc) { case 'd': +#ifdef MKSH_SMALL + return (0); +#else t = &homedirs; +#endif break; case 'p': pflag = 1; @@ -950,7 +954,11 @@ c_unalias(char **wp) all = 1; break; case 'd': +#ifdef MKSH_SMALL + return (0); +#else t = &homedirs; +#endif break; case 't': t = &taliases; diff --git a/main.c b/main.c index 81d251b..6de5206 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.64 2007/01/06 17:08:14 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.65 2007/01/11 00:32:31 tg Exp $"); extern char **environ; @@ -117,7 +117,9 @@ main(int argc, char *argv[]) /* set up variable and command dictionaries */ ktinit(&taliases, APERM, 0); ktinit(&aliases, APERM, 0); +#ifndef MKSH_SMALL ktinit(&homedirs, APERM, 0); +#endif /* define shell keywords */ initkeywords(); diff --git a/sh.h b/sh.h index 9c2aa68..e75c382 100644 --- a/sh.h +++ b/sh.h @@ -8,8 +8,8 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.91 2007/01/06 18:48:27 tg Exp $" -#define MKSH_VERSION "R29 2007/01/06" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.92 2007/01/11 00:32:31 tg Exp $" +#define MKSH_VERSION "R29 2007/01/11" #if HAVE_SYS_PARAM_H #include @@ -683,7 +683,9 @@ EXTERN struct table taliases; /* tracked aliases */ EXTERN struct table builtins; /* built-in commands */ EXTERN struct table aliases; /* aliases */ EXTERN struct table keywords; /* keywords */ +#ifndef MKSH_SMALL EXTERN struct table homedirs; /* homedir() cache */ +#endif struct builtin { const char *name;