@@ -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 } }