<commit_before>#!/usr/bin/tclsh
# /etc/ports.conf options
package provide darwinports 1.0

global ports_opts
global bootstrap_options
set bootstrap_options "sysportpath libpath"
set portinterp_options "sysportpath portpath auto_path portconf"

# XXX not portable
proc ccextension {file} {
    if {[regexp {([A-Za-z]+).c} [file tail $file] match name] == 1} {
	set objfile [file join [file dirname $file] $name.dylib]
	if {[file exists $objfile]} {
	    if {[file mtime $file] <= [file mtime $objfile]} {
		return
	    }
	}
	exec cc -dynamiclib $file -o $objfile -ltcl
    }
}

proc init {args} {
    global auto_path env bootstrap_options sysportpath portconf

    if [file isfile /etc/ports.conf] {
	set portconf /etc/ports.conf
	set fd [open /etc/ports.conf r]
	while {[gets $fd line] >= 0} {
	    foreach option $bootstrap_options {
		if {[regexp "^$option\[ \t\]+(\[A-Za-z0-9/\]+$)" $line match val] == 1} {
		    set $option $val
		}
	    }
	}
    }

    # Prefer the PORTPATH environment variable
    if {[llength [array names env PORTPATH]] > 0} {
	set sysportpath [lindex [array get env PORTPATH] 1]
    }

    if ![info exists sysportpath] {
	return -code error "sysportpath must be set in /etc/ports.conf or in the PORTPATH env variable"
    }
	
    if ![info exists libpath] {
	set libpath [file join $sysportpath Tcl]
    }

    if [file isdirectory $libpath] {
	lappend auto_path $libpath
	foreach dir [glob -nocomplain -directory $libpath -types d *] {
	    if [file isdirectory $dir] {
		foreach srcfile [glob -nocomplain -directory $dir -types f *.c] {
		    ccextension $srcfile
		}
		catch {pkg_mkIndex $dir *.tcl *.so *.dylib} result
	    }
	}
    } else {
	return -code error "Library directory '$libpath' must exist"
    }
}

proc build {portdir chain target args} {
    global targets portpath portinterp_options user_options

    if [file isdirectory $portdir] {
	cd $portdir
	set portpath [pwd]
	interp create bombus
	bombus alias {} build bombus build
	foreach opt $portinterp_options {
		upvar #0 $opt upopt
		if [info exists upopt] {
			bombus eval set $opt \"$upopt\"
		}
	}
	if {[llength $args] > 0} {
		bombus eval set user_options $args
	}
	bombus eval source Portfile
	bombus eval eval_targets targets $chain $target
    } else {
	return -code error "Portdir $portpath does not exist"
    }
}<commit_msg>Give the child interpreter a better name than "bombus." It's now "workerbee" =)<commit_after>#!/usr/bin/tclsh
# /etc/ports.conf options
package provide darwinports 1.0

global ports_opts
global bootstrap_options
set bootstrap_options "sysportpath libpath"
set portinterp_options "sysportpath portpath auto_path portconf"

# XXX not portable
proc ccextension {file} {
    if {[regexp {([A-Za-z]+).c} [file tail $file] match name] == 1} {
	set objfile [file join [file dirname $file] $name.dylib]
	if {[file exists $objfile]} {
	    if {[file mtime $file] <= [file mtime $objfile]} {
		return
	    }
	}
	exec cc -dynamiclib $file -o $objfile -ltcl
    }
}

proc init {args} {
    global auto_path env bootstrap_options sysportpath portconf

    if [file isfile /etc/ports.conf] {
	set portconf /etc/ports.conf
	set fd [open /etc/ports.conf r]
	while {[gets $fd line] >= 0} {
	    foreach option $bootstrap_options {
		if {[regexp "^$option\[ \t\]+(\[A-Za-z0-9/\]+$)" $line match val] == 1} {
		    set $option $val
		}
	    }
	}
    }

    # Prefer the PORTPATH environment variable
    if {[llength [array names env PORTPATH]] > 0} {
	set sysportpath [lindex [array get env PORTPATH] 1]
    }

    if ![info exists sysportpath] {
	return -code error "sysportpath must be set in /etc/ports.conf or in the PORTPATH env variable"
    }
	
    if ![info exists libpath] {
	set libpath [file join $sysportpath Tcl]
    }

    if [file isdirectory $libpath] {
	lappend auto_path $libpath
	foreach dir [glob -nocomplain -directory $libpath -types d *] {
	    if [file isdirectory $dir] {
		foreach srcfile [glob -nocomplain -directory $dir -types f *.c] {
		    ccextension $srcfile
		}
		catch {pkg_mkIndex $dir *.tcl *.so *.dylib} result
	    }
	}
    } else {
	return -code error "Library directory '$libpath' must exist"
    }
}

proc build {portdir chain target args} {
    global targets portpath portinterp_options user_options

    if [file isdirectory $portdir] {
	cd $portdir
	set portpath [pwd]
	interp create workerbee
	workerbee alias {} build workerbee build
	foreach opt $portinterp_options {
		upvar #0 $opt upopt
		if [info exists upopt] {
			workerbee eval set $opt \"$upopt\"
		}
	}
	if {[llength $args] > 0} {
		workerbee eval set user_options $args
	}
	workerbee eval source Portfile
	workerbee eval eval_targets targets $chain $target
    } else {
	return -code error "Portdir $portpath does not exist"
    }
}
{'fraction_non_alphanumeric': 0.11304895986551797, 'fraction_numerical': 0.004622819920151292, 'mean_word_length': 3.242424242424242, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4996191', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1638, 'n_words': 552}