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 );
69 function ProcessFolder($prefix, $items)
71 global $gOutput, $gDependencies;
72 global $ACESSDIR, $ARCH;
74 foreach($items as $i=>$item)
77 if(is_array($item[1]))
79 ProcessFolder("{$prefix}_{$i}", $item[1]);
81 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
82 foreach($item[1] as $j=>$child)
84 if($j) $gOutput .= ",\n";
85 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
89 $size = count($item[1]);
91 tVFS_Node {$prefix}_{$i} = {
93 .ACLs = &gVFS_ACL_EveryoneRX,
94 .Flags = VFS_FFLAG_DIRECTORY,
97 .ImplPtr = {$prefix}_{$i}_entries,
98 .ReadDir = InitRD_ReadDir,
99 .FindDir = InitRD_FindDir
108 // Parse path components
109 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
110 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
114 $gDependencies[] = $path;
116 if(!file_exists($path)) {
117 echo "ERROR: '{$path}' does not exist\n",
120 $size = filesize($path);
122 $fp = fopen($path, "rb");
124 $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
125 for( $j = 0; $j + 16 < $size; $j += 16 ) {
127 $gOutput .= hd8($fp).",".hd8($fp).",";
128 $gOutput .= hd8($fp).",".hd8($fp).",";
129 $gOutput .= hd8($fp).",".hd8($fp).",";
130 $gOutput .= hd8($fp).",".hd8($fp).",";
131 $gOutput .= hd8($fp).",".hd8($fp).",";
132 $gOutput .= hd8($fp).",".hd8($fp).",";
133 $gOutput .= hd8($fp).",".hd8($fp).",";
134 $gOutput .= hd8($fp).",".hd8($fp).",\n";
137 for( ; $j < $size; $j ++ ) {
138 if( $j & 15 ) $gOutput .= ",";
139 $gOutput .= hd8($fp);
142 $gOutput .= "\n};\n";
144 tVFS_Node {$prefix}_{$i} = {
146 .ACLs = &gVFS_ACL_EveryoneRX,
150 .ImplPtr = {$prefix}_{$i}_data,
151 .Read = InitRD_ReadFile
162 ProcessFolder("gInitRD_Files", $lStack[0][1]);
164 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
165 foreach($lStack[0][1] as $j=>$child)
167 if($j) $gOutput .= ",\n";
168 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
170 $gOutput .= "\n};\n";
171 $nRootFiles = count($lStack[0][1]);
173 tVFS_Node gInitRD_RootNode = {
175 .ACLs = &gVFS_ACL_EveryoneRX,
176 .Flags = VFS_FFLAG_DIRECTORY,
178 .ImplPtr = gInitRD_Root_Files,
179 .ReadDir = InitRD_ReadDir,
180 .FindDir = InitRD_FindDir
186 tVFS_Node * const gInitRD_FileList[] = {
190 function PutNodePointers($prefix, $items)
193 foreach($items as $i=>$item)
195 $gOutput .= ",&{$prefix}_{$i}";
196 if(is_array($item[1]))
198 PutNodePointers("{$prefix}_{$i}", $item[1]);
203 PutNodePointers("gInitRD_Files", $lStack[0][1]);
207 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
212 $fp = fopen($gOutputFile, "w");
213 fputs($fp, $gOutput);
217 if($gDepFile !== false)
219 $fp = fopen($gDepFile, "w");
220 $line = $gOutputFile.":\t".implode(" ", $gDependencies);