home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / last_m.zip / LAST_M.CMD
OS/2 REXX Batch file  |  1993-08-28  |  3KB  |  131 lines

  1. /* File:    LAST_MSG.CMD */
  2. /* Author:  Brad Roberts */
  3. /* Revised: 08/17/1993   */
  4.  
  5. /* GOAL: To display the last message(s) received on this workstation */
  6.  
  7. /* Setup */
  8. msg_file='C:\IBMLAN\LOGS\MESSAGES.LOG'    /* Message file for IBM LAN */
  9. number=1                /* Number of messages desired */
  10. one = 1                    /* Value of 1 */
  11. lines_in_file=1                /* Count all lines */
  12. print_flag=0                /* Set to 1 when ready to display msgs */
  13. pause_flag=0                            /* Set to 1 to pause between messages */
  14.  
  15. /* Check for help request */
  16. parse arg option
  17. if option == '?'
  18. then
  19.     do
  20.     /* Help */
  21.     say 'HELP: LAST_MSG [$NUMBER] [PAUSE] [?]'
  22.     say 'GOAL: To display the last $NUMBER messages received by this workstation'
  23.     say '      from the network, e.g. via NET SENDs.'
  24.     say ' '
  25.     say 'PARM: $NUMBER indicates the quantity of messages that you want to review.'
  26.     say '      By default, this is 1 for the last message received today. However,'
  27.     say '      it can be any number up to the total number of messages that have'
  28.     say '      been logged by this workstation.'
  29.     say '      PAUSE causes the display to pause after every message in the group.'
  30.     say '      Use this when you are running from an ICON or when you want to browse.'
  31.     say '      ? Redisplays this help screen.'
  32.     say ' '
  33.     say 'NOTE: This job will display the last message received by this workstation. It'
  34.     say '      simply accesses the MESSAGES.LOG file and displays the last entry. Each'
  35.     say '      message is separated by four asterisks (i.e ****) in the output. You'
  36.     say '      could print the last message by running the following command:'
  37.     say '          LAST_MSG >PRN:'
  38.     say ' '
  39.     exit(1)
  40.     end
  41.  
  42. /* Get value */
  43. parse arg quantity pause
  44.  
  45. /* Check quantity */
  46. if quantity > 0
  47. then
  48.     number = quantity
  49.  
  50. /* Check pause flag */
  51. if pause \== ''
  52. then
  53.     do
  54.     pause=translate(space(pause))
  55.     if pause == 'PAUSE'
  56.     then
  57.         pause_flag=1
  58.     end
  59.  
  60. /* Check file */
  61. extant1=stream(msg_file, 'c', 'query exists')
  62. if extant1 == ''
  63. then
  64.     do
  65.     say '*** File 'msg_file' does not exist! Check it. ***'
  66.     exit(1)
  67.     end
  68.  
  69. /* Open the file */
  70. extant2=stream(msg_file, 'c', 'OPEN')
  71. if extant2 \== 'READY:'
  72. then
  73.     do
  74.     say '*** File 'msg_file' will not open! Check it. ***'
  75.     exit(1)
  76.     end
  77.  
  78.  
  79. /* Read lines in file */
  80. if number <= one
  81. then
  82.     say 'Now scanning the network message file for the last message received...'
  83. else
  84.     say 'Now scanning the network message file for the last 'number' messages received...'
  85.  
  86.  
  87. /* Loop through the message file to determine the number of messages therein */
  88. /* This is redundant, but necessary to identify where to start displaying */
  89. count=1
  90. tally=0
  91. do while lines(msg_file)
  92.    lt=linein(msg_file)
  93.    if lt == '****'
  94.    then
  95.         tally = tally + one
  96. end
  97. lines_in_file=tally - one
  98. rc=stream(msg_file, 'c', 'CLOSE')
  99.  
  100. /* Now display last $NUMBER of lines in file */
  101. count=tally - number
  102.  
  103. /* Now reopen file */
  104. extant3=stream(msg_file, 'c', 'OPEN')
  105. tally=0
  106. do while lines(msg_file)
  107.     lt=linein(msg_file)
  108.     if print_flag
  109.     then
  110.     do
  111.         say lt
  112.         if lt == '****' & tally >= count & pause_flag == 1
  113.         then
  114.         '@PAUSE'
  115.     end
  116.  
  117.     if lt == '****'
  118.     then
  119.         do
  120.         tally = tally + one
  121.         if tally >= count
  122.         then
  123.             print_flag=1
  124.     end
  125.     
  126. end
  127.  
  128. rc=stream(msg_file, 'c', 'CLOSE')
  129.  
  130. /* All done */
  131.