123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619 |
- #!/usr/bin/env python
- # coding: utf-8
- #### license: creative commons cc0 1.0 (public domain)
- #### http://creativecommons.org/publicdomain/zero/1.0/
- proginf = "alex 2.9, mar 2019 mn"
- try: import readline
- except: p = 0
- import sys
- import os
- from datetime import datetime
- from hashlib import sha256
- from sys import stdin, stdout
- from os import popen
- from os import name as alexosname
- if alexosname == "nt":
- try: from colorama import init ; init()
- except: pass
- try: from sys import exit as quit
- except: pass
- cmdhelp = [("timer", "input (shared-line) change main variable to number of seconds past midnight")
- ,("arrstdin", "input (shared-line) change main variable to array containing lines of stdin")
- ,("flineinput filepath", "input (shared-line) change main var to string of line from open file filepath")
- ,("arropen filepath", "input (shared-line) change main variable to array of file lines in filepath")
- ,("arrcurl url", "input (shared-line) like arropen, except downloading url into the array")
- ,("sleep seconds", "input (shared-line) wait for number of seconds before continuing with program")
- ,("command", "input (shared-line) change main variable to array of command line parameters")
- ,("print", "output (shared-line) output main variable to the screen (aka stdout)")
- ,("prints", "output (shared-line) put main var to screen; like print but (s)tays on line.")
- ,("fprint filepath", "output (shared-line) write main variable to open file designated by filepath")
- ,("while", "loop --\\own\\line mark the start of a loop (will keep going without break)")
- ,("break", "loop --\\own\\line put in the middle of a loop to exit (stop looping)")
- ,("for var strt stop step", "loop --\\own\\line start a for loop, changing var from strt to stop, by step")
- ,("forin var array", "loop --\\own\\line loop through each item in array; for each, set var to item")
- ,("iftrue ckvar", "conditional --\\own\\line run lines between iftrue and fig if ckvar is \"non-zero\"")
- ,("ifequal var1 var2", "conditional --\\own\\line run lines between ifequal and fig if var1 equals var2")
- ,("ifmore var1 var2", "conditional --\\own\\line run lines between ifmore and fig if var1 is > var2")
- ,("ifless var1 var2", "conditional --\\own\\line run lines between ifless and fig if var1 is < var2")
- ,("try", "conditional --\\own\\line put code that might not work between try and except")
- ,("except", "conditional --\\own\\line if code between try/except fails, run the code after except")
- ,("resume", "conditional --\\own\\line mark the end of try / except / resume command block")
- ,("else", "conditional --\\own\\line after if- line, before fig. run lines if condition isnt true")
- ,("function name p1 p2 …", "function --\\own\\line define function named name with optional params p1,p2, etc")
- ,("get parametername", "function (shared-line) (no longer required) copy parametername value to main var")
- ,("python", "function --\\own\\line put inline python code between lines python and fig")
- ,("fig/next/nextin/wend", "fig (interchangeable) function --\\own\\line finalise a block (started by if/while/function/for/forin")
- ,("pass", "function --\\own\\line blocks (for/next, etc) require something inside lines; pass works / does nothing")
- ,("lcase", "function (shared-line) change main variable to all-lower-case copy of own value")
- ,("ucase", "function (shared-line) change main variable to all-upper-case copy of own value")
- ,("str", "function (shared-line) convert main variable from number to string")
- ,("asc", "function (shared-line) change main variable from string to ascii code of 1st char")
- ,("val", "function (shared-line) change main variable from string to numeric (int if whole)")
- ,("len", "function (shared-line) change main variable to numeric length of main var")
- ,("not", "function (shared-line) change main variable to zero if non-zero; or -1 if zero")
- ,("ltrim", "function (shared-line) strip whitespace from left side of main variable")
- ,("rtrim", "function (shared-line) strip whitespace from right side of main variable")
- ,("chr", "function (shared-line) change main variable from numeric to ascii/uni string")
- ,("arrshell", "function (shared-line) change main var to array of shell output (from main var)")
- ,("arreverse", "function (shared-line) change main variable from array to reverse order of array")
- ,("reverse", "function (shared-line) like arreverse (which might be faster for array) for strings")
- ,("arrsort", "function (shared-line) change main variable from array to sorted array")
- ,("#", "comment (can\\share) place at beginning (or end) of line, prior to a comment")
- ,("():;|=,. ( ) : ; | = , .", "optional (shared-line) use in a shared line (and some others) for aesthetics/notation")
- ,("left numofcharsoritems", "function (shared-line) change main variable to __ leftmost group of chars/items")
- ,("right numofchrsoritems", "function (shared-line) change main variable to __ rightmost group of chars/items")
- ,("arrget array position", "function (shared-line) change main variable to position-th item from array")
- ,("arrset position setto", "function (shared-line) change item in array in main variable to value of setto")
- ,("mid position len", "function (shared-line) change main variable to range of len items from position")
- ,("string len asciiorstr", "function (shared-line) change main variable to len instances of asciiorstr")
- ,("split string splitby", "function (shared-line) split string by separator splitby into array, to main var")
- ,("join array usestring", "function (shared-line) change main var to string by joining array using usestring")
- ,("instr lookin lookfor", "function (shared-line) change main var to numeric position of lookfor in lookin")
- ,("chdir", "function (shared-line) change current folder to path string from main variable")
- ,("system", "function (shared-line) put on (usually at the end of) a line to stop the program")
- ,("close", "function (shared-line) close the open file designated by main variable")
- ,("end", "function (shared-line) interchangeable with system which ends the program")
- ,("open mode", "function (shared-line) open file at filepath main variable in mode \"r\" or \"w\"")
- ,("return var", "function (shared-line) (optional) exit current function, returning value var")
- ,("swap var1 var2", "function (shared-line) change contents of var1 to contents of var2 and vice-versa")
- ,("plus numstrarr", "math (shared-line) change main variable to itself plus num or string or arr")
- ,("minus numeric", "math (shared-line) change main variable to itself minus numeric")
- ,("divby numeric", "math (shared-line) change main variable to itself divided by numeric")
- ,("times numeric", "math (shared-line) change main variable to itself times numeric")
- ,("oct", "math (shared-line) change main variable from numeric decimal to octal")
- ,("atn", "math (shared-line) change numeric main variable to its arctangent")
- ,("int", "math (shared-line) change main variable from decimal (aka \"float\") to integer")
- ,("sgn", "math (shared-line) change main variable to 0 if 0, to -1 if < 0, or 1 if > 0.")
- ,("sqr", "math (shared-line) change main variable to square root of itself")
- ,("mod denominator", "math (shared-line) change main variable to: main var modulus denominator")
- ,("topwr n", "math (shared-line) raise numeric main variable to n-th power")
- ,("randint smallst largst", "input (shared-line) change main var to random number from smallst to largst")
- ,("arr", "function (shared-line) change main var to array (starting with same contents)") ]
- def chelp(f):
- ck = 0 ; print ""
- for p in cmdhelp:
- rcmd = p[0]
- if f in rcmd.split()[0]:
- ck = 1
- rd = p[1].split()
- rcat = rd[0] ; rd.remove(rd[0])
- rt = rd[0] ; rd.remove(rd[0])
- cde = rcmd.split(" ")
- print ""
- stdout.write(" " + colour(14,0)+ cde[0])
- cda = cde.remove(cde[0])
- for c in cde:
- stdout.write(" " + colour(0, 7)+ " " + c + " " + colour(7,0)+" ") ; stdout.flush()
- print ""
- print ""
- print colour(3,0) + " category:", rcat, rt.replace("\\", " ")
- print ""
- print " " + colour(7,0) + " ".join(rd)
- print ""
- colour(7,0);
- return ck
- def outfilewrite(outb, p):
- outb += [p]
- #global vrck
- #vrck += p.strip()
- #if inle: print colour(5, 0) + p.rstrip() ; p=raw_input() ; quit()
- def colour(f, b):
- if f == None: f = 0
- if b == None: b = 0
- n = "0"
- if f > 7: n = "1" ; f = f - 8
- if f == 1: f = 4 ## switch ansi colours for qb colours
- elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc.
- if f == 3: f = 6
- elif f == 6: f = 3
- if b > 7: b = b - 8
- if b == 1: b = 4
- elif b == 4: b = 1
- if b == 3: b = 6
- elif b == 6: b = 3
- #stdout.write("\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m")
- return 0 #return "\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m"
- def bcolour(b):
- f = None
- if f == None: f = 0
- if b == None: b = 0
- n = "0"
- if f > 7: n = "1" ; f = f - 8
- if f == 1: f = 4 ## switch ansi colours for qb colours
- elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc.
- if f == 3: f = 6
- elif f == 6: f = 3
- if b > 7: b = b - 8
- if b == 1: b = 4
- elif b == 4: b = 1
- if b == 3: b = 6
- elif b == 6: b = 3
- #stdout.write("\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m")
- return 0 # "\x1b[" + n + str(40+b) + "m"
- 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 alexatleast(s, p):
- if p < s: return s
- else: return p
- def alexfsp(p):
- pp = "" ; flg = 0
- fsp = alexfsplit(p)
- for fp in enumerate(fsp):
- if flg == 0 and fp[1] in cmds.keys():
- pp += colour(8,0) + "_" + colour(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 += colour(8,0) + "_" + colour(7,0) + " "
- return pp.rstrip().replace(colour(8,0) + "_" + colour(7,0) + " " + colour(8,0) +
- "_" + colour(7,0), colour(8,0) + "__" + colour(7,0)).replace(colour(8,0) + "_" +
- colour(7,0),colour(8,0) + "__" + colour(7,0))
- def alexfsplit(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 wr(p):
- buf = [p + "\n"]
- addtoout = [0]
- addto = [0]
- addtoout[0] = ""
- import sys, os
- from sys import stdin, stdout
- from sys import argv as alexargv
- #try: from colorama import init ; init()
- #except: pass # (only) windows users want colorama installed or ansi.sys enabled
- try: from sys import exit as quit
- except: pass
- from random import randint
- from time import sleep
- from os import chdir as alexoch
- from os import popen as alexpo
- from os import system as alexsh
- alexsysteme = 0
- alexfilehandles = {}
- alexfilecounters = {}
- def alexnonz(p, n=None):
- if n==None:
- if p == 0: return 1
- else:
- if p == 0: return n
- return p
- addtoout += [0] ; addto += [0]
- addtoout[1] = """from sys import stdout
- def alexlocate(x, l = "ignore", c = "ignore"):
- import sys
- if l == "ignore" and c == "ignore": pass
- # do nothing. want it to return an error?
- elif l < 1 and c != "ignore":
- sys.stdout.write("\x1b[" + str(c) + "G") # not ansi.sys compatible
- elif l != "ignore" and c == "ignore":
- sys.stdout.write("\x1b[" + str(l) + ";" + str(1) + "H")
- else: sys.stdout.write("\x1b[" + str(l) + ";" + str(c) + "H")
- stdout.flush()
- import time
- figbac = None
- figprsbac = None
- sub = None
- def alexnone(p, alexbac):
- if p == None: return alexbac
- return p
- return -1
- def stopgraphics():
- global yourscreen
- global alexraphics
- alexraphics = 0
- try: pygame.quit()
- except: pass\n
- \n"""
- addtoout += [0] ; addto += [0]
- addtoout[2] = ""
- figraphics = -1
- figrupd = 1
- try: import pygame
- except: alexraphics = 0
- yourscreen = ""
- try: pygame.init()
- except: alexraphics = 0 # unable to init pygame, just use text
- def alexlocate(x, l = "ignore", c = "ignore"):
- import sys
- if l == "ignore" and c == "ignore": pass
- # do nothing. want it to return an error?
- elif l < 1 and c != "ignore":
- sys.stdout.write("\x1b[" + str(c) + "G") # not ansi.sys compatible
- elif l != "ignore" and c == "ignore":
- sys.stdout.write("\x1b[" + str(l) + ";" + str(1) + "H")
- else: sys.stdout.write("\x1b[" + str(l) + ";" + str(c) + "H")
- def alexpset(x, y, c):
- global alexcgapal
- if "alexraphics" != "":
- if x > -1 and y > -1:
- alexcolourtext(c)
- alexlocate(0, int(y) + 1, int(x) + 1) ; stdout.write(unichr(9608))
- sys.stdout.flush()
- def alexline(x, y, x2, y2, c):
- x = int(x)
- y = int(y)
- x2 = int(x2)
- y2 = int(y2)
- c = int(c)
- if "alexraphics" != "":
- if x > -1 and y > -1 and x2 > -1 and y2 > -1:
- alexcolourtext(c)
- if x2 < x: x, y, x2, y2 = x2, y2, x, y
- alexliney = [y, y2]
- alexlinec = 0
- alexlinestep = int(y2 - y)
- if alexlinestep < 0: alexlinestep = int(y - y2) ; alexlinec = 0
- if alexlinestep < 1: alexlinestep = 1
- alexlinestep = float(1) / alexlinestep
- alexlinex = x
- while 1:
- if alexlinex > x2: break
- if y2 - y == 0:
- alexlocate(0, int(y) + 1, int(alexlinex) + 1)
- stdout.write(unichr(9608))
- elif y2 < y:
- alexlinec -= alexlinestep
- alexlocate(0, int(y + int(float(y - y2) / alexnonz(x2 - x,.1) *
- alexnonz(alexlinec,.1) ) ) + 1, int(alexlinex) + 1)
- stdout.write(unichr(9608))
- else:
- alexlocate(0, int(y + int(float(y2 - y) / alexnonz(x2 - x,.1) *
- alexnonz ( alexlinec,.1) ) ) + 1, int(alexlinex) + 1) ;
- stdout.write(unichr(9608))
- alexlinec += alexlinestep
- alexlinex += alexlinestep
- alexlocate(0, int(y) + 1, int(x) + 1) ; stdout.write(unichr(9608))
- alexlocate(0, int(y2) + 1, int(x2) + 1) ; stdout.write(unichr(9608))
- sys.stdout.flush()
- 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, "colourtext":-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,
- "sin":0, "instr":2, "chdir":-1, "shell":-1, "arrshell":0, "colortext":-2,
- "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 = ""
- def alexcolortext(f, b):
- if f == None: f = 0
- if b == None: b = 0
- n = "0"
- if f > 7: n = "1" ; f = f - 8
- if f == 1: f = 4 ## switch ansi colours for qb colours
- elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc.
- if f == 3: f = 6
- elif f == 6: f = 3
- if b > 7: b = b - 8
- if b == 1: b = 4
- elif b == 4: b = 1
- if b == 3: b = 6
- elif b == 6: b = 3
- stdout.write(chr(27) + "[" + n + ";" + str(30+f) + ";" + str(40+b) + "m") ; stdout.flush()
- return "\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m"
- def alexcolourtext(f):
- b = 0
- if f == None: f = 0
- if b == None: b = 0
- n = "0"
- if f > 7: n = "1" ; f = f - 8
- if f == 1: f = 4 ## switch ansi colours for qb colours
- elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc.
- if f == 3: f = 6
- elif f == 6: f = 3
- if b > 7: b = b - 8
- if b == 1: b = 4
- elif b == 4: b = 1
- if b == 3: b = 6
- elif b == 6: b = 3
- stdout.write("\x1b[" + n + ";" + str(30+f) + "m") ; stdout.flush()
- return "\x1b[" + n + ";" + str(30+f) + ";" + str(40+b) + "m"
- figcgapal = [(0, 0, 0), (0, 0, 170), (0, 170, 0), (0, 170, 170),
- (170, 0, 0), (170, 0, 170), (170, 85, 0), (170, 170, 170),
- (85, 85, 85), (85, 85, 255), (85, 255, 85), (85, 255, 255),
- (255, 85, 85), (255, 85, 255), (255, 255, 85), (255, 255, 255)]
- def alexget(p, s): return s
- def alexhighlight(x, b):
- f = None
- if f == None: f = 0
- if b == None: b = 0
- n = "0"
- if f > 7: n = "1" ; f = f - 8
- if f == 1: f = 4 ## switch ansi colours for qb colours
- elif f == 4: f = 1 ## 1 = blue not red, 4 = red not blue, etc.
- if f == 3: f = 6
- elif f == 6: f = 3
- if b > 7: b = b - 8
- if b == 1: b = 4
- elif b == 4: b = 1
- if b == 3: b = 6
- elif b == 6: b = 3
- #stdout.write("\\x1b[" + n + str(40+b) + "m") ; stdout.flush()
- #return "\\x1b[" + n + str(40+b) + "m"
- def alexinstr(p, e):
- try: return p.index(e) + 1
- except: return 0
- def alexchdir(p):
- try: alexoch(p)
- except: print "no such file or directory: " + str(p) ; alexend(1)
- def alexshell(p):
- global alexsysteme
- try: alexsysteme = alexsh(p)
- except:
- print "error running shell command: " + chr(34) + str(p) + chr(34)
- alexend(1)
- def alexarrshell(c):
- global alexsysteme
- try:
- alexsysteme = 0
- sh = alexpo(c)
- ps = sh.read().replace(chr(13) + chr(10),
- chr(10)).replace(chr(13), chr(10)).split(chr(10))
- alexsysteme = sh.close()
- except:
- print "error running arrshell command: " + chr(34) + str(c) + chr(34)
- alexend(1)
- return ps[:]
- def alexvarproc(c):
- if c[-1] == "": c = c[:-1]
- if type(c) == list and len(c) == 1: c = c[0]
- return c
- def alexsgn(p):
- p = float(p)
- if p > 0: return 1
- if p < 0: return -1
- return 0
- def alexstr(p): return str(p)
- def alexprint(p): print p
- def alexfws(p):
- c = ""
- for t in p:
- if ord(t) > 32 and ord(t) < 127:
- c += t
- return c
- def alexchr(p):
- if type(p) == str:
- if len(p) > 0:
- return p[0]
- return chr(p)
- def alexprints(p): stdout.write(str(p)) ; sys.stdout.flush()
- def alexleft(p, s): return p[:s]
- def alexmid(p, s, x):
- arr = 0
- if type(p) == list or type(p) == tuple: arr = 1
- rt = p[s - 1:x + s - 1]
- if arr and len(rt) == 1: rt = rt[0]
- return rt
- def alextops(p, s):
- if type(p) == list:
- return p[:s]
- else:
- return p
- def alexbots(p, s):
- if type(p) == list:
- return p[-s:]
- else:
- return p
- def alexright(p, s): return p[-s:]
- def alexrandint(s, f):
- return randint(int(s), int(f))
- def alexlcase(p): return p.lower()
- def alexucase(p): return p.upper()
- def alexint(p): return int(p)
- def alexarrset(x, p, s):
- if 1:
- #if type(p) == str: p = p + s # str(s) if you want it easier
- if 1: #type(p) == list:
- if type(s) == tuple:
- if len(s) == 1: fas = s[0]
- elif type(s) == list:
- if len(s) == 1: fas = s[0]
- else:
- fas = s
- x[p - 1] = s
- def alexopen(x, s):
- import fileinput
- if s.lower() == "w":
- if (x) not in alexfilehandles.keys():
- alexfilehandles[x] = open(x[:], s.lower())
- elif s.lower() == "r":
- if (x) not in alexfilehandles.keys():
- alexfilehandles[x] = fileinput.input(x[:])
- alexfilecounters[x] = 0
- else:
- if (x) not in alexfilehandles.keys(): alexfilehandles[x] = open(x[:], s[:])
- def alexfprint(x, s):
- fon = alexosname
- sep = chr(10)
- if fon == "nt": sep = chr(13) + chr(10)
- alexfilehandles[s].write(str(x) + sep)
- def alexflineinput(s):
- try:
- p = alexfilehandles[s][alexfilecounters[s]].replace(chr(13),
- "").replace(chr(10), "")
- alexfilecounters[s] += 1
- except:
- p = chr(10)
- return p
- def alexclose(x):
- if (x) in alexfilehandles.keys():
- alexfilehandles[x].close() ; del alexfilehandles[x]
- try: del alexfilecounters[x]
- except: pass
- #def alexcls(x):
- # if alexosname == "nt": cls = alexsh("cls")
- # else: stdout.write("\x1b[2J\x1b[1;1H") ; sys.stdout.flush()
- def alexarropen(s):
- x = open(s).read().replace(chr(13) + chr(10), chr(10)).replace(chr(13),
- chr(10)).split(chr(10))
- return x[:]
- def alexarrcurl(x, s):
- from urllib import urlopen
- if x.lower() == "-a":
- try:
- c = str(urlopen(s).read()) ; c = c.replace(chr(13) + chr(10),
- chr(10)).replace(chr(13), chr(10)).split(chr(10))
- except:
- c = [""]
- else:
- try:
- c = str(urlopen(s).read())
- except:
- c = ""
- return c[:]
- def alexdequote(p):
- if len(p) > 2:
- if p[0] == chr(34) and p[-1] == chr(34):
- p = p[1:]
- p = p[:-1]
- return p
- def alexarrstdin():
- ps = []
- for textlines in stdin:
- p = textlines[:]
- if p:
- if p[-1] != chr(10):
- p += chr(10)
- if alexosname == "nt":
- ps += [alexdequote(p[:-1].strip())]
- else:
- ps += [p[:-1]]
- return ps[:]
- def alexarrget(p, s):
- if 1:
- return p[s - 1]
- def alexplus(p, s):
- if type(p) in (float, int):
- if type(s) in (float, int):
- p = p + s
- else:
- p = p + s # float(s) if you want it easier
- if p == float(int(p)): p = int(p)
- else:
- if type(p) == str: p = p + s # str(s) if you want it easier
- if type(p) == list:
- if type(s) == tuple:
- p = p + list(s)
- elif type(s) == list:
- p = p + s[:]
- else:
- p = p + [s]
- if type(p) == tuple:
- if type(s) == tuple:
- p = tuple(list(p) + list(s))
- elif type(s) == list:
- p = tuple(list(p) + s[:])
- else:
- p = tuple(list(p) + [s])
- return p
- def alexpadleft(p, s, c=7):
- if type(c) == int:
- c = (c, 0)
- else:
- c = c.split()
- return alexcolortext(int(c[0]), int(c[1])) + (" " * s + str(p))[-s:] + alexcolortext(7, 0)
- def alexpadright(p, s, c="5 0"):
- if type(c) == int:
- c = (c, 0)
- else:
- c = c.split()
- return alexcolortext(int(c[0]), int(c[1])) + (str(p) + " " * s)[:s] + alexcolortext(7, 0)
- def alexprintlinedc(p, s):
- try:
- searchdate = p.split()[0]
- printline = int(s and s in searchdate)
- return printline
- except:
- return 1
- def alexcolourdc(c, f="p"):
- if type(c) != int: c = c.lower()
- if c in [0]:
- return "9 0"
- cb = "0"
- if len(f.split()) > 1:
- cb = "1"
- if c in [2, ".bat", ".com", ".exe"]:
- return "10 " + cb
- if c in [1, ".lnk"]:
- return "11 " + cb
- if c in [".tgz", ".tar.gz", ".gz", ".zip", ".7z"]:
- return "4 " + cb
- if c in [".fig", ".alex", ".py", ".fig.py", ".rose"]:
- return "2 " + cb
- if c in [".ogg", ".mp4", ".mpeg", ".mpg", ".mp3", ".webm", ".odt", ".odp", ".pdf"]:
- return "3 " + cb
- if c in ["."]:
- return "8 " + cb
- if c in [".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pgm", ".ppm", ".tga", ".xbm", ".xpm", ".tif", ".tiff", ".png", ".svg", ".svgz", ".mng", ".pcx", ".mov", ".mpg", ".mpeg", ".m2v", ".mkv", ".ogm", ".m4v", ".mp4v", ".vob", ".flc", ".avi", ".fli", ".flv", ".gl", ".dl", ".xcf", ".xwd", ".yuv", ".cgm", ".emf", ".ogv"]:
- return "13 " + cb
- if c in [".htm", ".html", ".txt", ".js", ".php"]:
- return "14 " + cb
- return "7 " + cb
- def alexjoin(x, s):
- t = ""
- if len(x) : t = str(x[0])
- for c in range(len(x)):
- if c > 0: t += str(s) + str(x[c])
- return t # s.join(x)
- def alexarr(p):
- if type(p) in (float, int, str):
- p = [p]
- else:
- p = list(p)
- return p
- def alexsplit(x, s):
- return x.split(s)
- def alexval(n):
- n = float(n)
- if float(int(n)) == float(n): n = int(n)
- return n
- def alextimes(p, s):
- if type(p) in (float, int):
- p = p * s # float(s) if you want it easier
- if p == float(int(p)): p = int(p)
- else:
- if type(p) == list:
- p = p[:] * s # alexval(s)
- else:
- p = p * s # alexval(s) if you want it easer
- return p
- def alexdivby(p, s):
- p = float(p) / s
- if p == float(int(p)): p = int(p)
- return p
- def alexminus(p, s): return p - s
- def alextopwr(p, s):
- p = p ** s
- if p == float(int(p)): p = int(p)
- return p
- def alexmod(p, s):
- return p % s
- def alexcos(p):
- from math import cos ; p = cos(p)
- if p == float(int(p)): p = int(p)
- return p
- def alexsin(p):
- from math import sin ; p = sin(p)
- if p == float(int(p)): p = int(p)
- return p
- def alexsqr(p):
- from math import sqrt ; p = sqrt(p)
- if p == float(int(p)): p = int(p)
- return p
- def alexltrim(p): return p.lstrip()
- def alexlineinput(p):
- p = raw_input()
- if alexosname == "nt":
- p = alexdequote(p.strip())
- return p
- def alexlen(p): return len(p)
- def alexasc(p): return ord(p[0])
- def alexatn(p):
- from math import atan ; p = atan(p)
- if p == float(int(p)): p = int(p)
- return p
- def alexhex(p): return hex(p)
- def alexrtrim(p): return p.rstrip()
- def alexstring(x, p, n):
- if type(n) == str: return n * p
- return chr(n) * p
- def alextimer(p):
- from time import strftime
- return int(strftime("%H"))*60*60+int(strftime("%M"))*60+int(strftime("%S"))
- def alextime(p): from time import strftime ; return strftime("%H:%M:%S")
- def alexdate(p): from time import strftime ; return strftime("%m/%d/%Y")
- def alexcommand(p): return alexargv[1:]
- def alextan(p):
- from math import tan ; p = tan(p)
- if p == float(int(p)): p = int(p)
- return p
- def alexoct(p): return oct(p)
- def alexsleep(s):
- sleep(s)
- def alexarrsort(p):
- p.sort()
- def alexdisplay(x):
- global alexraphics, alexrupd
- alexrupd = 0
- if alexraphics == 1:
- pygame.display.update()
- def alexreverse(p):
- if type(p) == list: p.reverse() ; return p
- elif type(p) == str:
- p = map(str, p) ; p.reverse()
- p = "".join(p)
- return p
- def alexarreverse(p):
- p.reverse()
- def alexfunction(p, s): return p
- def alexend(x): quit()
- def alexif(p, s): return p
- def alexthen(p, s): return p
- def alexsystem(x): quit()
- demo = """
- p 7 arr times 5
- x "hello, world!"
- x 5
- x 5 times 7
- x 3 plus 5 times 7
- abs
- z x abs
- x z str asc abs int
- c command print
- p print
- p print arrset 2 8 print
- z join p "(_)" print
- x z print
- p print end
- function add5 r
- x get r plus 5 return x
- fig
- function ppp
- z 32 chr print
- for p 1 100 1
- x randint 0 3
- y randint 0 3
- c randint 1 9
- c colourtext 7
- next
- fig
- z ppp
- z sleep 1
- 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":
- stdout.write("\n type (any) part of the command you want help on." +
- "\n\n alex will show all matches.\n\n\n ")
- helpf = chelp(raw_input())
- if not helpf: print(colour(14,0)+"\n no commands match your search.") ; print("")
- #colour(7,0)
- quit()
- else:
- 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: p = 0
- #try: outfile = open(p + ".py", "w")
- #except: print "couldn't write to \"" + p + ".py" "\", exiting." ; print ; quit()
- outname = ".py"
- inputfile = ""
- flen = len(str(len(inputfile)))
- linecount = 0
- indent = 0
- inlinep = 0
- inle = 0
- errorin = 0
- errorsrc = ""
- error = ""
- mode = 0
- figraphics = -1 # -1 = uninitialised, 0 = textmode, 1 = initialised
- 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:
- #outfile.write("# alex translator version: " + proginf.split(",")[0] + "\n")
- if inlinep:
- if p.lower().strip() == "fig":
- inlinep = 0
- #print lc() + p
- indent = alexatleast(0, indent - 4)
- else:
- #print lc() + colour(2, None) + p + colour(7, None)
- #% write copied lines of inline python
- outfilewrite(outb, chr(32) * alexatleast(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) * alexatleast(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 = alexfsplit(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(), alexfsp(p)
- #else: print lc() + "[this first comment isn't copied over]"
- es = 0
- else:
- #% write comments
- #print colour(14, 0) + p + colour(7,0) ; znul = raw_input() #$
- outfilewrite(outb, chr(32) * alexatleast(0, indent) + p + "\n")
- #print lc(), alexfsp(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 colour(14, 0) + "variable:" + lnob(x, 0) + colour(7,0) ; znul = raw_input() #$
- outfilewrite(outb, "\n")
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "figlist = 0\n")
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "try: alexlist = int(type(" + lnob(x, 0) + ") == list)\n")
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "except NameError: pass\n")
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "if not alexlist: " + lnob(x, 0) + " = 0 \n")
- if lnob(x, 0) == "fig":
- #print lc () + p
- #% write? its whitespace
- indent = alexatleast(0, indent - 4)
- if lnob(x, 0) == "wend":
- #print lc () + p
- #% write? its whitespace
- indent = alexatleast(0, indent - 4)
- if lnob(x, 0) == "next":
- #print lc () + p
- #% write? its whitespace
- indent = alexatleast(0, indent - 4)
- if lnob(x, 0) == "nextin":
- #print lc () + p
- #% write? its whitespace
- indent = alexatleast(0, indent - 4)
- if lnob(x, 0) == "try":
- #print lc () + p
- #% write try line
- outfilewrite(outb, chr(32) * alexatleast(0, indent) + "try:\n")
- indent = alexatleast(0, indent + 4)
- if lnob(x, 0) == "else":
- #print lc () + p
- #% write else line
- outfilewrite(outb, chr(32) * alexatleast(0, indent - 4) +
- "else:\n")
- if lnob(x, 0) == "except":
- #print lc () + p
- indent = alexatleast(0, indent - 4)
- #% write except line
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "except:\n")
- indent = alexatleast(0, indent + 4)
- if lnob(x, 0) == "resume":
- #print lc () + p
- #% write? its whitespace
- #$
- indent = alexatleast(0, indent - 4)
- if lnob(x, 0) == "while":
- #print lc () + p
- #% write simple loop
- #$
- outfilewrite(outb, chr(32) * alexatleast(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 colour(14,0)+ "def " + funcname + "(" + ", ".join(mkf) + "):" + colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(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) * alexatleast(0, indent)
- + "for "
- + gmro + " in range(int(float(" + gmrt +
- ")), int(float(" + gmrh + ")) + alexsgn(" + gmrf +
- "), alexnonz(int(float(" + gmrf + ")))):\n")
- else:
- #% write for loop that allows floating step
- #$
- outfilewrite(outb, chr(32) * alexatleast(0, indent) + gmro
- + " = float(" + gmrt + ") - float(" + gmrf + ")\n" +
- chr(32) * alexatleast(0, indent) + "while 1:\n" + chr(32) *
- alexatleast(0, indent + 4) + gmro + " += float(" + gmrf +
- ")\n" + chr(32) * alexatleast(0, indent + 4) + "if " +
- gmrf +
- " > 0 and " + gmro + " > float(" + gmrh + "): break\n"
- + chr(32) * alexatleast(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) * alexatleast(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) *
- alexatleast(0, indent) + "break\n")
- if lp.rstrip() == "graphics":
- ingfx = 1
- #% write change to default mode (dont suppress gfx)
- #$
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "figraphics = -1\n")
- alexraphics = -1
- outfilewrite(outb, chr(32) * alexatleast(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) * alexatleast(0, indent) +
- "figraphics = 0\n")
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "stopgraphics()\n")
- alexraphics = 0
- if lnob(x, 0) == "pass":
- #print lc () + p
- #% write pass command
- #$ print
- outfilewrite(outb, chr(32) *
- alexatleast(0, indent) + "pass\n")
- if lnob(x, 0) == "iftrue":
- #print lc () + p
- #% write iftrue
- #$ print colour(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(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 colour(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(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 colour(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(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 colour(14,0) + "if " + snob(x, 1) + " > " + snob(x, 2) + ":\n"+ " ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(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 colour(14,0) +vrcs + " ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(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 colour(14,0) +vrcs + " ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(0,
- indent) + vrcs + " ; ")
- else:
- if alexprsbac in ufunc.keys():
- #% write parametered func call
- #$ print colour(14,0)+ vrcs + ") ; " + lnob(x, 0) + " = alexnone(" + lnob(x, 0) + ", alexbac) ; " +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(0,
- indent) + vrcs + ") ; " + lnob(x, 0) +
- " = alexnone(" + lnob(x, 0) +
- ", alexbac) ; ") ; vrcl += 1
- else:
- #% write builtin func call assignment
- #$ print colour(14,0)+ vr + " = " + vrcs + ") ; " +colour(7,0)
- outfilewrite(outb, chr(32) *
- alexatleast(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
- alexprsbac = 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 colour(14,0)+ vr + " = " + prs.lower() +colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- vr + " = " + prs.lower() + "\n")
- if prs[0] == "\"":
- #% write string assignment (any place in shared line)
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- vr + " = " + prs + " ; ")
- if prs[0] in ".1234567890-":
- #% write numerics
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- vr + " = " + prs + " ; ")
- if prs[0] == "#":
- #% write trailing comments #$ print colour(14, 0) + prs + colour(7,0)
- outfilewrite(outb, prs + "\n") ; break
- if prs.lower() in ufunc.keys():
- #% write pre-func-call var backup for sub-style behavior #$ print colour(14, 0) + "figbac = " + lnob(x,0) + " ; " + colour(7,0)
- outfilewrite(outb, chr(32) * alexatleast(0, indent) +
- "figbac = " + lnob(x,0) + " ; " ) # ##
- alexprsbac = prs.lower()
- cstrctr = len(ufunc[prs])
- #print cstrctr
- if cstrctr == 0:
- #% write zero-param func/?sub call
- #$ print colour(14, 0) + vr + " = " + prs.lower() + "() ; " + lnob(x, 0) + " = alexnone(" + lnob(x, 0) + ", alexbac) ; " + colour(7,0)
- outfilewrite(outb, chr(32) *
- alexatleast(0, indent) +
- vr + " = " + prs.lower() + "() ; " + lnob(x, 0) +
- " = alexnone(" + lnob(x, 0) + ", alexbac) ; ") # #
- else:
- #print "y"
- vrop += 1
- vrcs = vr + " = " + prs.lower() + "("
- #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
- outfilewrite(outb, chr(32) *
- alexatleast(0, indent) + "fig" +
- prs.lower() + "(" + vr + ") ; " ) ; vrcl += 1
- if cstrctr == 0:
- #% write zero-param functions
- outfilewrite(outb, chr(32) * alexatleast(0,
- indent) + vr +
- " = alex" + 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 + " = alex" + prs.lower() + "(" + vr
- vrcs += ", " #multiparameter
- #if vrop == vrcl and e == 0:
- #print lc(), alexfsp(p)
- #% finish each line with lf
- outfilewrite(outb, "\n")
- #else:
- #print lc() + p
- else:
- e = 2
- if e == 1:
- e = 0
- if not len(error):
- error = "error: problem in command structure or details."
- errorin = linecount
- errorsrc = p
- #print lc() + colour(14, 0) + str(p) + colour(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() + colour(14, 0) + p + colour(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() + colour(14, 0) + p + colour(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() + colour(14, 0) + p + colour(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() + colour(14, 0) + p + colour(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
- break
- try:
- sc = alexreverse(alexleft(alexreverse(alexargv[1]), 5).lower())
- if sc == ".alex": sc = alexarropen(alexargv[1])
- except: sc = ""
- if "--" not in " ".join(alexargv):
- if not sc: alexcolourtext(11) ; print proginf + chr(32),
- hist = os.path.join(os.path.expanduser("~"), ".alex_history")
- #if errorin:
- # print error ; colour(14, None) ; print "error in line " + str(errorin) + ":"
- # colour(7, None)
- # print errorsrc
- alexver = alexjoin(proginf.split(",")[0].split(" "), "").replace(".", "")
- arrdostart = ""
- nl = chr(10)
- if alexosname == "nt": nl = chr(13) + chr(10) ; arrdostart = "start /b /wait "
- def alexgetpsim(x, y):
- px = alexsplit(x, " ")
- py = alexsplit(y, " ")
- xlen = len(px)
- ylen = len(py)
- xc = 0
- yc = 0
- b = "" ;
- for p in px:
- c = alexinstr(py, p)
- if p == b:
- c = 0
- if c:
- now = xc
- now = alexplus(now, 1)
- now, xc = xc, now
- b = p
- xper = xc
- xper = alexdivby(xper, xlen)
- for p in py:
- c = alexinstr(px, p)
- if p == b:
- c = 0
- if c:
- now = yc
- now = alexplus(now, 1)
- now, yc = yc, now
- b = p
- yper = alexdivby(yc, ylen)
- now = alexplus(xper, yper)
- now = alexdivby(now, 2) * 100
- return now
- def ptrans(token, argu, alexhist, nl):
- global indent
- if token.lower() == "cd":
- if argu: argu = argu[0]
- if argu:
- if argu[0] == chr(34) and argu[-1] == chr(34) and len(argu) > 2: argu = argu[1:-1]
- argu = alexqesc(argu)
- return (chr(32) * alexatleast(0, indent) + "try: os.chdir(" + argu + ")" + nl +
- chr(32) * alexatleast(0, indent) + "except: print 'no such file or directory: ' + str(" + argu + ")" + nl)
- #; alexq(alexhist)
- elif token.lower() == "set":
- if argu: vname = argu[0] ; argu = argu[1]
- if argu and alexvalidvar(vname):
- if vname[0] == chr(34) and argu[-1] == chr(34) and len(argu) > 2: argu = argu[1:-1]
- argu = chr(34) + argu.replace(chr(34), chr(92) + chr(34)) + chr(34)
- return (chr(32) * alexatleast(0, indent) + vname + " = " + argu + nl)
- #; alexq(alexhist)
- elif token.lower() == "setrandint":
- if argu: vname = argu[0] ; argm = argu[1] ; argu = argu[2]
- if argu and alexvalidvar(vname):
- if vname[0] == chr(34) and argu[-1] == chr(34) and len(argu) > 2: argu = argu[1:-1]
- argu = chr(34) + argu.replace(chr(34), chr(92) + chr(34)) + chr(34)
- return (chr(32) * alexatleast(0, indent) + vname + " = str(alexrandint(" + str(argm) + ", " + str(argu) + "))" + nl)
- elif token.lower() == "setnum":
- if argu: vname = argu[0] ; argm = argu[1]
- if argm and alexvalidvar(vname):
- if vname[0] == chr(34) and argu[-1] == chr(34) and len(argu) > 2: argu = argu[1:-1]
- #argu = chr(34) + argu.replace(chr(34), chr(92) + chr(34)) + chr(34)
- return (chr(32) * alexatleast(0, indent) + vname + " = alexval(" + str(argm) + ")" + nl)
- elif token.lower() == "setadd":
- if argu: vname = argu[0] ; argm = argu[1] ; argu = argu[2]
- if argu and alexvalidvar(vname):
- if vname[0] == chr(34) and argu[-1] == chr(34) and len(argu) > 2: argu = argu[1:-1]
- #argu = chr(34) + argu.replace(chr(34), chr(92) + chr(34)) + chr(34)
- return (chr(32) * alexatleast(0, indent) + vname + " = str(" + str(argm) + " + " + str(argu) + ")" + nl)
- elif token.lower() == "setinput":
- if argu: vname = argu[0]
- if argu and alexvalidvar(vname):
- return (chr(32) * alexatleast(0, indent) + vname + " = raw_input()" + nl)
- #if token.lower() == "locate":
- # if argu: vname = argu[0] ; argu = argu[1]
- # if argu and vname:
- # return (chr(32) * alexatleast(0, indent) + "alexlocate(0, str(" + vname + "), str(" + argu + "))" + nl)
- elif token.lower() == "next":
- indent = alexatleast(0, indent -4)
- return (chr(32) * alexatleast(0, indent) + nl)
- elif token.lower() == "break":
- return (chr(32) * alexatleast(0, indent) + "break" + nl)
- elif token.lower() == "while":
- outwr = chr(32) * alexatleast(0, indent) + "while 1:" + nl
- indent += 4
- outwr += chr(32) * alexatleast(0, indent) + "try: sleep(.025)" + nl
- outwr += chr(32) * alexatleast(0, indent) + "except: break" + nl
- return outwr
- elif token.lower() == "forin":
- if argu: vname = argu[0] ; argm = argu[1]
- try:
- argm = int(argm) ; outwr = chr(32) * alexatleast(0, indent) + "for " + vname + " in range(1, " + str(argm) + " + 1):" + nl
- except:
- outwr = chr(32) * alexatleast(0, indent) + "for " + vname + " in " + argm + ":" + nl
- indent += 4
- #outwr += chr(32) * alexatleast(0, indent) + "try: sleep(.025)" + nl
- #outwr += chr(32) * alexatleast(0, indent) + "except: break" + nl
- return outwr
- x = 0
- try:
- if sys.argv[1] == "--help":
- print proginf ; x = 1
- print
- print "usage:"
- print
- print " alex run the alex line executive"
- print " or:"
- print " alex --help show this help information and exit"
- print
- print " sleep [n] pause for one second or [n] seconds"
- print " arrcurl [-a] url write contents of url as output"
- print " pserver run a mini http server using the current folder"
- print " locate row column change the cursor position"
- print " colour colour highlight change the text colours"
- print " cat file1 [file2] [-n] concatenate files and/or number all lines"
- print " set vname value set vname to value"
- print " setrandint vname min max set vname to a random number between min / max"
- print " setinput vname set vname to whatever is input from the keyboard"
- print " setnum vname num set vname to numeric num (variable or value)"
- print " setadd vname v1 v2 set vname to sum of v1 and v2 (string or numeric)"
- print " find | fsortplus find files, show size / sha256 / date / time"
- print " find | fsortplusnows fsortplus, but create hash without whitespace"
- print " find | dc [n] [d[srchdate]] [+/-szlimit] list name/size/time, colour by type"
- print
- print " | isoname text only show lines containing \"text\""
- print " | isoplus text only list files with lines containing \"text\""
- print " | minusname text remove lines containing \"text\""
- print " | isoleft text include if left equals text"
- print " | isoright text include if right equals text"
- print " | isonotleft text include if left != text"
- print " | isonotright text include if right != text"
- print " | lcase [or] ucase convert lines to lower or upper case"
- print " | fields 1 2 3 4 _ show 1st, 2nd, 3rd, 4th, _all fields/tokens"
- print " | replace what with replace \"what\" with \"with\""
- print " | arrdo \"do what\" very powerful / do not use"
- print " | tops n only show top n lines"
- print " | bots n only show bottom n lines"
- print " | noreps only show each line once, regardless of sort"
- print " | var varname pipe output to varname"
- print " | ascii [-h] display text as ascii codes (-h for hex)"
- print " | rainbow rotate colours by -f field, -p pos, -l level"
- print " | findsim find similar files"
- print " | isogroup text show only groups containing text"
- print " | isogroupnotonly text show groups that dont exclusively contain text"
- print " | groupbyleft howmuch uniq/sep by howmuch (includes singles)"
- print " | groupsortlen sort groups by size"
- print " | groupminlen len remove groups with fewer lines than len"
- print " | groupmaxlen len remove groups with more lines than len"
- print " | arrlen prepend each line with length"
- print
- print " while ; repeatedly do part after ;"
- print " forin vname 500 ; do part after ; ...500 times"
- print " forin vname array ; do part after ; ...loop through array"
- print " next mark the bottom of a while or forin loop"
- print " break exit a while or forin loop"
- print " clear clear the screen"
- print " pset x y c draw a dot at x, y in colour c"
- print " chr asciicode [or unicode] output a character from ascii or unicode"
- print " line x y x2 y2 c draw a line from x, y to x2, y2 in colour c"
- print " echo $varname output $varname"
- print " quit, exit quit the shell"
- x = 1
- elif sys.argv[1] == "--pserver":
- try: alexr = alexshell("python -m SimpleHTTPServer")
- except: print
- x = 1
- elif sys.argv[1] == "--isoname":
- lfor = sys.argv[2].split("|")
- for y in alexarrstdin():
- for t in lfor:
- if t in y: print y ; break
- x = 1
- elif sys.argv[1] == "--minusname":
- lfor = sys.argv[2].split("|")
- for y in alexarrstdin():
- for t in lfor:
- if t in y: y = 0 ; break
- if y != 0: print y
- x = 1
- elif sys.argv[1] == "--locate":
- try: c = int(sys.argv[3])
- except: c = None
- try: r = int(sys.argv[2])
- except: r = None
- alexlocate(r, r, c)
- x = 1
- elif sys.argv[1] == "--line":
- try:
- c = int(sys.argv[6])
- y2 = int(sys.argv[5])
- x2 = int(sys.argv[4])
- y = int(sys.argv[3])
- x = int(sys.argv[2])
- except: r = None
- alexline(x, y, x2, y2, c)
- x = 1
- elif sys.argv[1] == "--pset":
- try:
- c = int(sys.argv[4])
- y = int(sys.argv[3])
- x = int(sys.argv[2])
- except: r = None
- alexpset(x, y, c)
- x = 1
- elif sys.argv[1] == "--colour":
- try: c = int(sys.argv[3])
- except: c = None
- try: r = int(sys.argv[2])
- except: r = None
- alexcolortext(r, c)
- x = 1
- elif sys.argv[1] == "--findsim":
- files = alexarr(0) ; files = alexmid(files, 1, 0) ; # sizes
- filen = alexarr(0) ; filen = alexmid(filen, 1, 0) ; # names
- filec = alexarr(0) ; filec = alexmid(filec, 1, 0) ; # contents
- fileh = alexarr(0) ; fileh = alexmid(fileh, 1, 0) ; # hashes
- filed = alexarr(0) ; filed = alexmid(filed, 1, 0) ; # done already
- filelist = alexarr(0) ; filelist = alexmid(filelist, 1, 0) ; # output
- p = alexarrstdin()
- p = filter(os.path.isfile, p)
- for f in p:
- fs = 0
- fs = int(os.path.getsize(f))
- if 1:
- filen = alexplus(filen, f)
- files = alexplus(files, fs)
- now = sha256(open(f).read()).hexdigest()
- fileh = now
- contentarr = alexarropen(f)
- contentarr = alexjoin(contentarr, " ")
- contentarr = alexsplit(contentarr, " ")
- alexarrsort(contentarr)
- content = ""
- oldc = ""
- for c in contentarr:
- if c:
- if c != oldc:
- now = alexplus(content, c)
- now = alexplus(now, " ")
- now, content = content, now
- filec = alexplus(filec, content)
- quot = chr(34)
- filenlen = alexlen(filen)
- for x in range(1, filenlen + 1, 1):
- print alexjoin(("comparing", alexarrget(filen, x), "to other files, file",
- x, "of", filenlen, "(" + str(int(float(x) / filenlen * 100)) + "%)"), " ")
- for y in range(1, filenlen + 1, 1):
- a = alexarrget(filen, x)
- b = alexarrget(filen, y)
- fwd = quot
- fwd = alexplus(fwd, a) ;
- fwd = alexplus(fwd, quot) ;
- fwd = alexplus(fwd, " ") ;
- fwd = alexplus(fwd, quot) ;
- fwd = alexplus(fwd, b) ;
- fwd = alexplus(fwd, quot)
- rev = quot
- rev = alexplus(rev, b) ;
- rev = alexplus(rev, quot) ;
- rev = alexplus(rev, " ") ;
- rev = alexplus(rev, quot) ;
- rev = alexplus(rev, a) ;
- rev = alexplus(rev, quot)
- already = alexinstr(filed, rev)
- if a == b:
- already = 1
- if already:
- already = 1
- else:
- filed = alexplus(filed, fwd)
- ca = alexarrget(filec, x)
- cb = alexarrget(filec, y)
- cas = alexarrget(files, x)
- cbs = alexarrget(files, y)
- try:
- cah = alexarrget(fileh, x)
- except:
- cbh = chr(32)
- try:
- cbh = alexarrget(fileh, y)
- except:
- cbh = ""
- if 1:
- if ca == cb:
- if cah == cbh:
- cbs = alexjoin((" match: ", cah), "")
- filelist += [(100, alexjoin((fwd, " # ", cas, " ", cbs), ""))]
- else:
- per = alexgetpsim(ca, cb)
- filelist += [(per, alexjoin((fwd, " # ", cas, " ", cbs), ""))]
- alexarrsort(filelist)
- for p in filelist:
- try: print alexjoin((int(p[0]), p[1]), " ")
- except: pass
- x = 1
- elif sys.argv[1] == "--cat":
- whichfiles = []
- catn = 0
- for p in sys.argv[2:]:
- if p == "-n": catn = 1
- elif p not in [";", "|"]: whichfiles += [p]
- else: break
- linec = 1
- for p in whichfiles:
- if catn:
- tab = chr(9)
- for textlines in alexarropen(p):
- alexprints(str(linec) + tab + textlines + nl) ; linec += 1
- else:
- alexprints(alexjoin(alexarropen(p), nl))
- if len(whichfiles) == 0:
- if catn:
- tab = chr(9)
- for textlines in alexarrstdin():
- alexprints(str(linec) + tab + textlines + nl) ; linec += 1
- else:
- alexprint(alexjoin(alexarrstdin(), nl))
- x = 1
- elif sys.argv[1] == "--rainbow":
- try:
- f = sys.argv[2].lower()
- except:
- f = ""
- linec = 0
- prevw = 0
- for textlines in alexarrstdin():
- if f not in ["-f", "-p", "-l"]:
- ckw = (textlines.strip() == "")
- if ckw and not prevw:
- linec += 1
- linec = linec % 6
- alexcolourtext([0, 12, 6, 14, 2, 9, 5][linec + 1])
- alexprints(textlines + nl) ;
- prevw = ckw
- else:
- chc = 0
- linec = 0
- prevw = 0
- for tc in textlines:
- chc += 1
- ckw = (tc.strip() != "")
- if ckw and not prevw:
- if f == "-p":
- linec = chc % 6
- else:
- linec += 1
- if f == "-l":
- linec = len(textlines) - len(textlines.lstrip())
- linec = linec % 6
- prevw = ckw
- alexcolourtext([0, 5, 12, 6, 14, 2, 9][linec + 1])
- alexprints(tc)
- alexprint("")
- x = 1
- elif sys.argv[1] == "--dc":
- dates = ""
- cw = 80
- try:
- sizel = 0
- cw = sys.argv[2]
- if cw[0].lower() == "d":
- dates = cw
- cw = 80
- elif cw[0].lower() in "-+":
- try:
- sizel = int(float(cw))
- except:
- sizel = 0
- cw = 80
- else:
- cw = int(cw)
- dates = sys.argv[3]
- if dates[0] in "-+":
- try:
- sizel = int(float(dates))
- except:
- sizel = 0
- dates = ""
- if dates[0].lower() != "d":
- dates = ""
- except:
- if type(cw) != int:
- cw = 80
- dates = dates[1:]
- from os import listdir
- from os import path
- for fp in alexarrstdin():
- b = []
- bfext = 0
- bp = 0
- bfs = 0
- bfiletime = 19
-
- try:
- paths = 0
- for p in listdir(fp):
- if not paths:
- paths = 1
- alexcolortext(9, 0)
- alexprints(fp + " ")
- alexcolortext(3, 0)
- try:
- alexprints(unichr(0x2500) * (cw - 2 - len(fp)))
- except:
- alexprints("-" * (cw - 2 - len(fp)))
- alexcolortext(7, 0)
- alexprint("")
- fext = path.splitext(fp + path.sep + p)[1]
- if len(p) > bfext:
- bfext = len(p)
- try:
- fs = int(os.path.getsize(fp + path.sep + p))
- if len(str(fs)) > bfs:
- bfs = len(str(fs))
- except:
- fs = ""
- try:
- if p[0] == ".":
- fext = "."
- if alexosname != "nt":
- if os.access(fp + path.sep + p, os.X_OK):
- fext = 2
- if os.path.isdir(fp + path.sep + p):
- fext = 0
- if os.path.islink(fp + path.sep + p):
- fext = 1
- except:
- pass
- try:
- filetime = str(datetime.fromtimestamp(os.path.getmtime(fp
- + path.sep + p)))[0:19]
- except:
- filetime = ""
- try:
- b += [(fext, p, fs, filetime)]
- except: b += [("problem", "with", 0, "fsortplus")]
- b.sort()
- mw = bfext + 1 + bfs + 1 + bfiletime + 2
- lw = 1
- if mw < cw:
- lw = int(cw / mw)
- for lp in range(0, len(b), lw):
- tab = chr(9)
- try:
- if lw < 2:
- p = b[lp]
- alexpld = 0
- sizem = 1
-
- if sizel < 0:
- if p[2] > abs(sizel): sizem = 0
- if sizel > 0:
- if p[2] < abs(sizel): sizem = 0
- if sizem and alexprintlinedc(str(p[3]), dates):
- alexpld = 1
- alexprint( alexpadright(p[1], bfext,
- alexcolourdc(p[0], p[1])) + " " +
- alexpadleft(p[2], bfs, alexcolourdc(p[0])) +
- " " + alexpadleft(str(p[3]), bfiletime) + " " + " " )
- else:
- alexpld = 0
- for lpc in range(lw):
- try:
- p = b[lp + lpc]
- sizem = 1
- if sizel < 0:
- if p[2] > abs(sizel): sizem = 0
- if sizel > 0:
- if p[2] < abs(sizel): sizem = 0
- if sizem and alexprintlinedc(str(p[3]), dates):
- alexpld = 1
- alexprints( alexpadright(p[1], bfext,
- alexcolourdc(p[0], p[1])) + " " +
- alexpadleft(p[2], bfs, alexcolourdc(p[0])) + " " +
- alexpadleft(str(p[3]), bfiletime) + " " + " " )
- except:
- pass
- if alexpld:
- alexprint("")
- except:
- print p[1] #"" #-1" + chr(32) + "-" * 64 + chr(32) + "?" + chr(32) + "?" + chr(32) + p[3]
- except OSError:
- pass
- x = 1
- elif sys.argv[1] == "--ascii":
- try:
- f = sys.argv[2].lower()
- except:
- f = ""
- linec = 0
- tab = chr(9)
- for textlines in alexarrstdin():
- linec += 1
- alexprints(str(linec) + tab)
- count = 1
- for tc in textlines:
- if f == "-h":
- alexprints(hex(ord(tc)).replace("0x", ""))
- else:
- alexprints(ord(tc))
- if count > 7:
- count = 0
- alexprints(chr(32))
- alexprints(" ")
- count += 1
- alexprint("")
- x = 1
- elif sys.argv[1] == "--groupbyleft":
- try:
- f = int(sys.argv[2])
- except:
- f = 0
- b = ""
- tab = chr(9)
- for textlines in alexarrstdin():
- lft = alexleft(textlines, f)
- if lft == b:
- b = lft
- else:
- if b.rstrip() != "":
- alexprint("")
- if textlines.rstrip() != "":
- alexprint(textlines)
- b = lft
- x = 1
- elif sys.argv[1] == "--groupsortlen":
- p = alexarrstdin() + [""]
- trimlen = 0
- grouplen = 0
- topgrouplen = 0
- for textlines in p:
- trimlen = len(textlines.rstrip())
- if trimlen > 0:
- grouplen += 1
- if grouplen > topgrouplen:
- topgrouplen = grouplen
- if trimlen == 0:
- grouplen = 0
- grouplen = 0
- for group in range(topgrouplen):
- buf = []
- for textlines in p:
- trimlen = len(textlines.rstrip())
- if trimlen > 0:
- grouplen += 1
- buf += [textlines]
- if trimlen == 0:
- if grouplen == (group + 1):
- for groupeach in buf:
- alexprint(groupeach.rstrip())
- alexprint("")
- grouplen = 0
- buf = []
- x = 1
- elif sys.argv[1] == "--isogroup":
- try:
- f = sys.argv[2]
- except:
- f = ""
- p = alexarrstdin() + [""]
- if 1:
- buf = []
- found = 0
- for textlines in p:
- trimlen = len(textlines.rstrip())
- if trimlen > 0:
- buf += [textlines]
- if f in textlines:
- found = 1
- if trimlen == 0:
- if found:
- for groupeach in buf:
- alexprint(groupeach.rstrip())
- alexprint("")
- found = 0
- buf = []
- x = 1
- elif sys.argv[1] == "--isogroupnotonly":
- try:
- f = sys.argv[2]
- except:
- f = ""
- p = alexarrstdin() + [""]
- if 1:
- buf = []
- found = 0
- for textlines in p:
- trimlen = len(textlines.rstrip())
- if trimlen > 0:
- buf += [textlines]
- if not f in textlines:
- found = 1
- if trimlen == 0:
- if found:
- for groupeach in buf:
- alexprint(groupeach.rstrip())
- alexprint("")
- found = 0
- buf = []
- x = 1
- elif sys.argv[1] == "--groupminlen":
- try:
- f = int(sys.argv[2])
- except:
- f = 0
- p = alexarrstdin() + [""]
- if 1:
- buf = []
- found = 0
- for textlines in p:
- trimlen = len(textlines.rstrip())
- if trimlen > 0:
- buf += [textlines]
- found = 1
- if trimlen == 0:
- if found and len(buf) >= f:
- for groupeach in buf:
- alexprint(groupeach.rstrip())
- alexprint("")
- found = 0
- buf = []
- x = 1
- elif sys.argv[1] == "--groupmaxlen":
- try:
- f = int(sys.argv[2])
- except:
- f = ""
- p = alexarrstdin() + [""]
- if 1:
- buf = []
- found = 0
- for textlines in p:
- trimlen = len(textlines.rstrip())
- if trimlen > 0:
- buf += [textlines]
- found = 1
- if trimlen == 0:
- if found and len(buf) <= f:
- for groupeach in buf:
- alexprint(groupeach.rstrip())
- alexprint("")
- found = 0
- buf = []
- x = 1
- elif sys.argv[1] == "--arrlen":
- f = ""
- b = ""
- for textlines in alexarrstdin():
- rln = len(textlines)
- alexprints(rln)
- alexprints(chr(9))
- alexprint(textlines)
- x = 1
- elif sys.argv[1] == "--isoleft":
- try:
- f = sys.argv[2]
- except:
- f = ""
- b = ""
- for textlines in alexarrstdin():
- lft = alexleft(textlines, len(f))
- if lft == f:
- if textlines.rstrip() != "" or b != "":
- alexprint(textlines)
- b = textlines.rstrip()
- x = 1
- elif sys.argv[1] == "--isoright":
- try:
- f = sys.argv[2]
- except:
- f = ""
- b = ""
- for textlines in alexarrstdin():
- lft = alexright(textlines, len(f))
- if lft == f:
- if textlines.rstrip() != "" or b != "":
- alexprint(textlines)
- b = textlines.rstrip()
- x = 1
- elif sys.argv[1] == "--isonotleft":
- try:
- f = sys.argv[2]
- except:
- f = ""
- b = ""
- for textlines in alexarrstdin():
- lft = alexleft(textlines, len(f))
- if lft != f:
- if textlines.rstrip() != "" or b != "":
- alexprint(textlines)
- b = textlines.rstrip()
- x = 1
- elif sys.argv[1] == "--isonotright":
- try:
- f = sys.argv[2]
- except:
- f = ""
- b = ""
- for textlines in alexarrstdin():
- lft = alexright(textlines, len(f))
- if lft != f:
- if textlines.rstrip() != "" or b != "":
- alexprint(textlines)
- b = textlines.rstrip()
- x = 1
- elif sys.argv[1] == "--sleep":
- try:
- alexsleep(float(sys.argv[2]))
- except:
- alexsleep(1)
- x = 1
- elif sys.argv[1] == "--arrcurl":
- try:
- alexaru = ""
- alexar = sys.argv[2]
- except:
- alexar = ""
- if alexar.lower() == "-a":
- try:
- alexaru = sys.argv[3]
- alexar, alexaru = alexaru, alexar
- except:
- alexaru = ""
- if alexar:
- alexu = alexarrcurl(alexaru, alexdequote(alexar))
- if alexaru.lower() == "-a":
- alexu = alexjoin(alexu, nl)
- alexprints(alexu)
- x = 1
- elif sys.argv[1] == "--chr":
- try:
- t = int(sys.argv[2])
- if t > 255:
- alexprints(unichr(t))
- else:
- alexprints(chr(t))
- except:
- pass
- x = 1
- elif sys.argv[1] == "--lcase":
- for textlines in alexarrstdin():
- alexprints(textlines.lower() + nl)
- x = 1
- elif sys.argv[1] == "--ucase":
- for textlines in alexarrstdin():
- alexprints(textlines.upper() + nl)
- x = 1
- elif sys.argv[1] == "--replace":
- fr = sys.argv[2].replace(chr(92) + chr(110), nl)
- try: into = sys.argv[3].replace(chr(92) + chr(110), nl)
- except: into = ""
- for textlines in alexjoin(alexarrstdin(), nl).replace(fr, into).split(nl):
- alexprints(textlines.replace(fr, into) + nl)
- x = 1
- elif sys.argv[1] == "--tops":
- fr = sys.argv[2]
- for textlines in alextops(alexarrstdin(), int(fr)):
- alexprints(textlines + nl)
- x = 1
- elif sys.argv[1] == "--bots":
- fr = sys.argv[2]
- for textlines in alexbots(alexarrstdin(), int(fr)):
- alexprints(textlines + nl)
- x = 1
- elif sys.argv[1] == "--arrdo":
- try: now = sys.argv[2]
- except: now = ""
- linec = 1
- if len(now):
- for textlines in alexarrstdin():
- s = alexshell(arrdostart + now + " " + textlines)
- x = 1
- elif sys.argv[1] == "--addquotes":
- quot = chr(34)
- if 1:
- for textlines in alexarrstdin():
- alexprints(quot + textlines.strip() + quot + nl)
- x = 1
- elif sys.argv[1] == "--var":
- for textlines in alexarrstdin():
- alexprint(textlines)
- x = 1
- elif sys.argv[1] == "--fsortplus":
- b = []
- for p in alexarrstdin():
- try: fs = int(os.path.getsize(p))
- except: fs = -1
- try: s256 = sha256(open(p).read()).hexdigest()
- except: s256 = "-" * 64
- try: filetime = str(datetime.fromtimestamp(os.path.getmtime(p)))[0:19]
- except: filetime = -1
- try: b += [(fs, s256, filetime, p)]
- except: b += [(0, "problem", "with", "fsortplus")]
- b.sort()
- for p in b:
- tab = chr(9)
- try: print str(p[0]) + " " + p[1] + " " + p[2] + tab + p[3]
- except: print "-1" + chr(32) + "-" * 64 + chr(32) + "?" + chr(32) + "?" + chr(32) + p[3]
- x = 1
- elif sys.argv[1] == "--fsortplusnows":
- b = []
- for p in alexarrstdin():
- try: fs = len(alexfws(open(p).read()))
- except: fs = -1
- try: s256 = sha256(alexfws(open(p).read())).hexdigest()
- except: s256 = "-" * 64
- try: filetime = str(datetime.fromtimestamp(os.path.getmtime(p)))[0:19]
- except: filetime = -1
- try: b += [(fs, s256, filetime, p)]
- except: b += [(0, "problem", "with", "fsortplus")]
- b.sort()
- for p in b:
- tab = chr(9)
- try: print str(p[0]) + " " + p[1] + " " + p[2] + tab + p[3]
- except: print "-1" + chr(32) + "-" * 64 + chr(32) + "?" + chr(32) + "?" + chr(32) + p[3]
- x = 1
- elif sys.argv[1] == "--isoplus":
- fr = sys.argv[2]
- tab = chr(9)
- for p in alexarrstdin():
- try:
- f = alexopen(p, "r")
- except:
- f = 0
- while 1:
- try:
- textlines = alexflineinput(p)
- except:
- textlines = ""
- if textlines == chr(10):
- break
- if fr.lower() in textlines.lower():
- print p + tab + textlines
- try:
- f = alexclose(p)
- except:
- f = 0
- x = 1
- elif sys.argv[1] == "--noreps":
- b = {}
- for textlines in alexarrstdin():
- try:
- t = b[textlines]
- except:
- print textlines
- b[textlines] = 0
- x = 1
- elif sys.argv[1] == "--fields":
- try:
- now = sys.argv[2:]
- except:
- now = ""
- if len(now):
- for textlines in alexarrstdin():
- count = 0
- for p in now:
- count += 1
- if p == "_":
- alexprints(textlines)
- else:
- try:
- alexprints(textlines.split()[int(p) - 1])
- except:
- alexprints("~")
- if count < len(now):
- alexprints(" ")
- print ""
- x = 1
- except: p = 0
- if x > 0: sys.exit()
- alexhist = os.path.join(os.path.expanduser("~"), ".alex_history")
- try: f = open(alexhist).read()
- except:
- try:
- f = open(alexhist, "w")
- f.write("")
- f.close()
- f = open(alexhist).read()
- except: print "unable to open history file"
- def alexq(alexhist):
- try: readline.write_history_file(alexhist)
- except: print "couldnt write history file"
- quit()
- pcmds = ["cd", "while", "set", "setrandint", "setinput", "next", "break", "setadd", "setnum", "forin"] # take priority no matter what files are found
- ntlocalcmds = ["dir", "echo"]
- def alexparse(p):
- quot = chr(34)
- inquotes = 0
- buf = ""
- tokencount = 0
- out = ["",]
- for t in p:
- # handle quote mark
- if t == quot:
- if inquotes: out[tokencount] += t ; inquotes = 0
- else: tokencount += 1 ; out += [""] ; out[tokencount] = t ; inquotes = 1
- # handle spaces outside quotes
- elif inquotes == 0 and t == " ":
- tokencount += 1 ; out += [""]
- # handle pipes outside quotes
- elif inquotes == 0 and t == "|":
- tokencount += 1 ; out += ["|"] ; tokencount += 1 ; out += [""]
- # handle semicolons outside quotes
- elif inquotes == 0 and t == ";":
- tokencount += 1 ; out += [";"] ; tokencount += 1 ; out += [""]
- elif inquotes == 0 and t == "$":
- tokencount += 1 ; out += [""] ; out[tokencount] = t
- elif inquotes == 0 and t == ";":
- tokencount += 1 ; out += [";"] ; tokencount += 1 ; out += [""]
- # handle everything else
- else: out[tokencount] += t
- if len(" ".join(out).strip()): out += [";"]
- while "" in out: out.remove("")
- if inquotes: return 0
- else: return out
- def alexesc(p, anglebr):
- p = p.replace(chr(92), chr(92) + chr(92))
- p = p.replace(chr(34), chr(92) + chr(34))
- p = p.replace(chr(38), chr(92) + chr(38))
- if anglebr:
- p = p.replace("<", chr(92) + "<") # allow redirection
- p = p.replace(">", chr(92) + ">") # if 0
- p = p.replace("(", chr(92) + "(")
- p = p.replace(")", chr(92) + ")")
- return p
- def alexqesc(p):
- b = chr(34) + alexesc(p, 0) + chr(34)
- p = ""
- normal = 1
- for t in b:
- if t == "$" and normal: normal = 0 ; extra = "$"
- elif normal: p += t
- elif t in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_": extra += t
- else:
- normal = 1
- if alexosname == "nt":
- if alexvalidrefvar(extra): p += chr(34) + " + alexesc(alexprocstring(" + extra[1:] + "), 1) + " + chr(34) + t
- else: p = 0
- else:
- if alexvalidrefvar(extra): p += chr(92) + chr(34) + chr(34) + " + alexesc(alexprocstring(" + extra[1:] + "), 1) + " + chr(34) + chr(92) + chr(34) + t
- else: p = 0
- return p
- def alexprocstring(p):
- global nl
- if type(p) == list:
- return alexjoin(p, nl)
- else: return str(p)
- def alexvalidvar(p):
- try: p4 = p[0:4]
- except: p4 = ""
- try:
- if p.lower()[0] in "abcdefghijklmnopqrstuvwxyz" and p.lower() != "var" and p4.lower() != "alex":
- for t in p:
- if t.lower() not in "abcdefghijklmnopqrstuvwxyz_1234567890": return 0
- return 1
- except: return 0
- return 0
- def alexvalidrefvar(p):
- if len(p) > 1:
- if p[0] == "$":
- p = p[1:]
- else: return 0
- try: p4 = p[0:4]
- except: p4 = ""
- try:
- if p.lower()[0] in "abcdefghijklmnopqrstuvwxyz" and p.lower() != "var" and p4.lower() != "alex":
- for t in p:
- if t.lower() not in "abcdefghijklmnopqrstuvwxyz_1234567890": return 0
- return 1
- except: return 0
- return 0
- csc = 0
- buf = []
- bufpos = 0
- agg = ""
- prevtoken = ""
- ptoken = ""
- outprog = ""
- runvar = 0
- invflag = 0
- while 1:
- p = ""
- bufpos += 1
- arrpath = os.getenv('PATH').split(os.pathsep)
- if bufpos > len(buf): exec(outprog) ; outprog = "" ; indent = 0
- if sc and bufpos > len(buf):
- bufpos = 1
- csc += 1
- try: p = alexparse(sc[csc-1]) ; prevtoken = ""
- except: p = ["quit"]
- elif bufpos > len(buf):
- bufpos = 1
- getuser = os.getenv("LOGNAME")
- if getuser == None: getuser = os.getenv("USER")
- if getuser == None: getuser = ""
- alexcolourtext(7)
- if getuser == "root":
- alexcolourtext(12) ; alexprints("root") ; alexcolourtext(7) ; alexprints(":") ; userp = "#> "
- elif getuser: alexprints(getuser + ":") ; userp = "$> "
- if alexosname == "nt": userp = "> "
- alexcolourtext(9) ; alexprints(os.getcwd()) ; alexcolourtext(7) ; alexprints(userp)
- try: p = alexparse(alexlineinput("")) ; prevtoken = ""
- except EOFError: p=["quit"] ; print "exit"
- except KeyboardInterrupt: print "^C" ; buf = [] ; agg = "" ; outprog = "" ; indent = 0 ; p = ""
- except: p = [""]
- invflag = 0
- if p == 0: print "a quoted string was not end-quoted; syntax is invalid" ; p = []
- if len(p): buf = p
- try: token = buf[bufpos - 1]
- except: token = ""
-
- if token in pcmds and bufpos == 1: ptoken = token
- ntreplace = 1
- if alexosname == "nt":
- pyprefix = "c:\python27\python "
- if token == "find" and (bufpos == 1 or prevtoken == "|"): token = "dir /b /a /s"
- elif token == "clear" and (bufpos == 1 or prevtoken == "|"): token = "cls"
- elif token == "ucase" and (bufpos == 1 or prevtoken == "|"): token = pyprefix + alexver + ".py --ucase"
- else: ntreplace = 0
- arrpath += [os.getcwd()]
- pfound = 1
- elif bufpos == 1 or prevtoken == "|":
- ntreplace = 0
- pyprefix = ""
- ntlocalcmds = []
- try: pfound = int(len(alexarrshell("which " + token + " 2> /dev/null")) > 1) ; ##print "TOKEN("+token+")"
- except: pfound = 0 ; token = ""
- x = 0
- if len(token) or len(ptoken):
- if runvar and alexvalidvar(token): alexvar = token ; x = 1
- if runvar: runvar = 2
- if len(ptoken) and bufpos == 1: argu = [] ; x = 1
- elif token in ["quit", "exit"] and bufpos == 1: alexq(alexhist)
- elif token in ["help", "pserver", "isoname", "minusname", "locate", "colour", "line", "pset", "tops", "bots",
- "cat", "arrdo", "fsortplus", "fsortplusnows", "fields", "replace", "rainbow", "ascii", "isoplus", "noreps", "sleep", "dc", "arrlen", "findsim", "isogroup", "isogroupnotonly", "groupminlen", "groupmaxlen", "groupbyleft", "groupsortlen", "isoleft", "isoright", "isonotleft", "isonotright", "lcase", "ucase", "chr", "arrcurl"] and (bufpos == 1 or prevtoken == "|"): token = pyprefix + alexver + ".py --" + token ; x = 1
- elif token in ["var"] and prevtoken == "|": token = pyprefix + alexver + ".py --" + token ; x = 1 ; runvar = 1 ; alexvar = ""
- if len(buf) and (bufpos == 1 or prevtoken == "|"): lfor = [token,]
- if len(buf) > 0 and alexosname == "nt" and (bufpos == 1 or prevtoken == "|"):
- lfor += [token + ".exe", token + ".bat"]
- for plfor in lfor:
- for ap in arrpath:
- if plfor in os.listdir(ap) and x == 0:
- token = ap + os.sep + plfor ; x = 1 ; break
- if os.path.isfile(plfor) and x == 0: token = plfor ; x = 1 ; break
- if x == 0 and lfor[0] in ntlocalcmds:
- token = lfor[0] ; x = 1
- elif ntreplace > 0 and x == 0:
- x = 1
- elif len(buf) > 0 and pfound == 1 and x == 0 and (bufpos == 1 or prevtoken == "|"):
- x = 1
- # invalid command
- if len(buf) > 0 and invflag == 0 and x == 0 and (bufpos == 1 or prevtoken == "|"): print "type the word \"help\" or a question mark and hit enter for a list of commands" ; token = "" ; bufpos = buf.index(";", bufpos-1) ; agg = "" ; invflag = 1
- elif len(buf) > 0 and invflag == 1 and x == 0 and (bufpos == 1 or prevtoken == "|"): token = "" ; bufpos = buf.index(";", bufpos-1) ; agg = ""
- # invalid variable
- if len(buf) > 0 and runvar == 2 and alexvar == "": print "type the word \"help\" or a question mark and hit enter for a list of commands" ; token = "" ; bufpos = buf.index(";", bufpos-1) ; agg = "" ; runvar = 0
- if x == 1 and bufpos == 1: agg = token
- prevtoken = token
- if token != ";" and bufpos > 1:
- if ptoken:
- argu += [token] ; x = 0
- else:
- agg += " " + token ; x = 0
- if token == ";" and bufpos > 1:
- if ptoken:
- outprog += ptrans(ptoken, argu, alexhist, nl) ; argu = [] ; ptoken = "" ; prevtoken = ""
- elif runvar:
- if alexvar:
- outprog += chr(32) * alexatleast(0, indent) + alexvar + " = alexvarproc(alexarrshell(" + alexqesc(agg) + "))" + nl ; agg = "" ; prevtoken = "" ; runvar = 0
- else:
- outprog += chr(32) * alexatleast(0, indent) + "alexr = alexshell(" + alexqesc(agg) + ")" + nl ; agg = "" ; prevtoken = ""
- buf = buf[bufpos:] ; bufpos = 0
|