Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- output_file = ""
- if(len(sys.argv) >= 2 and sys.argv[1].endswith(".h")):
- output_file = sys.argv[1]
- else:
- print("Please specify the full path to your 4Coder directory as the first commandline argument")
- quit()
- b_print = False;
- typenames = set()
- types = ["class", "struct", "typedef"]
- files = set()
- file_types = [".h", "cpp", "c", ".hpp"]
- def find_type_name(words,type,offset):
- for i in range(len(words)):
- if(words[i] == type):
- if(len(words) > i + 1):
- return words[i + offset]
- return ""
- def find_typedef_name(words):
- for i in range(len(words)):
- if(words[i] == "typedef"):
- if(len(words) > i + 2):
- return words[i + 2]
- def scan_file(file_name):
- with open(file_name,"rt") as in_file:
- for line in in_file:
- for type in types:
- if(line.find(type) != -1):
- words = line.split()
- offset = 1
- t = ""
- if(type == "typedef"):
- t = find_typedef_name(words)
- if not isinstance(t, str):
- break
- if t.endswith(";"):
- t = t[:-1]
- else:
- t = find_type_name(words,type,offset)
- if t != "":
- typenames.add(t)
- def scan_files():
- for root, dirs, local_files in os.walk('./'):
- for name in local_files:
- for file_type in file_types:
- if name.endswith(file_type):
- files.add(name)
- break
- scan_files()
- if b_print:
- print("Scanned Files: " + str(files))
- for file_name in files:
- scan_file(file_name)
- if b_print:
- print("Found the following types: " + str(typenames))
- output_file_line = "PSAT( \"{type}\", CPP_TOKEN_KEY_TYPE ),\n"
- f = open(output_file,"w+")
- for t in typenames:
- f.write(output_file_line.format(type = t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement