home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / auto / cm95-10.zip / CUPCAKE.OZ < prev    next >
Text File  |  1996-08-30  |  7KB  |  212 lines

  1. ;Gets the latest Cupcake's CB Society Column, a twice-monthly newsletter for
  2. ;Compuserve CB aficionados.
  3.  
  4. ;****************************************************************************
  5. ; ClockMan95 Automation Assistant support file
  6. ; (c) 1995 Graphical Dynamics, Inc. The "Common helper functions" are placed
  7. ; in the public domain; otherwise permission is granted to use/modify this
  8. ; script file as long as it's not for resale.
  9. ;
  10. ; Written by: Jennifer Palonus
  11. ;
  12. ; Date    Who    Major changes
  13. ;-------  ---    -------------------------------------------------------------
  14. ;20aug95  jlp    Created.
  15. ;****************************************************************************
  16.     define $ServiceName        ; used by GoService
  17.     define #ServiceHasHdr    ; used by GoService
  18.     define $MenuItem        ; used by ChooseMenuItem & FindMenuItem
  19.     define $SubjectLine        ; used by CaptureMsg
  20.     define $Prompt            ; used by WaitForPrompt
  21.     define #OK                ; used everywhere. Routines return %TRUE or /%FALSE
  22.     onerror HandleErrors
  23.     timeout 90
  24.  
  25.  
  26. ;****************************************************************************
  27. ; Main processing section.
  28. ;****************************************************************************
  29.     set $ServiceName    "CIS:CUPCAKE"
  30.     set #ServiceHasHdr  %FALSE
  31.     set $Prompt         ^M^J "!"
  32.     gosub GoService
  33.  
  34.     set $MenuItem       "1"
  35.     gosub ChooseMenuItem
  36.  
  37.     set $SubjectLine    "Cupcake's CB Society Column"
  38.     if $MenuItem <> "" gosub CaptureMsg
  39.     end
  40.  
  41.  
  42. ;****************************************************************************
  43. ; Common helper functions. (These are placed in the "public domain" by GDI.)
  44. ;****************************************************************************
  45. ; GoService
  46. ;
  47. ; Carries out a GO command & passes over the introductory text (if any).
  48. ; When this returns, you're ready to capture or parse the service's top menu.
  49. ;
  50. ; $ServiceName        The CIS service you want to GO to.
  51. ; #ServiceHasHdr    Does this service have an intro paragraph ending with a
  52. ;                    "MORE !" prompt?
  53. ;****************************************************************************
  54. GoService:
  55.     set #OK %TRUE
  56.     sendln "GO " $ServiceName
  57.  
  58.     if #ServiceHasHdr = %FALSE return
  59.     set $Prompt ^M^J "MORE !"         
  60.     gosub WaitForPrompt
  61.     send %CR
  62.     return
  63.  
  64.     
  65. ;****************************************************************************
  66. ; ChooseMenuItem
  67. ;
  68. ; Selects an article (by item #) from a menu. Upon return, you're ready to
  69. ; CaptureMsg it.
  70. ;
  71. ; $MenuItem            The menu selection #.
  72. ; $SubjectLine        The generated mail message's subject line if different
  73. ;                    than the default.
  74. ; $Prompt            The prompt that ends the article. Usu. ^M^J "!".
  75. ;****************************************************************************
  76. ChooseMenuItem:
  77.     set #OK %TRUE
  78.     set $Prompt ^M^J "!"
  79.     gosub WaitForPrompt
  80.  
  81.     sendln $MenuItem
  82.     wait ^M^J            ; Skip echo of menu item #
  83.     return
  84.  
  85.  
  86. ;****************************************************************************
  87. ; FindMenuItem
  88. ;
  89. ; Selects the first item in a menu that contains the string in $MenuItem.
  90. ; Assumes the menu is being sent & ready to parse.
  91. ;
  92. ; This is for services that keep adding articles to the front of the menu,
  93. ; and the article we're looking for always has the same title. There can end
  94. ; up being 0, 1, or more items with the same name, in unpredictable positions
  95. ; in the menu. The 1st one we find (lowest item #) is the most recent one.
  96. ; (ex.: AP's "Today in History", or "<day>'s Most Active Stocks", etc.)
  97. ;
  98. ; Using this routine also protects you when the provider moves items around
  99. ; within a menu. (It doesn't protect against the provider changing menu
  100. ; item names or moving items to other menus.)
  101. ;
  102. ; Upon return, #OK is %TRUE or %FALSE depending on whether any items were
  103. ; found that contained $MenuItem. If %TRUE then $MenuItem is also set to the
  104. ; full menu item description & caller is ready to capture or parse the
  105. ; selected article/submenu.
  106. ;
  107. ; If $MenuItem is found in the preface to the menu, then I guess we could get
  108. ; into trouble!
  109. ;
  110. ; $MenuItem            The menu selection name (or partial name).
  111. ; $SubjectLine        The generated mail message's subject line if different
  112. ;                    than the default.
  113. ; $Prompt            The prompt that ends the article. Usu. ^M^J "!".
  114. ;****************************************************************************
  115. FindMenuItem:
  116.     define $FMILine
  117.     define $FMIItem
  118.     define $FMINum
  119.     define #FMIToken
  120.     define #FMIFound
  121.  
  122.     set #OK %TRUE
  123.     FMILoop:
  124.         add 1 "!"
  125.         add 2 ^M^J                ; Examine each line in turn...
  126.         mwait #FMIToken
  127.         
  128.         if #FMIToken = 2 goto FMICheckWholeLine
  129.  
  130.         ; ...else this is either a "!" or "MORE !" prompt, or a
  131.         ; stray "!" or "MORE !" inside a whole line...
  132.         set $FMILine %COMDATA
  133.         trim $FMILine
  134.  
  135.         ; If multipart menu, tell CIS to send next part...
  136.         if $FMILine = "MORE !" send %CR
  137.         if $FMILine = "MORE !" goto FMILoop
  138.  
  139.         ; If end of full menu & item wasn't found...
  140.         if $FMILine = "!" set #OK %FALSE
  141.         if $FMILine = "!" return
  142.  
  143.         FMICheckWholeLine:
  144.         set $FMILine %LCOMDATA
  145.         
  146.         ; Split off what should be item description & check it...
  147.         midstr $FMILine 4 255 $FMIItem
  148.         posnc #FMIFound $MenuItem $FMIItem
  149.     if #FMIFound = 0 goto FMILoop
  150.     
  151.     ; If we get here, we've found $MenuItem in a line...
  152.     midstr $FMILine 1 2 $FMINum
  153.     trim $FMINum        ; We ASSUME first nonblank chars are a real menu item #!
  154.  
  155.     ; Now that we have our item, skip the rest of the menu...
  156.     set $Prompt ^M^J "!"
  157.     gosub WaitForPrompt
  158.     sendln $FMINum
  159.     wait ^M^J                    ; Skip echo of menu item #
  160.     set $MenuItem $FMIItem        ; Return full menu item description
  161.     return
  162.  
  163.  
  164. ;****************************************************************************
  165. ; CaptureMsg
  166. ;
  167. ; Assuming CIS is about to send us the text that we want to place into a mail
  168. ; message, this routine captures the text 'till we get a <CR> & ! prompt.
  169. ;
  170. ; $SubjectLine        The custom subject line if different than the default.
  171. ; $Prompt            The prompt that ends the article. Usu. ^M^J "!".
  172. ;****************************************************************************
  173. CaptureMsg:
  174.     set #OK %TRUE
  175.     capture on CISMAIL.MSG
  176.     if $SubjectLine =  "" WMH
  177.     if $SubjectLine <> "" WMH $SubjectLine
  178.  
  179.     gosub WaitForPrompt
  180.     capture off
  181.  
  182.     set $SubjectLine ""
  183.     return
  184.  
  185.  
  186. ;****************************************************************************
  187. ; WaitForPrompt
  188. ;
  189. ; Wait till the end of a menu or opening text. This routine handles menus
  190. ; split up into multiple chunks, each of which end in "MORE !" prompts.
  191. ; If you DO want to wait for "MORE !", then set $Prompt to it.
  192. ;
  193. ; $Prompt            The prompt you're waiting for. Usu. ^M^J "!".
  194. ;****************************************************************************
  195. WaitForPrompt:
  196.     define #WFPToken
  197.     set #OK %TRUE
  198.     
  199.     add 1 $Prompt
  200.     add 2 ^M^J "MORE !"
  201.     mwait #WFPToken
  202.     if #WFPToken = 2 send %CR
  203.     if #WFPToken = 2 goto WaitForPrompt
  204.  
  205.     return
  206.  
  207.  
  208. ;****************************************************************************
  209. HandleErrors:
  210.     fail
  211.  
  212.