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]);
51 echo "ERROR: $line\n";
57 //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT );
58 $val = unpack("I", fread($fp, 4));
59 //print_r($val); exit -1;
60 return "0x".dechex($val[1]);
65 return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
68 function ProcessFolder($prefix, $items)
70 global $gOutput, $gDependencies;
71 global $ACESSDIR, $ARCH;
72 foreach($items as $i=>$item)
74 if(is_array($item[1]))
76 ProcessFolder("{$prefix}_{$i}", $item[1]);
78 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
79 foreach($item[1] as $j=>$child)
81 if($j) $gOutput .= ",\n";
82 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
86 $size = count($item[1]);
88 tVFS_Node {$prefix}_{$i} = {
90 .ACLs = &gVFS_ACL_EveryoneRX,
91 .Flags = VFS_FFLAG_DIRECTORY,
93 .ImplPtr = {$prefix}_{$i}_entries,
94 .ReadDir = InitRD_ReadDir,
95 .FindDir = InitRD_FindDir
104 // Parse path components
105 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
106 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
110 $gDependencies[] = $path;
112 if(!file_exists($path)) {
113 echo "ERROR: '{$path}' does not exist\n",
116 $size = filesize($path);
118 $fp = fopen($path, "rb");
120 $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
121 for( $j = 0; $j + 16 < $size; $j += 16 ) {
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).",";
130 $gOutput .= hd8($fp).",".hd8($fp).",\n";
133 for( ; $j < $size; $j ++ ) {
134 if( $j & 15 ) $gOutput .= ",";
135 $gOutput .= hd8($fp);
138 $gOutput .= "\n};\n";
140 tVFS_Node {$prefix}_{$i} = {
142 .ACLs = &gVFS_ACL_EveryoneRX,
145 .ImplPtr = {$prefix}_{$i}_data,
146 .Read = InitRD_ReadFile
157 ProcessFolder("gInitRD_Files", $lStack[0][1]);
159 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
160 foreach($lStack[0][1] as $j=>$child)
162 if($j) $gOutput .= ",\n";
163 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
165 $gOutput .= "\n};\n";
166 $nRootFiles = count($lStack[0][1]);
168 tVFS_Node gInitRD_RootNode = {
170 .ACLs = &gVFS_ACL_EveryoneRX,
171 .Flags = VFS_FFLAG_DIRECTORY,
173 .ImplPtr = gInitRD_Root_Files,
174 .ReadDir = InitRD_ReadDir,
175 .FindDir = InitRD_FindDir
179 $fp = fopen($gOutputFile, "w");
180 fputs($fp, $gOutput);
184 if($gDepFile !== false)
186 $fp = fopen($gDepFile, "w");
187 $line = $gOutputFile.":\t".implode(" ", $gDependencies);