Index: lib/xvfs/xvfs.tcl ================================================================== --- lib/xvfs/xvfs.tcl +++ lib/xvfs/xvfs.tcl @@ -1,18 +1,22 @@ #! /usr/bin/env tclsh namespace eval ::xvfs {} # Functions +proc ::xvfs::_emitLine {line} { + ::minirivet::_emitOutput "${line}\n" +} + proc ::xvfs::printHelp {channel {errors ""}} { if {[llength $errors] != 0} { foreach error $errors { - puts $channel "error: $error" + ::xvfs::_emitLine $channel "error: $error" } - puts $channel "" + ::xvfs::_emitLine $channel "" } - puts $channel "Usage: dir2c \[--help\] --directory --name " + ::xvfs::_emitLine $channel "Usage: dir2c \[--help\] --directory --name " flush $channel } proc ::xvfs::sanitizeCString {string} { set output [join [lmap char [split $string ""] { @@ -111,23 +115,23 @@ default { return -code error "Unable to process $inputFile, unknown type: $fileInfo(type)" } } - puts "\t\{" - puts "\t\t.name = \"[sanitizeCString $outputFile]\"," - puts "\t\t.type = $type," - puts "\t\t.size = $size," + ::xvfs::_emitLine "\t\{" + ::xvfs::_emitLine "\t\t.name = \"[sanitizeCString $outputFile]\"," + ::xvfs::_emitLine "\t\t.type = $type," + ::xvfs::_emitLine "\t\t.size = $size," switch -exact -- $fileInfo(type) { "file" { - puts "\t\t.data.fileContents = (const unsigned char *) $data" + ::xvfs::_emitLine "\t\t.data.fileContents = (const unsigned char *) $data" } "directory" { - puts "\t\t.data.dirChildren = $children" + ::xvfs::_emitLine "\t\t.data.dirChildren = $children" } } - puts "\t\}," + ::xvfs::_emitLine "\t\}," } proc ::xvfs::processDirectory {fsName directory {subDirectory ""}} { set subDirectories [list] set outputFiles [list] @@ -139,11 +143,11 @@ } else { set isTopLevel false } if {$isTopLevel} { - puts "static const struct xvfs_file_data xvfs_${fsName}_data\[\] = \{" + ::xvfs::_emitLine "static const struct xvfs_file_data xvfs_${fsName}_data\[\] = \{" } # XXX:TODO: Include hidden files ? set children [list] foreach file [glob -nocomplain -tails -directory $workingDirectory *] { @@ -157,11 +161,11 @@ unset -nocomplain fileInfo catch { file lstat $inputFile fileInfo } if {![info exists fileInfo]} { - puts stderr "warning: Unable to access $inputFile, skipping" + ::xvfs::_emitLine stderr "warning: Unable to access $inputFile, skipping" } lappend children [file tail $file] if {$fileInfo(type) eq "directory"} { @@ -185,11 +189,11 @@ processFile $fsName $inputFile $outputFile [array get fileInfo] lappend outputFiles $outputFile if {$isTopLevel} { - puts "\};" + ::xvfs::_emitLine "\};" } return $outputFiles } @@ -210,10 +214,13 @@ set rootDirectory $val } "--name" { set fsName $val } + "--output" { + # Ignored, handled as part of some other process + } default { printHelp stderr [list "Invalid option: $arg $val"] exit 1 } } Index: xvfs-create ================================================================== --- xvfs-create +++ xvfs-create @@ -10,10 +10,18 @@ set mode "run" if {[lindex $argv 0] == "--dump-tcl"} { set mode "dump-tcl" } + +foreach {arg val} $argv { + switch -exact -- $arg { + "--output" { + set outputFile $val + } + } +} proc remove_debug {input} { set output [list] set lastLine - @@ -33,11 +41,20 @@ return [join $output "\n"] } switch -- $mode { "run" { + if {[info exists outputFile]} { + set fd [open $outputFile w] + ::minirivet::setOutputChannel $fd + } + ::minirivet::parse $template + + if {[info exists fd]} { + close $fd + } } "dump-tcl" { set xvfs_tcl [file join $sourceDirectory lib xvfs xvfs.tcl] set xvfs_core_h [file join $sourceDirectory xvfs-core.h] set xvfs_core_c [file join $sourceDirectory xvfs-core.c] @@ -55,10 +72,13 @@ set core_header_data [remove_debug $core_header_data] } puts "#! /usr/bin/env tclsh" puts "" + puts [list namespace eval ::minirivet {}] + puts [list set ::minirivet::_outputChannel stdout] + puts [list proc ::minirivet::_emitOutput [info args ::minirivet::_emitOutput] [info body ::minirivet::_emitOutput]] puts [read [open $xvfs_tcl]] puts "" puts [list puts -nonewline $core_header_data] puts "" puts [string map $cleanup [::minirivet::parseStringToCode [read [open $template]]]]