free software resistance

 the cost of computing freedom is eternal vigilance

### figdb.py *original date:* jan 2017 *originally posted:* oct 2024 figdb.py: ``` #!/usr/bin/env python # coding: utf-8 #### license: creative commons cc0 1.0 (public domain) #### http://creativecommons.org/publicdomain/zero/1.0/ proginf = "figdb 4.1, jan 2017 mn" import sys import os from sys import stdin, stdout from os import popen try: from colorama import init ; init() except: pass buf = [] cmdhelp = [("timer", "input (shared-line) change main variable to number of seconds past midnight") ,("arr", "function (shared-line) change main var to array (starting with same contents)") ] def chelp(f): f="" def outfilewrite(outb, p): outb += [p] #global vrck #vrck += p.strip() #if inle: print color(5, 0) + p.rstrip() ; p=raw_input() ; quit() def color(f, b): return "" def bcolor(b): return "" def sgn(p): p = float(p) if p > 0: return 1 if p < 0: return -1 return 0 def left(p, s): return p[:s] def right(p, s): return p[-s:] def leftfour(p): try: if left(p, 4) == chr(32) * 4: p = right(p, len(p) - 4) except: pass return p def atleast(s, p): if p < s: return s else: return p def figfsp(p): pp = "" ; flg = 0 fsp = figfsplit(p) for fp in enumerate(fsp): if flg == 0 and fp[1] in cmds.keys(): pp += color(8,0) + "_" + color(7,0) + " " ; flg = cmds[fp[1]] if flg < 0: flg = flg * -1 else: flg = flg + 1 pp += fp[1] + " " if flg > 0: flg -= 1 if flg == 0 and fp[0] + 1 < len(fsp): pp += color(8,0) + "_" + color(7,0) + " " return pp.rstrip().replace(color(8,0) + "_" + color(7,0) + " " + color(8,0) + "_" + color(7,0), color(8,0) + "\n" + color(7,0)).replace(color(8,0) + "_" + color(7,0),color(8,0) + "\n" + color(7,0)) def figfsplit(p): # return p.split() # that was fine when strings weren't tokens # we have to make this 3 tokens: variable "hello, world!" #comment not string px = [] pxc = -1 # could use len(px) -1 instead? inquotes = 0 remarked = 0 inspc = "" ; vnspc = "" #print "->", p for l in p: if inquotes == 0 and remarked == 0 and l == "#": remarked = 1 pxc += 1 ; px += [""] if remarked == 1: px[pxc] += l if remarked == 0: if l == "\"": if inquotes == 0: inquotes = 1 ; pxc += 1 ; px += [""] else: inquotes = 0 #; px[pxc] += l if inquotes == 1: px[pxc] += l if remarked == 0 and inquotes == 0: if vnspc not in "1234567890-" + chr(32) and l[0] == ".": l = " " vnspc = l if l[0] in "():;|=,": l = " " if inspc != " " and l == " ": pxc += 1 ; px += [""] if l != " ": if pxc == -1: pxc += 1 ; px += [""] px[pxc] += l.lower() inspc = l #print "->", px[:] while ('') in px: px.remove('') while (':') in px: px.remove(':') for p in range(len(px)): if px[p][0] != "#": if right(px[p], 1) == ":": lenpx = len(px[p]) - 1 if lenpx > 0: px[p] = left(px[p], lenpx) return px[:] def nob(p, s): r = "" if s == len(p) - 1: if len(p): if p[s].rstrip() != ".": r = p[s].rstrip() if len(r): if r[-1:] == ".": r = left(r, len(r) - 1) pfig = "" try: pfig = left(p[s], 3) except: pfig = "" if pfig.lower() == "fig" and p[s].lower() != "fig": return "figg" try: if r != "": return r else: return p[s] except: return "" def snobl(p): if "\"" in p: return p else: return p.lower() def snob(p, s): r = "" if s == len(p) - 1: if len(p): if p[s].rstrip() != ".": r = p[s].rstrip() if len(r): if r[-1:] == ".": r = left(r, len(r) - 1) pqt = "" try: pqt = left(p[s], 3) except: pqt = "" if pqt.lower() == "fig" and p[s].lower() != "fig": return "figg" try: if r != "": return snobl(r) else: return snobl(p[s]) except: return "" def lnob(p, s): r = "" if s == len(p) - 1: if len(p): if p[s].rstrip() != ".": r = p[s].rstrip() if len(r): if r[-1:] == ".": r = left(r, len(r) - 1) pfig = "" try: pfig = left(p[s], 3) except: pfig = "" if pfig.lower() == "fig" and p[s].lower() != "fig": return "figg" try: if r != "": return r.lower() else: return p[s].lower() except: return "" def stripcoords(p): ps = "" for s in str(p): if s in "1234567890.": ps += s return ps def getmore(p, s): try: for t in range(1, s + 1): if len(p) == 1: p = [] p = right(p, len(p) - 1) while "" in p: p.remove("") for prx in range(len(p)): if p[prx][0] == "#": p.remove(p[prx]) return p except: return [] def getlmore(p, s): try: for t in range(1, s + 1): if len(p) == 1: p = [] p = right(p, len(p) - 1) while "" in p: p.remove("") return p except: return [] def getpairs(p, s): r = "" if len(p): if p[len(p) - 1].rstrip() != ".": r = p[len(p) - 1].rstrip() if len(r): if r[-1:] == ".": r = left(r, len(r) - 1) p[len(p) - 1] = r try: p = right(p, len(p) - s) if not len(p) % 2: return p else: return [] except: return [] def lc(): global linecount global flen es = " \x1b[0;37;40m" return "&" #right(chr(32) * flen + str(linecount), flen) + "" def wr(p): global buf buf += [p + "\n"] ####color(11, None) ; print proginf; color(7, None) ; print addtoout = [0] addto = [0] addtoout[0] = "" addtoout += [0] ; addto += [0] addtoout[1] = "" addtoout += [0] ; addto += [0] addtoout[2] = "" addtoout += [0] ; addto += [0] addtoout[3] = "" addtoout += [0] ; addto += [0] # -2: print(variable, etc) # -1: print(variable), 0: variable = int(variable), 1: variable=left(variable, etc) cmds = {"ltrim":0, "lineinput":0, "len":0, "asc":0, "atn":0, "str":0, "get":1, "chr":0, "prints":-1, "sleep":-2, "arrsort":-1, "arreverse":-1, "reverse":0, "display":-1, "system":-1, "end":-1, "print":-1, "arrset":-3, "split":2, "left":1, "join":2, "arrget":2, "mid":2, "right":1, "plus":1, "times":1, "close":-1, "cls":-1, "flineinput":1, "fprint":-2, "open":-2, "arropen":1, "arrstdin":0, "arrcurl":1, "colortext":-2, "highlight":-2, "divby":1, "hex":0, "rtrim":0, "string":2, "timer":0, "command":0, "time":0, "date":0, "tan":0, "oct":0, "val":0, "minus":1, "lcase":0, "ucase":0, "int":0, "left":1, "swap":-3, "locate":-3, "pset":-4, "line":-6, "return":-2, "randint":2, "topwr":1, "arr":0, "mod":1, "cos":0, "not":0, "sin":0, "instr":2, "chdir":-1, "shell":-1, "arrshell":0, "sgn":0, "sqr":0} funcs = {"function" : -1, "iftrue" : -2, "ifequal" : -3, "ifless" : -3, "ifmore" : -3, "try":0, "except":0, "resume":0, "else":0} ufunc = {} #addfuncs = addtoout[0] + addtoout[1] + addtoout[3] + """ addfuncs = "" demo = """ p 7 arr times 5 x "hello, world!" #z x prints #z x print x 5 x 5 times 7 x 3 plus 5 times 7 abs z x abs x z str asc abs int function hello p | # function hello(p) x "hello, " | # x = "hello, " x prints return 5 | # print x; : hello = 5 : exit function fig | # end function x hello x | # x = hello(x) #x if 5```````````````` # if x = 5 then #p "five" print```````` # p = "five" : print p #else`````````````````` # else #p "not 5 or 7" print`` # p = "not 5 or 7" : print p #fig````````````````````# end if c command print #y x````````````````````# y = x #y chr 70 mid y 1 1```` # y = chr(70) : y = mid(y, 1, 1) #x print sleep 2 cls````# print x : sleep 2 : cls p print p print arrset 2 8 print z join p "(_)" print x z print p print end #p "hello, world!" left 5 ucase locate 5 7 prints # comment comment #y 100 chr rtrim print #z 32 chr print print print swap y p #x int plus 5 times 7 colortext 11 highlight 1 prints #y 32 highlight 0 colortext 14 chr prints #x 97 #y 97 plus 25 #for n x y 1 #for p x y 1 #for pp x y 1 #z n chr prints #z p chr prints #z pp chr prints #z 32 chr prints #next #z 32 chr print #next #next #while # y 10 print # these indents are optional, they don't do anything # iftrue y # break # this command breaks from while, never from if # fig # wend function pete p "hello" print fig function add5 r x get r plus 5 return x fig #z pete #y 12 #p z add5 y colortext 7 print sleep 1 function ppp z 32 chr print for p 1 100 1 x randint 0 3 y randint 0 3 c randint 1 9 #z pset x y c c colortext 7 next fig z ppp z sleep 1 #textmode z ppp sleep 2 z ppp """ p = "" try: p = right(sys.argv, 1)[0] except: pass if not ".fig" in p.lower(): if p.lower() == "help": #try: inputfile = stdin.read().replace(chr(13), "").split("\n") #except: #print "need an input file to do anything..."; print ; quit() quit() else: print "using built-in demo source, translating to demo.fig.py..." ; print p = "demo.fig" inputfile = demo.replace(chr(13), "").split("\n") else: try: inputfile = open(p).read().replace(chr(13) + chr(10), chr(10)).replace(chr(13), chr(10)).split(chr(10)) except: print "couldn't open." ; print ; quit() #try: outfile = open(p + ".py", "w") #except: print "couldn't write to \"" + p + ".py" "\", exiting." ; print ; quit() outname = p + ".py" flen = len(str(len(inputfile))) linecount = 0 indent = 0 inlinep = 0 inle = 0 errorin = 0 errorsrc = "" error = "" mode = 0 figraphics = -1 # -1 = uninitialized, 0 = textmode, 1 = initialized vrs = [] vr = "" outb = [] ingfx = 0 linesoutc = 0 for p in inputfile: linecount += 1 ; vrop = 0 ; vrcl = 0 if linecount == 1: #outfile.write("#!/usr/bin/env python" + "\n# encoding: utf-8\n") if "," in proginf: pass # outfile.write("# fig translator version: " + proginf.split(",")[0] + "\n") if inlinep: if p.lower().strip() == "fig": inlinep = 0 print lc() + p indent = atleast(0, indent - 4) else: print lc() + color(2, None) + p + color(7, None) #% write copied lines of inline python outfilewrite(outb, chr(32) * atleast(0, indent - 4) + leftfour(p) + "\n") elif mode == "output the following:": if p.lower().strip() == "display": mode = 0 print lc() + p else: wr(chr(32) * atleast(0, indent) + "print \"" + p.replace(chr(34), "\" + chr(34) + \"").replace(chr(92), "\" + chr(92) + \"") + "\"") print lc() + p.replace(chr(34), "\" + chr(34) + \"").replace(chr(92), "\" + chr(92) + \"") elif mode == 0: x = figfsplit(p.lstrip()) lp = p.lower() if not len(p): print lc() + "" #% write copied blank lines from inline python outfilewrite(outb, "\n") if len(p.lstrip()): e = 0 if p.lstrip()[0] == "#": if linecount == 1: es = 0 try: if p.lstrip()[1] == "!": es = 1 except: es = 0 if not es: wr(p) print lc(), figfsp(p) else: print lc() + "[this first comment isn't copied over]" es = 0 else: #% write comments #print color(14, 0) + p + color(7,0) ; znul = raw_input() #$ outfilewrite(outb, chr(32) * atleast(0, indent) + p + "\n") print lc(), figfsp(p) elif lnob(x, 0) == "figg": e = 2 elif lp.rstrip() == "python": indent += 4 inlinep = 1 print lc() + p else: if not lnob(x, 0) == "figg": if lnob(x, 0) != "fig" and not lnob(x, 0) in cmds.keys() and not lnob(x, 0) in funcs.keys() + ["forin", "for", "function", "nextin", "next", "while", "wend"] + ["break", "pass"]: if not lnob(x, 0) in vrs: vrs += [lnob(x, 0)[:]] # main vars, also func params, etc #% write variable #var: print color(14, 0) + "variable:" + lnob(x, 0) + color(7,0) ; znul = raw_input() #$ outfilewrite(outb, "\n") outfilewrite(outb, chr(32) * atleast(0, indent) + "figlist = 0\n") outfilewrite(outb, chr(32) * atleast(0, indent) + "try: figlist = int(type(" + lnob(x, 0) + ") == list)\n") outfilewrite(outb, chr(32) * atleast(0, indent) + "except NameError: pass\n") outfilewrite(outb, chr(32) * atleast(0, indent) + "if not figlist: " + lnob(x, 0) + " = 0 \n") if lnob(x, 0) == "fig": #print lc () + p #% write? its whitespace #$ indent = atleast(0, indent - 4) if lnob(x, 0) == "wend": #print lc () + p #% write? its whitespace #$ indent = atleast(0, indent - 4) if lnob(x, 0) == "next": #print lc () + p #% write? its whitespace #$ indent = atleast(0, indent - 4) if lnob(x, 0) == "nextin": #print lc () + p #% write? its whitespace #$ indent = atleast(0, indent - 4) if lnob(x, 0) == "try": #print lc () + p #% write try line #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "try:\n") indent = atleast(0, indent + 4) if lnob(x, 0) == "else": #print lc () + p #% write else line #$ outfilewrite(outb, chr(32) * atleast(0, indent - 4) + "else:\n") if lnob(x, 0) == "except": #print lc () + p indent = atleast(0, indent - 4) #% write except line #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "except:\n") indent = atleast(0, indent + 4) if lnob(x, 0) == "resume": #print lc () + p #% write? its whitespace #$ indent = atleast(0, indent - 4) if lnob(x, 0) == "while": #print lc () + p #% write simple loop #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "while 1:\n") indent += 4 if lnob(x, 0) == "function" and len(getmore(x, 1)) > 0: #print lc () + p mkf = [] funcname = getlmore(x, 1)[0] prm = 1 while 1: try: aprm = getlmore(x, 1)[prm] if len(aprm): if aprm[0] != "#": mkf += [aprm] if aprm not in vrs: vrs += [aprm[:]] prm += 1 except: break ufunc[funcname] = mkf[:] #; print ufunc # # #print ufunc #print len(ufunc[funcname]) #% write func def #$ print color(14,0)+ "def " + funcname + "(" + ", ".join(mkf) + "):" + color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + "def " + funcname + "(" + ", ".join(mkf) + "):\n") indent += 4 if lnob(x, 0) == "for" and len(getmore(x, 1)) == 4: #print lc () + p gmro = getlmore(x, 1)[0] gmrt = getlmore(x, 1)[1] gmrh = getlmore(x, 1)[2] gmrf = getlmore(x, 1)[3] if gmro not in vrs: vrs += [gmro[:]] if "." not in gmrf and (gmrf.strip()) not in ("0", "0.0", "-0") and "." not in gmrt and "." not in gmrh: #% write standard for loop #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "for " + gmro + " in range(int(float(" + gmrt + ")), int(float(" + gmrh + ")) + figsgn(" + gmrf + "), fignonz(int(float(" + gmrf + ")))):\n") else: #% write for loop that allows floating step #$ outfilewrite(outb, chr(32) * atleast(0, indent) + gmro + " = float(" + gmrt + ") - float(" + gmrf + ")\n" + chr(32) * atleast(0, indent) + "while 1:\n" + chr(32) * atleast(0, indent + 4) + gmro + " += float(" + gmrf + ")\n" + chr(32) * atleast(0, indent + 4) + "if " + gmrf + " > 0 and " + gmro + " > float(" + gmrh + "): break\n" + chr(32) * atleast(0, indent + 4) + "elif " + gmrf + " <= 0 and " + gmro + " < float(" + gmrh + "): break\n") indent += 4 if lnob(x, 0) == "forin" and len(getmore(x, 1)) == 2: #print lc () + p gmro = getlmore(x, 1)[0] gmrt = getlmore(x, 1)[1] if gmro not in vrs: vrs += [gmro[:]] #% write forin command with params #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "for " + gmro + " in " + gmrt + ":\n") indent += 4 if lnob(x, 0) == "break": #print lc () + p #% write break command #$ print outfilewrite(outb, chr(32) * atleast(0, indent) + "break\n") if lp.rstrip() == "graphics": ingfx = 1 #% write change to default mode (dont suppress gfx) #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "figraphics = -1\n") figraphics = -1 outfilewrite(outb, chr(32) * atleast(0, indent) + "figpset(0, -1, -1, 0)\n") #print lc () + p if lnob(x, 0) == "textmode": #print lc () + p addto[3] = 1 #% write change to text mode (suppress graphics) #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "figraphics = 0\n") outfilewrite(outb, chr(32) * atleast(0, indent) + "stopgraphics()\n") figraphics = 0 if lnob(x, 0) == "pass": #print lc () + p #% write pass command #$ print outfilewrite(outb, chr(32) * atleast(0, indent) + "pass\n") if lnob(x, 0) == "iftrue": #print lc () + p #% write iftrue #$ print color(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + "if " + snob(x, 1) + ":\n") ; indent += 4 if lnob(x, 0) == "ifequal" and len(getmore(x, 1)) == 2: #print lc () + p #% write ifequal #$ print color(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + "if " + snob(x, 1) + " == " + snob(x, 2) + ":\n") ; indent += 4 if lnob(x, 0) == "ifless" and len(getmore(x, 1)) == 2: #print lc () + p #% write ifless #$ print color(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + "if " + snob(x, 1) + " < " + snob(x, 2) + ":\n") ; indent += 4 if lnob(x, 0) == "ifmore" and len(getmore(x, 1)) == 2: #print lc () + p #% write ifmore #$ print color(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n") ; indent += 4 if lnob(x, 0) in cmds.keys(): # + ufunc.keys(): e = 4 ; shln = lnob(x, 0) if lnob(x, 0) != "fig" and lnob(x, 0) not in funcs.keys() + ["forin", "for", "function", "nextin", "next", "while", "wend"] + ["break", "pass"]: #print lc () + p vr = lnob(x, 0) #print vr, type(vr) #print getlmore(x, 1) prsc = 0 cstrctr = 0 csbuf = [] vrcs = "" for prs in getlmore(x, 1): #$ print prs if "fig" in prs: if prs[:3] == "fig": e = 2 ; break ; break if prs in funcs.keys(): e = 3 ; shln = prs prsc += 1 if cstrctr > 0: vrcs += prs cstrctr -= 1 if cstrctr == 0: if lnob(x, prsc - 1) == "return": #% write return command #$ print color(14,0) +vrcs + " ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + vrcs) elif lnob(x, prsc - 2) == "swap": vrcs = lnob(x, prsc - 1) + ", " + lnob(x, prsc - 0) + " = " + lnob(x, prsc - 0) + ", " + lnob(x, prsc - 1) #% write swap of 2 vars in python syntax #$ print color(14,0) +vrcs + " ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + vrcs + " ; ") else: if figprsbac in ufunc.keys(): #% write parametered func call #$ print color(14,0)+ vrcs + ") ; " + lnob(x, 0) + " = fignone(" + lnob(x, 0) + ", figbac) ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + vrcs + ") ; " + lnob(x, 0) + " = fignone(" + lnob(x, 0) + ", figbac) ; ") ; vrcl += 1 else: #% write builtin func call assignment #$ print color(14,0)+ vr + " = " + vrcs + ") ; " +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + vrcs + ") ; ") ; vrcl += 1 else: vrcs += ", " #; print "*" #if continue if prs.lower() in funcs.keys() + ["forin", "for", "function", "nextin", "next", "while", "wend"] + ["break", "pass"]: e = 3 figprsbac = None if cstrctr == 0: if not prs.lower() in vrs: if prs.lower()[0] in "abcdefghijklmnopqrstuvwxyz": if not prs.lower() in ufunc.keys(): if not prs.lower() in funcs.keys(): if not prs.lower() in cmds.keys(): e = 5 ; shln = prs if prs.lower() in vrs and cstrctr == 0: #and len(getmore(x, 1)) == 1: #% write lefthand variable assignment #$ print color(14,0)+ vr + " = " + prs.lower() +color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + vr + " = " + prs.lower() + "\n") if prs[0] == "\"": #% write string assignment (any place in shared line) outfilewrite(outb, chr(32) * atleast(0, indent) + vr + " = " + prs + " ; ") if prs[0] in ".1234567890-": #% write numerics outfilewrite(outb, chr(32) * atleast(0, indent) + vr + " = " + prs + " ; ") if prs[0] == "#": print ":)" + prs #% write trailing comments #$ print color(14, 0) + prs + color(7,0) outfilewrite(outb, prs + "\n") ; break if prs.lower() in ufunc.keys(): #% write pre-func-call var backup for sub-style behavior #$ print color(14, 0) + "figbac = " + lnob(x,0) + " ; " + color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + "figbac = " + lnob(x,0) + " ; " ) # ## figprsbac = prs.lower() cstrctr = len(ufunc[prs]) #print cstrctr if cstrctr == 0: #% write zero-param func/?sub call #$ print color(14, 0) + vr + " = " + prs.lower() + "() ; " + lnob(x, 0) + " = fignone(" + lnob(x, 0) + ", figbac) ; " + color(7,0) outfilewrite(outb, chr(32) * atleast(0, indent) + vr + " = " + prs.lower() + "() ; " + lnob(x, 0) + " = fignone(" + lnob(x, 0) + ", figbac) ; ") # # else: #print "y" vrop += 1 vrcs = vr + " = " + prs.lower() + "(" #$ print color(4, 0) + vr + " = " + prs.lower() + "(" + color(7,0) #$ #multiparameter if prs.lower() in cmds.keys(): if prs.lower() in ["display", "pset", "line"]: ingfx = 1 ##print prs cstrctr = cmds[prs] ##print cstrctr if cstrctr == -1: #% write zero-param subs #print color(14, 0) + "fig" + prs.lower() + "(" + vr #+ ") ; " + color(7,0) ; #znul = raw_input() #$ outfilewrite(outb, chr(32) * atleast(0, indent) + "fig" + prs.lower() + "(" + vr + ") ; " ) ; vrcl += 1 if cstrctr == 0: #% write zero-param functions #print color(14, 0) + vr + " = fig" + prs.lower() #+ "(" + vr + ") ; "+ color(7,0) ; #znul = raw_input() #$ outfilewrite(outb, chr(32) * atleast(0, indent) + vr + " = fig" + prs.lower() + "(" + vr + ") ; " ) ; vrcl += 1 if cstrctr < -1: if prs == "return": cstrctr = abs(cstrctr) - 1 vrcs = "return " #parameter else: cstrctr = abs(cstrctr) - 1 if prs == "swap": vrcs = "swap " else: vrop += 1 vrcs = "fig" + prs.lower() + "(" + vr vrcs += ", " #multiparameter else: vrop += 1 vrcs = vr + " = fig" + prs.lower() + "(" + vr vrcs += ", " #multiparameter if vrop == vrcl and e == 0: print "*"+figfsp(p) #% finish each line with lf outfilewrite(outb, "\n") else: print lc() + p else: e = 2 #vrck = len(outb) #try: # if "(" in vrcs and vrck == 0: # e = 1 #except: pass if e == 1: e = 0 if not len(error): error = "error: problem in command structure or details." errorin = linecount errorsrc = p print lc() + color(14, 0) + str(p) + color(7, 0) break if e == 2: e = 0 if not len(error): error = "error: cannot create variable or function beginning" error += " with \"fig\"" errorin = linecount errorsrc = p print lc() + color(14, 0) + p + color(7, 0) break if e == 3: e = 0 if not len(error): error = "error: single-line command \"" + shln + "\" not on own line" errorin = linecount errorsrc = p print lc() + color(14, 0) + p + color(7, 0) break if e == 4: e = 0 if not len(error): error = "error: shared-line function \"" error += shln + "\" cannot be used to start a line" errorin = linecount errorsrc = p print lc() + color(14, 0) + p + color(7, 0) break if e == 5: e = 0 if not len(error): error = "error: variable or function not created, but referenced... \"" error += shln + "\" needs to be set before first use" errorin = linecount errorsrc = p print lc() + color(14, 0) + p + color(7, 0) break if vrcl != vrop: e = 0 if not len(error): error = "error: a command has the wrong number of parameters." errorin = linecount errorsrc = p print lc() + color(14, 0) + str(p) + color(7, 0) break #for p in range(len(addtoout)): # if addto[p]: outfilewrite(outb, addtoout[p]) #for p in buf: # outfilewrite(outb, p) #if ingfx == 0: addtoout[3] = "" #outfile.write(addtoout[0] + addtoout[1] + addtoout[3] + addfuncs) #for outsb in outb: outfile.write(outsb) #outfile.close() print if errorin: print error ; color(14, None) ; print "error in line " + str(errorin) + ":" color(7, None) print errorsrc #from os import system as stf ; p = stf("touch e") else: #try: os.system("chmod +x \"" + outname + "\"") #except: pass print "translation complete." #, ; color(7, None) #print "here's a python script you can run: ", #print color(11, None) + outname + color(7, None) print ``` license: 0-clause bsd ``` # 2017 mn # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ``` => https://freesoftwareresistance.neocities.org