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 / DialPanel.c < prev    next >
C/C++ Source or Header  |  1991-12-01  |  25KB  |  1,080 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1991 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: DialPanel.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    01-Sep-91       Olsen           Major rewrite.
  12.  *    21-Jan-91       Olsen           Created this file!
  13.  *
  14.  * $Revision Header ********************************************************/
  15.  
  16. #include "TermGlobal.h"
  17.  
  18.     /* Dimensions of the panel window. */
  19.  
  20. #define WIDTH        451
  21. #define HEIGHT        99
  22.  
  23.     /* Rendering offsets into the window. */
  24.  
  25. #define ORIGIN_X    14
  26. #define ORIGIN_Y    14
  27.  
  28.     /* Panel gadget IDs. */
  29.  
  30. enum    {    GAD_SKIP,GAD_ONLINE,GAD_ABORT };
  31.  
  32.     /* Menu item IDs. */
  33.  
  34. enum    {    MEN_SKIP=1,MEN_ONLINE,MEN_ABORT,MEN_QUITPANEL };
  35.  
  36.     /* The menu attached to the dial window. */
  37.  
  38. STATIC struct NewMenu DialMenu[] =
  39. {
  40.     { NM_TITLE, "Project",         0 , 0, 0, (APTR)0},
  41.     {  NM_ITEM, "Skip",        "S", 0, 0, (APTR)MEN_SKIP},
  42.     {  NM_ITEM, "Go To Online",    "G", 0, 0, (APTR)MEN_ONLINE},
  43.     {  NM_ITEM, "Abort Dialing",    "A", 0, 0, (APTR)MEN_ABORT},
  44.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  45.     {  NM_ITEM, "Quit",        "Q", 0, 0, (APTR)MEN_QUITPANEL},
  46.     { NM_END, 0,             0 , 0, 0, (APTR)0}
  47. };
  48.  
  49.     /* CreateAllGadgets():
  50.      *
  51.      *    Create all gadgets required by the dial panel.
  52.      */
  53.  
  54. STATIC struct Gadget *
  55. CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
  56. {
  57.     struct Gadget        *Gadget;
  58.     struct NewGadget     NewGadget;
  59.     UWORD             Counter = 0;
  60.  
  61.     memset(&NewGadget,0,sizeof(struct NewGadget));
  62.  
  63.     if(Gadget = CreateContext(GadgetList))
  64.     {
  65.         NewGadget . ng_Height        = 12;
  66.         NewGadget . ng_GadgetText    = "_Skip";
  67.         NewGadget . ng_Width        = 15 * 8;
  68.         NewGadget . ng_TextAttr        = &DefaultFont;
  69.         NewGadget . ng_VisualInfo    = VisualInfo;
  70.         NewGadget . ng_GadgetID        = Counter;
  71.         NewGadget . ng_LeftEdge        = 10;
  72.         NewGadget . ng_Flags        = 0;
  73.         NewGadget . ng_TopEdge        = HEIGHT - 3 - NewGadget . ng_Height;
  74.  
  75.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  76.             GT_Underscore,    '_',
  77.         TAG_DONE);
  78.  
  79.         NewGadget . ng_GadgetText    = "_Go To Online";
  80.         NewGadget . ng_GadgetID        = Counter;
  81.         NewGadget . ng_LeftEdge        = (WIDTH - NewGadget . ng_Width) >> 1;
  82.  
  83.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  84.             GT_Underscore,    '_',
  85.         TAG_DONE);
  86.  
  87.         NewGadget . ng_GadgetText    = "_Abort Dialing";
  88.         NewGadget . ng_GadgetID        = Counter;
  89.         NewGadget . ng_LeftEdge        = WIDTH - (10 + NewGadget . ng_Width);
  90.  
  91.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  92.             GT_Underscore,    '_',
  93.         TAG_DONE);
  94.     }
  95.  
  96.     return(Gadget);
  97. }
  98.  
  99.     /* PrintInfo(struct Window *SomeWindow,WORD X,WORD Y,BYTE *String,...):
  100.      *
  101.      *    Print a string at a given position into the panel window.
  102.      */
  103.  
  104. STATIC VOID
  105. PrintInfo(struct Window *SomeWindow,WORD X,WORD Y,BYTE *String,...)
  106. {
  107.     va_list    VarArgs;
  108.  
  109.     va_start(VarArgs,String);
  110.     VSPrintf(SharedBuffer,String,VarArgs);
  111.     va_end(VarArgs);
  112.  
  113.     Move(SomeWindow -> RPort,ORIGIN_X + X * 8,ORIGIN_Y + 6 + Y * 8);
  114.     Text(SomeWindow -> RPort,SharedBuffer,strlen(SharedBuffer));
  115. }
  116.  
  117.     /* DialPanel():
  118.      *
  119.      *    This routine opens a small window in the middle of the
  120.      *    console window and walks down the list of numbers to
  121.      *    dial.
  122.      */
  123.  
  124. VOID
  125. DialPanel()
  126. {
  127.     STATIC WORD     PositionX = -1,PositionY = -1;
  128.  
  129.     struct Gadget    *GadgetList = NULL;
  130.     struct Gadget    *GadgetArray[3];
  131.     struct Window    *PanelWindow;
  132.     struct Menu    *PanelMenu;
  133.  
  134.     struct PhoneNode *SubNode;
  135.  
  136.     BaudBuffer[0] = 0;
  137.  
  138.         /* We are dialing. */
  139.  
  140.     Status = STATUS_DIALING;
  141.  
  142.         /* Create the gadgets. */
  143.  
  144.     if(CreateAllGadgets(&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
  145.     {
  146.             /* Create the menu. */
  147.  
  148.         if(PanelMenu = CreateMenus(DialMenu,
  149.             GTMN_FrontPen, 0,
  150.         TAG_DONE))
  151.         {
  152.                 /* Layout the menu items to fit on the
  153.                  * screen.
  154.                  */
  155.  
  156.             if(LayoutMenus(PanelMenu,VisualInfo,
  157.                 GTMN_TextAttr,&DefaultFont,
  158.             TAG_DONE))
  159.             {
  160.                 if(PositionX == -1)
  161.                     PositionX = (Screen -> Width - WIDTH) >> 1;
  162.  
  163.                 if(PositionY == -1)
  164.                     PositionY = (Screen -> Height - HEIGHT) >> 1;
  165.  
  166.                     /* At last, open the window. */
  167.  
  168.                 if(PanelWindow = OpenWindowTags(NULL,
  169.                     WA_Width,    WIDTH,
  170.                     WA_Height,    HEIGHT,
  171.  
  172.                     WA_Left,    PositionX,
  173.                     WA_Top,        PositionY,
  174.  
  175.                     WA_Activate,    TRUE,
  176.                     WA_DragBar,    TRUE,
  177.                     WA_DepthGadget,    TRUE,
  178.                     WA_CloseGadget,    TRUE,
  179.                     WA_RMBTrap,    TRUE,
  180.                     WA_CustomScreen,Screen,
  181.  
  182.                     WA_IDCMP,    IDCMP_CLOSEWINDOW | BUTTONIDCMP | IDCMP_MENUPICK,
  183.  
  184.                     WA_Title,    "Dialing...",
  185.                 TAG_DONE))
  186.                 {
  187.                     struct IntuiMessage    *Massage;
  188.                     ULONG             Class,Code;
  189.                     struct Gadget        *Gadget;
  190.                     LONG             RedialDelay = 0,DialTimeout,DialRetries,DialAttempt;
  191.                     BYTE             Dialing,Terminated = FALSE,BaudWasPending = FALSE;
  192.  
  193.                     UBYTE             SomeBuffer[300],*ExitString = NULL;
  194.                     BYTE             Pen1,Pen2,RunCount = 0;
  195.  
  196.                     DrawBevelBox(PanelWindow -> RPort,10,12,431,68,
  197.                         GTBB_Recessed,    TRUE,
  198.                         GT_VisualInfo,    VisualInfo,
  199.                     TAG_DONE);
  200.  
  201.                         /* Determine the colours to use for display. */
  202.  
  203.                     switch(Config . ColourMode)
  204.                     {
  205.                         case COLOUR_AMIGA:    Pen1 = 1;
  206.                                     Pen2 = 3;
  207.                                     break;
  208.  
  209.                         case COLOUR_EIGHT:    Pen1 = 4;
  210.                                     Pen2 = 7;
  211.                                     break;
  212.  
  213.                         case COLOUR_SIXTEEN:    Pen1 = 15;
  214.                                     Pen2 = 8;
  215.                                     break;
  216.  
  217.                         case COLOUR_MONO:    Pen1 = Pen2 = 1;
  218.                                     break;
  219.                     }
  220.  
  221.                         /* Make the current one the active one. */
  222.  
  223.                     PushWindow(PanelWindow);
  224.  
  225.                         /* Make a backup of the current configuration. */
  226.  
  227.                     CopyMem(&Config,&PrivateConfig,sizeof(struct Configuration));
  228.  
  229.                         /* Add the gadgets and refresh them. */
  230.  
  231.                     AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  232.                     RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  233.                     GT_RefreshWindow(PanelWindow,NULL);
  234.  
  235.                         /* Attach the menu to the window. */
  236.  
  237.                     SetMenuStrip(PanelWindow,PanelMenu);
  238.  
  239.                     PanelWindow -> Flags &= ~WFLG_RMBTRAP;
  240.  
  241.                         /* Print someinformation into the
  242.                          * panel window.
  243.                          */
  244.  
  245.                     SetAPen(PanelWindow -> RPort,Pen1);
  246.                     SetBPen(PanelWindow -> RPort,0);
  247.                     SetDrMd(PanelWindow -> RPort,JAM2);
  248.  
  249.                     PrintInfo(PanelWindow,0,0,"Calling...:");
  250.                     PrintInfo(PanelWindow,0,1,"Number....:");
  251.                     PrintInfo(PanelWindow,0,2,"Next......:");
  252.  
  253.                     PrintInfo(PanelWindow,0,4,"Timeout...:");
  254.                     PrintInfo(PanelWindow,0,5,"Attempt...:");
  255.  
  256.                     PrintInfo(PanelWindow,0,7,"Message...:");
  257.  
  258.                     SetAPen(PanelWindow -> RPort,Pen2);
  259.  
  260.                         /* Don't echo serial output. */
  261.  
  262.                     Quiet        = TRUE;
  263.  
  264.                         /* Perform full sequence check. */
  265.  
  266.                     FullCheck    = TRUE;
  267.  
  268.                         /* Reset the number of dial attempts. */
  269.  
  270.                     DialAttempt    = 0;
  271.  
  272.                         /* Get the first dial list entry. */
  273.  
  274.                     SubNode        = (struct PhoneNode *)SubList -> lh_Head;
  275.  
  276.                         /* The big dialing loop, implemented as a goto -> mark
  277.                          * loop rather than one of those classical while .. do
  278.                          * loops.
  279.                          */
  280.  
  281. Dial:                    Dialing        = TRUE;
  282.  
  283.                         /* Reset the sequence scanner, the user may have skipped
  284.                          * the previous dial attempt causing the modem to return
  285.                          * `NO CARRIER'. To prevent the dialer from skipping the
  286.                          * next dial entry as well as the previous we have to
  287.                          * have to flush any data pending on the serial line.
  288.                          */
  289.  
  290.                     HandleSerial();
  291.  
  292.                     FlowInit();
  293.  
  294.                     FullCheck = TRUE;
  295.  
  296.                     FlushSerial();
  297.  
  298.                         /* If SubNode -> Entry is nonzero it has
  299.                          * a configuration attached.
  300.                          */
  301.  
  302.                     if(SubNode -> Entry)
  303.                     {
  304.                         DialTimeout    = SubNode -> Entry -> Config . DialTimeout;
  305.                         DialRetries    = SubNode -> Entry -> Config . DialRetries;
  306.  
  307.                             /* We will need to change the serial parameters
  308.                              * in order to establish a connection.
  309.                              */
  310.  
  311.                         if(memcmp(&Config,&SubNode -> Entry -> Config,58))
  312.                         {
  313.                             CopyMem(&Config,&PrivateConfig,58);
  314.  
  315.                             CopyMem(&SubNode -> Entry -> Config,&Config,58);
  316.  
  317.                             ConfigSetup();
  318.  
  319.                             WaitTime(0,MILLION / 2);
  320.                             SerWrite("\rAT\r",4);
  321.                             WaitTime(0,MILLION / 2);
  322.                         }
  323.  
  324.                         if(ExitString)
  325.                         {
  326.                             SerialCommand(ExitString);
  327.                             WaitTime(0,MILLION / 2);
  328.                         }
  329.  
  330.                         if(SubNode -> Entry -> Config . ModemInit[0])
  331.                         {
  332.                             SerialCommand(SubNode -> Entry -> Config . ModemInit);
  333.                             WaitTime(0,MILLION / 2);
  334.                         }
  335.  
  336.                         if(SubNode -> Entry -> Config . ModemExit[0])
  337.                             ExitString = SubNode -> Entry -> Config . ModemExit;
  338.                         else
  339.                             ExitString = NULL;
  340.  
  341.                         PrintInfo(PanelWindow,12,0,"%-40.40s",SubNode -> Entry -> Name);
  342.  
  343.                         Say("Now calling: %s",SubNode -> Entry -> Name);
  344.  
  345.                         strcpy(SomeBuffer,SubNode -> Entry -> Config . DialPrefix);
  346.  
  347.                         PrintInfo(PanelWindow,12,1,"%-40.40s",SubNode -> Entry -> Number);
  348.                         strcat(SomeBuffer,SubNode -> Entry -> Number);
  349.                     }
  350.                     else
  351.                     {
  352.                         DialTimeout    = Config . DialTimeout;
  353.                         DialRetries    = Config . DialRetries;
  354.  
  355.                         if(ExitString)
  356.                         {
  357.                             SerialCommand(ExitString);
  358.                             WaitTime(0,MILLION / 2);
  359.                         }
  360.  
  361.                         if(Config . ModemExit[0])
  362.                             ExitString = Config . ModemExit;
  363.                         else
  364.                             ExitString = NULL;
  365.  
  366.                         PrintInfo(PanelWindow,12,0,"%-40.40s","-- Unknown --");
  367.  
  368.                         Say("Now calling: %s",SubNode -> VanillaNode . ln_Name);
  369.  
  370.                         strcpy(SomeBuffer,Config . DialPrefix);
  371.  
  372.                         PrintInfo(PanelWindow,12,1,"%-40.40s",SubNode -> VanillaNode . ln_Name);
  373.                         strcat(SomeBuffer,SubNode -> VanillaNode . ln_Name);
  374.                     }
  375.  
  376.                     if(SubNode -> VanillaNode . ln_Succ -> ln_Succ)
  377.                         PrintInfo(PanelWindow,12,2,"%-40.40s",((struct PhoneNode *)SubNode -> VanillaNode . ln_Succ) -> Entry -> Name);
  378.                     else
  379.                         PrintInfo(PanelWindow,12,2,"%-40.40s","-- None --");
  380.  
  381.                     strcat(SomeBuffer,"\r");
  382.  
  383.                     PrintInfo(PanelWindow,12,7,"%-40.40s","Dialing...");
  384.  
  385.                         /* Dial the number. */
  386.  
  387.                     SerialCommand(SomeBuffer);
  388.  
  389.                         /* Reset the signal. */
  390.  
  391.                     SetSignal(NULL,SIGBREAKF_CTRL_F);
  392.  
  393.                     while(!Terminated)
  394.                     {
  395.                         if(Dialing)
  396.                         {
  397.                             PrintInfo(PanelWindow,12,4,"%2ld:%02ld",DialTimeout / 60,DialTimeout % 60);
  398.                             PrintInfo(PanelWindow,12,5,"%5ld of %5ld",DialAttempt + 1,DialRetries);
  399.                         }
  400.                         else
  401.                             PrintInfo(PanelWindow,12,4,"%2ld:%02ld",RedialDelay / 60,RedialDelay % 60);
  402.  
  403.                         WaitTime(0,MILLION / 2);
  404.  
  405.                             /* The following commands are executed each second */
  406.  
  407.                         if((RunCount++) && !Terminated)
  408.                         {
  409.                             RunCount = 0;
  410.  
  411.                                 /* Are we dialing or waiting? */
  412.  
  413.                             if(Dialing)
  414.                             {
  415.                                     /* No chance, the dial timeout
  416.                                      * has elapsed and no connection
  417.                                      * was made.
  418.                                      */
  419.  
  420.                                 if(!(--DialTimeout))
  421.                                 {
  422.                                     PrintInfo(PanelWindow,12,7,"%-40.40s","Dial Attempt Timeout.");
  423.  
  424. Skip1:                                    WaitTime(0,MILLION / 2);
  425.                                     SerWrite("\r",1);
  426.                                     WaitTime(0,MILLION / 2);
  427.  
  428.                                         /* Is this one the last entry? */
  429.  
  430.                                     if(SubNode -> VanillaNode . ln_Succ -> ln_Succ)
  431.                                     {
  432.                                             /* Proceed to the next entry. */
  433.  
  434.                                         SubNode = (struct SubNode *)SubNode -> VanillaNode . ln_Succ;
  435.  
  436.                                         goto Dial;
  437.                                     }
  438.                                     else
  439.                                     {
  440.                                             /* Is this one the last dial
  441.                                              * attempt to be made?
  442.                                              */
  443.  
  444.                                         if(++DialAttempt >= DialRetries)
  445.                                         {
  446.                                             PrintInfo(PanelWindow,12,7,"%-40.40s","Maximum Number Of Dial Retries Reached!");
  447.  
  448.                                             Say("Maximum number of dial retries reached.");
  449.  
  450.                                             WaitTime(2,0);
  451.  
  452.                                             Terminated = TRUE;
  453.                                         }
  454.                                         else
  455.                                         {
  456.                                                 /* Get the first list entry. */
  457.  
  458.                                             SubNode = (struct PhoneNode *)SubList -> lh_Head;
  459.  
  460.                                                 /* Get the redial delay. */
  461.  
  462.                                             if(SubNode -> Entry)
  463.                                                 RedialDelay = 60 * SubNode -> Entry -> Config . RedialDelay;
  464.                                             else
  465.                                                 RedialDelay = 60 * Config . RedialDelay;
  466.  
  467.                                                 /* No redial delay? Restart dialing... */
  468.  
  469.                                             if(!RedialDelay)
  470.                                             {
  471.                                                 WaitTime(1,0);
  472.  
  473.                                                 goto Dial;
  474.                                             }
  475.                                             else
  476.                                             {
  477.                                                     /* Go into redial delay. */
  478.  
  479.                                                 PrintInfo(PanelWindow,12,7,"%-40.40s","Redial Delay...");
  480.  
  481.                                                 Dialing = FALSE;
  482.                                             }
  483.                                         }
  484.                                     }
  485.                                 }
  486.                             }
  487.                             else
  488.                             {
  489.                                 if(!(--RedialDelay))
  490.                                 {
  491.                                         /* Get the first list entry. */
  492.  
  493. Skip2:                                    SubNode = (struct PhoneNode *)SubList -> lh_Head;
  494.  
  495.                                         /* We are once again dialing. */
  496.  
  497.                                     Dialing = TRUE;
  498.  
  499.                                     goto Dial;
  500.                                 }
  501.                             }
  502.                         }
  503.  
  504.                             /* Handle serial data flow. */
  505.  
  506.                         HandleSerial();
  507.  
  508.                             /* Something has changed in the flow
  509.                              * info structure.
  510.                              */
  511.  
  512.                         if(FlowInfo . Changed)
  513.                         {
  514.                                 /* We had a connect and the
  515.                                  * baud rate has been transferred.
  516.                                  */
  517.  
  518.                             if(BaudWasPending && !BaudPending)
  519.                             {
  520.                                 ULONG Value;
  521.  
  522.                                 if(Value = atol(BaudBuffer))
  523.                                 {
  524.                                     if(SubNode -> Entry)
  525.                                         CopyMem(&SubNode -> Entry -> Config,&Config,sizeof(struct Configuration));
  526.  
  527.                                     PrivateConfig . BaudRate = Config . BaudRate = Value;
  528.  
  529.                                     ClearSerial();
  530.  
  531.                                     SetParameters();
  532.  
  533.                                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  534.                                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  535.                                     ReadRequest -> IOSer . io_Length    = 1;
  536.  
  537.                                     SendIO(ReadRequest);
  538.                                 }
  539.  
  540.                                 goto ConnectIt;
  541.                             }
  542.  
  543.                                 /* Current number is busy. */
  544.  
  545.                             if(FlowInfo . Busy || FlowInfo . NoCarrier)
  546.                             {
  547.                                 FlowInit();
  548.  
  549.                                 FullCheck = TRUE;
  550.  
  551.                                 FlowInfo . Busy        = FALSE;
  552.                                 FlowInfo . NoCarrier    = FALSE;
  553.                                 FlowInfo . Changed    = FALSE;
  554.  
  555.                                 if(Dialing)
  556.                                 {
  557.                                     PrintInfo(PanelWindow,12,7,"%-40.40s","Line Is Busy.");
  558.  
  559.                                     Say("Line is busy.");
  560.  
  561.                                     WaitTime(1,0);
  562.  
  563.                                     goto Skip1;
  564.                                 }
  565.                             }
  566.  
  567.                                 /* Somebody tries to call us. */
  568.  
  569.                             if(FlowInfo . Ring && !Terminated)
  570.                             {
  571.                                 FlowInit();
  572.  
  573.                                 PrintInfo(PanelWindow,12,7,"%-40.40s","Incoming Call!");
  574.  
  575.                                 WakeUp(PanelWindow);
  576.  
  577.                                 Say("Incoming call.");
  578.  
  579.                                 Terminated = TRUE;
  580.                             }
  581.  
  582.                                 /* Somebody's talking. */
  583.  
  584.                             if(FlowInfo . Voice && !Terminated)
  585.                             {
  586.                                 FlowInit();
  587.  
  588.                                 PrintInfo(PanelWindow,12,7,"%-40.40s","Incoming Voice Call!");
  589.  
  590.                                 WakeUp(PanelWindow);
  591.  
  592.                                 Say("Icoming voice call.");
  593.  
  594.                                 Terminated = TRUE;
  595.                             }
  596.  
  597.                                 /* We got a connect. */
  598.  
  599.                             if(FlowInfo . Connect && !Terminated)
  600.                             {
  601.                                 FlowInfo . Connect = FALSE;
  602.                                 FlowInfo . Changed = FALSE;
  603.  
  604.                                     /* Auto-baud feature enabled?
  605.                                      * If yes, wait for the number.
  606.                                      */
  607.  
  608.                                 if(BaudPending)
  609.                                 {
  610.                                     if(Config . ConnectAutoBaud)
  611.                                         BaudWasPending = TRUE;
  612.                                     else
  613.                                         BaudPending = FALSE;
  614.                                 }
  615.  
  616.                                     /* Seems that we've received
  617.                                      * a number.
  618.                                      */
  619.  
  620. ConnectIt:                            if(!BaudPending)
  621.                                 {
  622.                                         /* Install the new configuration. */
  623.  
  624.                                     if(!BaudWasPending)
  625.                                     {
  626.                                         if(SubNode -> Entry)
  627.                                             CopyMem(&SubNode -> Entry -> Config,&Config,sizeof(struct Configuration));
  628.                                     }
  629.  
  630.                                         /* Convert the baud rate. */
  631.  
  632.                                     if(BaudBuffer[0])
  633.                                     {
  634.                                         LONG TestRate = atol(BaudBuffer);
  635.  
  636.                                         if(TestRate >= 110)
  637.                                         {
  638.                                             Config . BaudRate = TestRate;
  639.  
  640.                                             SetParameters();
  641.                                         }
  642.                                     }
  643.  
  644.                                         /* Reset the scanner. */
  645.  
  646.                                     FlowInit();
  647.  
  648.                                         /* Copy the remaining data. */
  649.  
  650.                                     if(SubNode -> Entry)
  651.                                     {
  652.                                         PayPerUnit[0]    = SubNode -> Entry -> PayPerUnit[0];
  653.                                         PayPerUnit[1]    = SubNode -> Entry -> PayPerUnit[1];
  654.  
  655.                                         SecPerUnit[0]    = SubNode -> Entry -> SecPerUnit[0];
  656.                                         SecPerUnit[1]    = SubNode -> Entry -> SecPerUnit[1];
  657.  
  658.                                         TimeOfDay[0]    = SubNode -> Entry -> TimeOfDay[0];
  659.                                         TimeOfDay[1]    = SubNode -> Entry -> TimeOfDay[1];
  660.  
  661.                                         CurrentPay    = 0;
  662.  
  663.                                         SendStartup    = TRUE;
  664.  
  665.                                         strcpy(Password,SubNode -> Entry -> Password);
  666.                                     }
  667.                                     else
  668.                                     {
  669.                                         CurrentPay    = 0;
  670.  
  671.                                         SecPerUnit[0]    = SecPerUnit[1]    = 0;
  672.                                         PayPerUnit[0]    = PayPerUnit[1]    = 0;
  673.  
  674.                                         TimeOfDay[0]    = TimeOfDay[1];
  675.  
  676.                                         Password[0]    = 0;
  677.  
  678.                                         SendStartup    = FALSE;
  679.                                     }
  680.  
  681.                                         /* We are now online. */
  682.  
  683.                                     Online        = TRUE;
  684.                                     Terminated    = TRUE;
  685.  
  686.                                         /* Add another logfile entry. */
  687.  
  688.                                     if(SubNode -> Entry)
  689.                                         LogAction("Connected to \"%s\" (%s).",SubNode -> Entry -> Name,SubNode -> Entry -> Number);
  690.                                     else
  691.                                         LogAction("Connected to %s.",SubNode -> VanillaNode . ln_Name);
  692.  
  693.                                         /* Open auto-capture file if necessary. */
  694.  
  695.                                     if(Config . ConnectAutoCapture && Config . CapturePath[0])
  696.                                     {
  697.                                         UBYTE        SharedBuffer[256],Name[50],Date[20];
  698.                                         struct DateTime    DateTime;
  699.  
  700.                                         DateStamp(&DateTime . dat_Stamp);
  701.  
  702.                                         DateTime . dat_Format    = FORMAT_DOS;
  703.                                         DateTime . dat_Flags    = 0;
  704.                                         DateTime . dat_StrDay    = NULL;
  705.                                         DateTime . dat_StrDate    = Date;
  706.                                         DateTime . dat_StrTime    = NULL;
  707.  
  708.                                         strcpy(SharedBuffer,Config . CapturePath);
  709.  
  710.                                         if(DateToStr(&DateTime))
  711.                                         {
  712.                                             if(SubNode -> Entry)
  713.                                             {
  714.                                                 WORD i;
  715.  
  716.                                                 strcpy(Name,SubNode -> Entry -> Name);
  717.  
  718.                                                 for(i = 0 ; i < strlen(Name) ; i++)
  719.                                                 {
  720.                                                     if(Name[i] == ' ')
  721.                                                         Name[i] = '_';
  722.                                                 }
  723.                                             }
  724.                                             else
  725.                                                 strcpy(Name,"Capture");
  726.  
  727.                                             strcat(Name,"_");
  728.                                             strcat(Name,Date);
  729.  
  730.                                             if(AddPart(SharedBuffer,Name,256))
  731.                                             {
  732.                                                 struct MenuItem *Item;
  733.  
  734.                                                 Item = FindThisItem(MEN_CAPTUREDISK);
  735.  
  736.                                                 Item -> Flags &= ~CHECKED;
  737.  
  738.                                                 if(FileCapture)
  739.                                                 {
  740.                                                     BufferClose(FileCapture);
  741.  
  742.                                                     if(!GetFileSize(CaptureName))
  743.                                                         DeleteFile(CaptureName);
  744.                                                     else
  745.                                                         SetProtection(CaptureName,FIBF_EXECUTE);
  746.                                                 }
  747.  
  748.                                                 if(FileCapture = BufferOpen(SharedBuffer,"a"))
  749.                                                 {
  750.                                                     Item -> Flags |= CHECKED;
  751.  
  752.                                                     strcpy(CaptureName,SharedBuffer);
  753.                                                 }
  754.                                             }
  755.                                         }
  756.                                     }
  757.  
  758.                                         /* Remove the node from the
  759.                                          * dialing list.
  760.                                          */
  761.  
  762.                                     RemSub(SubNode);
  763.  
  764.                                         /* Wake the user up. */
  765.  
  766.                                     PrintInfo(PanelWindow,12,7,"%-40.40s","Connection Established.");
  767.  
  768.                                     WakeUp(PanelWindow);
  769.  
  770.                                     Say("Connection established.");
  771.  
  772.                                         /* Perform system initialization. */
  773.  
  774.                                     ConfigSetup();
  775.                                 }
  776.                             }
  777.                         }
  778.  
  779.                             /* Look for the hotkey. */
  780.  
  781.                         if(SetSignal(NULL,NULL) & SIGBREAKF_CTRL_F)
  782.                         {
  783.                             SetSignal(NULL,SIGBREAKF_CTRL_F);
  784.  
  785.                                 /* Are we dialing or waiting? */
  786.  
  787.                             if(Dialing)
  788.                             {
  789.                                 DialTimeout = 0;
  790.  
  791.                                 goto Skip1;
  792.                             }
  793.                             else
  794.                             {
  795.                                 RedialDelay = 0;
  796.  
  797.                                 goto Skip2;
  798.                             }
  799.                         }
  800.  
  801.                             /* Pick up the window input. */
  802.  
  803.                         while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  804.                         {
  805.                             Class    = Massage -> Class;
  806.                             Code    = Massage -> Code;
  807.                             Gadget    = (struct Gadget *)Massage -> IAddress;
  808.  
  809.                             GT_ReplyIMsg(Massage);
  810.  
  811.                                 /* Handle the menu events. */
  812.  
  813.                             if(Class == MENUPICK)
  814.                             {
  815.                                 struct MenuItem *MenuItem;
  816.  
  817.                                 while(Code != MENUNULL)
  818.                                 {
  819.                                     MenuItem = ItemAddress(PanelMenu,Code);
  820.  
  821.                                     switch((ULONG)GTMENUITEM_USERDATA(MenuItem))
  822.                                     {
  823.                                         case MEN_QUITPANEL:    Class    = IDCMP_CLOSEWINDOW;
  824.                                                     break;
  825.  
  826.                                         case MEN_SKIP:        Class    = IDCMP_GADGETUP;
  827.                                                     Gadget    = GadgetArray[GAD_SKIP];
  828.                                                     break;
  829.  
  830.                                         case MEN_ONLINE:    Class    = IDCMP_GADGETUP;
  831.                                                     Gadget    = GadgetArray[GAD_ONLINE];
  832.                                                     break;
  833.  
  834.                                         case MEN_ABORT:        Class    = IDCMP_GADGETUP;
  835.                                                     Gadget    = GadgetArray[GAD_ABORT];
  836.                                                     break;
  837.  
  838.                                         default:        break;
  839.                                     }
  840.  
  841.                                     Code = MenuItem -> NextSelect;
  842.                                 }
  843.                             }
  844.  
  845.                                 /* Close the window, hang up the line. */
  846.  
  847.                             if(Class == IDCMP_CLOSEWINDOW)
  848.                             {
  849.                                 Terminated = TRUE;
  850.  
  851.                                 WaitTime(0,MILLION / 2);
  852.                                 SerWrite("\r",1);
  853.                                 WaitTime(0,MILLION / 2);
  854.                             }
  855.  
  856.                             if(Class == IDCMP_GADGETUP)
  857.                             {
  858.                                 switch(Gadget -> GadgetID)
  859.                                 {
  860.                                     case GAD_SKIP:    if(Dialing)
  861.                                             {
  862.                                                 DialTimeout = 0;
  863.  
  864.                                                 goto Skip1;
  865.                                             }
  866.                                             else
  867.                                             {
  868.                                                 RedialDelay = 0;
  869.  
  870.                                                 goto Skip2;
  871.                                             }
  872.  
  873.                                                 /* Forced online,
  874.                                                  * install new configuration
  875.                                                  * first.
  876.                                                  */
  877.  
  878.                                     case GAD_ONLINE:if(SubNode -> Entry)
  879.                                                 CopyMem(&SubNode -> Entry -> Config,&Config,sizeof(struct Configuration));
  880.  
  881.                                                 /* Copy the remaining information. */
  882.  
  883.                                             if(SubNode -> Entry)
  884.                                             {
  885.                                                 PayPerUnit[0]    = SubNode -> Entry -> PayPerUnit[0];
  886.                                                 PayPerUnit[1]    = SubNode -> Entry -> PayPerUnit[1];
  887.  
  888.                                                 SecPerUnit[0]    = SubNode -> Entry -> SecPerUnit[0];
  889.                                                 SecPerUnit[1]    = SubNode -> Entry -> SecPerUnit[1];
  890.  
  891.                                                 TimeOfDay[0]    = SubNode -> Entry -> TimeOfDay[0];
  892.                                                 TimeOfDay[1]    = SubNode -> Entry -> TimeOfDay[1];
  893.  
  894.                                                 CurrentPay    = 0;
  895.  
  896.                                                 SendStartup    = TRUE;
  897.  
  898.                                                 strcpy(Password,SubNode -> Entry -> Password);
  899.                                             }
  900.                                             else
  901.                                             {
  902.                                                 CurrentPay    = 0;
  903.  
  904.                                                 SecPerUnit[0]    = SecPerUnit[1]    = 0;
  905.                                                 PayPerUnit[0]    = PayPerUnit[1]    = 0;
  906.  
  907.                                                 TimeOfDay[0]    = TimeOfDay[1];
  908.  
  909.                                                 Password[0]    = 0;
  910.  
  911.                                                 SendStartup    = FALSE;
  912.                                             }
  913.  
  914.                                                 /* We are now online. */
  915.  
  916.                                             Online        = TRUE;
  917.                                             Terminated    = TRUE;
  918.  
  919.                                                 /* Add a new log action. */
  920.  
  921.                                             if(SubNode -> Entry)
  922.                                                 LogAction("Connected to \"%s\" (%s).",SubNode -> Entry -> Name,SubNode -> Entry -> Number);
  923.                                             else
  924.                                                 LogAction("Connected to %s.",SubNode -> VanillaNode . ln_Name);
  925.  
  926.                                                 /* Open auto-capture file. */
  927.  
  928.                                             if(Config . ConnectAutoCapture && Config . CapturePath[0])
  929.                                             {
  930.                                                 UBYTE        SharedBuffer[256],Name[50],Date[20];
  931.                                                 struct DateTime    DateTime;
  932.  
  933.                                                 DateStamp(&DateTime . dat_Stamp);
  934.  
  935.                                                 DateTime . dat_Format    = FORMAT_DOS;
  936.                                                 DateTime . dat_Flags    = 0;
  937.                                                 DateTime . dat_StrDay    = NULL;
  938.                                                 DateTime . dat_StrDate    = Date;
  939.                                                 DateTime . dat_StrTime    = NULL;
  940.  
  941.                                                 strcpy(SharedBuffer,Config . CapturePath);
  942.  
  943.                                                 if(DateToStr(&DateTime))
  944.                                                 {
  945.                                                     if(SubNode -> Entry)
  946.                                                     {
  947.                                                         WORD i;
  948.  
  949.                                                         strcpy(Name,SubNode -> Entry -> Name);
  950.  
  951.                                                         for(i = 0 ; i < strlen(Name) ; i++)
  952.                                                         {
  953.                                                             if(Name[i] == ' ')
  954.                                                                 Name[i] = '_';
  955.                                                         }
  956.                                                     }
  957.                                                     else
  958.                                                         strcpy(Name,"Capture");
  959.  
  960.                                                     strcat(Name,"_");
  961.                                                     strcat(Name,Date);
  962.  
  963.                                                     if(AddPart(SharedBuffer,Name,256))
  964.                                                     {
  965.                                                         struct MenuItem *Item;
  966.  
  967.                                                         Item = FindThisItem(MEN_CAPTUREDISK);
  968.  
  969.                                                         Item -> Flags &= ~CHECKED;
  970.  
  971.                                                         if(FileCapture)
  972.                                                         {
  973.                                                             BufferClose(FileCapture);
  974.  
  975.                                                             if(!GetFileSize(CaptureName))
  976.                                                                 DeleteFile(CaptureName);
  977.                                                             else
  978.                                                                 SetProtection(CaptureName,FIBF_EXECUTE);
  979.                                                         }
  980.  
  981.                                                         if(FileCapture = BufferOpen(SharedBuffer,"a"))
  982.                                                         {
  983.                                                             Item -> Flags |= CHECKED;
  984.  
  985.                                                             strcpy(CaptureName,SharedBuffer);
  986.                                                         }
  987.                                                     }
  988.                                                 }
  989.                                             }
  990.  
  991.                                                 /* Remove node from
  992.                                                  * dialing list and
  993.                                                  * perform system
  994.                                                  * setup.
  995.                                                  */
  996.  
  997.                                             RemSub(SubNode);
  998.  
  999.                                             ConfigSetup();
  1000.  
  1001.                                             break;
  1002.  
  1003.                                         /* Abort the dialing process. */
  1004.  
  1005.                                     case GAD_ABORT:    Terminated = TRUE;
  1006.  
  1007.                                             PrintInfo(PanelWindow,12,7,"%-40.40s","Aborting...");
  1008.  
  1009.                                             WaitTime(0,MILLION / 2);
  1010.                                             SerWrite("\r",1);
  1011.                                             WaitTime(0,MILLION / 2);
  1012.  
  1013.                                             break;
  1014.                                 }
  1015.                             }
  1016.                         }
  1017.                     }
  1018.  
  1019.                         /* Are we perhaps not online? */
  1020.  
  1021.                     if(!Online)
  1022.                     {
  1023.                             /* Is the serial setup different? */
  1024.  
  1025.                         if(memcmp(&PrivateConfig,&Config,58))
  1026.                         {
  1027.                                 /* Swap the serial data. */
  1028.  
  1029.                             swmem(&PrivateConfig,&Config,58);
  1030.  
  1031.                                 /* Set up the old serial configuration. */
  1032.  
  1033.                             ConfigSetup();
  1034.  
  1035.                                 /* Reinitialize... */
  1036.  
  1037.                             WaitTime(0,MILLION / 2);
  1038.                             SerWrite("\rAT\r",4);
  1039.                             WaitTime(0,MILLION / 2);
  1040.                         }
  1041.  
  1042.                             /* Do we have a valid modem exit string? */
  1043.  
  1044.                         if(ExitString)
  1045.                         {
  1046.                             SerialCommand(ExitString);
  1047.                             WaitTime(0,MILLION / 2);
  1048.                         }
  1049.                     }
  1050.  
  1051.                         /* Reset the scanner. */
  1052.  
  1053.                     FlowInit();
  1054.  
  1055.                     PanelWindow -> Flags |= WFLG_RMBTRAP;
  1056.  
  1057.                     ClearMenuStrip(PanelWindow);
  1058.  
  1059.                     RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  1060.  
  1061.                     PopWindow();
  1062.  
  1063.                     PositionX = PanelWindow -> LeftEdge;
  1064.                     PositionY = PanelWindow -> TopEdge;
  1065.  
  1066.                     CloseWindow(PanelWindow);
  1067.                 }
  1068.             }
  1069.  
  1070.             FreeMenus(PanelMenu);
  1071.         }
  1072.     }
  1073.  
  1074.     FreeGadgets(GadgetList);
  1075.  
  1076.         /* We are done now, restart echoing serial */
  1077.  
  1078.     Quiet = FALSE;
  1079. }
  1080.