EOF;
+$ACESSDIR = getenv("ACESSDIR");
+$ARCH = getenv("ARCH");
+
+$gInputFile = $argv[1];
+$gOutputFile = $argv[2];
+$gDepFile = ($argc > 3 ? $argv[3] : false);
+
+$gDependencies = array();
+
$lines = file($argv[1]);
$lDepth = 0;
foreach($lines as $line)
{
$line = trim($line);
+ // Directory
if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
{
$new = array($matches[1], array());
$lDepth ++;
continue;
}
+ // End of a block
if($line == "}")
{
$lDepth --;
$lStack[$lDepth][1][] = array_pop($lStack);
continue;
}
+ // File
if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
{
$lStack[$lDepth][1][] = array($matches[1], $matches[2]);
+ $gDependencies[] = $matches[2];
continue;
}
echo "ERROR: $line\n";
}
function hd($fp)
+{
+ //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
+ $val = unpack("I", fread($fp, 4));
+ //print_r($val); exit -1;
+ return "0x".dechex($val[1]);
+}
+
+function hd8($fp)
{
return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
}
function ProcessFolder($prefix, $items)
{
global $gOutput;
+ global $ACESSDIR, $ARCH;
foreach($items as $i=>$item)
{
if(is_array($item[1]))
EOF;
}
- else {
- if(!file_exists($item[1])) {
- echo "ERROR: '{$item[1]}' does not exist\n",
+ else
+ {
+ $path = $item[1];
+
+ // Parse path components
+ $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
+ $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
+ echo $path,"\n";
+ // ---
+
+ if(!file_exists($path)) {
+ echo "ERROR: '{$path}' does not exist\n",
exit(1);
}
- $size = filesize($item[1]);
+ $size = filesize($path);
+
+ $fp = fopen($path, "rb");
$gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
- $fp = fopen($item[1], "rb");
- for( $j = 0; $j + 16 < $size; $j += 16 )
- {
+ for( $j = 0; $j + 16 < $size; $j += 16 ) {
$gOutput .= "\t";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",";
- $gOutput .= hd($fp).",".hd($fp).",\n";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",";
+ $gOutput .= hd8($fp).",".hd8($fp).",\n";
}
$gOutput .= "\t";
- for( ; $j < $size; $j ++ )
- {
+ for( ; $j < $size; $j ++ ) {
if( $j & 15 ) $gOutput .= ",";
- $gOutput .= hd($fp);
+ $gOutput .= hd8($fp);
}
fclose($fp);
$gOutput .= "\n};\n";
};
EOF;
-$fp = fopen($argv[2], "w");
+$fp = fopen($gOutputFile, "w");
fputs($fp, $gOutput);
fclose($fp);
+
+
+if($gDepFile !== false)
+{
+ $fp = fopen($gDepFile, "w");
+ $line = $gOutputFile.":\t".implode(" ", $gDependencies);
+ fputs($fp, $line);
+ fclose($fp);
+}
+
?>