home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: jpmens@ingres.com (Jan-Piet Mens)
- Subject: v40i114: vname - build filename from metacharacters, Part01/01
- Message-ID: <1993Nov9.023400.22919@sparky.sterling.com>
- X-Md4-Signature: 59e7142c6983c35ff99b5e420af85892
- Sender: kent@sparky.sterling.com (Kent Landfield)
- Organization: Ingres GmbH, Frankfurt, Germany
- Date: Tue, 9 Nov 1993 02:34:00 GMT
- Approved: kent@sparky.sterling.com
-
- Submitted-by: jpmens@ingres.com (Jan-Piet Mens)
- Posting-number: Volume 40, Issue 114
- Archive-name: vname/part01
- Environment: UNIX
-
- vname() will expand the meta characters in the pathname string and return
- a pathname that may be fed to open () et al.
- The metacharacters that vname() understands are the tilde and dollar sign.
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: Makefile config.h samples tt.c vname.3 vname.3.ps vname.c
- # vname.h
- # Wrapped by jpmens@trsun1 on Thu Nov 4 16:06:05 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(241 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- XCC=gcc
- XCFLAGS=-Wall -g -I.
- X
- XLIB=libv.a
- XOBJ= $(LIB)(vname.o)
- X
- Xall: $(LIB) tt
- X
- Xtt: tt.o $(LIB)
- X $(CC) $(CFLAGS) -o tt tt.o $(LIB)
- X
- X$(LIB): $(OBJ)
- X ranlib $(LIB)
- X$(OBJ): config.h vname.h
- X
- Xclean:
- X rm -f *.o core
- Xclobber: clean
- X rm -f tt $(LIB)
- END_OF_FILE
- if test 241 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'config.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'config.h'\"
- else
- echo shar: Extracting \"'config.h'\" \(133 characters\)
- sed "s/^X//" >'config.h' <<'END_OF_FILE'
- X#include <sys/param.h>
- X
- X#ifndef MAXPATHLEN
- X# define MAXPATHLEN 1024
- X#endif
- X#define EOS '\0'
- X#define BLEN 128 /* Sundry buffers */
- END_OF_FILE
- if test 133 -ne `wc -c <'config.h'`; then
- echo shar: \"'config.h'\" unpacked with wrong size!
- fi
- # end of 'config.h'
- fi
- if test -f 'samples' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'samples'\"
- else
- echo shar: Extracting \"'samples'\" \(90 characters\)
- sed "s/^X//" >'samples' <<'END_OF_FILE'
- X$II_SYSTEM
- X$HOME/my/file
- X~/my/file
- X~root/etc/passwd
- X~dieterl/$HOME/$NOT/$FOUND/~jpmens/kk
- END_OF_FILE
- if test 90 -ne `wc -c <'samples'`; then
- echo shar: \"'samples'\" unpacked with wrong size!
- fi
- # end of 'samples'
- fi
- if test -f 'tt.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tt.c'\"
- else
- echo shar: Extracting \"'tt.c'\" \(503 characters\)
- sed "s/^X//" >'tt.c' <<'END_OF_FILE'
- X#include <vname.h>
- X#include <stdio.h>
- X#include <errno.h>
- X#include <fcntl.h>
- X
- Xint main(argc, argv)
- Xint argc;
- Xchar **argv;
- X{
- X char buf[1000];
- X int fd;
- X extern char *sys_errlist[];
- X extern int errno;
- X
- X
- X if (argc == 1) {
- X while (gets(buf))
- X (void) printf("%s = [%s]\n", buf, vname(buf));
- X return (0);
- X }
- X
- X while (*++argv) {
- X fd = vopen(*argv, O_RDONLY, 0);
- X (void) printf("%s => %s\n", last_vname,
- X (fd != -1) ? "ok" : sys_errlist[errno]);
- X if (fd != -1)
- X (void) vclose(fd);
- X }
- X return (0);
- X}
- END_OF_FILE
- if test 503 -ne `wc -c <'tt.c'`; then
- echo shar: \"'tt.c'\" unpacked with wrong size!
- fi
- # end of 'tt.c'
- fi
- if test -f 'vname.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vname.3'\"
- else
- echo shar: Extracting \"'vname.3'\" \(2240 characters\)
- sed "s/^X//" >'vname.3' <<'END_OF_FILE'
- X.de L
- X.nr pq \\n(.f
- X.if t .ft CR
- X.if n .ft 1
- X.if !\e\\$1\e\e \&\\s-\\n(Ls\\$1\|\\s+\\n(Ls\f\\n(pq\\$2
- X..
- X.TH VNAME 3 "Local Facilities" vname-1.1
- X.SH NAME
- X.B vname
- X\-
- Xbuild filename from metacharacters
- X.SH SYNOPSIS
- X.nf
- X\fB#include <vname.h>
- X
- Xextern char last_vname[];
- X
- Xchar *vname(char *pathname)\fR
- X.fi
- X.SH DESCRIPTION
- X.BR vname ()
- Xwill expand the meta characters in the
- X.I pathname
- Xstring and return a pathname that may be fed to
- X.IR open ()
- Xet al.
- XThe metacharacters that
- X.BR vname ()
- Xunderstands are the tilde
- X.B ~
- Xand dollar sign
- X.BR $ .
- X.PP
- XEach
- X.I pathname
- Xis checked to see if it begins with a ~.
- XIf it does, then the word up to a / is checked to see if it
- Xmatches the name of a user. If so, then the ~
- Xand the matched portion are replaced with the value of the
- Xuser's home directory. A ~ by itself or followed by a / is
- Xreplaced by the value of the user's home directory.
- XThe character
- X.B $
- Xis used to introduce parameter expansions which are taken from the user's
- Xenvironment.
- X.PP
- XThis routine is typically used for expanding pathnames prior to an
- X.IR open ()
- Xor
- X.IR fopen ()
- Xcall as in
- X.ft CR
- X.sp
- X.nf
- X int fd;
- X char *name;
- X
- X name = vname("~joe/his/file/called/$SOMETHING/or/$other");
- X fd = open(name, O_RDONLY);
- X.ft
- X.fi
- X.PP
- XThe file
- X.B <vname.h>
- Xdefines several macros which expand the
- X.I path
- Xargument of the macro using
- X.BR vname ().
- XThe names of theses macros begin with the letter
- X.BR v .
- X.ps -2
- X.TS
- Xtab(@), center, box;
- Xlb lb | lb lb
- Xlb l | lb l.
- Xmacro@function@macro@function
- X_
- Xvaccess@access@vopen@open
- Xvclose@close@vchdir@chdir
- Xvchmod@chmod@vchown@chown
- Xvexecv@execv@vexecve@execve
- Xvexecvp@execvp@vlink@link
- Xvrmdir@rmdir@vunlink@unlink
- Xvfopen@fopen@vpopen@popen
- X.TE
- X.ps
- X.PP
- XThe above macros may be used as in
- X.ft CR
- X.sp
- X.nf
- X int fd;
- X
- X fd = vopen("~joe/his/file/called/$SOMETHING/or/$other", O_RDONLY);
- X.ft
- X.fi
- X.PP
- XThe external array
- X.L last_vname
- Xalways points to the result of the last
- X.BR vname ()
- Xcall and thus contains the last pathname that was expanded.
- X.SH RETURN VALUE
- X.BR vname ()
- Xreturns a pointer to a value that is overwritten at each call.
- X.SH FILES
- X.IP "\fI/etc/passwd\fR" 1i
- Xfor matching ~
- X.IR name.
- X.SH SEE ALSO
- X.IR sh (1),
- X.IR open (2),
- X.IR fopen (3)
- X.SH AUTHOR
- XJan-Piet Mens <jpmens@ingres.com>
- END_OF_FILE
- if test 2240 -ne `wc -c <'vname.3'`; then
- echo shar: \"'vname.3'\" unpacked with wrong size!
- fi
- # end of 'vname.3'
- fi
- if test -f 'vname.3.ps' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vname.3.ps'\"
- else
- echo shar: Extracting \"'vname.3.ps'\" \(9748 characters\)
- sed "s/^X//" >'vname.3.ps' <<'END_OF_FILE'
- X%!PS-Adobe-3.0
- X%%Creator: groff version 1.08
- X%%DocumentNeededResources: font Times-Bold
- X%%+ font Times-Roman
- X%%+ font Times-Italic
- X%%+ font Courier
- X%%DocumentSuppliedResources: procset grops 1.08 0
- X%%Pages: 1
- X%%PageOrder: Ascend
- X%%Orientation: Portrait
- X%%EndComments
- X%%BeginProlog
- X%%BeginResource: procset grops 1.08 0
- X/setpacking where{
- Xpop
- Xcurrentpacking
- Xtrue setpacking
- X}if
- X/grops 120 dict dup begin
- X/SC 32 def
- X/A/show load def
- X/B{0 SC 3 -1 roll widthshow}bind def
- X/C{0 exch ashow}bind def
- X/D{0 exch 0 SC 5 2 roll awidthshow}bind def
- X/E{0 rmoveto show}bind def
- X/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
- X/G{0 rmoveto 0 exch ashow}bind def
- X/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
- X/I{0 exch rmoveto show}bind def
- X/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
- X/K{0 exch rmoveto 0 exch ashow}bind def
- X/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
- X/M{rmoveto show}bind def
- X/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
- X/O{rmoveto 0 exch ashow}bind def
- X/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
- X/Q{moveto show}bind def
- X/R{moveto 0 SC 3 -1 roll widthshow}bind def
- X/S{moveto 0 exch ashow}bind def
- X/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
- X/SF{
- Xfindfont exch
- X[exch dup 0 exch 0 exch neg 0 0]makefont
- Xdup setfont
- X[exch/setfont cvx]cvx bind def
- X}bind def
- X/MF{
- Xfindfont
- X[5 2 roll
- X0 3 1 roll
- Xneg 0 0]makefont
- Xdup setfont
- X[exch/setfont cvx]cvx bind def
- X}bind def
- X/level0 0 def
- X/RES 0 def
- X/PL 0 def
- X/LS 0 def
- X/PLG{
- Xgsave newpath clippath pathbbox grestore
- Xexch pop add exch pop
- X}bind def
- X/BP{
- X/level0 save def
- X1 setlinecap
- X1 setlinejoin
- X72 RES div dup scale
- XLS{
- X90 rotate
- X}{
- X0 PL translate
- X}ifelse
- X1 -1 scale
- X}bind def
- X/EP{
- Xlevel0 restore
- Xshowpage
- X}bind def
- X/DA{
- Xnewpath arcn stroke
- X}bind def
- X/SN{
- Xtransform
- X.25 sub exch .25 sub exch
- Xround .25 add exch round .25 add exch
- Xitransform
- X}bind def
- X/DL{
- XSN
- Xmoveto
- XSN
- Xlineto stroke
- X}bind def
- X/DC{
- Xnewpath 0 360 arc closepath
- X}bind def
- X/TM matrix def
- X/DE{
- XTM currentmatrix pop
- Xtranslate scale newpath 0 0 .5 0 360 arc closepath
- XTM setmatrix
- X}bind def
- X/RC/rcurveto load def
- X/RL/rlineto load def
- X/ST/stroke load def
- X/MT/moveto load def
- X/CL/closepath load def
- X/FL{
- Xcurrentgray exch setgray fill setgray
- X}bind def
- X/BL/fill load def
- X/LW/setlinewidth load def
- X/RE{
- Xfindfont
- Xdup maxlength 1 index/FontName known not{1 add}if dict begin
- X{
- X1 index/FID ne{def}{pop pop}ifelse
- X}forall
- X/Encoding exch def
- Xdup/FontName exch def
- Xcurrentdict end definefont pop
- X}bind def
- X/DEFS 0 def
- X/EBEGIN{
- Xmoveto
- XDEFS begin
- X}bind def
- X/EEND/end load def
- X/CNT 0 def
- X/level1 0 def
- X/PBEGIN{
- X/level1 save def
- Xtranslate
- Xdiv 3 1 roll div exch scale
- Xneg exch neg exch translate
- X0 setgray
- X0 setlinecap
- X1 setlinewidth
- X0 setlinejoin
- X10 setmiterlimit
- X[]0 setdash
- X/setstrokeadjust where{
- Xpop
- Xfalse setstrokeadjust
- X}if
- X/setoverprint where{
- Xpop
- Xfalse setoverprint
- X}if
- Xnewpath
- X/CNT countdictstack def
- Xuserdict begin
- X/showpage{}def
- X}bind def
- X/PEND{
- Xclear
- Xcountdictstack CNT sub{end}repeat
- Xlevel1 restore
- X}bind def
- Xend def
- X/setpacking where{
- Xpop
- Xsetpacking
- X}if
- X%%EndResource
- X%%IncludeResource: font Times-Bold
- X%%IncludeResource: font Times-Roman
- X%%IncludeResource: font Times-Italic
- X%%IncludeResource: font Courier
- Xgrops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL
- X841.89 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron/scaron
- X/zcaron/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef/.notdef/.notdef
- X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
- X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space
- X/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft
- X/parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four
- X/five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/at/A/B/C
- X/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash
- X/bracketright/circumflex/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q
- X/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase
- X/guillemotleft/guillemotright/bullet/florin/fraction/perthousand/dagger
- X/daggerdbl/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
- X/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
- X/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar
- X/section/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus
- X/registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu
- X/paragraph/periodcentered/cedilla/onesuperior/ordmasculine/guilsinglright
- X/onequarter/onehalf/threequarters/questiondown/Agrave/Aacute/Acircumflex/Atilde
- X/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute
- X/Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
- X/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
- X/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute
- X/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve
- X/oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex
- X/udieresis/yacute/thorn/ydieresis]def/Courier@0 ENC0/Courier RE/Times-Italic@0
- XENC0/Times-Italic RE/Times-Roman@0 ENC0/Times-Roman RE/Times-Bold@0 ENC0
- X/Times-Bold RE
- X%%EndProlog
- X%%Page: 1 1
- X%%BeginPageSetup
- XBP
- X%%EndPageSetup
- X/F0 10/Times-Bold@0 SF(VN)72 60 Q 367.04(AME\(3\) VN)-.2 F(AME\(3\))-.2 E/F1 9
- X/Times-Bold@0 SF -.18(NA)72 84 S(ME).18 E F0(vname)108 96 Q/F2 10/Times-Roman@0
- XSF 2.5<ad62>2.5 G(uild \214lename from metacharacters)151.77 96 Q F1(SYNOPSIS)
- X72 112.8 Q F0(#include <vname.h>)108 124.8 Q(exter)108 148.8 Q 2.5(nc)-.15 G
- X(har last_vname[];)142 148.8 Q(char *vname\(char *pathname\))108 172.8 Q F1
- X(DESCRIPTION)72 189.6 Q F0(vname)108 201.6 Q F2 .526(\(\) will e)B .526
- X(xpand the meta characters in the)-.15 F/F3 10/Times-Italic@0 SF(pathname)3.026
- XE F2 .525(string and return a pathname that may be fed to)3.026 F F3(open)108
- X213.6 Q F2(\(\) et al.).24 E(The metacharacters that)5 E F0(vname)2.5 E F2
- X(\(\) understands are the tilde)A F0(~)2.5 E F2(and dollar sign)2.5 E F0($)2.5
- XE F2(.)A(Each)108 230.4 Q F3(pathname)2.714 E F2 .214(is check)2.714 F .214
- X(ed to see if it be)-.1 F .214(gins with a ~.)-.15 F .215
- X(If it does, then the w)5.215 F .215(ord up to a / is check)-.1 F .215
- X(ed to see if)-.1 F .688(it matches the name of a user)108 242.4 R 3.187(.I)
- X-.55 G 3.187(fs)237.235 242.4 S .687
- X(o, then the ~ and the matched portion are replaced with the v)247.642 242.4 R
- X.687(alue of the)-.25 F(user')108 254.4 Q 2.803(sh)-.55 G .303(ome directory)
- X139.133 254.4 R -5.302 2.803(.A~ b)-.65 H 2.804(yi)221.066 254.4 S .304
- X(tself or follo)231.65 254.4 R .304(wed by a / is replaced by the v)-.25 F .304
- X(alue of the user')-.25 F 2.804(sh)-.55 G .304(ome directory)482.026 254.4 R(.)
- X-.65 E(The character)108 266.4 Q F0($)2.5 E F2
- X(is used to introduce parameter e)2.5 E(xpansions which are tak)-.15 E
- X(en from the user')-.1 E 2.5(se)-.55 G -.4(nv)475.15 266.4 S(ironment.).4 E
- X(This routine is typically used for e)108 283.2 Q
- X(xpanding pathnames prior to an)-.15 E F3(open)2.5 E F2(\(\) or).24 E F3(fopen)
- X2.5 E F2(\(\) call as in).24 E/F4 10/Courier@0 SF(int fd;)144 307.2 Q
- X(char *name;)144 319.2 Q
- X(name = vname\("~joe/his/file/called/$SOMETHING/or/$other"\);)144 343.2 Q
- X(fd = open\(name, O_RDONLY\);)144 355.2 Q F2 .52(The \214le)108 372 R F0
- X(<vname.h>)3.02 E F2 .52(de\214nes se)3.02 F -.15(ve)-.25 G .519
- X(ral macros which e).15 F .519(xpand the)-.15 F F3(path)3.019 E F2(ar)3.019 E
- X.519(gument of the macro using)-.18 F F0(vname)3.019 E F2(\(\).)A
- X(The names of theses macros be)108 384 Q(gin with the letter)-.15 E F0(v)2.5 E
- XF2(.)A .32 LW 401.124 388 246.876 388 DL/F5 8/Times-Bold@0 SF(macr)250.876 398
- XQ 17.488(of)-.144 G 10(unction macr)292.652 398 R 16.616(of)-.144 G(unction)
- X371.34 398 Q 401.124 402 246.876 402 DL -.08(va)250.876 412 S(ccess).08 E/F6 8
- X/Times-Roman@0 SF(access)289.988 412 Q F5 -.08(vo)330.436 412 S(pen).08 E F6
- X(open)368.676 412 Q F5(vclose)250.876 424 Q F6(close)289.988 424 Q F5(vchdir)
- X330.436 424 Q F6(chdir)368.676 424 Q F5(vchmod)250.876 436 Q F6(chmod)289.988
- X436 Q F5(vcho)330.436 436 Q(wn)-.08 E F6(cho)368.676 436 Q(wn)-.2 E F5 -.08(ve)
- X250.876 448 S(xecv).08 E F6 -.12(exe)289.988 448 S(cv).12 E F5 -.08(ve)330.436
- X448 S(xecv).08 E(e)-.08 E F6 -.12(exe)368.676 448 S(cv).12 E(e)-.12 E F5 -.08
- X(ve)250.876 460 S(xecvp).08 E F6 -.12(exe)289.988 460 S(cvp).12 E F5(vlink)
- X330.436 460 Q F6(link)368.676 460 Q F5(vrmdir)250.876 472 Q F6(rmdir)289.988
- X472 Q F5(vunlink)330.436 472 Q F6(unlink)368.676 472 Q F5(vf)250.876 484 Q
- X(open)-.2 E F6(fopen)289.988 484 Q F5(vpopen)330.436 484 Q F6(popen)368.676 484
- XQ 401.124 488 246.876 488 DL 324.436 388 324.436 488 DL 401.124 388 401.124 488
- XDL 246.876 388 246.876 488 DL F2(The abo)108 500.8 Q .3 -.15(ve m)-.15 H
- X(acros may be used as in).15 E F4(int fd;)139.112 524.8 Q
- X(fd = vopen\("~joe/his/file/called/$SOMETHING/or/$other", O_RDONLY\);)139.112
- X548.8 Q F2 .289(The e)108 565.6 R .289(xternal array)-.15 F F4(last_vname)2.789
- XE F2(al)4.455 E -.1(wa)-.1 G .289(ys points to the result of the last).1 F F0
- X(vname)2.789 E F2 .289(\(\) call and thus contains the)B(last pathname that w)
- X108 577.6 Q(as e)-.1 E(xpanded.)-.15 E F1(RETURN V)72 594.4 Q(ALUE)-1.215 E F0
- X(vname)108 606.4 Q F2(\(\) returns a pointer to a v)A(alue that is o)-.25 E
- X-.15(ve)-.15 G(rwritten at each call.).15 E F1(FILES)72 623.2 Q F3(/etc/passwd)
- X108 635.2 Q F2(for matching ~)180 635.2 Q F3(name)2.5 E(.)-.15 E F1(SEE ALSO)72
- X652 Q F3(sh)108 664 Q F2(\(1\),).28 E F3(open)2.5 E F2(\(2\),).24 E F3(fopen)
- X2.5 E F2(\(3\)).24 E F1 -.45(AU)72 680.8 S(THOR).45 E F2(Jan-Piet Mens)108
- X692.8 Q(<jpmens@ingres.com>)5 E 158.115(vname-1.1 Local)72 768 R -.15(Fa)2.5 G
- X195.605(cilities 1).15 F EP
- X%%Trailer
- Xend
- X%%EOF
- END_OF_FILE
- if test 9748 -ne `wc -c <'vname.3.ps'`; then
- echo shar: \"'vname.3.ps'\" unpacked with wrong size!
- fi
- # end of 'vname.3.ps'
- fi
- if test -f 'vname.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vname.c'\"
- else
- echo shar: Extracting \"'vname.c'\" \(1436 characters\)
- sed "s/^X//" >'vname.c' <<'END_OF_FILE'
- X#include "config.h"
- X#include "vname.h"
- X#include <pwd.h>
- X#include <string.h>
- X#include <ctype.h>
- X
- X#define isvchar(c) ((c) && ((isalnum((c))) || ((c) == '_')))
- X
- Xstatic char *homedir P_((char *uname));
- X
- Xchar last_vname[MAXPATHLEN];
- X
- X/*
- X * char *vname(path)
- X * char *path;
- X *
- X * Return a pointer to a newly-built path. The following patterns are
- X * parsed in FNAME.
- X *
- X * ~/ My home
- X * ~user/ User's home
- X * .../$VAR/... Shell Environment
- X */
- X
- Xchar *vname(path)
- Xchar *path;
- X{
- X char *lp = last_vname;
- X char buf[BLEN], *bp, *getlogin(), *getenv();
- X
- X if (*path == '~') {
- X if (*++path == '/') /* ~/ */
- X (void) strcpy(buf, getlogin());
- X else {
- X for (bp = buf; *path != '/'; )
- X *bp++ = *path++;
- X *bp = EOS;
- X }
- X (void) strcpy(last_vname, homedir(buf));
- X lp += strlen(last_vname);
- X }
- X
- X for (; path && *path;) {
- X if (*path != '$')
- X *lp++ = *path++;
- X else {
- X /*
- X * Find $SOMETHING
- X */
- X
- X *lp = EOS;
- X for (bp = buf, ++path; isvchar(*path); path++)
- X *bp++ = *path;
- X *bp = EOS;
- X
- X /*
- X * Get from environment. If not found use the literal
- X */
- X
- X bp = (bp = getenv(buf)) ? bp : buf;
- X for (; bp && *bp; )
- X *lp++ = *bp++;
- X }
- X }
- X *lp = EOS;
- X return (last_vname);
- X}
- X
- Xstatic char *homedir(user)
- Xchar *user;
- X{
- X struct passwd *pw, *getpwnam();
- X static char buf[BLEN];
- X
- X if ((pw = getpwnam(user)) != (struct passwd *)0)
- X return (pw->pw_dir);
- X
- X *buf = '~';
- X (void) strcpy(buf + 1, user);
- X return (buf);
- X}
- END_OF_FILE
- if test 1436 -ne `wc -c <'vname.c'`; then
- echo shar: \"'vname.c'\" unpacked with wrong size!
- fi
- # end of 'vname.c'
- fi
- if test -f 'vname.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vname.h'\"
- else
- echo shar: Extracting \"'vname.h'\" \(986 characters\)
- sed "s/^X//" >'vname.h' <<'END_OF_FILE'
- X#ifndef _VOPEN_H_INCLUDED
- X# define _VOPEN_H_INCLUDED
- X
- X#define vaccess(path, mode) access(vname((path)), (mode))
- X#define vopen(path, flags, mode) open(vname((path)), (flags), (mode))
- X#define vclose(fd) close((fd))
- X#define vchdir(path) chdir(vname((path)))
- X#define vchmod(path, mode) chmod(vname((path)), mode)
- X#define vchown(path, own, grp) chown(vname((path)), own, grp)
- X#define vexecv(path, argv) execv(vname((path)), argv)
- X#define vexecve(path,argv,envp) execve(vname((path)), argv, envp)
- X#define vexecvp(file, argv) execvp(vname((file)), argv)
- X#define vlink(path1, path2) link(vname((path1)), vname((path2)))
- X#define vrmdir(path) rmdir(vname((path)))
- X#define vunlink(path) unlink(vname((path)))
- X#define vfopen(path, mode) fopen(vname((path)), (mode))
- X#define vpopen(path, mode) popen(vname((path)), (mode))
- X
- Xextern char last_vname[];
- X
- X#ifndef __STDC__
- X# define P_(s) ()
- X#else
- X# define P_(s) s
- X#endif
- X
- Xchar *vname P_((char *path));
- X
- X# endif /* _VOPEN_H_INCLUDED */
- END_OF_FILE
- if test 986 -ne `wc -c <'vname.h'`; then
- echo shar: \"'vname.h'\" unpacked with wrong size!
- fi
- # end of 'vname.h'
- fi
- echo shar: End of shell archive.
- exit 0
- --
- Jan-Piet Mens jpmens@ingres.com
- ASK Ingres GmbH, Frankfurt, Germany +49 69 66413-285
-
- exit 0 # Just in case...
-