home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / edit.c < prev    next >
C/C++ Source or Header  |  1997-09-10  |  6KB  |  217 lines

  1. /***********************************************************************/
  2. /* EDIT.C - The body of the program.                                   */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1997 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  33.  * PO Box 203                    Phone:                    +617 3802 0800
  34.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  35.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  36.  * Australia                     ************* Author of THE ************
  37.  */
  38.  
  39. /*
  40. $Id: edit.c 2.1 1995/06/24 16:29:45 MH Rel MH $
  41. */
  42.  
  43.  
  44. #include <the.h>
  45. #include <proto.h>
  46.  
  47. /*#define TRACE*/
  48.  bool prefix_changed=FALSE;
  49. /***********************************************************************/
  50. #ifdef HAVE_PROTO
  51. void editor(void)
  52. #else
  53. void editor()
  54. #endif
  55. /***********************************************************************/
  56. {
  57. /*-------------------------- external data ----------------------------*/
  58.  extern bool error_on_screen;
  59.  extern WINDOW *error_window;
  60.  extern CHARTYPE display_screens;
  61. /*--------------------------- local data ------------------------------*/
  62.  short y=0,x=0;
  63. /*--------------------------- processing ------------------------------*/
  64. #ifdef TRACE
  65.  trace_function("edit.c:    editor");
  66. #endif
  67.  
  68.  if (display_screens > 1)
  69.     display_screen(other_screen);
  70.  
  71.  getyx(CURRENT_WINDOW,y,x);
  72.  wmove(CURRENT_WINDOW,y,x);
  73.  wrefresh(CURRENT_WINDOW);
  74.  if (error_on_screen)
  75.    {
  76.     if (error_window != NULL)
  77.       {
  78.        touchwin(error_window);
  79.        wrefresh(error_window);
  80.        wmove(CURRENT_WINDOW,y,x);
  81.        wrefresh(CURRENT_WINDOW);
  82.       }
  83.    }
  84.  
  85.  while (1)
  86.    {
  87.     if (process_key(-1) != RC_OK)
  88.        break;
  89.    }
  90. #ifdef TRACE
  91.  trace_return();
  92. #endif
  93.  return;
  94. }
  95. /***********************************************************************/
  96. #ifdef HAVE_PROTO
  97. int process_key(int key)
  98. #else
  99. int process_key(key)
  100. int key;
  101. #endif
  102. /***********************************************************************/
  103. {
  104. /*-------------------------- external data ----------------------------*/
  105.  extern bool error_on_screen;
  106.  extern bool initial;
  107.  extern CHARTYPE number_of_files;
  108.  extern WINDOW *error_window;
  109.  extern CHARTYPE display_screens;
  110. /*--------------------------- local data ------------------------------*/
  111.  unsigned short x=0,y=0;
  112.  short rc=RC_OK;
  113.  CHARTYPE string_key[2];
  114. /*--------------------------- processing ------------------------------*/
  115. #ifdef TRACE
  116.  trace_function("edit.c:    process_key");
  117. #endif
  118. #if defined(USE_EXTCURSES)
  119.  getyx(CURRENT_WINDOW,y,x);
  120.  wmove(CURRENT_WINDOW,y,x);
  121.  wrefresh(CURRENT_WINDOW);
  122. #endif
  123.  string_key[1] = '\0';
  124.  
  125. #ifdef CAN_RESIZE
  126.  if (is_termresized())
  127.    {
  128.     (void)THE_Resize(0,0);
  129.     (void)THERefresh((CHARTYPE *)"");
  130.    }
  131. #endif
  132.  
  133.  if (key == (-1))
  134.     key = my_getch(stdscr);
  135. #if defined (MOUSE_SUPPORT_ENABLED)
  136.     if (key == KEY_MOUSE)
  137.       {
  138.        int b,ba,bm;
  139.        if (get_mouse_info(&b,&ba,&bm) != RC_OK)
  140. #if 0
  141.        ||  (BUTTON_STATUS(b) & BUTTON_ACTION_MASK) == BUTTON_RELEASED)
  142. #endif
  143.          {
  144. #ifdef TRACE
  145.           trace_return();
  146. #endif
  147.           return(RC_OK);
  148.          }
  149.       }
  150. #endif
  151. #ifdef CAN_RESIZE
  152.  if (is_termresized())
  153.    {
  154. #ifdef TRACE
  155.     trace_return();
  156. #endif
  157.     return(RC_OK);
  158.    }
  159. #endif
  160.  
  161.  initial = FALSE;                 /* set first time a key is requested */
  162.  if (error_on_screen)
  163.     clear_msgline();
  164.  rc = function_key(key,OPTION_NORMAL);
  165.  if (number_of_files == 0)
  166.    {
  167. #ifdef TRACE
  168.     trace_return();
  169. #endif
  170.     return(RC_INVALID_ENVIRON);
  171.    }
  172.  
  173.  if (rc >= RAW_KEY)
  174.    {
  175.     if (rc > RAW_KEY)
  176.        key = rc - (RAW_KEY*2);
  177.     if (key < 256 && key >= 0)
  178.       {
  179.        string_key[0] = (CHARTYPE)key;
  180.        (void)Text(string_key);
  181.       }
  182.    }
  183.  show_statarea();
  184.  if (display_screens > 1
  185.  &&  SCREEN_FILE(0) == SCREEN_FILE(1))
  186.    {
  187.     build_screen(other_screen);
  188.     display_screen(other_screen);
  189. /*    refresh_screen(other_screen);*/
  190.     show_heading(other_screen);
  191.    }
  192.  refresh_screen(current_screen);
  193.  if (error_on_screen)
  194.    {
  195.     getyx(CURRENT_WINDOW,y,x);
  196.     if (error_window != NULL)
  197.       {
  198.        touchwin(error_window);
  199.        wnoutrefresh(error_window);
  200.       }
  201.     wmove(CURRENT_WINDOW,y,x);
  202.     wnoutrefresh(CURRENT_WINDOW);
  203.    }
  204.  
  205. #ifdef HAVE_BROKEN_SYSVR4_CURSES
  206.  getyx(CURRENT_WINDOW,y,x);
  207.  wmove(CURRENT_WINDOW,y,x);
  208.  wrefresh(CURRENT_WINDOW);
  209. #else
  210.  doupdate();
  211. #endif
  212. #ifdef TRACE
  213.  trace_return();
  214. #endif
  215.  return(RC_OK);
  216. }
  217.