Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ie/ie.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1984-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# Pat Sullivan #
19
# #
20
########################################################################
21
: ie : execute a command with ksh-style input editing
22
23
typeset env histfile show command opt prefix dll suffix ifs root path s
24
typeset OPT ARGV0 USAGE
25
26
command=ie
27
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
28
0123) ARGV0="-a $command"
29
USAGE=$'
30
[-?
31
@(#)$Id: ie (AT&T Labs Research) 1998-11-30 $
32
]
33
'$USAGE_LICENSE$'
34
[+NAME?ie - execute a command with ksh-style input editing]
35
[+DESCRIPTION?\bie\b executes a dynamically linked \acommand\a
36
with ksh-style input editing on the standard input terminal. The
37
default history file name is \b$HOME/.\abase\a, where \abase\a is
38
the base name of \acommand\a with leading [\bnox\b]] deleted. All processes
39
executed by \acommand\a will have input editing enabled on the same
40
history file.]
41
[h:history?Sets the history file name to \apath\a.]:[path]
42
[n!:exec?Execute \acommand\a. \b--noexec\b shows how \acommand\a would be
43
invoked but does not execute.]
44
[+DETAILS?Input editing is implemented by intercepting the \bread\b(2) system call
45
on file descriptor 0 with a dll that is preloaded at process startup
46
before \amain\a() is called. The interception mechanism may involve the
47
environment on some systems; in those cases commands like \benv\b(1)
48
that clear the enviroment before execution may defeat the \bie\b
49
intercept.]
50
[+?Also intercepted are the \b_\b and \b_libc_\b name permutations of the
51
\bread\b call, as well as any 32-bit and 64-bit versions. \bie\b
52
ignores calls not present in a particular host system. In addition,
53
\bie\b only works on dynamically linked executables that have neither
54
set-uid nor set-gid permissions. It may not have the intended effect
55
on programs written in a language or linked with a language runtime
56
that hides or mangles system call library symbols, or that
57
directly emit system call instruction sequences rather than using
58
the corresponding library functions, or that dynamically link
59
libraries outside of the scope of the \bie\b intercepts.]
60
[+?Multi-process client-server applications may misbehave if the \bie\b
61
environment between the related processes is not kept in sync.]
62
63
command [ arg ... ]
64
65
[+ENVIRONMENT?\bie\b is implemented by two components: the \bie\b script,
66
located on \b$PATH\b and the \bie\b dll (shared library), located
67
either on \b$PATH\b or in one of the \b../lib\b* directories on
68
\b$PATH\b, depending on local compilation system conventions. Systems
69
like \bsgi.mips3\b that support multiple a.out formats may have
70
multiple versions of the \bie\b dll. In all cases the \bie\b script
71
handles the dll search.]
72
[+SEE ALSO?\b3d\b(1), \bsh\b(1), \btrace\b(1), \bwarp\b(1), \bread\b(2)]
73
'
74
;;
75
*) ARGV0=""
76
USAGE='h:[history]nt command [ arg ... ]'
77
;;
78
esac
79
80
: grab the options
81
82
while getopts $ARGV0 "$USAGE" OPT
83
do case $OPT in
84
h) histfile=$OPTARG ;;
85
n) show=print ;;
86
*) exit 2 ;;
87
esac
88
done
89
shift $OPTIND-1
90
case $# in
91
0) set -- '-?'; getopts $ARGV0 "$USAGE" OPT; exit 2 ;;
92
esac
93
94
: history file hooks
95
96
if test -x "$1"
97
then command=$1
98
else command=$(whence $1)
99
fi
100
shift
101
case $histfile in
102
'') histfile=${command##*/}
103
case $histfile in
104
[nox]?*) histfile=${histfile#?} ;;
105
esac
106
histfile=$HOME/.$histfile
107
;;
108
esac
109
110
: find the dll root dir
111
112
ifs=${IFS-'
113
'}
114
IFS=:
115
set -A path $PATH
116
IFS=$ifs
117
for root in ${path[@]}
118
do root=${root%/*}
119
set -A lib $root/@(bin|lib)/@(lib|)edit*([0-9]).@(dll|s[ol]*([0-9.]))
120
dll=${lib[${#lib[@]}-1]}
121
if test -f $dll
122
then break
123
fi
124
done
125
prefix=${dll%.@(dll|s[ol]*([0-9.]))}
126
suffix=${dll##$prefix}
127
prefix=${prefix#$root/}
128
129
: hack the preload magic, and we mean hack
130
131
env="HISTFILE='$histfile' LD_PRELOAD='$root/$prefix$suffix${LD_PRELOAD:+ $LD_PRELOAD}'"
132
case $root in
133
*-n32) env="$env _RLDN32_LIST=$root/$prefix$suffix"
134
case $_RLDN32_LIST in
135
"") env="$env:DEFAULT" ;;
136
*) env="$env:$_RLDN32_LIST" ;;
137
esac
138
;;
139
*) if test -f $root/$prefix-n32$suffix
140
then env="$env _RLD64_LIST=$dll"
141
case $_RLD64_LIST in
142
"") env="$env:DEFAULT" ;;
143
*) env="$env:$_RLD64_LIST" ;;
144
esac
145
env="$env _RLDN32_LIST=$root/$prefix-n32$suffix"
146
case $_RLDN32_LIST in
147
"") env="$env:DEFAULT" ;;
148
*) env="$env:$_RLDN32_LIST" ;;
149
esac
150
env="$env _RLD_LIST=$root/$prefix-o32$suffix"
151
case $_RLD_LIST in
152
"") env="$env:DEFAULT" ;;
153
*) env="$env:$_RLD_LIST" ;;
154
esac
155
elif test -f $root/$prefix-64$suffix -o -f $root/$prefix-o32$suffix
156
then env="$env _RLD64_LIST=$root/$prefix-64$suffix"
157
case $_RLD64_LIST in
158
"") env="$env:DEFAULT" ;;
159
*) env="$env:$_RLD64_LIST" ;;
160
esac
161
env="$env _RLDN32_LIST=$dll"
162
case $_RLDN32_LIST in
163
"") env="$env:DEFAULT" ;;
164
*) env="$env:$_RLDN32_LIST" ;;
165
esac
166
env="$env _RLD_LIST=$root/$prefix-o32$suffix"
167
case $_RLD_LIST in
168
"") env="$env:DEFAULT" ;;
169
*) env="$env:$_RLD_LIST" ;;
170
esac
171
else case $root in
172
*/sgi.mips[2-9]*)
173
root=${root%-*}
174
root=${root%?}
175
env="$env _RLD64_LIST=${root}4/$prefix$suffix"
176
case $_RLD64_LIST in
177
"") env="$env:DEFAULT" ;;
178
*) env="$env:$_RLD64_LIST" ;;
179
esac
180
env="$env _RLDN32_LIST=${root}3/$prefix$suffix"
181
case $_RLDN32_LIST in
182
"") env="$env:DEFAULT" ;;
183
*) env="$env:$_RLDN32_LIST" ;;
184
esac
185
env="$env _RLD_LIST=${root}2/$prefix$suffix"
186
case $_RLD_LIST in
187
"") env="$env:DEFAULT" ;;
188
*) env="$env:$_RLD_LIST" ;;
189
esac
190
;;
191
*) env="$env _RLD_LIST=${root}/$prefix$suffix"
192
case $_RLD_LIST in
193
"") env="$env:DEFAULT" ;;
194
*) env="$env:$_RLD_LIST" ;;
195
esac
196
esac
197
fi
198
;;
199
esac
200
201
: engage
202
203
case $show in
204
"") eval $env '$command "$@"' ;;
205
*) $show $env $command "$@" ;;
206
esac
207
208