daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Sep 10th, 2018 27 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import sys
  3.  
  4. output_file = ""
  5. if(len(sys.argv) >= 2 and sys.argv[1].endswith(".h")):
  6.     output_file = sys.argv[1]
  7. else:
  8.     print("Please specify the full path to your 4Coder directory as the first commandline argument")
  9.     quit()
  10. b_print = False;
  11.  
  12. typenames = set()
  13. types = ["class", "struct", "typedef"]
  14. files = set()
  15. file_types = [".h", "cpp", "c", ".hpp"]
  16.  
  17. def find_type_name(words,type,offset):
  18.     for i in range(len(words)):
  19.         if(words[i] == type):
  20.             if(len(words) > i + 1):
  21.                 return words[i + offset]
  22.     return ""
  23.  
  24. def find_typedef_name(words):
  25.     for i in range(len(words)):
  26.         if(words[i] == "typedef"):
  27.             if(len(words) > i + 2):
  28.                 return words[i + 2]
  29.  
  30. def scan_file(file_name):
  31.     with open(file_name,"rt") as in_file:
  32.         for line in in_file:
  33.             for type in types:
  34.                 if(line.find(type) != -1):
  35.                     words = line.split()
  36.                     offset = 1
  37.                     t = ""
  38.                     if(type == "typedef"):
  39.                         t = find_typedef_name(words)
  40.                         if not isinstance(t, str):
  41.                             break
  42.                         if t.endswith(";"):
  43.                             t = t[:-1]
  44.                     else:
  45.                         t = find_type_name(words,type,offset)
  46.                     if t != "":
  47.                         typenames.add(t)
  48.  
  49.  
  50. def scan_files():
  51.     for root, dirs, local_files in os.walk('./'):
  52.         for name in local_files:
  53.             for file_type in file_types:
  54.                 if name.endswith(file_type):
  55.                     files.add(name)
  56.                     break
  57.  
  58.  
  59. scan_files()
  60. if b_print:
  61.     print("Scanned Files: "  + str(files))
  62. for file_name in files:
  63.     scan_file(file_name)
  64. if b_print:
  65.     print("Found the following types: " + str(typenames))
  66.  
  67. output_file_line = "PSAT( \"{type}\", CPP_TOKEN_KEY_TYPE ),\n"
  68.  
  69. f = open(output_file,"w+")
  70. for t in typenames:
  71.     f.write(output_file_line.format(type = t))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top