2 $lGenDate = date("Y-m-d H:i");
13 $lines = file($argv[1]);
17 $lStack = array( array("",array()) );
18 foreach($lines as $line)
21 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
23 $new = array($matches[1], array());
24 array_push($lStack, $new);
31 $lStack[$lDepth][1][] = array_pop($lStack);
34 if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
36 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
39 echo "ERROR: $line\n";
45 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
48 function ProcessFolder($prefix, $items)
51 foreach($items as $i=>$item)
53 if(is_array($item[1]))
55 ProcessFolder("{$prefix}_{$i}", $item[1]);
57 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
58 foreach($item[1] as $j=>$child)
60 if($j) $gOutput .= ",\n";
61 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
65 $size = count($item[1]);
67 tVFS_Node {$prefix}_{$i} = {
69 .ACLs = &gVFS_ACL_EveryoneRX,
70 .Flags = VFS_FFLAG_DIRECTORY,
72 .ImplPtr = {$prefix}_{$i}_entries,
73 .ReadDir = InitRD_ReadDir,
74 .FindDir = InitRD_FindDir
80 if(!file_exists($item[1])) {
81 echo "ERROR: '{$item[1]}' does not exist\n",
84 $size = filesize($item[1]);
86 $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
87 $fp = fopen($item[1], "rb");
88 for( $j = 0; $j + 16 < $size; $j += 16 )
91 $gOutput .= hd($fp).",".hd($fp).",";
92 $gOutput .= hd($fp).",".hd($fp).",";
93 $gOutput .= hd($fp).",".hd($fp).",";
94 $gOutput .= hd($fp).",".hd($fp).",";
95 $gOutput .= hd($fp).",".hd($fp).",";
96 $gOutput .= hd($fp).",".hd($fp).",";
97 $gOutput .= hd($fp).",".hd($fp).",";
98 $gOutput .= hd($fp).",".hd($fp).",\n";
101 for( ; $j < $size; $j ++ )
103 if( $j & 15 ) $gOutput .= ",";
107 $gOutput .= "\n};\n";
109 tVFS_Node {$prefix}_{$i} = {
111 .ACLs = &gVFS_ACL_EveryoneRX,
114 .ImplPtr = {$prefix}_{$i}_data,
115 .Read = InitRD_ReadFile
126 ProcessFolder("gInitRD_Files", $lStack[0][1]);
128 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
129 foreach($lStack[0][1] as $j=>$child)
131 if($j) $gOutput .= ",\n";
132 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
134 $gOutput .= "\n};\n";
135 $nRootFiles = count($lStack[0][1]);
137 tVFS_Node gInitRD_RootNode = {
139 .ACLs = &gVFS_ACL_EveryoneRX,
140 .Flags = VFS_FFLAG_DIRECTORY,
142 .ImplPtr = gInitRD_Root_Files,
143 .ReadDir = InitRD_ReadDir,
144 .FindDir = InitRD_FindDir
148 $fp = fopen($argv[2], "w");
149 fputs($fp, $gOutput);