home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / textfilt.zip / tail.cmd < prev    next >
OS/2 REXX Batch file  |  1995-04-05  |  4KB  |  96 lines

  1. /*---------------------------------------------------------------------------*/
  2.   '@echo off'
  3.   programNameStr=   "Print the last 'x' lines of a file"
  4.   copyrightStr=     "Copyright (c) Paul Gallagher 1995"
  5.  
  6. /*                                ***keywords*** "Version: %v  Date: %d %t"  */
  7.   versionStr=       "Version: 1:3  Date: 5-Apr-95 12:00:36"
  8. /*
  9. ;                                 ***keywords*** "%l"
  10. ; LOCK STATUS       "***_NOBODY_***"
  11. ;
  12. ;                                 ***keywords*** "%n"
  13. ; Filename          "TAIL.CMD"
  14. ; Platform          OS/2 (REXX)
  15. ;
  16. ; Authors           Paul Gallagher (paulpg@ibm.net)
  17. ;
  18. ; Description       Prints the last 'x' lines of a file that is piped to
  19. ;                   the standard input stream
  20. ;
  21. ; Revision History
  22. ;                                 ***revision-history***
  23. ; 1 TAIL.CMD 26-Feb-95,18:32:44,`PAULG/EDMSUB1' Initial check-in
  24. ; 1:1 TAIL.CMD 6-Mar-95,21:34:20,`PAULG/EDMSUB1' Expanded documentation
  25. ; 1:2 TAIL.CMD 9-Mar-95,22:22:46,`PAULG/EDMSUB1' Final for EDM submission
  26. ; 1:3 TAIL.CMD 5-Apr-95,12:00:36,`PAULG/EDMSUB1' Add my new email address
  27. ;                                 ***revision-history***
  28. ;----------------------------------------------------------------------------*/
  29.  
  30. /*-----------------------------------------------------------------------------
  31. ; Do initial parse of command line and call help message if required
  32. ;----------------------------------------------------------------------------*/
  33.                                   /* get the command line arguments */
  34. Parse Arg params
  35.                                   /* call help routine if required */
  36. If (POS(TRANSLATE(params),"-?"'00'x"/?"'00'x"-HELP"'00'x"/HELP") > 0) | (DATATYPE(params) <> "NUM") Then Do
  37.   Call HelpInfo
  38.   Signal ExitProc
  39. End
  40.  
  41. /*-----------------------------------------------------------------------------
  42. ; Start tail procedure
  43. ;----------------------------------------------------------------------------*/
  44.  
  45.                                   /* lc is our line counter */
  46.   lc=0
  47.                                   /* should print at least 1 line */
  48.   If (params<1) Then
  49.     params=1
  50.  
  51.                                   /* loop through the input file */
  52.   Do While LINES() > 0
  53.     line = LINEIN()
  54.     lc=lc+1
  55.                                   /* enqueue the new line */
  56.     Queue line
  57.                                   /* if we already have our quota, also discard
  58.                                      a line from the front of the queue */
  59.     If (lc>params) Then
  60.       Pull line
  61.   End
  62.  
  63.                                   /* clear/print the remaining entries in
  64.                                      the queue */
  65.   Do While QUEUED() > 0
  66.     Parse Pull line
  67.     Say line
  68.   End
  69.  
  70.   Drop lc line
  71.  
  72. /*-----------------------------------------------------------------------------
  73. ; General exit procedure
  74. ;----------------------------------------------------------------------------*/
  75. ExitProc:
  76.   Drop params programNameStr copyrightStr versionStr
  77. Exit
  78. /*-----------------------------------------------------------------------------
  79. ; end of main routine
  80. ;----------------------------------------------------------------------------*/
  81.  
  82. /*-----------------------------------------------------------------------------
  83. ; routine to display help message
  84. ;----------------------------------------------------------------------------*/
  85. HelpInfo: Procedure Expose programNameStr copyrightStr versionStr
  86.   Say
  87.   Say "*======================================================================*"
  88.   Say "   "programNameStr
  89.   Say "   "versionStr
  90.   Say "   "copyrightStr
  91.   Say
  92.   Say " TAIL x"
  93.   say "    prints the last 'x' lines of a file"
  94.   Say "*======================================================================*"
  95. Return
  96.