1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-06 14:16:32 +02:00

Add vim modelines to all files.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2008-12-06 04:24:59 -05:00
parent 781f9a4084
commit 12b811d749
699 changed files with 1071 additions and 107 deletions

126
maintenance/add-vimline.php Normal file
View File

@@ -0,0 +1,126 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Adds vimline to files
*/
chdir(dirname(__FILE__) . '/..');
$FS = new FSTools();
$vimline = 'vim: et sw=4 sts=4';
$files = $FS->globr('.', '*');
foreach ($files as $file) {
if (
!is_file($file) ||
prefix_is('./docs/doxygen', $file) ||
prefix_is('./library/standalone', $file) ||
postfix_is('.ser', $file) ||
postfix_is('.tgz', $file) ||
postfix_is('.patch', $file) ||
postfix_is('.dtd', $file) ||
postfix_is('.ent', $file) ||
postfix_is('.png', $file) ||
postfix_is('.ico', $file) ||
// wontfix
postfix_is('.vtest', $file) ||
postfix_is('.svg', $file) ||
postfix_is('.phpt', $file) ||
postfix_is('VERSION', $file) ||
postfix_is('WHATSNEW', $file) ||
postfix_is('FOCUS', $file) ||
// phpt files
postfix_is('.diff', $file) ||
postfix_is('.exp', $file) ||
postfix_is('.log', $file) ||
postfix_is('.out', $file) ||
$file == './library/HTMLPurifier/Lexer/PH5P.php' ||
$file == './maintenance/PH5P.php'
) continue;
$ext = strrchr($file, '.');
if (
postfix_is('README', $file) ||
postfix_is('LICENSE', $file) ||
postfix_is('CREDITS', $file) ||
postfix_is('INSTALL', $file) ||
postfix_is('NEWS', $file) ||
postfix_is('TODO', $file) ||
postfix_is('WYSIWYG', $file) ||
postfix_is('Changelog', $file)
) $ext = '.txt';
if (postfix_is('Doxyfile', $file)) $ext = 'Doxyfile';
if (postfix_is('.php.in', $file)) $ext = '.php';
$no_nl = false;
switch ($ext) {
case '.php':
case '.inc':
case '.js':
$line = '// %s';
break;
case '.html':
case '.xsl':
case '.xml':
case '.htc':
$line = '<!-- %s -->';
break;
case '.htmlt':
$no_nl = true;
$line = '--# %s';
break;
case '.ini':
$line = '; %s';
break;
case '.css':
$line = '/* %s */';
break;
case '.bat':
$line = 'rem %s';
break;
case '.txt':
case '.utf8':
if (
prefix_is('./library/HTMLPurifier/ConfigSchema', $file) ||
prefix_is('./smoketests/test-schema', $file) ||
prefix_is('./tests/HTMLPurifier/StringHashParser', $file)
) {
$no_nl = true;
$line = '--# %s';
} else {
$line = ' %s';
}
break;
case 'Doxyfile':
$line = '# %s';
break;
default:
throw new Exception('Unknown file: ' . $file);
}
echo "$file\n";
$contents = file_get_contents($file);
$regex = '~' . str_replace('%s', 'vim: .+', preg_quote($line, '~')) . '~m';
$contents = preg_replace($regex, '', $contents);
$contents = rtrim($contents);
if (strpos($contents, "\r\n") !== false) $nl = "\r\n";
elseif (strpos($contents, "\n") !== false) $nl = "\n";
elseif (strpos($contents, "\r") !== false) $nl = "\r";
else $nl = PHP_EOL;
if (!$no_nl) $contents .= $nl;
$contents .= $nl . str_replace('%s', $vimline, $line) . $nl;
file_put_contents($file, $contents);
}
// vim: et sw=4 sts=4

View File

@@ -8,5 +8,15 @@ set environment variable PHP_IS_CLI to work around this).';
}
}
function prefix_is($comp, $subject) {
return strncmp($comp, $subject, strlen($comp)) === 0;
}
function postfix_is($comp, $subject) {
return strlen($subject) < $comp ? false : substr($subject, -strlen($comp)) === $comp;
}
// Load useful stuff like FSTools
require_once '../extras/HTMLPurifierExtras.auto.php';
// vim: et sw=4 sts=4

View File

@@ -157,3 +157,5 @@ $xw->endElement();
$xw->flush();
echo "done!\n";
// vim: et sw=4 sts=4

View File

@@ -39,3 +39,4 @@ foreach ($names as $name) {
echo "Cache flushed successfully.\n";
// vim: et sw=4 sts=4

View File

@@ -26,3 +26,5 @@ e($php . ' generate-schema-cache.php');
e($php . ' flush-definition-cache.php');
e($php . ' generate-standalone.php');
e($php . ' config-scanner.php');
// vim: et sw=4 sts=4

View File

@@ -71,3 +71,4 @@ fclose($fh);
echo "Completed successfully.";
// vim: et sw=4 sts=4

View File

@@ -185,3 +185,5 @@ foreach ($files as $file) {
echo "Writing HTMLPurifier.safe-includes.php... ";
file_put_contents('HTMLPurifier.safe-includes.php', $php);
echo "done!\n";
// vim: et sw=4 sts=4

View File

@@ -18,3 +18,5 @@ $new_src = '<?php' . PHP_EOL . substr($new_src, strpos($new_src, 'class HTML5 {'
file_put_contents($newt, $new_src);
shell_exec("diff -u \"$orig\" \"$newt\" > PH5P.patch");
unlink($newt);
// vim: et sw=4 sts=4

View File

@@ -27,3 +27,5 @@ $schema = $schema_builder->build($interchange);
echo "Saving schema... ";
file_put_contents($target, serialize($schema));
echo "done!\n";
// vim: et sw=4 sts=4

View File

@@ -43,6 +43,7 @@ $FS = new MergeLibraryFSTools();
* @param string $text PHP source code to replace includes from
*/
function replace_includes($text) {
// also remove vim modelines
return preg_replace_callback(
"/require(?:_once)? ['\"]([^'\"]+)['\"];/",
'replace_includes_callback',
@@ -52,11 +53,12 @@ function replace_includes($text) {
/**
* Removes leading PHP tags from included files. Assumes that there is
* no trailing tag.
* no trailing tag. Also removes vim modelines.
* @note This is safe for files that have internal <?php
* @param string $text Text to have leading PHP tag from
*/
function remove_php_tags($text) {
$text = preg_replace('#// vim:.+#', '', $text);
return substr($text, 5);
}
@@ -146,3 +148,5 @@ make_file_standalone('HTMLPurifier/Lexer/PH5P.php');
make_file_standalone('HTMLPurifier/Lexer/PEARSax3.php');
echo ' done!' . PHP_EOL;
// vim: et sw=4 sts=4

View File

@@ -7,3 +7,5 @@
*/
require dirname(__FILE__) . '/generate-standalone.php';
// vim: et sw=4 sts=4

View File

@@ -66,3 +66,5 @@ foreach ($schema->info as $ns => $ns_array) {
saveHash($adapter->get($ns, $dir));
}
}
// vim: et sw=4 sts=4

View File

@@ -28,3 +28,5 @@ foreach ($files as $file) {
file_put_contents($file, $new_code);
}
}
// vim: et sw=4 sts=4

View File

@@ -28,3 +28,5 @@ foreach ($files as $file) {
echo "Indented ConfigSchema call in $file\n";
}
}
// vim: et sw=4 sts=4

View File

@@ -13,14 +13,6 @@ assertCli();
chdir(dirname(__FILE__) . '/..');
$FS = new FSTools();
function prefix_is($comp, $subject) {
return strncmp($comp, $subject, strlen($comp)) === 0;
}
function postfix_is($comp, $subject) {
return strlen($subject) < $comp ? false : substr($subject, -strlen($comp)) === $comp;
}
$files = $FS->globr('.', '{,.}*', GLOB_BRACE);
foreach ($files as $file) {
if (
@@ -41,3 +33,5 @@ foreach ($files as $file) {
echo "$file\n";
file_put_contents($file, $result);
}
// vim: et sw=4 sts=4

View File

@@ -152,3 +152,5 @@ $rpc->publishRelease(
'url_zip', "http://htmlpurifier.org/releases/htmlpurifier-$version.zip",
'url_changelog', "http://htmlpurifier.org/svnroot/htmlpurifier/tags/$version/NEWS"
);
// vim: et sw=4 sts=4