File: process.php

package info (click to toggle)
phpdoc 20020310-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 35,272 kB
  • ctags: 354
  • sloc: xml: 799,767; php: 1,395; cpp: 500; makefile: 200; sh: 140; awk: 51
file content (116 lines) | stat: -rwxr-xr-x 3,361 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/php -q
<?php 
/*
# +----------------------------------------------------------------------+
# | PHP Version 4                                                        |
# +----------------------------------------------------------------------+
# | Copyright (c) 1997-2002 The PHP Group                                |
# +----------------------------------------------------------------------+
# | This source file is subject to version 2.02 of the PHP licience,     |
# | that is bundled with this package in the file LICENCE and is         |
# | avalible through the world wide web at                               |
# | http://www.php.net/license/2_02.txt.                                 |
# | If uou did not receive a copy of the PHP license and are unable to   |
# | obtain it through the world wide web, please send a note to          |
# | license@php.net so we can mail you a copy immediately                |
# +----------------------------------------------------------------------+
# | Authors:    Jeroen van Wolffelaar <jeroen@php.net>                   |
# +----------------------------------------------------------------------+
*/

set_time_limit(0);
ob_implicit_flush();

if ($argc < 2 || $argc > 3) { ?>
Process the manual to do some replacements.

  Usage:
  <?=$argv[0]?> <apply-script> [<startdir>]

  <apply-script> must contain the function apply($input),
  which recieves a whole xml-file, and should return
  the new file, or false if no modification needed.
  Apply scripts reside in the apply folder below this
  script. You only need to give the file name.

  With <startdir> you can specify in which dir
  to start looking recursively for xml files.

  Written by jeroen@php.net

<?php
    exit;
}

echo "Starting with manual-process\n";
echo "Including $argv[1]...";
include("apply/$argv[1]");
echo " done\n";
if (!function_exists('apply')) {
?>

### FATAL ERROR ###

In <?=$argv[1]?> you should define a function:
  string apply(string $string)

<?php
    exit;
}

$startdir = isset($argv[2]) ? $argv[2] : '.';

echo "Constructing list of all xml-files (may take a while)...";
$files = all_xml_files($startdir);
echo " done (".count($files)." xml files found)\n";

foreach ($files as $file) {

    echo "[Processing $file]\n";
    $fp = fopen($file,'r');
    $old = fread($fp,filesize($file));
    fclose($fp);

    if (!$old) {
        echo "WARNING: problem reading $file, skipping\n";
        continue;
    }

    $new = apply($old);
    if ($new === FALSE) { echo "NO MODIFICATION: $file not modified\n"; }
    else {
        $fp = fopen($file,'w');
        $res = fwrite($fp,$new);
        fclose($fp);
        if (!$res) {
            echo "WARNING: problem writing $file, file might be damaged\n";
            continue;
        }
    }
}

    
/* Utility functions: */

function all_xml_files($startdir)
{
    $startdir = ereg_replace('/+$','',$startdir);
    //echo "\$startdir = $startdir\n";
    $entries = array();

    $handle=opendir($startdir);
    while ($file = readdir($handle)) {

        $ffile = "$startdir/$file"; // full file(path)
        //echo "$file\n";
        if (ereg('\.xml$',$file))
            $entries[] = $ffile;
        if ($file{0} != '.' && is_dir($ffile))
            $entries = array_merge($entries,all_xml_files($ffile));
    }
    closedir($handle);

    return $entries;
}