File: knr2ansi.pl

package info (click to toggle)
cxref 1.6c-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,608 kB
  • ctags: 2,058
  • sloc: ansic: 18,218; yacc: 2,086; sh: 915; lex: 462; perl: 452; makefile: 418; lisp: 256; cpp: 188; python: 80
file content (78 lines) | stat: -rwxr-xr-x 1,649 bytes parent folder | download | duplicates (11)
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
#!/bin/sh

exec perl -x $0 $*

#!perl

die "Usage: $0 <filename>\n" if($#ARGV==-1);

foreach $argv (@ARGV)
  {
   push(@files,$argv) if(-f $argv);
   push(@args,$argv) if(! -f $argv);
  }

$args=join(" ",@args);

foreach $file (@files)
  {
   open(CXREF,"cxref $args $file -raw |") || die "Cannot run cxref on $file\n";

   $function=0;
   $comment=0;
   $functype="";
   $funcname="";
   @funcargs=();

   @local=();
   @global=();

   while(<CXREF>)
       {
        if(m/^FUNCTION : ([a-z0-9A-Z_\$]+) \[([a-zA-Z]+)\]$/)
            {
             $function=1;
             $functype="static " if($2 eq "Local");
             $funcname=$1;
            }
        $comment=1 if($function && m/^<<<$/);
        $comment=0 if($function && m/^>>>$/);

        $functype.=substr($1,0,length($1)-length($funcname)-1) if($function && m/^Type: ([^<]+)( <|\n)/);
        push(@funcargs,$1) if($function && m/^Arguments: ([^<]+)( <|\n)/);

        if(!$comment && $function && (m/^$/ || m/^-+$/))
            {
             push(@funcargs,"void") if($#funcargs==-1);

             $f="$functype $funcname(".join(",",@funcargs).");";

             push(@local,$f)  if($functype =~ m/static/);
             push(@global,$f) if($functype !~ m/static/);

             $functype="";
             $funcname="";
             @funcargs=();
             $function=0;
            }
       }

   close(CXREF);

# Output the results

   print "\n /* local functions in $file */\n\n";

   foreach $f (@local)
       {
        print "$f\n";
       }

   print "\n /* global functions in $file */\n\n";

   foreach $f (@global)
       {
        print "$f\n";
       }

  }