2 $lGenDate = date("Y-m-d H:i");
13 $ACESSDIR = getenv("ACESSDIR");
14 $ARCH = getenv("ARCH");
16 $gInputFile = $argv[1];
17 $gOutputFile = $argv[2];
18 $gDepFile = ($argc > 3 ? $argv[3] : false);
20 $gDependencies = array();
22 $lines = file($argv[1]);
26 $lStack = array( array("",array()) );
27 foreach($lines as $line)
31 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
33 $new = array($matches[1], array());
34 array_push($lStack, $new);
42 $lStack[$lDepth][1][] = array_pop($lStack);
46 if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
48 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
49 $gDependencies[] = $matches[2];
52 echo "ERROR: $line\n";
58 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
59 $val = unpack("I", fread($fp, 4));
60 //print_r($val); exit -1;
61 return "0x".dechex($val[1]);
66 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
69 function ProcessFolder($prefix, $items)
72 global $ACESSDIR, $ARCH;
73 foreach($items as $i=>$item)
75 if(is_array($item[1]))
77 ProcessFolder("{$prefix}_{$i}", $item[1]);
79 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
80 foreach($item[1] as $j=>$child)
82 if($j) $gOutput .= ",\n";
83 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
87 $size = count($item[1]);
89 tVFS_Node {$prefix}_{$i} = {
91 .ACLs = &gVFS_ACL_EveryoneRX,
92 .Flags = VFS_FFLAG_DIRECTORY,
94 .ImplPtr = {$prefix}_{$i}_entries,
95 .ReadDir = InitRD_ReadDir,
96 .FindDir = InitRD_FindDir
105 // Parse path components
106 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
107 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
111 if(!file_exists($path)) {
112 echo "ERROR: '{$path}' does not exist\n",
115 $size = filesize($path);
117 $fp = fopen($path, "rb");
119 $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
120 for( $j = 0; $j + 16 < $size; $j += 16 ) {
122 $gOutput .= hd8($fp).",".hd8($fp).",";
123 $gOutput .= hd8($fp).",".hd8($fp).",";
124 $gOutput .= hd8($fp).",".hd8($fp).",";
125 $gOutput .= hd8($fp).",".hd8($fp).",";
126 $gOutput .= hd8($fp).",".hd8($fp).",";
127 $gOutput .= hd8($fp).",".hd8($fp).",";
128 $gOutput .= hd8($fp).",".hd8($fp).",";
129 $gOutput .= hd8($fp).",".hd8($fp).",\n";
132 for( ; $j < $size; $j ++ ) {
133 if( $j & 15 ) $gOutput .= ",";
134 $gOutput .= hd8($fp);
137 $gOutput .= "\n};\n";
139 tVFS_Node {$prefix}_{$i} = {
141 .ACLs = &gVFS_ACL_EveryoneRX,
144 .ImplPtr = {$prefix}_{$i}_data,
145 .Read = InitRD_ReadFile
156 ProcessFolder("gInitRD_Files", $lStack[0][1]);
158 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
159 foreach($lStack[0][1] as $j=>$child)
161 if($j) $gOutput .= ",\n";
162 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
164 $gOutput .= "\n};\n";
165 $nRootFiles = count($lStack[0][1]);
167 tVFS_Node gInitRD_RootNode = {
169 .ACLs = &gVFS_ACL_EveryoneRX,
170 .Flags = VFS_FFLAG_DIRECTORY,
172 .ImplPtr = gInitRD_Root_Files,
173 .ReadDir = InitRD_ReadDir,
174 .FindDir = InitRD_FindDir
178 $fp = fopen($gOutputFile, "w");
179 fputs($fp, $gOutput);
183 if($gDepFile !== false)
185 $fp = fopen($gDepFile, "w");
186 $line = $gOutputFile.":\t".implode(" ", $gDependencies);