home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / fish / fisher / fisher.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-27  |  14KB  |  506 lines

  1. /*
  2. ** $VER: Fisher.rexx 1.1 (27.3.94) Keith R. Burby
  3. ** -------------------------------------------------------------------------
  4. ** ARexx front end for KingFisher database.
  5. ** Copyright © 1994 Keith R. Burby
  6. */
  7.  
  8. /*
  9.   History:
  10.   -------------------------------------------------------------------------
  11.   v0.0 (12.1.94)
  12.  
  13.   First Edition.
  14.   -------------------------------------------------------------------------
  15.   v0.1 (13.1.94)
  16.  
  17.   Moved some code around, nothing anyone would notice.
  18.  
  19.   Rewrote the menu displays to accomodate a 24 line screen instead of 48
  20.   (silly me).
  21.  
  22.   Removed search command for later work.
  23.  
  24.   Added in use flag.
  25.  
  26.   Entering a negative number will now move to the specified entry.
  27.  
  28.   Added break/error handling.
  29.   -------------------------------------------------------------------------
  30.   v0.2 (14.1.94)
  31.  
  32.   Added an improved and more flexible search command.
  33.  
  34.   Added online help.
  35.  
  36.   Added ANSI color.
  37.   -------------------------------------------------------------------------
  38.   v0.3 (15.1.94)
  39.  
  40.   Fisher will now abort if it is set to quit KingFisher upon exit and
  41.   KingFisher is currently running.
  42.   -------------------------------------------------------------------------
  43.   v1.0 (4.3.94)
  44.  
  45.   First public release.
  46.  
  47.   Fisher is now able to send requests for selections and entire disks to
  48.   the sysop, if the sysop's name is entered in the variable.
  49.  
  50.   Removed online help and created doc file for users.
  51.   -------------------------------------------------------------------------
  52.   v1.1 (27.3.94)
  53.  
  54.   Fixed problem with ANSI colors and command line parameters
  55.  
  56.   If CLI mode was turned off, as specified in the docs, this script was
  57.   unable to get input from local terminals.
  58. */
  59.  
  60. /* ====================================================================== */
  61.  
  62. /*
  63. ** Constants
  64. */
  65. FALSE = 0
  66. TRUE = ~FALSE
  67. clr = "0C"x
  68. esc = "1B"x
  69.  
  70. /*
  71. DLG command to allows ANSI colors
  72. %a4
  73. */
  74.  
  75. /* ====================================================================== */
  76.  
  77. /*
  78. ** Settings that may need to be changed by the sysop.
  79. **
  80. ** Kingfisher.Path  = Complete path to find the KingFisher program.
  81. ** Kignfisher.Prefs = Complete path to find the prefs file for KingFisher.
  82. ** KingFisher.Port  = Name of KingFisher port to conduct business on.
  83. ** KingFisher.Quit  = Whether or not KingFisher should quit on termination of
  84. **                    this script.
  85. ** Sysop            = Sysop's name.  Note, all spaces should be changed to
  86. **                    underscores, ala My_Name.
  87. ** RightMargin      = Right margin for word wrapping.
  88. */
  89.  
  90. KingFisher.Path  = "DH1:Database/KingFisher"
  91. KingFisher.Prefs = "DOORS:Fisher/KingFisher.cfg"
  92. KingFisher.Port  = "KINGFISHER1"
  93. KingFisher.Quit  = TRUE
  94.  
  95. Sysop = "Keith_Burby"
  96.  
  97. RightMargin = 77
  98.  
  99. /* ====================================================================== */
  100.  
  101. options failat 20
  102. options results
  103. signal on Break_C
  104. signal on Break_D
  105. signal on Break_E
  106. signal on Break_F
  107. signal on Halt
  108. signal on Syntax
  109.  
  110. if ~Show("P", KingFisher.Port) then
  111.   do
  112.     address "COMMAND" "Run >NIL:" KingFisher.Path "SETTINGS=" || KingFisher.Prefs "NOABOUT STAYBEHIND"
  113.     address "COMMAND" "WaitForPort" KingFisher.Port
  114.     if ~Show("P", KingFisher.Port) then
  115.       do
  116.         say clr
  117.         say "I'm sorry, but the KingFisher program is currently not available for use."
  118.         say "Please inform the SysOp about this problem."
  119.         say
  120.         call GetInput("-- Press any key to return to the BBS --", "I")
  121.         signal Halt
  122.       end
  123.     call SetClip("KingFisher") /* Nobody can be using it if it's not running. */
  124.   end
  125. else
  126.   if KingFisher.Quit = TRUE then
  127.     do
  128.       say clr
  129.       say "I'm sorry, but KingFisher is currently being used by another person."
  130.       say "Please try again at a later time."
  131.       say
  132.       call GetInput("-- Press any key to return to the BBS --", "I")
  133.       signal Halt
  134.     end
  135.  
  136. if GetClip("KingFisher") ~= "" then
  137.   do
  138.     say clr
  139.     say "I'm sorry, but KingFisher is currently being used by another person."
  140.     say "Please try again at a later time."
  141.     say
  142.     call GetInput("-- Press any key to return to the BBS --", "I")
  143.     signal Halt
  144.   end
  145.  
  146. call SetClip("KingFisher", "IN USE")
  147. interpret "address" "'" || KingFisher.Port || "'"
  148.  
  149. parse Arg ANSI UserName
  150.  
  151. if (ANSI ~= "") & (ANSI ~= "TRUE") & (ANSI ~= 0) then
  152.   do
  153.     BR = esc || "[33m" /* brown    */
  154.     DC = esc || "[36m" /* Dark Cyan  */
  155.     DG = esc || "[32m" /* Dark Green */
  156.     LG = esc || "[37m" /* Light Grey */
  157.   end
  158. else
  159.   do
  160.     BR = ""
  161.     DC = ""
  162.     DG = ""
  163.     LG = ""
  164.   end
  165.  
  166. /* Misc information */
  167. VERSION
  168. VerStr = Result
  169. TELL FISHCOUNT
  170. LastFish = Result
  171. TELL DISKCOUNT
  172. LastDisk = Result
  173.  
  174. /* Initialize the default search parameters */
  175. RESET
  176. Search.Mode = TRUE    /* TRUE = Title, FALSE = Description     */
  177. Search.Direction = FALSE /* TRUE = Forward, FALSE = Backward      */
  178. Search.Range = FALSE   /* TRUE = Active, FALSE = Inactive      */
  179. Search.Case = FALSE    /* TRUE = Case Sensitive, FALSE = Insenstive */
  180. Search.Low = 0
  181. Search.High = 0
  182. Search.For = ""
  183.  
  184. Cmd = ""
  185. ShowMenu = TRUE
  186.  
  187. do until Cmd = "Q"
  188.  
  189.   TELL FISH
  190.   CurrFish = Result
  191.   TELL DISK
  192.   CurrDisk = Result
  193.   SHOW TITLE
  194.   fTitle = Result
  195.   SHOW DESCRIPTION
  196.   fDescription = FormatString(Result, RightMargin);
  197.   call ShowTitle
  198.   say DC || "Current entry: " || LG || CurrFish "(of" LastFish || ")"
  199.   say DC || "Current disk:  " || LG || CurrDisk "(of" LastDisk || ")"
  200.   say DC || "Entry name:    " || LG || fTitle
  201.   say DC || Copies("-", RightMargin)
  202.  
  203.   if ShowMenu then
  204.     do
  205.       /* Display the main menu. */
  206.       say DC || "Options:"
  207.       say
  208.       say LG || " F" || DC || Left(") First Entry", RightMargin % 2 - 2),
  209.           LG || " L" || DC || ") Last Entry"
  210.       say LG || " P" || DC || Left(") Previous Entry", RightMargin % 2 - 2),
  211.           LG || " N" || DC || ") Next Entry"
  212.       say LG || " -" || DC || Left(") Previous Disk", RightMargin % 2 - 2),
  213.           LG || " +" || DC || ") Next Disk"
  214.       say LG || " <" || DC || Left(") Previous Version", RightMargin % 2 - 2),
  215.           LG || " >" || DC || ") Next Version"
  216.       say LG || " S" || DC || Left(") Begin Search", RightMargin % 2 - 2),
  217.           LG || " C" || DC || ") Continue Search"
  218.       if Sysop ~= "" then
  219.         say LG || " R" || DC || ") Make Request"
  220.       say LG || " 1-" || LastDisk || DC || ") specific disk."
  221.       say LG || " Q" || DC || ") Quit Fisher."
  222.       say
  223.       say " <" || LG || "Enter" || DC || "> toggles between the menu and entry description."
  224.     end
  225.   else
  226.     say LG || fDescription /* The description of the current entry */
  227.   say
  228.  
  229.   Cmd = GetInput(DC || "Enter your command: " || LG, "U")
  230.   if ~DataType(Cmd, "N") then
  231.     Cmd = Left(Cmd, 1)
  232.   select
  233.     when Cmd = "" then
  234.       ShowMenu = ~ShowMenu
  235.     when Cmd = "F" then
  236.       MOVETO FIRST FISH
  237.     when Cmd = "L" then
  238.       MOVETO LAST FISH
  239.     when Cmd = "P" then
  240.       MOVETO PREV FISH
  241.     when Cmd = "N" then
  242.       MOVETO NEXT FISH
  243.     when Cmd = "-" then
  244.       MOVETO PREV DISK
  245.     when Cmd = "+" then
  246.       MOVETO NEXT DISK
  247.     when Cmd = "<" then
  248.       MOVETO PREV VERSION
  249.     when Cmd = ">" then
  250.       MOVETO NEXT VERSION
  251.     when Cmd = "S" then
  252.       call Search()
  253.     when Cmd = "C" then
  254.       do
  255.         SEARCH AGAIN
  256.         if RC ~= 0 then
  257.           call GetInput("No matches found.  Press any key.", "I")
  258.       end
  259.     when Cmd = "R" then
  260.       if Sysop ~= "" then
  261.         call MakeRequest(CurrDisk, fTitle)
  262.     otherwise
  263.       if DataType(Cmd, "N") & ((Cmd >= 1) | (Cmd <= LastDisk)) then
  264.         MOVETO DISK Cmd
  265.       if DataType(Cmd, "N") & ((Cmd <= -1) | (Cmd >= -LastDisk)) then
  266.         MOVETO FISH (-1 * Cmd)
  267.   end
  268.  
  269. end
  270.  
  271. if KingFisher.Quit then
  272.   QUIT
  273.  
  274. Halt:
  275. call SetClip("KingFisher", "")
  276. exit
  277.  
  278. /* ====================================================================== */
  279.  
  280. /*
  281. ** Break and errors handling routine.
  282. */
  283. Syntax:
  284. say FormatString("An error occured on line" SIGL || ".", RightMargin)
  285. say FormatString("Please inform the SysOp of this.", RightMargin)
  286. call GetInput("-- Press any key to return to the BBS --", "I")
  287.  
  288. Break_C:
  289. Break_D:
  290. Break_E:
  291. Break_F:
  292. call SetClip("KingFisher", "")
  293. exit
  294.  
  295. /* ====================================================================== */
  296.  
  297. /*
  298. ** The Search Menu.
  299. */
  300. Search:
  301.  
  302. do until (sCmd = "Q") | (sCmd = "B")
  303.  
  304.   if Search.Mode then
  305.     sMode = "TITLE"
  306.   else
  307.     sMode = "DESCRIPTION"
  308.   if Search.Direction then
  309.     sDirection = "FORWARD"
  310.   else
  311.     sDirection = "BACKWARD"
  312.   if Search.Range then
  313.     sRange = Search.Low || "-" || Search.High
  314.   else
  315.     sRange = "DISABLED"
  316.   if Search.Case then
  317.     sCase = "SENSITIVE"
  318.   else
  319.     sCase = "IGNORED"
  320.  
  321.   call ShowTitle
  322.   say DC || "Mode:      " || LG || Left(sMode, RightMargin % 2 - 11),
  323.       DC || "Current entry: " || LG || CurrFish "(of" LastFish || ")"
  324.   say DC || "Direction: " || LG || Left(sDirection, RightMargin % 2 - 11),
  325.       DC || "Current disk:  " || LG || CurrDisk "(of" LastDisk || ")"
  326.   say DC || "Range:     " || LG || sRange
  327.   say DC || "Case:      " || LG || sCase
  328.   say DC || "String:    " || BR || '"' || LG || Search.For || BR || '"'
  329.   say DC || Copies("-", RightMargin)
  330.   say DC || "Options:"
  331.   say LG || " M" || DC || ") Change Mode      " || LG || "[TITLE | DESCRIPTION]"
  332.   say LG || " D" || DC || ") Change Direction " || LG || "[FORWARD | BACKWARD]"
  333.   say LG || " R" || DC || ") Change Range     " || LG || "[DISABLED | max 1-" || LastDisk || "]"
  334.   say LG || " C" || DC || ") Change Case      " || LG || "[IGNORED | SENSITIVE]"
  335.   say LG || " S" || DC || ") Change String"
  336.   say LG || " B" || DC || ") Begin search"
  337.   say LG || " Q" || DC || ") Quit search menu"
  338.   say
  339.  
  340.   sCmd = Left(GetInput("Enter your search command: " || LG, "U"), 1)
  341.   select
  342.     when sCmd = "M" then
  343.       Search.Mode = ~Search.Mode
  344.     when sCmd = "D" then
  345.       Search.Direction = ~Search.Direction
  346.     when sCmd = "R" then
  347.       do
  348.         Search.Range = ~Search.Range
  349.         if Search.Range then
  350.           do
  351.             Search.Low = GetInput("Enter the low disk: ", "N")
  352.             if (Search.Low < 1) | (Search.Low > LastDisk) then
  353.               Search.Low = 0
  354.             Search.High = GetInput("Enter the high disk: ", "N")
  355.             if (Search.High < Search.Low) | (Search.High > LastDisk) then
  356.               Search.High = 0
  357.             if (Search.Low = 0) | (Search.High = 0) then
  358.               Search.Range = FALSE
  359.           end
  360.       end
  361.     when sCmd = "C" then
  362.       Search.Case = ~Search.Case
  363.     when sCmd = "S" then
  364.       Search.For = GetInput("Enter the search string: ", "M")
  365.     otherwise
  366.       nop
  367.   end
  368.  
  369. end
  370.  
  371. if (sCmd = "B") & (Search.For ~= "") then
  372.   do
  373.     SEARCH MODE sMode
  374.     SEARCH DIRECTION sDirection
  375.     SEARCH CASE sCase
  376.     SEARCH RANGE sRange
  377.     if Search.Range then
  378.       SEARCH RANGE ACTIVE
  379.     SEARCH FOR Search.For
  380.     if RC ~= 0 then
  381.       call GetInput("No matches were found.  Press any key", "I")
  382.   end
  383.  
  384. drop sMode
  385. drop sDirection
  386. drop sRange
  387. drop sCase
  388. drop sCmd
  389.  
  390. return
  391.  
  392. /* ====================================================================== */
  393.  
  394. /*
  395. ** Allow the user to make a request for a specific title or disk.
  396. */
  397.  
  398. MakeRequest:
  399.  
  400. parse arg DiskNum, Selection
  401.  
  402. ReqSel = ""
  403. do until ReqSel ~= ""
  404.   call ShowTitle
  405.   say
  406.   say DC || "Current entry: " || LG || CurrFish "(of" LastFish || ")"
  407.   say DC || "Current disk:  " || LG || CurrDisk "(of" LastDisk || ")"
  408.   say DC || "Entry name:    " || LG || fTitle
  409.   say DC || Copies("-", RightMargin)
  410.   say DG || FormatString("Did you want to request the current selection, or the entire disk?", RightMargin)
  411.   say LG || " S" || DG || ") Current selection"
  412.   say LG || " D" || DG || ") Entire disk"
  413.   say LG || " Q" || DG || ") Quit (Don't send request)"
  414.   say
  415.  
  416.   ReqSel = GetInput(DC || "Which would you like? " || LG, "U")
  417.  
  418.   select
  419.     when ReqSel = "S" then
  420.       call SendRequest("S")
  421.     when ReqSel = "D" then
  422.       call SendRequest("D")
  423.     when ReqSel = "Q" then
  424.       nop
  425.   end
  426. end
  427.  
  428. drop ReqSel
  429. return
  430.  
  431. /* ====================================================================== */
  432.  
  433. /*
  434. ** Send the request to the sysop.
  435. */
  436. SendRequest:
  437.  
  438. parse arg ReqType
  439.  
  440. call Open("Request", "T:FisherReq", "Write")
  441. call WriteLn("Request", "USER:   " UserName)
  442. if ReqType = "S" then
  443.   do
  444.     call WriteLn("Request", "TITLE:  " fTitle)
  445.     call WriteLn("Request", "ON DISK:" CurrDisk)
  446.   end
  447. else
  448.   call WriteLn("Request", "DISK:   " CurrDisk)
  449. call Close("Request")
  450.  
  451. address "COMMAND" "DLG:SendMsg -f Fisher.rexx -s Fish Request -b T:FisherReq -q -r" Sysop
  452. address "COMMAND" "Delete T:FisherReq quiet"
  453.  
  454. return
  455.  
  456. /* ====================================================================== */
  457.  
  458. /*
  459. ** Display Fisher's title bar.
  460. */
  461. ShowTitle:
  462. say clr || BR || Copies("*", RightMargin) || LG
  463. say Trim(Center("Fisher 1.1 Copyright 1994 Keith R. Burby", RightMargin))
  464. say Trim(Center(VerStr, RightMargin))
  465. say BR || Copies("*", RightMargin) || DG
  466. return
  467.  
  468. /* ====================================================================== */
  469.  
  470. /*
  471. ** Formats the string into a multi-line string where each line ends on or
  472. ** before the specified right margin.
  473. */
  474. FormatString: procedure
  475. nl = "0A"x
  476.  
  477. parse arg String, Margin
  478. fString = ""
  479. do while Length(String) > Margin
  480.   bPos = Max(LastPos(" ", String, Margin), LastPos("/", String, Margin), LastPos("-", String, Margin))
  481.   if bPos = 0 then
  482.     bPos = Margin
  483.   fString = fString || Strip(Left(String, bPos), "T") || nl
  484.   String = Strip(SubStr(String, bPos + 1), "L")
  485. end /* until */
  486. fString = fString || String
  487. return fString
  488.  
  489. /* ====================================================================== */
  490.  
  491. /*
  492. ** Get input from the user.
  493. */
  494. GetInput: procedure
  495.  
  496. parse arg PromptStr, Mode
  497. Mode = Upper(Left(Mode, 1))
  498. options prompt PromptStr
  499. if Upper(Left(Mode, 1)) = "U" then
  500.   parse upper pull Response
  501. else
  502.   parse pull Response
  503. if (Mode = "N") & ~DataType(Response, "N") then
  504.   Response = 0
  505. return Response
  506.