home *** CD-ROM | disk | FTP | other *** search
/ The Princeton Review - Science Smart / SCIENCE.iso / pc / science / files / cad.dir / 04132.ls < prev    next >
Encoding:
Text File  |  1996-01-26  |  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 puppet of sprite 48 = 1 then
  18.     exit
  19.   end if
  20.   if the frameLabel = "scard" then
  21.     if the key = RETURN then
  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
  31.   set gsectlist to 1
  32.   set gsublist to 1
  33.   set gsubsublist to 0
  34.   set grecent to EMPTY
  35.   set gframe to EMPTY
  36.   set log1 to "land"
  37.   set log2 to "land"
  38.   mfileNew()
  39.   set the hilite of cast 7758 to 1
  40.   set the hilite of cast 7761 to 1
  41.   unLoad()
  42. end
  43.  
  44. on mfileNew
  45.   global gReadObject, marklist, dloc
  46.   if objectp(gReadObject) then
  47.     gReadObject(mdispose)
  48.   end if
  49.   set gReadObject to FileIO(mnew, "read", dloc)
  50.   set mtemp to value(gReadObject(mReadLine))
  51.   if mtemp <> 0 then
  52.     set marklist to mtemp
  53.   else
  54.     set marklist to list()
  55.   end if
  56.   gReadObject(mdispose)
  57. end
  58.  
  59. on initloc
  60.   global gindexnum, gcodenum, greadnum, gpreadnum, gmapnum, ggplistnum, gsresults, gindexoffset, gslider1, gslider2, gpcountnum
  61.   set gslider1 to 4538
  62.   set gslider2 to 4539
  63.   set gindexnum to 4512
  64.   set gcodenum to 4514
  65.   set greadnum to 4515
  66.   set gpreadnum to 4516
  67.   set gmapnum to 4517
  68.   set ggplistnum to 4518
  69.   set gsresults to 5993
  70.   set gindexoffset to 4411
  71.   set gpcountnum to 4519
  72. end
  73.  
  74. on stopprint
  75.   global printer, hook
  76.   if objectp(printer) then
  77.     printer(mdispose)
  78.   end if
  79.   if objectp(hook) then
  80.     hook(mdispose)
  81.   end if
  82. end
  83.  
  84. on scardok
  85.   global gmatchlist, gmatchlistnum, gsword, log1, log2, ghits, gonsearch
  86.   set the itemDelimiter to ","
  87.   set gsword to word 1 of field 7766
  88.   if gsword = EMPTY then
  89.     exit
  90.   end if
  91.   cursor(4)
  92.   puppetSprite(9, 1)
  93.   puppetSprite(11, 1)
  94.   set the visible of sprite 9 to 0
  95.   set the visible of sprite 11 to 0
  96.   updateStage()
  97.   set gsword to word 1 of field 7766
  98.   set temp to lup(line 1 of gsword)
  99.   if word 1 of field 7756 <> EMPTY then
  100.     put line 1 of field 7756 into line 2 of gsword
  101.     set temp2 to lup(line 2 of gsword)
  102.     set exres to "put " & log1 & " (temp,temp2) into temp"
  103.     do(exres)
  104.     if line 1 of field 7757 <> EMPTY then
  105.       put line 1 of field 7757 into line 3 of gsword
  106.       set temp2 to lup(line 3 of gsword)
  107.       set exres to "put " & log2 & " (temp,temp2) into temp"
  108.       do(exres)
  109.     end if
  110.   end if
  111.   set gmatchlist to expand(temp)
  112.   set ghits to line 1 of gmatchlist
  113.   put ghits into field 7765
  114.   delete line 1 of gmatchlist
  115.   set gmatchlistnum to the number of lines in gmatchlist
  116.   put gmatchlist into field 7764
  117.   set the visible of sprite 9 to 1
  118.   set the visible of sprite 11 to 1
  119.   cursor(0)
  120.   updateStage()
  121.   puppetSprite(9, 0)
  122.   puppetSprite(11, 0)
  123.   if gmatchlistnum > 1 then
  124.     set gonsearch to 1
  125.   end if
  126.   if gmatchlist = EMPTY then
  127.     showdiag("There are no matches.")
  128.   end if
  129. end
  130.  
  131. on closeWindow
  132.   stopMovie()
  133.   tell the stage
  134.     cleanupMIAW()
  135.   end tell
  136. end
  137.  
  138. on lup vword
  139.   global stime
  140.   set stime to the ticks
  141.   set res to shash(vword)
  142.   set lnum to value(item 2 of res)
  143.   set cname to "lup" & item 1 of res
  144.   set res to line lnum of the text of cast cname
  145.   set the itemDelimiter to "!"
  146.   repeat with ind = 1 to the number of items in res
  147.     if item ind of res starts vword & "," then
  148.       set temp to item ind of res
  149.       set the itemDelimiter to ","
  150.       delete item 1 of temp
  151.       return temp
  152.     end if
  153.   end repeat
  154.   set the itemDelimiter to ","
  155.   return EMPTY
  156. end
  157.  
  158. on land l1, l2
  159.   set lres to EMPTY
  160.   set hittemp to 0
  161.   delete item 1 of l1
  162.   delete item 1 of l2
  163.   set in2 to 2
  164.   set l1count to the number of items in l1
  165.   set l2count to the number of items in l2
  166.   if (l1 = EMPTY) or (l2 = EMPTY) then
  167.     return EMPTY
  168.   end if
  169.   repeat with index = 1 to l1count / 2
  170.     set in1 to index * 2
  171.     repeat while (value(item in2 of l2) < value(item in1 of l1)) and (l2count > 0)
  172.       set in2 to in2 + 2
  173.       if in2 > l2count then
  174.         exit repeat
  175.       end if
  176.     end repeat
  177.     if item in2 of l2 = item in1 of l1 then
  178.       put integer(item in1 - 1 of l1 + item in2 - 1 of l2) & "," & item in1 of l1 & "," after lres
  179.       set hittemp to hittemp + item in1 - 1 of l1 + item in2 - 1 of l2
  180.     end if
  181.   end repeat
  182.   delete item the number of items in lres of lres
  183.   set hittemp to integer(hittemp) & "/" & integer(the number of items in lres / 2)
  184.   return hittemp & "," & lres
  185. end
  186.  
  187. on lor l1, l2
  188.   set hittemp to 0
  189.   set lres to EMPTY
  190.   delete item 1 of l1
  191.   delete item 1 of l2
  192.   set l1count to the number of items in l1
  193.   set l2count to the number of items in l2
  194.   if l1count = 1 then
  195.     set l1count to 0
  196.   end if
  197.   if l2count = 1 then
  198.     set l2count to 0
  199.   end if
  200.   set in2 to 2
  201.   repeat with index = 1 to l1count / 2
  202.     set in1 to index * 2
  203.     repeat while (in2 <= l2count) and (value(item in2 of l2) < value(item in1 of l1))
  204.       put item in2 - 1 of l2 & "," & item in2 of l2 & "," after lres
  205.       set in2 to in2 + 2
  206.       if in2 = l2count then
  207.         put item in2 - 1 of l2 & "," & item in2 of l2 & "," after lres
  208.       end if
  209.     end repeat
  210.     if item in2 of l2 = item in1 of l1 then
  211.       put integer(item in1 - 1 of l1 + item in2 - 1 of l2) & "," & item in1 of l1 & "," after lres
  212.       set in2 to in2 + 2
  213.       next repeat
  214.     end if
  215.     put item in1 - 1 of l1 & "," & item in1 of l1 & "," after lres
  216.   end repeat
  217.   if in2 < l2count then
  218.     put item in2 - 1 to l2count of l2 & "," after lres
  219.   end if
  220.   delete item the number of items in lres of lres
  221.   set xnum to the number of items in lres
  222.   repeat with index = 0 to (xnum / 2) - 1
  223.     set hittemp to hittemp + item (2 * index) + 1 of lres
  224.   end repeat
  225.   set hittemp to integer(hittemp) & "/" & integer(xnum / 2)
  226.   return hittemp & "," & lres
  227. end
  228.  
  229. on lbnot l1, l2
  230.   set lres to EMPTY
  231.   set hittemp to 0
  232.   delete item 1 of l1
  233.   delete item 1 of l2
  234.   set l1count to the number of items in l1
  235.   set l2count to the number of items in l2
  236.   if l1count = 1 then
  237.     set l1count to 0
  238.   end if
  239.   if l2count = 1 then
  240.     set l2count to 0
  241.   end if
  242.   set in2 to 2
  243.   repeat with index = 1 to l1count / 2
  244.     set in1 to index * 2
  245.     repeat while (l2count > 0) and (in2 <= l2count) and (value(item in2 of l2) < value(item in1 of l1))
  246.       set in2 to in2 + 2
  247.     end repeat
  248.     if item in2 of l2 <> item in1 of l1 then
  249.       put item in1 - 1 of l1 & "," & item in1 of l1 & "," after lres
  250.     end if
  251.   end repeat
  252.   if the number of items in lres = 1 then
  253.     return EMPTY
  254.   end if
  255.   delete item the number of items in lres of lres
  256.   set xnum to the number of items in lres
  257.   repeat with index = 0 to (xnum / 2) - 1
  258.     set hittemp to hittemp + item (2 * index) + 1 of lres
  259.   end repeat
  260.   set hittemp to integer(hittemp) & "/" & integer(xnum / 2)
  261.   return hittemp & "," & lres
  262. end
  263.  
  264. on clearall
  265.   global rval, son, gsword, scard, gmatchlist, log1, log2, ghits, gscardon, gmatchlistnum, gonsearch
  266.   cursor(4)
  267.   go("clearcard")
  268.   set gmatchlistnum to 0
  269.   set gonsearch to 0
  270.   set log1 to "land"
  271.   set log2 to "land"
  272.   set rval to EMPTY
  273.   set son to EMPTY
  274.   set gscardon to EMPTY
  275.   set gsword to EMPTY
  276.   set scard to EMPTY
  277.   set ghits to EMPTY
  278.   set gmatchlist to EMPTY
  279.   put EMPTY into field 7764
  280.   put EMPTY into field 7766
  281.   put EMPTY into field 7756
  282.   put EMPTY into field 7757
  283.   put EMPTY into field 7765
  284.   set the hilite of cast 7758 to 1
  285.   set the hilite of cast 7759 to 0
  286.   set the hilite of cast 7760 to 0
  287.   set the hilite of cast 7761 to 1
  288.   set the hilite of cast 7762 to 0
  289.   set the hilite of cast 7763 to 0
  290.   switchmatch(2060)
  291.   go("scard")
  292.   cursor(0)
  293. end
  294.  
  295. on expand temp
  296.   set res to EMPTY
  297.   set num to (the number of items in temp - 1) / 2
  298.   repeat with index = 1 to num
  299.     put item index * 2 of temp & "   " & numtoframe(item (index * 2) + 1 of temp) into line index + 1 of res
  300.   end repeat
  301.   put item 1 of temp into line 1 of res
  302.   repeat while word 2 of line the number of lines in res of res = "0"
  303.     delete line the number of lines in res of res
  304.   end repeat
  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.