home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / rmsg < prev    next >
Text File  |  2020-01-01  |  3KB  |  54 lines

  1. # RMSG - Macro implementation of Kermit REMOTE MESSAGE
  2. #
  3. # The REMOTE MESSAGE command sends a short text message to a Kermit
  4. # server for display.  This command is found in MS-DOS Kermit but
  5. # not in C-Kermit or Kermit 95.  The following macros implement it.
  6. # C-Kermit 8.0 or later or Kermit 95 2.0 or later are required, and
  7. # a connection to a Kermit server must already exist.  TAKE this file
  8. # to define the needed macros, or add the definitions to your K95
  9. # or C-Kermit customization file.  Usage:
  10. #
  11. #   rmsg "This is a message"
  12. #
  13. # Sends the quoted text (quotes required if message includes spaces) in a
  14. # Kermit Message packet.  Message should not include control characters.
  15. # Waits for acknowledgement.  Tries up to five times.  Default timeout is
  16. # four seconds; adjust as necessary by redefining \%t.
  17. #
  18. # F. da Cruz, Columbia University, May 2004.
  19. #
  20. local \%t                               # Local variables
  21. .\%t = 4                                # INPUT timeout (change if necessary)
  22.  
  23. def CHK1 {                              # Construct Type 1 Block Check
  24.     local s                             # Local variable
  25.     .s := \fchecksum(\fcontents(\%1))   # Arithmetic checksum
  26.     (+ (& (+ (/ (& s 192) 64) s) 63) 32)  # Return Kermit block check
  27. }
  28. def MPKT {                              # Construct Message Packet
  29.     local t n p                         # Local vars
  30.     .t := \fcontents(\%1)               # Message text
  31.     .t := \freplace(\m(t),\v(p_ctl),\v(p_ctl)\v(p_ctl)) # Escape special chars
  32.     .t := \freplace(\m(t),\v(p_rpt),\v(p_ctl)\v(p_rpt))
  33.     if def \v(p_8bit) .t := \freplace(\m(t),\v(p_8bit),\v(p_ctl)\v(p_8bit))
  34.     .n := \flength(\m(t))               # Length of message
  35.     if ( > n 90 ) stop 1 "TOO LONG"     # Long packets not allowed
  36.     .p := "\fchar(n+37)\{32}GM\fchar(n+32)\m(t)" # Make Message packet
  37.     chk1 "\m(p)"                        # Get its checksum
  38.     return \{1}\m(p)\fchar(\v(return))  # Return the complete packet
  39. }
  40. def RMSG {                              # Send Message Packet to Kermit server
  41.     local spkt i                        # Local variables
  42.     mpkt "\fcontents(\%1)"              # Encapsulate message in packet
  43.     .spkt := \v(return)                 # Save the packet
  44.     clear input                         # Clear the INPUT buffer
  45.     for ( i 1 5 1 ) {                   # Try five times
  46.         output \m(spkt)\13              # Send the M-packet
  47.         if fail stop 1 "I/O Error"      # Check for I/O error
  48.         input \%t "\{1}#\{32}Y>"        # Wait up to \%t seconds for ACK
  49.         if success break                # Got it
  50.     }
  51.     if ( > i 5 ) end 1 "MESSAGE FAILED" # Return and print status
  52.     end 0 "MESSAGE OK"
  53. }
  54.