! MM.TPU - TPU procedures to provide an EVE interface to SRI's MM-32. ! ! Place this file in MULTINET: as MM.TPU. Use it by defining symbol ! MMEVE as follows: ! ! MMEVE :== EDIT/TPU/COMMAND=MULTINET:MM/JOURNAL=SYS$LOGIN:MM ! ! and by placing this command in the MM.INIT file: ! ! EDITOR-INVOCATION-COMMAND mmeve %s ! ! Written by Betsy Ramsey, American Mathematical Society, March 1988 ! Routines to enable and disable EVE messages by unmapping and remapping ! the message window. Procedure Messages_Off Unmap (Message_Window); Position (Main_Window); EndProcedure; Procedure Messages_On (Win); Map (Message_Window, Message_Buffer); Position (Win); EndProcedure; Procedure MM_Send_Edit Set (Status_Line, Main_Window, Reverse, " TPU/EVE: MM Send Edit Type Ctrl-Z to return to S> "); Position (End_Of (Main_Buffer)); Messages_Off; Write_File (Main_Buffer); !in case the user QUITs Messages_On (Main_Window); Message ("Enter the text of your message."); EndProcedure; Procedure MM_Forward_Edit Set (Status_Line, Main_Window, Reverse, " TPU/EVE: MM Forward Edit Type Ctrl-Z to return to S> "); Position (Beginning_Of (Main_Buffer)); Messages_Off; Write_File (Main_Buffer); !in case the user QUITs Messages_On (Main_Window); Message ("Forwarded message(s) will be attached to this message when you exit."); EndProcedure; Procedure Switch_Windows If Current_Buffer = Main_Buffer Then Position (Reply_Window); Else Position (Msg_Window); Set (Status_Line, Msg_Window, Reverse, " TPU/EVE: MM Reply Edit Press keypad ENTER for other window"); EndIf; EndProcedure; Procedure MM_Reply_Edit Local Mark1, Mark2, SRange, SString; ! On_Error ! Message("Invalid MM TPU message format"); ! Return; ! EndOn_Error; Set (Status_Line, Msg_Window, Reverse, " TPU/EVE: MM Reply Edit Press keypad ENTER for other window "); Set (Status_Line, Reply_Window, Reverse, " MM Message You Are Replying To Press keypad ENTER for other window"); Position (Beginning_Of (Main_Buffer)); Mark1 := Mark (None); SString := Ascii (3) + "***END-OF-MESSAGE***" + Ascii (3); SRange := Search (SString, Forward, Exact); Position (SRange); Move_Horizontal (-Current_Offset); Erase_Line; Move_Vertical (-1); Move_Horizontal (Length (Current_Line)); Mark2 := Mark(None); Reply_Message_Range := Create_Range (Mark1, Mark2, None); Unmap (Main_Window); Position (Reply_Buffer); Move_Text (Reply_Message_Range); Position (End_Of (Reply_Buffer)); Map (Reply_Window, Reply_Buffer); Position (End_Of (Main_Buffer)); Map (Msg_Window, Main_Buffer); Messages_Off; Write_File (Main_Buffer); !in case the user QUITs Messages_On (Msg_Window); Define_Key ("Switch_Windows", ENTER); Message ("Enter your reply in the bottom window to the message in the top window."); EndProcedure; Procedure MM_Read_Message Set (No_Write, Main_Buffer, On); Set (EoB_Text, Main_Buffer, "[End of Message]"); Set (Status_Line, Main_Window, Reverse, " TPU/EVE: MM Read Message Type Ctrl-Z to return to R> "); Position (Beginning_Of (Main_Buffer)); Message ("Use TPU/EVE screen commands to view the message."); EndProcedure; Procedure MM_Dispatch; Position (Beginning_Of (Main_Buffer)); MM_Function := Erase_Character (Length (Current_Line)); Erase_Line; If MM_Function = "mm-send-edit" Then MM_Send_Edit; Else If MM_Function = "mm-reply-edit" Then MM_Reply_Edit; Else If MM_Function = "mm-forward-edit" Then MM_Forward_Edit; Else If MM_Function = "mm-read-message" Then MM_Read_Message; Else Message ("Unknown MM Function"); EndIf; EndIf; EndIf; EndIf; EndProcedure; Procedure Attach_MM Local Filename, OldFlags; ! Map Main_Buffer back into Main_Window, first removing any other windows If Get_Info (Msg_Window, "buffer") Then UnMap (Msg_Window) EndIf; If Get_Info (Reply_Window, "buffer") Then UnMap (Reply_Window) EndIf; Map (Main_Window, Main_Buffer); Position (Main_Buffer); ! Write the message, unless the user made no changes or we're doing ! mm-read-edit If Get_Info (Main_Buffer, "modified") Then If Get_Info (Main_Buffer, "no_write") <> 1 Then Write_File (Main_Buffer); EndIf; EndIf; Erase (Main_Buffer); ! Attach to the owner process (MM) and wait for MM to reattach to us Attach; ! MM has reattached. Reinitialize some settings Set (No_Write, Main_Buffer, Off); If Lookup_Key (Ctrl_Z_Key, Comment) <> "Attach_MM" Then Define_Key ("Attach_MM", Ctrl_Z_Key, "Attach_MM"); EndIf; ! Read in the new message file MM has prepared for us FileName := Get_Info (Main_Buffer, "file_name"); If FileName = "" Then FileName := Get_Info (Main_Buffer, "output_file"); EndIf; Messages_Off; Read_File (FileName); Messages_On (Main_Window); ! And execute the function contained in the file MM_Dispatch; EndProcedure; ! Create all the windows we will need and set their parameters. ! ! Main_Window is the full-screen window ! Main_Buffer is the buffer the message will be typed in always ! Msg_Window is the half-screen window for Main_Buffer when the user ! is replying to a message ! Reply_Buffer holds the text of the message being replied to and is ! set NoWrite ! Reply_Window is the half-screen window for Reply_Buffer Main_Buffer := Current_Buffer; Main_Window := Current_Window; Set (Margins, Main_Buffer, 1, 72); Set (EoB_Text, Main_Buffer, "[End of Message]"); Window_Length := Get_Info (Main_Window, "Original_Length"); Msg_Length := Window_Length / 2; Reply_Length := Window_Length / 2; If (Msg_Length + Reply_Length) < Window_Length Then Msg_Length := Msg_Length + 1; EndIf; Reply_Top := 1; Msg_Top := Reply_Length + 1; Msg_Window := Create_Window (Msg_Top, Msg_Length, ON); Reply_Buffer := Create_Buffer ("Reply_Msg"); Reply_Window := Create_Window (Reply_Top, Reply_Length, ON); Set (No_Write, Reply_Buffer, On); Set (EoB_Text, Reply_Buffer, "[End of Original Message]"); ! ! Define the Ctrl-Z key to perform TPU command EXIT, in case the user ! ! has bound it to something else. ! ! Define_Key ("Exit", Ctrl_Z_Key); ! Define the Ctrl-Z key to perform routine Attach_MM, not EVE EXIT or ! whatever else the user may have bound it to Define_Key ("Attach_MM", Ctrl_Z_Key, "Attach_MM"); ! Now go perform the function contained in the first line of the file ! we've just read in MM_Dispatch; !------------------------------------------------------------------------ ! !You can modify this procedure for use with a non-kept MM by uncommenting !the "Define_Key ("Exit", Ctrl_Z_Key)" command and commenting out the !"Define_Key ("Attach_MM")..." command. (For greater efficiency in !that case, you might also want to remove the ATTACH_MM procedure.) !