home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 5 / boot-disc-1997-01.iso / media / utility.cst / 00031_Script_databaseClass < prev    next >
Text File  |  1996-11-05  |  6KB  |  213 lines

  1. property data,activerec,sectiontree,activesection,activecategory
  2. property datadelimiter,template,textsource
  3.  
  4. on new me,mytextsource,fromFileFlag
  5.   set datadelimiter="|"
  6.   if fromFileFlag then
  7.     loadfile me,textsource
  8.   end if
  9.   set textsource=mytextsource
  10.   load me,textsource
  11.   if listP(data) then
  12.     if count(data)>0 then
  13.       set activerec=getat(data,1)
  14.       set activesection=the section of activerec
  15.       set activecategory=the category of activerec
  16.     else
  17.       set activerec=[:]
  18.       set activesection=0
  19.       set activecategory=0
  20.     end if
  21.   end if
  22.   return me
  23. end
  24.  
  25. on load me
  26.   set mytext=the text of member textsource
  27.   set proptext=line 1 of mytext
  28.   set propflatlist=texttolist(proptext,datadelimiter)
  29.   set template=symbol(propflatlist)
  30.   delete line 1 of mytext
  31.   set data=[:]
  32.   set sectiontree=[:]
  33.   repeat with index=1 to the number of lines in mytext
  34.     set curline=line index of mytext
  35.     set rec=filltemplate(template,curline,datadelimiter)
  36.     if stringP(rec) then
  37.       alert(rec&";Error was in line "&index&".")
  38.       halt
  39.     end if
  40.     addprop data,the name of rec,rec
  41.     if voidP(getaprop(sectiontree,the section of rec)) then
  42.       addprop sectiontree,the section of rec,[:]
  43.     end if
  44.     set sectionlist=getprop(sectiontree,the section of rec)
  45.     if voidP(getaprop(sectionlist,the category of rec)) then
  46.       addprop sectionlist,the category of rec,[]
  47.     end if
  48.     set catlist=getprop(sectionlist,the category of rec)
  49.     add catlist,the name of rec
  50.   end repeat
  51. end 
  52.  
  53. on loadfile me
  54.   --
  55.   set file=new(xtra "FileIO")
  56.   set filename=displayOpen(file)
  57.   if voidP(filename) then exit
  58.   starttimer
  59.   openfile(file,filename,1)
  60.   if error(file,status(file))<>"OK" then
  61.     alert(error(file,status(file)))
  62.     halt
  63.   end if
  64.   delpush(datadelimiter)
  65.   set proptext=readline(file)
  66.   set buffer=proptext
  67.   set propflatlist=texttolist(proptext,datadelimiter)
  68.   set template=symbol(propflatlist)
  69.   set numprops=count(template)
  70.   set data=[:]
  71.   set sectiontree=[:]
  72.   set status=true
  73.   repeat while(status)
  74.     set curline=readline(file)
  75.     if (curline="") or (length(curline)<2) then exit repeat
  76.     -- set curline=safetext(curline)
  77.     if word 1 of curline="" then set curline=""
  78.     set buffer=buffer&curline
  79.     put curline
  80.     set rec=filltemplate(template,curline,datadelimiter)
  81.     if stringP(rec) then
  82.       alert(rec&";Error was in line starting '"&(char 1 to 20 of curline)&"...'")
  83.       halt
  84.     end if
  85.     addprop data,the name of rec,rec
  86.     if voidP(getaprop(sectiontree,the section of rec)) then
  87.       addprop sectiontree,the section of rec,[:]
  88.     end if
  89.     set sectionlist=getprop(sectiontree,the section of rec)
  90.     if voidP(getaprop(sectionlist,the category of rec)) then
  91.       addprop sectionlist,the category of rec,[]
  92.     end if
  93.     set catlist=getprop(sectionlist,the category of rec)
  94.     add catlist,the name of rec
  95.   end repeat
  96.   closefile(file)
  97.   delete char length(buffer) of buffer
  98.   put buffer into field textsource
  99.   if the machinetype<256 then
  100.     set basepath=the pathname
  101.     delpush(":")
  102.     set basepath=item 1 to ((the number of items in basepath)-2) of basepath
  103.     delpop()
  104.     set imagepath=basepath&":images:"
  105.     set videopath=basepath&":movies:"
  106.     set textpath=basepath&":text:"
  107.   else
  108.     set imagepath="..\images\"
  109.     set videopath="..\movies\"
  110.     set textpath="..\text\"
  111.   end if
  112.   set imageptr=100
  113.   repeat with index=1 to count(data)
  114.     set rec=getat(data,index)
  115.     if not voidP(getaprop(rec,#image)) then
  116.       set image=getaprop(rec,#image)
  117.       if image<>"" then
  118.         set imageloc=imagepath&(image)
  119.         importfileinto member imageptr,imageloc
  120.         set imageptr=imageptr+1
  121.       else
  122.         set imageloc=""
  123.       end if
  124.     end if
  125.     --    if not voidP(getaprop(rec,#video)) then
  126.     --      set video=getaprop(rec,#video)
  127.     --      if video<>"" then
  128.     --        set videoloc=videopath&(video)
  129.     --      end if
  130.     --    end if
  131.     --    if not voidP(getaprop(rec,#text)) then
  132.     --      set text=getaprop(rec,#text)
  133.     --      if text<>"" then
  134.     --        set textloc=textpath&(text)
  135.     --      end if
  136.     --    end if  
  137.   end repeat
  138.   saveMovie
  139. end
  140.  
  141. on getindexedrecord me,myindex
  142.   set catlist=getprop(sectiontree,activesection)
  143.   set reclist=getprop(catlist,activecategory)
  144.   if myindex>0 and myindex<=count(reclist) then
  145.     set activerec=getprop(data,getat(reclist,myindex))
  146.   else
  147.     set activerec=0
  148.   end if
  149.   return activerec
  150. end
  151.  
  152. on getsections me
  153.   set sectionlist=[]
  154.   repeat with index=1 to count(sectiontree)
  155.     add sectionlist,getpropat(sectiontree,index)
  156.   end repeat
  157.   return sectionlist
  158. end
  159.  
  160. on getcategories me
  161.   set categorytree=getprop(sectiontree,activesection)
  162.   set categorylist=[]
  163.   repeat with index=1 to count(categorytree)
  164.     add categorylist,getpropat(categorytree,index)
  165.   end repeat
  166.   return categorylist
  167. end
  168.  
  169. on getrecords me
  170.   set categorytree=getprop(sectiontree,activesection)
  171.   set reclist=getprop(categorytree,activecategory)
  172.   return reclist
  173. end
  174.  
  175. on getrecord me,name
  176.   set testlist=[]
  177.   repeat with index=1 to count(data)
  178.     set recname=getpropat(data,index)
  179.     if recname=name then
  180.       set rec=getat(data,index)
  181.       if ((the section of rec)=activesection) and ((the category of rec)=activecategory) then
  182.         set rec=getat(data,index)
  183.         exit repeat
  184.       end if
  185.     end if
  186.   end repeat
  187.   set activerec=rec
  188.   return rec
  189. end
  190.  
  191. on searchrecords me,prop,srcstr
  192.   set searchedrecs=[]
  193.   repeat with index=1 to count(data)
  194.     set rec=getat(data,index)
  195.     set entry=getprop(rec,prop)
  196.     if offset(srcstr,entry)>0 then
  197.       add searchedrecs,rec
  198.     end if
  199.   end repeat
  200.   return searchedrecs
  201. end
  202.  
  203. on getRecordFromProp me,prop,value
  204.   repeat with index=1 to count(data)
  205.     set rec=getat(data,index)
  206.     if getprop(rec,prop)=value then
  207.       set activerec=rec
  208.       exit repeat
  209.     end if
  210.   end repeat
  211.   return activerec
  212. end
  213.