home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / WHOIS3.ZIP / WHOIS.CMD
OS/2 REXX Batch file  |  1991-12-29  |  12KB  |  326 lines

  1. /* WHOIS.CMD - a REXX procedure to interpret those cryptic hexadecimal */
  2. /*             filenames in your Binkley-style outbound directory.     */
  3. /*                                                                     */
  4. /* Written by Emmitt Dove, Fernwood BBS, 1:141/209                     */
  5. /*                         Branford, CT  USA                           */
  6. /*                         (203) 483-0348 HST 14.4 and v.32            */
  7. /*                                                                     */
  8. /* Last modified 911228                                                */
  9. /* Additions and enhancements by Marcel Stikkleman 910401              */
  10. /* Additions and enhancements by Jaap Geluk 911227                     */
  11. /*                                                                     */
  12. /*                                                                     */
  13. /* Requires:  OS/2 EE 1.2, SE 1.3 or EE 1.3 (so far); may also work    */
  14. /*            with Personal REXX from Mansfield, though I haven't      */
  15. /*            tried that.                                              */
  16. /*                                                                     */
  17. /* Usage form one:  WHOIS filename.ext                                 */
  18. /*                                                                     */
  19. /*         where "filename.ext" is just about any file you may find    */
  20. /*         in your outbound directory.  WHOIS understands mail         */
  21. /*         packets, archived mail bundles, file-attaches, incomplete   */
  22. /*         transmission indicators (*.Z), requests, call progress      */
  23. /*         entries and no-sends.                                       */
  24. /*                                                                     */
  25. /*         No checking is done on filename validity - you're on        */
  26. /*         your own to be sure you enter a valid name.                 */
  27. /*                                                                     */
  28. /* Usage form two:  WHOIS net/node                                     */
  29. /*                                                                     */
  30. /*         where net/node is any valid address.  WHOIS will return the */
  31. /*         two flavors of outbound filenames for the net/node.         */
  32. /*         Note that WHOIS only understands 2-D addresses in this      */
  33. /*         mode.  EXAMPLE:  WHOIS 141/209                              */
  34. /*                                                                     */
  35. /* Usage form three:  WHOIS [d:][\path\]outbound[\filespec]            */
  36. /*                                                                     */
  37. /*       WHERE  "d:" is the drive on which the outbound directory      */
  38. /*                    resides,                                         */
  39. /*              "\path\" is the path to the outbound directory,        */
  40. /*              "outbound" is the outbound directory itself, and       */
  41. /*              "\filespec" is a valid file specification including    */
  42. /*                    wildcards.                                       */
  43. /*                                                                     */
  44. /*       EXAMPLES:    WHOIS d:\max\outbound\*.*  will list all files   */
  45. /*                          in the specified directory                 */
  46. /*                    WHOIS outbound\*.clo  will list all crash        */
  47. /*                          attach lists in a directory named outbound */
  48. /*                          which exists beneath the current directory */
  49. /*                                                                     */
  50. /*         WHOIS gets your net/node address from one of two places.    */
  51. /*         First, you can modify lines 66 and 67 to represent your     */
  52. /*         own net and node number.  Second, you can set an OS/2       */
  53. /*         environment variable Fido4DAddress to your full 4-D         */
  54. /*         address.  Example:  SET Fido4DAddress=1:141/209.0           */
  55. /*                                                                     */
  56. /*         If the environment variable is set, it is used and lines    */
  57. /*         66 and 67 are overridden.                                   */
  58. /*                                                                     */
  59. /*         This file may be freely used, distributed and modified.     */
  60. /*         Be nice and leave my credit in if you modify it and         */
  61. /*         distribute the modifications.  It would also be nice if     */
  62. /*         you were to share your enhancements with the author.        */
  63.  
  64. trace off
  65.  
  66. mynet  = 141
  67. mynode = 209
  68.  
  69. NetNode = Value('Fido4DAddress',,'OS2ENVIRONMENT')
  70. if NetNode \= '' then do
  71.   if pos('.', NetNode) > 0 then NetNode =   left(NetNode, pos('.', NetNode) - 1)
  72.   if pos(':', NetNode) > 0 then NetNode = substr(NetNode, pos(':', NetNode) + 1)
  73.   mynet  =   left(NetNode, pos('/', NetNode) - 1)
  74.   mynode = substr(NetNode, pos('/', NetNode) + 1)
  75. end
  76.  
  77. /* Get the parameter and parse it */
  78.  
  79. arg filename
  80.  
  81. if filename = '?' | filename = '' then signal HELP
  82. if pos('/', filename) > 0         then signal TOHEX
  83.  
  84. fullname = stream(filename, 'c', 'query exists')
  85. filename = filespec('name', fullname)
  86. if filename = '' then arg filename
  87. temp = directory() 
  88. if directory(fullname) = fullname then fullname = fullname || '\*.*'
  89. call directory temp
  90. drop temp
  91.  
  92. parse source . . WhoIs
  93. if pos('?',filename) > 0 | pos('*',filename) > 0 then do
  94.   if fullname = '' then
  95.     arg fullname
  96.   '@dir ' fullname ' > null'
  97.   if rc <> 0 then do
  98.     say filename "not found ..."
  99.     return
  100.   end
  101.   '@for %%i in (' fullname ') do @call' WhoIs '%%i'
  102.   return
  103. end
  104.  
  105. netdiff = substr(filename,1,4)
  106. nodediff = substr(filename,5,4)
  107. ext = substr(filename,10,3)
  108. extflavor = substr(filename,10,1)
  109. exttype = substr(filename,11,2)
  110.  
  111. /* Decide which routine to execute */
  112.  
  113. if extflavor = 'Z' then signal BADFLAG
  114. if extflavor = '$' then signal DIALED
  115. if exttype = 'UT' then signal PACKET
  116. if exttype = 'LO' then signal ATTACH
  117. if exttype = 'EQ' then signal REQUEST
  118. if ext = 'NOT' then signal NOSEND
  119.  
  120. /* If we didn't go somewhere else, we have a compressed mail bundle.      */
  121. /* Since the hex values we have are offsets from our own net/node number, */
  122. /* we have to convert to decimal, undo the offset and make certain it is  */
  123. /* not a negative result.                                                 */
  124.  
  125. /* First, the network portion. */
  126.  
  127. if netdiff = 0 then
  128.     hisnet = mynet
  129.   else do
  130.  
  131.     dnetdiff = x2d(netdiff)
  132.     newdiff = mynet-dnetdiff
  133.     if newdiff < 0 then
  134.       hisnet = 65536+newdiff
  135.     else
  136.       hisnet = newdiff
  137.   end
  138.  
  139. /* Now, the node portion. */
  140.  
  141. if nodediff = 0 then
  142.      hisnode = mynode
  143.    else do
  144.      dnodediff = x2d(nodediff)
  145.      newdiff = mynode-dnodediff
  146.      if newdiff < 0 then
  147.        hisnode = 65536+newdiff
  148.      else
  149.        hisnode = newdiff
  150.    end
  151.  
  152. /* Report the result and leave. */
  153.  
  154. say
  155. say filename "is a compressed mail file to "hisnet"/"hisnode"."
  156. signal done
  157.  
  158. PACKET:
  159.  
  160. /* We are here since the last two characters of the extension are "UT".  */
  161. /* This is a simpler case since all we have to do is a hex to decimal    */
  162. /* conversion.  But, we also want to figure out the flavor (crash, hold, */
  163. /* etc.) and report it.                                                  */
  164.  
  165. net = substr(filename,1,4)
  166. node = substr(filename,5,4)
  167. hisnet = x2d(net)
  168. hisnode = x2d(node)
  169. select
  170.   when extflavor = 'C' then flavor = crash
  171.   when extflavor = 'D' then flavor = direct
  172.   when extflavor = 'H' then flavor = hold
  173.   when extflavor = 'O' then flavor = normal
  174. otherwise flavor = '???'
  175. end
  176.  
  177. say
  178. say filename "is a "flavor" mail packet to "hisnet"/"hisnode"."
  179. signal done
  180.  
  181. ATTACH:
  182.  
  183. /* We are here since the last two characters of the extension are "LO",  */
  184. /* indicating we have a file-attach.  Otherwise, it is almost identical  */
  185. /* to the packet case.  There are minor differences in the flavor cases. */
  186.  
  187. net = substr(filename,1,4)
  188. node = substr(filename,5,4)
  189. hisnet = x2d(net)
  190. hisnode = x2d(node)
  191. select
  192.   when extflavor = 'C' then flavor = crash
  193.   when extflavor = 'D' then flavor = direct
  194.   when extflavor = 'F' then flavor = normal
  195.   when extflavor = 'H' then flavor = hold
  196. otherwise flavor = '???'
  197. end
  198.  
  199. say
  200. say filename "is a "flavor" file-attach list to "hisnet"/"hisnode"."
  201. call stream fullname, 'c', 'open read'
  202. do while lines(fullname)
  203.   say linein(fullname)
  204. end
  205. call stream fullname, 'c', 'close'
  206. signal DONE
  207.  
  208. BADFLAG:
  209.  
  210. /* This indicates a .Z file.  Very easy to handle.   */
  211.  
  212. net = substr(filename,1,4)
  213. node = substr(filename,5,4)
  214. hisnet = x2d(net)
  215. hisnode = x2d(node)
  216.  
  217. say
  218. say filename "indicates an incomplete transmission to "hisnet"/"hisnode"."
  219. signal DONE
  220.  
  221. DIALED:
  222.  
  223. /* We have a .$$? extension.  Is it undialable yet? */
  224.  
  225. net = substr(filename,1,4)
  226. node = substr(filename,5,4)
  227. hisnet = x2d(net)
  228. hisnode = x2d(node)
  229.  
  230. if substr(filename,12,1) = 0 then do
  231.    say
  232.    say filename "is a call progress entry for "hisnet"/"hisnode"."
  233. end
  234. else
  235.  
  236. select
  237.   when substr(filename,12,1) = 1 then do
  238.      say
  239.      say filename "is a call progress entry for "hisnet"/"hisnode "indicating one bad connect."
  240.   end
  241.  
  242.   when substr(filename,12,1) = 2 then do
  243.      say
  244.      say filename "is a call progress entry for "hisnet"/"hisnode "indicating two bad connects."
  245.   end
  246.  
  247.   when substr(filename,12,1) = 3 then do
  248.      say
  249.      say filename "is a call progress entry for "hisnet"/"hisnode "indicating three bad connects."
  250.      say
  251.      say hisnet"/"hisnode "is now undialable."
  252.   end
  253.  
  254. otherwise
  255. say
  256. say "Beats the hell outa me!"
  257. end
  258. signal DONE
  259.  
  260. REQUEST:
  261.  
  262. /* .REQ files are lists of file requests.  */
  263.  
  264. net = substr(filename,1,4)
  265. node = substr(filename,5,4)
  266. hisnet = x2d(net)
  267. hisnode = x2d(node)
  268.  
  269. say
  270. say filename "is a list of requests for "hisnet"/"hisnode"."
  271. call stream fullname, 'c', 'open read'
  272. do while lines(fullname)
  273.   say linein(fullname)
  274. end
  275. call stream fullname, 'c', 'close'
  276. signal DONE
  277.  
  278. NOSEND:
  279.  
  280. /* This type has been "left" by oMMM - that is, flagged to not be sent or  */
  281. /* routed under any conditions.                                            */
  282.  
  283. net = substr(filename,1,4)
  284. node = substr(filename,5,4)
  285. hisnet = x2d(net)
  286. hisnode = x2d(node)
  287.  
  288. say
  289. say filename "indicates that the mail for "hisnet"/"hisnode" should not be sent"
  290. say "under any circumstances."
  291. signal DONE
  292.  
  293. TOHEX:
  294.  
  295. /* This routine calculates the filenames from the node address */
  296.  
  297. address = right(filename,length(filename)-pos(':',filename))
  298. net = substr(address,1,pos('/',address)-1)
  299. node = substr(address,pos('/',address)+1,length(address)-pos('/',address))
  300.  
  301. say
  302. say ".?LO/.OUT of" filename "=" d2x(net,4) || d2x(node,4)
  303. say ".MO?/.TU? of" filename "=" d2x(mynet - net,4) || d2x(mynode - node,4)
  304. signal DONE
  305.  
  306. HELP:
  307. say "WHOIS.CMD - a tool for sysops of Binkley and compatible systems"
  308. say "            which will tell you who the file is for and what kind"
  309. say "            of file it is."
  310. say
  311. say "Usage:  WHOIS <filename.ext | net/node>"
  312. say
  313. say "        where 'filename.ext' is a qualified filename you will find"
  314. say "        in your outbound directory. Wildcards and pathnames supported."
  315. say "         or"
  316. say "        where 'net/node' is the address for which you are seeking"
  317. say "        the outbound files."
  318. say
  319.  
  320.  
  321. DONE:
  322.  
  323. /* That's all, folks!  Not bad for my first REXX program, eh?   */
  324.  
  325. exit
  326.