diff --git a/it/main.py b/it/main.py new file mode 100644 index 0000000..580bc5d --- /dev/null +++ b/it/main.py @@ -0,0 +1,74 @@ +# it, a shITtier version of ed +import importlib +import sys + +oldinput = input + +def input(*args, **kwargs): + message = args[0] if len(args) > 0 else "" + while 1: + try: + user_input = str(oldinput(message)) + except KeyboardInterrupt: + pass + except EOFError: + sys.exit(0) + return user_input + +def parsecommand(command): + casesensitive = True + escapes = ["\\"] + quotes = ["'", '"'] + spaces = [" ", "\t"] + + command = command.rstrip().lstrip() + + inQuotes = 0 + word = "" + parsed_command = [] + + for i in range(len(command)): + if (command[i] in quotes) and inQuotes == 0\ + and (i == 0 \ + or (i > 0 and command[i-1] != escape)): + inQuotes = command[i] + + elif command[i] == inQuotes \ + and (i > 0 and command[i-1] != escape): + inQuotes = 0 + + elif command[i] in space and inQuotes == 0\ + and (i > 0 and command[i-1] != escape): + parsed_command += [word] + word = "" + + elif command[i] != "\\" or (i == len(command) - 1) \ + or not(command[i+1] in space + quotes): + word += command[i] + + parsed_command += [word] + if parsed_command == ['']: return [] + return parsed_command + +class buffer: # all the information about the current file + content = [] + dot = -1 + filename = "" + saved = 0 + +def main(argc, argv): + file = buffer() + modules = {} + while True: + command = parsecommand(input()) + if(command == []): + continue + try: + modules[command[0]] = importlib.import_module(command[0]) + except ModuleNotFoundError as err: + print(err) + else: + file = modules[command[0]].main(len(command), command, file) + +if __name__ == "__main__": + return main(len(sys.argv), sys.argv)