home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d534 / term.lha / Term / Source.LZH / DialPanel.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  26KB  |  1,073 lines

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