1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import re
class bcolors:
"""
Helper class that contains formatting classes and functions
"""
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def is_legal_parameter(name):
"""
Function that returns true if the given name can be used as a
parameter in the c programming language.
"""
# List of C reserved keywords
reserved_keywords = [
"auto", "break", "case", "char", "const", "continue", "default", "do",
"double", "else", "enum", "extern", "float", "for", "goto", "if",
"inline", "int", "long", "register", "restrict", "return", "short",
"signed", "sizeof", "static", "struct", "switch", "typedef", "union",
"unsigned", "void", "volatile", "while", "_Bool", "_Complex", "_Imaginary"
]
# Regular expression pattern for a legal C variable name
pattern = r'^[a-zA-Z_][a-zA-Z0-9_]*$'
# Check if the input string matches the pattern and is not a reserved keyword
return re.match(pattern, name) and name not in reserved_keywords
def is_legal_filename(name):
"""
Function that returns true if the given name can be used as a
filename
"""
if name == "":
return False
if " " in name:
return False
if "/" in name:
return False
if "\\" in name:
return False
return True
|