binheader_readf_check.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. g#!/usr/bin/python
  2. import re, string, sys
  3. def trim_function_and_params (section):
  4. k = string.find (section, "(") + 1
  5. brackets = 1
  6. section_len = len (section)
  7. while k < section_len:
  8. if section [k] == '(':
  9. brackets += 1
  10. elif section [k] == ')':
  11. brackets -= 1
  12. if brackets < 1:
  13. return section [:k+1]
  14. k += 1
  15. print "Whoops!!!!"
  16. sys.exit (1)
  17. def get_function_calls (filedata):
  18. filedata = string.split (filedata, "psf_binheader_readf")
  19. filedata = filedata [1:]
  20. func_calls = []
  21. for section in filedata:
  22. section = "psf_binheader_readf" + section
  23. func_calls.append (trim_function_and_params (section))
  24. return func_calls
  25. def search_for_problems (filename):
  26. filedata = open (filename, "r").read ()
  27. if len (filedata) < 1:
  28. print "Error : file '%s' contains no data." % filename
  29. sys.exit (1)
  30. count = 0
  31. calls = get_function_calls (filedata)
  32. for call in calls:
  33. if string.find (call, "sizeof") > 0:
  34. print "Found : ", call
  35. count += 1
  36. if count == 0:
  37. print "%-20s : No problems found." % filename
  38. else:
  39. print "\n%-20s : Found %d errors." % (filename, count)
  40. sys.exit (1)
  41. return
  42. #-------------------------------------------------------------------------------
  43. if len (sys.argv) < 2:
  44. print "Usage : %s <file>" % sys.argv [0]
  45. sys.exit (1)
  46. for file in sys.argv [1:]:
  47. search_for_problems (file)