misc/libfreetype/src/tools/chktrcmp.py
author Xeli
Fri, 07 Oct 2011 14:17:07 +0200
branchhedgeroid
changeset 6035 bdd0528ee8a6
parent 5172 88f2e05288ba
permissions -rw-r--r--
Close a game without leaking memory. It should be noted that sending an SDL Quit event leaks memory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
#!/usr/bin/env python
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
# Check trace components in FreeType 2 source.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
# Author: suzuki toshiya, 2009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
# This code is explicitly into the public domain.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
import sys
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
import os
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
import re
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
SRC_FILE_LIST   = []
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
USED_COMPONENT  = {}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
KNOWN_COMPONENT = {}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
SRC_FILE_DIRS   = [ "src" ]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
TRACE_DEF_FILES = [ "include/freetype/internal/fttrace.h" ]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
# --------------------------------------------------------------
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
# Parse command line options
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
for i in range( 1, len( sys.argv ) ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  if sys.argv[i].startswith( "--help" ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
    print "Usage: %s [option]" % sys.argv[0]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
    print "Search used-but-defined and defined-but-not-used trace_XXX macros"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
    print ""
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
    print "  --help:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
    print "        Show this help"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
    print ""
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    print "  --src-dirs=dir1:dir2:..."
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
    print "        Specify the directories of C source files to be checked"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    print "        Default is %s" % ":".join( SRC_FILE_DIRS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
    print ""
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    print "  --def-files=file1:file2:..."
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    print "        Specify the header files including FT_TRACE_DEF()"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
    print "        Default is %s" % ":".join( TRACE_DEF_FILES )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
    print ""
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    exit(0)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  if sys.argv[i].startswith( "--src-dirs=" ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    SRC_FILE_DIRS = sys.argv[i].replace( "--src-dirs=", "", 1 ).split( ":" )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  elif sys.argv[i].startswith( "--def-files=" ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
    TRACE_DEF_FILES = sys.argv[i].replace( "--def-files=", "", 1 ).split( ":" )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
# --------------------------------------------------------------
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
# Scan C source and header files using trace macros.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
c_pathname_pat = re.compile( '^.*\.[ch]$', re.IGNORECASE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
trace_use_pat  = re.compile( '^[ \t]*#define[ \t]+FT_COMPONENT[ \t]+trace_' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
for d in SRC_FILE_DIRS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  for ( p, dlst, flst ) in os.walk( d ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    for f in flst:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      if c_pathname_pat.match( f ) != None:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
        src_pathname = os.path.join( p, f )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
        line_num = 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
        for src_line in open( src_pathname, 'r' ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
          line_num = line_num + 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
          src_line = src_line.strip()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
          if trace_use_pat.match( src_line ) != None:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
            component_name = trace_use_pat.sub( '', src_line )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
            if component_name in USED_COMPONENT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
              USED_COMPONENT[component_name].append( "%s:%d" % ( src_pathname, line_num ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
            else:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
              USED_COMPONENT[component_name] = [ "%s:%d" % ( src_pathname, line_num ) ]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
# --------------------------------------------------------------
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
# Scan header file(s) defining trace macros.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
trace_def_pat_opn = re.compile( '^.*FT_TRACE_DEF[ \t]*\([ \t]*' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
trace_def_pat_cls = re.compile( '[ \t\)].*$' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
for f in TRACE_DEF_FILES:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  line_num = 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  for hdr_line in open( f, 'r' ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    line_num = line_num + 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    hdr_line = hdr_line.strip()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    if trace_def_pat_opn.match( hdr_line ) != None:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      component_name = trace_def_pat_opn.sub( '', hdr_line )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
      component_name = trace_def_pat_cls.sub( '', component_name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
      if component_name in KNOWN_COMPONENT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
        print "trace component %s is defined twice, see %s and fttrace.h:%d" % \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
          ( component_name, KNOWN_COMPONENT[component_name], line_num )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      else:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
        KNOWN_COMPONENT[component_name] = "%s:%d" % \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
          ( os.path.basename( f ), line_num )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
# --------------------------------------------------------------
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
# Compare the used and defined trace macros.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
print "# Trace component used in the implementations but not defined in fttrace.h."
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
cmpnt = USED_COMPONENT.keys()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
cmpnt.sort()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
for c in cmpnt:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  if c not in KNOWN_COMPONENT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    print "Trace component %s (used in %s) is not defined." % ( c, ", ".join( USED_COMPONENT[c] ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
print "# Trace component is defined but not used in the implementations."
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
cmpnt = KNOWN_COMPONENT.keys()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
cmpnt.sort()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
for c in cmpnt:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  if c not in USED_COMPONENT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    if c != "any":
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      print "Trace component %s (defined in %s) is not used." % ( c, KNOWN_COMPONENT[c] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114