home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / vname / part01 < prev    next >
Encoding:
Text File  |  1993-11-08  |  19.7 KB  |  678 lines

  1. Newsgroups: comp.sources.misc
  2. From: jpmens@ingres.com (Jan-Piet Mens)
  3. Subject: v40i114:  vname - build filename from metacharacters, Part01/01
  4. Message-ID: <1993Nov9.023400.22919@sparky.sterling.com>
  5. X-Md4-Signature: 59e7142c6983c35ff99b5e420af85892
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Ingres GmbH, Frankfurt, Germany
  8. Date: Tue, 9 Nov 1993 02:34:00 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: jpmens@ingres.com (Jan-Piet Mens)
  12. Posting-number: Volume 40, Issue 114
  13. Archive-name: vname/part01
  14. Environment: UNIX
  15.  
  16. vname() will expand the meta characters in the pathname string and return
  17. a pathname that may be fed to open () et al.
  18. The metacharacters that vname() understands are the tilde and dollar sign.
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of shell archive."
  27. # Contents:  Makefile config.h samples tt.c vname.3 vname.3.ps vname.c
  28. #   vname.h
  29. # Wrapped by jpmens@trsun1 on Thu Nov  4 16:06:05 1993
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'Makefile'\"
  33. else
  34. echo shar: Extracting \"'Makefile'\" \(241 characters\)
  35. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  36. XCC=gcc
  37. XCFLAGS=-Wall -g -I.
  38. X
  39. XLIB=libv.a
  40. XOBJ=    $(LIB)(vname.o)
  41. X
  42. Xall:  $(LIB) tt
  43. X
  44. Xtt: tt.o $(LIB)
  45. X    $(CC) $(CFLAGS) -o tt tt.o $(LIB)
  46. X
  47. X$(LIB): $(OBJ)
  48. X    ranlib $(LIB)
  49. X$(OBJ): config.h vname.h
  50. X
  51. Xclean:
  52. X    rm -f *.o core
  53. Xclobber: clean
  54. X    rm -f tt $(LIB)
  55. END_OF_FILE
  56. if test 241 -ne `wc -c <'Makefile'`; then
  57.     echo shar: \"'Makefile'\" unpacked with wrong size!
  58. fi
  59. # end of 'Makefile'
  60. fi
  61. if test -f 'config.h' -a "${1}" != "-c" ; then 
  62.   echo shar: Will not clobber existing file \"'config.h'\"
  63. else
  64. echo shar: Extracting \"'config.h'\" \(133 characters\)
  65. sed "s/^X//" >'config.h' <<'END_OF_FILE'
  66. X#include <sys/param.h>
  67. X
  68. X#ifndef MAXPATHLEN
  69. X# define MAXPATHLEN 1024
  70. X#endif
  71. X#define EOS        '\0'
  72. X#define BLEN        128        /* Sundry buffers */
  73. END_OF_FILE
  74. if test 133 -ne `wc -c <'config.h'`; then
  75.     echo shar: \"'config.h'\" unpacked with wrong size!
  76. fi
  77. # end of 'config.h'
  78. fi
  79. if test -f 'samples' -a "${1}" != "-c" ; then 
  80.   echo shar: Will not clobber existing file \"'samples'\"
  81. else
  82. echo shar: Extracting \"'samples'\" \(90 characters\)
  83. sed "s/^X//" >'samples' <<'END_OF_FILE'
  84. X$II_SYSTEM
  85. X$HOME/my/file
  86. X~/my/file
  87. X~root/etc/passwd
  88. X~dieterl/$HOME/$NOT/$FOUND/~jpmens/kk
  89. END_OF_FILE
  90. if test 90 -ne `wc -c <'samples'`; then
  91.     echo shar: \"'samples'\" unpacked with wrong size!
  92. fi
  93. # end of 'samples'
  94. fi
  95. if test -f 'tt.c' -a "${1}" != "-c" ; then 
  96.   echo shar: Will not clobber existing file \"'tt.c'\"
  97. else
  98. echo shar: Extracting \"'tt.c'\" \(503 characters\)
  99. sed "s/^X//" >'tt.c' <<'END_OF_FILE'
  100. X#include <vname.h>
  101. X#include <stdio.h>
  102. X#include <errno.h>
  103. X#include <fcntl.h>
  104. X
  105. Xint main(argc, argv)
  106. Xint argc;
  107. Xchar **argv;
  108. X{
  109. X    char buf[1000];
  110. X    int fd;
  111. X    extern char *sys_errlist[];
  112. X    extern int errno;
  113. X
  114. X
  115. X    if (argc == 1) {
  116. X        while (gets(buf))
  117. X            (void) printf("%s = [%s]\n", buf, vname(buf));
  118. X        return (0);
  119. X    }
  120. X
  121. X    while (*++argv) {
  122. X        fd = vopen(*argv, O_RDONLY, 0);
  123. X        (void) printf("%s  =>  %s\n", last_vname, 
  124. X            (fd != -1) ? "ok" : sys_errlist[errno]);
  125. X        if (fd != -1)
  126. X            (void) vclose(fd);
  127. X    }
  128. X    return (0);
  129. X}
  130. END_OF_FILE
  131. if test 503 -ne `wc -c <'tt.c'`; then
  132.     echo shar: \"'tt.c'\" unpacked with wrong size!
  133. fi
  134. # end of 'tt.c'
  135. fi
  136. if test -f 'vname.3' -a "${1}" != "-c" ; then 
  137.   echo shar: Will not clobber existing file \"'vname.3'\"
  138. else
  139. echo shar: Extracting \"'vname.3'\" \(2240 characters\)
  140. sed "s/^X//" >'vname.3' <<'END_OF_FILE'
  141. X.de L
  142. X.nr pq \\n(.f
  143. X.if t .ft CR
  144. X.if n .ft 1
  145. X.if !\e\\$1\e\e \&\\s-\\n(Ls\\$1\|\\s+\\n(Ls\f\\n(pq\\$2
  146. X..
  147. X.TH VNAME 3 "Local Facilities" vname-1.1
  148. X.SH NAME
  149. X.B vname
  150. X\-
  151. Xbuild filename from metacharacters
  152. X.SH SYNOPSIS
  153. X.nf
  154. X\fB#include <vname.h>
  155. X
  156. Xextern char last_vname[];
  157. X
  158. Xchar *vname(char *pathname)\fR
  159. X.fi
  160. X.SH DESCRIPTION
  161. X.BR vname ()
  162. Xwill expand the meta characters in the 
  163. X.I pathname
  164. Xstring and return a pathname that may be fed to
  165. X.IR open ()
  166. Xet al.
  167. XThe metacharacters that
  168. X.BR vname ()
  169. Xunderstands are the tilde
  170. X.B ~
  171. Xand dollar sign
  172. X.BR $ .
  173. X.PP
  174. XEach
  175. X.I pathname
  176. Xis checked to see if it begins with a ~.
  177. XIf it does, then the word up to a / is checked to see if it
  178. Xmatches the name of a user. If so, then the ~
  179. Xand the matched portion are replaced with the value of the
  180. Xuser's home directory. A ~ by itself or followed by a / is
  181. Xreplaced by the value of the user's home directory.
  182. XThe character
  183. X.B $
  184. Xis used to introduce parameter expansions which are taken from the user's
  185. Xenvironment.
  186. X.PP
  187. XThis routine is typically used for expanding pathnames prior to an
  188. X.IR open ()
  189. Xor 
  190. X.IR fopen ()
  191. Xcall as in
  192. X.ft CR
  193. X.sp
  194. X.nf
  195. X     int fd;
  196. X     char *name;
  197. X
  198. X     name = vname("~joe/his/file/called/$SOMETHING/or/$other");
  199. X     fd = open(name, O_RDONLY);
  200. X.ft
  201. X.fi
  202. X.PP
  203. XThe file
  204. X.B <vname.h>
  205. Xdefines several macros which expand the
  206. X.I path
  207. Xargument of the macro using
  208. X.BR vname ().
  209. XThe names of theses macros begin with the letter
  210. X.BR v .
  211. X.ps -2
  212. X.TS
  213. Xtab(@), center, box;
  214. Xlb lb | lb lb
  215. Xlb l  | lb l.
  216. Xmacro@function@macro@function
  217. X_
  218. Xvaccess@access@vopen@open
  219. Xvclose@close@vchdir@chdir
  220. Xvchmod@chmod@vchown@chown
  221. Xvexecv@execv@vexecve@execve
  222. Xvexecvp@execvp@vlink@link
  223. Xvrmdir@rmdir@vunlink@unlink
  224. Xvfopen@fopen@vpopen@popen
  225. X.TE
  226. X.ps
  227. X.PP
  228. XThe above macros may be used as in
  229. X.ft CR
  230. X.sp
  231. X.nf
  232. X    int fd;
  233. X
  234. X    fd = vopen("~joe/his/file/called/$SOMETHING/or/$other", O_RDONLY);
  235. X.ft
  236. X.fi
  237. X.PP
  238. XThe external array
  239. X.L last_vname
  240. Xalways points to the result of the last
  241. X.BR vname ()
  242. Xcall and thus contains the last pathname that was expanded.
  243. X.SH RETURN VALUE
  244. X.BR vname ()
  245. Xreturns a pointer to a value that is overwritten at each call.
  246. X.SH FILES
  247. X.IP "\fI/etc/passwd\fR" 1i
  248. Xfor matching ~
  249. X.IR name.
  250. X.SH SEE ALSO
  251. X.IR sh (1),
  252. X.IR open (2),
  253. X.IR fopen (3)
  254. X.SH AUTHOR
  255. XJan-Piet Mens  <jpmens@ingres.com>
  256. END_OF_FILE
  257. if test 2240 -ne `wc -c <'vname.3'`; then
  258.     echo shar: \"'vname.3'\" unpacked with wrong size!
  259. fi
  260. # end of 'vname.3'
  261. fi
  262. if test -f 'vname.3.ps' -a "${1}" != "-c" ; then 
  263.   echo shar: Will not clobber existing file \"'vname.3.ps'\"
  264. else
  265. echo shar: Extracting \"'vname.3.ps'\" \(9748 characters\)
  266. sed "s/^X//" >'vname.3.ps' <<'END_OF_FILE'
  267. X%!PS-Adobe-3.0
  268. X%%Creator: groff version 1.08
  269. X%%DocumentNeededResources: font Times-Bold
  270. X%%+ font Times-Roman
  271. X%%+ font Times-Italic
  272. X%%+ font Courier
  273. X%%DocumentSuppliedResources: procset grops 1.08 0
  274. X%%Pages: 1
  275. X%%PageOrder: Ascend
  276. X%%Orientation: Portrait
  277. X%%EndComments
  278. X%%BeginProlog
  279. X%%BeginResource: procset grops 1.08 0
  280. X/setpacking where{
  281. Xpop
  282. Xcurrentpacking
  283. Xtrue setpacking
  284. X}if
  285. X/grops 120 dict dup begin
  286. X/SC 32 def
  287. X/A/show load def
  288. X/B{0 SC 3 -1 roll widthshow}bind def
  289. X/C{0 exch ashow}bind def
  290. X/D{0 exch 0 SC 5 2 roll awidthshow}bind def
  291. X/E{0 rmoveto show}bind def
  292. X/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
  293. X/G{0 rmoveto 0 exch ashow}bind def
  294. X/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  295. X/I{0 exch rmoveto show}bind def
  296. X/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
  297. X/K{0 exch rmoveto 0 exch ashow}bind def
  298. X/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  299. X/M{rmoveto show}bind def
  300. X/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
  301. X/O{rmoveto 0 exch ashow}bind def
  302. X/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  303. X/Q{moveto show}bind def
  304. X/R{moveto 0 SC 3 -1 roll widthshow}bind def
  305. X/S{moveto 0 exch ashow}bind def
  306. X/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  307. X/SF{
  308. Xfindfont exch
  309. X[exch dup 0 exch 0 exch neg 0 0]makefont
  310. Xdup setfont
  311. X[exch/setfont cvx]cvx bind def
  312. X}bind def
  313. X/MF{
  314. Xfindfont
  315. X[5 2 roll
  316. X0 3 1 roll 
  317. Xneg 0 0]makefont
  318. Xdup setfont
  319. X[exch/setfont cvx]cvx bind def
  320. X}bind def
  321. X/level0 0 def
  322. X/RES 0 def
  323. X/PL 0 def
  324. X/LS 0 def
  325. X/PLG{
  326. Xgsave newpath clippath pathbbox grestore
  327. Xexch pop add exch pop
  328. X}bind def
  329. X/BP{
  330. X/level0 save def
  331. X1 setlinecap
  332. X1 setlinejoin
  333. X72 RES div dup scale
  334. XLS{
  335. X90 rotate
  336. X}{
  337. X0 PL translate
  338. X}ifelse
  339. X1 -1 scale
  340. X}bind def
  341. X/EP{
  342. Xlevel0 restore
  343. Xshowpage
  344. X}bind def
  345. X/DA{
  346. Xnewpath arcn stroke
  347. X}bind def
  348. X/SN{
  349. Xtransform
  350. X.25 sub exch .25 sub exch
  351. Xround .25 add exch round .25 add exch
  352. Xitransform
  353. X}bind def
  354. X/DL{
  355. XSN
  356. Xmoveto
  357. XSN
  358. Xlineto stroke
  359. X}bind def
  360. X/DC{
  361. Xnewpath 0 360 arc closepath
  362. X}bind def
  363. X/TM matrix def
  364. X/DE{
  365. XTM currentmatrix pop
  366. Xtranslate scale newpath 0 0 .5 0 360 arc closepath
  367. XTM setmatrix
  368. X}bind def
  369. X/RC/rcurveto load def
  370. X/RL/rlineto load def
  371. X/ST/stroke load def
  372. X/MT/moveto load def
  373. X/CL/closepath load def
  374. X/FL{
  375. Xcurrentgray exch setgray fill setgray
  376. X}bind def
  377. X/BL/fill load def
  378. X/LW/setlinewidth load def
  379. X/RE{
  380. Xfindfont
  381. Xdup maxlength 1 index/FontName known not{1 add}if dict begin
  382. X{
  383. X1 index/FID ne{def}{pop pop}ifelse
  384. X}forall
  385. X/Encoding exch def
  386. Xdup/FontName exch def
  387. Xcurrentdict end definefont pop
  388. X}bind def
  389. X/DEFS 0 def
  390. X/EBEGIN{
  391. Xmoveto
  392. XDEFS begin
  393. X}bind def
  394. X/EEND/end load def
  395. X/CNT 0 def
  396. X/level1 0 def
  397. X/PBEGIN{
  398. X/level1 save def
  399. Xtranslate
  400. Xdiv 3 1 roll div exch scale
  401. Xneg exch neg exch translate
  402. X0 setgray
  403. X0 setlinecap
  404. X1 setlinewidth
  405. X0 setlinejoin
  406. X10 setmiterlimit
  407. X[]0 setdash
  408. X/setstrokeadjust where{
  409. Xpop
  410. Xfalse setstrokeadjust
  411. X}if
  412. X/setoverprint where{
  413. Xpop
  414. Xfalse setoverprint
  415. X}if
  416. Xnewpath
  417. X/CNT countdictstack def
  418. Xuserdict begin
  419. X/showpage{}def
  420. X}bind def
  421. X/PEND{
  422. Xclear
  423. Xcountdictstack CNT sub{end}repeat
  424. Xlevel1 restore
  425. X}bind def
  426. Xend def
  427. X/setpacking where{
  428. Xpop
  429. Xsetpacking
  430. X}if
  431. X%%EndResource
  432. X%%IncludeResource: font Times-Bold
  433. X%%IncludeResource: font Times-Roman
  434. X%%IncludeResource: font Times-Italic
  435. X%%IncludeResource: font Courier
  436. Xgrops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL
  437. X841.89 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron/scaron
  438. X/zcaron/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef/.notdef/.notdef
  439. X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  440. X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space
  441. X/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft
  442. X/parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four
  443. X/five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/at/A/B/C
  444. 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
  445. X/bracketright/circumflex/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q
  446. X/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase
  447. X/guillemotleft/guillemotright/bullet/florin/fraction/perthousand/dagger
  448. X/daggerdbl/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
  449. X/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
  450. X/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar
  451. X/section/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus
  452. X/registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu
  453. X/paragraph/periodcentered/cedilla/onesuperior/ordmasculine/guilsinglright
  454. X/onequarter/onehalf/threequarters/questiondown/Agrave/Aacute/Acircumflex/Atilde
  455. X/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute
  456. X/Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
  457. X/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
  458. X/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute
  459. X/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve
  460. X/oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex
  461. X/udieresis/yacute/thorn/ydieresis]def/Courier@0 ENC0/Courier RE/Times-Italic@0
  462. XENC0/Times-Italic RE/Times-Roman@0 ENC0/Times-Roman RE/Times-Bold@0 ENC0
  463. X/Times-Bold RE
  464. X%%EndProlog
  465. X%%Page: 1 1
  466. X%%BeginPageSetup
  467. XBP
  468. X%%EndPageSetup
  469. X/F0 10/Times-Bold@0 SF(VN)72 60 Q 367.04(AME\(3\) VN)-.2 F(AME\(3\))-.2 E/F1 9
  470. X/Times-Bold@0 SF -.18(NA)72 84 S(ME).18 E F0(vname)108 96 Q/F2 10/Times-Roman@0
  471. XSF 2.5<ad62>2.5 G(uild \214lename from metacharacters)151.77 96 Q F1(SYNOPSIS)
  472. X72 112.8 Q F0(#include <vname.h>)108 124.8 Q(exter)108 148.8 Q 2.5(nc)-.15 G
  473. X(har last_vname[];)142 148.8 Q(char *vname\(char *pathname\))108 172.8 Q F1
  474. X(DESCRIPTION)72 189.6 Q F0(vname)108 201.6 Q F2 .526(\(\) will e)B .526
  475. X(xpand the meta characters in the)-.15 F/F3 10/Times-Italic@0 SF(pathname)3.026
  476. XE F2 .525(string and return a pathname that may be fed to)3.026 F F3(open)108
  477. X213.6 Q F2(\(\) et al.).24 E(The metacharacters that)5 E F0(vname)2.5 E F2
  478. X(\(\) understands are the tilde)A F0(~)2.5 E F2(and dollar sign)2.5 E F0($)2.5
  479. XE F2(.)A(Each)108 230.4 Q F3(pathname)2.714 E F2 .214(is check)2.714 F .214
  480. X(ed to see if it be)-.1 F .214(gins with a ~.)-.15 F .215
  481. X(If it does, then the w)5.215 F .215(ord up to a / is check)-.1 F .215
  482. X(ed to see if)-.1 F .688(it matches the name of a user)108 242.4 R 3.187(.I)
  483. X-.55 G 3.187(fs)237.235 242.4 S .687
  484. X(o, then the ~ and the matched portion are replaced with the v)247.642 242.4 R
  485. X.687(alue of the)-.25 F(user')108 254.4 Q 2.803(sh)-.55 G .303(ome directory)
  486. X139.133 254.4 R -5.302 2.803(.A~ b)-.65 H 2.804(yi)221.066 254.4 S .304
  487. X(tself or follo)231.65 254.4 R .304(wed by a / is replaced by the v)-.25 F .304
  488. X(alue of the user')-.25 F 2.804(sh)-.55 G .304(ome directory)482.026 254.4 R(.)
  489. X-.65 E(The character)108 266.4 Q F0($)2.5 E F2
  490. X(is used to introduce parameter e)2.5 E(xpansions which are tak)-.15 E
  491. X(en from the user')-.1 E 2.5(se)-.55 G -.4(nv)475.15 266.4 S(ironment.).4 E
  492. X(This routine is typically used for e)108 283.2 Q
  493. X(xpanding pathnames prior to an)-.15 E F3(open)2.5 E F2(\(\) or).24 E F3(fopen)
  494. X2.5 E F2(\(\) call as in).24 E/F4 10/Courier@0 SF(int fd;)144 307.2 Q
  495. X(char *name;)144 319.2 Q
  496. X(name = vname\("~joe/his/file/called/$SOMETHING/or/$other"\);)144 343.2 Q
  497. X(fd = open\(name, O_RDONLY\);)144 355.2 Q F2 .52(The \214le)108 372 R F0
  498. X(<vname.h>)3.02 E F2 .52(de\214nes se)3.02 F -.15(ve)-.25 G .519
  499. X(ral macros which e).15 F .519(xpand the)-.15 F F3(path)3.019 E F2(ar)3.019 E
  500. X.519(gument of the macro using)-.18 F F0(vname)3.019 E F2(\(\).)A
  501. X(The names of theses macros be)108 384 Q(gin with the letter)-.15 E F0(v)2.5 E
  502. XF2(.)A .32 LW 401.124 388 246.876 388 DL/F5 8/Times-Bold@0 SF(macr)250.876 398
  503. XQ 17.488(of)-.144 G 10(unction macr)292.652 398 R 16.616(of)-.144 G(unction)
  504. X371.34 398 Q 401.124 402 246.876 402 DL -.08(va)250.876 412 S(ccess).08 E/F6 8
  505. X/Times-Roman@0 SF(access)289.988 412 Q F5 -.08(vo)330.436 412 S(pen).08 E F6
  506. X(open)368.676 412 Q F5(vclose)250.876 424 Q F6(close)289.988 424 Q F5(vchdir)
  507. X330.436 424 Q F6(chdir)368.676 424 Q F5(vchmod)250.876 436 Q F6(chmod)289.988
  508. X436 Q F5(vcho)330.436 436 Q(wn)-.08 E F6(cho)368.676 436 Q(wn)-.2 E F5 -.08(ve)
  509. X250.876 448 S(xecv).08 E F6 -.12(exe)289.988 448 S(cv).12 E F5 -.08(ve)330.436
  510. X448 S(xecv).08 E(e)-.08 E F6 -.12(exe)368.676 448 S(cv).12 E(e)-.12 E F5 -.08
  511. X(ve)250.876 460 S(xecvp).08 E F6 -.12(exe)289.988 460 S(cvp).12 E F5(vlink)
  512. X330.436 460 Q F6(link)368.676 460 Q F5(vrmdir)250.876 472 Q F6(rmdir)289.988
  513. X472 Q F5(vunlink)330.436 472 Q F6(unlink)368.676 472 Q F5(vf)250.876 484 Q
  514. X(open)-.2 E F6(fopen)289.988 484 Q F5(vpopen)330.436 484 Q F6(popen)368.676 484
  515. XQ 401.124 488 246.876 488 DL 324.436 388 324.436 488 DL 401.124 388 401.124 488
  516. XDL 246.876 388 246.876 488 DL F2(The abo)108 500.8 Q .3 -.15(ve m)-.15 H
  517. X(acros may be used as in).15 E F4(int fd;)139.112 524.8 Q
  518. X(fd = vopen\("~joe/his/file/called/$SOMETHING/or/$other", O_RDONLY\);)139.112
  519. X548.8 Q F2 .289(The e)108 565.6 R .289(xternal array)-.15 F F4(last_vname)2.789
  520. XE F2(al)4.455 E -.1(wa)-.1 G .289(ys points to the result of the last).1 F F0
  521. X(vname)2.789 E F2 .289(\(\) call and thus contains the)B(last pathname that w)
  522. X108 577.6 Q(as e)-.1 E(xpanded.)-.15 E F1(RETURN V)72 594.4 Q(ALUE)-1.215 E F0
  523. X(vname)108 606.4 Q F2(\(\) returns a pointer to a v)A(alue that is o)-.25 E
  524. X-.15(ve)-.15 G(rwritten at each call.).15 E F1(FILES)72 623.2 Q F3(/etc/passwd)
  525. X108 635.2 Q F2(for matching ~)180 635.2 Q F3(name)2.5 E(.)-.15 E F1(SEE ALSO)72
  526. X652 Q F3(sh)108 664 Q F2(\(1\),).28 E F3(open)2.5 E F2(\(2\),).24 E F3(fopen)
  527. X2.5 E F2(\(3\)).24 E F1 -.45(AU)72 680.8 S(THOR).45 E F2(Jan-Piet Mens)108
  528. X692.8 Q(<jpmens@ingres.com>)5 E 158.115(vname-1.1 Local)72 768 R -.15(Fa)2.5 G
  529. X195.605(cilities 1).15 F EP
  530. X%%Trailer
  531. Xend
  532. X%%EOF
  533. END_OF_FILE
  534. if test 9748 -ne `wc -c <'vname.3.ps'`; then
  535.     echo shar: \"'vname.3.ps'\" unpacked with wrong size!
  536. fi
  537. # end of 'vname.3.ps'
  538. fi
  539. if test -f 'vname.c' -a "${1}" != "-c" ; then 
  540.   echo shar: Will not clobber existing file \"'vname.c'\"
  541. else
  542. echo shar: Extracting \"'vname.c'\" \(1436 characters\)
  543. sed "s/^X//" >'vname.c' <<'END_OF_FILE'
  544. X#include "config.h"
  545. X#include "vname.h"
  546. X#include <pwd.h>
  547. X#include <string.h>
  548. X#include <ctype.h>
  549. X
  550. X#define isvchar(c)    ((c) && ((isalnum((c))) || ((c) == '_')))
  551. X
  552. Xstatic char *homedir P_((char *uname));
  553. X
  554. Xchar last_vname[MAXPATHLEN];
  555. X
  556. X/*
  557. X * char *vname(path)
  558. X * char *path;
  559. X *
  560. X * Return a pointer to a newly-built path. The following patterns are
  561. X * parsed in FNAME.
  562. X *
  563. X *    ~/                My home
  564. X *    ~user/                User's home
  565. X *    .../$VAR/...            Shell Environment
  566. X */
  567. X
  568. Xchar *vname(path)
  569. Xchar *path;
  570. X{
  571. X    char *lp = last_vname;
  572. X    char buf[BLEN], *bp, *getlogin(), *getenv();
  573. X
  574. X    if (*path == '~') {
  575. X        if (*++path == '/')             /* ~/ */
  576. X            (void) strcpy(buf, getlogin());
  577. X        else {
  578. X            for (bp = buf; *path != '/'; )
  579. X                *bp++ = *path++;
  580. X            *bp = EOS;
  581. X        }
  582. X        (void) strcpy(last_vname, homedir(buf));
  583. X        lp += strlen(last_vname);
  584. X    }
  585. X
  586. X    for (; path && *path;) {
  587. X        if (*path != '$')
  588. X            *lp++ = *path++;
  589. X        else {
  590. X            /*
  591. X             * Find $SOMETHING
  592. X             */
  593. X
  594. X            *lp = EOS;
  595. X            for (bp = buf, ++path; isvchar(*path); path++)
  596. X                *bp++ = *path;
  597. X            *bp = EOS;
  598. X
  599. X            /*
  600. X             * Get from environment. If not found use the literal
  601. X             */
  602. X
  603. X            bp = (bp = getenv(buf)) ? bp : buf;
  604. X            for (; bp && *bp; )
  605. X                *lp++ = *bp++;
  606. X        }
  607. X    }
  608. X    *lp = EOS;
  609. X    return (last_vname);
  610. X}
  611. X
  612. Xstatic char *homedir(user)
  613. Xchar *user;
  614. X{
  615. X    struct passwd *pw, *getpwnam();
  616. X    static char buf[BLEN];
  617. X
  618. X    if ((pw = getpwnam(user)) != (struct passwd *)0)
  619. X        return (pw->pw_dir);
  620. X
  621. X    *buf = '~';
  622. X    (void) strcpy(buf + 1, user);
  623. X    return (buf);
  624. X}
  625. END_OF_FILE
  626. if test 1436 -ne `wc -c <'vname.c'`; then
  627.     echo shar: \"'vname.c'\" unpacked with wrong size!
  628. fi
  629. # end of 'vname.c'
  630. fi
  631. if test -f 'vname.h' -a "${1}" != "-c" ; then 
  632.   echo shar: Will not clobber existing file \"'vname.h'\"
  633. else
  634. echo shar: Extracting \"'vname.h'\" \(986 characters\)
  635. sed "s/^X//" >'vname.h' <<'END_OF_FILE'
  636. X#ifndef _VOPEN_H_INCLUDED
  637. X# define _VOPEN_H_INCLUDED
  638. X
  639. X#define vaccess(path, mode)        access(vname((path)), (mode))
  640. X#define vopen(path, flags, mode)    open(vname((path)), (flags), (mode))
  641. X#define vclose(fd)            close((fd))
  642. X#define vchdir(path)            chdir(vname((path)))
  643. X#define vchmod(path, mode)        chmod(vname((path)), mode)
  644. X#define vchown(path, own, grp)        chown(vname((path)), own, grp)
  645. X#define vexecv(path, argv)        execv(vname((path)), argv)
  646. X#define vexecve(path,argv,envp)        execve(vname((path)), argv, envp)
  647. X#define vexecvp(file, argv)        execvp(vname((file)), argv)
  648. X#define vlink(path1, path2)        link(vname((path1)), vname((path2)))
  649. X#define vrmdir(path)            rmdir(vname((path)))
  650. X#define vunlink(path)            unlink(vname((path)))
  651. X#define vfopen(path, mode)        fopen(vname((path)), (mode))
  652. X#define vpopen(path, mode)        popen(vname((path)), (mode))
  653. X
  654. Xextern char last_vname[];
  655. X
  656. X#ifndef __STDC__
  657. X# define P_(s)  ()
  658. X#else
  659. X# define P_(s)  s
  660. X#endif
  661. X
  662. Xchar *vname P_((char *path));
  663. X
  664. X# endif /* _VOPEN_H_INCLUDED */
  665. END_OF_FILE
  666. if test 986 -ne `wc -c <'vname.h'`; then
  667.     echo shar: \"'vname.h'\" unpacked with wrong size!
  668. fi
  669. # end of 'vname.h'
  670. fi
  671. echo shar: End of shell archive.
  672. exit 0
  673. -- 
  674. Jan-Piet Mens                                               jpmens@ingres.com
  675. ASK Ingres GmbH, Frankfurt, Germany                          +49 69 66413-285
  676.  
  677. exit 0 # Just in case...
  678.