|
1 # |
|
2 # Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: Parse headers files and search for public methods |
|
15 # |
|
16 |
|
17 #!perl -w |
|
18 |
|
19 use Getopt::Long; |
|
20 |
|
21 my $help = 0; |
|
22 my $output_path = "."; |
|
23 GetOptions ("path=s" => \@api_path, |
|
24 "output=s" => \$output_path, |
|
25 "verbose"=> \$verbose, |
|
26 "help" => \$help); |
|
27 |
|
28 if ($help or !@api_path){ |
|
29 print "\nPath parameter is mandatory!\n" unless $help; |
|
30 print "\n"; |
|
31 print "This script will parse header files looking for exported methods\n"; |
|
32 print "Parameters:\n"; |
|
33 print "\t --path -p -> (mandatory) path where parsing will start, multi-parameters are allowed\n"; |
|
34 print "\t --output -o -> path where output will be stored\n"; |
|
35 print "\t --verbose -v -> verbose output messages\n"; |
|
36 print "\t --help -h -> print this help\n"; |
|
37 exit; |
|
38 } |
|
39 |
|
40 my $file_location; |
|
41 my $file_name; |
|
42 |
|
43 $output_path .="\\"; |
|
44 `md $output_path 2>&1`; |
|
45 |
|
46 foreach $api_path (@api_path){ |
|
47 |
|
48 @dirs = `dir $api_path\\*.h /s/b 2>&1`; |
|
49 chomp @dirs; |
|
50 $tmp_path = $api_path; |
|
51 $tmp_path =~ s/\\/\./g; |
|
52 |
|
53 foreach (@dirs) { |
|
54 $file_location = $1 if /$tmp_path(.+)/; |
|
55 $file_name = "$1.txt" if /(\w+\.\w+)$/; |
|
56 print "Public methods from file ($file_name): $api_path$file_location\n" if $verbose;; |
|
57 open (APIFILE, "$api_path$file_location") or warn "Can not open file $file_location"; |
|
58 open (OUT, ">>$output_path$file_name") or warn "Can not create file $file_name"; |
|
59 |
|
60 while (<APIFILE>) |
|
61 { |
|
62 #remove white chars |
|
63 chomp; |
|
64 s/^\s+//; |
|
65 |
|
66 #find class name |
|
67 $class = $1 if /^\s*class (\w+)/i; |
|
68 |
|
69 #concatenate lines if definision is in multiline |
|
70 if ($line){ |
|
71 $line .= $_; |
|
72 next unless /;/; #next if line does not contain end of declaration |
|
73 } |
|
74 |
|
75 #search for all IMPORT_C lines |
|
76 if (/IMPORT_C/){ |
|
77 $line = "$class"."::"."$1" if /IMPORT_C.+?([~\[\]\w]+\s*\(.*)/i; |
|
78 next unless /;/; #next if line does not contain full declaration |
|
79 } |
|
80 |
|
81 $line .= "\n" if /;/; |
|
82 #remove some unnesessary chars |
|
83 if ($line) { |
|
84 $line = "$1\n" if ($line =~ /(.+\))/); |
|
85 $line =~ s/^\s+// if $line; |
|
86 print "\t$line" if $verbose and $line; |
|
87 print OUT "$line" if $line; |
|
88 } |
|
89 $line = ""; |
|
90 } |
|
91 close OUT; |
|
92 close APIFILE; |
|
93 } |
|
94 |
|
95 } |