156 lines
3.0 KiB
PHP
156 lines
3.0 KiB
PHP
|
#!/usr/bin/php
|
||
|
<?php
|
||
|
|
||
|
if (isset($argc)) {
|
||
|
for ($i = 0; $i < $argc; $i++) {
|
||
|
echo "Argument #" . $i . " - " . $argv[$i] . "\n";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
echo "argc and argv disabled\n";
|
||
|
}
|
||
|
|
||
|
if ($argv[1] == 'all') {
|
||
|
$files = scandir('src/r3', SCANDIR_SORT_DESCENDING);
|
||
|
|
||
|
$newFiles = [];
|
||
|
|
||
|
for ($i = 0; $i < sizeof($files); $i++) {
|
||
|
if (preg_match('/\.js$/', $files[$i])) {
|
||
|
array_push($newFiles, 'src/r3/' . $files[$i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$files = $newFiles;
|
||
|
|
||
|
} else {
|
||
|
$files = [$argv[1]];
|
||
|
}
|
||
|
|
||
|
foreach ($files as $file) {
|
||
|
|
||
|
echo $file . "\n";
|
||
|
|
||
|
echo "processing file " . $file . "\n";
|
||
|
|
||
|
$fn = fopen($file, "r");
|
||
|
|
||
|
$startCapture = false;
|
||
|
|
||
|
$saveLine = true;
|
||
|
|
||
|
$options = [];
|
||
|
|
||
|
$lines = [];
|
||
|
|
||
|
while (!feof($fn)) {
|
||
|
|
||
|
$line = fgets($fn);
|
||
|
|
||
|
if (
|
||
|
preg_match('/OPTIONS_END/', $line)
|
||
|
) {
|
||
|
$startCapture = false;
|
||
|
}
|
||
|
|
||
|
if (
|
||
|
preg_match('/OPTIONS_INIT_END/', $line)
|
||
|
) {
|
||
|
$saveLine = true;
|
||
|
}
|
||
|
|
||
|
if ($saveLine) {
|
||
|
array_push($lines, $line);
|
||
|
}
|
||
|
|
||
|
if (
|
||
|
preg_match('/OPTIONS_INIT_START/', $line)
|
||
|
) {
|
||
|
$saveLine = false;
|
||
|
}
|
||
|
|
||
|
if ($startCapture) {
|
||
|
|
||
|
$line = trim($line);
|
||
|
|
||
|
$key_value = preg_split('/=/', $line);
|
||
|
|
||
|
if ($key_value === false) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$options[$key_value[0]] = $key_value[1];
|
||
|
|
||
|
}
|
||
|
|
||
|
if (
|
||
|
preg_match('/OPTIONS_START/', $line)
|
||
|
) {
|
||
|
$startCapture = true;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
fclose($fn);
|
||
|
|
||
|
file_put_contents($file, $lines);
|
||
|
|
||
|
$template = file_get_contents('src/templates/options_init.template');
|
||
|
|
||
|
$newOptions = '';
|
||
|
|
||
|
foreach ($options as $key => $value) {
|
||
|
$updated = str_replace('KEY', $key, $template);
|
||
|
$updated = str_replace('VALUE', $value, $updated);
|
||
|
$newOptions .= $updated;
|
||
|
}
|
||
|
|
||
|
$contents = file_get_contents($file);
|
||
|
|
||
|
$contents = preg_replace(
|
||
|
'/\/\/OPTIONS_INIT_START.*?\/\/OPTIONS_INIT_END/s',
|
||
|
"//OPTIONS_INIT_START\n" . $newOptions . "\t\t//OPTIONS_INIT_END",
|
||
|
$contents
|
||
|
);
|
||
|
|
||
|
file_put_contents($file, $contents);
|
||
|
|
||
|
print_r($newOptions);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
exit(0);
|
||
|
array_push($events, 'Event.START');
|
||
|
array_push($events, 'Event.PAUSE');
|
||
|
array_push($events, 'Event.RESTART');
|
||
|
|
||
|
sort($events);
|
||
|
|
||
|
$i = 1;
|
||
|
|
||
|
$eventList = '';
|
||
|
|
||
|
$eventFunction = "Event.GetEventName = function(eventId) {\n\n\tswitch(eventId) {\n";
|
||
|
|
||
|
foreach ($events as $event) {
|
||
|
$eventList .= $event . " = " . "0x" . dechex($i) . ";\n";
|
||
|
|
||
|
$eventFunction .= "\t\tcase 0x" . dechex($i). " : return '" . strtolower(str_replace('Event.', '', $event)) . "';\n";
|
||
|
|
||
|
$i++;
|
||
|
}
|
||
|
|
||
|
$eventList .= "Event.MAX_EVENTS = " . "0x" . dechex($i) . ";\n\n";
|
||
|
|
||
|
$eventFunction .= "\t\tdefault :\n\t\t\tthrow new Error('Event type not defined : ' + eventId);\n";
|
||
|
$eventFunction .= "\t}\n\n";
|
||
|
$eventFunction .= "};\n";
|
||
|
|
||
|
echo $eventList;
|
||
|
echo $eventFunction;
|
||
|
|
||
|
file_put_contents('./src/r3/events-generated', $eventList . $eventFunction);
|
||
|
|
||
|
?>
|