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);
111 $path = str_replace("__SRC__", "$ACESSDIR", $path);
115 $gDependencies[] = $path;
117 if(!file_exists($path)) {
118 echo "ERROR: '{$path}' does not exist\n",
121 $size = filesize($path);
123 $fp = fopen($path, "rb");
125 $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
126 for( $j = 0; $j + 16 < $size; $j += 16 ) {
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).",";
135 $gOutput .= hd8($fp).",".hd8($fp).",\n";
138 for( ; $j < $size; $j ++ ) {
139 if( $j & 15 ) $gOutput .= ",";
140 $gOutput .= hd8($fp);
143 $gOutput .= "\n};\n";
145 tVFS_Node {$prefix}_{$i} = {
147 .ACLs = &gVFS_ACL_EveryoneRX,
151 .ImplPtr = {$prefix}_{$i}_data,
152 .Read = InitRD_ReadFile
163 ProcessFolder("gInitRD_Files", $lStack[0][1]);
165 $gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
166 foreach($lStack[0][1] as $j=>$child)
168 if($j) $gOutput .= ",\n";
169 $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
171 $gOutput .= "\n};\n";
172 $nRootFiles = count($lStack[0][1]);
174 tVFS_Node gInitRD_RootNode = {
176 .ACLs = &gVFS_ACL_EveryoneRX,
177 .Flags = VFS_FFLAG_DIRECTORY,
179 .ImplPtr = gInitRD_Root_Files,
180 .ReadDir = InitRD_ReadDir,
181 .FindDir = InitRD_FindDir
187 tVFS_Node * const gInitRD_FileList[] = {
191 function PutNodePointers($prefix, $items)
194 foreach($items as $i=>$item)
196 $gOutput .= ",&{$prefix}_{$i}";
197 if(is_array($item[1]))
199 PutNodePointers("{$prefix}_{$i}", $item[1]);
204 PutNodePointers("gInitRD_Files", $lStack[0][1]);
208 const int giInitRD_NumFiles = sizeof(gInitRD_FileList)/sizeof(gInitRD_FileList[0]);
213 $fp = fopen($gOutputFile, "w");
214 fputs($fp, $gOutput);
218 if($gDepFile !== false)
220 $fp = fopen($gDepFile, "w");
221 $line = $gOutputFile.":\t".implode(" ", $gDependencies);