Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created June 8, 2010 14:44
Show Gist options
  • Save v6ak/430117 to your computer and use it in GitHub Desktop.
Save v6ak/430117 to your computer and use it in GitHub Desktop.
@sh "%~pd0port.sh" %*
<?php
// This code is ASAP (as SHORT as possible), not nice
$tokens = token_get_all(file_get_contents('php://stdin'));
$write=true;
echo '<?php /* Ported by this scratchy tool: http://gist.github.com/430117
(!) GENERATED CODE - DO NOT EDIT!
*/?'.'>';
foreach ($tokens as $tok) {
$s = is_array($tok) ? $tok[1] : $tok;
switch ($s) {
case 'use':
case 'namespace':
$write = false;
break;
case ';':
if($write){
echo ';';
}
$write = true;
break;
case '\\':
break;
default:
if($write){
echo $s;
}
};
};
#!/bin/bash
# config
PHP="" # should be php 5.3
LINTPHP="" # should be php 5.2
SCRIPT=""
out="../p52"
for f in *.php; do
echo "$f"
case "$f" in
. )
;;
.. )
;;
* )
cat "$f" \
| "$PHP" -f "$SCRIPT" \
> "$out/$f"
"$LINTPHP" -l "$out/$f"
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment