tons of suggested fixes from alen
This commit is contained in:
parent
fab099f7ac
commit
67d4eb2748
72
it/main.py
Normal file → Executable file
72
it/main.py
Normal file → Executable file
@ -1,25 +1,13 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
# it, a shITtier version of ed
|
# it, a shITtier version of ed
|
||||||
import importlib
|
import importlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
oldinput = input
|
|
||||||
|
|
||||||
def input(*args):
|
|
||||||
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):
|
def parsecommand(command):
|
||||||
casesensitive = True
|
casesensitive = True
|
||||||
escapes = ["\\"]
|
escapes = {"\\"}
|
||||||
quotes = ["'", '"']
|
quotes = {"'", '"'}
|
||||||
spaces = [" ", "\t"]
|
spaces = {" ", "\t"}
|
||||||
|
|
||||||
command = command.strip()
|
command = command.strip()
|
||||||
|
|
||||||
@ -27,48 +15,56 @@ def parsecommand(command):
|
|||||||
word = ""
|
word = ""
|
||||||
parsed_command = []
|
parsed_command = []
|
||||||
|
|
||||||
|
# copied from other project. mystery code. works though
|
||||||
for i in range(len(command)):
|
for i in range(len(command)):
|
||||||
if (command[i] in quotes) and inQuotes == 0\
|
if ((command[i] in quotes)
|
||||||
and (i == 0 \
|
and inQuotes == 0
|
||||||
or (i > 0 and not(command[i-1] in escapes))):
|
and (i == 0
|
||||||
|
or (i > 0 and not(command[i-1] in escapes)))):
|
||||||
inQuotes = command[i]
|
inQuotes = command[i]
|
||||||
|
|
||||||
elif command[i] == inQuotes \
|
elif (command[i] == inQuotes
|
||||||
and (i > 0 and not(command[i-1] in escapes)):
|
and (i > 0 and not(command[i-1] in escapes))):
|
||||||
inQuotes = 0
|
inQuotes = 0
|
||||||
|
|
||||||
elif command[i] in space and inQuotes == 0\
|
elif (command[i] in spaces and inQuotes == 0
|
||||||
and (i > 0 and not(command[i-1] in escapes)):
|
and (i > 0 and not(command[i-1] in escapes))):
|
||||||
parsed_command += [word]
|
parsed_command += [word]
|
||||||
word = ""
|
word = ""
|
||||||
|
|
||||||
elif command[i] != "\\" or (i == len(command) - 1) \
|
elif (command[i] != "\\" or (i == len(command) - 1)
|
||||||
or not(command[i+1] in space + quotes):
|
or not(command[i+1] in spaces + quotes)):
|
||||||
word += command[i]
|
word += command[i]
|
||||||
|
|
||||||
parsed_command += [word]
|
parsed_command += [word]
|
||||||
if parsed_command == ['']: return []
|
return [] if parsed_command == [''] else parsed_command
|
||||||
return parsed_command
|
|
||||||
|
|
||||||
class buffer: # all the information about the current file
|
class Buffer: # all the information about the current file
|
||||||
content = []
|
def __init__(self):
|
||||||
dot = -1
|
self.content = [] # content of the file
|
||||||
filename = ""
|
self.dot = 0 # where we are in the file
|
||||||
saved = 0
|
self.filename = "" # name of where we'll save the file
|
||||||
|
self.saved = 1 # bool that says whether or not we have saved the file
|
||||||
|
|
||||||
def main(argc, argv):
|
def main():
|
||||||
file = buffer()
|
buffer = Buffer()
|
||||||
modules = {}
|
modules = {}
|
||||||
while True:
|
while True:
|
||||||
command = parsecommand(input())
|
try:
|
||||||
if(command == []):
|
command = parsecommand(input())
|
||||||
|
except KeyboardInterrupt: # bastard behavior from ed
|
||||||
|
pass
|
||||||
|
except EOFError:
|
||||||
|
break
|
||||||
|
if command == []:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
modules[command[0]] = importlib.import_module(command[0])
|
modules[command[0]] = importlib.import_module(command[0])
|
||||||
except ModuleNotFoundError as err:
|
except ModuleNotFoundError as err:
|
||||||
print(err)
|
print(err)
|
||||||
else:
|
else:
|
||||||
file = modules[command[0]].main(len(command), command, file)
|
buffer = modules[command[0]].main(buffer, command)
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
return main(len(sys.argv), sys.argv)
|
sys.exit(main())
|
||||||
|
Loading…
Reference in New Issue
Block a user