Check-in [2c40fcc696]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com or submit via the online form
by Aug 20.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Macro'd out the source decrypt function. It's stupid to leave it in there Moved the loading of the VFS package manifest until after the interp has initialized. The problem is that windows needs the encodings for source to work on arbitrary files. Injected some puts statements to debug package loading. We now work on Windows, let's see if I broke Mac
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2c40fcc6961801817c052fde92f46d1a0edd2d63
User & Date: hypnotoad 2016-03-01 20:07:53
Context
2016-03-01
20:11
Removed chatty puts statements injected for debugging check-in: faad732680 user: hypnotoad tags: trunk
20:07
Macro'd out the source decrypt function. It's stupid to leave it in there Moved the loading of the VFS package manifest until after the interp has initialized. The problem is that windows needs the encodings for source to work on arbitrary files. Injected some puts statements to debug package loading. We now work on Windows, let's see if I broke Mac check-in: 2c40fcc696 user: hypnotoad tags: trunk
18:13
Closing the gort branch check-in: 02f5a924cb user: hypnotoad tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to build.tcl.
134
135
136
137
138
139
140










141
142
143
144
145
146
147
148
149
150


151
152
153
154
155
156
157

158
159
160
161

162

163
164
165
166

167
168
169
170
171
172
173
    } finally {
      set thisline {}
    }
  }
  return $buffer
}











###
# Index all paths given as though they will end up in the same
# virtual file system
###
proc ::practcl::pkgindex_path args {
  set stack {}
  set buffer {
lappend ::PATHSTACK $dir
  }
  foreach base $args {


    set i    [string length  $base]
    # Build a list of all of the paths
    set paths [fileutil::find $base ::practcl::_isdirectory]
    foreach path $paths {
      if {$path eq $base} continue
      set path_indexed($path) 0
    }

    set path_index([file join $base boot tcl]) 1
    set path_index([file join $base boot tk]) 1
  
    foreach path $paths {

      set thisdir [::fileutil::relative $base $path]

      set idxbuf [::practcl::_pkgindex_directory $path]
      if {[string length $idxbuf]} {
        incr path_indexed($path)
        append buffer "set dir \[file join \[lindex \$::PATHSTACK end\] $thisdir\]" \n

        append buffer [string trimright $idxbuf] \n
      } 
    }
  }
  append buffer {
set dir [lindex $::PATHSTACK end]  
set ::PATHSTACK [lrange $::PATHSTACK 0 end-1]







>
>
>
>
>
>
>
>
>
>










>
>


<




>
|
|


>
|
>




>







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    } finally {
      set thisline {}
    }
  }
  return $buffer
}


proc ::practcl::_pkgindex_path_subdir {path} {
  set result {}
  foreach subpath [glob -nocomplain [file join $path *]] {
    if {[file isdirectory $subpath]} {
      lappend result $subpath {*}[_pkgindex_path_subdir $subpath]
    }
  }
  return $result
}
###
# Index all paths given as though they will end up in the same
# virtual file system
###
proc ::practcl::pkgindex_path args {
  set stack {}
  set buffer {
lappend ::PATHSTACK $dir
  }
  foreach base $args {
    set base [file normalize $base]
    set paths [::practcl::_pkgindex_path_subdir $base]
    set i    [string length  $base]
    # Build a list of all of the paths

    foreach path $paths {
      if {$path eq $base} continue
      set path_indexed($path) 0
    }
    set path_indexed($base) 1
    set path_indexed([file join $base boot tcl]) 1
    #set path_index([file join $base boot tk]) 1
  
    foreach path $paths {
      if {$path_indexed($path)} continue
      #set thisdir [::fileutil::relative $base $path]
      set thisdir [string range $path $i+1 end]
      set idxbuf [::practcl::_pkgindex_directory $path]
      if {[string length $idxbuf]} {
        incr path_indexed($path)
        append buffer "set dir \[file join \[lindex \$::PATHSTACK end\] $thisdir\]" \n
        append buffer "puts \"INDEXED \$dir\"" \n
        append buffer [string trimright $idxbuf] \n
      } 
    }
  }
  append buffer {
set dir [lindex $::PATHSTACK end]  
set ::PATHSTACK [lrange $::PATHSTACK 0 end-1]
243
244
245
246
247
248
249

250


251
252


253
254

255
256
257
258

259

260
261
262
263
264
265
266
proc ::practcl::wrap {PWD name vfspath args} {
  cd $PWD
  if {![file exists $vfspath]} {
    file mkdir $vfspath
  }
  package ifneeded zipfile::mkzip 1.2 [list source [file join $::HERE scripts mkzip.tcl]]
  package require zipfile::mkzip

  set fout [open [file join $vfspath packages.tcl] w]


  set buffer [::practcl::pkgindex_path $::KIT(BASEVFS) $vfspath]
  puts $fout $buffer


  close $fout
  copyDir $::KIT(BASEVFS) $vfspath

  foreach arg $args {
     copyDir $arg $vfspath
  }
  ::zipfile::mkzip::mkzip ${name}$::KIT(EXEEXT) -runtime $::TARGET(tclkit_bare) -directory $vfspath

  file attributes ${name}$::KIT(EXEEXT) -permissions a+x

}

#########################################
#
# BUILD THE INTERPRETER ENVIRONMENT
#
#########################################







>

>
>


>
>


>




>
|
>







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
proc ::practcl::wrap {PWD name vfspath args} {
  cd $PWD
  if {![file exists $vfspath]} {
    file mkdir $vfspath
  }
  package ifneeded zipfile::mkzip 1.2 [list source [file join $::HERE scripts mkzip.tcl]]
  package require zipfile::mkzip

  set fout [open [file join $vfspath packages.tcl] w]
  puts $fout "puts {LOADING VFS PACKAGE MANIFEST}"
  puts $fout [list set dir $::KIT(PKGPREFIX)]
  set buffer [::practcl::pkgindex_path $::KIT(BASEVFS) $vfspath]
  puts $fout $buffer
  puts $fout "puts {/LOADING VFS PACKAGE MANIFEST}"

  close $fout
  copyDir $::KIT(BASEVFS) $vfspath
  copyDir $::KIT(PKGROOT)$::KIT(PKGPREFIX)/lib $vfspath/boot/pkgs
  foreach arg $args {
     copyDir $arg $vfspath
  }
  ::zipfile::mkzip::mkzip ${name}$::KIT(EXEEXT) -runtime $::TARGET(tclkit_bare) -directory $vfspath
  if { $::KIT(platform) ne "windows" } {
    file attributes ${name}$::KIT(EXEEXT) -permissions a+x
  }
}

#########################################
#
# BUILD THE INTERPRETER ENVIRONMENT
#
#########################################
738
739
740
741
742
743
744
745
746
747
748
749
750
751
  }
  puts $fout [string map $map {
package ifneeded Tk @TKVERSION@ [list load $::tk_library/@TKDLL@ Tk]
  }]
  close $fout
}
if {$COMMAND eq "toadkit"} {
  ::practcl::wrap $::PWD toadkit toadkit-vfs
}

if {$COMMAND eq "wrap"} {
  puts "WRAP {*}[lrange $argv 1 end]"
  ::practcl::wrap $::PWD {*}[lrange $argv 1 end]
}







|






761
762
763
764
765
766
767
768
769
770
771
772
773
774
  }
  puts $fout [string map $map {
package ifneeded Tk @TKVERSION@ [list load $::tk_library/@TKDLL@ Tk]
  }]
  close $fout
}
if {$COMMAND eq "toadkit"} {
  ::practcl::wrap $::PWD toadkit toadkit-vfs 
}

if {$COMMAND eq "wrap"} {
  puts "WRAP {*}[lrange $argv 1 end]"
  ::practcl::wrap $::PWD {*}[lrange $argv 1 end]
}
Changes to generic/rc4.c.
387
388
389
390
391
392
393

394
395
396
397
398
399
400
  zOut = encode64(zBuf, nIn+4, &nOut);
  Tcl_SetObjResult(interp, Tcl_NewStringObj(zOut, nOut));
  Tcl_Free((char *)zOut);
  Tcl_Free((char *)zBuf);
  return TCL_OK;
}


/*
** Usage:   source_decrypt   CYPHERTEXT
**
** Decrypt CYPHERTEXT using compiled in PASSWORD and a nonce
** found at the beginning of
** the cyphertext.  The cyphertext is base64 encoded.
*/







>







387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
  zOut = encode64(zBuf, nIn+4, &nOut);
  Tcl_SetObjResult(interp, Tcl_NewStringObj(zOut, nOut));
  Tcl_Free((char *)zOut);
  Tcl_Free((char *)zBuf);
  return TCL_OK;
}

#ifdef never
/*
** Usage:   source_decrypt   CYPHERTEXT
**
** Decrypt CYPHERTEXT using compiled in PASSWORD and a nonce
** found at the beginning of
** the cyphertext.  The cyphertext is base64 encoded.
*/
430
431
432
433
434
435
436

437
438
439
440
441
442
443
  memcpy(&zKey[4], zPasswd, nPasswd);
  rc4_init(&codec, nPasswd+4, (unsigned char*)zKey);
  rc4_coder(&codec, nOut-4, (unsigned char*)&zOut[4]);
  Tcl_SetObjResult(interp, Tcl_NewStringObj(&zOut[4], nOut-4));
  Tcl_Free(zOut);
  return TCL_OK;
}


/*
** Usage:   eval_decrypt   CYPHERTEXT
**
** Decrypt CYPHERTEXT using compiled in PASSWORD and a nonce
** found at the beginning of
** the cyphertext.  The cyphertext is base64 encoded.







>







431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
  memcpy(&zKey[4], zPasswd, nPasswd);
  rc4_init(&codec, nPasswd+4, (unsigned char*)zKey);
  rc4_coder(&codec, nOut-4, (unsigned char*)&zOut[4]);
  Tcl_SetObjResult(interp, Tcl_NewStringObj(&zOut[4], nOut-4));
  Tcl_Free(zOut);
  return TCL_OK;
}
#endif

/*
** Usage:   eval_decrypt   CYPHERTEXT
**
** Decrypt CYPHERTEXT using compiled in PASSWORD and a nonce
** found at the beginning of
** the cyphertext.  The cyphertext is base64 encoded.
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489
    return TCL_OK;
  }
  memcpy(zKey, zOut, 4);
  if( nPasswd>252 ) nPasswd = 252;
  memcpy(&zKey[4], zPasswd, nPasswd);
  rc4_init(&codec, nPasswd+4, (unsigned char*)zKey);
  rc4_coder(&codec, nOut-4, (unsigned char*)&zOut[4]);

  cleartext=Tcl_NewStringObj(&zOut[4], nOut-4);
  Tcl_IncrRefCount(cleartext);
  code=Tcl_EvalObjEx(interp,cleartext,NULL);
  Tcl_DecrRefCount(cleartext);
  Tcl_Free(zOut);
  return code;
}

/*
** Initialize the rc4 codec subsystem.
*/







>
|
|
|
|







474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
    return TCL_OK;
  }
  memcpy(zKey, zOut, 4);
  if( nPasswd>252 ) nPasswd = 252;
  memcpy(&zKey[4], zPasswd, nPasswd);
  rc4_init(&codec, nPasswd+4, (unsigned char*)zKey);
  rc4_coder(&codec, nOut-4, (unsigned char*)&zOut[4]);
  code=Tcl_Eval(interp,&zOut[4]);
  //cleartext=Tcl_NewStringObj(&zOut[4], nOut-4);
  //Tcl_IncrRefCount(cleartext);
  //code=Tcl_EvalObj(interp,cleartext);
  //Tcl_DecrRefCount(cleartext);
  Tcl_Free(zOut);
  return code;
}

/*
** Initialize the rc4 codec subsystem.
*/
Changes to generic/tclkit_init.c.
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51








52
53
54
55
56
57
58
59
 * Side effects:
 *	Depends on the startup script.
 *
 *----------------------------------------------------------------------
 */

int Toadkit_AppInit(Tcl_Interp *interp) {

  if ((Tcl_Init)(interp) == TCL_ERROR) {
      return TCL_ERROR;
  }

  /*
  * Start up all extensions.
  */
  Tclkit_Packages_Init(interp);
  /*
   * Call Tcl_CreateCommand for application-specific commands, if
   * they weren't already created by the init procedures called above.
   */









  /*
   * Specify a user-specific startup file to invoke if the application
   * is run interactively.  Typically the startup file is "~/.apprc"
   * where "app" is the name of the application.  If this line is deleted
   * then no user-specific startup file will be run under any conditions.
   */
  Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);







>












>
>
>
>
>
>
>
>
|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 * Side effects:
 *	Depends on the startup script.
 *
 *----------------------------------------------------------------------
 */

int Toadkit_AppInit(Tcl_Interp *interp) {

  if ((Tcl_Init)(interp) == TCL_ERROR) {
      return TCL_ERROR;
  }

  /*
  * Start up all extensions.
  */
  Tclkit_Packages_Init(interp);
  /*
   * Call Tcl_CreateCommand for application-specific commands, if
   * they weren't already created by the init procedures called above.
   */
  Tcl_Eval(interp,
"puts {Hello World!}"
"\nif {[file exists [file join $::SRCDIR packages.tcl]]} {"         
"\n  #In a wrapped exe, we don't go out to the environment"
"\n  set dir $::SRCDIR"
"\n  source [file join $::SRCDIR packages.tcl]"
"\n}"
  );
   
  /*
   * Specify a user-specific startup file to invoke if the application
   * is run interactively.  Typically the startup file is "~/.apprc"
   * where "app" is the name of the application.  If this line is deleted
   * then no user-specific startup file will be run under any conditions.
   */
  Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
Changes to generic/zvfsboot.c.
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
        Tcl_DStringAppendElement(&preinit,Tcl_GetString(vfstcllib));
        Tcl_DStringAppend(&preinit,"\nset auto_path {}",-1);
      }
      if(Tcl_FSAccess(vfstklib,F_OK)==0) {
        Tcl_DStringAppend(&preinit,"\nset tk_library ",-1);
        Tcl_DStringAppendElement(&preinit,Tcl_GetString(vfstklib));
      }

      Tcl_DStringAppend(&preinit,"\nif {[file exists [file join $::SRCDIR packages.tcl]]} \{",-1);
      Tcl_DStringAppend(&preinit,"\n  #In a wrapped exe, we don't go out to the environment",-1);
      Tcl_DStringAppend(&preinit,"\n  set auto_path {}",-1);
      Tcl_DStringAppend(&preinit,"\n  set dir $::SRCDIR",-1);
      Tcl_DStringAppend(&preinit,"\n  source [file join $::SRCDIR packages.tcl]",-1);
      Tcl_DStringAppend(&preinit,"\n\}",-1);
      
      vfspreinit=Tcl_NewStringObj(Tcl_DStringValue(&preinit),-1);
      /* NOTE: We never decr this refcount, lest the contents of the script be deallocated */
      Tcl_IncrRefCount(vfspreinit);
      TclSetPreInitScript(Tcl_GetString(vfspreinit));

      Tcl_DecrRefCount(vfsinitscript);
      Tcl_DecrRefCount(vfstcllib);







>
|

|
|
|
|
|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        Tcl_DStringAppendElement(&preinit,Tcl_GetString(vfstcllib));
        Tcl_DStringAppend(&preinit,"\nset auto_path {}",-1);
      }
      if(Tcl_FSAccess(vfstklib,F_OK)==0) {
        Tcl_DStringAppend(&preinit,"\nset tk_library ",-1);
        Tcl_DStringAppendElement(&preinit,Tcl_GetString(vfstklib));
      }
      /*
      Tcl_DStringAppend(&preinit,"\nif {[file exists [file join $::SRCDIR packages.tcl]]} {",-1);
      Tcl_DStringAppend(&preinit,"\n  #In a wrapped exe, we don't go out to the environment",-1);
      Tcl_DStringAppend(&preinit,"\n  set dir $::SRCDIR",-1);
      Tcl_DStringAppend(&preinit,"\n  source -encoding utf-8 [file join $::SRCDIR packages.tcl]",-1);
      Tcl_DStringAppend(&preinit,"\n  set auto_path {}",-1);
      Tcl_DStringAppend(&preinit,"\n}",-1);
      */
      vfspreinit=Tcl_NewStringObj(Tcl_DStringValue(&preinit),-1);
      /* NOTE: We never decr this refcount, lest the contents of the script be deallocated */
      Tcl_IncrRefCount(vfspreinit);
      TclSetPreInitScript(Tcl_GetString(vfspreinit));

      Tcl_DecrRefCount(vfsinitscript);
      Tcl_DecrRefCount(vfstcllib);