home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / word / text / 024 / hwind.c < prev    next >
C/C++ Source or Header  |  1993-06-04  |  15KB  |  521 lines

  1. /*******************  start of original comments  ********************/
  2. /*
  3.  * Written by Douglas Thomson (1989/1990)
  4.  *
  5.  * This source code is released into the public domain.
  6.  */
  7.  
  8. /*
  9.  * Name:    hardware independent screen IO module
  10.  * Purpose: This file contains the code to interface the rest of the
  11.  *           editor to the display and input hardware.
  12.  * File:    hwind.c
  13.  * Author:  Douglas Thomson
  14.  * System:  this file is intended to be system-independent
  15.  * Date:    October 2, 1989
  16.  * Notes:   This is the only module that is allowed to call the hardware
  17.  *           dependent display IO library.
  18.  *          Typically, functions here check whether any action is
  19.  *           necessary (for example, the cursor may already happen to be
  20.  *           in the required position), call hardware dependent functions
  21.  *           to achieve the required effect, and finally update status
  22.  *           information about the current state of the terminal display.
  23.  *          The idea behind this approach is to keep the hardware
  24.  *           dependent code as small and simple as possible, thus making
  25.  *           porting the code easier.
  26.  */
  27. /*********************  end of original comments   ********************/
  28.  
  29.  
  30. /*
  31.  * Some routines were added to display current editor modes in the lite bar
  32.  * at the bottom of the screen. Other routines were rewritten in assembly.
  33.  * I feel the need for speed.
  34.  *
  35.  * New editor name:  TDE, the Thomson-Davis Editor.
  36.  * Author:           Frank Davis
  37.  * Date:             June 5, 1991, version 1.0
  38.  * Date:             July 29, 1991, version 1.1
  39.  * Date:             October 5, 1991, version 1.2
  40.  * Date:             January 20, 1992, version 1.3
  41.  * Date:             February 17, 1992, version 1.4
  42.  * Date:             April 1, 1992, version 1.5
  43.  * Date:             June 5, 1992, version 2.0
  44.  * Date:             October 31, 1992, version 2.1
  45.  * Date:             April 1, 1993, version 2.2
  46.  * Date:             June 5, 1993, version 3.0
  47.  *
  48.  * This modification of Douglas Thomson's code is released into the
  49.  * public domain, Frank Davis.  You may distribute it freely.
  50.  */
  51.  
  52. #include <bios.h>       /* for REGS */
  53. #include <dos.h>        /* for intdos */
  54.  
  55. #include "tdestr.h"
  56. #include "common.h"
  57. #include "tdefunc.h"
  58. #include "define.h"
  59.  
  60.  
  61. /*
  62.  * Name:    get_date
  63.  * Purpose: get system date from DOS
  64.  * Date:    June 5, 1992
  65.  * Passed:  year:  pointer to integer to store year
  66.  *          month: pointer to integer to store month
  67.  *          day:   pointer to integer to store day
  68.  *          day_of_week:  pointer to integer to store dow
  69.  * Notes:   call standard DOS interrupt 0x21, function 0x2a to get the date.
  70.  */
  71. void get_date( int *year, int *month, int *day, int *day_of_week  )
  72. {
  73. union REGS inregs, outregs;
  74.  
  75.    inregs.h.ah = 0x2a;
  76.    intdos( &inregs, &outregs );
  77.    *year        = (int)outregs.x.cx;
  78.    *month       = (int)outregs.h.dh;
  79.    *day         = (int)outregs.h.dl;
  80.    *day_of_week = (int)outregs.h.al;
  81. }
  82.  
  83.  
  84. /*
  85.  * Name:    get_time
  86.  * Purpose: get system time from DOS
  87.  * Date:    June 5, 1992
  88.  * Passed:  hour:  pointer to integer to store hour - system returns 24 hour
  89.  *          minutes:  pointer to integer to store minutes
  90.  *          seconds:  pointer to integer to store seconds
  91.  *          hundredths:  pointer to integer to store hundredths of second
  92.  * Notes:   call standard DOS interrupt 0x21, function 0x2c to get the time.
  93.  */
  94. void get_time( int *hour, int *minutes, int *seconds, int *hundredths  )
  95. {
  96. union REGS inregs, outregs;
  97.  
  98.    inregs.h.ah = 0x2c;
  99.    intdos( &inregs, &outregs );
  100.    *hour       = (int)outregs.h.ch;
  101.    *minutes    = (int)outregs.h.cl;
  102.    *seconds    = (int)outregs.h.dh;
  103.    *hundredths = (int)outregs.h.dl;
  104. }
  105.  
  106.  
  107. /*
  108.  * Name:    show_modes
  109.  * Purpose: show current editor modes in lite bar at bottom of screen
  110.  * Date:    June 5, 1991
  111.  */
  112. void show_modes( void )
  113. {
  114. char status_line[MAX_COLS+2];
  115.  
  116.    memset( status_line, ' ', MAX_COLS );
  117.    status_line[MAX_COLS] = '\0';
  118.    s_output( status_line, g_display.mode_line, 0, g_display.mode_color );
  119.    s_output( "F=   W=", g_display.mode_line, 1, g_display.mode_color );
  120.    s_output( "m=", g_display.mode_line, 12, g_display.mode_color );
  121.    show_window_count( g_status.window_count );
  122.    show_file_count( g_status.file_count );
  123.    show_avail_mem( );
  124.    show_tab_modes( );
  125.    show_indent_mode( );
  126.    show_sync_mode( );
  127.    show_control_z( );
  128.    show_insert_mode( );
  129.    show_search_case( );
  130.    show_wordwrap_mode( );
  131.    show_trailing( );
  132. }
  133.  
  134.  
  135. /*
  136.  * Name:    show_file_count
  137.  * Purpose: show number of open files in lite bar at bottom of screen
  138.  * Passed:  fc:  file count - number of open files
  139.  * Date:    June 5, 1991
  140.  */
  141. void show_file_count( int fc )
  142. {
  143. char status_line[MAX_COLS+2];
  144.  
  145.    s_output( "  ", g_display.mode_line, 3, g_display.mode_color );
  146.    s_output( itoa( fc, status_line, 10 ), g_display.mode_line, 3,
  147.              g_display.mode_color );
  148. }
  149.  
  150.  
  151. /*
  152.  * Name:    show_window_count
  153.  * Purpose: show total number of windows in lite bar at bottom of screen
  154.  * Passed:  wc:  window count - visible and hidden.
  155.  * Date:    September 13, 1991
  156.  */
  157. void show_window_count( int wc )
  158. {
  159. char status_line[MAX_COLS+2];
  160.  
  161.    s_output( "  ", g_display.mode_line, 8, g_display.mode_color );
  162.    s_output( itoa( wc, status_line, 10 ), g_display.mode_line, 8,
  163.              g_display.mode_color );
  164. }
  165.  
  166.  
  167. /*
  168.  * Name:    show_avail_mem
  169.  * Purpose: show available free memory in lite bar at bottom of screen
  170.  * Date:    June 5, 1991
  171.  */
  172. void show_avail_mem( void )
  173. {
  174. char line[MAX_COLS+2];
  175. unsigned long avail_mem;
  176.  
  177. #if defined( __MSC__ )
  178. unsigned paragraphs;
  179.  
  180.    _dos_allocmem( 0xffff, ¶graphs );
  181.    /*
  182.     * A paragraph is 16 bytes.  Convert paragraphs to bytes by shifting left
  183.     * 4 bits.
  184.     */
  185.    avail_mem = (long)paragraphs << 4;
  186. #else
  187.    avail_mem = farcoreleft( );
  188. #endif
  189.  
  190.    s_output( "        ", g_display.mode_line, 14, g_display.mode_color );
  191.    ultoa( avail_mem, line, 10 );
  192.    s_output( line, g_display.mode_line, 14,
  193.              g_display.mode_color );
  194. }
  195.  
  196.  
  197. /*
  198.  * Name:    show_tab_modes
  199.  * Purpose: show smart tab mode in lite bar at bottom of screen
  200.  * Date:    October 31, 1992
  201.  */
  202. void show_tab_modes( void )
  203. {
  204. char *blank_tab = "   ";
  205. char ascii_tab[10];
  206.  
  207.    s_output( tabs, g_display.mode_line, 22, g_display.mode_color );
  208.    s_output( mode.smart_tab ? smart : fixed, g_display.mode_line, 27,
  209.              g_display.mode_color );
  210.    s_output( mode.inflate_tabs ? intab : outtab, g_display.mode_line, 28,
  211.              g_display.mode_color );
  212.    s_output( blank_tab, g_display.mode_line, 29, g_display.mode_color );
  213.    s_output( itoa( mode.ptab_size, ascii_tab, 10), g_display.mode_line, 29,
  214.              g_display.mode_color );
  215. }
  216.  
  217.  
  218. /*
  219.  * Name:    show_indent_mode
  220.  * Purpose: show indent mode in lite bar at bottom of screen
  221.  * Date:    June 5, 1991
  222.  */
  223. void show_indent_mode( void )
  224. {
  225.    s_output( mode.indent ? indent : blank, g_display.mode_line, 32,
  226.              g_display.mode_color );
  227. }
  228.  
  229.  
  230. /*
  231.  * Name:    show_search_case
  232.  * Purpose: show search mode in lite bar
  233.  * Date:    June 5, 1991
  234.  */
  235. void show_search_case( void )
  236. {
  237.    s_output( mode.search_case == IGNORE ? ignore : match, g_display.mode_line,
  238.              40, g_display.mode_color );
  239. }
  240.  
  241.  
  242. /*
  243.  * Name:    show_sync_mode
  244.  * Purpose: show sync mode in lite bar
  245.  * Date:    January 15, 1992
  246.  */
  247. void show_sync_mode( void )
  248. {
  249.    s_output( mode.sync ? sync_on : sync_off, g_display.mode_line, 48,
  250.              g_display.mode_color );
  251. }
  252.  
  253.  
  254. /*
  255.  * Name:    show_wordwrap_mode
  256.  * Purpose: display state of word wrap mode
  257.  * Date:    June 5, 1991
  258.  */
  259. void show_wordwrap_mode( void )
  260. {
  261.    s_output( ww_mode[mode.word_wrap], g_display.mode_line, 54,
  262.              g_display.mode_color );
  263. }
  264.  
  265.  
  266. /*
  267.  * Name:    show_trailing
  268.  * Purpose: show state of trailing flag
  269.  * Date:    June 5, 1991
  270.  */
  271. void show_trailing( void )
  272. {
  273.    c_output( mode.trailing ? 'T' : ' ', 66, g_display.mode_line,
  274.              g_display.mode_