home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff589.lza / Term / TermSrc.lha / termInit.c < prev    next >
C/C++ Source or Header  |  1991-12-01  |  30KB  |  1,446 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1991 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: TermInit.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Jan-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* Screen title. */
  18.  
  19. STATIC UBYTE ScreenTitle[80];
  20.  
  21.     /* A couple of private strings which are to `impersonate' the
  22.      * control sequences associated with the four function keys.
  23.      */
  24.  
  25. STATIC UBYTE *FunctionKeyCodes[4] =
  26. {
  27.     "\\eOP",
  28.     "\\eOQ",
  29.     "\\eOR",
  30.     "\\eOS"
  31. };
  32.  
  33.     /* This variable helps us to remember whether the fast!
  34.      * macro panel was open or not.
  35.      */
  36.  
  37. STATIC BYTE HadFastMacros = FALSE;
  38.  
  39.     /* ConfigSetup():
  40.      *
  41.      *    Compare the current configuration with the
  42.      *    last backup and reset the serial device, terminal,
  43.      *    etc. if necessary.
  44.      */
  45.  
  46. VOID
  47. ConfigSetup()
  48. {
  49.     if(strcmp(PrivateConfig . MacroFile,Config . MacroFile))
  50.     {
  51.         if(!LoadMacros(Config . MacroFile,MacroKeys))
  52.         {
  53.             WORD i,j;
  54.  
  55.             for(j = 0 ; j < 4 ; j++)
  56.             {
  57.                 for(i = 0 ; i < 10 ; i++)
  58.                     MacroKeys -> Keys[j][i][0] = 0;
  59.             }
  60.  
  61.             for(i = 0 ; i < 4 ; i++)
  62.                 strcpy(MacroKeys -> Keys[1][i],FunctionKeyCodes[i]);
  63.         }
  64.         else
  65.             strcpy(LastMacros,Config . MacroFile);
  66.     }
  67.  
  68.     if(PrivateConfig . Font != Config . Font)
  69.     {
  70.         if(Config . Font == FONT_IBM && IBM)
  71.             CurrentFont = IBM;
  72.         else
  73.             CurrentFont = Topaz;
  74.  
  75.         SetFont(RPort,CurrentFont);
  76.     }
  77.  
  78.     if(PrivateConfig . DisplayMode != Config . DisplayMode || PrivateConfig . ColourMode != Config . ColourMode)
  79.         ResetDisplay = TRUE;
  80.  
  81.     if(strcmp(PrivateConfig . Protocol,Config . Protocol))
  82.     {
  83.         strcpy(LastXprLibrary,Config . Protocol);
  84.         ProtocolSetup();
  85.     }
  86.  
  87.     if(memcmp(&PrivateConfig,&Config,58))
  88.     {
  89.         ClearSerial();
  90.  
  91.         DeleteSerial();
  92.  
  93.         if(!CreateSerial())
  94.         {
  95.             MyEasyRequest(Window,"`term' has a problem:\nFailed to open %s!","Continue",Config . SerialDevice);
  96.  
  97.             DeleteSerial();
  98.         }
  99.     }
  100.  
  101.     if(!ResetDisplay && memcmp(&PrivateConfig . Colours[0],&Config . Colours[0],sizeof(UWORD) * 16))
  102.     {
  103.         WORD i;
  104.  
  105.         for(i = 0 ; i < 16 ; i++)
  106.             BlinkColours[i] = Config . Colours[i];
  107.  
  108.         LoadRGB4(VPort,&Config . Colours[0],(1 << Screen -> RastPort . BitMap -> Depth));
  109.  
  110.         switch(Config . ColourMode)
  111.         {
  112.             case COLOUR_EIGHT:    for(i = 0 ; i < 8 ; i++)
  113.                             BlinkColours[i + 8] = BlinkColours[0];
  114.  
  115.                         break;
  116.  
  117.             case COLOUR_SIXTEEN:    break;
  118.  
  119.             case COLOUR_AMIGA:
  120.             default:        BlinkColours[3] = BlinkColours[0];
  121.                         break;
  122.         }
  123.     }
  124.  
  125.     if(Config . EightyColumns)
  126.     {
  127.         if(Config . FontScale == SCALE_HALF)
  128.             LastColumn = 131;
  129.         else
  130.             LastColumn = 79;
  131.  
  132.         if(Config . EightyColumns == 1)
  133.             LastLine = 23;
  134.         else
  135.             LastLine = 24;
  136.  
  137.         BackupRender();
  138.  
  139.         SetAPen(RPort,0);
  140.         RectFill(RPort,0,(LastLine + 1) * 8,Window -> Width - 1,Window -> Height - 1);
  141.  
  142.         BackupRender();
  143.     }
  144.     else
  145.     {
  146.         LastColumn    = (Window -> Width >> 3) - 1;
  147.         LastLine    = (Window -> Height >> 3) - 1;
  148.  
  149.         if(!RegionSet)
  150.             Bottom = LastLine;
  151.     }
  152.  
  153.     if(CursorY > LastLine)
  154.         CursorY = LastLine;
  155.  
  156.     if(PrivateConfig . FontScale == SCALE_HALF && Config . FontScale != SCALE_HALF)
  157.     {
  158.         CursorX >>= 1;
  159.  
  160.         if(Config . EightyColumns)
  161.             LastColumn = 79;
  162.         else
  163.             LastColumn = (Window -> Width >> 3) - 1;
  164.     }
  165.  
  166.     if(PrivateConfig . ColourMode == Config . ColourMode && memcmp(&PrivateConfig . Colours[0],&Config . Colours[0],sizeof(UWORD) * 16))
  167.     {
  168.         switch(Config . ColourMode)
  169.         {
  170.             case COLOUR_EIGHT:    CopyMem(&Config . Colours[0],&ANSIColours[0],16 * sizeof(UWORD));
  171.                         break;
  172.  
  173.             case COLOUR_SIXTEEN:    CopyMem(&Config . Colours[0],&EGAColours[0],16 * sizeof(UWORD));
  174.                         break;
  175.  
  176.             case COLOUR_AMIGA:    CopyMem(&Config . Colours[0],&DefaultColours[0],16 * sizeof(UWORD));
  177.                         break;
  178.  
  179.             case COLOUR_MONO:    CopyMem(&Config . Colours[0],&AtomicColours[0],16 * sizeof(UWORD));
  180.                         break;
  181.         }
  182.     }
  183.  
  184.     if(Config . Emulation == EMULATION_EXTERNAL && Config . EmulationName[0])
  185.     {
  186.         if(Stricmp(PrivateConfig . EmulationName,Config . EmulationName))
  187.         {
  188.             if(!ResetDisplay)
  189.             {
  190.                 if(!CreateEmulator(Config . EmulationName,TRUE))
  191.                 {
  192.                     Config . Emulation = EMULATION_ANSIVT100;
  193.  
  194.                     if(Config . Font == FONT_IBM && IBM)
  195.                         CurrentFont = IBM;
  196.                     else
  197.                         CurrentFont = Topaz;
  198.  
  199.                     SetFont(RPort,CurrentFont);
  200.                 }
  201.                 else
  202.                 {
  203.                     Config . RasterEnabled = FALSE;
  204.  
  205.                     EraseScreen("2");
  206.                 }
  207.  
  208.                 NewEmulatorPlease = FALSE;
  209.             }
  210.             else
  211.                 NewEmulatorPlease = TRUE;
  212.         }
  213.         else
  214.         {
  215.             if(!Console)
  216.                 NewEmulatorPlease = TRUE;
  217.         }
  218.     }
  219.  
  220.     if(PrivateConfig . RasterEnabled != Config . RasterEnabled)
  221.     {
  222.         RasterEraseScreen(2);
  223.  
  224.         if(Config . RasterEnabled)
  225.         {
  226.             OnMenu(Window,FULLMENUNUM(0,4,0));
  227.             OnMenu(Window,FULLMENUNUM(5,5,0));
  228.         }
  229.         else
  230.         {
  231.             OffMenu(Window,FULLMENUNUM(0,4,0));
  232.             OffMenu(Window,FULLMENUNUM(5,5,0));
  233.         }
  234.     }
  235.  
  236.     if(Config . DisableBlinking && !ResetDisplay)
  237.         LoadRGB4(VPort,&Config . Colours[0],16);
  238.  
  239.     SetCursor();
  240. }
  241.  
  242.     /* PubScreenStuff():
  243.      *
  244.      *    This part handles the public screen setup stuff.
  245.      */
  246.  
  247. VOID
  248. PubScreenStuff()
  249. {
  250.         /* Are we to make our screen public? */
  251.  
  252.     if(Config . MakeScreenPublic)
  253.         PubScreenStatus(Screen,NULL);
  254.     else
  255.         PubScreenStatus(Screen,PSNF_PRIVATE);
  256.  
  257.         /* Are we to `shanghai' Workbench windows? */
  258.  
  259.     if(Config . ShanghaiWindows)
  260.     {
  261.         PublicModes |= SHANGHAI;
  262.  
  263.         SetPubScreenModes(PublicModes);
  264.  
  265.             /* Make this the default public screen. */
  266.  
  267.         SetDefaultPubScreen("term");
  268.     }
  269.     else
  270.     {
  271.         PublicModes &= ~SHANGHAI;
  272.  
  273.         if(LockPubScreen(DefaultPubScreen))
  274.         {
  275.             SetDefaultPubScreen(DefaultPubScreen);
  276.  
  277.             UnlockPubScreen(DefaultPubScreen,NULL);
  278.         }
  279.         else
  280.             SetDefaultPubScreen(NULL);
  281.  
  282.         SetPubScreenModes(PublicModes);
  283.     }
  284. }
  285.  
  286.     /* DeleteDisplay():
  287.      *
  288.      *    Free all resources associated with the terminal
  289.      *    display (tasks, interrupts, screen, window, etc.).
  290.      */
  291.  
  292. BYTE
  293. DeleteDisplay()
  294. {
  295.     if(Screen)
  296.     {
  297.         struct List        *PubScreenList;
  298.         struct PubScreenNode    *ScreenNode;
  299.  
  300.         PubScreenList = LockPubScreenList();
  301.  
  302.         for(ScreenNode = (struct PubScreenNode *)PubScreenList -> lh_Head ; ScreenNode -> psn_Node . ln_Succ ; ScreenNode = (struct PubScreenNode *)ScreenNode -> psn_Node . ln_Succ)
  303.         {
  304.             if(ScreenNode -> psn_Screen == Screen)
  305.                 break;
  306.         }
  307.  
  308.         if(ScreenNode)
  309.         {
  310.             if(ScreenNode -> psn_VisitorCount)
  311.             {
  312.                 UnlockPubScreenList();
  313.  
  314.                 return(FALSE);
  315.             }
  316.             else
  317.             {
  318.                 Forbid();
  319.  
  320.                 UnlockPubScreenList();
  321.  
  322.                 PubScreenStatus(Screen,PSNF_PRIVATE);
  323.  
  324.                 Permit();
  325.             }
  326.         }
  327.         else
  328.             UnlockPubScreenList();
  329.     }
  330.  
  331.     if(Config . Emulation == EMULATION_EXTERNAL)
  332.         DeleteEmulator(NewEmulatorPlease);
  333.  
  334.     NewEmulatorPlease = FALSE;
  335.  
  336.     if(StatusTask)
  337.     {
  338.         SetSignal(0,SIGBREAKF_CTRL_C);
  339.  
  340.         Signal(StatusTask,SIGBREAKF_CTRL_C);
  341.  
  342.         Wait(SIGBREAKF_CTRL_C);
  343.     }
  344.  
  345.     DeleteRaster();
  346.  
  347.     DeleteScale();
  348.  
  349.     if(Screen)
  350.         ScreenToBack(Screen);
  351.  
  352.     if(StatusWindow)
  353.     {
  354.         ClearMenuStrip(StatusWindow);
  355.         CloseWindowSafely(StatusWindow);
  356.  
  357.         StatusWindow = NULL;
  358.     }
  359.  
  360.     if(Window)
  361.     {
  362.         ClearMenuStrip(Window);
  363.  
  364.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  365.  
  366.         PopWindow();
  367.  
  368.         if(TermPort)
  369.             TermPort -> TopWindow = NULL;
  370.  
  371.         CloseWindow(Window);
  372.  
  373.         Window = NULL;
  374.     }
  375.  
  376.     if(FastWindow)
  377.     {
  378.         HadFastMacros = TRUE;
  379.  
  380.         CloseFastWindow();
  381.     }
  382.     else
  383.         HadFastMacros = FALSE;
  384.  
  385.     if(Menu)
  386.     {
  387.         FreeMenus(Menu);
  388.  
  389.         Menu = NULL;
  390.     }
  391.  
  392.     if(VisualInfo)
  393.     {
  394.         FreeVisualInfo(VisualInfo);
  395.  
  396.         VisualInfo = NULL;
  397.     }
  398.  
  399.     DeletePacketWindow();
  400.  
  401.     if(Screen)
  402.     {
  403.         CloseScreen(Screen);
  404.  
  405.         Screen = NULL;
  406.     }
  407.  
  408.     return(TRUE);
  409. }
  410.  
  411.     /* CreateDisplay(BYTE FirstSetup):
  412.      *
  413.      *    Open the display and allocate associated data.
  414.      */
  415.  
  416. UBYTE *
  417. CreateDisplay(BYTE FirstSetup)
  418. {
  419.     UWORD         Dummy = ~0,Count = 0,i;
  420.     LONG         ErrorCode;
  421.     ULONG         TagArray[9];
  422.     struct MenuItem    *SomeItem;
  423.  
  424.         /* We'll configure the screen parameters at
  425.          * run time, at first we'll set up the screen
  426.          * depth.
  427.          */
  428.  
  429.     TagArray[Count++] = SA_Depth;
  430.  
  431.         /* Now set up the approriate colour mode. */
  432.  
  433.     switch(Config . ColourMode)
  434.     {
  435.         case COLOUR_EIGHT:    TagArray[Count++] = 4;
  436.  
  437.                     TagArray[Count++] = SA_DetailPen;
  438.                     TagArray[Count++] = 0;
  439.  
  440.                     TagArray[Count++] = SA_Pens;
  441.                     TagArray[Count++] = (LONG)&ANSIPens;
  442.  
  443.                     TagArray[Count++] = SA_BlockPen;
  444.                     TagArray[Count++] = 4;
  445.  
  446.                     break;
  447.  
  448.         case COLOUR_SIXTEEN:    TagArray[Count++] = 4;
  449.  
  450.                     TagArray[Count++] = SA_DetailPen;
  451.                     TagArray[Count++] = 0;
  452.  
  453.                     TagArray[Count++] = SA_Pens;
  454.                     TagArray[Count++] = (LONG)&EGAPens;
  455.  
  456.                     TagArray[Count++] = SA_BlockPen;
  457.                     TagArray[Count++] = 8;
  458.  
  459.                     break;
  460.  
  461.         case COLOUR_MONO:    TagArray[Count++] = 1;
  462.  
  463.                     TagArray[Count++] = SA_Pens;
  464.                     TagArray[Count++] = (LONG)&Dummy;
  465.  
  466.                     break;
  467.  
  468.         case COLOUR_AMIGA:    TagArray[Count++] = 2;
  469.  
  470.                     TagArray[Count++] = SA_Pens;
  471.                     TagArray[Count++] = (LONG)&Dummy;
  472.  
  473.                     break;
  474.     }
  475.  
  476.         /* Terminate the tag array. */
  477.  
  478.     TagArray[Count] = TAG_END;
  479.  
  480.         /* Open the screen with the given requirements. */
  481.  
  482. OpenS:    SPrintf(ScreenTitle,"%s (%s) ARexx ID/Screen ID = \"%s\"",TermName,TermDate,TermIDString);
  483.  
  484.     if(!(Screen = (struct Screen *)OpenScreenTags(NULL,
  485.         SA_Title,    ScreenTitle,
  486.         SA_Overscan,    OSCAN_TEXT,
  487.         SA_DisplayID,    Config . DisplayMode,
  488.         SA_Font,    &DefaultFont,
  489.         SA_Behind,    TRUE,
  490.         SA_AutoScroll,    TRUE,
  491.         SA_PubName,    TermIDString,
  492.         SA_ErrorCode,    &ErrorCode,
  493.         TAG_MORE,    &TagArray[0],
  494.     TAG_END)))
  495.     {
  496.             /* We've got an error. */
  497.  
  498.         switch(ErrorCode)
  499.         {
  500.                 /* Can't open screen with these display
  501.                  * modes.
  502.                  */
  503.  
  504.             case OSERR_NOMONITOR:
  505.             case OSERR_NOCHIPS:
  506.             case OSERR_UNKNOWNMODE:        if(Config . DisplayMode & LACE)
  507.                                 Config . DisplayMode = HIRESLACE_KEY;
  508.                             else
  509.                                 Config . DisplayMode = HIRES_KEY;
  510.  
  511.                             goto OpenS;
  512.  
  513.             case OSERR_PUBNOTUNIQUE:    return("Screen ID already in use");
  514.  
  515.                 /* Some different error, probably out of
  516.                  * memory.
  517.                  */
  518.  
  519.             default:            return("Failed to open screen");
  520.         }
  521.     }
  522.  
  523.         /* Set up scaling data (bitmaps & rastports). */
  524.  
  525.     if(!CreateScale())
  526.         return("Failed to create font scaling info");
  527.  
  528.         /* Obtain visual info (whatever that may be). */
  529.  
  530.     if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  531.         return("Failed to obtain visual info");
  532.  
  533.     VPort = &Screen -> ViewPort;
  534.  
  535.         /* Fill the `default' colour with current values. */
  536.  
  537.     if(Initializing)
  538.     {
  539.         for(i = 0 ; i < 16 ; i++)
  540.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  541.  
  542.         Initializing = FALSE;
  543.     }
  544.  
  545.         /* Load the approriate colours. */
  546.  
  547.     if(LoadColours)
  548.     {
  549.         switch(Config . ColourMode)
  550.         {
  551.             case COLOUR_EIGHT:    CopyMem(&ANSIColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  552.                         break;
  553.  
  554.             case COLOUR_SIXTEEN:    CopyMem(&EGAColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  555.                         break;
  556.  
  557.             case COLOUR_AMIGA:    CopyMem(&DefaultColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  558.                         break;
  559.  
  560.             case COLOUR_MONO:    CopyMem(&AtomicColours[0],&Config . Colours[0],16 * sizeof(UWORD));
  561.                         break;
  562.         }
  563.  
  564.         LoadColours = FALSE;
  565.     }
  566.  
  567.         /* Reset the current colours and the blinking equivalents. */
  568.  
  569.     for(i = 0 ; i < 16 ; i++)
  570.         BlinkColours[i] = Config . Colours[i];
  571.  
  572.     LoadRGB4(VPort,&Config . Colours[0],(1 << Screen -> RastPort . BitMap -> Depth));
  573.  
  574.         /* Fiddle with the blinking colours. */
  575.  
  576.     switch(Config . ColourMode)
  577.     {
  578.         case COLOUR_EIGHT:    for(i = 0 ; i < 8 ; i++)
  579.                         BlinkColours[i + 8] = BlinkColours[0];
  580.  
  581.                     break;
  582.  
  583.         case COLOUR_SIXTEEN:    break;
  584.  
  585.         case COLOUR_AMIGA:
  586.         default:        BlinkColours[3] = BlinkColours[0];
  587.                     break;
  588.     }
  589.  
  590.         /* Open the main window. */
  591.  
  592.     if(!(Window = OpenWindowTags(NULL,
  593.         WA_Top,        Screen -> BarHeight + 2,
  594.         WA_Left,    0,
  595.         WA_Width,    Screen -> Width,
  596.         WA_Height,    Screen -> Height - (Screen -> BarHeight + 2) - (4 + 2 * 8),
  597.         WA_Backdrop,    TRUE,
  598.         WA_Borderless,    TRUE,
  599.         WA_SmartRefresh,TRUE,
  600.         WA_CustomScreen,Screen,
  601.         WA_RMBTrap,    TRUE,
  602.         WA_IDCMP,    IDCMP_RAWKEY | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | LISTVIEWIDCMP,
  603.     TAG_DONE)))
  604.         return("Failed to open window");
  605.  
  606.         /* Push it on the window stack (should become bottommost
  607.          * entry).
  608.          */
  609.  
  610.     PushWindow(Window);
  611.  
  612.     if(TermPort)
  613.         TermPort -> TopWindow = Window;
  614.  
  615.         /* Open the tiny status window. */
  616.  
  617.     if(!(StatusWindow = OpenWindowTags(NULL,
  618.         WA_Top,        Window -> TopEdge + Window -> Height,
  619.         WA_Left,    0,
  620.         WA_Width,    Screen -> Width,
  621.         WA_Height,    Screen -> Height - (Window -> TopEdge + Window -> Height),
  622.         WA_Backdrop,    TRUE,
  623.         WA_Borderless,    TRUE,
  624.         WA_SmartRefresh,TRUE,
  625.         WA_CustomScreen,Screen,
  626.         WA_RMBTrap,    TRUE,
  627.     TAG_DONE)))
  628.         return("Failed to open status window");
  629.  
  630.         /* Default console setup. */
  631.  
  632.     if(Config . EightyColumns)
  633.     {
  634.         LastColumn = 79;
  635.  
  636.         if(Config . EightyColumns == 1)
  637.             LastLine = 23;
  638.         else
  639.             LastLine = 24;
  640.     }
  641.     else
  642.     {
  643.         LastColumn    = (Window -> Width >> 3) - 1;
  644.         LastLine    = (Window -> Height >> 3) - 1;
  645.     }
  646.  
  647.     CursorX = 0;
  648.     CursorY    = 0;
  649.  
  650.     SetDrMd(Window -> RPort,JAM2);
  651.  
  652.     StatusWindow -> UserPort = Window -> UserPort;
  653.  
  654.     ModifyIDCMP(StatusWindow,Window -> IDCMPFlags);
  655.  
  656.     RPort = Window -> RPort;
  657.  
  658.         /* Redirect AmigaDOS requesters. */
  659.  
  660.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  661.  
  662.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  663.  
  664.         /* Create the character raster. */
  665.  
  666.     if(!CreateRaster())
  667.         return("Unable to create screen raster");
  668.  
  669.         /* Reset terminal emulation. */
  670.  
  671.     Reset();
  672.  
  673.         /* Set the font. */
  674.  
  675.     if(Config . Font == FONT_IBM && IBM)
  676.         CurrentFont = IBM;
  677.     else
  678.         CurrentFont = Topaz;
  679.  
  680.     SetFont(RPort,CurrentFont);
  681.  
  682.         /* Create the menu strip. */
  683.  
  684.     if(!(Menu = CreateMenus(TermMenu,
  685.         GTMN_FrontPen, 0,
  686.     TAG_DONE)))
  687.         return("Failed to create menus");
  688.  
  689.         /* Do the menu layout. */
  690.  
  691.     if(!LayoutMenus(Menu,VisualInfo,
  692.         GTMN_TextAttr,&DefaultFont,
  693.     TAG_DONE))
  694.         return("Failed to layout menus");
  695.  
  696.         /* Disable the `Execute ARexx Command' menu item if
  697.          * the rexx server is not available.
  698.          */
  699.  
  700.     if(!RexxSysBase)
  701.     {
  702.         struct MenuItem *SomeItem;
  703.  
  704.         if(SomeItem = FindThisItem(MEN_REXXCOMMAND))
  705.             SomeItem -> Flags &= ~ITEMENABLED;
  706.     }
  707.  
  708.         /* Add a tick if file capture is active. */
  709.  
  710.     if(FileCapture)
  711.     {
  712.         if(SomeItem = FindThisItem(MEN_CAPTUREDISK))
  713.             SomeItem -> Flags |= CHECKED;
  714.     }
  715.  
  716.         /* Add a tick if printer capture is active. */
  717.  
  718.     if(PrinterCapture)
  719.     {
  720.         if(SomeItem = FindThisItem(MEN_CAPTUREPRINTER))
  721.             SomeItem -> Flags |= CHECKED;
  722.     }
  723.  
  724.         /* Add the menu to the windows. */
  725.  
  726.     SetMenuStrip(Window,Menu);
  727.     SetMenuStrip(StatusWindow,Menu);
  728.  
  729.         /* Enable the menu. */
  730.  
  731.     Window -> Flags        &= ~WFLG_RMBTRAP;
  732.     StatusWindow -> Flags    &= ~WFLG_RMBTRAP;
  733.  
  734.         /* Set up the status window, draw a border. */
  735.  
  736.     DrawBevelBox(StatusWindow -> RPort,0,0,StatusWindow -> Width,StatusWindow -> Height,
  737.         GT_VisualInfo,VisualInfo,
  738.     TAG_DONE);
  739.  
  740.         /* Render the information. */
  741.  
  742.     switch(Config . ColourMode)
  743.     {
  744.         case COLOUR_EIGHT:    SetAPen(StatusWindow -> RPort,4);
  745.                     break;
  746.  
  747.         case COLOUR_SIXTEEN:    SetAPen(StatusWindow -> RPort,8);
  748.                     break;
  749.  
  750.         case COLOUR_AMIGA:
  751.         default:        SetAPen(StatusWindow -> RPort,1);
  752.                     break;
  753.     }
  754.  
  755.     SetBPen(StatusWindow -> RPort,0);
  756.     SetDrMd(StatusWindow -> RPort,JAM2);
  757.  
  758.     Move(StatusWindow -> RPort,(Screen -> Width - (79 << 3)) >> 1,2 + 6 + 0);
  759.     Text(StatusWindow -> RPort,"Status ..:          Protocol :          Baud Rate:          Time ....:",70);
  760.  
  761.     Move(StatusWindow -> RPort,(Screen -> Width - (79 << 3)) >> 1,2 + 6 + 8);
  762.     Text(StatusWindow -> RPort,"Font ....:          Emulation:          Parameters          Online ..:",70);
  763.  
  764.     switch(Config . ColourMode)
  765.     {
  766.         case COLOUR_EIGHT:    SetAPen(StatusWindow -> RPort,6);
  767.                     break;
  768.  
  769.         case COLOUR_SIXTEEN:    SetAPen(StatusWindow -> RPort,7);
  770.                     break;
  771.  
  772.         case COLOUR_AMIGA:    SetAPen(StatusWindow -> RPort,2);
  773.                     break;
  774.  
  775.         case COLOUR_MONO:    SetAPen(StatusWindow -> RPort,1);
  776.                     break;
  777.     }
  778.  
  779.         /* Create the status server. */
  780.  
  781.     if(!(StatusTask = (struct Task *)CreateTask("term Status Task",5,StatusServer,4096)))
  782.         return("Unable to create status task");
  783.  
  784.         /* Wait for ringback signal. */
  785.  
  786.     Wait(SIGBREAKF_CTRL_C);
  787.  
  788.         /* Status server has `died'. */
  789.  
  790.     if(!StatusTask)
  791.         return("Unable to create status task");
  792.  
  793.         /* Restart the fast! macro panel. */
  794.  
  795.     if(HadFastMacros)
  796.         OpenFastWindow();
  797.  
  798.         /* Obtain the default public screen name just in case
  799.          * we'll need it later.
  800.          */
  801.  
  802.     GetDefaultPubScreen(DefaultPubScreen);
  803.  
  804.     if(Config . Emulation == EMULATION_EXTERNAL && Config . EmulationName[0])
  805.     {
  806.         if(!CreateEmulator(Config . EmulationName,NewEmulatorPlease))
  807.         {
  808.             Config . Emulation = EMULATION_ANSIVT100;
  809.  
  810.             if(Config . Font == FONT_IBM && IBM)
  811.                 CurrentFont = IBM;
  812.             else
  813.                 CurrentFont = Topaz;
  814.  
  815.             SetFont(RPort,CurrentFont);
  816.         }
  817.         else
  818.         {
  819.             if(Config . RasterEnabled)
  820.             {
  821.                 Config . RasterEnabled = FALSE;
  822.  
  823.                 RasterEraseScreen(2);
  824.  
  825.                 EraseScreen("2");
  826.  
  827.                 OffMenu(Window,FULLMENUNUM(0,4,0));
  828.                 OffMenu(Window,FULLMENUNUM(5,5,0));
  829.             }
  830.         }
  831.     }
  832.  
  833.     NewEmulatorPlease = FALSE;
  834.  
  835.     return(NULL);
  836. }
  837.  
  838.     /* CloseAll():
  839.      *
  840.      *    Free all resources and leave the program.
  841.      */
  842.  
  843. VOID
  844. CloseAll()
  845. {
  846.     if(IntuitionBase && Window && StatusWindow)
  847.         BlockWindows();
  848.  
  849.     if(RexxProcess)
  850.     {
  851.         Signal(RexxProcess,SIGBREAKF_CTRL_C);
  852.  
  853.         Wait(SIGBREAKF_CTRL_C);
  854.     }
  855.  
  856.     if(ClipProcess)
  857.     {
  858.         Signal(ClipProcess,SIGBREAKF_CTRL_C);
  859.  
  860.         Wait(SIGBREAKF_CTRL_C);
  861.     }
  862.  
  863.     if(TermRexxPort)
  864.     {
  865.         if(RexxSysBase)
  866.         {
  867.             struct RexxMsg *RexxMsg;
  868.  
  869.             while(RexxMsg = (struct RexxMsg *)GetMsg(TermRexxPort))
  870.                 ReplyRexxCommand(RexxMsg,RC_ERROR,0,NULL);
  871.         }
  872.  
  873.         DeleteMsgPort(TermRexxPort);
  874.     }
  875.  
  876.     if(XprIO && XProtocolBase)
  877.         XProtocolCleanup(XprIO);
  878.  
  879.     if(XProtocolBase)
  880.         CloseLibrary(XProtocolBase);
  881.  
  882.     if(XprIO)
  883.         FreeVec(XprIO);
  884.  
  885.     if(FileAnchor)
  886.         FreeVec(FileAnchor);
  887.  
  888.     if(Phonebook && PhoneSize)
  889.         DeletePhonebook(Phonebook,PhoneSize,TRUE);
  890.  
  891.     if(MacroKeys)
  892.         FreeVec(MacroKeys);
  893.  
  894.     ClearBuffer();
  895.  
  896.     DeleteSpeech();
  897.  
  898.     Forbid();
  899.  
  900.     BufferClosed = TRUE;
  901.  
  902.     if(BufferLines)
  903.         FreeVec(BufferLines);
  904.  
  905.     if(BufferSemaphore)
  906.         FreeVec(BufferSemaphore);
  907.  
  908.     Permit();
  909.  
  910.     ClearDownloadObjects();
  911.  
  912.     if(DownloadSemaphore)
  913.         FreeVec(DownloadSemaphore);
  914.  
  915.     FreeSubList();
  916.  
  917.     ClearFastMacroList(&FastMacroList);
  918.  
  919.     if(FileCapture)
  920.     {
  921.         BufferClose(FileCapture);
  922.  
  923.         if(!GetFileSize(CaptureName))
  924.             DeleteFile(CaptureName);
  925.         else
  926.             SetProtection(CaptureName,FIBF_EXECUTE);
  927.     }
  928.  
  929.     if(PrinterCapture)
  930.         Close(PrinterCapture);
  931.  
  932.     DeleteEmulator(TRUE);
  933.  
  934.     DeleteDisplay();
  935.  
  936.     if(TimeRequest)
  937.     {
  938.         if(TimeRequest -> tr_node . io_Device)
  939.             CloseDevice(TimeRequest);
  940.  
  941.         if(TimeRequest -> tr_node . io_Message . mn_ReplyPort)
  942.             DeleteMsgPort(TimeRequest -> tr_node . io_Message . mn_ReplyPort);
  943.  
  944.         DeleteIORequest(TimeRequest);
  945.     }
  946.  
  947.     DeleteBeep();
  948.  
  949.     ClearSerial();
  950.  
  951.     DeleteSerial();
  952.  
  953.     ShutdownCx();
  954.  
  955.     if(TermPort)
  956.     {
  957.         if(TermID != -1)
  958.         {
  959.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  960.  
  961.             TermPort -> OpenCount--;
  962.  
  963.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  964.             {
  965.                 RemPort(&TermPort -> ExecNode);
  966.  
  967.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  968.  
  969.                 FreeVec(TermPort);
  970.             }
  971.             else
  972.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  973.         }
  974.     }
  975.  
  976.     if(KeymapBase)
  977.         CloseLibrary(KeymapBase);
  978.  
  979.     if(LayersBase)
  980.         CloseLibrary(LayersBase);
  981.  
  982.     if(CxBase)
  983.         CloseLibrary(CxBase);
  984.  
  985.     if(IFFParseBase)
  986.         CloseLibrary(IFFParseBase);
  987.  
  988.     if(AslBase)
  989.         CloseLibrary(AslBase);
  990.  
  991.     if(DiskfontBase)
  992.         CloseLibrary(DiskfontBase);
  993.  
  994.     if(FakeInputEvent)
  995.         FreeVec(FakeInputEvent);
  996.  
  997.     if(ConsoleDevice)
  998.         CloseDevice(ConsoleRequest);
  999.  
  1000.     if(ConsoleRequest)
  1001.         FreeVec(ConsoleRequest);
  1002.  
  1003.     if(IBM)
  1004.         CloseFont(IBM);
  1005.  
  1006.     if(GFX)
  1007.         CloseFont(GFX);
  1008.  
  1009.     if(Topaz)
  1010.         CloseFont(Topaz);
  1011.  
  1012.     if(RexxSysBase)
  1013.         CloseLibrary(RexxSysBase);
  1014.  
  1015.     if(GadToolsBase)
  1016.         CloseLibrary(GadToolsBase);
  1017.  
  1018.     if(UtilityBase)
  1019.         CloseLibrary(UtilityBase);
  1020.  
  1021.     if(GfxBase)
  1022.         CloseLibrary(GfxBase);
  1023.  
  1024.     if(IntuitionBase)
  1025.         CloseLibrary(IntuitionBase);
  1026.  
  1027.     if(RemoteCurrentDir)
  1028.         UnLock(RemoteCurrentDir);
  1029.  
  1030.     if(DOSBase)
  1031.         CloseLibrary(DOSBase);
  1032.  
  1033.     if(WBenchMsg)
  1034.     {
  1035.         Forbid();
  1036.  
  1037.         ReplyMsg((struct Message *)WBenchMsg);
  1038.     }
  1039. }
  1040.  
  1041.     /* OpenAll():
  1042.      *
  1043.      *    Open all required resources or return an error message
  1044.      *    if anything went wrong.
  1045.      */
  1046.  
  1047. UBYTE *
  1048. OpenAll()
  1049. {
  1050.     UBYTE         PathBuffer[256];
  1051.     struct MsgPort    *IOPort;
  1052.     WORD         i;
  1053.     UBYTE        *Result;
  1054.  
  1055.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  1056.         return("Failed to open intuition.library");
  1057.  
  1058.     if((SysBase -> SoftVer < 175 && SysBase -> LibNode . lib_Version == 37) || SysBase -> LibNode . lib_Version < 37)
  1059.     {
  1060.         if(!MyEasyRequest(NULL,"This   nifty  little  program  requires  Kickstart\nversion 37.175 or higher to work properly.  You are\ncurrently  using Kickstart version %ld.%ld, do you\nreally wish to continue???",
  1061.             "Proceed with fingers crossed|Back out backwards!",SysBase -> LibNode . lib_Version,SysBase -> SoftVer))
  1062.                 return("");
  1063.     }
  1064.  
  1065.     PublicModes = SetPubScreenModes(0);
  1066.  
  1067.     SetPubScreenModes(PublicModes);
  1068.  
  1069.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  1070.         return("Failed to open graphics.library");
  1071.  
  1072.     if(!(UtilityBase = OpenLibrary("utility.library",0)))
  1073.         return("Failed to open utility.library");
  1074.  
  1075.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  1076.         return("Failed to open gadtools.library");
  1077.  
  1078.     if(!(AslBase = OpenLibrary("asl.library",0)))
  1079.         return("Failed to open asl.library");
  1080.  
  1081.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  1082.         return("Failed to open iffparse.library");
  1083.  
  1084.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  1085.         return("Failed to open commodities.library");
  1086.  
  1087.     if(!(KeymapBase = OpenLibrary("keymap.library",0)))
  1088.         return("Failed to open keymap.library");
  1089.  
  1090.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  1091.         return("Failed to open layers.library");
  1092.  
  1093.     if(!(Topaz = (struct TextFont *)OpenFont(&DefaultFont)))
  1094.         return("Failed to open default font");
  1095.  
  1096.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVec(sizeof(struct IOStdReq),MEMF_PUBLIC|MEMF_CLEAR)))
  1097.         return("Failed to allocate console request");
  1098.  
  1099.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  1100.         return("Failed to open console.device");
  1101.  
  1102.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  1103.  
  1104.     if(!(FakeInputEvent = (struct InputEvent *)AllocVec(sizeof(struct InputEvent),MEMF_PUBLIC|MEMF_CLEAR)))
  1105.         return("Failed to allocate InputEvent");
  1106.  
  1107.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  1108.  
  1109.     if(!(MacroKeys = (struct MacroKeys *)AllocVec(sizeof(struct MacroKeys),MEMF_PUBLIC|MEMF_CLEAR)))
  1110.         return("Failed to allocate MacroKeys");
  1111.  
  1112.     if(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0))
  1113.     {
  1114.         if(!(IBM = (struct TextFont *)OpenFont(&IBMFont)))
  1115.             IBM = (struct TextFont *)OpenDiskFont(&IBMFont);
  1116.  
  1117.         if(!(GFX = (struct TextFont *)OpenFont(&GFXFont)))
  1118.             GFX = (struct TextFont *)OpenDiskFont(&GFXFont);
  1119.     }
  1120.  
  1121.         /* Initialize the data flow parser. */
  1122.  
  1123.     FlowInit();
  1124.  
  1125.         /* Obtain the default environment storage
  1126.          * path.
  1127.          */
  1128.  
  1129.     if(!GetEnvDOS("TERMPATH",PathBuffer))
  1130.     {
  1131.         APTR LastPtr = ThisProcess -> pr_WindowPtr;
  1132.         BPTR FileLock;
  1133.  
  1134.         strcpy(PathBuffer,"ENVARC:term");
  1135.  
  1136.         SetEnvDOS("TERMPATH",PathBuffer);
  1137.  
  1138.         ThisProcess -> pr_WindowPtr = (APTR)-1;
  1139.  
  1140.         if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  1141.             FileLock = CreateDir(PathBuffer);
  1142.  
  1143.         if(FileLock)
  1144.             UnLock(FileLock);
  1145.  
  1146.         ThisProcess -> pr_WindowPtr = LastPtr;
  1147.     }
  1148.  
  1149.         /* Create proper path names. */
  1150.  
  1151.     strcpy(LastConfig,PathBuffer);
  1152.  
  1153.     AddPart(LastConfig,"Preferences.term",256);
  1154.  
  1155.     strcpy(DefaultPubScreen,"Workbench");
  1156.  
  1157.         /* Read some more environment variables. */
  1158.  
  1159.     if(!GetEnvDOS("TERMWINDOW",WindowName))
  1160.         strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREENTERM");
  1161.  
  1162.     GetEnvDOS("EDITOR",Config . Editor);
  1163.  
  1164.         /* Look for the default configuration file. */
  1165.  
  1166.     if(!ReadIFFData(LastConfig,&Config,sizeof(struct Configuration),'PREF'))
  1167.     {
  1168.         SetPrefToDefaults(&Config,PathBuffer);
  1169.  
  1170.         Initializing = TRUE;
  1171.  
  1172.         LoadColours = TRUE;
  1173.     }
  1174.     else
  1175.     {
  1176.         switch(Config . ColourMode)
  1177.         {
  1178.             case COLOUR_EIGHT:    CopyMem(&Config . Colours[0],&ANSIColours[0],16 * sizeof(UWORD));
  1179.                         break;
  1180.  
  1181.             case COLOUR_SIXTEEN:    CopyMem(&Config . Colours[0],&EGAColours[0],16 * sizeof(UWORD));
  1182.                         break;
  1183.  
  1184.             case COLOUR_AMIGA:    CopyMem(&Config . Colours[0],&DefaultColours[0],16 * sizeof(UWORD));
  1185.                         break;
  1186.  
  1187.             case COLOUR_MONO:    CopyMem(&Config . Colours[0],&AtomicColours[0],16 * sizeof(UWORD));
  1188.                         break;
  1189.         }
  1190.  
  1191.         if(Config . ColourMode == COLOUR_AMIGA)
  1192.             Initializing = FALSE;
  1193.         else
  1194.             Initializing = TRUE;
  1195.     }
  1196.  
  1197.     NewList(&FastMacroList);
  1198.  
  1199.     strcpy(LastPhone,Config . DefaultStorage);
  1200.     strcpy(LastMacros,Config . DefaultStorage);
  1201.     strcpy(LastKeys,Config . DefaultStorage);
  1202.     strcpy(LastSpeech,Config . DefaultStorage);
  1203.     strcpy(LastFastMacros,Config . DefaultStorage);
  1204.  
  1205.     AddPart(LastPhone,"Phonebook.term",256);
  1206.     AddPart(LastMacros,"Macros.term",256);
  1207.     AddPart(LastKeys,"Hotkeys.term",256);
  1208.     AddPart(LastSpeech,"Speech.term",256);
  1209.     AddPart(LastFastMacros,"Fast!Macros.term",256);
  1210.  
  1211.         /* Load the keyboard macros. */
  1212.  
  1213.     if(!LoadMacros(LastMacros,MacroKeys))
  1214.     {
  1215.         for(i = 0 ; i < 4 ; i++)
  1216.             strcpy(MacroKeys -> Keys[1][i],FunctionKeyCodes[i]);
  1217.     }
  1218.  
  1219.         /* Load the fast! macro settings. */
  1220.  
  1221.     LoadFastMacros(LastFastMacros);
  1222.  
  1223.         /* Load the phone book. */
  1224.  
  1225.     LoadPhonebook(LastPhone);
  1226.  
  1227.         /* Load the speech settings. */
  1228.  
  1229.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),'SPEK'))
  1230.     {
  1231.         SpeechConfig . Rate        = DEFRATE;
  1232.         SpeechConfig . Pitch        = DEFPITCH;
  1233.         SpeechConfig . Frequency    = DEFFREQ;
  1234.         SpeechConfig . Volume        = DEFVOL;
  1235.         SpeechConfig . Sex        = DEFSEX;
  1236.         SpeechConfig . Enabled        = FALSE;
  1237.     }
  1238.  
  1239.         /* Load the hotkey settings. */
  1240.  
  1241.     if(!ReadIFFData(LastKeys,&Hotkeys,sizeof(struct Hotkeys),'HOTK'))
  1242.     {
  1243.         strcpy(Hotkeys . termScreenToFront,"lshift rshift return");
  1244.         strcpy(Hotkeys . BufferScreenToFront,"control rshift return");
  1245.         strcpy(Hotkeys . SkipDialEntry,"control lshift rshift return");
  1246.  
  1247.         Hotkeys . CommodityPriority = 0;
  1248.         Hotkeys . HotkeysEnabled = TRUE;
  1249.     }
  1250.  
  1251.         /* Set up the serial driver. */
  1252.  
  1253.     if(!CreateSerial())
  1254.     {
  1255.         MyEasyRequest(NULL,"`term' has a problem:\nFailed to open %s!","Continue",Config . SerialDevice);
  1256.  
  1257.         DeleteSerial();
  1258.     }
  1259.  
  1260.         /* Load alternative beep sound if desired. */
  1261.  
  1262.     if(Config . BeepSound[0])
  1263.         OpenSound(Config . BeepSound);
  1264.  
  1265.     if(!CreateBeep())
  1266.         return("Failed to open audio.device");
  1267.  
  1268.     if(!(IOPort = (struct MsgPort *)CreateMsgPort()))
  1269.         return("Failed to create msgport");
  1270.  
  1271.     if(!(IOPort = (struct MsgPort *)CreateMsgPort()))
  1272.         return("Failed to create msgport");
  1273.  
  1274.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(IOPort,sizeof(struct timerequest))))
  1275.     {
  1276.         DeleteMsgPort(IOPort);
  1277.         return("Failed to create iorequest");
  1278.     }
  1279.  
  1280.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  1281.         return("Failed to open timer.device");
  1282.  
  1283.     TimerBase = (struct Device *)TimeRequest -> tr_node . io_Device;
  1284.  
  1285.     ClipProcess = CreateNewProcTags(
  1286.         NP_Entry,    ClipServer,
  1287.         NP_Name,    "term Clipboard Server",
  1288.         NP_WindowPtr,    -1,
  1289.         NP_Priority,    20,
  1290.     TAG_DONE);
  1291.  
  1292.     Wait(SIGBREAKF_CTRL_C);
  1293.  
  1294.     if(!ClipProcess)
  1295.         return("Failed to create clipboard server");
  1296.  
  1297.         /* Add the global term port. */
  1298.  
  1299.     if(!TermPort)
  1300.     {
  1301.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort),MEMF_PUBLIC|MEMF_CLEAR)))
  1302.             return("Failed to create global port");
  1303.  
  1304.         NewList(&TermPort -> ExecNode . mp_MsgList);
  1305.  
  1306.         InitSemaphore(&TermPort -> OpenSemaphore);
  1307.  
  1308.         TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  1309.         TermPort -> ExecNode . mp_Node . ln_Name    = "term Port";
  1310.  
  1311.         AddPort(&TermPort -> ExecNode);
  1312.     }
  1313.  
  1314.         /* Keep another term task from removing the port. */
  1315.  
  1316.     TermPort -> HoldIt = TRUE;
  1317.  
  1318.         /* Install a new term process. */
  1319.  
  1320.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  1321.  
  1322.     TermPort -> OpenCount++;
  1323.  
  1324.     TermPort -> HoldIt = FALSE;
  1325.  
  1326.     TermID = TermPort -> ID++;
  1327.  
  1328.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  1329.  
  1330.         /* Set up the ID string. */
  1331.  
  1332.     if(TermID)
  1333.         SPrintf(TermIDString,"TERM%ld",TermID);
  1334.     else
  1335.         strcpy(TermIDString,"TERM");
  1336.  
  1337.         /* Install the hotkey handler. */
  1338.  
  1339.     SetupCx();
  1340.  
  1341.         /* Create the speech data. */
  1342.  
  1343.     CreateSpeech();
  1344.  
  1345.         /* Allocate the first few lines for the display buffer. */
  1346.  
  1347.     if(!(BufferLines = (UBYTE **)AllocVec(MaxLines * sizeof(UBYTE *),MEMF_PUBLIC|MEMF_CLEAR)))
  1348.         return("Failed to allocate view buffer");
  1349.  
  1350.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_PUBLIC|MEMF_CLEAR)))
  1351.         return("Failed to create protocol buffer");
  1352.  
  1353.     if(!(FileAnchor = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath),MEMF_PUBLIC|MEMF_CLEAR)))
  1354.         return("Failed to create anchor path");
  1355.  
  1356.         /* Create the download list access semaphore. */
  1357.  
  1358.     if(!(DownloadSemaphore = (struct SignalSemaphore *)AllocVec(sizeof(struct SignalSemaphore),MEMF_PUBLIC|MEMF_CLEAR)))
  1359.         return("Failed to allocate semaphore");
  1360.  
  1361.     InitSemaphore(DownloadSemaphore);
  1362.  
  1363.     NewList(&SequenceList);
  1364.     NewList(&PacketHistoryList);
  1365.     NewList(&DownloadList);
  1366.  
  1367.         /* Create the buffer access semaphore. */
  1368.  
  1369.     if(!(BufferSemaphore = (struct SignalSemaphore *)AllocVec(sizeof(struct SignalSemaphore),MEMF_PUBLIC|MEMF_CLEAR)))
  1370.         return("Failed to allocate semaphore");
  1371.  
  1372.     InitSemaphore(BufferSemaphore);
  1373.  
  1374.     strcpy(LastXprLibrary,Config . Protocol);
  1375.  
  1376.     ProtocolSetup();
  1377.  
  1378.         /* Double buffered file locking. */
  1379.  
  1380.     NewList(&DoubleBufferList);
  1381.     InitSemaphore(&DoubleBufferSemaphore);
  1382.  
  1383.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  1384.         return("Failed to create msgport");
  1385.  
  1386.         /* If rexxsyslib.library opens cleanly it's time for
  1387.          * us to create the background term Rexx server.
  1388.          */
  1389.  
  1390.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  1391.     {
  1392.             /* Create a background process handling the
  1393.              * rexx messages asynchronously.
  1394.              */
  1395.  
  1396.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  1397.             NP_Entry,    RexxServer,
  1398.             NP_Name,    "term Rexx Process",
  1399.             NP_Priority,    5,
  1400.             NP_StackSize,    8192,
  1401.             NP_WindowPtr,    -1,
  1402.         TAG_END))
  1403.         {
  1404.             Wait(SIGBREAKF_CTRL_C);
  1405.  
  1406.             if(!RexxProcess)
  1407.                 return("Unable to create rexx process");
  1408.         }
  1409.     }
  1410.  
  1411.     BinaryTransfer    = TRUE;
  1412.  
  1413.     Status        = STATUS_READY;
  1414.     Online        = FALSE;
  1415.  
  1416.     InSequence    = FALSE;
  1417.     Quiet        = FALSE;
  1418.  
  1419.     memset(&SpecialMap[0],-1,256);
  1420.  
  1421.     for(i = 0 ; i < SPECIALKEYS ; i++)
  1422.         SpecialMap[SpecialKeys[i] . Key] = i;
  1423.  
  1424.     InitHook(&CommandHook,CommandKey);
  1425.  
  1426.         /* Create the whole display. */
  1427.  
  1428.     if(Result = CreateDisplay(TRUE))
  1429.         return(Result);
  1430.     else
  1431.     {
  1432.         if(Config . RasterEnabled)
  1433.         {
  1434.             OnMenu(Window,FULLMENUNUM(0,4,0));
  1435.             OnMenu(Window,FULLMENUNUM(5,5,0));
  1436.         }
  1437.         else
  1438.         {
  1439.             OffMenu(Window,FULLMENUNUM(0,4,0));
  1440.             OffMenu(Window,FULLMENUNUM(5,5,0));
  1441.         }
  1442.  
  1443.         return(NULL);
  1444.     }
  1445. }
  1446.