home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / term232.lha / Source_Code / termSource / termInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-22  |  48.9 KB  |  2,327 lines

  1. /*
  2. **    $Id: termInit.c,v 1.16 92/08/18 16:12:31 olsen Sta Locker: olsen $
  3. **    $Revision: 1.16 $
  4. **    $Date: 92/08/18 16:12:31 $
  5. **
  6. **    Program initialization and shutdown routines
  7. **
  8. **    Copyright ⌐ 1990-1992 by Olaf `Olsen' Barthel & MXM
  9. **        All Rights Reserved
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14. #include "OwnDevUnit.h"
  15.  
  16.     /* Screen title. */
  17.  
  18. STATIC UBYTE ScreenTitle[80];
  19.  
  20.     /* A couple of private strings which are to `impersonate' the
  21.      * control sequences associated with the four function keys.
  22.      */
  23.  
  24. STATIC UBYTE *FunctionKeyCodes[4] =
  25. {
  26.     "\\eOP",
  27.     "\\eOQ",
  28.     "\\eOR",
  29.     "\\eOS"
  30. };
  31.  
  32.     /* This variable helps us to remember whether the fast!
  33.      * macro panel was open or not.
  34.      */
  35.  
  36. STATIC BYTE HadFastMacros = FALSE;
  37.  
  38.     /* ProcessCleanup(register __d1 BPTR SegList):
  39.      *
  40.      *    Frees all resource the main process has allocated when
  41.      *    it exits.
  42.      */
  43.  
  44. STATIC VOID __saveds __asm
  45. ProcessCleanup(register __d1 BPTR SegList)
  46. {
  47.     CloseAll();
  48.  
  49.     Forbid();
  50.  
  51.     UnLoadSeg(SegList);
  52.  
  53.     CloseLibrary(DOSBase);
  54. }
  55.  
  56.     /* SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function):
  57.      *
  58.      *    Create a new process from the current one.
  59.      */
  60.  
  61. struct Process *
  62. SegmentSplit(STRPTR Name,BYTE Pri,LONG StackSize,APTR Function)
  63. {
  64.     struct Process            *Child;
  65.     struct CommandLineInterface    *CLI;
  66.  
  67.     CLI = (struct CommandLineInterface *)BADDR(((struct Process *)SysBase -> ThisTask) -> pr_CLI);
  68.  
  69.     if(Child = CreateNewProcTags(
  70.         NP_CommandName,    "term",
  71.         NP_Name,    Name,
  72.         NP_Priority,    Pri,
  73.         NP_StackSize,    StackSize,
  74.         NP_Entry,    Function,
  75.         NP_Cli,        TRUE,
  76.         NP_ExitCode,    ProcessCleanup,
  77.         NP_ExitData,    CLI -> cli_Module,
  78.     TAG_DONE))
  79.     {
  80.         CLI -> cli_Module = NULL;
  81.  
  82.         return(Child);
  83.     }
  84.     else
  85.         return(NULL);
  86. }
  87.  
  88.     /* LoadKeyMap(STRPTR Name):
  89.      *
  90.      *    Load a keymap file from disk.
  91.      */
  92.  
  93. struct KeyMap *
  94. LoadKeyMap(STRPTR Name)
  95. {
  96.     struct KeyMapResource    *KeyMapResource;
  97.     struct KeyMap        *Map = NULL;
  98.  
  99.         /* Try to get access to the list of currently loaded
  100.          * keymap files.
  101.          */
  102.  
  103.     if(KeyMapResource = (struct KeyMapResource *)OpenResource("keymap.resource"))
  104.     {
  105.         struct KeyMapNode *Node;
  106.  
  107.             /* Try to find the keymap in the list. */
  108.  
  109.         Forbid();
  110.  
  111.         if(Node = (struct KeyMapNode *)FindName(&KeyMapResource -> kr_List,FilePart(Config . KeyMapName)))
  112.             Map = &Node -> kn_KeyMap;
  113.  
  114.         Permit();
  115.     }
  116.  
  117.         /* Still no keymap available? */
  118.  
  119.     if(!Map)
  120.     {
  121.         APTR OldPtr = ThisProcess -> pr_WindowPtr;
  122.  
  123.             /* Disable DOS requesters. */
  124.  
  125.         ThisProcess -> pr_WindowPtr = (APTR)-1;
  126.  
  127.             /* Unload the old keymap code. */
  128.  
  129.         if(KeySegment)
  130.             UnLoadSeg(KeySegment);
  131.  
  132.             /* Try to load the keymap from the
  133.              * name the user entered.
  134.              */
  135.  
  136.         if(!(KeySegment = LoadSeg(Config . KeyMapName)))
  137.         {
  138.                 /* Second try: load it from
  139.                   * the standard keymaps drawer.
  140.                   */
  141.  
  142.             strcpy(SharedBuffer,"KEYMAPS:");
  143.  
  144.             if(AddPart(SharedBuffer,FilePart(Config . KeyMapName),256))
  145.             {
  146.                 if(!(KeySegment = LoadSeg(SharedBuffer)))
  147.                 {
  148.                     strcpy(SharedBuffer,"Devs:Keymaps");
  149.  
  150.                     if(AddPart(SharedBuffer,FilePart(Config . KeyMapName),256))
  151.                         KeySegment = LoadSeg(SharedBuffer);
  152.                 }
  153.             }
  154.         }
  155.  
  156.             /* Did we get the keymap file? */
  157.  
  158.         if(KeySegment)
  159.         {
  160.             struct KeyMapNode *Node = (struct KeyMapNode *)&((ULONG *)BADDR(KeySegment))[1];
  161.  
  162.             Map = &Node -> kn_KeyMap;
  163.         }
  164.  
  165.             /* Enable DOS requesters again. */
  166.  
  167.         ThisProcess -> pr_WindowPtr = OldPtr;
  168.     }
  169.     else
  170.     {
  171.         if(KeySegment)
  172.         {
  173.             UnLoadSeg(KeySegment);
  174.  
  175.             KeySegment = NULL;
  176.         }
  177.     }
  178.  
  179.     return(Map);
  180. }
  181.  
  182.     /* ConfigSetup():
  183.      *
  184.      *    Compare the current configuration with the
  185.      *    last backup and reset the serial device, terminal,
  186.      *    etc. if necessary.
  187.      */
  188.  
  189. VOID
  190. ConfigSetup()
  191. {
  192.     BYTE NewEmulation = FALSE;
  193.  
  194.     if(Config . OpenFastMacroPanel)
  195.         HadFastMacros = TRUE;
  196.  
  197.     if(!Config . BufferEnabled)
  198.         BufferFrozen = TRUE;
  199.  
  200.     if(Menu)
  201.     {
  202.         struct MenuItem *SomeItem;
  203.  
  204.         if(SomeItem = FindThisItem(MEN_FREEZE_BUFFER))
  205.         {
  206.             if(BufferFrozen)
  207.                 SomeItem -> Flags |= CHECKED;
  208.             else
  209.                 SomeItem -> Flags &= ~CHECKED;
  210.         }
  211.     }
  212.  
  213.     if(PrivateConfig . SerBuffSize != Config . SerBuffSize)
  214.     {
  215.         if(StripBuffer)
  216.             FreeVec(StripBuffer);
  217.  
  218.         if(!(StripBuffer = (UBYTE *)AllocVec(Config . SerBuffSize,MEMF_ANY)))
  219.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  220.     }
  221.  
  222.     if(Stricmp(PrivateConfig . FastMacroFile,Config . FastMacroFile))
  223.         LoadFastMacros(Config . FastMacroFile);
  224.  
  225.         /* No custom keymap this time? */
  226.  
  227.     if(!Config . KeyMapName[0])
  228.     {
  229.         KeyMap = NULL;
  230.  
  231.         if(KeySegment)
  232.         {
  233.             UnLoadSeg(KeySegment);
  234.  
  235.             KeySegment = NULL;
  236.         }
  237.     }
  238.     else
  239.     {
  240.             /* Check whether the keymap name has changed. */
  241.  
  242.         if(strcmp(PrivateConfig . KeyMapName,Config . KeyMapName))
  243.             KeyMap = LoadKeyMap(Config . KeyMapName);
  244.     }
  245.  
  246.     if(Stricmp(PrivateConfig . MacroFile,Config . MacroFile))
  247.     {
  248.         if(!LoadMacros(Config . MacroFile,MacroKeys))
  249.         {
  250.             WORD i,j;
  251.  
  252.             for(j = 0 ; j < 4 ; j++)
  253.             {
  254.                 for(i = 0 ; i < 10 ; i++)
  255.                     MacroKeys -> Keys[j][i][0] = 0;
  256.             }
  257.  
  258.             for(i = 0 ; i < 4 ; i++)
  259.                 strcpy(MacroKeys -> Keys[1][i],FunctionKeyCodes[i]);
  260.         }
  261.         else
  262.             strcpy(LastMacros,Config . MacroFile);
  263.     }
  264.  
  265.     if(PrivateConfig . FontHeight != Config . FontHeight)
  266.         ResetDisplay = TRUE;
  267.  
  268.     if(Stricmp(PrivateConfig . FontName,Config . FontName))
  269.         ResetDisplay = TRUE;
  270.  
  271.     if(PrivateConfig . Font != Config . Font)
  272.         ResetDisplay = TRUE;
  273.  
  274.     if(PrivateConfig . TextFontHeight != Config . TextFontHeight)
  275.         ResetDisplay = TRUE;
  276.  
  277.     if(Stricmp(PrivateConfig . TextFontName,Config . TextFontName))
  278.         ResetDisplay = TRUE;
  279.  
  280.     if(PrivateConfig . DisplayMode != Config . DisplayMode || PrivateConfig . ColourMode != Config . ColourMode)
  281.         ResetDisplay = TRUE;
  282.  
  283.     if(PrivateConfig . ColourMode == COLOUR_EIGHT && Config . ColourMode == COLOUR_EIGHT)
  284.     {
  285.         if((PrivateConfig . DisableBlinking & ~TERMINAL_FASTER) != (Config . DisableBlinking & ~TERMINAL_FASTER))
  286.             ResetDisplay = TRUE;
  287.     }
  288.  
  289.     if((PrivateConfig . DisableBlinking & TERMINAL_FASTER) != (Config . DisableBlinking & TERMINAL_FASTER))
  290.         ResetDisplay = TRUE;
  291.  
  292.     if(PrivateConfig . StatusLine != Config . StatusLine)
  293.         ResetDisplay = TRUE;
  294.  
  295.     if(PrivateConfig . TitleBar != Config . TitleBar)
  296.         ResetDisplay = TRUE;
  297.  
  298.     if(strcmp(PrivateConfig . Protocol,Config . Protocol))
  299.     {
  300.         strcpy(LastXprLibrary,Config . Protocol);
  301.  
  302.         ProtocolSetup();
  303.     }
  304.  
  305.         /* Serial configuration needs updating? */
  306.  
  307.     if(!SerialSet && (memcmp(&PrivateConfig,&Config,offsetof(struct Configuration,ModemInit)) || PrivateConfig . SerBuffSize != Config . SerBuffSize))
  308.     {
  309.         BYTE SameDevice = TRUE;
  310.  
  311.             /* Any device name change? */
  312.  
  313.         if(strcmp(PrivateConfig . SerialDevice,Config . SerialDevice))
  314.             SameDevice = FALSE;
  315.         else
  316.         {
  317.             if(PrivateConfig . SerBuffSize != Config . SerBuffSize)
  318.                 SameDevice = FALSE;
  319.  
  320.                 /* Handshaking mode changed to RTS/CTS protocol? */
  321.  
  322.             if(PrivateConfig . HandshakingProtocol == HANDSHAKING_NONE && PrivateConfig . HandshakingProtocol != HANDSHAKING_NONE)
  323.                 SameDevice = FALSE;
  324.         }
  325.  
  326.         if(ReadRequest)
  327.         {
  328.                 /* Stop any IO activity. */
  329.  
  330.             ClearSerial();
  331.         }
  332.         else
  333.             SameDevice = FALSE;
  334.  
  335.             /* No dramatic changes? Simply change the parameters. */
  336.  
  337.         if(SameDevice)
  338.         {
  339.             LONG Error;
  340.  
  341.                 /* Use new parameters... */
  342.  
  343.             SetFlags(WriteRequest);
  344.             SetFlags(ReadRequest);
  345.  
  346.                 /* ...and set them. */
  347.  
  348.             WriteRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
  349.  
  350.             if(Error = DoIO(WriteRequest))
  351.             {
  352.                 STRPTR    String;
  353.                 BYTE    Reset;
  354.  
  355.                 if(!(String = GetSerialError(Error,&Reset)))
  356.                     String = LocaleString(MSG_SERIAL_ERROR_DEVBUSY_TXT);
  357.  
  358.                 SPrintf(SharedBuffer,String,Config . SerialDevice,Config . UnitNumber);
  359.  
  360.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SharedBuffer);
  361.  
  362.                 if(Reset)
  363.                 {
  364.                     WriteRequest -> IOSer . io_Command = CMD_RESET;
  365.  
  366.                     DoIO(WriteRequest);
  367.  
  368.                     GetFlags(&Config,WriteRequest);
  369.                     SetFlags(ReadRequest);
  370.                 }
  371.             }
  372.  
  373.                 /* Restart read request. */
  374.  
  375.             ReadRequest -> IOSer . io_Command    = CMD_READ;
  376.             ReadRequest -> IOSer . io_Data        = ReadBuffer;
  377.             ReadRequest -> IOSer . io_Length    = 1;
  378.  
  379.             SetSignal(0,SIG_SERIAL);
  380.  
  381.             SendIO(ReadRequest);
  382.         }
  383.         else
  384.         {
  385.             UBYTE *Error;
  386.  
  387.             DeleteSerial();
  388.  
  389.             if(Error = CreateSerial())
  390.             {
  391.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  392.  
  393.                 DeleteSerial();
  394.             }
  395.             else
  396.             {
  397.                 if(SerialMessage)
  398.                 {
  399.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  400.  
  401.                     SerialMessage = NULL;
  402.                 }
  403.             }
  404.         }
  405.     }
  406.  
  407.     if(Config . EightyColumns)
  408.     {
  409.         ClearCursor();
  410.  
  411.         if(Config . FontScale == SCALE_HALF)
  412.             LastColumn = 131;
  413.         else
  414.             LastColumn = 79;
  415.  
  416.         if(Config . EightyColumns == 1)
  417.             LastLine = 23;
  418.         else
  419.             LastLine = 24;
  420.  
  421.         LastPixel = 80 * 8 - 1;
  422.  
  423.         BackupRender();
  424.  
  425.         SetAPen(RPort,0);
  426.  
  427.         SetWrMsk(RPort,0xFF);
  428.  
  429.         ScrollLineRectFill(RPort,0,(LastLine + 1) * TextFontHeight,Window -> Width - 1,Window -> Height - 1);
  430.         ScrollLineRectFill(RPort,80 * TextFontWidth,0,Window -> Width - 1,Window -> Height - 1);
  431.  
  432.         BackupRender();
  433.  
  434.         SetCursor();
  435.     }
  436.     else
  437.     {
  438.         LastLine    = Window -> Height / TextFontHeight - 1;
  439.         LastColumn    = Window -> Width / TextFontWidth - 1;
  440.         LastPixel    = (LastColumn + 1) * TextFontWidth - 1;
  441.  
  442.         if(!RegionSet)
  443.             Bottom = LastLine;
  444.     }
  445.  
  446.     if(LastLine > Window -> Height / TextFontHeight - 1)
  447.         LastLine = Window -> Height / TextFontHeight - 1;
  448.  
  449.     if(CursorY > LastLine)
  450.     {
  451.         ClearCursor();
  452.  
  453.         CursorY = LastLine;
  454.     }
  455.  
  456.     if(PrivateConfig . FontScale == SCALE_HALF && Config . FontScale != SCALE_HALF)
  457.     {
  458.         CursorX /= 2;
  459.  
  460.         if(Config . EightyColumns)
  461.         {
  462.             LastColumn    = 79;
  463.             LastPixel    = 80 * 8 - 1;
  464.         }
  465.         else
  466.         {
  467.             LastColumn    = Window -> Width / TextFontWidth - 1;
  468.             LastPixel    = (LastColumn + 1) * TextFontWidth - 1;
  469.         }
  470.     }
  471.  
  472.     if(PrivateConfig . ColourMode == Config . ColourMode && memcmp(&PrivateConfig . Colours[0],&Config . Colours[0],sizeof(UWORD) * 16))
  473.     {
  474.         switch(Config . ColourMode)
  475.         {
  476.             case COLOUR_EIGHT:    CopyMem(&Config . Colours[0],&ANSIColours[0],16 * sizeof(UWORD));
  477.                         break;
  478.  
  479.             case COLOUR_SIXTEEN:    CopyMem(&Config . Colours[0],&EGAColours[0],16 * sizeof(UWORD));
  480.                         break;
  481.  
  482.             case COLOUR_AMIGA:    CopyMem(&Config . Colours[0],&DefaultColours[0],16 * sizeof(UWORD));
  483.                         break;
  484.  
  485.             case COLOUR_MONO:    CopyMem(&Config . Colours[0],&AtomicColours[0],16 * sizeof(UWORD));
  486.                         break;
  487.         }
  488.     }
  489.  
  490.     if(Config . Emulation == EMULATION_EXTERNAL)
  491.     {
  492.         if(PrivateConfig . Emulation != EMULATION_EXTERNAL)
  493.             NewEmulation = TRUE;
  494.  
  495.         if(Stricmp(PrivateConfig . EmulationName,Config . EmulationName))
  496.             NewEmulation = TRUE;
  497.     }
  498.     else
  499.     {
  500.         if(XEmulatorBase && PrivateConfig . Emulation == EMULATION_EXTERNAL)
  501.         {
  502.             XEmulatorClearConsole(XEM_IO);
  503.  
  504.             CloseEmulator();
  505.  
  506.             Reset();
  507.         }
  508.  
  509.         OnMenu(Window,FULLMENUNUM(0,0,1));
  510.         OnMenu(Window,FULLMENUNUM(0,2,0));
  511.  
  512.         Config . RasterEnabled = TRUE;
  513.     }
  514.  
  515.     if(!ResetDisplay && NewEmulation && Config . EmulationName[0])
  516.     {
  517.         if(!OpenEmulator(Config . EmulationName))
  518.         {
  519.             Config . Emulation = EMULATION_ANSIVT100;
  520.  
  521.             ResetDisplay = TRUE;
  522.  
  523.             Config . RasterEnabled = TRUE;
  524.  
  525.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Config . EmulationName);
  526.         }
  527.         else
  528.         {
  529.             if(Config . RasterEnabled)
  530.             {
  531.                 Config . RasterEnabled = FALSE;
  532.  
  533.                 OffMenu(Window,FULLMENUNUM(0,0,1));
  534.                 OffMenu(Window,FULLMENUNUM(0,2,0));
  535.             }
  536.         }
  537.     }
  538.  
  539.     if(!ResetDisplay)
  540.     {
  541.         if(PrivateConfig . RasterEnabled != Config . RasterEnabled)
  542.         {
  543.             RasterEraseScreen(2);
  544.  
  545.             if(Config . RasterEnabled)
  546.             {
  547.                 OnMenu(Window,FULLMENUNUM(0,0,1));
  548.                 OnMenu(Window,FULLMENUNUM(0,2,0));
  549.             }
  550.             else
  551.             {
  552.                 OffMenu(Window,FULLMENUNUM(0,0,1));
  553.                 OffMenu(Window,FULLMENUNUM(0,2,0));
  554.             }
  555.         }
  556.  
  557.         if(Config . Emulation != EMULATION_EXTERNAL)
  558.             SetCursor();
  559.  
  560.         if(memcmp(&PrivateConfig . Colours[0],&Config . Colours[0],sizeof(UWORD) * 16))
  561.         {
  562.             WORD i;
  563.  
  564.             for(i = 0 ; i < 16 ; i++)
  565.                 BlinkColours[i] = Config . Colours[i];
  566.  
  567.             LoadRGB4(VPort,&Config . Colours[0],(1 << Screen -> RastPort . BitMap -> Depth));
  568.  
  569.             switch(Config . ColourMode)
  570.             {
  571.                 case COLOUR_EIGHT:    for(i = 0 ; i < 8 ; i++)
  572.                                 BlinkColours[i + 8] = BlinkColours[0];
  573.  
  574.                             break;
  575.  
  576.                 case COLOUR_SIXTEEN:    break;
  577.  
  578.                 case COLOUR_AMIGA:    BlinkColours[3] = BlinkColours[0];
  579.                             break;
  580.  
  581.                 default:        BlinkColours[3] = BlinkColours[0];
  582.                             break;
  583.             }
  584.         }
  585.         else
  586.         {
  587.             if(Config . DisableBlinking & ~TERMINAL_FASTER)
  588.                 LoadRGB4(VPort,&Config . Colours[0],16);
  589.         }
  590.  
  591.         if(!XProtocolBase)
  592.             OffMenu(Window,FULLMENUNUM(4,NOITEM,NOSUB));
  593.         else
  594.             OnMenu(Window,FULLMENUNUM(4,NOITEM,NOSUB));
  595.  
  596.         if(Config . OpenFastMacroPanel && !FastWindow)
  597.             OpenFastWindow();
  598.  
  599.         Blocking = FALSE;
  600.     }
  601.  
  602.     SetTaskPri(ThisProcess,(LONG)Config . Priority);
  603. }
  604.  
  605.     /* PubScreenStuff():
  606.      *
  607.      *    This part handles the public screen setup stuff.
  608.      */
  609.  
  610. VOID
  611. PubScreenStuff()
  612. {
  613.         /* Are we to make our screen public? */
  614.  
  615.     if(Config . MakeScreenPublic)
  616.         PubScreenStatus(Screen,NULL);
  617.     else
  618.         PubScreenStatus(Screen,PSNF_PRIVATE);
  619.  
  620.         /* Are we to `shanghai' Workbench windows? */
  621.  
  622.     if(Config . ShanghaiWindows)
  623.     {
  624.         PublicModes |= SHANGHAI;
  625.  
  626.         SetPubScreenModes(PublicModes);
  627.  
  628.             /* Make this the default public screen. */
  629.  
  630.         SetDefaultPubScreen(TermIDString);
  631.     }
  632.     else
  633.     {
  634.         PublicModes &= ~SHANGHAI;
  635.  
  636.         if(LockPubScreen(DefaultPubScreen))
  637.         {
  638.             SetDefaultPubScreen(DefaultPubScreen);
  639.  
  640.             UnlockPubScreen(DefaultPubScreen,NULL);
  641.         }
  642.         else
  643.             SetDefaultPubScreen(NULL);
  644.  
  645.         SetPubScreenModes(PublicModes);
  646.     }
  647. }
  648.  
  649.     /* DisplayReset():
  650.      *
  651.      *    Reset the entire display if necessary.
  652.      */
  653.  
  654. BYTE
  655. DisplayReset()
  656. {
  657.     UBYTE    *Result;
  658.     BYTE     Success = TRUE;
  659.  
  660.         /* Delete the display (if possible).
  661.          * This will go wrong if there
  662.          * are any visitor windows on our
  663.          * screen.
  664.          */
  665.  
  666.     if(DeleteDisplay())
  667.     {
  668.         if(Result = CreateDisplay(FALSE))
  669.         {
  670.             ThisProcess -> pr_WindowPtr = (APTR)Window;
  671.  
  672.             MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  673.  
  674.             Success = FALSE;
  675.         }
  676.         else
  677.         {
  678.             BumpWindow(Window);
  679.  
  680.             PubScreenStuff();
  681.  
  682.             DisplayReopened = TRUE;
  683.         }
  684.     }
  685.     else
  686.     {
  687.         CopyMem(&PrivateConfig,&Config,sizeof(struct Configuration));
  688.  
  689.         BlockWindows();
  690.  
  691.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  692.  
  693.         ReleaseWindows();
  694.  
  695.         Success = TRUE;
  696.     }
  697.  
  698.     ResetDisplay = FALSE;
  699.  
  700.     return(Success);
  701. }
  702.  
  703.     /* DeleteDisplay():
  704.      *
  705.      *    Free all resources associated with the terminal
  706.      *    display (tasks, interrupts, screen, window, etc.).
  707.      */
  708.  
  709. BYTE
  710. DeleteDisplay()
  711. {
  712.     if(Screen)
  713.     {
  714.         struct List        *PubScreenList;
  715.         struct PubScreenNode    *ScreenNode;
  716.  
  717.         PubScreenList = LockPubScreenList();
  718.  
  719.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  720.         {
  721.             if(ScreenNode -> psn_Screen == Screen)
  722.                 break;
  723.         }
  724.  
  725.         if(ScreenNode)
  726.         {
  727.             if(ScreenNode -> psn_VisitorCount)
  728.             {
  729.                 UnlockPubScreenList();
  730.  
  731.                 return(FALSE);
  732.             }
  733.             else
  734.             {
  735.                 Forbid();
  736.  
  737.                 UnlockPubScreenList();
  738.  
  739.                 PubScreenStatus(Screen,PSNF_PRIVATE);
  740.  
  741.                 Permit();
  742.             }
  743.         }
  744.         else
  745.             UnlockPubScreenList();
  746.     }
  747.  
  748.     CloseInfoWindow();
  749.  
  750.     DeleteReview();
  751.  
  752.     if(Config . Emulation == EMULATION_EXTERNAL && XEmulatorBase)
  753.         CloseEmulator();
  754.  
  755.     if(StatusProcess)
  756.     {
  757.         SetSignal(0,SIGBREAKF_CTRL_C);
  758.  
  759.         Signal(StatusProcess,SIGBREAKF_CTRL_C);
  760.  
  761.         Wait(SIGBREAKF_CTRL_C);
  762.     }
  763.  
  764.     DeleteRaster();
  765.  
  766.     DeleteScale();
  767.  
  768.     if(ScrollLines)
  769.     {
  770.         FreeVec(ScrollLines);
  771.  
  772.         ScrollLines = NULL;
  773.     }
  774.  
  775.     if(Screen)
  776.         ScreenToBack(Screen);
  777.  
  778.     if(FastWindow)
  779.     {
  780.         HadFastMacros = TRUE;
  781.  
  782.         CloseFastWindow();
  783.     }
  784.     else
  785.         HadFastMacros = FALSE;
  786.  
  787.     if(StatusWindow)
  788.     {
  789.         ClearMenuStrip(StatusWindow);
  790.         CloseWindowSafely(StatusWindow);
  791.  
  792.         StatusWindow = NULL;
  793.     }
  794.  
  795.     if(Window)
  796.     {
  797.         ClearMenuStrip(Window);
  798.  
  799.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  800.  
  801.         PopWindow();
  802.  
  803.         if(TermPort)
  804.             TermPort -> TopWindow = NULL;
  805.  
  806.         CloseWindow(Window);
  807.  
  808.         Window = NULL;
  809.     }
  810.  
  811.     if(Menu)
  812.     {
  813.         FreeMenus(Menu);
  814.  
  815.         Menu = NULL;
  816.     }
  817.  
  818.     if(VisualInfo)
  819.     {
  820.         FreeVisualInfo(VisualInfo);
  821.  
  822.         VisualInfo = NULL;
  823.     }
  824.  
  825.     DeletePacketWindow(FALSE);
  826.  
  827.     if(UserTextFont)
  828.     {
  829.         CloseFont(UserTextFont);
  830.  
  831.         UserTextFont = NULL;
  832.     }
  833.  
  834.         /* Before we can close screen we will have to
  835.          * make sure that it is no longer the default
  836.          * public screen.
  837.          */
  838.  
  839.     if(Config . ShanghaiWindows)
  840.     {
  841.         if(LockPubScreen(DefaultPubScreen))
  842.         {
  843.             SetDefaultPubScreen(DefaultPubScreen);
  844.  
  845.             UnlockPubScreen(DefaultPubScreen,NULL);
  846.         }
  847.         else
  848.             SetDefaultPubScreen(NULL);
  849.     }
  850.  
  851.     if(Screen)
  852.     {
  853.         CloseScreen(Screen);
  854.  
  855.         Screen = NULL;
  856.     }
  857.  
  858.     if(InterleavedBitMap)
  859.     {
  860.         DeleteInterleavedBitMap(InterleavedBitMap);
  861.  
  862.         InterleavedBitMap = NULL;
  863.     }
  864.  
  865.     if(GFX)
  866.     {
  867.         CloseFont(GFX);
  868.  
  869.         GFX = NULL;
  870.     }
  871.  
  872.     if(TextFont)
  873.     {
  874.         CloseFont(TextFont);
  875.  
  876.         TextFont = NULL;
  877.     }
  878.  
  879.     return(TRUE);
  880. }
  881.  
  882.     /* CreateDisplay(BYTE FirstSetup):
  883.      *
  884.      *    Open the display and allocate associated data.
  885.      */
  886.  
  887. UBYTE *
  888. CreateDisplay(BYTE FirstSetup)
  889. {
  890.     UWORD             Count = 0,i;
  891.     LONG             ErrorCode,Top,Height;
  892.     ULONG             TagArray[9];
  893.     struct MenuItem        *SomeItem;
  894.     struct Rectangle     OverscanSize;
  895.     BYTE             OpenFailed = FALSE,
  896.                  ScreenDepth;
  897.  
  898.     strcpy(UserFontName,Config . FontName);
  899.  
  900.     UserFont . ta_Name    = UserFontName;
  901.     UserFont . ta_YSize    = Config . FontHeight;
  902.     UserFont . ta_Style    = FS_NORMAL;
  903.     UserFont . ta_Flags    = FPF_DESIGNED;
  904.  
  905.     if(DiskfontBase)
  906.     {
  907.         if(!(UserTextFont = OpenDiskFont(&UserFont)))
  908.         {
  909.             strcpy(Config . FontName,    "topaz.font");
  910.             strcpy(UserFontName,        "topaz.font");
  911.  
  912.             Config . FontHeight = 8;
  913.  
  914.             UserFont . ta_YSize    = Config . FontHeight;
  915.             UserFont . ta_Style    = FS_NORMAL;
  916.             UserFont . ta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  917.  
  918.             if(!(UserTextFont = OpenFont(&UserFont)))
  919.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  920.         }
  921.     }
  922.     else
  923.     {
  924.         if(!(UserTextFont = OpenFont(&UserFont)))
  925.         {
  926.             strcpy(Config . FontName,    "topaz.font");
  927.             strcpy(UserFontName,        "topaz.font");
  928.  
  929.             Config . FontHeight = 8;
  930.  
  931.             UserFont . ta_YSize    = Config . FontHeight;
  932.             UserFont . ta_Style    = FS_NORMAL;
  933.             UserFont . ta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  934.  
  935.             if(!(UserTextFont = OpenFont(&UserFont)))
  936.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  937.         }
  938.     }
  939.  
  940. Reopen:    if(Config . Font == FONT_IBM)
  941.         strcpy(TextFontName,"IBM.font");
  942.     else
  943.         strcpy(TextFontName,Config . TextFontName);
  944.  
  945.     TextAttr . ta_Name    = TextFontName;
  946.     TextAttr . ta_YSize    = Config . TextFontHeight;
  947.     TextAttr . ta_Style    = FS_NORMAL;
  948.     TextAttr . ta_Flags    = 0;
  949.  
  950.     if(DiskfontBase)
  951.     {
  952.         if(!(TextFont = OpenDiskFont(&TextAttr)))
  953.         {
  954.             if(!Stricmp(TextFontName,"IBM.font") && Stricmp("IBM.font",Config . TextFontName))
  955.             {
  956.                 Config . Font = FONT_TOPAZ;
  957.  
  958.                 goto Reopen;
  959.             }
  960.  
  961.             strcpy(Config . TextFontName,    "topaz.font");
  962.             strcpy(TextFontName,        "topaz.font");
  963.  
  964.             Config . TextFontHeight = 8;
  965.  
  966.             TextAttr . ta_YSize    = Config . TextFontHeight;
  967.             TextAttr . ta_Style    = FS_NORMAL;
  968.             TextAttr . ta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  969.  
  970.             if(!(TextFont = OpenFont(&TextAttr)))
  971.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_TEXT_TXT));
  972.         }
  973.     }
  974.     else
  975.     {
  976.         if(!(TextFont = OpenFont(&TextAttr)))
  977.         {
  978.             if(!Stricmp(TextFontName,"IBM.font") && Stricmp("IBM.font",Config . TextFontName))
  979.             {
  980.                 Config . Font = FONT_TOPAZ;
  981.  
  982.                 goto Reopen;
  983.             }
  984.  
  985.             strcpy(Config . TextFontName,    "topaz.font");
  986.             strcpy(TextFontName,        "topaz.font");
  987.  
  988.             Config . TextFontHeight = 8;
  989.  
  990.             TextAttr . ta_YSize    = Config . TextFontHeight;
  991.             TextAttr . ta_Style    = FS_NORMAL;
  992.             TextAttr . ta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  993.  
  994.             if(!(TextFont = OpenFont(&TextAttr)))
  995.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_TEXT_TXT));
  996.         }
  997.     }
  998.  
  999.     TextFontHeight        = TextFont -> tf_YSize;
  1000.     TextFontWidth        = TextFont -> tf_XSize;
  1001.     TextFontBase        = TextFont -> tf_Baseline;
  1002.  
  1003.     CurrentFont = TextFont;
  1004.  
  1005.     GFXFont . ta_YSize = Config . FontHeight;
  1006.  
  1007.     if(DiskfontBase)
  1008.         GFX = (struct TextFont *)OpenDiskFont(&GFXFont);
  1009.     else
  1010.         GFX = (struct TextFont *)OpenFont(&GFXFont);
  1011.  
  1012.     UserFontHeight        = UserTextFont -> tf_YSize;
  1013.     UserFontWidth        = UserTextFont -> tf_XSize;
  1014.     UserFontBase        = UserTextFont -> tf_Baseline;
  1015.  
  1016.         /* We'll configure the screen parameters at
  1017.          * run time, at first we'll set up the screen
  1018.          * depth.
  1019.          */
  1020.  
  1021.     TagArray[Count++] = SA_Depth;
  1022.  
  1023.         /* Now set up the approriate colour mode. */
  1024.  
  1025.     switch(Config . ColourMode)
  1026.     {
  1027.         case COLOUR_EIGHT:    if(Config . DisableBlinking & ~TERMINAL_FASTER)
  1028.                         TagArray[Count++] = ScreenDepth = 3;
  1029.                     else
  1030.                         TagArray[Count++] = ScreenDepth = 4;
  1031.  
  1032.                     TagArray[Count++] = SA_DetailPen;
  1033.                     TagArray[Count++] = 0;
  1034.  
  1035.                     if(Config . DisableBlinking & TERMINAL_FASTER)
  1036.                     {
  1037.                         TagArray[Count++] = SA_BlockPen;
  1038.                         TagArray[Count++] = 7;
  1039.                     }
  1040.                     else
  1041.                     {
  1042.                         TagArray[Count++] = SA_Pens;
  1043.                         TagArray[Count++] = (LONG)&ANSIPens;
  1044.  
  1045.                         TagArray[Count++] = SA_BlockPen;
  1046.                         TagArray[Count++] = 4;
  1047.                     }
  1048.  
  1049.                     break;
  1050.  
  1051.         case COLOUR_SIXTEEN:    TagArray[Count++] = ScreenDepth = 4;
  1052.  
  1053.                     TagArray[Count++] = SA_DetailPen;
  1054.                     TagArray[Count++] = 0;
  1055.  
  1056.                     if(Config . DisableBlinking & TERMINAL_FASTER)
  1057.                     {
  1058.                         TagArray[Count++] = SA_BlockPen;
  1059.                         TagArray[Count++] = 15;
  1060.                     }
  1061.                     else
  1062.                     {
  1063.                         TagArray[Count++] = SA_Pens;
  1064.                         TagArray[Count++] = (LONG)&EGAPens;
  1065.  
  1066.                         TagArray[Count++] = SA_BlockPen;
  1067.                         TagArray[Count++] = 8;
  1068.                     }
  1069.  
  1070.                     break;
  1071.  
  1072.         case COLOUR_MONO:    TagArray[Count++] = ScreenDepth = 1;
  1073.  
  1074.                     break;
  1075.  
  1076.         case COLOUR_AMIGA:    TagArray[Count++] = ScreenDepth = 2;
  1077.  
  1078.                     if(!(Config . DisableBlinking & TERMINAL_FASTER))
  1079.                     {
  1080.                         TagArray[Count++] = SA_Pens;
  1081.                         TagArray[Count++] = (LONG)&StandardPens;
  1082.                     }
  1083.  
  1084.                     break;
  1085.     }
  1086.  
  1087.         /* Terminate the tag array. */
  1088.  
  1089.     TagArray[Count] = TAG_END;
  1090.  
  1091.         /* Inquire overscan limits and try to create an interleaved
  1092.          * bitmap if possible.
  1093.          */
  1094.  
  1095.     if((Config . DisableBlinking & TERMINAL_FASTER) && ScreenDepth > 1)
  1096.     {
  1097.         if(QueryOverscan(Config . DisplayMode,&OverscanSize,OSCAN_TEXT))
  1098.         {
  1099.             if(IntuitionBase -> LibNode . lib_Version < 39)
  1100.                 InterleavedBitMap = CreateInterleavedBitMap(OverscanSize . MaxX - OverscanSize . MinX + 1,OverscanSize . MaxY - OverscanSize . MinY + 1,ScreenDepth);
  1101.             else
  1102.                 InterleavedBitMap = NULL;
  1103.         }
  1104.     }
  1105.  
  1106.         /* Open the screen with the given requirements. */
  1107.  
  1108. #ifdef MC68030
  1109. OpenS:    SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_30_TXT),TermName,TermDate,TermIDString);
  1110. #else
  1111. OpenS:    SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_00_TXT),TermName,TermDate,TermIDString);
  1112. #endif    /* MC68030 */
  1113.  
  1114.     if(InterleavedBitMap)
  1115.     {
  1116.         Screen = (struct Screen *)OpenScreenTags(NULL,
  1117.             SA_Title,    ScreenTitle,
  1118.             SA_DClip,    &OverscanSize,
  1119.             SA_BitMap,    InterleavedBitMap,
  1120.             SA_DisplayID,    Config . DisplayMode,
  1121.             SA_Font,    &UserFont,
  1122.             SA_Behind,    TRUE,
  1123.             SA_AutoScroll,    TRUE,
  1124.             SA_ShowTitle,    Config . TitleBar,
  1125.             SA_PubName,    TermIDString,
  1126.             SA_ErrorCode,    &ErrorCode,
  1127.             TAG_MORE,    &TagArray[0],
  1128.         TAG_END);
  1129.     }
  1130.     else
  1131.     {
  1132.         BYTE Interleaved;
  1133.  
  1134.         if((Config . DisableBlinking & TERMINAL_FASTER) && IntuitionBase -> LibNode . lib_Version >= 39)
  1135.             Interleaved = TRUE;
  1136.         else
  1137.             Interleaved = FALSE;
  1138.  
  1139.         Screen = (struct Screen *)OpenScreenTags(NULL,
  1140.             SA_Title,    ScreenTitle,
  1141.             SA_Overscan,    OSCAN_TEXT,
  1142.             SA_DisplayID,    Config . DisplayMode,
  1143.             SA_Font,    &UserFont,
  1144.             SA_Behind,    TRUE,
  1145.             SA_AutoScroll,    TRUE,
  1146.             SA_ShowTitle,    Config . TitleBar,
  1147.             SA_PubName,    TermIDString,
  1148.             SA_ErrorCode,    &ErrorCode,
  1149.             SA_Interleaved,    Interleaved,
  1150.             TAG_MORE,    &TagArray[0],
  1151.         TAG_END);
  1152.     }
  1153.  
  1154.         /* We've got an error. */
  1155.  
  1156.     if(!Screen)
  1157.     {
  1158.         if(!OpenFailed)
  1159.         {
  1160.             switch(ErrorCode)
  1161.             {
  1162.                     /* Can't open screen with these display
  1163.                      * modes.
  1164.                      */
  1165.  
  1166.                 case OSERR_NOMONITOR:
  1167.                 case OSERR_NOCHIPS:
  1168.                 case OSERR_UNKNOWNMODE:        if(Config . DisplayMode & LACE)
  1169.                                     Config . DisplayMode = HIRESLACE_KEY;
  1170.                                 else
  1171.                                     Config . DisplayMode = HIRES_KEY;
  1172.  
  1173.                                 OpenFailed = TRUE;
  1174.  
  1175.                                 goto OpenS;
  1176.  
  1177.                 case OSERR_PUBNOTUNIQUE:    return(LocaleString(MSG_TERMINIT_SCREEN_ID_ALREADY_IN_USE_TXT));
  1178.             }
  1179.         }
  1180.  
  1181.             /* Some different error, probably out of
  1182.              * memory.
  1183.              */
  1184.  
  1185.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_SCREEN_TXT));
  1186.     }
  1187.  
  1188.     SZ_SizeSetup(Screen,&UserFont,TRUE);
  1189.  
  1190.         /* Set up scaling data (bitmaps & rastports). */
  1191.  
  1192.     if(!CreateScale())
  1193.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_FONT_SCALING_INFO_TXT));
  1194.  
  1195.         /* Obtain visual info (whatever that may be). */
  1196.  
  1197.     if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  1198.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  1199.  
  1200.     VPort = &Screen -> ViewPort;
  1201.  
  1202.         /* Fill the `default' colour with current values. */
  1203.  
  1204.     if(Initializing)
  1205.     {
  1206.         for(i = 0 ; i < 16 ; i++)
  1207.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  1208.  
  1209.         Initializing = FALSE;
  1210.     }
  1211.  
  1212.         /* Load the approriate colours. */
  1213.  
  1214.     if(LoadColours)
  1215.     {
  1216.         switch(Config . ColourMode)
  1217.         {
  1218.             case COLOUR_EIGHT:    CopyMem(&ANSIColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  1219.                         break;
  1220.  
  1221.             case COLOUR_SIXTEEN:    CopyMem(&EGAColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  1222.                         break;
  1223.  
  1224.             case COLOUR_AMIGA:    CopyMem(&DefaultColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  1225.                         break;
  1226.  
  1227.             case COLOUR_MONO:    CopyMem(&AtomicColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  1228.                         break;
  1229.         }
  1230.  
  1231.         LoadColours = FALSE;
  1232.     }
  1233.  
  1234.         /* Reset the current colours and the blinking equivalents. */
  1235.  
  1236.     for(i = 0 ; i < 16 ; i++)
  1237.         BlinkColours[i] = Config . Colours[i];
  1238.  
  1239.     LoadRGB4(VPort,&Config . Colours[0],(1 << Screen -> RastPort . BitMap -> Depth));
  1240.  
  1241.         /* Fiddle with the blinking colours. */
  1242.  
  1243.     switch(Config . ColourMode)
  1244.     {
  1245.         case COLOUR_EIGHT:    for(i = 0 ; i < 8 ; i++)
  1246.                         BlinkColours[i + 8] = BlinkColours[0];
  1247.  
  1248.                     break;
  1249.  
  1250.         case COLOUR_SIXTEEN:    break;
  1251.  
  1252.         case COLOUR_AMIGA:
  1253.         default:        BlinkColours[3] = BlinkColours[0];
  1254.                     break;
  1255.     }
  1256.  
  1257.     if(Config . TitleBar)
  1258.     {
  1259.         Top = Screen -> BarHeight + 2;
  1260.  
  1261.         if(Config . StatusLine)
  1262.         {
  1263.             if(Config . StatusLine == STATUSLINE_COMPRESSED)
  1264.                 Height = Screen -> Height - (Screen -> BarHeight + 2) - (UserFontHeight + 2);
  1265.             else
  1266.                 Height = Screen -> Height - (Screen -> BarHeight + 2) - (2 + SZ_BoxHeight(2));
  1267.         }
  1268.         else
  1269.             Height = Screen -> Height - (Screen -> BarHeight + 2);
  1270.     }
  1271.     else
  1272.     {
  1273.         Top = 0;
  1274.  
  1275.         if(Config . StatusLine)
  1276.         {
  1277.             if(Config . StatusLine == STATUSLINE_COMPRESSED)
  1278.                 Height = Screen -> Height - (UserFontHeight + 2);
  1279.             else
  1280.                 Height = Screen -> Height - (2 + SZ_BoxHeight(2));
  1281.         }
  1282.         else
  1283.             Height = Screen -> Height;
  1284.     }
  1285.  
  1286.         /* Open the main window. */
  1287.  
  1288.     if(!(Window = OpenWindowTags(NULL,
  1289.         WA_Top,        Top,
  1290.         WA_Left,    0,
  1291.         WA_Width,    Screen -> Width,
  1292.         WA_Height,    Height,
  1293.         WA_Backdrop,    TRUE,
  1294.         WA_Borderless,    TRUE,
  1295.         WA_SmartRefresh,TRUE,
  1296.         WA_CustomScreen,Screen,
  1297.         WA_NewLookMenus,TRUE,
  1298.         WA_RMBTrap,    TRUE,
  1299.         WA_IDCMP,    IDCMP_RAWKEY | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | LISTVIEWIDCMP,
  1300.     TAG_DONE)))
  1301.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  1302.  
  1303.         /* Push it on the window stack (should become bottommost
  1304.          * entry).
  1305.          */
  1306.  
  1307.     PushWindow(Window);
  1308.  
  1309.     if(TermPort)
  1310.         TermPort -> TopWindow = Window;
  1311.  
  1312.         /* Open the tiny status window. */
  1313.  
  1314.     if(Config . StatusLine)
  1315.     {
  1316.         if(!(StatusWindow = OpenWindowTags(NULL,
  1317.             WA_Top,        Window -> TopEdge + Window -> Height,
  1318.             WA_Left,    0,
  1319.             WA_Width,    Screen -> Width,
  1320.             WA_Height,    Screen -> Height - (Window -> TopEdge + Window -> Height),
  1321.             WA_Backdrop,    TRUE,
  1322.             WA_Borderless,    TRUE,
  1323.             WA_SmartRefresh,TRUE,
  1324.             WA_NewLookMenus,TRUE,
  1325.             WA_CustomScreen,Screen,
  1326.             WA_RMBTrap,    TRUE,
  1327.         TAG_DONE)))
  1328.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  1329.     }
  1330.     else
  1331.         StatusWindow = NULL;
  1332.  
  1333.         /* Default console setup. */
  1334.  
  1335.     if(Config . EightyColumns)
  1336.     {
  1337.         LastColumn = 79;
  1338.  
  1339.         if(Config . EightyColumns == 1)
  1340.             LastLine = 23;
  1341.         else
  1342.             LastLine = 24;
  1343.  
  1344.         LastPixel = 80 * 8 - 1;
  1345.     }
  1346.     else
  1347.     {
  1348.         LastLine    = Window -> Height / TextFontHeight - 1;
  1349.         LastColumn    = Window -> Width / TextFontWidth - 1;
  1350.         LastPixel    = (LastColumn + 1) * TextFontWidth - 1;
  1351.     }
  1352.  
  1353.     if(LastLine > Window -> Height / TextFontHeight - 1)
  1354.         LastLine = Window -> Height / TextFontHeight - 1;
  1355.  
  1356.     CursorX = 0;
  1357.     CursorY    = 0;
  1358.  
  1359.     SetDrMd(Window -> RPort,JAM2);
  1360.  
  1361.     if(StatusWindow)
  1362.     {
  1363.         StatusWindow -> UserPort = Window -> UserPort;
  1364.  
  1365.         ModifyIDCMP(StatusWindow,Window -> IDCMPFlags);
  1366.     }
  1367.  
  1368.     RPort = Window -> RPort;
  1369.  
  1370.         /* Redirect AmigaDOS requesters. */
  1371.  
  1372.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  1373.  
  1374.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  1375.  
  1376.         /* Create the character raster. */
  1377.  
  1378.     if(!CreateRaster())
  1379.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_SCREEN_RASTER_TXT));
  1380.  
  1381.         /* Set up the scrolling info. */
  1382.  
  1383.     ScrollLineCount = Window -> Height / TextFontHeight;
  1384.  
  1385.     if(!(ScrollLines = (struct ScrollLine *)AllocVec(sizeof(struct ScrollLineInfo) * ScrollLineCount,MEMF_ANY|MEMF_CLEAR)))
  1386.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SCROLLING_SUPPORT_INFO_TXT));
  1387.  
  1388.         /* Reset terminal emulation. */
  1389.  
  1390.     if(Config . Emulation != EMULATION_EXTERNAL) 
  1391.         Reset();
  1392.     else
  1393.     {
  1394.         if(XEmulatorBase)
  1395.             XEmulatorResetConsole(XEM_IO);
  1396.     }
  1397.  
  1398.         /* Set the font. */
  1399.  
  1400.     SetFont(RPort,CurrentFont);
  1401.  
  1402.         /* Create the menu strip. */
  1403.  
  1404.     if(!(Menu = CreateMenus(TermMenu,TAG_DONE)))
  1405.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  1406.  
  1407.         /* Do the menu layout. */
  1408.  
  1409.     if(!LayoutMenus(Menu,VisualInfo,
  1410.         GTMN_NewLookMenus,    TRUE,
  1411.         GTMN_TextAttr,        &UserFont,
  1412.     TAG_DONE))
  1413.         return(LocaleString(MSG_TERMINIT_FAILED_TO_LAYOUT_MENUS_TXT));
  1414.  
  1415.         /* Disable the `Execute ARexx Command' menu item if
  1416.          * the rexx server is not available.
  1417.          */
  1418.  
  1419.     if(!RexxSysBase)
  1420.     {
  1421.         struct MenuItem *SomeItem;
  1422.  
  1423.         if(SomeItem = FindThisItem(MEN_EXECUTE_REXX_COMMAND))
  1424.             SomeItem -> Flags &= ~ITEMENABLED;
  1425.     }
  1426.  
  1427.         /* Add a tick if file capture is active. */
  1428.  
  1429.     if(FileCapture)
  1430.     {
  1431.         if(SomeItem = FindThisItem(MEN_CAPTURE_TO_FILE))
  1432.             SomeItem -> Flags |= CHECKED;
  1433.     }
  1434.  
  1435.         /* Add a tick if printer capture is active. */
  1436.  
  1437.     if(PrinterCapture)
  1438.     {
  1439.         if(SomeItem = FindThisItem(MEN_CAPTURE_TO_PRINTER))
  1440.             SomeItem -> Flags |= CHECKED;
  1441.     }
  1442.  
  1443.         /* Add a tick if the buffer is frozen. */
  1444.  
  1445.     if(BufferFrozen)
  1446.     {
  1447.         if(SomeItem = FindThisItem(MEN_FREEZE_BUFFER))
  1448.             SomeItem -> Flags |= CHECKED;
  1449.     }
  1450.  
  1451.         /* Disable the dialing functions if online. */
  1452.  
  1453.     if(Online)
  1454.         SetDialMenu(FALSE);
  1455.  
  1456.         /* Add the menu to the windows. */
  1457.  
  1458.     SetMenuStrip(Window,Menu);
  1459.  
  1460.     if(!XProtocolBase)
  1461.         SetTransferMenu(FALSE);
  1462.  
  1463.         /* Disable the `Print Screen' and `Save ASCII' functions
  1464.          * if raster is not enabled.
  1465.          */
  1466.  
  1467.     if(!Config . RasterEnabled)
  1468.     {
  1469.         OffMenu(Window,FULLMENUNUM(0,0,1));
  1470.         OffMenu(Window,FULLMENUNUM(0,2,0));
  1471.     }
  1472.  
  1473.         /* Enable the menu. */
  1474.  
  1475.     Window -> Flags &= ~WFLG_RMBTRAP;
  1476.  
  1477.     if(StatusWindow)
  1478.     {
  1479.         SetMenuStrip(StatusWindow,Menu);
  1480.  
  1481.         StatusWindow -> Flags &= ~WFLG_RMBTRAP;
  1482.  
  1483.         SetDrMd(StatusWindow -> RPort,JAM2);
  1484.     }
  1485.  
  1486.     strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
  1487.  
  1488.         /* Create the status server. */
  1489.  
  1490.     StatusProcess = CreateNewProcTags(
  1491.         NP_Entry,    StatusServer,
  1492.         NP_Name,    "term status process",
  1493.         NP_WindowPtr,    -1,
  1494.         NP_Priority,    5,
  1495.     TAG_DONE);
  1496.  
  1497.         /* Wait for ringback signal. */
  1498.  
  1499.     Wait(SIGBREAKF_CTRL_C);
  1500.  
  1501.         /* Status server has `died'. */
  1502.  
  1503.     if(!StatusProcess)
  1504.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_STATUS_TASK_TXT));
  1505.  
  1506.         /* Obtain the default public screen name just in case
  1507.          * we'll need it later.
  1508.          */
  1509.  
  1510.     GetDefaultPubScreen(DefaultPubScreen);
  1511.  
  1512.     if(Config . Emulation == EMULATION_EXTERNAL && Config . EmulationName[0])
  1513.     {
  1514.         if(!OpenEmulator(Config . EmulationName))
  1515.         {
  1516.             Config . Emulation = EMULATION_ANSIVT100;
  1517.  
  1518.             ResetDisplay = TRUE;
  1519.  
  1520.             Config . RasterEnabled = TRUE;
  1521.  
  1522.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),Config . EmulationName);
  1523.         }
  1524.         else
  1525.         {
  1526.             if(Config . RasterEnabled)
  1527.             {
  1528.                 Config . RasterEnabled = FALSE;
  1529.  
  1530.                 OffMenu(Window,FULLMENUNUM(0,0,1));
  1531.                 OffMenu(Window,FULLMENUNUM(0,2,0));
  1532.             }
  1533.         }
  1534.     }
  1535.  
  1536.         /* Restart the fast! macro panel. */
  1537.  
  1538.     if(HadFastMacros || Config . OpenFastMacroPanel)
  1539.         OpenFastWindow();
  1540.  
  1541.     return(NULL);
  1542. }
  1543.  
  1544.     /* CloseAll():
  1545.      *
  1546.      *    Free all resources and leave the program.
  1547.      */
  1548.  
  1549. VOID
  1550. CloseAll()
  1551. {
  1552.     SZ_SizeCleanup();
  1553.  
  1554.     FreeDialList();
  1555.  
  1556.     if(SpecialTable)
  1557.         FreeVec(SpecialTable);
  1558.  
  1559.     if(AbortTable)
  1560.         FreeVec(AbortTable);
  1561.  
  1562.     if(StripBuffer)
  1563.         FreeVec(StripBuffer);
  1564.  
  1565.     if(BackupConfig)
  1566.         FreeVec(BackupConfig);
  1567.  
  1568.     if(IntuitionBase && Window)
  1569.         BlockWindows();
  1570.  
  1571.     if(RexxProcess)
  1572.     {
  1573.         Signal(RexxProcess,SIGBREAKF_CTRL_C);
  1574.  
  1575.         Wait(SIGBREAKF_CTRL_C);
  1576.     }
  1577.  
  1578.     if(ClipProcess)
  1579.     {
  1580.         Signal(ClipProcess,SIGBREAKF_CTRL_C);
  1581.  
  1582.         Wait(SIGBREAKF_CTRL_C);
  1583.     }
  1584.  
  1585.     if(BufferProcess)
  1586.     {
  1587.         Signal(BufferProcess,SIGBREAKF_CTRL_C);
  1588.  
  1589.         Wait(SIGBREAKF_CTRL_C);
  1590.     }
  1591.  
  1592.     if(TermRexxPort)
  1593.     {
  1594.         if(RexxSysBase)
  1595.         {
  1596.             struct RexxMsg *RexxMsg;
  1597.  
  1598.             while(RexxMsg = (struct RexxMsg *)GetMsg(TermRexxPort))
  1599.                 ReplyRexxCommand(RexxMsg,RC_ERROR,0,NULL);
  1600.         }
  1601.  
  1602.         DeleteMsgPort(TermRexxPort);
  1603.     }
  1604.  
  1605.     if(XprIO && XProtocolBase)
  1606.         XProtocolCleanup(XprIO);
  1607.  
  1608.     if(XProtocolBase)
  1609.         CloseLibrary(XProtocolBase);
  1610.  
  1611.     if(XprIO)
  1612.         FreeVec(XprIO);
  1613.  
  1614.     if(FileAnchor)
  1615.         FreeVec(FileAnchor);
  1616.  
  1617.     if(Phonebook && PhoneSize)
  1618.         DeletePhonebook(Phonebook,PhoneSize,TRUE);
  1619.  
  1620.     if(MacroKeys)
  1621.         FreeVec(MacroKeys);
  1622.  
  1623.     ClearBuffer();
  1624.  
  1625.     DeleteSpeech();
  1626.  
  1627.     Forbid();
  1628.  
  1629.     BufferClosed = TRUE;
  1630.  
  1631.     if(BufferLines)
  1632.         FreeVec(BufferLines);
  1633.  
  1634.     if(BufferSemaphore)
  1635.         FreeVec(BufferSemaphore);
  1636.  
  1637.     Permit();
  1638.  
  1639.     ClearDownloadObjects();
  1640.  
  1641.     if(DownloadSemaphore)
  1642.         FreeVec(DownloadSemaphore);
  1643.  
  1644.     if(AttentionBuffers[0])
  1645.         FreeVec(AttentionBuffers[0]);
  1646.  
  1647.     FreeDialList();
  1648.  
  1649.     ClearFastMacroList(&FastMacroList);
  1650.  
  1651.     if(FileCapture)
  1652.     {
  1653.         BufferClose(FileCapture);
  1654.  
  1655.         if(!GetFileSize(CaptureName))
  1656.             DeleteFile(CaptureName);
  1657.         else
  1658.             SetProtection(CaptureName,FIBF_EXECUTE);
  1659.     }
  1660.  
  1661.     if(PrinterCapture)
  1662.         Close(PrinterCapture);
  1663.  
  1664.     CloseEmulator();
  1665.  
  1666.     if(XEM_MacroKeys)
  1667.         FreeVec(XEM_MacroKeys);
  1668.  
  1669.     DeleteDisplay();
  1670.  
  1671.     if(KeySegment)
  1672.         UnLoadSeg(KeySegment);
  1673.  
  1674.     StopCall(TRUE);
  1675.  
  1676.     if(ClipBit != -1)
  1677.         FreeSignal(ClipBit);
  1678.  
  1679.     if(CheckBit != -1)
  1680.         FreeSignal(CheckBit);
  1681.  
  1682.     ClearSerial();
  1683.  
  1684.     DeleteSerial();
  1685.  
  1686.     if(TimeRequest)
  1687.     {
  1688.         if(TimeRequest -> tr_node . io_Device)
  1689.             CloseDevice(TimeRequest);
  1690.  
  1691.         DeleteIORequest(TimeRequest);
  1692.     }
  1693.  
  1694.     if(TimePort)
  1695.         DeleteMsgPort(TimePort);
  1696.  
  1697.     DeleteBeep();
  1698.  
  1699.     ShutdownCx();
  1700.  
  1701.     if(TermPort)
  1702.     {
  1703.         if(TermID != -1)
  1704.         {
  1705.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  1706.  
  1707.             TermPort -> OpenCount--;
  1708.  
  1709.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  1710.             {
  1711.                 RemPort(&TermPort -> ExecNode);
  1712.  
  1713.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  1714.  
  1715.                 FreeVec(TermPort);
  1716.             }
  1717.             else
  1718.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  1719.         }
  1720.     }
  1721.  
  1722.     CloseClip();
  1723.  
  1724.     if(RequesterList)
  1725.         FreeVec(RequesterList);
  1726.  
  1727.     if(OwnDevUnitBase)
  1728.         CloseLibrary(OwnDevUnitBase);
  1729.  
  1730.     if(LayersBase)
  1731.         CloseLibrary(LayersBase);
  1732.  
  1733.     if(CxBase)
  1734.         CloseLibrary(CxBase);
  1735.  
  1736.     if(IFFParseBase)
  1737.         CloseLibrary(IFFParseBase);
  1738.  
  1739.     if(AslBase)
  1740.         CloseLibrary(AslBase);
  1741.  
  1742.     if(DiskfontBase)
  1743.         CloseLibrary(DiskfontBase);
  1744.  
  1745.     if(FakeInputEvent)
  1746.         FreeVec(FakeInputEvent);
  1747.  
  1748.     if(ConsoleDevice)
  1749.         CloseDevice(ConsoleRequest);
  1750.  
  1751.     if(ConsoleRequest)
  1752.         FreeVec(ConsoleRequest);
  1753.  
  1754.     if(Topaz)
  1755.         CloseFont(Topaz);
  1756.  
  1757.     if(RexxSysBase)
  1758.         CloseLibrary(RexxSysBase);
  1759.  
  1760.     if(GadToolsBase)
  1761.         CloseLibrary(GadToolsBase);
  1762.  
  1763.     if(UtilityBase)
  1764.         CloseLibrary(UtilityBase);
  1765.  
  1766.     if(GfxBase)
  1767.         CloseLibrary(GfxBase);
  1768.  
  1769.     if(IntuitionBase)
  1770.         CloseLibrary(IntuitionBase);
  1771.  
  1772.     LocaleClose();
  1773.  
  1774.     if(WBenchMsg)
  1775.     {
  1776.         if(DOSBase)
  1777.             CloseLibrary(DOSBase);
  1778.  
  1779.         Forbid();
  1780.  
  1781.         ReplyMsg((struct Message *)WBenchMsg);
  1782.     }
  1783. }
  1784.  
  1785.     /* OpenAll():
  1786.      *
  1787.      *    Open all required resources or return an error message
  1788.      *    if anything went wrong.
  1789.      */
  1790.  
  1791. UBYTE *
  1792. OpenAll(STRPTR ConfigPath)
  1793. {
  1794.     UBYTE     PathBuffer[256];
  1795.     WORD     i;
  1796.     UBYTE    *Result,
  1797.         *Error;
  1798.  
  1799.     DateStamp(&SessionStart);
  1800.  
  1801.     LocaleOpen("term.catalog","english",7);
  1802.  
  1803.     LocalizeMenu(TermMenu,MSG_TERMDATA_PROJECT_MEN);
  1804.  
  1805.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  1806.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_INTUITION_LIBRARY_TXT));
  1807.  
  1808.     if((SysBase -> SoftVer < 175 && SysBase -> LibNode . lib_Version == 37) || SysBase -> LibNode . lib_Version < 37)
  1809.     {
  1810.         if(!MyEasyRequest(NULL,LocaleString(MSG_TERMINIT_VERSION_WARNING_TXT),
  1811.             LocaleString(MSG_TERMINIT_PROCEED_BACK_OUT_TXT),SysBase -> LibNode . lib_Version,SysBase -> SoftVer))
  1812.                 return("");
  1813.     }
  1814.  
  1815.     PublicModes = SetPubScreenModes(0);
  1816.  
  1817.     SetPubScreenModes(PublicModes);
  1818.  
  1819.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  1820.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GRAPHICS_LIBRARY_TXT));
  1821.  
  1822.     if(!(UtilityBase = OpenLibrary("utility.library",0)))
  1823.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_UTILITY_LIBRARY_TXT));
  1824.  
  1825.     LanguageCheck();
  1826.  
  1827.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  1828.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GADTOOLS_LIBRARY_TXT));
  1829.  
  1830.     if(!(AslBase = OpenLibrary("asl.library",0)))
  1831.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_ASL_LIBRARY_TXT));
  1832.  
  1833.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  1834.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_IFFPARSE_LIBRARY_TXT));
  1835.  
  1836.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  1837.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_COMMODITIES_LIBRARY_TXT));
  1838.  
  1839.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  1840.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_LAYERS_LIBRARY_TXT));
  1841.  
  1842.     OwnDevUnitBase = OpenLibrary(ODU_NAME,0);
  1843.  
  1844.     if(!(Topaz = (struct TextFont *)OpenFont(&DefaultFont)))
  1845.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_DEFAULT_FONT_TXT));
  1846.  
  1847.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVec(sizeof(struct IOStdReq),MEMF_ANY|MEMF_CLEAR)))
  1848.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CONSOLE_REQUEST_TXT));
  1849.  
  1850.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  1851.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_CONSOLE_DEVICE_TXT));
  1852.  
  1853.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  1854.  
  1855.     if(!(FakeInputEvent = (struct InputEvent *)AllocVec(sizeof(struct InputEvent),MEMF_ANY|MEMF_CLEAR)))
  1856.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_INPUTEVENT_TXT));
  1857.  
  1858.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  1859.  
  1860.     if(!(MacroKeys = (struct MacroKeys *)AllocVec(sizeof(struct MacroKeys),MEMF_ANY|MEMF_CLEAR)))
  1861.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACROKEYS_TXT));
  1862.  
  1863.     if(!(RequesterList = (struct Requester *)AllocVec(10 * sizeof(struct Requester),MEMF_ANY|MEMF_CLEAR)))
  1864.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_REQUESTER_DATA_TXT));
  1865.  
  1866.     DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0);
  1867.  
  1868.         /* Set up the attention buffers. */
  1869.  
  1870.     if(!(AttentionBuffers[0] = (UBYTE *)AllocVec(8 * 81,MEMF_PUBLIC|MEMF_CLEAR)))
  1871.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SEQUENCE_ATTENTION_INFO_TXT));
  1872.  
  1873.     for(i = 1 ; i < 8 ; i++)
  1874.         AttentionBuffers[i] = &AttentionBuffers[i - 1][81];
  1875.  
  1876.         /* Obtain the default environment storage
  1877.          * path.
  1878.          */
  1879.  
  1880.     if(!ConfigPath)
  1881.     {
  1882.         ConfigPath = PathBuffer;
  1883.  
  1884.         if(!GetEnvDOS("TERMPATH",PathBuffer))
  1885.         {
  1886.             APTR LastPtr = ThisProcess -> pr_WindowPtr;
  1887.             BPTR FileLock;
  1888.  
  1889.             strcpy(PathBuffer,"TERM:config");
  1890.  
  1891.             SetEnvDOS("TERMPATH",PathBuffer);
  1892.  
  1893.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  1894.  
  1895.             if(FileLock = Lock("TERM:",ACCESS_READ))
  1896.                 UnLock(FileLock);
  1897.             else
  1898.             {
  1899.                 FileLock = DupLock(ThisProcess-> pr_CurrentDir);
  1900.  
  1901.                     /* Create TERM: assignment referring to
  1902.                      * current directory.
  1903.                      */
  1904.  
  1905.                 if(!AssignLock("TERM",FileLock))
  1906.                     UnLock(FileLock);
  1907.             }
  1908.  
  1909.             if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  1910.                 FileLock = CreateDir(PathBuffer);
  1911.  
  1912.             if(FileLock)
  1913.                 UnLock(FileLock);
  1914.  
  1915.             ThisProcess -> pr_WindowPtr = LastPtr;
  1916.         }
  1917.     }
  1918.  
  1919.         /* Check for proper assignment path if necessary. */
  1920.  
  1921.         if(!Strnicmp(ConfigPath,"TERM:",5))
  1922.         {
  1923.             APTR OldPtr = ThisProcess -> pr_WindowPtr;
  1924.             BPTR DirLock;
  1925.  
  1926.             /* Block dos requesters. */
  1927.  
  1928.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  1929.  
  1930.             /* Try to get a lock on `TERM:' assignment. */
  1931.  
  1932.         if(DirLock = Lock("TERM:",ACCESS_READ))
  1933.             UnLock(DirLock);
  1934.         else
  1935.         {
  1936.                 /* Clone current directory lock. */
  1937.  
  1938.             DirLock = DupLock(ThisProcess-> pr_CurrentDir);
  1939.  
  1940.                 /* Create TERM: assignment referring to
  1941.                  * current directory.
  1942.                  */
  1943.  
  1944.             if(!AssignLock("TERM",DirLock))
  1945.                 UnLock(DirLock);
  1946.         }
  1947.  
  1948.         ThisProcess -> pr_WindowPtr = OldPtr;
  1949.         }
  1950.  
  1951.         /* Create proper path names. */
  1952.  
  1953.     strcpy(LastConfig,ConfigPath);
  1954.  
  1955.     AddPart(LastConfig,"term_preferences.iff",256);
  1956.  
  1957.     if(!GetFileSize(LastConfig))
  1958.     {
  1959.         strcpy(LastConfig,ConfigPath);
  1960.  
  1961.         AddPart(LastConfig,"term.prefs",256);
  1962.     }
  1963.  
  1964.     strcpy(DefaultPubScreen,"Workbench");
  1965.  
  1966.         /* Read some more environment variables. */
  1967.  
  1968.     if(!GetEnvDOS("TERMWINDOW",WindowName))
  1969.         strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN TERM");
  1970.  
  1971.     GetEnvDOS("EDITOR",Config . Editor);
  1972.  
  1973.     SetPrefToDefaults(&Config,ConfigPath);
  1974.  
  1975.         /* Look for the default configuration file. */
  1976.  
  1977.     if(!ReadIFFData(LastConfig,&Config,sizeof(struct Configuration),'PREF'))
  1978.     {
  1979.         SetPrefToDefaults(&Config,ConfigPath);
  1980.  
  1981.         Initializing = TRUE;
  1982.  
  1983.         LoadColours = TRUE;
  1984.     }
  1985.     else
  1986.     {
  1987.         switch(Config . ColourMode)
  1988.         {
  1989.             case COLOUR_EIGHT:    CopyMem(&Config . Colours[0],&ANSIColours[0],16 * sizeof(UWORD));
  1990.                         break;
  1991.  
  1992.             case COLOUR_SIXTEEN:    CopyMem(&Config . Colours[0],&EGAColours[0],16 * sizeof(UWORD));
  1993.                         break;
  1994.  
  1995.             case COLOUR_AMIGA:    CopyMem(&Config . Colours[0],&DefaultColours[0],16 * sizeof(UWORD));
  1996.                         break;
  1997.  
  1998.             case COLOUR_MONO:    CopyMem(&Config . Colours[0],&AtomicColours[0],16 * sizeof(UWORD));
  1999.                         break;
  2000.         }
  2001.  
  2002.         if(Config . ColourMode == COLOUR_AMIGA)
  2003.             Initializing = FALSE;
  2004.         else
  2005.             Initializing = TRUE;
  2006.     }
  2007.  
  2008.     UpdatePrefs(&Config);
  2009.  
  2010.     if(Config . OpenFastMacroPanel)
  2011.         HadFastMacros = TRUE;
  2012.  
  2013.     NewList(&FastMacroList);
  2014.  
  2015.     strcpy(LastPhone,    Config . DefaultStorage);
  2016.     AddPart(LastPhone,    "term_phonebook.iff",256);
  2017.  
  2018.     if(!GetFileSize(LastPhone))
  2019.     {
  2020.         strcpy(LastPhone,    Config . DefaultStorage);
  2021.         AddPart(LastPhone,    "phonebook.prefs",256);
  2022.     }
  2023.  
  2024.     strcpy(LastKeys,    Config . DefaultStorage);
  2025.     AddPart(LastKeys,    "term_hotkeys.iff",256);
  2026.  
  2027.     if(!GetFileSize(LastKeys))
  2028.     {
  2029.         strcpy(LastKeys,    Config . DefaultStorage);
  2030.         AddPart(LastKeys,    "hotkeys.prefs",256);
  2031.     }
  2032.  
  2033.     strcpy(LastSpeech,    Config . DefaultStorage);
  2034.     AddPart(LastSpeech,    "term_speech.iff",256);
  2035.  
  2036.     if(!GetFileSize(LastSpeech))
  2037.     {
  2038.         strcpy(LastSpeech,    Config . DefaultStorage);
  2039.         AddPart(LastSpeech,    "speech.prefs",256);
  2040.     }
  2041.  
  2042.     strcpy(LastFastMacros,    Config . DefaultStorage);
  2043.     AddPart(LastFastMacros,    "term_fastmacros.iff",256);
  2044.  
  2045.     if(!GetFileSize(LastFastMacros))
  2046.     {
  2047.         strcpy(LastFastMacros,    Config . DefaultStorage);
  2048.         AddPart(LastFastMacros,    "fastmacros.prefs",256);
  2049.     }
  2050.  
  2051.     strcpy(LastMacros,Config . MacroFile);
  2052.  
  2053.         /* Load the keyboard macros. */
  2054.  
  2055.     if(!LoadMacros(LastMacros,MacroKeys))
  2056.     {
  2057.         for(i = 0 ; i < 4 ; i++)
  2058.             strcpy(MacroKeys -> Keys[1][i],FunctionKeyCodes[i]);
  2059.     }
  2060.  
  2061.         /* Load the fast! macro settings. */
  2062.  
  2063.     LoadFastMacros(LastFastMacros);
  2064.  
  2065.         /* Load the speech settings. */
  2066.  
  2067.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),'SPEK'))
  2068.     {
  2069.         SpeechConfig . Rate        = DEFRATE;
  2070.         SpeechConfig . Pitch        = DEFPITCH;
  2071.         SpeechConfig . Frequency    = DEFFREQ;
  2072.         SpeechConfig . Volume        = DEFVOL;
  2073.         SpeechConfig . Sex        = DEFSEX;
  2074.         SpeechConfig . Enabled        = FALSE;
  2075.     }
  2076.  
  2077.         /* Load the hotkey settings. */
  2078.  
  2079.     if(!LoadHotkeys(LastKeys,&Hotkeys))
  2080.     {
  2081.         strcpy(Hotkeys . termScreenToFront,    "lshift rshift return");
  2082.         strcpy(Hotkeys . BufferScreenToFront,    "control rshift return");
  2083.         strcpy(Hotkeys . SkipDialEntry,        "control lshift rshift return");
  2084.         strcpy(Hotkeys . AbortARexx,        "lshift rshift escape");
  2085.  
  2086.         Hotkeys . CommodityPriority    = 0;
  2087.         Hotkeys . HotkeysEnabled    = TRUE;
  2088.     }
  2089.  
  2090.         /* Initialize the data flow parser. */
  2091.  
  2092.     FlowInit();
  2093.  
  2094.         /* Set up parsing jump tables. */
  2095.  
  2096.     if(!(SpecialTable = (JUMP *)AllocVec(256 * sizeof(JUMP),MEMF_ANY|MEMF_CLEAR)))
  2097.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  2098.  
  2099.     for(i = 0 ; i < sizeof(SpecialKeys) / sizeof(struct SpecialKey) ; i++)
  2100.         SpecialTable[SpecialKeys[i] . Key] = (JUMP)SpecialKeys[i] . Routine;
  2101.  
  2102.     if(!(AbortTable = (JUMP *)AllocVec(256 * sizeof(JUMP),MEMF_ANY)))
  2103.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  2104.  
  2105.     for(i = 0 ; i < 256 ; i++)
  2106.     {
  2107.         switch(AbortMap[i])
  2108.         {
  2109.             case 0:    AbortTable[i] = ParseCode;
  2110.                 break;
  2111.  
  2112.             case 1:    AbortTable[i] = (JUMP)DoCancel;
  2113.                 break;
  2114.  
  2115.             case 2:    AbortTable[i] = DoNewEsc;
  2116.                 break;
  2117.  
  2118.             case 3:    AbortTable[i] = DoNewCsi;
  2119.                 break;
  2120.         }
  2121.     }
  2122.  
  2123.         /* Allocate the ANSI sequence work buffer. */
  2124.  
  2125.     if(!(StripBuffer = (UBYTE *)AllocVec(Config . SerBuffSize,MEMF_ANY)))
  2126.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  2127.  
  2128.         /* Set up the serial driver. */
  2129.  
  2130.     if(Error = CreateSerial())
  2131.     {
  2132.         MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  2133.  
  2134.         DeleteSerial();
  2135.     }
  2136.     else
  2137.     {
  2138.         if(SerialMessage)
  2139.         {
  2140.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  2141.  
  2142.             SerialMessage = NULL;
  2143.         }
  2144.     }
  2145.  
  2146.         /* Get two signal bits. */
  2147.  
  2148.     if((ClipBit = AllocSignal(-1)) == -1)
  2149.         return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_CLIP_SIGNAL_TXT));
  2150.  
  2151.     if((CheckBit = AllocSignal(-1)) == -1)
  2152.         return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_CHECK_SIGNAL_TXT));
  2153.  
  2154.         /* Load alternative beep sound if desired. */
  2155.  
  2156.     if(Config . BeepSound[0])
  2157.         OpenSound(Config . BeepSound);
  2158.  
  2159.     if(!CreateBeep())
  2160.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_AUDIO_DEVICE_TXT));
  2161.  
  2162.     if(!(TimePort = (struct MsgPort *)CreateMsgPort()))
  2163.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  2164.  
  2165.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(TimePort,sizeof(struct timerequest))))
  2166.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_IOREQUEST_TXT));
  2167.  
  2168.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  2169.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_TIMER_DEVICE_TXT));
  2170.  
  2171.     TimerBase = (struct Device *)TimeRequest -> tr_node . io_Device;
  2172.  
  2173.     if(ClipProcess = CreateNewProcTags(
  2174.         NP_Entry,    ClipServer,
  2175.         NP_Name,    "term clipboard process",
  2176.         NP_WindowPtr,    -1,
  2177.         NP_Priority,    20,
  2178.     TAG_DONE))
  2179.         Wait(SIGBREAKF_CTRL_C);
  2180.  
  2181.     if(!ClipProcess)
  2182.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_CLIPBOARD_SERVER_TXT));
  2183.  
  2184.         /* Add the global term port. */
  2185.  
  2186.     if(!TermPort)
  2187.     {
  2188.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort),MEMF_PUBLIC|MEMF_CLEAR)))
  2189.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_GLOBAL_PORT_TXT));
  2190.  
  2191.         NewList(&TermPort -> ExecNode . mp_MsgList);
  2192.  
  2193.         InitSemaphore(&TermPort -> OpenSemaphore);
  2194.  
  2195.         TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  2196.         TermPort -> ExecNode . mp_Node . ln_Name    = "term Port";
  2197.  
  2198.         AddPort(&TermPort -> ExecNode);
  2199.     }
  2200.  
  2201.         /* Keep another term task from removing the port. */
  2202.  
  2203.     TermPort -> HoldIt = TRUE;
  2204.  
  2205.         /* Install a new term process. */
  2206.  
  2207.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  2208.  
  2209.     TermPort -> OpenCount++;
  2210.  
  2211.     TermPort -> HoldIt = FALSE;
  2212.  
  2213.     TermID = TermPort -> ID++;
  2214.  
  2215.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  2216.  
  2217.         /* Set up the ID string. */
  2218.  
  2219.     if(TermID)
  2220.         SPrintf(TermIDString,"TERM.%ld",TermID);
  2221.     else
  2222.         strcpy(TermIDString,"TERM");
  2223.  
  2224.         /* Install the hotkey handler. */
  2225.  
  2226.     SetupCx();
  2227.  
  2228.         /* Allocate the first few lines for the display buffer. */
  2229.  
  2230.     if(!(BufferLines = (UBYTE **)AllocVec(MaxLines * sizeof(UBYTE *),MEMF_ANY|MEMF_CLEAR)))
  2231.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_VIEW_BUFFER_TXT));
  2232.  
  2233.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_ANY|MEMF_CLEAR)))
  2234.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_PROTOCOL_BUFFER_TXT));
  2235.  
  2236.     if(!(FileAnchor = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath),MEMF_ANY|MEMF_CLEAR)))
  2237.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_ANCHOR_PATH_TXT));
  2238.  
  2239.         /* Create the download list access semaphore. */
  2240.  
  2241.     if(!(DownloadSemaphore = (struct SignalSemaphore *)AllocVec(sizeof(struct SignalSemaphore),MEMF_ANY|MEMF_CLEAR)))
  2242.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SEMAPHORE_TXT));
  2243.  
  2244.     InitSemaphore(DownloadSemaphore);
  2245.  
  2246.     NewList(&SequenceList);
  2247.     NewList(&PacketHistoryList);
  2248.     NewList(&DownloadList);
  2249.     NewList(&EmptyList);
  2250.  
  2251.         /* Create the buffer access semaphore. */
  2252.  
  2253.     if(!(BufferSemaphore = (struct SignalSemaphore *)AllocVec(sizeof(struct SignalSemaphore),MEMF_ANY|MEMF_CLEAR)))
  2254.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SEMAPHORE_TXT));
  2255.  
  2256.     InitSemaphore(BufferSemaphore);
  2257.  
  2258.         /* Set up the external emulation macro data. */
  2259.  
  2260.     if(!(XEM_MacroKeys = (struct XEmulatorMacroKey *)AllocVec((2 + 10 * 4) * sizeof(struct XEmulatorMacroKey),MEMF_ANY|MEMF_CLEAR)))
  2261.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACRO_KEY_DATA_TXT));
  2262.  
  2263.     strcpy(LastXprLibrary,Config . Protocol);
  2264.  
  2265.     ProtocolSetup();
  2266.  
  2267.         /* Double buffered file locking. */
  2268.  
  2269.     NewList(&DoubleBufferList);
  2270.  
  2271.     InitSemaphore(&DoubleBufferSemaphore);
  2272.  
  2273.         /* Load a keymap file if required. */
  2274.  
  2275.     if(Config . KeyMapName[0])
  2276.         KeyMap = LoadKeyMap(Config . KeyMapName);
  2277.  
  2278.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  2279.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  2280.  
  2281.         /* If rexxsyslib.library opens cleanly it's time for
  2282.          * us to create the background term Rexx server.
  2283.          */
  2284.  
  2285.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  2286.     {
  2287.             /* Create a background process handling the
  2288.              * rexx messages asynchronously.
  2289.              */
  2290.  
  2291.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  2292.             NP_Entry,    RexxServer,
  2293.             NP_Name,    "term Rexx Process",
  2294.             NP_Priority,    5,
  2295.             NP_StackSize,    8192,
  2296.             NP_WindowPtr,    -1,
  2297.         TAG_END))
  2298.         {
  2299.             Wait(SIGBREAKF_CTRL_C);
  2300.  
  2301.             if(!RexxProcess)
  2302.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_AREXX_PROCESS_TXT));
  2303.         }
  2304.     }
  2305.  
  2306.     BinaryTransfer    = TRUE;
  2307.  
  2308.     Status        = STATUS_READY;
  2309.     Online        = FALSE;
  2310.  
  2311.     InSequence    = FALSE;
  2312.     Quiet        = FALSE;
  2313.  
  2314.     NewList(&TransferInfoList);
  2315.  
  2316.     CommandHook . h_Entry        = (APTR)CommandKey;
  2317.     CommandHook . h_SubEntry    = NULL;
  2318.     CommandHook . h_Data        = NULL;
  2319.  
  2320.         /* Create the whole display. */
  2321.  
  2322.     if(Result = CreateDisplay(TRUE))
  2323.         return(Result);
  2324.     else
  2325.         return(NULL);
  2326. }
  2327.