#!/usr/bin/php $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); ?>