home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Boot Disc 5
/
boot-disc-1997-01.iso
/
media
/
utility.cst
/
00031_Script_databaseClass
< prev
next >
Wrap
Text File
|
1996-11-05
|
6KB
|
213 lines
property data,activerec,sectiontree,activesection,activecategory
property datadelimiter,template,textsource
on new me,mytextsource,fromFileFlag
set datadelimiter="|"
if fromFileFlag then
loadfile me,textsource
end if
set textsource=mytextsource
load me,textsource
if listP(data) then
if count(data)>0 then
set activerec=getat(data,1)
set activesection=the section of activerec
set activecategory=the category of activerec
else
set activerec=[:]
set activesection=0
set activecategory=0
end if
end if
return me
end
on load me
set mytext=the text of member textsource
set proptext=line 1 of mytext
set propflatlist=texttolist(proptext,datadelimiter)
set template=symbol(propflatlist)
delete line 1 of mytext
set data=[:]
set sectiontree=[:]
repeat with index=1 to the number of lines in mytext
set curline=line index of mytext
set rec=filltemplate(template,curline,datadelimiter)
if stringP(rec) then
alert(rec&";Error was in line "&index&".")
halt
end if
addprop data,the name of rec,rec
if voidP(getaprop(sectiontree,the section of rec)) then
addprop sectiontree,the section of rec,[:]
end if
set sectionlist=getprop(sectiontree,the section of rec)
if voidP(getaprop(sectionlist,the category of rec)) then
addprop sectionlist,the category of rec,[]
end if
set catlist=getprop(sectionlist,the category of rec)
add catlist,the name of rec
end repeat
end
on loadfile me
--
set file=new(xtra "FileIO")
set filename=displayOpen(file)
if voidP(filename) then exit
starttimer
openfile(file,filename,1)
if error(file,status(file))<>"OK" then
alert(error(file,status(file)))
halt
end if
delpush(datadelimiter)
set proptext=readline(file)
set buffer=proptext
set propflatlist=texttolist(proptext,datadelimiter)
set template=symbol(propflatlist)
set numprops=count(template)
set data=[:]
set sectiontree=[:]
set status=true
repeat while(status)
set curline=readline(file)
if (curline="") or (length(curline)<2) then exit repeat
-- set curline=safetext(curline)
if word 1 of curline="" then set curline=""
set buffer=buffer&curline
put curline
set rec=filltemplate(template,curline,datadelimiter)
if stringP(rec) then
alert(rec&";Error was in line starting '"&(char 1 to 20 of curline)&"...'")
halt
end if
addprop data,the name of rec,rec
if voidP(getaprop(sectiontree,the section of rec)) then
addprop sectiontree,the section of rec,[:]
end if
set sectionlist=getprop(sectiontree,the section of rec)
if voidP(getaprop(sectionlist,the category of rec)) then
addprop sectionlist,the category of rec,[]
end if
set catlist=getprop(sectionlist,the category of rec)
add catlist,the name of rec
end repeat
closefile(file)
delete char length(buffer) of buffer
put buffer into field textsource
if the machinetype<256 then
set basepath=the pathname
delpush(":")
set basepath=item 1 to ((the number of items in basepath)-2) of basepath
delpop()
set imagepath=basepath&":images:"
set videopath=basepath&":movies:"
set textpath=basepath&":text:"
else
set imagepath="..\images\"
set videopath="..\movies\"
set textpath="..\text\"
end if
set imageptr=100
repeat with index=1 to count(data)
set rec=getat(data,index)
if not voidP(getaprop(rec,#image)) then
set image=getaprop(rec,#image)
if image<>"" then
set imageloc=imagepath&(image)
importfileinto member imageptr,imageloc
set imageptr=imageptr+1
else
set imageloc=""
end if
end if
-- if not voidP(getaprop(rec,#video)) then
-- set video=getaprop(rec,#video)
-- if video<>"" then
-- set videoloc=videopath&(video)
-- end if
-- end if
-- if not voidP(getaprop(rec,#text)) then
-- set text=getaprop(rec,#text)
-- if text<>"" then
-- set textloc=textpath&(text)
-- end if
-- end if
end repeat
saveMovie
end
on getindexedrecord me,myindex
set catlist=getprop(sectiontree,activesection)
set reclist=getprop(catlist,activecategory)
if myindex>0 and myindex<=count(reclist) then
set activerec=getprop(data,getat(reclist,myindex))
else
set activerec=0
end if
return activerec
end
on getsections me
set sectionlist=[]
repeat with index=1 to count(sectiontree)
add sectionlist,getpropat(sectiontree,index)
end repeat
return sectionlist
end
on getcategories me
set categorytree=getprop(sectiontree,activesection)
set categorylist=[]
repeat with index=1 to count(categorytree)
add categorylist,getpropat(categorytree,index)
end repeat
return categorylist
end
on getrecords me
set categorytree=getprop(sectiontree,activesection)
set reclist=getprop(categorytree,activecategory)
return reclist
end
on getrecord me,name
set testlist=[]
repeat with index=1 to count(data)
set recname=getpropat(data,index)
if recname=name then
set rec=getat(data,index)
if ((the section of rec)=activesection) and ((the category of rec)=activecategory) then
set rec=getat(data,index)
exit repeat
end if
end if
end repeat
set activerec=rec
return rec
end
on searchrecords me,prop,srcstr
set searchedrecs=[]
repeat with index=1 to count(data)
set rec=getat(data,index)
set entry=getprop(rec,prop)
if offset(srcstr,entry)>0 then
add searchedrecs,rec
end if
end repeat
return searchedrecs
end
on getRecordFromProp me,prop,value
repeat with index=1 to count(data)
set rec=getat(data,index)
if getprop(rec,prop)=value then
set activerec=rec
exit repeat
end if
end repeat
return activerec
end