home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termMain.c < prev    next >
C/C++ Source or Header  |  1993-02-18  |  70KB  |  3,728 lines

  1. /*
  2. **    termMain.c
  3. **
  4. **    Program main routines and event loop
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Argument vectors offsets. */
  13.  
  14. enum    {    ARG_WINDOW,ARG_PUBSCREEN,ARG_STARTUP,ARG_PORTNAME,ARG_SETTINGS,ARG_UNIT,ARG_DEVICE,
  15.         ARG_NEW,ARG_SYNC,ARG_COUNT };
  16.  
  17.     /* Argument template. */
  18.  
  19. #define ARGTEMPLATE "WINDOW/K,PUBSCREEN/K,STARTUP/K,PORTNAME/K,SETTINGS/K,UNIT/K/N,DEVICE/K,NEW/S,SYNC/S"
  20.  
  21.     /* Local config path variable. */
  22.  
  23. STATIC STRPTR    ConfigPath;
  24. STATIC UBYTE    ThePath[MAX_FILENAME_LENGTH];
  25.  
  26.     /* Startup file name. */
  27.  
  28. STATIC UBYTE    StartupFile[MAX_FILENAME_LENGTH];
  29.  
  30.     /* Segment split routine, has to be local. */
  31.  
  32. STATIC struct Process * SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function);
  33. STATIC VOID        CloseLibs(VOID);
  34.  
  35.     /* main():
  36.      *
  37.      *    This is our main entry point, check for the right
  38.      *    Kickstart version and fire off the background task
  39.      *    if approritate.
  40.      */
  41.  
  42. LONG
  43. main()
  44. {
  45.     STRPTR Result;
  46.  
  47.         /* Are we running as a child of Workbench? */
  48.  
  49.     ThisProcess = (struct Process *)SysBase -> ThisTask;
  50.  
  51.     if(!ThisProcess -> pr_CLI)
  52.     {
  53.         WaitPort(&ThisProcess -> pr_MsgPort);
  54.  
  55.         WBenchMsg = (struct WBStartup *)GetMsg(&ThisProcess -> pr_MsgPort);
  56.     }
  57.     else
  58.         WBenchMsg = NULL;
  59.  
  60.         /* Now try to open dos.library and utility.library and go on examining
  61.          * our calling parameters.
  62.          */
  63.  
  64.     if(!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0)))
  65.     {
  66.         CloseLibs();
  67.  
  68.         return(RETURN_FAIL);
  69.     }
  70.  
  71.     if(!(UtilityBase = OpenLibrary("utility.library",0)))
  72.     {
  73.         CloseLibs();
  74.  
  75.         return(RETURN_FAIL);
  76.     }
  77.  
  78.         /* We were called from Shell. */
  79.  
  80.     if(ThisProcess -> pr_CLI)
  81.     {
  82.         STRPTR *ArgArray;
  83.  
  84.             /* Use the cute ReadArgs parser, allocate the
  85.              * argument vectors...
  86.              */
  87.  
  88.         if(ArgArray = (STRPTR *)AllocVec(sizeof(STRPTR) * (ARG_COUNT),MEMF_ANY|MEMF_CLEAR))
  89.         {
  90.             struct RDArgs *ArgsPtr;
  91.  
  92.             if(ArgsPtr = (struct RDArgs *)AllocDosObject(DOS_RDARGS,TAG_DONE))
  93.             {
  94.                 ArgsPtr -> RDA_ExtHelp = "\nUsage: term [WINDOW <Name>] [PUBSCREEN <Name>] [STARTUP <File name>]\n            [SETTINGS <File or path name>] [UNIT <Number>] [DEVICE <Name>]\n            [NEW] [SYNC]\n\n     Window = Output window specifier\n  PubScreen = Name of public screen to open window upon\n    Startup = ARexx script file to run on startup\n   Settings = Main configuration file name or path name to search for it\n       Unit = Serial device driver unit number\n     Device = Serial device driver name\n        New = Spawn a new `term' process\n       Sync = Keep links to Shell environment\n\n";
  95.  
  96.                     /* Parse the args (if any). */
  97.  
  98.                 if(ReadArgs(ARGTEMPLATE,(LONG *)ArgArray,ArgsPtr))
  99.                 {
  100.                         /* Pop a running `term' to the front? */
  101.  
  102.                     if((TermPort = (struct TermPort *)FindPort("term Port")) && !ArgArray[ARG_NEW])
  103.                     {
  104.                         if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0))
  105.                         {
  106.                             if(TermPort -> TopWindow)
  107.                                 BumpWindow(TermPort -> TopWindow);
  108.                         }
  109.  
  110.                         TermPort = NULL;
  111.  
  112.                         FreeArgs(ArgsPtr);
  113.                         FreeDosObject(DOS_RDARGS,ArgsPtr);
  114.                         FreeVec(ArgArray);
  115.  
  116.                         CloseLibs();
  117.  
  118.                         return(RETURN_OK);
  119.                     }
  120.  
  121.                         /* Are we to use a special settings path? */
  122.  
  123.                     if(ArgArray[ARG_SETTINGS])
  124.                     {
  125.                         ConfigPath = ThePath;
  126.  
  127.                         strcpy(ThePath,ArgArray[ARG_SETTINGS]);
  128.                     }
  129.  
  130.                         /* Are we to use a special ARexx host port name? */
  131.  
  132.                     if(ArgArray[ARG_PORTNAME])
  133.                         strcpy(RexxPortName,ArgArray[ARG_PORTNAME]);
  134.  
  135.                         /* Are we to use a special output window name? */
  136.  
  137.                     if(ArgArray[ARG_WINDOW])
  138.                         strcpy(WindowName,ArgArray[ARG_WINDOW]);
  139.  
  140.                         /* Are we to run an ARexx script on startup? */
  141.  
  142.                     if(ArgArray[ARG_STARTUP])
  143.                         strcpy(StartupFile,ArgArray[ARG_STARTUP]);
  144.  
  145.                         /* Are we to open a window on a public screen? */
  146.  
  147.                     if(ArgArray[ARG_PUBSCREEN])
  148.                         strcpy(SomePubScreenName,ArgArray[ARG_PUBSCREEN]);
  149.  
  150.                         /* Are we to use a special device? */
  151.  
  152.                     if(ArgArray[ARG_DEVICE])
  153.                     {
  154.                         if(ArgArray[ARG_DEVICE][0])
  155.                         {
  156.                             strcpy(NewDevice,ArgArray[ARG_DEVICE]);
  157.  
  158.                             UseNewDevice = TRUE;
  159.                         }
  160.                     }
  161.  
  162.                         /* Are we to use a special unit number? */
  163.  
  164.                     if(ArgArray[ARG_UNIT])
  165.                     {
  166.                         NewUnit = *(LONG *)ArgArray[ARG_UNIT];
  167.  
  168.                         UseNewUnit = TRUE;
  169.                     }
  170.  
  171.                         /* We are to keep our links to
  172.                          * the Shell.
  173.                          */
  174.  
  175.                     if(ArgArray[ARG_SYNC])
  176.                     {
  177.                         BYTE OldPri = ThisProcess -> pr_Task . tc_Node . ln_Pri;
  178.  
  179.                             /* Do we have enough stack space available? */
  180.  
  181.                         if(((struct CommandLineInterface *)BADDR(ThisProcess -> pr_CLI)) -> cli_DefaultStack < 4096)
  182.                         {
  183.                             Printf("\33[1mterm:\33[0m %s.\a\n","Sorry, the Shell stack must be at least 16384 bytes large");
  184.  
  185.                             FreeArgs(ArgsPtr);
  186.                             FreeDosObject(DOS_RDARGS,ArgsPtr);
  187.                             FreeVec(ArgArray);
  188.  
  189.                             CloseLibs();
  190.  
  191.                             return(RETURN_FAIL);
  192.                         }
  193.  
  194.                             /* Open our resources and
  195.                              * squeak on failure.
  196.                              */
  197.  
  198.                         if(Result = OpenAll(ConfigPath))
  199.                         {
  200.                             if(Result[0])
  201.                                 Printf("\33[1mterm:\33[0m %s!\a\n",Result);
  202.  
  203.                             FreeArgs(ArgsPtr);
  204.                             FreeDosObject(DOS_RDARGS,ArgsPtr);
  205.                             FreeVec(ArgArray);
  206.  
  207.                             CloseAll(TRUE);
  208.  
  209.                             return(RETURN_FAIL);
  210.                         }
  211.  
  212.                             /* Go into main input
  213.                              * loop.
  214.                              */
  215.  
  216.                         HandleInput();
  217.  
  218.                             /* Free the argument
  219.                              * data.
  220.                              */
  221.  
  222.                         FreeArgs(ArgsPtr);
  223.                         FreeDosObject(DOS_RDARGS,ArgsPtr);
  224.                         FreeVec(ArgArray);
  225.  
  226.                             /* Restore old priority. */
  227.  
  228.                         SetTaskPri(ThisProcess,(LONG)OldPri);
  229.  
  230.                             /* Terminate execution. */
  231.  
  232.                         CloseAll(TRUE);
  233.  
  234.                         return(RETURN_OK);
  235.                     }
  236.  
  237.                     FreeArgs(ArgsPtr);
  238.                 }
  239.                 else
  240.                 {
  241.                     PrintFault(IoErr(),"term");
  242.  
  243.                     FreeDosObject(DOS_RDARGS,ArgsPtr);
  244.                     FreeVec(ArgArray);
  245.  
  246.                     return(RETURN_ERROR);
  247.                 }
  248.  
  249.                 FreeDosObject(DOS_RDARGS,ArgsPtr);
  250.             }
  251.  
  252.             FreeVec(ArgArray);
  253.  
  254.                 /* Create a new process from our code. */
  255.  
  256.             if(!SegmentSplit("term main process",0,16384,HandleInput))
  257.             {
  258.                 Printf("\33[1mterm:\33[0m Failed to create new process!\a\n");
  259.  
  260.                 CloseLibs();
  261.  
  262.                 return(RETURN_FAIL);
  263.             }
  264.         }
  265.         else
  266.         {
  267.             Printf("\33[1mterm:\33[0m Failed to allocate argument vectors!\a\n");
  268.  
  269.             CloseLibs();
  270.  
  271.             return(RETURN_FAIL);
  272.         }
  273.     }
  274.     else
  275.     {
  276.         LONG StackSize;
  277.  
  278.         StackSize = (LONG)SysBase -> ThisTask -> tc_SPUpper - (LONG)SysBase -> ThisTask -> tc_SPLower;
  279.  
  280.         if(StackSize < 16384)
  281.         {
  282.             if(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37))
  283.                 MyEasyRequest(NULL,"`term' has a problem:\nThe current stack size of %ld bytes is too low,\nplease edit the tool icon to use at least\n16384 bytes and restart the proram.","Continue",StackSize);
  284.  
  285.             CloseLibs();
  286.  
  287.             return(RETURN_FAIL);
  288.         }
  289.         else
  290.         {
  291.             WBenchLock = CurrentDir(WBenchMsg -> sm_ArgList -> wa_Lock);
  292.  
  293.                 /* Open icon.library, we want to take a
  294.                  * look at the icon.
  295.                  */
  296.  
  297.             if(IconBase = OpenLibrary("icon.library",0))
  298.             {
  299.                 struct DiskObject *Icon;
  300.  
  301.                     /* Try to read the icon file. */
  302.  
  303.                 if(Icon = GetProgramIcon())
  304.                 {
  305.                     STRPTR Type;
  306.  
  307.                         /* Look for a `Settings' tooltype. */
  308.  
  309.                     if(ConfigPath = FindToolType(Icon -> do_ToolTypes,"SETTINGS"))
  310.                     {
  311.                             /* Remember the path and continue. */
  312.  
  313.                         strcpy(ThePath,ConfigPath);
  314.  
  315.                         ConfigPath = ThePath;
  316.                     }
  317.  
  318.                         /* Look for a `Portname' tooltype. */
  319.  
  320.                     if(Type = FindToolType(Icon -> do_ToolTypes,"PORTNAME"))
  321.                         strcpy(RexxPortName,Type);
  322.                     else
  323.                         RexxPortName[0] = 0;
  324.  
  325.                         /* Look for a `Window' tooltype. */
  326.  
  327.                     if(Type = FindToolType(Icon -> do_ToolTypes,"WINDOW"))
  328.                         strcpy(WindowName,Type);
  329.                     else
  330.                         WindowName[0] = 0;
  331.  
  332.                         /* Look for a `Pubscreen' tooltype. */
  333.  
  334.                     if(Type = FindToolType(Icon -> do_ToolTypes,"PUBSCREEN"))
  335.                         strcpy(SomePubScreenName,Type);
  336.                     else
  337.                         SomePubScreenName[0] = 0;
  338.  
  339.                         /* Look for a `Startup' tooltype. */
  340.  
  341.                     if(Type = FindToolType(Icon -> do_ToolTypes,"STARTUP"))
  342.                         strcpy(StartupFile,Type);
  343.                     else
  344.                         StartupFile[0] = 0;
  345.  
  346.                         /* Look for a `Device' tooltype. */
  347.  
  348.                     if(Type = FindToolType(Icon -> do_ToolTypes,"DEVICE"))
  349.                     {
  350.                         if(Type[0])
  351.                         {
  352.                             strcpy(NewDevice,Type);
  353.  
  354.                             UseNewDevice = TRUE;
  355.                         }
  356.                     }
  357.  
  358.                         /* Look for a `Unit' tooltype. */
  359.  
  360.                     if(Type = FindToolType(Icon -> do_ToolTypes,"UNIT"))
  361.                     {
  362.                         if(Type[0])
  363.                         {
  364.                             NewUnit = Atol(Type);
  365.  
  366.                             UseNewUnit = TRUE;
  367.                         }
  368.                     }
  369.  
  370.                         /* Free the icon. */
  371.  
  372.                     FreeDiskObject(Icon);
  373.                 }
  374.  
  375.                     /* Close the library. */
  376.  
  377.                 CloseLibrary(IconBase);
  378.  
  379.                 IconBase = NULL;
  380.             }
  381.  
  382.                 /* Initialize this, so OpenAll will work with
  383.                  * correct data.
  384.                  */
  385.  
  386.             TermPort = (struct TermPort *)FindPort("term Port");
  387.  
  388.                 /* We were called from Workbench. */
  389.  
  390.             if(Result = OpenAll(ConfigPath))
  391.             {
  392.                 if(IntuitionBase && Result[0])
  393.                     MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  394.  
  395.                 CloseAll(TRUE);
  396.             }
  397.             else
  398.                 HandleInput();
  399.         }
  400.     }
  401.  
  402.     return(RETURN_OK);
  403. }
  404.  
  405.     /* CloseLibs():
  406.      *
  407.      *    Plain and simple: close two libraries and clean up.
  408.      */
  409.  
  410. STATIC VOID
  411. CloseLibs()
  412. {
  413.     if(UtilityBase)
  414.     {
  415.         CloseLibrary(UtilityBase);
  416.  
  417.         UtilityBase = NULL;
  418.     }
  419.  
  420.     if(WBenchMsg)
  421.         CurrentDir(WBenchLock);
  422.  
  423.     if(DOSBase)
  424.     {
  425.         CloseLibrary(DOSBase);
  426.  
  427.         DOSBase = NULL;
  428.     }
  429.  
  430.     if(WBenchMsg)
  431.     {
  432.         Forbid();
  433.  
  434.         ReplyMsg((struct Message *)WBenchMsg);
  435.     }
  436. }
  437.  
  438.     /* ProcessCleanup(register __d1 BPTR SegList):
  439.      *
  440.      *    Frees all resource the main process has allocated when
  441.      *    it exits.
  442.      */
  443.  
  444. STATIC VOID __saveds __asm
  445. ProcessCleanup(register __d1 BPTR SegList)
  446. {
  447.     CloseAll(FALSE);
  448.  
  449.     Forbid();
  450.  
  451.     UnLoadSeg(SegList);
  452.  
  453.     CloseLibrary(DOSBase);
  454.  
  455.     DOSBase = NULL;
  456. }
  457.  
  458.     /* SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function):
  459.      *
  460.      *    Create a new process from the current one.
  461.      */
  462.  
  463. STATIC struct Process *
  464. SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function)
  465. {
  466.     struct Process            *Child;
  467.     struct CommandLineInterface    *CLI;
  468.  
  469.     CLI = (struct CommandLineInterface *)BADDR(((struct Process *)SysBase -> ThisTask) -> pr_CLI);
  470.  
  471.     Forbid();
  472.  
  473.     Child = CreateNewProcTags(
  474.         NP_CommandName,    "term",
  475.         NP_Name,    Name,
  476.         NP_Priority,    Pri,
  477.         NP_StackSize,    StackSize,
  478.         NP_Entry,    Function,
  479.         NP_Cli,        TRUE,
  480.         NP_ExitCode,    ProcessCleanup,
  481.         NP_ExitData,    CLI -> cli_Module,
  482.     TAG_DONE);
  483.  
  484.     if(Child)
  485.         CLI -> cli_Module = NULL;
  486.  
  487.     Permit();
  488.  
  489.     return(Child);
  490. }
  491.  
  492.     /* HandleInput():
  493.      *
  494.      *    This is our main input loop (check window & serial).
  495.      */
  496.  
  497. VOID __saveds
  498. HandleInput()
  499. {
  500.     ThisProcess = (struct Process *)SysBase -> ThisTask;
  501.  
  502.         /* Open the resources we need. */
  503.  
  504.     if(!IntuitionBase)
  505.     {
  506.         STRPTR Result;
  507.  
  508.         if(Result = OpenAll(ConfigPath))
  509.         {
  510.             if(IntuitionBase && Result[0])
  511.                 MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  512.  
  513.             CloseAll(TRUE);
  514.  
  515.             return;
  516.         }
  517.     }
  518.  
  519.     BumpWindow(Window);
  520.  
  521.         /* Set up the public screen data. */
  522.  
  523.     PubScreenStuff();
  524.  
  525.         /* Change program priority. */
  526.  
  527.     SetTaskPri(ThisProcess,(LONG)Config -> MiscConfig -> Priority);
  528.  
  529.     BlockWindows();
  530.  
  531.         /* Load the phone book. */
  532.  
  533.     LoadPhonebook(LastPhone);
  534.  
  535.         /* Show our business card. */
  536.  
  537.     if(!StartupFile[0])
  538.     {
  539.         if(ShowInfo(TRUE))
  540.             while(HandleRexx());
  541.     }
  542.  
  543.     ReleaseWindows();
  544.  
  545.         /* Initialize the modem. */
  546.  
  547.     SerialCommand(Config -> ModemConfig -> ModemInit);
  548.  
  549.         /* Execute the startup macro (if any). */
  550.  
  551.     if(Config -> CommandConfig -> StartupMacro[0])
  552.         SerialCommand(Config -> CommandConfig -> StartupMacro);
  553.  
  554.     LogAction(LocaleString(MSG_TERMMAIN_LOGMSG_PROGRAM_STARTED_TXT),TermName,TermDate);
  555.  
  556.         /* Go into input loop... */
  557.  
  558. Loop:    while(!MainTerminated)
  559.     {
  560.             /* Handle the signal responses. */
  561.  
  562.         HandleResponse();
  563.  
  564.             /* Are we to run an ARexx script file? */
  565.  
  566.         if(StartupFile[0])
  567.         {
  568.             BlockWindows();
  569.  
  570.             SendARexxCommand(StartupFile);
  571.  
  572.             ReleaseWindows();
  573.  
  574.             StartupFile[0] = 0;
  575.         }
  576.  
  577.             /* Are we to leave the main loop? */
  578.  
  579.         if(MainTerminated)
  580.             break;
  581.  
  582.             /* Make the user notice not too obvious events. */
  583.  
  584.         if(FlowInfo . Changed)
  585.             HandleFlowChange();
  586.  
  587.             /* Are we no longer online? */
  588.  
  589.         if(!Online && WasOnline)
  590.             HandleOnlineCleanup();
  591.  
  592.             /* Now for public screen mode changes. */
  593.  
  594.         if(FixPubScreenMode)
  595.             PubScreenStuff();
  596.  
  597.             /* Now for window size changes. */
  598.  
  599.         if(FixScreenSize)
  600.             ScreenSizeStuff();
  601.  
  602.             /* Somebody told us to re-open the display
  603.              * (changed the terminal emulation/colour
  604.              * mode, etc.).
  605.              */
  606.  
  607.         if(ResetDisplay)
  608.         {
  609.             if(!DisplayReset())
  610.                 break;
  611.         }
  612.  
  613.             /* Display the online cost. */
  614.  
  615.         if(!Online && CurrentPay)
  616.         {
  617.                 /* Reset the text rendering styles, font, etc. in
  618.                  * order to keep the following text from getting
  619.                  * illegible.
  620.                  */
  621.  
  622.             SoftReset();
  623.  
  624.                 /* Display how much we expect
  625.                  * the user will have to pay for
  626.                  * this call.
  627.                  */
  628.  
  629.             ConWrites(LocaleString(MSG_TERMMAIN_THIS_CALL_WILL_COST_YOU_TXT),CreateSum(CurrentPay,TRUE));
  630.  
  631.             CurrentPay = 0;
  632.         }
  633.  
  634.             /* Iconify the program? */
  635.  
  636.         if(DoIconify)
  637.         {
  638.             HandleIconify();
  639.  
  640.             if(MainTerminated)
  641.                 break;
  642.         }
  643.  
  644.             /* Reset the serial driver? */
  645.  
  646.         if(ResetSerial)
  647.         {
  648.             HandleSerialReset();
  649.  
  650.             if(MainTerminated)
  651.                 break;
  652.         }
  653.  
  654.             /* We are to release the serial.device (or
  655.              * whatever we are using) for some reason.
  656.              */
  657.  
  658.         if(ReleaseSerial)
  659.         {
  660.             HandleSerialRelease();
  661.  
  662.             if(MainTerminated)
  663.                 break;
  664.         }
  665.  
  666.             /* Invoke the dialing function? */
  667.  
  668.         if(DoDial != DIAL_IGNORE)
  669.         {
  670.             if(DoDial == DIAL_LIST)
  671.             {
  672.                 BYTE OldStatus = Status;
  673.  
  674.                 DoDial = DIAL_IGNORE;
  675.  
  676.                 BlockWindows();
  677.  
  678.                 DialPanel();
  679.  
  680.                 FreeDialList(FALSE);
  681.  
  682.                 Status = OldStatus;
  683.  
  684.                 SetRedialMenu();
  685.  
  686.                 ReleaseWindows();
  687.             }
  688.             else
  689.             {
  690.                 DoDial = DIAL_IGNORE;
  691.  
  692.                 HandleMenuCode(MEN_REDIAL,NULL);
  693.             }
  694.         }
  695.     }
  696.  
  697.         /* User wants to quit term, so let's try to close
  698.          * our magnificient screen and exit.
  699.          */
  700.  
  701.     if(Screen)
  702.     {
  703.         struct List        *PubScreenList;
  704.         struct PubScreenNode    *ScreenNode;
  705.  
  706.             /* Lock the list of public screens. */
  707.  
  708.         PubScreenList = LockPubScreenList();
  709.  
  710.             /* Scan the list and try to find our
  711.              * private node.
  712.              */
  713.  
  714.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  715.         {
  716.             if(ScreenNode -> psn_Screen == Screen)
  717.                 break;
  718.         }
  719.  
  720.         if(ScreenNode)
  721.         {
  722.                 /* Okay, we know who and where we are,
  723.                  * check the number of visitor windows
  724.                  * currently open on our screen.
  725.                  */
  726.  
  727.             if(ScreenNode -> psn_VisitorCount)
  728.             {
  729.                     /* No chance, don't close
  730.                      * the screen now.
  731.                      */
  732.  
  733.                 UnlockPubScreenList();
  734.  
  735.                 BlockWindows();
  736.  
  737.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  738.  
  739.                 ReleaseWindows();
  740.  
  741.                 MainTerminated = FALSE;
  742.  
  743.                 goto Loop;
  744.             }
  745.         }
  746.  
  747.         UnlockPubScreenList();
  748.     }
  749.  
  750.         /* Send the modem exit command, shut down the
  751.          * serial.device and close all resources.
  752.          */
  753.  
  754.     SerialCommand(Config -> ModemConfig -> ModemExit);
  755.  
  756.     ClearSerial();
  757.  
  758.     LogAction(LocaleString(MSG_TERMMAIN_LOGMSG_PROGRAM_TERMINATED_TXT));
  759.  
  760.     Say(LocaleString(MSG_TERMMAIN_BYE_BYE_TXT));
  761.  
  762.     if(Phonebook && PhoneSize)
  763.         DeletePhonebook(Phonebook,PhoneSize,TRUE);
  764.  
  765.     if(!ThisProcess -> pr_CLI)
  766.         CloseAll(TRUE);
  767. }
  768.  
  769.     /* HandleWindow():
  770.      *
  771.      *    This funny part checks the window(s) for incoming
  772.      *    user input. Menus are handled elsewhere.
  773.      */
  774.  
  775. BYTE
  776. HandleWindow()
  777. {
  778.     struct IntuiMessage    *Massage;
  779.     ULONG             IClass,Code,Qualifier;
  780.     LONG             MouseX,MouseY,Len;
  781.     UBYTE             Char,InputBuffer[257];
  782.     struct Window        *IDCMPWindow;
  783.     BYTE             Result = FALSE;
  784.  
  785.     if(ClipInput)
  786.     {
  787.         WORD Len = GetClip(InputBuffer,256,FALSE);
  788.  
  789.         if(Len < 0)
  790.         {
  791.             CloseClip();
  792.  
  793.             ClipInput = FALSE;
  794.  
  795.             if(ClipXerox)
  796.             {
  797.                 if(Config -> ClipConfig -> InsertSuffix[0])
  798.                     SerialCommand(Config -> ClipConfig -> InsertSuffix);
  799.  
  800.                 ClipXerox = FALSE;
  801.             }
  802.  
  803.             ClipPrefix = FALSE;
  804.         }
  805.         else
  806.         {
  807.             if(!ClipPrefix && ClipXerox)
  808.             {
  809.                 if(Config -> ClipConfig -> InsertPrefix[0])
  810.                     SerialCommand(Config -> ClipConfig -> InsertPrefix);
  811.  
  812.                 ClipPrefix = TRUE;
  813.             }
  814.  
  815.             if(Len > 0)
  816.             {
  817.                     /* Is a send-delay enabled? */
  818.  
  819.                 if(Config -> ClipConfig -> CharDelay || Config -> ClipConfig -> LineDelay)
  820.                 {
  821.                     WORD i;
  822.  
  823.                         /* Run down the buffer... */
  824.  
  825.                     for(i = 0 ; i < Len ; i++)
  826.                     {
  827.                         SerWrite(&InputBuffer[i],1);
  828.  
  829.                             /* What kind of delay
  830.                              * are we to provide?
  831.                              */
  832.  
  833.                         if(InputBuffer[i] == '\r')
  834.                         {
  835.                             if(Config -> ClipConfig -> LineDelay)
  836.                                 WaitTime(Config -> ClipConfig -> LineDelay / 100,(Config -> ClipConfig -> LineDelay % 100) * 10000);
  837.                         }
  838.                         else
  839.                         {
  840.                             if(Config -> ClipConfig -> CharDelay)
  841.                                 WaitTime(Config -> ClipConfig -> CharDelay / 100,(Config -> ClipConfig -> CharDelay % 100) * 10000);
  842.                         }
  843.                     }
  844.                 }
  845.                 else
  846.                     SerWrite(InputBuffer,Len);
  847.             }
  848.  
  849.             Result = TRUE;
  850.         }
  851.     }
  852.  
  853.         /* Any news in the mail? */
  854.  
  855.     if(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  856.     {
  857.         if(Massage -> IDCMPWindow != Window)
  858.         {
  859.             struct IntuiMessage *OriginalMessage = Massage;
  860.  
  861.             if(!(Massage = GT_FilterIMsg(Massage)))
  862.                 ReplyMsg(OriginalMessage);
  863.             else
  864.             {
  865.                     /* Pick up the pieces. */
  866.  
  867.                 IClass        = Massage -> Class;
  868.                 Code        = Massage -> Code;
  869.                 Qualifier    = Massage -> Qualifier;
  870.  
  871.                 MouseX        = Massage -> MouseX;
  872.                 MouseY        = Massage -> MouseY;
  873.  
  874.                 IDCMPWindow    = Massage -> IDCMPWindow;
  875.  
  876.                 if(IClass == IDCMP_RAWKEY)
  877.                 {
  878.                         /* Perform key conversion. */
  879.  
  880.                     if(XEmulatorBase)
  881.                     {
  882.                         if(Len = XEmulatorUserMon(XEM_IO,InputBuffer,256,Massage))
  883.                             Char = InputBuffer[0];
  884.                     }
  885.                     else
  886.                         Char = KeyConvert(Massage,InputBuffer,&Len);
  887.                 }
  888.  
  889.                 Massage = GT_PostFilterIMsg(Massage);
  890.             }
  891.         }
  892.         else
  893.         {
  894.                 /* Pick up the pieces. */
  895.  
  896.             IClass        = Massage -> Class;
  897.             Code        = Massage -> Code;
  898.             Qualifier    = Massage -> Qualifier;
  899.  
  900.             MouseX        = Massage -> MouseX;
  901.             MouseY        = Massage -> MouseY;
  902.  
  903.             IDCMPWindow    = Massage -> IDCMPWindow;
  904.  
  905.             if(IClass == IDCMP_RAWKEY)
  906.             {
  907.                     /* Perform key conversion. */
  908.  
  909.                 if(XEmulatorBase)
  910.                 {
  911.                     if(Len = XEmulatorUserMon(XEM_IO,InputBuffer,256,Massage))
  912.                         Char = InputBuffer[0];
  913.                 }
  914.                 else
  915.                     Char = KeyConvert(Massage,InputBuffer,&Len);
  916.             }
  917.         }
  918.     }
  919.  
  920.     if(Massage)
  921.     {
  922.         ReplyMsg(Massage);
  923.  
  924.         if(IDCMPWindow == InfoWindow)
  925.         {
  926.             switch(IClass)
  927.             {
  928.                 case IDCMP_CLOSEWINDOW:
  929.  
  930.                     CloseInfoWindow();
  931.  
  932.                     return(Result);
  933.  
  934.                 case IDCMP_MOUSEBUTTONS:
  935.  
  936.                     if(!(Code & IECODE_UP_PREFIX))
  937.                         RefreshInfoWindow();
  938.  
  939.                     return(Result);
  940.             }
  941.         }
  942.  
  943.             /* The following messages probably
  944.              * originated from the fast! macro
  945.              * panel.
  946.              */
  947.  
  948.         if(IDCMPWindow == FastWindow)
  949.         {
  950.             struct MacroNode *Node;
  951.  
  952.             switch(IClass)
  953.             {
  954.                     /* Close the window. */
  955.  
  956.                 case IDCMP_CLOSEWINDOW:
  957.  
  958.                     CloseFastWindow();
  959.  
  960.                     return(Result);
  961.  
  962.                     /* Window size has changed for some reason. */
  963.  
  964.                 case IDCMP_NEWSIZE:
  965.  
  966.                     if(FastWindow -> Height != Window -> WScreen -> WBorTop + Window -> WScreen -> Font -> ta_YSize + 1)
  967.                     {
  968.                         RefreshFastWindow(FastWindow -> Height);
  969.  
  970.                         RefreshWindowFrame(FastWindow);
  971.                     }
  972.  
  973.                     return(Result);
  974.  
  975.                 case IDCMP_GADGETUP:
  976.  
  977.                     if(Node = GetFastMacro(Code))
  978.                     {
  979.                         if(Node -> mn_Code[0])
  980.                             SerialCommand(Node -> mn_Code);
  981.                     }
  982.  
  983.                     return(Result);
  984.  
  985.                 case IDCMP_MOUSEBUTTONS:
  986.  
  987.                     return(Result);
  988.             }
  989.         }
  990.  
  991.         if(IDCMPWindow == Window)
  992.         {
  993.             switch(IClass)
  994.             {
  995.                 case IDCMP_NEWSIZE:
  996.  
  997.                     HandleMenuCode(MEN_RESET_TERMINAL,Qualifier);
  998.                     break;
  999.  
  1000.                 case IDCMP_CLOSEWINDOW:
  1001.  
  1002.                     HandleMenuCode(MEN_QUIT,Qualifier);
  1003.                     break;
  1004.             }
  1005.         }
  1006.  
  1007.             /* This looks like a raw, or better, now cooked key. */
  1008.  
  1009.         if(IClass == IDCMP_RAWKEY && Len)
  1010.         {
  1011.             if(Code == HELP_CODE)
  1012.                 GuideDisplay(CONTEXT_MAIN);
  1013.  
  1014.             if(ClipInput)
  1015.             {
  1016.                 CloseClip();
  1017.  
  1018.                 ClipInput = ClipXerox = ClipPrefix = FALSE;
  1019.             }
  1020.  
  1021.                 /* VT100 prefers to handle
  1022.                  * the numeric keypad differently
  1023.                  * in applications mode.
  1024.                  */
  1025.  
  1026.             if(Qualifier & IEQUALIFIER_NUMERICPAD)
  1027.             {
  1028.                 if(HandleCursor(Char,Qualifier))
  1029.                     goto SkipIt;
  1030.             }
  1031.  
  1032.                 /* If input is not a control
  1033.                  * character, such as F-keys,
  1034.                  * cursor keys, etc. process
  1035.                  * it as usual.
  1036.                  */
  1037.  
  1038.             if(Char <= 127 || Char >= 160)
  1039.             {
  1040.                 WORD    i;
  1041.                 UBYTE    c;
  1042.  
  1043.                     /* Run down the contents of
  1044.                      * the key result string.
  1045.                      */
  1046.  
  1047.                 for(i = 0 ; i < Len ; i++)
  1048.                 {
  1049.                     if(Config -> SerialConfig -> StripBit8)
  1050.                         c = InputBuffer[i] & 0x7F;
  1051.                     else
  1052.                         c = InputBuffer[i];
  1053.  
  1054.                         /* Restart serial line
  1055.                          * after XON.
  1056.                          */
  1057.  
  1058.                     if(Status == STATUS_HOLDING)
  1059.                     {
  1060.                         if(c == XOF)
  1061.                         {
  1062.                             SerWrite(&c,1);
  1063.  
  1064.                             Status = STATUS_READY;
  1065.                         }
  1066.                         else
  1067.                             DoBeep();
  1068.                     }
  1069.                     else
  1070.                     {
  1071.                             /* Convert chars
  1072.                              * as approriate.
  1073.                              */
  1074.  
  1075.                         if(c == '\n')
  1076.                         {
  1077.                             switch(Config -> TerminalConfig -> SendLF)
  1078.                             {
  1079.                                 case LF_ASLF:
  1080.  
  1081.                                     goto SendIt;
  1082.  
  1083.                                 case LF_ASLFCR:
  1084.  
  1085.                                     SerWrite("\n\r",2);
  1086.                                     break;
  1087.                             }
  1088.  
  1089.                             continue;
  1090.                         }
  1091.  
  1092.                         if(c == '\r')
  1093.                         {
  1094.                             switch(Config -> TerminalConfig -> SendCR)
  1095.                             {
  1096.                                 case CR_ASCR:
  1097.  
  1098.                                     goto SendIt;
  1099.  
  1100.                                 case CR_ASCRLF:
  1101.  
  1102.                                     SerWrite("\r\n",2);
  1103.                                     break;
  1104.                             }
  1105.  
  1106.                             continue;
  1107.                         }
  1108.  
  1109.                             /* Stop in/output. */
  1110.  
  1111.                         if(c == XON)
  1112.                         {
  1113.                             if(Config -> SerialConfig -> PassThrough)
  1114.                             {
  1115.                                 SerWrite(&c,1);
  1116.  
  1117.                                 continue;
  1118.                             }
  1119.                             else
  1120.                             {
  1121.                                 if(Config -> SerialConfig -> xONxOFF)
  1122.                                     Status = STATUS_HOLDING;
  1123.                             }
  1124.                         }
  1125.  
  1126.                             /* Restart in/output. */
  1127.  
  1128.                         if(c == XOF)
  1129.                         {
  1130.                             if(Config -> SerialConfig -> PassThrough)
  1131.                             {
  1132.                                 SerWrite(&c,1);
  1133.  
  1134.                                 continue;
  1135.                             }
  1136.                         }
  1137.  
  1138.                             /* Convert special
  1139.                              * Amiga characters into
  1140.                              * alien IBM dialect.
  1141.                              */
  1142.  
  1143. SendIt:                        if(Config -> TerminalConfig -> FontMode == FONT_IBM)
  1144.                         {
  1145.                             if(IBMConversion[c])
  1146.                                 SerWrite(&IBMConversion[c],1);
  1147.                             else
  1148.                                 SerWrite(&c,1);
  1149.                         }
  1150.                         else
  1151.                             SerWrite(&c,1);
  1152.                     }
  1153.                 }
  1154.             }
  1155.             else
  1156.             {
  1157.                     /* Send keyboard macro commands
  1158.                      * or perform cursor functions.
  1159.                      */
  1160.  
  1161.                 if(Char >= FN1 && Char <= F10)
  1162.                 {
  1163.                     if(Qualifier & IEQUALIFIER_CONTROL)
  1164.                         SerialCommand(MacroKeys -> Keys[3][Char - FN1]);
  1165.                     else
  1166.                     {
  1167.                         if(Qualifier & (IEQUALIFIER_LALT|IEQUALIFIER_RALT))
  1168.                             SerialCommand(MacroKeys -> Keys[2][Char - FN1]);
  1169.                         else
  1170.                         {
  1171.                             if(Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  1172.                                 SerialCommand(MacroKeys -> Keys[1][Char - FN1]);
  1173.                             else
  1174.                                 SerialCommand(MacroKeys -> Keys[0][Char - FN1]);
  1175.                         }
  1176.                     }
  1177.                 }
  1178.                 else
  1179.                     HandleCursor(Char,Qualifier);
  1180.             }
  1181.         }
  1182.  
  1183.             /* Capture characters from the main
  1184.              * screen.
  1185.              */
  1186.  
  1187.         if(IDCMPWindow == Window)
  1188.         {
  1189.             MouseX -= WindowLeft;
  1190.  
  1191.             if(MouseX < 0)
  1192.                 MouseX = 0;
  1193.  
  1194.             if(MouseX > WindowWidth - 1)
  1195.                 MouseX = WindowWidth - 1;
  1196.  
  1197.             MouseY -= WindowTop;
  1198.  
  1199.             if(MouseY < 0)
  1200.                 MouseY = 0;
  1201.  
  1202.             if(MouseY > WindowHeight - 1)
  1203.                 MouseY = WindowHeight - 1;
  1204.  
  1205.             if(IClass == IDCMP_INACTIVEWINDOW)
  1206.                 HoldClick = FALSE;
  1207.  
  1208.             if(IClass == IDCMP_MOUSEBUTTONS && (!XEmulatorBase || Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL))
  1209.             {
  1210.                 if(Code == SELECTUP)
  1211.                     HoldClick = FALSE;
  1212.  
  1213.                 if(Code == SELECTDOWN)
  1214.                 {
  1215.                     HoldClick = TRUE;
  1216.  
  1217.                     if(Qualifier & IEQUALIFIER_CONTROL)
  1218.                     {
  1219.                         WORD FirstX,FirstY;
  1220.  
  1221.                         FirstX = MouseX / TextFontWidth;
  1222.                         FirstY = MouseY / TextFontHeight;
  1223.  
  1224.                         if(FirstX <= LastColumn && FirstY <= LastLine)
  1225.                         {
  1226.                             UBYTE Char;
  1227.  
  1228.                             ObtainSemaphore(RasterSemaphore);
  1229.  
  1230.                             Char = Raster[FirstY * RasterWidth + FirstX];
  1231.  
  1232.                             ReleaseSemaphore(RasterSemaphore);
  1233.  
  1234.                             if(Char && Char != ' ')
  1235.                             {
  1236.                                 SerWrite(&Char,1);
  1237.  
  1238.                                 if(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  1239.                                 {
  1240.                                     switch(Config -> TerminalConfig -> SendCR)
  1241.                                     {
  1242.                                         case CR_ASCR:
  1243.  
  1244.                                             SerWrite("\r",1);
  1245.                                             break;
  1246.  
  1247.                                         case CR_ASCRLF:
  1248.  
  1249.                                             SerWrite("\r\n",2);
  1250.                                             break;
  1251.                                     }
  1252.                                 }
  1253.                             }
  1254.                         }
  1255.  
  1256.                         return(TRUE);
  1257.                     }
  1258.  
  1259.                     if((Qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT)) && (Qualifier & IEQUALIFIER_LEFTBUTTON))
  1260.                     {
  1261.                         WORD DeltaX,DeltaY;
  1262.  
  1263.                         DeltaX = MouseX / TextFontWidth  - CursorX;
  1264.                         DeltaY = MouseY / TextFontHeight - CursorY;
  1265.  
  1266.                         if(DeltaX || DeltaY)
  1267.                         {
  1268.                             if(DeltaX > 0)
  1269.                             {
  1270.                                 DeltaX++;
  1271.  
  1272.                                 while(DeltaX--)
  1273.                                     SerWrite("\33[C",3);
  1274.                             }
  1275.  
  1276.                             if(DeltaX < 0)
  1277.                             {
  1278.                                 while(DeltaX++)
  1279.                                     SerWrite("\33[D",3);
  1280.                             }
  1281.  
  1282.                             if(DeltaY > 0)
  1283.                             {
  1284.                                 DeltaY++;
  1285.  
  1286.                                 while(DeltaY--)
  1287.                                     SerWrite("\33[B",3);
  1288.                             }
  1289.  
  1290.                             if(DeltaY < 0)
  1291.                             {
  1292.                                 while(DeltaY++)
  1293.                                     SerWrite("\33[A",3);
  1294.                             }
  1295.                         }
  1296.  
  1297.                         return(TRUE);
  1298.                     }
  1299.  
  1300.                     ReportMouse(TRUE,Window);
  1301.  
  1302.                     if(!FirstClick)
  1303.                     {
  1304.                         ULONG CurrentSecs,CurrentMicros;
  1305.  
  1306.                         CurrentTime(&CurrentSecs,&CurrentMicros);
  1307.  
  1308.                         FirstClick = TRUE;
  1309.  
  1310.                         if(ABS(ClickX - MouseX) <= TextFontWidth && ABS(ClickY - MouseY) <= TextFontHeight && DoubleClick(ClickSecs,ClickMicros,CurrentSecs,CurrentMicros))
  1311.                         {
  1312.                             MarkWord(ClickX,ClickY);
  1313.  
  1314.                             return(TRUE);
  1315.                         }
  1316.                         else
  1317.                         {
  1318.                             CurrentTime(&ClickSecs,&ClickMicros);
  1319.  
  1320.                             FirstClick    = FALSE;
  1321.  
  1322.                             ClickX        = MouseX;
  1323.                             ClickY        = MouseY;
  1324.                         }
  1325.                     }
  1326.                     else
  1327.                     {
  1328.                         CurrentTime(&ClickSecs,&ClickMicros);
  1329.  
  1330.                         FirstClick    = FALSE;
  1331.  
  1332.                         ClickX        = MouseX;
  1333.                         ClickY        = MouseY;
  1334.                     }
  1335.  
  1336.                     if(Marking)
  1337.                     {
  1338.                         if(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  1339.                             MoveMarker(MouseX,MouseY);
  1340.                         else
  1341.                         {
  1342.                             DropMarker();
  1343.  
  1344.                             CurrentTime(&ClickSecs,&ClickMicros);
  1345.  
  1346.                             FirstClick    = FALSE;
  1347.  
  1348.                             ClickX        = MouseX;
  1349.                             ClickY        = MouseY;
  1350.  
  1351.                             ReportMouse(TRUE,Window);
  1352.                         }
  1353.                     }
  1354.                 }
  1355.             }
  1356.  
  1357.             if(IClass == IDCMP_MOUSEMOVE)
  1358.             {
  1359.                 if(HoldClick)
  1360.                 {
  1361.                     if(!Marking)
  1362.                         SetMarker(ClickX,ClickY);
  1363.                     else
  1364.                         MoveMarker(MouseX,MouseY);
  1365.                 }
  1366.             }
  1367.         }
  1368.  
  1369.             /* A menu item was selected. */
  1370.  
  1371. SkipIt:        if(IClass == IDCMP_MENUPICK)
  1372.             HandleMenu(Code,Qualifier);
  1373.  
  1374.         return(TRUE);
  1375.     }
  1376.  
  1377.     return(Result);
  1378. }
  1379.  
  1380.     /* HandleMenuCode(ULONG Code,ULONG Qualifier):
  1381.      *
  1382.      *    Handle each function associated with a menu code.
  1383.      */
  1384.  
  1385. VOID
  1386. HandleMenuCode(ULONG Code,ULONG Qualifier)
  1387. {
  1388.     struct FileRequester    *FileRequest;
  1389.     UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  1390.                 *DummyChar;
  1391.     BYTE             OldStatus = Status;
  1392.  
  1393.     BPTR             SomeFile;
  1394.     APTR             OldPtr;
  1395.  
  1396.     switch(Code)
  1397.     {
  1398.             /* Save screen as IFF-ILBM file. */
  1399.  
  1400.         case MEN_SAVE_AS_PICTURE:
  1401.  
  1402.             BlockWindows();
  1403.  
  1404.             if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_SAVE_SCREEN_IFF_TXT),"","",DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT)))
  1405.             {
  1406.                 if(!SaveWindow(DummyBuffer,Window))
  1407.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_SAVE_SCREEN_TO_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  1408.  
  1409.                 FreeAslRequest(FileRequest);
  1410.             }
  1411.  
  1412.             ReleaseWindows();
  1413.  
  1414.             break;
  1415.  
  1416.             /* Save screen as ASCII file. */
  1417.  
  1418.         case MEN_SAVE_AS_TEXT:
  1419.  
  1420.             BlockWindows();
  1421.  
  1422.             if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_SAVE_SCREEN_ASCII_TXT),"","",DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT)))
  1423.             {
  1424.                 if(GetFileSize(DummyBuffer))
  1425.                 {
  1426.                     switch(MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  1427.                     {
  1428.                         case 1:    SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  1429.                             break;
  1430.  
  1431.                         case 2:    if(SomeFile = Open(DummyBuffer,MODE_READWRITE))
  1432.                             {
  1433.                                 if(Seek(SomeFile,0,OFFSET_END) == -1)
  1434.                                 {
  1435.                                     Close(SomeFile);
  1436.  
  1437.                                     SomeFile = NULL;
  1438.                                 }
  1439.                             }
  1440.  
  1441.                             break;
  1442.  
  1443.                         case 0:    SomeFile = ~0;
  1444.                             break;
  1445.                     }
  1446.                 }
  1447.                 else
  1448.                     SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  1449.  
  1450.                 if(!SomeFile)
  1451.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_SAVE_SCREEN_TO_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  1452.                 else
  1453.                 {
  1454.                     if(SomeFile != ~0)
  1455.                     {
  1456.                         LONG     i,j;
  1457.                         UBYTE    *Buffer;
  1458.  
  1459.                         for(i = 0 ; i < RasterHeight ; i++)
  1460.                         {
  1461.                             Buffer = &Raster[i * RasterWidth];
  1462.  
  1463.                             j = LastColumn;
  1464.  
  1465.                             while(j >= 0 && Buffer[j] == ' ')
  1466.                                 j--;
  1467.  
  1468.                             if(j >= 0)
  1469.                             {
  1470.                                 if(!FWrite(SomeFile,Buffer,j + 1,1))
  1471.                                     break;
  1472.                             }
  1473.  
  1474.                             if(!FWrite(SomeFile,"\n",1,1))
  1475.                                 break;
  1476.                         }
  1477.  
  1478.                         Close(SomeFile);
  1479.  
  1480.                         SetProtection(DummyBuffer,FIBF_EXECUTE);
  1481.                     }
  1482.                 }
  1483.  
  1484.                 FreeAslRequest(FileRequest);
  1485.             }
  1486.  
  1487.             ReleaseWindows();
  1488.  
  1489.             break;
  1490.  
  1491.             /* Print the screen (pure ASCII). */
  1492.  
  1493.         case MEN_PRINT_SCREEN:
  1494.  
  1495.             BlockWindows();
  1496.  
  1497.             if(RasterEnabled)
  1498.                 PrintSomething(PRINT_SCREEN);
  1499.             else
  1500.                 MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_NO_DATA_TO_PRINT_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  1501.  
  1502.             ReleaseWindows();
  1503.  
  1504.             break;
  1505.  
  1506.             /* Print the clipboard contents. */
  1507.  
  1508.         case MEN_PRINT_CLIP:
  1509.  
  1510.             BlockWindows();
  1511.  
  1512.             PrintSomething(PRINT_CLIP);
  1513.  
  1514.             ReleaseWindows();
  1515.  
  1516.             break;
  1517.  
  1518.             /* Open/close the terminal capture file. */
  1519.  
  1520.         case MEN_CAPTURE_TO_FILE:
  1521.  
  1522.             if(FileCapture)
  1523.                 CloseFileCapture();
  1524.             else
  1525.                 OpenFileCapture();
  1526.  
  1527.             break;
  1528.  
  1529.             /* Start/terminate the printer
  1530.              * capture.
  1531.              */
  1532.  
  1533.         case MEN_CAPTURE_TO_PRINTER:
  1534.  
  1535.             if(PrinterCapture)
  1536.                 ClosePrinterCapture(TRUE);
  1537.             else
  1538.                 OpenPrinterCapture(FALSE);
  1539.  
  1540.             break;
  1541.  
  1542.             /* Iconify the program. */
  1543.  
  1544.         case MEN_ICONIFY:
  1545.  
  1546.             DoIconify = TRUE;
  1547.  
  1548.             break;
  1549.  
  1550.             /* Say who we are. */
  1551.  
  1552.         case MEN_ABOUT:
  1553.  
  1554.             BlockWindows();
  1555.  
  1556.             ShowInfo(FALSE);
  1557.  
  1558.             ReleaseWindows();
  1559.  
  1560.             break;
  1561.  
  1562.             /* Terminate the program. */
  1563.  
  1564.         case MEN_QUIT:
  1565.  
  1566.             if(Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  1567.                 MainTerminated = TRUE;
  1568.             else
  1569.             {
  1570.                 STRPTR    Buffer;
  1571.                 LONG    OldLen,Len = strlen(LocaleString(MSG_TERMMAIN_REALLY_QUIT_TXT)) + 3;
  1572.  
  1573.                 OldLen = Len;
  1574.  
  1575.                 if(Online)
  1576.                     Len += strlen(LocaleString(MSG_WAIT_PROGRAM_IS_STILL_ONLINE_TXT)) + 4;
  1577.  
  1578.                 if(BufferChanged)
  1579.                     Len += strlen(LocaleString(MSG_WAIT_REVIEW_BUFFER_NOT_SAVED_TXT)) + 4;
  1580.  
  1581.                 if(ConfigChanged)
  1582.                     Len += strlen(LocaleString(MSG_WAIT_CONFIGURATION_HAS_BEEN_CHANGED_TXT)) + 4;
  1583.  
  1584.                 if(PhonebookChanged)
  1585.                     Len += strlen(LocaleString(MSG_WAIT_PHONEBOOK_NOT_SAVED_TXT)) + 4;
  1586.  
  1587.                 if(TranslationChanged)
  1588.                     Len += strlen(LocaleString(MSG_WAIT_TRANSLATION_TABLES_CHANGED_TXT)) + 4;
  1589.  
  1590.                 if(MacroChanged)
  1591.                     Len += strlen(LocaleString(MSG_WAIT_MACRO_KEYS_CHANGED_TXT)) + 4;
  1592.  
  1593.                 if(CursorKeysChanged)
  1594.                     Len += strlen(LocaleString(MSG_WAIT_CURSOR_KEYS_CHANGED_TXT)) + 4;
  1595.  
  1596.                 if(FastMacrosChanged)
  1597.                     Len += strlen(LocaleString(MSG_WAIT_FAST_MACROS_CHANGED_TXT)) + 4;
  1598.  
  1599.                 if(HotkeysChanged)
  1600.                     Len += strlen(LocaleString(MSG_WAIT_HOTKEYS_CHANGED_TXT)) + 4;
  1601.  
  1602.                 if(SpeechChanged)
  1603.                     Len += strlen(LocaleString(MSG_WAIT_SPEECH_SETTINGS_CHANGED_TXT)) + 4;
  1604.  
  1605.                 BlockWindows();
  1606.  
  1607.                 OldPtr = ThisProcess -> pr_WindowPtr;
  1608.  
  1609.                 ThisProcess -> pr_WindowPtr = (APTR)Window;
  1610.  
  1611.                 if(OldLen != Len)
  1612.                 {
  1613.                     if(Buffer = (STRPTR)AllocVec(Len,MEMF_ANY))
  1614.                     {
  1615.                         SPrintf(Buffer,"%s\n\n",LocaleString(MSG_TERMMAIN_REALLY_QUIT_TXT));
  1616.  
  1617.                         if(Online)
  1618.                         {
  1619.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_PROGRAM_IS_STILL_ONLINE_TXT));
  1620.  
  1621.                             strcat(Buffer,SharedBuffer);
  1622.                         }
  1623.  
  1624.                         if(BufferChanged)
  1625.                         {
  1626.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_REVIEW_BUFFER_NOT_SAVED_TXT));
  1627.  
  1628.                             strcat(Buffer,SharedBuffer);
  1629.                         }
  1630.  
  1631.                         if(ConfigChanged)
  1632.                         {
  1633.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_CONFIGURATION_HAS_BEEN_CHANGED_TXT));
  1634.  
  1635.                             strcat(Buffer,SharedBuffer);
  1636.                         }
  1637.  
  1638.                         if(PhonebookChanged)
  1639.                         {
  1640.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_PHONEBOOK_NOT_SAVED_TXT));
  1641.  
  1642.                             strcat(Buffer,SharedBuffer);
  1643.                         }
  1644.  
  1645.                         if(TranslationChanged)
  1646.                         {
  1647.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_TRANSLATION_TABLES_CHANGED_TXT));
  1648.  
  1649.                             strcat(Buffer,SharedBuffer);
  1650.                         }
  1651.  
  1652.                         if(MacroChanged)
  1653.                         {
  1654.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_MACRO_KEYS_CHANGED_TXT));
  1655.  
  1656.                             strcat(Buffer,SharedBuffer);
  1657.                         }
  1658.  
  1659.                         if(CursorKeysChanged)
  1660.                         {
  1661.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_CURSOR_KEYS_CHANGED_TXT));
  1662.  
  1663.                             strcat(Buffer,SharedBuffer);
  1664.                         }
  1665.  
  1666.                         if(FastMacrosChanged)
  1667.                         {
  1668.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_FAST_MACROS_CHANGED_TXT));
  1669.  
  1670.                             strcat(Buffer,SharedBuffer);
  1671.                         }
  1672.  
  1673.                         if(HotkeysChanged)
  1674.                         {
  1675.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_HOTKEYS_CHANGED_TXT));
  1676.  
  1677.                             strcat(Buffer,SharedBuffer);
  1678.                         }
  1679.  
  1680.                         if(SpeechChanged)
  1681.                         {
  1682.                             SPrintf(SharedBuffer," · %s\n",LocaleString(MSG_WAIT_SPEECH_SETTINGS_CHANGED_TXT));
  1683.  
  1684.                             strcat(Buffer,SharedBuffer);
  1685.                         }
  1686.  
  1687.                         if(MyEasyRequest(Window,Buffer,LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  1688.                             MainTerminated = TRUE;
  1689.  
  1690.                         FreeVec(Buffer);
  1691.                     }
  1692.                     else
  1693.                     {
  1694.                         if(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_REALLY_QUIT_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  1695.                             MainTerminated = TRUE;
  1696.                     }
  1697.                 }
  1698.                 else
  1699.                 {
  1700.                     if(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_REALLY_QUIT_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  1701.                         MainTerminated = TRUE;
  1702.                 }
  1703.  
  1704.                 ThisProcess -> pr_WindowPtr = OldPtr;
  1705.  
  1706.                 ReleaseWindows();
  1707.             }
  1708.  
  1709.             break;
  1710.  
  1711.             /* Feed the contents of the clipboard
  1712.              * into the input stream.
  1713.              */
  1714.  
  1715.         case MEN_PASTE:
  1716.  
  1717.             if(!OpenClip(Config -> ClipConfig -> ClipboardUnit))
  1718.             {
  1719.                 ClipInput = TRUE;
  1720.  
  1721.                 if(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  1722.                     ClipXerox = TRUE;
  1723.             }
  1724.             else
  1725.                 ClipInput = FALSE;
  1726.  
  1727.             break;
  1728.  
  1729.         case MEN_COPY:
  1730.  
  1731.             ClipMarker();
  1732.             break;
  1733.  
  1734.         case MEN_CLEAR:
  1735.  
  1736.             DropMarker();
  1737.             break;
  1738.  
  1739.             /* Execute an AmigaDOS command. */
  1740.  
  1741.         case MEN_EXECUTE_DOS_COMMAND:
  1742.  
  1743.             BlockWindows();
  1744.  
  1745.             DummyBuffer[0] = 0;
  1746.  
  1747.                 /* Enter the name of the command. */
  1748.  
  1749.             if(GetString(TRUE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_AMIGADOS_COMMAND_TXT),DummyBuffer))
  1750.                 SendAmigaDOSCommand(DummyBuffer);
  1751.  
  1752.             ReleaseWindows();
  1753.  
  1754.             break;
  1755.  
  1756.             /* Execute an ARexx script command. */
  1757. #ifdef USE_AREXX
  1758.  
  1759.         case MEN_EXECUTE_REXX_COMMAND:
  1760.  
  1761.             BlockWindows();
  1762.  
  1763.             DummyBuffer[0] = 0;
  1764.  
  1765.                 /* Get the rexx file name/program. */
  1766.  
  1767.             if(GetString(TRUE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_AREXX_COMMAND_TXT),DummyBuffer))
  1768.                 SendARexxCommand(DummyBuffer);
  1769.  
  1770.             ReleaseWindows();
  1771.  
  1772.             break;
  1773.  
  1774. #endif    /* USE_AREXX */
  1775.  
  1776.             /* Set the name we will use to open the
  1777.              * default console output window for
  1778.              * AmigaDOS commands and ARexx scripts.
  1779.              */
  1780.  
  1781.         case MEN_SET_CONSOLE:
  1782.  
  1783.             BlockWindows();
  1784.  
  1785.             if(GetString(FALSE,FALSE,0,LocaleString(MSG_TERMMAIN_SET_CONSOLE_WINDOW_TXT),WindowName))
  1786.                 SetEnvDOS("TERMWINDOW",WindowName);
  1787.  
  1788.             ReleaseWindows();
  1789.  
  1790.             break;
  1791.  
  1792.             /* Open the phonebook and dial the
  1793.              * list of entries the user will select.
  1794.              */
  1795.  
  1796.         case MEN_PHONEBOOK:
  1797.  
  1798.             BlockWindows();
  1799.  
  1800.             while(PhonePanel())
  1801.             {
  1802.                 if(!DialPanel())
  1803.                 {
  1804.                     Status = OldStatus;
  1805.  
  1806.                     break;
  1807.                 }
  1808.  
  1809.                 Status = OldStatus;
  1810.             }
  1811.  
  1812.             SetRedialMenu();
  1813.  
  1814.             ReleaseWindows();
  1815.  
  1816.             break;
  1817.  
  1818.             /* Redial those dial list entries which
  1819.              * we were unable to connect.
  1820.              */
  1821.  
  1822.         case MEN_REDIAL:
  1823.  
  1824.             BlockWindows();
  1825.  
  1826.             do
  1827.             {
  1828.                 if(!DialPanel())
  1829.                 {
  1830.                     Status = OldStatus;
  1831.  
  1832.                     break;
  1833.                 }
  1834.  
  1835.                 Status = OldStatus;
  1836.             }
  1837.             while(PhonePanel());
  1838.  
  1839.             SetRedialMenu();
  1840.  
  1841.             ReleaseWindows();
  1842.  
  1843.             break;
  1844.  
  1845.             /* Dial a single number. */
  1846.  
  1847.         case MEN_DIAL_NUMBER:
  1848.  
  1849.             BlockWindows();
  1850.  
  1851.             DummyBuffer[0] = 0;
  1852.  
  1853.             if(GetString(FALSE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_PHONE_NUMBER_TXT),DummyBuffer))
  1854.             {
  1855.                 if(DummyBuffer[0])
  1856.                 {
  1857.                     struct List *LocalList;
  1858.  
  1859.                     if(LocalList = (struct List *)AllocVec(sizeof(struct List),MEMF_ANY|MEMF_CLEAR))
  1860.                     {
  1861.                         struct PhoneNode    *DialNode;
  1862.                         LONG             Len = strlen(DummyBuffer);
  1863.  
  1864.                         NewList(LocalList);
  1865.  
  1866.                         if(DialNode = (struct PhoneNode *)AllocVec(sizeof(struct PhoneNode) + Len + 1,MEMF_ANY|MEMF_CLEAR))
  1867.                         {
  1868.                             DialNode -> VanillaNode . ln_Name = (char *)(DialNode + 1);
  1869.  
  1870.                             strcpy(DialNode -> VanillaNode . ln_Name,DummyBuffer);
  1871.  
  1872.                             AddTail(LocalList,&DialNode -> VanillaNode);
  1873.  
  1874.                             FreeDialList(TRUE);
  1875.  
  1876.                             DialList = LocalList;
  1877.  
  1878.                             DialPanel();
  1879.  
  1880.                             Status = OldStatus;
  1881.                         }
  1882.                         else
  1883.                             FreeVec(LocalList);
  1884.                     }
  1885.                 }
  1886.             }
  1887.  
  1888.             SetRedialMenu();
  1889.  
  1890.             ReleaseWindows();
  1891.  
  1892.             break;
  1893.  
  1894.             /* Send a break across the serial line. */
  1895.  
  1896.         case MEN_SEND_BREAK:
  1897.  
  1898.             if(WriteRequest)
  1899.             {
  1900.                 Status = STATUS_BREAKING;
  1901.  
  1902.                 WriteRequest -> IOSer . io_Command = SDCMD_BREAK;
  1903.  
  1904.                 DoIO(WriteRequest);
  1905.  
  1906.                 Status = OldStatus;
  1907.             }
  1908.  
  1909.             break;
  1910.  
  1911.             /* Hang up the phone line. */
  1912.  
  1913.         case MEN_HANG_UP:
  1914.  
  1915.             BlockWindows();
  1916.  
  1917.             Status = STATUS_HANGUP;
  1918.  
  1919.                 /* Are we to drop the DTR line
  1920.                  * before sending the hangup
  1921.                  * string?
  1922.                  */
  1923.  
  1924.             if(Config -> ModemConfig -> DropDTR)
  1925.             {
  1926.                 /* Let's be nice and try to transmit the
  1927.                  * `drop the line' command before
  1928.                  * trying to close and reopen the driver.
  1929.                  */
  1930.  
  1931.                 WriteRequest -> IOSer . io_Command    = SIOCMD_SETCTRLLINES;
  1932.                 WriteRequest -> IOSer . io_Offset    = SIOB_DTRF;
  1933.                 WriteRequest -> IOSer . io_Length    = 0;
  1934.  
  1935.                 /* Transmit the command. */
  1936.  
  1937.                 if(!DoIO(WriteRequest))
  1938.                 {
  1939.                     /* Wait a bit... */
  1940.  
  1941.                     WaitTime(1,0);
  1942.  
  1943.                     /* Raise the line again. */
  1944.  
  1945.                     WriteRequest -> IOSer . io_Command    = SIOCMD_SETCTRLLINES;
  1946.                     WriteRequest -> IOSer . io_Offset    = SIOB_DTRF;
  1947.                     WriteRequest -> IOSer . io_Length    = SIOB_DTRF;
  1948.  
  1949.                     DoIO(WriteRequest);
  1950.                 }
  1951.                 else
  1952.                 {
  1953.                     /* Do it the standard way: close and reopen
  1954.                      * the serial driver (the serial.device is
  1955.                      * supposed to drop the DTR line when closed).
  1956.                      */
  1957.  
  1958.                     if(!DropDTR())
  1959.                     {
  1960.                         if(!MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_REOPEN_UNIT_TXT),LocaleString(MSG_TERMMAIN_IGNORE_QUIT_TXT),Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber))
  1961.                             MainTerminated = TRUE;
  1962.                     }
  1963.                 }
  1964.             }
  1965.  
  1966.                 /* Transmit the hangup command. */
  1967.  
  1968.             if(Config -> ModemConfig -> ModemHangup[0])
  1969.                 SerialCommand(Config -> ModemConfig -> ModemHangup);
  1970.  
  1971.                 /* Reset to old status. */
  1972.  
  1973.             Status = OldStatus;
  1974.  
  1975.                 /* We are no longer online. */
  1976.  
  1977.             Online = FALSE;
  1978.  
  1979.                 /* Clear the password. */
  1980.  
  1981.             Password[0]        = 0;
  1982.             UserName[0]        = 0;
  1983.  
  1984.             CurrentBBSName[0]    = 0;
  1985.             CurrentBBSComment[0]    = 0;
  1986.             CurrentBBSNumber[0]    = 0;
  1987.  
  1988.                 /* Note the  last action. */
  1989.  
  1990.             LogAction(LocaleString(MSG_TERMMAIN_LOGMSG_HANG_UP_TXT));
  1991.  
  1992.             ReleaseWindows();
  1993.  
  1994.                 /* Execute logoff macro. */
  1995.  
  1996.             if(Config -> CommandConfig -> LogoffMacro[0] && WasOnline)
  1997.                 SerialCommand(Config -> CommandConfig -> LogoffMacro);
  1998.  
  1999.                 /* Update the logfile. */
  2000.  
  2001.             StopCall(FALSE);
  2002.  
  2003.                 /* Don't execute the logoff macro twice. */
  2004.  
  2005.             WasOnline = FALSE;
  2006.  
  2007.             ChosenEntry = NULL;
  2008.  
  2009.                 /* Enable the dialing functions. */
  2010.  
  2011.             SetDialMenu(TRUE);
  2012.  
  2013.             if(Config -> ModemConfig -> RedialAfterHangup)
  2014.             {
  2015.                 if(DialList)
  2016.                 {
  2017.                     if(DialList -> lh_Head -> ln_Succ)
  2018.                         DoDial = DIAL_REDIAL;
  2019.                 }
  2020.             }
  2021.  
  2022.             break;
  2023.  
  2024.             /* Wait a bit... */
  2025.  
  2026.         case MEN_WAIT:
  2027.         {
  2028.             struct Window        *ReqWindow;
  2029.             struct EasyStruct     Easy;
  2030.  
  2031.             Easy . es_StructSize    = sizeof(struct EasyStruct);
  2032.             Easy . es_Flags        = NULL;
  2033.             Easy . es_Title        = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  2034.             Easy . es_GadgetFormat    = (UBYTE *)LocaleString(MSG_GLOBAL_CONTINUE_TXT);
  2035.             Easy . es_TextFormat    = (UBYTE *)LocaleString(MSG_TERMMAIN_WAITING_TXT);
  2036.  
  2037.             BlockWindows();
  2038.  
  2039.             if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  2040.             {
  2041.                 ULONG    Signals;
  2042.                 BYTE    Done = FALSE;
  2043.  
  2044.                     /* Don't echo serial output. */
  2045.  
  2046.                 Quiet = TRUE;
  2047.  
  2048.                 do
  2049.                 {
  2050.                     SerWrite(" \b",2);
  2051.  
  2052.                     HandleSerial();
  2053.  
  2054.                     TimeRequest -> tr_node . io_Command    = TR_ADDREQUEST;
  2055.                     TimeRequest -> tr_time . tv_secs    = 1;
  2056.                     TimeRequest -> tr_time . tv_micro    = 0;
  2057.  
  2058.                     BeginIO(TimeRequest);
  2059.  
  2060.                     Signals = Wait(SIG_TIMER | PORTMASK(ReqWindow -> UserPort));
  2061.  
  2062.                     if(Signals & SIG_TIMER)
  2063.                         WaitIO(TimeRequest);
  2064.  
  2065.                     if(Signals & PORTMASK(ReqWindow -> UserPort))
  2066.                     {
  2067.                         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  2068.                         {
  2069.                             Done = TRUE;
  2070.  
  2071.                             if(!CheckIO(TimeRequest))
  2072.                                 AbortIO(TimeRequest);
  2073.  
  2074.                             WaitIO(TimeRequest);
  2075.                         }
  2076.                     }
  2077.                 }
  2078.                 while(!Done);
  2079.  
  2080.                 Quiet = FALSE;
  2081.  
  2082.                 FreeSysRequest(ReqWindow);
  2083.             }
  2084.  
  2085.             ReleaseWindows();
  2086.         }
  2087.  
  2088.         break;
  2089.  
  2090.             /* Flush the serial buffers. */
  2091.  
  2092.         case MEN_FLUSH_BUFFER:
  2093.  
  2094.             ClearSerial();
  2095.  
  2096.             if(ReadRequest)
  2097.             {
  2098.                 ReadRequest -> IOSer . io_Command    = CMD_READ;
  2099.                 ReadRequest -> IOSer . io_Data        = ReadBuffer;
  2100.                 ReadRequest -> IOSer . io_Length     = 1;
  2101.  
  2102.                 SetSignal(0,SIG_SERIAL);
  2103.  
  2104.                 BeginIO(ReadRequest);
  2105.             }
  2106.  
  2107.             break;
  2108.  
  2109.             /* Release the serial device for other
  2110.              * applications.
  2111.              */
  2112.  
  2113.         case MEN_RELEASE_DEVICE:
  2114.  
  2115.             ReleaseSerial = TRUE;
  2116.             break;
  2117.  
  2118.         case MEN_UPLOAD_ASCII:
  2119.  
  2120.             BlockWindows();
  2121.  
  2122.             if(ASCIISetup())
  2123.             {
  2124.                 StartXprSend(TRANSFER_ASCII,TRUE);
  2125.  
  2126.                 ASCIIShutdown();
  2127.             }
  2128.  
  2129.             ReleaseWindows();
  2130.  
  2131.             break;
  2132.  
  2133.         case MEN_DOWNLOAD_ASCII:
  2134.  
  2135.             BlockWindows();
  2136.  
  2137.             if(ASCIISetup())
  2138.             {
  2139.                 StartXprReceive(TRANSFER_ASCII,NULL,TRUE);
  2140.  
  2141.                 ASCIIShutdown();
  2142.             }
  2143.  
  2144.             ReleaseWindows();
  2145.  
  2146.             break;
  2147.  
  2148.         case MEN_UPLOAD_TEXT:
  2149.  
  2150.             BlockWindows();
  2151.  
  2152.             BinaryTransfer = FALSE;
  2153.  
  2154.             StartXprSend(TRANSFER_TEXT,TRUE);
  2155.  
  2156.             BinaryTransfer = TRUE;
  2157.  
  2158.             ReleaseWindows();
  2159.  
  2160.             break;
  2161.  
  2162.         case MEN_DOWNLOAD_TEXT:
  2163.  
  2164.             BlockWindows();
  2165.  
  2166.             BinaryTransfer = FALSE;
  2167.  
  2168.             StartXprReceive(TRANSFER_TEXT,NULL,TRUE);
  2169.  
  2170.             BinaryTransfer = TRUE;
  2171.  
  2172.             ReleaseWindows();
  2173.  
  2174.             break;
  2175.  
  2176.             /* Edit and transfer a file. */
  2177.  
  2178.         case MEN_EDIT_AND_UPLOAD_TEXT:
  2179.  
  2180.             BlockWindows();
  2181.  
  2182.             if(!Config -> PathConfig -> Editor[0])
  2183.                 GetString(TRUE,FALSE,0,LocaleString(MSG_TERMMAIN_ENTER_NAME_OF_EDITOR_TO_USE_TXT),Config -> PathConfig -> Editor);
  2184.  
  2185.             if(Config -> PathConfig -> Editor[0])
  2186.             {
  2187.                 if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_EDIT_AND_TRANSFER_FILE_TXT),"","",DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_TERMMAIN_EDIT_TXT)))
  2188.                 {
  2189.                     UBYTE CompoundName[512];
  2190.  
  2191.                     strcpy(CompoundName,Config -> PathConfig -> Editor);
  2192.                     strcat(CompoundName," ");
  2193.                     strcat(CompoundName,DummyBuffer);
  2194.  
  2195.                     SystemTags(CompoundName,TAG_DONE);
  2196.  
  2197.                     BumpWindow(Window);
  2198.  
  2199.                     FreeAslRequest(FileRequest);
  2200.  
  2201.                     if(GetFileSize(DummyBuffer))
  2202.                     {
  2203.                         BinaryTransfer = FALSE;
  2204.  
  2205.                         switch(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_TRANSFER_FILE_AS_TXT),LocaleString(MSG_TERMMAIN_ASCII_UPLOAD_CANCEL_TXT),FilePart(DummyBuffer)))
  2206.                         {
  2207.                             case 1:    if(ASCIISetup())
  2208.                                 {
  2209.                                     SendTextFile(DummyBuffer);
  2210.  
  2211.                                     ASCIIShutdown();
  2212.                                 }
  2213.  
  2214.                                 break;
  2215.  
  2216.                             case 2:    SendTextFile(DummyBuffer);
  2217.  
  2218.                                 break;
  2219.  
  2220.                             case 0:    break;
  2221.                         }
  2222.  
  2223.                         BinaryTransfer = TRUE;
  2224.                     }
  2225.                 }
  2226.             }
  2227.  
  2228.             ReleaseWindows();
  2229.             break;
  2230.  
  2231.         case MEN_UPLOAD_BINARY:
  2232.  
  2233.             BlockWindows();
  2234.  
  2235.             BinaryTransfer = TRUE;
  2236.  
  2237.             StartXprSend(TRANSFER_BINARY,TRUE);
  2238.  
  2239.             ReleaseWindows();
  2240.  
  2241.             break;
  2242.  
  2243.             /* Download some files. */
  2244.  
  2245.         case MEN_DOWNLOAD_BINARY:
  2246.  
  2247.             BlockWindows();
  2248.  
  2249.             BinaryTransfer = TRUE;
  2250.  
  2251.             StartXprReceive(TRANSFER_BINARY,NULL,TRUE);
  2252.  
  2253.             ReleaseWindows();
  2254.  
  2255.             break;
  2256.  
  2257.             /* Clear the contents of the scrollback
  2258.              * buffer.
  2259.              */
  2260.  
  2261.         case MEN_CLEAR_BUFFER:
  2262.  
  2263.             if(Lines)
  2264.             {
  2265.                 BlockWindows();
  2266.  
  2267.                 if(Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  2268.                     FreeBuffer();
  2269.                 else
  2270.                 {
  2271.                     if(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Lines))
  2272.                         FreeBuffer();
  2273.                 }
  2274.  
  2275.                 UpdateReview(TRUE);
  2276.  
  2277.                 ReleaseWindows();
  2278.             }
  2279.  
  2280.             break;
  2281.  
  2282.             /* Display the scrollback buffer.
  2283.              * Notify the scrollback task or
  2284.              * fire it off if approriate.
  2285.              */
  2286.  
  2287.         case MEN_DISPLAY_BUFFER:
  2288.  
  2289.             if(!LaunchBuffer())
  2290.             {
  2291.                 BlockWindows();
  2292.  
  2293.                 MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_UNABLE_TO_CREATE_BUFFER_TASK_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  2294.  
  2295.                 ReleaseWindows();
  2296.             }
  2297.  
  2298.             break;
  2299.  
  2300.             /* Close the buffer display. */
  2301.  
  2302.         case MEN_CLOSE_BUFFER:
  2303.  
  2304.             if(BufferProcess)
  2305.             {
  2306.                 Forbid();
  2307.  
  2308.                 Signal(BufferProcess,SIG_KILL);
  2309.  
  2310.                 SetSignal(0,SIG_HANDSHAKE);
  2311.  
  2312.                 Wait(SIG_HANDSHAKE);
  2313.  
  2314.                 Permit();
  2315.             }
  2316.  
  2317.             break;
  2318.  
  2319.             /* Is the buffer to be frozen? */
  2320.  
  2321.         case MEN_FREEZE_BUFFER:
  2322.  
  2323.             BufferFrozen ^= TRUE;
  2324.  
  2325.             CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  2326.  
  2327.             break;
  2328.  
  2329.             /* Load the buffer contents from a file. */
  2330.  
  2331.         case MEN_OPEN_BUFFER:
  2332.  
  2333.             BlockWindows();
  2334.  
  2335.             if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_LOAD_BUFFER_TXT),"","",DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT)))
  2336.             {
  2337.                 if(GetFileSize(DummyBuffer))
  2338.                 {
  2339.                     if(SomeFile = Open(DummyBuffer,MODE_OLDFILE))
  2340.                     {
  2341.                         if(Lines)
  2342.                         {
  2343.                             switch(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_TERMMAIN_DISCARD_APPPEND_CANCEL_TXT),Lines))
  2344.                             {
  2345.                                 case 1:    FreeBuffer();
  2346.                                     break;
  2347.  
  2348.                                 case 2:    break;
  2349.  
  2350.                                 case 0:    Close(SomeFile);
  2351.                                     SomeFile = NULL;
  2352.                                     break;
  2353.                             }
  2354.                         }
  2355.  
  2356.                         if(SomeFile)
  2357.                         {
  2358.                             LONG Len;
  2359.  
  2360.                             LineRead(NULL,NULL,NULL);
  2361.  
  2362.                             while((Len = LineRead(SomeFile,DummyBuffer,80)) > 0)
  2363.                                 StoreBuffer(DummyBuffer,Len);
  2364.  
  2365.                             Close(SomeFile);
  2366.  
  2367.                             BufferChanged = TRUE;
  2368.                         }
  2369.                     }
  2370.                 }
  2371.  
  2372.                 FreeAslRequest(FileRequest);
  2373.             }
  2374.  
  2375.             ReleaseWindows();
  2376.             break;
  2377.  
  2378.             /* Save the contents of the scrollback
  2379.              * buffer to a file (line by line).
  2380.              */
  2381.  
  2382.         case MEN_SAVE_BUFFER_AS:
  2383.  
  2384.             BlockWindows();
  2385.  
  2386.             if(!Lines || !BufferLines)
  2387.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_NOTHING_IN_THE_BUFFER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  2388.             else
  2389.             {
  2390.                 if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_SAVE_BUFFER_TXT),Config -> CaptureConfig -> BufferPath,"",DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT)))
  2391.                 {
  2392.                     SomeFile = NULL;
  2393.  
  2394.                         /* If the file we are about
  2395.                          * to create already exists,
  2396.                          * ask the user whether we are
  2397.                          * to create, append or skip
  2398.                          * the file.
  2399.                          */
  2400.  
  2401.                     if(GetFileSize(DummyBuffer))
  2402.                     {
  2403.                         switch(MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  2404.                         {
  2405.                             case 1:    SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  2406.                                 break;
  2407.  
  2408.                             case 2:    if(SomeFile = Open(DummyBuffer,MODE_READWRITE))
  2409.                                 {
  2410.                                     if(Seek(SomeFile,0,OFFSET_END) == -1)
  2411.                                     {
  2412.                                         Close(SomeFile);
  2413.  
  2414.                                         SomeFile = NULL;
  2415.                                     }
  2416.                                 }
  2417.  
  2418.                                 break;
  2419.                         }
  2420.                     }
  2421.                     else
  2422.                         SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  2423.  
  2424.                     if(!SomeFile)
  2425.                         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  2426.                     else
  2427.                     {
  2428.                         LONG i,Len;
  2429.  
  2430.                             /* Obtain the semaphore required
  2431.                              * to gain access to the line buffer
  2432.                              */
  2433.  
  2434.                         ObtainSemaphore(BufferSemaphore);
  2435.  
  2436.                         for(i = 0 ; i < Lines ; i++)
  2437.                         {
  2438.                             Len = BufferLines[i][-1];
  2439.  
  2440.                             if(Len)
  2441.                             {
  2442.                                 if(FWrite(SomeFile,BufferLines[i],Len,1) != 1)
  2443.                                     break;
  2444.                             }
  2445.  
  2446.                             if(FPrintf(SomeFile,"\n") < 1)
  2447.                                 break;
  2448.                         }
  2449.  
  2450.                         ReleaseSemaphore(BufferSemaphore);
  2451.  
  2452.                         Close(SomeFile);
  2453.  
  2454.                         SetProtection(DummyBuffer,FIBF_EXECUTE);
  2455.  
  2456.                         BufferChanged = FALSE;
  2457.                     }
  2458.  
  2459.                     FreeAslRequest(FileRequest);
  2460.                 }
  2461.             }
  2462.  
  2463.             ReleaseWindows();
  2464.  
  2465.             break;
  2466.  
  2467.             /* Simply clear the screen and move the
  2468.              * cursor to its home position.
  2469.              */
  2470.  
  2471.         case MEN_CLEAR_SCREEN:
  2472.  
  2473.             if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  2474.                 XEmulatorClearConsole(XEM_IO);
  2475.             else
  2476.             {
  2477.                 DropMarker();
  2478.  
  2479.                 ClearCursor();
  2480.  
  2481.                 EraseScreen("2J");
  2482.                 SetAbsolutePosition("H");
  2483.  
  2484.                 DrawCursor();
  2485.             }
  2486.  
  2487.             break;
  2488.  
  2489.             /* Reset the current text rendering font. */
  2490.  
  2491.         case MEN_RESET_FONT:
  2492.  
  2493.             if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  2494.                 XEmulatorResetCharset(XEM_IO);
  2495.             else
  2496.             {
  2497.                 DropMarker();
  2498.  
  2499.                 CurrentFont = TextFont;
  2500.  
  2501.                 SetFont(RPort,CurrentFont);
  2502.  
  2503.                 ConOutputUpdate();
  2504.             }
  2505.  
  2506.             break;
  2507.  
  2508.             /* Reset the display styles and restore
  2509.              * the colours.
  2510.              */
  2511.  
  2512.         case MEN_RESET_STYLES:
  2513.  
  2514.             if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  2515.                 XEmulatorResetTextStyles(XEM_IO);
  2516.             else
  2517.             {
  2518.                 DropMarker();
  2519.  
  2520.                 ClearCursor();
  2521.  
  2522.                 SetAttributes("0m");
  2523.  
  2524.                 Config -> EmulationConfig -> FontScale = SCALE_NORMAL;
  2525.  
  2526.                 FgPen = GetPenIndex(SafeTextPen);
  2527.                 BgPen = 0;
  2528.  
  2529.                 if(ReadAPen(RPort) != MappedPens[0][FgPen])
  2530.                     SetAPen(RPort,MappedPens[0][FgPen]);
  2531.  
  2532.                 if(ReadBPen(RPort) != MappedPens[0][BgPen])
  2533.                     SetBPen(RPort,MappedPens[0][BgPen]);
  2534.  
  2535.                 SetWrMsk(RPort,DepthMask);
  2536.  
  2537.                 ConFontScaleUpdate();
  2538.  
  2539.                 DrawCursor();
  2540.             }
  2541.  
  2542.             break;
  2543.  
  2544.             /* Reset the whole terminal. */
  2545.  
  2546.         case MEN_RESET_TERMINAL:
  2547.  
  2548.             if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  2549.                 XEmulatorResetConsole(XEM_IO);
  2550.             else
  2551.             {
  2552.                 FreeMarker();
  2553.  
  2554.                 DoCancel();
  2555.  
  2556.                 ClearCursor();
  2557.  
  2558.                 Reset();
  2559.  
  2560.                 DrawCursor();
  2561.             }
  2562.  
  2563.             break;
  2564.  
  2565.         case MEN_SET_EMULATION:
  2566.  
  2567.             BlockWindows();
  2568.  
  2569.             if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  2570.             {
  2571.                 OptionTitle = LocaleString(MSG_TERMMAIN_EMULATION_PREFERENCES_TXT);
  2572.  
  2573.                 XEmulatorOptions(XEM_IO);
  2574.  
  2575.                 if(NewOptions)
  2576.                 {
  2577.                     SetEmulatorOptions(XEM_PREFS_SAVE);
  2578.  
  2579.                     NewOptions = FALSE;
  2580.                 }
  2581.  
  2582.                 OptionTitle = NULL;
  2583.             }
  2584.             else
  2585.                 EmulationPanel(Config,NULL);
  2586.  
  2587.             ReleaseWindows();
  2588.  
  2589.             break;
  2590.  
  2591.             /* Set the serial preferences. */
  2592.  
  2593.         case MEN_SERIAL:
  2594.  
  2595.             BlockWindows();
  2596.  
  2597.             if(SerialPanel(Config,NULL))
  2598.             {
  2599.                 ConfigSetup();
  2600.  
  2601.                 ConfigChanged = TRUE;
  2602.             }
  2603.  
  2604.             ReleaseWindows();
  2605.  
  2606.             break;
  2607.  
  2608.             /* Set the modem preferences. */
  2609.  
  2610.         case MEN_MODEM:
  2611.  
  2612.             BlockWindows();
  2613.  
  2614.             if(ModemPanel(Config,NULL))
  2615.             {
  2616.                 FlowInit(TRUE);
  2617.  
  2618.                 ConfigChanged = TRUE;
  2619.             }
  2620.  
  2621.             ReleaseWindows();
  2622.  
  2623.             break;
  2624.  
  2625.             /* Set the screen preferences. */
  2626.  
  2627.         case MEN_SCREEN:
  2628.  
  2629.             BlockWindows();
  2630.  
  2631.             if(ScreenPanel(Config,NULL))
  2632.             {
  2633.                 if(memcmp(PrivateConfig -> ScreenConfig -> Colours,Config -> ScreenConfig -> Colours,sizeof(UWORD) * 16))
  2634.                 {
  2635.                     switch(Config -> ScreenConfig -> ColourMode)
  2636.                     {
  2637.                         case COLOUR_EIGHT:
  2638.  
  2639.                             CopyMem(Config -> ScreenConfig -> Colours,ANSIColours,16 * sizeof(UWORD));
  2640.                             break;
  2641.  
  2642.                         case COLOUR_SIXTEEN:
  2643.  
  2644.                             CopyMem(Config -> ScreenConfig -> Colours,EGAColours,16 * sizeof(UWORD));
  2645.                             break;
  2646.  
  2647.                         case COLOUR_AMIGA:
  2648.  
  2649.                             CopyMem(Config -> ScreenConfig -> Colours,DefaultColours,16 * sizeof(UWORD));
  2650.                             break;
  2651.  
  2652.                         case COLOUR_MONO:
  2653.  
  2654.                             CopyMem(Config -> ScreenConfig -> Colours,AtomicColours,16 * sizeof(UWORD));
  2655.                             break;
  2656.                     }
  2657.                 }
  2658.  
  2659.                 ConfigSetup();
  2660.  
  2661.                 ConfigChanged = TRUE;
  2662.             }
  2663.             else
  2664.             {
  2665.                 if(memcmp(PrivateConfig -> ScreenConfig -> Colours,Config -> ScreenConfig -> Colours,sizeof(UWORD) * 16))
  2666.                 {
  2667.                     switch(Config -> ScreenConfig -> ColourMode)
  2668.                     {
  2669.                         case COLOUR_EIGHT:
  2670.  
  2671.                             CopyMem(Config -> ScreenConfig -> Colours,ANSIColours,16 * sizeof(UWORD));
  2672.                             break;
  2673.  
  2674.                         case COLOUR_SIXTEEN:
  2675.  
  2676.                             CopyMem(Config -> ScreenConfig -> Colours,EGAColours,16 * sizeof(UWORD));
  2677.                             break;
  2678.  
  2679.                         case COLOUR_AMIGA:
  2680.  
  2681.                             CopyMem(Config -> ScreenConfig -> Colours,DefaultColours,16 * sizeof(UWORD));
  2682.                             break;
  2683.  
  2684.                         case COLOUR_MONO:
  2685.  
  2686.                             CopyMem(Config -> ScreenConfig -> Colours,AtomicColours,16 * sizeof(UWORD));
  2687.                             break;
  2688.                     }
  2689.  
  2690.                     ConfigChanged = TRUE;
  2691.                 }
  2692.             }
  2693.  
  2694.             ReleaseWindows();
  2695.  
  2696.             break;
  2697.  
  2698.             /* Set the terminal preferences. */
  2699.  
  2700.         case MEN_TERMINAL:
  2701.  
  2702.             BlockWindows();
  2703.  
  2704.             if(TerminalPanel(Config,NULL))
  2705.             {
  2706.                 ConfigSetup();
  2707.  
  2708.                 ConfigChanged = TRUE;
  2709.             }
  2710.  
  2711.             ReleaseWindows();
  2712.  
  2713.             break;
  2714.  
  2715.             /* Set the clipboard preferences. */
  2716.  
  2717.         case MEN_CLIPBOARD:
  2718.  
  2719.             BlockWindows();
  2720.  
  2721.             if(ClipPanel(Config,NULL))
  2722.             {
  2723.                 ConfigSetup();
  2724.  
  2725.                 ConfigChanged = TRUE;
  2726.             }
  2727.  
  2728.             ReleaseWindows();
  2729.  
  2730.             break;
  2731.  
  2732.             /* Set the capture preferences. */
  2733.  
  2734.         case MEN_CAPTURE:
  2735.  
  2736.             BlockWindows();
  2737.  
  2738.             if(CapturePanel(Config,NULL))
  2739.             {
  2740.                 ConfigSetup();
  2741.  
  2742.                 ConfigChanged = TRUE;
  2743.             }
  2744.  
  2745.             ReleaseWindows();
  2746.  
  2747.             break;
  2748.  
  2749.             /* Set the command preferences. */
  2750.  
  2751.         case MEN_COMMANDS:
  2752.  
  2753.             BlockWindows();
  2754.  
  2755.             if(CommandPanel(Config,NULL))
  2756.                 ConfigChanged = TRUE;
  2757.  
  2758.             ReleaseWindows();
  2759.  
  2760.             break;
  2761.  
  2762.             /* Set the miscellaneous preferences. */
  2763.  
  2764.         case MEN_MISC:
  2765.  
  2766.             BlockWindows();
  2767.  
  2768.             if(MiscPanel(Config,NULL))
  2769.             {
  2770.                 ConfigSetup();
  2771.  
  2772.                 ConfigChanged = TRUE;
  2773.             }
  2774.  
  2775.             ReleaseWindows();
  2776.  
  2777.             break;
  2778.  
  2779.             /* Set the path settings. */
  2780.  
  2781.         case MEN_PATH:
  2782.  
  2783.             BlockWindows();
  2784.  
  2785.             if(PathPanel(Config,NULL))
  2786.                 ConfigChanged = TRUE;
  2787.  
  2788.             ReleaseWindows();
  2789.  
  2790.             break;
  2791.  
  2792.             /* Set the file transfer options. */
  2793.  
  2794.         case MEN_TRANSFER:
  2795.  
  2796.             BlockWindows();
  2797.  
  2798.             XprIO -> xpr_filename = NULL;
  2799.  
  2800.                 /* Set up the library options. */
  2801.  
  2802.             if(XProtocolBase)
  2803.             {
  2804.                 TransferBits = XProtocolSetup(XprIO);
  2805.  
  2806.                     /* Successful? */
  2807.  
  2808.                 if(!(TransferBits & XPRS_SUCCESS))
  2809.                 {
  2810.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_SET_UP_PROTOCOL_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LastXprLibrary);
  2811.  
  2812.                     CloseLibrary(XProtocolBase);
  2813.  
  2814.                     XProtocolBase = NULL;
  2815.  
  2816.                     LastXprLibrary[0] = 0;
  2817.  
  2818.                     TransferBits = 0;
  2819.                 }
  2820.                 else
  2821.                     SaveProtocolOpts();
  2822.             }
  2823.  
  2824.             ReleaseWindows();
  2825.  
  2826.             break;
  2827.  
  2828.             /* Select the transfer protocol; I had hoped
  2829.              * to get rid of this option but xprascii and
  2830.              * the older pre-2.0 standard xpr-libraries
  2831.              * forced it back in.
  2832.              */
  2833.  
  2834.         case MEN_TRANSFER_PROTOCOL:
  2835.  
  2836.             BlockWindows();
  2837.  
  2838.             if(SelectProtocol(LastXprLibrary,Window))
  2839.             {
  2840.                 if(ProtocolSetup())
  2841.                     strcpy(Config -> FileConfig -> ProtocolFileName,LastXprLibrary);
  2842.                 else
  2843.                 {
  2844.                     strcpy(LastXprLibrary,Config -> FileConfig -> ProtocolFileName);
  2845.  
  2846.                     ProtocolSetup();
  2847.                 }
  2848.  
  2849.                 if(!XProtocolBase)
  2850.                     SetTransferMenu(FALSE);
  2851.                 else
  2852.                     SetTransferMenu(TRUE);
  2853.             }
  2854.  
  2855.             ReleaseWindows();
  2856.  
  2857.             break;
  2858.  
  2859.             /* Set the translation tables. */
  2860.  
  2861.         case MEN_TRANSLATION:
  2862.  
  2863.             BlockWindows();
  2864.  
  2865.             TranslationChanged |= TranslationPanel();
  2866.  
  2867.                 /* Choose the right console write routine. */
  2868.  
  2869.             ConOutputUpdate();
  2870.  
  2871.             ReleaseWindows();
  2872.  
  2873.             break;
  2874.  
  2875.             /* Set the keyboard macros. */
  2876.  
  2877.         case MEN_MACROS:
  2878.  
  2879.             BlockWindows();
  2880.  
  2881.             if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  2882.             {
  2883.                 XEmulatorMacroKeyFilter(XEM_IO,NULL);
  2884.  
  2885.                 MacroPanel(MacroKeys);
  2886.  
  2887.                 SetupXEM_MacroKeys(MacroKeys);
  2888.             }
  2889.             else
  2890.                 MacroPanel(MacroKeys);
  2891.  
  2892.             ReleaseWindows();
  2893.  
  2894.             break;
  2895.  
  2896.             /* Set the cursor keys. */
  2897.  
  2898.         case MEN_CURSORKEYS:
  2899.  
  2900.             BlockWindows();
  2901.  
  2902.             CursorPanel(CursorKeys);
  2903.  
  2904.             ReleaseWindows();
  2905.  
  2906.             break;
  2907.  
  2908.             /* Set the fast macros. */
  2909.  
  2910.         case MEN_FAST_MACROS:
  2911.  
  2912.             BlockWindows();
  2913.  
  2914.             FastMacroPanel();
  2915.  
  2916.             ReleaseWindows();
  2917.  
  2918.             break;
  2919.  
  2920.             /* Set the hotkey preferences. */
  2921.  
  2922.         case MEN_HOTKEYS:
  2923.  
  2924.             BlockWindows();
  2925.  
  2926.             if(HotkeyPanel(&Hotkeys))
  2927.             {
  2928.                 if(!SetupCx())
  2929.                     MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_SET_UP_HOTKEYS_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  2930.             }
  2931.  
  2932.             ReleaseWindows();
  2933.  
  2934.             break;
  2935.  
  2936.             /* Set the speech preferences. */
  2937.  
  2938.         case MEN_SPEECH:
  2939.  
  2940.             BlockWindows();
  2941.  
  2942.             SpeechPanel();
  2943.  
  2944.             ReleaseWindows();
  2945.  
  2946.             break;
  2947.  
  2948.             /* Open the preferences settings. */
  2949.  
  2950.         case MEN_OPEN_SETTINGS:
  2951.  
  2952.             BlockWindows();
  2953.  
  2954.             strcpy(DummyBuffer,LastConfig);
  2955.  
  2956.             DummyChar = PathPart(DummyBuffer);
  2957.  
  2958.             *DummyChar = 0;
  2959.  
  2960.             if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_OPEN_PREFERENCES_TXT),DummyBuffer,FilePart(LastConfig),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,NULL))
  2961.             {
  2962.                 if(ReadConfig(DummyBuffer,PrivateConfig))
  2963.                 {
  2964.                     SwapConfig(PrivateConfig,Config);
  2965.  
  2966.                     strcpy(DummyBuffer,LastConfig);
  2967.  
  2968.                     ConfigSetup();
  2969.  
  2970.                     ConfigChanged = FALSE;
  2971.                 }
  2972.                 else
  2973.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  2974.  
  2975.                 FreeAslRequest(FileRequest);
  2976.             }
  2977.  
  2978.             ReleaseWindows();
  2979.  
  2980.             break;
  2981.  
  2982.             /* Save the terminal preferences. */
  2983.  
  2984.         case MEN_SAVE_SETTINGS:
  2985.  
  2986.             if(LastConfig[0])
  2987.             {
  2988.                 BlockWindows();
  2989.  
  2990.                 if(!WriteConfig(LastConfig,Config))
  2991.                     MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_ERROR_WRITING_PREFERENCES_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LastConfig);
  2992.                 else
  2993.                     ConfigChanged = FALSE;
  2994.  
  2995.                 ReleaseWindows();
  2996.  
  2997.                 break;
  2998.             }
  2999.  
  3000.             /* Save the terminal preferences to a
  3001.              * given file name.
  3002.              */
  3003.  
  3004.         case MEN_SAVE_SETTINGS_AS:
  3005.  
  3006.             BlockWindows();
  3007.  
  3008.             strcpy(DummyBuffer,LastConfig);
  3009.  
  3010.             DummyChar = PathPart(DummyBuffer);
  3011.  
  3012.             *DummyChar = 0;
  3013.  
  3014.             if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_SAVE_PREFERENCES_AS_TXT),DummyBuffer,FilePart(LastConfig),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,NULL))
  3015.             {
  3016.                 if(WriteConfig(DummyBuffer,Config))
  3017.                 {
  3018.                     strcpy(LastConfig,DummyBuffer);
  3019.  
  3020.                     ConfigChanged = FALSE;
  3021.                 }
  3022.                 else
  3023.                     MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_ERROR_WRITING_PREFERENCES_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  3024.  
  3025.                 FreeAslRequest(FileRequest);
  3026.             }
  3027.  
  3028.             ReleaseWindows();
  3029.  
  3030.             break;
  3031.  
  3032.             /* Show terminal information window. */
  3033.  
  3034.         case MEN_STATUS_WINDOW:
  3035.  
  3036.             if(InfoWindow)
  3037.                 CloseInfoWindow();
  3038.             else
  3039.                 OpenInfoWindow();
  3040.  
  3041.             break;
  3042.  
  3043.         case MEN_REVIEW_WINDOW:
  3044.  
  3045.             if(ReviewWindow)
  3046.                 DeleteReview();
  3047.             else
  3048.                 CreateReview();
  3049.  
  3050.             break;
  3051.  
  3052.             /* Open the packet window if necessary, else
  3053.              * just activate it.
  3054.              */
  3055.  
  3056.         case MEN_PACKET_WINDOW:
  3057.  
  3058.             if(!PacketWindow)
  3059.                 CreatePacketWindow();
  3060.             else
  3061.             {
  3062.                 ActivateWindow(PacketWindow);
  3063.  
  3064.                 CheckItem(MEN_PACKET_WINDOW,TRUE);
  3065.             }
  3066.  
  3067.             break;
  3068.  
  3069.             /* Toggle the presence of the fast! macro panel. */
  3070.  
  3071.         case MEN_FAST_MACROS_WINDOW:
  3072.  
  3073.             if(FastWindow)
  3074.                 CloseFastWindow();
  3075.             else
  3076.                 OpenFastWindow();
  3077.  
  3078.             break;
  3079.     }
  3080. }
  3081.  
  3082.     /* HandleMenu(ULONG Code,ULONG Qualifier):
  3083.      *
  3084.      *    Skip along the number of selected menu items and
  3085.      *    handle the associated functions.
  3086.      */
  3087.  
  3088. VOID
  3089. HandleMenu(ULONG Code,ULONG Qualifier)
  3090. {
  3091.     struct MenuItem *MenuItem;
  3092.  
  3093.     DisplayReopened = FALSE;
  3094.  
  3095.         /* Check until the last menuitem has been
  3096.          * processed.
  3097.          */
  3098.  
  3099.     while(Code != MENUNULL)
  3100.     {
  3101.             /* Pick up the associated menu item. */
  3102.  
  3103.         if(MenuItem = ItemAddress(Menu,Code))
  3104.         {
  3105.             HandleMenuCode((ULONG)GTMENUITEM_USERDATA(MenuItem),Qualifier);
  3106.  
  3107.             if(DisplayReopened)
  3108.             {
  3109.                 DisplayReopened = FALSE;
  3110.  
  3111.                 break;
  3112.             }
  3113.  
  3114.             Code = MenuItem -> NextSelect;
  3115.         }
  3116.         else
  3117.             break;
  3118.     }
  3119. }
  3120.  
  3121.     /* HandleWorkbenchWindow():
  3122.      *
  3123.      *    Handle input coming from the Workbench window.
  3124.      */
  3125.  
  3126. VOID
  3127. HandleWorkbenchWindow()
  3128. {
  3129.     struct FileInfoBlock    *FileInfo;
  3130.     struct AppMessage    *AppMessage;
  3131.  
  3132.     if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  3133.     {
  3134.         struct FileTransferInfo *Info;
  3135.  
  3136.         if(Info = AllocFileTransferInfo())
  3137.         {
  3138.             LONG FilesFound = 0,i;
  3139.             BYTE Success = TRUE;
  3140.  
  3141.             while(AppMessage = (struct AppMessage *)GetMsg(WorkbenchPort))
  3142.             {
  3143.                 if(Success && AppMessage -> am_Type == MTYPE_APPWINDOW)
  3144.                 {
  3145.                     for(i = 0 ; Success && i < AppMessage -> am_NumArgs ; i++)
  3146.                     {
  3147.                         if(AppMessage -> am_ArgList[i] . wa_Lock && AppMessage -> am_ArgList[i] . wa_Name)
  3148.                         {
  3149.                             BPTR OldLock;
  3150.  
  3151.                             if(OldLock = CurrentDir(AppMessage -> am_ArgList[i] . wa_Lock))
  3152.                             {
  3153.                                 BPTR FileLock;
  3154.  
  3155.                                 if(FileLock = Lock(AppMessage -> am_ArgList[i] . wa_Name,ACCESS_READ))
  3156.                                 {
  3157.                                     if(Examine(FileLock,FileInfo))
  3158.                                     {
  3159.                                         if(FileInfo -> fib_DirEntryType < 0)
  3160.                                         {
  3161.                                             if(NameFromLock(FileLock,SharedBuffer,512))
  3162.                                             {
  3163.                                                 if(!AddFileTransferNode(Info,SharedBuffer,FileInfo -> fib_Size))
  3164.                                                     Success = FALSE;
  3165.                                                 else
  3166.                                                 {
  3167.                                                     FilesFound++;
  3168.  
  3169.                                                     if(Config -> MiscConfig -> TransferIcons)
  3170.                                                     {
  3171.                                                         BPTR InfoLock;
  3172.  
  3173.                                                         strcat(SharedBuffer,".info");
  3174.  
  3175.                                                         if(InfoLock = Lock(SharedBuffer,ACCESS_READ))
  3176.                                                         {
  3177.                                                             if(Examine(InfoLock,FileInfo))
  3178.                                                             {
  3179.                                                                 if(FileInfo -> fib_DirEntryType < 0)
  3180.                                                                 {
  3181.                                                                     if(!AddFileTransferNode(Info,SharedBuffer,FileInfo -> fib_Size))
  3182.                                                                         Success = FALSE;
  3183.                                                                     else
  3184.                                                                         FilesFound++;
  3185.                                                                 }
  3186.                                                             }
  3187.  
  3188.                                                             UnLock(InfoLock);
  3189.                                                         }
  3190.                                                     }
  3191.                                                 }
  3192.                                             }
  3193.                                         }
  3194.                                     }
  3195.  
  3196.                                     UnLock(FileLock);
  3197.                                 }
  3198.  
  3199.                                 CurrentDir(OldLock);
  3200.                             }
  3201.                         }
  3202.                     }
  3203.                 }
  3204.  
  3205.                 ReplyMsg((struct Message *)AppMessage);
  3206.             }
  3207.  
  3208.             if(FilesFound)
  3209.             {
  3210.                 SortFileTransferInfo(Info);
  3211.  
  3212.                 BlockWindows();
  3213.  
  3214.                 switch(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_TRANSFER_FILES_AS_TXT),LocaleString(MSG_TERMMAIN_BINARY_UPLOAD_CANCEL_TXT)))
  3215.                 {
  3216.                     case 1:    BinaryTransfer        = FALSE;
  3217.                         FileTransferInfo    = Info;
  3218.  
  3219.                         StartXprSendFromList(TRANSFER_TEXT,TRUE);
  3220.  
  3221.                         break;
  3222.  
  3223.                     case 2:    BinaryTransfer        = TRUE;
  3224.                         FileTransferInfo    = Info;
  3225.  
  3226.                         StartXprSendFromList(TRANSFER_BINARY,TRUE);
  3227.  
  3228.                         break;
  3229.  
  3230.                     case 0:    FreeFileTransferInfo(Info);
  3231.                         break;
  3232.                 }
  3233.  
  3234.                 ReleaseWindows();
  3235.             }
  3236.         }
  3237.  
  3238.         FreeDosObject(DOS_FIB,FileInfo);
  3239.     }
  3240.  
  3241.     while(AppMessage = (struct AppMessage *)GetMsg(WorkbenchPort))
  3242.         ReplyMsg((struct Message *)AppMessage);
  3243. }
  3244.  
  3245.     /* HandleIconify():
  3246.      *
  3247.      *    Handle program iconification.
  3248.      */
  3249.  
  3250. VOID
  3251. HandleIconify()
  3252. {
  3253.     BYTE Released = FALSE;
  3254.  
  3255.         /* Set the wait mouse pointer... */
  3256.  
  3257.     BlockWindows();
  3258.  
  3259.         /* Open workbench.library. */
  3260.  
  3261.     if(WorkbenchBase)
  3262.     {
  3263.             /* Open icon.library. */
  3264.  
  3265.         if(IconBase = OpenLibrary("icon.library",0))
  3266.         {
  3267.             struct DiskObject *Icon;
  3268.  
  3269.             if(!(Icon = GetProgramIcon()))
  3270.                 Icon = GetDefDiskObject(WBTOOL);
  3271.  
  3272.                 /* Did we get an icon? */
  3273.  
  3274.             if(Icon)
  3275.             {
  3276.                 struct MsgPort *IconPort;
  3277.  
  3278.                     /* Reset the icon type. */
  3279.  
  3280.                 Icon -> do_Type        = NULL;
  3281.  
  3282.                     /* Default icon position. */
  3283.  
  3284.                 Icon -> do_CurrentX    = NO_ICON_POSITION;
  3285.                 Icon -> do_CurrentY    = NO_ICON_POSITION;
  3286.  
  3287.                     /* Create the Workbench reply port. */
  3288.  
  3289.                 if(IconPort = CreateMsgPort())
  3290.                 {
  3291.                     struct AppIcon *AppIcon;
  3292.  
  3293.                         /* Add the application icon. */
  3294.  
  3295.                     if(AppIcon = AddAppIcon(0,0,TermIDString,IconPort,NULL,Icon,TAG_DONE))
  3296.                     {
  3297.                         struct AppMessage    *AppMessage;
  3298.                         UBYTE            *String,*Error;
  3299.  
  3300.                             /* Reset the guardian. */
  3301.  
  3302.                         IconTerminated = FALSE;
  3303.  
  3304.                             /* Release the window. */
  3305.  
  3306.                         Released = TRUE;
  3307.  
  3308.                         ReleaseWindows();
  3309.  
  3310.                             /* Close the display. full stop. */
  3311.  
  3312.                         if(DeleteDisplay())
  3313.                         {
  3314.                                 /* Reset and release the serial driver. */
  3315.  
  3316.                             if(Config -> MiscConfig -> ReleaseDevice)
  3317.                             {
  3318.                                 ClearSerial();
  3319.  
  3320.                                 DeleteSerial();
  3321.                             }
  3322.  
  3323.                                 /* Wait for double-click. */
  3324.  
  3325. IconLoop:                        while(!IconTerminated)
  3326.                             {
  3327.                                 ULONG SignalSet = Wait(PORTMASK(IconPort) | SIG_REXX);
  3328.  
  3329.                                 if(SignalSet & PORTMASK(IconPort))
  3330.                                 {
  3331.                                         /* Pick up application messages. */
  3332.  
  3333.                                     while(AppMessage = (struct AppMessage *)GetMsg(IconPort))
  3334.                                     {
  3335.                                             /* Received a double-click? */
  3336.  
  3337.                                         IconTerminated = TRUE;
  3338.  
  3339.                                         ReplyMsg(AppMessage);
  3340.                                     }
  3341.                                 }
  3342.  
  3343.                                     /* Wake up if ARexx command received. */
  3344.  
  3345.                                 if(SignalSet & SIG_REXX)
  3346.                                     while(HandleRexx());
  3347.                             }
  3348.  
  3349.                                 /* Open the serial driver. */
  3350.  
  3351.                             if(Config -> MiscConfig -> ReleaseDevice)
  3352.                             {
  3353.                                 if(Error = CreateSerial())
  3354.                                 {
  3355.                                     DeleteSerial();
  3356.  
  3357.                                     switch(MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_TERMMAIN_ICONIFY_IGNORE_QUIT_TXT),Error))
  3358.                                     {
  3359.                                         case 1:    goto IconLoop;
  3360.                                         case 0:    MainTerminated = TRUE;
  3361.                                     }
  3362.                                 }
  3363.                                 else
  3364.                                 {
  3365.                                     if(SerialMessage)
  3366.                                     {
  3367.                                         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  3368.  
  3369.                                         SerialMessage = NULL;
  3370.                                     }
  3371.                                 }
  3372.                             }
  3373.  
  3374.                                 /* Create the display. */
  3375.  
  3376.                             if(!MainTerminated)
  3377.                             {
  3378.                                 if(String = CreateDisplay(FALSE))
  3379.                                 {
  3380.                                     if(MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_TERMMAIN_ICONIFY_QUIT_TXT),String))
  3381.                                     {
  3382.                                         ClearSerial();
  3383.  
  3384.                                         DeleteSerial();
  3385.  
  3386.                                         IconTerminated = FALSE;
  3387.  
  3388.                                         goto IconLoop;
  3389.                                     }
  3390.                                     else
  3391.                                         MainTerminated = FALSE;
  3392.                                 }
  3393.                                 else
  3394.                                 {
  3395.                                     BumpWindow(Window);
  3396.  
  3397.                                     PubScreenStuff();
  3398.                                 }
  3399.                             }
  3400.                         }
  3401.                         else
  3402.                         {
  3403.                             BlockWindows();
  3404.  
  3405.                             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  3406.  
  3407.                             ReleaseWindows();
  3408.                         }
  3409.  
  3410.                             /* Remove the application icon. */
  3411.  
  3412.                         RemoveAppIcon(AppIcon);
  3413.  
  3414.                             /* Reply pending messages. */
  3415.  
  3416.                         while(AppMessage = (struct AppMessage *)GetMsg(IconPort))
  3417.                             ReplyMsg(AppMessage);
  3418.                     }
  3419.                     else
  3420.                         MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_ADD_APPLICATION_ICON_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  3421.  
  3422.                     DeleteMsgPort(IconPort);
  3423.                 }
  3424.                 else
  3425.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  3426.  
  3427.                 FreeDiskObject(Icon);
  3428.             }
  3429.             else
  3430.                 MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_TOOL_ICON_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  3431.  
  3432.             CloseLibrary(IconBase);
  3433.  
  3434.             IconBase = NULL;
  3435.         }
  3436.         else
  3437.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_ICON_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  3438.     }
  3439.     else
  3440.         MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_WORKBENCH_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  3441.  
  3442.     if(!Released)
  3443.         ReleaseWindows();
  3444.  
  3445.         /* Finished! */
  3446.  
  3447.     DoIconify = FALSE;
  3448. }
  3449.  
  3450.     /* HandleOnlineCleanup():
  3451.      *
  3452.      *    Perform offline cleanup tasks.
  3453.      */
  3454.  
  3455. VOID
  3456. HandleOnlineCleanup()
  3457. {
  3458.     StopCall(FALSE);
  3459.  
  3460.     SetDialMenu(TRUE);
  3461.  
  3462.         /* Execute logoff macro. */
  3463.  
  3464.     if(Config -> CommandConfig -> LogoffMacro[0])
  3465.         SerialCommand(Config -> CommandConfig -> LogoffMacro);
  3466.  
  3467.         /* Clear the password. */
  3468.  
  3469.     Password[0]        = 0;
  3470.     UserName[0]        = 0;
  3471.  
  3472.     CurrentBBSName[0]    = 0;
  3473.     CurrentBBSComment[0]    = 0;
  3474.     CurrentBBSNumber[0]    = 0;
  3475.  
  3476.     WasOnline = FALSE;
  3477.  
  3478.     ChosenEntry = NULL;
  3479.  
  3480.         /* Previous configuration available? */
  3481.  
  3482.     if(BackupConfig)
  3483.     {
  3484.             /* Remember old configuration. */
  3485.  
  3486.         SaveConfig(Config,PrivateConfig);
  3487.  
  3488.             /* Copy configuration. */
  3489.  
  3490.         SaveConfig(BackupConfig,Config);
  3491.  
  3492.             /* Set up new configuration. */
  3493.  
  3494.         ConfigSetup();
  3495.  
  3496.             /* Free old configuration. */
  3497.  
  3498.         DeleteConfiguration(BackupConfig);
  3499.  
  3500.         BackupConfig = NULL;
  3501.     }
  3502.  
  3503.     if(Config -> ModemConfig -> RedialAfterHangup)
  3504.     {
  3505.         if(DialList)
  3506.         {
  3507.             if(DialList -> lh_Head -> ln_Succ)
  3508.                 DoDial = DIAL_REDIAL;
  3509.         }
  3510.     }
  3511. }
  3512.  
  3513.     /* HandleFlowChange():
  3514.      *
  3515.      *    Handle data flow scanner information.
  3516.      */
  3517.  
  3518. VOID
  3519. HandleFlowChange()
  3520. {
  3521.     if(!Online && (FlowInfo . Voice || FlowInfo . Ring || FlowInfo . Connect))
  3522.     {
  3523.         WakeUp(Window);
  3524.  
  3525.         if(FlowInfo . Voice)
  3526.         {
  3527.             ConWrites(LocaleString(MSG_TERMMAIN_INCOMING_VOIC_CALL_TXT));
  3528.  
  3529.             Say(LocaleString(MSG_TERMMAIN_SAY_INCOMING_VOICE_CALL_TXT));
  3530.         }
  3531.  
  3532.         if(FlowInfo . Ring)
  3533.         {
  3534.             ConWrites(LocaleString(MSG_TERMMAIN_INCOMING_CALL_TXT));
  3535.  
  3536.             Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  3537.         }
  3538.  
  3539.         if(FlowInfo . Connect)
  3540.         {
  3541.             Online        = TRUE;
  3542.             BaudPending    = FALSE;
  3543.  
  3544.             SetDialMenu(FALSE);
  3545.         }
  3546.     }
  3547.  
  3548.         /* Check if we are to prompt the user for
  3549.          * ZModem upload type.
  3550.          */
  3551.  
  3552.     if(UsesZModem && FlowInfo . ZModemUpload && XProtocolBase)
  3553.     {
  3554.         if(Config -> MiscConfig -> AutoUpload)
  3555.         {
  3556.             BlockWindows();
  3557.  
  3558.             switch(UploadPanel())
  3559.             {
  3560.                 case UPLOAD_TEXT:
  3561.  
  3562.                     BinaryTransfer = FALSE;
  3563.  
  3564.                     if(!StartXprSend(TRANSFER_TEXT,TRUE))
  3565.                         SerWrite(ZModemCancel,20);
  3566.  
  3567.                     break;
  3568.  
  3569.                 case UPLOAD_BINARY:
  3570.  
  3571.                     BinaryTransfer = TRUE;
  3572.  
  3573.                     if(!StartXprSend(TRANSFER_BINARY,TRUE))
  3574.                         SerWrite(ZModemCancel,20);
  3575.  
  3576.                     break;
  3577.  
  3578.                 case UPLOAD_ABORT:
  3579.  
  3580.                     SerWrite(ZModemCancel,20);
  3581.                     break;
  3582.             }
  3583.  
  3584.             ReleaseWindows();
  3585.         }
  3586.     }
  3587.  
  3588.     FlowInit(TRUE);
  3589. }
  3590.  
  3591.     /* HandleSerialReset():
  3592.      *
  3593.      *    Handle serial device reset.
  3594.      */
  3595.  
  3596. VOID
  3597. HandleSerialReset()
  3598. {
  3599.     ClearSerial();
  3600.  
  3601.     DeleteSerial();
  3602.  
  3603.     BlockWindows();
  3604.  
  3605.     ReopenSerial();
  3606.  
  3607.     ReleaseWindows();
  3608. }
  3609.  
  3610.     /* HandleSerialRelease():
  3611.      *
  3612.      *    Release the serial device driver, then reopen it again.
  3613.      */
  3614.  
  3615. VOID
  3616. HandleSerialRelease()
  3617. {
  3618.     APTR    OldPtr = ThisProcess -> pr_WindowPtr;
  3619.     BYTE    Continue,SerialClosed;
  3620.  
  3621.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  3622.  
  3623.         /* This might happen if an ARexx user
  3624.          * released the serial device and
  3625.          * failed to reopen it.
  3626.          */
  3627.  
  3628.     if(ReadPort)
  3629.         SerialClosed = FALSE;
  3630.     else
  3631.         SerialClosed = TRUE;
  3632.  
  3633.     BlockWindows();
  3634.  
  3635.         /* Prevent catastrophes! */
  3636.  
  3637.     if(Online && !SerialClosed)
  3638.     {
  3639.         if(!MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_YOU_ARE_STILL_ONLINE_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT)))
  3640.             Continue = FALSE;
  3641.         else
  3642.             Continue = TRUE;
  3643.     }
  3644.     else
  3645.         Continue = TRUE;
  3646.  
  3647.     if(Continue)
  3648.     {
  3649.         if(SerialClosed)
  3650.             ReopenSerial();
  3651.         else
  3652.         {
  3653.             ClearSerial();
  3654.  
  3655.             DeleteSerial();
  3656.  
  3657.             if(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_UNIT_RESET_AND_RELEASED_TXT),LocaleString(MSG_TERMMAIN_RETURN_QUIT_TXT),Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber))
  3658.                 ReopenSerial();
  3659.             else
  3660.                 MainTerminated = TRUE;
  3661.         }
  3662.     }
  3663.  
  3664.     ReleaseSerial = FALSE;
  3665.  
  3666.     ThisProcess -> pr_WindowPtr = OldPtr;
  3667.  
  3668.     ReleaseWindows();
  3669. }
  3670.  
  3671.     /* HandleExternalEmulation():
  3672.      *
  3673.      *    Handle external emulation event.
  3674.      */
  3675.  
  3676. VOID
  3677. HandleExternalEmulation()
  3678. {
  3679.     if(!XEmulatorSignal(XEM_IO,XEM_Signal))
  3680.     {
  3681.         CloseEmulator();
  3682.  
  3683.         ResetDisplay = TRUE;
  3684.     }
  3685. }
  3686.  
  3687.     /* HandleClipboard():
  3688.      *
  3689.      *    Handle clipboard input processing.
  3690.      */
  3691.  
  3692. VOID
  3693. HandleClipboard()
  3694. {
  3695.     if(!ClipInput)
  3696.     {
  3697.         if(!OpenClip(Config -> ClipConfig -> ClipboardUnit))
  3698.             ClipInput = ClipXerox = TRUE;
  3699.         else
  3700.             ClipInput = ClipXerox = FALSE;
  3701.     }
  3702. }
  3703.  
  3704.     /* HandleSerialCheck():
  3705.      *
  3706.      *    Query the state of the serial line.
  3707.      */
  3708.  
  3709. VOID
  3710. HandleSerialCheck()
  3711. {
  3712.         /* Query serial status. */
  3713.  
  3714.     WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  3715.  
  3716.     DoIO(WriteRequest);
  3717.  
  3718.         /* Is the carrier detect signal
  3719.          * still present?
  3720.          */
  3721.  
  3722.     if(WriteRequest -> io_Status & CIAF_COMCD)
  3723.     {
  3724.         WasOnline    = TRUE;
  3725.         Online        = FALSE;
  3726.     }
  3727. }
  3728.