free software resistance
the cost of computing freedom is eternal vigilance
### dibb.py
*original date:* oct 2014
*orginally posted:* sep 2024
the idea of dib isnt basic was pretty simple- i was showing people how to make python script equivalents of basic programs, by creating somewhat compatible functions for common basic commands, then calling those functions from python.
then i started making toy languages that would translate to such calls and include the functions. dib was an early one, the point was pretty much to do a simple translator.
```
#!/usr/bin/env python
#### dib isn't basic
#### license: creative commons cc0 1.0 (public domain)
####http://creativecommons.org/publicdomain/zero/1.0/
## sample program (loops are next)
#
# cls
# thisisastring hello there
# print thisisastring
# oka 1
# okb 2
# okc 3
# bcolor 3
# write oka okb okc
# fcolor 5
# os ls | tail -5
# fcolor 4
# print thisisastring thisisastring
#
####################################
import os, time, sys
print "\n"*10
print "dib isn't basic v0.1 2014 mennonite"
print
tmp = ""
print "open a .dib file -",
tmp = raw_input()
tmp = tmp.split(" ")[0]
what = ""
for part in tmp:
if part <> " ":
if part in "qazwsxedcrfvtgbyhnujmikolp1234567890_-.": what += part
tmp = ""
if what == "" or len(what) < 5: what = "dib"
if what[-4:] <> ".dib": what += ".dib"
try: dibfile = open(what).readlines()
except: dibfile = []
print "\x1b[1;32mtranslating to python..."
res = ['active','goback','print','cls','write','fcolor','bcolor','os']
tmpfile = open("/tmp/" + what + ".tmp", "w")
tmpfile.write("#!/usr/bin/env python\n")
tmpfile.write("\n")
tmpfile.write("""import os, time, sys
def color(f, b):
n = "0"
if f > 7:n="1" ; f=f-8
if f==1:f=4
elif f==4:f=1
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
sys.stdout.write("\x1b["+n+";"+str(30+f)+";"+str(40+b)+"m")
global fcolor
global bcolor
fcolor, bcolor = 7, 0
""")
colorused = 0
for line in dibfile:
cmd = ""
if len(line.strip()):
cmd = line.rstrip().split(" ")[0].lower()
print "cmd: " + cmd
#time.sleep(0.1)
if cmd not in res:
cmdless = "\"" + line[len(cmd):].strip() + "\""
tmpfile.write("global "+cmd+"\n" + cmd + " = " + cmdless + "\n")
elif cmd == "print":
cmdless = ", ".join(line[len(cmd):].strip().split(" "))
tmpfile.write("print " + cmdless + "\n")
elif cmd == "cls":
tmpfile.write("sys.stdout.write(\"\\x1b[2J\\x1b[1;1H\")\n")
elif cmd == "write":
cmdless = " + ".join(line[len(cmd):].strip().split(" "))
tmpfile.write("sys.stdout.write(" + cmdless + ")\n")
elif cmd == "fcolor":
cmdless = line[len(cmd):].strip().split(" ")[0]
tmpfile.write("fcolor = " + cmdless + "\ncolor(fcolor, bcolor)\n")
colorused = 1
elif cmd == "bcolor":
cmdless = line[len(cmd):].strip().split(" ")[0]
tmpfile.write("bcolor = " + cmdless + "\ncolor(fcolor, bcolor)\n")
colorused = 1
elif cmd == "os":
cmdless = "\"\"\" " + line[len(cmd):].strip() + " \"\"\""
tmpfile.write("os.system(" + cmdless + ")\n")
if colorused: tmpfile.write("color(7, 0)\n")
tmpfile.close()
print "\x1b[0;37m"
p = os.system("cat /tmp/" + what + ".tmp")
print "---"
print "\x1b[1;32mrunning " + what + ".tmp...\x1b[0;37m"
p = os.system("python /tmp/" + what + ".tmp")
os.remove("/tmp/" + what + ".tmp")
```
license: 0-clause bsd
```
# 2014 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