File: function_finder.tcl

package info (click to toggle)
r-cran-tcltk2 1.2-10-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,356 kB
  • ctags: 1,386
  • sloc: tcl: 37,888; ansic: 792; python: 324; sh: 68; sed: 16; makefile: 1
file content (45 lines) | stat: -rwxr-xr-x 1,587 bytes parent folder | download | duplicates (12)
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
#!/bin/tclsh8.3

proc main {argc argv} {

	array set functions ""

	foreach f $argv {
		puts stderr "PROCESSING FILE $f"

		catch {exec cc -DNeedFunctionPrototypes -E $f} data
		#set functionList [regexp -all -inline {[a-zA-Z0-9_-]+[ \t\n\r]+([a-zA-Z0-9_-]+)[ \t\n\r]+\([ \t\n\r]*([^\)]+)[ \t\n\r]*\)[ \t\n\r]*;} $data]
		set functionList [regexp -all -inline {[a-zA-Z0-9_\-\*]+[ \t\n\r\*]+([a-zA-Z0-9_\-\*]+)[ \t\n\r]*\(([^\)]*)\)[ \t\n\r]*;} $data]
		set functionList [concat $functionList \
			[regexp -all -inline {[a-zA-Z0-9_\-\*]+[ \t\n\r\*]+([a-zA-Z0-9_\-\*]+)[ \t\n\r]*_ANSI_ARGS_\(\(([^\)]*)\)\)[ \t\n\r]*;} $data]]
		#puts "FL $functionList"
		foreach {junk function args} $functionList {
			#puts "FUNC $function ARGS $args"
			set args [string map {"\n" "" "\r" "" "\t" " " "," ", "} $args]
			regsub -all {\s{2,}} $args " " args
			set functions($function) $args
		}
	}

	puts "array set ::functions \{"
	foreach function [lsort -dictionary [array names functions]] {
		if {"_" == [string index $function 0] || "_" == [string index $function end]} {
			continue
		}
		puts "\t$function [list [set functions($function)]]"
	}
	puts "\}"
}

proc sglob {pattern} {
	return [glob -nocomplain $pattern]
}

#main $argc /usr/local/include/tclDecls.h
#return
        
main $argc [concat [sglob /usr/include/*.h] [sglob /usr/include/*/*.h] \
[sglob /usr/local/include/*.h] [sglob /usr/local/include/*/*.h] \
[sglob /usr/X11R6/include/*.h] [sglob /usr/X11R6/include/*/*.h] \
[sglob /usr/X11R6/include/*/*/*.h] [sglob /usr/local/include/X11/*.h] \
[sglob /usr/local/include/X11/*/*.h]]