www.pudn.com > commutil.zip > GLOBAL.CPP


// ******************************************************************** // 
//                                                                      // 
//      GLOBAL.CPP                                                      // 
//      Copyright (c) 1993, Michael Holmes and Bob Flanders             // 
//      C++ Communication Utilities                                     // 
//                                                                      // 
//      Chapter 7: Receiving a FAX                                      // 
//      Last changed in chapter 7                                       // 
//                                                                      // 
//      This file contains the global definitions and the main()        // 
//      function for PolyComm.                                          // 
//                                                                      // 
// ******************************************************************** // 
 
 
/* ******************************************************************** * 
 * 
 *  Messages and strings 
 * 
 * ******************************************************************** */ 
 
char    copyright[]    = "PolyComm 1.00 \xfe Copyright (c) 1993, " 
                         "Michael Holmes and Bob Flanders\n\r" 
                         "C++ Communication Utilities\n\n\r", 
        about_msg[]    = " Press any key to continue .. ", 
        stat_format[]  = "     PolyComm 1.00     \xb3" 
                         "  %s %5s %s%1.1s%s  %s %s %s     \xb3" 
                         "     [Alt] = Menu    ", 
        bad_width[]    = "Screen must be at least 80 columns wide\n", 
        loading_cfg[]  = "Processing configuration file: %s\n", 
        no_config[]    = "Configuration file: %s not found\n", 
        unknown_cmd[]  = "Unknown command: %s\n", 
        bad_setting[]  = "Bad %s= setting: %s\n", 
        bad_port[]     = "Bad base port setting in COM%d: %s\n", 
        bad_irq[]      = "Bad interrupt setting in COM%d: %s\n", 
        bad_pc_cmd[]   = "Bad PC: command\n", 
        bad_parm[]     = "Bad value in COMSETTING statement: %s\n", 
        loading_pb[]   = "Loading phonebook: %s\n", 
        pb_overflow[]  = "Too many phonebook entries\n", 
        pb_setting[]   = "Phonebook entry: %s \n  has a bad %s setting: %s\n", 
        pb_format[]    = "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 
       *fld_name[]  =  { "Name", "Telephone", "Fax Number", 
                         "Modem Setup", "Speed", "Parity", 
                         "Data Bits", "Stop Bits" }, 
        no_ports[]     = "No communication ports were found\n", 
       *line_error[] = { "®Overrun¯", "®Parity¯", "®Framing¯", "®Break¯" }, 
        overflow_msg[] = "\r\n®Buffer Overflow: %d chars lost¯\r\n", 
        hangup_msg[]   = " Issuing hangup to modem\r\n", 
        hangup_done[]  = " ..hangup completed", 
       *dial_msg[]   = { "Setting communications port parameters\r\n",// 0 
                         "Sending reset command to modem\r\n",        // 1 
                         "...user terminated dialing sequence",       // 2 
                         "...timeout waiting for modem response\r\n", // 3 
                         "...reset completed properly\r\n",           // 4 
                         "...reset command rejected by modem\r\n",    // 5 
                         "Sending modem setup commands\r\n",          // 6 
                         "...modem setup completed successfully\r\n", // 7 
                         "...modem rejected setup string\r\n",        // 8 
                         "Sending phone number to modem\r\n",         // 9 
                         "...connection established",                // 10 
                         "...connection failed",                     // 11 
                         "Phone number entry blank\r\n"              // 12 
                         "...dial sequence terminated", 
                         "...",                                      // 13 
                         " command not found in .CFG file" },        // 14 
       *endings[]    = { "\r", "\n" }, 
       *dl_msg[]     = { " Filename: ",                               // 0 
                         " Overwrite file? ",                         // 1 
                         "\r\n..user terminated download",            // 2 
                         "\r\n..too many errors",                     // 3 
                         "\r\n..sender terminated download",          // 4 
                         "\r\n..unable to create output file",        // 5 
                         "\r %lu packets  %u errors",                 // 6 
                         "\r\n %lu data bytes using XMODEM %s",       // 7 
                         "\r\n%d files transferred, %lu bytes.",      // 8 
                         "\r\n%s using %s\r\n",                       // 9 
                         "\r\n..timeout error",                       // 10 
                         "\r\nTransferring %s: Len=%lu\r\n",          // 11 
                         "\r\n..unrecoverable sequence error",        // 12 
                         "\r %lu bytes left (%u errors)       ",      // 13 
                         "\r\n..user terminated upload",              // 14 
                         "\r\n..receiver terminated send",            // 15 
                         "Enter the names of files to send:\r\n"      // 16 
                            "1:\r\n2:\r\n3:\r\n4:\r\n5:" 
                         }, 
       *fax_msgs[]   = { "%s Fax file %s\r\n",                        // 0 
                         "Initializing modem\r\n",                    // 1 
                         "Awaiting call\r\n",                         // 2 
                         "Answering call\r\n",                        // 3 
                         "Sending our station ID\r\n",                // 4 
                         "Sending DIS\r\n",                           // 5 
                         "TSI received\r\n",                          // 6 
                         "DCS received\r\n",                          // 7 
                         "NSF received\r\n",                          // 8 
                         "Receiving TCF\r\n",                         // 9 
                         "Confirming TCF\r\n",                        // 10 
                         "Receiving Fax page...\r\n",                 // 11 
                         "Page received\r\n",                         // 12 
                         "Multipage signal (MPS) received\r\n",       // 13 
                         "End of message (EOM) received\r\n",         // 14 
                         "End of procedure (EOP) received\r\n",       // 15 
                         "Disconnect received\r\n",                   // 16 
                         "Error!!\07\07\r\n",                         // 17 
                         "User cancelled FAX procedure\r\n",          // 18 
                         "Retrying TCF receive\r\n",                  // 19 
                         "Timeout awaiting response\r\n",             // 20 
                         "Unexpected response\r\n",                   // 21 
                         "Calling remote FAX ...\r\n",                // 22 
                         "CSI received\r\n",                          // 23 
                         "DIS received\r\n",                          // 24 
                         "Sending TSI\r\n",                           // 25 
                         "Sending DCS\r\n",                           // 26 
                         "Sending TCF\r\n",                           // 27 
                         "TCF confirmed\r\n",                         // 28 
                         "Sending page\r\n",                          // 29 
                         "TCF failed ..\r\n",                         // 30 
                         "Page sent\r\n",                             // 31 
                         "Sending multipage signal (MPS)\r\n",        // 32 
                         "Sending end of procedure (EOP)\r\n",        // 33 
                         "Sending disconnect (DCN)\r\n",              // 34 
                         "*** XOFF received ***\r",                   // 35 
                         "                     \r",                   // 36 
                         "Modem did not respond to reset\r\n",        // 37 
                         "Modem reset\r\n",                           // 38 
                         "Modem reset error\r\n",                     // 39 
                         " Filename: ",                               // 40 
                         "Attempting 9600bps...\r\n",                 // 41 
                         "Attempting 7200bps...\r\n",                 // 42 
                         "Attempting 4800bps...\r\n",                 // 43 
                         "Attempting 2400bps...\r\n"                  // 44 
                         }, 
       *fax_errors[] = { "No error\r\n",                              // 0 
                         "Modem initialization error\r\n",            // 1 
                         "Modem did not connect\r\n",                 // 2 
                         "Error receiving HDLC frame\r\n",            // 3 
                         "No DCS received\r\n",                       // 4 
                         "Unsupported speed requested\r\n",           // 5 
                         "Invalid TCF format\r\n",                    // 6 
                         "TCF improperly terminated\r\n",             // 7 
                         "Improper TCF length\r\n",                   // 8 
                         "Unable to open fax file\r\n",               // 9 
                         "Connection failed... try again later.\r\n", // 10 
                         "No DIS received\r\n",                       // 11 
                         "Unable to establish session\r\n",           // 12 
                         "Invalid file format\r\n",                   // 13 
                         "Expected confirmation not received\r\n",    // 14 
                         "Timeout sending FAX data"                   // 15 
                         }, 
        no_memory[]    = "\nUnable to allocate %d bytes of memory\n", 
        open_error[]   = "\nError opening file (%s)\n", 
        read_error[]   = "\nError reading file (%s)\n", 
        write_error[]  = "\nError writing file (%s)\n", 
        stop_here[]    = "\nStopping at user's request\n", 
        answer_yes[]   = "Yes\r", 
        answer_no[]    = "No\r", 
        done[]         = "PolyComm completed normally\n", 
        cfg_file[]     = "POLYCOMM", 
        cfg_extension[]= ".CFG", 
        pb_file[]      = "POLYCOMM.PB", 
        delimit_1[]    = "= \t;\n", 
        delimit_2[]    = ", \t;\n", 
        delimit_3[]    = ";\n", 
        delimit_4[]    = " ", 
        delimit_eol[]  = "\n", 
        beep[]         = "\a", 
        help[]         = 
            "  Usage:  PolyComm  config\n\n" 
            "  Where:  config  is the name of the configuration file\n"; 
 
 
#define COMPORT     "COMPORT"               // configuration file keywords 
#define COMSETTING  "COMSETTING" 
#define FLOWCTL     "FLOWCTL" 
#define NOCOMCHECK  "NOCOMCHECK" 
#define COM         "COM" 
#define PC          "PC:" 
#define ON          "ON" 
#define OFF         "OFF" 
#define CMD_INIT    commands[0][1]          // commands[] index 
#define CMD_DIAL    commands[1][1] 
#define CMD_EXECUTE commands[2][1] 
#define CMD_RESET   commands[3][1] 
#define CMD_CONNECT commands[4][1] 
#define CMD_NO_CONN commands[5][1] 
#define CMD_OK      commands[6][1] 
#define CMD_ERROR   commands[7][1] 
 
 
 
/* ******************************************************************** * 
 * 
 *  Line parameters structure 
 * 
 * ******************************************************************** */ 
 
struct  line_parameters                     // line parameters 
    { 
    char *parm,                                 // coded line parm 
          idx,                                  // grouping index number 
          next;                                 // index of next item 
    UINT  value;                                // data value for entry 
    } line_parms[] = 
        { 
        { "300",   0,  1,   384 },              // baud rates 
        { "1200",  0,  2,    96 }, 
        { "2400",  0,  3,    48 }, 
        { "4800",  0,  4,    24 }, 
        { "9600",  0,  5,    12 }, 
        { "19200", 0,  0,     6 }, 
        { "None",  1,  7,     0 },              // parity settings 
        { "Even",  1,  8,  0x18 }, 
        { "Odd",   1,  6,  0x08 }, 
        { "8",     2, 10,     3 },              // data bits 
        { "7",     2,  9,     2 }, 
        { "1",     3, 12,     0 },              // stop bits 
        { "2",     3, 11,     4 } 
        }; 
 
#define LINE_SPEED  &line_parms[4]          // default entries   9600 
#define LINE_PARITY &line_parms[6]          // ..for line array     N 
#define LINE_DATA   &line_parms[9]          //                      8 
#define LINE_STOP   &line_parms[11]         //                      1 
 
#define SPEED       0                       // defines for line parameter 
#define PARITY      1                       // ..array entries 
#define DATA        2 
#define STOP        3 
 
 
 
/* ******************************************************************** * 
 * 
 *  Globals 
 * 
 * ******************************************************************** */ 
 
int     rc = 1,                             // errorlevel return code 
        key,                                // last key field 
        quit_flag,                          // termination flag 
        full_screen,                        // full screen mode active 
        term_cn = MIX(WHITE, BLUE),         // terminal screen normal 
        term_cr = MIX(GREEN, BLUE),         // ..and reverse colors 
        stat_cn = MIX(BLUE, CYAN),          // status line 
        mono_1 = MIX(WHITE, BLACK),         // mono color schemes 
        mono_2 = MIX(BLACK, LIGHTGRAY),     // ..for all windows 
        flowctl,                            // flow control flag 
        comcheck = 1,                       // check com ports 
        comport = -1;                       // current com port 
 
char    nbr_ports,                          // number of ports found 
        phone_changed,                      // phonebook changed flag 
        pb_path[MAX_PATH],                  // fully qualified phone file 
       *commands[8][2] =                    // command strings 
            { 
            { "INIT",       "ATZ"        }, //  initialization command 
            { "DIAL",       "ATD"        }, //  cmd to start dialing 
            { "EXECUTE",    "\r"         }, //  cmd to cause execution 
            { "RESETCMD",   "ATV1Q0"     }, //  command to reset modem 
            { "CONNECT",    "CONNECT"    }, //  connection established 
            { "NO-CONNECT", "NO CARRIER" }, //  no connection message 
            { "OK",         "OK"         }, //  OK response 
            { "ERROR",      "ERROR"      }  //  error response 
            }; 
 
void    (interrupt far *old_break)(void);   // old ^break handler address 
 
List    user_commands;                      // define list header for 
                                            // ..user's modem commands 
 
Window  *term;                              // terminal emulator window 
Comm    *comm;                              // active comm instance 
 
struct                                      // selected line parameters 
    { 
    char *name;                             //  parameter name 
    struct line_parameters *lp;             //  selected option 
    } line[4] = 
        {                                   //  defaults 
        { "Speed",     LINE_SPEED  },       //    9600 baud 
        { "Parity",    LINE_PARITY },       //    no parity 
        { "Data Bits", LINE_DATA   },       //    8 data bits 
        { "Stop Bits", LINE_STOP   }        //    1 stop bit 
        }; 
 
enum port_type                              // port type 
    { 
    no_port,                                //  not available 
    std_uart,                               //  8250/16450/16550 
    fifo_uart                               //  16550 w/FIFO queues 
    }; 
 
struct                                      // com port table 
    { 
    int  port;                                  // port base address 
    char irq;                                   // interrupt number 
    port_type available;                        // port available flag 
    char *name;                                 // port name 
    } com_ports[8] = 
        { 
        { 0x3f8, 4, no_port, "COM1:" },         // COM1: 
        { 0x2f8, 3, no_port, "COM2:" },         // COM2: 
        { 0x3e8, 4, no_port, "COM3:" },         // COM3: 
        { 0x2e8, 3, no_port, "COM4:" },         // COM4: 
        { 0,     0, no_port, "COM5:" },         // COM5: 
        { 0,     0, no_port, "COM6:" },         // COM6: 
        { 0,     0, no_port, "COM7:" },         // COM7: 
        { 0,     0, no_port, "COM8:" },         // COM8: 
        }; 
 
 
struct  phone_entry                         // dialing phonebook 
    { 
    char *strings[4];                       // character strings 
    struct line_parameters *lp[4];          // line options 
    } phonebook[10]; 
 
#define PB_LEN      32                      // length of string fields 
#define PB_NAME     strings[0]              // entry name field 
#define PB_PHONE    strings[1]              // modem phone number 
#define PB_FAX      strings[2]              // fax phone number 
#define PB_MODEM    strings[3]              // modem set up string 
#define PB_BAUD     lp[0]                   // baud rate entry 
#define PB_PAR      lp[1]                   // parity entry 
#define PB_DATA     lp[2]                   // data bits entry 
#define PB_STOP     lp[3]                   // stop bit entry 
 
 
 
/* ******************************************************************** * 
 * 
 *  Menu tree 
 * 
 * ******************************************************************** */ 
 
Menu main_menu(0,        "÷÷", 0, 0, ' ');  // Alt-Space menu 
Menu menu_10(&main_menu,   "About", about, 1);  // Give version info 
Menu menu_11(&menu_10,     "Exit", pc_exit);    // Exit program 
 
Menu menu_20(&main_menu, "Configure");      // Configuration menu 
Menu menu_21(&menu_20,     "Ports", ports, 1);  // Ports submenu 
Menu menu_22(&menu_21,     "Comm Parms",        // Comm parms submenu 
                                comm_parms); 
 
Menu menu_30(&main_menu, "Dial");           // Dialing menu 
Menu menu_31(&menu_30,     "Phonebook",         // Phonebook display 
                                phone_list, 1); 
Menu menu_32(&menu_31,     "Hangup", hangup);   // Hangup command 
 
Menu menu_40(&main_menu, "TransferFile");   // Transfer protocols 
Menu menu_41(&menu_40,     "Download", 0, 1);   // Download submenu 
Menu menu_42(&menu_41,       "Xmodem",              // Xmodem protocol 
                                dl_xmodem, 1); 
Menu menu_44(&menu_42,       "Ymodem",              // Ymodem protocol 
                                dl_ymodem); 
Menu menu_45(&menu_41,     "Upload");           // Upload submenu 
Menu menu_46(&menu_45,       "Xmodem",              // Xmodem protocol 
                                ul_xmodem, 1); 
Menu menu_48(&menu_46,       "Ymodem",              // Ymodem protocol 
                                ul_ymodem); 
 
Menu menu_50(&main_menu, "FAX");            // Send and receive faxes 
Menu menu_51(&menu_50,     "Receive",           // Receive a fax 
                                rcv_fax, 1); 
Menu menu_52(&menu_51,     "Send",              // Send a fax 
                                send_fax);