2021-06-19 11:27:32 +02:00
|
|
|
#!/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");
|
|
|
|
|
|
|
|
$saveLine = true;
|
|
|
|
|
|
|
|
$options = [];
|
2021-06-19 13:40:22 +02:00
|
|
|
$instanceMappings = [];
|
|
|
|
$excludeOptions = [];
|
|
|
|
|
|
|
|
$saveOption = false;
|
|
|
|
$saveInstanceMappings = false;
|
|
|
|
$saveExcludeOptions = false;
|
2021-06-19 11:27:32 +02:00
|
|
|
|
|
|
|
$lines = [];
|
|
|
|
|
|
|
|
while (!feof($fn)) {
|
|
|
|
|
|
|
|
$line = fgets($fn);
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* if exiting an options definition block - stop saving that definition
|
|
|
|
*/
|
|
|
|
if (preg_match('/\bOPTIONS_END\b/', $line)) {
|
|
|
|
$saveOption = false;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bINSTANCE_OPTIONS_MAPPING_END\b/', $line)) {
|
|
|
|
$saveInstanceMappings = false;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bEXCLUDED_FROM_INSTANCE_OPTIONS_END\b/', $line)) {
|
|
|
|
$saveExcludeOptions = false;
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* if exiting an options implementation block - save the line for later
|
|
|
|
*/
|
|
|
|
if (preg_match('/\bOPTIONS_INIT_END\b/', $line)) {
|
|
|
|
$saveLine = true;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bCREATE_INSTANCE_OPTIONS_END\b/', $line)) {
|
|
|
|
$saveLine = true;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bUPDATE_INSTANCE_OPTIONS_END\b/', $line)) {
|
|
|
|
$saveLine = true;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bUPDATE_FROM_INSTANCE_OPTIONS_END\b/', $line)) {
|
2021-06-19 11:27:32 +02:00
|
|
|
$saveLine = true;
|
|
|
|
}
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* Now save the line
|
|
|
|
*/
|
2021-06-19 11:27:32 +02:00
|
|
|
if ($saveLine) {
|
|
|
|
array_push($lines, $line);
|
|
|
|
}
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* if entering an options implementation block - do not save the line for later
|
|
|
|
*/
|
|
|
|
if (preg_match('/\bOPTIONS_INIT_START\b/', $line)) {
|
|
|
|
$saveLine = false;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bCREATE_INSTANCE_OPTIONS_START\b/', $line)) {
|
|
|
|
$saveLine = false;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bUPDATE_INSTANCE_OPTIONS_START\b/', $line)) {
|
|
|
|
$saveLine = false;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bUPDATE_FROM_INSTANCE_OPTIONS_START\b/', $line)) {
|
2021-06-19 11:27:32 +02:00
|
|
|
$saveLine = false;
|
|
|
|
}
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
if ($saveOption) {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
|
|
|
$line = trim($line);
|
|
|
|
|
|
|
|
$key_value = preg_split('/=/', $line);
|
|
|
|
|
|
|
|
if ($key_value === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$options[$key_value[0]] = $key_value[1];
|
2021-06-19 13:40:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($saveInstanceMappings) {
|
|
|
|
|
|
|
|
$line = trim($line);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$key_value = preg_split('/=/', $line);
|
|
|
|
|
|
|
|
if ($key_value === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instanceMappings[$key_value[0]] = $key_value[1];
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
if ($saveExcludeOptions) {
|
|
|
|
$line = trim($line);
|
|
|
|
array_push($excludeOptions, $line);
|
|
|
|
print_r($excludeOptions);
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If entering an options definition block - start saving that definition
|
|
|
|
*/
|
|
|
|
if (preg_match('/\bOPTIONS_START\b/', $line)) {
|
|
|
|
$saveOption = true;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bINSTANCE_OPTIONS_MAPPING_START\b/', $line)) {
|
|
|
|
$saveInstanceMappings = true;
|
|
|
|
}
|
|
|
|
if (preg_match('/\bEXCLUDED_FROM_INSTANCE_OPTIONS_START\b/', $line)) {
|
|
|
|
$saveExcludeOptions = true;
|
|
|
|
}
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose($fn);
|
|
|
|
|
|
|
|
file_put_contents($file, $lines);
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* Process the constructor options
|
|
|
|
*/
|
2021-06-19 11:27:32 +02:00
|
|
|
$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(
|
2021-06-19 13:40:22 +02:00
|
|
|
'/\/\/\bOPTIONS_INIT_START\b.*?\/\/\bOPTIONS_INIT_END\b/s',
|
2021-06-19 11:27:32 +02:00
|
|
|
"//OPTIONS_INIT_START\n" . $newOptions . "\t\t//OPTIONS_INIT_END",
|
|
|
|
$contents
|
|
|
|
);
|
|
|
|
|
|
|
|
file_put_contents($file, $contents);
|
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* Process createInstance options
|
|
|
|
*/
|
|
|
|
$template = file_get_contents('src/templates/create_instance_options.template');
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$newOptions = [];
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
foreach ($options as $key => $value) {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
if (in_array($key, $excludeOptions)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
if (array_key_exists($key, $instanceMappings)) {
|
|
|
|
$value = $instanceMappings[$key];
|
|
|
|
} else {
|
|
|
|
$value = $key;
|
|
|
|
}
|
|
|
|
$updated = str_replace('INSTANCE_KEY', $value, $template);
|
|
|
|
$updated = str_replace('KEY', $key, $updated);
|
|
|
|
array_push($newOptions, $updated);
|
|
|
|
}
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$contents = file_get_contents($file);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$contents = preg_replace(
|
|
|
|
'/\/\/\bCREATE_INSTANCE_OPTIONS_START\b.*?\/\/\bCREATE_INSTANCE_OPTIONS_END\b/s',
|
|
|
|
"//CREATE_INSTANCE_OPTIONS_START\n" . implode(",\n", $newOptions) . "\n\t\t\t\t\t//CREATE_INSTANCE_OPTIONS_END",
|
|
|
|
$contents
|
|
|
|
);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
file_put_contents($file, $contents);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
/**
|
|
|
|
* Process updateInstance options
|
|
|
|
*/
|
|
|
|
$template = file_get_contents('src/templates/update_instance_options.template');
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$newOptions = '';
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
foreach ($options as $key => $value) {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
if (in_array($key, $excludeOptions)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists($key, $instanceMappings)) {
|
|
|
|
$value = $instanceMappings[$key];
|
|
|
|
} else {
|
|
|
|
$value = $key;
|
|
|
|
}
|
|
|
|
$updated = str_replace('INSTANCE_KEY', $value, $template);
|
|
|
|
$updated = str_replace('KEY', $key, $updated);
|
|
|
|
$newOptions .= $updated;
|
|
|
|
}
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$contents = file_get_contents($file);
|
|
|
|
|
|
|
|
$contents = preg_replace(
|
|
|
|
'/\/\/\bUPDATE_INSTANCE_OPTIONS_START\b.*?\/\/\bUPDATE_INSTANCE_OPTIONS_END\b/s',
|
|
|
|
"//UPDATE_INSTANCE_OPTIONS_START\n" . $newOptions. "\t\t//UPDATE_INSTANCE_OPTIONS_END",
|
|
|
|
$contents
|
|
|
|
);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
file_put_contents($file, $contents);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process updateFromInstance options
|
|
|
|
*/
|
|
|
|
$template = file_get_contents('src/templates/update_from_instance_options.template');
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
$newOptions = '';
|
|
|
|
|
|
|
|
foreach ($options as $key => $value) {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 13:40:22 +02:00
|
|
|
if (in_array($key, $excludeOptions)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists($key, $instanceMappings)) {
|
|
|
|
$value = $instanceMappings[$key];
|
|
|
|
} else {
|
|
|
|
$value = $key;
|
|
|
|
}
|
|
|
|
$updated = str_replace('INSTANCE_KEY', $value, $template);
|
|
|
|
$updated = str_replace('KEY', $key, $updated);
|
|
|
|
$newOptions .= $updated;
|
|
|
|
}
|
|
|
|
|
|
|
|
$contents = file_get_contents($file);
|
|
|
|
|
|
|
|
$contents = preg_replace(
|
|
|
|
'/\/\/\bUPDATE_FROM_INSTANCE_OPTIONS_START\b.*?\/\/\bUPDATE_FROM_INSTANCE_OPTIONS_END\b/s',
|
|
|
|
"//UPDATE_FROM_INSTANCE_OPTIONS_START\n" . $newOptions. "\t\t//UPDATE_FROM_INSTANCE_OPTIONS_END",
|
|
|
|
$contents
|
|
|
|
);
|
|
|
|
|
|
|
|
file_put_contents($file, $contents);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
?>
|
2021-06-19 11:27:32 +02:00
|
|
|
|