Tcl Source Code

Hex Artifact Content
Login

Artifact 6867007412f3aa4ce3216fde93523c0b427aa52b:

Attachment "tm.tcl" to ticket [942881ffff] added by andreas_kupries 2004-07-16 01:23:34.
0000: 23 20 2d 2a 2d 20 74 63 6c 20 2d 2a 2d 0a 23 0a  # -*- tcl -*-.#.
0010: 23 20 53 65 61 72 63 68 69 6e 67 20 66 6f 72 20  # Searching for 
0020: 54 63 6c 20 4d 6f 64 75 6c 65 73 2e 20 44 65 66  Tcl Modules. Def
0030: 69 6e 65 73 20 61 20 70 72 6f 63 65 64 75 72 65  ines a procedure
0040: 2c 20 64 65 63 6c 61 72 65 73 20 69 74 20 61 73  , declares it as
0050: 20 74 68 65 0a 23 20 70 72 69 6d 61 72 79 20 63   the.# primary c
0060: 6f 6d 6d 61 6e 64 20 66 6f 72 20 66 69 6e 64 69  ommand for findi
0070: 6e 67 20 70 61 63 6b 61 67 65 73 2c 20 68 6f 77  ng packages, how
0080: 65 76 65 72 20 61 6c 73 6f 20 75 73 65 73 20 74  ever also uses t
0090: 68 65 20 66 6f 72 6d 65 72 0a 23 20 27 70 61 63  he former.# 'pac
00a0: 6b 61 67 65 20 75 6e 6b 6e 6f 77 6e 27 20 63 6f  kage unknown' co
00b0: 6d 6d 61 6e 64 20 61 73 20 61 20 66 61 6c 6c 62  mmand as a fallb
00c0: 61 63 6b 2e 0a 23 0a 23 20 4c 6f 63 61 74 65 73  ack..#.# Locates
00d0: 20 61 6c 6c 20 70 6f 73 73 69 62 6c 65 20 70 61   all possible pa
00e0: 63 6b 61 67 65 73 20 69 6e 20 61 20 64 69 72 65  ckages in a dire
00f0: 63 74 6f 72 79 20 76 69 61 20 61 20 6c 65 73 73  ctory via a less
0100: 20 72 65 73 74 72 69 63 74 65 64 0a 23 20 67 6c   restricted.# gl
0110: 6f 62 2e 20 54 68 65 20 74 61 72 67 65 74 65 64  ob. The targeted
0120: 20 64 69 72 65 63 74 6f 72 79 20 69 73 20 64 65   directory is de
0130: 72 69 76 65 64 20 66 72 6f 6d 20 74 68 65 20 6e  rived from the n
0140: 61 6d 65 20 6f 66 20 74 68 65 0a 23 20 72 65 71  ame of the.# req
0150: 75 65 73 74 65 64 20 70 61 63 6b 61 67 65 2e 20  uested package. 
0160: 49 2e 65 2e 20 74 68 65 20 54 4d 20 73 63 61 6e  I.e. the TM scan
0170: 20 77 69 6c 6c 20 6c 6f 6f 6b 20 6f 6e 6c 79 20   will look only 
0180: 61 74 20 64 69 72 65 63 74 6f 72 69 65 73 0a 23  at directories.#
0190: 20 77 68 69 63 68 20 63 61 6e 20 63 6f 6e 74 61   which can conta
01a0: 69 6e 20 74 68 65 20 72 65 71 75 65 73 74 65 64  in the requested
01b0: 20 70 61 63 6b 61 67 65 2e 20 49 74 20 77 69 6c   package. It wil
01c0: 6c 20 72 65 67 69 73 74 65 72 20 61 6c 6c 0a 23  l register all.#
01d0: 20 70 61 63 6b 61 67 65 73 20 69 74 20 66 6f 75   packages it fou
01e0: 6e 64 20 69 6e 20 74 68 65 20 64 69 72 65 63 74  nd in the direct
01f0: 6f 72 79 20 73 6f 20 74 68 61 74 20 66 75 74 75  ory so that futu
0200: 72 65 20 72 65 71 75 65 73 74 73 20 68 61 76 65  re requests have
0210: 20 61 0a 23 20 68 69 67 68 65 72 20 63 68 61 6e   a.# higher chan
0220: 63 65 20 6f 66 20 62 65 69 6e 67 20 66 75 6c 66  ce of being fulf
0230: 69 6c 6c 65 64 20 62 79 20 74 68 65 20 69 66 6e  illed by the ifn
0240: 65 65 64 65 64 20 64 61 74 61 62 61 73 65 20 77  eeded database w
0250: 69 74 68 6f 75 74 0a 23 20 68 61 76 69 6e 67 20  ithout.# having 
0260: 74 6f 20 63 6f 6d 65 20 74 6f 20 75 73 20 61 67  to come to us ag
0270: 61 69 6e 2e 0a 23 0a 23 20 57 65 20 64 6f 20 6e  ain..#.# We do n
0280: 6f 74 20 72 65 6d 65 6d 62 65 72 20 77 68 65 72  ot remember wher
0290: 65 20 77 65 20 68 61 76 65 20 62 65 65 6e 20 61  e we have been a
02a0: 6e 64 20 73 69 6d 70 6c 79 20 72 65 73 63 61 6e  nd simply rescan
02b0: 20 74 61 72 67 65 74 65 64 0a 23 20 64 69 72 65   targeted.# dire
02c0: 63 74 6f 72 69 65 73 20 77 68 65 6e 20 69 6e 76  ctories when inv
02d0: 6f 6b 65 64 20 61 67 61 69 6e 2e 20 54 68 65 20  oked again. The 
02e0: 72 65 61 73 6f 6e 69 6e 67 20 69 73 20 74 68 69  reasoning is thi
02f0: 73 3a 0a 23 0a 23 20 2d 20 54 68 65 20 6f 6e 6c  s:.#.# - The onl
0300: 79 20 77 61 79 20 77 65 20 67 65 74 20 62 61 63  y way we get bac
0310: 6b 20 74 6f 20 74 68 65 20 73 61 6d 65 20 64 69  k to the same di
0320: 72 65 63 74 6f 72 79 20 69 73 20 69 66 20 73 6f  rectory is if so
0330: 6d 65 6f 6e 65 20 69 73 0a 23 20 20 20 74 72 79  meone is.#   try
0340: 69 6e 67 20 74 6f 20 5b 70 61 63 6b 61 67 65 20  ing to [package 
0350: 72 65 71 75 69 72 65 5d 20 73 6f 6d 65 74 68 69  require] somethi
0360: 6e 67 20 74 68 61 74 20 77 61 73 6e 27 74 20 74  ng that wasn't t
0370: 68 65 72 65 20 6f 6e 20 74 68 65 0a 23 20 20 20  here on the.#   
0380: 66 69 72 73 74 20 73 63 61 6e 2e 0a 23 0a 23 20  first scan..#.# 
0390: 20 20 45 69 74 68 65 72 0a 23 20 20 20 31 29 20    Either.#   1) 
03a0: 49 74 20 69 73 20 74 68 65 72 65 20 6e 6f 77 3a  It is there now:
03b0: 20 20 49 66 20 77 65 20 72 65 73 63 61 6e 2c 20    If we rescan, 
03c0: 79 6f 75 20 67 65 74 20 69 74 3b 20 69 66 20 6e  you get it; if n
03d0: 6f 74 20 79 6f 75 20 64 6f 6e 27 74 2e 0a 23 0a  ot you don't..#.
03e0: 23 20 20 20 20 20 20 54 68 69 73 20 63 6f 76 65  #      This cove
03f0: 72 73 20 74 68 65 20 70 6f 73 73 69 62 69 6c 69  rs the possibili
0400: 74 79 20 74 68 61 74 20 74 68 65 20 61 70 70 6c  ty that the appl
0410: 69 63 61 74 69 6f 6e 20 61 73 6b 65 64 20 66 6f  ication asked fo
0420: 72 20 61 0a 23 20 20 20 20 20 20 70 61 63 6b 61  r a.#      packa
0430: 67 65 20 6c 61 74 65 2c 20 61 6e 64 20 74 68 65  ge late, and the
0440: 20 70 61 63 6b 61 67 65 20 77 61 73 20 61 63 74   package was act
0450: 75 61 6c 6c 79 20 61 64 64 65 64 20 74 6f 20 74  ually added to t
0460: 68 65 0a 23 20 20 20 20 20 20 69 6e 73 74 61 6c  he.#      instal
0470: 6c 61 74 69 6f 6e 20 61 66 74 65 72 20 74 68 65  lation after the
0480: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 77 61 73   application was
0490: 20 73 74 61 72 74 65 64 2e 20 49 74 20 73 68 6f   started. It sho
04a0: 75 6b 6c 64 0a 23 20 20 20 20 20 20 73 74 69 6c  ukld.#      stil
04b0: 6c 20 62 65 20 61 62 6c 65 20 74 6f 20 66 69 6e  l be able to fin
04c0: 64 20 69 74 2e 0a 23 0a 23 20 20 20 32 29 20 49  d it..#.#   2) I
04d0: 74 20 73 74 69 6c 6c 20 69 73 20 6e 6f 74 20 74  t still is not t
04e0: 68 65 72 65 3a 20 45 69 74 68 65 72 20 77 61 79  here: Either way
04f0: 2c 20 79 6f 75 20 64 6f 6e 27 74 20 67 65 74 20  , you don't get 
0500: 69 74 2c 20 62 75 74 20 74 68 65 0a 23 20 20 20  it, but the.#   
0510: 20 20 20 72 65 73 63 61 6e 20 74 61 6b 65 73 20     rescan takes 
0520: 74 69 6d 65 2e 20 54 68 69 73 20 69 73 20 68 6f  time. This is ho
0530: 77 65 76 65 72 20 61 6e 20 65 72 72 6f 72 20 63  wever an error c
0540: 61 73 65 20 61 6e 64 20 77 65 20 64 6f 6e 74 27  ase and we dont'
0550: 74 0a 23 20 20 20 20 20 20 63 61 72 65 20 74 68  t.#      care th
0560: 61 74 20 6d 75 63 68 20 61 62 6f 75 74 20 69 74  at much about it
0570: 0a 23 0a 23 20 20 20 33 29 20 49 74 20 77 61 73  .#.#   3) It was
0580: 20 74 68 65 72 65 20 74 68 65 20 66 69 72 73 74   there the first
0590: 20 74 69 6d 65 3b 20 62 75 74 20 66 6f 72 20 73   time; but for s
05a0: 6f 6d 65 20 72 65 61 73 6f 6e 20 61 20 22 70 61  ome reason a "pa
05b0: 63 6b 61 67 65 0a 23 20 20 20 20 20 20 66 6f 72  ckage.#      for
05c0: 67 65 74 22 20 68 61 73 20 62 65 65 6e 20 72 75  get" has been ru
05d0: 6e 2c 20 61 6e 64 20 22 70 61 63 6b 61 67 65 22  n, and "package"
05e0: 20 64 6f 65 73 6e 27 74 20 6b 6e 6f 77 20 61 62   doesn't know ab
05f0: 6f 75 74 20 69 74 0a 23 20 20 20 20 20 20 61 6e  out it.#      an
0600: 79 6d 6f 72 65 2e 0a 23 0a 23 20 20 20 20 20 20  ymore..#.#      
0610: 54 68 69 73 20 63 61 6e 20 62 65 20 61 6e 20 69  This can be an i
0620: 6e 64 69 63 61 74 69 6f 6e 20 74 68 61 74 20 74  ndication that t
0630: 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 77  he application w
0640: 69 73 68 65 73 20 74 6f 20 72 65 6c 6f 61 64 0a  ishes to reload.
0650: 23 20 20 20 20 20 20 73 6f 6d 65 20 66 75 6e 63  #      some func
0660: 74 69 6f 6e 61 6c 69 74 79 2e 20 41 6e 64 20 73  tionality. And s
0670: 68 6f 75 6c 64 20 77 6f 72 6b 20 61 73 20 77 65  hould work as we
0680: 6c 6c 2e 0a 23 0a 23 20 4e 6f 74 65 20 74 68 61  ll..#.# Note tha
0690: 74 20 74 68 69 73 20 61 6c 73 6f 20 73 74 72 69  t this also stri
06a0: 6b 65 73 20 61 20 62 61 6c 61 6e 63 65 20 62 65  kes a balance be
06b0: 74 77 65 65 6e 20 64 6f 69 6e 67 20 61 20 67 6c  tween doing a gl
06c0: 6f 62 20 74 61 72 67 65 74 69 6e 67 0a 23 20 61  ob targeting.# a
06d0: 20 73 69 6e 67 6c 65 20 70 61 63 6b 61 67 65 2c   single package,
06e0: 20 61 6e 64 20 74 68 75 73 20 6d 6f 73 74 20 6c   and thus most l
06f0: 69 6b 65 6c 79 20 72 65 71 75 69 72 69 6e 67 20  ikely requiring 
0700: 6d 75 6c 74 69 70 6c 65 20 67 6c 6f 62 73 20 6f  multiple globs o
0710: 66 0a 23 20 74 68 65 20 73 61 6d 65 20 64 69 72  f.# the same dir
0720: 65 63 74 6f 72 79 20 77 68 65 6e 20 74 68 65 20  ectory when the 
0730: 61 70 70 6c 69 63 61 74 69 6f 6e 20 69 73 20 61  application is a
0740: 73 6b 69 6e 67 20 66 6f 72 20 6d 61 6e 79 20 70  sking for many p
0750: 61 63 6b 61 67 65 73 2c 0a 23 20 61 6e 64 20 74  ackages,.# and t
0760: 72 79 69 6e 67 20 74 6f 20 67 6c 6f 62 20 66 6f  rying to glob fo
0770: 72 20 5f 65 76 65 72 79 74 68 69 6e 67 5f 20 69  r _everything_ i
0780: 6e 20 61 6c 6c 20 73 75 62 64 69 72 65 63 74 6f  n all subdirecto
0790: 72 69 65 73 20 77 68 65 6e 0a 23 20 6c 6f 6f 6b  ries when.# look
07a0: 69 6e 67 20 66 6f 72 20 61 20 70 61 63 6b 61 67  ing for a packag
07b0: 65 2c 20 77 68 69 63 68 20 63 6f 6d 65 73 20 77  e, which comes w
07c0: 69 74 68 20 61 20 68 65 61 76 79 20 73 74 61 72  ith a heavy star
07d0: 74 75 70 20 63 6f 73 74 2e 0a 23 0a 23 20 57 65  tup cost..#.# We
07e0: 20 73 63 61 6e 20 66 6f 72 20 72 65 67 75 6c 61   scan for regula
07f0: 72 20 70 61 63 6b 61 67 65 73 20 6f 6e 6c 79 20  r packages only 
0800: 69 66 20 6e 6f 20 73 61 74 69 73 66 79 69 6e 67  if no satisfying
0810: 20 6d 6f 64 75 6c 65 20 77 61 73 20 66 6f 75 6e   module was foun
0820: 64 2e 0a 0a 6e 61 6d 65 73 70 61 63 65 20 65 76  d...namespace ev
0830: 61 6c 20 3a 3a 74 63 6c 3a 3a 74 6d 20 7b 0a 20  al ::tcl::tm {. 
0840: 20 20 20 23 20 44 65 66 61 75 6c 74 20 70 61 74     # Default pat
0850: 68 73 2e 20 4e 6f 6e 65 20 79 65 74 2e 0a 0a 20  hs. None yet... 
0860: 20 20 20 76 61 72 69 61 62 6c 65 20 70 61 74 68     variable path
0870: 73 20 7b 7d 0a 0a 20 20 20 20 23 20 54 68 65 20  s {}..    # The 
0880: 72 65 67 65 78 20 70 61 74 74 65 72 6e 20 61 20  regex pattern a 
0890: 66 69 6c 65 20 6e 61 6d 65 20 68 61 73 20 74 6f  file name has to
08a0: 20 6d 61 74 63 68 20 74 6f 20 6d 61 6b 65 20 69   match to make i
08b0: 74 20 61 20 54 63 6c 20 4d 6f 64 75 6c 65 2e 0a  t a Tcl Module..
08c0: 0a 20 20 20 20 73 65 74 20 70 6b 67 70 61 74 74  .    set pkgpatt
08d0: 65 72 6e 20 7b 5e 28 5b 5b 3a 61 6c 70 68 61 3a  ern {^([[:alpha:
08e0: 5d 5d 5b 3a 5b 3a 61 6c 6e 75 6d 3a 5d 5d 2a 29  ]][:[:alnum:]]*)
08f0: 2d 28 5b 5b 3a 64 69 67 69 74 3a 5d 5d 2e 2a 29  -([[:digit:]].*)
0900: 5b 2e 5d 74 6d 24 7d 0a 0a 20 20 20 20 23 20 45  [.]tm$}..    # E
0910: 78 70 6f 72 74 20 74 68 65 20 70 75 62 6c 69 63  xport the public
0920: 20 41 50 49 0a 0a 20 20 20 20 6e 61 6d 65 73 70   API..    namesp
0930: 61 63 65 20 65 78 70 6f 72 74 20 70 61 74 68 0a  ace export path.
0940: 7d 0a 0a 23 20 3a 3a 74 63 6c 3a 3a 74 6d 3a 3a  }..# ::tcl::tm::
0950: 70 61 74 68 20 2d 2d 0a 23 0a 23 09 50 75 62 6c  path --.#.#.Publ
0960: 69 63 20 41 50 49 20 74 6f 20 74 68 65 20 6d 6f  ic API to the mo
0970: 64 75 6c 65 20 70 61 74 68 2e 20 53 65 65 20 73  dule path. See s
0980: 70 65 63 69 66 69 63 61 74 69 6f 6e 2e 0a 23 0a  pecification..#.
0990: 23 20 41 72 67 75 6d 65 6e 74 73 0a 23 09 63 6d  # Arguments.#.cm
09a0: 64 20 2d 09 54 68 65 20 73 75 62 63 6f 6d 6d 61  d -.The subcomma
09b0: 6e 64 20 74 6f 20 65 78 65 63 75 74 65 0a 23 09  nd to execute.#.
09c0: 61 72 67 73 20 2d 09 54 68 65 20 70 61 74 68 73  args -.The paths
09d0: 20 74 6f 20 61 64 64 2f 72 65 6d 6f 76 65 2e 20   to add/remove. 
09e0: 4d 75 73 74 20 6e 6f 74 20 61 70 70 65 61 72 20  Must not appear 
09f0: 71 75 65 72 79 69 6e 67 20 74 68 65 0a 23 09 09  querying the.#..
0a00: 70 61 74 68 20 77 69 74 68 20 27 6c 69 73 74 27  path with 'list'
0a10: 2e 0a 23 0a 23 20 52 65 73 75 6c 74 73 0a 23 09  ..#.# Results.#.
0a20: 4e 6f 20 72 65 73 75 6c 74 20 66 6f 72 20 73 75  No result for su
0a30: 62 63 6f 6d 6d 61 6e 64 73 20 27 61 64 64 27 20  bcommands 'add' 
0a40: 61 6e 64 20 27 72 65 6d 6f 76 65 27 2e 20 41 20  and 'remove'. A 
0a50: 6c 69 73 74 20 6f 66 20 70 61 74 68 73 0a 23 09  list of paths.#.
0a60: 66 6f 72 20 27 6c 69 73 74 27 2e 0a 23 0a 23 20  for 'list'..#.# 
0a70: 53 69 64 65 65 66 66 65 63 74 73 0a 23 09 54 68  Sideeffects.#.Th
0a80: 65 20 73 75 62 63 6f 6d 6d 61 6e 64 73 20 27 61  e subcommands 'a
0a90: 64 64 27 20 61 6e 64 20 27 72 65 6d 6f 76 65 27  dd' and 'remove'
0aa0: 20 6d 61 6e 69 70 75 6c 61 74 65 20 74 68 65 20   manipulate the 
0ab0: 6c 69 73 74 20 6f 66 0a 23 09 70 61 74 68 73 20  list of.#.paths 
0ac0: 74 6f 20 73 65 61 72 63 68 20 66 6f 72 20 54 63  to search for Tc
0ad0: 6c 20 4d 6f 64 75 6c 65 73 2e 20 54 68 65 20 73  l Modules. The s
0ae0: 75 62 63 6f 6d 6d 61 6e 64 20 27 6c 69 73 74 27  ubcommand 'list'
0af0: 20 68 61 73 20 6e 6f 0a 23 09 73 69 64 65 65 66   has no.#.sideef
0b00: 66 65 63 74 73 2e 0a 0a 70 72 6f 63 20 3a 3a 74  fects...proc ::t
0b10: 63 6c 3a 3a 74 6d 3a 3a 70 61 74 68 20 7b 63 6d  cl::tm::path {cm
0b20: 64 20 61 72 67 73 7d 20 7b 0a 20 20 20 20 76 61  d args} {.    va
0b30: 72 69 61 62 6c 65 20 70 61 74 68 73 0a 20 20 20  riable paths.   
0b40: 20 73 77 69 74 63 68 20 2d 65 78 61 63 74 20 2d   switch -exact -
0b50: 2d 20 24 63 6d 64 20 7b 0a 09 61 64 64 20 7b 0a  - $cmd {..add {.
0b60: 09 20 20 20 20 23 20 54 68 65 20 70 61 74 68 20  .    # The path 
0b70: 69 73 20 61 64 64 65 64 20 61 74 20 74 68 65 20  is added at the 
0b80: 68 65 61 64 20 74 6f 20 74 68 65 20 6c 69 73 74  head to the list
0b90: 20 6f 66 20 6d 6f 64 75 6c 65 0a 09 20 20 20 20   of module..    
0ba0: 23 20 70 61 74 68 73 2e 0a 09 20 20 20 20 23 0a  # paths...    #.
0bb0: 09 20 20 20 20 23 20 54 68 65 20 63 6f 6d 6d 61  .    # The comma
0bc0: 6e 64 20 65 6e 66 6f 72 63 65 73 20 74 68 65 20  nd enforces the 
0bd0: 72 65 73 74 72 69 63 74 69 6f 6e 20 74 68 61 74  restriction that
0be0: 20 6e 6f 20 70 61 74 68 20 6d 61 79 20 62 65 0a   no path may be.
0bf0: 09 20 20 20 20 23 20 61 6e 20 61 6e 63 65 73 74  .    # an ancest
0c00: 6f 72 20 64 69 72 65 63 74 6f 72 79 20 6f 66 20  or directory of 
0c10: 61 6e 79 20 6f 74 68 65 72 20 70 61 74 68 20 6f  any other path o
0c20: 6e 20 74 68 65 20 6c 69 73 74 2e 20 49 66 0a 09  n the list. If..
0c30: 20 20 20 20 23 20 74 68 65 20 6e 65 77 20 70 61      # the new pa
0c40: 74 68 20 76 69 6f 6c 61 74 65 73 20 74 68 69 73  th violates this
0c50: 20 72 65 73 74 72 69 63 74 69 6f 6e 20 61 6e 20   restriction an 
0c60: 65 72 72 6f 72 20 77 69 6c 20 62 65 0a 09 20 20  error wil be..  
0c70: 20 20 23 20 72 61 69 73 65 64 2e 0a 09 20 20 20    # raised...   
0c80: 20 23 0a 09 20 20 20 20 23 20 49 66 20 74 68 65   #..    # If the
0c90: 20 70 61 74 68 20 69 73 20 61 6c 72 65 61 64 79   path is already
0ca0: 20 70 72 65 73 65 6e 74 20 61 73 20 69 73 20 6e   present as is n
0cb0: 6f 20 65 72 72 6f 72 20 77 69 6c 6c 20 62 65 0a  o error will be.
0cc0: 09 20 20 20 20 23 20 72 61 69 73 65 64 20 61 6e  .    # raised an
0cd0: 64 20 6e 6f 20 61 63 74 69 6f 6e 20 77 69 6c 6c  d no action will
0ce0: 20 62 65 20 74 61 6b 65 6e 2e 0a 0a 09 20 20 20   be taken....   
0cf0: 20 69 66 20 7b 21 5b 6c 6c 65 6e 67 74 68 20 24   if {![llength $
0d00: 61 72 67 73 5d 7d 20 7b 0a 09 09 72 65 74 75 72  args]} {...retur
0d10: 6e 20 2d 63 6f 64 65 20 65 72 72 6f 72 20 22 77  n -code error "w
0d20: 72 6f 6e 67 23 61 72 67 73 2c 20 65 78 70 65 63  rong#args, expec
0d30: 74 65 64 3a 20 5b 6c 69 6e 64 65 78 20 5b 69 6e  ted: [lindex [in
0d40: 66 6f 20 6c 65 76 65 6c 20 30 5d 20 30 5d 20 61  fo level 0] 0] a
0d50: 64 64 20 70 61 74 68 20 70 61 74 68 2e 2e 2e 22  dd path path..."
0d60: 0a 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 73 65  ..    }...    se
0d70: 74 20 6e 65 77 70 61 74 68 73 20 7b 7d 0a 09 20  t newpaths {}.. 
0d80: 20 20 20 66 6f 72 65 61 63 68 20 70 20 24 61 72     foreach p $ar
0d90: 67 73 20 7b 0a 09 09 73 65 74 20 70 6f 73 20 5b  gs {...set pos [
0da0: 6c 73 65 61 72 63 68 20 2d 65 78 61 63 74 20 24  lsearch -exact $
0db0: 70 61 74 68 73 20 24 70 5d 0a 09 09 69 66 20 7b  paths $p]...if {
0dc0: 24 70 6f 73 20 3e 3d 20 30 7d 20 7b 0a 09 09 20  $pos >= 0} {... 
0dd0: 20 20 20 23 20 49 67 6e 6f 72 65 20 61 20 70 61     # Ignore a pa
0de0: 74 68 20 61 6c 72 65 61 64 79 20 6f 6e 20 74 68  th already on th
0df0: 65 20 6c 69 73 74 2e 0a 09 09 20 20 20 20 63 6f  e list....    co
0e00: 6e 74 69 6e 75 65 0a 09 09 7d 0a 0a 09 09 23 20  ntinue...}....# 
0e10: 53 65 61 72 63 68 20 66 6f 72 20 70 61 74 68 73  Search for paths
0e20: 20 77 68 69 63 68 20 61 72 65 20 73 75 62 64 69   which are subdi
0e30: 72 65 63 74 6f 72 69 65 73 20 6f 66 20 74 68 65  rectories of the
0e40: 20 6e 65 77 0a 09 09 23 20 6f 6e 65 2e 20 49 66   new...# one. If
0e50: 20 74 68 65 72 65 20 61 72 65 20 61 6e 79 20 74   there are any t
0e60: 68 65 6e 20 6e 65 77 20 70 61 74 68 20 76 69 6f  hen new path vio
0e70: 6c 61 74 65 73 20 74 68 65 0a 09 09 23 20 72 65  lates the...# re
0e80: 73 74 72 69 63 74 69 6f 6e 20 61 62 6f 75 74 20  striction about 
0e90: 61 6e 63 65 73 74 6f 72 73 2e 0a 0a 09 09 73 65  ancestors.....se
0ea0: 74 20 70 6f 73 20 5b 6c 73 65 61 72 63 68 20 2d  t pos [lsearch -
0eb0: 67 6c 6f 62 20 24 70 61 74 68 73 20 24 7b 70 7d  glob $paths ${p}
0ec0: 2f 2a 5d 0a 09 09 69 66 20 7b 24 70 6f 73 20 3e  /*]...if {$pos >
0ed0: 3d 20 30 7d 20 7b 0a 09 09 20 20 20 20 72 65 74  = 0} {...    ret
0ee0: 75 72 6e 20 2d 63 6f 64 65 20 65 72 72 6f 72 20  urn -code error 
0ef0: 22 24 70 20 69 73 20 61 6e 63 65 73 74 6f 72 20  "$p is ancestor 
0f00: 6f 66 20 65 78 69 73 74 69 6e 67 20 6d 6f 64 75  of existing modu
0f10: 6c 65 20 70 61 74 68 20 5b 6c 69 6e 64 65 78 20  le path [lindex 
0f20: 24 70 61 74 68 73 20 24 70 6f 73 5d 2e 22 0a 09  $paths $pos]."..
0f30: 09 7d 0a 0a 09 09 23 20 4e 6f 77 20 6c 6f 6f 6b  .}....# Now look
0f40: 20 66 6f 72 20 70 61 74 68 73 20 77 68 69 63 68   for paths which
0f50: 20 61 72 65 20 61 6e 63 65 73 74 6f 72 73 20 6f   are ancestors o
0f60: 66 20 74 68 65 20 6e 65 77 0a 09 09 23 20 6f 6e  f the new...# on
0f70: 65 2e 20 54 68 69 73 20 72 65 76 65 72 73 65 20  e. This reverse 
0f80: 71 75 65 73 74 69 6f 6e 20 72 65 71 20 75 73 20  question req us 
0f90: 74 6f 20 6c 6f 6f 70 20 6f 76 65 72 20 74 68 65  to loop over the
0fa0: 0a 09 09 23 20 65 78 69 73 74 69 6e 67 20 70 61  ...# existing pa
0fb0: 74 68 73 20 3a 28 0a 0a 09 09 66 6f 72 65 61 63  ths :(....foreac
0fc0: 68 20 65 70 20 24 70 61 74 68 73 20 7b 0a 09 09  h ep $paths {...
0fd0: 20 20 20 20 69 66 20 7b 5b 73 74 72 69 6e 67 20      if {[string 
0fe0: 6d 61 74 63 68 20 24 7b 65 70 7d 2f 2a 20 24 70  match ${ep}/* $p
0ff0: 5d 7d 20 7b 0a 09 09 09 72 65 74 75 72 6e 20 2d  ]} {....return -
1000: 63 6f 64 65 20 65 72 72 6f 72 20 22 24 70 20 69  code error "$p i
1010: 73 20 73 75 62 64 69 72 65 63 74 6f 72 79 20 6f  s subdirectory o
1020: 66 20 65 78 69 73 74 69 6e 67 20 6d 6f 64 75 6c  f existing modul
1030: 65 20 70 61 74 68 20 24 65 70 2e 22 0a 09 09 20  e path $ep."... 
1040: 20 20 20 7d 0a 09 09 7d 0a 0a 09 09 6c 61 70 70     }...}....lapp
1050: 65 6e 64 20 6e 65 77 70 61 74 68 73 20 24 70 0a  end newpaths $p.
1060: 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 23 20 54  .    }...    # T
1070: 68 65 20 76 61 6c 69 64 61 74 69 6f 6e 20 6f 66  he validation of
1080: 20 74 68 65 20 69 6e 70 75 74 20 69 73 20 63 6f   the input is co
1090: 6d 70 6c 65 74 65 20 61 6e 64 20 73 75 63 63 65  mplete and succe
10a0: 73 73 66 75 6c 2c 0a 09 20 20 20 20 23 20 61 6e  ssful,..    # an
10b0: 64 20 65 76 65 72 79 74 68 69 6e 67 20 69 6e 20  d everything in 
10c0: 6e 65 77 70 61 74 68 73 20 69 73 20 61 63 74 75  newpaths is actu
10d0: 61 6c 6c 79 20 6e 65 77 2e 20 57 65 20 63 61 6e  ally new. We can
10e0: 20 6e 6f 77 0a 09 20 20 20 20 23 20 65 78 74 65   now..    # exte
10f0: 6e 64 20 74 68 65 20 6c 69 73 74 20 6f 66 20 70  nd the list of p
1100: 61 74 68 73 2e 0a 0a 09 20 20 20 20 66 6f 72 65  aths....    fore
1110: 61 63 68 20 70 20 24 6e 65 77 70 61 74 68 73 20  ach p $newpaths 
1120: 7b 0a 09 09 73 65 74 20 70 61 74 68 73 20 5b 6c  {...set paths [l
1130: 69 6e 73 65 72 74 20 24 70 61 74 68 73 20 30 20  insert $paths 0 
1140: 24 70 5d 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 72  $p]..    }..}..r
1150: 65 6d 6f 76 65 20 7b 0a 09 20 20 20 20 23 20 52  emove {..    # R
1160: 65 6d 6f 76 65 73 20 74 68 65 20 70 61 74 68 20  emoves the path 
1170: 66 72 6f 6d 20 74 68 65 20 6c 69 73 74 20 6f 66  from the list of
1180: 20 6d 6f 64 75 6c 65 20 70 61 74 68 73 2e 20 54   module paths. T
1190: 68 65 0a 09 20 20 20 20 23 20 63 6f 6d 6d 61 6e  he..    # comman
11a0: 64 20 69 73 20 73 69 6c 65 6e 74 6c 79 20 69 67  d is silently ig
11b0: 6e 6f 72 65 64 20 69 66 20 74 68 65 20 70 61 74  nored if the pat
11c0: 68 20 69 73 20 6e 6f 74 20 6f 6e 20 74 68 65 0a  h is not on the.
11d0: 09 20 20 20 20 23 20 6c 69 73 74 2e 0a 0a 09 20  .    # list.... 
11e0: 20 20 20 69 66 20 7b 21 5b 6c 6c 65 6e 67 74 68     if {![llength
11f0: 20 24 61 72 67 73 5d 7d 20 7b 0a 09 09 72 65 74   $args]} {...ret
1200: 75 72 6e 20 2d 63 6f 64 65 20 65 72 72 6f 72 20  urn -code error 
1210: 22 77 72 6f 6e 67 23 61 72 67 73 2c 20 65 78 70  "wrong#args, exp
1220: 65 63 74 65 64 3a 20 5b 6c 69 6e 64 65 78 20 5b  ected: [lindex [
1230: 69 6e 66 6f 20 6c 65 76 65 6c 20 30 5d 20 30 5d  info level 0] 0]
1240: 20 72 65 6d 6f 76 65 20 70 61 74 68 20 70 61 74   remove path pat
1250: 68 20 2e 2e 2e 22 0a 09 20 20 20 20 7d 0a 0a 09  h ..."..    }...
1260: 20 20 20 20 66 6f 72 65 61 63 68 20 70 20 24 61      foreach p $a
1270: 72 67 73 20 7b 0a 09 09 73 65 74 20 70 6f 73 20  rgs {...set pos 
1280: 5b 6c 73 65 61 72 63 68 20 2d 65 78 61 63 74 20  [lsearch -exact 
1290: 24 70 61 74 68 73 20 24 70 5d 0a 09 09 69 66 20  $paths $p]...if 
12a0: 7b 24 70 6f 73 20 3e 3d 20 30 7d 20 7b 0a 09 09  {$pos >= 0} {...
12b0: 20 20 20 20 73 65 74 20 70 61 74 68 73 20 5b 6c      set paths [l
12c0: 72 65 70 6c 61 63 65 20 24 70 61 74 68 73 20 24  replace $paths $
12d0: 70 6f 73 20 24 70 6f 73 5d 0a 09 09 7d 0a 09 20  pos $pos]...}.. 
12e0: 20 20 20 7d 0a 09 7d 0a 09 6c 69 73 74 20 7b 0a     }..}..list {.
12f0: 09 20 20 20 20 69 66 20 7b 5b 6c 6c 65 6e 67 74  .    if {[llengt
1300: 68 20 24 61 72 67 73 5d 7d 20 7b 0a 09 09 72 65  h $args]} {...re
1310: 74 75 72 6e 20 2d 63 6f 64 65 20 65 72 72 6f 72  turn -code error
1320: 20 22 77 72 6f 6e 67 23 61 72 67 73 2c 20 65 78   "wrong#args, ex
1330: 70 65 63 74 65 64 3a 20 5b 6c 69 6e 64 65 78 20  pected: [lindex 
1340: 5b 69 6e 66 6f 20 6c 65 76 65 6c 20 30 5d 20 30  [info level 0] 0
1350: 5d 20 6c 69 73 74 22 0a 09 20 20 20 20 7d 0a 09  ] list"..    }..
1360: 20 20 20 20 72 65 74 75 72 6e 20 24 70 61 74 68      return $path
1370: 73 0a 09 7d 0a 09 64 65 66 61 75 6c 74 20 7b 0a  s..}..default {.
1380: 09 20 20 20 20 72 65 74 75 72 6e 20 2d 63 6f 64  .    return -cod
1390: 65 20 65 72 72 6f 72 20 22 45 78 70 65 63 74 20  e error "Expect 
13a0: 6f 6e 65 20 6f 66 20 61 64 64 2c 20 72 65 6d 6f  one of add, remo
13b0: 76 65 2c 20 6f 72 20 6c 69 73 74 2c 20 67 6f 74  ve, or list, got
13c0: 20 5c 22 24 63 6d 64 5c 22 22 0a 09 7d 0a 20 20   \"$cmd\""..}.  
13d0: 20 20 7d 0a 7d 0a 0a 23 20 3a 3a 74 63 6c 3a 3a    }.}..# ::tcl::
13e0: 74 6d 3a 3a 75 6e 6b 6e 6f 77 6e 20 2d 2d 0a 23  tm::unknown --.#
13f0: 0a 23 09 55 6e 6b 6e 6f 77 6e 20 68 61 6e 64 6c  .#.Unknown handl
1400: 65 72 20 66 6f 72 20 54 63 6c 20 4d 6f 64 75 6c  er for Tcl Modul
1410: 65 73 2c 20 69 2e 65 2e 20 70 61 63 6b 61 67 65  es, i.e. package
1420: 73 20 69 6e 20 6d 6f 64 75 6c 65 20 66 6f 72 6d  s in module form
1430: 2e 0a 23 0a 23 20 41 72 67 75 6d 65 6e 74 73 0a  ..#.# Arguments.
1440: 23 09 6f 72 69 67 69 6e 61 6c 09 2d 20 4f 72 69  #.original.- Ori
1450: 67 69 6e 61 6c 20 5b 70 61 63 6b 61 67 65 20 75  ginal [package u
1460: 6e 6b 6e 6f 77 6e 5d 20 70 72 6f 63 65 64 75 72  nknown] procedur
1470: 65 2e 0a 23 09 6e 61 6d 65 09 09 2d 20 4e 61 6d  e..#.name..- Nam
1480: 65 20 6f 66 20 64 65 73 69 72 65 64 20 70 61 63  e of desired pac
1490: 6b 61 67 65 2e 0a 23 09 76 65 72 73 69 6f 6e 09  kage..#.version.
14a0: 09 2d 20 56 65 72 73 69 6f 6e 20 6f 66 20 64 65  .- Version of de
14b0: 73 69 72 65 64 20 70 61 63 6b 61 67 65 2e 20 43  sired package. C
14c0: 61 6e 20 62 65 20 74 68 65 0a 23 09 09 09 20 20  an be the.#...  
14d0: 65 6d 70 74 79 20 73 74 72 69 6e 67 2e 0a 23 09  empty string..#.
14e0: 65 78 61 63 74 09 09 2d 20 45 69 74 68 65 72 20  exact..- Either 
14f0: 2d 65 78 61 63 74 20 6f 72 20 6f 6d 6d 69 74 74  -exact or ommitt
1500: 65 64 2e 0a 23 0a 23 09 4e 61 6d 65 2c 20 76 65  ed..#.#.Name, ve
1510: 72 73 69 6f 6e 2c 20 61 6e 64 20 65 78 61 63 74  rsion, and exact
1520: 20 61 72 65 20 75 73 65 64 20 74 6f 20 64 65 74   are used to det
1530: 65 72 6d 69 6e 65 0a 23 09 73 61 74 69 73 66 61  ermine.#.satisfa
1540: 63 74 69 6f 6e 2e 20 54 68 65 20 6f 72 69 67 69  ction. The origi
1550: 6e 61 6c 20 69 73 20 63 61 6c 6c 65 64 20 69 66  nal is called if
1560: 66 20 6e 6f 20 73 61 74 69 73 66 61 63 74 69 6f  f no satisfactio
1570: 6e 20 77 61 73 0a 23 09 61 63 68 69 65 76 65 64  n was.#.achieved
1580: 2e 20 54 68 65 20 6e 61 6d 65 20 69 73 20 61 6c  . The name is al
1590: 73 6f 20 75 73 65 64 20 74 6f 20 63 6f 6d 70 75  so used to compu
15a0: 74 65 20 74 68 65 20 64 69 72 65 63 74 6f 72 79  te the directory
15b0: 20 74 6f 0a 23 09 74 61 72 67 65 74 20 69 6e 20   to.#.target in 
15c0: 74 68 65 20 73 65 61 72 63 68 2e 0a 23 0a 23 20  the search..#.# 
15d0: 52 65 73 75 6c 74 73 0a 23 09 4e 6f 6e 65 2e 0a  Results.#.None..
15e0: 23 0a 23 20 53 69 64 65 65 66 66 65 63 74 73 0a  #.# Sideeffects.
15f0: 23 09 4d 61 79 20 70 6f 70 75 6c 61 74 65 20 74  #.May populate t
1600: 68 65 20 70 61 63 6b 61 67 65 20 69 66 6e 65 65  he package ifnee
1610: 64 65 64 20 64 61 74 61 62 61 73 65 20 77 69 74  ded database wit
1620: 68 20 61 64 64 69 74 69 6f 6e 61 6c 0a 23 09 70  h additional.#.p
1630: 72 6f 76 69 64 65 20 73 63 72 69 70 74 73 2e 0a  rovide scripts..
1640: 0a 70 72 6f 63 20 3a 3a 74 63 6c 3a 3a 74 6d 3a  .proc ::tcl::tm:
1650: 3a 75 6e 6b 6e 6f 77 6e 20 7b 6f 72 69 67 69 6e  :unknown {origin
1660: 61 6c 20 6e 61 6d 65 20 76 65 72 73 69 6f 6e 20  al name version 
1670: 7b 65 78 61 63 74 20 7b 7d 7d 7d 20 7b 0a 20 20  {exact {}}} {.  
1680: 20 20 23 20 49 6d 70 6f 72 74 20 74 68 65 20 6c    # Import the l
1690: 69 73 74 20 6f 66 20 70 61 74 68 73 20 74 6f 20  ist of paths to 
16a0: 73 65 61 72 63 68 20 66 6f 72 20 70 61 63 6b 61  search for packa
16b0: 67 65 73 20 69 6e 20 6d 6f 64 75 6c 65 20 66 6f  ges in module fo
16c0: 72 6d 2e 0a 20 20 20 20 23 20 49 6d 70 6f 72 74  rm..    # Import
16d0: 20 74 68 65 20 70 61 74 74 65 72 6e 20 75 73 65   the pattern use
16e0: 64 20 74 6f 20 63 68 65 63 6b 20 70 61 63 6b 61  d to check packa
16f0: 67 65 20 6e 61 6d 65 73 20 69 6e 20 64 65 74 61  ge names in deta
1700: 69 6c 2e 20 20 0a 0a 20 20 20 20 76 61 72 69 61  il.  ..    varia
1710: 62 6c 65 20 70 61 74 68 73 0a 20 20 20 20 76 61  ble paths.    va
1720: 72 69 61 62 6c 65 20 70 6b 67 70 61 74 74 65 72  riable pkgpatter
1730: 6e 0a 0a 20 20 20 20 23 20 57 69 74 68 6f 75 74  n..    # Without
1740: 20 70 61 74 68 73 20 74 6f 20 73 65 61 72 63 68   paths to search
1750: 20 77 65 20 63 61 6e 20 64 6f 20 6e 6f 74 68 69   we can do nothi
1760: 6e 67 2e 20 28 45 78 63 65 70 74 20 66 61 6c 6c  ng. (Except fall
1770: 69 6e 67 20 62 61 63 6b 0a 20 20 20 20 23 20 74  ing back.    # t
1780: 6f 20 74 68 65 20 72 65 67 75 6c 61 72 20 73 65  o the regular se
1790: 61 72 63 68 29 2e 0a 0a 20 20 20 20 69 66 20 7b  arch)...    if {
17a0: 5b 6c 6c 65 6e 67 74 68 20 24 70 61 74 68 73 5d  [llength $paths]
17b0: 7d 20 7b 0a 09 73 65 74 20 70 6b 67 70 61 74 68  } {..set pkgpath
17c0: 20 5b 73 74 72 69 6e 67 20 6d 61 70 20 7b 3a 3a   [string map {::
17d0: 20 2f 7d 20 24 6e 61 6d 65 5d 0a 09 73 65 74 20   /} $name]..set 
17e0: 70 6b 67 72 6f 6f 74 20 5b 66 69 6c 65 20 64 69  pkgroot [file di
17f0: 72 6e 61 6d 65 20 24 70 6b 67 70 61 74 68 5d 0a  rname $pkgpath].
1800: 09 69 66 20 7b 24 70 6b 67 72 6f 6f 74 20 65 71  .if {$pkgroot eq
1810: 20 22 2e 22 7d 20 7b 73 65 74 20 70 6b 67 72 6f   "."} {set pkgro
1820: 6f 74 20 22 22 7d 0a 0a 09 23 20 57 65 20 64 6f  ot ""}...# We do
1830: 6e 27 74 20 72 65 6d 65 6d 62 65 72 20 61 20 63  n't remember a c
1840: 6f 70 79 20 6f 66 20 74 68 65 20 70 61 74 68 73  opy of the paths
1850: 20 77 68 69 6c 65 20 6c 6f 6f 70 69 6e 67 2e 20   while looping. 
1860: 54 63 6c 0a 09 23 20 4d 6f 64 75 6c 65 73 20 61  Tcl..# Modules a
1870: 72 65 20 75 6e 61 62 6c 65 20 74 6f 20 63 68 61  re unable to cha
1880: 6e 67 65 20 74 68 65 20 6c 69 73 74 20 77 68 69  nge the list whi
1890: 6c 65 20 77 65 20 61 72 65 20 73 65 61 72 63 68  le we are search
18a0: 69 6e 67 0a 09 23 20 66 6f 72 20 74 68 65 6d 2e  ing..# for them.
18b0: 20 54 68 69 73 20 61 6c 73 6f 20 73 69 6d 70 6c   This also simpl
18c0: 69 66 69 65 73 20 74 68 65 20 6c 6f 6f 70 2c 20  ifies the loop, 
18d0: 61 73 20 77 65 20 63 61 6e 6e 6f 74 20 67 65 74  as we cannot get
18e0: 0a 09 23 20 61 64 64 69 74 69 6f 6e 61 6c 20 64  ..# additional d
18f0: 69 72 65 63 74 6f 72 69 65 73 20 77 68 69 6c 65  irectories while
1900: 20 69 74 65 72 61 74 69 6e 67 20 6f 76 65 72 20   iterating over 
1910: 74 68 65 20 6c 69 73 74 2e 20 41 0a 09 23 20 73  the list. A..# s
1920: 69 6d 70 6c 65 20 66 6f 72 65 61 63 68 20 69 73  imple foreach is
1930: 20 73 75 66 66 69 63 69 65 6e 74 2e 0a 0a 09 73   sufficient....s
1940: 65 74 20 73 61 74 69 73 66 69 65 64 20 30 0a 09  et satisfied 0..
1950: 66 6f 72 65 61 63 68 20 70 61 74 68 20 24 70 61  foreach path $pa
1960: 74 68 73 20 7b 0a 09 20 20 20 20 69 66 20 7b 21  ths {..    if {!
1970: 5b 66 69 6c 65 20 65 78 69 73 74 73 20 24 70 61  [file exists $pa
1980: 74 68 5d 7d 20 63 6f 6e 74 69 6e 75 65 0a 09 20  th]} continue.. 
1990: 20 20 20 73 65 74 20 63 75 72 72 65 6e 74 73 65     set currentse
19a0: 61 72 63 68 70 61 74 68 20 5b 66 69 6c 65 20 6a  archpath [file j
19b0: 6f 69 6e 20 24 70 61 74 68 20 24 70 6b 67 72 6f  oin $path $pkgro
19c0: 6f 74 5d 0a 09 20 20 20 20 69 66 20 7b 21 5b 66  ot]..    if {![f
19d0: 69 6c 65 20 65 78 69 73 74 73 20 24 63 75 72 72  ile exists $curr
19e0: 65 6e 74 73 65 61 72 63 68 70 61 74 68 5d 7d 20  entsearchpath]} 
19f0: 63 6f 6e 74 69 6e 75 65 0a 09 20 20 20 20 73 65  continue..    se
1a00: 74 20 73 74 72 69 70 20 20 20 20 20 20 20 20 20  t strip         
1a10: 20 20 20 20 5b 6c 6c 65 6e 67 74 68 20 5b 66 69      [llength [fi
1a20: 6c 65 20 73 70 6c 69 74 20 24 70 61 74 68 5d 5d  le split $path]]
1a30: 0a 0a 09 20 20 20 20 23 20 57 65 20 63 61 6e 27  ...    # We can'
1a40: 74 20 75 73 65 20 67 6c 6f 62 20 69 6e 20 73 61  t use glob in sa
1a50: 66 65 20 69 6e 74 65 72 70 73 2c 20 73 6f 20 65  fe interps, so e
1a60: 6e 63 6c 6f 73 65 20 74 68 65 20 66 6f 6c 6c 6f  nclose the follo
1a70: 77 69 6e 67 0a 09 20 20 20 20 23 20 69 6e 20 61  wing..    # in a
1a80: 20 63 61 74 63 68 20 73 74 61 74 65 6d 65 6e 74   catch statement
1a90: 2c 20 77 68 65 72 65 20 77 65 20 67 65 74 20 74  , where we get t
1aa0: 68 65 20 6d 6f 64 75 6c 65 20 66 69 6c 65 73 20  he module files 
1ab0: 6f 75 74 0a 09 20 20 20 20 23 20 6f 66 20 74 68  out..    # of th
1ac0: 65 20 73 75 62 64 69 72 65 63 74 6f 72 69 65 73  e subdirectories
1ad0: 2e 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73  . In other words
1ae0: 2c 20 54 63 6c 20 4d 6f 64 75 6c 65 73 20 61 72  , Tcl Modules ar
1af0: 65 0a 09 20 20 20 20 23 20 6e 6f 74 2d 66 75 6e  e..    # not-fun
1b00: 63 74 69 6f 6e 61 6c 20 69 6e 20 73 75 63 68 20  ctional in such 
1b10: 61 6e 20 69 6e 74 65 72 70 72 65 74 65 72 2e 20  an interpreter. 
1b20: 54 68 69 73 20 69 73 20 74 68 65 20 73 61 6d 65  This is the same
1b30: 0a 09 20 20 20 20 23 20 61 73 20 66 6f 72 20 74  ..    # as for t
1b40: 68 65 20 63 6f 6d 6d 61 6e 64 20 22 74 63 6c 50  he command "tclP
1b50: 6b 67 55 6e 6b 6e 6f 77 6e 22 2c 20 69 2e 65 2e  kgUnknown", i.e.
1b60: 20 74 68 65 20 73 65 61 72 63 68 20 66 6f 72 0a   the search for.
1b70: 09 20 20 20 20 23 20 72 65 67 75 6c 61 72 20 70  .    # regular p
1b80: 61 63 6b 61 67 65 73 2e 0a 0a 09 20 20 20 20 63  ackages....    c
1b90: 61 74 63 68 20 7b 0a 09 09 23 20 57 65 20 61 6c  atch {...# We al
1ba0: 77 61 79 73 20 6c 6f 6f 6b 20 66 6f 72 20 5f 61  ways look for _a
1bb0: 6c 6c 5f 20 70 6f 73 73 69 62 6c 65 20 6d 6f 64  ll_ possible mod
1bc0: 75 6c 65 73 20 69 6e 20 74 68 65 20 63 75 72 72  ules in the curr
1bd0: 65 6e 74 0a 09 09 23 20 70 61 74 68 2c 20 74 6f  ent...# path, to
1be0: 20 67 65 74 20 74 68 65 20 6d 61 78 20 72 65 73   get the max res
1bf0: 75 6c 74 20 6f 75 74 20 6f 66 20 74 68 65 20 67  ult out of the g
1c00: 6c 6f 62 2e 0a 0a 09 09 66 6f 72 65 61 63 68 20  lob.....foreach 
1c10: 66 69 6c 65 20 5b 67 6c 6f 62 20 2d 6e 6f 63 6f  file [glob -noco
1c20: 6d 70 6c 61 69 6e 20 2d 64 69 72 65 63 74 6f 72  mplain -director
1c30: 79 20 24 63 75 72 72 65 6e 74 73 65 61 72 63 68  y $currentsearch
1c40: 70 61 74 68 20 2a 2e 74 6d 5d 20 7b 0a 09 09 20  path *.tm] {... 
1c50: 20 20 20 73 65 74 20 70 6b 67 66 69 6c 65 6e 61     set pkgfilena
1c60: 6d 65 20 5b 6a 6f 69 6e 20 5b 6c 72 61 6e 67 65  me [join [lrange
1c70: 20 5b 66 69 6c 65 20 73 70 6c 69 74 20 24 66 69   [file split $fi
1c80: 6c 65 5d 20 24 73 74 72 69 70 20 65 6e 64 5d 20  le] $strip end] 
1c90: 3a 3a 5d 0a 0a 09 09 20 20 20 20 69 66 20 7b 21  ::]....    if {!
1ca0: 5b 72 65 67 65 78 70 20 2d 2d 20 24 70 6b 67 70  [regexp -- $pkgp
1cb0: 61 74 74 65 72 6e 20 24 70 6b 67 66 69 6c 65 6e  attern $pkgfilen
1cc0: 61 6d 65 20 2d 2d 3e 20 70 6b 67 6e 61 6d 65 20  ame --> pkgname 
1cd0: 70 6b 67 76 65 72 73 69 6f 6e 5d 7d 20 7b 0a 09  pkgversion]} {..
1ce0: 09 09 23 20 49 67 6e 6f 72 65 20 65 76 65 72 79  ..# Ignore every
1cf0: 74 68 69 6e 67 20 6e 6f 74 20 6d 61 74 63 68 69  thing not matchi
1d00: 6e 67 20 6f 75 72 20 70 61 74 74 65 72 6e 0a 09  ng our pattern..
1d10: 09 09 23 20 66 6f 72 20 70 61 63 6b 61 67 65 20  ..# for package 
1d20: 6e 61 6d 65 73 2e 0a 09 09 09 63 6f 6e 74 69 6e  names.....contin
1d30: 75 65 0a 09 09 20 20 20 20 7d 0a 09 09 20 20 20  ue...    }...   
1d40: 20 69 66 20 7b 5b 63 61 74 63 68 20 7b 70 61 63   if {[catch {pac
1d50: 6b 61 67 65 20 76 63 6f 6d 70 61 72 65 20 24 70  kage vcompare $p
1d60: 6b 67 76 65 72 73 69 6f 6e 20 30 7d 5d 7d 20 7b  kgversion 0}]} {
1d70: 0a 09 09 09 23 20 49 67 6e 6f 72 65 20 65 76 65  ....# Ignore eve
1d80: 72 79 74 68 69 6e 67 20 77 68 65 72 65 20 74 68  rything where th
1d90: 65 20 76 65 72 73 69 6f 6e 20 70 61 72 74 20 69  e version part i
1da0: 73 0a 09 09 09 23 20 6e 6f 74 20 61 63 63 65 70  s....# not accep
1db0: 74 61 62 6c 65 20 74 6f 20 22 70 61 63 6b 61 67  table to "packag
1dc0: 65 20 76 63 6f 6d 70 61 72 65 22 2e 0a 09 09 09  e vcompare".....
1dd0: 63 6f 6e 74 69 6e 75 65 0a 09 09 20 20 20 20 7d  continue...    }
1de0: 0a 0a 09 09 20 20 20 20 23 20 57 65 20 68 61 76  ....    # We hav
1df0: 65 20 66 6f 75 6e 64 20 61 20 63 61 6e 64 69 64  e found a candid
1e00: 61 74 65 2c 20 67 65 6e 65 72 61 74 65 20 61 20  ate, generate a 
1e10: 22 70 72 6f 76 69 64 65 0a 09 09 20 20 20 20 23  "provide...    #
1e20: 20 73 63 72 69 70 74 22 20 66 6f 72 20 69 74 2c   script" for it,
1e30: 20 61 6e 64 20 72 65 6d 65 6d 62 65 72 20 69 74   and remember it
1e40: 2e 0a 0a 09 09 20 20 20 20 70 61 63 6b 61 67 65  .....    package
1e50: 20 69 66 6e 65 65 64 65 64 20 24 70 6b 67 6e 61   ifneeded $pkgna
1e60: 6d 65 20 24 70 6b 67 76 65 72 73 69 6f 6e 20 5b  me $pkgversion [
1e70: 6c 69 73 74 20 73 6f 75 72 63 65 20 24 66 69 6c  list source $fil
1e80: 65 5d 0a 0a 09 09 20 20 20 20 23 20 57 65 20 61  e]....    # We a
1e90: 62 6f 72 74 20 69 6e 20 74 68 69 73 20 75 6e 6b  bort in this unk
1ea0: 6e 6f 77 6e 20 68 61 6e 64 6c 65 72 20 6f 6e 6c  nown handler onl
1eb0: 79 20 69 66 20 77 65 20 67 6f 74 0a 09 09 20 20  y if we got...  
1ec0: 20 20 23 20 61 20 73 61 74 69 73 66 79 69 6e 67    # a satisfying
1ed0: 20 63 61 6e 64 69 64 61 74 65 20 66 6f 72 20 74   candidate for t
1ee0: 68 65 20 72 65 71 75 65 73 74 65 64 0a 09 09 20  he requested... 
1ef0: 20 20 20 23 20 70 61 63 6b 61 67 65 2e 20 4f 74     # package. Ot
1f00: 68 65 72 77 69 73 65 20 77 65 20 73 74 69 6c 6c  herwise we still
1f10: 20 68 61 76 65 20 74 6f 20 66 61 6c 6c 62 61 63   have to fallbac
1f20: 6b 20 74 6f 0a 09 09 20 20 20 20 23 20 74 68 65  k to...    # the
1f30: 20 72 65 67 75 6c 61 72 20 70 61 63 6b 61 67 65   regular package
1f40: 20 73 65 61 72 63 68 20 74 6f 20 63 6f 6d 70 6c   search to compl
1f50: 65 74 65 20 74 68 65 0a 09 09 20 20 20 20 23 20  ete the...    # 
1f60: 70 72 6f 63 65 73 73 69 6e 67 2e 0a 0a 09 09 20  processing..... 
1f70: 20 20 20 69 66 20 7b 0a 09 09 09 28 24 70 6b 67     if {....($pkg
1f80: 6e 61 6d 65 20 65 71 20 24 6e 61 6d 65 29 20 26  name eq $name) &
1f90: 26 0a 09 09 09 28 28 28 24 65 78 61 63 74 20 65  &....((($exact e
1fa0: 71 20 22 2d 65 78 61 63 74 22 29 20 26 26 20 28  q "-exact") && (
1fb0: 30 3d 3d 5b 70 61 63 6b 61 67 65 20 76 63 6f 6d  0==[package vcom
1fc0: 70 61 72 65 20 24 70 6b 67 76 65 72 73 69 6f 6e  pare $pkgversion
1fd0: 20 24 76 65 72 73 69 6f 6e 5d 29 29 20 7c 7c 0a   $version])) ||.
1fe0: 09 09 09 28 28 24 76 65 72 73 69 6f 6e 20 6e 65  ...(($version ne
1ff0: 20 22 22 29 20 26 26 20 5b 70 61 63 6b 61 67 65   "") && [package
2000: 20 76 73 61 74 69 73 66 69 65 73 20 24 70 6b 67   vsatisfies $pkg
2010: 76 65 72 73 69 6f 6e 20 24 76 65 72 73 69 6f 6e  version $version
2020: 5d 29 20 7c 7c 0a 09 09 09 28 24 76 65 72 73 69  ]) ||....($versi
2030: 6f 6e 20 65 71 20 22 22 29 29 0a 09 09 20 20 20  on eq ""))...   
2040: 20 7d 20 7b 0a 09 09 09 73 65 74 20 73 61 74 69   } {....set sati
2050: 73 66 69 65 64 20 31 0a 09 09 09 23 20 57 65 20  sfied 1....# We 
2060: 64 6f 20 6e 6f 74 20 61 62 6f 72 74 20 74 68 65  do not abort the
2070: 20 6c 6f 6f 70 2c 20 61 6e 64 20 6b 65 65 70 20   loop, and keep 
2080: 61 64 64 69 6e 67 0a 09 09 09 23 20 70 72 6f 76  adding....# prov
2090: 69 64 65 20 73 63 72 69 70 74 73 20 66 6f 72 20  ide scripts for 
20a0: 65 76 65 72 79 20 63 61 6e 64 69 64 61 74 65 20  every candidate 
20b0: 69 6e 20 74 68 65 0a 09 09 09 23 20 64 69 72 65  in the....# dire
20c0: 63 74 6f 72 79 2c 20 6a 75 73 74 20 72 65 6d 65  ctory, just reme
20d0: 6d 62 65 72 20 74 6f 20 6e 6f 74 20 66 61 6c 6c  mber to not fall
20e0: 20 62 61 63 6b 20 74 6f 0a 09 09 09 23 20 74 68   back to....# th
20f0: 65 20 72 65 67 75 6c 61 72 20 73 65 61 72 63 68  e regular search
2100: 20 61 6e 79 6d 6f 72 65 2e 0a 09 09 20 20 20 20   anymore....    
2110: 7d 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a  }...}..    }..}.
2120: 0a 09 69 66 20 7b 24 73 61 74 69 73 66 69 65 64  ..if {$satisfied
2130: 7d 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e 0a  } {..    return.
2140: 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 23 20  .}.    }..    # 
2150: 46 61 6c 6c 62 61 63 6b 20 74 6f 20 70 72 65 76  Fallback to prev
2160: 69 6f 75 73 20 63 6f 6d 6d 61 6e 64 2c 20 69 66  ious command, if
2170: 20 65 78 69 73 74 69 6e 67 2e 0a 20 20 20 20 69   existing..    i
2180: 66 20 7b 5b 6c 6c 65 6e 67 74 68 20 24 6f 72 69  f {[llength $ori
2190: 67 69 6e 61 6c 5d 7d 20 7b 0a 09 75 70 6c 65 76  ginal]} {..uplev
21a0: 65 6c 20 31 20 24 6f 72 69 67 69 6e 61 6c 20 5b  el 1 $original [
21b0: 6c 69 73 74 20 24 6e 61 6d 65 20 24 76 65 72 73  list $name $vers
21c0: 69 6f 6e 20 24 65 78 61 63 74 5d 0a 20 20 20 20  ion $exact].    
21d0: 7d 0a 7d 0a 0a 23 20 3a 3a 74 63 6c 3a 3a 74 6d  }.}..# ::tcl::tm
21e0: 3a 3a 44 65 66 61 75 6c 74 73 20 2d 2d 0a 23 0a  ::Defaults --.#.
21f0: 23 09 44 65 74 65 72 6d 69 6e 65 73 20 74 68 65  #.Determines the
2200: 20 64 65 66 61 75 6c 74 20 73 65 61 72 63 68 20   default search 
2210: 70 61 74 68 73 2e 0a 23 0a 23 20 41 72 67 75 6d  paths..#.# Argum
2220: 65 6e 74 73 0a 23 09 4e 6f 6e 65 0a 23 0a 23 20  ents.#.None.#.# 
2230: 52 65 73 75 6c 74 73 0a 23 09 4e 6f 6e 65 2e 0a  Results.#.None..
2240: 23 0a 23 20 53 69 64 65 65 66 66 65 63 74 73 0a  #.# Sideeffects.
2250: 23 09 4d 61 79 20 61 64 64 20 70 61 74 68 73 20  #.May add paths 
2260: 74 6f 20 74 68 65 20 6c 69 73 74 20 6f 66 20 64  to the list of d
2270: 65 66 61 75 6c 74 73 2e 0a 0a 70 72 6f 63 20 3a  efaults...proc :
2280: 3a 74 63 6c 3a 3a 74 6d 3a 3a 44 65 66 61 75 6c  :tcl::tm::Defaul
2290: 74 73 20 7b 7d 20 7b 0a 20 20 20 20 66 6f 72 65  ts {} {.    fore
22a0: 61 63 68 20 7b 6d 61 6a 6f 72 20 6d 69 6e 6f 72  ach {major minor
22b0: 7d 20 5b 73 70 6c 69 74 20 5b 69 6e 66 6f 20 74  } [split [info t
22c0: 63 6c 76 65 72 73 69 6f 6e 5d 20 2e 5d 20 62 72  clversion] .] br
22d0: 65 61 6b 0a 0a 20 20 20 20 72 6f 6f 74 73 20 5b  eak..    roots [
22e0: 6c 69 73 74 20 5c 0a 09 20 20 20 20 5b 66 69 6c  list \..    [fil
22f0: 65 20 64 69 72 6e 61 6d 65 20 5b 69 6e 66 6f 20  e dirname [info 
2300: 6c 69 62 72 61 72 79 5d 5d 20 5c 0a 09 20 20 20  library]] \..   
2310: 20 5b 66 69 6c 65 20 6a 6f 69 6e 20 5b 66 69 6c   [file join [fil
2320: 65 20 64 69 72 6e 61 6d 65 20 5b 66 69 6c 65 20  e dirname [file 
2330: 6e 6f 72 6d 61 6c 69 7a 65 20 5b 69 6e 66 6f 20  normalize [info 
2340: 6e 61 6d 65 6f 66 65 78 65 63 75 74 61 62 6c 65  nameofexecutable
2350: 5d 5d 5d 20 6c 69 62 5d 20 5c 0a 09 20 20 20 20  ]]] lib] \..    
2360: 5d 0a 0a 20 20 20 20 69 66 20 7b 24 3a 3a 74 63  ]..    if {$::tc
2370: 6c 5f 70 6c 61 74 66 6f 72 6d 28 70 6c 61 74 66  l_platform(platf
2380: 6f 72 6d 29 20 65 71 20 22 77 69 6e 64 6f 77 73  orm) eq "windows
2390: 22 7d 20 7b 0a 09 73 65 74 20 73 65 70 20 5c 3b  "} {..set sep \;
23a0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 73  .    } else {..s
23b0: 65 74 20 73 65 70 20 3a 0a 20 20 20 20 7d 0a 20  et sep :.    }. 
23c0: 20 20 20 66 6f 72 20 7b 73 65 74 20 6e 20 24 6d     for {set n $m
23d0: 69 6e 6f 72 7d 20 7b 24 6e 20 3e 3d 20 30 7d 20  inor} {$n >= 0} 
23e0: 7b 69 6e 63 72 20 6e 20 2d 31 7d 20 7b 0a 09 73  {incr n -1} {..s
23f0: 65 74 20 65 76 20 54 43 4c 24 7b 6d 61 6a 6f 72  et ev TCL${major
2400: 7d 2e 7b 24 6e 7d 5f 54 4d 5f 50 41 54 48 0a 09  }.{$n}_TM_PATH..
2410: 69 66 20 7b 5b 69 6e 66 6f 20 65 78 69 73 74 73  if {[info exists
2420: 20 3a 3a 65 6e 76 28 24 65 76 29 5d 7d 20 7b 0a   ::env($ev)]} {.
2430: 09 20 20 20 20 66 6f 72 65 61 63 68 20 70 20 5b  .    foreach p [
2440: 73 70 6c 69 74 20 24 3a 3a 65 6e 76 28 24 65 76  split $::env($ev
2450: 29 20 24 73 65 70 5d 20 7b 0a 09 09 70 61 74 68  ) $sep] {...path
2460: 20 61 64 64 20 24 70 0a 09 20 20 20 20 7d 0a 09   add $p..    }..
2470: 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75  }.    }.    retu
2480: 72 6e 0a 7d 0a 0a 23 20 3a 3a 74 63 6c 3a 3a 74  rn.}..# ::tcl::t
2490: 6d 3a 3a 72 6f 6f 74 73 20 2d 2d 0a 23 0a 23 09  m::roots --.#.#.
24a0: 50 75 62 6c 69 63 20 41 50 49 20 74 6f 20 74 68  Public API to th
24b0: 65 20 6d 6f 64 75 6c 65 20 70 61 74 68 2e 20 53  e module path. S
24c0: 65 65 20 73 70 65 63 69 66 69 63 61 74 69 6f 6e  ee specification
24d0: 2e 0a 23 0a 23 20 41 72 67 75 6d 65 6e 74 73 0a  ..#.# Arguments.
24e0: 23 09 70 61 74 68 73 20 2d 09 4c 69 73 74 20 6f  #.paths -.List o
24f0: 66 20 27 72 6f 6f 74 27 20 70 61 74 68 73 20 74  f 'root' paths t
2500: 6f 20 64 65 72 69 76 65 20 73 65 61 72 63 68 20  o derive search 
2510: 70 61 74 68 73 20 66 72 6f 6d 2e 0a 23 0a 23 20  paths from..#.# 
2520: 52 65 73 75 6c 74 73 0a 23 09 4e 6f 20 72 65 73  Results.#.No res
2530: 75 6c 74 2e 0a 23 0a 23 20 53 69 64 65 65 66 66  ult..#.# Sideeff
2540: 65 63 74 73 0a 23 09 43 61 6c 6c 73 20 27 70 61  ects.#.Calls 'pa
2550: 74 68 20 61 64 64 27 20 74 6f 20 70 61 74 68 73  th add' to paths
2560: 20 74 6f 20 74 68 65 20 6c 69 73 74 20 6f 66 20   to the list of 
2570: 6d 6f 64 75 6c 65 20 73 65 61 72 63 68 20 70 61  module search pa
2580: 74 68 73 2e 0a 0a 70 72 6f 63 20 3a 3a 74 63 6c  ths...proc ::tcl
2590: 3a 3a 74 6d 3a 3a 72 6f 6f 74 73 20 7b 70 61 74  ::tm::roots {pat
25a0: 68 73 7d 20 7b 0a 20 20 20 20 66 6f 72 65 61 63  hs} {.    foreac
25b0: 68 20 7b 6d 61 6a 6f 72 20 6d 69 6e 6f 72 7d 20  h {major minor} 
25c0: 5b 73 70 6c 69 74 20 5b 69 6e 66 6f 20 74 63 6c  [split [info tcl
25d0: 76 65 72 73 69 6f 6e 5d 20 2e 5d 20 62 72 65 61  version] .] brea
25e0: 6b 0a 20 20 20 20 66 6f 72 65 61 63 68 20 70 20  k.    foreach p 
25f0: 24 70 61 20 7b 0a 09 73 65 74 20 70 20 5b 66 69  $pa {..set p [fi
2600: 6c 65 20 6a 6f 69 6e 20 24 70 20 74 63 6c 24 6d  le join $p tcl$m
2610: 61 6a 6f 72 5d 0a 09 66 6f 72 20 7b 73 65 74 20  ajor]..for {set 
2620: 6e 20 24 6d 69 6e 6f 72 7d 20 7b 24 6e 20 3e 3d  n $minor} {$n >=
2630: 20 30 7d 20 7b 69 6e 63 72 20 6e 20 2d 31 7d 20   0} {incr n -1} 
2640: 7b 0a 09 20 20 20 20 70 61 74 68 20 61 64 64 20  {..    path add 
2650: 5b 66 69 6c 65 20 6e 6f 72 6d 61 6c 69 7a 65 20  [file normalize 
2660: 5b 66 69 6c 65 20 6a 6f 69 6e 20 24 70 20 24 7b  [file join $p ${
2670: 6d 61 6a 6f 72 7d 2e 24 7b 6e 7d 5d 5d 0a 09 7d  major}.${n}]]..}
2680: 0a 09 70 61 74 68 20 61 64 64 20 5b 66 69 6c 65  ..path add [file
2690: 20 6e 6f 72 6d 61 6c 69 7a 65 20 5b 66 69 6c 65   normalize [file
26a0: 20 6a 6f 69 6e 20 24 70 20 73 69 74 65 2d 74 63   join $p site-tc
26b0: 6c 5d 5d 0a 20 20 20 20 7d 0a 20 20 20 20 72 65  l]].    }.    re
26c0: 74 75 72 6e 0a 7d 0a 0a 23 20 49 6e 69 74 69 61  turn.}..# Initia
26d0: 6c 69 7a 61 74 69 6f 6e 2e 20 53 65 74 20 75 70  lization. Set up
26e0: 20 74 68 65 20 64 65 66 61 75 6c 74 20 70 61 74   the default pat
26f0: 68 73 2c 20 74 68 65 6e 20 69 6e 73 65 72 74 20  hs, then insert 
2700: 74 68 65 20 6e 65 77 0a 23 20 68 61 6e 64 6c 65  the new.# handle
2710: 72 20 69 6e 74 6f 20 74 68 65 20 63 68 61 69 6e  r into the chain
2720: 2e 0a 0a 3a 3a 74 63 6c 3a 3a 74 6d 3a 3a 44 65  ...::tcl::tm::De
2730: 66 61 75 6c 74 73 0a 70 61 63 6b 61 67 65 20 75  faults.package u
2740: 6e 6b 6e 6f 77 6e 20 5b 6c 69 73 74 20 3a 3a 74  nknown [list ::t
2750: 63 6c 3a 3a 74 6d 3a 3a 75 6e 6b 6e 6f 77 6e 20  cl::tm::unknown 
2760: 5b 70 61 63 6b 61 67 65 20 75 6e 6b 6e 6f 77 6e  [package unknown
2770: 5d 5d 0a                                         ]].