FAXUTIL.CPP
上传用户:xr_qian
上传日期:2007-01-05
资源大小:443k
文件大小:9k
源码类别:

通讯/手机编程

开发平台:

DOS

  1. // ******************************************************************** //
  2. //                                                                      //
  3. //      FAXUTIL.CPP                                                     //
  4. //      Copyright (c) 1993, Michael Holmes and Bob Flanders             //
  5. //      C++ Communication Utilities                                     //
  6. //                                                                      //
  7. //      This file contains the main function for the fax utility        //
  8. //      program.  This program allows the user to view, print and       //
  9. //      encode ASCII text files into fax formated files.  This code     //
  10. //      is Borland C++ version 3.x specific.  Code for Microsoft        //
  11. //      C/C++ version 7 is on diskette.                                 //
  12. //                                                                      //
  13. //          Compile with:  BCC -O2-i -mc faxutil.cpp                    //
  14. //                                                                      //
  15. // ******************************************************************** //
  16. #include <stdio.h>                          // standard i/o library
  17. #include <stdarg.h>                         // variable argument list
  18. #include <string.h>                         // string handling routines
  19. #include <stdlib.h>                         // std conversion routines
  20. #include <assert.h>                         // assertion routines
  21. #include <dos.h>                            // dos functions
  22. #include <ctype.h>                          // character routines
  23. #include <conio.h>                          // console functions
  24. #include <bios.h>                           // bios functions
  25. #include <dir.h>                            // directory routines
  26. #include <malloc.h>                         // memory routines
  27. #include <io.h>                             // file i/o functions
  28. #include <fcntl.h>                          // access symbolics
  29. #include <graphics.h>                       // graphics routines
  30. #include <sysstat.h>                       // dos create fnc flags
  31. #include "keys.h"                           // keyboard definitions
  32. #define CURSOR()    _setcursortype(_NORMALCURSOR)   // normal text cursor
  33. #define BIGCURSOR() _setcursortype(_SOLIDCURSOR)    // insert mode cursor
  34. #define NOCURSOR()  _setcursortype(_NOCURSOR)       // turn off cursor
  35. #define COUNT(x)    (sizeof(x) / sizeof(x[0]))      // item count
  36. #define NOT         !                       // shorthand logical
  37. #define BYTE        char                    // single byte
  38. #define UINT        unsigned int            // unsigned integer
  39. #define UCHAR       unsigned char           // unsigned char
  40. #define MAX_PATH    79                      // maximum path length
  41. #define MIX(x,y)    ((x << 4) + (y))        // mix colors for fg and bg
  42. #define FG(x)       (unsigned char) x >> 4  // extract foreground color
  43. #define BG(x)       x & 0x07                // ..and background color
  44. #define IN(x)       inportb(base + x)       // read a UART register
  45. #define OUT(x,y)    outportb(base + x, y)   // ..and write a register
  46. #define PELS        1728                    // pixels per line
  47. #define LINE        PELS / 8                // bytes per line
  48. #define LINES       1143                    // lines per page
  49. #define PAGE        ((long)LINE * LINES)    // bitmap size
  50. #define COLUMNS     PELS / 16               // max chars per line
  51. #define ROWS        LINES / 22              // ..and max lines per page
  52. #define DLE         0x10                    // DLE character
  53. #define ETX         0x3                     // ..and ETX character
  54. #define ESC_CHAR    "x1b"                  // escape char for printer
  55. /* ******************************************************************** *
  56.  *
  57.  *  Routine definitions
  58.  *
  59.  * ******************************************************************** */
  60. void    initialization(int, char **),       // initialization
  61.         wait(long);                         // wait a number of ticks
  62. int     f_exit(int, int),                   // menu exit routine
  63.         f_open(int, int),                   // fax file open routine
  64.         f_format(int, int),                 // format ASCII file routine
  65.         f_lpt1(int, int),                   // fax print for LPT1:
  66.         f_lpt2(int, int),                   // ..LPT2:
  67.         f_lpt3(int, int),                   // ..and LPT3:
  68.         f_view(int, int),                   // view fax onscreen
  69.         get_key(int);                       // get any type of key
  70. /* ******************************************************************** *
  71.  *
  72.  *  Includes
  73.  *
  74.  * ******************************************************************** */
  75. #include "window.cpp"                       // window class
  76. #include "menu.cpp"                         // menu class
  77. #include "fglobal.cpp"                      // strings and global data
  78. #include "futility.cpp"                     // utility functions
  79. #include "codeword.cpp"                     // codewords for G3 encoding
  80. #include "asciimap.cpp"                     // bitmap of ASCII chars
  81. #include "fconvert.cpp"                     // conversion routines
  82. #include "ffile.cpp"                        // file menu functions
  83. #include "fprint.cpp"                       // print menu functions
  84. #include "fview.cpp"                        // view menu functions
  85. /* ******************************************************************** *
  86.  *
  87.  *  main() -- mainline
  88.  *
  89.  * ******************************************************************** */
  90. void   main(int argc,                       // command line token count
  91.             char *argv[])                   // ..and command line tokens
  92. {
  93. printf(copyright);                          // display copyright msg
  94. initialization(argc, argv);                 // init and parse cmd line
  95. while(NOT quit_flag)                        // loop 'til user requests out
  96.     main_menu.Display(0x100);               // ..else display menu, always
  97. clrscr();                                   // clean up screen
  98. rc = 0;                                     // clear DOS errorlevel
  99. quit_with(done);                            // ..and give completion msg
  100. }
  101. /* ******************************************************************** *
  102.  *
  103.  *  initialization() -- perform framework initializations
  104.  *
  105.  * ******************************************************************** */
  106. void    initialization(int  ac,             // command line token count
  107.                        char *av[])          // ..and command line tokens
  108. {
  109. struct  text_info screen;                   // screen info structure
  110. old_break = _dos_getvect(0x1b);             // get old ^break handler addr
  111. if (ac > 1 ||                               // q. need help..
  112.             NOT strcmp(av[1], "/?"))        // ..or want help?
  113.     quit_with(help);                        // a. yes .. give help/quit
  114. _dos_setvect(0x1b, control_break);          // set up control break
  115. _dos_setvect(0x24, critical_routine);       // ..and DOS critical handler
  116. gettextinfo(&screen);                       // get current screen info
  117. max_lines = screen.screenheight;            // save max lines on screen
  118. if (screen.screenwidth < 80)                // q. less than 80 columns?
  119.     quit_with(bad_width);                   // a. yes .. give error/quit
  120. if (screen.currmode == BW80 ||              // q. black and white mode..
  121.             screen.currmode == MONO)        // ..or monochrome mode?
  122.     {
  123.     main_menu.SetColors(mono_1, mono_2);    // a. yes .. set up for
  124.     term_cn = mono_2;                       // ..monochrome display
  125.     term_cr = mono_1;                       // ..for all windows
  126.     stat_cn = mono_1;
  127.     }
  128. page = (char *) malloc_chk(PAGE);           // get memory for bitmap
  129. wait_ms(1000L);                             // wait a little bit
  130. full_screen = 1;                            // show init complete
  131. _wscroll = 1;                               // set scrolling mode
  132. term = new Window(1, 1, 80, 24,             // define main window
  133.               term_cn, term_cr);            // ..and its colors
  134. term->Open(none);                           // ..then open w/o borders
  135. status_line(status, "");                    // clear status line
  136. }
  137. /* ******************************************************************** *
  138.  *
  139.  *  f_exit() -- user exit request, called from memu entry
  140.  *
  141.  * ******************************************************************** */
  142. #pragma argsused                            // hold unused arg messages
  143. int     f_exit(int c, int r)                // column and row
  144. {
  145. quit_flag = 1;                              // set termination flag
  146. return(ESC);                                // return with an ESC to
  147.                                             // ..cause menu to return
  148. }