source: trunk/debathena/third/bash/hesiod.dpatch @ 22698

Revision 22698, 3.6 KB checked in by ghudson, 16 years ago (diff)
Snapshot some of the Debathena third-party package materials. This commit only covers the packages which use the debathenificator framework (bash, tcsh, krb5).
  • Property svn:executable set to *
Line 
1#! /bin/sh -e
2
3if [ $# -eq 3 -a "$2" = '-d' ]; then
4    pdir="-d $3"
5elif [ $# -ne 1 ]; then
6    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
7    exit 1
8fi
9case "$1" in
10    -patch) patch $pdir -f --no-backup-if-mismatch -p1 < $0;;
11    -unpatch) patch $pdir -f --no-backup-if-mismatch -R -p1 < $0;;
12    *)
13        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
14        exit 1
15esac
16exit 0
17
18# DP: Support Hesiod-based ~ expansion; from Athena 9.4 bash.
19
20diff -ur bash-3.0.16.orig/general.c bash-3.0.16/general.c
21--- bash-3.0.16.orig/general.c  2004-10-26 17:13:29.000000000 -0400
22+++ bash-3.0.16/general.c       2005-04-15 02:01:50.000000000 -0400
23@@ -56,6 +56,11 @@
24 static int unquoted_tilde_word __P((const char *));
25 static void initialize_group_array __P((void));
26 
27+#ifdef HESIOD
28+#include <hesiod.h>
29+static char *hes_gethomedir __P((char *));
30+#endif
31+
32 /* A standard error message to use when getcwd() returns NULL. */
33 char *bash_getcwd_errstr = N_("getcwd: cannot access parent directories");
34 
35@@ -706,10 +711,78 @@
36   else if (DIGIT (*text) || ((*text == '+' || *text == '-') && DIGIT (text[1])))
37     result = get_dirstack_from_string (text);
38 #endif
39+#ifdef HESIOD
40+  /* Always use hesiod for ~~username. */
41+  else if (*text == '~')
42+    {
43+      *text++;
44+      result = hes_gethomedir(text);
45+    }
46+#endif
47 
48   return (result ? savestring (result) : (char *)NULL);
49 }
50 
51+#ifdef HESIOD
52+static char *
53+hes_gethomedir (us)
54+     char *us;
55+{
56+  char **res, **res1, *cp, *rp;
57+  int which;
58+
59+  res = hes_resolve(us, "filsys");
60+  rp = 0;
61+  if (res != 0) {
62+    extern char *strtok();
63+    if ((*res) != 0) {
64+      int i, lowest, new;
65+
66+      /* Use the first filesys if there's an ordered list */
67+      lowest = -1;
68+      which = 0;
69+      if (res[1]) {
70+        for (i = 0; res[i]; i++) {
71+          cp = strrchr(res[i], ' ');
72+          if (!cp)
73+            return NULL;
74+          new = atoi(cp + 1);
75+          if (lowest == -1 || new < lowest) {
76+            lowest = new;
77+            which = i;
78+          }
79+        }
80+      }
81+      /*
82+       * Look at the first token to determine how to interpret
83+       * the rest of it.
84+       * Yes, strtok is evil (it's not thread-safe), but it's also
85+       * easy to use.
86+       */
87+      cp = strtok(res[which], " ");
88+      if (strcmp(cp, "AFS") == 0) {
89+        /* next token is AFS pathname.. */
90+        cp = strtok(NULL, " ");
91+        if (cp != NULL)
92+          rp = savestring(cp);
93+      } else if (strcmp(cp, "NFS") == 0) {
94+        cp = NULL;
95+        if ((strtok(NULL, " ")) && /* skip remote pathname */
96+            (strtok(NULL, " ")) && /* skip host */
97+            (strtok(NULL, " ")) && /* skip mode */
98+            (cp = strtok(NULL, " "))) {
99+          rp = savestring(cp);
100+        }
101+      }
102+    }
103+    for (res1 = res; *res1; res1++)
104+      free(*res1);
105+    return rp;
106+  }
107+  return NULL;
108+}
109+#endif /* HESIOD */
110+
111 /* Initialize the tilde expander.  In Bash, we handle `~-' and `~+', as
112    well as handling special tilde prefixes; `:~" and `=~' are indications
113    that we should do tilde expansion. */
114@@ -721,6 +794,11 @@
115   /* Tell the tilde expander that we want a crack first. */
116   tilde_expansion_preexpansion_hook = bash_special_tilde_expansions;
117 
118+#ifdef HESIOD
119+  /* Fall back to hesiod if the default behavior fails. */
120+  tilde_expansion_failure_hook = hes_gethomedir;
121+#endif
122+
123   /* Tell the tilde expander about special strings which start a tilde
124      expansion, and the special strings that end one.  Only do this once.
125      tilde_initialize () is called from within bashline_reinitialize (). */
Note: See TracBrowser for help on using the repository browser.