0000: 2f 2a 0a 20 2a 20 74 63 6c 50 61 74 68 4f 62 6a /*. * tclPathObj
0010: 2e 63 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 .c --. *. *.This
0020: 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 73 20 74 file contains t
0030: 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f he implementatio
0040: 6e 20 6f 66 20 54 63 6c 27 73 20 22 70 61 74 68 n of Tcl's "path
0050: 22 20 6f 62 6a 65 63 74 20 74 79 70 65 20 75 73 " object type us
0060: 65 64 0a 20 2a 09 74 6f 20 72 65 70 72 65 73 65 ed. *.to represe
0070: 6e 74 20 61 6e 64 20 6d 61 6e 69 70 75 6c 61 74 nt and manipulat
0080: 65 20 61 20 67 65 6e 65 72 61 6c 20 28 76 69 72 e a general (vir
0090: 74 75 61 6c 29 20 66 69 6c 65 73 79 73 74 65 6d tual) filesystem
00a0: 20 65 6e 74 69 74 79 20 69 6e 0a 20 2a 09 61 6e entity in. *.an
00b0: 20 65 66 66 69 63 69 65 6e 74 20 6d 61 6e 6e 65 efficient manne
00c0: 72 2e 0a 20 2a 0a 20 2a 20 43 6f 70 79 72 69 67 r.. *. * Copyrig
00d0: 68 74 20 28 63 29 20 32 30 30 33 20 56 69 6e 63 ht (c) 2003 Vinc
00e0: 65 20 44 61 72 6c 65 79 2e 0a 20 2a 0a 20 2a 20 e Darley.. *. *
00f0: 53 65 65 20 74 68 65 20 66 69 6c 65 20 22 6c 69 See the file "li
0100: 63 65 6e 73 65 2e 74 65 72 6d 73 22 20 66 6f 72 cense.terms" for
0110: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 information on
0120: 75 73 61 67 65 20 61 6e 64 20 72 65 64 69 73 74 usage and redist
0130: 72 69 62 75 74 69 6f 6e 20 6f 66 0a 20 2a 20 74 ribution of. * t
0140: 68 69 73 20 66 69 6c 65 2c 20 61 6e 64 20 66 6f his file, and fo
0150: 72 20 61 20 44 49 53 43 4c 41 49 4d 45 52 20 4f r a DISCLAIMER O
0160: 46 20 41 4c 4c 20 57 41 52 52 41 4e 54 49 45 53 F ALL WARRANTIES
0170: 2e 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 .. */..#include
0180: 22 74 63 6c 49 6e 74 2e 68 22 0a 23 69 6e 63 6c "tclInt.h".#incl
0190: 75 64 65 20 22 74 63 6c 46 69 6c 65 53 79 73 74 ude "tclFileSyst
01a0: 65 6d 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 3c em.h".#include <
01b0: 61 73 73 65 72 74 2e 68 3e 0a 0a 2f 2a 0a 20 2a assert.h>../*. *
01c0: 20 50 72 6f 74 6f 74 79 70 65 73 20 66 6f 72 20 Prototypes for
01d0: 66 75 6e 63 74 69 6f 6e 73 20 64 65 66 69 6e 65 functions define
01e0: 64 20 6c 61 74 65 72 20 69 6e 20 74 68 69 73 20 d later in this
01f0: 66 69 6c 65 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 file.. */..stati
0200: 63 20 54 63 6c 5f 4f 62 6a 20 2a 09 41 70 70 65 c Tcl_Obj *.Appe
0210: 6e 64 50 61 74 68 28 54 63 6c 5f 4f 62 6a 20 2a ndPath(Tcl_Obj *
0220: 68 65 61 64 2c 20 54 63 6c 5f 4f 62 6a 20 2a 74 head, Tcl_Obj *t
0230: 61 69 6c 29 3b 0a 73 74 61 74 69 63 20 76 6f 69 ail);.static voi
0240: 64 09 09 44 75 70 46 73 50 61 74 68 49 6e 74 65 d..DupFsPathInte
0250: 72 6e 61 6c 52 65 70 28 54 63 6c 5f 4f 62 6a 20 rnalRep(Tcl_Obj
0260: 2a 73 72 63 50 74 72 2c 0a 09 09 09 20 20 20 20 *srcPtr,....
0270: 54 63 6c 5f 4f 62 6a 20 2a 63 6f 70 79 50 74 72 Tcl_Obj *copyPtr
0280: 29 3b 0a 73 74 61 74 69 63 20 76 6f 69 64 09 09 );.static void..
0290: 46 72 65 65 46 73 50 61 74 68 49 6e 74 65 72 6e FreeFsPathIntern
02a0: 61 6c 52 65 70 28 54 63 6c 5f 4f 62 6a 20 2a 70 alRep(Tcl_Obj *p
02b0: 61 74 68 50 74 72 29 3b 0a 73 74 61 74 69 63 20 athPtr);.static
02c0: 76 6f 69 64 09 09 55 70 64 61 74 65 53 74 72 69 void..UpdateStri
02d0: 6e 67 4f 66 46 73 50 61 74 68 28 54 63 6c 5f 4f ngOfFsPath(Tcl_O
02e0: 62 6a 20 2a 70 61 74 68 50 74 72 29 3b 0a 73 74 bj *pathPtr);.st
02f0: 61 74 69 63 20 69 6e 74 09 09 53 65 74 46 73 50 atic int..SetFsP
0300: 61 74 68 46 72 6f 6d 41 6e 79 28 54 63 6c 5f 49 athFromAny(Tcl_I
0310: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 54 nterp *interp, T
0320: 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 72 29 cl_Obj *pathPtr)
0330: 3b 0a 73 74 61 74 69 63 20 69 6e 74 09 09 46 69 ;.static int..Fi
0340: 6e 64 53 70 6c 69 74 50 6f 73 28 63 6f 6e 73 74 ndSplitPos(const
0350: 20 63 68 61 72 20 2a 70 61 74 68 2c 20 69 6e 74 char *path, int
0360: 20 73 65 70 61 72 61 74 6f 72 29 3b 0a 73 74 61 separator);.sta
0370: 74 69 63 20 69 6e 74 09 09 49 73 53 65 70 61 72 tic int..IsSepar
0380: 61 74 6f 72 4f 72 4e 75 6c 6c 28 69 6e 74 20 63 atorOrNull(int c
0390: 68 29 3b 0a 73 74 61 74 69 63 20 54 63 6c 5f 4f h);.static Tcl_O
03a0: 62 6a 20 2a 09 47 65 74 45 78 74 65 6e 73 69 6f bj *.GetExtensio
03b0: 6e 28 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 n(Tcl_Obj *pathP
03c0: 74 72 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 09 tr);.static int.
03d0: 09 4d 61 6b 65 50 61 74 68 46 72 6f 6d 4e 6f 72 .MakePathFromNor
03e0: 6d 61 6c 69 7a 65 64 28 54 63 6c 5f 49 6e 74 65 malized(Tcl_Inte
03f0: 72 70 20 2a 69 6e 74 65 72 70 2c 0a 09 09 09 20 rp *interp,....
0400: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 Tcl_Obj *path
0410: 50 74 72 29 3b 0a 0a 2f 2a 0a 20 2a 20 44 65 66 Ptr);../*. * Def
0420: 69 6e 65 20 74 68 65 20 27 70 61 74 68 27 20 6f ine the 'path' o
0430: 62 6a 65 63 74 20 74 79 70 65 2c 20 77 68 69 63 bject type, whic
0440: 68 20 54 63 6c 20 75 73 65 73 20 74 6f 20 72 65 h Tcl uses to re
0450: 70 72 65 73 65 6e 74 20 66 69 6c 65 20 70 61 74 present file pat
0460: 68 73 0a 20 2a 20 69 6e 74 65 72 6e 61 6c 6c 79 hs. * internally
0470: 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 63 6f .. */..static co
0480: 6e 73 74 20 54 63 6c 5f 4f 62 6a 54 79 70 65 20 nst Tcl_ObjType
0490: 74 63 6c 46 73 50 61 74 68 54 79 70 65 20 3d 20 tclFsPathType =
04a0: 7b 0a 20 20 20 20 22 70 61 74 68 22 2c 09 09 09 {. "path",...
04b0: 09 2f 2a 20 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 ./* name */.
04c0: 46 72 65 65 46 73 50 61 74 68 49 6e 74 65 72 6e FreeFsPathIntern
04d0: 61 6c 52 65 70 2c 09 09 2f 2a 20 66 72 65 65 49 alRep,../* freeI
04e0: 6e 74 52 65 70 50 72 6f 63 20 2a 2f 0a 20 20 20 ntRepProc */.
04f0: 20 44 75 70 46 73 50 61 74 68 49 6e 74 65 72 6e DupFsPathIntern
0500: 61 6c 52 65 70 2c 09 09 2f 2a 20 64 75 70 49 6e alRep,../* dupIn
0510: 74 52 65 70 50 72 6f 63 20 2a 2f 0a 20 20 20 20 tRepProc */.
0520: 55 70 64 61 74 65 53 74 72 69 6e 67 4f 66 46 73 UpdateStringOfFs
0530: 50 61 74 68 2c 09 09 2f 2a 20 75 70 64 61 74 65 Path,../* update
0540: 53 74 72 69 6e 67 50 72 6f 63 20 2a 2f 0a 20 20 StringProc */.
0550: 20 20 53 65 74 46 73 50 61 74 68 46 72 6f 6d 41 SetFsPathFromA
0560: 6e 79 09 09 09 2f 2a 20 73 65 74 46 72 6f 6d 41 ny.../* setFromA
0570: 6e 79 50 72 6f 63 20 2a 2f 0a 7d 3b 0a 0a 2f 2a nyProc */.};../*
0580: 0a 20 2a 20 73 74 72 75 63 74 20 46 73 50 61 74 . * struct FsPat
0590: 68 20 2d 2d 0a 20 2a 0a 20 2a 20 49 6e 74 65 72 h --. *. * Inter
05a0: 6e 61 6c 20 72 65 70 72 65 73 65 6e 74 61 74 69 nal representati
05b0: 6f 6e 20 6f 66 20 61 20 54 63 6c 5f 4f 62 6a 20 on of a Tcl_Obj
05c0: 6f 66 20 22 70 61 74 68 22 20 74 79 70 65 2e 20 of "path" type.
05d0: 54 68 69 73 20 63 61 6e 20 62 65 20 75 73 65 64 This can be used
05e0: 20 74 6f 0a 20 2a 20 72 65 70 72 65 73 65 6e 74 to. * represent
05f0: 20 72 65 6c 61 74 69 76 65 20 6f 72 20 61 62 73 relative or abs
0600: 6f 6c 75 74 65 20 70 61 74 68 73 2c 20 61 6e 64 olute paths, and
0610: 20 68 61 73 20 63 65 72 74 61 69 6e 20 6f 70 74 has certain opt
0620: 69 6d 69 73 61 74 69 6f 6e 73 20 77 68 65 6e 0a imisations when.
0630: 20 2a 20 75 73 65 64 20 74 6f 20 72 65 70 72 65 * used to repre
0640: 73 65 6e 74 20 70 61 74 68 73 20 77 68 69 63 68 sent paths which
0650: 20 61 72 65 20 61 6c 72 65 61 64 79 20 6e 6f 72 are already nor
0660: 6d 61 6c 69 7a 65 64 20 61 6e 64 20 61 62 73 6f malized and abso
0670: 6c 75 74 65 2e 0a 20 2a 0a 20 2a 20 4e 6f 74 65 lute.. *. * Note
0680: 20 74 68 61 74 20 62 6f 74 68 20 27 74 72 61 6e that both 'tran
0690: 73 6c 61 74 65 64 50 61 74 68 50 74 72 27 20 61 slatedPathPtr' a
06a0: 6e 64 20 27 6e 6f 72 6d 50 61 74 68 50 74 72 27 nd 'normPathPtr'
06b0: 20 63 61 6e 20 62 65 20 61 20 63 69 72 63 75 6c can be a circul
06c0: 61 72 0a 20 2a 20 72 65 66 65 72 65 6e 63 65 20 ar. * reference
06d0: 74 6f 20 74 68 65 20 63 6f 6e 74 61 69 6e 65 72 to the container
06e0: 20 54 63 6c 5f 4f 62 6a 20 6f 66 20 74 68 69 73 Tcl_Obj of this
06f0: 20 46 73 50 61 74 68 2e 0a 20 2a 0a 20 2a 20 54 FsPath.. *. * T
0700: 68 65 72 65 20 61 72 65 20 74 77 6f 20 63 61 73 here are two cas
0710: 65 73 2c 20 77 69 74 68 20 74 68 65 20 66 69 72 es, with the fir
0720: 73 74 20 62 65 69 6e 67 20 74 68 65 20 6d 6f 73 st being the mos
0730: 74 20 63 6f 6d 6d 6f 6e 3a 0a 20 2a 0a 20 2a 20 t common:. *. *
0740: 28 69 29 20 66 6c 61 67 73 20 3d 3d 20 30 2c 20 (i) flags == 0,
0750: 3d 3e 20 4f 72 64 69 6e 61 72 79 20 70 61 74 68 => Ordinary path
0760: 2e 0a 20 2a 0a 20 2a 20 74 72 61 6e 73 6c 61 74 .. *. * translat
0770: 65 64 50 61 74 68 50 74 72 20 63 6f 6e 74 61 69 edPathPtr contai
0780: 6e 73 20 74 68 65 20 74 72 61 6e 73 6c 61 74 65 ns the translate
0790: 64 20 70 61 74 68 20 28 77 68 69 63 68 20 6d 61 d path (which ma
07a0: 79 20 62 65 20 61 20 63 69 72 63 75 6c 61 72 0a y be a circular.
07b0: 20 2a 20 72 65 66 65 72 65 6e 63 65 20 74 6f 20 * reference to
07c0: 74 68 65 20 6f 62 6a 65 63 74 20 69 74 73 65 6c the object itsel
07d0: 66 29 2e 20 49 66 20 69 74 20 69 73 20 4e 55 4c f). If it is NUL
07e0: 4c 20 74 68 65 6e 20 74 68 65 20 70 61 74 68 20 L then the path
07f0: 69 73 20 70 75 72 65 0a 20 2a 20 6e 6f 72 6d 61 is pure. * norma
0800: 6c 69 7a 65 64 20 28 61 6e 64 20 74 68 65 20 6e lized (and the n
0810: 6f 72 6d 50 61 74 68 50 74 72 20 77 69 6c 6c 20 ormPathPtr will
0820: 62 65 20 61 20 63 69 72 63 75 6c 61 72 20 72 65 be a circular re
0830: 66 65 72 65 6e 63 65 29 2e 20 63 77 64 50 74 72 ference). cwdPtr
0840: 20 69 73 0a 20 2a 20 6e 75 6c 6c 20 66 6f 72 20 is. * null for
0850: 61 6e 20 61 62 73 6f 6c 75 74 65 20 70 61 74 68 an absolute path
0860: 2c 20 61 6e 64 20 6e 6f 6e 2d 6e 75 6c 6c 20 66 , and non-null f
0870: 6f 72 20 61 20 72 65 6c 61 74 69 76 65 20 70 61 or a relative pa
0880: 74 68 20 28 75 6e 6c 65 73 73 20 74 68 65 20 63 th (unless the c
0890: 77 64 0a 20 2a 20 68 61 73 20 6e 65 76 65 72 20 wd. * has never
08a0: 62 65 65 6e 20 73 65 74 2c 20 69 6e 20 77 68 69 been set, in whi
08b0: 63 68 20 63 61 73 65 20 74 68 65 20 63 77 64 50 ch case the cwdP
08c0: 74 72 20 6d 61 79 20 61 6c 73 6f 20 62 65 20 6e tr may also be n
08d0: 75 6c 6c 20 66 6f 72 20 61 0a 20 2a 20 72 65 6c ull for a. * rel
08e0: 61 74 69 76 65 20 70 61 74 68 29 2e 0a 20 2a 0a ative path).. *.
08f0: 20 2a 20 28 69 69 29 20 66 6c 61 67 73 20 21 3d * (ii) flags !=
0900: 20 30 2c 20 3d 3e 20 53 70 65 63 69 61 6c 20 70 0, => Special p
0910: 61 74 68 2c 20 73 65 65 20 54 63 6c 4e 65 77 46 ath, see TclNewF
0920: 53 50 61 74 68 4f 62 6a 0a 20 2a 0a 20 2a 20 4e SPathObj. *. * N
0930: 6f 77 2c 20 74 68 69 73 20 69 73 20 61 20 70 61 ow, this is a pa
0940: 74 68 20 6c 69 6b 65 20 27 66 69 6c 65 20 6a 6f th like 'file jo
0950: 69 6e 20 24 64 69 72 20 24 74 61 69 6c 27 20 77 in $dir $tail' w
0960: 68 65 72 65 2c 20 63 77 64 50 74 72 20 69 73 20 here, cwdPtr is
0970: 74 68 65 20 24 64 69 72 0a 20 2a 20 61 6e 64 20 the $dir. * and
0980: 6e 6f 72 6d 50 61 74 68 50 74 72 20 69 73 20 74 normPathPtr is t
0990: 68 65 20 24 74 61 69 6c 2e 0a 20 2a 0a 20 2a 2f he $tail.. *. */
09a0: 0a 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ..typedef struct
09b0: 20 46 73 50 61 74 68 20 7b 0a 20 20 20 20 54 63 FsPath {. Tc
09c0: 6c 5f 4f 62 6a 20 2a 74 72 61 6e 73 6c 61 74 65 l_Obj *translate
09d0: 64 50 61 74 68 50 74 72 3b 20 2f 2a 20 4e 61 6d dPathPtr; /* Nam
09e0: 65 20 77 69 74 68 6f 75 74 20 61 6e 79 20 7e 75 e without any ~u
09f0: 73 65 72 20 73 65 71 75 65 6e 63 65 73 2e 20 49 ser sequences. I
0a00: 66 20 74 68 69 73 0a 09 09 09 09 20 2a 20 69 73 f this..... * is
0a10: 20 4e 55 4c 4c 2c 20 74 68 65 6e 20 74 68 69 73 NULL, then this
0a20: 20 69 73 20 61 20 70 75 72 65 20 6e 6f 72 6d 61 is a pure norma
0a30: 6c 69 7a 65 64 2c 0a 09 09 09 09 20 2a 20 61 62 lized,..... * ab
0a40: 73 6f 6c 75 74 65 20 70 61 74 68 20 6f 62 6a 65 solute path obje
0a50: 63 74 2c 20 69 6e 20 77 68 69 63 68 20 74 68 65 ct, in which the
0a60: 20 70 61 72 65 6e 74 0a 09 09 09 09 20 2a 20 54 parent..... * T
0a70: 63 6c 5f 4f 62 6a 27 73 20 73 74 72 69 6e 67 20 cl_Obj's string
0a80: 72 65 70 20 69 73 20 61 6c 72 65 61 64 79 20 62 rep is already b
0a90: 6f 74 68 0a 09 09 09 09 20 2a 20 74 72 61 6e 73 oth..... * trans
0aa0: 6c 61 74 65 64 20 61 6e 64 20 6e 6f 72 6d 61 6c lated and normal
0ab0: 69 7a 65 64 2e 20 2a 2f 0a 20 20 20 20 54 63 6c ized. */. Tcl
0ac0: 5f 4f 62 6a 20 2a 6e 6f 72 6d 50 61 74 68 50 74 _Obj *normPathPt
0ad0: 72 3b 09 2f 2a 20 4e 6f 72 6d 61 6c 69 7a 65 64 r;./* Normalized
0ae0: 20 61 62 73 6f 6c 75 74 65 20 70 61 74 68 2c 20 absolute path,
0af0: 77 69 74 68 6f 75 74 20 2e 2c 20 2e 2e 20 6f 72 without ., .. or
0b00: 0a 09 09 09 09 20 2a 20 7e 75 73 65 72 20 73 65 ..... * ~user se
0b10: 71 75 65 6e 63 65 73 2e 20 49 66 20 74 68 65 20 quences. If the
0b20: 54 63 6c 5f 4f 62 6a 20 63 6f 6e 74 61 69 6e 69 Tcl_Obj containi
0b30: 6e 67 0a 09 09 09 09 20 2a 20 74 68 69 73 20 46 ng..... * this F
0b40: 73 50 61 74 68 20 69 73 20 61 6c 72 65 61 64 79 sPath is already
0b50: 20 6e 6f 72 6d 61 6c 69 7a 65 64 2c 20 74 68 69 normalized, thi
0b60: 73 20 6d 61 79 0a 09 09 09 09 20 2a 20 62 65 20 s may..... * be
0b70: 61 20 63 69 72 63 75 6c 61 72 20 72 65 66 65 72 a circular refer
0b80: 65 6e 63 65 20 62 61 63 6b 20 74 6f 20 74 68 65 ence back to the
0b90: 0a 09 09 09 09 20 2a 20 63 6f 6e 74 61 69 6e 65 ..... * containe
0ba0: 72 2e 20 49 66 20 74 68 61 74 20 69 73 20 4e 4f r. If that is NO
0bb0: 54 20 74 68 65 20 63 61 73 65 2c 20 77 65 20 68 T the case, we h
0bc0: 61 76 65 0a 09 09 09 09 20 2a 20 61 20 72 65 66 ave..... * a ref
0bd0: 43 6f 75 6e 74 20 6f 6e 20 74 68 65 20 6f 62 6a Count on the obj
0be0: 65 63 74 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f ect. */. Tcl_
0bf0: 4f 62 6a 20 2a 63 77 64 50 74 72 3b 09 09 2f 2a Obj *cwdPtr;../*
0c00: 20 49 66 20 6e 75 6c 6c 2c 20 70 61 74 68 20 69 If null, path i
0c10: 73 20 61 62 73 6f 6c 75 74 65 2c 20 65 6c 73 65 s absolute, else
0c20: 20 74 68 69 73 20 70 6f 69 6e 74 73 0a 09 09 09 this points....
0c30: 09 20 2a 20 74 6f 20 74 68 65 20 63 77 64 20 6f . * to the cwd o
0c40: 62 6a 65 63 74 20 75 73 65 64 20 66 6f 72 20 74 bject used for t
0c50: 68 69 73 20 70 61 74 68 2e 20 57 65 0a 09 09 09 his path. We....
0c60: 09 20 2a 20 68 61 76 65 20 61 20 72 65 66 43 6f . * have a refCo
0c70: 75 6e 74 20 6f 6e 20 74 68 65 20 6f 62 6a 65 63 unt on the objec
0c80: 74 2e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 66 6c t. */. int fl
0c90: 61 67 73 3b 09 09 09 2f 2a 20 46 6c 61 67 73 20 ags;.../* Flags
0ca0: 74 6f 20 64 65 73 63 72 69 62 65 20 69 6e 74 65 to describe inte
0cb0: 72 70 72 65 74 61 74 69 6f 6e 20 2d 20 73 65 65 rpretation - see
0cc0: 0a 09 09 09 09 20 2a 20 62 65 6c 6f 77 2e 20 2a ..... * below. *
0cd0: 2f 0a 20 20 20 20 43 6c 69 65 6e 74 44 61 74 61 /. ClientData
0ce0: 20 6e 61 74 69 76 65 50 61 74 68 50 74 72 3b 09 nativePathPtr;.
0cf0: 2f 2a 20 4e 61 74 69 76 65 20 72 65 70 72 65 73 /* Native repres
0d00: 65 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 69 73 entation of this
0d10: 20 70 61 74 68 2c 20 77 68 69 63 68 0a 09 09 09 path, which....
0d20: 09 20 2a 20 69 73 20 66 69 6c 65 73 79 73 74 65 . * is filesyste
0d30: 6d 20 64 65 70 65 6e 64 65 6e 74 2e 20 2a 2f 0a m dependent. */.
0d40: 20 20 20 20 69 6e 74 20 66 69 6c 65 73 79 73 74 int filesyst
0d50: 65 6d 45 70 6f 63 68 3b 09 2f 2a 20 55 73 65 64 emEpoch;./* Used
0d60: 20 74 6f 20 65 6e 73 75 72 65 20 74 68 65 20 70 to ensure the p
0d70: 61 74 68 20 72 65 70 72 65 73 65 6e 74 61 74 69 ath representati
0d80: 6f 6e 20 77 61 73 0a 09 09 09 09 20 2a 20 67 65 on was..... * ge
0d90: 6e 65 72 61 74 65 64 20 64 75 72 69 6e 67 20 74 nerated during t
0da0: 68 65 20 63 6f 72 72 65 63 74 20 66 69 6c 65 73 he correct files
0db0: 79 73 74 65 6d 0a 09 09 09 09 20 2a 20 65 70 6f ystem..... * epo
0dc0: 63 68 2e 20 54 68 65 20 65 70 6f 63 68 20 63 68 ch. The epoch ch
0dd0: 61 6e 67 65 73 20 77 68 65 6e 0a 09 09 09 09 20 anges when.....
0de0: 2a 20 66 69 6c 65 73 79 73 74 65 6d 2d 6d 6f 75 * filesystem-mou
0df0: 6e 74 73 20 61 72 65 20 63 68 61 6e 67 65 64 2e nts are changed.
0e00: 20 2a 2f 0a 20 20 20 20 63 6f 6e 73 74 20 54 63 */. const Tc
0e10: 6c 5f 46 69 6c 65 73 79 73 74 65 6d 20 2a 66 73 l_Filesystem *fs
0e20: 50 74 72 3b 2f 2a 20 54 68 65 20 54 63 6c 5f 46 Ptr;/* The Tcl_F
0e30: 69 6c 65 73 79 73 74 65 6d 20 74 68 61 74 20 63 ilesystem that c
0e40: 6c 61 69 6d 73 20 74 68 69 73 20 70 61 74 68 20 laims this path
0e50: 2a 2f 0a 7d 20 46 73 50 61 74 68 3b 0a 0a 2f 2a */.} FsPath;../*
0e60: 0a 20 2a 20 46 6c 61 67 20 76 61 6c 75 65 73 20 . * Flag values
0e70: 66 6f 72 20 46 73 50 61 74 68 2d 3e 66 6c 61 67 for FsPath->flag
0e80: 73 2e 0a 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 s.. */..#define
0e90: 54 43 4c 50 41 54 48 5f 41 50 50 45 4e 44 45 44 TCLPATH_APPENDED
0ea0: 20 31 0a 23 64 65 66 69 6e 65 20 54 43 4c 50 41 1.#define TCLPA
0eb0: 54 48 5f 4e 45 45 44 4e 4f 52 4d 20 34 0a 0a 2f TH_NEEDNORM 4../
0ec0: 2a 0a 20 2a 20 44 65 66 69 6e 65 20 73 6f 6d 65 *. * Define some
0ed0: 20 6d 61 63 72 6f 73 20 74 6f 20 67 69 76 65 20 macros to give
0ee0: 75 73 20 63 6f 6e 76 65 6e 69 65 6e 74 20 61 63 us convenient ac
0ef0: 63 65 73 73 20 74 6f 20 70 61 74 68 2d 6f 62 6a cess to path-obj
0f00: 65 63 74 20 73 70 65 63 69 66 69 63 0a 20 2a 20 ect specific. *
0f10: 66 69 65 6c 64 73 2e 0a 20 2a 2f 0a 0a 23 64 65 fields.. */..#de
0f20: 66 69 6e 65 20 50 41 54 48 4f 42 4a 28 70 61 74 fine PATHOBJ(pat
0f30: 68 50 74 72 29 20 28 28 46 73 50 61 74 68 20 2a hPtr) ((FsPath *
0f40: 29 20 28 70 61 74 68 50 74 72 29 2d 3e 69 6e 74 ) (pathPtr)->int
0f50: 65 72 6e 61 6c 52 65 70 2e 74 77 6f 50 74 72 56 ernalRep.twoPtrV
0f60: 61 6c 75 65 2e 70 74 72 31 29 0a 23 64 65 66 69 alue.ptr1).#defi
0f70: 6e 65 20 53 45 54 50 41 54 48 4f 42 4a 28 70 61 ne SETPATHOBJ(pa
0f80: 74 68 50 74 72 2c 66 73 50 61 74 68 50 74 72 29 thPtr,fsPathPtr)
0f90: 20 5c 0a 09 28 28 70 61 74 68 50 74 72 29 2d 3e \..((pathPtr)->
0fa0: 69 6e 74 65 72 6e 61 6c 52 65 70 2e 74 77 6f 50 internalRep.twoP
0fb0: 74 72 56 61 6c 75 65 2e 70 74 72 31 20 3d 20 28 trValue.ptr1 = (
0fc0: 76 6f 69 64 20 2a 29 20 28 66 73 50 61 74 68 50 void *) (fsPathP
0fd0: 74 72 29 29 0a 23 64 65 66 69 6e 65 20 50 41 54 tr)).#define PAT
0fe0: 48 46 4c 41 47 53 28 70 61 74 68 50 74 72 29 20 HFLAGS(pathPtr)
0ff0: 28 50 41 54 48 4f 42 4a 28 70 61 74 68 50 74 72 (PATHOBJ(pathPtr
1000: 29 2d 3e 66 6c 61 67 73 29 0a 0c 0a 2f 2a 0a 20 )->flags).../*.
1010: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *---------------
1020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1050: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a ------------. *.
1060: 20 2a 20 54 63 6c 46 53 4e 6f 72 6d 61 6c 69 7a * TclFSNormaliz
1070: 65 41 62 73 6f 6c 75 74 65 50 61 74 68 20 2d 2d eAbsolutePath --
1080: 0a 20 2a 0a 20 2a 09 54 61 6b 65 73 20 61 6e 20 . *. *.Takes an
1090: 61 62 73 6f 6c 75 74 65 20 70 61 74 68 20 73 70 absolute path sp
10a0: 65 63 69 66 69 63 61 74 69 6f 6e 20 61 6e 64 20 ecification and
10b0: 63 6f 6d 70 75 74 65 73 20 61 20 27 6e 6f 72 6d computes a 'norm
10c0: 61 6c 69 7a 65 64 27 20 70 61 74 68 0a 20 2a 09 alized' path. *.
10d0: 66 72 6f 6d 20 69 74 2e 0a 20 2a 0a 20 2a 09 41 from it.. *. *.A
10e0: 20 6e 6f 72 6d 61 6c 69 7a 65 64 20 70 61 74 68 normalized path
10f0: 20 69 73 20 6f 6e 65 20 77 68 69 63 68 20 68 61 is one which ha
1100: 73 20 61 6c 6c 20 27 2e 2e 2f 27 2c 20 27 2e 2f s all '../', './
1110: 27 20 72 65 6d 6f 76 65 64 2e 20 41 6c 73 6f 20 ' removed. Also
1120: 69 74 20 69 73 0a 20 2a 09 6f 6e 65 20 77 68 69 it is. *.one whi
1130: 63 68 20 69 73 20 69 6e 20 74 68 65 20 27 73 74 ch is in the 'st
1140: 61 6e 64 61 72 64 27 20 66 6f 72 6d 61 74 20 66 andard' format f
1150: 6f 72 20 74 68 65 20 6e 61 74 69 76 65 20 70 6c or the native pl
1160: 61 74 66 6f 72 6d 2e 20 4f 6e 0a 20 2a 09 55 6e atform. On. *.Un
1170: 69 78 2c 20 74 68 69 73 20 6d 65 61 6e 73 20 74 ix, this means t
1180: 68 65 20 70 61 74 68 20 6d 75 73 74 20 62 65 20 he path must be
1190: 66 72 65 65 20 6f 66 20 73 79 6d 62 6f 6c 69 63 free of symbolic
11a0: 20 6c 69 6e 6b 73 2f 61 6c 69 61 73 65 73 2c 20 links/aliases,
11b0: 61 6e 64 0a 20 2a 09 6f 6e 20 57 69 6e 64 6f 77 and. *.on Window
11c0: 73 20 69 74 20 6d 65 61 6e 73 20 77 65 20 77 61 s it means we wa
11d0: 6e 74 20 74 68 65 20 6c 6f 6e 67 20 66 6f 72 6d nt the long form
11e0: 2c 20 77 69 74 68 20 74 68 61 74 20 6c 6f 6e 67 , with that long
11f0: 20 66 6f 72 6d 27 73 0a 20 2a 09 63 61 73 65 2d form's. *.case-
1200: 64 65 70 65 6e 64 65 6e 63 65 20 28 77 68 69 63 dependence (whic
1210: 68 20 67 69 76 65 73 20 75 73 20 61 20 75 6e 69 h gives us a uni
1220: 71 75 65 2c 20 63 61 73 65 2d 64 65 70 65 6e 64 que, case-depend
1230: 65 6e 74 20 70 61 74 68 29 2e 0a 20 2a 0a 20 2a ent path).. *. *
1240: 09 54 68 65 20 62 65 68 61 76 69 6f 75 72 20 6f .The behaviour o
1250: 66 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 f this function
1260: 69 66 20 70 61 73 73 65 64 20 61 20 6e 6f 6e 2d if passed a non-
1270: 61 62 73 6f 6c 75 74 65 20 70 61 74 68 20 69 73 absolute path is
1280: 20 4e 4f 54 0a 20 2a 09 64 65 66 69 6e 65 64 2e NOT. *.defined.
1290: 0a 20 2a 0a 20 2a 09 70 61 74 68 50 74 72 20 6d . *. *.pathPtr m
12a0: 61 79 20 68 61 76 65 20 61 20 72 65 66 43 6f 75 ay have a refCou
12b0: 6e 74 20 6f 66 20 7a 65 72 6f 2c 20 6f 72 20 6d nt of zero, or m
12c0: 61 79 20 62 65 20 61 20 73 68 61 72 65 64 20 6f ay be a shared o
12d0: 62 6a 65 63 74 2e 0a 20 2a 0a 20 2a 20 52 65 73 bject.. *. * Res
12e0: 75 6c 74 73 3a 0a 20 2a 09 54 68 65 20 72 65 73 ults:. *.The res
12f0: 75 6c 74 20 69 73 20 72 65 74 75 72 6e 65 64 20 ult is returned
1300: 69 6e 20 61 20 54 63 6c 5f 4f 62 6a 20 77 69 74 in a Tcl_Obj wit
1310: 68 20 61 20 72 65 66 43 6f 75 6e 74 20 6f 66 20 h a refCount of
1320: 31 2c 20 77 68 69 63 68 20 69 73 0a 20 2a 09 74 1, which is. *.t
1330: 68 65 72 65 66 6f 72 65 20 6f 77 6e 65 64 20 62 herefore owned b
1340: 79 20 74 68 65 20 63 61 6c 6c 65 72 2e 20 49 74 y the caller. It
1350: 20 6d 75 73 74 20 62 65 20 66 72 65 65 64 20 28 must be freed (
1360: 77 69 74 68 0a 20 2a 09 54 63 6c 5f 44 65 63 72 with. *.Tcl_Decr
1370: 52 65 66 43 6f 75 6e 74 29 20 62 79 20 74 68 65 RefCount) by the
1380: 20 63 61 6c 6c 65 72 20 77 68 65 6e 20 6e 6f 20 caller when no
1390: 6c 6f 6e 67 65 72 20 6e 65 65 64 65 64 2e 0a 20 longer needed..
13a0: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 *. * Side effect
13b0: 73 3a 0a 20 2a 09 4e 6f 6e 65 20 28 62 65 79 6f s:. *.None (beyo
13c0: 6e 64 20 74 68 65 20 6d 65 6d 6f 72 79 20 61 6c nd the memory al
13d0: 6c 6f 63 61 74 69 6f 6e 20 66 6f 72 20 74 68 65 location for the
13e0: 20 72 65 73 75 6c 74 29 2e 0a 20 2a 0a 20 2a 20 result).. *. *
13f0: 53 70 65 63 69 61 6c 20 6e 6f 74 65 3a 0a 20 2a Special note:. *
1400: 09 54 68 69 73 20 63 6f 64 65 20 77 61 73 20 6f .This code was o
1410: 72 69 67 69 6e 61 6c 6c 79 20 62 61 73 65 64 20 riginally based
1420: 6f 6e 20 63 6f 64 65 20 66 72 6f 6d 20 4d 61 74 on code from Mat
1430: 74 20 4e 65 77 6d 61 6e 20 61 6e 64 0a 20 2a 09 t Newman and. *.
1440: 4a 65 61 6e 2d 43 6c 61 75 64 65 20 57 69 70 70 Jean-Claude Wipp
1450: 6c 65 72 2c 20 62 75 74 20 68 61 73 20 73 69 6e ler, but has sin
1460: 63 65 20 62 65 65 6e 20 74 6f 74 61 6c 6c 79 20 ce been totally
1470: 72 65 77 72 69 74 74 65 6e 20 62 79 20 56 69 6e rewritten by Vin
1480: 63 65 0a 20 2a 09 44 61 72 6c 65 79 20 74 6f 20 ce. *.Darley to
1490: 64 65 61 6c 20 77 69 74 68 20 73 79 6d 62 6f 6c deal with symbol
14a0: 69 63 20 6c 69 6e 6b 73 2e 0a 20 2a 0a 20 2a 2d ic links.. *. *-
14b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
14f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a ----------. */..
1500: 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 46 53 4e Tcl_Obj *.TclFSN
1510: 6f 72 6d 61 6c 69 7a 65 41 62 73 6f 6c 75 74 65 ormalizeAbsolute
1520: 50 61 74 68 28 0a 20 20 20 20 54 63 6c 5f 49 6e Path(. Tcl_In
1530: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 09 09 2f terp *interp,../
1540: 2a 20 49 6e 74 65 72 70 72 65 74 65 72 20 74 6f * Interpreter to
1550: 20 75 73 65 20 2a 2f 0a 20 20 20 20 54 63 6c 5f use */. Tcl_
1560: 4f 62 6a 20 2a 70 61 74 68 50 74 72 29 09 09 2f Obj *pathPtr)../
1570: 2a 20 41 62 73 6f 6c 75 74 65 20 70 61 74 68 20 * Absolute path
1580: 74 6f 20 6e 6f 72 6d 61 6c 69 7a 65 20 2a 2f 0a to normalize */.
1590: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 {. const char
15a0: 20 2a 64 69 72 53 65 70 2c 20 2a 6f 6c 64 44 69 *dirSep, *oldDi
15b0: 72 53 65 70 3b 0a 20 20 20 20 69 6e 74 20 66 69 rSep;. int fi
15c0: 72 73 74 20 3d 20 31 3b 09 09 2f 2a 20 53 65 74 rst = 1;../* Set
15d0: 20 74 6f 20 7a 65 72 6f 20 6f 6e 63 65 20 77 65 to zero once we
15e0: 27 76 65 20 70 61 73 73 65 64 20 74 68 65 20 66 've passed the f
15f0: 69 72 73 74 0a 09 09 09 09 20 2a 20 64 69 72 65 irst..... * dire
1600: 63 74 6f 72 79 20 73 65 70 61 72 61 74 6f 72 20 ctory separator
1610: 2d 20 77 65 20 63 61 6e 27 74 20 75 73 65 20 27 - we can't use '
1620: 2e 2e 27 20 74 6f 0a 09 09 09 09 20 2a 20 72 65 ..' to..... * re
1630: 6d 6f 76 65 20 74 68 65 20 76 6f 6c 75 6d 65 20 move the volume
1640: 69 6e 20 61 20 70 61 74 68 2e 20 2a 2f 0a 20 20 in a path. */.
1650: 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 74 56 61 Tcl_Obj *retVa
1660: 6c 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 64 69 l = NULL;. di
1670: 72 53 65 70 20 3d 20 54 63 6c 47 65 74 53 74 72 rSep = TclGetStr
1680: 69 6e 67 28 70 61 74 68 50 74 72 29 3b 0a 0a 20 ing(pathPtr);..
1690: 20 20 20 69 66 20 28 74 63 6c 50 6c 61 74 66 6f if (tclPlatfo
16a0: 72 6d 20 3d 3d 20 54 43 4c 5f 50 4c 41 54 46 4f rm == TCL_PLATFO
16b0: 52 4d 5f 57 49 4e 44 4f 57 53 29 20 7b 0a 09 69 RM_WINDOWS) {..i
16c0: 66 20 28 20 20 20 28 64 69 72 53 65 70 5b 30 5d f ( (dirSep[0]
16d0: 20 3d 3d 20 27 2f 27 20 7c 7c 20 64 69 72 53 65 == '/' || dirSe
16e0: 70 5b 30 5d 20 3d 3d 20 27 5c 5c 27 29 0a 09 20 p[0] == '\\')..
16f0: 20 20 20 26 26 20 28 64 69 72 53 65 70 5b 31 5d && (dirSep[1]
1700: 20 3d 3d 20 27 2f 27 20 7c 7c 20 64 69 72 53 65 == '/' || dirSe
1710: 70 5b 31 5d 20 3d 3d 20 27 5c 5c 27 29 0a 09 20 p[1] == '\\')..
1720: 20 20 20 26 26 20 28 64 69 72 53 65 70 5b 32 5d && (dirSep[2]
1730: 20 3d 3d 20 27 3f 27 29 0a 09 20 20 20 20 26 26 == '?').. &&
1740: 20 28 64 69 72 53 65 70 5b 33 5d 20 3d 3d 20 27 (dirSep[3] == '
1750: 2f 27 20 7c 7c 20 64 69 72 53 65 70 5b 33 5d 20 /' || dirSep[3]
1760: 3d 3d 20 27 5c 5c 27 29 29 20 7b 0a 09 20 20 20 == '\\')) {..
1770: 20 2f 2a 20 4e 54 20 65 78 74 65 6e 64 65 64 20 /* NT extended
1780: 70 61 74 68 20 2a 2f 0a 09 20 20 20 20 64 69 72 path */.. dir
1790: 53 65 70 20 2b 3d 20 34 3b 0a 0a 09 20 20 20 20 Sep += 4;...
17a0: 69 66 20 28 20 20 20 28 64 69 72 53 65 70 5b 30 if ( (dirSep[0
17b0: 5d 20 3d 3d 20 27 55 27 20 7c 7c 20 64 69 72 53 ] == 'U' || dirS
17c0: 65 70 5b 30 5d 20 3d 3d 20 27 75 27 29 0a 09 09 ep[0] == 'u')...
17d0: 26 26 20 28 64 69 72 53 65 70 5b 31 5d 20 3d 3d && (dirSep[1] ==
17e0: 20 27 4e 27 20 7c 7c 20 64 69 72 53 65 70 5b 31 'N' || dirSep[1
17f0: 5d 20 3d 3d 20 27 6e 27 29 0a 09 09 26 26 20 28 ] == 'n')...&& (
1800: 64 69 72 53 65 70 5b 32 5d 20 3d 3d 20 27 43 27 dirSep[2] == 'C'
1810: 20 7c 7c 20 64 69 72 53 65 70 5b 32 5d 20 3d 3d || dirSep[2] ==
1820: 20 27 63 27 29 0a 09 09 26 26 20 28 64 69 72 53 'c')...&& (dirS
1830: 65 70 5b 33 5d 20 3d 3d 20 27 2f 27 20 7c 7c 20 ep[3] == '/' ||
1840: 64 69 72 53 65 70 5b 33 5d 20 3d 3d 20 27 5c 5c dirSep[3] == '\\
1850: 27 29 29 20 7b 0a 09 09 2f 2a 20 4e 54 20 65 78 ')) {.../* NT ex
1860: 74 65 6e 64 65 64 20 55 4e 43 20 70 61 74 68 20 tended UNC path
1870: 2a 2f 0a 09 09 64 69 72 53 65 70 20 2b 3d 20 34 */...dirSep += 4
1880: 3b 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 69 66 20 ;.. }..}..if
1890: 28 64 69 72 53 65 70 5b 30 5d 20 21 3d 20 30 20 (dirSep[0] != 0
18a0: 26 26 20 64 69 72 53 65 70 5b 31 5d 20 3d 3d 20 && dirSep[1] ==
18b0: 27 3a 27 20 26 26 0a 09 09 28 64 69 72 53 65 70 ':' &&...(dirSep
18c0: 5b 32 5d 20 3d 3d 20 27 2f 27 20 7c 7c 20 64 69 [2] == '/' || di
18d0: 72 53 65 70 5b 32 5d 20 3d 3d 20 27 5c 5c 27 29 rSep[2] == '\\')
18e0: 29 20 7b 0a 09 20 20 20 20 2f 2a 20 44 6f 20 6e ) {.. /* Do n
18f0: 6f 74 68 69 6e 67 20 2a 2f 0a 09 7d 20 65 6c 73 othing */..} els
1900: 65 20 69 66 20 28 28 64 69 72 53 65 70 5b 30 5d e if ((dirSep[0]
1910: 20 3d 3d 20 27 2f 27 20 7c 7c 20 64 69 72 53 65 == '/' || dirSe
1920: 70 5b 30 5d 20 3d 3d 20 27 5c 5c 27 29 0a 09 09 p[0] == '\\')...
1930: 26 26 20 28 64 69 72 53 65 70 5b 31 5d 20 3d 3d && (dirSep[1] ==
1940: 20 27 2f 27 20 7c 7c 20 64 69 72 53 65 70 5b 31 '/' || dirSep[1
1950: 5d 20 3d 3d 20 27 5c 5c 27 29 29 20 7b 0a 09 20 ] == '\\')) {..
1960: 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 55 4e /*.. * UN
1970: 43 20 73 74 79 6c 65 20 70 61 74 68 2c 20 77 68 C style path, wh
1980: 65 72 65 20 77 65 20 6d 75 73 74 20 73 6b 69 70 ere we must skip
1990: 20 6f 76 65 72 20 74 68 65 20 66 69 72 73 74 20 over the first
19a0: 73 65 70 61 72 61 74 6f 72 2c 0a 09 20 20 20 20 separator,..
19b0: 20 2a 20 73 69 6e 63 65 20 74 68 65 20 66 69 72 * since the fir
19c0: 73 74 20 74 77 6f 20 73 65 67 6d 65 6e 74 73 20 st two segments
19d0: 61 72 65 20 61 63 74 75 61 6c 6c 79 20 69 6e 73 are actually ins
19e0: 65 70 61 72 61 62 6c 65 2e 0a 09 20 20 20 20 20 eparable...
19f0: 2a 2f 0a 0a 09 20 20 20 20 64 69 72 53 65 70 20 */... dirSep
1a00: 2b 3d 20 32 3b 0a 09 20 20 20 20 64 69 72 53 65 += 2;.. dirSe
1a10: 70 20 2b 3d 20 46 69 6e 64 53 70 6c 69 74 50 6f p += FindSplitPo
1a20: 73 28 64 69 72 53 65 70 2c 20 27 2f 27 29 3b 0a s(dirSep, '/');.
1a30: 09 20 20 20 20 69 66 20 28 2a 64 69 72 53 65 70 . if (*dirSep
1a40: 20 21 3d 20 30 29 20 7b 0a 09 09 64 69 72 53 65 != 0) {...dirSe
1a50: 70 2b 2b 3b 0a 09 20 20 20 20 7d 0a 09 7d 0a 20 p++;.. }..}.
1a60: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 }.. /*.
1a70: 20 20 2a 20 53 63 61 6e 20 66 6f 72 77 61 72 64 * Scan forward
1a80: 20 66 72 6f 6d 20 6f 6e 65 20 64 69 72 65 63 74 from one direct
1a90: 6f 72 79 20 73 65 70 61 72 61 74 6f 72 20 74 6f ory separator to
1aa0: 20 74 68 65 20 6e 65 78 74 2c 20 63 68 65 63 6b the next, check
1ab0: 69 6e 67 20 66 6f 72 0a 20 20 20 20 20 2a 20 27 ing for. * '
1ac0: 2e 2e 27 20 61 6e 64 20 27 2e 27 20 73 65 71 75 ..' and '.' sequ
1ad0: 65 6e 63 65 73 20 77 68 69 63 68 20 6d 75 73 74 ences which must
1ae0: 20 62 65 20 68 61 6e 64 6c 65 64 20 73 70 65 63 be handled spec
1af0: 69 61 6c 6c 79 2e 20 49 6e 20 70 61 72 74 69 63 ially. In partic
1b00: 75 6c 61 72 0a 20 20 20 20 20 2a 20 68 61 6e 64 ular. * hand
1b10: 6c 69 6e 67 20 6f 66 20 27 2e 2e 27 20 63 61 6e ling of '..' can
1b20: 20 62 65 20 63 6f 6d 70 6c 69 63 61 74 65 64 20 be complicated
1b30: 69 66 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 if the directory
1b40: 20 62 65 66 6f 72 65 20 69 73 20 61 20 6c 69 6e before is a lin
1b50: 6b 2c 0a 20 20 20 20 20 2a 20 73 69 6e 63 65 20 k,. * since
1b60: 77 65 20 77 69 6c 6c 20 68 61 76 65 20 74 6f 20 we will have to
1b70: 65 78 70 61 6e 64 20 74 68 65 20 6c 69 6e 6b 20 expand the link
1b80: 74 6f 20 62 65 20 61 62 6c 65 20 74 6f 20 62 61 to be able to ba
1b90: 63 6b 20 75 70 20 6f 6e 65 20 6c 65 76 65 6c 2e ck up one level.
1ba0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 77 68 . */.. wh
1bb0: 69 6c 65 20 28 2a 64 69 72 53 65 70 20 21 3d 20 ile (*dirSep !=
1bc0: 30 29 20 7b 0a 09 6f 6c 64 44 69 72 53 65 70 20 0) {..oldDirSep
1bd0: 3d 20 64 69 72 53 65 70 3b 0a 09 69 66 20 28 21 = dirSep;..if (!
1be0: 66 69 72 73 74 29 20 7b 0a 09 20 20 20 20 64 69 first) {.. di
1bf0: 72 53 65 70 2b 2b 3b 0a 09 7d 0a 09 64 69 72 53 rSep++;..}..dirS
1c00: 65 70 20 2b 3d 20 46 69 6e 64 53 70 6c 69 74 50 ep += FindSplitP
1c10: 6f 73 28 64 69 72 53 65 70 2c 20 27 2f 27 29 3b os(dirSep, '/');
1c20: 0a 09 69 66 20 28 64 69 72 53 65 70 5b 30 5d 20 ..if (dirSep[0]
1c30: 3d 3d 20 30 20 7c 7c 20 64 69 72 53 65 70 5b 31 == 0 || dirSep[1
1c40: 5d 20 3d 3d 20 30 29 20 7b 0a 09 20 20 20 20 69 ] == 0) {.. i
1c50: 66 20 28 72 65 74 56 61 6c 20 21 3d 20 4e 55 4c f (retVal != NUL
1c60: 4c 29 20 7b 0a 09 09 54 63 6c 5f 41 70 70 65 6e L) {...Tcl_Appen
1c70: 64 54 6f 4f 62 6a 28 72 65 74 56 61 6c 2c 20 6f dToObj(retVal, o
1c80: 6c 64 44 69 72 53 65 70 2c 20 64 69 72 53 65 70 ldDirSep, dirSep
1c90: 20 2d 20 6f 6c 64 44 69 72 53 65 70 29 3b 0a 09 - oldDirSep);..
1ca0: 20 20 20 20 7d 0a 09 20 20 20 20 62 72 65 61 6b }.. break
1cb0: 3b 0a 09 7d 0a 09 69 66 20 28 64 69 72 53 65 70 ;..}..if (dirSep
1cc0: 5b 31 5d 20 3d 3d 20 27 2e 27 29 20 7b 0a 09 20 [1] == '.') {..
1cd0: 20 20 20 69 66 20 28 72 65 74 56 61 6c 20 21 3d if (retVal !=
1ce0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 54 63 6c 5f 41 NULL) {...Tcl_A
1cf0: 70 70 65 6e 64 54 6f 4f 62 6a 28 72 65 74 56 61 ppendToObj(retVa
1d00: 6c 2c 20 6f 6c 64 44 69 72 53 65 70 2c 20 64 69 l, oldDirSep, di
1d10: 72 53 65 70 20 2d 20 6f 6c 64 44 69 72 53 65 70 rSep - oldDirSep
1d20: 29 3b 0a 09 09 6f 6c 64 44 69 72 53 65 70 20 3d );...oldDirSep =
1d30: 20 64 69 72 53 65 70 3b 0a 09 20 20 20 20 7d 0a dirSep;.. }.
1d40: 09 61 67 61 69 6e 3a 0a 09 20 20 20 20 69 66 20 .again:.. if
1d50: 28 49 73 53 65 70 61 72 61 74 6f 72 4f 72 4e 75 (IsSeparatorOrNu
1d60: 6c 6c 28 64 69 72 53 65 70 5b 32 5d 29 29 20 7b ll(dirSep[2])) {
1d70: 0a 09 09 2f 2a 0a 09 09 20 2a 20 4e 65 65 64 20 .../*... * Need
1d80: 74 6f 20 73 6b 69 70 20 27 2e 27 20 69 6e 20 74 to skip '.' in t
1d90: 68 65 20 70 61 74 68 2e 0a 09 09 20 2a 2f 0a 09 he path.... */..
1da0: 09 69 6e 74 20 63 75 72 4c 65 6e 3b 0a 0a 09 09 .int curLen;....
1db0: 69 66 20 28 72 65 74 56 61 6c 20 3d 3d 20 4e 55 if (retVal == NU
1dc0: 4c 4c 29 20 7b 0a 09 09 20 20 20 20 63 6f 6e 73 LL) {... cons
1dd0: 74 20 63 68 61 72 20 2a 70 61 74 68 20 3d 20 54 t char *path = T
1de0: 63 6c 47 65 74 53 74 72 69 6e 67 28 70 61 74 68 clGetString(path
1df0: 50 74 72 29 3b 0a 09 09 20 20 20 20 72 65 74 56 Ptr);... retV
1e00: 61 6c 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 al = Tcl_NewStri
1e10: 6e 67 4f 62 6a 28 70 61 74 68 2c 20 64 69 72 53 ngObj(path, dirS
1e20: 65 70 20 2d 20 70 61 74 68 29 3b 0a 09 09 20 20 ep - path);...
1e30: 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 Tcl_IncrRefCou
1e40: 6e 74 28 72 65 74 56 61 6c 29 3b 0a 09 09 7d 0a nt(retVal);...}.
1e50: 09 09 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 ..Tcl_GetStringF
1e60: 72 6f 6d 4f 62 6a 28 72 65 74 56 61 6c 2c 20 26 romObj(retVal, &
1e70: 63 75 72 4c 65 6e 29 3b 0a 09 09 69 66 20 28 63 curLen);...if (c
1e80: 75 72 4c 65 6e 20 3d 3d 20 30 29 20 7b 0a 09 09 urLen == 0) {...
1e90: 20 20 20 20 54 63 6c 5f 41 70 70 65 6e 64 54 6f Tcl_AppendTo
1ea0: 4f 62 6a 28 72 65 74 56 61 6c 2c 20 64 69 72 53 Obj(retVal, dirS
1eb0: 65 70 2c 20 31 29 3b 0a 09 09 7d 0a 09 09 64 69 ep, 1);...}...di
1ec0: 72 53 65 70 20 2b 3d 20 32 3b 0a 09 09 6f 6c 64 rSep += 2;...old
1ed0: 44 69 72 53 65 70 20 3d 20 64 69 72 53 65 70 3b DirSep = dirSep;
1ee0: 0a 09 09 69 66 20 28 64 69 72 53 65 70 5b 30 5d ...if (dirSep[0]
1ef0: 20 21 3d 20 30 20 26 26 20 64 69 72 53 65 70 5b != 0 && dirSep[
1f00: 31 5d 20 3d 3d 20 27 2e 27 29 20 7b 0a 09 09 20 1] == '.') {...
1f10: 20 20 20 67 6f 74 6f 20 61 67 61 69 6e 3b 0a 09 goto again;..
1f20: 09 7d 0a 09 09 63 6f 6e 74 69 6e 75 65 3b 0a 09 .}...continue;..
1f30: 20 20 20 20 7d 0a 09 20 20 20 20 69 66 20 28 64 }.. if (d
1f40: 69 72 53 65 70 5b 32 5d 20 3d 3d 20 27 2e 27 20 irSep[2] == '.'
1f50: 26 26 20 49 73 53 65 70 61 72 61 74 6f 72 4f 72 && IsSeparatorOr
1f60: 4e 75 6c 6c 28 64 69 72 53 65 70 5b 33 5d 29 29 Null(dirSep[3]))
1f70: 20 7b 0a 09 09 54 63 6c 5f 4f 62 6a 20 2a 6c 69 {...Tcl_Obj *li
1f80: 6e 6b 4f 62 6a 3b 0a 09 09 69 6e 74 20 63 75 72 nkObj;...int cur
1f90: 4c 65 6e 3b 0a 09 09 63 68 61 72 20 2a 6c 69 6e Len;...char *lin
1fa0: 6b 53 74 72 3b 0a 0a 09 09 2f 2a 0a 09 09 20 2a kStr;..../*... *
1fb0: 20 48 61 76 65 20 27 2e 2e 27 20 73 6f 20 6e 65 Have '..' so ne
1fc0: 65 64 20 74 6f 20 73 6b 69 70 20 70 72 65 76 69 ed to skip previ
1fd0: 6f 75 73 20 64 69 72 65 63 74 6f 72 79 2e 0a 09 ous directory...
1fe0: 09 20 2a 2f 0a 0a 09 09 69 66 20 28 72 65 74 56 . */....if (retV
1ff0: 61 6c 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 al == NULL) {...
2000: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
2010: 70 61 74 68 20 3d 20 54 63 6c 47 65 74 53 74 72 path = TclGetStr
2020: 69 6e 67 28 70 61 74 68 50 74 72 29 3b 0a 0a 09 ing(pathPtr);...
2030: 09 20 20 20 20 72 65 74 56 61 6c 20 3d 20 54 63 . retVal = Tc
2040: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 70 l_NewStringObj(p
2050: 61 74 68 2c 20 64 69 72 53 65 70 20 2d 20 70 61 ath, dirSep - pa
2060: 74 68 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f 49 th);... Tcl_I
2070: 6e 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 56 ncrRefCount(retV
2080: 61 6c 29 3b 0a 09 09 7d 0a 09 09 54 63 6c 5f 47 al);...}...Tcl_G
2090: 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 etStringFromObj(
20a0: 72 65 74 56 61 6c 2c 20 26 63 75 72 4c 65 6e 29 retVal, &curLen)
20b0: 3b 0a 09 09 69 66 20 28 63 75 72 4c 65 6e 20 3d ;...if (curLen =
20c0: 3d 20 30 29 20 7b 0a 09 09 20 20 20 20 54 63 6c = 0) {... Tcl
20d0: 5f 41 70 70 65 6e 64 54 6f 4f 62 6a 28 72 65 74 _AppendToObj(ret
20e0: 56 61 6c 2c 20 64 69 72 53 65 70 2c 20 31 29 3b Val, dirSep, 1);
20f0: 0a 09 09 7d 0a 09 09 69 66 20 28 21 66 69 72 73 ...}...if (!firs
2100: 74 20 7c 7c 20 28 74 63 6c 50 6c 61 74 66 6f 72 t || (tclPlatfor
2110: 6d 20 3d 3d 20 54 43 4c 5f 50 4c 41 54 46 4f 52 m == TCL_PLATFOR
2120: 4d 5f 55 4e 49 58 29 29 20 7b 0a 09 09 20 20 20 M_UNIX)) {...
2130: 20 6c 69 6e 6b 4f 62 6a 20 3d 20 54 63 6c 5f 46 linkObj = Tcl_F
2140: 53 4c 69 6e 6b 28 72 65 74 56 61 6c 2c 20 4e 55 SLink(retVal, NU
2150: 4c 4c 2c 20 30 29 3b 0a 0a 09 09 20 20 20 20 2f LL, 0);.... /
2160: 2a 20 53 61 66 65 74 79 20 63 68 65 63 6b 20 69 * Safety check i
2170: 6e 20 63 61 73 65 20 64 72 69 76 65 72 20 63 61 n case driver ca
2180: 75 73 65 64 20 73 68 61 72 69 6e 67 20 2a 2f 0a used sharing */.
2190: 09 09 20 20 20 20 69 66 20 28 54 63 6c 5f 49 73 .. if (Tcl_Is
21a0: 53 68 61 72 65 64 28 72 65 74 56 61 6c 29 29 20 Shared(retVal))
21b0: 7b 0a 09 09 09 54 63 6c 44 65 63 72 52 65 66 43 {....TclDecrRefC
21c0: 6f 75 6e 74 28 72 65 74 56 61 6c 29 3b 0a 09 09 ount(retVal);...
21d0: 09 72 65 74 56 61 6c 20 3d 20 54 63 6c 5f 44 75 .retVal = Tcl_Du
21e0: 70 6c 69 63 61 74 65 4f 62 6a 28 72 65 74 56 61 plicateObj(retVa
21f0: 6c 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 l);....Tcl_IncrR
2200: 65 66 43 6f 75 6e 74 28 72 65 74 56 61 6c 29 3b efCount(retVal);
2210: 0a 09 09 20 20 20 20 7d 0a 0a 09 09 20 20 20 20 ... }....
2220: 69 66 20 28 6c 69 6e 6b 4f 62 6a 20 21 3d 20 4e if (linkObj != N
2230: 55 4c 4c 29 20 7b 0a 09 09 09 2f 2a 0a 09 09 09 ULL) {..../*....
2240: 20 2a 20 47 6f 74 20 61 20 6c 69 6e 6b 2e 20 4e * Got a link. N
2250: 65 65 64 20 74 6f 20 63 68 65 63 6b 20 69 66 20 eed to check if
2260: 74 68 65 20 6c 69 6e 6b 20 69 73 20 72 65 6c 61 the link is rela
2270: 74 69 76 65 0a 09 09 09 20 2a 20 6f 72 20 61 62 tive.... * or ab
2280: 73 6f 6c 75 74 65 2c 20 66 6f 72 20 74 68 6f 73 solute, for thos
2290: 65 20 70 6c 61 74 66 6f 72 6d 73 20 77 68 65 72 e platforms wher
22a0: 65 20 72 65 6c 61 74 69 76 65 0a 09 09 09 20 2a e relative.... *
22b0: 20 6c 69 6e 6b 73 20 65 78 69 73 74 2e 0a 09 09 links exist....
22c0: 09 20 2a 2f 0a 0a 09 09 09 69 66 20 28 74 63 6c . */.....if (tcl
22d0: 50 6c 61 74 66 6f 72 6d 20 21 3d 20 54 43 4c 5f Platform != TCL_
22e0: 50 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 4f 57 53 PLATFORM_WINDOWS
22f0: 0a 09 09 09 09 26 26 20 54 63 6c 5f 46 53 47 65 .....&& Tcl_FSGe
2300: 74 50 61 74 68 54 79 70 65 28 6c 69 6e 6b 4f 62 tPathType(linkOb
2310: 6a 29 0a 09 09 09 09 09 3d 3d 20 54 43 4c 5f 50 j)......== TCL_P
2320: 41 54 48 5f 52 45 4c 41 54 49 56 45 29 20 7b 0a ATH_RELATIVE) {.
2330: 09 09 09 20 20 20 20 2f 2a 0a 09 09 09 20 20 20 ... /*....
2340: 20 20 2a 20 57 65 20 6e 65 65 64 20 74 6f 20 66 * We need to f
2350: 6f 6c 6c 6f 77 20 74 68 69 73 20 6c 69 6e 6b 20 ollow this link
2360: 77 68 69 63 68 20 69 73 20 72 65 6c 61 74 69 76 which is relativ
2370: 65 0a 09 09 09 20 20 20 20 20 2a 20 74 6f 20 72 e.... * to r
2380: 65 74 56 61 6c 27 73 20 64 69 72 65 63 74 6f 72 etVal's director
2390: 79 2e 20 54 68 69 73 20 6d 65 61 6e 73 20 63 6f y. This means co
23a0: 6e 63 61 74 65 6e 61 74 69 6e 67 0a 09 09 09 20 ncatenating....
23b0: 20 20 20 20 2a 20 74 68 65 20 6c 69 6e 6b 20 6f * the link o
23c0: 6e 74 6f 20 74 68 65 20 64 69 72 65 63 74 6f 72 nto the director
23d0: 79 20 6f 66 20 74 68 65 20 70 61 74 68 20 73 6f y of the path so
23e0: 20 66 61 72 2e 0a 09 09 09 20 20 20 20 20 2a 2f far..... */
23f0: 0a 0a 09 09 09 20 20 20 20 63 6f 6e 73 74 20 63 ..... const c
2400: 68 61 72 20 2a 70 61 74 68 20 3d 0a 09 09 09 09 har *path =.....
2410: 20 20 20 20 54 63 6c 5f 47 65 74 53 74 72 69 6e Tcl_GetStrin
2420: 67 46 72 6f 6d 4f 62 6a 28 72 65 74 56 61 6c 2c gFromObj(retVal,
2430: 20 26 63 75 72 4c 65 6e 29 3b 0a 0a 09 09 09 20 &curLen);.....
2440: 20 20 20 77 68 69 6c 65 20 28 2d 2d 63 75 72 4c while (--curL
2450: 65 6e 20 3e 3d 20 30 29 20 7b 0a 09 09 09 09 69 en >= 0) {.....i
2460: 66 20 28 49 73 53 65 70 61 72 61 74 6f 72 4f 72 f (IsSeparatorOr
2470: 4e 75 6c 6c 28 70 61 74 68 5b 63 75 72 4c 65 6e Null(path[curLen
2480: 5d 29 29 20 7b 0a 09 09 09 09 20 20 20 20 62 72 ])) {..... br
2490: 65 61 6b 3b 0a 09 09 09 09 7d 0a 09 09 09 20 20 eak;.....}....
24a0: 20 20 7d 0a 0a 09 09 09 20 20 20 20 2f 2a 0a 09 }..... /*..
24b0: 09 09 20 20 20 20 20 2a 20 57 65 20 77 61 6e 74 .. * We want
24c0: 20 74 68 65 20 74 72 61 69 6c 69 6e 67 20 73 6c the trailing sl
24d0: 61 73 68 2e 0a 09 09 09 20 20 20 20 20 2a 2f 0a ash..... */.
24e0: 0a 09 09 09 20 20 20 20 54 63 6c 5f 53 65 74 4f .... Tcl_SetO
24f0: 62 6a 4c 65 6e 67 74 68 28 72 65 74 56 61 6c 2c bjLength(retVal,
2500: 20 63 75 72 4c 65 6e 2b 31 29 3b 0a 09 09 09 20 curLen+1);....
2510: 20 20 20 54 63 6c 5f 41 70 70 65 6e 64 4f 62 6a Tcl_AppendObj
2520: 54 6f 4f 62 6a 28 72 65 74 56 61 6c 2c 20 6c 69 ToObj(retVal, li
2530: 6e 6b 4f 62 6a 29 3b 0a 09 09 09 20 20 20 20 54 nkObj);.... T
2540: 63 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 6c clDecrRefCount(l
2550: 69 6e 6b 4f 62 6a 29 3b 0a 09 09 09 20 20 20 20 inkObj);....
2560: 6c 69 6e 6b 53 74 72 20 3d 20 54 63 6c 5f 47 65 linkStr = Tcl_Ge
2570: 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 72 tStringFromObj(r
2580: 65 74 56 61 6c 2c 20 26 63 75 72 4c 65 6e 29 3b etVal, &curLen);
2590: 0a 09 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 ....} else {....
25a0: 20 20 20 20 2f 2a 0a 09 09 09 20 20 20 20 20 2a /*.... *
25b0: 20 41 62 73 6f 6c 75 74 65 20 6c 69 6e 6b 2e 0a Absolute link..
25c0: 09 09 09 20 20 20 20 20 2a 2f 0a 0a 09 09 09 20 ... */.....
25d0: 20 20 20 54 63 6c 44 65 63 72 52 65 66 43 6f 75 TclDecrRefCou
25e0: 6e 74 28 72 65 74 56 61 6c 29 3b 0a 09 09 09 20 nt(retVal);....
25f0: 20 20 20 69 66 20 28 54 63 6c 5f 49 73 53 68 61 if (Tcl_IsSha
2600: 72 65 64 28 6c 69 6e 6b 4f 62 6a 29 29 20 7b 0a red(linkObj)) {.
2610: 09 09 09 09 72 65 74 56 61 6c 20 3d 20 54 63 6c ....retVal = Tcl
2620: 5f 44 75 70 6c 69 63 61 74 65 4f 62 6a 28 6c 69 _DuplicateObj(li
2630: 6e 6b 4f 62 6a 29 3b 0a 09 09 09 09 54 63 6c 44 nkObj);.....TclD
2640: 65 63 72 52 65 66 43 6f 75 6e 74 28 6c 69 6e 6b ecrRefCount(link
2650: 4f 62 6a 29 3b 0a 09 09 09 20 20 20 20 7d 20 65 Obj);.... } e
2660: 6c 73 65 20 7b 0a 09 09 09 09 72 65 74 56 61 6c lse {.....retVal
2670: 20 3d 20 6c 69 6e 6b 4f 62 6a 3b 0a 09 09 09 20 = linkObj;....
2680: 20 20 20 7d 0a 09 09 09 20 20 20 20 6c 69 6e 6b }.... link
2690: 53 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 Str = Tcl_GetStr
26a0: 69 6e 67 46 72 6f 6d 4f 62 6a 28 72 65 74 56 61 ingFromObj(retVa
26b0: 6c 2c 20 26 63 75 72 4c 65 6e 29 3b 0a 0a 09 09 l, &curLen);....
26c0: 09 20 20 20 20 2f 2a 0a 09 09 09 20 20 20 20 20 . /*....
26d0: 2a 20 43 6f 6e 76 65 72 74 20 74 6f 20 66 6f 72 * Convert to for
26e0: 77 61 72 64 2d 73 6c 61 73 68 65 73 20 6f 6e 20 ward-slashes on
26f0: 77 69 6e 64 6f 77 73 2e 0a 09 09 09 20 20 20 20 windows.....
2700: 20 2a 2f 0a 0a 09 09 09 20 20 20 20 69 66 20 28 */..... if (
2710: 74 63 6c 50 6c 61 74 66 6f 72 6d 20 3d 3d 20 54 tclPlatform == T
2720: 43 4c 5f 50 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 CL_PLATFORM_WIND
2730: 4f 57 53 29 20 7b 0a 09 09 09 09 69 6e 74 20 69 OWS) {.....int i
2740: 3b 0a 0a 09 09 09 09 66 6f 72 20 28 69 20 3d 20 ;......for (i =
2750: 30 3b 20 69 20 3c 20 63 75 72 4c 65 6e 3b 20 69 0; i < curLen; i
2760: 2b 2b 29 20 7b 0a 09 09 09 09 20 20 20 20 69 66 ++) {..... if
2770: 20 28 6c 69 6e 6b 53 74 72 5b 69 5d 20 3d 3d 20 (linkStr[i] ==
2780: 27 5c 5c 27 29 20 7b 0a 09 09 09 09 09 6c 69 6e '\\') {......lin
2790: 6b 53 74 72 5b 69 5d 20 3d 20 27 2f 27 3b 0a 09 kStr[i] = '/';..
27a0: 09 09 09 20 20 20 20 7d 0a 09 09 09 09 7d 0a 09 ... }.....}..
27b0: 09 09 20 20 20 20 7d 0a 09 09 09 7d 0a 09 09 20 .. }....}...
27c0: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09 09 6c } else {....l
27d0: 69 6e 6b 53 74 72 20 3d 20 54 63 6c 5f 47 65 74 inkStr = Tcl_Get
27e0: 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 72 65 StringFromObj(re
27f0: 74 56 61 6c 2c 20 26 63 75 72 4c 65 6e 29 3b 0a tVal, &curLen);.
2800: 09 09 20 20 20 20 7d 0a 0a 09 09 20 20 20 20 2f .. }.... /
2810: 2a 0a 09 09 20 20 20 20 20 2a 20 45 69 74 68 65 *... * Eithe
2820: 72 20 77 61 79 2c 20 77 65 20 6e 6f 77 20 72 65 r way, we now re
2830: 6d 6f 76 65 20 74 68 65 20 6c 61 73 74 20 70 61 move the last pa
2840: 74 68 20 65 6c 65 6d 65 6e 74 20 28 62 75 74 0a th element (but.
2850: 09 09 20 20 20 20 20 2a 20 6e 6f 74 20 74 68 65 .. * not the
2860: 20 66 69 72 73 74 20 63 68 61 72 61 63 74 65 72 first character
2870: 20 6f 66 20 74 68 65 20 70 61 74 68 29 2e 0a 09 of the path)...
2880: 09 20 20 20 20 20 2a 2f 0a 0a 09 09 20 20 20 20 . */....
2890: 77 68 69 6c 65 20 28 2d 2d 63 75 72 4c 65 6e 20 while (--curLen
28a0: 3e 3d 20 30 29 20 7b 0a 09 09 09 69 66 20 28 49 >= 0) {....if (I
28b0: 73 53 65 70 61 72 61 74 6f 72 4f 72 4e 75 6c 6c sSeparatorOrNull
28c0: 28 6c 69 6e 6b 53 74 72 5b 63 75 72 4c 65 6e 5d (linkStr[curLen]
28d0: 29 29 20 7b 0a 09 09 09 20 20 20 20 69 66 20 28 )) {.... if (
28e0: 63 75 72 4c 65 6e 29 20 7b 0a 09 09 09 09 54 63 curLen) {.....Tc
28f0: 6c 5f 53 65 74 4f 62 6a 4c 65 6e 67 74 68 28 72 l_SetObjLength(r
2900: 65 74 56 61 6c 2c 20 63 75 72 4c 65 6e 29 3b 0a etVal, curLen);.
2910: 09 09 09 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a ... } else {.
2920: 09 09 09 09 54 63 6c 5f 53 65 74 4f 62 6a 4c 65 ....Tcl_SetObjLe
2930: 6e 67 74 68 28 72 65 74 56 61 6c 2c 20 31 29 3b ngth(retVal, 1);
2940: 0a 09 09 09 20 20 20 20 7d 0a 09 09 09 20 20 20 .... }....
2950: 20 62 72 65 61 6b 3b 0a 09 09 09 7d 0a 09 09 20 break;....}...
2960: 20 20 20 7d 0a 09 09 7d 0a 09 09 64 69 72 53 65 }...}...dirSe
2970: 70 20 2b 3d 20 33 3b 0a 09 09 6f 6c 64 44 69 72 p += 3;...oldDir
2980: 53 65 70 20 3d 20 64 69 72 53 65 70 3b 0a 0a 09 Sep = dirSep;...
2990: 09 69 66 20 28 28 63 75 72 4c 65 6e 20 3d 3d 20 .if ((curLen ==
29a0: 30 29 20 26 26 20 28 64 69 72 53 65 70 5b 30 5d 0) && (dirSep[0]
29b0: 20 21 3d 20 30 29 29 20 7b 0a 09 09 20 20 20 20 != 0)) {...
29c0: 54 63 6c 5f 53 65 74 4f 62 6a 4c 65 6e 67 74 68 Tcl_SetObjLength
29d0: 28 72 65 74 56 61 6c 2c 20 30 29 3b 0a 09 09 7d (retVal, 0);...}
29e0: 0a 0a 09 09 69 66 20 28 64 69 72 53 65 70 5b 30 ....if (dirSep[0
29f0: 5d 20 21 3d 20 30 20 26 26 20 64 69 72 53 65 70 ] != 0 && dirSep
2a00: 5b 31 5d 20 3d 3d 20 27 2e 27 29 20 7b 0a 09 09 [1] == '.') {...
2a10: 20 20 20 20 67 6f 74 6f 20 61 67 61 69 6e 3b 0a goto again;.
2a20: 09 09 7d 0a 09 09 63 6f 6e 74 69 6e 75 65 3b 0a ..}...continue;.
2a30: 09 20 20 20 20 7d 0a 09 7d 0a 09 66 69 72 73 74 . }..}..first
2a40: 20 3d 20 30 3b 0a 09 69 66 20 28 72 65 74 56 61 = 0;..if (retVa
2a50: 6c 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 l != NULL) {..
2a60: 20 20 54 63 6c 5f 41 70 70 65 6e 64 54 6f 4f 62 Tcl_AppendToOb
2a70: 6a 28 72 65 74 56 61 6c 2c 20 6f 6c 64 44 69 72 j(retVal, oldDir
2a80: 53 65 70 2c 20 64 69 72 53 65 70 20 2d 20 6f 6c Sep, dirSep - ol
2a90: 64 44 69 72 53 65 70 29 3b 0a 09 7d 0a 20 20 20 dDirSep);..}.
2aa0: 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 }.. /*.
2ab0: 2a 20 49 66 20 77 65 20 64 69 64 6e 27 74 20 6d * If we didn't m
2ac0: 61 6b 65 20 61 6e 79 20 63 68 61 6e 67 65 73 2c ake any changes,
2ad0: 20 6a 75 73 74 20 75 73 65 20 74 68 65 20 69 6e just use the in
2ae0: 70 75 74 20 70 61 74 68 2e 0a 20 20 20 20 20 2a put path.. *
2af0: 2f 0a 0a 20 20 20 20 69 66 20 28 72 65 74 56 61 /.. if (retVa
2b00: 6c 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 l == NULL) {..re
2b10: 74 56 61 6c 20 3d 20 70 61 74 68 50 74 72 3b 0a tVal = pathPtr;.
2b20: 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e .Tcl_IncrRefCoun
2b30: 74 28 72 65 74 56 61 6c 29 3b 0a 0a 09 69 66 20 t(retVal);...if
2b40: 28 54 63 6c 5f 49 73 53 68 61 72 65 64 28 72 65 (Tcl_IsShared(re
2b50: 74 56 61 6c 29 29 20 7b 0a 09 20 20 20 20 2f 2a tVal)) {.. /*
2b60: 0a 09 20 20 20 20 20 2a 20 55 6e 66 6f 72 74 75 .. * Unfortu
2b70: 6e 61 74 65 6c 79 2c 20 74 68 65 20 70 6c 61 74 nately, the plat
2b80: 66 6f 72 6d 2d 73 70 65 63 69 66 69 63 20 6e 6f form-specific no
2b90: 72 6d 61 6c 69 7a 61 74 69 6f 6e 20 63 6f 64 65 rmalization code
2ba0: 20 77 68 69 63 68 0a 09 20 20 20 20 20 2a 20 77 which.. * w
2bb0: 69 6c 6c 20 62 65 20 63 61 6c 6c 65 64 20 62 65 ill be called be
2bc0: 6c 6f 77 20 68 61 73 20 6e 6f 20 77 61 79 20 6f low has no way o
2bd0: 66 20 64 65 61 6c 69 6e 67 20 77 69 74 68 20 74 f dealing with t
2be0: 68 65 20 63 61 73 65 20 77 68 65 72 65 0a 09 20 he case where..
2bf0: 20 20 20 20 2a 20 61 6e 20 6f 62 6a 65 63 74 20 * an object
2c00: 69 73 20 73 68 61 72 65 64 2e 20 49 74 20 69 73 is shared. It is
2c10: 20 65 78 70 65 63 74 69 6e 67 20 74 6f 20 6d 6f expecting to mo
2c20: 64 69 66 79 20 61 6e 20 6f 62 6a 65 63 74 20 69 dify an object i
2c30: 6e 0a 09 20 20 20 20 20 2a 20 70 6c 61 63 65 2e n.. * place.
2c40: 20 53 6f 2c 20 77 65 20 6d 75 73 74 20 64 75 70 So, we must dup
2c50: 6c 69 63 61 74 65 20 74 68 69 73 20 68 65 72 65 licate this here
2c60: 20 74 6f 20 65 6e 73 75 72 65 20 61 6e 20 6f 62 to ensure an ob
2c70: 6a 65 63 74 20 77 69 74 68 0a 09 20 20 20 20 20 ject with..
2c80: 2a 20 61 20 73 69 6e 67 6c 65 20 72 65 66 2d 63 * a single ref-c
2c90: 6f 75 6e 74 2e 0a 09 20 20 20 20 20 2a 0a 09 20 ount... *..
2ca0: 20 20 20 20 2a 20 49 66 20 74 68 61 74 20 63 68 * If that ch
2cb0: 61 6e 67 65 73 20 69 6e 20 74 68 65 20 66 75 74 anges in the fut
2cc0: 75 72 65 20 28 65 2e 67 2e 20 74 68 65 20 6e 6f ure (e.g. the no
2cd0: 72 6d 61 6c 69 7a 65 20 70 72 6f 63 20 69 73 20 rmalize proc is
2ce0: 67 69 76 65 6e 0a 09 20 20 20 20 20 2a 20 6f 6e given.. * on
2cf0: 65 20 6f 62 6a 65 63 74 20 61 6e 64 20 69 73 20 e object and is
2d00: 61 62 6c 65 20 74 6f 20 72 65 74 75 72 6e 20 61 able to return a
2d10: 20 64 69 66 66 65 72 65 6e 74 20 6f 6e 65 29 2c different one),
2d20: 20 74 68 65 6e 20 77 65 0a 09 20 20 20 20 20 2a then we.. *
2d30: 20 63 6f 75 6c 64 20 72 65 6d 6f 76 65 20 74 68 could remove th
2d40: 69 73 20 63 6f 64 65 2e 0a 09 20 20 20 20 20 2a is code... *
2d50: 2f 0a 0a 09 20 20 20 20 54 63 6c 44 65 63 72 52 /... TclDecrR
2d60: 65 66 43 6f 75 6e 74 28 72 65 74 56 61 6c 29 3b efCount(retVal);
2d70: 0a 09 20 20 20 20 72 65 74 56 61 6c 20 3d 20 54 .. retVal = T
2d80: 63 6c 5f 44 75 70 6c 69 63 61 74 65 4f 62 6a 28 cl_DuplicateObj(
2d90: 70 61 74 68 50 74 72 29 3b 0a 09 20 20 20 20 54 pathPtr);.. T
2da0: 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 cl_IncrRefCount(
2db0: 72 65 74 56 61 6c 29 3b 0a 09 7d 0a 20 20 20 20 retVal);..}.
2dc0: 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a }.. /*. *
2dd0: 20 45 6e 73 75 72 65 20 61 20 77 69 6e 64 6f 77 Ensure a window
2de0: 73 20 64 72 69 76 65 20 6c 69 6b 65 20 43 3a 2f s drive like C:/
2df0: 20 68 61 73 20 61 20 74 72 61 69 6c 69 6e 67 20 has a trailing
2e00: 73 65 70 61 72 61 74 6f 72 2e 0a 20 20 20 20 20 separator..
2e10: 2a 2f 0a 0a 20 20 20 20 69 66 20 28 74 63 6c 50 */.. if (tclP
2e20: 6c 61 74 66 6f 72 6d 20 3d 3d 20 54 43 4c 5f 50 latform == TCL_P
2e30: 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 4f 57 53 29 LATFORM_WINDOWS)
2e40: 20 7b 0a 09 69 6e 74 20 6c 65 6e 3b 0a 09 63 6f {..int len;..co
2e50: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 20 3d nst char *path =
2e60: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 Tcl_GetStringFr
2e70: 6f 6d 4f 62 6a 28 72 65 74 56 61 6c 2c 20 26 6c omObj(retVal, &l
2e80: 65 6e 29 3b 0a 0a 09 69 66 20 28 6c 65 6e 20 3d en);...if (len =
2e90: 3d 20 32 20 26 26 20 70 61 74 68 5b 30 5d 20 21 = 2 && path[0] !
2ea0: 3d 20 30 20 26 26 20 70 61 74 68 5b 31 5d 20 3d = 0 && path[1] =
2eb0: 3d 20 27 3a 27 29 20 7b 0a 09 20 20 20 20 69 66 = ':') {.. if
2ec0: 20 28 54 63 6c 5f 49 73 53 68 61 72 65 64 28 72 (Tcl_IsShared(r
2ed0: 65 74 56 61 6c 29 29 20 7b 0a 09 09 54 63 6c 44 etVal)) {...TclD
2ee0: 65 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 56 ecrRefCount(retV
2ef0: 61 6c 29 3b 0a 09 09 72 65 74 56 61 6c 20 3d 20 al);...retVal =
2f00: 54 63 6c 5f 44 75 70 6c 69 63 61 74 65 4f 62 6a Tcl_DuplicateObj
2f10: 28 72 65 74 56 61 6c 29 3b 0a 09 09 54 63 6c 5f (retVal);...Tcl_
2f20: 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 IncrRefCount(ret
2f30: 56 61 6c 29 3b 0a 09 20 20 20 20 7d 0a 09 20 20 Val);.. }..
2f40: 20 20 54 63 6c 5f 41 70 70 65 6e 64 54 6f 4f 62 Tcl_AppendToOb
2f50: 6a 28 72 65 74 56 61 6c 2c 20 22 2f 22 2c 20 31 j(retVal, "/", 1
2f60: 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 );..}. }..
2f70: 20 2f 2a 0a 20 20 20 20 20 2a 20 4e 6f 77 20 77 /*. * Now w
2f80: 65 20 68 61 76 65 20 61 6e 20 61 62 73 6f 6c 75 e have an absolu
2f90: 74 65 20 70 61 74 68 2c 20 77 69 74 68 20 6e 6f te path, with no
2fa0: 20 27 2e 2e 27 2c 20 27 2e 27 20 73 65 71 75 65 '..', '.' seque
2fb0: 6e 63 65 73 2c 20 62 75 74 20 69 74 20 73 74 69 nces, but it sti
2fc0: 6c 6c 0a 20 20 20 20 20 2a 20 6d 61 79 20 6e 6f ll. * may no
2fd0: 74 20 62 65 20 69 6e 20 27 75 6e 69 71 75 65 27 t be in 'unique'
2fe0: 20 66 6f 72 6d 2c 20 64 65 70 65 6e 64 69 6e 67 form, depending
2ff0: 20 6f 6e 20 74 68 65 20 70 6c 61 74 66 6f 72 6d on the platform
3000: 2e 20 46 6f 72 20 69 6e 73 74 61 6e 63 65 2c 0a . For instance,.
3010: 20 20 20 20 20 2a 20 55 6e 69 78 20 69 73 20 63 * Unix is c
3020: 61 73 65 2d 73 65 6e 73 69 74 69 76 65 2c 20 73 ase-sensitive, s
3030: 6f 20 74 68 65 20 70 61 74 68 20 69 73 20 6f 6b o the path is ok
3040: 2e 20 57 69 6e 64 6f 77 73 20 69 73 20 63 61 73 . Windows is cas
3050: 65 2d 69 6e 73 65 6e 73 69 74 69 76 65 2c 0a 20 e-insensitive,.
3060: 20 20 20 20 2a 20 61 6e 64 20 61 6c 73 6f 20 68 * and also h
3070: 61 73 20 74 68 65 20 77 65 69 72 64 20 27 6c 6f as the weird 'lo
3080: 6e 67 6e 61 6d 65 2f 73 68 6f 72 74 6e 61 6d 65 ngname/shortname
3090: 27 20 74 68 69 6e 67 20 28 65 2e 67 2e 20 43 3a ' thing (e.g. C:
30a0: 2f 50 72 6f 67 72 61 6d 0a 20 20 20 20 20 2a 20 /Program. *
30b0: 46 69 6c 65 73 2f 20 61 6e 64 20 43 3a 2f 50 72 Files/ and C:/Pr
30c0: 6f 67 72 61 7e 31 2f 20 61 72 65 20 65 71 75 69 ogra~1/ are equi
30d0: 76 61 6c 65 6e 74 29 2e 0a 20 20 20 20 20 2a 0a valent).. *.
30e0: 20 20 20 20 20 2a 20 56 69 72 74 75 61 6c 20 66 * Virtual f
30f0: 69 6c 65 20 73 79 73 74 65 6d 73 20 77 68 69 63 ile systems whic
3100: 68 20 6d 61 79 20 62 65 20 72 65 67 69 73 74 65 h may be registe
3110: 72 65 64 20 6d 61 79 20 68 61 76 65 20 6f 74 68 red may have oth
3120: 65 72 20 63 72 69 74 65 72 69 61 0a 20 20 20 20 er criteria.
3130: 20 2a 20 66 6f 72 20 6e 6f 72 6d 61 6c 69 7a 69 * for normalizi
3140: 6e 67 20 61 20 70 61 74 68 2e 0a 20 20 20 20 20 ng a path..
3150: 2a 2f 0a 0a 20 20 20 20 54 63 6c 46 53 4e 6f 72 */.. TclFSNor
3160: 6d 61 6c 69 7a 65 54 6f 55 6e 69 71 75 65 50 61 malizeToUniquePa
3170: 74 68 28 69 6e 74 65 72 70 2c 20 72 65 74 56 61 th(interp, retVa
3180: 6c 2c 20 30 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 l, 0);.. /*.
3190: 20 20 20 20 2a 20 53 69 6e 63 65 20 77 65 20 6b * Since we k
31a0: 6e 6f 77 20 69 74 20 69 73 20 61 20 6e 6f 72 6d now it is a norm
31b0: 61 6c 69 7a 65 64 20 70 61 74 68 2c 20 77 65 20 alized path, we
31c0: 63 61 6e 20 61 63 74 75 61 6c 6c 79 20 63 6f 6e can actually con
31d0: 76 65 72 74 20 74 68 69 73 0a 20 20 20 20 20 2a vert this. *
31e0: 20 6f 62 6a 65 63 74 20 69 6e 74 6f 20 61 6e 20 object into an
31f0: 46 73 50 61 74 68 20 66 6f 72 20 67 72 65 61 74 FsPath for great
3200: 65 72 20 65 66 66 69 63 69 65 6e 63 79 0a 20 20 er efficiency.
3210: 20 20 20 2a 2f 0a 0a 20 20 20 20 4d 61 6b 65 50 */.. MakeP
3220: 61 74 68 46 72 6f 6d 4e 6f 72 6d 61 6c 69 7a 65 athFromNormalize
3230: 64 28 69 6e 74 65 72 70 2c 20 72 65 74 56 61 6c d(interp, retVal
3240: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
3250: 2a 20 54 68 69 73 20 68 61 73 20 61 20 72 65 66 * This has a ref
3260: 43 6f 75 6e 74 20 6f 66 20 31 20 66 6f 72 20 74 Count of 1 for t
3270: 68 65 20 63 61 6c 6c 65 72 2c 20 75 6e 6c 69 6b he caller, unlik
3280: 65 20 6d 61 6e 79 20 54 63 6c 5f 4f 62 6a 20 41 e many Tcl_Obj A
3290: 50 49 73 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 PIs.. */..
32a0: 20 20 72 65 74 75 72 6e 20 72 65 74 56 61 6c 3b return retVal;
32b0: 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d .}.../*. *------
32c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
32d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
32e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
32f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3300: 0a 20 2a 0a 20 2a 20 54 63 6c 5f 46 53 47 65 74 . *. * Tcl_FSGet
3310: 50 61 74 68 54 79 70 65 20 2d 2d 0a 20 2a 0a 20 PathType --. *.
3320: 2a 09 44 65 74 65 72 6d 69 6e 65 73 20 77 68 65 *.Determines whe
3330: 74 68 65 72 20 61 20 67 69 76 65 6e 20 70 61 74 ther a given pat
3340: 68 20 69 73 20 72 65 6c 61 74 69 76 65 20 74 6f h is relative to
3350: 20 74 68 65 20 63 75 72 72 65 6e 74 20 64 69 72 the current dir
3360: 65 63 74 6f 72 79 2c 0a 20 2a 09 72 65 6c 61 74 ectory,. *.relat
3370: 69 76 65 20 74 6f 20 74 68 65 20 63 75 72 72 65 ive to the curre
3380: 6e 74 20 76 6f 6c 75 6d 65 2c 20 6f 72 20 61 62 nt volume, or ab
3390: 73 6f 6c 75 74 65 2e 0a 20 2a 0a 20 2a 20 52 65 solute.. *. * Re
33a0: 73 75 6c 74 73 3a 0a 20 2a 09 52 65 74 75 72 6e sults:. *.Return
33b0: 73 20 6f 6e 65 20 6f 66 20 54 43 4c 5f 50 41 54 s one of TCL_PAT
33c0: 48 5f 41 42 53 4f 4c 55 54 45 2c 20 54 43 4c 5f H_ABSOLUTE, TCL_
33d0: 50 41 54 48 5f 52 45 4c 41 54 49 56 45 2c 20 6f PATH_RELATIVE, o
33e0: 72 0a 20 2a 09 54 43 4c 5f 50 41 54 48 5f 56 4f r. *.TCL_PATH_VO
33f0: 4c 55 4d 45 5f 52 45 4c 41 54 49 56 45 2e 0a 20 LUME_RELATIVE..
3400: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 *. * Side effect
3410: 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 s:. *.None.. *.
3420: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *---------------
3430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3460: 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 54 63 6c -------. */..Tcl
3470: 5f 50 61 74 68 54 79 70 65 0a 54 63 6c 5f 46 53 _PathType.Tcl_FS
3480: 47 65 74 50 61 74 68 54 79 70 65 28 0a 20 20 20 GetPathType(.
3490: 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 Tcl_Obj *pathPt
34a0: 72 29 0a 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 r).{. return
34b0: 54 63 6c 46 53 47 65 74 50 61 74 68 54 79 70 65 TclFSGetPathType
34c0: 28 70 61 74 68 50 74 72 2c 20 4e 55 4c 4c 2c 20 (pathPtr, NULL,
34d0: 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a NULL);.}.../*. *
34e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
34f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3510: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3520: 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63 6c ------. *. * Tcl
3530: 46 53 47 65 74 50 61 74 68 54 79 70 65 20 2d 2d FSGetPathType --
3540: 0a 20 2a 0a 20 2a 09 44 65 74 65 72 6d 69 6e 65 . *. *.Determine
3550: 73 20 77 68 65 74 68 65 72 20 61 20 67 69 76 65 s whether a give
3560: 6e 20 70 61 74 68 20 69 73 20 72 65 6c 61 74 69 n path is relati
3570: 76 65 20 74 6f 20 74 68 65 20 63 75 72 72 65 6e ve to the curren
3580: 74 20 64 69 72 65 63 74 6f 72 79 2c 0a 20 2a 09 t directory,. *.
3590: 72 65 6c 61 74 69 76 65 20 74 6f 20 74 68 65 20 relative to the
35a0: 63 75 72 72 65 6e 74 20 76 6f 6c 75 6d 65 2c 20 current volume,
35b0: 6f 72 20 61 62 73 6f 6c 75 74 65 2e 20 49 66 20 or absolute. If
35c0: 74 68 65 20 63 61 6c 6c 65 72 20 77 69 73 68 65 the caller wishe
35d0: 73 20 74 6f 0a 20 2a 09 6b 6e 6f 77 20 77 68 69 s to. *.know whi
35e0: 63 68 20 66 69 6c 65 73 79 73 74 65 6d 20 63 6c ch filesystem cl
35f0: 61 69 6d 65 64 20 74 68 65 20 70 61 74 68 20 28 aimed the path (
3600: 69 6e 20 74 68 65 20 63 61 73 65 20 66 6f 72 20 in the case for
3610: 77 68 69 63 68 20 74 68 65 20 70 61 74 68 0a 20 which the path.
3620: 2a 09 69 73 20 61 62 73 6f 6c 75 74 65 29 2c 20 *.is absolute),
3630: 74 68 65 6e 20 61 20 72 65 66 65 72 65 6e 63 65 then a reference
3640: 20 74 6f 20 61 20 66 69 6c 65 73 79 73 74 65 6d to a filesystem
3650: 20 70 6f 69 6e 74 65 72 20 63 61 6e 20 62 65 20 pointer can be
3660: 70 61 73 73 65 64 0a 20 2a 09 69 6e 20 28 62 75 passed. *.in (bu
3670: 74 20 70 61 73 73 69 6e 67 20 4e 55 4c 4c 20 69 t passing NULL i
3680: 73 20 61 63 63 65 70 74 61 62 6c 65 29 2e 0a 20 s acceptable)..
3690: 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a *. * Results:. *
36a0: 09 52 65 74 75 72 6e 73 20 6f 6e 65 20 6f 66 20 .Returns one of
36b0: 54 43 4c 5f 50 41 54 48 5f 41 42 53 4f 4c 55 54 TCL_PATH_ABSOLUT
36c0: 45 2c 20 54 43 4c 5f 50 41 54 48 5f 52 45 4c 41 E, TCL_PATH_RELA
36d0: 54 49 56 45 2c 20 6f 72 0a 20 2a 09 54 43 4c 5f TIVE, or. *.TCL_
36e0: 50 41 54 48 5f 56 4f 4c 55 4d 45 5f 52 45 4c 41 PATH_VOLUME_RELA
36f0: 54 49 56 45 2e 20 54 68 65 20 66 69 6c 65 73 79 TIVE. The filesy
3700: 73 74 65 6d 20 72 65 66 65 72 65 6e 63 65 20 77 stem reference w
3710: 69 6c 6c 20 62 65 20 73 65 74 20 69 66 20 61 6e ill be set if an
3720: 64 0a 20 2a 09 6f 6e 6c 79 20 69 66 20 69 74 20 d. *.only if it
3730: 69 73 20 6e 6f 6e 2d 4e 55 4c 4c 20 61 6e 64 20 is non-NULL and
3740: 74 68 65 20 66 75 6e 63 74 69 6f 6e 27 73 20 72 the function's r
3750: 65 74 75 72 6e 20 76 61 6c 75 65 20 69 73 0a 20 eturn value is.
3760: 2a 09 54 43 4c 5f 50 41 54 48 5f 41 42 53 4f 4c *.TCL_PATH_ABSOL
3770: 55 54 45 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 UTE.. *. * Side
3780: 65 66 66 65 63 74 73 3a 0a 20 2a 09 4e 6f 6e 65 effects:. *.None
3790: 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d .. *. *---------
37a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
37b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
37c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
37d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a -------------. *
37e0: 2f 0a 0a 54 63 6c 5f 50 61 74 68 54 79 70 65 0a /..Tcl_PathType.
37f0: 54 63 6c 46 53 47 65 74 50 61 74 68 54 79 70 65 TclFSGetPathType
3800: 28 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70 (. Tcl_Obj *p
3810: 61 74 68 50 74 72 2c 0a 20 20 20 20 63 6f 6e 73 athPtr,. cons
3820: 74 20 54 63 6c 5f 46 69 6c 65 73 79 73 74 65 6d t Tcl_Filesystem
3830: 20 2a 2a 66 69 6c 65 73 79 73 74 65 6d 50 74 72 **filesystemPtr
3840: 50 74 72 2c 0a 20 20 20 20 69 6e 74 20 2a 64 72 Ptr,. int *dr
3850: 69 76 65 4e 61 6d 65 4c 65 6e 67 74 68 50 74 72 iveNameLengthPtr
3860: 29 0a 7b 0a 20 20 20 20 46 73 50 61 74 68 20 2a ).{. FsPath *
3870: 66 73 50 61 74 68 50 74 72 3b 0a 0a 20 20 20 20 fsPathPtr;..
3880: 69 66 20 28 54 63 6c 5f 46 53 43 6f 6e 76 65 72 if (Tcl_FSConver
3890: 74 54 6f 50 61 74 68 54 79 70 65 28 4e 55 4c 4c tToPathType(NULL
38a0: 2c 20 70 61 74 68 50 74 72 29 20 21 3d 20 54 43 , pathPtr) != TC
38b0: 4c 5f 4f 4b 29 20 7b 0a 09 72 65 74 75 72 6e 20 L_OK) {..return
38c0: 54 63 6c 47 65 74 50 61 74 68 54 79 70 65 28 70 TclGetPathType(p
38d0: 61 74 68 50 74 72 2c 20 66 69 6c 65 73 79 73 74 athPtr, filesyst
38e0: 65 6d 50 74 72 50 74 72 2c 20 64 72 69 76 65 4e emPtrPtr, driveN
38f0: 61 6d 65 4c 65 6e 67 74 68 50 74 72 2c 0a 09 09 ameLengthPtr,...
3900: 4e 55 4c 4c 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 NULL);. }..
3910: 20 20 66 73 50 61 74 68 50 74 72 20 3d 20 50 41 fsPathPtr = PA
3920: 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b 0a THOBJ(pathPtr);.
3930: 20 20 20 20 69 66 20 28 66 73 50 61 74 68 50 74 if (fsPathPt
3940: 72 2d 3e 63 77 64 50 74 72 20 3d 3d 20 4e 55 4c r->cwdPtr == NUL
3950: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 54 63 6c L) {..return Tcl
3960: 47 65 74 50 61 74 68 54 79 70 65 28 70 61 74 68 GetPathType(path
3970: 50 74 72 2c 20 66 69 6c 65 73 79 73 74 65 6d 50 Ptr, filesystemP
3980: 74 72 50 74 72 2c 20 64 72 69 76 65 4e 61 6d 65 trPtr, driveName
3990: 4c 65 6e 67 74 68 50 74 72 2c 0a 09 09 4e 55 4c LengthPtr,...NUL
39a0: 4c 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 L);. }.. i
39b0: 66 20 28 50 41 54 48 46 4c 41 47 53 28 70 61 74 f (PATHFLAGS(pat
39c0: 68 50 74 72 29 20 3d 3d 20 30 29 20 7b 0a 09 2f hPtr) == 0) {../
39d0: 2a 20 54 68 65 20 70 61 74 68 20 69 73 20 6e 6f * The path is no
39e0: 74 20 61 62 73 6f 6c 75 74 65 2e 2e 2e 20 2a 2f t absolute... */
39f0: 0a 23 69 66 64 65 66 20 5f 57 49 4e 33 32 0a 09 .#ifdef _WIN32..
3a00: 2f 2a 20 2e 2e 2e 20 6f 6e 20 57 69 6e 64 6f 77 /* ... on Window
3a10: 73 20 77 65 20 6d 75 73 74 20 6d 61 6b 65 20 61 s we must make a
3a20: 6e 6f 74 68 65 72 20 63 61 6c 6c 20 74 6f 20 64 nother call to d
3a30: 65 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 etermine whether
3a40: 0a 09 20 2a 20 69 74 27 73 20 72 65 6c 61 74 69 .. * it's relati
3a50: 76 65 20 6f 72 20 76 6f 6c 75 6d 65 72 65 6c 61 ve or volumerela
3a60: 74 69 76 65 20 5b 42 75 67 20 32 35 37 31 35 39 tive [Bug 257159
3a70: 37 5d 2e 20 2a 2f 0a 09 72 65 74 75 72 6e 20 54 7]. */..return T
3a80: 63 6c 47 65 74 50 61 74 68 54 79 70 65 28 70 61 clGetPathType(pa
3a90: 74 68 50 74 72 2c 20 66 69 6c 65 73 79 73 74 65 thPtr, filesyste
3aa0: 6d 50 74 72 50 74 72 2c 20 64 72 69 76 65 4e 61 mPtrPtr, driveNa
3ab0: 6d 65 4c 65 6e 67 74 68 50 74 72 2c 0a 09 09 4e meLengthPtr,...N
3ac0: 55 4c 4c 29 3b 0a 23 65 6c 73 65 0a 09 2f 2a 20 ULL);.#else../*
3ad0: 4f 6e 20 6f 74 68 65 72 20 73 79 73 74 65 6d 73 On other systems
3ae0: 2c 20 71 75 69 63 6b 6c 79 20 64 65 64 75 63 65 , quickly deduce
3af0: 20 21 61 62 73 6f 6c 75 74 65 20 2d 3e 20 72 65 !absolute -> re
3b00: 6c 61 74 69 76 65 20 2a 2f 0a 09 72 65 74 75 72 lative */..retur
3b10: 6e 20 54 43 4c 5f 50 41 54 48 5f 52 45 4c 41 54 n TCL_PATH_RELAT
3b20: 49 56 45 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 IVE;.#endif.
3b30: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 54 63 6c }. return Tcl
3b40: 46 53 47 65 74 50 61 74 68 54 79 70 65 28 66 73 FSGetPathType(fs
3b50: 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 2c PathPtr->cwdPtr,
3b60: 20 66 69 6c 65 73 79 73 74 65 6d 50 74 72 50 74 filesystemPtrPt
3b70: 72 2c 0a 09 20 20 20 20 64 72 69 76 65 4e 61 6d r,.. driveNam
3b80: 65 4c 65 6e 67 74 68 50 74 72 29 3b 0a 7d 0a 0c eLengthPtr);.}..
3b90: 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ./*. *----------
3ba0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3bb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3bc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3bd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3be0: 2d 0a 20 2a 0a 20 2a 20 54 63 6c 50 61 74 68 50 -. *. * TclPathP
3bf0: 61 72 74 0a 20 2a 0a 20 2a 09 54 68 69 73 20 66 art. *. *.This f
3c00: 75 6e 63 74 69 6f 6e 20 63 61 6c 63 75 6c 61 74 unction calculat
3c10: 65 73 20 74 68 65 20 72 65 71 75 65 73 74 65 64 es the requested
3c20: 20 70 61 72 74 20 6f 66 20 74 68 65 20 67 69 76 part of the giv
3c30: 65 6e 20 70 61 74 68 2c 20 77 68 69 63 68 0a 20 en path, which.
3c40: 2a 09 63 61 6e 20 62 65 3a 0a 20 2a 0a 20 2a 09 *.can be:. *. *.
3c50: 2d 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20 - the directory
3c60: 61 62 6f 76 65 20 28 27 66 69 6c 65 20 64 69 72 above ('file dir
3c70: 6e 61 6d 65 27 29 0a 20 2a 09 2d 20 74 68 65 20 name'). *.- the
3c80: 74 61 69 6c 20 20 20 20 20 20 20 20 20 20 20 20 tail
3c90: 28 27 66 69 6c 65 20 74 61 69 6c 27 29 0a 20 2a ('file tail'). *
3ca0: 09 2d 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e .- the extension
3cb0: 20 20 20 20 20 20 20 28 27 66 69 6c 65 20 65 78 ('file ex
3cc0: 74 65 6e 73 69 6f 6e 27 29 0a 20 2a 09 2d 20 74 tension'). *.- t
3cd0: 68 65 20 72 6f 6f 74 20 20 20 20 20 20 20 20 20 he root
3ce0: 20 20 20 28 27 66 69 6c 65 20 72 6f 6f 74 27 29 ('file root')
3cf0: 0a 20 2a 0a 20 2a 09 54 68 65 20 27 70 6f 72 74 . *. *.The 'port
3d00: 69 6f 6e 27 20 70 61 72 61 6d 65 74 65 72 20 64 ion' parameter d
3d10: 69 63 74 61 74 65 73 20 77 68 69 63 68 20 6f 66 ictates which of
3d20: 20 74 68 65 73 65 20 74 6f 20 63 61 6c 63 75 6c these to calcul
3d30: 61 74 65 2e 20 54 68 65 72 65 0a 20 2a 09 61 72 ate. There. *.ar
3d40: 65 20 61 20 6e 75 6d 62 65 72 20 6f 66 20 73 70 e a number of sp
3d50: 65 63 69 61 6c 20 63 61 73 65 73 20 62 6f 74 68 ecial cases both
3d60: 20 74 6f 20 62 65 20 6d 6f 72 65 20 65 66 66 69 to be more effi
3d70: 63 69 65 6e 74 2c 20 61 6e 64 20 62 65 63 61 75 cient, and becau
3d80: 73 65 0a 20 2a 09 74 68 65 20 62 65 68 61 76 69 se. *.the behavi
3d90: 6f 75 72 20 77 68 65 6e 20 67 69 76 65 6e 20 61 our when given a
3da0: 20 70 61 74 68 20 77 69 74 68 20 6f 6e 6c 79 20 path with only
3db0: 61 20 73 69 6e 67 6c 65 20 65 6c 65 6d 65 6e 74 a single element
3dc0: 20 69 73 20 64 65 66 69 6e 65 64 0a 20 2a 09 74 is defined. *.t
3dd0: 6f 20 72 65 71 75 69 72 65 20 74 68 65 20 65 78 o require the ex
3de0: 70 61 6e 73 69 6f 6e 20 6f 66 20 74 68 61 74 20 pansion of that
3df0: 73 69 6e 67 6c 65 20 65 6c 65 6d 65 6e 74 2c 20 single element,
3e00: 77 68 65 72 65 20 70 6f 73 73 69 62 6c 65 2e 0a where possible..
3e10: 20 2a 0a 20 2a 09 53 68 6f 75 6c 64 20 6c 6f 6f *. *.Should loo
3e20: 6b 20 69 6e 74 6f 20 69 6e 74 65 67 72 61 74 69 k into integrati
3e30: 6e 67 20 27 46 69 6c 65 42 61 73 65 6e 61 6d 65 ng 'FileBasename
3e40: 27 20 69 6e 20 74 63 6c 46 43 6d 64 2e 63 20 69 ' in tclFCmd.c i
3e50: 6e 74 6f 20 74 68 69 73 0a 20 2a 09 66 75 6e 63 nto this. *.func
3e60: 74 69 6f 6e 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 tion.. *. * Resu
3e70: 6c 74 73 3a 0a 20 2a 09 4e 55 4c 4c 20 69 66 20 lts:. *.NULL if
3e80: 61 6e 20 65 72 72 6f 72 20 6f 63 63 75 72 72 65 an error occurre
3e90: 64 2c 20 6f 74 68 65 72 77 69 73 65 20 61 20 54 d, otherwise a T
3ea0: 63 6c 5f 4f 62 6a 20 6f 77 6e 65 64 20 62 79 20 cl_Obj owned by
3eb0: 74 68 65 20 63 61 6c 6c 65 72 0a 20 2a 09 28 69 the caller. *.(i
3ec0: 2e 65 2e 20 6d 6f 73 74 20 6c 69 6b 65 6c 79 20 .e. most likely
3ed0: 77 69 74 68 20 72 65 66 43 6f 75 6e 74 20 31 29 with refCount 1)
3ee0: 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 .. *. * Side eff
3ef0: 65 63 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 ects:. *.None..
3f00: 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *. *------------
3f10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3f20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3f30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3f40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
3f50: 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 */..Tcl_Obj *.T
3f60: 63 6c 50 61 74 68 50 61 72 74 28 0a 20 20 20 20 clPathPart(.
3f70: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
3f80: 72 70 2c 09 09 2f 2a 20 55 73 65 64 20 66 6f 72 rp,../* Used for
3f90: 20 65 72 72 6f 72 20 72 65 70 6f 72 74 69 6e 67 error reporting
3fa0: 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 */. Tcl_Obj
3fb0: 2a 70 61 74 68 50 74 72 2c 09 09 2f 2a 20 50 61 *pathPtr,../* Pa
3fc0: 74 68 20 74 6f 20 74 61 6b 65 20 64 69 72 6e 61 th to take dirna
3fd0: 6d 65 20 6f 66 20 2a 2f 0a 20 20 20 20 54 63 6c me of */. Tcl
3fe0: 5f 50 61 74 68 50 61 72 74 20 70 6f 72 74 69 6f _PathPart portio
3ff0: 6e 29 09 2f 2a 20 52 65 71 75 65 73 74 65 64 20 n)./* Requested
4000: 70 6f 72 74 69 6f 6e 20 6f 66 20 6e 61 6d 65 20 portion of name
4010: 2a 2f 0a 7b 0a 20 20 20 20 69 66 20 28 70 61 74 */.{. if (pat
4020: 68 50 74 72 2d 3e 74 79 70 65 50 74 72 20 3d 3d hPtr->typePtr ==
4030: 20 26 74 63 6c 46 73 50 61 74 68 54 79 70 65 29 &tclFsPathType)
4040: 20 7b 0a 09 46 73 50 61 74 68 20 2a 66 73 50 61 {..FsPath *fsPa
4050: 74 68 50 74 72 20 3d 20 50 41 54 48 4f 42 4a 28 thPtr = PATHOBJ(
4060: 70 61 74 68 50 74 72 29 3b 0a 0a 09 69 66 20 28 pathPtr);...if (
4070: 50 41 54 48 46 4c 41 47 53 28 70 61 74 68 50 74 PATHFLAGS(pathPt
4080: 72 29 20 21 3d 20 30 29 20 7b 0a 09 20 20 20 20 r) != 0) {..
4090: 73 77 69 74 63 68 20 28 70 6f 72 74 69 6f 6e 29 switch (portion)
40a0: 20 7b 0a 09 20 20 20 20 63 61 73 65 20 54 43 4c {.. case TCL
40b0: 5f 50 41 54 48 5f 44 49 52 4e 41 4d 45 3a 20 7b _PATH_DIRNAME: {
40c0: 0a 09 09 2f 2a 0a 09 09 20 2a 20 43 68 65 63 6b .../*... * Check
40d0: 20 69 66 20 74 68 65 20 6a 6f 69 6e 65 64 2d 6f if the joined-o
40e0: 6e 20 62 69 74 20 68 61 73 20 61 6e 79 20 64 69 n bit has any di
40f0: 72 65 63 74 6f 72 79 20 64 65 6c 69 6d 69 74 65 rectory delimite
4100: 72 73 20 69 6e 0a 09 09 20 2a 20 69 74 2e 20 49 rs in... * it. I
4110: 66 20 73 6f 2c 20 74 68 65 20 27 64 69 72 6e 61 f so, the 'dirna
4120: 6d 65 27 20 77 6f 75 6c 64 20 62 65 20 61 20 6a me' would be a j
4130: 6f 69 6e 69 6e 67 20 6f 66 20 74 68 65 20 6d 61 oining of the ma
4140: 69 6e 0a 09 09 20 2a 20 70 61 72 74 20 77 69 74 in... * part wit
4150: 68 20 74 68 65 20 64 69 72 6e 61 6d 65 20 6f 66 h the dirname of
4160: 20 74 68 65 20 6a 6f 69 6e 65 64 2d 6f 6e 20 62 the joined-on b
4170: 69 74 2e 20 57 65 20 63 6f 75 6c 64 20 68 61 6e it. We could han
4180: 64 6c 65 0a 09 09 20 2a 20 74 68 61 74 20 73 70 dle... * that sp
4190: 65 63 69 61 6c 20 63 61 73 65 20 68 65 72 65 2c ecial case here,
41a0: 20 62 75 74 20 77 65 20 64 6f 6e 27 74 2c 20 61 but we don't, a
41b0: 6e 64 20 69 6e 73 74 65 61 64 20 6a 75 73 74 20 nd instead just
41c0: 75 73 65 0a 09 09 20 2a 20 74 68 65 20 73 74 61 use... * the sta
41d0: 6e 64 61 72 64 50 61 74 68 20 63 6f 64 65 2e 0a ndardPath code..
41e0: 09 09 20 2a 2f 0a 0a 09 09 69 6e 74 20 6e 75 6d .. */....int num
41f0: 42 79 74 65 73 3b 0a 09 09 63 6f 6e 73 74 20 63 Bytes;...const c
4200: 68 61 72 20 2a 72 65 73 74 20 3d 0a 09 09 09 54 har *rest =....T
4210: 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d cl_GetStringFrom
4220: 4f 62 6a 28 66 73 50 61 74 68 50 74 72 2d 3e 6e Obj(fsPathPtr->n
4230: 6f 72 6d 50 61 74 68 50 74 72 2c 20 26 6e 75 6d ormPathPtr, &num
4240: 42 79 74 65 73 29 3b 0a 0a 09 09 69 66 20 28 73 Bytes);....if (s
4250: 74 72 63 68 72 28 72 65 73 74 2c 20 27 2f 27 29 trchr(rest, '/')
4260: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 20 20 != NULL) {...
4270: 20 20 67 6f 74 6f 20 73 74 61 6e 64 61 72 64 50 goto standardP
4280: 61 74 68 3b 0a 09 09 7d 0a 09 09 2f 2a 0a 09 09 ath;...}.../*...
4290: 20 2a 20 49 66 20 74 68 65 20 6a 6f 69 6e 65 64 * If the joined
42a0: 2d 6f 6e 20 62 69 74 20 69 73 20 65 6d 70 74 79 -on bit is empty
42b0: 2c 20 74 68 65 6e 20 5b 66 69 6c 65 20 64 69 72 , then [file dir
42c0: 6e 61 6d 65 5d 20 69 73 0a 09 09 20 2a 20 64 6f name] is... * do
42d0: 63 75 6d 65 6e 74 65 64 20 74 6f 20 72 65 74 75 cumented to retu
42e0: 72 6e 20 61 6c 6c 20 62 75 74 20 74 68 65 20 6c rn all but the l
42f0: 61 73 74 20 6e 6f 6e 2d 65 6d 70 74 79 20 65 6c ast non-empty el
4300: 65 6d 65 6e 74 0a 09 09 20 2a 20 6f 66 20 74 68 ement... * of th
4310: 65 20 70 61 74 68 2c 20 73 6f 20 77 65 20 6e 65 e path, so we ne
4320: 65 64 20 74 6f 20 73 70 6c 69 74 20 61 70 61 72 ed to split apar
4330: 74 20 74 68 65 20 6d 61 69 6e 20 70 61 72 74 20 t the main part
4340: 74 6f 0a 09 09 20 2a 20 67 65 74 20 74 68 65 20 to... * get the
4350: 72 69 67 68 74 20 61 6e 73 77 65 72 2e 20 20 57 right answer. W
4360: 65 20 63 6f 75 6c 64 20 64 6f 20 74 68 61 74 20 e could do that
4370: 68 65 72 65 2c 20 62 75 74 20 69 74 27 73 0a 09 here, but it's..
4380: 09 20 2a 20 73 69 6d 70 6c 65 72 20 74 6f 20 66 . * simpler to f
4390: 61 6c 6c 20 62 61 63 6b 20 74 6f 20 74 68 65 20 all back to the
43a0: 73 74 61 6e 64 61 72 64 50 61 74 68 20 63 6f 64 standardPath cod
43b0: 65 2e 0a 09 09 20 2a 20 5b 42 75 67 20 32 37 31 e.... * [Bug 271
43c0: 30 39 32 30 5d 0a 09 09 20 2a 2f 0a 09 09 69 66 0920]... */...if
43d0: 20 28 6e 75 6d 42 79 74 65 73 20 3d 3d 20 30 29 (numBytes == 0)
43e0: 20 7b 0a 09 09 20 20 20 20 67 6f 74 6f 20 73 74 {... goto st
43f0: 61 6e 64 61 72 64 50 61 74 68 3b 0a 09 09 7d 0a andardPath;...}.
4400: 09 09 69 66 20 28 74 63 6c 50 6c 61 74 66 6f 72 ..if (tclPlatfor
4410: 6d 20 3d 3d 20 54 43 4c 5f 50 4c 41 54 46 4f 52 m == TCL_PLATFOR
4420: 4d 5f 57 49 4e 44 4f 57 53 0a 09 09 09 26 26 20 M_WINDOWS....&&
4430: 73 74 72 63 68 72 28 72 65 73 74 2c 20 27 5c 5c strchr(rest, '\\
4440: 27 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 ') != NULL) {...
4450: 20 20 20 20 67 6f 74 6f 20 73 74 61 6e 64 61 72 goto standar
4460: 64 50 61 74 68 3b 0a 09 09 7d 0a 0a 09 09 2f 2a dPath;...}..../*
4470: 0a 09 09 20 2a 20 54 68 65 20 6a 6f 69 6e 65 64 ... * The joined
4480: 2d 6f 6e 20 70 61 74 68 20 69 73 20 73 69 6d 70 -on path is simp
4490: 6c 65 2c 20 73 6f 20 77 65 20 63 61 6e 20 6a 75 le, so we can ju
44a0: 73 74 20 72 65 74 75 72 6e 20 68 65 72 65 2e 0a st return here..
44b0: 09 09 20 2a 2f 0a 0a 09 09 54 63 6c 5f 49 6e 63 .. */....Tcl_Inc
44c0: 72 52 65 66 43 6f 75 6e 74 28 66 73 50 61 74 68 rRefCount(fsPath
44d0: 50 74 72 2d 3e 63 77 64 50 74 72 29 3b 0a 09 09 Ptr->cwdPtr);...
44e0: 72 65 74 75 72 6e 20 66 73 50 61 74 68 50 74 72 return fsPathPtr
44f0: 2d 3e 63 77 64 50 74 72 3b 0a 09 20 20 20 20 7d ->cwdPtr;.. }
4500: 0a 09 20 20 20 20 63 61 73 65 20 54 43 4c 5f 50 .. case TCL_P
4510: 41 54 48 5f 54 41 49 4c 3a 20 7b 0a 09 09 2f 2a ATH_TAIL: {.../*
4520: 0a 09 09 20 2a 20 43 68 65 63 6b 20 69 66 20 74 ... * Check if t
4530: 68 65 20 6a 6f 69 6e 65 64 2d 6f 6e 20 62 69 74 he joined-on bit
4540: 20 68 61 73 20 61 6e 79 20 64 69 72 65 63 74 6f has any directo
4550: 72 79 20 64 65 6c 69 6d 69 74 65 72 73 20 69 6e ry delimiters in
4560: 0a 09 09 20 2a 20 69 74 2e 20 49 66 20 73 6f 2c ... * it. If so,
4570: 20 74 68 65 20 27 74 61 69 6c 27 20 77 6f 75 6c the 'tail' woul
4580: 64 20 62 65 20 6f 6e 6c 79 20 74 68 65 20 70 61 d be only the pa
4590: 72 74 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 rt following the
45a0: 0a 09 09 20 2a 20 6c 61 73 74 20 64 65 6c 69 6d ... * last delim
45b0: 69 74 65 72 2e 20 57 65 20 63 6f 75 6c 64 20 68 iter. We could h
45c0: 61 6e 64 6c 65 20 74 68 61 74 20 73 70 65 63 69 andle that speci
45d0: 61 6c 20 63 61 73 65 20 68 65 72 65 2c 20 62 75 al case here, bu
45e0: 74 0a 09 09 20 2a 20 77 65 20 64 6f 6e 27 74 2c t... * we don't,
45f0: 20 61 6e 64 20 69 6e 73 74 65 61 64 20 6a 75 73 and instead jus
4600: 74 20 75 73 65 20 74 68 65 20 73 74 61 6e 64 61 t use the standa
4610: 72 64 50 61 74 68 20 63 6f 64 65 2e 0a 09 09 20 rdPath code....
4620: 2a 2f 0a 0a 09 09 69 6e 74 20 6e 75 6d 42 79 74 */....int numByt
4630: 65 73 3b 0a 09 09 63 6f 6e 73 74 20 63 68 61 72 es;...const char
4640: 20 2a 72 65 73 74 20 3d 0a 09 09 09 54 63 6c 5f *rest =....Tcl_
4650: 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a GetStringFromObj
4660: 28 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d (fsPathPtr->norm
4670: 50 61 74 68 50 74 72 2c 20 26 6e 75 6d 42 79 74 PathPtr, &numByt
4680: 65 73 29 3b 0a 0a 09 09 69 66 20 28 73 74 72 63 es);....if (strc
4690: 68 72 28 72 65 73 74 2c 20 27 2f 27 29 20 21 3d hr(rest, '/') !=
46a0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 20 20 20 20 67 NULL) {... g
46b0: 6f 74 6f 20 73 74 61 6e 64 61 72 64 50 61 74 68 oto standardPath
46c0: 3b 0a 09 09 7d 0a 09 09 2f 2a 0a 09 09 20 2a 20 ;...}.../*... *
46d0: 49 66 20 74 68 65 20 6a 6f 69 6e 65 64 2d 6f 6e If the joined-on
46e0: 20 62 69 74 20 69 73 20 65 6d 70 74 79 2c 20 74 bit is empty, t
46f0: 68 65 6e 20 5b 66 69 6c 65 20 74 61 69 6c 5d 20 hen [file tail]
4700: 69 73 0a 09 09 20 2a 20 64 6f 63 75 6d 65 6e 74 is... * document
4710: 65 64 20 74 6f 20 72 65 74 75 72 6e 20 74 68 65 ed to return the
4720: 20 6c 61 73 74 20 6e 6f 6e 2d 65 6d 70 74 79 20 last non-empty
4730: 65 6c 65 6d 65 6e 74 0a 09 09 20 2a 20 6f 66 20 element... * of
4740: 74 68 65 20 70 61 74 68 2c 20 73 6f 20 77 65 20 the path, so we
4750: 6e 65 65 64 20 74 6f 20 73 70 6c 69 74 20 6f 66 need to split of
4760: 66 20 74 68 65 20 6c 61 73 74 20 65 6c 65 6d 65 f the last eleme
4770: 6e 74 0a 09 09 20 2a 20 6f 66 20 74 68 65 20 6d nt... * of the m
4780: 61 69 6e 20 70 61 72 74 20 74 6f 20 67 65 74 20 ain part to get
4790: 74 68 65 20 72 69 67 68 74 20 61 6e 73 77 65 72 the right answer
47a0: 2e 20 20 57 65 20 63 6f 75 6c 64 20 64 6f 0a 09 . We could do..
47b0: 09 20 2a 20 74 68 61 74 20 68 65 72 65 2c 20 62 . * that here, b
47c0: 75 74 20 69 74 27 73 20 73 69 6d 70 6c 65 72 20 ut it's simpler
47d0: 74 6f 20 66 61 6c 6c 20 62 61 63 6b 20 74 6f 20 to fall back to
47e0: 74 68 65 0a 09 09 20 2a 20 73 74 61 6e 64 61 72 the... * standar
47f0: 64 50 61 74 68 20 63 6f 64 65 2e 20 20 5b 42 75 dPath code. [Bu
4800: 67 20 32 37 31 30 39 32 30 5d 0a 09 09 20 2a 2f g 2710920]... */
4810: 0a 09 09 69 66 20 28 6e 75 6d 42 79 74 65 73 20 ...if (numBytes
4820: 3d 3d 20 30 29 20 7b 0a 09 09 20 20 20 20 67 6f == 0) {... go
4830: 74 6f 20 73 74 61 6e 64 61 72 64 50 61 74 68 3b to standardPath;
4840: 0a 09 09 7d 0a 09 09 69 66 20 28 74 63 6c 50 6c ...}...if (tclPl
4850: 61 74 66 6f 72 6d 20 3d 3d 20 54 43 4c 5f 50 4c atform == TCL_PL
4860: 41 54 46 4f 52 4d 5f 57 49 4e 44 4f 57 53 0a 09 ATFORM_WINDOWS..
4870: 09 09 26 26 20 73 74 72 63 68 72 28 72 65 73 74 ..&& strchr(rest
4880: 2c 20 27 5c 5c 27 29 20 21 3d 20 4e 55 4c 4c 29 , '\\') != NULL)
4890: 20 7b 0a 09 09 20 20 20 20 67 6f 74 6f 20 73 74 {... goto st
48a0: 61 6e 64 61 72 64 50 61 74 68 3b 0a 09 09 7d 0a andardPath;...}.
48b0: 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 ..Tcl_IncrRefCou
48c0: 6e 74 28 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f nt(fsPathPtr->no
48d0: 72 6d 50 61 74 68 50 74 72 29 3b 0a 09 09 72 65 rmPathPtr);...re
48e0: 74 75 72 6e 20 66 73 50 61 74 68 50 74 72 2d 3e turn fsPathPtr->
48f0: 6e 6f 72 6d 50 61 74 68 50 74 72 3b 0a 09 20 20 normPathPtr;..
4900: 20 20 7d 0a 09 20 20 20 20 63 61 73 65 20 54 43 }.. case TC
4910: 4c 5f 50 41 54 48 5f 45 58 54 45 4e 53 49 4f 4e L_PATH_EXTENSION
4920: 3a 0a 09 09 72 65 74 75 72 6e 20 47 65 74 45 78 :...return GetEx
4930: 74 65 6e 73 69 6f 6e 28 66 73 50 61 74 68 50 74 tension(fsPathPt
4940: 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 29 3b r->normPathPtr);
4950: 0a 09 20 20 20 20 63 61 73 65 20 54 43 4c 5f 50 .. case TCL_P
4960: 41 54 48 5f 52 4f 4f 54 3a 20 7b 0a 09 09 63 6f ATH_ROOT: {...co
4970: 6e 73 74 20 63 68 61 72 20 2a 66 69 6c 65 4e 61 nst char *fileNa
4980: 6d 65 2c 20 2a 65 78 74 65 6e 73 69 6f 6e 3b 0a me, *extension;.
4990: 09 09 69 6e 74 20 6c 65 6e 67 74 68 3b 0a 0a 09 ..int length;...
49a0: 09 66 69 6c 65 4e 61 6d 65 20 3d 20 54 63 6c 5f .fileName = Tcl_
49b0: 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a GetStringFromObj
49c0: 28 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d (fsPathPtr->norm
49d0: 50 61 74 68 50 74 72 2c 0a 09 09 09 26 6c 65 6e PathPtr,....&len
49e0: 67 74 68 29 3b 0a 09 09 65 78 74 65 6e 73 69 6f gth);...extensio
49f0: 6e 20 3d 20 54 63 6c 47 65 74 45 78 74 65 6e 73 n = TclGetExtens
4a00: 69 6f 6e 28 66 69 6c 65 4e 61 6d 65 29 3b 0a 09 ion(fileName);..
4a10: 09 69 66 20 28 65 78 74 65 6e 73 69 6f 6e 20 3d .if (extension =
4a20: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 20 20 20 20 = NULL) {...
4a30: 2f 2a 0a 09 09 20 20 20 20 20 2a 20 54 68 65 72 /*... * Ther
4a40: 65 20 69 73 20 6e 6f 20 65 78 74 65 6e 73 69 6f e is no extensio
4a50: 6e 20 73 6f 20 74 68 65 20 72 6f 6f 74 20 69 73 n so the root is
4a60: 20 74 68 65 20 73 61 6d 65 20 61 73 20 74 68 65 the same as the
4a70: 0a 09 09 20 20 20 20 20 2a 20 70 61 74 68 20 77 ... * path w
4a80: 65 20 77 65 72 65 20 67 69 76 65 6e 2e 0a 09 09 e were given....
4a90: 20 20 20 20 20 2a 2f 0a 0a 09 09 20 20 20 20 54 */.... T
4aa0: 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 cl_IncrRefCount(
4ab0: 70 61 74 68 50 74 72 29 3b 0a 09 09 20 20 20 20 pathPtr);...
4ac0: 72 65 74 75 72 6e 20 70 61 74 68 50 74 72 3b 0a return pathPtr;.
4ad0: 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 20 20 20 ..} else {...
4ae0: 20 2f 2a 0a 09 09 20 20 20 20 20 2a 20 4e 65 65 /*... * Nee
4af0: 64 20 74 6f 20 72 65 74 75 72 6e 20 74 68 65 20 d to return the
4b00: 77 68 6f 6c 65 20 70 61 74 68 20 77 69 74 68 20 whole path with
4b10: 74 68 65 20 65 78 74 65 6e 73 69 6f 6e 0a 09 09 the extension...
4b20: 20 20 20 20 20 2a 20 73 75 66 66 69 78 20 72 65 * suffix re
4b30: 6d 6f 76 65 64 2e 20 20 44 6f 20 74 68 61 74 20 moved. Do that
4b40: 62 79 20 6a 6f 69 6e 69 6e 67 20 6f 75 72 20 22 by joining our "
4b50: 68 65 61 64 22 20 74 6f 0a 09 09 20 20 20 20 20 head" to...
4b60: 2a 20 6f 75 72 20 22 74 61 69 6c 22 20 77 69 74 * our "tail" wit
4b70: 68 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e 20 h the extension
4b80: 73 75 66 66 69 78 20 72 65 6d 6f 76 65 64 20 66 suffix removed f
4b90: 72 6f 6d 0a 09 09 20 20 20 20 20 2a 20 74 68 65 rom... * the
4ba0: 20 74 61 69 6c 2e 0a 09 09 20 20 20 20 20 2a 2f tail.... */
4bb0: 0a 0a 09 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 .... Tcl_Obj
4bc0: 2a 72 65 73 75 6c 74 50 74 72 20 3d 0a 09 09 09 *resultPtr =....
4bd0: 20 20 20 20 54 63 6c 4e 65 77 46 53 50 61 74 68 TclNewFSPath
4be0: 4f 62 6a 28 66 73 50 61 74 68 50 74 72 2d 3e 63 Obj(fsPathPtr->c
4bf0: 77 64 50 74 72 2c 20 66 69 6c 65 4e 61 6d 65 2c wdPtr, fileName,
4c00: 0a 09 09 09 20 20 20 20 28 69 6e 74 29 28 6c 65 .... (int)(le
4c10: 6e 67 74 68 20 2d 20 73 74 72 6c 65 6e 28 65 78 ngth - strlen(ex
4c20: 74 65 6e 73 69 6f 6e 29 29 29 3b 0a 0a 09 09 20 tension)));....
4c30: 20 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f Tcl_IncrRefCo
4c40: 75 6e 74 28 72 65 73 75 6c 74 50 74 72 29 3b 0a unt(resultPtr);.
4c50: 09 09 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 .. return res
4c60: 75 6c 74 50 74 72 3b 0a 09 09 7d 0a 09 20 20 20 ultPtr;...}..
4c70: 20 7d 0a 09 20 20 20 20 64 65 66 61 75 6c 74 3a }.. default:
4c80: 0a 09 09 2f 2a 20 57 65 20 73 68 6f 75 6c 64 20 .../* We should
4c90: 6e 65 76 65 72 20 67 65 74 20 68 65 72 65 20 2a never get here *
4ca0: 2f 0a 09 09 54 63 6c 5f 50 61 6e 69 63 28 22 42 /...Tcl_Panic("B
4cb0: 61 64 20 70 6f 72 74 69 6f 6e 20 74 6f 20 54 63 ad portion to Tc
4cc0: 6c 50 61 74 68 50 61 72 74 22 29 3b 0a 09 09 2f lPathPart");.../
4cd0: 2a 20 46 6f 72 20 6c 65 73 73 20 63 6c 65 76 65 * For less cleve
4ce0: 72 20 63 6f 6d 70 69 6c 65 72 73 20 2a 2f 0a 09 r compilers */..
4cf0: 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 09 20 .return NULL;..
4d00: 20 20 20 7d 0a 09 7d 20 65 6c 73 65 20 69 66 20 }..} else if
4d10: 28 66 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 (fsPathPtr->cwdP
4d20: 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 tr != NULL) {..
4d30: 20 20 20 2f 2a 20 52 65 6c 61 74 69 76 65 20 70 /* Relative p
4d40: 61 74 68 20 2a 2f 0a 09 20 20 20 20 67 6f 74 6f ath */.. goto
4d50: 20 73 74 61 6e 64 61 72 64 50 61 74 68 3b 0a 09 standardPath;..
4d60: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 2f 2a } else {.. /*
4d70: 20 41 62 73 6f 6c 75 74 65 20 70 61 74 68 20 2a Absolute path *
4d80: 2f 0a 09 20 20 20 20 67 6f 74 6f 20 73 74 61 6e /.. goto stan
4d90: 64 61 72 64 50 61 74 68 3b 0a 09 7d 0a 20 20 20 dardPath;..}.
4da0: 20 7d 20 65 6c 73 65 20 7b 0a 09 69 6e 74 20 73 } else {..int s
4db0: 70 6c 69 74 45 6c 65 6d 65 6e 74 73 3b 0a 09 54 plitElements;..T
4dc0: 63 6c 5f 4f 62 6a 20 2a 73 70 6c 69 74 50 74 72 cl_Obj *splitPtr
4dd0: 2c 20 2a 72 65 73 75 6c 74 50 74 72 3b 0a 0a 20 , *resultPtr;..
4de0: 20 20 20 73 74 61 6e 64 61 72 64 50 61 74 68 3a standardPath:
4df0: 0a 09 72 65 73 75 6c 74 50 74 72 20 3d 20 4e 55 ..resultPtr = NU
4e00: 4c 4c 3b 0a 09 69 66 20 28 70 6f 72 74 69 6f 6e LL;..if (portion
4e10: 20 3d 3d 20 54 43 4c 5f 50 41 54 48 5f 45 58 54 == TCL_PATH_EXT
4e20: 45 4e 53 49 4f 4e 29 20 7b 0a 09 20 20 20 20 72 ENSION) {.. r
4e30: 65 74 75 72 6e 20 47 65 74 45 78 74 65 6e 73 69 eturn GetExtensi
4e40: 6f 6e 28 70 61 74 68 50 74 72 29 3b 0a 09 7d 20 on(pathPtr);..}
4e50: 65 6c 73 65 20 69 66 20 28 70 6f 72 74 69 6f 6e else if (portion
4e60: 20 3d 3d 20 54 43 4c 5f 50 41 54 48 5f 52 4f 4f == TCL_PATH_ROO
4e70: 54 29 20 7b 0a 09 20 20 20 20 69 6e 74 20 6c 65 T) {.. int le
4e80: 6e 67 74 68 3b 0a 09 20 20 20 20 63 6f 6e 73 74 ngth;.. const
4e90: 20 63 68 61 72 20 2a 66 69 6c 65 4e 61 6d 65 2c char *fileName,
4ea0: 20 2a 65 78 74 65 6e 73 69 6f 6e 3b 0a 0a 09 20 *extension;...
4eb0: 20 20 20 66 69 6c 65 4e 61 6d 65 20 3d 20 54 63 fileName = Tc
4ec0: 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f l_GetStringFromO
4ed0: 62 6a 28 70 61 74 68 50 74 72 2c 20 26 6c 65 6e bj(pathPtr, &len
4ee0: 67 74 68 29 3b 0a 09 20 20 20 20 65 78 74 65 6e gth);.. exten
4ef0: 73 69 6f 6e 20 3d 20 54 63 6c 47 65 74 45 78 74 sion = TclGetExt
4f00: 65 6e 73 69 6f 6e 28 66 69 6c 65 4e 61 6d 65 29 ension(fileName)
4f10: 3b 0a 09 20 20 20 20 69 66 20 28 65 78 74 65 6e ;.. if (exten
4f20: 73 69 6f 6e 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a sion == NULL) {.
4f30: 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 ..Tcl_IncrRefCou
4f40: 6e 74 28 70 61 74 68 50 74 72 29 3b 0a 09 09 72 nt(pathPtr);...r
4f50: 65 74 75 72 6e 20 70 61 74 68 50 74 72 3b 0a 09 eturn pathPtr;..
4f60: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09 54 } else {...T
4f70: 63 6c 5f 4f 62 6a 20 2a 72 6f 6f 74 20 3d 20 54 cl_Obj *root = T
4f80: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
4f90: 66 69 6c 65 4e 61 6d 65 2c 0a 09 09 09 28 69 6e fileName,....(in
4fa0: 74 29 20 28 6c 65 6e 67 74 68 20 2d 20 73 74 72 t) (length - str
4fb0: 6c 65 6e 28 65 78 74 65 6e 73 69 6f 6e 29 29 29 len(extension)))
4fc0: 3b 0a 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 ;....Tcl_IncrRef
4fd0: 43 6f 75 6e 74 28 72 6f 6f 74 29 3b 0a 09 09 72 Count(root);...r
4fe0: 65 74 75 72 6e 20 72 6f 6f 74 3b 0a 09 20 20 20 eturn root;..
4ff0: 20 7d 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 54 }..}.../*.. * T
5000: 68 65 20 62 65 68 61 76 69 6f 75 72 20 77 65 20 he behaviour we
5010: 77 61 6e 74 20 68 65 72 65 20 69 73 20 73 6c 69 want here is sli
5020: 67 68 74 6c 79 20 64 69 66 66 65 72 65 6e 74 20 ghtly different
5030: 74 6f 20 74 68 65 20 73 74 61 6e 64 61 72 64 0a to the standard.
5040: 09 20 2a 20 54 63 6c 5f 46 53 53 70 6c 69 74 50 . * Tcl_FSSplitP
5050: 61 74 68 20 69 6e 20 74 68 65 20 68 61 6e 64 6c ath in the handl
5060: 69 6e 67 20 6f 66 20 68 6f 6d 65 20 64 69 72 65 ing of home dire
5070: 63 74 6f 72 69 65 73 3b 0a 09 20 2a 20 54 63 6c ctories;.. * Tcl
5080: 5f 46 53 53 70 6c 69 74 50 61 74 68 20 70 72 65 _FSSplitPath pre
5090: 73 65 72 76 65 73 20 74 68 65 20 22 7e 22 20 77 serves the "~" w
50a0: 68 69 6c 65 20 74 68 69 73 20 63 6f 64 65 20 63 hile this code c
50b0: 6f 6d 70 75 74 65 73 20 74 68 65 0a 09 20 2a 20 omputes the.. *
50c0: 61 63 74 75 61 6c 20 66 75 6c 6c 20 70 61 74 68 actual full path
50d0: 20 6e 61 6d 65 2c 20 69 66 20 77 65 20 68 61 64 name, if we had
50e0: 20 6a 75 73 74 20 61 20 73 69 6e 67 6c 65 20 63 just a single c
50f0: 6f 6d 70 6f 6e 65 6e 74 2e 0a 09 20 2a 2f 0a 0a omponent... */..
5100: 09 73 70 6c 69 74 50 74 72 20 3d 20 54 63 6c 5f .splitPtr = Tcl_
5110: 46 53 53 70 6c 69 74 50 61 74 68 28 70 61 74 68 FSSplitPath(path
5120: 50 74 72 2c 20 26 73 70 6c 69 74 45 6c 65 6d 65 Ptr, &splitEleme
5130: 6e 74 73 29 3b 0a 09 54 63 6c 5f 49 6e 63 72 52 nts);..Tcl_IncrR
5140: 65 66 43 6f 75 6e 74 28 73 70 6c 69 74 50 74 72 efCount(splitPtr
5150: 29 3b 0a 09 69 66 20 28 73 70 6c 69 74 45 6c 65 );..if (splitEle
5160: 6d 65 6e 74 73 20 3d 3d 20 31 20 20 26 26 20 20 ments == 1 &&
5170: 54 63 6c 47 65 74 53 74 72 69 6e 67 28 70 61 74 TclGetString(pat
5180: 68 50 74 72 29 5b 30 5d 20 3d 3d 20 27 7e 27 29 hPtr)[0] == '~')
5190: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 {.. Tcl_Obj
51a0: 2a 6e 6f 72 6d 3b 0a 0a 09 20 20 20 20 54 63 6c *norm;... Tcl
51b0: 44 65 63 72 52 65 66 43 6f 75 6e 74 28 73 70 6c DecrRefCount(spl
51c0: 69 74 50 74 72 29 3b 0a 09 20 20 20 20 6e 6f 72 itPtr);.. nor
51d0: 6d 20 3d 20 54 63 6c 5f 46 53 47 65 74 4e 6f 72 m = Tcl_FSGetNor
51e0: 6d 61 6c 69 7a 65 64 50 61 74 68 28 69 6e 74 65 malizedPath(inte
51f0: 72 70 2c 20 70 61 74 68 50 74 72 29 3b 0a 09 20 rp, pathPtr);..
5200: 20 20 20 69 66 20 28 6e 6f 72 6d 20 3d 3d 20 4e if (norm == N
5210: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 ULL) {...return
5220: 4e 55 4c 4c 3b 0a 09 20 20 20 20 7d 0a 09 20 20 NULL;.. }..
5230: 20 20 73 70 6c 69 74 50 74 72 20 3d 20 54 63 6c splitPtr = Tcl
5240: 5f 46 53 53 70 6c 69 74 50 61 74 68 28 6e 6f 72 _FSSplitPath(nor
5250: 6d 2c 20 26 73 70 6c 69 74 45 6c 65 6d 65 6e 74 m, &splitElement
5260: 73 29 3b 0a 09 20 20 20 20 54 63 6c 5f 49 6e 63 s);.. Tcl_Inc
5270: 72 52 65 66 43 6f 75 6e 74 28 73 70 6c 69 74 50 rRefCount(splitP
5280: 74 72 29 3b 0a 09 7d 0a 09 69 66 20 28 70 6f 72 tr);..}..if (por
5290: 74 69 6f 6e 20 3d 3d 20 54 43 4c 5f 50 41 54 48 tion == TCL_PATH
52a0: 5f 54 41 49 4c 29 20 7b 0a 09 20 20 20 20 2f 2a _TAIL) {.. /*
52b0: 0a 09 20 20 20 20 20 2a 20 52 65 74 75 72 6e 20 .. * Return
52c0: 74 68 65 20 6c 61 73 74 20 63 6f 6d 70 6f 6e 65 the last compone
52d0: 6e 74 2c 20 75 6e 6c 65 73 73 20 69 74 20 69 73 nt, unless it is
52e0: 20 74 68 65 20 6f 6e 6c 79 20 63 6f 6d 70 6f 6e the only compon
52f0: 65 6e 74 2c 20 61 6e 64 0a 09 20 20 20 20 20 2a ent, and.. *
5300: 20 69 74 20 69 73 20 74 68 65 20 72 6f 6f 74 20 it is the root
5310: 6f 66 20 61 6e 20 61 62 73 6f 6c 75 74 65 20 70 of an absolute p
5320: 61 74 68 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 ath... */...
5330: 20 20 20 20 69 66 20 28 28 73 70 6c 69 74 45 6c if ((splitEl
5340: 65 6d 65 6e 74 73 20 3e 20 30 29 20 26 26 20 28 ements > 0) && (
5350: 28 73 70 6c 69 74 45 6c 65 6d 65 6e 74 73 20 3e (splitElements >
5360: 20 31 29 20 7c 7c 0a 09 09 20 20 20 20 28 54 63 1) ||... (Tc
5370: 6c 5f 46 53 47 65 74 50 61 74 68 54 79 70 65 28 l_FSGetPathType(
5380: 70 61 74 68 50 74 72 29 20 3d 3d 20 54 43 4c 5f pathPtr) == TCL_
5390: 50 41 54 48 5f 52 45 4c 41 54 49 56 45 29 29 29 PATH_RELATIVE)))
53a0: 20 7b 0a 09 09 54 63 6c 5f 4c 69 73 74 4f 62 6a {...Tcl_ListObj
53b0: 49 6e 64 65 78 28 4e 55 4c 4c 2c 20 73 70 6c 69 Index(NULL, spli
53c0: 74 50 74 72 2c 20 73 70 6c 69 74 45 6c 65 6d 65 tPtr, splitEleme
53d0: 6e 74 73 2d 31 2c 20 26 72 65 73 75 6c 74 50 74 nts-1, &resultPt
53e0: 72 29 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 r);.. } else
53f0: 7b 0a 09 09 72 65 73 75 6c 74 50 74 72 20 3d 20 {...resultPtr =
5400: 54 63 6c 5f 4e 65 77 4f 62 6a 28 29 3b 0a 09 20 Tcl_NewObj();..
5410: 20 20 20 7d 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 }..} else {..
5420: 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 52 /*.. * R
5430: 65 74 75 72 6e 20 61 6c 6c 20 62 75 74 20 74 68 eturn all but th
5440: 65 20 6c 61 73 74 20 63 6f 6d 70 6f 6e 65 6e 74 e last component
5450: 2e 20 49 66 20 74 68 65 72 65 20 69 73 20 6f 6e . If there is on
5460: 6c 79 20 6f 6e 65 0a 09 20 20 20 20 20 2a 20 63 ly one.. * c
5470: 6f 6d 70 6f 6e 65 6e 74 2c 20 72 65 74 75 72 6e omponent, return
5480: 20 69 74 20 69 66 20 74 68 65 20 70 61 74 68 20 it if the path
5490: 77 61 73 20 6e 6f 6e 2d 72 65 6c 61 74 69 76 65 was non-relative
54a0: 2c 20 6f 74 68 65 72 77 69 73 65 0a 09 20 20 20 , otherwise..
54b0: 20 20 2a 20 72 65 74 75 72 6e 20 74 68 65 20 63 * return the c
54c0: 75 72 72 65 6e 74 20 64 69 72 65 63 74 6f 72 79 urrent directory
54d0: 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 ... */...
54e0: 20 69 66 20 28 73 70 6c 69 74 45 6c 65 6d 65 6e if (splitElemen
54f0: 74 73 20 3e 20 31 29 20 7b 0a 09 09 72 65 73 75 ts > 1) {...resu
5500: 6c 74 50 74 72 20 3d 20 54 63 6c 5f 46 53 4a 6f ltPtr = Tcl_FSJo
5510: 69 6e 50 61 74 68 28 73 70 6c 69 74 50 74 72 2c inPath(splitPtr,
5520: 20 73 70 6c 69 74 45 6c 65 6d 65 6e 74 73 20 2d splitElements -
5530: 20 31 29 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 1);.. } else
5540: 20 69 66 20 28 73 70 6c 69 74 45 6c 65 6d 65 6e if (splitElemen
5550: 74 73 20 3d 3d 20 30 20 7c 7c 0a 09 09 20 20 20 ts == 0 ||...
5560: 20 28 54 63 6c 5f 46 53 47 65 74 50 61 74 68 54 (Tcl_FSGetPathT
5570: 79 70 65 28 70 61 74 68 50 74 72 29 20 3d 3d 20 ype(pathPtr) ==
5580: 54 43 4c 5f 50 41 54 48 5f 52 45 4c 41 54 49 56 TCL_PATH_RELATIV
5590: 45 29 29 20 7b 0a 09 09 54 63 6c 4e 65 77 4c 69 E)) {...TclNewLi
55a0: 74 65 72 61 6c 53 74 72 69 6e 67 4f 62 6a 28 72 teralStringObj(r
55b0: 65 73 75 6c 74 50 74 72 2c 20 22 2e 22 29 3b 0a esultPtr, ".");.
55c0: 09 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09 . } else {...
55d0: 54 63 6c 5f 4c 69 73 74 4f 62 6a 49 6e 64 65 78 Tcl_ListObjIndex
55e0: 28 4e 55 4c 4c 2c 20 73 70 6c 69 74 50 74 72 2c (NULL, splitPtr,
55f0: 20 30 2c 20 26 72 65 73 75 6c 74 50 74 72 29 3b 0, &resultPtr);
5600: 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 54 63 6c 5f .. }..}..Tcl_
5610: 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 72 65 73 IncrRefCount(res
5620: 75 6c 74 50 74 72 29 3b 0a 09 54 63 6c 44 65 63 ultPtr);..TclDec
5630: 72 52 65 66 43 6f 75 6e 74 28 73 70 6c 69 74 50 rRefCount(splitP
5640: 74 72 29 3b 0a 09 72 65 74 75 72 6e 20 72 65 73 tr);..return res
5650: 75 6c 74 50 74 72 3b 0a 20 20 20 20 7d 0a 7d 0a ultPtr;. }.}.
5660: 0c 0a 2f 2a 0a 20 2a 20 53 69 6d 70 6c 65 20 68 ../*. * Simple h
5670: 65 6c 70 65 72 20 66 75 6e 63 74 69 6f 6e 0a 20 elper function.
5680: 2a 2f 0a 0a 73 74 61 74 69 63 20 54 63 6c 5f 4f */..static Tcl_O
5690: 62 6a 20 2a 0a 47 65 74 45 78 74 65 6e 73 69 6f bj *.GetExtensio
56a0: 6e 28 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a n(. Tcl_Obj *
56b0: 70 61 74 68 50 74 72 29 0a 7b 0a 20 20 20 20 63 pathPtr).{. c
56c0: 6f 6e 73 74 20 63 68 61 72 20 2a 74 61 69 6c 2c onst char *tail,
56d0: 20 2a 65 78 74 65 6e 73 69 6f 6e 3b 0a 20 20 20 *extension;.
56e0: 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 74 3b 0a 0a Tcl_Obj *ret;..
56f0: 20 20 20 20 74 61 69 6c 20 3d 20 54 63 6c 47 65 tail = TclGe
5700: 74 53 74 72 69 6e 67 28 70 61 74 68 50 74 72 29 tString(pathPtr)
5710: 3b 0a 20 20 20 20 65 78 74 65 6e 73 69 6f 6e 20 ;. extension
5720: 3d 20 54 63 6c 47 65 74 45 78 74 65 6e 73 69 6f = TclGetExtensio
5730: 6e 28 74 61 69 6c 29 3b 0a 20 20 20 20 69 66 20 n(tail);. if
5740: 28 65 78 74 65 6e 73 69 6f 6e 20 3d 3d 20 4e 55 (extension == NU
5750: 4c 4c 29 20 7b 0a 09 72 65 74 20 3d 20 54 63 6c LL) {..ret = Tcl
5760: 5f 4e 65 77 4f 62 6a 28 29 3b 0a 20 20 20 20 7d _NewObj();. }
5770: 20 65 6c 73 65 20 7b 0a 09 72 65 74 20 3d 20 54 else {..ret = T
5780: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
5790: 65 78 74 65 6e 73 69 6f 6e 2c 20 2d 31 29 3b 0a extension, -1);.
57a0: 20 20 20 20 7d 0a 20 20 20 20 54 63 6c 5f 49 6e }. Tcl_In
57b0: 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 29 3b crRefCount(ret);
57c0: 0a 20 20 20 20 72 65 74 75 72 6e 20 72 65 74 3b . return ret;
57d0: 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d .}.../*. *------
57e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
57f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5820: 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63 6c 5f -----. *. * Tcl_
5830: 46 53 4a 6f 69 6e 50 61 74 68 20 2d 2d 0a 20 2a FSJoinPath --. *
5840: 0a 20 2a 09 54 68 69 73 20 66 75 6e 63 74 69 6f . *.This functio
5850: 6e 20 74 61 6b 65 73 20 74 68 65 20 67 69 76 65 n takes the give
5860: 6e 20 54 63 6c 5f 4f 62 6a 2c 20 77 68 69 63 68 n Tcl_Obj, which
5870: 20 73 68 6f 75 6c 64 20 62 65 20 61 20 76 61 6c should be a val
5880: 69 64 20 6c 69 73 74 2c 0a 20 2a 09 61 6e 64 20 id list,. *.and
5890: 72 65 74 75 72 6e 73 20 74 68 65 20 70 61 74 68 returns the path
58a0: 20 6f 62 6a 65 63 74 20 67 69 76 65 6e 20 62 79 object given by
58b0: 20 63 6f 6e 73 69 64 65 72 69 6e 67 20 74 68 65 considering the
58c0: 20 66 69 72 73 74 20 27 65 6c 65 6d 65 6e 74 73 first 'elements
58d0: 27 0a 20 2a 09 65 6c 65 6d 65 6e 74 73 20 61 73 '. *.elements as
58e0: 20 76 61 6c 69 64 20 70 61 74 68 20 73 65 67 6d valid path segm
58f0: 65 6e 74 73 20 28 65 61 63 68 20 70 61 74 68 20 ents (each path
5900: 73 65 67 6d 65 6e 74 20 6d 61 79 20 62 65 20 61 segment may be a
5910: 20 63 6f 6d 70 6c 65 74 65 0a 20 2a 09 70 61 74 complete. *.pat
5920: 68 2c 20 61 20 70 61 72 74 69 61 6c 20 70 61 74 h, a partial pat
5930: 68 20 6f 72 20 6a 75 73 74 20 61 20 73 69 6e 67 h or just a sing
5940: 6c 65 20 70 6f 73 73 69 62 6c 65 20 64 69 72 65 le possible dire
5950: 63 74 6f 72 79 20 6f 72 20 66 69 6c 65 0a 20 2a ctory or file. *
5960: 09 6e 61 6d 65 29 2e 20 49 66 20 61 6e 79 20 70 .name). If any p
5970: 61 74 68 20 73 65 67 6d 65 6e 74 20 69 73 20 61 ath segment is a
5980: 63 74 75 61 6c 6c 79 20 61 6e 20 61 62 73 6f 6c ctually an absol
5990: 75 74 65 20 70 61 74 68 2c 20 74 68 65 6e 20 61 ute path, then a
59a0: 6c 6c 0a 20 2a 09 70 72 69 6f 72 20 70 61 74 68 ll. *.prior path
59b0: 20 73 65 67 6d 65 6e 74 73 20 61 72 65 20 64 69 segments are di
59c0: 73 63 61 72 64 65 64 2e 0a 20 2a 0a 20 2a 09 49 scarded.. *. *.I
59d0: 66 20 65 6c 65 6d 65 6e 74 73 20 3c 20 30 2c 20 f elements < 0,
59e0: 77 65 20 75 73 65 20 74 68 65 20 65 6e 74 69 72 we use the entir
59f0: 65 20 6c 69 73 74 20 74 68 61 74 20 77 61 73 20 e list that was
5a00: 67 69 76 65 6e 2e 0a 20 2a 0a 20 2a 09 49 74 20 given.. *. *.It
5a10: 69 73 20 70 6f 73 73 69 62 6c 65 20 74 68 61 74 is possible that
5a20: 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 6f 62 the returned ob
5a30: 6a 65 63 74 20 69 73 20 61 63 74 75 61 6c 6c 79 ject is actually
5a40: 20 61 6e 20 65 6c 65 6d 65 6e 74 20 6f 66 20 74 an element of t
5a50: 68 65 0a 20 2a 09 67 69 76 65 6e 20 6c 69 73 74 he. *.given list
5a60: 2c 20 73 6f 20 74 68 65 20 63 61 6c 6c 65 72 20 , so the caller
5a70: 73 68 6f 75 6c 64 20 62 65 20 63 61 72 65 66 75 should be carefu
5a80: 6c 20 74 6f 20 73 74 6f 72 65 20 61 20 72 65 66 l to store a ref
5a90: 43 6f 75 6e 74 20 74 6f 20 69 74 0a 20 2a 09 62 Count to it. *.b
5aa0: 65 66 6f 72 65 20 66 72 65 65 69 6e 67 20 74 68 efore freeing th
5ab0: 65 20 6c 69 73 74 2e 0a 20 2a 0a 20 2a 20 52 65 e list.. *. * Re
5ac0: 73 75 6c 74 73 3a 0a 20 2a 09 52 65 74 75 72 6e sults:. *.Return
5ad0: 73 20 6f 62 6a 65 63 74 20 77 69 74 68 20 72 65 s object with re
5ae0: 66 43 6f 75 6e 74 20 6f 66 20 7a 65 72 6f 2c 20 fCount of zero,
5af0: 28 6f 72 20 69 66 20 6e 6f 6e 2d 7a 65 72 6f 2c (or if non-zero,
5b00: 20 69 74 20 68 61 73 0a 20 2a 09 72 65 66 65 72 it has. *.refer
5b10: 65 6e 63 65 73 20 65 6c 73 65 77 68 65 72 65 20 ences elsewhere
5b20: 69 6e 20 54 63 6c 29 2e 20 45 69 74 68 65 72 20 in Tcl). Either
5b30: 77 61 79 2c 20 74 68 65 20 63 61 6c 6c 65 72 20 way, the caller
5b40: 6d 75 73 74 20 69 6e 63 72 65 6d 65 6e 74 0a 20 must increment.
5b50: 2a 09 69 74 73 20 72 65 66 43 6f 75 6e 74 20 62 *.its refCount b
5b60: 65 66 6f 72 65 20 75 73 65 2e 20 4e 6f 74 65 20 efore use. Note
5b70: 74 68 61 74 20 69 6e 20 74 68 65 20 63 61 73 65 that in the case
5b80: 20 77 68 65 72 65 20 74 68 65 20 63 61 6c 6c 65 where the calle
5b90: 72 20 68 61 73 0a 20 2a 09 61 73 6b 65 64 20 74 r has. *.asked t
5ba0: 6f 20 6a 6f 69 6e 20 7a 65 72 6f 20 65 6c 65 6d o join zero elem
5bb0: 65 6e 74 73 20 6f 66 20 74 68 65 20 6c 69 73 74 ents of the list
5bc0: 2c 20 74 68 65 20 72 65 74 75 72 6e 20 76 61 6c , the return val
5bd0: 75 65 20 77 69 6c 6c 20 62 65 20 61 6e 0a 20 2a ue will be an. *
5be0: 09 65 6d 70 74 79 2d 73 74 72 69 6e 67 20 54 63 .empty-string Tc
5bf0: 6c 5f 4f 62 6a 2e 0a 20 2a 0a 20 2a 09 49 66 20 l_Obj.. *. *.If
5c00: 74 68 65 20 67 69 76 65 6e 20 6c 69 73 74 4f 62 the given listOb
5c10: 6a 20 77 61 73 20 69 6e 76 61 6c 69 64 2c 20 74 j was invalid, t
5c20: 68 65 6e 20 74 68 65 20 63 61 6c 6c 69 6e 67 20 hen the calling
5c30: 72 6f 75 74 69 6e 65 20 68 61 73 20 61 20 62 75 routine has a bu
5c40: 67 2c 0a 20 2a 09 61 6e 64 20 74 68 69 73 20 66 g,. *.and this f
5c50: 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 6a 75 73 unction will jus
5c60: 74 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 0a 20 t return NULL..
5c70: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 *. * Side effect
5c80: 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 s:. *.None.. *.
5c90: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *---------------
5ca0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5cb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5cc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5cd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f ------------. */
5ce0: 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 5f ..Tcl_Obj *.Tcl_
5cf0: 46 53 4a 6f 69 6e 50 61 74 68 28 0a 20 20 20 20 FSJoinPath(.
5d00: 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 4f 62 6a Tcl_Obj *listObj
5d10: 2c 09 09 2f 2a 20 50 61 74 68 20 65 6c 65 6d 65 ,../* Path eleme
5d20: 6e 74 73 20 74 6f 20 6a 6f 69 6e 2c 20 6d 61 79 nts to join, may
5d30: 20 68 61 76 65 20 61 20 7a 65 72 6f 0a 09 09 09 have a zero....
5d40: 09 20 2a 20 72 65 66 65 72 65 6e 63 65 20 63 6f . * reference co
5d50: 75 6e 74 2e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 unt. */. int
5d60: 65 6c 65 6d 65 6e 74 73 29 09 09 2f 2a 20 4e 75 elements)../* Nu
5d70: 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 6e 74 73 mber of elements
5d80: 20 74 6f 20 75 73 65 20 28 2d 31 20 3d 20 61 6c to use (-1 = al
5d90: 6c 29 20 2a 2f 0a 7b 0a 20 20 20 20 54 63 6c 5f l) */.{. Tcl_
5da0: 4f 62 6a 20 2a 72 65 73 3b 0a 20 20 20 20 69 6e Obj *res;. in
5db0: 74 20 6f 62 6a 63 3b 0a 20 20 20 20 54 63 6c 5f t objc;. Tcl_
5dc0: 4f 62 6a 20 2a 2a 6f 62 6a 76 3b 0a 0a 20 20 20 Obj **objv;..
5dd0: 20 69 66 20 28 54 63 6c 5f 4c 69 73 74 4f 62 6a if (Tcl_ListObj
5de0: 4c 65 6e 67 74 68 28 4e 55 4c 4c 2c 20 6c 69 73 Length(NULL, lis
5df0: 74 4f 62 6a 2c 20 26 6f 62 6a 63 29 20 21 3d 20 tObj, &objc) !=
5e00: 54 43 4c 5f 4f 4b 29 20 7b 0a 09 72 65 74 75 72 TCL_OK) {..retur
5e10: 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 n NULL;. }..
5e20: 20 20 20 65 6c 65 6d 65 6e 74 73 20 3d 20 28 28 elements = ((
5e30: 65 6c 65 6d 65 6e 74 73 20 3e 3d 20 30 29 20 26 elements >= 0) &
5e40: 26 20 28 65 6c 65 6d 65 6e 74 73 20 3c 3d 20 6f & (elements <= o
5e50: 62 6a 63 29 29 20 3f 20 65 6c 65 6d 65 6e 74 73 bjc)) ? elements
5e60: 20 3a 20 6f 62 6a 63 3b 0a 20 20 20 20 54 63 6c : objc;. Tcl
5e70: 5f 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 6d 65 _ListObjGetEleme
5e80: 6e 74 73 28 4e 55 4c 4c 2c 20 6c 69 73 74 4f 62 nts(NULL, listOb
5e90: 6a 2c 20 26 6f 62 6a 63 2c 20 26 6f 62 6a 76 29 j, &objc, &objv)
5ea0: 3b 0a 20 20 20 20 72 65 73 20 3d 20 54 63 6c 4a ;. res = TclJ
5eb0: 6f 69 6e 50 61 74 68 28 65 6c 65 6d 65 6e 74 73 oinPath(elements
5ec0: 2c 20 6f 62 6a 76 2c 20 30 29 3b 0a 20 20 20 20 , objv, 0);.
5ed0: 72 65 74 75 72 6e 20 72 65 73 3b 0a 7d 0a 0a 54 return res;.}..T
5ee0: 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 4a 6f 69 6e cl_Obj *.TclJoin
5ef0: 50 61 74 68 28 0a 20 20 20 20 69 6e 74 20 65 6c Path(. int el
5f00: 65 6d 65 6e 74 73 2c 09 09 2f 2a 20 4e 75 6d 62 ements,../* Numb
5f10: 65 72 20 6f 66 20 65 6c 65 6d 65 6e 74 73 20 74 er of elements t
5f20: 6f 20 75 73 65 20 28 2d 31 20 3d 20 61 6c 6c 29 o use (-1 = all)
5f30: 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 */. Tcl_Obj
5f40: 2a 20 63 6f 6e 73 74 20 6f 62 6a 76 5b 5d 2c 09 * const objv[],.
5f50: 2f 2a 20 50 61 74 68 20 65 6c 65 6d 65 6e 74 73 /* Path elements
5f60: 20 74 6f 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 20 to join */.
5f70: 69 6e 74 20 66 6f 72 63 65 52 65 6c 61 74 69 76 int forceRelativ
5f80: 65 29 09 09 2f 2a 20 49 66 20 6e 6f 6e 2d 7a 65 e)../* If non-ze
5f90: 72 6f 2c 20 61 73 73 75 6d 65 20 61 6c 6c 20 6d ro, assume all m
5fa0: 6f 72 65 20 70 61 74 68 73 20 61 72 65 0a 09 09 ore paths are...
5fb0: 09 09 20 2a 20 72 65 6c 61 74 69 76 65 20 28 65 .. * relative (e
5fc0: 2e 20 67 2e 20 73 69 6d 70 6c 65 20 6e 6f 72 6d . g. simple norm
5fd0: 61 6c 69 7a 61 74 69 6f 6e 29 20 2a 2f 0a 7b 0a alization) */.{.
5fe0: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 73 Tcl_Obj *res
5ff0: 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 69 6e 74 = NULL;. int
6000: 20 69 3b 0a 20 20 20 20 63 6f 6e 73 74 20 54 63 i;. const Tc
6010: 6c 5f 46 69 6c 65 73 79 73 74 65 6d 20 2a 66 73 l_Filesystem *fs
6020: 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 0a 20 20 20 Ptr = NULL;..
6030: 20 61 73 73 65 72 74 20 28 20 65 6c 65 6d 65 6e assert ( elemen
6040: 74 73 20 3e 3d 20 30 20 29 3b 0a 0a 20 20 20 20 ts >= 0 );..
6050: 69 66 20 28 65 6c 65 6d 65 6e 74 73 20 3d 3d 20 if (elements ==
6060: 30 29 20 7b 0a 09 72 65 74 75 72 6e 20 54 63 6c 0) {..return Tcl
6070: 5f 4e 65 77 4f 62 6a 28 29 3b 0a 20 20 20 20 7d _NewObj();. }
6080: 0a 0a 20 20 20 20 61 73 73 65 72 74 20 28 20 65 .. assert ( e
6090: 6c 65 6d 65 6e 74 73 20 3e 20 30 20 29 3b 0a 0a lements > 0 );..
60a0: 20 20 20 20 69 66 20 28 65 6c 65 6d 65 6e 74 73 if (elements
60b0: 20 3d 3d 20 32 29 20 7b 0a 09 54 63 6c 5f 4f 62 == 2) {..Tcl_Ob
60c0: 6a 20 2a 65 6c 74 20 3d 20 6f 62 6a 76 5b 30 5d j *elt = objv[0]
60d0: 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 54 68 69 73 20 ;.../*.. * This
60e0: 69 73 20 61 20 73 70 65 63 69 61 6c 20 63 61 73 is a special cas
60f0: 65 20 77 68 65 72 65 20 77 65 20 63 61 6e 20 62 e where we can b
6100: 65 20 6d 75 63 68 20 6d 6f 72 65 20 65 66 66 69 e much more effi
6110: 63 69 65 6e 74 2c 20 77 68 65 72 65 0a 09 20 2a cient, where.. *
6120: 20 77 65 20 61 72 65 20 6a 6f 69 6e 69 6e 67 20 we are joining
6130: 61 20 73 69 6e 67 6c 65 20 72 65 6c 61 74 69 76 a single relativ
6140: 65 20 70 61 74 68 20 6f 6e 74 6f 20 61 6e 20 6f e path onto an o
6150: 62 6a 65 63 74 20 74 68 61 74 20 69 73 0a 09 20 bject that is..
6160: 2a 20 61 6c 72 65 61 64 79 20 6f 66 20 70 61 74 * already of pat
6170: 68 20 74 79 70 65 2e 20 54 68 65 20 27 54 63 6c h type. The 'Tcl
6180: 4e 65 77 46 53 50 61 74 68 4f 62 6a 27 20 63 61 NewFSPathObj' ca
6190: 6c 6c 20 62 65 6c 6f 77 20 63 72 65 61 74 65 73 ll below creates
61a0: 20 61 6e 0a 09 20 2a 20 6f 62 6a 65 63 74 20 77 an.. * object w
61b0: 68 69 63 68 20 63 61 6e 20 62 65 20 6e 6f 72 6d hich can be norm
61c0: 61 6c 69 7a 65 64 20 6d 6f 72 65 20 65 66 66 69 alized more effi
61d0: 63 69 65 6e 74 6c 79 2e 20 43 75 72 72 65 6e 74 ciently. Current
61e0: 6c 79 20 77 65 20 6f 6e 6c 79 0a 09 20 2a 20 75 ly we only.. * u
61f0: 73 65 20 74 68 65 20 73 70 65 63 69 61 6c 20 63 se the special c
6200: 61 73 65 20 77 68 65 6e 20 77 65 20 68 61 76 65 ase when we have
6210: 20 65 78 61 63 74 6c 79 20 74 77 6f 20 65 6c 65 exactly two ele
6220: 6d 65 6e 74 73 2c 20 62 75 74 20 77 65 0a 09 20 ments, but we..
6230: 2a 20 63 6f 75 6c 64 20 65 78 70 61 6e 64 20 74 * could expand t
6240: 68 61 74 20 69 6e 20 74 68 65 20 66 75 74 75 72 hat in the futur
6250: 65 2e 0a 09 20 2a 0a 09 20 2a 20 42 75 67 66 69 e... *.. * Bugfi
6260: 78 20 5b 61 34 37 36 34 31 61 30 5d 2e 20 54 63 x [a47641a0]. Tc
6270: 6c 4e 65 77 46 53 50 61 74 68 4f 62 6a 20 72 65 lNewFSPathObj re
6280: 71 75 69 72 65 73 20 66 69 72 73 74 20 61 72 67 quires first arg
6290: 75 6d 65 6e 74 0a 09 20 2a 20 74 6f 20 62 65 20 ument.. * to be
62a0: 61 6e 20 61 62 73 6f 6c 75 74 65 20 70 61 74 68 an absolute path
62b0: 2e 20 41 64 64 65 64 20 61 20 63 68 65 63 6b 20 . Added a check
62c0: 66 6f 72 20 74 68 61 74 20 65 6c 74 20 69 73 20 for that elt is
62d0: 61 62 73 6f 6c 75 74 65 2e 0a 09 20 2a 2f 0a 0a absolute... */..
62e0: 09 69 66 20 28 28 65 6c 74 2d 3e 74 79 70 65 50 .if ((elt->typeP
62f0: 74 72 20 3d 3d 20 26 74 63 6c 46 73 50 61 74 68 tr == &tclFsPath
6300: 54 79 70 65 29 0a 09 09 26 26 20 21 28 28 65 6c Type)...&& !((el
6310: 74 2d 3e 62 79 74 65 73 20 21 3d 20 4e 55 4c 4c t->bytes != NULL
6320: 29 20 26 26 20 28 65 6c 74 2d 3e 62 79 74 65 73 ) && (elt->bytes
6330: 5b 30 5d 20 3d 3d 20 27 5c 30 27 29 29 0a 09 09 [0] == '\0'))...
6340: 26 26 20 54 63 6c 47 65 74 50 61 74 68 54 79 70 && TclGetPathTyp
6350: 65 28 65 6c 74 2c 20 4e 55 4c 4c 2c 20 4e 55 4c e(elt, NULL, NUL
6360: 4c 2c 20 4e 55 4c 4c 29 20 3d 3d 20 54 43 4c 5f L, NULL) == TCL_
6370: 50 41 54 48 5f 41 42 53 4f 4c 55 54 45 29 20 7b PATH_ABSOLUTE) {
6380: 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 74 .. Tcl_Obj *t
6390: 61 69 6c 4f 62 6a 20 3d 20 6f 62 6a 76 5b 31 5d ailObj = objv[1]
63a0: 3b 0a 09 20 20 20 20 54 63 6c 5f 50 61 74 68 54 ;.. Tcl_PathT
63b0: 79 70 65 20 74 79 70 65 3b 0a 0a 09 20 20 20 20 ype type;...
63c0: 2f 2a 20 69 66 20 66 6f 72 63 65 52 65 6c 61 74 /* if forceRelat
63d0: 69 76 65 20 2d 20 73 65 63 6f 6e 64 20 70 61 74 ive - second pat
63e0: 68 20 69 73 20 72 65 6c 61 74 69 76 65 20 2a 2f h is relative */
63f0: 0a 09 20 20 20 20 74 79 70 65 20 3d 20 66 6f 72 .. type = for
6400: 63 65 52 65 6c 61 74 69 76 65 20 3f 20 54 43 4c ceRelative ? TCL
6410: 5f 50 41 54 48 5f 52 45 4c 41 54 49 56 45 20 3a _PATH_RELATIVE :
6420: 0a 09 09 20 20 20 20 54 63 6c 47 65 74 50 61 74 ... TclGetPat
6430: 68 54 79 70 65 28 74 61 69 6c 4f 62 6a 2c 20 4e hType(tailObj, N
6440: 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 ULL, NULL, NULL)
6450: 3b 0a 09 20 20 20 20 69 66 20 28 74 79 70 65 20 ;.. if (type
6460: 3d 3d 20 54 43 4c 5f 50 41 54 48 5f 52 45 4c 41 == TCL_PATH_RELA
6470: 54 49 56 45 29 20 7b 0a 09 09 63 6f 6e 73 74 20 TIVE) {...const
6480: 63 68 61 72 20 2a 73 74 72 3b 0a 09 09 69 6e 74 char *str;...int
6490: 20 6c 65 6e 3b 0a 0a 09 09 73 74 72 20 3d 20 54 len;....str = T
64a0: 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d cl_GetStringFrom
64b0: 4f 62 6a 28 74 61 69 6c 4f 62 6a 2c 20 26 6c 65 Obj(tailObj, &le
64c0: 6e 29 3b 0a 09 09 69 66 20 28 6c 65 6e 20 3d 3d n);...if (len ==
64d0: 20 30 29 20 7b 0a 09 09 20 20 20 20 2f 2a 0a 09 0) {... /*..
64e0: 09 20 20 20 20 20 2a 20 54 68 69 73 20 68 61 70 . * This hap
64f0: 70 65 6e 73 20 69 66 20 77 65 20 74 72 79 20 74 pens if we try t
6500: 6f 20 68 61 6e 64 6c 65 20 74 68 65 20 72 6f 6f o handle the roo
6510: 74 20 76 6f 6c 75 6d 65 20 27 2f 27 2e 0a 09 09 t volume '/'....
6520: 20 20 20 20 20 2a 20 54 68 65 72 65 27 73 20 6e * There's n
6530: 6f 20 6e 65 65 64 20 74 6f 20 72 65 74 75 72 6e o need to return
6540: 20 61 20 73 70 65 63 69 61 6c 20 70 61 74 68 20 a special path
6550: 6f 62 6a 65 63 74 2c 20 77 68 65 6e 0a 09 09 20 object, when...
6560: 20 20 20 20 2a 20 74 68 65 20 62 61 73 65 20 69 * the base i
6570: 74 73 65 6c 66 20 69 73 20 6a 75 73 74 20 66 69 tself is just fi
6580: 6e 65 21 0a 09 09 20 20 20 20 20 2a 2f 0a 0a 09 ne!... */...
6590: 09 20 20 20 20 72 65 74 75 72 6e 20 65 6c 74 3b . return elt;
65a0: 0a 09 09 7d 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 ...}..../*... *
65b0: 49 66 20 69 74 20 64 6f 65 73 6e 27 74 20 62 65 If it doesn't be
65c0: 67 69 6e 20 77 69 74 68 20 27 2e 27 20 61 6e 64 gin with '.' and
65d0: 20 69 73 20 61 20 75 6e 69 78 20 70 61 74 68 20 is a unix path
65e0: 6f 72 20 69 74 20 61 0a 09 09 20 2a 20 77 69 6e or it a... * win
65f0: 64 6f 77 73 20 70 61 74 68 20 77 69 74 68 6f 75 dows path withou
6600: 74 20 62 61 63 6b 73 6c 61 73 68 65 73 2c 20 74 t backslashes, t
6610: 68 65 6e 20 77 65 20 63 61 6e 20 62 65 20 76 65 hen we can be ve
6620: 72 79 0a 09 09 20 2a 20 65 66 66 69 63 69 65 6e ry... * efficien
6630: 74 20 68 65 72 65 2e 20 28 49 6e 20 66 61 63 74 t here. (In fact
6640: 20 65 76 65 6e 20 61 20 77 69 6e 64 6f 77 73 20 even a windows
6650: 70 61 74 68 20 77 69 74 68 0a 09 09 20 2a 20 62 path with... * b
6660: 61 63 6b 73 6c 61 73 68 65 73 20 63 61 6e 20 62 ackslashes can b
6670: 65 20 6a 6f 69 6e 65 64 20 65 66 66 69 63 69 65 e joined efficie
6680: 6e 74 6c 79 2c 20 62 75 74 20 74 68 65 20 70 61 ntly, but the pa
6690: 74 68 20 6f 62 6a 65 63 74 0a 09 09 20 2a 20 77 th object... * w
66a0: 6f 75 6c 64 20 6e 6f 74 20 68 61 76 65 20 66 6f ould not have fo
66b0: 72 77 61 72 64 20 73 6c 61 73 68 65 73 20 6f 6e rward slashes on
66c0: 6c 79 2c 20 61 6e 64 20 74 68 69 73 20 77 6f 75 ly, and this wou
66d0: 6c 64 0a 09 09 20 2a 20 74 68 65 72 65 66 6f 72 ld... * therefor
66e0: 65 20 63 6f 6e 74 72 61 64 69 63 74 20 6f 75 72 e contradict our
66f0: 20 27 66 69 6c 65 20 6a 6f 69 6e 27 20 64 6f 63 'file join' doc
6700: 75 6d 65 6e 74 61 74 69 6f 6e 29 2e 0a 09 09 20 umentation)....
6710: 2a 2f 0a 0a 09 09 69 66 20 28 73 74 72 5b 30 5d */....if (str[0]
6720: 20 21 3d 20 27 2e 27 20 26 26 20 28 28 74 63 6c != '.' && ((tcl
6730: 50 6c 61 74 66 6f 72 6d 20 21 3d 20 54 43 4c 5f Platform != TCL_
6740: 50 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 4f 57 53 PLATFORM_WINDOWS
6750: 29 0a 09 09 09 7c 7c 20 28 73 74 72 63 68 72 28 )....|| (strchr(
6760: 73 74 72 2c 20 27 5c 5c 27 29 20 3d 3d 20 4e 55 str, '\\') == NU
6770: 4c 4c 29 29 29 20 7b 0a 09 09 20 20 20 20 2f 2a LL))) {... /*
6780: 0a 09 09 20 20 20 20 20 2a 20 46 69 6e 61 6c 6c ... * Finall
6790: 79 2c 20 6f 6e 20 57 69 6e 64 6f 77 73 2c 20 27 y, on Windows, '
67a0: 66 69 6c 65 20 6a 6f 69 6e 27 20 69 73 20 64 65 file join' is de
67b0: 66 69 6e 65 64 20 74 6f 20 63 6f 6e 76 65 72 74 fined to convert
67c0: 0a 09 09 20 20 20 20 20 2a 20 61 6c 6c 20 62 61 ... * all ba
67d0: 63 6b 73 6c 61 73 68 65 73 20 74 6f 20 66 6f 72 ckslashes to for
67e0: 77 61 72 64 20 73 6c 61 73 68 65 73 2c 20 73 6f ward slashes, so
67f0: 20 74 68 65 20 62 61 73 65 20 70 61 72 74 0a 09 the base part..
6800: 09 20 20 20 20 20 2a 20 63 61 6e 6e 6f 74 20 68 . * cannot h
6810: 61 76 65 20 62 61 63 6b 73 6c 61 73 68 65 73 20 ave backslashes
6820: 65 69 74 68 65 72 2e 0a 09 09 20 20 20 20 20 2a either.... *
6830: 2f 0a 0a 09 09 20 20 20 20 69 66 20 28 28 74 63 /.... if ((tc
6840: 6c 50 6c 61 74 66 6f 72 6d 20 21 3d 20 54 43 4c lPlatform != TCL
6850: 5f 50 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 4f 57 _PLATFORM_WINDOW
6860: 53 29 0a 09 09 09 20 20 20 20 7c 7c 20 28 73 74 S).... || (st
6870: 72 63 68 72 28 54 63 6c 5f 47 65 74 53 74 72 69 rchr(Tcl_GetStri
6880: 6e 67 28 65 6c 74 29 2c 20 27 5c 5c 27 29 20 3d ng(elt), '\\') =
6890: 3d 20 4e 55 4c 4c 29 29 20 7b 0a 0a 09 09 09 69 = NULL)) {.....i
68a0: 66 20 28 50 41 54 48 46 4c 41 47 53 28 65 6c 74 f (PATHFLAGS(elt
68b0: 29 29 20 7b 0a 09 09 09 20 20 20 20 72 65 74 75 )) {.... retu
68c0: 72 6e 20 54 63 6c 4e 65 77 46 53 50 61 74 68 4f rn TclNewFSPathO
68d0: 62 6a 28 65 6c 74 2c 20 73 74 72 2c 20 6c 65 6e bj(elt, str, len
68e0: 29 3b 0a 09 09 09 7d 0a 09 09 09 69 66 20 28 54 );....}....if (T
68f0: 43 4c 5f 50 41 54 48 5f 41 42 53 4f 4c 55 54 45 CL_PATH_ABSOLUTE
6900: 20 21 3d 20 54 63 6c 5f 46 53 47 65 74 50 61 74 != Tcl_FSGetPat
6910: 68 54 79 70 65 28 65 6c 74 29 29 20 7b 0a 09 09 hType(elt)) {...
6920: 09 20 20 20 20 72 65 74 75 72 6e 20 54 63 6c 4e . return TclN
6930: 65 77 46 53 50 61 74 68 4f 62 6a 28 65 6c 74 2c ewFSPathObj(elt,
6940: 20 73 74 72 2c 20 6c 65 6e 29 3b 0a 09 09 09 7d str, len);....}
6950: 0a 09 09 09 28 76 6f 69 64 29 20 54 63 6c 5f 46 ....(void) Tcl_F
6960: 53 47 65 74 4e 6f 72 6d 61 6c 69 7a 65 64 50 61 SGetNormalizedPa
6970: 74 68 28 4e 55 4c 4c 2c 20 65 6c 74 29 3b 0a 09 th(NULL, elt);..
6980: 09 09 69 66 20 28 65 6c 74 20 3d 3d 20 50 41 54 ..if (elt == PAT
6990: 48 4f 42 4a 28 65 6c 74 29 2d 3e 6e 6f 72 6d 50 HOBJ(elt)->normP
69a0: 61 74 68 50 74 72 29 20 7b 0a 09 09 09 20 20 20 athPtr) {....
69b0: 20 72 65 74 75 72 6e 20 54 63 6c 4e 65 77 46 53 return TclNewFS
69c0: 50 61 74 68 4f 62 6a 28 65 6c 74 2c 20 73 74 72 PathObj(elt, str
69d0: 2c 20 6c 65 6e 29 3b 0a 09 09 09 7d 0a 09 09 20 , len);....}...
69e0: 20 20 20 7d 0a 09 09 7d 0a 0a 09 09 2f 2a 0a 09 }...}..../*..
69f0: 09 20 2a 20 4f 74 68 65 72 77 69 73 65 20 77 65 . * Otherwise we
6a00: 20 64 6f 6e 27 74 20 68 61 76 65 20 61 6e 20 65 don't have an e
6a10: 61 73 79 20 6a 6f 69 6e 2c 20 61 6e 64 20 77 65 asy join, and we
6a20: 20 6d 75 73 74 20 6c 65 74 20 74 68 65 0a 09 09 must let the...
6a30: 20 2a 20 6d 6f 72 65 20 67 65 6e 65 72 61 6c 20 * more general
6a40: 63 6f 64 65 20 62 65 6c 6f 77 20 68 61 6e 64 6c code below handl
6a50: 65 20 74 68 69 6e 67 73 2e 0a 09 09 20 2a 2f 0a e things.... */.
6a60: 09 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 . } else if (
6a70: 74 63 6c 50 6c 61 74 66 6f 72 6d 20 3d 3d 20 54 tclPlatform == T
6a80: 43 4c 5f 50 4c 41 54 46 4f 52 4d 5f 55 4e 49 58 CL_PLATFORM_UNIX
6a90: 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 74 61 69 ) {...return tai
6aa0: 6c 4f 62 6a 3b 0a 09 20 20 20 20 7d 20 65 6c 73 lObj;.. } els
6ab0: 65 20 7b 0a 09 09 63 6f 6e 73 74 20 63 68 61 72 e {...const char
6ac0: 20 2a 73 74 72 20 3d 20 54 63 6c 47 65 74 53 74 *str = TclGetSt
6ad0: 72 69 6e 67 28 74 61 69 6c 4f 62 6a 29 3b 0a 0a ring(tailObj);..
6ae0: 09 09 69 66 20 28 74 63 6c 50 6c 61 74 66 6f 72 ..if (tclPlatfor
6af0: 6d 20 3d 3d 20 54 43 4c 5f 50 4c 41 54 46 4f 52 m == TCL_PLATFOR
6b00: 4d 5f 57 49 4e 44 4f 57 53 29 20 7b 0a 09 09 20 M_WINDOWS) {...
6b10: 20 20 20 69 66 20 28 73 74 72 63 68 72 28 73 74 if (strchr(st
6b20: 72 2c 20 27 5c 5c 27 29 20 3d 3d 20 4e 55 4c 4c r, '\\') == NULL
6b30: 29 20 7b 0a 09 09 09 72 65 74 75 72 6e 20 74 61 ) {....return ta
6b40: 69 6c 4f 62 6a 3b 0a 09 09 20 20 20 20 7d 0a 09 ilObj;... }..
6b50: 09 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a 20 20 20 .}.. }..}.
6b60: 20 7d 0a 0a 20 20 20 20 61 73 73 65 72 74 20 28 }.. assert (
6b70: 20 72 65 73 20 3d 3d 20 4e 55 4c 4c 20 29 3b 0a res == NULL );.
6b80: 0a 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 3b . for (i = 0;
6b90: 20 69 20 3c 20 65 6c 65 6d 65 6e 74 73 3b 20 69 i < elements; i
6ba0: 2b 2b 29 20 7b 0a 09 69 6e 74 20 64 72 69 76 65 ++) {..int drive
6bb0: 4e 61 6d 65 4c 65 6e 67 74 68 2c 20 73 74 72 45 NameLength, strE
6bc0: 6c 74 4c 65 6e 2c 20 6c 65 6e 67 74 68 3b 0a 09 ltLen, length;..
6bd0: 54 63 6c 5f 50 61 74 68 54 79 70 65 20 74 79 70 Tcl_PathType typ
6be0: 65 3b 0a 09 63 68 61 72 20 2a 73 74 72 45 6c 74 e;..char *strElt
6bf0: 2c 20 2a 70 74 72 3b 0a 09 54 63 6c 5f 4f 62 6a , *ptr;..Tcl_Obj
6c00: 20 2a 64 72 69 76 65 4e 61 6d 65 20 3d 20 4e 55 *driveName = NU
6c10: 4c 4c 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 65 6c LL;..Tcl_Obj *el
6c20: 74 20 3d 20 6f 62 6a 76 5b 69 5d 3b 0a 0a 09 73 t = objv[i];...s
6c30: 74 72 45 6c 74 20 3d 20 54 63 6c 5f 47 65 74 53 trElt = Tcl_GetS
6c40: 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 65 6c 74 tringFromObj(elt
6c50: 2c 20 26 73 74 72 45 6c 74 4c 65 6e 29 3b 0a 09 , &strEltLen);..
6c60: 64 72 69 76 65 4e 61 6d 65 4c 65 6e 67 74 68 20 driveNameLength
6c70: 3d 20 30 3b 0a 09 2f 2a 20 69 66 20 66 6f 72 63 = 0;../* if forc
6c80: 65 52 65 6c 61 74 69 76 65 20 2d 20 61 6c 6c 20 eRelative - all
6c90: 70 61 74 68 73 20 65 78 63 65 70 74 69 6e 67 20 paths excepting
6ca0: 66 69 72 73 74 20 6f 6e 65 20 61 72 65 20 72 65 first one are re
6cb0: 6c 61 74 69 76 65 20 2a 2f 0a 09 74 79 70 65 20 lative */..type
6cc0: 3d 20 28 66 6f 72 63 65 52 65 6c 61 74 69 76 65 = (forceRelative
6cd0: 20 26 26 20 28 69 20 3e 20 30 29 29 20 3f 20 54 && (i > 0)) ? T
6ce0: 43 4c 5f 50 41 54 48 5f 52 45 4c 41 54 49 56 45 CL_PATH_RELATIVE
6cf0: 20 3a 0a 09 09 54 63 6c 47 65 74 50 61 74 68 54 :...TclGetPathT
6d00: 79 70 65 28 65 6c 74 2c 20 26 66 73 50 74 72 2c ype(elt, &fsPtr,
6d10: 20 26 64 72 69 76 65 4e 61 6d 65 4c 65 6e 67 74 &driveNameLengt
6d20: 68 2c 20 26 64 72 69 76 65 4e 61 6d 65 29 3b 0a h, &driveName);.
6d30: 09 69 66 20 28 74 79 70 65 20 21 3d 20 54 43 4c .if (type != TCL
6d40: 5f 50 41 54 48 5f 52 45 4c 41 54 49 56 45 29 20 _PATH_RELATIVE)
6d50: 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 {.. /*..
6d60: 2a 20 5a 65 72 6f 20 6f 75 74 20 74 68 65 20 63 * Zero out the c
6d70: 75 72 72 65 6e 74 20 72 65 73 75 6c 74 2e 0a 09 urrent result...
6d80: 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 69 66 */... if
6d90: 20 28 72 65 73 20 21 3d 20 4e 55 4c 4c 29 20 7b (res != NULL) {
6da0: 0a 09 09 54 63 6c 44 65 63 72 52 65 66 43 6f 75 ...TclDecrRefCou
6db0: 6e 74 28 72 65 73 29 3b 0a 09 20 20 20 20 7d 0a nt(res);.. }.
6dc0: 0a 09 20 20 20 20 69 66 20 28 64 72 69 76 65 4e .. if (driveN
6dd0: 61 6d 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 ame != NULL) {..
6de0: 09 2f 2a 0a 09 09 20 2a 20 57 65 27 76 65 20 62 ./*... * We've b
6df0: 65 65 6e 20 67 69 76 65 6e 20 61 20 73 65 70 61 een given a sepa
6e00: 72 61 74 65 20 64 72 69 76 65 2d 6e 61 6d 65 20 rate drive-name
6e10: 6f 62 6a 65 63 74 2c 20 62 65 63 61 75 73 65 20 object, because
6e20: 74 68 65 0a 09 09 20 2a 20 70 72 65 66 69 78 20 the... * prefix
6e30: 69 6e 20 27 65 6c 74 27 20 69 73 20 6e 6f 74 20 in 'elt' is not
6e40: 69 6e 20 61 20 73 75 69 74 61 62 6c 65 20 66 6f in a suitable fo
6e50: 72 6d 61 74 20 66 6f 72 20 75 73 20 28 65 2e 67 rmat for us (e.g
6e60: 2e 20 69 74 0a 09 09 20 2a 20 6d 61 79 20 63 6f . it... * may co
6e70: 6e 74 61 69 6e 20 69 72 72 65 6c 65 76 61 6e 74 ntain irrelevant
6e80: 20 6d 75 6c 74 69 70 6c 65 20 73 65 70 61 72 61 multiple separa
6e90: 74 6f 72 73 2c 20 6c 69 6b 65 0a 09 09 20 2a 20 tors, like... *
6ea0: 43 3a 2f 2f 2f 2f 2f 66 6f 6f 29 2e 0a 09 09 20 C://///foo)....
6eb0: 2a 2f 0a 0a 09 09 72 65 73 20 3d 20 54 63 6c 5f */....res = Tcl_
6ec0: 44 75 70 6c 69 63 61 74 65 4f 62 6a 28 64 72 69 DuplicateObj(dri
6ed0: 76 65 4e 61 6d 65 29 3b 0a 09 09 54 63 6c 44 65 veName);...TclDe
6ee0: 63 72 52 65 66 43 6f 75 6e 74 28 64 72 69 76 65 crRefCount(drive
6ef0: 4e 61 6d 65 29 3b 0a 0a 09 09 2f 2a 0a 09 09 20 Name);..../*...
6f00: 2a 20 44 6f 20 6e 6f 74 20 73 65 74 20 64 72 69 * Do not set dri
6f10: 76 65 4e 61 6d 65 20 74 6f 20 4e 55 4c 4c 2c 20 veName to NULL,
6f20: 62 65 63 61 75 73 65 20 77 65 20 77 69 6c 6c 20 because we will
6f30: 63 68 65 63 6b 20 69 74 73 0a 09 09 20 2a 20 76 check its... * v
6f40: 61 6c 75 65 20 62 65 6c 6f 77 20 28 62 75 74 20 alue below (but
6f50: 77 65 20 77 6f 6e 27 74 20 61 63 63 65 73 73 20 we won't access
6f60: 74 68 65 20 63 6f 6e 74 65 6e 74 73 2c 20 73 69 the contents, si
6f70: 6e 63 65 20 74 68 6f 73 65 0a 09 09 20 2a 20 68 nce those... * h
6f80: 61 76 65 20 62 65 65 6e 20 63 6c 65 61 6e 65 64 ave been cleaned
6f90: 2d 75 70 29 2e 0a 09 09 20 2a 2f 0a 09 20 20 20 -up).... */..
6fa0: 20 7d 20 65 6c 73 65 20 7b 0a 09 09 72 65 73 20 } else {...res
6fb0: 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f = Tcl_NewStringO
6fc0: 62 6a 28 73 74 72 45 6c 74 2c 20 64 72 69 76 65 bj(strElt, drive
6fd0: 4e 61 6d 65 4c 65 6e 67 74 68 29 3b 0a 09 20 20 NameLength);..
6fe0: 20 20 7d 0a 09 20 20 20 20 73 74 72 45 6c 74 20 }.. strElt
6ff0: 2b 3d 20 64 72 69 76 65 4e 61 6d 65 4c 65 6e 67 += driveNameLeng
7000: 74 68 3b 0a 09 7d 20 65 6c 73 65 20 69 66 20 28 th;..} else if (
7010: 64 72 69 76 65 4e 61 6d 65 20 21 3d 20 4e 55 4c driveName != NUL
7020: 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 44 65 L) {.. Tcl_De
7030: 63 72 52 65 66 43 6f 75 6e 74 28 64 72 69 76 65 crRefCount(drive
7040: 4e 61 6d 65 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 Name);..}.../*..
7050: 20 2a 20 4f 70 74 69 6d 69 73 61 74 69 6f 6e 20 * Optimisation
7060: 62 6c 6f 63 6b 3a 20 69 66 20 74 68 69 73 20 69 block: if this i
7070: 73 20 74 68 65 20 6c 61 73 74 20 65 6c 65 6d 65 s the last eleme
7080: 6e 74 20 74 6f 20 62 65 20 65 78 61 6d 69 6e 65 nt to be examine
7090: 64 2c 20 61 6e 64 0a 09 20 2a 20 69 74 20 69 73 d, and.. * it is
70a0: 20 61 62 73 6f 6c 75 74 65 20 6f 72 20 74 68 65 absolute or the
70b0: 20 6f 6e 6c 79 20 65 6c 65 6d 65 6e 74 2c 20 61 only element, a
70c0: 6e 64 20 74 68 65 20 64 72 69 76 65 2d 70 72 65 nd the drive-pre
70d0: 66 69 78 20 77 61 73 20 6f 6b 20 28 69 66 0a 09 fix was ok (if..
70e0: 20 2a 20 74 68 65 72 65 20 69 73 20 6f 6e 65 29 * there is one)
70f0: 2c 20 69 74 20 6d 69 67 68 74 20 62 65 20 74 68 , it might be th
7100: 61 74 20 74 68 65 20 70 61 74 68 20 69 73 20 61 at the path is a
7110: 6c 72 65 61 64 79 20 69 6e 20 61 20 73 75 69 74 lready in a suit
7120: 61 62 6c 65 0a 09 20 2a 20 66 6f 72 6d 20 74 6f able.. * form to
7130: 20 62 65 20 72 65 74 75 72 6e 65 64 2e 20 54 68 be returned. Th
7140: 65 6e 20 77 65 20 63 61 6e 20 73 68 6f 72 74 2d en we can short-
7150: 63 75 74 20 74 68 65 20 72 65 73 74 20 6f 66 20 cut the rest of
7160: 74 68 69 73 0a 09 20 2a 20 66 75 6e 63 74 69 6f this.. * functio
7170: 6e 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 28 64 n... */...if ((d
7180: 72 69 76 65 4e 61 6d 65 20 3d 3d 20 4e 55 4c 4c riveName == NULL
7190: 29 20 26 26 20 28 69 20 3d 3d 20 28 65 6c 65 6d ) && (i == (elem
71a0: 65 6e 74 73 20 2d 20 31 29 29 0a 09 09 26 26 20 ents - 1))...&&
71b0: 28 74 79 70 65 20 21 3d 20 54 43 4c 5f 50 41 54 (type != TCL_PAT
71c0: 48 5f 52 45 4c 41 54 49 56 45 20 7c 7c 20 72 65 H_RELATIVE || re
71d0: 73 20 3d 3d 20 4e 55 4c 4c 29 29 20 7b 0a 09 20 s == NULL)) {..
71e0: 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 49 74 /*.. * It
71f0: 27 73 20 74 68 65 20 6c 61 73 74 20 70 61 74 68 's the last path
7200: 20 73 65 67 6d 65 6e 74 2e 20 50 65 72 66 6f 72 segment. Perfor
7210: 6d 20 61 20 71 75 69 63 6b 20 63 68 65 63 6b 20 m a quick check
7220: 69 66 20 74 68 65 20 70 61 74 68 0a 09 20 20 20 if the path..
7230: 20 20 2a 20 69 73 20 61 6c 72 65 61 64 79 20 69 * is already i
7240: 6e 20 61 20 73 75 69 74 61 62 6c 65 20 66 6f 72 n a suitable for
7250: 6d 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 m... */...
7260: 20 20 69 66 20 28 74 63 6c 50 6c 61 74 66 6f 72 if (tclPlatfor
7270: 6d 20 3d 3d 20 54 43 4c 5f 50 4c 41 54 46 4f 52 m == TCL_PLATFOR
7280: 4d 5f 57 49 4e 44 4f 57 53 29 20 7b 0a 09 09 69 M_WINDOWS) {...i
7290: 66 20 28 73 74 72 63 68 72 28 73 74 72 45 6c 74 f (strchr(strElt
72a0: 2c 20 27 5c 5c 27 29 20 21 3d 20 4e 55 4c 4c 29 , '\\') != NULL)
72b0: 20 7b 0a 09 09 20 20 20 20 67 6f 74 6f 20 6e 6f {... goto no
72c0: 51 75 69 63 6b 52 65 74 75 72 6e 3b 0a 09 09 7d QuickReturn;...}
72d0: 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 70 74 72 .. }.. ptr
72e0: 20 3d 20 73 74 72 45 6c 74 3b 0a 09 20 20 20 20 = strElt;..
72f0: 2f 2a 20 5b 42 75 67 20 66 33 34 63 66 38 33 64 /* [Bug f34cf83d
7300: 64 30 5d 20 2a 2f 0a 09 20 20 20 20 69 66 20 28 d0] */.. if (
7310: 64 72 69 76 65 4e 61 6d 65 4c 65 6e 67 74 68 20 driveNameLength
7320: 3e 20 30 29 20 7b 0a 09 09 69 66 20 28 70 74 72 > 0) {...if (ptr
7330: 5b 30 5d 20 3d 3d 20 27 2f 27 20 26 26 20 70 74 [0] == '/' && pt
7340: 72 5b 2d 31 5d 20 3d 3d 20 27 2f 27 29 20 7b 0a r[-1] == '/') {.
7350: 09 09 20 20 20 20 67 6f 74 6f 20 6e 6f 51 75 69 .. goto noQui
7360: 63 6b 52 65 74 75 72 6e 3b 0a 09 09 7d 0a 09 20 ckReturn;...}..
7370: 20 20 20 7d 0a 09 20 20 20 20 77 68 69 6c 65 20 }.. while
7380: 28 2a 70 74 72 20 21 3d 20 27 5c 30 27 29 20 7b (*ptr != '\0') {
7390: 0a 09 09 69 66 20 28 2a 70 74 72 20 3d 3d 20 27 ...if (*ptr == '
73a0: 2f 27 20 26 26 20 28 70 74 72 5b 31 5d 20 3d 3d /' && (ptr[1] ==
73b0: 20 27 2f 27 20 7c 7c 20 70 74 72 5b 31 5d 20 3d '/' || ptr[1] =
73c0: 3d 20 27 5c 30 27 29 29 20 7b 0a 09 09 20 20 20 = '\0')) {...
73d0: 20 2f 2a 0a 09 09 20 20 20 20 20 2a 20 57 65 20 /*... * We
73e0: 68 61 76 65 20 61 20 72 65 70 65 61 74 65 64 20 have a repeated
73f0: 66 69 6c 65 20 73 65 70 61 72 61 74 6f 72 2c 20 file separator,
7400: 77 68 69 63 68 20 6d 65 61 6e 73 20 74 68 65 20 which means the
7410: 70 61 74 68 0a 09 09 20 20 20 20 20 2a 20 69 73 path... * is
7420: 20 6e 6f 74 20 69 6e 20 6e 6f 72 6d 61 6c 69 7a not in normaliz
7430: 65 64 20 66 6f 72 6d 0a 09 09 20 20 20 20 20 2a ed form... *
7440: 2f 0a 0a 09 09 20 20 20 20 67 6f 74 6f 20 6e 6f /.... goto no
7450: 51 75 69 63 6b 52 65 74 75 72 6e 3b 0a 09 09 7d QuickReturn;...}
7460: 0a 09 09 70 74 72 2b 2b 3b 0a 09 20 20 20 20 7d ...ptr++;.. }
7470: 0a 09 20 20 20 20 69 66 20 28 72 65 73 20 21 3d .. if (res !=
7480: 20 4e 55 4c 4c 29 20 7b 0a 09 09 54 63 6c 44 65 NULL) {...TclDe
7490: 63 72 52 65 66 43 6f 75 6e 74 28 72 65 73 29 3b crRefCount(res);
74a0: 0a 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 2f 2a .. }... /*
74b0: 0a 09 20 20 20 20 20 2a 20 54 68 69 73 20 65 6c .. * This el
74c0: 65 6d 65 6e 74 20 69 73 20 6a 75 73 74 20 77 68 ement is just wh
74d0: 61 74 20 77 65 20 77 61 6e 74 20 74 6f 20 72 65 at we want to re
74e0: 74 75 72 6e 20 61 6c 72 65 61 64 79 3b 20 6e 6f turn already; no
74f0: 20 66 75 72 74 68 65 72 0a 09 20 20 20 20 20 2a further.. *
7500: 20 6d 61 6e 69 70 75 6c 61 74 69 6f 6e 20 69 73 manipulation is
7510: 20 72 65 71 75 72 65 64 2e 0a 09 20 20 20 20 20 requred...
7520: 2a 2f 0a 0a 09 20 20 20 20 72 65 74 75 72 6e 20 */... return
7530: 65 6c 74 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a elt;..}.../*.. *
7540: 20 54 68 65 20 70 61 74 68 20 65 6c 65 6d 65 6e The path elemen
7550: 74 20 77 61 73 20 6e 6f 74 20 6f 66 20 61 20 73 t was not of a s
7560: 75 69 74 61 62 6c 65 20 66 6f 72 6d 20 74 6f 20 uitable form to
7570: 62 65 20 72 65 74 75 72 6e 65 64 20 61 73 20 69 be returned as i
7580: 73 2e 0a 09 20 2a 20 57 65 20 6e 65 65 64 20 74 s... * We need t
7590: 6f 20 70 65 72 66 6f 72 6d 20 61 20 6d 6f 72 65 o perform a more
75a0: 20 63 6f 6d 70 6c 65 78 20 6f 70 65 72 61 74 69 complex operati
75b0: 6f 6e 20 68 65 72 65 2e 0a 09 20 2a 2f 0a 0a 20 on here... */..
75c0: 20 20 20 6e 6f 51 75 69 63 6b 52 65 74 75 72 6e noQuickReturn
75d0: 3a 0a 09 69 66 20 28 72 65 73 20 3d 3d 20 4e 55 :..if (res == NU
75e0: 4c 4c 29 20 7b 0a 09 20 20 20 20 72 65 73 20 3d LL) {.. res =
75f0: 20 54 63 6c 5f 4e 65 77 4f 62 6a 28 29 3b 0a 09 Tcl_NewObj();..
7600: 20 20 20 20 70 74 72 20 3d 20 54 63 6c 5f 47 65 ptr = Tcl_Ge
7610: 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 72 tStringFromObj(r
7620: 65 73 2c 20 26 6c 65 6e 67 74 68 29 3b 0a 09 7d es, &length);..}
7630: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 70 74 72 else {.. ptr
7640: 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 = Tcl_GetString
7650: 46 72 6f 6d 4f 62 6a 28 72 65 73 2c 20 26 6c 65 FromObj(res, &le
7660: 6e 67 74 68 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 ngth);..}.../*..
7670: 20 2a 20 53 74 72 69 70 20 6f 66 66 20 61 6e 79 * Strip off any
7680: 20 27 2e 2f 27 20 62 65 66 6f 72 65 20 61 20 74 './' before a t
7690: 69 6c 64 65 2c 20 75 6e 6c 65 73 73 20 74 68 69 ilde, unless thi
76a0: 73 20 69 73 20 74 68 65 20 62 65 67 69 6e 6e 69 s is the beginni
76b0: 6e 67 20 6f 66 0a 09 20 2a 20 74 68 65 20 70 61 ng of.. * the pa
76c0: 74 68 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 6c th... */...if (l
76d0: 65 6e 67 74 68 20 3e 20 30 20 26 26 20 73 74 72 ength > 0 && str
76e0: 45 6c 74 4c 65 6e 20 3e 20 30 20 26 26 20 28 73 EltLen > 0 && (s
76f0: 74 72 45 6c 74 5b 30 5d 20 3d 3d 20 27 2e 27 29 trElt[0] == '.')
7700: 20 26 26 0a 09 09 28 73 74 72 45 6c 74 5b 31 5d &&...(strElt[1]
7710: 20 3d 3d 20 27 2f 27 29 20 26 26 20 28 73 74 72 == '/') && (str
7720: 45 6c 74 5b 32 5d 20 3d 3d 20 27 7e 27 29 29 20 Elt[2] == '~'))
7730: 7b 0a 09 20 20 20 20 73 74 72 45 6c 74 20 2b 3d {.. strElt +=
7740: 20 32 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 2;..}.../*.. *
7750: 41 20 4e 55 4c 4c 20 76 61 6c 75 65 20 66 6f 72 A NULL value for
7760: 20 66 73 50 74 72 20 61 74 20 74 68 69 73 20 73 fsPtr at this s
7770: 74 61 67 65 20 62 61 73 69 63 61 6c 6c 79 20 6d tage basically m
7780: 65 61 6e 73 20 77 65 27 72 65 20 74 72 79 69 6e eans we're tryin
7790: 67 0a 09 20 2a 20 74 6f 20 6a 6f 69 6e 20 61 20 g.. * to join a
77a0: 72 65 6c 61 74 69 76 65 20 70 61 74 68 20 6f 6e relative path on
77b0: 74 6f 20 73 6f 6d 65 74 68 69 6e 67 20 77 68 69 to something whi
77c0: 63 68 20 69 73 20 61 6c 73 6f 20 72 65 6c 61 74 ch is also relat
77d0: 69 76 65 20 28 6f 72 0a 09 20 2a 20 65 6d 70 74 ive (or.. * empt
77e0: 79 29 2e 20 54 68 65 72 65 27 73 20 6e 6f 74 68 y). There's noth
77f0: 69 6e 67 20 70 61 72 74 69 63 75 6c 61 72 6c 79 ing particularly
7800: 20 77 72 6f 6e 67 20 77 69 74 68 20 74 68 61 74 wrong with that
7810: 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 2a 73 74 ... */...if (*st
7820: 72 45 6c 74 20 3d 3d 20 27 5c 30 27 29 20 7b 0a rElt == '\0') {.
7830: 09 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 09 . continue;..
7840: 7d 0a 0a 09 69 66 20 28 66 73 50 74 72 20 3d 3d }...if (fsPtr ==
7850: 20 26 74 63 6c 4e 61 74 69 76 65 46 69 6c 65 73 &tclNativeFiles
7860: 79 73 74 65 6d 20 7c 7c 20 66 73 50 74 72 20 3d ystem || fsPtr =
7870: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 54 = NULL) {.. T
7880: 63 6c 70 4e 61 74 69 76 65 4a 6f 69 6e 50 61 74 clpNativeJoinPat
7890: 68 28 72 65 73 2c 20 73 74 72 45 6c 74 29 3b 0a h(res, strElt);.
78a0: 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 63 .} else {.. c
78b0: 68 61 72 20 73 65 70 61 72 61 74 6f 72 20 3d 20 har separator =
78c0: 27 2f 27 3b 0a 09 20 20 20 20 69 6e 74 20 6e 65 '/';.. int ne
78d0: 65 64 73 53 65 70 20 3d 20 30 3b 0a 0a 09 20 20 edsSep = 0;...
78e0: 20 20 69 66 20 28 66 73 50 74 72 2d 3e 66 69 6c if (fsPtr->fil
78f0: 65 73 79 73 74 65 6d 53 65 70 61 72 61 74 6f 72 esystemSeparator
7900: 50 72 6f 63 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a Proc != NULL) {.
7910: 09 09 54 63 6c 5f 4f 62 6a 20 2a 73 65 70 20 3d ..Tcl_Obj *sep =
7920: 20 66 73 50 74 72 2d 3e 66 69 6c 65 73 79 73 74 fsPtr->filesyst
7930: 65 6d 53 65 70 61 72 61 74 6f 72 50 72 6f 63 28 emSeparatorProc(
7940: 72 65 73 29 3b 0a 0a 09 09 69 66 20 28 73 65 70 res);....if (sep
7950: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 20 20 != NULL) {...
7960: 20 20 73 65 70 61 72 61 74 6f 72 20 3d 20 54 63 separator = Tc
7970: 6c 47 65 74 53 74 72 69 6e 67 28 73 65 70 29 5b lGetString(sep)[
7980: 30 5d 3b 0a 09 09 20 20 20 20 54 63 6c 5f 44 65 0];... Tcl_De
7990: 63 72 52 65 66 43 6f 75 6e 74 28 73 65 70 29 3b crRefCount(sep);
79a0: 0a 09 09 7d 0a 09 09 2f 2a 20 53 61 66 65 74 79 ...}.../* Safety
79b0: 20 63 68 65 63 6b 20 69 6e 20 63 61 73 65 20 74 check in case t
79c0: 68 65 20 56 46 53 20 64 72 69 76 65 72 20 63 61 he VFS driver ca
79d0: 75 73 65 64 20 73 68 61 72 69 6e 67 20 2a 2f 0a used sharing */.
79e0: 09 09 69 66 20 28 54 63 6c 5f 49 73 53 68 61 72 ..if (Tcl_IsShar
79f0: 65 64 28 72 65 73 29 29 20 7b 0a 09 09 20 20 20 ed(res)) {...
7a00: 20 54 63 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 TclDecrRefCount
7a10: 28 72 65 73 29 3b 0a 09 09 20 20 20 20 72 65 73 (res);... res
7a20: 20 3d 20 54 63 6c 5f 44 75 70 6c 69 63 61 74 65 = Tcl_Duplicate
7a30: 4f 62 6a 28 72 65 73 29 3b 0a 09 09 20 20 20 20 Obj(res);...
7a40: 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 Tcl_IncrRefCount
7a50: 28 72 65 73 29 3b 0a 09 09 7d 0a 09 20 20 20 20 (res);...}..
7a60: 7d 0a 0a 09 20 20 20 20 69 66 20 28 6c 65 6e 67 }... if (leng
7a70: 74 68 20 3e 20 30 20 26 26 20 70 74 72 5b 6c 65 th > 0 && ptr[le
7a80: 6e 67 74 68 20 2d 31 5d 20 21 3d 20 27 2f 27 29 ngth -1] != '/')
7a90: 20 7b 0a 09 09 54 63 6c 5f 41 70 70 65 6e 64 54 {...Tcl_AppendT
7aa0: 6f 4f 62 6a 28 72 65 73 2c 20 26 73 65 70 61 72 oObj(res, &separ
7ab0: 61 74 6f 72 2c 20 31 29 3b 0a 09 09 54 63 6c 5f ator, 1);...Tcl_
7ac0: 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a GetStringFromObj
7ad0: 28 72 65 73 2c 20 26 6c 65 6e 67 74 68 29 3b 0a (res, &length);.
7ae0: 09 20 20 20 20 7d 0a 09 20 20 20 20 54 63 6c 5f . }.. Tcl_
7af0: 53 65 74 4f 62 6a 4c 65 6e 67 74 68 28 72 65 73 SetObjLength(res
7b00: 2c 20 6c 65 6e 67 74 68 20 2b 20 28 69 6e 74 29 , length + (int)
7b10: 20 73 74 72 6c 65 6e 28 73 74 72 45 6c 74 29 29 strlen(strElt))
7b20: 3b 0a 0a 09 20 20 20 20 70 74 72 20 3d 20 54 63 ;... ptr = Tc
7b30: 6c 47 65 74 53 74 72 69 6e 67 28 72 65 73 29 20 lGetString(res)
7b40: 2b 20 6c 65 6e 67 74 68 3b 0a 09 20 20 20 20 66 + length;.. f
7b50: 6f 72 20 28 3b 20 2a 73 74 72 45 6c 74 20 21 3d or (; *strElt !=
7b60: 20 27 5c 30 27 3b 20 73 74 72 45 6c 74 2b 2b 29 '\0'; strElt++)
7b70: 20 7b 0a 09 09 69 66 20 28 2a 73 74 72 45 6c 74 {...if (*strElt
7b80: 20 3d 3d 20 73 65 70 61 72 61 74 6f 72 29 20 7b == separator) {
7b90: 0a 09 09 20 20 20 20 77 68 69 6c 65 20 28 73 74 ... while (st
7ba0: 72 45 6c 74 5b 31 5d 20 3d 3d 20 73 65 70 61 72 rElt[1] == separ
7bb0: 61 74 6f 72 29 20 7b 0a 09 09 09 73 74 72 45 6c ator) {....strEl
7bc0: 74 2b 2b 3b 0a 09 09 20 20 20 20 7d 0a 09 09 20 t++;... }...
7bd0: 20 20 20 69 66 20 28 73 74 72 45 6c 74 5b 31 5d if (strElt[1]
7be0: 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09 09 09 69 != '\0') {....i
7bf0: 66 20 28 6e 65 65 64 73 53 65 70 29 20 7b 0a 09 f (needsSep) {..
7c00: 09 09 20 20 20 20 2a 70 74 72 2b 2b 20 3d 20 73 .. *ptr++ = s
7c10: 65 70 61 72 61 74 6f 72 3b 0a 09 09 09 7d 0a 09 eparator;....}..
7c20: 09 20 20 20 20 7d 0a 09 09 7d 20 65 6c 73 65 20 . }...} else
7c30: 7b 0a 09 09 20 20 20 20 2a 70 74 72 2b 2b 20 3d {... *ptr++ =
7c40: 20 2a 73 74 72 45 6c 74 3b 0a 09 09 20 20 20 20 *strElt;...
7c50: 6e 65 65 64 73 53 65 70 20 3d 20 31 3b 0a 09 09 needsSep = 1;...
7c60: 7d 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 6c 65 }.. }.. le
7c70: 6e 67 74 68 20 3d 20 70 74 72 20 2d 20 54 63 6c ngth = ptr - Tcl
7c80: 47 65 74 53 74 72 69 6e 67 28 72 65 73 29 3b 0a GetString(res);.
7c90: 09 20 20 20 20 54 63 6c 5f 53 65 74 4f 62 6a 4c . Tcl_SetObjL
7ca0: 65 6e 67 74 68 28 72 65 73 2c 20 6c 65 6e 67 74 ength(res, lengt
7cb0: 68 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 h);..}. }.
7cc0: 20 61 73 73 65 72 74 20 28 20 72 65 73 20 21 3d assert ( res !=
7cd0: 20 4e 55 4c 4c 20 29 3b 0a 20 20 20 20 72 65 74 NULL );. ret
7ce0: 75 72 6e 20 72 65 73 3b 0a 7d 0a 0c 0a 2f 2a 0a urn res;.}.../*.
7cf0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *--------------
7d00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7d10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7d20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a -------------. *
7d40: 0a 20 2a 20 54 63 6c 5f 46 53 43 6f 6e 76 65 72 . * Tcl_FSConver
7d50: 74 54 6f 50 61 74 68 54 79 70 65 20 2d 2d 0a 20 tToPathType --.
7d60: 2a 0a 20 2a 09 54 68 69 73 20 66 75 6e 63 74 69 *. *.This functi
7d70: 6f 6e 20 74 72 69 65 73 20 74 6f 20 63 6f 6e 76 on tries to conv
7d80: 65 72 74 20 74 68 65 20 67 69 76 65 6e 20 54 63 ert the given Tc
7d90: 6c 5f 4f 62 6a 20 74 6f 20 61 20 76 61 6c 69 64 l_Obj to a valid
7da0: 20 54 63 6c 20 70 61 74 68 0a 20 2a 09 74 79 70 Tcl path. *.typ
7db0: 65 2c 20 74 61 6b 69 6e 67 20 61 63 63 6f 75 6e e, taking accoun
7dc0: 74 20 6f 66 20 74 68 65 20 66 61 63 74 20 74 68 t of the fact th
7dd0: 61 74 20 74 68 65 20 63 77 64 20 6d 61 79 20 68 at the cwd may h
7de0: 61 76 65 20 63 68 61 6e 67 65 64 20 65 76 65 6e ave changed even
7df0: 20 69 66 0a 20 2a 09 74 68 69 73 20 6f 62 6a 65 if. *.this obje
7e00: 63 74 20 69 73 20 61 6c 72 65 61 64 79 20 73 75 ct is already su
7e10: 70 70 6f 73 65 64 6c 79 20 6f 66 20 74 68 65 20 pposedly of the
7e20: 63 6f 72 72 65 63 74 20 74 79 70 65 2e 0a 20 2a correct type.. *
7e30: 0a 20 2a 09 54 68 65 20 66 69 6c 65 6e 61 6d 65 . *.The filename
7e40: 20 6d 61 79 20 62 65 67 69 6e 20 77 69 74 68 20 may begin with
7e50: 22 7e 22 20 28 74 6f 20 69 6e 64 69 63 61 74 65 "~" (to indicate
7e60: 20 63 75 72 72 65 6e 74 20 75 73 65 72 27 73 20 current user's
7e70: 68 6f 6d 65 0a 20 2a 09 64 69 72 65 63 74 6f 72 home. *.director
7e80: 79 29 20 6f 72 20 22 7e 3c 75 73 65 72 3e 22 20 y) or "~<user>"
7e90: 28 74 6f 20 69 6e 64 69 63 61 74 65 20 61 6e 79 (to indicate any
7ea0: 20 75 73 65 72 27 73 20 68 6f 6d 65 20 64 69 72 user's home dir
7eb0: 65 63 74 6f 72 79 29 2e 0a 20 2a 0a 20 2a 20 52 ectory).. *. * R
7ec0: 65 73 75 6c 74 73 3a 0a 20 2a 09 53 74 61 6e 64 esults:. *.Stand
7ed0: 61 72 64 20 54 63 6c 20 65 72 72 6f 72 20 63 6f ard Tcl error co
7ee0: 64 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 de.. *. * Side e
7ef0: 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65 20 6f ffects:. *.The o
7f00: 6c 64 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ld representatio
7f10: 6e 20 6d 61 79 20 62 65 20 66 72 65 65 64 2c 20 n may be freed,
7f20: 61 6e 64 20 6e 65 77 20 6d 65 6d 6f 72 79 20 61 and new memory a
7f30: 6c 6c 6f 63 61 74 65 64 2e 0a 20 2a 0a 20 2a 2d llocated.. *. *-
7f40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7f50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7f60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
7f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a ----------. */..
7f90: 69 6e 74 0a 54 63 6c 5f 46 53 43 6f 6e 76 65 72 int.Tcl_FSConver
7fa0: 74 54 6f 50 61 74 68 54 79 70 65 28 0a 20 20 20 tToPathType(.
7fb0: 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 Tcl_Interp *int
7fc0: 65 72 70 2c 09 09 2f 2a 20 49 6e 74 65 72 70 72 erp,../* Interpr
7fd0: 65 74 65 72 20 69 6e 20 77 68 69 63 68 20 74 6f eter in which to
7fe0: 20 73 74 6f 72 65 20 65 72 72 6f 72 20 6d 65 73 store error mes
7ff0: 73 61 67 65 0a 09 09 09 09 20 2a 20 28 69 66 20 sage..... * (if
8000: 6e 65 63 65 73 73 61 72 79 29 2e 20 2a 2f 0a 20 necessary). */.
8010: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 Tcl_Obj *path
8020: 50 74 72 29 09 09 2f 2a 20 4f 62 6a 65 63 74 20 Ptr)../* Object
8030: 74 6f 20 63 6f 6e 76 65 72 74 20 74 6f 20 61 20 to convert to a
8040: 76 61 6c 69 64 2c 20 63 75 72 72 65 6e 74 20 70 valid, current p
8050: 61 74 68 0a 09 09 09 09 20 2a 20 74 79 70 65 2e ath..... * type.
8060: 20 2a 2f 0a 7b 0a 20 20 20 20 2f 2a 0a 20 20 20 */.{. /*.
8070: 20 20 2a 20 57 68 69 6c 65 20 69 74 20 69 73 20 * While it is
8080: 62 61 64 20 70 72 61 63 74 69 63 65 20 74 6f 20 bad practice to
8090: 65 78 61 6d 69 6e 65 20 61 6e 20 6f 62 6a 65 63 examine an objec
80a0: 74 27 73 20 74 79 70 65 20 64 69 72 65 63 74 6c t's type directl
80b0: 79 2c 20 74 68 69 73 20 69 73 0a 20 20 20 20 20 y, this is.
80c0: 2a 20 61 63 74 75 61 6c 6c 79 20 74 68 65 20 62 * actually the b
80d0: 65 73 74 20 74 68 69 6e 67 20 74 6f 20 64 6f 20 est thing to do
80e0: 68 65 72 65 2e 20 54 68 65 20 72 65 61 73 6f 6e here. The reason
80f0: 20 69 73 20 74 68 61 74 20 69 66 20 77 65 20 61 is that if we a
8100: 72 65 0a 20 20 20 20 20 2a 20 63 6f 6e 76 65 72 re. * conver
8110: 74 69 6e 67 20 74 68 69 73 20 6f 62 6a 65 63 74 ting this object
8120: 20 74 6f 20 46 73 50 61 74 68 20 74 79 70 65 20 to FsPath type
8130: 66 6f 72 20 74 68 65 20 66 69 72 73 74 20 74 69 for the first ti
8140: 6d 65 2c 20 77 65 20 64 6f 6e 27 74 20 6e 65 65 me, we don't nee
8150: 64 0a 20 20 20 20 20 2a 20 74 6f 20 77 6f 72 72 d. * to worr
8160: 79 20 77 68 65 74 68 65 72 20 74 68 65 20 27 63 y whether the 'c
8170: 77 64 27 20 68 61 73 20 63 68 61 6e 67 65 64 2e wd' has changed.
8180: 20 4f 6e 20 74 68 65 20 6f 74 68 65 72 20 68 61 On the other ha
8190: 6e 64 2c 20 69 66 20 74 68 69 73 0a 20 20 20 20 nd, if this.
81a0: 20 2a 20 6f 62 6a 65 63 74 20 69 73 20 61 6c 72 * object is alr
81b0: 65 61 64 79 20 6f 66 20 46 73 50 61 74 68 20 74 eady of FsPath t
81c0: 79 70 65 2c 20 61 6e 64 20 69 73 20 61 20 72 65 ype, and is a re
81d0: 6c 61 74 69 76 65 20 70 61 74 68 2c 20 77 65 20 lative path, we
81e0: 64 6f 20 68 61 76 65 20 74 6f 0a 20 20 20 20 20 do have to.
81f0: 2a 20 77 6f 72 72 79 20 61 62 6f 75 74 20 74 68 * worry about th
8200: 65 20 63 77 64 2e 20 49 66 20 74 68 65 20 63 77 e cwd. If the cw
8210: 64 20 68 61 73 20 63 68 61 6e 67 65 64 2c 20 77 d has changed, w
8220: 65 20 6d 75 73 74 20 72 65 63 6f 6d 70 75 74 65 e must recompute
8230: 20 74 68 65 0a 20 20 20 20 20 2a 20 70 61 74 68 the. * path
8240: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 69 .. */.. i
8250: 66 20 28 70 61 74 68 50 74 72 2d 3e 74 79 70 65 f (pathPtr->type
8260: 50 74 72 20 3d 3d 20 26 74 63 6c 46 73 50 61 74 Ptr == &tclFsPat
8270: 68 54 79 70 65 29 20 7b 0a 09 69 66 20 28 54 63 hType) {..if (Tc
8280: 6c 46 53 45 70 6f 63 68 4f 6b 28 50 41 54 48 4f lFSEpochOk(PATHO
8290: 42 4a 28 70 61 74 68 50 74 72 29 2d 3e 66 69 6c BJ(pathPtr)->fil
82a0: 65 73 79 73 74 65 6d 45 70 6f 63 68 29 29 20 7b esystemEpoch)) {
82b0: 0a 09 20 20 20 20 72 65 74 75 72 6e 20 54 43 4c .. return TCL
82c0: 5f 4f 4b 3b 0a 09 7d 0a 0a 09 69 66 20 28 70 61 _OK;..}...if (pa
82d0: 74 68 50 74 72 2d 3e 62 79 74 65 73 20 3d 3d 20 thPtr->bytes ==
82e0: 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 55 70 64 NULL) {.. Upd
82f0: 61 74 65 53 74 72 69 6e 67 4f 66 46 73 50 61 74 ateStringOfFsPat
8300: 68 28 70 61 74 68 50 74 72 29 3b 0a 09 7d 0a 09 h(pathPtr);..}..
8310: 46 72 65 65 46 73 50 61 74 68 49 6e 74 65 72 6e FreeFsPathIntern
8320: 61 6c 52 65 70 28 70 61 74 68 50 74 72 29 3b 0a alRep(pathPtr);.
8330: 20 20 20 20 7d 0a 0a 20 20 20 20 72 65 74 75 72 }.. retur
8340: 6e 20 53 65 74 46 73 50 61 74 68 46 72 6f 6d 41 n SetFsPathFromA
8350: 6e 79 28 69 6e 74 65 72 70 2c 20 70 61 74 68 50 ny(interp, pathP
8360: 74 72 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 tr);.. /*.
8370: 20 20 2a 20 57 65 20 75 73 65 64 20 74 6f 20 68 * We used to h
8380: 61 76 65 20 6d 6f 72 65 20 63 6f 6d 70 6c 65 78 ave more complex
8390: 20 63 6f 64 65 20 68 65 72 65 3a 0a 20 20 20 20 code here:.
83a0: 20 2a 0a 20 20 20 20 20 2a 20 46 73 50 61 74 68 *. * FsPath
83b0: 20 2a 66 73 50 61 74 68 50 74 72 20 3d 20 50 41 *fsPathPtr = PA
83c0: 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b 0a THOBJ(pathPtr);.
83d0: 20 20 20 20 20 2a 20 69 66 20 28 66 73 50 61 74 * if (fsPat
83e0: 68 50 74 72 2d 3e 63 77 64 50 74 72 20 3d 3d 20 hPtr->cwdPtr ==
83f0: 4e 55 4c 4c 20 7c 7c 20 50 41 54 48 46 4c 41 47 NULL || PATHFLAG
8400: 53 28 70 61 74 68 50 74 72 29 20 21 3d 20 30 29 S(pathPtr) != 0)
8410: 20 7b 0a 20 20 20 20 20 2a 20 20 20 20 20 72 65 {. * re
8420: 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 20 20 20 turn TCL_OK;.
8430: 20 20 2a 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 * } else {.
8440: 20 20 2a 20 20 20 20 20 69 66 20 28 54 63 6c 46 * if (TclF
8450: 53 43 77 64 50 6f 69 6e 74 65 72 45 71 75 61 6c SCwdPointerEqual
8460: 73 28 26 66 73 50 61 74 68 50 74 72 2d 3e 63 77 s(&fsPathPtr->cw
8470: 64 50 74 72 29 29 20 7b 0a 20 20 20 20 20 2a 20 dPtr)) {. *
8480: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 54 return T
8490: 43 4c 5f 4f 4b 3b 0a 20 20 20 20 20 2a 20 20 20 CL_OK;. *
84a0: 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20 20 } else {.
84b0: 2a 20 20 20 20 20 20 20 20 20 69 66 20 28 70 61 * if (pa
84c0: 74 68 50 74 72 2d 3e 62 79 74 65 73 20 3d 3d 20 thPtr->bytes ==
84d0: 4e 55 4c 4c 29 20 7b 0a 20 20 20 20 20 2a 20 20 NULL) {. *
84e0: 20 20 20 20 20 20 20 20 20 20 20 55 70 64 61 74 Updat
84f0: 65 53 74 72 69 6e 67 4f 66 46 73 50 61 74 68 28 eStringOfFsPath(
8500: 70 61 74 68 50 74 72 29 3b 0a 20 20 20 20 20 2a pathPtr);. *
8510: 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 }.
8520: 2a 20 20 20 20 20 20 20 20 20 46 72 65 65 46 73 * FreeFs
8530: 50 61 74 68 49 6e 74 65 72 6e 61 6c 52 65 70 28 PathInternalRep(
8540: 70 61 74 68 50 74 72 29 3b 0a 20 20 20 20 20 2a pathPtr);. *
8550: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
8560: 54 63 6c 5f 43 6f 6e 76 65 72 74 54 6f 54 79 70 Tcl_ConvertToTyp
8570: 65 28 69 6e 74 65 72 70 2c 20 70 61 74 68 50 74 e(interp, pathPt
8580: 72 2c 20 26 74 63 6c 46 73 50 61 74 68 54 79 70 r, &tclFsPathTyp
8590: 65 29 3b 0a 20 20 20 20 20 2a 20 20 20 20 20 7d e);. * }
85a0: 0a 20 20 20 20 20 2a 20 7d 0a 20 20 20 20 20 2a . * }. *
85b0: 0a 20 20 20 20 20 2a 20 42 75 74 20 77 65 20 6e . * But we n
85c0: 6f 20 6c 6f 6e 67 65 72 20 62 65 6c 69 65 76 65 o longer believe
85d0: 20 74 68 69 73 20 69 73 20 6e 65 63 65 73 73 61 this is necessa
85e0: 72 79 2e 0a 20 20 20 20 20 2a 2f 0a 7d 0a 0c 0a ry.. */.}...
85f0: 2f 2a 0a 20 2a 20 48 65 6c 70 65 72 20 66 75 6e /*. * Helper fun
8600: 63 74 69 6f 6e 20 66 6f 72 20 6e 6f 72 6d 61 6c ction for normal
8610: 69 7a 61 74 69 6f 6e 2e 0a 20 2a 2f 0a 0a 73 74 ization.. */..st
8620: 61 74 69 63 20 69 6e 74 0a 49 73 53 65 70 61 72 atic int.IsSepar
8630: 61 74 6f 72 4f 72 4e 75 6c 6c 28 0a 20 20 20 20 atorOrNull(.
8640: 69 6e 74 20 63 68 29 0a 7b 0a 20 20 20 20 69 66 int ch).{. if
8650: 20 28 63 68 20 3d 3d 20 30 29 20 7b 0a 09 72 65 (ch == 0) {..re
8660: 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 turn 1;. }.
8670: 20 20 73 77 69 74 63 68 20 28 74 63 6c 50 6c 61 switch (tclPla
8680: 74 66 6f 72 6d 29 20 7b 0a 20 20 20 20 63 61 73 tform) {. cas
8690: 65 20 54 43 4c 5f 50 4c 41 54 46 4f 52 4d 5f 55 e TCL_PLATFORM_U
86a0: 4e 49 58 3a 0a 09 72 65 74 75 72 6e 20 28 63 68 NIX:..return (ch
86b0: 20 3d 3d 20 27 2f 27 20 3f 20 31 20 3a 20 30 29 == '/' ? 1 : 0)
86c0: 3b 0a 20 20 20 20 63 61 73 65 20 54 43 4c 5f 50 ;. case TCL_P
86d0: 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 4f 57 53 3a LATFORM_WINDOWS:
86e0: 0a 09 72 65 74 75 72 6e 20 28 28 63 68 20 3d 3d ..return ((ch ==
86f0: 20 27 2f 27 20 7c 7c 20 63 68 20 3d 3d 20 27 5c '/' || ch == '\
8700: 5c 27 29 20 3f 20 31 20 3a 20 30 29 3b 0a 20 20 \') ? 1 : 0);.
8710: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 30 }. return 0
8720: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 48 65 6c 70 ;.}.../*. * Help
8730: 65 72 20 66 75 6e 63 74 69 6f 6e 20 66 6f 72 20 er function for
8740: 53 65 74 46 73 50 61 74 68 46 72 6f 6d 41 6e 79 SetFsPathFromAny
8750: 2e 20 52 65 74 75 72 6e 73 20 70 6f 73 69 74 69 . Returns positi
8760: 6f 6e 20 6f 66 20 66 69 72 73 74 20 64 69 72 65 on of first dire
8770: 63 74 6f 72 79 0a 20 2a 20 64 65 6c 69 6d 69 74 ctory. * delimit
8780: 65 72 20 69 6e 20 74 68 65 20 70 61 74 68 2e 20 er in the path.
8790: 49 66 20 6e 6f 20 73 65 70 61 72 61 74 6f 72 20 If no separator
87a0: 69 73 20 66 6f 75 6e 64 2c 20 74 68 65 6e 20 72 is found, then r
87b0: 65 74 75 72 6e 73 20 74 68 65 20 70 6f 73 69 74 eturns the posit
87c0: 69 6f 6e 0a 20 2a 20 6f 66 20 74 68 65 20 65 6e ion. * of the en
87d0: 64 20 6f 66 20 74 68 65 20 73 74 72 69 6e 67 2e d of the string.
87e0: 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 . */..static int
87f0: 0a 46 69 6e 64 53 70 6c 69 74 50 6f 73 28 0a 20 .FindSplitPos(.
8800: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 const char *p
8810: 61 74 68 2c 0a 20 20 20 20 69 6e 74 20 73 65 70 ath,. int sep
8820: 61 72 61 74 6f 72 29 0a 7b 0a 20 20 20 20 69 6e arator).{. in
8830: 74 20 63 6f 75 6e 74 20 3d 20 30 3b 0a 20 20 20 t count = 0;.
8840: 20 73 77 69 74 63 68 20 28 74 63 6c 50 6c 61 74 switch (tclPlat
8850: 66 6f 72 6d 29 20 7b 0a 20 20 20 20 63 61 73 65 form) {. case
8860: 20 54 43 4c 5f 50 4c 41 54 46 4f 52 4d 5f 55 4e TCL_PLATFORM_UN
8870: 49 58 3a 0a 09 77 68 69 6c 65 20 28 70 61 74 68 IX:..while (path
8880: 5b 63 6f 75 6e 74 5d 20 21 3d 20 30 29 20 7b 0a [count] != 0) {.
8890: 09 20 20 20 20 69 66 20 28 70 61 74 68 5b 63 6f . if (path[co
88a0: 75 6e 74 5d 20 3d 3d 20 73 65 70 61 72 61 74 6f unt] == separato
88b0: 72 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 63 6f r) {...return co
88c0: 75 6e 74 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 unt;.. }..
88d0: 20 63 6f 75 6e 74 2b 2b 3b 0a 09 7d 0a 09 62 72 count++;..}..br
88e0: 65 61 6b 3b 0a 0a 20 20 20 20 63 61 73 65 20 54 eak;.. case T
88f0: 43 4c 5f 50 4c 41 54 46 4f 52 4d 5f 57 49 4e 44 CL_PLATFORM_WIND
8900: 4f 57 53 3a 0a 09 77 68 69 6c 65 20 28 70 61 74 OWS:..while (pat
8910: 68 5b 63 6f 75 6e 74 5d 20 21 3d 20 30 29 20 7b h[count] != 0) {
8920: 0a 09 20 20 20 20 69 66 20 28 70 61 74 68 5b 63 .. if (path[c
8930: 6f 75 6e 74 5d 20 3d 3d 20 73 65 70 61 72 61 74 ount] == separat
8940: 6f 72 20 7c 7c 20 70 61 74 68 5b 63 6f 75 6e 74 or || path[count
8950: 5d 20 3d 3d 20 27 5c 5c 27 29 20 7b 0a 09 09 72 ] == '\\') {...r
8960: 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 09 20 20 eturn count;..
8970: 20 20 7d 0a 09 20 20 20 20 63 6f 75 6e 74 2b 2b }.. count++
8980: 3b 0a 09 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 ;..}..break;.
8990: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 63 6f }. return co
89a0: 75 6e 74 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d unt;.}.../*. *--
89b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
89c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
89d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
89e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
89f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 ---------. *. *
8a00: 54 63 6c 4e 65 77 46 53 50 61 74 68 4f 62 6a 20 TclNewFSPathObj
8a10: 2d 2d 0a 20 2a 0a 20 2a 09 43 72 65 61 74 65 73 --. *. *.Creates
8a20: 20 61 20 70 61 74 68 20 6f 62 6a 65 63 74 20 77 a path object w
8a30: 68 6f 73 65 20 73 74 72 69 6e 67 20 72 65 70 72 hose string repr
8a40: 65 73 65 6e 74 61 74 69 6f 6e 20 69 73 20 27 5b esentation is '[
8a50: 66 69 6c 65 20 6a 6f 69 6e 0a 20 2a 09 64 69 72 file join. *.dir
8a60: 50 74 72 20 61 64 64 53 74 72 52 65 70 5d 27 2c Ptr addStrRep]',
8a70: 20 62 75 74 20 64 6f 65 73 20 73 6f 20 69 6e 20 but does so in
8a80: 61 20 77 61 79 20 74 68 61 74 20 61 6c 6c 6f 77 a way that allow
8a90: 73 20 66 6f 72 20 6d 6f 72 65 0a 20 2a 09 65 66 s for more. *.ef
8aa0: 66 69 63 69 65 6e 74 20 63 72 65 61 74 69 6f 6e ficient creation
8ab0: 20 61 6e 64 20 63 61 63 68 69 6e 67 20 6f 66 20 and caching of
8ac0: 6e 6f 72 6d 61 6c 69 7a 65 64 20 70 61 74 68 73 normalized paths
8ad0: 2c 20 61 6e 64 20 6d 6f 72 65 20 65 66 66 69 63 , and more effic
8ae0: 69 65 6e 74 0a 20 2a 09 27 66 69 6c 65 20 64 69 ient. *.'file di
8af0: 72 6e 61 6d 65 27 2c 20 27 66 69 6c 65 20 74 61 rname', 'file ta
8b00: 69 6c 27 2c 20 65 74 63 2e 0a 20 2a 0a 20 2a 20 il', etc.. *. *
8b10: 41 73 73 75 6d 70 74 69 6f 6e 73 3a 0a 20 2a 09 Assumptions:. *.
8b20: 27 64 69 72 50 74 72 27 20 6d 75 73 74 20 62 65 'dirPtr' must be
8b30: 20 61 6e 20 61 62 73 6f 6c 75 74 65 20 70 61 74 an absolute pat
8b40: 68 2e 20 27 6c 65 6e 27 20 6d 61 79 20 6e 6f 74 h. 'len' may not
8b50: 20 62 65 20 7a 65 72 6f 2e 0a 20 2a 0a 20 2a 20 be zero.. *. *
8b60: 52 65 73 75 6c 74 73 3a 0a 20 2a 09 54 68 65 20 Results:. *.The
8b70: 6e 65 77 20 54 63 6c 20 6f 62 6a 65 63 74 2c 20 new Tcl object,
8b80: 77 69 74 68 20 72 65 66 43 6f 75 6e 74 20 7a 65 with refCount ze
8b90: 72 6f 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 ro.. *. * Side e
8ba0: 66 66 65 63 74 73 3a 0a 20 2a 09 4d 65 6d 6f 72 ffects:. *.Memor
8bb0: 79 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 2e 20 y is allocated.
8bc0: 27 64 69 72 50 74 72 27 20 67 65 74 73 20 61 6e 'dirPtr' gets an
8bd0: 20 61 64 64 69 74 69 6f 6e 61 6c 20 72 65 66 43 additional refC
8be0: 6f 75 6e 74 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d ount.. *. *-----
8bf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
8c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
8c10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
8c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
8c30: 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 54 63 6c 5f ------. */..Tcl_
8c40: 4f 62 6a 20 2a 0a 54 63 6c 4e 65 77 46 53 50 61 Obj *.TclNewFSPa
8c50: 74 68 4f 62 6a 28 0a 20 20 20 20 54 63 6c 5f 4f thObj(. Tcl_O
8c60: 62 6a 20 2a 64 69 72 50 74 72 2c 0a 20 20 20 20 bj *dirPtr,.
8c70: 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 64 64 53 const char *addS
8c80: 74 72 52 65 70 2c 0a 20 20 20 20 69 6e 74 20 6c trRep,. int l
8c90: 65 6e 29 0a 7b 0a 20 20 20 20 46 73 50 61 74 68 en).{. FsPath
8ca0: 20 2a 66 73 50 61 74 68 50 74 72 3b 0a 20 20 20 *fsPathPtr;.
8cb0: 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 Tcl_Obj *pathPt
8cc0: 72 3b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 r;. const cha
8cd0: 72 20 2a 70 3b 0a 20 20 20 20 69 6e 74 20 73 74 r *p;. int st
8ce0: 61 74 65 20 3d 20 30 2c 20 63 6f 75 6e 74 20 3d ate = 0, count =
8cf0: 20 30 3b 0a 0a 20 20 20 20 2f 2a 20 5b 42 75 67 0;.. /* [Bug
8d00: 20 32 38 30 36 32 35 30 5d 20 2d 20 74 68 69 73 2806250] - this
8d10: 20 69 73 20 6f 6e 6c 79 20 61 20 70 61 72 74 69 is only a parti
8d20: 61 6c 20 73 6f 6c 75 74 69 6f 6e 20 6f 66 20 74 al solution of t
8d30: 68 65 20 70 72 6f 62 6c 65 6d 2e 0a 20 20 20 20 he problem..
8d40: 20 2a 20 54 68 65 20 50 41 54 48 46 4c 41 47 53 * The PATHFLAGS
8d50: 20 21 3d 20 30 20 72 65 70 72 65 73 65 6e 74 61 != 0 representa
8d60: 74 69 6f 6e 20 61 73 73 75 6d 65 73 20 69 6e 20 tion assumes in
8d70: 6d 61 6e 79 20 70 6c 61 63 65 73 20 74 68 61 74 many places that
8d80: 0a 20 20 20 20 20 2a 20 74 68 65 20 22 74 61 69 . * the "tai
8d90: 6c 22 20 70 61 72 74 20 73 74 6f 72 65 64 20 69 l" part stored i
8da0: 6e 20 74 68 65 20 6e 6f 72 6d 50 61 74 68 50 74 n the normPathPt
8db0: 72 20 66 69 65 6c 64 20 69 73 20 69 74 73 65 6c r field is itsel
8dc0: 66 20 61 0a 20 20 20 20 20 2a 20 72 65 6c 61 74 f a. * relat
8dd0: 69 76 65 20 70 61 74 68 2e 20 20 53 74 72 69 6e ive path. Strin
8de0: 67 73 20 74 68 61 74 20 62 65 67 69 6e 20 77 69 gs that begin wi
8df0: 74 68 20 22 7e 22 20 61 72 65 20 6e 6f 74 20 72 th "~" are not r
8e00: 65 6c 61 74 69 76 65 20 70 61 74 68 73 2c 0a 20 elative paths,.
8e10: 20 20 20 20 2a 20 73 6f 20 77 65 20 6d 75 73 74 * so we must
8e20: 20 70 72 65 76 65 6e 74 20 74 68 65 69 72 20 73 prevent their s
8e30: 74 6f 72 61 67 65 20 69 6e 20 74 68 65 20 6e 6f torage in the no
8e40: 72 6d 50 61 74 68 50 74 72 20 66 69 65 6c 64 2e rmPathPtr field.
8e50: 0a 20 20 20 20 20 2a 0a 20 20 20 20 20 2a 20 4d . *. * M
8e60: 6f 72 65 20 67 65 6e 65 72 61 6c 6c 79 20 77 65 ore generally we
8e70: 20 6f 75 67 68 74 20 74 6f 20 62 65 20 74 65 73 ought to be tes
8e80: 74 69 6e 67 20 22 61 64 64 53 74 72 52 65 70 22 ting "addStrRep"
8e90: 20 66 6f 72 20 61 6e 79 20 76 61 6c 75 65 0a 20 for any value.
8ea0: 20 20 20 20 2a 20 74 68 61 74 20 69 73 20 6e 6f * that is no
8eb0: 74 20 61 20 72 65 6c 61 74 69 76 65 20 70 61 74 t a relative pat
8ec0: 68 2c 20 62 75 74 20 69 6e 20 61 6e 20 75 6e 63 h, but in an unc
8ed0: 6f 6e 73 74 72 61 69 6e 65 64 20 56 46 53 20 77 onstrained VFS w
8ee0: 6f 72 6c 64 0a 20 20 20 20 20 2a 20 74 68 61 74 orld. * that
8ef0: 20 63 6f 75 6c 64 20 62 65 20 6a 75 73 74 20 61 could be just a
8f00: 62 6f 75 74 20 61 6e 79 74 68 69 6e 67 2c 20 61 bout anything, a
8f10: 6e 64 20 74 65 73 74 69 6e 67 20 63 6f 75 6c 64 nd testing could
8f20: 20 62 65 20 65 78 70 65 6e 73 69 76 65 2e 0a 20 be expensive..
8f30: 20 20 20 20 2a 20 53 69 6e 63 65 20 74 68 69 73 * Since this
8f40: 20 72 6f 75 74 69 6e 65 20 70 6c 61 79 73 20 61 routine plays a
8f50: 20 62 69 67 20 72 6f 6c 65 20 69 6e 20 5b 67 6c big role in [gl
8f60: 6f 62 5d 2c 20 61 6e 79 74 68 69 6e 67 20 74 68 ob], anything th
8f70: 61 74 20 73 6c 6f 77 73 0a 20 20 20 20 20 2a 20 at slows. *
8f80: 69 74 20 64 6f 77 6e 20 77 6f 75 6c 64 20 62 65 it down would be
8f90: 20 75 6e 77 65 6c 63 6f 6d 65 2e 20 20 46 6f 72 unwelcome. For
8fa0: 20 6e 6f 77 2c 20 63 6f 6e 74 69 6e 75 65 20 74 now, continue t
8fb0: 68 65 20 72 69 73 6b 20 6f 66 20 66 75 72 74 68 he risk of furth
8fc0: 65 72 0a 20 20 20 20 20 2a 20 62 75 67 73 20 77 er. * bugs w
8fd0: 68 65 6e 20 73 6f 6d 65 20 54 63 6c 5f 46 69 6c hen some Tcl_Fil
8fe0: 65 73 79 73 74 65 6d 20 75 73 65 73 20 6f 74 68 esystem uses oth
8ff0: 65 72 77 69 73 65 20 72 65 6c 61 74 69 76 65 20 erwise relative
9000: 70 61 74 68 20 73 74 72 69 6e 67 73 0a 20 20 20 path strings.
9010: 20 20 2a 20 61 73 20 61 62 73 6f 6c 75 74 65 20 * as absolute
9020: 70 61 74 68 20 73 74 72 69 6e 67 73 2e 20 20 53 path strings. S
9030: 65 6e 73 69 62 6c 65 20 54 63 6c 5f 46 69 6c 65 ensible Tcl_File
9040: 73 79 73 74 65 6d 73 20 77 69 6c 6c 20 61 76 6f systems will avo
9050: 69 64 0a 20 20 20 20 20 2a 20 74 68 61 74 20 62 id. * that b
9060: 79 20 6d 6f 75 6e 74 69 6e 67 20 6f 6e 20 70 61 y mounting on pa
9070: 74 68 20 70 72 65 66 69 78 65 73 20 6c 69 6b 65 th prefixes like
9080: 20 66 6f 6f 3a 2f 2f 20 77 68 69 63 68 20 63 61 foo:// which ca
9090: 6e 6e 6f 74 20 62 65 20 74 68 65 0a 20 20 20 20 nnot be the.
90a0: 20 2a 20 6e 61 6d 65 20 6f 66 20 61 20 66 69 6c * name of a fil
90b0: 65 20 6f 72 20 64 69 72 65 63 74 6f 72 79 20 72 e or directory r
90c0: 65 61 64 20 66 72 6f 6d 20 61 20 6e 61 74 69 76 ead from a nativ
90d0: 65 20 5b 67 6c 6f 62 5d 20 6f 70 65 72 61 74 69 e [glob] operati
90e0: 6f 6e 2e 0a 20 20 20 20 20 2a 2f 0a 20 20 20 20 on.. */.
90f0: 69 66 20 28 61 64 64 53 74 72 52 65 70 5b 30 5d if (addStrRep[0]
9100: 20 3d 3d 20 27 7e 27 29 20 7b 0a 09 54 63 6c 5f == '~') {..Tcl_
9110: 4f 62 6a 20 2a 74 61 69 6c 20 3d 20 54 63 6c 5f Obj *tail = Tcl_
9120: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 61 64 64 NewStringObj(add
9130: 53 74 72 52 65 70 2c 20 6c 65 6e 29 3b 0a 0a 09 StrRep, len);...
9140: 70 61 74 68 50 74 72 20 3d 20 41 70 70 65 6e 64 pathPtr = Append
9150: 50 61 74 68 28 64 69 72 50 74 72 2c 20 74 61 69 Path(dirPtr, tai
9160: 6c 29 3b 0a 09 54 63 6c 5f 44 65 63 72 52 65 66 l);..Tcl_DecrRef
9170: 43 6f 75 6e 74 28 74 61 69 6c 29 3b 0a 09 72 65 Count(tail);..re
9180: 74 75 72 6e 20 70 61 74 68 50 74 72 3b 0a 20 20 turn pathPtr;.
9190: 20 20 7d 0a 0a 20 20 20 20 70 61 74 68 50 74 72 }.. pathPtr
91a0: 20 3d 20 54 63 6c 5f 4e 65 77 4f 62 6a 28 29 3b = Tcl_NewObj();
91b0: 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 20 3d . fsPathPtr =
91c0: 20 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 ckalloc(sizeof(
91d0: 46 73 50 61 74 68 29 29 3b 0a 0a 20 20 20 20 2f FsPath));.. /
91e0: 2a 0a 20 20 20 20 20 2a 20 53 65 74 20 75 70 20 *. * Set up
91f0: 74 68 65 20 70 61 74 68 2e 0a 20 20 20 20 20 2a the path.. *
9200: 2f 0a 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 /.. fsPathPtr
9210: 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 61 74 68 ->translatedPath
9220: 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 Ptr = NULL;.
9230: 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 fsPathPtr->normP
9240: 61 74 68 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 athPtr = Tcl_New
9250: 53 74 72 69 6e 67 4f 62 6a 28 61 64 64 53 74 72 StringObj(addStr
9260: 52 65 70 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 54 Rep, len);. T
9270: 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 cl_IncrRefCount(
9280: 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 fsPathPtr->normP
9290: 61 74 68 50 74 72 29 3b 0a 20 20 20 20 66 73 50 athPtr);. fsP
92a0: 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 20 3d athPtr->cwdPtr =
92b0: 20 64 69 72 50 74 72 3b 0a 20 20 20 20 54 63 6c dirPtr;. Tcl
92c0: 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 64 69 _IncrRefCount(di
92d0: 72 50 74 72 29 3b 0a 20 20 20 20 66 73 50 61 74 rPtr);. fsPat
92e0: 68 50 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 68 hPtr->nativePath
92f0: 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 Ptr = NULL;.
9300: 66 73 50 61 74 68 50 74 72 2d 3e 66 73 50 74 72 fsPathPtr->fsPtr
9310: 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 66 73 50 = NULL;. fsP
9320: 61 74 68 50 74 72 2d 3e 66 69 6c 65 73 79 73 74 athPtr->filesyst
9330: 65 6d 45 70 6f 63 68 20 3d 20 30 3b 0a 0a 20 20 emEpoch = 0;..
9340: 20 20 53 45 54 50 41 54 48 4f 42 4a 28 70 61 74 SETPATHOBJ(pat
9350: 68 50 74 72 2c 20 66 73 50 61 74 68 50 74 72 29 hPtr, fsPathPtr)
9360: 3b 0a 20 20 20 20 50 41 54 48 46 4c 41 47 53 28 ;. PATHFLAGS(
9370: 70 61 74 68 50 74 72 29 20 3d 20 54 43 4c 50 41 pathPtr) = TCLPA
9380: 54 48 5f 41 50 50 45 4e 44 45 44 3b 0a 20 20 20 TH_APPENDED;.
9390: 20 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 74 pathPtr->typePt
93a0: 72 20 3d 20 26 74 63 6c 46 73 50 61 74 68 54 79 r = &tclFsPathTy
93b0: 70 65 3b 0a 20 20 20 20 70 61 74 68 50 74 72 2d pe;. pathPtr-
93c0: 3e 62 79 74 65 73 20 3d 20 4e 55 4c 4c 3b 0a 20 >bytes = NULL;.
93d0: 20 20 20 70 61 74 68 50 74 72 2d 3e 6c 65 6e 67 pathPtr->leng
93e0: 74 68 20 3d 20 30 3b 0a 0a 20 20 20 20 2f 2a 0a th = 0;.. /*.
93f0: 20 20 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 * Look for
9400: 70 61 74 68 20 63 6f 6d 70 6f 6e 65 6e 74 73 20 path components
9410: 6d 61 64 65 20 75 70 20 6f 66 20 6f 6e 6c 79 20 made up of only
9420: 22 2e 22 0a 20 20 20 20 20 2a 20 54 68 69 73 20 ".". * This
9430: 69 73 20 6f 76 65 72 6c 79 20 63 6f 6e 73 65 72 is overly conser
9440: 76 61 74 69 76 65 20 61 6e 61 6c 79 73 69 73 20 vative analysis
9450: 74 6f 20 6b 65 65 70 20 73 69 6d 70 6c 65 2e 20 to keep simple.
9460: 49 74 20 6d 61 79 20 6d 61 72 6b 20 73 6f 6d 65 It may mark some
9470: 0a 20 20 20 20 20 2a 20 74 68 69 6e 67 73 20 61 . * things a
9480: 73 20 6e 65 65 64 69 6e 67 20 6d 6f 72 65 20 61 s needing more a
9490: 67 67 72 65 73 73 69 76 65 20 6e 6f 72 6d 61 6c ggressive normal
94a0: 69 7a 61 74 69 6f 6e 20 74 68 61 74 20 64 6f 6e ization that don
94b0: 27 74 20 61 63 74 75 61 6c 6c 79 0a 20 20 20 20 't actually.
94c0: 20 2a 20 6e 65 65 64 20 69 74 2e 20 4e 6f 20 68 * need it. No h
94d0: 61 72 6d 20 64 6f 6e 65 2e 0a 20 20 20 20 20 2a arm done.. *
94e0: 2f 0a 20 20 20 20 66 6f 72 20 28 70 20 3d 20 61 /. for (p = a
94f0: 64 64 53 74 72 52 65 70 3b 20 6c 65 6e 20 3e 20 ddStrRep; len >
9500: 30 3b 20 70 2b 2b 2c 20 6c 65 6e 2d 2d 29 20 7b 0; p++, len--) {
9510: 0a 09 73 77 69 74 63 68 20 28 73 74 61 74 65 29 ..switch (state)
9520: 20 7b 0a 09 63 61 73 65 20 30 3a 09 09 2f 2a 20 {..case 0:../*
9530: 53 6f 20 66 61 72 20 6f 6e 6c 79 20 22 2e 22 20 So far only "."
9540: 73 69 6e 63 65 20 6c 61 73 74 20 64 69 72 73 65 since last dirse
9550: 70 20 6f 72 20 73 74 61 72 74 20 2a 2f 0a 09 20 p or start */..
9560: 20 20 20 73 77 69 74 63 68 20 28 2a 70 29 20 7b switch (*p) {
9570: 0a 09 20 20 20 20 63 61 73 65 20 27 2e 27 3a 0a .. case '.':.
9580: 09 09 63 6f 75 6e 74 2b 2b 3b 0a 09 09 62 72 65 ..count++;...bre
9590: 61 6b 3b 0a 09 20 20 20 20 63 61 73 65 20 27 2f ak;.. case '/
95a0: 27 3a 0a 09 20 20 20 20 63 61 73 65 20 27 5c 5c ':.. case '\\
95b0: 27 3a 0a 09 20 20 20 20 63 61 73 65 20 27 3a 27 ':.. case ':'
95c0: 3a 0a 09 09 69 66 20 28 63 6f 75 6e 74 29 20 7b :...if (count) {
95d0: 0a 09 09 20 20 20 20 50 41 54 48 46 4c 41 47 53 ... PATHFLAGS
95e0: 28 70 61 74 68 50 74 72 29 20 7c 3d 20 54 43 4c (pathPtr) |= TCL
95f0: 50 41 54 48 5f 4e 45 45 44 4e 4f 52 4d 3b 0a 09 PATH_NEEDNORM;..
9600: 09 20 20 20 20 6c 65 6e 20 3d 20 30 3b 0a 09 09 . len = 0;...
9610: 7d 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 20 20 }...break;..
9620: 64 65 66 61 75 6c 74 3a 0a 09 09 63 6f 75 6e 74 default:...count
9630: 20 3d 20 30 3b 0a 09 09 73 74 61 74 65 20 3d 20 = 0;...state =
9640: 31 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 62 1;.. }.. b
9650: 72 65 61 6b 3b 0a 09 63 61 73 65 20 31 3a 09 09 reak;..case 1:..
9660: 2f 2a 20 53 63 61 6e 6e 69 6e 67 20 66 6f 72 20 /* Scanning for
9670: 6e 65 78 74 20 64 69 72 73 65 70 20 2a 2f 0a 09 next dirsep */..
9680: 20 20 20 20 73 77 69 74 63 68 20 28 2a 70 29 20 switch (*p)
9690: 7b 0a 09 20 20 20 20 63 61 73 65 20 27 2f 27 3a {.. case '/':
96a0: 0a 09 20 20 20 20 63 61 73 65 20 27 5c 5c 27 3a .. case '\\':
96b0: 0a 09 20 20 20 20 63 61 73 65 20 27 3a 27 3a 0a .. case ':':.
96c0: 09 09 73 74 61 74 65 20 3d 20 30 3b 0a 09 09 62 ..state = 0;...b
96d0: 72 65 61 6b 3b 0a 09 20 20 20 20 7d 0a 09 7d 0a reak;.. }..}.
96e0: 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 6c 65 }. if (le
96f0: 6e 20 3d 3d 20 30 20 26 26 20 63 6f 75 6e 74 29 n == 0 && count)
9700: 20 7b 0a 09 50 41 54 48 46 4c 41 47 53 28 70 61 {..PATHFLAGS(pa
9710: 74 68 50 74 72 29 20 7c 3d 20 54 43 4c 50 41 54 thPtr) |= TCLPAT
9720: 48 5f 4e 45 45 44 4e 4f 52 4d 3b 0a 20 20 20 20 H_NEEDNORM;.
9730: 7d 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 70 61 }.. return pa
9740: 74 68 50 74 72 3b 0a 7d 0a 0a 73 74 61 74 69 63 thPtr;.}..static
9750: 20 54 63 6c 5f 4f 62 6a 20 2a 0a 41 70 70 65 6e Tcl_Obj *.Appen
9760: 64 50 61 74 68 28 0a 20 20 20 20 54 63 6c 5f 4f dPath(. Tcl_O
9770: 62 6a 20 2a 68 65 61 64 2c 0a 20 20 20 20 54 63 bj *head,. Tc
9780: 6c 5f 4f 62 6a 20 2a 74 61 69 6c 29 0a 7b 0a 20 l_Obj *tail).{.
9790: 20 20 20 69 6e 74 20 6e 75 6d 42 79 74 65 73 3b int numBytes;
97a0: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
97b0: 2a 62 79 74 65 73 3b 0a 20 20 20 20 54 63 6c 5f *bytes;. Tcl_
97c0: 4f 62 6a 20 2a 63 6f 70 79 20 3d 20 54 63 6c 5f Obj *copy = Tcl_
97d0: 44 75 70 6c 69 63 61 74 65 4f 62 6a 28 68 65 61 DuplicateObj(hea
97e0: 64 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 d);.. /*.
97f0: 20 2a 20 54 68 69 73 20 69 73 20 6c 69 6b 65 6c * This is likel
9800: 79 20 62 75 67 67 79 20 77 68 65 6e 20 64 65 61 y buggy when dea
9810: 6c 69 6e 67 20 77 69 74 68 20 76 69 72 74 75 61 ling with virtua
9820: 6c 20 66 69 6c 65 73 79 73 74 65 6d 20 64 72 69 l filesystem dri
9830: 76 65 72 73 0a 20 20 20 20 20 2a 20 74 68 61 74 vers. * that
9840: 20 75 73 65 20 73 6f 6d 65 20 63 68 61 72 61 63 use some charac
9850: 74 65 72 20 6f 74 68 65 72 20 74 68 61 6e 20 22 ter other than "
9860: 2f 22 20 61 73 20 61 20 70 61 74 68 20 73 65 70 /" as a path sep
9870: 61 72 61 74 6f 72 2e 20 20 49 20 6b 6e 6f 77 0a arator. I know.
9880: 20 20 20 20 20 2a 20 6f 66 20 6e 6f 20 65 76 69 * of no evi
9890: 64 65 6e 63 65 20 74 68 61 74 20 73 75 63 68 20 dence that such
98a0: 61 20 66 6f 6f 6c 69 73 68 20 74 68 69 6e 67 20 a foolish thing
98b0: 65 78 69 73 74 73 2e 20 20 54 68 69 73 20 73 6f exists. This so
98c0: 6c 75 74 69 6f 6e 20 77 61 73 0a 20 20 20 20 20 lution was.
98d0: 2a 20 63 68 6f 73 65 6e 20 73 6f 20 74 68 61 74 * chosen so that
98e0: 20 22 4a 6f 69 6e 50 61 74 68 22 20 6f 70 65 72 "JoinPath" oper
98f0: 61 74 69 6f 6e 73 20 74 68 61 74 20 70 61 73 73 ations that pass
9900: 20 74 68 72 6f 75 67 68 20 65 69 74 68 65 72 20 through either
9910: 70 61 74 68 0a 20 20 20 20 20 2a 20 69 6e 74 72 path. * intr
9920: 65 70 20 70 72 6f 64 75 63 65 20 74 68 65 20 73 ep produce the s
9930: 61 6d 65 20 72 65 73 75 6c 74 73 3b 20 74 68 61 ame results; tha
9940: 74 20 69 73 2c 20 62 75 67 77 61 72 64 20 63 6f t is, bugward co
9950: 6d 70 61 74 69 62 69 6c 69 74 79 2e 20 20 49 66 mpatibility. If
9960: 0a 20 20 20 20 20 2a 20 77 65 20 6e 65 65 64 20 . * we need
9970: 74 6f 20 66 69 78 20 74 68 61 74 20 62 75 67 20 to fix that bug
9980: 68 65 72 65 2c 20 69 74 20 6e 65 65 64 73 20 66 here, it needs f
9990: 69 78 69 6e 67 20 69 6e 20 54 63 6c 4a 6f 69 6e ixing in TclJoin
99a0: 50 61 74 68 28 29 20 74 6f 6f 2e 0a 20 20 20 20 Path() too..
99b0: 20 2a 2f 0a 20 20 20 20 62 79 74 65 73 20 3d 20 */. bytes =
99c0: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f Tcl_GetStringFro
99d0: 6d 4f 62 6a 28 74 61 69 6c 2c 20 26 6e 75 6d 42 mObj(tail, &numB
99e0: 79 74 65 73 29 3b 0a 20 20 20 20 69 66 20 28 6e ytes);. if (n
99f0: 75 6d 42 79 74 65 73 20 3d 3d 20 30 29 20 7b 0a umBytes == 0) {.
9a00: 09 54 63 6c 5f 41 70 70 65 6e 64 54 6f 4f 62 6a .Tcl_AppendToObj
9a10: 28 63 6f 70 79 2c 20 22 2f 22 2c 20 31 29 3b 0a (copy, "/", 1);.
9a20: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 54 63 } else {..Tc
9a30: 6c 70 4e 61 74 69 76 65 4a 6f 69 6e 50 61 74 68 lpNativeJoinPath
9a40: 28 63 6f 70 79 2c 20 62 79 74 65 73 29 3b 0a 20 (copy, bytes);.
9a50: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
9a60: 63 6f 70 79 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d copy;.}.../*. *-
9a70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9a80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9a90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a ----------. *. *
9ac0: 20 54 63 6c 46 53 4d 61 6b 65 50 61 74 68 52 65 TclFSMakePathRe
9ad0: 6c 61 74 69 76 65 20 2d 2d 0a 20 2a 0a 20 2a 09 lative --. *. *.
9ae0: 4f 6e 6c 79 20 66 6f 72 20 69 6e 74 65 72 6e 61 Only for interna
9af0: 6c 20 75 73 65 2e 0a 20 2a 0a 20 2a 09 54 61 6b l use.. *. *.Tak
9b00: 65 73 20 61 20 70 61 74 68 20 61 6e 64 20 61 20 es a path and a
9b10: 64 69 72 65 63 74 6f 72 79 2c 20 77 68 65 72 65 directory, where
9b20: 20 77 65 20 5f 61 73 73 75 6d 65 5f 20 62 6f 74 we _assume_ bot
9b30: 68 20 70 61 74 68 20 61 6e 64 0a 20 2a 09 64 69 h path and. *.di
9b40: 72 65 63 74 6f 72 79 20 61 72 65 20 61 62 73 6f rectory are abso
9b50: 6c 75 74 65 2c 20 6e 6f 72 6d 61 6c 69 7a 65 64 lute, normalized
9b60: 20 61 6e 64 20 74 68 61 74 20 74 68 65 20 70 61 and that the pa
9b70: 74 68 20 6c 69 65 73 20 69 6e 73 69 64 65 20 74 th lies inside t
9b80: 68 65 0a 20 2a 09 64 69 72 65 63 74 6f 72 79 2e he. *.directory.
9b90: 20 52 65 74 75 72 6e 73 20 61 20 54 63 6c 5f 4f Returns a Tcl_O
9ba0: 62 6a 20 72 65 70 72 65 73 65 6e 74 69 6e 67 20 bj representing
9bb0: 66 69 6c 65 6e 61 6d 65 20 6f 66 20 74 68 65 20 filename of the
9bc0: 70 61 74 68 0a 20 2a 09 72 65 6c 61 74 69 76 65 path. *.relative
9bd0: 20 74 6f 20 74 68 65 20 64 69 72 65 63 74 6f 72 to the director
9be0: 79 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 y.. *. * Results
9bf0: 3a 0a 20 2a 09 4e 55 4c 4c 20 6f 6e 20 65 72 72 :. *.NULL on err
9c00: 6f 72 2c 20 6f 74 68 65 72 77 69 73 65 20 61 20 or, otherwise a
9c10: 76 61 6c 69 64 20 6f 62 6a 65 63 74 2c 20 74 79 valid object, ty
9c20: 70 69 63 61 6c 6c 79 20 77 69 74 68 20 72 65 66 pically with ref
9c30: 43 6f 75 6e 74 20 6f 66 0a 20 2a 09 7a 65 72 6f Count of. *.zero
9c40: 2c 20 77 68 69 63 68 20 69 74 20 69 73 20 61 73 , which it is as
9c50: 73 75 6d 65 64 20 74 68 65 20 63 61 6c 6c 65 72 sumed the caller
9c60: 20 77 69 6c 6c 20 69 6e 63 72 65 6d 65 6e 74 2e will increment.
9c70: 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 . *. * Side effe
9c80: 63 74 73 3a 0a 20 2a 09 54 68 65 20 6f 6c 64 20 cts:. *.The old
9c90: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6d representation m
9ca0: 61 79 20 62 65 20 66 72 65 65 64 2c 20 61 6e 64 ay be freed, and
9cb0: 20 6e 65 77 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f new memory allo
9cc0: 63 61 74 65 64 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d cated.. *. *----
9cd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9ce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9cf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9d00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
9d10: 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 54 63 6c -------. */..Tcl
9d20: 5f 4f 62 6a 20 2a 0a 54 63 6c 46 53 4d 61 6b 65 _Obj *.TclFSMake
9d30: 50 61 74 68 52 65 6c 61 74 69 76 65 28 0a 20 20 PathRelative(.
9d40: 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e Tcl_Interp *in
9d50: 74 65 72 70 2c 09 09 2f 2a 20 55 73 65 64 20 66 terp,../* Used f
9d60: 6f 72 20 65 72 72 6f 72 20 72 65 70 6f 72 74 69 or error reporti
9d70: 6e 67 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 2e 20 ng if not NULL.
9d80: 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a */. Tcl_Obj *
9d90: 70 61 74 68 50 74 72 2c 09 09 2f 2a 20 54 68 65 pathPtr,../* The
9da0: 20 70 61 74 68 20 77 65 20 68 61 76 65 2e 20 2a path we have. *
9db0: 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 /. Tcl_Obj *c
9dc0: 77 64 50 74 72 29 09 09 2f 2a 20 4d 61 6b 65 20 wdPtr)../* Make
9dd0: 69 74 20 72 65 6c 61 74 69 76 65 20 74 6f 20 74 it relative to t
9de0: 68 69 73 2e 20 2a 2f 0a 7b 0a 20 20 20 20 69 6e his. */.{. in
9df0: 74 20 63 77 64 4c 65 6e 2c 20 6c 65 6e 3b 0a 20 t cwdLen, len;.
9e00: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 74 const char *t
9e10: 65 6d 70 53 74 72 3b 0a 0a 20 20 20 20 69 66 20 empStr;.. if
9e20: 28 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 74 (pathPtr->typePt
9e30: 72 20 3d 3d 20 26 74 63 6c 46 73 50 61 74 68 54 r == &tclFsPathT
9e40: 79 70 65 29 20 7b 0a 09 46 73 50 61 74 68 20 2a ype) {..FsPath *
9e50: 66 73 50 61 74 68 50 74 72 20 3d 20 50 41 54 48 fsPathPtr = PATH
9e60: 4f 42 4a 28 70 61 74 68 50 74 72 29 3b 0a 0a 09 OBJ(pathPtr);...
9e70: 69 66 20 28 50 41 54 48 46 4c 41 47 53 28 70 61 if (PATHFLAGS(pa
9e80: 74 68 50 74 72 29 20 21 3d 20 30 20 26 26 20 66 thPtr) != 0 && f
9e90: 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 sPathPtr->cwdPtr
9ea0: 20 3d 3d 20 63 77 64 50 74 72 29 20 7b 0a 09 20 == cwdPtr) {..
9eb0: 20 20 20 72 65 74 75 72 6e 20 66 73 50 61 74 68 return fsPath
9ec0: 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 Ptr->normPathPtr
9ed0: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 ;..}. }..
9ee0: 2f 2a 0a 20 20 20 20 20 2a 20 57 65 20 6b 6e 6f /*. * We kno
9ef0: 77 20 74 68 65 20 63 77 64 20 69 73 20 61 20 6e w the cwd is a n
9f00: 6f 72 6d 61 6c 69 73 65 64 20 6f 62 6a 65 63 74 ormalised object
9f10: 20 77 68 69 63 68 20 64 6f 65 73 20 6e 6f 74 20 which does not
9f20: 65 6e 64 20 69 6e 20 61 0a 20 20 20 20 20 2a 20 end in a. *
9f30: 64 69 72 65 63 74 6f 72 79 20 64 65 6c 69 6d 69 directory delimi
9f40: 74 65 72 2c 20 75 6e 6c 65 73 73 20 74 68 65 20 ter, unless the
9f50: 63 77 64 20 69 73 20 74 68 65 20 6e 61 6d 65 20 cwd is the name
9f60: 6f 66 20 61 20 76 6f 6c 75 6d 65 2c 20 69 6e 20 of a volume, in
9f70: 77 68 69 63 68 0a 20 20 20 20 20 2a 20 63 61 73 which. * cas
9f80: 65 20 69 74 20 77 69 6c 6c 20 65 6e 64 20 69 6e e it will end in
9f90: 20 61 20 64 65 6c 69 6d 69 74 65 72 21 20 57 65 a delimiter! We
9fa0: 20 68 61 6e 64 6c 65 20 74 68 69 73 20 73 69 74 handle this sit
9fb0: 75 61 74 69 6f 6e 20 68 65 72 65 2e 20 41 0a 20 uation here. A.
9fc0: 20 20 20 20 2a 20 62 65 74 74 65 72 20 74 65 73 * better tes
9fd0: 74 20 74 68 61 6e 20 74 68 65 20 27 21 3d 20 73 t than the '!= s
9fe0: 65 70 27 20 6d 69 67 68 74 20 62 65 20 74 6f 20 ep' might be to
9ff0: 73 69 6d 70 6c 79 20 63 68 65 63 6b 20 69 66 20 simply check if
a000: 27 63 77 64 27 20 69 73 20 61 0a 20 20 20 20 20 'cwd' is a.
a010: 2a 20 72 6f 6f 74 20 76 6f 6c 75 6d 65 2e 0a 20 * root volume..
a020: 20 20 20 20 2a 0a 20 20 20 20 20 2a 20 4e 6f 74 *. * Not
a030: 65 20 74 68 61 74 20 69 66 20 77 65 20 67 65 74 e that if we get
a040: 20 74 68 69 73 20 77 72 6f 6e 67 2c 20 77 65 20 this wrong, we
a050: 77 69 6c 6c 20 73 74 72 69 70 20 6f 66 66 20 65 will strip off e
a060: 69 74 68 65 72 20 74 6f 6f 20 6d 75 63 68 20 6f ither too much o
a070: 72 0a 20 20 20 20 20 2a 20 74 6f 6f 20 6c 69 74 r. * too lit
a080: 74 6c 65 20 62 65 6c 6f 77 2c 20 6c 65 61 64 69 tle below, leadi
a090: 6e 67 20 74 6f 20 77 72 6f 6e 67 20 61 6e 73 77 ng to wrong answ
a0a0: 65 72 73 20 72 65 74 75 72 6e 65 64 20 62 79 20 ers returned by
a0b0: 67 6c 6f 62 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 glob.. */..
a0c0: 20 20 20 74 65 6d 70 53 74 72 20 3d 20 54 63 6c tempStr = Tcl
a0d0: 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 _GetStringFromOb
a0e0: 6a 28 63 77 64 50 74 72 2c 20 26 63 77 64 4c 65 j(cwdPtr, &cwdLe
a0f0: 6e 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 n);.. /*.
a100: 20 2a 20 53 68 6f 75 6c 64 20 77 65 20 70 65 72 * Should we per
a110: 68 61 70 73 20 75 73 65 20 27 54 63 6c 5f 46 53 haps use 'Tcl_FS
a120: 50 61 74 68 53 65 70 61 72 61 74 6f 72 27 3f 20 PathSeparator'?
a130: 42 75 74 20 74 68 65 6e 20 77 68 61 74 20 61 62 But then what ab
a140: 6f 75 74 20 74 68 65 0a 20 20 20 20 20 2a 20 57 out the. * W
a150: 69 6e 64 6f 77 73 20 73 70 65 63 69 61 6c 20 63 indows special c
a160: 61 73 65 3f 20 50 65 72 68 61 70 73 20 77 65 20 ase? Perhaps we
a170: 73 68 6f 75 6c 64 20 6a 75 73 74 20 63 68 65 63 should just chec
a180: 6b 20 69 66 20 63 77 64 20 69 73 20 61 20 72 6f k if cwd is a ro
a190: 6f 74 0a 20 20 20 20 20 2a 20 76 6f 6c 75 6d 65 ot. * volume
a1a0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 73 .. */.. s
a1b0: 77 69 74 63 68 20 28 74 63 6c 50 6c 61 74 66 6f witch (tclPlatfo
a1c0: 72 6d 29 20 7b 0a 20 20 20 20 63 61 73 65 20 54 rm) {. case T
a1d0: 43 4c 5f 50 4c 41 54 46 4f 52 4d 5f 55 4e 49 58 CL_PLATFORM_UNIX
a1e0: 3a 0a 09 69 66 20 28 74 65 6d 70 53 74 72 5b 63 :..if (tempStr[c
a1f0: 77 64 4c 65 6e 2d 31 5d 20 21 3d 20 27 2f 27 29 wdLen-1] != '/')
a200: 20 7b 0a 09 20 20 20 20 63 77 64 4c 65 6e 2b 2b {.. cwdLen++
a210: 3b 0a 09 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 ;..}..break;.
a220: 20 63 61 73 65 20 54 43 4c 5f 50 4c 41 54 46 4f case TCL_PLATFO
a230: 52 4d 5f 57 49 4e 44 4f 57 53 3a 0a 09 69 66 20 RM_WINDOWS:..if
a240: 28 74 65 6d 70 53 74 72 5b 63 77 64 4c 65 6e 2d (tempStr[cwdLen-
a250: 31 5d 20 21 3d 20 27 2f 27 20 26 26 20 74 65 6d 1] != '/' && tem
a260: 70 53 74 72 5b 63 77 64 4c 65 6e 2d 31 5d 20 21 pStr[cwdLen-1] !
a270: 3d 20 27 5c 5c 27 29 20 7b 0a 09 20 20 20 20 63 = '\\') {.. c
a280: 77 64 4c 65 6e 2b 2b 3b 0a 09 7d 0a 09 62 72 65 wdLen++;..}..bre
a290: 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 74 65 ak;. }. te
a2a0: 6d 70 53 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 mpStr = Tcl_GetS
a2b0: 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 70 61 74 tringFromObj(pat
a2c0: 68 50 74 72 2c 20 26 6c 65 6e 29 3b 0a 0a 20 20 hPtr, &len);..
a2d0: 20 20 72 65 74 75 72 6e 20 54 63 6c 5f 4e 65 77 return Tcl_New
a2e0: 53 74 72 69 6e 67 4f 62 6a 28 74 65 6d 70 53 74 StringObj(tempSt
a2f0: 72 20 2b 20 63 77 64 4c 65 6e 2c 20 6c 65 6e 20 r + cwdLen, len
a300: 2d 20 63 77 64 4c 65 6e 29 3b 0a 7d 0a 0c 0a 2f - cwdLen);.}.../
a310: 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *. *------------
a320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a330: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a340: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a350: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
a360: 20 2a 0a 20 2a 20 4d 61 6b 65 50 61 74 68 46 72 *. * MakePathFr
a370: 6f 6d 4e 6f 72 6d 61 6c 69 7a 65 64 20 2d 2d 0a omNormalized --.
a380: 20 2a 0a 20 2a 09 4c 69 6b 65 20 53 65 74 46 73 *. *.Like SetFs
a390: 50 61 74 68 46 72 6f 6d 41 6e 79 2c 20 62 75 74 PathFromAny, but
a3a0: 20 61 73 73 75 6d 65 73 20 74 68 65 20 67 69 76 assumes the giv
a3b0: 65 6e 20 6f 62 6a 65 63 74 20 69 73 20 61 6e 20 en object is an
a3c0: 61 62 73 6f 6c 75 74 65 0a 20 2a 09 6e 6f 72 6d absolute. *.norm
a3d0: 61 6c 69 7a 65 64 20 70 61 74 68 2e 20 4f 6e 6c alized path. Onl
a3e0: 79 20 66 6f 72 20 69 6e 74 65 72 6e 61 6c 20 75 y for internal u
a3f0: 73 65 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 se.. *. * Result
a400: 73 3a 0a 20 2a 09 53 74 61 6e 64 61 72 64 20 54 s:. *.Standard T
a410: 63 6c 20 65 72 72 6f 72 20 63 6f 64 65 2e 0a 20 cl error code..
a420: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 *. * Side effect
a430: 73 3a 0a 20 2a 09 54 68 65 20 6f 6c 64 20 72 65 s:. *.The old re
a440: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6d 61 79 presentation may
a450: 20 62 65 20 66 72 65 65 64 2c 20 61 6e 64 20 6e be freed, and n
a460: 65 77 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 ew memory alloca
a470: 74 65 64 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d ted.. *. *------
a480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a490: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a4a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a4b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
a4c0: 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74 61 74 69 -----. */..stati
a4d0: 63 20 69 6e 74 0a 4d 61 6b 65 50 61 74 68 46 72 c int.MakePathFr
a4e0: 6f 6d 4e 6f 72 6d 61 6c 69 7a 65 64 28 0a 20 20 omNormalized(.
a4f0: 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e Tcl_Interp *in
a500: 74 65 72 70 2c 09 09 2f 2a 20 55 73 65 64 20 66 terp,../* Used f
a510: 6f 72 20 65 72 72 6f 72 20 72 65 70 6f 72 74 69 or error reporti
a520: 6e 67 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 2e 20 ng if not NULL.
a530: 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a */. Tcl_Obj *
a540: 70 61 74 68 50 74 72 29 09 09 2f 2a 20 54 68 65 pathPtr)../* The
a550: 20 6f 62 6a 65 63 74 20 74 6f 20 63 6f 6e 76 65 object to conve
a560: 72 74 2e 20 2a 2f 0a 7b 0a 20 20 20 20 46 73 50 rt. */.{. FsP
a570: 61 74 68 20 2a 66 73 50 61 74 68 50 74 72 3b 0a ath *fsPathPtr;.
a580: 0a 20 20 20 20 69 66 20 28 70 61 74 68 50 74 72 . if (pathPtr
a590: 2d 3e 74 79 70 65 50 74 72 20 3d 3d 20 26 74 63 ->typePtr == &tc
a5a0: 6c 46 73 50 61 74 68 54 79 70 65 29 20 7b 0a 09 lFsPathType) {..
a5b0: 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 20 return TCL_OK;.
a5c0: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 }.. /*.
a5d0: 20 20 2a 20 46 72 65 65 20 6f 6c 64 20 72 65 70 * Free old rep
a5e0: 72 65 73 65 6e 74 61 74 69 6f 6e 0a 20 20 20 20 resentation.
a5f0: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 70 61 74 */.. if (pat
a600: 68 50 74 72 2d 3e 74 79 70 65 50 74 72 20 21 3d hPtr->typePtr !=
a610: 20 4e 55 4c 4c 29 20 7b 0a 09 69 66 20 28 70 61 NULL) {..if (pa
a620: 74 68 50 74 72 2d 3e 62 79 74 65 73 20 3d 3d 20 thPtr->bytes ==
a630: 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 69 66 20 NULL) {.. if
a640: 28 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 74 (pathPtr->typePt
a650: 72 2d 3e 75 70 64 61 74 65 53 74 72 69 6e 67 50 r->updateStringP
a660: 72 6f 63 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 roc == NULL) {..
a670: 09 69 66 20 28 69 6e 74 65 72 70 20 21 3d 20 4e .if (interp != N
a680: 55 4c 4c 29 20 7b 0a 09 09 20 20 20 20 54 63 6c ULL) {... Tcl
a690: 5f 53 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e _SetObjResult(in
a6a0: 74 65 72 70 2c 20 54 63 6c 5f 4e 65 77 53 74 72 terp, Tcl_NewStr
a6b0: 69 6e 67 4f 62 6a 28 0a 09 09 09 20 20 20 20 22 ingObj(.... "
a6c0: 63 61 6e 27 74 20 66 69 6e 64 20 6f 62 6a 65 63 can't find objec
a6d0: 74 20 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 t string represe
a6e0: 6e 74 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a ntation", -1));.
a6f0: 09 09 20 20 20 20 54 63 6c 5f 53 65 74 45 72 72 .. Tcl_SetErr
a700: 6f 72 43 6f 64 65 28 69 6e 74 65 72 70 2c 20 22 orCode(interp, "
a710: 54 43 4c 22 2c 20 22 56 41 4c 55 45 22 2c 20 22 TCL", "VALUE", "
a720: 50 41 54 48 22 2c 20 22 57 54 46 22 2c 0a 09 09 PATH", "WTF",...
a730: 09 20 20 20 20 4e 55 4c 4c 29 3b 0a 09 09 7d 0a . NULL);...}.
a740: 09 09 72 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 ..return TCL_ERR
a750: 4f 52 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 OR;.. }..
a760: 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 74 72 pathPtr->typePtr
a770: 2d 3e 75 70 64 61 74 65 53 74 72 69 6e 67 50 72 ->updateStringPr
a780: 6f 63 28 70 61 74 68 50 74 72 29 3b 0a 09 7d 0a oc(pathPtr);..}.
a790: 09 54 63 6c 46 72 65 65 49 6e 74 52 65 70 28 70 .TclFreeIntRep(p
a7a0: 61 74 68 50 74 72 29 3b 0a 20 20 20 20 7d 0a 0a athPtr);. }..
a7b0: 20 20 20 20 66 73 50 61 74 68 50 74 72 20 3d 20 fsPathPtr =
a7c0: 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 46 ckalloc(sizeof(F
a7d0: 73 50 61 74 68 29 29 3b 0a 0a 20 20 20 20 2f 2a sPath));.. /*
a7e0: 0a 20 20 20 20 20 2a 20 49 74 27 73 20 61 20 70 . * It's a p
a7f0: 75 72 65 20 6e 6f 72 6d 61 6c 69 7a 65 64 20 61 ure normalized a
a800: 62 73 6f 6c 75 74 65 20 70 61 74 68 2e 0a 20 20 bsolute path..
a810: 20 20 20 2a 2f 0a 0a 20 20 20 20 66 73 50 61 74 */.. fsPat
a820: 68 50 74 72 2d 3e 74 72 61 6e 73 6c 61 74 65 64 hPtr->translated
a830: 50 61 74 68 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a PathPtr = NULL;.
a840: 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 . /*. * C
a850: 69 72 63 75 6c 61 72 20 72 65 66 65 72 65 6e 63 ircular referenc
a860: 65 20 62 79 20 64 65 73 69 67 6e 2e 0a 20 20 20 e by design..
a870: 20 20 2a 2f 0a 0a 20 20 20 20 66 73 50 61 74 68 */.. fsPath
a880: 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 Ptr->normPathPtr
a890: 20 3d 20 70 61 74 68 50 74 72 3b 0a 20 20 20 20 = pathPtr;.
a8a0: 66 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 fsPathPtr->cwdPt
a8b0: 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 66 73 r = NULL;. fs
a8c0: 50 61 74 68 50 74 72 2d 3e 6e 61 74 69 76 65 50 PathPtr->nativeP
a8d0: 61 74 68 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 athPtr = NULL;.
a8e0: 20 20 20 66 73 50 61 74 68 50 74 72 2d 3e 66 73 fsPathPtr->fs
a8f0: 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 Ptr = NULL;.
a900: 2f 2a 20 52 65 6d 65 6d 62 65 72 20 74 68 65 20 /* Remember the
a910: 65 70 6f 63 68 20 75 6e 64 65 72 20 77 68 69 63 epoch under whic
a920: 68 20 77 65 20 64 65 63 69 64 65 64 20 70 61 74 h we decided pat
a930: 68 50 74 72 20 77 61 73 20 6e 6f 72 6d 61 6c 69 hPtr was normali
a940: 7a 65 64 20 2a 2f 0a 20 20 20 20 66 73 50 61 74 zed */. fsPat
a950: 68 50 74 72 2d 3e 66 69 6c 65 73 79 73 74 65 6d hPtr->filesystem
a960: 45 70 6f 63 68 20 3d 20 54 63 6c 46 53 45 70 6f Epoch = TclFSEpo
a970: 63 68 28 29 3b 0a 0a 20 20 20 20 53 45 54 50 41 ch();.. SETPA
a980: 54 48 4f 42 4a 28 70 61 74 68 50 74 72 2c 20 66 THOBJ(pathPtr, f
a990: 73 50 61 74 68 50 74 72 29 3b 0a 20 20 20 20 50 sPathPtr);. P
a9a0: 41 54 48 46 4c 41 47 53 28 70 61 74 68 50 74 72 ATHFLAGS(pathPtr
a9b0: 29 20 3d 20 30 3b 0a 20 20 20 20 70 61 74 68 50 ) = 0;. pathP
a9c0: 74 72 2d 3e 74 79 70 65 50 74 72 20 3d 20 26 74 tr->typePtr = &t
a9d0: 63 6c 46 73 50 61 74 68 54 79 70 65 3b 0a 0a 20 clFsPathType;..
a9e0: 20 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b return TCL_OK
a9f0: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d ;.}.../*. *-----
aa00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
aa10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
aa20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
aa30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
aa40: 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63 6c ------. *. * Tcl
aa50: 5f 46 53 4e 65 77 4e 61 74 69 76 65 50 61 74 68 _FSNewNativePath
aa60: 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 66 --. *. *.This f
aa70: 75 6e 63 74 69 6f 6e 20 70 65 72 66 6f 72 6d 73 unction performs
aa80: 20 74 68 65 20 73 6f 6d 65 74 68 69 6e 67 20 6c the something l
aa90: 69 6b 65 20 74 68 65 20 72 65 76 65 72 73 65 20 ike the reverse
aaa0: 6f 66 20 74 68 65 20 75 73 75 61 6c 0a 20 2a 09 of the usual. *.
aab0: 6f 62 6a 2d 3e 70 61 74 68 2d 3e 6e 61 74 69 76 obj->path->nativ
aac0: 65 72 65 70 20 63 6f 6e 76 65 72 73 69 6f 6e 73 erep conversions
aad0: 2e 20 49 66 20 73 6f 6d 65 20 63 6f 64 65 20 72 . If some code r
aae0: 65 74 72 69 65 76 65 73 20 61 20 70 61 74 68 20 etrieves a path
aaf0: 69 6e 0a 20 2a 09 6e 61 74 69 76 65 20 66 6f 72 in. *.native for
ab00: 6d 20 28 66 72 6f 6d 2c 20 65 2e 67 2e 20 72 65 m (from, e.g. re
ab10: 61 64 6c 69 6e 6b 20 6f 72 20 61 20 6e 61 74 69 adlink or a nati
ab20: 76 65 20 64 69 61 6c 6f 67 29 2c 20 61 6e 64 20 ve dialog), and
ab30: 74 68 61 74 20 70 61 74 68 20 69 73 0a 20 2a 09 that path is. *.
ab40: 74 6f 20 62 65 20 75 73 65 64 20 61 74 20 74 68 to be used at th
ab50: 65 20 54 63 6c 20 6c 65 76 65 6c 2c 20 74 68 65 e Tcl level, the
ab60: 6e 20 63 61 6c 6c 69 6e 67 20 74 68 69 73 20 66 n calling this f
ab70: 75 6e 63 74 69 6f 6e 20 69 73 20 61 6e 0a 20 2a unction is an. *
ab80: 09 65 66 66 69 63 69 65 6e 74 20 77 61 79 20 6f .efficient way o
ab90: 66 20 63 72 65 61 74 69 6e 67 20 74 68 65 20 61 f creating the a
aba0: 70 70 72 6f 70 72 69 61 74 65 20 70 61 74 68 20 ppropriate path
abb0: 6f 62 6a 65 63 74 20 74 79 70 65 2e 0a 20 2a 0a object type.. *.
abc0: 20 2a 09 41 6e 79 20 6d 65 6d 6f 72 79 20 77 68 *.Any memory wh
abd0: 69 63 68 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 ich is allocated
abe0: 20 66 6f 72 20 27 63 6c 69 65 6e 74 44 61 74 61 for 'clientData
abf0: 27 20 73 68 6f 75 6c 64 20 62 65 20 72 65 74 61 ' should be reta
ac00: 69 6e 65 64 0a 20 2a 09 75 6e 74 69 6c 20 63 6c ined. *.until cl
ac10: 69 65 6e 74 44 61 74 61 20 69 73 20 70 61 73 73 ientData is pass
ac20: 65 64 20 74 6f 20 74 68 65 20 66 69 6c 65 73 79 ed to the filesy
ac30: 73 74 65 6d 27 73 20 66 72 65 65 49 6e 74 65 72 stem's freeInter
ac40: 6e 61 6c 52 65 70 50 72 6f 63 0a 20 2a 09 77 68 nalRepProc. *.wh
ac50: 65 6e 20 69 74 20 63 61 6e 20 62 65 20 66 72 65 en it can be fre
ac60: 65 64 2e 20 54 68 65 20 62 75 69 6c 74 20 69 6e ed. The built in
ac70: 20 70 6c 61 74 66 6f 72 6d 2d 73 70 65 63 69 66 platform-specif
ac80: 69 63 20 66 69 6c 65 73 79 73 74 65 6d 73 20 75 ic filesystems u
ac90: 73 65 0a 20 2a 09 27 63 6b 61 6c 6c 6f 63 27 20 se. *.'ckalloc'
aca0: 74 6f 20 61 6c 6c 6f 63 61 74 65 20 63 6c 69 65 to allocate clie
acb0: 6e 74 44 61 74 61 2c 20 61 6e 64 20 63 6b 66 72 ntData, and ckfr
acc0: 65 65 20 74 6f 20 66 72 65 65 20 69 74 2e 0a 20 ee to free it..
acd0: 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a *. * Results:. *
ace0: 09 4e 55 4c 4c 20 6f 72 20 61 20 76 61 6c 69 64 .NULL or a valid
acf0: 20 70 61 74 68 20 6f 62 6a 65 63 74 20 70 6f 69 path object poi
ad00: 6e 74 65 72 2c 20 77 69 74 68 20 72 65 66 43 6f nter, with refCo
ad10: 75 6e 74 20 7a 65 72 6f 2e 0a 20 2a 0a 20 2a 20 unt zero.. *. *
ad20: 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a Side effects:. *
ad30: 09 4e 65 77 20 6d 65 6d 6f 72 79 20 6d 61 79 20 .New memory may
ad40: 62 65 20 61 6c 6c 6f 63 61 74 65 64 2e 0a 20 2a be allocated.. *
ad50: 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d . *-------------
ad60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ad70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ad80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ad90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 --------------.
ada0: 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 */..Tcl_Obj *.Tc
adb0: 6c 5f 46 53 4e 65 77 4e 61 74 69 76 65 50 61 74 l_FSNewNativePat
adc0: 68 28 0a 20 20 20 20 63 6f 6e 73 74 20 54 63 6c h(. const Tcl
add0: 5f 46 69 6c 65 73 79 73 74 65 6d 20 2a 66 72 6f _Filesystem *fro
ade0: 6d 46 69 6c 65 73 79 73 74 65 6d 2c 0a 20 20 20 mFilesystem,.
adf0: 20 43 6c 69 65 6e 74 44 61 74 61 20 63 6c 69 65 ClientData clie
ae00: 6e 74 44 61 74 61 29 0a 7b 0a 20 20 20 20 54 63 ntData).{. Tc
ae10: 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 72 20 3d l_Obj *pathPtr =
ae20: 20 4e 55 4c 4c 3b 0a 20 20 20 20 46 73 50 61 74 NULL;. FsPat
ae30: 68 20 2a 66 73 50 61 74 68 50 74 72 3b 0a 0a 0a h *fsPathPtr;...
ae40: 20 20 20 20 69 66 20 28 66 72 6f 6d 46 69 6c 65 if (fromFile
ae50: 73 79 73 74 65 6d 2d 3e 69 6e 74 65 72 6e 61 6c system->internal
ae60: 54 6f 4e 6f 72 6d 61 6c 69 7a 65 64 50 72 6f 63 ToNormalizedProc
ae70: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 70 61 74 != NULL) {..pat
ae80: 68 50 74 72 20 3d 20 28 2a 66 72 6f 6d 46 69 6c hPtr = (*fromFil
ae90: 65 73 79 73 74 65 6d 2d 3e 69 6e 74 65 72 6e 61 esystem->interna
aea0: 6c 54 6f 4e 6f 72 6d 61 6c 69 7a 65 64 50 72 6f lToNormalizedPro
aeb0: 63 29 28 63 6c 69 65 6e 74 44 61 74 61 29 3b 0a c)(clientData);.
aec0: 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 70 61 }. if (pa
aed0: 74 68 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b thPtr == NULL) {
aee0: 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 ..return NULL;.
aef0: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 }.. /*.
af00: 20 20 2a 20 46 72 65 65 20 6f 6c 64 20 72 65 70 * Free old rep
af10: 72 65 73 65 6e 74 61 74 69 6f 6e 3b 20 73 68 6f resentation; sho
af20: 75 6c 64 6e 27 74 20 6e 6f 72 6d 61 6c 6c 79 20 uldn't normally
af30: 62 65 20 61 6e 79 2c 20 62 75 74 20 62 65 73 74 be any, but best
af40: 20 74 6f 20 62 65 0a 20 20 20 20 20 2a 20 73 61 to be. * sa
af50: 66 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 fe.. */..
af60: 20 69 66 20 28 70 61 74 68 50 74 72 2d 3e 74 79 if (pathPtr->ty
af70: 70 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b pePtr != NULL) {
af80: 0a 09 69 66 20 28 70 61 74 68 50 74 72 2d 3e 62 ..if (pathPtr->b
af90: 79 74 65 73 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a ytes == NULL) {.
afa0: 09 20 20 20 20 69 66 20 28 70 61 74 68 50 74 72 . if (pathPtr
afb0: 2d 3e 74 79 70 65 50 74 72 2d 3e 75 70 64 61 74 ->typePtr->updat
afc0: 65 53 74 72 69 6e 67 50 72 6f 63 20 3d 3d 20 4e eStringProc == N
afd0: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 ULL) {...return
afe0: 4e 55 4c 4c 3b 0a 09 20 20 20 20 7d 0a 09 20 20 NULL;.. }..
aff0: 20 20 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 pathPtr->typeP
b000: 74 72 2d 3e 75 70 64 61 74 65 53 74 72 69 6e 67 tr->updateString
b010: 50 72 6f 63 28 70 61 74 68 50 74 72 29 3b 0a 09 Proc(pathPtr);..
b020: 7d 0a 09 54 63 6c 46 72 65 65 49 6e 74 52 65 70 }..TclFreeIntRep
b030: 28 70 61 74 68 50 74 72 29 3b 0a 20 20 20 20 7d (pathPtr);. }
b040: 0a 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 20 .. fsPathPtr
b050: 3d 20 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 = ckalloc(sizeof
b060: 28 46 73 50 61 74 68 29 29 3b 0a 0a 20 20 20 20 (FsPath));..
b070: 66 73 50 61 74 68 50 74 72 2d 3e 74 72 61 6e 73 fsPathPtr->trans
b080: 6c 61 74 65 64 50 61 74 68 50 74 72 20 3d 20 4e latedPathPtr = N
b090: 55 4c 4c 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 ULL;.. /*.
b0a0: 20 20 2a 20 43 69 72 63 75 6c 61 72 20 72 65 66 * Circular ref
b0b0: 65 72 65 6e 63 65 2c 20 62 79 20 64 65 73 69 67 erence, by desig
b0c0: 6e 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 n.. */..
b0d0: 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 fsPathPtr->normP
b0e0: 61 74 68 50 74 72 20 3d 20 70 61 74 68 50 74 72 athPtr = pathPtr
b0f0: 3b 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 2d ;. fsPathPtr-
b100: 3e 63 77 64 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a >cwdPtr = NULL;.
b110: 20 20 20 20 66 73 50 61 74 68 50 74 72 2d 3e 6e fsPathPtr->n
b120: 61 74 69 76 65 50 61 74 68 50 74 72 20 3d 20 63 ativePathPtr = c
b130: 6c 69 65 6e 74 44 61 74 61 3b 0a 20 20 20 20 66 lientData;. f
b140: 73 50 61 74 68 50 74 72 2d 3e 66 73 50 74 72 20 sPathPtr->fsPtr
b150: 3d 20 66 72 6f 6d 46 69 6c 65 73 79 73 74 65 6d = fromFilesystem
b160: 3b 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 2d ;. fsPathPtr-
b170: 3e 66 69 6c 65 73 79 73 74 65 6d 45 70 6f 63 68 >filesystemEpoch
b180: 20 3d 20 54 63 6c 46 53 45 70 6f 63 68 28 29 3b = TclFSEpoch();
b190: 0a 0a 20 20 20 20 53 45 54 50 41 54 48 4f 42 4a .. SETPATHOBJ
b1a0: 28 70 61 74 68 50 74 72 2c 20 66 73 50 61 74 68 (pathPtr, fsPath
b1b0: 50 74 72 29 3b 0a 20 20 20 20 50 41 54 48 46 4c Ptr);. PATHFL
b1c0: 41 47 53 28 70 61 74 68 50 74 72 29 20 3d 20 30 AGS(pathPtr) = 0
b1d0: 3b 0a 20 20 20 20 70 61 74 68 50 74 72 2d 3e 74 ;. pathPtr->t
b1e0: 79 70 65 50 74 72 20 3d 20 26 74 63 6c 46 73 50 ypePtr = &tclFsP
b1f0: 61 74 68 54 79 70 65 3b 0a 0a 20 20 20 20 72 65 athType;.. re
b200: 74 75 72 6e 20 70 61 74 68 50 74 72 3b 0a 7d 0a turn pathPtr;.}.
b210: 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d ../*. *---------
b220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b260: 2d 2d 0a 20 2a 0a 20 2a 20 54 63 6c 5f 46 53 47 --. *. * Tcl_FSG
b270: 65 74 54 72 61 6e 73 6c 61 74 65 64 50 61 74 68 etTranslatedPath
b280: 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 66 --. *. *.This f
b290: 75 6e 63 74 69 6f 6e 20 61 74 74 65 6d 70 74 73 unction attempts
b2a0: 20 74 6f 20 65 78 74 72 61 63 74 20 74 68 65 20 to extract the
b2b0: 74 72 61 6e 73 6c 61 74 65 64 20 70 61 74 68 20 translated path
b2c0: 66 72 6f 6d 20 74 68 65 20 67 69 76 65 6e 0a 20 from the given.
b2d0: 2a 09 54 63 6c 5f 4f 62 6a 2e 20 49 66 20 74 68 *.Tcl_Obj. If th
b2e0: 65 20 74 72 61 6e 73 6c 61 74 69 6f 6e 20 73 75 e translation su
b2f0: 63 63 65 65 64 73 20 28 69 2e 65 2e 20 74 68 65 cceeds (i.e. the
b300: 20 6f 62 6a 65 63 74 20 69 73 20 61 20 76 61 6c object is a val
b310: 69 64 0a 20 2a 09 70 61 74 68 29 2c 20 74 68 65 id. *.path), the
b320: 6e 20 69 74 20 69 73 20 72 65 74 75 72 6e 65 64 n it is returned
b330: 2e 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c 4c . Otherwise NULL
b340: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 will be returne
b350: 64 2c 20 61 6e 64 20 61 6e 0a 20 2a 09 65 72 72 d, and an. *.err
b360: 6f 72 20 6d 65 73 73 61 67 65 20 6d 61 79 20 62 or message may b
b370: 65 20 6c 65 66 74 20 69 6e 20 74 68 65 20 69 6e e left in the in
b380: 74 65 72 70 72 65 74 65 72 20 28 69 66 20 69 74 terpreter (if it
b390: 20 69 73 20 6e 6f 6e 2d 4e 55 4c 4c 29 0a 20 2a is non-NULL). *
b3a0: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 . * Results:. *.
b3b0: 4e 55 4c 4c 20 6f 72 20 61 20 76 61 6c 69 64 20 NULL or a valid
b3c0: 54 63 6c 5f 4f 62 6a 20 70 6f 69 6e 74 65 72 2e Tcl_Obj pointer.
b3d0: 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 . *. * Side effe
b3e0: 63 74 73 3a 0a 20 2a 09 4f 6e 6c 79 20 74 68 6f cts:. *.Only tho
b3f0: 73 65 20 6f 66 20 27 54 63 6c 5f 46 53 43 6f 6e se of 'Tcl_FSCon
b400: 76 65 72 74 54 6f 50 61 74 68 54 79 70 65 27 0a vertToPathType'.
b410: 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *. *-----------
b420: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
b460: 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 20 2a 0a . */..Tcl_Obj *.
b470: 54 63 6c 5f 46 53 47 65 74 54 72 61 6e 73 6c 61 Tcl_FSGetTransla
b480: 74 65 64 50 61 74 68 28 0a 20 20 20 20 54 63 6c tedPath(. Tcl
b490: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c _Interp *interp,
b4a0: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 . Tcl_Obj *pa
b4b0: 74 68 50 74 72 29 0a 7b 0a 20 20 20 20 54 63 6c thPtr).{. Tcl
b4c0: 5f 4f 62 6a 20 2a 72 65 74 4f 62 6a 20 3d 20 4e _Obj *retObj = N
b4d0: 55 4c 4c 3b 0a 20 20 20 20 46 73 50 61 74 68 20 ULL;. FsPath
b4e0: 2a 73 72 63 46 73 50 61 74 68 50 74 72 3b 0a 0a *srcFsPathPtr;..
b4f0: 20 20 20 20 69 66 20 28 54 63 6c 5f 46 53 43 6f if (Tcl_FSCo
b500: 6e 76 65 72 74 54 6f 50 61 74 68 54 79 70 65 28 nvertToPathType(
b510: 69 6e 74 65 72 70 2c 20 70 61 74 68 50 74 72 29 interp, pathPtr)
b520: 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 72 != TCL_OK) {..r
b530: 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 eturn NULL;.
b540: 7d 0a 20 20 20 20 73 72 63 46 73 50 61 74 68 50 }. srcFsPathP
b550: 74 72 20 3d 20 50 41 54 48 4f 42 4a 28 70 61 74 tr = PATHOBJ(pat
b560: 68 50 74 72 29 3b 0a 20 20 20 20 69 66 20 28 73 hPtr);. if (s
b570: 72 63 46 73 50 61 74 68 50 74 72 2d 3e 74 72 61 rcFsPathPtr->tra
b580: 6e 73 6c 61 74 65 64 50 61 74 68 50 74 72 20 3d nslatedPathPtr =
b590: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 69 66 20 28 50 = NULL) {..if (P
b5a0: 41 54 48 46 4c 41 47 53 28 70 61 74 68 50 74 72 ATHFLAGS(pathPtr
b5b0: 29 20 21 3d 20 30 29 20 7b 0a 09 20 20 20 20 2f ) != 0) {.. /
b5c0: 2a 0a 09 20 20 20 20 20 2a 20 57 65 20 6c 61 63 *.. * We lac
b5d0: 6b 20 61 20 74 72 61 6e 73 6c 61 74 65 64 20 70 k a translated p
b5e0: 61 74 68 20 72 65 73 75 6c 74 2c 20 62 75 74 20 ath result, but
b5f0: 77 65 20 68 61 76 65 20 61 20 64 69 72 65 63 74 we have a direct
b600: 6f 72 79 0a 09 20 20 20 20 20 2a 20 28 63 77 64 ory.. * (cwd
b610: 50 74 72 29 20 61 6e 64 20 61 20 74 61 69 6c 20 Ptr) and a tail
b620: 28 6e 6f 72 6d 50 61 74 68 50 74 72 29 2c 20 61 (normPathPtr), a
b630: 6e 64 20 69 66 20 77 65 20 6a 6f 69 6e 20 74 68 nd if we join th
b640: 65 0a 09 20 20 20 20 20 2a 20 74 72 61 6e 73 6c e.. * transl
b650: 61 74 65 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 ated version of
b660: 63 77 64 50 74 72 20 74 6f 20 6e 6f 72 6d 50 61 cwdPtr to normPa
b670: 74 68 50 74 72 2c 20 77 65 27 6c 6c 20 67 65 74 thPtr, we'll get
b680: 20 74 68 65 0a 09 20 20 20 20 20 2a 20 74 72 61 the.. * tra
b690: 6e 73 6c 61 74 65 64 20 72 65 73 75 6c 74 20 77 nslated result w
b6a0: 65 20 6e 65 65 64 2c 20 61 6e 64 20 63 61 6e 20 e need, and can
b6b0: 73 74 6f 72 65 20 69 74 20 66 6f 72 20 66 75 74 store it for fut
b6c0: 75 72 65 20 75 73 65 2e 0a 09 20 20 20 20 20 2a ure use... *
b6d0: 2f 0a 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 /... Tcl_Obj
b6e0: 2a 74 72 61 6e 73 6c 61 74 65 64 43 77 64 50 74 *translatedCwdPt
b6f0: 72 20 3d 20 54 63 6c 5f 46 53 47 65 74 54 72 61 r = Tcl_FSGetTra
b700: 6e 73 6c 61 74 65 64 50 61 74 68 28 69 6e 74 65 nslatedPath(inte
b710: 72 70 2c 0a 09 09 20 20 20 20 73 72 63 46 73 50 rp,... srcFsP
b720: 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 29 3b athPtr->cwdPtr);
b730: 0a 09 20 20 20 20 69 66 20 28 74 72 61 6e 73 6c .. if (transl
b740: 61 74 65 64 43 77 64 50 74 72 20 3d 3d 20 4e 55 atedCwdPtr == NU
b750: 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 4e LL) {...return N
b760: 55 4c 4c 3b 0a 09 20 20 20 20 7d 0a 0a 09 20 20 ULL;.. }...
b770: 20 20 72 65 74 4f 62 6a 20 3d 20 54 63 6c 5f 46 retObj = Tcl_F
b780: 53 4a 6f 69 6e 54 6f 50 61 74 68 28 74 72 61 6e SJoinToPath(tran
b790: 73 6c 61 74 65 64 43 77 64 50 74 72 2c 20 31 2c slatedCwdPtr, 1,
b7a0: 0a 09 09 20 20 20 20 26 73 72 63 46 73 50 61 74 ... &srcFsPat
b7b0: 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 hPtr->normPathPt
b7c0: 72 29 3b 0a 09 20 20 20 20 73 72 63 46 73 50 61 r);.. srcFsPa
b7d0: 74 68 50 74 72 2d 3e 74 72 61 6e 73 6c 61 74 65 thPtr->translate
b7e0: 64 50 61 74 68 50 74 72 20 3d 20 72 65 74 4f 62 dPathPtr = retOb
b7f0: 6a 3b 0a 09 20 20 20 20 69 66 20 28 74 72 61 6e j;.. if (tran
b800: 73 6c 61 74 65 64 43 77 64 50 74 72 2d 3e 74 79 slatedCwdPtr->ty
b810: 70 65 50 74 72 20 3d 3d 20 26 74 63 6c 46 73 50 pePtr == &tclFsP
b820: 61 74 68 54 79 70 65 29 20 7b 0a 09 09 73 72 63 athType) {...src
b830: 46 73 50 61 74 68 50 74 72 2d 3e 66 69 6c 65 73 FsPathPtr->files
b840: 79 73 74 65 6d 45 70 6f 63 68 0a 09 09 09 3d 20 ystemEpoch....=
b850: 50 41 54 48 4f 42 4a 28 74 72 61 6e 73 6c 61 74 PATHOBJ(translat
b860: 65 64 43 77 64 50 74 72 29 2d 3e 66 69 6c 65 73 edCwdPtr)->files
b870: 79 73 74 65 6d 45 70 6f 63 68 3b 0a 09 20 20 20 ystemEpoch;..
b880: 20 7d 20 65 6c 73 65 20 7b 0a 09 09 73 72 63 46 } else {...srcF
b890: 73 50 61 74 68 50 74 72 2d 3e 66 69 6c 65 73 79 sPathPtr->filesy
b8a0: 73 74 65 6d 45 70 6f 63 68 20 3d 20 30 3b 0a 09 stemEpoch = 0;..
b8b0: 20 20 20 20 7d 0a 09 20 20 20 20 54 63 6c 5f 49 }.. Tcl_I
b8c0: 6e 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 4f ncrRefCount(retO
b8d0: 62 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f 44 65 bj);.. Tcl_De
b8e0: 63 72 52 65 66 43 6f 75 6e 74 28 74 72 61 6e 73 crRefCount(trans
b8f0: 6c 61 74 65 64 43 77 64 50 74 72 29 3b 0a 09 7d latedCwdPtr);..}
b900: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 2f 2a 0a else {.. /*.
b910: 09 20 20 20 20 20 2a 20 49 74 20 69 73 20 61 20 . * It is a
b920: 70 75 72 65 20 61 62 73 6f 6c 75 74 65 2c 20 6e pure absolute, n
b930: 6f 72 6d 61 6c 69 7a 65 64 20 70 61 74 68 20 6f ormalized path o
b940: 62 6a 65 63 74 2e 20 54 68 69 73 20 69 73 0a 09 bject. This is..
b950: 20 20 20 20 20 2a 20 73 6f 6d 65 74 68 69 6e 67 * something
b960: 20 6c 69 6b 65 20 62 65 69 6e 67 20 61 20 27 70 like being a 'p
b970: 75 72 65 20 6c 69 73 74 27 2e 20 54 68 65 20 6f ure list'. The o
b980: 62 6a 65 63 74 27 73 20 73 74 72 69 6e 67 2c 0a bject's string,.
b990: 09 20 20 20 20 20 2a 20 74 72 61 6e 73 6c 61 74 . * translat
b9a0: 65 64 50 61 74 68 20 61 6e 64 20 6e 6f 72 6d 61 edPath and norma
b9b0: 6c 69 7a 65 64 50 61 74 68 20 61 72 65 20 61 6c lizedPath are al
b9c0: 6c 20 69 64 65 6e 74 69 63 61 6c 2e 0a 09 20 20 l identical...
b9d0: 20 20 20 2a 2f 0a 0a 09 20 20 20 20 72 65 74 4f */... retO
b9e0: 62 6a 20 3d 20 73 72 63 46 73 50 61 74 68 50 74 bj = srcFsPathPt
b9f0: 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 3b 0a r->normPathPtr;.
ba00: 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a .}. } else {.
ba10: 09 2f 2a 0a 09 20 2a 20 49 74 20 69 73 20 61 6e ./*.. * It is an
ba20: 20 6f 72 64 69 6e 61 72 79 20 70 61 74 68 20 6f ordinary path o
ba30: 62 6a 65 63 74 2e 0a 09 20 2a 2f 0a 0a 09 72 65 bject... */...re
ba40: 74 4f 62 6a 20 3d 20 73 72 63 46 73 50 61 74 68 tObj = srcFsPath
ba50: 50 74 72 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 Ptr->translatedP
ba60: 61 74 68 50 74 72 3b 0a 20 20 20 20 7d 0a 0a 20 athPtr;. }..
ba70: 20 20 20 69 66 20 28 72 65 74 4f 62 6a 20 21 3d if (retObj !=
ba80: 20 4e 55 4c 4c 29 20 7b 0a 09 54 63 6c 5f 49 6e NULL) {..Tcl_In
ba90: 63 72 52 65 66 43 6f 75 6e 74 28 72 65 74 4f 62 crRefCount(retOb
baa0: 6a 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 j);. }. re
bab0: 74 75 72 6e 20 72 65 74 4f 62 6a 3b 0a 7d 0a 0c turn retObj;.}..
bac0: 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ./*. *----------
bad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
baf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bb00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bb10: 2d 0a 20 2a 0a 20 2a 20 54 63 6c 5f 46 53 47 65 -. *. * Tcl_FSGe
bb20: 74 54 72 61 6e 73 6c 61 74 65 64 53 74 72 69 6e tTranslatedStrin
bb30: 67 50 61 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 54 gPath --. *. *.T
bb40: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 61 74 74 his function att
bb50: 65 6d 70 74 73 20 74 6f 20 65 78 74 72 61 63 74 empts to extract
bb60: 20 74 68 65 20 74 72 61 6e 73 6c 61 74 65 64 20 the translated
bb70: 70 61 74 68 20 66 72 6f 6d 20 74 68 65 20 67 69 path from the gi
bb80: 76 65 6e 0a 20 2a 09 54 63 6c 5f 4f 62 6a 2e 20 ven. *.Tcl_Obj.
bb90: 49 66 20 74 68 65 20 74 72 61 6e 73 6c 61 74 69 If the translati
bba0: 6f 6e 20 73 75 63 63 65 65 64 73 20 28 69 2e 65 on succeeds (i.e
bbb0: 2e 20 74 68 65 20 6f 62 6a 65 63 74 20 69 73 20 . the object is
bbc0: 61 20 76 61 6c 69 64 0a 20 2a 09 70 61 74 68 29 a valid. *.path)
bbd0: 2c 20 74 68 65 6e 20 74 68 65 20 70 61 74 68 20 , then the path
bbe0: 69 73 20 72 65 74 75 72 6e 65 64 2e 20 4f 74 68 is returned. Oth
bbf0: 65 72 77 69 73 65 20 4e 55 4c 4c 20 77 69 6c 6c erwise NULL will
bc00: 20 62 65 20 72 65 74 75 72 6e 65 64 2c 20 61 6e be returned, an
bc10: 64 0a 20 2a 09 61 6e 20 65 72 72 6f 72 20 6d 65 d. *.an error me
bc20: 73 73 61 67 65 20 6d 61 79 20 62 65 20 6c 65 66 ssage may be lef
bc30: 74 20 69 6e 20 74 68 65 20 69 6e 74 65 72 70 72 t in the interpr
bc40: 65 74 65 72 20 28 69 66 20 69 74 20 69 73 20 6e eter (if it is n
bc50: 6f 6e 2d 4e 55 4c 4c 29 0a 20 2a 0a 20 2a 20 52 on-NULL). *. * R
bc60: 65 73 75 6c 74 73 3a 0a 20 2a 09 4e 55 4c 4c 20 esults:. *.NULL
bc70: 6f 72 20 61 20 76 61 6c 69 64 20 73 74 72 69 6e or a valid strin
bc80: 67 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 g.. *. * Side ef
bc90: 66 65 63 74 73 3a 0a 20 2a 09 4f 6e 6c 79 20 74 fects:. *.Only t
bca0: 68 6f 73 65 20 6f 66 20 27 54 63 6c 5f 46 53 43 hose of 'Tcl_FSC
bcb0: 6f 6e 76 65 72 74 54 6f 50 61 74 68 54 79 70 65 onvertToPathType
bcc0: 27 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d '. *. *---------
bcd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bcf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bd00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bd10: 2d 2d 0a 20 2a 2f 0a 0a 63 6f 6e 73 74 20 63 68 --. */..const ch
bd20: 61 72 20 2a 0a 54 63 6c 5f 46 53 47 65 74 54 72 ar *.Tcl_FSGetTr
bd30: 61 6e 73 6c 61 74 65 64 53 74 72 69 6e 67 50 61 anslatedStringPa
bd40: 74 68 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74 65 th(. Tcl_Inte
bd50: 72 70 20 2a 69 6e 74 65 72 70 2c 0a 20 20 20 20 rp *interp,.
bd60: 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 72 Tcl_Obj *pathPtr
bd70: 29 0a 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 ).{. Tcl_Obj
bd80: 2a 74 72 61 6e 73 50 74 72 20 3d 20 54 63 6c 5f *transPtr = Tcl_
bd90: 46 53 47 65 74 54 72 61 6e 73 6c 61 74 65 64 50 FSGetTranslatedP
bda0: 61 74 68 28 69 6e 74 65 72 70 2c 20 70 61 74 68 ath(interp, path
bdb0: 50 74 72 29 3b 0a 0a 20 20 20 20 69 66 20 28 74 Ptr);.. if (t
bdc0: 72 61 6e 73 50 74 72 20 21 3d 20 4e 55 4c 4c 29 ransPtr != NULL)
bdd0: 20 7b 0a 09 69 6e 74 20 6c 65 6e 3b 0a 09 63 6f {..int len;..co
bde0: 6e 73 74 20 63 68 61 72 20 2a 6f 72 69 67 20 3d nst char *orig =
bdf0: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 Tcl_GetStringFr
be00: 6f 6d 4f 62 6a 28 74 72 61 6e 73 50 74 72 2c 20 omObj(transPtr,
be10: 26 6c 65 6e 29 3b 0a 09 63 68 61 72 20 2a 72 65 &len);..char *re
be20: 73 75 6c 74 20 3d 20 63 6b 61 6c 6c 6f 63 28 6c sult = ckalloc(l
be30: 65 6e 2b 31 29 3b 0a 0a 09 6d 65 6d 63 70 79 28 en+1);...memcpy(
be40: 72 65 73 75 6c 74 2c 20 6f 72 69 67 2c 20 6c 65 result, orig, le
be50: 6e 2b 31 29 3b 0a 09 54 63 6c 44 65 63 72 52 65 n+1);..TclDecrRe
be60: 66 43 6f 75 6e 74 28 74 72 61 6e 73 50 74 72 29 fCount(transPtr)
be70: 3b 0a 09 72 65 74 75 72 6e 20 72 65 73 75 6c 74 ;..return result
be80: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 72 65 74 ;. }.. ret
be90: 75 72 6e 20 4e 55 4c 4c 3b 0a 7d 0a 0c 0a 2f 2a urn NULL;.}.../*
bea0: 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d . *-------------
beb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bec0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bed0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
bee0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 --------------.
bef0: 2a 0a 20 2a 20 54 63 6c 5f 46 53 47 65 74 4e 6f *. * Tcl_FSGetNo
bf00: 72 6d 61 6c 69 7a 65 64 50 61 74 68 20 2d 2d 0a rmalizedPath --.
bf10: 20 2a 0a 20 2a 09 54 68 69 73 20 69 6d 70 6f 72 *. *.This impor
bf20: 74 61 6e 74 20 66 75 6e 63 74 69 6f 6e 20 61 74 tant function at
bf30: 74 65 6d 70 74 73 20 74 6f 20 65 78 74 72 61 63 tempts to extrac
bf40: 74 20 66 72 6f 6d 20 74 68 65 20 67 69 76 65 6e t from the given
bf50: 20 54 63 6c 5f 4f 62 6a 20 61 0a 20 2a 09 75 6e Tcl_Obj a. *.un
bf60: 69 71 75 65 20 6e 6f 72 6d 61 6c 69 73 65 64 20 ique normalised
bf70: 70 61 74 68 20 72 65 70 72 65 73 65 6e 74 61 74 path representat
bf80: 69 6f 6e 2c 20 77 68 6f 73 65 20 73 74 72 69 6e ion, whose strin
bf90: 67 20 76 61 6c 75 65 20 63 61 6e 20 62 65 20 75 g value can be u
bfa0: 73 65 64 0a 20 2a 09 61 73 20 61 20 75 6e 69 71 sed. *.as a uniq
bfb0: 75 65 20 69 64 65 6e 74 69 66 69 65 72 20 66 6f ue identifier fo
bfc0: 72 20 74 68 65 20 66 69 6c 65 2e 0a 20 2a 0a 20 r the file.. *.
bfd0: 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 4e 55 * Results:. *.NU
bfe0: 4c 4c 20 6f 72 20 61 20 76 61 6c 69 64 20 70 61 LL or a valid pa
bff0: 74 68 20 6f 62 6a 65 63 74 20 70 6f 69 6e 74 65 th object pointe
c000: 72 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 r.. *. * Side ef
c010: 66 65 63 74 73 3a 0a 20 2a 09 4e 65 77 20 6d 65 fects:. *.New me
c020: 6d 6f 72 79 20 6d 61 79 20 62 65 20 61 6c 6c 6f mory may be allo
c030: 63 61 74 65 64 2e 20 54 68 65 20 54 63 6c 20 27 cated. The Tcl '
c040: 65 72 72 6e 6f 27 20 6d 61 79 20 62 65 20 6d 6f errno' may be mo
c050: 64 69 66 69 65 64 20 69 6e 20 74 68 65 0a 20 2a dified in the. *
c060: 09 70 72 6f 63 65 73 73 20 6f 66 20 74 72 79 69 .process of tryi
c070: 6e 67 20 74 6f 20 65 78 61 6d 69 6e 65 20 76 61 ng to examine va
c080: 72 69 6f 75 73 20 70 61 74 68 20 70 6f 73 73 69 rious path possi
c090: 62 69 6c 69 74 69 65 73 2e 0a 20 2a 0a 20 2a 2d bilities.. *. *-
c0a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
c0b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
c0c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
c0d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
c0e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a ----------. */..
c0f0: 54 63 6c 5f 4f 62 6a 20 2a 0a 54 63 6c 5f 46 53 Tcl_Obj *.Tcl_FS
c100: 47 65 74 4e 6f 72 6d 61 6c 69 7a 65 64 50 61 74 GetNormalizedPat
c110: 68 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74 65 72 h(. Tcl_Inter
c120: 70 20 2a 69 6e 74 65 72 70 2c 0a 20 20 20 20 54 p *interp,. T
c130: 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 72 29 cl_Obj *pathPtr)
c140: 0a 7b 0a 20 20 20 20 46 73 50 61 74 68 20 2a 66 .{. FsPath *f
c150: 73 50 61 74 68 50 74 72 3b 0a 0a 20 20 20 20 69 sPathPtr;.. i
c160: 66 20 28 54 63 6c 5f 46 53 43 6f 6e 76 65 72 74 f (Tcl_FSConvert
c170: 54 6f 50 61 74 68 54 79 70 65 28 69 6e 74 65 72 ToPathType(inter
c180: 70 2c 20 70 61 74 68 50 74 72 29 20 21 3d 20 54 p, pathPtr) != T
c190: 43 4c 5f 4f 4b 29 20 7b 0a 09 72 65 74 75 72 6e CL_OK) {..return
c1a0: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 20 20 20 NULL;. }.
c1b0: 20 66 73 50 61 74 68 50 74 72 20 3d 20 50 41 54 fsPathPtr = PAT
c1c0: 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b 0a 0a HOBJ(pathPtr);..
c1d0: 20 20 20 20 69 66 20 28 50 41 54 48 46 4c 41 47 if (PATHFLAG
c1e0: 53 28 70 61 74 68 50 74 72 29 20 21 3d 20 30 29 S(pathPtr) != 0)
c1f0: 20 7b 0a 09 2f 2a 0a 09 20 2a 20 54 68 69 73 20 {../*.. * This
c200: 69 73 20 61 20 73 70 65 63 69 61 6c 20 70 61 74 is a special pat
c210: 68 20 6f 62 6a 65 63 74 20 77 68 69 63 68 20 69 h object which i
c220: 73 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 s the result of
c230: 73 6f 6d 65 74 68 69 6e 67 20 6c 69 6b 65 0a 09 something like..
c240: 20 2a 20 27 66 69 6c 65 20 6a 6f 69 6e 27 0a 09 * 'file join'..
c250: 20 2a 2f 0a 0a 09 54 63 6c 5f 4f 62 6a 20 2a 64 */...Tcl_Obj *d
c260: 69 72 2c 20 2a 63 6f 70 79 3b 0a 09 69 6e 74 20 ir, *copy;..int
c270: 74 61 69 6c 4c 65 6e 2c 20 63 77 64 4c 65 6e 2c tailLen, cwdLen,
c280: 20 70 61 74 68 54 79 70 65 3b 0a 0a 09 70 61 74 pathType;...pat
c290: 68 54 79 70 65 20 3d 20 54 63 6c 5f 46 53 47 65 hType = Tcl_FSGe
c2a0: 74 50 61 74 68 54 79 70 65 28 66 73 50 61 74 68 tPathType(fsPath
c2b0: 50 74 72 2d 3e 63 77 64 50 74 72 29 3b 0a 09 64 Ptr->cwdPtr);..d
c2c0: 69 72 20 3d 20 54 63 6c 5f 46 53 47 65 74 4e 6f ir = Tcl_FSGetNo
c2d0: 72 6d 61 6c 69 7a 65 64 50 61 74 68 28 69 6e 74 rmalizedPath(int
c2e0: 65 72 70 2c 20 66 73 50 61 74 68 50 74 72 2d 3e erp, fsPathPtr->
c2f0: 63 77 64 50 74 72 29 3b 0a 09 69 66 20 28 64 69 cwdPtr);..if (di
c300: 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 r == NULL) {..
c310: 20 20 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 09 return NULL;..
c320: 7d 0a 09 2f 2a 20 54 4f 44 4f 3a 20 46 69 67 75 }../* TODO: Figu
c330: 72 65 20 6f 75 74 20 77 68 79 20 74 68 69 73 20 re out why this
c340: 69 73 20 6e 65 65 64 65 64 2e 20 2a 2f 0a 09 69 is needed. */..i
c350: 66 20 28 70 61 74 68 50 74 72 2d 3e 62 79 74 65 f (pathPtr->byte
c360: 73 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 s == NULL) {..
c370: 20 20 55 70 64 61 74 65 53 74 72 69 6e 67 4f 66 UpdateStringOf
c380: 46 73 50 61 74 68 28 70 61 74 68 50 74 72 29 3b FsPath(pathPtr);
c390: 0a 09 7d 0a 0a 09 54 63 6c 5f 47 65 74 53 74 72 ..}...Tcl_GetStr
c3a0: 69 6e 67 46 72 6f 6d 4f 62 6a 28 66 73 50 61 74 ingFromObj(fsPat
c3b0: 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 hPtr->normPathPt
c3c0: 72 2c 20 26 74 61 69 6c 4c 65 6e 29 3b 0a 09 69 r, &tailLen);..i
c3d0: 66 20 28 74 61 69 6c 4c 65 6e 29 20 7b 0a 09 20 f (tailLen) {..
c3e0: 20 20 20 63 6f 70 79 20 3d 20 41 70 70 65 6e 64 copy = Append
c3f0: 50 61 74 68 28 64 69 72 2c 20 66 73 50 61 74 68 Path(dir, fsPath
c400: 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 Ptr->normPathPtr
c410: 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 );..} else {..
c420: 20 20 63 6f 70 79 20 3d 20 54 63 6c 5f 44 75 70 copy = Tcl_Dup
c430: 6c 69 63 61 74 65 4f 62 6a 28 64 69 72 29 3b 0a licateObj(dir);.
c440: 09 7d 0a 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 .}..Tcl_IncrRefC
c450: 6f 75 6e 74 28 64 69 72 29 3b 0a 09 54 63 6c 5f ount(dir);..Tcl_
c460: 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 63 6f 70 IncrRefCount(cop
c470: 79 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 57 65 20 y);.../*.. * We
c480: 6e 6f 77 20 6f 77 6e 20 61 20 72 65 66 65 72 65 now own a refere
c490: 6e 63 65 20 6f 6e 20 62 6f 74 68 20 27 64 69 72 nce on both 'dir
c4a0: 27 20 61 6e 64 20 27 63 6f 70 79 27 0a 09 20 2a ' and 'copy'.. *
c4b0: 2f 0a 0a 09 28 76 6f 69 64 29 20 54 63 6c 5f 47 /...(void) Tcl_G
c4c0: 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 etStringFromObj(
c4d0: 64 69 72 2c 20 26 63 77 64 4c 65 6e 29 3b 0a 0a dir, &cwdLen);..
c4e0: 09 2f 2a 20 4e 6f 72 6d 61 6c 69 7a 65 20 74 68 ./* Normalize th
c4f0: 65 20 63 6f 6d 62 69 6e 65 64 20 73 74 72 69 6e e combined strin
c500: 67 2e 20 2a 2f 0a 0a 09 69 66 20 28 50 41 54 48 g. */...if (PATH
c510: 46 4c 41 47 53 28 70 61 74 68 50 74 72 29 20 26 FLAGS(pathPtr) &
c520: 20 54 43 4c 50 41 54 48 5f 4e 45 45 44 4e 4f 52 TCLPATH_NEEDNOR
c530: 4d 29 20 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 M) {.. /*..
c540: 20 20 20 2a 20 49 66 20 74 68 65 20 22 74 61 69 * If the "tai
c550: 6c 22 20 70 61 72 74 20 68 61 73 20 63 6f 6d 70 l" part has comp
c560: 6f 6e 65 6e 74 73 20 28 6c 69 6b 65 20 2f 2e 2e onents (like /..
c570: 2f 29 20 74 68 61 74 20 63 61 75 73 65 20 74 68 /) that cause th
c580: 65 0a 09 20 20 20 20 20 2a 20 63 6f 6d 62 69 6e e.. * combin
c590: 65 64 20 70 61 74 68 20 74 6f 20 6e 65 65 64 20 ed path to need
c5a0: 6d 6f 72 65 20 63 6f 6d 70 6c 65 74 65 20 6e 6f more complete no
c5b0: 72 6d 61 6c 69 7a 69 6e 67 2c 20 63 61 6c 6c 20 rmalizing, call
c5c0: 6f 6e 20 74 68 65 0a 09 20 20 20 20 20 2a 20 6d on the.. * m
c5d0: 6f 72 65 20 70 6f 77 65 72 66 75 6c 20 72 6f 75 ore powerful rou
c5e0: 74 69 6e 65 20 74 6f 20 61 63 63 6f 6d 70 6c 69 tine to accompli
c5f0: 73 68 20 74 68 61 74 20 73 6f 20 77 65 20 61 76 sh that so we av
c600: 6f 69 64 20 5b 42 75 67 0a 09 20 20 20 20 20 2a oid [Bug.. *
c610: 20 32 33 38 35 35 34 39 5d 20 2e 2e 2e 0a 09 20 2385549] .....
c620: 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 54 63 6c */... Tcl
c630: 5f 4f 62 6a 20 2a 6e 65 77 43 6f 70 79 20 3d 20 _Obj *newCopy =
c640: 54 63 6c 46 53 4e 6f 72 6d 61 6c 69 7a 65 41 62 TclFSNormalizeAb
c650: 73 6f 6c 75 74 65 50 61 74 68 28 69 6e 74 65 72 solutePath(inter
c660: 70 2c 20 63 6f 70 79 29 3b 0a 0a 09 20 20 20 20 p, copy);...
c670: 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74 Tcl_DecrRefCount
c680: 28 63 6f 70 79 29 3b 0a 09 20 20 20 20 63 6f 70 (copy);.. cop
c690: 79 20 3d 20 6e 65 77 43 6f 70 79 3b 0a 09 7d 20 y = newCopy;..}
c6a0: 65 6c 73 65 20 7b 0a 09 20 20 20 20 2f 2a 0a 09 else {.. /*..
c6b0: 20 20 20 20 20 2a 20 2e 2e 2e 20 62 75 74 20 69 * ... but i
c6c0: 6e 20 6d 6f 73 74 20 63 61 73 65 73 20 77 68 65 n most cases whe
c6d0: 72 65 20 77 65 20 6a 6f 69 6e 20 61 20 74 72 6f re we join a tro
c6e0: 75 62 6c 65 20 66 72 65 65 20 74 61 69 6c 20 74 uble free tail t
c6f0: 6f 20 61 0a 09 20 20 20 20 20 2a 20 6e 6f 72 6d o a.. * norm
c700: 61 6c 69 7a 65 64 20 68 65 61 64 2c 20 77 65 20 alized head, we
c710: 63 61 6e 20 6d 6f 72 65 20 65 66 66 69 63 69 65 can more efficie
c720: 6e 74 6c 79 20 6e 6f 72 6d 61 6c 69 7a 65 20 74 ntly normalize t
c730: 68 65 20 63 6f 6d 62 69 6e 65 64 0a 09 20 20 20 he combined..
c740: 20 20 2a 20 70 61 74 68 20 62 79 20 70 61 73 73 * path by pass
c750: 69 6e 67 20 6f 76 65 72 20 6f 6e 6c 79 20 74 68 ing over only th
c760: 65 20 75 6e 6e 6f 72 6d 61 6c 69 7a 65 64 20 74 e unnormalized t
c770: 61 69 6c 20 70 6f 72 74 69 6f 6e 2e 20 57 68 65 ail portion. Whe
c780: 6e 0a 09 20 20 20 20 20 2a 20 74 68 69 73 20 69 n.. * this i
c790: 73 20 73 75 66 66 69 63 69 65 6e 74 2c 20 70 72 s sufficient, pr
c7a0: 69 6f 72 20 64 65 76 65 6c 6f 70 65 72 73 20 63 ior developers c
c7b0: 6c 61 69 6d 20 74 68 69 73 20 73 68 6f 75 6c 64 laim this should
c7c0: 20 62 65 20 6d 75 63 68 0a 09 20 20 20 20 20 2a be much.. *
c7d0: 20 66 61 73 74 65 72 2e 20 57 65 20 75 73 65 20 faster. We use
c7e0: 27 63 77 64 4c 65 6e 27 20 73 6f 20 74 68 61 74 'cwdLen' so that
c7f0: 20 77 65 20 61 72 65 20 61 6c 72 65 61 64 79 20 we are already
c800: 70 6f 69 6e 74 69 6e 67 20 61 74 0a 09 20 20 20 pointing at..
c810: 20 20 2a 20 74 68 65 20 64 69 72 2d 73 65 70 61 * the dir-sepa
c820: 72 61 74 6f 72 20 74 68 61 74 20 77 65 20 6b 6e rator that we kn
c830: 6f 77 20 61 62 6f 75 74 2e 20 54 68 65 20 6e 6f ow about. The no
c840: 72 6d 61 6c 69 7a 61 74 69 6f 6e 20 63 6f 64 65 rmalization code
c850: 0a 09 20 20 20 20 20 2a 20 77 69 6c 6c 20 61 63 .. * will ac
c860: 74 75 61 6c 6c 79 20 73 74 61 72 74 20 6f 66 66 tually start off
c870: 20 64 69 72 65 63 74 6c 79 20 61 66 74 65 72 20 directly after
c880: 74 68 61 74 20 73 65 70 61 72 61 74 6f 72 2e 0a that separator..
c890: 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 54 . */... T
c8a0: 63 6c 46 53 4e 6f 72 6d 61 6c 69 7a 65 54 6f 55 clFSNormalizeToU
c8b0: 6e 69 71 75 65 50 61 74 68 28 69 6e 74 65 72 70 niquePath(interp
c8c0: 2c 20 63 6f 70 79 2c 20 63 77 64 4c 65 6e 29 3b , copy, cwdLen);
c8d0: 0a 09 7d 0a 0a 09 2f 2a 20 4e 6f 77 20 77 65 20 ..}.../* Now we
c8e0: 6e 65 65 64 20 74 6f 20 63 6f 6e 73 74 72 75 63 need to construc
c8f0: 74 20 74 68 65 20 6e 65 77 20 70 61 74 68 20 6f t the new path o
c900: 62 6a 65 63 74 2e 20 2a 2f 0a 0a 09 69 66 20 28 bject. */...if (
c910: 70 61 74 68 54 79 70 65 20 3d 3d 20 54 43 4c 5f pathType == TCL_
c920: 50 41 54 48 5f 52 45 4c 41 54 49 56 45 29 20 7b PATH_RELATIVE) {
c930: 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6f .. Tcl_Obj *o
c940: 72 69 67 44 69 72 20 3d 20 66 73 50 61 74 68 50 rigDir = fsPathP
c950: 74 72 2d 3e 63 77 64 50 74 72 3b 0a 0a 09 20 20 tr->cwdPtr;...
c960: 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 4e 4f 54 /*.. * NOT
c970: 45 3a 20 68 65 72 65 20 77 65 20 61 72 65 20 28 E: here we are (
c980: 64 61 6e 67 65 72 6f 75 73 6c 79 3f 29 20 61 73 dangerously?) as
c990: 73 75 6d 69 6e 67 20 74 68 61 74 20 6f 72 69 67 suming that orig
c9a0: 44 69 72 20 70 6f 69 6e 74 73 0a 09 20 20 20 20 Dir points..
c9b0: 20 2a 20 74 6f 20 61 20 54 63 6c 5f 4f 62 6a 20 * to a Tcl_Obj
c9c0: 77 69 74 68 20 54 63 6c 5f 4f 62 6a 54 79 70 65 with Tcl_ObjType
c9d0: 20 3d 3d 20 26 74 63 6c 46 73 50 61 74 68 54 79 == &tclFsPathTy
c9e0: 70 65 2e 20 54 68 65 0a 09 20 20 20 20 20 2a 20 pe. The.. *
c9f0: 20 20 20 20 70 61 74 68 54 79 70 65 20 3d 20 54 pathType = T
ca00: 63 6c 5f 46 53 47 65 74 50 61 74 68 54 79 70 65 cl_FSGetPathType
ca10: 28 66 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 (fsPathPtr->cwdP
ca20: 74 72 29 3b 0a 09 20 20 20 20 20 2a 20 61 62 6f tr);.. * abo
ca30: 76 65 20 74 68 61 74 20 73 65 74 20 74 68 65 20 ve that set the
ca40: 70 61 74 68 54 79 70 65 20 76 61 6c 75 65 20 73 pathType value s
ca50: 68 6f 75 6c 64 20 68 61 76 65 20 65 73 74 61 62 hould have estab
ca60: 6c 69 73 68 65 64 20 74 68 61 74 2c 0a 09 20 20 lished that,..
ca70: 20 20 20 2a 20 62 75 74 20 69 74 27 73 20 66 61 * but it's fa
ca80: 72 20 6c 65 73 73 20 63 6c 65 61 72 20 6f 6e 20 r less clear on
ca90: 77 68 61 74 20 62 61 73 69 73 20 77 65 20 6b 6e what basis we kn
caa0: 6f 77 20 74 68 65 72 65 27 73 20 62 65 65 6e 20 ow there's been
cab0: 6e 6f 0a 09 20 20 20 20 20 2a 20 73 68 69 6d 6d no.. * shimm
cac0: 65 72 69 6e 67 20 73 69 6e 63 65 20 74 68 65 6e ering since then
cad0: 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 ... */...
cae0: 20 46 73 50 61 74 68 20 2a 6f 72 69 67 44 69 72 FsPath *origDir
caf0: 46 73 50 61 74 68 50 74 72 20 3d 20 50 41 54 48 FsPathPtr = PATH
cb00: 4f 42 4a 28 6f 72 69 67 44 69 72 29 3b 0a 0a 09 OBJ(origDir);...
cb10: 20 20 20 20 66 73 50 61 74 68 50 74 72 2d 3e 63 fsPathPtr->c
cb20: 77 64 50 74 72 20 3d 20 6f 72 69 67 44 69 72 46 wdPtr = origDirF
cb30: 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 sPathPtr->cwdPtr
cb40: 3b 0a 09 20 20 20 20 54 63 6c 5f 49 6e 63 72 52 ;.. Tcl_IncrR
cb50: 65 66 43 6f 75 6e 74 28 66 73 50 61 74 68 50 74 efCount(fsPathPt
cb60: 72 2d 3e 63 77 64 50 74 72 29 3b 0a 0a 09 20 20 r->cwdPtr);...
cb70: 20 20 54 63 6c 44 65 63 72 52 65 66 43 6f 75 6e TclDecrRefCoun
cb80: 74 28 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 t(fsPathPtr->nor
cb90: 6d 50 61 74 68 50 74 72 29 3b 0a 09 20 20 20 20 mPathPtr);..
cba0: 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 fsPathPtr->normP
cbb0: 61 74 68 50 74 72 20 3d 20 63 6f 70 79 3b 0a 0a athPtr = copy;..
cbc0: 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 . /*.. *
cbd0: 54 68 61 74 27 73 20 6f 75 72 20 72 65 66 65 72 That's our refer
cbe0: 65 6e 63 65 20 74 6f 20 63 6f 70 79 20 75 73 65 ence to copy use
cbf0: 64 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 d... */...
cc00: 20 20 54 63 6c 44 65 63 72 52 65 66 43 6f 75 6e TclDecrRefCoun
cc10: 74 28 64 69 72 29 3b 0a 09 20 20 20 20 54 63 6c t(dir);.. Tcl
cc20: 44 65 63 72 52 65 66 43 6f 75 6e 74 28 6f 72 69 DecrRefCount(ori
cc30: 67 44 69 72 29 3b 0a 09 7d 20 65 6c 73 65 20 7b gDir);..} else {
cc40: 0a 09 20 20 20 20 54 63 6c 44 65 63 72 52 65 66 .. TclDecrRef
cc50: 43 6f 75 6e 74 28 66 73 50 61 74 68 50 74 72 2d Count(fsPathPtr-
cc60: 3e 63 77 64 50 74 72 29 3b 0a 09 20 20 20 20 66 >cwdPtr);.. f
cc70: 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 sPathPtr->cwdPtr
cc80: 20 3d 20 4e 55 4c 4c 3b 0a 09 20 20 20 20 54 63 = NULL;.. Tc
cc90: 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 66 73 lDecrRefCount(fs
cca0: 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
ccb0: 68 50 74 72 29 3b 0a 09 20 20 20 20 66 73 50 61 hPtr);.. fsPa
ccc0: 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 thPtr->normPathP
ccd0: 74 72 20 3d 20 63 6f 70 79 3b 0a 0a 09 20 20 20 tr = copy;...
cce0: 20 2f 2a 0a 09 20 20 20 20 20 2a 20 54 68 61 74 /*.. * That
ccf0: 27 73 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 's our reference
cd00: 20 74 6f 20 63 6f 70 79 20 75 73 65 64 2e 0a 09 to copy used...
cd10: 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 54 63 */... Tc
cd20: 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 64 69 lDecrRefCount(di
cd30: 72 29 3b 0a 09 7d 0a 09 50 41 54 48 46 4c 41 47 r);..}..PATHFLAG
cd40: 53 28 70 61 74 68 50 74 72 29 20 3d 20 30 3b 0a S(pathPtr) = 0;.
cd50: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 }.. /*.
cd60: 20 20 20 2a 20 45 6e 73 75 72 65 20 63 77 64 20 * Ensure cwd
cd70: 68 61 73 6e 27 74 20 63 68 61 6e 67 65 64 2e 0a hasn't changed..
cd80: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 69 66 20 */.. if
cd90: 28 66 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 (fsPathPtr->cwdP
cda0: 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 69 tr != NULL) {..i
cdb0: 66 20 28 21 54 63 6c 46 53 43 77 64 50 6f 69 6e f (!TclFSCwdPoin
cdc0: 74 65 72 45 71 75 61 6c 73 28 26 66 73 50 61 74 terEquals(&fsPat
cdd0: 68 50 74 72 2d 3e 63 77 64 50 74 72 29 29 20 7b hPtr->cwdPtr)) {
cde0: 0a 09 20 20 20 20 69 66 20 28 70 61 74 68 50 74 .. if (pathPt
cdf0: 72 2d 3e 62 79 74 65 73 20 3d 3d 20 4e 55 4c 4c r->bytes == NULL
ce00: 29 20 7b 0a 09 09 55 70 64 61 74 65 53 74 72 69 ) {...UpdateStri
ce10: 6e 67 4f 66 46 73 50 61 74 68 28 70 61 74 68 50 ngOfFsPath(pathP
ce20: 74 72 29 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 tr);.. }..
ce30: 20 46 72 65 65 46 73 50 61 74 68 49 6e 74 65 72 FreeFsPathInter
ce40: 6e 61 6c 52 65 70 28 70 61 74 68 50 74 72 29 3b nalRep(pathPtr);
ce50: 0a 09 20 20 20 20 69 66 20 28 53 65 74 46 73 50 .. if (SetFsP
ce60: 61 74 68 46 72 6f 6d 41 6e 79 28 69 6e 74 65 72 athFromAny(inter
ce70: 70 2c 20 70 61 74 68 50 74 72 29 20 21 3d 20 54 p, pathPtr) != T
ce80: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 72 65 74 75 72 CL_OK) {...retur
ce90: 6e 20 4e 55 4c 4c 3b 0a 09 20 20 20 20 7d 0a 09 n NULL;.. }..
cea0: 20 20 20 20 66 73 50 61 74 68 50 74 72 20 3d 20 fsPathPtr =
ceb0: 50 41 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 PATHOBJ(pathPtr)
cec0: 3b 0a 09 7d 20 65 6c 73 65 20 69 66 20 28 66 73 ;..} else if (fs
ced0: 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
cee0: 68 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a hPtr == NULL) {.
cef0: 09 20 20 20 20 69 6e 74 20 63 77 64 4c 65 6e 3b . int cwdLen;
cf00: 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 .. Tcl_Obj *c
cf10: 6f 70 79 3b 0a 0a 09 20 20 20 20 63 6f 70 79 20 opy;... copy
cf20: 3d 20 41 70 70 65 6e 64 50 61 74 68 28 66 73 50 = AppendPath(fsP
cf30: 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 2c 20 athPtr->cwdPtr,
cf40: 70 61 74 68 50 74 72 29 3b 0a 0a 09 20 20 20 20 pathPtr);...
cf50: 28 76 6f 69 64 29 20 54 63 6c 5f 47 65 74 53 74 (void) Tcl_GetSt
cf60: 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 66 73 50 61 ringFromObj(fsPa
cf70: 74 68 50 74 72 2d 3e 63 77 64 50 74 72 2c 20 26 thPtr->cwdPtr, &
cf80: 63 77 64 4c 65 6e 29 3b 0a 09 20 20 20 20 63 77 cwdLen);.. cw
cf90: 64 4c 65 6e 20 2b 3d 20 28 54 63 6c 5f 47 65 74 dLen += (Tcl_Get
cfa0: 53 74 72 69 6e 67 28 63 6f 70 79 29 5b 63 77 64 String(copy)[cwd
cfb0: 4c 65 6e 5d 20 3d 3d 20 27 2f 27 29 3b 0a 0a 09 Len] == '/');...
cfc0: 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 4e /*.. * N
cfd0: 6f 72 6d 61 6c 69 7a 65 20 74 68 65 20 63 6f 6d ormalize the com
cfe0: 62 69 6e 65 64 20 73 74 72 69 6e 67 2c 20 62 75 bined string, bu
cff0: 74 20 6f 6e 6c 79 20 73 74 61 72 74 69 6e 67 20 t only starting
d000: 61 66 74 65 72 20 74 68 65 20 65 6e 64 0a 09 20 after the end..
d010: 20 20 20 20 2a 20 6f 66 20 74 68 65 20 70 72 65 * of the pre
d020: 76 69 6f 75 73 6c 79 20 6e 6f 72 6d 61 6c 69 7a viously normaliz
d030: 65 64 20 27 64 69 72 27 2e 20 54 68 69 73 20 73 ed 'dir'. This s
d040: 68 6f 75 6c 64 20 62 65 20 6d 75 63 68 20 66 61 hould be much fa
d050: 73 74 65 72 21 0a 09 20 20 20 20 20 2a 2f 0a 0a ster!.. */..
d060: 09 20 20 20 20 54 63 6c 46 53 4e 6f 72 6d 61 6c . TclFSNormal
d070: 69 7a 65 54 6f 55 6e 69 71 75 65 50 61 74 68 28 izeToUniquePath(
d080: 69 6e 74 65 72 70 2c 20 63 6f 70 79 2c 20 63 77 interp, copy, cw
d090: 64 4c 65 6e 2d 31 29 3b 0a 09 20 20 20 20 66 73 dLen-1);.. fs
d0a0: 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
d0b0: 68 50 74 72 20 3d 20 63 6f 70 79 3b 0a 09 20 20 hPtr = copy;..
d0c0: 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 Tcl_IncrRefCou
d0d0: 6e 74 28 66 73 50 61 74 68 50 74 72 2d 3e 6e 6f nt(fsPathPtr->no
d0e0: 72 6d 50 61 74 68 50 74 72 29 3b 0a 09 7d 0a 20 rmPathPtr);..}.
d0f0: 20 20 20 7d 0a 20 20 20 20 69 66 20 28 66 73 50 }. if (fsP
d100: 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 athPtr->normPath
d110: 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 Ptr == NULL) {..
d120: 54 63 6c 5f 4f 62 6a 20 2a 75 73 65 54 68 69 73 Tcl_Obj *useThis
d130: 43 77 64 20 3d 20 4e 55 4c 4c 3b 0a 09 69 6e 74 Cwd = NULL;..int
d140: 20 70 75 72 65 4e 6f 72 6d 61 6c 69 7a 65 64 20 pureNormalized
d150: 3d 20 31 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 53 69 = 1;.../*.. * Si
d160: 6e 63 65 20 6e 6f 72 6d 50 61 74 68 50 74 72 20 nce normPathPtr
d170: 69 73 20 4e 55 4c 4c 2c 20 62 75 74 20 74 68 69 is NULL, but thi
d180: 73 20 69 73 20 61 20 76 61 6c 69 64 20 70 61 74 s is a valid pat
d190: 68 20 6f 62 6a 65 63 74 2c 20 77 65 20 6b 6e 6f h object, we kno
d1a0: 77 0a 09 20 2a 20 74 68 61 74 20 74 68 65 20 74 w.. * that the t
d1b0: 72 61 6e 73 6c 61 74 65 64 50 61 74 68 50 74 72 ranslatedPathPtr
d1c0: 20 63 61 6e 6e 6f 74 20 62 65 20 4e 55 4c 4c 2e cannot be NULL.
d1d0: 0a 09 20 2a 2f 0a 0a 09 54 63 6c 5f 4f 62 6a 20 .. */...Tcl_Obj
d1e0: 2a 61 62 73 6f 6c 75 74 65 50 61 74 68 20 3d 20 *absolutePath =
d1f0: 66 73 50 61 74 68 50 74 72 2d 3e 74 72 61 6e 73 fsPathPtr->trans
d200: 6c 61 74 65 64 50 61 74 68 50 74 72 3b 0a 09 63 latedPathPtr;..c
d210: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 20 onst char *path
d220: 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67 28 61 = TclGetString(a
d230: 62 73 6f 6c 75 74 65 50 61 74 68 29 3b 0a 0a 09 bsolutePath);...
d240: 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 Tcl_IncrRefCount
d250: 28 61 62 73 6f 6c 75 74 65 50 61 74 68 29 3b 0a (absolutePath);.
d260: 0a 09 2f 2a 0a 09 20 2a 20 57 65 20 68 61 76 65 ../*.. * We have
d270: 20 74 6f 20 62 65 20 61 20 6c 69 74 74 6c 65 20 to be a little
d280: 62 69 74 20 63 61 72 65 66 75 6c 20 68 65 72 65 bit careful here
d290: 20 74 6f 20 61 76 6f 69 64 20 69 6e 66 69 6e 69 to avoid infini
d2a0: 74 65 20 6c 6f 6f 70 73 0a 09 20 2a 20 77 65 27 te loops.. * we'
d2b0: 72 65 20 61 73 6b 69 6e 67 20 54 63 6c 5f 46 53 re asking Tcl_FS
d2c0: 47 65 74 50 61 74 68 54 79 70 65 20 74 6f 20 72 GetPathType to r
d2d0: 65 74 75 72 6e 20 74 68 65 20 70 61 74 68 27 73 eturn the path's
d2e0: 20 74 79 70 65 2c 20 62 75 74 20 74 68 61 74 0a type, but that.
d2f0: 09 20 2a 20 63 61 6c 6c 20 63 61 6e 20 61 63 74 . * call can act
d300: 75 61 6c 6c 79 20 72 65 73 75 6c 74 20 69 6e 20 ually result in
d310: 61 20 6c 6f 74 20 6f 66 20 6f 74 68 65 72 20 66 a lot of other f
d320: 69 6c 65 73 79 73 74 65 6d 20 61 63 74 69 6f 6e ilesystem action
d330: 2c 20 77 68 69 63 68 0a 09 20 2a 20 6d 69 67 68 , which.. * migh
d340: 74 20 6c 6f 6f 70 20 62 61 63 6b 20 74 68 72 6f t loop back thro
d350: 75 67 68 20 68 65 72 65 2e 0a 09 20 2a 2f 0a 0a ugh here... */..
d360: 09 69 66 20 28 70 61 74 68 5b 30 5d 20 3d 3d 20 .if (path[0] ==
d370: 27 5c 30 27 29 20 7b 0a 09 20 20 20 20 2f 2a 0a '\0') {.. /*.
d380: 09 20 20 20 20 20 2a 20 53 70 65 63 69 61 6c 20 . * Special
d390: 68 61 6e 64 6c 69 6e 67 20 66 6f 72 20 74 68 65 handling for the
d3a0: 20 65 6d 70 74 79 20 73 74 72 69 6e 67 20 76 61 empty string va
d3b0: 6c 75 65 2e 20 54 68 69 73 20 6f 6e 65 20 69 73 lue. This one is
d3c0: 20 76 65 72 79 0a 09 20 20 20 20 20 2a 20 77 65 very.. * we
d3d0: 69 72 64 20 77 69 74 68 20 5b 66 69 6c 65 20 6e ird with [file n
d3e0: 6f 72 6d 61 6c 69 7a 65 20 7b 7d 5d 20 3d 3e 20 ormalize {}] =>
d3f0: 7b 7d 2e 20 28 54 68 65 20 72 65 61 73 6f 6e 69 {}. (The reasoni
d400: 6e 67 20 73 75 70 70 6f 72 74 69 6e 67 0a 09 20 ng supporting..
d410: 20 20 20 20 2a 20 74 68 69 73 20 69 73 20 75 6e * this is un
d420: 6b 6e 6f 77 6e 20 74 6f 20 44 47 50 2c 20 62 75 known to DGP, bu
d430: 74 20 68 65 20 66 65 61 72 73 20 63 68 61 6e 67 t he fears chang
d440: 69 6e 67 20 69 74 2e 29 20 41 74 74 65 6d 70 74 ing it.) Attempt
d450: 20 68 65 72 65 0a 09 20 20 20 20 20 2a 20 74 6f here.. * to
d460: 20 6b 65 65 70 20 74 68 65 20 65 78 70 65 63 74 keep the expect
d470: 61 74 69 6f 6e 73 20 6f 66 20 6f 74 68 65 72 20 ations of other
d480: 70 61 72 74 73 20 6f 66 20 54 63 6c 5f 46 69 6c parts of Tcl_Fil
d490: 65 73 79 73 74 65 6d 20 63 6f 64 65 0a 09 20 20 esystem code..
d4a0: 20 20 20 2a 20 61 62 6f 75 74 20 73 74 61 74 65 * about state
d4b0: 20 6f 66 20 74 68 65 20 46 73 50 61 74 68 20 66 of the FsPath f
d4c0: 69 65 6c 64 73 20 73 61 74 69 73 66 69 65 64 2e ields satisfied.
d4d0: 0a 09 20 20 20 20 20 2a 0a 09 20 20 20 20 20 2a .. *.. *
d4e0: 20 49 6e 20 70 61 72 74 69 63 75 6c 61 72 2c 20 In particular,
d4f0: 63 61 70 74 75 72 65 20 74 68 65 20 63 77 64 20 capture the cwd
d500: 76 61 6c 75 65 20 61 6e 64 20 73 61 76 65 20 73 value and save s
d510: 6f 20 69 74 20 63 61 6e 20 62 65 0a 09 20 20 20 o it can be..
d520: 20 20 2a 20 73 74 6f 72 65 64 20 69 6e 20 74 68 * stored in th
d530: 65 20 63 77 64 50 74 72 20 66 69 65 6c 64 20 62 e cwdPtr field b
d540: 65 6c 6f 77 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a elow... */..
d550: 09 20 20 20 20 75 73 65 54 68 69 73 43 77 64 20 . useThisCwd
d560: 3d 20 54 63 6c 5f 46 53 47 65 74 43 77 64 28 69 = Tcl_FSGetCwd(i
d570: 6e 74 65 72 70 29 3b 0a 09 7d 20 65 6c 73 65 20 nterp);..} else
d580: 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 {.. /*..
d590: 2a 20 57 65 20 64 6f 6e 27 74 20 61 73 6b 20 66 * We don't ask f
d5a0: 6f 72 20 74 68 65 20 74 79 70 65 20 6f 66 20 27 or the type of '
d5b0: 70 61 74 68 50 74 72 27 20 68 65 72 65 2c 20 62 pathPtr' here, b
d5c0: 65 63 61 75 73 65 20 74 68 61 74 20 69 73 0a 09 ecause that is..
d5d0: 20 20 20 20 20 2a 20 6e 6f 74 20 63 6f 72 72 65 * not corre
d5e0: 63 74 20 66 6f 72 20 6f 75 72 20 70 75 72 70 6f ct for our purpo
d5f0: 73 65 73 20 77 68 65 6e 20 77 65 20 68 61 76 65 ses when we have
d600: 20 61 20 70 61 74 68 20 6c 69 6b 65 20 27 7e 27 a path like '~'
d610: 2e 20 54 63 6c 0a 09 20 20 20 20 20 2a 20 68 61 . Tcl.. * ha
d620: 73 20 61 20 62 69 74 20 6f 66 20 61 20 63 6f 6e s a bit of a con
d630: 74 72 61 64 69 63 74 69 6f 6e 20 69 6e 20 74 68 tradiction in th
d640: 61 74 20 27 7e 27 20 70 61 74 68 73 20 61 72 65 at '~' paths are
d650: 20 64 65 66 69 6e 65 64 20 61 73 0a 09 20 20 20 defined as..
d660: 20 20 2a 20 27 61 62 73 6f 6c 75 74 65 27 2c 20 * 'absolute',
d670: 62 75 74 20 69 6e 20 72 65 61 6c 69 74 79 20 63 but in reality c
d680: 61 6e 20 62 65 20 6a 75 73 74 20 61 62 6f 75 74 an be just about
d690: 20 61 6e 79 74 68 69 6e 67 2c 0a 09 20 20 20 20 anything,..
d6a0: 20 2a 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 * depending on
d6b0: 68 6f 77 20 65 6e 76 28 48 4f 4d 45 29 20 69 73 how env(HOME) is
d6c0: 20 73 65 74 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a set... */..
d6d0: 09 20 20 20 20 54 63 6c 5f 50 61 74 68 54 79 70 . Tcl_PathTyp
d6e0: 65 20 74 79 70 65 20 3d 20 54 63 6c 5f 46 53 47 e type = Tcl_FSG
d6f0: 65 74 50 61 74 68 54 79 70 65 28 61 62 73 6f 6c etPathType(absol
d700: 75 74 65 50 61 74 68 29 3b 0a 0a 09 20 20 20 20 utePath);...
d710: 69 66 20 28 74 79 70 65 20 3d 3d 20 54 43 4c 5f if (type == TCL_
d720: 50 41 54 48 5f 52 45 4c 41 54 49 56 45 29 20 7b PATH_RELATIVE) {
d730: 0a 09 09 75 73 65 54 68 69 73 43 77 64 20 3d 20 ...useThisCwd =
d740: 54 63 6c 5f 46 53 47 65 74 43 77 64 28 69 6e 74 Tcl_FSGetCwd(int
d750: 65 72 70 29 3b 0a 0a 09 09 69 66 20 28 75 73 65 erp);....if (use
d760: 54 68 69 73 43 77 64 20 3d 3d 20 4e 55 4c 4c 29 ThisCwd == NULL)
d770: 20 7b 0a 09 09 20 20 20 20 72 65 74 75 72 6e 20 {... return
d780: 4e 55 4c 4c 3b 0a 09 09 7d 0a 0a 09 09 70 75 72 NULL;...}....pur
d790: 65 4e 6f 72 6d 61 6c 69 7a 65 64 20 3d 20 30 3b eNormalized = 0;
d7a0: 0a 09 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f ...Tcl_DecrRefCo
d7b0: 75 6e 74 28 61 62 73 6f 6c 75 74 65 50 61 74 68 unt(absolutePath
d7c0: 29 3b 0a 09 09 61 62 73 6f 6c 75 74 65 50 61 74 );...absolutePat
d7d0: 68 20 3d 20 54 63 6c 5f 46 53 4a 6f 69 6e 54 6f h = Tcl_FSJoinTo
d7e0: 50 61 74 68 28 75 73 65 54 68 69 73 43 77 64 2c Path(useThisCwd,
d7f0: 20 31 2c 20 26 61 62 73 6f 6c 75 74 65 50 61 74 1, &absolutePat
d800: 68 29 3b 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 h);...Tcl_IncrRe
d810: 66 43 6f 75 6e 74 28 61 62 73 6f 6c 75 74 65 50 fCount(absoluteP
d820: 61 74 68 29 3b 0a 0a 09 09 2f 2a 0a 09 09 20 2a ath);..../*... *
d830: 20 57 65 20 68 61 76 65 20 61 20 72 65 66 43 6f We have a refCo
d840: 75 6e 74 20 6f 6e 20 74 68 65 20 63 77 64 2e 0a unt on the cwd..
d850: 09 09 20 2a 2f 0a 23 69 66 64 65 66 20 5f 57 49 .. */.#ifdef _WI
d860: 4e 33 32 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 N32.. } else
d870: 69 66 20 28 74 79 70 65 20 3d 3d 20 54 43 4c 5f if (type == TCL_
d880: 50 41 54 48 5f 56 4f 4c 55 4d 45 5f 52 45 4c 41 PATH_VOLUME_RELA
d890: 54 49 56 45 29 20 7b 0a 09 09 2f 2a 0a 09 09 20 TIVE) {.../*...
d8a0: 2a 20 4f 6e 6c 79 20 57 69 6e 64 6f 77 73 20 68 * Only Windows h
d8b0: 61 73 20 76 6f 6c 75 6d 65 2d 72 65 6c 61 74 69 as volume-relati
d8c0: 76 65 20 70 61 74 68 73 2e 0a 09 09 20 2a 2f 0a ve paths.... */.
d8d0: 0a 09 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f ...Tcl_DecrRefCo
d8e0: 75 6e 74 28 61 62 73 6f 6c 75 74 65 50 61 74 68 unt(absolutePath
d8f0: 29 3b 0a 09 09 61 62 73 6f 6c 75 74 65 50 61 74 );...absolutePat
d900: 68 20 3d 20 54 63 6c 57 69 6e 56 6f 6c 75 6d 65 h = TclWinVolume
d910: 52 65 6c 61 74 69 76 65 4e 6f 72 6d 61 6c 69 7a RelativeNormaliz
d920: 65 28 69 6e 74 65 72 70 2c 0a 09 09 09 70 61 74 e(interp,....pat
d930: 68 2c 20 26 75 73 65 54 68 69 73 43 77 64 29 3b h, &useThisCwd);
d940: 0a 09 09 69 66 20 28 61 62 73 6f 6c 75 74 65 50 ...if (absoluteP
d950: 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 ath == NULL) {..
d960: 09 20 20 20 20 72 65 74 75 72 6e 20 4e 55 4c 4c . return NULL
d970: 3b 0a 09 09 7d 0a 09 09 70 75 72 65 4e 6f 72 6d ;...}...pureNorm
d980: 61 6c 69 7a 65 64 20 3d 20 30 3b 0a 23 65 6e 64 alized = 0;.#end
d990: 69 66 20 2f 2a 20 5f 57 49 4e 33 32 20 2a 2f 0a if /* _WIN32 */.
d9a0: 09 20 20 20 20 7d 0a 09 7d 0a 0a 09 2f 2a 0a 09 . }..}.../*..
d9b0: 20 2a 20 41 6c 72 65 61 64 79 20 68 61 73 20 72 * Already has r
d9c0: 65 66 43 6f 75 6e 74 20 69 6e 63 72 65 6d 65 6e efCount incremen
d9d0: 74 65 64 2e 0a 09 20 2a 2f 0a 0a 09 66 73 50 61 ted... */...fsPa
d9e0: 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 thPtr->normPathP
d9f0: 74 72 20 3d 20 54 63 6c 46 53 4e 6f 72 6d 61 6c tr = TclFSNormal
da00: 69 7a 65 41 62 73 6f 6c 75 74 65 50 61 74 68 28 izeAbsolutePath(
da10: 69 6e 74 65 72 70 2c 0a 09 09 61 62 73 6f 6c 75 interp,...absolu
da20: 74 65 50 61 74 68 29 3b 0a 0a 09 2f 2a 0a 09 20 tePath);.../*..
da30: 2a 20 43 68 65 63 6b 20 69 66 20 70 61 74 68 20 * Check if path
da40: 69 73 20 70 75 72 65 20 6e 6f 72 6d 61 6c 69 7a is pure normaliz
da50: 65 64 20 28 74 68 69 73 20 63 61 6e 20 6f 6e 6c ed (this can onl
da60: 79 20 62 65 20 74 68 65 20 63 61 73 65 20 69 66 y be the case if
da70: 20 69 74 0a 09 20 2a 20 69 73 20 61 6e 20 61 62 it.. * is an ab
da80: 73 6f 6c 75 74 65 20 70 61 74 68 29 2e 0a 09 20 solute path)...
da90: 2a 2f 0a 0a 09 69 66 20 28 70 75 72 65 4e 6f 72 */...if (pureNor
daa0: 6d 61 6c 69 7a 65 64 29 20 7b 0a 09 20 20 20 20 malized) {..
dab0: 69 6e 74 20 6e 6f 72 6d 50 61 74 68 4c 65 6e 2c int normPathLen,
dac0: 20 70 61 74 68 4c 65 6e 3b 0a 09 20 20 20 20 63 pathLen;.. c
dad0: 6f 6e 73 74 20 63 68 61 72 20 2a 6e 6f 72 6d 50 onst char *normP
dae0: 61 74 68 3b 0a 0a 09 20 20 20 20 70 61 74 68 20 ath;... path
daf0: 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67 46 72 = TclGetStringFr
db00: 6f 6d 4f 62 6a 28 70 61 74 68 50 74 72 2c 20 26 omObj(pathPtr, &
db10: 70 61 74 68 4c 65 6e 29 3b 0a 09 20 20 20 20 6e pathLen);.. n
db20: 6f 72 6d 50 61 74 68 20 3d 20 54 63 6c 47 65 74 ormPath = TclGet
db30: 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 66 73 StringFromObj(fs
db40: 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
db50: 68 50 74 72 2c 20 26 6e 6f 72 6d 50 61 74 68 4c hPtr, &normPathL
db60: 65 6e 29 3b 0a 09 20 20 20 20 69 66 20 28 28 70 en);.. if ((p
db70: 61 74 68 4c 65 6e 20 3d 3d 20 6e 6f 72 6d 50 61 athLen == normPa
db80: 74 68 4c 65 6e 29 20 26 26 20 21 6d 65 6d 63 6d thLen) && !memcm
db90: 70 28 70 61 74 68 2c 20 6e 6f 72 6d 50 61 74 68 p(path, normPath
dba0: 2c 20 70 61 74 68 4c 65 6e 29 29 20 7b 0a 09 09 , pathLen)) {...
dbb0: 2f 2a 0a 09 09 20 2a 20 54 68 65 20 70 61 74 68 /*... * The path
dbc0: 20 77 61 73 20 61 6c 72 65 61 64 79 20 6e 6f 72 was already nor
dbd0: 6d 61 6c 69 7a 65 64 2e 20 47 65 74 20 72 69 64 malized. Get rid
dbe0: 20 6f 66 20 74 68 65 20 64 75 70 6c 69 63 61 74 of the duplicat
dbf0: 65 2e 0a 09 09 20 2a 2f 0a 0a 09 09 54 63 6c 44 e.... */....TclD
dc00: 65 63 72 52 65 66 43 6f 75 6e 74 28 66 73 50 61 ecrRefCount(fsPa
dc10: 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 thPtr->normPathP
dc20: 74 72 29 3b 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 tr);..../*... *
dc30: 57 65 20 64 6f 20 2a 6e 6f 74 2a 20 69 6e 63 72 We do *not* incr
dc40: 65 6d 65 6e 74 20 74 68 65 20 72 65 66 43 6f 75 ement the refCou
dc50: 6e 74 20 66 6f 72 20 74 68 69 73 20 63 69 72 63 nt for this circ
dc60: 75 6c 61 72 0a 09 09 20 2a 20 72 65 66 65 72 65 ular... * refere
dc70: 6e 63 65 2e 0a 09 09 20 2a 2f 0a 0a 09 09 66 73 nce.... */....fs
dc80: 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
dc90: 68 50 74 72 20 3d 20 70 61 74 68 50 74 72 3b 0a hPtr = pathPtr;.
dca0: 09 20 20 20 20 7d 0a 09 7d 0a 09 69 66 20 28 75 . }..}..if (u
dcb0: 73 65 54 68 69 73 43 77 64 20 21 3d 20 4e 55 4c seThisCwd != NUL
dcc0: 4c 29 20 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 L) {.. /*..
dcd0: 20 20 20 2a 20 57 65 20 6a 75 73 74 20 6e 65 65 * We just nee
dce0: 64 20 74 6f 20 66 72 65 65 20 61 6e 20 6f 62 6a d to free an obj
dcf0: 65 63 74 20 77 65 20 61 6c 6c 6f 63 61 74 65 64 ect we allocated
dd00: 20 61 62 6f 76 65 20 66 6f 72 20 72 65 6c 61 74 above for relat
dd10: 69 76 65 0a 09 20 20 20 20 20 2a 20 70 61 74 68 ive.. * path
dd20: 73 20 28 74 68 69 73 20 77 61 73 20 72 65 74 75 s (this was retu
dd30: 72 6e 65 64 20 62 79 20 54 63 6c 5f 46 53 4a 6f rned by Tcl_FSJo
dd40: 69 6e 54 6f 50 61 74 68 20 61 62 6f 76 65 29 2c inToPath above),
dd50: 20 61 6e 64 20 74 68 65 6e 0a 09 20 20 20 20 20 and then..
dd60: 2a 20 6f 66 20 63 6f 75 72 73 65 20 73 74 6f 72 * of course stor
dd70: 65 20 74 68 65 20 63 77 64 2e 0a 09 20 20 20 20 e the cwd...
dd80: 20 2a 2f 0a 0a 09 20 20 20 20 66 73 50 61 74 68 */... fsPath
dd90: 50 74 72 2d 3e 63 77 64 50 74 72 20 3d 20 75 73 Ptr->cwdPtr = us
dda0: 65 54 68 69 73 43 77 64 3b 0a 09 7d 0a 09 54 63 eThisCwd;..}..Tc
ddb0: 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 61 62 lDecrRefCount(ab
ddc0: 73 6f 6c 75 74 65 50 61 74 68 29 3b 0a 20 20 20 solutePath);.
ddd0: 20 7d 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 66 }.. return f
dde0: 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 sPathPtr->normPa
ddf0: 74 68 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a thPtr;.}.../*. *
de00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
de10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
de20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
de30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
de40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 -----------. *.
de50: 2a 20 54 63 6c 5f 46 53 47 65 74 49 6e 74 65 72 * Tcl_FSGetInter
de60: 6e 61 6c 52 65 70 20 2d 2d 0a 20 2a 0a 20 2a 09 nalRep --. *. *.
de70: 45 78 74 72 61 63 74 20 74 68 65 20 69 6e 74 65 Extract the inte
de80: 72 6e 61 6c 20 72 65 70 72 65 73 65 6e 74 61 74 rnal representat
de90: 69 6f 6e 20 6f 66 20 61 20 67 69 76 65 6e 20 70 ion of a given p
dea0: 61 74 68 20 6f 62 6a 65 63 74 2c 20 69 6e 20 74 ath object, in t
deb0: 68 65 0a 20 2a 09 67 69 76 65 6e 20 66 69 6c 65 he. *.given file
dec0: 73 79 73 74 65 6d 2e 20 49 66 20 74 68 65 20 70 system. If the p
ded0: 61 74 68 20 6f 62 6a 65 63 74 20 62 65 6c 6f 6e ath object belon
dee0: 67 73 20 74 6f 20 61 20 64 69 66 66 65 72 65 6e gs to a differen
def0: 74 0a 20 2a 09 66 69 6c 65 73 79 73 74 65 6d 2c t. *.filesystem,
df00: 20 77 65 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e we return NULL.
df10: 0a 20 2a 0a 20 2a 09 49 66 20 74 68 65 20 69 6e . *. *.If the in
df20: 74 65 72 6e 61 6c 20 72 65 70 72 65 73 65 6e 74 ternal represent
df30: 61 74 69 6f 6e 20 69 73 20 63 75 72 72 65 6e 74 ation is current
df40: 6c 79 20 4e 55 4c 4c 2c 20 77 65 20 61 74 74 65 ly NULL, we atte
df50: 6d 70 74 20 74 6f 0a 20 2a 09 67 65 6e 65 72 61 mpt to. *.genera
df60: 74 65 20 69 74 2c 20 62 79 20 63 61 6c 6c 69 6e te it, by callin
df70: 67 20 74 68 65 20 66 69 6c 65 73 79 73 74 65 6d g the filesystem
df80: 27 73 0a 20 2a 09 27 54 63 6c 5f 46 53 43 72 65 's. *.'Tcl_FSCre
df90: 61 74 65 49 6e 74 65 72 6e 61 6c 52 65 70 50 72 ateInternalRepPr
dfa0: 6f 63 27 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c oc'.. *. * Resul
dfb0: 74 73 3a 0a 20 2a 09 4e 55 4c 4c 20 6f 72 20 61 ts:. *.NULL or a
dfc0: 20 76 61 6c 69 64 20 69 6e 74 65 72 6e 61 6c 20 valid internal
dfd0: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2e 0a representation..
dfe0: 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 *. * Side effec
dff0: 74 73 3a 0a 20 2a 09 41 6e 20 61 74 74 65 6d 70 ts:. *.An attemp
e000: 74 20 6d 61 79 20 62 65 20 6d 61 64 65 20 74 6f t may be made to
e010: 20 63 6f 6e 76 65 72 74 20 74 68 65 20 6f 62 6a convert the obj
e020: 65 63 74 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d ect.. *. *------
e030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
e040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
e050: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
e060: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
e070: 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 43 6c 69 65 6e -----. */..Clien
e080: 74 44 61 74 61 0a 54 63 6c 5f 46 53 47 65 74 49 tData.Tcl_FSGetI
e090: 6e 74 65 72 6e 61 6c 52 65 70 28 0a 20 20 20 20 nternalRep(.
e0a0: 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 68 50 74 72 Tcl_Obj *pathPtr
e0b0: 2c 0a 20 20 20 20 63 6f 6e 73 74 20 54 63 6c 5f ,. const Tcl_
e0c0: 46 69 6c 65 73 79 73 74 65 6d 20 2a 66 73 50 74 Filesystem *fsPt
e0d0: 72 29 0a 7b 0a 20 20 20 20 46 73 50 61 74 68 20 r).{. FsPath
e0e0: 2a 73 72 63 46 73 50 61 74 68 50 74 72 3b 0a 0a *srcFsPathPtr;..
e0f0: 20 20 20 20 69 66 20 28 54 63 6c 5f 46 53 43 6f if (Tcl_FSCo
e100: 6e 76 65 72 74 54 6f 50 61 74 68 54 79 70 65 28 nvertToPathType(
e110: 4e 55 4c 4c 2c 20 70 61 74 68 50 74 72 29 20 21 NULL, pathPtr) !
e120: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 72 65 74 = TCL_OK) {..ret
e130: 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a urn NULL;. }.
e140: 20 20 20 20 73 72 63 46 73 50 61 74 68 50 74 72 srcFsPathPtr
e150: 20 3d 20 50 41 54 48 4f 42 4a 28 70 61 74 68 50 = PATHOBJ(pathP
e160: 74 72 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 tr);.. /*.
e170: 20 20 2a 20 57 65 20 77 69 6c 6c 20 6f 6e 6c 79 * We will only
e180: 20 72 65 74 75 72 6e 20 74 68 65 20 6e 61 74 69 return the nati
e190: 76 65 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ve representatio
e1a0: 6e 20 66 6f 72 20 74 68 65 20 63 61 6c 6c 65 72 n for the caller
e1b0: 27 73 0a 20 20 20 20 20 2a 20 66 69 6c 65 73 79 's. * filesy
e1c0: 73 74 65 6d 2e 20 4f 74 68 65 72 77 69 73 65 20 stem. Otherwise
e1d0: 77 65 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 72 we will simply r
e1e0: 65 74 75 72 6e 20 4e 55 4c 4c 2e 20 54 68 69 73 eturn NULL. This
e1f0: 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 72 means that ther
e200: 65 0a 20 20 20 20 20 2a 20 6d 75 73 74 20 62 65 e. * must be
e210: 20 61 20 75 6e 69 71 75 65 20 62 69 2d 64 69 72 a unique bi-dir
e220: 65 63 74 69 6f 6e 61 6c 20 6d 61 70 70 69 6e 67 ectional mapping
e230: 20 62 65 74 77 65 65 6e 20 70 61 74 68 73 20 61 between paths a
e240: 6e 64 20 66 69 6c 65 73 79 73 74 65 6d 73 2c 0a nd filesystems,.
e250: 20 20 20 20 20 2a 20 61 6e 64 20 74 68 61 74 20 * and that
e260: 74 68 69 73 20 6d 61 70 70 69 6e 67 20 77 69 6c this mapping wil
e270: 6c 20 6e 6f 74 20 61 6c 6c 6f 77 20 27 72 65 6d l not allow 'rem
e280: 61 70 70 65 64 27 20 66 69 6c 65 73 20 2d 2d 20 apped' files --
e290: 66 69 6c 65 73 20 77 68 69 63 68 0a 20 20 20 20 files which.
e2a0: 20 2a 20 61 72 65 20 69 6e 20 6f 6e 65 20 66 69 * are in one fi
e2b0: 6c 65 73 79 73 74 65 6d 20 62 75 74 20 6d 61 70 lesystem but map
e2c0: 70 65 64 20 69 6e 74 6f 20 61 6e 6f 74 68 65 72 ped into another
e2d0: 2e 20 41 6e 6f 74 68 65 72 20 77 61 79 20 6f 66 . Another way of
e2e0: 20 70 75 74 74 69 6e 67 0a 20 20 20 20 20 2a 20 putting. *
e2f0: 74 68 69 73 20 69 73 20 74 68 61 74 20 27 73 74 this is that 'st
e300: 61 63 6b 65 64 27 20 66 69 6c 65 73 79 73 74 65 acked' filesyste
e310: 6d 73 20 61 72 65 20 6e 6f 74 20 61 6c 6c 6f 77 ms are not allow
e320: 65 64 2e 20 57 65 20 72 65 63 6f 67 6e 69 73 65 ed. We recognise
e330: 20 74 68 61 74 0a 20 20 20 20 20 2a 20 74 68 69 that. * thi
e340: 73 20 69 73 20 61 20 70 6f 74 65 6e 74 69 61 6c s is a potential
e350: 6c 79 20 75 73 65 66 75 6c 20 66 65 61 74 75 72 ly useful featur
e360: 65 20 66 6f 72 20 74 68 65 20 66 75 74 75 72 65 e for the future
e370: 2e 0a 20 20 20 20 20 2a 0a 20 20 20 20 20 2a 20 .. *. *
e380: 45 76 65 6e 20 73 6f 6d 65 74 68 69 6e 67 20 73 Even something s
e390: 69 6d 70 6c 65 20 6c 69 6b 65 20 61 20 27 70 61 imple like a 'pa
e3a0: 73 73 20 74 68 72 6f 75 67 68 27 20 66 69 6c 65 ss through' file
e3b0: 73 79 73 74 65 6d 20 77 68 69 63 68 20 6c 6f 67 system which log
e3c0: 73 20 61 6c 6c 0a 20 20 20 20 20 2a 20 61 63 74 s all. * act
e3d0: 69 76 69 74 79 20 61 6e 64 20 70 61 73 73 65 73 ivity and passes
e3e0: 20 74 68 65 20 63 61 6c 6c 73 20 6f 6e 74 6f 20 the calls onto
e3f0: 74 68 65 20 6e 61 74 69 76 65 20 73 79 73 74 65 the native syste
e400: 6d 20 77 6f 75 6c 64 20 62 65 20 6e 69 63 65 2c m would be nice,
e410: 20 62 75 74 0a 20 20 20 20 20 2a 20 6e 6f 74 20 but. * not
e420: 65 61 73 69 6c 79 20 61 63 68 69 65 76 61 62 6c easily achievabl
e430: 65 20 77 69 74 68 20 74 68 65 20 63 75 72 72 65 e with the curre
e440: 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f nt implementatio
e450: 6e 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 n.. */..
e460: 69 66 20 28 73 72 63 46 73 50 61 74 68 50 74 72 if (srcFsPathPtr
e470: 2d 3e 66 73 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 ->fsPtr == NULL)
e480: 20 7b 0a 09 2f 2a 0a 09 20 2a 20 54 68 69 73 20 {../*.. * This
e490: 6f 6e 6c 79 20 75 73 75 61 6c 6c 79 20 68 61 70 only usually hap
e4a0: 70 65 6e 73 20 69 6e 20 77 72 61 70 70 65 72 73 pens in wrappers
e4b0: 20 6c 69 6b 65 20 54 63 6c 70 53 74 61 74 20 77 like TclpStat w
e4c0: 68 69 63 68 20 63 72 65 61 74 65 20 61 0a 09 20 hich create a..
e4d0: 2a 20 73 74 72 69 6e 67 20 6f 62 6a 65 63 74 20 * string object
e4e0: 61 6e 64 20 70 61 73 73 20 69 74 20 74 6f 20 54 and pass it to T
e4f0: 63 6c 70 4f 62 6a 53 74 61 74 2e 20 43 6f 64 65 clpObjStat. Code
e500: 20 77 68 69 63 68 20 63 61 6c 6c 73 20 74 68 65 which calls the
e510: 0a 09 20 2a 20 54 63 6c 5f 46 53 2e 2e 20 66 75 .. * Tcl_FS.. fu
e520: 6e 63 74 69 6f 6e 73 20 73 68 6f 75 6c 64 20 61 nctions should a
e530: 6c 77 61 79 73 20 68 61 76 65 20 61 20 66 69 6c lways have a fil
e540: 65 73 79 73 74 65 6d 20 61 6c 72 65 61 64 79 20 esystem already
e550: 73 65 74 2e 0a 09 20 2a 20 57 68 65 74 68 65 72 set... * Whether
e560: 20 74 68 69 73 20 63 6f 64 65 20 70 61 74 68 20 this code path
e570: 69 73 20 6c 65 67 61 6c 20 6f 72 20 6e 6f 74 20 is legal or not
e580: 64 65 70 65 6e 64 73 20 6f 6e 20 77 68 65 74 68 depends on wheth
e590: 65 72 20 77 65 20 64 65 63 69 64 65 0a 09 20 2a er we decide.. *
e5a0: 20 74 6f 20 61 6c 6c 6f 77 20 65 78 74 65 72 6e to allow extern
e5b0: 61 6c 20 63 6f 64 65 20 74 6f 20 63 61 6c 6c 20 al code to call
e5c0: 74 68 65 20 6e 61 74 69 76 65 20 66 69 6c 65 73 the native files
e5d0: 79 73 74 65 6d 20 64 69 72 65 63 74 6c 79 2e 20 ystem directly.
e5e0: 49 74 0a 09 20 2a 20 69 73 20 61 74 20 6c 65 61 It.. * is at lea
e5f0: 73 74 20 73 61 66 65 72 20 74 6f 20 61 6c 6c 6f st safer to allo
e600: 77 20 74 68 69 73 20 73 75 62 2d 6f 70 74 69 6d w this sub-optim
e610: 61 6c 20 72 6f 75 74 69 6e 67 2e 0a 09 20 2a 2f al routing... */
e620: 0a 0a 09 54 63 6c 5f 46 53 47 65 74 46 69 6c 65 ...Tcl_FSGetFile
e630: 53 79 73 74 65 6d 46 6f 72 50 61 74 68 28 70 61 SystemForPath(pa
e640: 74 68 50 74 72 29 3b 0a 0a 09 2f 2a 0a 09 20 2a thPtr);.../*.. *
e650: 20 49 66 20 77 65 20 66 61 69 6c 20 74 68 72 6f If we fail thro
e660: 75 67 68 20 68 65 72 65 2c 20 74 68 65 6e 20 74 ugh here, then t
e670: 68 65 20 70 61 74 68 20 69 73 20 70 72 6f 62 61 he path is proba
e680: 62 6c 79 20 6e 6f 74 20 61 20 76 61 6c 69 64 20 bly not a valid
e690: 70 61 74 68 0a 09 20 2a 20 69 6e 20 74 68 65 20 path.. * in the
e6a0: 66 69 6c 65 73 79 73 74 73 65 6d 2c 20 61 6e 64 filesystsem, and
e6b0: 20 69 73 20 6d 6f 73 74 20 6c 69 6b 65 6c 79 20 is most likely
e6c0: 74 6f 20 62 65 20 61 20 75 73 65 20 6f 66 20 74 to be a use of t
e6d0: 68 65 20 65 6d 70 74 79 0a 09 20 2a 20 70 61 74 he empty.. * pat
e6e0: 68 20 22 22 20 76 69 61 20 61 20 64 69 72 65 63 h "" via a direc
e6f0: 74 20 63 61 6c 6c 20 74 6f 20 6f 6e 65 20 6f 66 t call to one of
e700: 20 74 68 65 20 6f 62 6a 65 63 74 69 66 69 65 64 the objectified
e710: 20 69 6e 74 65 72 66 61 63 65 73 0a 09 20 2a 20 interfaces.. *
e720: 28 65 2e 67 2e 20 66 72 6f 6d 20 74 68 65 20 54 (e.g. from the T
e730: 63 6c 20 74 65 73 74 73 75 69 74 65 29 2e 0a 09 cl testsuite)...
e740: 20 2a 2f 0a 0a 09 73 72 63 46 73 50 61 74 68 50 */...srcFsPathP
e750: 74 72 20 3d 20 50 41 54 48 4f 42 4a 28 70 61 74 tr = PATHOBJ(pat
e760: 68 50 74 72 29 3b 0a 09 69 66 20 28 73 72 63 46 hPtr);..if (srcF
e770: 73 50 61 74 68 50 74 72 2d 3e 66 73 50 74 72 20 sPathPtr->fsPtr
e780: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 == NULL) {..
e790: 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 09 7d 0a return NULL;..}.
e7a0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 }.. /*.
e7b0: 20 20 20 2a 20 54 68 65 72 65 20 69 73 20 73 74 * There is st
e7c0: 69 6c 6c 20 6f 6e 65 20 70 6f 73 73 69 62 69 6c ill one possibil
e7d0: 69 74 79 20 77 65 20 73 68 6f 75 6c 64 20 63 6f ity we should co
e7e0: 6e 73 69 64 65 72 3b 20 69 66 20 74 68 65 20 66 nsider; if the f
e7f0: 69 6c 65 20 62 65 6c 6f 6e 67 73 0a 20 20 20 20 ile belongs.
e800: 20 2a 20 74 6f 20 61 20 64 69 66 66 65 72 65 6e * to a differen
e810: 74 20 66 69 6c 65 73 79 73 74 65 6d 2c 20 70 65 t filesystem, pe
e820: 72 68 61 70 73 20 69 74 20 69 73 20 61 63 74 75 rhaps it is actu
e830: 61 6c 6c 79 20 6c 69 6e 6b 65 64 20 74 68 72 6f ally linked thro
e840: 75 67 68 20 74 6f 20 61 0a 20 20 20 20 20 2a 20 ugh to a. *
e850: 66 69 6c 65 20 69 6e 20 6f 75 72 20 6f 77 6e 20 file in our own
e860: 66 69 6c 65 73 79 73 74 65 6d 20 77 68 69 63 68 filesystem which
e870: 20 77 65 20 64 6f 20 63 61 72 65 20 61 62 6f 75 we do care abou
e880: 74 2e 20 54 68 65 20 77 61 79 20 77 65 20 63 61 t. The way we ca
e890: 6e 20 63 68 65 63 6b 0a 20 20 20 20 20 2a 20 66 n check. * f
e8a0: 6f 72 20 74 68 69 73 20 69 73 20 77 65 20 61 73 or this is we as
e8b0: 6b 20 77 68 61 74 20 66 69 6c 65 73 79 73 74 65 k what filesyste
e8c0: 6d 20 74 68 69 73 20 70 61 74 68 20 62 65 6c 6f m this path belo
e8d0: 6e 67 73 20 74 6f 2e 0a 20 20 20 20 20 2a 2f 0a ngs to.. */.
e8e0: 0a 20 20 20 20 69 66 20 28 66 73 50 74 72 20 21 . if (fsPtr !
e8f0: 3d 20 73 72 63 46 73 50 61 74 68 50 74 72 2d 3e = srcFsPathPtr->
e900: 66 73 50 74 72 29 20 7b 0a 09 63 6f 6e 73 74 20 fsPtr) {..const
e910: 54 63 6c 5f 46 69 6c 65 73 79 73 74 65 6d 20 2a Tcl_Filesystem *
e920: 61 63 74 75 61 6c 46 73 20 3d 20 54 63 6c 5f 46 actualFs = Tcl_F
e930: 53 47 65 74 46 69 6c 65 53 79 73 74 65 6d 46 6f SGetFileSystemFo
e940: 72 50 61 74 68 28 70 61 74 68 50 74 72 29 3b 0a rPath(pathPtr);.
e950: 0a 09 69 66 20 28 61 63 74 75 61 6c 46 73 20 3d ..if (actualFs =
e960: 3d 20 66 73 50 74 72 29 20 7b 0a 09 20 20 20 20 = fsPtr) {..
e970: 72 65 74 75 72 6e 20 54 63 6c 5f 46 53 47 65 74 return Tcl_FSGet
e980: 49 6e 74 65 72 6e 61 6c 52 65 70 28 70 61 74 68 InternalRep(path
e990: 50 74 72 2c 20 66 73 50 74 72 29 3b 0a 09 7d 0a Ptr, fsPtr);..}.
e9a0: 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 .return NULL;.
e9b0: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 73 72 63 }.. if (src
e9c0: 46 73 50 61 74 68 50 74 72 2d 3e 6e 61 74 69 76 FsPathPtr->nativ
e9d0: 65 50 61 74 68 50 74 72 20 3d 3d 20 4e 55 4c 4c ePathPtr == NULL
e9e0: 29 20 7b 0a 09 54 63 6c 5f 46 53 43 72 65 61 74 ) {..Tcl_FSCreat
e9f0: 65 49 6e 74 65 72 6e 61 6c 52 65 70 50 72 6f 63 eInternalRepProc
ea00: 20 2a 70 72 6f 63 3b 0a 09 63 68 61 72 20 2a 6e *proc;..char *n
ea10: 61 74 69 76 65 50 61 74 68 50 74 72 3b 0a 0a 09 ativePathPtr;...
ea20: 70 72 6f 63 20 3d 20 73 72 63 46 73 50 61 74 68 proc = srcFsPath
ea30: 50 74 72 2d 3e 66 73 50 74 72 2d 3e 63 72 65 61 Ptr->fsPtr->crea
ea40: 74 65 49 6e 74 65 72 6e 61 6c 52 65 70 50 72 6f teInternalRepPro
ea50: 63 3b 0a 09 69 66 20 28 70 72 6f 63 20 3d 3d 20 c;..if (proc ==
ea60: 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 72 65 74 NULL) {.. ret
ea70: 75 72 6e 20 4e 55 4c 4c 3b 0a 09 7d 0a 0a 09 6e urn NULL;..}...n
ea80: 61 74 69 76 65 50 61 74 68 50 74 72 20 3d 20 70 ativePathPtr = p
ea90: 72 6f 63 28 70 61 74 68 50 74 72 29 3b 0a 09 73 roc(pathPtr);..s
eaa0: 72 63 46 73 50 61 74 68 50 74 72 20 3d 20 50 41 rcFsPathPtr = PA
eab0: 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b 0a THOBJ(pathPtr);.
eac0: 09 73 72 63 46 73 50 61 74 68 50 74 72 2d 3e 6e .srcFsPathPtr->n
ead0: 61 74 69 76 65 50 61 74 68 50 74 72 20 3d 20 6e ativePathPtr = n
eae0: 61 74 69 76 65 50 61 74 68 50 74 72 3b 0a 09 73 ativePathPtr;..s
eaf0: 72 63 46 73 50 61 74 68 50 74 72 2d 3e 66 69 6c rcFsPathPtr->fil
eb00: 65 73 79 73 74 65 6d 45 70 6f 63 68 20 3d 20 54 esystemEpoch = T
eb10: 63 6c 46 53 45 70 6f 63 68 28 29 3b 0a 20 20 20 clFSEpoch();.
eb20: 20 7d 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 73 }.. return s
eb30: 72 63 46 73 50 61 74 68 50 74 72 2d 3e 6e 61 74 rcFsPathPtr->nat
eb40: 69 76 65 50 61 74 68 50 74 72 3b 0a 7d 0a 0c 0a ivePathPtr;.}...
eb50: 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d /*. *-----------
eb60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
eb70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
eb80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
eb90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
eba0: 0a 20 2a 0a 20 2a 20 54 63 6c 46 53 45 6e 73 75 . *. * TclFSEnsu
ebb0: 72 65 45 70 6f 63 68 4f 6b 20 2d 2d 0a 20 2a 0a reEpochOk --. *.
ebc0: 20 2a 09 54 68 69 73 20 77 69 6c 6c 20 65 6e 73 *.This will ens
ebd0: 75 72 65 20 74 68 65 20 70 61 74 68 50 74 72 20 ure the pathPtr
ebe0: 69 73 20 75 70 20 74 6f 20 64 61 74 65 20 61 6e is up to date an
ebf0: 64 20 63 61 6e 20 62 65 20 63 6f 6e 76 65 72 74 d can be convert
ec00: 65 64 20 69 6e 74 6f 20 61 0a 20 2a 09 22 70 61 ed into a. *."pa
ec10: 74 68 22 20 74 79 70 65 2c 20 61 6e 64 20 74 68 th" type, and th
ec20: 61 74 20 77 65 20 61 72 65 20 61 62 6c 65 20 74 at we are able t
ec30: 6f 20 67 65 6e 65 72 61 74 65 20 61 20 63 6f 6d o generate a com
ec40: 70 6c 65 74 65 20 6e 6f 72 6d 61 6c 69 7a 65 64 plete normalized
ec50: 0a 20 2a 09 70 61 74 68 20 77 68 69 63 68 20 69 . *.path which i
ec60: 73 20 75 73 65 64 20 74 6f 20 64 65 74 65 72 6d s used to determ
ec70: 69 6e 65 20 74 68 65 20 66 69 6c 65 73 79 73 74 ine the filesyst
ec80: 65 6d 20 6d 61 74 63 68 2e 0a 20 2a 0a 20 2a 20 em match.. *. *
ec90: 52 65 73 75 6c 74 73 3a 0a 20 2a 09 53 74 61 6e Results:. *.Stan
eca0: 64 61 72 64 20 54 63 6c 20 72 65 74 75 72 6e 20 dard Tcl return
ecb0: 63 6f 64 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 code.. *. * Side
ecc0: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 41 6e 20 effects:. *.An
ecd0: 61 74 74 65 6d 70 74 20 6d 61 79 20 62 65 20 6d attempt may be m
ece0: 61 64 65 20 74 6f 20 63 6f 6e 76 65 72 74 20 74 ade to convert t
ecf0: 68 65 20 6f 62 6a 65 63 74 2e 0a 20 2a 0a 20 2a he object.. *. *
ed00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ed10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ed20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ed30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
ed40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a -----------. */.
ed50: 0a 69 6e 74 0a 54 63 6c 46 53 45 6e 73 75 72 65 .int.TclFSEnsure
ed60: 45 70 6f 63 68 4f 6b 28 0a 20 20 20 20 54 63 6c EpochOk(. Tcl
ed70: 5f 4f 62 6a 20 2a 70 61 74 68 50 74 72 2c 0a 20 _Obj *pathPtr,.
ed80: 20 20 20 63 6f 6e 73 74 20 54 63 6c 5f 46 69 6c const Tcl_Fil
ed90: 65 73 79 73 74 65 6d 20 2a 2a 66 73 50 74 72 50 esystem **fsPtrP
eda0: 74 72 29 0a 7b 0a 20 20 20 20 46 73 50 61 74 68 tr).{. FsPath
edb0: 20 2a 73 72 63 46 73 50 61 74 68 50 74 72 3b 0a *srcFsPathPtr;.
edc0: 0a 20 20 20 20 69 66 20 28 70 61 74 68 50 74 72 . if (pathPtr
edd0: 2d 3e 74 79 70 65 50 74 72 20 21 3d 20 26 74 63 ->typePtr != &tc
ede0: 6c 46 73 50 61 74 68 54 79 70 65 29 20 7b 0a 09 lFsPathType) {..
edf0: 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 20 return TCL_OK;.
ee00: 20 20 20 7d 0a 0a 20 20 20 20 73 72 63 46 73 50 }.. srcFsP
ee10: 61 74 68 50 74 72 20 3d 20 50 41 54 48 4f 42 4a athPtr = PATHOBJ
ee20: 28 70 61 74 68 50 74 72 29 3b 0a 0a 20 20 20 20 (pathPtr);..
ee30: 2f 2a 0a 20 20 20 20 20 2a 20 43 68 65 63 6b 20 /*. * Check
ee40: 69 66 20 74 68 65 20 66 69 6c 65 73 79 73 74 65 if the filesyste
ee50: 6d 20 68 61 73 20 63 68 61 6e 67 65 64 20 69 6e m has changed in
ee60: 20 73 6f 6d 65 20 77 61 79 20 73 69 6e 63 65 20 some way since
ee70: 74 68 69 73 20 6f 62 6a 65 63 74 27 73 0a 20 20 this object's.
ee80: 20 20 20 2a 20 69 6e 74 65 72 6e 61 6c 20 72 65 * internal re
ee90: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 77 61 73 presentation was
eea0: 20 63 61 6c 63 75 6c 61 74 65 64 2e 0a 20 20 20 calculated..
eeb0: 20 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 21 54 */.. if (!T
eec0: 63 6c 46 53 45 70 6f 63 68 4f 6b 28 73 72 63 46 clFSEpochOk(srcF
eed0: 73 50 61 74 68 50 74 72 2d 3e 66 69 6c 65 73 79 sPathPtr->filesy
eee0: 73 74 65 6d 45 70 6f 63 68 29 29 20 7b 0a 09 2f stemEpoch)) {../
eef0: 2a 0a 09 20 2a 20 57 65 20 68 61 76 65 20 74 6f *.. * We have to
ef00: 20 64 69 73 63 61 72 64 20 74 68 65 20 73 74 61 discard the sta
ef10: 6c 65 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f le representatio
ef20: 6e 20 61 6e 64 20 72 65 63 61 6c 63 75 6c 61 74 n and recalculat
ef30: 65 20 69 74 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 e it... */...if
ef40: 28 70 61 74 68 50 74 72 2d 3e 62 79 74 65 73 20 (pathPtr->bytes
ef50: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 == NULL) {..
ef60: 55 70 64 61 74 65 53 74 72 69 6e 67 4f 66 46 73 UpdateStringOfFs
ef70: 50 61 74 68 28 70 61 74 68 50 74 72 29 3b 0a 09 Path(pathPtr);..
ef80: 7d 0a 09 46 72 65 65 46 73 50 61 74 68 49 6e 74 }..FreeFsPathInt
ef90: 65 72 6e 61 6c 52 65 70 28 70 61 74 68 50 74 72 ernalRep(pathPtr
efa0: 29 3b 0a 09 69 66 20 28 53 65 74 46 73 50 61 74 );..if (SetFsPat
efb0: 68 46 72 6f 6d 41 6e 79 28 4e 55 4c 4c 2c 20 70 hFromAny(NULL, p
efc0: 61 74 68 50 74 72 29 20 21 3d 20 54 43 4c 5f 4f athPtr) != TCL_O
efd0: 4b 29 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e K) {.. return
efe0: 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 09 7d 0a 09 TCL_ERROR;..}..
eff0: 73 72 63 46 73 50 61 74 68 50 74 72 20 3d 20 50 srcFsPathPtr = P
f000: 41 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b ATHOBJ(pathPtr);
f010: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 . }.. /*.
f020: 20 20 20 20 2a 20 43 68 65 63 6b 20 77 68 65 74 * Check whet
f030: 68 65 72 20 74 68 65 20 6f 62 6a 65 63 74 20 69 her the object i
f040: 73 20 61 6c 72 65 61 64 79 20 61 73 73 69 67 6e s already assign
f050: 65 64 20 74 6f 20 61 20 66 73 2e 0a 20 20 20 20 ed to a fs..
f060: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 73 72 63 */.. if (src
f070: 46 73 50 61 74 68 50 74 72 2d 3e 66 73 50 74 72 FsPathPtr->fsPtr
f080: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 2a 66 73 != NULL) {..*fs
f090: 50 74 72 50 74 72 20 3d 20 73 72 63 46 73 50 61 PtrPtr = srcFsPa
f0a0: 74 68 50 74 72 2d 3e 66 73 50 74 72 3b 0a 20 20 thPtr->fsPtr;.
f0b0: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 54 }. return T
f0c0: 43 4c 5f 4f 4b 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a CL_OK;.}.../*. *
f0d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f0e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f0f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 -----------. *.
f120: 2a 20 54 63 6c 46 53 53 65 74 50 61 74 68 44 65 * TclFSSetPathDe
f130: 74 61 69 6c 73 20 2d 2d 0a 20 2a 0a 20 2a 09 3f tails --. *. *.?
f140: 3f 3f 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 ??. *. * Results
f150: 3a 0a 20 2a 09 4e 6f 6e 65 0a 20 2a 0a 20 2a 20 :. *.None. *. *
f160: 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a Side effects:. *
f170: 09 3f 3f 3f 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d .???. *. *------
f180: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f1a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f1b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f1c0: 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 76 6f 69 64 0a -----. */..void.
f1d0: 54 63 6c 46 53 53 65 74 50 61 74 68 44 65 74 61 TclFSSetPathDeta
f1e0: 69 6c 73 28 0a 20 20 20 20 54 63 6c 5f 4f 62 6a ils(. Tcl_Obj
f1f0: 20 2a 70 61 74 68 50 74 72 2c 0a 20 20 20 20 63 *pathPtr,. c
f200: 6f 6e 73 74 20 54 63 6c 5f 46 69 6c 65 73 79 73 onst Tcl_Filesys
f210: 74 65 6d 20 2a 66 73 50 74 72 2c 0a 20 20 20 20 tem *fsPtr,.
f220: 43 6c 69 65 6e 74 44 61 74 61 20 63 6c 69 65 6e ClientData clien
f230: 74 44 61 74 61 29 0a 7b 0a 20 20 20 20 46 73 50 tData).{. FsP
f240: 61 74 68 20 2a 73 72 63 46 73 50 61 74 68 50 74 ath *srcFsPathPt
f250: 72 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 r;.. /*.
f260: 2a 20 4d 61 6b 65 20 73 75 72 65 20 70 61 74 68 * Make sure path
f270: 50 74 72 20 69 73 20 6f 66 20 74 68 65 20 63 6f Ptr is of the co
f280: 72 72 65 63 74 20 74 79 70 65 2e 0a 20 20 20 20 rrect type..
f290: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 70 61 74 */.. if (pat
f2a0: 68 50 74 72 2d 3e 74 79 70 65 50 74 72 20 21 3d hPtr->typePtr !=
f2b0: 20 26 74 63 6c 46 73 50 61 74 68 54 79 70 65 29 &tclFsPathType)
f2c0: 20 7b 0a 09 69 66 20 28 53 65 74 46 73 50 61 74 {..if (SetFsPat
f2d0: 68 46 72 6f 6d 41 6e 79 28 4e 55 4c 4c 2c 20 70 hFromAny(NULL, p
f2e0: 61 74 68 50 74 72 29 20 21 3d 20 54 43 4c 5f 4f athPtr) != TCL_O
f2f0: 4b 29 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e K) {.. return
f300: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 ;..}. }..
f310: 73 72 63 46 73 50 61 74 68 50 74 72 20 3d 20 50 srcFsPathPtr = P
f320: 41 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b ATHOBJ(pathPtr);
f330: 0a 20 20 20 20 73 72 63 46 73 50 61 74 68 50 74 . srcFsPathPt
f340: 72 2d 3e 66 73 50 74 72 20 3d 20 66 73 50 74 72 r->fsPtr = fsPtr
f350: 3b 0a 20 20 20 20 73 72 63 46 73 50 61 74 68 50 ;. srcFsPathP
f360: 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 68 50 74 tr->nativePathPt
f370: 72 20 3d 20 63 6c 69 65 6e 74 44 61 74 61 3b 0a r = clientData;.
f380: 20 20 20 20 73 72 63 46 73 50 61 74 68 50 74 72 srcFsPathPtr
f390: 2d 3e 66 69 6c 65 73 79 73 74 65 6d 45 70 6f 63 ->filesystemEpoc
f3a0: 68 20 3d 20 54 63 6c 46 53 45 70 6f 63 68 28 29 h = TclFSEpoch()
f3b0: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d ;.}.../*. *-----
f3c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f3d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f3e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f3f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f400: 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 54 63 6c ------. *. * Tcl
f410: 5f 46 53 45 71 75 61 6c 50 61 74 68 73 20 2d 2d _FSEqualPaths --
f420: 0a 20 2a 0a 20 2a 09 54 68 69 73 20 66 75 6e 63 . *. *.This func
f430: 74 69 6f 6e 20 74 65 73 74 73 20 77 68 65 74 68 tion tests wheth
f440: 65 72 20 74 68 65 20 74 77 6f 20 70 61 74 68 73 er the two paths
f450: 20 67 69 76 65 6e 20 61 72 65 20 65 71 75 61 6c given are equal
f460: 20 70 61 74 68 0a 20 2a 09 6f 62 6a 65 63 74 73 path. *.objects
f470: 2e 20 49 66 20 65 69 74 68 65 72 20 6f 72 20 62 . If either or b
f480: 6f 74 68 20 69 73 20 4e 55 4c 4c 2c 20 30 20 69 oth is NULL, 0 i
f490: 73 20 61 6c 77 61 79 73 20 72 65 74 75 72 6e 65 s always returne
f4a0: 64 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 d.. *. * Results
f4b0: 3a 0a 20 2a 09 31 20 6f 72 20 30 2e 0a 20 2a 0a :. *.1 or 0.. *.
f4c0: 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a * Side effects:
f4d0: 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 2d . *.None.. *. *-
f4e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f4f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f510: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f520: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a ----------. */..
f530: 69 6e 74 0a 54 63 6c 5f 46 53 45 71 75 61 6c 50 int.Tcl_FSEqualP
f540: 61 74 68 73 28 0a 20 20 20 20 54 63 6c 5f 4f 62 aths(. Tcl_Ob
f550: 6a 20 2a 66 69 72 73 74 50 74 72 2c 0a 20 20 20 j *firstPtr,.
f560: 20 54 63 6c 5f 4f 62 6a 20 2a 73 65 63 6f 6e 64 Tcl_Obj *second
f570: 50 74 72 29 0a 7b 0a 20 20 20 20 63 6f 6e 73 74 Ptr).{. const
f580: 20 63 68 61 72 20 2a 66 69 72 73 74 53 74 72 2c char *firstStr,
f590: 20 2a 73 65 63 6f 6e 64 53 74 72 3b 0a 20 20 20 *secondStr;.
f5a0: 20 69 6e 74 20 66 69 72 73 74 4c 65 6e 2c 20 73 int firstLen, s
f5b0: 65 63 6f 6e 64 4c 65 6e 2c 20 74 65 6d 70 45 72 econdLen, tempEr
f5c0: 72 6e 6f 3b 0a 0a 20 20 20 20 69 66 20 28 66 69 rno;.. if (fi
f5d0: 72 73 74 50 74 72 20 3d 3d 20 73 65 63 6f 6e 64 rstPtr == second
f5e0: 50 74 72 29 20 7b 0a 09 72 65 74 75 72 6e 20 31 Ptr) {..return 1
f5f0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 ;. }.. if
f600: 28 66 69 72 73 74 50 74 72 20 3d 3d 20 4e 55 4c (firstPtr == NUL
f610: 4c 20 7c 7c 20 73 65 63 6f 6e 64 50 74 72 20 3d L || secondPtr =
f620: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 = NULL) {..retur
f630: 6e 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 n 0;. }. f
f640: 69 72 73 74 53 74 72 20 3d 20 54 63 6c 47 65 74 irstStr = TclGet
f650: 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 66 69 StringFromObj(fi
f660: 72 73 74 50 74 72 2c 20 26 66 69 72 73 74 4c 65 rstPtr, &firstLe
f670: 6e 29 3b 0a 20 20 20 20 73 65 63 6f 6e 64 53 74 n);. secondSt
f680: 72 20 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67 r = TclGetString
f690: 46 72 6f 6d 4f 62 6a 28 73 65 63 6f 6e 64 50 74 FromObj(secondPt
f6a0: 72 2c 20 26 73 65 63 6f 6e 64 4c 65 6e 29 3b 0a r, &secondLen);.
f6b0: 20 20 20 20 69 66 20 28 28 66 69 72 73 74 4c 65 if ((firstLe
f6c0: 6e 20 3d 3d 20 73 65 63 6f 6e 64 4c 65 6e 29 20 n == secondLen)
f6d0: 26 26 20 21 6d 65 6d 63 6d 70 28 66 69 72 73 74 && !memcmp(first
f6e0: 53 74 72 2c 20 73 65 63 6f 6e 64 53 74 72 2c 20 Str, secondStr,
f6f0: 66 69 72 73 74 4c 65 6e 29 29 20 7b 0a 09 72 65 firstLen)) {..re
f700: 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 0a 20 turn 1;. }..
f710: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 54 72 79 /*. * Try
f720: 20 74 68 65 20 6d 6f 73 74 20 74 68 6f 72 6f 75 the most thorou
f730: 67 68 2c 20 63 6f 72 72 65 63 74 20 6d 65 74 68 gh, correct meth
f740: 6f 64 20 6f 66 20 63 6f 6d 70 61 72 69 6e 67 20 od of comparing
f750: 66 75 6c 6c 79 20 6e 6f 72 6d 61 6c 69 7a 65 64 fully normalized
f760: 0a 20 20 20 20 20 2a 20 70 61 74 68 73 2e 0a 20 . * paths..
f770: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 74 65 6d 70 */.. temp
f780: 45 72 72 6e 6f 20 3d 20 54 63 6c 5f 47 65 74 45 Errno = Tcl_GetE
f790: 72 72 6e 6f 28 29 3b 0a 20 20 20 20 66 69 72 73 rrno();. firs
f7a0: 74 50 74 72 20 3d 20 54 63 6c 5f 46 53 47 65 74 tPtr = Tcl_FSGet
f7b0: 4e 6f 72 6d 61 6c 69 7a 65 64 50 61 74 68 28 4e NormalizedPath(N
f7c0: 55 4c 4c 2c 20 66 69 72 73 74 50 74 72 29 3b 0a ULL, firstPtr);.
f7d0: 20 20 20 20 73 65 63 6f 6e 64 50 74 72 20 3d 20 secondPtr =
f7e0: 54 63 6c 5f 46 53 47 65 74 4e 6f 72 6d 61 6c 69 Tcl_FSGetNormali
f7f0: 7a 65 64 50 61 74 68 28 4e 55 4c 4c 2c 20 73 65 zedPath(NULL, se
f800: 63 6f 6e 64 50 74 72 29 3b 0a 20 20 20 20 54 63 condPtr);. Tc
f810: 6c 5f 53 65 74 45 72 72 6e 6f 28 74 65 6d 70 45 l_SetErrno(tempE
f820: 72 72 6e 6f 29 3b 0a 0a 20 20 20 20 69 66 20 28 rrno);.. if (
f830: 66 69 72 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c firstPtr == NULL
f840: 20 7c 7c 20 73 65 63 6f 6e 64 50 74 72 20 3d 3d || secondPtr ==
f850: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
f860: 20 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66 0;. }.. f
f870: 69 72 73 74 53 74 72 20 3d 20 54 63 6c 47 65 74 irstStr = TclGet
f880: 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 66 69 StringFromObj(fi
f890: 72 73 74 50 74 72 2c 20 26 66 69 72 73 74 4c 65 rstPtr, &firstLe
f8a0: 6e 29 3b 0a 20 20 20 20 73 65 63 6f 6e 64 53 74 n);. secondSt
f8b0: 72 20 3d 20 54 63 6c 47 65 74 53 74 72 69 6e 67 r = TclGetString
f8c0: 46 72 6f 6d 4f 62 6a 28 73 65 63 6f 6e 64 50 74 FromObj(secondPt
f8d0: 72 2c 20 26 73 65 63 6f 6e 64 4c 65 6e 29 3b 0a r, &secondLen);.
f8e0: 20 20 20 20 72 65 74 75 72 6e 20 28 28 66 69 72 return ((fir
f8f0: 73 74 4c 65 6e 20 3d 3d 20 73 65 63 6f 6e 64 4c stLen == secondL
f900: 65 6e 29 20 26 26 20 21 6d 65 6d 63 6d 70 28 66 en) && !memcmp(f
f910: 69 72 73 74 53 74 72 2c 20 73 65 63 6f 6e 64 53 irstStr, secondS
f920: 74 72 2c 20 66 69 72 73 74 4c 65 6e 29 29 3b 0a tr, firstLen));.
f930: 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d }.../*. *-------
f940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f950: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f970: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
f980: 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 53 65 74 46 73 ----. *. * SetFs
f990: 50 61 74 68 46 72 6f 6d 41 6e 79 20 2d 2d 0a 20 PathFromAny --.
f9a0: 2a 0a 20 2a 09 54 68 69 73 20 66 75 6e 63 74 69 *. *.This functi
f9b0: 6f 6e 20 74 72 69 65 73 20 74 6f 20 63 6f 6e 76 on tries to conv
f9c0: 65 72 74 20 74 68 65 20 67 69 76 65 6e 20 54 63 ert the given Tc
f9d0: 6c 5f 4f 62 6a 20 74 6f 20 61 20 76 61 6c 69 64 l_Obj to a valid
f9e0: 20 54 63 6c 20 70 61 74 68 0a 20 2a 09 74 79 70 Tcl path. *.typ
f9f0: 65 2e 0a 20 2a 0a 20 2a 09 54 68 65 20 66 69 6c e.. *. *.The fil
fa00: 65 6e 61 6d 65 20 6d 61 79 20 62 65 67 69 6e 20 ename may begin
fa10: 77 69 74 68 20 22 7e 22 20 28 74 6f 20 69 6e 64 with "~" (to ind
fa20: 69 63 61 74 65 20 63 75 72 72 65 6e 74 20 75 73 icate current us
fa30: 65 72 27 73 20 68 6f 6d 65 0a 20 2a 09 64 69 72 er's home. *.dir
fa40: 65 63 74 6f 72 79 29 20 6f 72 20 22 7e 3c 75 73 ectory) or "~<us
fa50: 65 72 3e 22 20 28 74 6f 20 69 6e 64 69 63 61 74 er>" (to indicat
fa60: 65 20 61 6e 79 20 75 73 65 72 27 73 20 68 6f 6d e any user's hom
fa70: 65 20 64 69 72 65 63 74 6f 72 79 29 2e 0a 20 2a e directory).. *
fa80: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 . * Results:. *.
fa90: 53 74 61 6e 64 61 72 64 20 54 63 6c 20 65 72 72 Standard Tcl err
faa0: 6f 72 20 63 6f 64 65 2e 0a 20 2a 0a 20 2a 20 53 or code.. *. * S
fab0: 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 ide effects:. *.
fac0: 54 68 65 20 6f 6c 64 20 72 65 70 72 65 73 65 6e The old represen
fad0: 74 61 74 69 6f 6e 20 6d 61 79 20 62 65 20 66 72 tation may be fr
fae0: 65 65 64 2c 20 61 6e 64 20 6e 65 77 20 6d 65 6d eed, and new mem
faf0: 6f 72 79 20 61 6c 6c 6f 63 61 74 65 64 2e 0a 20 ory allocated..
fb00: 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *. *------------
fb10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
fb20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
fb30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
fb40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
fb50: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a */..static int.
fb60: 53 65 74 46 73 50 61 74 68 46 72 6f 6d 41 6e 79 SetFsPathFromAny
fb70: 28 0a 20 20 20 20 54 63 6c 5f 49 6e 74 65 72 70 (. Tcl_Interp
fb80: 20 2a 69 6e 74 65 72 70 2c 09 09 2f 2a 20 55 73 *interp,../* Us
fb90: 65 64 20 66 6f 72 20 65 72 72 6f 72 20 72 65 70 ed for error rep
fba0: 6f 72 74 69 6e 67 20 69 66 20 6e 6f 74 20 4e 55 orting if not NU
fbb0: 4c 4c 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f LL. */. Tcl_O
fbc0: 62 6a 20 2a 70 61 74 68 50 74 72 29 09 09 2f 2a bj *pathPtr)../*
fbd0: 20 54 68 65 20 6f 62 6a 65 63 74 20 74 6f 20 63 The object to c
fbe0: 6f 6e 76 65 72 74 2e 20 2a 2f 0a 7b 0a 20 20 20 onvert. */.{.
fbf0: 20 69 6e 74 20 6c 65 6e 3b 0a 20 20 20 20 46 73 int len;. Fs
fc00: 50 61 74 68 20 2a 66 73 50 61 74 68 50 74 72 3b Path *fsPathPtr;
fc10: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 74 72 . Tcl_Obj *tr
fc20: 61 6e 73 50 74 72 3b 0a 20 20 20 20 63 68 61 72 ansPtr;. char
fc30: 20 2a 6e 61 6d 65 3b 0a 0a 20 20 20 20 69 66 20 *name;.. if
fc40: 28 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 74 (pathPtr->typePt
fc50: 72 20 3d 3d 20 26 74 63 6c 46 73 50 61 74 68 54 r == &tclFsPathT
fc60: 79 70 65 29 20 7b 0a 09 72 65 74 75 72 6e 20 54 ype) {..return T
fc70: 43 4c 5f 4f 4b 3b 0a 20 20 20 20 7d 0a 0a 20 20 CL_OK;. }..
fc80: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 46 69 72 73 /*. * Firs
fc90: 74 20 73 74 65 70 20 69 73 20 74 6f 20 74 72 61 t step is to tra
fca0: 6e 73 6c 61 74 65 20 74 68 65 20 66 69 6c 65 6e nslate the filen
fcb0: 61 6d 65 2e 20 54 68 69 73 20 69 73 20 73 69 6d ame. This is sim
fcc0: 69 6c 61 72 20 74 6f 0a 20 20 20 20 20 2a 20 54 ilar to. * T
fcd0: 63 6c 5f 54 72 61 6e 73 6c 61 74 65 46 69 6c 65 cl_TranslateFile
fce0: 6e 61 6d 65 2c 20 62 75 74 20 73 68 6f 75 6c 64 name, but should
fcf0: 6e 27 74 20 63 6f 6e 76 65 72 74 20 65 76 65 72 n't convert ever
fd00: 79 74 68 69 6e 67 20 74 6f 20 77 69 6e 64 6f 77 ything to window
fd10: 73 0a 20 20 20 20 20 2a 20 62 61 63 6b 73 6c 61 s. * backsla
fd20: 73 68 65 73 20 6f 6e 20 74 68 61 74 20 70 6c 61 shes on that pla
fd30: 74 66 6f 72 6d 2e 20 54 68 65 20 63 75 72 72 65 tform. The curre
fd40: 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f nt implementatio
fd50: 6e 20 6f 66 20 74 68 69 73 20 70 69 65 63 65 0a n of this piece.
fd60: 20 20 20 20 20 2a 20 69 73 20 61 20 73 6c 69 67 * is a slig
fd70: 68 74 6c 79 20 6f 70 74 69 6d 69 73 65 64 20 76 htly optimised v
fd80: 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 76 61 ersion of the va
fd90: 72 69 6f 75 73 20 54 69 6c 64 65 2f 53 70 6c 69 rious Tilde/Spli
fda0: 74 2f 4a 6f 69 6e 20 73 74 75 66 66 0a 20 20 20 t/Join stuff.
fdb0: 20 20 2a 20 74 6f 20 61 76 6f 69 64 20 6d 75 6c * to avoid mul
fdc0: 74 69 70 6c 65 20 73 70 6c 69 74 2f 6a 6f 69 6e tiple split/join
fdd0: 20 6f 70 65 72 61 74 69 6f 6e 73 2e 0a 20 20 20 operations..
fde0: 20 20 2a 0a 20 20 20 20 20 2a 20 57 65 20 72 65 *. * We re
fdf0: 6d 6f 76 65 20 61 6e 79 20 74 72 61 69 6c 69 6e move any trailin
fe00: 67 20 64 69 72 65 63 74 6f 72 79 20 73 65 70 61 g directory sepa
fe10: 72 61 74 6f 72 2e 0a 20 20 20 20 20 2a 0a 20 20 rator.. *.
fe20: 20 20 20 2a 20 48 6f 77 65 76 65 72 2c 20 74 68 * However, th
fe30: 65 20 73 70 6c 69 74 2f 6a 6f 69 6e 20 72 6f 75 e split/join rou
fe40: 74 69 6e 65 73 20 61 72 65 20 71 75 69 74 65 20 tines are quite
fe50: 63 6f 6d 70 6c 65 78 2c 20 61 6e 64 20 6f 6e 65 complex, and one
fe60: 20 68 61 73 20 74 6f 20 6d 61 6b 65 0a 20 20 20 has to make.
fe70: 20 20 2a 20 73 75 72 65 20 6e 6f 74 20 74 6f 20 * sure not to
fe80: 62 72 65 61 6b 20 61 6e 79 74 68 69 6e 67 20 6f break anything o
fe90: 6e 20 55 6e 69 78 20 6f 72 20 57 69 6e 20 28 66 n Unix or Win (f
fea0: 43 6d 64 2e 74 65 73 74 2c 20 66 69 6c 65 4e 61 Cmd.test, fileNa
feb0: 6d 65 2e 74 65 73 74 20 61 6e 64 0a 20 20 20 20 me.test and.
fec0: 20 2a 20 63 6d 64 41 48 2e 74 65 73 74 20 65 78 * cmdAH.test ex
fed0: 65 72 63 69 73 65 20 6d 6f 73 74 20 6f 66 20 74 ercise most of t
fee0: 68 65 20 63 6f 64 65 29 2e 0a 20 20 20 20 20 2a he code).. *
fef0: 2f 0a 0a 20 20 20 20 6e 61 6d 65 20 3d 20 54 63 /.. name = Tc
ff00: 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f l_GetStringFromO
ff10: 62 6a 28 70 61 74 68 50 74 72 2c 20 26 6c 65 6e bj(pathPtr, &len
ff20: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
ff30: 2a 20 48 61 6e 64 6c 65 20 74 69 6c 64 65 20 73 * Handle tilde s
ff40: 75 62 73 74 69 74 75 74 69 6f 6e 73 2c 20 69 66 ubstitutions, if
ff50: 20 6e 65 65 64 65 64 2e 0a 20 20 20 20 20 2a 2f needed.. */
ff60: 0a 0a 20 20 20 20 69 66 20 28 6c 65 6e 20 26 26 .. if (len &&
ff70: 20 6e 61 6d 65 5b 30 5d 20 3d 3d 20 27 7e 27 29 name[0] == '~')
ff80: 20 7b 0a 09 54 63 6c 5f 44 53 74 72 69 6e 67 20 {..Tcl_DString
ff90: 74 65 6d 70 3b 0a 09 69 6e 74 20 73 70 6c 69 74 temp;..int split
ffa0: 3b 0a 09 63 68 61 72 20 73 65 70 61 72 61 74 6f ;..char separato
ffb0: 72 20 3d 20 27 2f 27 3b 0a 0a 09 2f 2a 0a 09 20 r = '/';.../*..
ffc0: 2a 20 57 65 20 68 61 76 65 20 6d 75 6c 74 69 70 * We have multip
ffd0: 6c 65 20 63 61 73 65 73 20 27 7e 2f 66 6f 6f 2f le cases '~/foo/
ffe0: 62 61 72 2e 2e 2e 27 2c 20 27 7e 75 73 65 72 2f bar...', '~user/
fff0: 66 6f 6f 2f 62 61 72 2e 2e 2e 27 2c 20 65 74 63 foo/bar...', etc
10000 2e 0a 09 20 2a 20 73 70 6c 69 74 20 62 65 63 6f ... * split beco
10010 6d 65 73 20 76 61 6c 75 65 20 31 20 66 6f 72 20 mes value 1 for
10020 27 7e 2f 2e 2e 2e 27 20 61 73 20 77 65 6c 6c 20 '~/...' as well
10030 61 73 20 66 6f 72 20 27 7e 27 2e 0a 09 20 2a 2f as for '~'... */
10040 0a 09 73 70 6c 69 74 20 3d 20 46 69 6e 64 53 70 ..split = FindSp
10050 6c 69 74 50 6f 73 28 6e 61 6d 65 2c 20 73 65 70 litPos(name, sep
10060 61 72 61 74 6f 72 29 3b 0a 0a 09 2f 2a 0a 09 20 arator);.../*..
10070 2a 20 44 6f 20 73 6f 6d 65 20 74 69 6c 64 65 20 * Do some tilde
10080 73 75 62 73 74 69 74 75 74 69 6f 6e 2e 0a 09 20 substitution...
10090 2a 2f 0a 0a 09 69 66 20 28 73 70 6c 69 74 20 3d */...if (split =
100a0 3d 20 31 29 20 7b 0a 09 20 20 20 20 2f 2a 0a 09 = 1) {.. /*..
100b0 20 20 20 20 20 2a 20 57 65 20 68 61 76 65 20 6a * We have j
100c0 75 73 74 20 27 7e 27 20 28 6f 72 20 27 7e 2f 2e ust '~' (or '~/.
100d0 2e 2e 27 29 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 ..').. */...
100e0 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
100f0 64 69 72 3b 0a 09 20 20 20 20 54 63 6c 5f 44 53 dir;.. Tcl_DS
10100 74 72 69 6e 67 20 64 69 72 53 74 72 69 6e 67 3b tring dirString;
10110 0a 0a 09 20 20 20 20 64 69 72 20 3d 20 54 63 6c ... dir = Tcl
10120 47 65 74 45 6e 76 28 22 48 4f 4d 45 22 2c 20 26 GetEnv("HOME", &
10130 64 69 72 53 74 72 69 6e 67 29 3b 0a 09 20 20 20 dirString);..
10140 20 69 66 20 28 64 69 72 20 3d 3d 20 4e 55 4c 4c if (dir == NULL
10150 29 20 7b 0a 09 09 69 66 20 28 69 6e 74 65 72 70 ) {...if (interp
10160 29 20 7b 0a 09 09 20 20 20 20 54 63 6c 5f 53 65 ) {... Tcl_Se
10170 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 tObjResult(inter
10180 70 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 p, Tcl_NewString
10190 4f 62 6a 28 0a 09 09 09 20 20 20 20 22 63 6f 75 Obj(.... "cou
101a0 6c 64 6e 27 74 20 66 69 6e 64 20 48 4f 4d 45 20 ldn't find HOME
101b0 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 environment vari
101c0 61 62 6c 65 20 74 6f 22 0a 09 09 09 20 20 20 20 able to"....
101d0 22 20 65 78 70 61 6e 64 20 70 61 74 68 22 2c 20 " expand path",
101e0 2d 31 29 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f -1));... Tcl_
101f0 53 65 74 45 72 72 6f 72 43 6f 64 65 28 69 6e 74 SetErrorCode(int
10200 65 72 70 2c 20 22 54 43 4c 22 2c 20 22 56 41 4c erp, "TCL", "VAL
10210 55 45 22 2c 20 22 50 41 54 48 22 2c 0a 09 09 09 UE", "PATH",....
10220 20 20 20 20 22 48 4f 4d 45 4c 45 53 53 22 2c 20 "HOMELESS",
10230 4e 55 4c 4c 29 3b 0a 09 09 7d 0a 09 09 72 65 74 NULL);...}...ret
10240 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 09 urn TCL_ERROR;..
10250 20 20 20 20 7d 0a 09 20 20 20 20 54 63 6c 5f 44 }.. Tcl_D
10260 53 74 72 69 6e 67 49 6e 69 74 28 26 74 65 6d 70 StringInit(&temp
10270 29 3b 0a 09 20 20 20 20 54 63 6c 5f 4a 6f 69 6e );.. Tcl_Join
10280 50 61 74 68 28 31 2c 20 26 64 69 72 2c 20 26 74 Path(1, &dir, &t
10290 65 6d 70 29 3b 0a 09 20 20 20 20 54 63 6c 5f 44 emp);.. Tcl_D
102a0 53 74 72 69 6e 67 46 72 65 65 28 26 64 69 72 53 StringFree(&dirS
102b0 74 72 69 6e 67 29 3b 0a 09 7d 20 65 6c 73 65 20 tring);..} else
102c0 7b 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 {.. /*..
102d0 2a 20 57 65 20 68 61 76 65 20 61 20 75 73 65 72 * We have a user
102e0 20 6e 61 6d 65 20 27 7e 75 73 65 72 27 0a 09 20 name '~user'..
102f0 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 63 6f 6e */... con
10300 73 74 20 63 68 61 72 20 2a 65 78 70 61 6e 64 65 st char *expande
10310 64 55 73 65 72 3b 0a 09 20 20 20 20 54 63 6c 5f dUser;.. Tcl_
10320 44 53 74 72 69 6e 67 20 75 73 65 72 4e 61 6d 65 DString userName
10330 3b 0a 0a 09 20 20 20 20 54 63 6c 5f 44 53 74 72 ;... Tcl_DStr
10340 69 6e 67 49 6e 69 74 28 26 75 73 65 72 4e 61 6d ingInit(&userNam
10350 65 29 3b 0a 09 20 20 20 20 54 63 6c 5f 44 53 74 e);.. Tcl_DSt
10360 72 69 6e 67 41 70 70 65 6e 64 28 26 75 73 65 72 ringAppend(&user
10370 4e 61 6d 65 2c 20 6e 61 6d 65 2b 31 2c 20 73 70 Name, name+1, sp
10380 6c 69 74 2d 31 29 3b 0a 09 20 20 20 20 65 78 70 lit-1);.. exp
10390 61 6e 64 65 64 55 73 65 72 20 3d 20 54 63 6c 5f andedUser = Tcl_
103a0 44 53 74 72 69 6e 67 56 61 6c 75 65 28 26 75 73 DStringValue(&us
103b0 65 72 4e 61 6d 65 29 3b 0a 0a 09 20 20 20 20 54 erName);... T
103c0 63 6c 5f 44 53 74 72 69 6e 67 49 6e 69 74 28 26 cl_DStringInit(&
103d0 74 65 6d 70 29 3b 0a 09 20 20 20 20 69 66 20 28 temp);.. if (
103e0 54 63 6c 70 47 65 74 55 73 65 72 48 6f 6d 65 28 TclpGetUserHome(
103f0 65 78 70 61 6e 64 65 64 55 73 65 72 2c 20 26 74 expandedUser, &t
10400 65 6d 70 29 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a emp) == NULL) {.
10410 09 09 69 66 20 28 69 6e 74 65 72 70 20 21 3d 20 ..if (interp !=
10420 4e 55 4c 4c 29 20 7b 0a 09 09 20 20 20 20 54 63 NULL) {... Tc
10430 6c 5f 53 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 l_SetObjResult(i
10440 6e 74 65 72 70 2c 20 54 63 6c 5f 4f 62 6a 50 72 nterp, Tcl_ObjPr
10450 69 6e 74 66 28 0a 09 09 09 20 20 20 20 22 75 73 intf(.... "us
10460 65 72 20 5c 22 25 73 5c 22 20 64 6f 65 73 6e 27 er \"%s\" doesn'
10470 74 20 65 78 69 73 74 22 2c 20 65 78 70 61 6e 64 t exist", expand
10480 65 64 55 73 65 72 29 29 3b 0a 09 09 20 20 20 20 edUser));...
10490 54 63 6c 5f 53 65 74 45 72 72 6f 72 43 6f 64 65 Tcl_SetErrorCode
104a0 28 69 6e 74 65 72 70 2c 20 22 54 43 4c 22 2c 20 (interp, "TCL",
104b0 22 56 41 4c 55 45 22 2c 20 22 50 41 54 48 22 2c "VALUE", "PATH",
104c0 20 22 4e 4f 55 53 45 52 22 2c 0a 09 09 09 20 20 "NOUSER",....
104d0 20 20 4e 55 4c 4c 29 3b 0a 09 09 7d 0a 09 09 54 NULL);...}...T
104e0 63 6c 5f 44 53 74 72 69 6e 67 46 72 65 65 28 26 cl_DStringFree(&
104f0 75 73 65 72 4e 61 6d 65 29 3b 0a 09 09 54 63 6c userName);...Tcl
10500 5f 44 53 74 72 69 6e 67 46 72 65 65 28 26 74 65 _DStringFree(&te
10510 6d 70 29 3b 0a 09 09 72 65 74 75 72 6e 20 54 43 mp);...return TC
10520 4c 5f 45 52 52 4f 52 3b 0a 09 20 20 20 20 7d 0a L_ERROR;.. }.
10530 09 20 20 20 20 54 63 6c 5f 44 53 74 72 69 6e 67 . Tcl_DString
10540 46 72 65 65 28 26 75 73 65 72 4e 61 6d 65 29 3b Free(&userName);
10550 0a 09 7d 0a 0a 09 74 72 61 6e 73 50 74 72 20 3d ..}...transPtr =
10560 20 54 63 6c 44 53 74 72 69 6e 67 54 6f 4f 62 6a TclDStringToObj
10570 28 26 74 65 6d 70 29 3b 0a 0a 09 69 66 20 28 73 (&temp);...if (s
10580 70 6c 69 74 20 21 3d 20 6c 65 6e 29 20 7b 0a 09 plit != len) {..
10590 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 4a /*.. * J
105a0 6f 69 6e 20 75 70 20 74 68 65 20 74 69 6c 64 65 oin up the tilde
105b0 20 73 75 62 73 74 69 74 75 74 69 6f 6e 20 77 69 substitution wi
105c0 74 68 20 74 68 65 20 72 65 73 74 2e 0a 09 20 20 th the rest...
105d0 20 20 20 2a 2f 0a 0a 09 20 20 20 20 69 66 20 28 */... if (
105e0 6e 61 6d 65 5b 73 70 6c 69 74 2b 31 5d 20 3d 3d name[split+1] ==
105f0 20 73 65 70 61 72 61 74 6f 72 29 20 7b 0a 09 09 separator) {...
10600 2f 2a 0a 09 09 20 2a 20 53 6f 6d 65 77 68 61 74 /*... * Somewhat
10610 20 74 72 69 63 6b 79 20 63 61 73 65 20 6c 69 6b tricky case lik
10620 65 20 7e 2f 2f 66 6f 6f 2f 62 61 72 2e 20 4d 61 e ~//foo/bar. Ma
10630 6b 65 20 75 73 65 20 6f 66 0a 09 09 20 2a 20 53 ke use of... * S
10640 70 6c 69 74 2f 4a 6f 69 6e 20 6d 61 63 68 69 6e plit/Join machin
10650 65 72 79 20 74 6f 20 67 65 74 20 69 74 20 72 69 ery to get it ri
10660 67 68 74 2e 20 41 73 73 75 6d 65 73 20 61 6c 6c ght. Assumes all
10670 20 70 61 74 68 73 0a 09 09 20 2a 20 62 65 67 69 paths... * begi
10680 6e 6e 69 6e 67 20 77 69 74 68 20 7e 20 61 72 65 nning with ~ are
10690 20 70 61 72 74 20 6f 66 20 74 68 65 20 6e 61 74 part of the nat
106a0 69 76 65 20 66 69 6c 65 73 79 73 74 65 6d 2e 0a ive filesystem..
106b0 09 09 20 2a 2f 0a 0a 09 09 69 6e 74 20 6f 62 6a .. */....int obj
106c0 63 3b 0a 09 09 54 63 6c 5f 4f 62 6a 20 2a 2a 6f c;...Tcl_Obj **o
106d0 62 6a 76 3b 0a 09 09 54 63 6c 5f 4f 62 6a 20 2a bjv;...Tcl_Obj *
106e0 70 61 72 74 73 20 3d 20 54 63 6c 70 4e 61 74 69 parts = TclpNati
106f0 76 65 53 70 6c 69 74 50 61 74 68 28 70 61 74 68 veSplitPath(path
10700 50 74 72 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 09 54 Ptr, NULL);....T
10710 63 6c 5f 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 cl_ListObjGetEle
10720 6d 65 6e 74 73 28 4e 55 4c 4c 2c 20 70 61 72 74 ments(NULL, part
10730 73 2c 20 26 6f 62 6a 63 2c 20 26 6f 62 6a 76 29 s, &objc, &objv)
10740 3b 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 53 6b 69 ;..../*... * Ski
10750 70 20 27 7e 27 2e 20 49 74 27 73 20 72 65 70 6c p '~'. It's repl
10760 61 63 65 64 20 62 79 20 69 74 73 20 65 78 70 61 aced by its expa
10770 6e 73 69 6f 6e 2e 0a 09 09 20 2a 2f 0a 0a 09 09 nsion.... */....
10780 6f 62 6a 63 2d 2d 3b 20 6f 62 6a 76 2b 2b 3b 0a objc--; objv++;.
10790 09 09 77 68 69 6c 65 20 28 6f 62 6a 63 2d 2d 29 ..while (objc--)
107a0 20 7b 0a 09 09 20 20 20 20 54 63 6c 70 4e 61 74 {... TclpNat
107b0 69 76 65 4a 6f 69 6e 50 61 74 68 28 74 72 61 6e iveJoinPath(tran
107c0 73 50 74 72 2c 20 54 63 6c 5f 47 65 74 53 74 72 sPtr, Tcl_GetStr
107d0 69 6e 67 28 2a 6f 62 6a 76 2b 2b 29 29 3b 0a 09 ing(*objv++));..
107e0 09 7d 0a 09 09 54 63 6c 44 65 63 72 52 65 66 43 .}...TclDecrRefC
107f0 6f 75 6e 74 28 70 61 72 74 73 29 3b 0a 09 20 20 ount(parts);..
10800 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09 54 63 6c } else {...Tcl
10810 5f 4f 62 6a 20 2a 70 61 69 72 5b 32 5d 3b 0a 0a _Obj *pair[2];..
10820 09 09 70 61 69 72 5b 30 5d 20 3d 20 74 72 61 6e ..pair[0] = tran
10830 73 50 74 72 3b 0a 09 09 70 61 69 72 5b 31 5d 20 sPtr;...pair[1]
10840 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f = Tcl_NewStringO
10850 62 6a 28 6e 61 6d 65 2b 73 70 6c 69 74 2b 31 2c bj(name+split+1,
10860 20 2d 31 29 3b 0a 09 09 74 72 61 6e 73 50 74 72 -1);...transPtr
10870 20 3d 20 54 63 6c 4a 6f 69 6e 50 61 74 68 28 32 = TclJoinPath(2
10880 2c 20 70 61 69 72 2c 20 31 29 3b 0a 09 09 69 66 , pair, 1);...if
10890 20 28 74 72 61 6e 73 50 74 72 20 21 3d 20 70 61 (transPtr != pa
108a0 69 72 5b 30 5d 29 20 7b 0a 09 09 20 20 20 20 54 ir[0]) {... T
108b0 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74 28 cl_DecrRefCount(
108c0 70 61 69 72 5b 30 5d 29 3b 0a 09 09 7d 0a 09 09 pair[0]);...}...
108d0 69 66 20 28 74 72 61 6e 73 50 74 72 20 21 3d 20 if (transPtr !=
108e0 70 61 69 72 5b 31 5d 29 20 7b 0a 09 09 20 20 20 pair[1]) {...
108f0 20 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e Tcl_DecrRefCoun
10900 74 28 70 61 69 72 5b 31 5d 29 3b 0a 09 09 7d 0a t(pair[1]);...}.
10910 09 20 20 20 20 7d 0a 09 7d 0a 20 20 20 20 7d 20 . }..}. }
10920 65 6c 73 65 20 7b 0a 09 74 72 61 6e 73 50 74 72 else {..transPtr
10930 20 3d 20 54 63 6c 4a 6f 69 6e 50 61 74 68 28 31 = TclJoinPath(1
10940 2c 20 26 70 61 74 68 50 74 72 2c 20 31 29 3b 0a , &pathPtr, 1);.
10950 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 }.. /*.
10960 20 20 20 2a 20 4e 6f 77 20 77 65 20 68 61 76 65 * Now we have
10970 20 61 20 74 72 61 6e 73 6c 61 74 65 64 20 66 69 a translated fi
10980 6c 65 6e 61 6d 65 20 69 6e 20 27 74 72 61 6e 73 lename in 'trans
10990 50 74 72 27 2e 20 54 68 69 73 20 77 69 6c 6c 20 Ptr'. This will
109a0 68 61 76 65 20 66 6f 72 77 61 72 64 0a 20 20 20 have forward.
109b0 20 20 2a 20 73 6c 61 73 68 65 73 20 6f 6e 20 57 * slashes on W
109c0 69 6e 64 6f 77 73 2c 20 61 6e 64 20 77 69 6c 6c indows, and will
109d0 20 6e 6f 74 20 63 6f 6e 74 61 69 6e 20 61 6e 79 not contain any
109e0 20 7e 75 73 65 72 20 73 65 71 75 65 6e 63 65 73 ~user sequences
109f0 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 66 .. */.. f
10a00 73 50 61 74 68 50 74 72 20 3d 20 63 6b 61 6c 6c sPathPtr = ckall
10a10 6f 63 28 73 69 7a 65 6f 66 28 46 73 50 61 74 68 oc(sizeof(FsPath
10a20 29 29 3b 0a 0a 20 20 20 20 66 73 50 61 74 68 50 ));.. fsPathP
10a30 74 72 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 61 tr->translatedPa
10a40 74 68 50 74 72 20 3d 20 74 72 61 6e 73 50 74 72 thPtr = transPtr
10a50 3b 0a 20 20 20 20 69 66 20 28 74 72 61 6e 73 50 ;. if (transP
10a60 74 72 20 21 3d 20 70 61 74 68 50 74 72 29 20 7b tr != pathPtr) {
10a70 0a 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 ..Tcl_IncrRefCou
10a80 6e 74 28 66 73 50 61 74 68 50 74 72 2d 3e 74 72 nt(fsPathPtr->tr
10a90 61 6e 73 6c 61 74 65 64 50 61 74 68 50 74 72 29 anslatedPathPtr)
10aa0 3b 0a 09 2f 2a 20 52 65 64 6f 20 74 72 61 6e 73 ;../* Redo trans
10ab0 6c 61 74 69 6f 6e 20 77 68 65 6e 20 24 65 6e 76 lation when $env
10ac0 28 48 4f 4d 45 29 20 63 68 61 6e 67 65 73 20 2a (HOME) changes *
10ad0 2f 0a 09 66 73 50 61 74 68 50 74 72 2d 3e 66 69 /..fsPathPtr->fi
10ae0 6c 65 73 79 73 74 65 6d 45 70 6f 63 68 20 3d 20 lesystemEpoch =
10af0 54 63 6c 46 53 45 70 6f 63 68 28 29 3b 0a 20 20 TclFSEpoch();.
10b00 20 20 7d 20 65 6c 73 65 20 7b 0a 09 66 73 50 61 } else {..fsPa
10b10 74 68 50 74 72 2d 3e 66 69 6c 65 73 79 73 74 65 thPtr->filesyste
10b20 6d 45 70 6f 63 68 20 3d 20 30 3b 0a 20 20 20 20 mEpoch = 0;.
10b30 7d 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 2d }. fsPathPtr-
10b40 3e 6e 6f 72 6d 50 61 74 68 50 74 72 20 3d 20 4e >normPathPtr = N
10b50 55 4c 4c 3b 0a 20 20 20 20 66 73 50 61 74 68 50 ULL;. fsPathP
10b60 74 72 2d 3e 63 77 64 50 74 72 20 3d 20 4e 55 4c tr->cwdPtr = NUL
10b70 4c 3b 0a 20 20 20 20 66 73 50 61 74 68 50 74 72 L;. fsPathPtr
10b80 2d 3e 6e 61 74 69 76 65 50 61 74 68 50 74 72 20 ->nativePathPtr
10b90 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 66 73 50 61 = NULL;. fsPa
10ba0 74 68 50 74 72 2d 3e 66 73 50 74 72 20 3d 20 4e thPtr->fsPtr = N
10bb0 55 4c 4c 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 ULL;.. /*.
10bc0 20 20 2a 20 46 72 65 65 20 6f 6c 64 20 72 65 70 * Free old rep
10bd0 72 65 73 65 6e 74 61 74 69 6f 6e 20 62 65 66 6f resentation befo
10be0 72 65 20 69 6e 73 74 61 6c 6c 69 6e 67 20 6f 75 re installing ou
10bf0 72 20 6e 65 77 20 6f 6e 65 2e 0a 20 20 20 20 20 r new one..
10c00 2a 2f 0a 0a 20 20 20 20 54 63 6c 46 72 65 65 49 */.. TclFreeI
10c10 6e 74 52 65 70 28 70 61 74 68 50 74 72 29 3b 0a ntRep(pathPtr);.
10c20 20 20 20 20 53 45 54 50 41 54 48 4f 42 4a 28 70 SETPATHOBJ(p
10c30 61 74 68 50 74 72 2c 20 66 73 50 61 74 68 50 74 athPtr, fsPathPt
10c40 72 29 3b 0a 20 20 20 20 50 41 54 48 46 4c 41 47 r);. PATHFLAG
10c50 53 28 70 61 74 68 50 74 72 29 20 3d 20 30 3b 0a S(pathPtr) = 0;.
10c60 20 20 20 20 70 61 74 68 50 74 72 2d 3e 74 79 70 pathPtr->typ
10c70 65 50 74 72 20 3d 20 26 74 63 6c 46 73 50 61 74 ePtr = &tclFsPat
10c80 68 54 79 70 65 3b 0a 20 20 20 20 72 65 74 75 72 hType;. retur
10c90 6e 20 54 43 4c 5f 4f 4b 3b 0a 7d 0a 0c 0a 73 74 n TCL_OK;.}...st
10ca0 61 74 69 63 20 76 6f 69 64 0a 46 72 65 65 46 73 atic void.FreeFs
10cb0 50 61 74 68 49 6e 74 65 72 6e 61 6c 52 65 70 28 PathInternalRep(
10cc0 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 . Tcl_Obj *pa
10cd0 74 68 50 74 72 29 09 09 2f 2a 20 50 61 74 68 20 thPtr)../* Path
10ce0 6f 62 6a 65 63 74 20 77 69 74 68 20 69 6e 74 65 object with inte
10cf0 72 6e 61 6c 20 72 65 70 20 74 6f 20 66 72 65 65 rnal rep to free
10d00 2e 20 2a 2f 0a 7b 0a 20 20 20 20 46 73 50 61 74 . */.{. FsPat
10d10 68 20 2a 66 73 50 61 74 68 50 74 72 20 3d 20 50 h *fsPathPtr = P
10d20 41 54 48 4f 42 4a 28 70 61 74 68 50 74 72 29 3b ATHOBJ(pathPtr);
10d30 0a 0a 20 20 20 20 69 66 20 28 66 73 50 61 74 68 .. if (fsPath
10d40 50 74 72 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 Ptr->translatedP
10d50 61 74 68 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 athPtr != NULL)
10d60 7b 0a 09 69 66 20 28 66 73 50 61 74 68 50 74 72 {..if (fsPathPtr
10d70 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 61 74 68 ->translatedPath
10d80 50 74 72 20 21 3d 20 70 61 74 68 50 74 72 29 20 Ptr != pathPtr)
10d90 7b 0a 09 20 20 20 20 54 63 6c 44 65 63 72 52 65 {.. TclDecrRe
10da0 66 43 6f 75 6e 74 28 66 73 50 61 74 68 50 74 72 fCount(fsPathPtr
10db0 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 61 74 68 ->translatedPath
10dc0 50 74 72 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 Ptr);..}. }.
10dd0 20 20 20 69 66 20 28 66 73 50 61 74 68 50 74 72 if (fsPathPtr
10de0 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 20 21 3d ->normPathPtr !=
10df0 20 4e 55 4c 4c 29 20 7b 0a 09 69 66 20 28 66 73 NULL) {..if (fs
10e00 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
10e10 68 50 74 72 20 21 3d 20 70 61 74 68 50 74 72 29 hPtr != pathPtr)
10e20 20 7b 0a 09 20 20 20 20 54 63 6c 44 65 63 72 52 {.. TclDecrR
10e30 65 66 43 6f 75 6e 74 28 66 73 50 61 74 68 50 74 efCount(fsPathPt
10e40 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 29 3b r->normPathPtr);
10e50 0a 09 7d 0a 09 66 73 50 61 74 68 50 74 72 2d 3e ..}..fsPathPtr->
10e60 6e 6f 72 6d 50 61 74 68 50 74 72 20 3d 20 4e 55 normPathPtr = NU
10e70 4c 4c 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 LL;. }. if
10e80 20 28 66 73 50 61 74 68 50 74 72 2d 3e 63 77 64 (fsPathPtr->cwd
10e90 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 Ptr != NULL) {..
10ea0 54 63 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 TclDecrRefCount(
10eb0 66 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 fsPathPtr->cwdPt
10ec0 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 r);. }. if
10ed0 20 28 66 73 50 61 74 68 50 74 72 2d 3e 6e 61 74 (fsPathPtr->nat
10ee0 69 76 65 50 61 74 68 50 74 72 20 21 3d 20 4e 55 ivePathPtr != NU
10ef0 4c 4c 20 26 26 20 66 73 50 61 74 68 50 74 72 2d LL && fsPathPtr-
10f00 3e 66 73 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 >fsPtr != NULL)
10f10 7b 0a 09 54 63 6c 5f 46 53 46 72 65 65 49 6e 74 {..Tcl_FSFreeInt
10f20 65 72 6e 61 6c 52 65 70 50 72 6f 63 20 2a 66 72 ernalRepProc *fr
10f30 65 65 50 72 6f 63 20 3d 0a 09 09 66 73 50 61 74 eeProc =...fsPat
10f40 68 50 74 72 2d 3e 66 73 50 74 72 2d 3e 66 72 65 hPtr->fsPtr->fre
10f50 65 49 6e 74 65 72 6e 61 6c 52 65 70 50 72 6f 63 eInternalRepProc
10f60 3b 0a 0a 09 69 66 20 28 66 72 65 65 50 72 6f 63 ;...if (freeProc
10f70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 != NULL) {..
10f80 20 66 72 65 65 50 72 6f 63 28 66 73 50 61 74 68 freeProc(fsPath
10f90 50 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 68 50 Ptr->nativePathP
10fa0 74 72 29 3b 0a 09 20 20 20 20 66 73 50 61 74 68 tr);.. fsPath
10fb0 50 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 68 50 Ptr->nativePathP
10fc0 74 72 20 3d 20 4e 55 4c 4c 3b 0a 09 7d 0a 20 20 tr = NULL;..}.
10fd0 20 20 7d 0a 0a 20 20 20 20 63 6b 66 72 65 65 28 }.. ckfree(
10fe0 66 73 50 61 74 68 50 74 72 29 3b 0a 20 20 20 20 fsPathPtr);.
10ff0 70 61 74 68 50 74 72 2d 3e 74 79 70 65 50 74 72 pathPtr->typePtr
11000 20 3d 20 4e 55 4c 4c 3b 0a 7d 0a 0c 0a 73 74 61 = NULL;.}...sta
11010 74 69 63 20 76 6f 69 64 0a 44 75 70 46 73 50 61 tic void.DupFsPa
11020 74 68 49 6e 74 65 72 6e 61 6c 52 65 70 28 0a 20 thInternalRep(.
11030 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 73 72 63 50 Tcl_Obj *srcP
11040 74 72 2c 09 09 2f 2a 20 50 61 74 68 20 6f 62 6a tr,../* Path obj
11050 20 77 69 74 68 20 69 6e 74 65 72 6e 61 6c 20 72 with internal r
11060 65 70 20 74 6f 20 63 6f 70 79 2e 20 2a 2f 0a 20 ep to copy. */.
11070 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 6f 70 79 Tcl_Obj *copy
11080 50 74 72 29 09 09 2f 2a 20 50 61 74 68 20 6f 62 Ptr)../* Path ob
11090 6a 20 77 69 74 68 20 69 6e 74 65 72 6e 61 6c 20 j with internal
110a0 72 65 70 20 74 6f 20 73 65 74 2e 20 2a 2f 0a 7b rep to set. */.{
110b0 0a 20 20 20 20 46 73 50 61 74 68 20 2a 73 72 63 . FsPath *src
110c0 46 73 50 61 74 68 50 74 72 20 3d 20 50 41 54 48 FsPathPtr = PATH
110d0 4f 42 4a 28 73 72 63 50 74 72 29 3b 0a 20 20 20 OBJ(srcPtr);.
110e0 20 46 73 50 61 74 68 20 2a 63 6f 70 79 46 73 50 FsPath *copyFsP
110f0 61 74 68 50 74 72 20 3d 20 63 6b 61 6c 6c 6f 63 athPtr = ckalloc
11100 28 73 69 7a 65 6f 66 28 46 73 50 61 74 68 29 29 (sizeof(FsPath))
11110 3b 0a 0a 20 20 20 20 53 45 54 50 41 54 48 4f 42 ;.. SETPATHOB
11120 4a 28 63 6f 70 79 50 74 72 2c 20 63 6f 70 79 46 J(copyPtr, copyF
11130 73 50 61 74 68 50 74 72 29 3b 0a 0a 20 20 20 20 sPathPtr);..
11140 69 66 20 28 73 72 63 46 73 50 61 74 68 50 74 72 if (srcFsPathPtr
11150 2d 3e 74 72 61 6e 73 6c 61 74 65 64 50 61 74 68 ->translatedPath
11160 50 74 72 20 3d 3d 20 73 72 63 50 74 72 29 20 7b Ptr == srcPtr) {
11170 0a 09 2f 2a 20 43 79 63 6c 65 20 69 6e 20 73 72 ../* Cycle in sr
11180 63 20 2d 3e 20 6d 61 6b 65 20 63 79 63 6c 65 20 c -> make cycle
11190 69 6e 20 63 6f 70 79 2e 20 2a 2f 0a 09 63 6f 70 in copy. */..cop
111a0 79 46 73 50 61 74 68 50 74 72 2d 3e 74 72 61 6e yFsPathPtr->tran
111b0 73 6c 61 74 65 64 50 61 74 68 50 74 72 20 3d 20 slatedPathPtr =
111c0 63 6f 70 79 50 74 72 3b 0a 20 20 20 20 7d 20 65 copyPtr;. } e
111d0 6c 73 65 20 7b 0a 09 63 6f 70 79 46 73 50 61 74 lse {..copyFsPat
111e0 68 50 74 72 2d 3e 74 72 61 6e 73 6c 61 74 65 64 hPtr->translated
111f0 50 61 74 68 50 74 72 20 3d 20 73 72 63 46 73 50 PathPtr = srcFsP
11200 61 74 68 50 74 72 2d 3e 74 72 61 6e 73 6c 61 74 athPtr->translat
11210 65 64 50 61 74 68 50 74 72 3b 0a 09 69 66 20 28 edPathPtr;..if (
11220 63 6f 70 79 46 73 50 61 74 68 50 74 72 2d 3e 74 copyFsPathPtr->t
11230 72 61 6e 73 6c 61 74 65 64 50 61 74 68 50 74 72 ranslatedPathPtr
11240 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 != NULL) {..
11250 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e Tcl_IncrRefCoun
11260 74 28 63 6f 70 79 46 73 50 61 74 68 50 74 72 2d t(copyFsPathPtr-
11270 3e 74 72 61 6e 73 6c 61 74 65 64 50 61 74 68 50 >translatedPathP
11280 74 72 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 tr);..}. }..
11290 20 20 20 69 66 20 28 73 72 63 46 73 50 61 74 68 if (srcFsPath
112a0 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 72 Ptr->normPathPtr
112b0 20 3d 3d 20 73 72 63 50 74 72 29 20 7b 0a 09 2f == srcPtr) {../
112c0 2a 20 43 79 63 6c 65 20 69 6e 20 73 72 63 20 2d * Cycle in src -
112d0 3e 20 6d 61 6b 65 20 63 79 63 6c 65 20 69 6e 20 > make cycle in
112e0 63 6f 70 79 2e 20 2a 2f 0a 09 63 6f 70 79 46 73 copy. */..copyFs
112f0 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
11300 68 50 74 72 20 3d 20 63 6f 70 79 50 74 72 3b 0a hPtr = copyPtr;.
11310 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 63 6f } else {..co
11320 70 79 46 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 pyFsPathPtr->nor
11330 6d 50 61 74 68 50 74 72 20 3d 20 73 72 63 46 73 mPathPtr = srcFs
11340 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 PathPtr->normPat
11350 68 50 74 72 3b 0a 09 69 66 20 28 63 6f 70 79 46 hPtr;..if (copyF
11360 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 sPathPtr->normPa
11370 74 68 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b thPtr != NULL) {
11380 0a 09 20 20 20 20 54 63 6c 5f 49 6e 63 72 52 65 .. Tcl_IncrRe
11390 66 43 6f 75 6e 74 28 63 6f 70 79 46 73 50 61 74 fCount(copyFsPat
113a0 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 74 68 50 74 hPtr->normPathPt
113b0 72 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 r);..}. }..
113c0 20 20 63 6f 70 79 46 73 50 61 74 68 50 74 72 2d copyFsPathPtr-
113d0 3e 63 77 64 50 74 72 20 3d 20 73 72 63 46 73 50 >cwdPtr = srcFsP
113e0 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 3b 0a athPtr->cwdPtr;.
113f0 20 20 20 20 69 66 20 28 63 6f 70 79 46 73 50 61 if (copyFsPa
11400 74 68 50 74 72 2d 3e 63 77 64 50 74 72 20 21 3d thPtr->cwdPtr !=
11410 20 4e 55 4c 4c 29 20 7b 0a 09 54 63 6c 5f 49 6e NULL) {..Tcl_In
11420 63 72 52 65 66 43 6f 75 6e 74 28 63 6f 70 79 46 crRefCount(copyF
11430 73 50 61 74 68 50 74 72 2d 3e 63 77 64 50 74 72 sPathPtr->cwdPtr
11440 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 63 6f );. }.. co
11450 70 79 46 73 50 61 74 68 50 74 72 2d 3e 66 6c 61 pyFsPathPtr->fla
11460 67 73 20 3d 20 73 72 63 46 73 50 61 74 68 50 74 gs = srcFsPathPt
11470 72 2d 3e 66 6c 61 67 73 3b 0a 0a 20 20 20 20 69 r->flags;.. i
11480 66 20 28 73 72 63 46 73 50 61 74 68 50 74 72 2d f (srcFsPathPtr-
11490 3e 66 73 50 74 72 20 21 3d 20 4e 55 4c 4c 0a 09 >fsPtr != NULL..
114a0 20 20 20 20 26 26 20 73 72 63 46 73 50 61 74 68 && srcFsPath
114b0 50 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 68 50 Ptr->nativePathP
114c0 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 54 tr != NULL) {..T
114d0 63 6c 5f 46 53 44 75 70 49 6e 74 65 72 6e 61 6c cl_FSDupInternal
114e0 52 65 70 50 72 6f 63 20 2a 64 75 70 50 72 6f 63 RepProc *dupProc
114f0 20 3d 0a 09 09 73 72 63 46 73 50 61 74 68 50 74 =...srcFsPathPt
11500 72 2d 3e 66 73 50 74 72 2d 3e 64 75 70 49 6e 74 r->fsPtr->dupInt
11510 65 72 6e 61 6c 52 65 70 50 72 6f 63 3b 0a 0a 09 ernalRepProc;...
11520 69 66 20 28 64 75 70 50 72 6f 63 20 21 3d 20 4e if (dupProc != N
11530 55 4c 4c 29 20 7b 0a 09 20 20 20 20 63 6f 70 79 ULL) {.. copy
11540 46 73 50 61 74 68 50 74 72 2d 3e 6e 61 74 69 76 FsPathPtr->nativ
11550 65 50 61 74 68 50 74 72 20 3d 0a 09 09 20 20 20 ePathPtr =...
11560 20 64 75 70 50 72 6f 63 28 73 72 63 46 73 50 61 dupProc(srcFsPa
11570 74 68 50 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 thPtr->nativePat
11580 68 50 74 72 29 3b 0a 09 7d 20 65 6c 73 65 20 7b hPtr);..} else {
11590 0a 09 20 20 20 20 63 6f 70 79 46 73 50 61 74 68 .. copyFsPath
115a0 50 74 72 2d 3e 6e 61 74 69 76 65 50 61 74 68 50 Ptr->nativePathP
115b0 74 72 20 3d 20 4e 55 4c 4c 3b 0a 09 7d 0a 20 20 tr = NULL;..}.
115c0 20 20 7d 20 65 6c 73 65 20 7b 0a 09 63 6f 70 79 } else {..copy
115d0 46 73 50 61 74 68 50 74 72 2d 3e 6e 61 74 69 76 FsPathPtr->nativ
115e0 65 50 61 74 68 50 74 72 20 3d 20 4e 55 4c 4c 3b ePathPtr = NULL;
115f0 0a 20 20 20 20 7d 0a 20 20 20 20 63 6f 70 79 46 . }. copyF
11600 73 50 61 74 68 50 74 72 2d 3e 66 73 50 74 72 20 sPathPtr->fsPtr
11610 3d 20 73 72 63 46 73 50 61 74 68 50 74 72 2d 3e = srcFsPathPtr->
11620 66 73 50 74 72 3b 0a 20 20 20 20 63 6f 70 79 46 fsPtr;. copyF
11630 73 50 61 74 68 50 74 72 2d 3e 66 69 6c 65 73 79 sPathPtr->filesy
11640 73 74 65 6d 45 70 6f 63 68 20 3d 20 73 72 63 46 stemEpoch = srcF
11650 73 50 61 74 68 50 74 72 2d 3e 66 69 6c 65 73 79 sPathPtr->filesy
11660 73 74 65 6d 45 70 6f 63 68 3b 0a 0a 20 20 20 20 stemEpoch;..
11670 63 6f 70 79 50 74 72 2d 3e 74 79 70 65 50 74 72 copyPtr->typePtr
11680 20 3d 20 26 74 63 6c 46 73 50 61 74 68 54 79 70 = &tclFsPathTyp
11690 65 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d e;.}.../*. *----
116a0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
116b0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
116c0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
116d0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
116e0 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 55 70 -------. *. * Up
116f0 64 61 74 65 53 74 72 69 6e 67 4f 66 46 73 50 61 dateStringOfFsPa
11700 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 47 69 76 65 th --. *. *.Give
11710 73 20 61 6e 20 6f 62 6a 65 63 74 20 61 20 76 61 s an object a va
11720 6c 69 64 20 73 74 72 69 6e 67 20 72 65 70 2e 0a lid string rep..
11730 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 *. * Results:.
11740 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 *.None.. *. * Si
11750 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 4d de effects:. *.M
11760 65 6d 6f 72 79 20 6d 61 79 20 62 65 20 61 6c 6c emory may be all
11770 6f 63 61 74 65 64 2e 0a 20 2a 0a 20 2a 2d 2d 2d ocated.. *. *---
11780 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11790 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
117a0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
117b0 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
117c0 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 73 74 --------. */..st
117d0 61 74 69 63 20 76 6f 69 64 0a 55 70 64 61 74 65 atic void.Update
117e0 53 74 72 69 6e 67 4f 66 46 73 50 61 74 68 28 0a StringOfFsPath(.
117f0 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70 61 74 Tcl_Obj *pat
11800 68 50 74 72 29 09 2f 2a 20 70 61 74 68 20 6f 62 hPtr)./* path ob
11810 6a 20 77 69 74 68 20 73 74 72 69 6e 67 20 72 65 j with string re
11820 70 20 74 6f 20 75 70 64 61 74 65 2e 20 2a 2f 0a p to update. */.
11830 7b 0a 20 20 20 20 46 73 50 61 74 68 20 2a 66 73 {. FsPath *fs
11840 50 61 74 68 50 74 72 20 3d 20 50 41 54 48 4f 42 PathPtr = PATHOB
11850 4a 28 70 61 74 68 50 74 72 29 3b 0a 20 20 20 20 J(pathPtr);.
11860 69 6e 74 20 63 77 64 4c 65 6e 3b 0a 20 20 20 20 int cwdLen;.
11870 54 63 6c 5f 4f 62 6a 20 2a 63 6f 70 79 3b 0a 0a Tcl_Obj *copy;..
11880 20 20 20 20 69 66 20 28 50 41 54 48 46 4c 41 47 if (PATHFLAG
11890 53 28 70 61 74 68 50 74 72 29 20 3d 3d 20 30 20 S(pathPtr) == 0
118a0 7c 7c 20 66 73 50 61 74 68 50 74 72 2d 3e 63 77 || fsPathPtr->cw
118b0 64 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a dPtr == NULL) {.
118c0 09 54 63 6c 5f 50 61 6e 69 63 28 22 43 61 6c 6c .Tcl_Panic("Call
118d0 65 64 20 55 70 64 61 74 65 53 74 72 69 6e 67 4f ed UpdateStringO
118e0 66 46 73 50 61 74 68 20 77 69 74 68 20 69 6e 76 fFsPath with inv
118f0 61 6c 69 64 20 6f 62 6a 65 63 74 22 29 3b 0a 20 alid object");.
11900 20 20 20 7d 0a 0a 20 20 20 20 63 6f 70 79 20 3d }.. copy =
11910 20 41 70 70 65 6e 64 50 61 74 68 28 66 73 50 61 AppendPath(fsPa
11920 74 68 50 74 72 2d 3e 63 77 64 50 74 72 2c 20 66 thPtr->cwdPtr, f
11930 73 50 61 74 68 50 74 72 2d 3e 6e 6f 72 6d 50 61 sPathPtr->normPa
11940 74 68 50 74 72 29 3b 0a 0a 20 20 20 20 70 61 74 thPtr);.. pat
11950 68 50 74 72 2d 3e 62 79 74 65 73 20 3d 20 54 63 hPtr->bytes = Tc
11960 6c 5f 47 65 74 53 74 72 69 6e 67 46 72 6f 6d 4f l_GetStringFromO
11970 62 6a 28 63 6f 70 79 2c 20 26 63 77 64 4c 65 6e bj(copy, &cwdLen
11980 29 3b 0a 20 20 20 20 70 61 74 68 50 74 72 2d 3e );. pathPtr->
11990 6c 65 6e 67 74 68 20 3d 20 63 77 64 4c 65 6e 3b length = cwdLen;
119a0 0a 20 20 20 20 63 6f 70 79 2d 3e 62 79 74 65 73 . copy->bytes
119b0 20 3d 20 74 63 6c 45 6d 70 74 79 53 74 72 69 6e = tclEmptyStrin
119c0 67 52 65 70 3b 0a 20 20 20 20 63 6f 70 79 2d 3e gRep;. copy->
119d0 6c 65 6e 67 74 68 20 3d 20 30 3b 0a 20 20 20 20 length = 0;.
119e0 54 63 6c 44 65 63 72 52 65 66 43 6f 75 6e 74 28 TclDecrRefCount(
119f0 63 6f 70 79 29 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a copy);.}.../*. *
11a00 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11a10 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11a20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11a30 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11a40 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 -----------. *.
11a50 2a 20 54 63 6c 4e 61 74 69 76 65 50 61 74 68 49 * TclNativePathI
11a60 6e 46 69 6c 65 73 79 73 74 65 6d 20 2d 2d 0a 20 nFilesystem --.
11a70 2a 0a 20 2a 09 41 6e 79 20 70 61 74 68 20 6f 62 *. *.Any path ob
11a80 6a 65 63 74 20 69 73 20 61 63 63 65 70 74 61 62 ject is acceptab
11a90 6c 65 20 74 6f 20 74 68 65 20 6e 61 74 69 76 65 le to the native
11aa0 20 66 69 6c 65 73 79 73 74 65 6d 2c 20 62 79 20 filesystem, by
11ab0 64 65 66 61 75 6c 74 20 28 77 65 0a 20 2a 09 77 default (we. *.w
11ac0 69 6c 6c 20 74 68 72 6f 77 20 65 72 72 6f 72 73 ill throw errors
11ad0 20 77 68 65 6e 20 69 6c 6c 65 67 61 6c 20 70 61 when illegal pa
11ae0 74 68 73 20 61 72 65 20 61 63 74 75 61 6c 6c 79 ths are actually
11af0 20 74 72 69 65 64 20 74 6f 20 62 65 20 75 73 65 tried to be use
11b00 64 29 2e 0a 20 2a 0a 20 2a 09 48 6f 77 65 76 65 d).. *. *.Howeve
11b10 72 2c 20 74 68 69 73 20 62 65 68 61 76 69 6f 72 r, this behavior
11b20 20 6d 65 61 6e 73 20 74 68 65 20 6e 61 74 69 76 means the nativ
11b30 65 20 66 69 6c 65 73 79 73 74 65 6d 20 6d 75 73 e filesystem mus
11b40 74 20 62 65 20 74 68 65 20 6c 61 73 74 0a 20 2a t be the last. *
11b50 09 66 69 6c 65 73 79 73 74 65 6d 20 69 6e 20 74 .filesystem in t
11b60 68 65 20 6c 6f 6f 6b 75 70 20 6c 69 73 74 20 28 he lookup list (
11b70 6f 74 68 65 72 77 69 73 65 20 69 74 20 77 69 6c otherwise it wil
11b80 6c 20 63 6c 61 69 6d 20 61 6c 6c 20 66 69 6c 65 l claim all file
11b90 73 0a 20 2a 09 62 65 6c 6f 6e 67 20 74 6f 20 69 s. *.belong to i
11ba0 74 2c 20 61 6e 64 20 6f 74 68 65 72 20 66 69 6c t, and other fil
11bb0 65 73 79 73 74 65 6d 73 20 77 69 6c 6c 20 6e 65 esystems will ne
11bc0 76 65 72 20 67 65 74 20 61 20 6c 6f 6f 6b 20 69 ver get a look i
11bd0 6e 29 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 n).. *. * Result
11be0 73 3a 0a 20 2a 09 54 43 4c 5f 4f 4b 2c 20 74 6f s:. *.TCL_OK, to
11bf0 20 69 6e 64 69 63 61 74 65 20 27 79 65 73 27 2c indicate 'yes',
11c00 20 2d 31 20 74 6f 20 69 6e 64 69 63 61 74 65 20 -1 to indicate
11c10 6e 6f 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 no.. *. * Side e
11c20 66 66 65 63 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e ffects:. *.None.
11c30 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d . *. *----------
11c40 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11c50 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11c60 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11c70 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
11c80 2d 0a 20 2a 2f 0a 0a 69 6e 74 0a 54 63 6c 4e 61 -. */..int.TclNa
11c90 74 69 76 65 50 61 74 68 49 6e 46 69 6c 65 73 79 tivePathInFilesy
11ca0 73 74 65 6d 28 0a 20 20 20 20 54 63 6c 5f 4f 62 stem(. Tcl_Ob
11cb0 6a 20 2a 70 61 74 68 50 74 72 2c 0a 20 20 20 20 j *pathPtr,.
11cc0 43 6c 69 65 6e 74 44 61 74 61 20 2a 63 6c 69 65 ClientData *clie
11cd0 6e 74 44 61 74 61 50 74 72 29 0a 7b 0a 20 20 20 ntDataPtr).{.
11ce0 20 2f 2a 0a 20 20 20 20 20 2a 20 41 20 73 70 65 /*. * A spe
11cf0 63 69 61 6c 20 63 61 73 65 20 69 73 20 72 65 71 cial case is req
11d00 75 69 72 65 64 20 74 6f 20 68 61 6e 64 6c 65 20 uired to handle
11d10 74 68 65 20 65 6d 70 74 79 20 70 61 74 68 20 22 the empty path "
11d20 22 2e 20 54 68 69 73 20 69 73 20 61 20 76 61 6c ". This is a val
11d30 69 64 0a 20 20 20 20 20 2a 20 70 61 74 68 20 28 id. * path (
11d40 69 2e 65 2e 20 74 68 65 20 75 73 65 72 20 73 68 i.e. the user sh
11d50 6f 75 6c 64 20 62 65 20 61 62 6c 65 20 74 6f 20 ould be able to
11d60 64 6f 20 27 66 69 6c 65 20 65 78 69 73 74 73 20 do 'file exists
11d70 22 22 27 20 77 69 74 68 6f 75 74 0a 20 20 20 20 ""' without.
11d80 20 2a 20 74 68 72 6f 77 69 6e 67 20 61 6e 20 65 * throwing an e
11d90 72 72 6f 72 29 2c 20 62 75 74 20 65 71 75 61 6c rror), but equal
11da0 6c 79 20 74 68 65 20 70 61 74 68 20 64 6f 65 73 ly the path does
11db0 6e 27 74 20 65 78 69 73 74 2e 20 54 68 6f 73 65 n't exist. Those
11dc0 20 61 72 65 20 74 68 65 0a 20 20 20 20 20 2a 20 are the. *
11dd0 73 65 6d 61 6e 74 69 63 73 20 6f 66 20 54 63 6c semantics of Tcl
11de0 20 28 61 74 20 70 72 65 73 65 6e 74 20 61 6e 79 (at present any
11df0 77 61 79 29 2c 20 73 6f 20 77 65 20 68 61 76 65 way), so we have
11e00 20 74 6f 20 61 62 69 64 65 20 62 79 20 74 68 65 to abide by the
11e10 6d 20 68 65 72 65 2e 0a 20 20 20 20 20 2a 2f 0a m here.. */.
11e20 0a 20 20 20 20 69 66 20 28 70 61 74 68 50 74 72 . if (pathPtr
11e30 2d 3e 74 79 70 65 50 74 72 20 3d 3d 20 26 74 63 ->typePtr == &tc
11e40 6c 46 73 50 61 74 68 54 79 70 65 29 20 7b 0a 09 lFsPathType) {..
11e50 69 66 20 28 70 61 74 68 50 74 72 2d 3e 62 79 74 if (pathPtr->byt
11e60 65 73 20 21 3d 20 4e 55 4c 4c 20 26 26 20 70 61 es != NULL && pa
11e70 74 68 50 74 72 2d 3e 62 79 74 65 73 5b 30 5d 20 thPtr->bytes[0]
11e80 3d 3d 20 27 5c 30 27 29 20 7b 0a 09 20 20 20 20 == '\0') {..
11e90 2f 2a 0a 09 20 20 20 20 20 2a 20 57 65 20 72 65 /*.. * We re
11ea0 6a 65 63 74 20 74 68 65 20 65 6d 70 74 79 20 70 ject the empty p
11eb0 61 74 68 20 22 22 2e 0a 09 20 20 20 20 20 2a 2f ath ""... */
11ec0 0a 0a 09 20 20 20 20 72 65 74 75 72 6e 20 2d 31 ... return -1
11ed0 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 4f 74 ;..}.../*.. * Ot
11ee0 68 65 72 77 69 73 65 20 74 68 65 72 65 20 69 73 herwise there is
11ef0 20 6e 6f 20 77 61 79 20 74 68 69 73 20 70 61 74 no way this pat
11f00 68 20 63 61 6e 20 62 65 20 65 6d 70 74 79 2e 0a h can be empty..
11f10 09 20 2a 2f 0a 20 20 20 20 7d 20 65 6c 73 65 20 . */. } else
11f20 7b 0a 09 2f 2a 0a 09 20 2a 20 49 74 20 69 73 20 {../*.. * It is
11f30 73 6f 6d 65 77 68 61 74 20 75 6e 75 73 75 61 6c somewhat unusual
11f40 20 74 6f 20 72 65 61 63 68 20 74 68 69 73 20 63 to reach this c
11f50 6f 64 65 20 70 61 74 68 20 77 69 74 68 6f 75 74 ode path without
11f60 20 74 68 65 20 6f 62 6a 65 63 74 0a 09 20 2a 20 the object.. *
11f70 62 65 69 6e 67 20 6f 66 20 74 63 6c 46 73 50 61 being of tclFsPa
11f80 74 68 54 79 70 65 2e 20 48 6f 77 65 76 65 72 2c thType. However,
11f90 20 77 65 20 64 6f 20 6f 75 72 20 62 65 73 74 20 we do our best
11fa0 74 6f 20 64 65 61 6c 20 77 69 74 68 20 74 68 65 to deal with the
11fb0 0a 09 20 2a 20 73 69 74 75 61 74 69 6f 6e 2e 0a .. * situation..
11fc0 09 20 2a 2f 0a 0a 09 69 6e 74 20 6c 65 6e 3b 0a . */...int len;.
11fd0 0a 09 28 76 6f 69 64 29 20 54 63 6c 5f 47 65 74 ..(void) Tcl_Get
11fe0 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 70 61 StringFromObj(pa
11ff0 74 68 50 74 72 2c 20 26 6c 65 6e 29 3b 0a 09 69 thPtr, &len);..i
12000 66 20 28 6c 65 6e 20 3d 3d 20 30 29 20 7b 0a 09 f (len == 0) {..
12010 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 57 /*.. * W
12020 65 20 72 65 6a 65 63 74 20 74 68 65 20 65 6d 70 e reject the emp
12030 74 79 20 70 61 74 68 20 22 22 2e 0a 09 20 20 20 ty path ""...
12040 20 20 2a 2f 0a 0a 09 20 20 20 20 72 65 74 75 72 */... retur
12050 6e 20 2d 31 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a n -1;..}. }..
12060 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 50 61 /*. * Pa
12070 74 68 20 69 73 20 6f 66 20 63 6f 72 72 65 63 74 th is of correct
12080 20 74 79 70 65 2c 20 6f 72 20 69 73 20 6f 66 20 type, or is of
12090 6e 6f 6e 2d 7a 65 72 6f 20 6c 65 6e 67 74 68 2c non-zero length,
120a0 20 73 6f 20 77 65 20 61 63 63 65 70 74 20 69 74 so we accept it
120b0 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 72 .. */.. r
120c0 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 7d 0a eturn TCL_OK;.}.
120d0 0c 0a 2f 2a 0a 20 2a 20 4c 6f 63 61 6c 20 56 61 ../*. * Local Va
120e0 72 69 61 62 6c 65 73 3a 0a 20 2a 20 6d 6f 64 65 riables:. * mode
120f0 3a 20 63 0a 20 2a 20 63 2d 62 61 73 69 63 2d 6f : c. * c-basic-o
12100 66 66 73 65 74 3a 20 34 0a 20 2a 20 66 69 6c 6c ffset: 4. * fill
12110 2d 63 6f 6c 75 6d 6e 3a 20 37 38 0a 20 2a 20 45 -column: 78. * E
12120 6e 64 3a 0a 20 2a 2f 0a nd:. */.