1. The world simplest database
- Posted by Matt Z Nunyabidness <matt1421 at JUNO.COM>
Sep 24, 1998
-
Last edited Sep 25, 1998
dbase.dbf:
Name: Everybody
Email address: ummm, ask 'em
Full name: That's kinda hard
Comment: Pure Euphoria!
*
database.ex:
-- -------------------------
-- -- My Database example --
-- -------------------------
--By matt1421 at juno.com. Email personally for questions and comments
--Please, no flame or junk mail.
clear_screen()
include get.e
include file.e
include graphics.e
include image.e
integer fn
object line,comm,cl,fname
cl=command_line()
if length(cl)=3 then
fname=cl[3]
else
fname="dbase.dbf"
end if
fn=open(fname,"r")
if fn=-1 then
puts(1,"\nCould not find database file")
abort(1)
end if
text_color(10)
puts(1,"The simplest database on earth!\n")
text_color(15)
while 1 do
line=gets(fn)
if atom(line) then
puts(1,"\nend-of-file")
puts(1,"\nQuit?")
comm=gets(0)
if find('n',comm) then
if seek(fn,0) then
end if
clear_screen()
line=gets(fn)
else
exit
end if
end if
--end if
if find('*',line) then
puts(1,"\nHit n for next entry, hit b for beginning, a to add, hit q
to quit>")
comm=gets(0)
puts(1,'\n')
if find('b',comm) then
clear_screen()
if seek(fn,0) then
end if
line=gets(fn)
end if
if find('n',comm) then
clear_screen()
line=gets(fn)
end if
if find('q',comm) then
close(fn)
abort(0)
end if
if find('a',comm) then
clear_screen()
close(fn)
fn=open(fname,"u")
if seek(fn,-1) then
end if
puts(1,"\nName: ")
comm=gets(0)
if not compare(comm,"") then
comm="N/A"
end if
puts(fn,"Name: "&comm)
puts(1,"\nEmail address: ")
comm=gets(0)
if not compare(comm,"") then
comm="N/A"
end if
puts(fn,"Email address: "&comm)
puts(1,"\nFull name: ")
comm=gets(0)
if not compare(comm,"") then
comm="N/A"
end if
puts(fn,"Full name: "&comm)
puts(1,"\nComment: ")
comm=gets(0)
if not compare(comm,"") then
comm="N/A"
end if
puts(fn,"Comment: "&comm)
puts(fn,'*')
puts(1,"\nNow you gotta restart the database")
puts(1,"\nHit cr>")
comm=gets(0)
abort(0)
end if
end if
puts(1,line)
end while
Oh, and that user.e file i've been using:
-- --------------------------------
-- --**functions and procedures**--
-- --------------------------------
-- I collected these functions and procedure from the euphoria mailing
-- list, which you can subscribe to by Mailing a message to
-- listserv at miamiu.acs.muohio.edu saying:
-- SUBSCRIBE EUPHORIA ANONYMOUS
-- If you want to unsubscribe, send another message to
-- listserv at miamiu.acs.muohio.edu saying SIGNOFF EUPHORIA
-- there, you will find flamers, programmers, hypocrites, band-width
eaters,
-- and newbies.
-- O, and BTW. Some of these i made
include image.e
include graphics.e
include get.e
object vc
global procedure cls()
vc=video_config()
for a= 1 to vc[3] do --the third argument supplies the ammount of lines
puts(1,"\n")
position(1,1)
end for
end procedure
--Tim Jiri's trim function from the thread
global function trim(sequence s)
-- trim 'white space' from both ends of string s
-- 'short-circuit' optimized
integer c,i,j,len
len=length(s)
i=1
while i<=len do
c=s[i]
if c=32 then i=i+1
elsif c=10 then i=i+1
elsif c=13 then i=i+1
elsif c=9 then i=i+1
else exit end if
end while
j=len
while j>=i do
c=s[j]
if c=32 then j=j-1
elsif c=10 then j=j-1
elsif c=13 then j=j-1
elsif c=9 then j=j-1
else exit end if
end while
return s[i..j]
end function
--I made this one.
--Variables: x and y: where to display the image
--filename: the picture to display
global procedure bmpview(object filename, integer x, integer y)
-- declare variables
integer mode
object source,pal,pixels
-- trim white space from the filename
filename=trim(filename)
-- read the bitmap
source=read_bitmap(filename)
-- seperate the palette from the rest of the picture
pal=source[1]
-- scale the palette
pal=pal/4
-- get the picture
pixels=source[2]
if length(pal)>16 then
mode=257 -- works on some computers
else
mode=18 -- works on all computers
end if
if graphics_mode(mode) then
end if
all_palette(pal) -- set the palette
display_image({x,y},pixels) -- finally, display the picture at x,y
end procedure
global procedure txtshow(object fname)
--txtshow.ex by Ralf
--[Variables]
sequence arg, image
integer fhandle
--[Getting filename]
arg = fname
if arg="" then
puts (1,"\nFileName: ")
fname = trim(gets(0))
end if
--[Opening file for input]
fhandle = open (fname, "r")
if fhandle = -1 then
puts (1, "File IO error!\n")
abort (3)
end if
--[Loading & showing textimage]
image = get (fhandle)
if image[1] = GET_EOF then
puts (1, "Unexpected end of file!\n")
abort (1)
elsif image[1] = GET_FAIL then
puts (1, "This file does not contain a valid text image!\n")
abort (2)
end if
display_text_image({1,1}, image[2])
if wait_key() then
end if
--object pos
--pos=get_position()
position(23,1)
--[Finished]
close (fhandle) -- Cleaner, but Ex.exe would have closed it anyway.
end procedure
global procedure bmpview(object fname, integer x, integer y)
object bitmap,pixels,pal
integer mode
fname=trim(fname)
bitmap=read_bitmap(fname)
pixels=bitmap[2]
pal=bitmap[1]
pal=pal/4
if length(pal)>16 then
mode=257
else
mode=18
end if
if graphics_mode(mode) then
end if
all_palette(pal)
display_image({x,y},pixels)
end procedure
global procedure discard(object trash)
if atom(trash) then
end if
end procedure
-------------------------------------
When it comes to programming languages, Euphoria is a cut above -
matt1278 at juno.com and matt1421 at juno.com(and soon to be
irisnmatt at prodigy.net. Then again, maybe not) Euphoria programmer