home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / thesrc15.zip / edit.c < prev    next >
C/C++ Source or Header  |  1993-11-17  |  7KB  |  197 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-1993 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@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Header: C:\THE\RCS\edit.c 1.4 1993/09/01 16:26:15 MH Interim MH $
  41. */
  42.  
  43. #include <stdio.h>
  44. #include <time.h>
  45.  
  46. #include "the.h"
  47. #include "proto.h"
  48.  
  49. /*#define TRACE*/
  50.  bool prefix_changed=FALSE;
  51. /*-------------------------- external data ----------------------------*/
  52. extern LINE *next_line,*curr_line;
  53. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  54. extern char current_file;         /* pointer to current file */
  55. extern char number_of_views;                   /* number of open files */
  56. extern char number_of_files;                   /* number of open files */
  57. extern char current_screen;
  58. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  59. extern WINDOW *foot,*error_window;
  60. extern bool error_on_screen;
  61. extern char file_disposition;
  62. extern short file_start;
  63. extern char *dirfilename;
  64. /***********************************************************************/
  65. #ifdef PROTO
  66. void editor(void)
  67. #else
  68. void editor()
  69. #endif
  70. /***********************************************************************/
  71. {
  72. /*--------------------------- local data ------------------------------*/
  73.  short key=0;
  74.  unsigned short x,y;
  75.  int rc;
  76.  char string_key[2];
  77.  VIEW_DETAILS *save_vd=vd_current;
  78. /*--------------------------- processing ------------------------------*/
  79. #ifdef TRACE
  80.  trace_function("edit.c:    editor");
  81. #endif
  82. /*---------------------------------------------------------------------*/
  83. /* For each view, calculate the current_row value. This has to be done */
  84. /* AFTER initscr() so that the size of the filearea is known.          */
  85. /*---------------------------------------------------------------------*/
  86.  CURRENT_VIEW = vd_first;
  87.  do
  88.    {
  89.     CURRENT_VIEW->current_row = calculate_current_row(CURRENT_VIEW->current_base,
  90.                                                       CURRENT_VIEW->current_off,
  91.                                                       CURRENT_SCREEN.rows);
  92.     CURRENT_VIEW = NEXT_VIEW;
  93.    }
  94.  while(CURRENT_VIEW);
  95.  CURRENT_VIEW = save_vd;
  96. /*---------------------------------------------------------------------*/
  97. /* Display the current view(s)...                                      */
  98. /*---------------------------------------------------------------------*/
  99.  show_page();
  100.  show_heading();
  101.  show_footing();
  102.  if (CURRENT_VIEW->prefix)
  103.     wnoutrefresh(CURRENT_WINDOW_PREFIX);
  104. /*---------------------------------------------------------------------*/
  105. /* Put the cursor into the column between file time and file name for  */
  106. /* the special DIR.DIR file.                                           */
  107. /*---------------------------------------------------------------------*/
  108.  if (strcmp(CURRENT_FILE->fname,dirfilename) == 0)
  109.     wmove(CURRENT_WINDOW_MAIN,CURRENT_VIEW->current_row,file_start-1);
  110.  else
  111.     wmove(CURRENT_WINDOW_MAIN,CURRENT_VIEW->current_row,0);
  112.  
  113.  touchwin(CURRENT_WINDOW_ARROW);
  114.  wnoutrefresh(CURRENT_WINDOW_ARROW);
  115.  wmove(CURRENT_WINDOW_COMMAND,0,0);
  116.  wnoutrefresh(CURRENT_WINDOW_COMMAND);
  117.  if (file_disposition != FILE_NORMAL)
  118.    {
  119.     switch(file_disposition)
  120.       {
  121.        case FILE_NEW:
  122.                           display_error(0,(char *)"New File...");
  123.                           break;
  124.        case FILE_READONLY:
  125.                           display_error(0,(char *)"File is read-only...");
  126.                           break;
  127.        default:
  128.                           break;
  129.       }
  130.     touchwin(error_window);
  131.     wnoutrefresh(error_window);
  132.     wrefresh(CURRENT_WINDOW);
  133.    }
  134. /*---------------------------------------------------------------------*/
  135. /* The following line has been added to fix an inconsistancy in the AIX*/
  136. /* version of curses. Without this the screen would be erased by the   */
  137. /* doupdate().                                                         */
  138. /*---------------------------------------------------------------------*/
  139.  clearok(stdscr,FALSE);
  140.  
  141.  doupdate();
  142.  
  143.  while (1)
  144.   {
  145.    key = my_getch(CURRENT_WINDOW);
  146.    if (error_on_screen)
  147.       {
  148.        error_on_screen = FALSE;
  149.        touchwin(foot);
  150.       }
  151.    rc = function_key(key);
  152.    if (number_of_files == 0)
  153.        break;
  154.    if (rc >= RAW_KEY)
  155.      {
  156.       if (rc > RAW_KEY)
  157.         key = rc - (RAW_KEY*2);
  158.       if (key < 256 && key >= 0)
  159.         {
  160.          string_key[0] = (char)key;
  161.          string_key[1] = '\0';
  162.          (void)Text(string_key);
  163.         }
  164.      }
  165.    if (MARK_VIEW != (VIEW_DETAILS *)NULL
  166.    &&  MARK_VIEW == CURRENT_VIEW)
  167.      {
  168.       getyx(CURRENT_WINDOW_MAIN,y,x);
  169.       show_marked_block();
  170.       wmove(CURRENT_WINDOW_MAIN,y,x);
  171.      }
  172.    wnoutrefresh(CURRENT_WINDOW_MAIN);
  173.    if (CURRENT_VIEW->prefix)
  174.       wnoutrefresh(CURRENT_WINDOW_PREFIX);
  175.    wnoutrefresh(CURRENT_WINDOW_COMMAND);
  176.    show_heading();
  177.    show_footing();
  178.  
  179.    touchwin(CURRENT_WINDOW_ARROW);
  180.    wnoutrefresh(CURRENT_WINDOW_ARROW);
  181.    wnoutrefresh(CURRENT_WINDOW);
  182.    if (error_on_screen)
  183.      {
  184.       getyx(CURRENT_WINDOW,y,x);
  185.       touchwin(error_window);
  186.       wnoutrefresh(error_window);
  187.       wmove(CURRENT_WINDOW,y,x);
  188.       wnoutrefresh(CURRENT_WINDOW);
  189.      }
  190.    doupdate();
  191.  }
  192. #ifdef TRACE
  193.  trace_return();
  194. #endif
  195.  return;
  196. }
  197.