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 $gOutputLDOptsFile = $argv[3];
19 $gDepFile = ($argc > 4 ? $argv[4] : false);
21 $gDependencies = array();
23 $lines = file($argv[1]);
27 $lStack = array( array("",array()) );
28 foreach($lines as $line)
32 if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
34 $new = array($matches[1], array());
35 array_push($lStack, $new);
43 $lStack[$lDepth][1][] = array_pop($lStack);
47 if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
49 $lStack[$lDepth][1][] = array($matches[1], $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 );
71 function ProcessFolder($prefix, $items)
73 global $gOutput, $gDependencies;
74 global $ACESSDIR, $ARCH;
77 foreach($items as $i=>$item)
80 if(is_array($item[1]))
82 ProcessFolder("{$prefix}_{$i}", $item[1]);
84 $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
85 foreach($item[1] as $j=>$child)
87 if($j) $gOutput .= ",\n";
88 $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
92 $size = count($item[1]);
94 tVFS_Node {$prefix}_{$i} = {
96 .ACLs = &gVFS_ACL_EveryoneRX,
97 .Flags = VFS_FFLAG_DIRECTORY,
100 .ImplPtr = {$prefix}_{$i}_entries,
101 .Type = &gInitRD_DirType
110 // Parse path components
111 $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path);
112 $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path);
113 $path = str_replace("__SRC__", "$ACESSDIR", $path);
117 $gDependencies[] = $path;
119 if(!file_exists($path)) {
120 echo "ERROR: '{$path}' does not exist\n",
123 $size = filesize($path);
126 $_sym = $prefix."_".$i."_data";
127 $fp = fopen($path, "rb");
129 $gOutput .= "Uint8 $_sym[] = {\n";
130 for( $j = 0; $j + 16 < $size; $j += 16 ) {
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).",";
139 $gOutput .= hd8($fp).",".hd8($fp).",\n";
142 for( ; $j < $size; $j ++ ) {
143 if( $j & 15 ) $gOutput .= ",";
144 $gOutput .= hd8($fp);
147 $gOutput .= "\n};\n";
151 $_sym = "_binary_".str_replace(array("/","-","."), "_", $path)."_start";
152 $gOutput .= "extern Uint8 {$_sym}[];";
153 $gSymFiles[] = $path;
156 tVFS_Node {$prefix}_{$i} = {
158 .ACLs = &gVFS_ACL_EveryoneRX,
163 .Type = &gInitRD_FileType
174 ProcessFolder("gInitRD_Files", $lStack[0][1]);
176 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
177 foreach($lStack[0][1] as $j=>$child)
179 if($j) $gOutput .= ",\n";
180 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
182 $gOutput .= "\n};\n";
183 $nRootFiles = count($lStack[0][1]);
185 tVFS_Node gInitRD_RootNode = {
187 .ACLs = &gVFS_ACL_EveryoneRX,
188 .Flags = VFS_FFLAG_DIRECTORY,
190 .ImplPtr = gInitRD_Root_Files,
191 .Type = &gInitRD_DirType
197 tVFS_Node * const gInitRD_FileList[] = {
201 function PutNodePointers($prefix, $items)
204 foreach($items as $i=>$item)
206 $gOutput .= ",&{$prefix}_{$i}";
207 if(is_array($item[1]))
209 PutNodePointers("{$prefix}_{$i}", $item[1]);
214 PutNodePointers("gInitRD_Files", $lStack[0][1]);
218 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
223 $fp = fopen($gOutputFile, "w");
224 fputs($fp, $gOutput);
227 // - Create options call
228 $fp = fopen($gOutputLDOptsFile, "w");
229 fputs($fp, "--format binary\n");
230 foreach($gSymFiles as $sym=>$file)
232 fputs($fp, "$file\n");
233 // fputs($fp, "--defsym $sym=_binary_".$sym_filename."_start\n");
237 if($gDepFile !== false)
239 $fp = fopen($gDepFile, "w");
240 $line = $gOutputFile.":\t".implode(" ", $gDependencies);