File: funclist.php3

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (119 lines) | stat: -rwxr-xr-x 3,278 bytes parent folder | download | duplicates (3)
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
117
118
119
#! ./php -q
<?

  /* To be started in your /php3 source direcory,
     using a CGI PHP interpreter within this directory.
     
     max_execution_time on my system (P1, 133 MHz): 300 Sec.
   
   */

  function scanforfunction($file) {
    global $func, $module;
    
    $size   = filesize($file);
    $tstart = time();
    print "processing $file ($size bytes): "; flush();

    $cfile = basename($file);
    $line = implode("", @file($file));

    
    print "names "; flush();
    # Scan for "function_entry" block
    if (preg_match("!function_entry\s+(\w+)_functions\[\]\s*=\s*\{(.*)\};!sUS", $line, $m)) :
      
      # save module name
      $module[$m[1]] = $m[1];
      $cmodule       = $m[1];
      
      # split function block into function names
      # Regexp ist an Alternative (alternative1|alternative2)
      # Alternative 1 matches '{ "func_name", php3_func_name,'
      # Alternative 2 matches 'PHP_FE(func_name,'
      if (preg_match_all(
        "!(\{\s*\"(\w+)\"\s*,\s*(\w+)\s*,|PHP_FE\(\s*(\w+)\s*,)!sUS",
        $m[2], 
        $m)) :
          $fnames = $m[2];
          $cnames = $m[3];
          $xnames = $m[4];

          reset($xnames);
          while(list($k, $v) = each($xnames)) :
            if ($v) :
              $fnames[] = $v;
              $cnames[] = "php3_$v";
            endif;
          endwhile;
          
          reset($fnames);
          while (list($k, $v) = each($fnames)) :
            if ($v) :
              $func[$fnames[$k]]["name"]  = $fnames[$k];
              $func[$fnames[$k]]["cfunc"] = $cnames[$k];
              $func[$fnames[$k]]["module"]= $cmodule;
              $func[$fnames[$k]]["file"]  = $cfile;
            endif;
          endwhile;
      endif;
    endif;

    print "descriptions "; flush();
    # Scan for '/* {{{ proto ... */ ... }}} */' blocks
    if (preg_match_all(
      "!/\*\s*\{\{\{(.*)\*/.*\}\}\}\s*\*/!sUS",
      $line,
      $m,
      PREG_SET_ORDER)) :
        reset($m);
        while(list($k, $v) = each($m)) :
          preg_match("!proto\s+(\w+)\s+(\w+)\((.*)\).*\n(.*)$!sUS", $v[1], $n);
          $func[$n[2]]["return"]    = $n[1];
          $func[$n[2]]["parameter"] = $n[3];
          $func[$n[2]]["desc"]      = $n[4];
        endwhile;
    endif;

    $tstop = time();
    $tuse  = $tstop - $tstart;
    $tfunc = count($func);
    $tmod  = count($module);
    print "($tuse sec, $tfunc functions in $tmod modules).\n"; flush();
  }

  function scandir($dirname = ".") {
    $dp = opendir($dirname);
    if (!$dp)
      die("Cannot open $dirname");
    
    while($name = readdir($dp)) {
      # skip . and ..
      if ("." == $name or ".." == $name)
        continue;
        
      # recurse subdirectories
      if ("dir" == filetype("$dirname/$name"))
        scandir("$dirname/$name");
        
      # skip all non-.c files
      if (!preg_match("/\.c$/", $name))
        continue;
      
      # scan the file for functions
      scanforfunction("$dirname/$name");
    }
    closedir($dp);
  }

scandir();

reset($func);
while(list($k, $v) = each($func)) :
  printf("Function %s (Module %s, %s:%s()):\n", 
    $k, $v["module"], $v["file"], $v["cfunc"]);
  printf("%s %s(%s)\n", $v["return"], $k, $v["parameter"]);
  printf("%s\n\n", $v["desc"]);
endwhile;
exit;
?>