home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 550b.lha / Term_v1.8a / Source.LZH / Packet.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  19KB  |  845 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: Packet.c
  6.  *    Created ..: Wednesday 06-Feb-91 12:35
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    06-Feb-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* Some private data required to handle both the window,
  18.      * the editing functions and the command history buffer.
  19.      */
  20.  
  21. STATIC struct Hook         PacketHook;
  22. STATIC UBYTE             PacketWorkBuffer[256];
  23. STATIC struct StringInfo    *PacketInfo;
  24.  
  25. STATIC struct Node        *PacketNode;
  26. STATIC LONG             PacketLine;
  27.  
  28. STATIC LONG             PacketX = -1,PacketY = -1,PacketWidth = -1,PacketHeight = -1;
  29.  
  30. struct StringExtend PacketExtend =
  31. {
  32.     (struct TextFont *)NULL,
  33.     1,0,
  34.     1,0,
  35.     SGM_NOFILTER,
  36.     &PacketHook,
  37.     PacketWorkBuffer
  38. };
  39.  
  40.     /* The menu to attach to the packet window. */
  41.  
  42. enum    {    MEN_LOADHISTORY=1,MEN_SAVEHISTORY,MEN_CLEARHISTORY,MEN_OTHERWINDOW,MEN_QUITPANEL };
  43.  
  44. STATIC struct NewMenu NewPacketMenu[] =
  45. {
  46.     { NM_TITLE, "Project",         0 , 0, 0, (APTR)0},
  47.     {  NM_ITEM, "Load History...",    "O", 0, 0, (APTR)MEN_LOADHISTORY},
  48.     {  NM_ITEM, "Save History...",    "S", 0, 0, (APTR)MEN_SAVEHISTORY},
  49.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  50.     {  NM_ITEM, "Clear History",    "K", 0, 0, (APTR)MEN_CLEARHISTORY},
  51.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  52.     {  NM_ITEM, "Other Window",    "-", 0, 0, (APTR)MEN_OTHERWINDOW},
  53.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  54.     {  NM_ITEM, "Quit",        "Q", 0, 0, (APTR)MEN_QUITPANEL},
  55.     { NM_END, 0,             0 , 0, 0, (APTR)0}
  56. };
  57.  
  58.     /* ClearPacketHistory():
  59.      *
  60.      *    Release the command history.
  61.      */
  62.  
  63. VOID
  64. ClearPacketHistory()
  65. {
  66.     struct Node *SomeNode,*NextNode;
  67.  
  68.     SomeNode = PacketHistoryList . lh_Head;
  69.  
  70.     while(SomeNode -> ln_Succ)
  71.     {
  72.         NextNode = SomeNode -> ln_Succ;
  73.  
  74.         Remove(SomeNode);
  75.  
  76.         FreeVec(SomeNode);
  77.  
  78.         SomeNode = NextNode;
  79.     }
  80.  
  81.     PacketNode = PacketHistoryList . lh_Head;
  82.  
  83.     PacketLine = 0;
  84. }
  85.  
  86.     /* DeletePacketWindow():
  87.      *
  88.      *    Delete the packet window and release the command
  89.      *    history.
  90.      */
  91.  
  92. VOID
  93. DeletePacketWindow()
  94. {
  95.     if(PacketWindow)
  96.     {
  97.         PacketWindow -> Flags |= WFLG_RMBTRAP;
  98.  
  99.         ClearMenuStrip(PacketWindow);
  100.  
  101.         if(PacketGadgetList)
  102.             RemoveGList(PacketWindow,PacketGadgetList,(UWORD)-1);
  103.  
  104.         PacketX        = PacketWindow -> LeftEdge;
  105.         PacketY        = PacketWindow -> TopEdge;
  106.  
  107.         PacketWidth    = PacketWindow -> Width;
  108.         PacketHeight    = PacketWindow -> Height;
  109.  
  110.         CloseWindow(PacketWindow);
  111.  
  112.         PacketWindow = NULL;
  113.     }
  114.  
  115.     if(PacketGadgetList)
  116.     {
  117.         FreeGadgets(PacketGadgetList);
  118.  
  119.         PacketGadgetList = NULL;
  120.     }
  121.  
  122.     ClearPacketHistory();
  123.  
  124.     if(PacketMenu)
  125.     {
  126.         FreeMenus(PacketMenu);
  127.  
  128.         PacketMenu = NULL;
  129.     }
  130. }
  131.  
  132.     /* AddPacketHistory(UBYTE *Buffer):
  133.      *
  134.      *    Add a line to the packet window command history. This
  135.      *    works very much the same as the AddLine()-routine.
  136.      */
  137.  
  138. VOID
  139. AddPacketHistory(UBYTE *Buffer)
  140. {
  141.     struct Node *SomeNode;
  142.  
  143.     if(SomeNode = (struct Node *)AllocVec(sizeof(struct Node) + strlen(Buffer) + 1,MEMF_PUBLIC|MEMF_CLEAR))
  144.     {
  145.         SomeNode -> ln_Name = (UBYTE *)(SomeNode + 1);
  146.  
  147.         strcpy(SomeNode -> ln_Name,Buffer);
  148.  
  149.         AddTail(&PacketHistoryList,SomeNode);
  150.  
  151.         PacketNode = NULL;
  152.  
  153.         PacketLine++;
  154.     }
  155. }
  156.  
  157.     /* CreateAllGadgets():
  158.      *
  159.      *    Create the packet string gadget.
  160.      */
  161.  
  162. STATIC struct Gadget *
  163. CreateAllGadgets(LONG Width,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
  164. {
  165.     struct Gadget        *Gadget;
  166.     struct NewGadget     NewGadget;
  167.  
  168.     if(Gadget = CreateContext(GadgetList))
  169.     {
  170.         NewGadget . ng_Width        = Width - 26;
  171.         NewGadget . ng_Height        = PacketHeight - 15;
  172.         NewGadget . ng_GadgetText    = NULL;
  173.         NewGadget . ng_TextAttr        = &DefaultFont;
  174.         NewGadget . ng_VisualInfo    = VisualInfo;
  175.         NewGadget . ng_GadgetID        = 0;
  176.         NewGadget . ng_Flags        = 0;
  177.         NewGadget . ng_LeftEdge        = 6;
  178.         NewGadget . ng_TopEdge        = 1 + TopEdge;
  179.  
  180.         GadgetArray[0] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  181.             GTST_MaxChars,    256,
  182.             GA_TabCycle,    FALSE,
  183.         TAG_DONE);
  184.  
  185.         if(Gadget)
  186.             SGEXT(Gadget,&PacketExtend);
  187.     }
  188.  
  189.     return(Gadget);
  190. }
  191.  
  192.     /* CreatePacketWindow():
  193.      *
  194.      *    Open the packet window and allocate the command history
  195.      *    buffer.
  196.      */
  197.  
  198. BYTE
  199. CreatePacketWindow()
  200. {
  201.     PacketNode = PacketHistoryList . lh_Head;
  202.  
  203.     switch(Config . ColourMode)
  204.     {
  205.         case COLOUR_EIGHT:    PacketExtend . Pens[0]        = ANSIPens[1];
  206.                     PacketExtend . Pens[1]        = ANSIPens[0];
  207.  
  208.                     PacketExtend . ActivePens[0]    = ANSIPens[1];
  209.                     PacketExtend . ActivePens[1]    = ANSIPens[3];
  210.  
  211.                     break;
  212.  
  213.         case COLOUR_SIXTEEN:    PacketExtend . Pens[0]        = EGAPens[1];
  214.                     PacketExtend . Pens[1]        = EGAPens[0];
  215.  
  216.                     PacketExtend . ActivePens[0]    = EGAPens[1];
  217.                     PacketExtend . ActivePens[1]    = EGAPens[3];
  218.  
  219.                     break;
  220.  
  221.         case COLOUR_AMIGA:
  222.         default:        PacketExtend . Pens[0]        = 1;
  223.                     PacketExtend . Pens[1]        = 0;
  224.  
  225.                     if(Config . ColourMode != COLOUR_MONO)
  226.                     {
  227.                         PacketExtend . ActivePens[0]    = 1;
  228.                         PacketExtend . ActivePens[1]    = 2;
  229.                     }
  230.                     else
  231.                     {
  232.                         PacketExtend . ActivePens[0]    = 1;
  233.                         PacketExtend . ActivePens[1]    = 0;
  234.                     }
  235.  
  236.                     break;
  237.     }
  238.  
  239.     if(PacketMenu = CreateMenus(NewPacketMenu,
  240.         GTMN_FrontPen, 0,
  241.     TAG_DONE))
  242.     {
  243.         if(LayoutMenus(PacketMenu,VisualInfo,
  244.             GTMN_TextAttr,&DefaultFont,
  245.         TAG_DONE))
  246.         {
  247.             if(PacketWidth == -1)
  248.                 PacketWidth = Screen -> Width;
  249.  
  250.             if(PacketHeight == -1)
  251.                 PacketHeight = 29;
  252.  
  253.             if(PacketX == -1 || (PacketX + PacketWidth > Screen -> Width))
  254.             {
  255.                 PacketX = 0;
  256.  
  257.                 if(PacketX + PacketWidth > Screen -> Width)
  258.                     PacketWidth = Screen -> Width;
  259.             }
  260.  
  261.             if(PacketY == -1 || (PacketY + PacketHeight > Screen -> Height))
  262.             {
  263.                 PacketY = Window -> TopEdge + Window -> Height;
  264.  
  265.                 if(PacketY + PacketHeight > Screen -> Height)
  266.                     PacketHeight = 29;
  267.             }
  268.  
  269.             if(CreateAllGadgets(PacketWidth,&PacketGadgetArray[0],&PacketGadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
  270.             {
  271.                 if(PacketWindow = OpenWindowTags(NULL,
  272.                     WA_Width,    PacketWidth,
  273.                     WA_Height,    PacketHeight,
  274.  
  275.                     WA_Left,    PacketX,
  276.                     WA_Top,        PacketY,
  277.  
  278.                     WA_Activate,    TRUE,
  279.                     WA_DragBar,    TRUE,
  280.                     WA_DepthGadget,    TRUE,
  281.                     WA_CloseGadget,    TRUE,
  282.                     WA_RMBTrap,    TRUE,
  283.                     WA_SizeGadget,    TRUE,
  284.                     WA_MinWidth,    80,
  285.                     WA_MinHeight,    29,
  286.                     WA_MaxWidth,    Screen -> Width,
  287.                     WA_MaxHeight,    29,
  288.                     WA_CustomScreen,Screen,
  289.  
  290.                     WA_IDCMP,    STRINGIDCMP | IDCMP_NEWSIZE | IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | IDCMP_ACTIVEWINDOW | IDCMP_RAWKEY,
  291.  
  292.                     WA_Title,    "Packet Window",
  293.                 TAG_DONE))
  294.                 {
  295.                     PacketExtend . Font = Topaz;
  296.  
  297.                     InitHook(&PacketHook,PacketKey);
  298.  
  299.                     PacketInfo = (struct StringInfo *)PacketGadgetArray[0] -> SpecialInfo;
  300.  
  301.                     AddGList(PacketWindow,PacketGadgetList,(UWORD)-1,(UWORD)-1,NULL);
  302.                     RefreshGList(PacketGadgetList,PacketWindow,NULL,(UWORD)-1);
  303.                     GT_RefreshWindow(PacketWindow,NULL);
  304.  
  305.                     SetMenuStrip(PacketWindow,PacketMenu);
  306.  
  307.                     PacketWindow -> Flags &= ~WFLG_RMBTRAP;
  308.  
  309.                     ActivateGadget(PacketGadgetArray[0],PacketWindow,NULL);
  310.                     return(TRUE);
  311.                 }
  312.             }
  313.         }
  314.     }
  315.  
  316.     DeletePacketWindow();
  317.  
  318.     return(FALSE);
  319. }
  320.  
  321.     /* PacketKey(struct Hook *Hook,struct SGWork *Work,ULONG *Msg):
  322.      *
  323.      *    This is a string gadget editing call back routine
  324.      *    (a so-called `hook') which is to perform all the
  325.      *    line editing and command history actions supported
  326.      *    by the packet window.
  327.      */
  328.  
  329. VOID
  330. PacketKey(struct Hook *Hook,struct SGWork *Work,ULONG *Msg)
  331. {
  332.         /* Someone activated the string gadget and
  333.          * hit a key.
  334.          */
  335.  
  336.     if(Msg[0] == SGH_KEY)
  337.     {
  338.             /* Right-Amiga-key was pressed, release the
  339.              * string gadget so user may select a menu
  340.              * item.
  341.              */
  342.  
  343.         if((Work -> IEvent -> ie_Qualifier & AMIGARIGHT) && Work -> IEvent -> ie_Code < 96)
  344.         {
  345.             if(!(Work -> IEvent -> ie_Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)) && (Work -> IEvent -> ie_Code == KEYCODE_X || Work -> IEvent -> ie_Code == KEYCODE_Q))
  346.                 return;
  347.             else
  348.             {
  349.                 Work -> Actions |= (SGA_END|SGA_REUSE);
  350.                 Work -> Actions &= ~(SGA_USE|SGA_BEEP);
  351.  
  352.                 CommandWindow = Work -> GadgetInfo -> gi_Window;
  353.                 CommandGadget = Work -> Gadget;
  354.             }
  355.         }
  356.  
  357.             /* The user pressed the cursor-right key to
  358.              * move the cursor to the next word in the buffer.
  359.              */
  360.  
  361.         if(Work -> IEvent -> ie_Code == CURSORRIGHT && (Work -> IEvent -> ie_Qualifier & IEQUALIFIER_CONTROL))
  362.         {
  363.             if(Work -> BufferPos != Work -> NumChars)
  364.             {
  365.                 SHORT i,Position = -1;
  366.  
  367.                 for(i = Work -> BufferPos ; i < Work -> NumChars ; i++)
  368.                 {
  369.                     if(Work -> WorkBuffer[i] == ' ')
  370.                     {
  371.                         for( ; i < Work -> NumChars ; i++)
  372.                         {
  373.                             if(Work -> WorkBuffer[i] != ' ')
  374.                             {
  375.                                 Position = i;
  376.                                 break;
  377.                             }
  378.                         }
  379.  
  380.                         break;
  381.                     }
  382.                 }
  383.  
  384.                 if(Position != -1)
  385.                     Work -> BufferPos = Position;
  386.                 else
  387.                     Work -> BufferPos = Work -> NumChars;
  388.  
  389.                 Work -> EditOp = EO_MOVECURSOR;
  390.             }
  391.         }
  392.  
  393.             /* The user pressed the cursor-right key to
  394.              * move the cursor to the previous word in the buffer.
  395.              */
  396.  
  397.         if(Work -> IEvent -> ie_Code == CURSORLEFT && (Work -> IEvent -> ie_Qualifier & IEQUALIFIER_CONTROL))
  398.         {
  399.             if(Work -> BufferPos)
  400.             {
  401.                 SHORT i,Position = -1;
  402.  
  403.                 for(i = Work -> BufferPos ; i >= 0 ; i--)
  404.                 {
  405.                     if(Work -> WorkBuffer[i] != ' ')
  406.                     {
  407.                         Position = i;
  408.                         break;
  409.                     }
  410.                 }
  411.  
  412.                 if(Position == -1)
  413.                     Position = 0;
  414.  
  415.                 if(Position)
  416.                 {
  417.                     i = Position;
  418.  
  419.                     Position = -1;
  420.  
  421.                     for( ; i >= 0 ; i--)
  422.                     {
  423.                         if(Work -> WorkBuffer[i] == ' ')
  424.                         {
  425.                             Position = i + 1;
  426.                             break;
  427.                         }
  428.                     }
  429.                 }
  430.  
  431.                 if(Position != -1)
  432.                     Work -> BufferPos = Position;
  433.                 else
  434.                     Work -> BufferPos = 0;
  435.  
  436.                 Work -> EditOp = EO_MOVECURSOR;
  437.             }
  438.         }
  439.  
  440.             /* The user pressed the cursor-up key to
  441.              * scroll through the command history.
  442.              */
  443.  
  444.         if(Work -> IEvent -> ie_Code == CURSORUP)
  445.         {
  446.                 /* Shift key: jump to first command
  447.                  * history entry.
  448.                  */
  449.  
  450.             if(Work -> IEvent -> ie_Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  451.             {
  452.                 PacketNode = PacketHistoryList . lh_Head;
  453.  
  454.                 if(PacketNode -> ln_Succ)
  455.                 {
  456.                     Work -> WorkBuffer    = PacketNode -> ln_Name;
  457.                     Work -> NumChars    = strlen(Work -> WorkBuffer);
  458.                     Work -> EditOp        = EO_BIGCHANGE;
  459.                 }
  460.             }
  461.             else
  462.             {
  463.                 BYTE TakeIt = FALSE;
  464.  
  465.                 if(!PacketNode)
  466.                 {
  467.                     PacketNode = PacketHistoryList . lh_TailPred;
  468.  
  469.                     if(PacketNode -> ln_Succ)
  470.                         TakeIt = TRUE;
  471.                 }
  472.                 else
  473.                 {
  474.                     if(PacketNode -> ln_Pred -> ln_Pred)
  475.                     {
  476.                         PacketNode = PacketNode -> ln_Pred;
  477.  
  478.                         TakeIt = TRUE;
  479.                     }
  480.                 }
  481.  
  482.                 if(TakeIt)
  483.                 {
  484.                     /* Jump to previous command
  485.                      * history entry.
  486.                      */
  487.  
  488.                     Work -> WorkBuffer    = PacketNode -> ln_Name;
  489.                     Work -> NumChars    = strlen(Work -> WorkBuffer);
  490.  
  491.                     Work -> EditOp = EO_BIGCHANGE;
  492.                 }
  493.             }
  494.         }
  495.  
  496.             /* The user pressed the cursor-down key to
  497.              * scroll through the command history.
  498.              */
  499.  
  500.         if(Work -> IEvent -> ie_Code == CURSORDOWN)
  501.         {
  502.                 /* Shift key: jump to last command
  503.                  * history entry.
  504.                  */
  505.  
  506.             if(Work -> IEvent -> ie_Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  507.             {
  508.                 if(PacketHistoryList . lh_Head -> ln_Succ)
  509.                 {
  510.                     PacketNode = PacketHistoryList . lh_TailPred;
  511.  
  512.                     if(PacketNode -> ln_Succ)
  513.                         Work -> WorkBuffer = PacketNode -> ln_Name;
  514.                     else
  515.                         Work -> WorkBuffer = "";
  516.  
  517.                     Work -> EditOp        = EO_BIGCHANGE;
  518.                     Work -> NumChars    = strlen(Work -> WorkBuffer);
  519.                 }
  520.             }
  521.             else
  522.             {
  523.                 if(PacketNode)
  524.                 {
  525.                     if(PacketNode -> ln_Succ)
  526.                     {
  527.                         PacketNode = PacketNode -> ln_Succ;
  528.  
  529.                         Work -> WorkBuffer = PacketNode -> ln_Name;
  530.                     }
  531.                     else
  532.                         Work -> WorkBuffer = "";
  533.  
  534.                     Work -> EditOp        = EO_BIGCHANGE;
  535.                     Work -> NumChars    = strlen(Work -> WorkBuffer);
  536.                 }
  537.             }
  538.         }
  539.     }
  540. }
  541.  
  542.     /* HandlePacket():
  543.      *
  544.      *    Process the input coming through the packet window.
  545.      */
  546.  
  547. BYTE
  548. HandlePacket()
  549. {
  550.     struct IntuiMessage    *Massage;
  551.     ULONG             Class,Code;
  552.     struct Gadget        *Gadget;
  553.     struct FileRequest    *FileRequest;
  554.     UBYTE             DummyBuffer[256];
  555.     BYTE             SwapWindow = FALSE;
  556.  
  557.         /* Are we already shut down? */
  558.  
  559.     if(PacketWindow)
  560.     {
  561.         if(Massage = (struct IntuiMessage *)GT_GetIMsg(PacketWindow -> UserPort))
  562.         {
  563.             Class    = Massage -> Class;
  564.             Code    = Massage -> Code;
  565.             Gadget    = (struct Gadget *)Massage -> IAddress;
  566.  
  567.             GT_ReplyIMsg(Massage);
  568.  
  569.                 /* Re-enable the string gadget if necessary. */
  570.  
  571.             if(Class == IDCMP_RAWKEY)
  572.                 if(Code == IECODE_UP_PREFIX|103 && CommandWindow == PacketWindow)
  573.                     ActivateGadget(CommandGadget,PacketWindow,NULL);
  574.  
  575.                 /* Handle the menu. */
  576.  
  577.             if(Class == IDCMP_MENUPICK)
  578.             {
  579.                 struct MenuItem *MenuItem;
  580.  
  581.                 while(Code != MENUNULL)
  582.                 {
  583.                     MenuItem = ItemAddress(PacketMenu,Code);
  584.  
  585.                     switch((ULONG)MENU_USERDATA(MenuItem))
  586.                     {
  587.                         case MEN_QUITPANEL:    Class = IDCMP_CLOSEWINDOW;
  588.                                     break;
  589.  
  590.                         case MEN_LOADHISTORY:    BlockWindows();
  591.  
  592.                                     if(FileRequest = GetFile("Load History...","","",DummyBuffer,NULL,FALSE,FALSE))
  593.                                     {
  594.                                         if(GetFileSize(DummyBuffer))
  595.                                         {
  596.                                             BPTR SomeFile;
  597.  
  598.                                             if(SomeFile = Open(DummyBuffer,MODE_OLDFILE))
  599.                                             {
  600.                                                 if(PacketLine)
  601.                                                 {
  602.                                                     switch(MyEasyRequest(Window,"The packet history still holds %ld\nlines, do you wish to continue?","Discard History|Append History|Cancel",PacketLine))
  603.                                                     {
  604.                                                         case 1:    ClearPacketHistory();
  605.                                                             break;
  606.  
  607.                                                         case 2:    break;
  608.  
  609.                                                         case 0:    Close(SomeFile);
  610.                                                             SomeFile = NULL;
  611.                                                             break;
  612.                                                     }
  613.                                                 }
  614.  
  615.                                                 if(SomeFile)
  616.                                                 {
  617.                                                     LineRead(NULL,NULL,NULL);
  618.  
  619.                                                     while(LineRead(SomeFile,DummyBuffer,255))
  620.                                                         AddPacketHistory(DummyBuffer);
  621.  
  622.                                                     Close(SomeFile);
  623.                                                 }
  624.                                             }
  625.                                         }
  626.                                     }
  627.  
  628.                                     ReleaseWindows();
  629.                                     break;
  630.  
  631.                         case MEN_SAVEHISTORY:    BlockWindows();
  632.  
  633.                                     if(!PacketLine)
  634.                                         MyEasyRequest(Window,"There isn't anything in the\npacket history right now.","Continue");
  635.                                     else
  636.                                     {
  637.                                         if(FileRequest = GetFile("Save History...","","",DummyBuffer,NULL,TRUE,FALSE))
  638.                                         {
  639.                                             BPTR SomeFile = NULL;
  640.  
  641.                                                 /* If the file we are about
  642.                                                  * to create already exists,
  643.                                                  * ask the user whether we are
  644.                                                  * to create, append or skip
  645.                                                  * the file.
  646.                                                  */
  647.  
  648.                                             if(GetFileSize(DummyBuffer))
  649.                                             {
  650.                                                 switch(MyEasyRequest(Window,"File %s already exists!","Create New File|Append Data|Cancel",DummyBuffer))
  651.                                                 {
  652.                                                     case 1:    SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  653.                                                         break;
  654.  
  655.                                                     case 2:    if(SomeFile = Open(DummyBuffer,MODE_READWRITE))
  656.                                                         {
  657.                                                             if(Seek(SomeFile,0,OFFSET_END) == -1)
  658.                                                             {
  659.                                                                 Close(SomeFile);
  660.  
  661.                                                                 SomeFile = NULL;
  662.                                                             }
  663.                                                         }
  664.                                                         break;
  665.                                                 }
  666.                                             }
  667.                                             else
  668.                                                 SomeFile = Open(DummyBuffer,MODE_NEWFILE);
  669.  
  670.                                             if(!SomeFile)
  671.                                                 MyEasyRequest(Window,"Error opening file %s!","Continue",DummyBuffer);
  672.                                             else
  673.                                             {
  674.                                                 struct Node *SomeNode;
  675.  
  676.                                                 SomeNode = PacketHistoryList . lh_Head;
  677.  
  678.                                                 while(SomeNode -> ln_Succ)
  679.                                                 {
  680.                                                     FPrintf(SomeFile,"%s\n",SomeNode -> ln_Name);
  681.  
  682.                                                     SomeNode = SomeNode -> ln_Succ;
  683.                                                 }
  684.  
  685.                                                 Close(SomeFile);
  686.                                             }
  687.  
  688.                                             FreeAslRequest(FileRequest);
  689.                                         }
  690.                                     }
  691.  
  692.                                     ReleaseWindows();
  693.  
  694.                                     break;
  695.  
  696.                         case MEN_CLEARHISTORY:  BlockWindows();
  697.  
  698.                                     ClearPacketHistory();
  699.  
  700.                                     ReleaseWindows();
  701.                                     break;
  702.  
  703.                         case MEN_OTHERWINDOW:    SwapWindow = TRUE;
  704.                                     break;
  705.  
  706.                         default:        break;
  707.                     }
  708.  
  709.                     Code = MenuItem -> NextSelect;
  710.                 }
  711.  
  712.                 ActivateGadget(PacketGadgetArray[0],PacketWindow,NULL);
  713.             }
  714.  
  715.                 /* Shut down. */
  716.  
  717.             if(Class == IDCMP_CLOSEWINDOW)
  718.                 DeletePacketWindow();
  719.  
  720.                 /* Activate the string gadget as well. */
  721.  
  722.             if(Class == IDCMP_ACTIVEWINDOW)
  723.                 ActivateGadget(PacketGadgetArray[0],PacketWindow,NULL);
  724.  
  725.             if(Class == IDCMP_NEWSIZE)
  726.             {
  727.                 PacketWindow -> Flags |= WFLG_RMBTRAP;
  728.  
  729.                 strcpy(DummyBuffer,PacketInfo -> Buffer);
  730.  
  731.                 RemoveGList(PacketWindow,PacketGadgetList,(UWORD)-1);
  732.  
  733.                 FreeGadgets(PacketGadgetList);
  734.  
  735.                 PacketGadgetList = NULL;
  736.  
  737.                 SetAPen(PacketWindow -> RPort,0);
  738.                 RectFill(PacketWindow -> RPort,PacketWindow -> BorderLeft,PacketWindow -> BorderTop,PacketWindow -> Width - PacketWindow -> BorderRight,PacketWindow -> Height - PacketWindow -> BorderBottom);
  739.                 RefreshWindowFrame(PacketWindow);
  740.  
  741.                 if(CreateAllGadgets(PacketWindow -> Width,&PacketGadgetArray[0],&PacketGadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
  742.                 {
  743.                     PacketInfo = (struct StringInfo *)PacketGadgetArray[0] -> SpecialInfo;
  744.  
  745.                     strcpy(PacketInfo -> Buffer,DummyBuffer);
  746.  
  747.                     AddGList(PacketWindow,PacketGadgetList,(UWORD)-1,(UWORD)-1,NULL);
  748.                     RefreshGList(PacketGadgetList,PacketWindow,NULL,(UWORD)-1);
  749.                     GT_RefreshWindow(PacketWindow,NULL);
  750.  
  751.                     PacketWindow -> Flags &= ~WFLG_RMBTRAP;
  752.  
  753.                     ActivateGadget(PacketGadgetArray[0],PacketWindow,NULL);
  754.                 }
  755.                 else
  756.                     DeletePacketWindow();
  757.             }
  758.  
  759.                 /* User has entered a string. */
  760.  
  761.             if(Class == IDCMP_GADGETUP)
  762.             {
  763.                     /* Just pressed Right-Amiga? */
  764.  
  765.                 if(!DontActivate)
  766.                 {
  767.                         /* Is there anything in the buffer at all? */
  768.  
  769.                     if(PacketInfo -> Buffer)
  770.                     {
  771.                             /* Perform selective history (don't
  772.                              * buffer anything that's already
  773.                              * in the command history.
  774.                              */
  775.  
  776.                         if(PacketNode -> ln_Succ)
  777.                         {
  778.                             if(strcmp(PacketNode -> ln_Name,PacketInfo -> Buffer))
  779.                                 AddPacketHistory(PacketInfo -> Buffer);
  780.                             else
  781.                                 PacketNode = NULL;
  782.                         }
  783.                         else
  784.                             AddPacketHistory(PacketInfo -> Buffer);
  785.  
  786.                         strcpy(DummyBuffer,PacketInfo -> Buffer);
  787.  
  788.                             /* Convert alien IBM characters. */
  789.  
  790.                         if(Config . Font == FONT_IBM)
  791.                         {
  792.                             SHORT i;
  793.                             UBYTE Char;
  794.  
  795.                             for(i = 0 ; i < strlen(DummyBuffer) ; i++)
  796.                             {
  797.                                 if(Char = IBMConversion[DummyBuffer[i]])
  798.                                     DummyBuffer[i] = Char;
  799.                             }
  800.                         }
  801.  
  802.                             /* Execute the command. */
  803.  
  804.                         SerialCommand(DummyBuffer);
  805.                     }
  806.  
  807.                         /* Clear the packet window string
  808.                          * gadget.
  809.                          */
  810.  
  811.                     PacketInfo -> Buffer[0] = 0;
  812.  
  813.                     RefreshGList(PacketGadgetList,PacketWindow,NULL,(UWORD)-1);
  814.  
  815.                         /* Send a terminating `CR'. */
  816.  
  817.                     switch(Config . SendCR)
  818.                     {
  819.                         case CR_IGNORE:    break;
  820.  
  821.                         case CR_ASCR:    SerWrite("\r",1);
  822.                                 break;
  823.  
  824.                         case CR_ASCRLF:    SerWrite("\r\n",2);
  825.                                 break;
  826.                     }
  827.  
  828.                         /* Re-activate the string gadget. */
  829.  
  830.                     ActivateGadget(PacketGadgetArray[0],PacketWindow,NULL);
  831.                 }
  832.                 else
  833.                     DontActivate = FALSE;
  834.             }
  835.  
  836.             if(SwapWindow)
  837.                 BumpWindow(Window);
  838.  
  839.             return(TRUE);
  840.         }
  841.     }
  842.  
  843.     return(FALSE);
  844. }
  845.