home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / organiza / bstorm.sit / HyperBrain / stack.txt < prev   
Encoding:
Text File  |  1988-02-25  |  14.2 KB  |  590 lines

  1. -- stack: in
  2. -- format: 8 (HyperCard 1)
  3. -- flags: 0x0 (none)
  4. -- protect password hash: 0
  5. -- maximum user level: 5 (scripting)
  6. -- window: Rect(x1=0, y1=0, x2=0, y2=0)
  7. -- screen: Rect(x1=0, y1=0, x2=0, y2=0)
  8. -- card dimensions: w=0 h=0
  9. -- scroll: x=0 y=0
  10. -- background count: 1
  11. -- first background id: 2690
  12. -- card count: 1
  13. -- first card id: 3351
  14. -- list block id: 2142
  15. -- print block id: 0
  16. -- font table block id: 0
  17. -- style table block id: 0
  18. -- free block count: 0
  19. -- free size: 0 bytes
  20. -- total size: 19104 bytes
  21. -- stack block size: 13312 bytes
  22. -- created by hypercard version: 0x00000000
  23. -- compacted by hypercard version: 0x00000000
  24. -- modified by hypercard version: 0x00000000
  25. -- opened by hypercard version: 0x00000000
  26. -- patterns[0]: 0x0000000000000000
  27. -- patterns[1]: 0x8000000008000000
  28. -- patterns[2]: 0x8800220088002200
  29. -- patterns[3]: 0x8888222288882222
  30. -- patterns[4]: 0x88AA22AA88AA22AA
  31. -- patterns[5]: 0xCCAA33AACCAA33AA
  32. -- patterns[6]: 0xEEAABBAAEEAABBAA
  33. -- patterns[7]: 0xEEBBBBEEEEBBBBEE
  34. -- patterns[8]: 0xFFBBFFEEFFBBFFEE
  35. -- patterns[9]: 0xFFBBFFFFFFBBFFFF
  36. -- patterns[10]: 0x8010022001084004
  37. -- patterns[11]: 0xFFFFFFFFFFFFFFFF
  38. -- patterns[12]: 0x8822882288228822
  39. -- patterns[13]: 0x1122448811224488
  40. -- patterns[14]: 0xC4800C6843023026
  41. -- patterns[15]: 0xB130031BD8C00C8D
  42. -- patterns[16]: 0xAA00AA00AA00AA00
  43. -- patterns[17]: 0x8822552288225522
  44. -- patterns[18]: 0x8855225588552255
  45. -- patterns[19]: 0x77DD77DD77DD77DD
  46. -- patterns[20]: 0x8000000000000000
  47. -- patterns[21]: 0xAA55AA55AA55AA55
  48. -- patterns[22]: 0x038448300C020101
  49. -- patterns[23]: 0x8244394482010101
  50. -- patterns[24]: 0x8814224188412214
  51. -- patterns[25]: 0x8080413E080814E3
  52. -- patterns[26]: 0x22048C7422179810
  53. -- patterns[27]: 0xBE808808EB088880
  54. -- patterns[28]: 0x25C8328964244C92
  55. -- patterns[29]: 0xA29C41BE2AC914EB
  56. -- patterns[30]: 0x40A00000040A0000
  57. -- patterns[31]: 0x8040200002040800
  58. -- patterns[32]: 0xAA00800088008000
  59. -- patterns[33]: 0xFF80808080808080
  60. -- patterns[34]: 0x081C22C180010204
  61. -- patterns[35]: 0xFF808080FF080808
  62. -- patterns[36]: 0xF87422478F172271
  63. -- patterns[37]: 0xBF00BFBFB0B0B0B0
  64. -- patterns[38]: 0xFF7FBE5DA2418000
  65. -- patterns[39]: 0xFAF5FAF5A050A050
  66. -- checksum: 0x0
  67. ----- HyperTalk script -----
  68.  
  69.  
  70. -- buttons
  71. --   19002:  empty line, icon is "Fleet, Nothing"
  72. --   19001:  currently being edited, icon is "Fleet, White"
  73. --   19000:  line has been entered, no children, "Fleet, Gray"
  74. --   22308:  line has been entered, has children, "Fleet, Next Arrow"
  75.  
  76.  
  77. on OpenStack
  78.   Hide MenuBar
  79. end OpenStack
  80.  
  81.  
  82.  
  83. -- the wait times can be optimized
  84. function GetThere
  85. put (the ticks + 600) into DieTime
  86. put 0 into NumOfAttempts
  87.  
  88. repeat forever
  89.   put NumOfAttempts + 1 into NumOfAttempts
  90.   put FileLockP( background field "Lock File" ) into temp
  91.   if temp is true then
  92.     --put "GotThere" into Msg
  93.     return true
  94.     --else
  95.     --if temp is not false then
  96.     --put ("Debug: IO Error:"&temp) into
  97.     --answer "Debug: GetThere had IO code of "&temp
  98.     --end if
  99.   end if
  100.  
  101.   if the ticks > DieTime then
  102.     answer "Timed out trying to get database" with "Look More" or "Quit"
  103.     if it is "Quit" then return false
  104.   end if
  105.  
  106.   wait (the Random of 40)
  107. end repeat
  108. end GetThere
  109.  
  110.  
  111. on ReleaseLock
  112.   repeat forever
  113.     put FileLockP( background field "Lock File", true ) into temp
  114.     if temp is true then exit ReleaseLock
  115.     --if temp is not false then
  116.     --answer "ReleaseLock CROAKED (normally):"&temp with "ribbit"
  117.     --end if
  118.     wait (the Random of 20)
  119.   end repeat
  120. end ReleaseLock
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. -- Go to the correct card in the global stack
  132. -- eventually throw in multi-user access crap
  133. function GoGlobalStack
  134. put name of this card into OurName
  135. put Word 2 of OurName into OurName
  136. put char 2 to (length of OurName - 1) of OurName into OurName
  137. set lockscreen to true
  138. if GetThere() is false then
  139.   return false
  140. end if
  141. go to stack background field "Root Stack"
  142. go to card OurName
  143. return true
  144. end GoGlobalStack
  145.  
  146.  
  147. --
  148. -- User is LEAVING this card
  149. -- -- so take their edited line
  150. -- -- go to global stack
  151. -- -- insert it in
  152. --
  153. function AddNewEdited
  154. global TheirLine, Entered
  155.  
  156. PUSH CARD        -- how we get back to our own stack
  157.  
  158. ExitUserCard     -- grab our entered data
  159.  
  160. if GoGlobalStack() is false then
  161.   POP CARD
  162.   return false
  163. end if
  164.  
  165. if Entered is not empty then
  166.   -- enter new data, leave locked
  167.   put Entered into background field ("b" & TheirLine)
  168.   set icon of button ("c" & TheirLine) to 19000
  169. else
  170.   if TheirLine > 0 and TheirLine < 11 then
  171.     -- clear lock
  172.     set icon of button ("c" & TheirLine) to 19002
  173.   end if
  174. end if
  175. return true
  176. end AddNewEdited
  177.  
  178.  
  179. --
  180. --
  181. --
  182. on GetEditableLine
  183.   global TheirLine
  184.  
  185.   repeat with TestLine = 1 to 10
  186.     if (icon of button ("c" & TestLine)) is 19002 then
  187.       put TestLine into TheirLine
  188.       set icon of button ("c" & TestLine) to 19001
  189.       exit GetEditableLine
  190.     end if
  191.   end repeat
  192.  
  193.   put 0 into TheirLine      -- nothing for them to edit
  194. end GetEditableLine
  195.  
  196.  
  197. on QuickCopyPopPaste
  198.   -- seems to take about one sec. even over AppleShare
  199.   doMenu "Copy Card"
  200.   pop card                  -- back to our own stack
  201.   ReleaseLock               -- let others access
  202.   doMenu "Paste Card"
  203.   --hide background button "New Stack"
  204.   --hide background button "Spew to File"
  205. end QuickCopyPopPaste
  206.  
  207.  
  208.  
  209. --
  210. -- Switched to proper card in global stack (somehow)
  211. -- -- (either stayed in same spot, or higher level routine moved)
  212. --
  213. on GetNewEditable
  214.   global TheirLine
  215.  
  216.   GetEditableLine           -- fills "TheirLine" with # to edit
  217.   QuickCopyPopPaste
  218.   DeleteAllButThis
  219.   EnterUserCard
  220. end GetNewEditable
  221.  
  222.  
  223. -- New Card in global stack
  224. -- we're starting in current card, any edits have already been added
  225. on NewGlobalCard WhichLine
  226.  
  227.   put background field "Root Topic" into RootTopic
  228.   put background field ("b" & WhichOne) into NewTopic
  229.   set icon of button ("c" & WhichLine) to 22308
  230.  
  231.   -- build new card, but carry along foreground buttons
  232.   doMenu "Copy Card"
  233.   doMenu "Paste Card"
  234.  
  235.   put (ParentName & "-" & WhichOne) into NewName
  236.   set name of this card to NewName
  237.   put NewName into background field "Card"
  238.   put NewTopic into background field "Topic"
  239.   put RootTopic into background field "Root Topic"
  240.  
  241. end NewGlobalCard
  242.  
  243. --
  244. -- Retrieve information that the user added
  245. --
  246. on ExitUserCard
  247.   global TheirLine, Entered
  248.  
  249.   put empty into Entered
  250.   if TheirLine > 0 and TheirLine < 11 then
  251.     put background field ("b" & TheirLine) into Entered
  252.   else
  253.     put 0 into TheirLine     -- help out for first time
  254.     put empty into Entered
  255.   end if
  256. end ExitUserCard
  257.  
  258. --
  259. -- Prepare card for user data entry/button pushing
  260. --
  261. on EnterUserCard
  262.   global TheirLine, Entered
  263.  
  264.   -- lock text on all lines
  265.   -- remove button if line is not empty
  266.   repeat with iter=1 to 10
  267.     set locktext of background field ("b" & iter) to true
  268.     -- no expansion on someone else's unfinished line
  269.     if background field ("b" & iter) is empty then
  270.       hide button ("c" & iter)
  271.     else
  272.       show button ("c" & iter)
  273.     end if
  274.   end repeat
  275.  
  276.   -- allow editing on "their" line
  277.   if TheirLine > 0 and TheirLine < 11 then
  278.     set locktext of background field ("b" & TheirLine) to false
  279.     --set icon of button ("c" & TheirLine) to 19001
  280.     show button ("c" & TheirLine)
  281.   end if
  282. end EnterUserCard
  283.  
  284.  
  285.  
  286. -- Test if we are shared Stack, or a User stack
  287. on AreWeRoot
  288.   if background field "Which One" is "Shared" then
  289.     return true
  290.   else
  291.     return false
  292.   end if
  293. end AreWeRoot
  294.  
  295.  
  296. -- Keep the user stack relatively small
  297. on DeleteAllButThis
  298.   put the id of this card into OurName
  299.   repeat forever
  300.     doMenu "Next"
  301.     if the id of this card is OurName then exit repeat
  302.     doMenu "Delete Card"
  303.   end repeat
  304. end DeleteAllButThis
  305.  
  306.  
  307. on ClickInField
  308.   global TheirLine
  309.  
  310.   set lockscreen to false
  311.   if TheirLine > 0 and TheirLine < 11 then
  312.  
  313.     repeat 5 times      -- oh bill, why do I need this?
  314.       set lockscreen to false
  315.       set locktext of background field ("b" & TheirLine) to false
  316.     end repeat
  317.  
  318.     click at loc of background field ("b" & TheirLine)
  319.   end if
  320. end ClickInField
  321.  
  322.  
  323. -- Insert BUTTON
  324. -- just insert this info, then try for another editable line
  325. on doInsert
  326.  
  327.   -- first check for illegal situation
  328.   push card
  329.   pop Card into CheckMe
  330.   put word 6 to 100 of CheckMe into CheckMe
  331.   if background field "Root Stack" is CheckMe then
  332.     beep
  333.     answer "Use a copy, not the root stack!" with "Restart"
  334.     exit doInsert
  335.   end if
  336.  
  337.   set lockscreen to true
  338.   if AddNewEdited() is false then exit doInsert
  339.   GetNewEditable
  340.   ClickInField
  341. end doInsert
  342.  
  343. on TabKey    -- same as insert button, wish could get return as well
  344.   set lockscreen to true
  345.   if AddNewEdited() is false then exit TabKey
  346.   GetNewEditable
  347.   ClickInField
  348. end TabKey
  349.  
  350.  
  351.  
  352. --
  353. -- pop up one level. if possible
  354. --
  355. on doToParent
  356.   set lockscreen to true
  357.   put word 2 of name of this card into CardName
  358.   put char 2 to (length of CardName - 1) of CardName into CardName
  359.   put length of CardName into NameL
  360.   put character NameL of CardName into LastChar
  361.   if CardName is not "Root" then
  362.     if LastChar is "0" then     -- ends in 10
  363.       put char 1 to (NameL - 3) of CardName into CardName
  364.     else
  365.       put char 1 to (NameL - 2) of CardName into CardName
  366.     end if
  367.   end if
  368.   if AddNewEdited() is false then exit doToParent
  369.   go to Card CardName
  370.   GetNewEditable
  371.   ClickInField
  372. end doToParent
  373.  
  374. on doToRoot
  375.   set lockscreen to true
  376.   if AddNewEdited() is false then exit doToRoot
  377.   go to card "Root"
  378.   GetNewEditable
  379.   ClickInField
  380. end doToRoot
  381.  
  382.  
  383. --
  384. -- user clicked on one of fleet arrows
  385. --
  386. on ExploreLine WhichOne
  387.   if AddNewEdited() is false then exit ExploreLine
  388.   FollowArrow WhichOne
  389.   GetNewEditable
  390.   ClickInField
  391. end ExploreLine
  392.  
  393.  
  394. on FollowArrow WhichOne
  395.  
  396.   -- check if possible
  397.   put background field "Root Topic" into RootTopic
  398.   put background field ("b" & WhichOne) into NewTopic
  399.   put background field "Root Stack" into RootStack
  400.   put background field "Lock File" into LockFile
  401.   if NewTopic is empty then
  402.     beep
  403.     exit FollowArrow
  404.   end if
  405.  
  406.  
  407.   put word 2 of (name of this card) into ParentName
  408.   put char 2 to (length of ParentName - 1) of ParentName into ParentName
  409.   put (ParentName & "-" & WhichOne) into NextCard
  410.   -- already been there?
  411.   if icon of button ("c" & WhichOne) is 22308 then
  412.     go to card NextCard
  413.   else
  414.     set icon of button ("c" & WhichOne) to 22308
  415.     -- New Card, but carry along foreground buttons
  416.     doMenu "Copy Card"
  417.     doMenu "Paste Card"
  418.  
  419.     set name of this card to NextCard
  420.     put NextCard into background field "Card"
  421.     put NewTopic into background field "Topic"
  422.     put RootTopic into background field "Root Topic"
  423.     put RootStack into background field "Root Stack"
  424.     put LockFile into background field "Lock File"
  425.     repeat with iter=1 to 10         -- everything is available
  426.       set icon of button ("c" & iter) to 19002
  427.       put empty into background field ("b" & iter)
  428.     end repeat
  429.   end if
  430. end FollowArrow
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437. --
  438. --    SPEW TO FILE
  439. --
  440. on CrankToFile
  441.   push card
  442.   go to stack (background field "Root Stack")
  443.   go to card "Root"
  444.   put PutFileName( (background field "Root Topic") & "--MOREΓäó format" ) into WhereTo
  445.   if WhereTo is empty then exit CrankToFile
  446.  
  447.   open file WhereTo
  448.   set lockscreen to true
  449.   write "Idea Mapping, by PcG, " & the date to file WhereTo
  450.   write return to file WhereTo
  451.   RecurseDump WhereTo, 1
  452.   close file WhereTo
  453.   set lockscreen to false
  454.  
  455.   pop card
  456.  
  457.   answer "Now you can open MOREΓäó (or MacWrite) with the file "&WhereTo
  458.   --if it is "Yes" then open WhereTo with "MOREΓäó V1.1"
  459. end CrankToFile
  460.  
  461.  
  462. -- dump this card out to the file
  463. on RecurseDump WhereTo, NumTabs
  464.   -- plop out topic
  465.   repeat for NumTabs
  466.     write Tab to file WhereTo
  467.   end repeat
  468.   write background field "Topic" to file WhereTo
  469.   write return to file WhereTo
  470.  
  471.   -- look at all fields
  472.   repeat with TheField = 1 to 10
  473.     if icon of button ("c" & TheField) is not 22308 then
  474.       if background field ("b" & TheField) is not empty then
  475.         repeat for NumTabs + 1
  476.           write Tab to file WhereTo
  477.         end repeat
  478.         write background field ("b" & TheField) to file WhereTo
  479.         write return to file WhereTo
  480.       end if
  481.     else
  482.       -- find name of recursed to card
  483.       put word 2 of name of this card into NewCard
  484.       put char 2 to (length of NewCard - 1) of NewCard into NewCard
  485.       put ( NewCard & "-" & TheField ) into NewCard
  486.  
  487.       -- recurse
  488.       push card
  489.       go to card NewCard
  490.       RecurseDump WhereTo, NumTabs + 1
  491.       pop card
  492.     end if
  493.   end repeat
  494.  
  495. end RecurseDump
  496.  
  497.  
  498.  
  499.  
  500. --
  501. -- NEW STACK
  502. --
  503. on CreateNewStack
  504.   ask "What is the new topic?"
  505.   if it is empty then exit CreateNewStack
  506.   put it into NewTopic
  507.  
  508.   DeleteAllButThis
  509.   put "Root" into background field "Card"
  510.   set the name of this card to "Root"
  511.  
  512.   repeat with WhichOne = 1 to 10
  513.     put empty into background field ("b" & WhichOne)
  514.     set locktext of background field ("b" & WhichOne) to true
  515.     show button ("c" & WhichOne)
  516.     set icon of button ("c" & WhichOne) to 19002
  517.   end repeat
  518.  
  519.   put NewTopic into background field "Topic"
  520.   put NewTopic into background field "Root Topic"
  521.  
  522.   push card
  523.   pop Card into ThisCard
  524.   put word 6 to 100 of ThisCard into ThisCard
  525.   put ThisCard into background field "Root Stack"
  526.   -- Now build "Lock File"
  527.   put DirectoryOf( ThisCard ) into LockFileName
  528.   put ( LockFileName & "Lock File" ) into LockFileName
  529.   put LockFileName into background field "Lock File"
  530.   open file LockFileName
  531.   write "UNLOCKED" to file LockFileName
  532.   close file LockFileName
  533.  
  534.   -- This card is all set for cloning now
  535.   push card
  536.  
  537.   doMenu "Copy Card"
  538.   doMenu "New Stack..."
  539.  
  540.   doMenu "Paste Card"
  541.   DeleteAllButThis
  542.  
  543.   hide background button "New Stack"
  544.   hide background button "Spew to File"
  545.   set the name of this card to "Only One"
  546.  
  547.   pop card
  548.  
  549.  
  550.   answer "Clone this new stack to all users"
  551.  
  552. end CreateNewStack
  553.  
  554.  
  555.  
  556. function DirectoryOf FullPath
  557. repeat forever
  558.   if ( char (length of FullPath) of FullPath ) is ":" then
  559.     return FullPath
  560.   end if
  561.   put char 1 to (length of FullPath - 1) of FullPath into FullPath
  562. end repeat
  563. return "Bad Path Name:"   -- will cause error
  564. end DirectoryOf
  565.  
  566.  
  567.  
  568.  
  569. -- test FileLockP robustness
  570. on Testing              -- loop through attempted file locking/releases
  571.   repeat forever
  572.     put "Look for FileServer" into Msg
  573.     put GetThere() into foo
  574.     if foo is true then
  575.       put "GotThere" into Msg
  576.       wait (60 + the Random of 120)
  577.       ReleaseLock
  578.       put "Released, now wait" into Msg
  579.     else
  580.       answer "Missed" with "AAARGGHHH"
  581.       --put "MISSED" into Msg
  582.     end if
  583.  
  584.     wait (60 + the Random of 300)
  585.   end repeat
  586. end Testing
  587.  
  588.  
  589.  
  590.