/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  MF.CPP                             by Alan Partis, Copyright (C)         */
/*                                     International Trade Systems, Inc.     */
/*                                     1993 All rights reserved.             */
/*                                                                           */
/*  Description:   Main module for the Modem Finder utility.  This utility   */
/*       expects to be able to interrogate the COM ports for the presence    */
/*       of a modem.  It will then dump the characteristics of any modems    */
/*       found to the screen.  This module contains the client code that     */
/*       interracts with the Modem object.                                   */
/*                                                                           */
/*  Contents: main()                                                         */
/*                                                                           */
/*  Date      Initials  Comments                                             */
/*  -----------------------------------------------------------------------  */
/*  04 Sep 93 acp       Initial Creation                                     */
/*                                                                           */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include "stddefs.h"
#include "mf.h"
#include "modem.hpp"
#include "portlist.hpp"

//
// ----- Global data -----
//




/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  main()                             by Alan Partis, Copyright (C)         */
/*                                     International Trade Systems, Inc.     */
/*                                     1993 All rights reserved.             */
/*                                                                           */
/*  Description:   Entry point for a DOS 'C' program.  Major program flow    */
/*       is managed here.                                                    */
/*                                                                           */
/*  Input:    argc                     number of command line args           */
/*            argv                     array of pointers to arg strings      */
/*                                                                           */
/*  Output:   none                                                           */
/*                                                                           */
/*  Return:   exit_code                                                      */
/*                                                                           */
/*  Date      Initials  Comments                                             */
/*  -----------------------------------------------------------------------  */
/*  04 Sep 93 acp       Initial Creation                                     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main(int argc, char *argv[])

{

    int  done;
    int  exit_code;
    int  rc;
    PORT comx;

    PortList  Ports;

    //
    // Initialize local variables
    //
    exit_code = SUCCESS;
    done      = NO;

    //
    // Put up banner identifying this program
    //
    cout << "\nModem Finder " << VERSION << "\n";
    cout << "Copyright (C) International Trade Systems, Inc, 1993\n";
    cout << "All rights reserved\n\n";

    //
    // Parse command line; if anything is there
    //  put up the usage information.
    //
    if (argc > 1)
    {
         cout << "\nUsage:\tmf\n";
         cout << "\nModem Finder takes no command line arguments\n";
         exit(1);
    }

    //
    // attempt to find a modem
    //
    cout << "Checking for modem.  Please allow 10 seconds for each port.\n";

    Ports.Next(&comx);
    while ((comx.port != -1) && (!done))
    {
         Modem     test_modem;

         cout << "COM" << (comx.port+1) << "\r";

         rc = test_modem.Init(comx.port, comx.address);
         if (rc == PASS)
         {
              done    = YES;
              cout << "modem found on COM" << (comx.port+1) << "\n";

              //
              // now go ahead and update the config file
              //
              UpdateCfg(comx.port+1);
         }

         //
         // Get the next port to work with if there is one
         //
         Ports.Next(&comx);
    }

    //
    // indicate exit status and exit
    //
    if (exit_code != SUCCESS)
    {
         cout << "\007";
         cout << "abnormal exit - program did not complete\n";
    }

    return (exit_code);

}   /* end of function main() */



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  UpdateCfg()                        by Alan Partis, Copyright (C)         */
/*                                     International Trade Systems, Inc.     */
/*                                     1993 All rights reserved.             */
/*                                                                           */
/*  Description:   Updates the configuration file with the supplied port     */
/*       number.                                                             */
/*                                                                           */
/*  Input:    port                     target COM port                       */
/*                                                                           */
/*  Output:   none                                                           */
/*                                                                           */
/*  Return:   none                                                           */
/*                                                                           */
/*  Date      Initials  Comments                                             */
/*  -----------------------------------------------------------------------  */
/*  04 Sep 93 acp       Initial Creation                                     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void UpdateCfg(int port)
{

    FILE     *fp;

    //
    // Attempt to open the target file in binary mode.  If
    //  it does not exist, DO NOT CREATE one.
    //
    fp = fopen(CFG_FILE, "r+b");

    if (fp)
    {
         //
         // Ensure we are at the 'port' location in the
         //  configuration file.  In this case, top of file.
         //
         fseek(fp, 0, SEEK_SET);
         fwrite(&port, sizeof(port), 1, fp);
         fclose(fp);
         cout << CFG_FILE << " configuration updated.\n";
    }
    else
    {
         cout << CFG_FILE << " does not exist.  Configuration not updated.\n";
    }

}   /* end of function UpdateCfg() */


  Copyright © Thundernet Development Group Inc., 2003.
All rights reserved.