[net.micro.att] more 7300 goodies

corey@fluke.UUCP (Corey Satten) (02/21/86)

: ------ cut here ------ ------ cut here ------ ------ cut here ------
: To unbundle, remove any lines above this one and feed the rest to "sh"
: by typing: sh thisfile.  --DO NOT use csh--
: SHAR format archive created: Fri Feb 21 10:43:55 PST 1986
echo x - READ_ME
echo '-rw-r--r--  1 corey        2991 Feb 21 10:43 READ_ME    (as sent)'
sed 's/^X//' >READ_ME <<'+FUNKY+STUFF+'
X
X As many of you are undoubtedly aware by now, version 3.0 of the Unix
X Utilities for the AT&T Unix-PC includes the Korn shell, ksh.  Probably
X the nicest feature of ksh for Unix systems without Berkeley style job
X control (such as sys V), is the ability to access a parent shell's history
X from a subshell.  This makes it possible to pop in and out of an editor
X and use the history mechanism to re-run whatever you last did, much as
X Berkeley Unix folks have been doing for years by stopping the editor.
X Though by no means equivalent to stopping an editor, in many cases, it's
X sufficient to fork a new shell from the editor if the environment and
X history in the new shell is the same as it was in the shell which invoked
X the editor.  Enough justification!  If you switch your default shell to
X ksh, you'll be wanting a .profile and .kshrc file to get you started.  I
X offer you mine.
X
X The majority of my .kshrc file is devoted to implementing a directory
X stacking mechanism similar to that of csh.  My implementation of these is
X less than obvious because of the need to code around a ksh bug involving
X shell functions.  As it happens, the entire body of a shell function is
X copied into your history file each time you start a new shell (often if
X you believe in the above method of popping in and out of editors.) A sneaky
X work-around to this is to put the body of the function in an alias, and
X put nothing but the alias in the definition of the function.  This keeps
X the overhead down to a few tens of bytes per subshell rather than about 1K.
X The disadvantage is that you run into another ksh bug which sometimes
X requires you to source (.) your .kshrc file twice in order to get the
X aliases into the functions.  Fortunately, this doesn't happen during ksh
X startup so unless you manually source the .kshrc file you won't ever notice
X the bug.  Other than that, you should be able to figure out what's
X happening if you speak sh.
X
X By the way, the obfuscated shell function for su is a work-around for the
X problem recently pointed out by Paul Fox (pfg@mtung.UUCP).  Using this su
X will allow you to have /bin/sh in your password file yet still invoke ksh
X when you type su.  Hopefully I have handled all the useful options.
X
X My second contribution is a script called nx, which postprocesses the
X output from nm into something sortable and grepable as it was back in the
X "good old" (pre sys V) days.
X
X A final thought:  Last time I posted anything to this group, I got no
X feedback (good or bad) for 6 weeks.  I was almost convinced that my posting
X never got out of the building when suddenly someone far away posted a
X followup.  Now I know we're all busy, and I too snarf up postings without
X ever replying, but there ought to be a way of at least finding out that
X the posting went out.  I offer no workable solution.
X
X The following code is hereby introduced into the public domain for use by
X anyone for anything at any time, etc.  Use at your own risk, etc., etc.
X
+FUNKY+STUFF+
chmod u=rw,g=r,o=r READ_ME
ls -l READ_ME
echo x - profile
echo '-rw-r--r--  1 corey         189 Feb 11 17:44 profile    (as sent)'
sed 's/^X//' >profile <<'+FUNKY+STUFF+'
Xexport me EXINIT TLS ENV HISTFILE
Xme=$HOME
XEXINIT=`cat $me/.exinit`
XENV=$me/.kshrc
XHISTFILE=$me/.kshhist
XTLS=75;
XPATH=:$me/bin:$me/binsh:/bin:/usr/bin:/etc
Xrm -f $HISTFILE
Xexec /usr/bin/ua
+FUNKY+STUFF+
chmod u=rw,g=r,o=r profile
ls -l profile
echo x - kshrc
echo '-rw-r--r--  1 corey        2321 Feb 21 08:36 kshrc    (as sent)'
sed 's/^X//' >kshrc <<'+FUNKY+STUFF+'
X################ start of pushd, popd, dirs package
X# ksh implementation of pushd/popd ala csh - Corey Satten 1/31/86
X#
X# usage: pushd newdir		stack and change to newdir
X#        pushd			swap top and top-1
X#        pushd +#		swap top and top-#
X
Xtypeset -i _p=${_p-1} _j
X
Xalias _pushd='case "$1" in
X	+[0-9]* | "")
X	    s=${1#+}; s=${s:-1};
X	    if [ $_p -ge 2 -a $_p -gt $s ] ;then
X		_v[$_p]=${_v[$_p-$s]}
X		_v[$_p-$s]=$PWD
X		cd ${_v[$_p]}
X	    else
X		print - \\c
X		fi
X	    ;;
X	*)
X	    _v[$_p]=$PWD
X	    if [ -d $1 ] ;then
X		((_p=$_p+1))
X		cd $1
X	    else
X		print - \\c
X		fi
X	    ;;
X    esac
X    dirs
X'
X
Xalias _dirs='
X    _v[_p]="$PWD"
X    _j=$_p;
X    while [ _j -gt 0 ] ;do
X	if [ "$HOME" != "/" -a "${_v[$_j]}" != "${_v[$_j]#$HOME}" ] ;then
X	    print - "~${_v[$_j]#$HOME} \\c" 
X	else
X	    print - "${_v[$_j]} \\c"
X	    fi
X	((_j=$_j-1))
X	done
X    print -
X'
X
X# can't re-alias so must name popd here
Xalias popd='
X    if [ "$_p" -lt 2 ] ;then
X	print - \\c
X    else
X	((_p=$_p-1))
X	cd ${_v[$_p]}
X	fi
X    dirs
X'
X
Xdirs () { _dirs; }
Xpushd () { _pushd; }
X################ end of pushd, popd, dirs package
X
X# leave /bin/sh as default shell in /etc/passwd, use office to set default shell
X# otherwise "su name -c command" fails, breaking some crontab entries, etc.
X# instead, instruct su to run ksh as follows:
X
Xalias _su='
X    typeset H U
X    case $# in
X	0|1) U=${1-root}; eval H=~$U;
X	   /bin/su $U -c "HOME=$H; export HOME; exec ksh";;
X	*) /bin/su "$@";;
X    esac
X    '
Xsu () { _su }
X
X# setup a fancy prompt with:  hostname directory process-id special-symbol
X# special symbol will be # if you are root, colon (:) otherwise
X
Xif [ "$HOME" = "/" ] ;then _=# ;else _=: ;fi
XPS1="! PC..\${PWD##*/} $$$_ "
Xset -h
XEDITOR=/usr/bin/vi					#for command editing
X
X# ksh may not prehash, so scripts may run faster if you alias common tools
Xalias -x grep=/bin/grep
Xalias -x sed=/bin/sed
Xalias -x awk=/usr/bin/awk
Xalias -x cat=/bin/cat
Xalias -x vi=/usr/bin/vi
X
X#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
X# the following are personal aliases you will probably not want to keep
X#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
Xalias a=alias
Xalias j='jobs -l'
Xalias l='ls -F'
Xalias c=/bin/cat
Xalias h='fc -l'
Xalias hg='fc -l -250 | grep'
Xalias ll='ls -lF'
Xalias back='cd ~-; dirs'
+FUNKY+STUFF+
chmod u=rw,g=r,o=r kshrc
ls -l kshrc
echo x - nx
echo '-rwxr-xr-x  1 corey        1124 Feb 20 16:46 nx    (as sent)'
sed 's/^X//' >nx <<'+FUNKY+STUFF+'
X: '
X: A postprocessor for common object format nm output which is:
X:   1 - sortable
X:   2 - grepable for a symbol to file mapping
X:   3 - less cluttered and more aligned with the unix philosophy
X:
X: Usage: nx options files
X:	options passed directly to nm
X:
X: This program is hereby officially introduced into the public domain.
X:	Corey Satten,  fluke!corey,  Feb. 20, 1986
X: '
X
XSTANDARD_NM=/bin/nm
XFLAGS=-e
Xfor i in $* ;do
X    case "$i" in
X	-*) FLAGS="$FLAGS $i"; shift;;
X	*)  break;;
X	esac
X    done
Xfor FILE in $* ;do
X    $STANDARD_NM $FLAGS $FILE |
X    sed -n '
X    1 {
X	h
X	s|.*|'"$FILE"'|
X	x
X	}
X    /^Symbols from \([^:]*\):$/ {
X	s//\1/
X	h
X	b noprint
X	}
X    /|static|/ {
X	/|\.text/s/^\([^|]*\)|\([^|]*\).*/\1 T \2/
X	/|\.data/s/^\([^|]*\)|\([^|]*\).*/\1 D \2/
X	/|\.bss/ s/^\([^|]*\)|\([^|]*\).*/\1 B \2/
X	s/^\([^|]*\)|\([^|]*\).*/\1 U \2/
X	t print
X	}
X    /|extern|/ {
X	/|\.text/s/^\([^|]*\)|\([^|]*\).*/\1 t \2/
X	/|\.data/s/^\([^|]*\)|\([^|]*\).*/\1 d \2/
X	/|\.bss/ s/^\([^|]*\)|\([^|]*\).*/\1 b \2/
X	s/^\([^|]*\)|\([^|]*\).*/\1 u \2/
X	t print
X	}
X
X    b noprint
X    : print
X    G; s/\n/  /; p
X    : noprint
X    '
X    done
+FUNKY+STUFF+
chmod u=rwx,g=rx,o=rx nx
ls -l nx
echo x - nx.1
echo '-rw-r--r--  1 corey        1772 Feb 20 16:27 nx.1    (as sent)'
sed 's/^X//' >nx.1 <<'+FUNKY+STUFF+'
X.TH nx LOCAL
X.UC 4
X.SH NAME
Xnx \- simplified and unified output from nm
X.SH SYNOPSIS
X.B nx [flags] files
X.SH DESCRIPTION
X.PP
XThe standard
X.I nm
Xcommon object file name list utility produces very verbose and tabular output
Xwhich is difficult to use in other scripts.  It is also difficult to
Xgrep in the customary way to find out which symbols are defined in which
Xfiles as V7 and 4.2BSD folks are accustomed to doing.
X.I nx
Xattempts to rectify this by postprocessing the tabular output of
X.I nm
Xinto something approximating the Berkeley output format, for example:
X.sp 1
X    _doprnt              u        0  libc.a[fprintf.o]
X    sprintf              t        0  libc.a[sprintf.o]
X    _doprnt              u        0  libc.a[sprintf.o]
X    _flsbuf              u        0  libc.a[sprintf.o]
X    printf               t        0  libc.a[printf.o]
X    _iob                 u        0  libc.a[printf.o]
X    _doprnt              u        0  libc.a[printf.o]
X    scanf                t        0  libc.a[scanf.o]
X    fscanf               t       34  libc.a[scanf.o]
X.PP
XThe single letter codes { t d u B T D } indicate the value is of type
Xdefined extern text, defined extern data, undefined reference, BSS, defined
Xstatic text, and defined static data respectively.  The file name is taken
Xfrom the tabular output of
X.I nm
Xif present, otherwise the command line file name is used.  The notation
Xfile[member] refers to a member of an archive (library) created by
X.I ar.
XThis can be
Xespecially handy for looking through the runtime library.
X.PP
X.I nx
Xsimply calls
X.I nm -e
Xso please see the manual for
X.I nm
Xfor a list and description of options.
X.SH SEE ALSO
Xnm(l), as(l), ld(l), cc(l), ar(l)
X.SH AUTHOR
XCorey Satten \- fluke!corey
X.SH BUGS
XAny bugs in
X.I nm
Xapply here as well.
+FUNKY+STUFF+
chmod u=rw,g=r,o=r nx.1
ls -l nx.1
exit 0
-- 

                                *******
Corey Satten; John Fluke Mfg. Co MS 223B; PO Box C9090 Everett WA 98206
{uw-beaver,decvax!microsoft,ucbvax!lbl-csam,allegra,tikal}!fluke!corey
                             (206) 356-5058