2 $lGenDate = date("Y-m-d H:i");
13 $gInputFile = $argv[1];
14 $gOutputFile = $argv[2];
15 $gDepFile = ($argc > 3 ? $argv[3] : false);
17 $gDependencies = array();
19 $lines = file($argv[1]);
23 $lStack = array( array("",array()) );
24 foreach($lines as $line)
27 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
29 $new = array($matches[1], array());
30 array_push($lStack, $new);
37 $lStack[$lDepth][1][] = array_pop($lStack);
40 if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
42 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
43 $gDependencies[] = $matches[2];
46 echo "ERROR: $line\n";
52 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
53 $val = unpack("I", fread($fp, 4));
54 //print_r($val); exit -1;
55 return "0x".dechex($val[1]);
60 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
63 function ProcessFolder($prefix, $items)
66 foreach($items as $i=>$item)
68 if(is_array($item[1]))
70 ProcessFolder("{$prefix}_{$i}", $item[1]);
72 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
73 foreach($item[1] as $j=>$child)
75 if($j) $gOutput .= ",\n";
76 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
80 $size = count($item[1]);
82 tVFS_Node {$prefix}_{$i} = {
84 .ACLs = &gVFS_ACL_EveryoneRX,
85 .Flags = VFS_FFLAG_DIRECTORY,
87 .ImplPtr = {$prefix}_{$i}_entries,
88 .ReadDir = InitRD_ReadDir,
89 .FindDir = InitRD_FindDir
95 if(!file_exists($item[1])) {
96 echo "ERROR: '{$item[1]}' does not exist\n",
99 $size = filesize($item[1]);
101 $fp = fopen($item[1], "rb");
104 $gOutput .= "Uint32 {$prefix}_{$i}_data[] = {\n";
105 for( $j = 0; $j + 16 < $size; $j += 16 )
108 $gOutput .= hd($fp).",".hd($fp).",";
109 $gOutput .= hd($fp).",".hd($fp).",\n";
112 for( ; $j+3 < $size; $j += 4 )
114 if( $j & 15 ) $gOutput .= ",";
122 $tmp = unpack("I", $tmp);
123 $gOutput .= "0x".dechex($tmp[1]);
128 $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
129 for( $j = 0; $j + 16 < $size; $j += 16 ) {
131 $gOutput .= hd8($fp).",".hd8($fp).",";
132 $gOutput .= hd8($fp).",".hd8($fp).",";
133 $gOutput .= hd8($fp).",".hd8($fp).",";
134 $gOutput .= hd8($fp).",".hd8($fp).",";
135 $gOutput .= hd8($fp).",".hd8($fp).",";
136 $gOutput .= hd8($fp).",".hd8($fp).",";
137 $gOutput .= hd8($fp).",".hd8($fp).",";
138 $gOutput .= hd8($fp).",".hd8($fp).",\n";
141 for( ; $j < $size; $j ++ ) {
142 if( $j & 15 ) $gOutput .= ",";
143 $gOutput .= hd8($fp);
147 $gOutput .= "\n};\n";
149 tVFS_Node {$prefix}_{$i} = {
151 .ACLs = &gVFS_ACL_EveryoneRX,
154 .ImplPtr = {$prefix}_{$i}_data,
155 .Read = InitRD_ReadFile
166 ProcessFolder("gInitRD_Files", $lStack[0][1]);
168 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
169 foreach($lStack[0][1] as $j=>$child)
171 if($j) $gOutput .= ",\n";
172 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
174 $gOutput .= "\n};\n";
175 $nRootFiles = count($lStack[0][1]);
177 tVFS_Node gInitRD_RootNode = {
179 .ACLs = &gVFS_ACL_EveryoneRX,
180 .Flags = VFS_FFLAG_DIRECTORY,
182 .ImplPtr = gInitRD_Root_Files,
183 .ReadDir = InitRD_ReadDir,
184 .FindDir = InitRD_FindDir
188 $fp = fopen($gOutputFile, "w");
189 fputs($fp, $gOutput);
193 if($gDepFile !== false)
195 $fp = fopen($gDepFile, "w");
196 $line = $gOutputFile.":\t".implode(" ", $gDependencies);