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

通讯/手机编程

开发平台:

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 <direct.h>                         // directory routines
  26. #include <systypes.h>                      // system types definition
  27. #include <malloc.h>                         // memory routines
  28. #include <io.h>                             // file i/o functions
  29. #include <fcntl.h>                          // access symbolics
  30. #include <graph.h>                          // text mode routines
  31. #include <sysstat.h>                       // dos create fnc flags
  32. #include "keys.h"                           // keyboard definitions
  33. #define CURSOR()    _settextcursor(0x0707)  // normal text cursor
  34. #define BIGCURSOR() _settextcursor(0x0000)  // insert mode cursor
  35. #define NOCURSOR()  _settextcursor(0x2000)  // turn off cursor
  36. #define COUNT(x)    (sizeof(x) / sizeof(x[0]))      // item count
  37. #define NOT         !                       // shorthand logical
  38. #define BYTE        char                    // single byte
  39. #define UINT        unsigned int            // unsigned integer
  40. #define UCHAR       unsigned char           // ..and unsigned character
  41. #define ULONG       unsigned long           // ..and unsigned long
  42. #define MAX_PATH    79                      // maximum path length
  43. #define MIX(x,y)    ((x << 4) + (y))        // mix colors for fg and bg
  44. #define FG(x)       (unsigned char) x >> 4  // extract foreground color
  45. #define BG(x)       x & 0x07                // ..and background color
  46. #define IN(x)       _inp(base + x)          // read a UART register
  47. #define OUT(x,y)    _outp(base + x, y)      // ..and write a register
  48. #define NULLPTR(x)  &x ? x : ""             // make null ptr point to null
  49. #define LAST(s)     s[strlen(s) - 1]        // last character in string
  50. #define SECS(x)     (long) (x * 182L) / 10L // seconds to ticks conversion
  51. #define TRUE        1                       // true value
  52. #define FALSE       0                       // false value
  53. #define PELS        1728                    // pixels per line
  54. #define LINE        PELS / 8                // bytes per line
  55. #define LINES       1143                    // lines per page
  56. #define PAGE        ((long)LINE * LINES)    // bitmap size
  57. #define COLUMNS     PELS / 16               // max chars per line
  58. #define ROWS        LINES / 22              // ..and max lines per page
  59. #define DLE         0x10                    // DLE character
  60. #define ETX         0x3                     // ..and ETX character
  61. #define ESC_CHAR    "x1b"                  // escape char for printer
  62. #define MK_FP(s,o)  (((long) s << 16) | (long) o)  // make a long pointer
  63. #define INT_PARMS UINT es, UINT ds,         /* interrupt calling conv  */
  64.                   UINT di, UINT si,                                      
  65.                   UINT bp, UINT sp,                                      
  66.                   UINT bx, UINT dx,                                      
  67.                   UINT cx, UINT ax,                                      
  68.                   UINT ip, UINT cs,                                      
  69.                   UINT flags
  70. /* ******************************************************************** *
  71.  *
  72.  *  Routine definitions
  73.  *
  74.  * ******************************************************************** */
  75. void    initialization(int, char *[]),      // initialization
  76.         wait(long);                         // wait a number of ticks
  77. int     f_exit(int, int),                   // menu exit routine
  78.         f_open(int, int),                   // fax file open routine
  79.         f_format(int, int),                 // format ASCII file routine
  80.         f_lpt1(int, int),                   // fax print for LPT1:
  81.         f_lpt2(int, int),                   // ..LPT2:
  82.         f_lpt3(int, int),                   // ..and LPT3:
  83.         f_view(int, int),                   // view fax onscreen
  84.         get_key(int);                       // get any type of key
  85. /* ******************************************************************** *
  86.  *
  87.  *  Includes
  88.  *
  89.  * ******************************************************************** */
  90. #include "screen.cpp"                       // screen handling routines
  91. #include "window.cpp"                       // window class
  92. #include "menu.cpp"                         // menu class
  93. #include "fglobal.cpp"                      // strings and global data
  94. #include "futility.cpp"                     // utility functions
  95. #include "codeword.cpp"                     // codewords for G3 encoding
  96. #include "asciimap.cpp"                     // bitmap of ASCII chars
  97. #include "fconvert.cpp"                     // conversion routines
  98. #include "ffile.cpp"                        // file menu functions
  99. #include "fprint.cpp"                       // print menu functions
  100. #include "fview.cpp"                        // view menu functions
  101. /* ******************************************************************** *
  102.  *
  103.  *  main() -- mainline
  104.  *
  105.  * ******************************************************************** */
  106. void   main(int argc,                       // command line token count
  107.             char *argv[])                   // ..and command line tokens
  108. {
  109. printf(copyright);                          // display copyright msg
  110. initialization(argc, argv);                 // init and parse cmd line
  111. while(NOT quit_flag)                        // loop 'til user requests out
  112.     main_menu.Display(0x100);               // ..else display menu, always
  113. clrscr();                                   // clean up screen
  114. rc = 0;                                     // clear DOS errorlevel
  115. quit_with(done);                            // ..and give completion msg
  116. }
  117. /* ******************************************************************** *
  118.  *
  119.  *  initialization() -- perform framework initializations
  120.  *
  121.  * ******************************************************************** */
  122. void    initialization(int  ac,             // command line token count
  123.                        char *av[])          // ..and command line tokens
  124. {
  125. struct  videoconfig vc;                     // screen info structure
  126. old_break = _dos_getvect(0x1b);             // get old ^break handler addr
  127. if (ac > 1 ||                               // q. need help..
  128.             NOT strcmp(av[1], "/?"))        // ..or want help?
  129.     quit_with(help);                        // a. yes .. give help/quit
  130. _dos_setvect(0x1b, control_break);          // set up control break
  131. _dos_setvect(0x24, critical_routine);       // ..and DOS critical handler
  132. _getvideoconfig(&vc);                       // get current screen info
  133. max_lines = vc.numtextrows;                 // save maximum nbr of lines
  134. if (vc.numtextcols != 80)                   // q. not equal to 80 columns?
  135.     quit_with(bad_width);                   // a. yes .. give error/quit
  136. if (vc.mode == _TEXTBW80 ||                 // q. black and white mode..
  137.             vc.mode == _TEXTMONO)           // ..or monochrome mode?
  138.     {
  139.     main_menu.SetColors(mono_1, mono_2);    // a. yes .. set up for
  140.     term_cn = mono_2;                       // ..monochrome display
  141.     term_cr = mono_1;                       // ..for all windows
  142.     stat_cn = mono_1;
  143.     }
  144. if (vc.mode == _TEXTMONO)                   // q. mono adapter?
  145.     vid_seg = (char huge *)MK_FP(0xb000, 0);// a. yes .. use mono memory
  146. page = (char *) malloc_chk(PAGE);           // get memory for bitmap
  147. wait_ms(1000L);                             // wait a little bit
  148. full_screen = 1;                            // show init complete
  149. _wscroll = 1;                               // set scrolling mode
  150. term = new Window(1, 1, 80, 24,             // define main window
  151.               term_cn, term_cr);            // ..and its colors
  152. term->Open(none);                           // ..then open w/o borders
  153. status_line(status, "");                    // clear status line
  154. }
  155. /* ******************************************************************** *
  156.  *
  157.  *  f_exit() -- user exit request, called from memu entry
  158.  *
  159.  * ******************************************************************** */
  160. int     f_exit(int c, int r)                // column and row
  161. {
  162. quit_flag = 1;                              // set termination flag
  163. return(ESC);                                // return with an ESC to
  164.                                             // ..cause menu to return
  165. }