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";
|
|
|
|
}
|
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
$save = [
|
|
|
|
'options' => '/^\s*\bOPTIONS_START\b.*\bOPTIONS_END\b/sm',
|
|
|
|
'instance_mappings' => '/^\s*\bINSTANCE_OPTIONS_MAPPING_START\b.*\bINSTANCE_OPTIONS_MAPPING_END\b/sm',
|
|
|
|
'linked_objects' => '/^\s*\bLINKED_OBJECTS_START\b.*\bLINKED_OBJECTS_END\b/sm',
|
|
|
|
'excluded_options' => '/^\s*\bEXCLUDED_FROM_INSTANCE_OPTIONS_START\b.*\bEXCLUDED_FROM_INSTANCE_OPTIONS_END\b/sm',
|
|
|
|
'custom_options' => '/^\s*\/\/\bCUSTOM_OPTIONS_INIT_START\b.*\/\/\bCUSTOM_OPTIONS_INIT_END\b/sm',
|
|
|
|
'custom_before_init' => '/^\s*\/\/\bCUSTOM_BEFORE_INIT_START\b.*\/\/\bCUSTOM_BEFORE_INIT_END\b/sm',
|
|
|
|
'custom_create_instance' => '/^\s*\/\/\bCUSTOM_CREATE_INSTANCE_START\b.*\/\/\bCUSTOM_CREATE_INSTANCE_END\b/sm',
|
|
|
|
'custom_update_instance' => '/^\s*\/\/\bCUSTOM_UPDATE_INSTANCE_START\b.*\/\/\bCUSTOM_UPDATE_INSTANCE_END\b/sm',
|
|
|
|
'custom_update_from_instance' => '/^\s*\/\/\bCUSTOM_UPDATE_FROM_INSTANCE_START\b.*\/\/\bCUSTOM_UPDATE_FROM_INSTANCE_END\b/sm',
|
|
|
|
'custom_dispose' => '/^\s*\/\/\bCUSTOM_DISPOSE_START\b.*\/\/\bCUSTOM_DISPOSE_END\b/sm',
|
|
|
|
'custom_dispose_instance' => '/^\s*\/\/\bCUSTOM_DISPOSE_INSTANCE_START\b.*\/\/\bCUSTOM_DISPOSE_INSTANCE_END\b/sm',
|
|
|
|
'custom_implementation' => '/^\s*\/\/\bCUSTOM_IMPLEMENTATION_START\b.*\/\/\bCUSTOM_IMPLEMENTATION_END\b/sm'
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($argv[2] == 'all') {
|
|
|
|
|
2021-06-19 11:27:32 +02:00
|
|
|
$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 {
|
2021-06-19 16:41:42 +02:00
|
|
|
$files = [$argv[2]];
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
function getContents($contents, $regex) {
|
|
|
|
$matches = [];
|
|
|
|
preg_match($regex, $contents, $matches);
|
|
|
|
if (sizeof($matches) > 0) {
|
|
|
|
return $matches[0];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
foreach ($files as $file) {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
if ($argv[1] == 'save') {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
echo "saving file " . $file . "\n";
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
$contents = file_get_contents($file);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
$saved = [];
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
foreach ($save as $key => $regex) {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
$value = getContents($contents, $regex);
|
|
|
|
if ($value) {
|
|
|
|
array_push($saved, "\n");
|
|
|
|
array_push($saved, $value);
|
|
|
|
array_push($saved, "\n");
|
|
|
|
}
|
2021-06-19 11:27:32 +02:00
|
|
|
|
|
|
|
}
|
2021-06-19 16:41:42 +02:00
|
|
|
file_put_contents($file . '.saved', $saved);
|
|
|
|
echo "saved file " . $file . ".saved\n";
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
} else if ($argv[1] == 'restore') {
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
echo "restoring file " . $file . "\n";
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
$saved = file_get_contents($file . '.saved');
|
|
|
|
$new = file_get_contents($file);
|
2021-06-19 11:27:32 +02:00
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
foreach ($save as $key => $regex) {
|
|
|
|
$value = getContents($saved, $regex);
|
|
|
|
echo "restoring " . $key . " in " . $file;
|
|
|
|
if ($value && preg_match($regex, $new)) {
|
|
|
|
$new = preg_replace($regex, $value, $new);
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-19 16:41:42 +02:00
|
|
|
file_put_contents($file, $new);
|
2021-06-19 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
?>
|