1#!/usr/bin/env python
2#
3# this program is used to find source code that includes linux kernel headers directly
4# (e.g. with #include <linux/...> or #include <asm/...>)
5#
6# then it lists
7
8import sys, cpp, glob, os, re, getopt
9import kernel
10from utils import *
11from defaults import *
12
13
14def usage():
15    print """\
16  usage:  find_users.py [-v] (file|directory|@listfile)+
17
18    this program is used to scan a list of files or directories for
19    sources that include kernel headers directly. the program prints
20    the list of said source files when it's done.
21
22    when scanning directories, only files matching the following
23    extension will be searched: .c .cpp .S .h
24
25    use -v to enable verbose output
26"""
27    sys.exit(1)
28
29
30try:
31    optlist, args = getopt.getopt( sys.argv[1:], 'v' )
32except:
33    # unrecognized option
34    print "error: unrecognized option"
35    usage()
36
37for opt, arg in optlist:
38    if opt == '-v':
39        kernel.verboseSearch = 1
40        kernel.verboseFind   = 1
41    else:
42        usage()
43
44if len(args) < 1:
45    usage()
46
47# helper function used to walk the user files
48def parse_file(path, parser):
49    parser.parseFile(path)
50
51
52# first, obtain the list of kernel files used by our clients
53# avoid parsing the 'kernel_headers' directory itself since we
54# use this program with the Android source tree by default.
55#
56fparser = kernel.HeaderScanner()
57walk_source_files( args, parse_file, fparser, excludes=["kernel_headers","original"] )
58files   = fparser.getFiles()
59
60for f in sorted(files):
61    print f
62
63sys.exit(0)
64