home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ircii30.zip / script / imap < prev    next >
Text File  |  1994-07-30  |  7KB  |  221 lines

  1. # imap version 1.0  by Ian Frechette.
  2. # To give credit where credit is due, this was inspired by Run's
  3. # ircmap2 script.  I looked at it once and decided it was slow and kludgy to
  4. # deal with and wrote my own.  All code here is original to me.
  5. #
  6. # Currently the only commands  are
  7. # /initmap [stuff]        - which will create a the data by issuing a /links 
  8. #                         from the current server.
  9. #                         - stuff can be whatever.. The map is split up if you
  10. #                         you try to use stuff.. try   '*.ca *'
  11. # /gomap [server_name]    - will show the current map of the visible irc
  12. #                         network.  If a servername is given it'll try to
  13. #                         recurse outward from that server instead of the
  14. #                         current server.
  15. # Note: you may issue the /gomap command as many times as you want after
  16. # the data has been created.  You may also /initmap at any time to update the
  17. # data.
  18. #
  19. # Note Also.. as of yet hostmasks are not possible, nor would they really
  20. # make much sense.
  21. #
  22.  
  23. ^set novice off
  24. ^set max_recursion 50
  25.  
  26. @ RCS.imap = [$$Header: /local/cvs/ircii/script/imap,v 1.2 1994/07/30 18:22:03 mrg stable $$]
  27. eval @ map.mask = encode(*.)
  28. # @ map.str = [| | | | | | | | | | | | | | | | | | | | | | | ]
  29.  
  30. #  It starts builds the map data list.   working on args now
  31. alias initmap {
  32.     echo *** imap: removing any old map data around
  33.     purge maplist
  34.     purge maplist2
  35.     purge maphublist
  36.     echo *** imap: building links list to use later
  37.     echo *** imap: please wait until it's finished .....
  38.     map.buildlist $*
  39. }
  40.  
  41. # This alias may take a server name as an argument or it may 
  42. # be left blank.
  43. # gomap tries to display the entire irc map from the point of view of
  44. # the given server or if no arg is given from the server the list was
  45. # built on.
  46. alias gomap {
  47.     if ([$0] != [])
  48.         {@ map.toptree = encode($tolower($0))}
  49.         {@ map.toptree = encode($tolower($map.from))}
  50.     echo *** Displaying map from $decode($map.toptree)
  51.     echo 0   $decode($map.toptree)
  52.     makemap 1 $map.toptree
  53.     map.restore
  54.     echo *** imap: done displaying map
  55. }
  56.  
  57. # used internally to build the actual map data list.  Takes no args.
  58. # This also constucts a list of hostmasks to be used by map.cleanmasks
  59. alias map.buildlist {
  60.     ^on ^364 * {
  61.         @ map.from = [$0]
  62.         @ map.srv = [$1]
  63.         @ map.uplink = [$2]
  64.         @ map.hops = [$3]
  65. #        ^set status_user2 . 
  66.         if (left(1 $map.srv) == [*]) {
  67.             @ mapmasklist[$encode($tolower($map.srv))] = map.srv
  68.         }
  69.         @ map.hub = encode($tolower($map.uplink))
  70.         @ maphublist[$map.hub] = maphublist[$map.hub] + 1
  71.         @ maplist[$map.hub][$encode($tolower($map.srv))] = map.hops
  72. #        ^set status_user2  .
  73.     }
  74.     ^on ^365 * {
  75.         ^on 364 -*
  76.         echo *** imap: Done building links list
  77.         ^set -status_user2
  78.         ^on 365 -*
  79.         @ map.tmp = encode($tolower($map.from))
  80.         ^assign -maplist[$map.tmp][$map.tmp]
  81.         @ maphublist[$map.tmp] = maphublist[$map.tmp] - 1
  82.         map.cleanmasks
  83.         map.save
  84.         echo *** imap: you may now issue a /gomap to view irc map
  85.     }
  86.     //links $*
  87. }
  88.  
  89. # called after the initial list is constucted.  no args.
  90. # This go through the main list of hubs and strips the names down to 
  91. # the hostmask so..  hub goren.u.washington.edu becomes *.washington.edu
  92. # the mask are determined from the servername field so this step cannot
  93. # be done until after the data list is complete
  94. alias map.cleanmasks {
  95.     foreach mapmasklist ii {
  96.         foreach maplist jj {
  97.             if (match(*$mid(2 100 $ii) $jj))
  98.             {
  99.                 foreach maplist.$jj kk {
  100.                     @ maplist[$ii][$kk] = maplist[$jj][$kk]
  101.                     ^assign -maplist[$jj][$kk]
  102.                 }
  103.                 @ maphublist[$ii] = maphublist[$jj]
  104.                 ^assign -maphublist[$jj]
  105.             }
  106.         }
  107.         ^assign -mapmasklist[$ii]
  108.     }
  109.     echo *** imap: map data masks have been cleaned
  110. }
  111.     
  112.  
  113. # used for debugging only
  114. # /showmap  will show you a list of the raw data.  Lists all hub servers
  115. #           sorted alphabetically with leafs of that hub following
  116. # a servername may be supplied as an argument and this will list only
  117. # the info for that one hub
  118. alias showmap {
  119.     if ([$0] == [])
  120.     {
  121.         foreach maplist ii {
  122.             foreach maplist.$ii jj {
  123.                 echo $decode($ii) links $decode($jj)
  124.             }
  125.         }
  126.     }
  127.     {
  128.         foreach maplist.$encode($tolower($0)) ii {
  129.             foreach maplist.$ii jj {
  130.                 echo $decode($ii) links $decode($jj)
  131.             }
  132.         }
  133.     }
  134. }
  135.  
  136. # called with  makemap level server
  137. # this is the real workhorse.. It's a recursive function.. It starts at
  138. # recursion level 1 and follows the servers through the data.
  139. # The following example doesn't use real argument types.
  140. # e.g.   makemap 1 colorado  looks at colorado's list of links
  141. #                            displays each one and then recurses into that
  142. #                            link if it can.  So when it gets to uiuc 
  143. #                            makemap is  called.   makemap 2 uiuc
  144. #                            and it follows it's links etc etc..
  145. # loops in the data are avoided by removing each link from the list entirely
  146. # as it's used.  map.restore can be called later to restore data
  147. #             
  148. alias makemap {
  149.     @ map.ind[$0] = 0
  150.     foreach maplist.$1 ii$0 {
  151.         echo $lformat(3 $0) $map.outmask(1 $0)`-$decode($(ii$0)) $maplist[$1][$(ii$0)]
  152.         ^assign -maplist[$1][$(ii$0)]
  153.         if ((map.ind[$0] = map.ind[$0] +1) >= maphublist[$1])
  154.         {@mask[$0] = 0}
  155.         {@mask[$0] = 1}
  156.         makemap ${[$0] + 1} $(ii$0)
  157.         ^assign -ii$0
  158.     }
  159. }
  160.  
  161. # called after the data is created and cleaned to keep for future use
  162. # no args
  163. alias map.save {
  164.     foreach maplist ii {
  165.         foreach maplist.$ii jj {
  166.             @ maplist2[$ii][$jj] = maplist[$ii][$jj] 
  167.         }
  168.     }
  169.     echo *** imap: Map data saved
  170. }
  171.  
  172.  
  173. # called after gomap has run makemap to restore data.
  174. # makemap destroys the entire list on purpose
  175. # no args.
  176. alias map.restore {
  177.     foreach maplist2 ii {
  178.         foreach maplist2.$ii jj {
  179.             @ maplist[$ii][$jj] = maplist2[$ii][$jj] 
  180.         }
  181.     }
  182.     echo *** imap: Map data restored
  183. }
  184.  
  185. # no stranger to the default scripts.. repeated here for completeness.
  186. alias lformat {
  187.     @ IRCII.word = [$1-]
  188.     if (@IRCII.word < [$0]) 
  189.         { @ function_return = [$([$0]IRCII.word)] } 
  190.         { @ function_return = IRCII.word } 
  191. }
  192.  
  193. # /purge <structure name>
  194. # removes all assignments under that name recursively.
  195. ^alias purge {
  196.   foreach $0 ii
  197.   {
  198.     purge $0.$ii
  199.   }
  200.   ^assign -ii
  201.   ^assign -$0
  202. }
  203.  
  204. # This special little recursive function scans the mask[]
  205. # array and generates an output string of the format
  206. # | |   |   | |  and so on.. depending on whether a mask[x] is
  207. # turned on or not
  208. alias map.outmask {
  209.     if ([$0] < [$1]) 
  210.     {
  211.         if (mask[$0])
  212.             {@ mask.mask = mask.mask ## [| ]}
  213.             {@ mask.mask = mask.mask ## [  ]}
  214.         @ function_return = map.outmask(${[$0] + 1} $1)
  215.     }
  216.     {
  217.         @ function_return = mask.mask
  218.         ^assign -mask.mask
  219.     }
  220. }
  221.