home *** CD-ROM | disk | FTP | other *** search
/ The Princeton Review - Science Smart / SCIENCE.iso / mac / files / CAD.DiR / 04132.ls < prev    next >
Encoding:
Text File  |  1995-12-08  |  11.3 KB  |  452 lines

  1. on startMovie
  2.   global fopen, gframe
  3.   put "Starting up the program. Please wait." into field 4305
  4.   preLoad(1, 1)
  5.   set gframe to EMPTY
  6.   cursor(4)
  7.   puppetSprite(42, 1)
  8.   if fopen <> 1 then
  9.     set fopen to 1
  10.     init()
  11.   end if
  12.   when keyDown then checkkey
  13.   cursor(0)
  14. end
  15.  
  16. on checkkey
  17.   if the frameLabel = "scard" then
  18.     if the key = RETURN then
  19.       if the puppet of sprite 48 = 1 then
  20.         exit
  21.       end if
  22.       sresp(8)
  23.       scardok()
  24.       dontPassEvent()
  25.     end if
  26.   end if
  27. end
  28.  
  29. on init
  30.   global log1, log2, gframe, grecent, gsectlist, gsublist, gsubsublist, csize, gunload
  31.   set csize to 4000
  32.   set gunload to 1
  33.   set the textSize of field 7 to 10
  34.   set gsectlist to 1
  35.   set gsublist to 1
  36.   set gsubsublist to 0
  37.   set grecent to EMPTY
  38.   set gframe to EMPTY
  39.   set log1 to "land"
  40.   set log2 to "land"
  41.   mfileNew()
  42.   set the hilite of cast 7758 to 1
  43.   set the hilite of cast 7761 to 1
  44.   unLoad()
  45. end
  46.  
  47. on mfileNew
  48.   global gReadObject, marklist, dloc
  49.   if objectp(gReadObject) then
  50.     gReadObject(mdispose)
  51.   end if
  52.   set gReadObject to FileIO(mnew, "read", dloc)
  53.   set mtemp to value(gReadObject(mReadLine))
  54.   if mtemp <> 0 then
  55.     set marklist to mtemp
  56.   else
  57.     set marklist to list()
  58.   end if
  59.   gReadObject(mdispose)
  60. end
  61.  
  62. on initloc
  63.   global gindexnum, gcodenum, greadnum, gpreadnum, gmapnum, ggplistnum, gsresults, gindexoffset, gslider1, gslider2, gpcountnum
  64.   set gslider1 to 4538
  65.   set gslider2 to 4539
  66.   set gindexnum to 4512
  67.   set gcodenum to 4514
  68.   set greadnum to 4515
  69.   set gpreadnum to 4516
  70.   set gmapnum to 4517
  71.   set ggplistnum to 4518
  72.   set gsresults to 5993
  73.   set gindexoffset to 4411
  74.   set gpcountnum to 4519
  75. end
  76.  
  77. on stopprint
  78.   global printer, hook
  79.   if objectp(printer) then
  80.     printer(mdispose)
  81.   end if
  82.   if objectp(hook) then
  83.     hook(mdispose)
  84.   end if
  85. end
  86.  
  87. on scardok
  88.   global gmatchlist, gmatchlistnum, gsword, log1, log2, ghits, gonsearch
  89.   set the itemDelimiter to ","
  90.   set gsword to word 1 of field 7766
  91.   if gsword = EMPTY then
  92.     exit
  93.   end if
  94.   cursor(4)
  95.   puppetSprite(9, 1)
  96.   puppetSprite(11, 1)
  97.   set the visible of sprite 9 to 0
  98.   set the visible of sprite 11 to 0
  99.   updateStage()
  100.   set gsword to word 1 of field 7766
  101.   set temp to lup(line 1 of gsword)
  102.   if word 1 of field 7756 <> EMPTY then
  103.     put word 1 of field 7756 into line 2 of gsword
  104.     set temp2 to lup(line 2 of gsword)
  105.     set exres to "put " & log1 & " (temp,temp2) into temp"
  106.     do(exres)
  107.     if word 1 of field 7757 <> EMPTY then
  108.       put word 1 of field 7757 into line 3 of gsword
  109.       set temp2 to lup(line 3 of gsword)
  110.       set exres to "put " & log2 & " (temp,temp2) into temp"
  111.       do(exres)
  112.     end if
  113.   end if
  114.   set gmatchlist to expand(temp)
  115.   set ghits to line 1 of gmatchlist
  116.   put ghits into field 7765
  117.   delete line 1 of gmatchlist
  118.   set gmatchlistnum to the number of lines in gmatchlist
  119.   put gmatchlist into field 7764
  120.   set the visible of sprite 9 to 1
  121.   set the visible of sprite 11 to 1
  122.   cursor(0)
  123.   updateStage()
  124.   puppetSprite(9, 0)
  125.   puppetSprite(11, 0)
  126.   if gmatchlistnum > 1 then
  127.     set gonsearch to 1
  128.   end if
  129.   if gmatchlist = EMPTY then
  130.     showdiag("There are no matches.")
  131.   end if
  132. end
  133.  
  134. on closeWindow
  135.   stopMovie()
  136.   tell the stage
  137.     cleanupMIAW()
  138.   end tell
  139. end
  140.  
  141. on lup vword
  142.   global stime
  143.   set stime to the ticks
  144.   set res to shash(vword)
  145.   set lnum to value(item 2 of res)
  146.   set cname to "lup" & item 1 of res
  147.   set res to line lnum of the text of cast cname
  148.   set the itemDelimiter to "!"
  149.   repeat with ind = 1 to the number of items in res
  150.     if item ind of res starts vword & "," then
  151.       set temp to item ind of res
  152.       set the itemDelimiter to ","
  153.       delete item 1 of temp
  154.       return temp
  155.     end if
  156.   end repeat
  157.   set the itemDelimiter to ","
  158.   return EMPTY
  159. end
  160.  
  161. on land l1, l2
  162.   set lres to EMPTY
  163.   set hittemp to 0
  164.   delete item 1 of l1
  165.   delete item 1 of l2
  166.   set in2 to 2
  167.   set l1count to the number of items in l1
  168.   set l2count to the number of items in l2
  169.   if (l1 = EMPTY) or (l2 = EMPTY) then
  170.     return EMPTY
  171.   end if
  172.   repeat with index = 1 to l1count / 2
  173.     set in1 to index * 2
  174.     repeat while (value(item in2 of l2) < value(item in1 of l1)) and (l2count > 0)
  175.       set in2 to in2 + 2
  176.       if in2 > l2count then
  177.         exit repeat
  178.       end if
  179.     end repeat
  180.     if item in2 of l2 = item in1 of l1 then
  181.       put integer(item in1 - 1 of l1 + item in2 - 1 of l2) & "," & item in1 of l1 & "," after lres
  182.       set hittemp to hittemp + item in1 - 1 of l1 + item in2 - 1 of l2
  183.     end if
  184.   end repeat
  185.   delete item the number of items in lres of lres
  186.   set hittemp to integer(hittemp) & "/" & integer(the number of items in lres / 2)
  187.   return hittemp & "," & lres
  188. end
  189.  
  190. on lor l1, l2
  191.   set hittemp to 0
  192.   set lres to EMPTY
  193.   delete item 1 of l1
  194.   delete item 1 of l2
  195.   set l1count to the number of items in l1
  196.   set l2count to the number of items in l2
  197.   if l1count = 1 then
  198.     set l1count to 0
  199.   end if
  200.   if l2count = 1 then
  201.     set l2count to 0
  202.   end if
  203.   set in2 to 2
  204.   repeat with index = 1 to l1count / 2
  205.     set in1 to index * 2
  206.     repeat while (in2 <= l2count) and (value(item in2 of l2) < value(item in1 of l1))
  207.       put item in2 - 1 of l2 & "," & item in2 of l2 & "," after lres
  208.       set in2 to in2 + 2
  209.       if in2 = l2count then
  210.         put item in2 - 1 of l2 & "," & item in2 of l2 & "," after lres
  211.       end if
  212.     end repeat
  213.     if item in2 of l2 = item in1 of l1 then
  214.       put integer(item in1 - 1 of l1 + item in2 - 1 of l2) & "," & item in1 of l1 & "," after lres
  215.       set in2 to in2 + 2
  216.       next repeat
  217.     end if
  218.     put item in1 - 1 of l1 & "," & item in1 of l1 & "," after lres
  219.   end repeat
  220.   if in2 < l2count then
  221.     put item in2 - 1 to l2count of l2 & "," after lres
  222.   end if
  223.   delete item the number of items in lres of lres
  224.   set xnum to the number of items in lres
  225.   repeat with index = 0 to (xnum / 2) - 1
  226.     set hittemp to hittemp + item (2 * index) + 1 of lres
  227.   end repeat
  228.   set hittemp to integer(hittemp) & "/" & integer(xnum / 2)
  229.   return hittemp & "," & lres
  230. end
  231.  
  232. on lbnot l1, l2
  233.   set lres to EMPTY
  234.   set hittemp to 0
  235.   delete item 1 of l1
  236.   delete item 1 of l2
  237.   set l1count to the number of items in l1
  238.   set l2count to the number of items in l2
  239.   if l1count = 1 then
  240.     set l1count to 0
  241.   end if
  242.   if l2count = 1 then
  243.     set l2count to 0
  244.   end if
  245.   set in2 to 2
  246.   repeat with index = 1 to l1count / 2
  247.     set in1 to index * 2
  248.     repeat while (l2count > 0) and (in2 <= l2count) and (value(item in2 of l2) < value(item in1 of l1))
  249.       set in2 to in2 + 2
  250.     end repeat
  251.     if item in2 of l2 <> item in1 of l1 then
  252.       put item in1 - 1 of l1 & "," & item in1 of l1 & "," after lres
  253.     end if
  254.   end repeat
  255.   if the number of items in lres = 1 then
  256.     return EMPTY
  257.   end if
  258.   delete item the number of items in lres of lres
  259.   set xnum to the number of items in lres
  260.   repeat with index = 0 to (xnum / 2) - 1
  261.     set hittemp to hittemp + item (2 * index) + 1 of lres
  262.   end repeat
  263.   set hittemp to integer(hittemp) & "/" & integer(xnum / 2)
  264.   return hittemp & "," & lres
  265. end
  266.  
  267. on clearall
  268.   global rval, son, gsword, scard, gmatchlist, log1, log2, ghits, gscardon, gmatchlistnum, gonsearch
  269.   cursor(4)
  270.   go("clearcard")
  271.   set gmatchlistnum to 0
  272.   set gonsearch to 0
  273.   set log1 to "land"
  274.   set log2 to "land"
  275.   set rval to EMPTY
  276.   set son to EMPTY
  277.   set gscardon to EMPTY
  278.   set gsword to EMPTY
  279.   set scard to EMPTY
  280.   set ghits to EMPTY
  281.   set gmatchlist to EMPTY
  282.   put EMPTY into field 7764
  283.   put EMPTY into field 7766
  284.   put EMPTY into field 7756
  285.   put EMPTY into field 7757
  286.   put EMPTY into field 7765
  287.   set the hilite of cast 7758 to 1
  288.   set the hilite of cast 7759 to 0
  289.   set the hilite of cast 7760 to 0
  290.   set the hilite of cast 7761 to 1
  291.   set the hilite of cast 7762 to 0
  292.   set the hilite of cast 7763 to 0
  293.   switchmatch(2060)
  294.   go("scard")
  295.   cursor(0)
  296. end
  297.  
  298. on expand temp
  299.   set res to EMPTY
  300.   set num to (the number of items in temp - 1) / 2
  301.   repeat with index = 1 to num
  302.     put item index * 2 of temp & "   " & numtoframe(item (index * 2) + 1 of temp) into line index + 1 of res
  303.   end repeat
  304.   put item 1 of temp into line 1 of res
  305.   return res
  306. end
  307.  
  308. on doentermainframe
  309.   global gpcount
  310.   setmatch()
  311.   set temp to numtoframe(the frame)
  312.   updatemarked(temp)
  313.   set temp to stripend(temp)
  314.   updaterecent(temp)
  315. end
  316.  
  317. on doenterpframe
  318.   global gpcount
  319.   set temp to numtoframe(the frame)
  320.   updatemarked(temp)
  321.   set temp to stripend(temp)
  322.   set temp to temp & " P"
  323.   updaterecent(temp)
  324. end
  325.  
  326. on updatemarked card
  327.   global marklist
  328.   set mvar to getOne(marklist, card)
  329.   if mvar >= 1 then
  330.     puppetSprite(43, 1)
  331.     set the locV of sprite 43 to 25
  332.   else
  333.     puppetSprite(43, 0)
  334.   end if
  335. end
  336.  
  337. on shash vword
  338.   set vword to tolower(vword)
  339.   set hashkey to EMPTY
  340.   set ex to length(vword)
  341.   if ex > 6 then
  342.     set ex to 6
  343.   end if
  344.   repeat with ind = 1 to ex
  345.     put charToNum(char ind of vword) after hashkey
  346.   end repeat
  347.   put ".0" after hashkey
  348.   set res1 to rmod((25173 * hashkey) + 13849, 65567)
  349.   set res2 to rmod(res1, 6000)
  350.   put strip(rdiv(res2, 300) + 1) into item 1 of finres
  351.   put strip(rmod(res2, 300) + 1) into item 2 of finres
  352.   return finres
  353. end
  354.  
  355. on shash2 vword
  356.   set vword to tolower(vword)
  357.   set hashkey to EMPTY
  358.   set ex to length(vword)
  359.   if ex > 6 then
  360.     set x to 6
  361.   end if
  362.   repeat with ind = 1 to x
  363.     put charToNum(char ind of vword) after hashkey
  364.   end repeat
  365.   put ".0" after hashkey
  366.   set hashkey to rmod(hashkey, 6000)
  367.   put strip(rdiv(hashkey, 300) + 1) into item 1 of finres
  368.   put strip(rmod(hashkey, 300) + 1) into item 2 of finres
  369.   return finres
  370. end
  371.  
  372. on rmod vnum, mnum
  373.   set vnumt to vnum / mnum
  374.   set numtemp to string(vnumt)
  375.   set varplace to offset(".", numtemp)
  376.   set numtemp to char 1 to varplace - 1 of numtemp
  377.   set nx to numtemp
  378.   return vnum - (nx * mnum)
  379. end
  380.  
  381. on rdiv vnum, mnum
  382.   set vnumt to vnum / mnum
  383.   set numtemp to string(vnumt)
  384.   set varplace to offset(".", numtemp)
  385.   set numtemp to char 1 to varplace - 1 of numtemp
  386.   return numtemp
  387. end
  388.  
  389. on strip num
  390.   set num to string(num)
  391.   set varplace to offset(".", num)
  392.   set num to char 1 to varplace - 1 of num
  393.   return value(num)
  394. end
  395.  
  396. on tolower pword
  397.   set wdnum to the number of chars in pword
  398.   repeat with x = 1 to wdnum
  399.     if (charToNum(char x of pword) >= 97) and (charToNum(char x of pword) <= 122) then
  400.       put numToChar(charToNum(char x of pword) - 32) into char x of pword
  401.     end if
  402.   end repeat
  403.   return pword
  404. end
  405.  
  406. on stripparts pword
  407.   set wdnum to the number of chars in pword
  408.   repeat while wdnum > 0
  409.     set avalue to charToNum(char 1 of pword)
  410.     if ((avalue >= 65) and (avalue <= 90)) or ((avalue >= 97) and (avalue <= 122)) then
  411.       exit repeat
  412.       next repeat
  413.     end if
  414.     delete char 1 of pword
  415.     set wdnum to wdnum - 1
  416.   end repeat
  417.   repeat while wdnum > 0
  418.     set avalue to charToNum(char wdnum of pword)
  419.     if ((avalue >= 65) and (avalue <= 90)) or ((avalue >= 97) and (avalue <= 122)) then
  420.       exit repeat
  421.       next repeat
  422.     end if
  423.     delete char wdnum of pword
  424.     set wdnum to wdnum - 1
  425.   end repeat
  426.   return pword
  427. end
  428.  
  429. on updaterecent card
  430.   global grecent
  431.   set numline to the number of lines in grecent
  432.   if grecent = EMPTY then
  433.     set grecent to card
  434.     exit
  435.   end if
  436.   repeat with index = 1 to numline
  437.     if line index of grecent = card then
  438.       put card into line numline + 1 of grecent
  439.       delete line index of grecent
  440.       exit
  441.     end if
  442.   end repeat
  443.   put card into line numline + 1 of grecent
  444.   if numline = 20 then
  445.     delete line 1 of grecent
  446.   end if
  447. end
  448.  
  449. on stripend what
  450.   return word 1 to the number of words in what - 1 of what
  451. end
  452.