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


// ******************************************************************** // 
//                                                                      // 
//      FAXUTIL.CPP                                                     // 
//      Copyright (c) 1993, Michael Holmes and Bob Flanders             // 
//      C++ Communication Utilities                                     // 
//                                                                      // 
//      This file contains the main function for the fax utility        // 
//      program.  This program allows the user to view, print and       // 
//      encode ASCII text files into fax formated files.  This code     // 
//      is Borland C++ version 3.x specific.  Code for Microsoft        // 
//      C/C++ version 7 is on diskette.                                 // 
//                                                                      // 
//          Compile with:  BCC -O2-i -mc faxutil.cpp                    // 
//                                                                      // 
// ******************************************************************** // 
 
 
#include                           // standard i/o library 
#include                          // variable argument list 
#include                          // string handling routines 
#include                          // std conversion routines 
#include                          // assertion routines 
#include                             // dos functions 
#include                           // character routines 
#include                           // console functions 
#include                            // bios functions 
#include                          // directory routines 
#include                       // system types definition 
#include                          // memory routines 
#include                              // file i/o functions 
#include                           // access symbolics 
#include                           // text mode routines 
#include                        // dos create fnc flags 
 
#include "keys.h"                           // keyboard definitions 
 
#define CURSOR()    _settextcursor(0x0707)  // normal text cursor 
#define BIGCURSOR() _settextcursor(0x0000)  // insert mode cursor 
#define NOCURSOR()  _settextcursor(0x2000)  // turn off cursor 
#define COUNT(x)    (sizeof(x) / sizeof(x[0]))      // item count 
#define NOT         !                       // shorthand logical 
#define BYTE        char                    // single byte 
#define UINT        unsigned int            // unsigned integer 
#define UCHAR       unsigned char           // ..and unsigned character 
#define ULONG       unsigned long           // ..and unsigned long 
#define MAX_PATH    79                      // maximum path length 
#define MIX(x,y)    ((x << 4) + (y))        // mix colors for fg and bg 
#define FG(x)       (unsigned char) x >> 4  // extract foreground color 
#define BG(x)       x & 0x07                // ..and background color 
#define IN(x)       _inp(base + x)          // read a UART register 
#define OUT(x,y)    _outp(base + x, y)      // ..and write a register 
#define NULLPTR(x)  &x ? x : ""             // make null ptr point to null 
#define LAST(s)     s[strlen(s) - 1]        // last character in string 
#define SECS(x)     (long) (x * 182L) / 10L // seconds to ticks conversion 
#define TRUE        1                       // true value 
#define FALSE       0                       // false value 
#define PELS        1728                    // pixels per line 
#define LINE        PELS / 8                // bytes per line 
#define LINES       1143                    // lines per page 
#define PAGE        ((long)LINE * LINES)    // bitmap size 
#define COLUMNS     PELS / 16               // max chars per line 
#define ROWS        LINES / 22              // ..and max lines per page 
#define DLE         0x10                    // DLE character 
#define ETX         0x3                     // ..and ETX character 
#define ESC_CHAR    "\x1b"                  // escape char for printer 
 
#define MK_FP(s,o)  (((long) s << 16) | (long) o)  // make a long pointer 
 
#define INT_PARMS UINT es, UINT ds,         /* interrupt calling conv  */\ 
                  UINT di, UINT si,                                      \ 
                  UINT bp, UINT sp,                                      \ 
                  UINT bx, UINT dx,                                      \ 
                  UINT cx, UINT ax,                                      \ 
                  UINT ip, UINT cs,                                      \ 
                  UINT flags 
 
 
/* ******************************************************************** * 
 * 
 *  Routine definitions 
 * 
 * ******************************************************************** */ 
 
void    initialization(int, char *[]),      // initialization 
        wait(long);                         // wait a number of ticks 
 
int     f_exit(int, int),                   // menu exit routine 
        f_open(int, int),                   // fax file open routine 
        f_format(int, int),                 // format ASCII file routine 
        f_lpt1(int, int),                   // fax print for LPT1: 
        f_lpt2(int, int),                   // ..LPT2: 
        f_lpt3(int, int),                   // ..and LPT3: 
        f_view(int, int),                   // view fax onscreen 
        get_key(int);                       // get any type of key 
 
 
 
/* ******************************************************************** * 
 * 
 *  Includes 
 * 
 * ******************************************************************** */ 
 
#include "screen.cpp"                       // screen handling routines 
#include "window.cpp"                       // window class 
#include "menu.cpp"                         // menu class 
#include "fglobal.cpp"                      // strings and global data 
#include "futility.cpp"                     // utility functions 
#include "codeword.cpp"                     // codewords for G3 encoding 
#include "asciimap.cpp"                     // bitmap of ASCII chars 
#include "fconvert.cpp"                     // conversion routines 
#include "ffile.cpp"                        // file menu functions 
#include "fprint.cpp"                       // print menu functions 
#include "fview.cpp"                        // view menu functions 
 
 
 
/* ******************************************************************** * 
 * 
 *  main() -- mainline 
 * 
 * ******************************************************************** */ 
 
void   main(int argc,                       // command line token count 
            char *argv[])                   // ..and command line tokens 
{ 
 
 
printf(copyright);                          // display copyright msg 
initialization(argc, argv);                 // init and parse cmd line 
 
while(NOT quit_flag)                        // loop 'til user requests out 
    main_menu.Display(0x100);               // ..else display menu, always 
 
clrscr();                                   // clean up screen 
rc = 0;                                     // clear DOS errorlevel 
quit_with(done);                            // ..and give completion msg 
 
} 
 
 
 
/* ******************************************************************** * 
 * 
 *  initialization() -- perform framework initializations 
 * 
 * ******************************************************************** */ 
 
void    initialization(int  ac,             // command line token count 
                       char *av[])          // ..and command line tokens 
{ 
struct  videoconfig vc;                     // screen info structure 
 
 
old_break = _dos_getvect(0x1b);             // get old ^break handler addr 
 
if (ac > 1 ||                               // q. need help.. 
            NOT strcmp(av[1], "/?"))        // ..or want help? 
    quit_with(help);                        // a. yes .. give help/quit 
 
_dos_setvect(0x1b, control_break);          // set up control break 
_dos_setvect(0x24, critical_routine);       // ..and DOS critical handler 
 
_getvideoconfig(&vc);                       // get current screen info 
max_lines = vc.numtextrows;                 // save maximum nbr of lines 
 
if (vc.numtextcols != 80)                   // q. not equal to 80 columns? 
    quit_with(bad_width);                   // a. yes .. give error/quit 
 
if (vc.mode == _TEXTBW80 ||                 // q. black and white mode.. 
            vc.mode == _TEXTMONO)           // ..or monochrome mode? 
    { 
    main_menu.SetColors(mono_1, mono_2);    // a. yes .. set up for 
    term_cn = mono_2;                       // ..monochrome display 
    term_cr = mono_1;                       // ..for all windows 
    stat_cn = mono_1; 
    } 
 
if (vc.mode == _TEXTMONO)                   // q. mono adapter? 
    vid_seg = (char huge *)MK_FP(0xb000, 0);// a. yes .. use mono memory 
 
page = (char *) malloc_chk(PAGE);           // get memory for bitmap 
wait_ms(1000L);                             // wait a little bit 
full_screen = 1;                            // show init complete 
 
_wscroll = 1;                               // set scrolling mode 
term = new Window(1, 1, 80, 24,             // define main window 
              term_cn, term_cr);            // ..and its colors 
term->Open(none);                           // ..then open w/o borders 
 
status_line(status, "");                    // clear status line 
 
} 
 
 
 
/* ******************************************************************** * 
 * 
 *  f_exit() -- user exit request, called from memu entry 
 * 
 * ******************************************************************** */ 
 
int     f_exit(int c, int r)                // column and row 
{ 
 
quit_flag = 1;                              // set termination flag 
return(ESC);                                // return with an ESC to 
                                            // ..cause menu to return 
}