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

  1. /***********************************************************************/
  2. /* RESERVED.C -                                                        */
  3. /* This file contains funtions related to reserved lines.              */
  4. /***********************************************************************/
  5. /*
  6.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  7.  * Copyright (C) 1991-1997 Mark Hessling
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License as
  11.  * published by the Free Software Foundation; either version 2 of
  12.  * the License, or any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17.  * General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to:
  21.  *
  22.  *    The Free Software Foundation, Inc.
  23.  *    675 Mass Ave,
  24.  *    Cambridge, MA 02139 USA.
  25.  *
  26.  *
  27.  * If you make modifications to this software that you feel increases
  28.  * it usefulness for the rest of the community, please email the
  29.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  30.  * This software is going to be maintained and enhanced as deemed
  31.  * necessary by the community.
  32.  *
  33.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  34.  * PO Box 203                    Phone:                    +617 3802 0800
  35.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  36.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  37.  * Australia                     ************* Author of THE ************
  38.  */
  39.  
  40. /*
  41. $Id: reserved.c 2.1 1995/06/24 16:31:02 MH Rel MH $
  42. */
  43.  
  44. #include <the.h>
  45. #include <proto.h>
  46.  
  47. /***********************************************************************/
  48. #ifdef HAVE_PROTO
  49. short add_reserved_line(CHARTYPE *spec,CHARTYPE *line,short base,short off,COLOUR_ATTR *attr)
  50. #else
  51. short add_reserved_line(spec,line,base,off,attr)
  52. CHARTYPE *spec,*line;
  53. short base;
  54. short off;
  55. COLOUR_ATTR *attr;
  56. #endif
  57. /***********************************************************************/
  58. {
  59. /*-------------------------- external data ----------------------------*/
  60. /*--------------------------- local data ------------------------------*/
  61.  RESERVED *curr=NULL;
  62.  CHARTYPE *templine=line;
  63. /*--------------------------- processing ------------------------------*/
  64. #ifdef TRACE
  65.  trace_function("reserved.c:add_reserved_line");
  66. #endif
  67. /*---------------------------------------------------------------------*/
  68. /* First check if the row already has a reserved line on it...         */
  69. /*---------------------------------------------------------------------*/
  70.  if ((curr = find_reserved_line(current_screen,FALSE,0,base,off)) != NULL)
  71.     delete_reserved_line(base,off);
  72.  curr = rll_add(CURRENT_FILE->first_reserved,CURRENT_FILE->first_reserved,sizeof(RESERVED));
  73.  if (CURRENT_FILE->first_reserved == NULL)
  74.     CURRENT_FILE->first_reserved = curr;
  75.  if (templine == NULL)
  76.     templine = (CHARTYPE *)"";
  77.  if ((curr->line = (CHARTYPE *)(*the_malloc)((strlen((DEFCHAR *)templine)+1)*sizeof(CHARTYPE))) == NULL)
  78.    {
  79.     display_error(30,(CHARTYPE *)"",FALSE);
  80. #ifdef TRACE
  81.     trace_return();
  82. #endif
  83.     return(RC_OUT_OF_MEMORY);
  84.    }
  85.  if ((curr->spec = (CHARTYPE *)(*the_malloc)((strlen((DEFCHAR *)spec)+1)*sizeof(CHARTYPE))) == NULL)
  86.    {
  87.     display_error(30,(CHARTYPE *)"",FALSE);
  88. #ifdef TRACE
  89.     trace_return();
  90. #endif
  91.     return(RC_OUT_OF_MEMORY);
  92.    }
  93.  if ((curr->attr = (COLOUR_ATTR *)(*the_malloc)(sizeof(COLOUR_ATTR))) == NULL)
  94.    {
  95.     display_error(30,(CHARTYPE *)"",FALSE);
  96. #ifdef TRACE
  97.     trace_return();
  98. #endif
  99.     return(RC_OUT_OF_MEMORY);
  100.    }
  101.  strcpy((DEFCHAR *)curr->line,(DEFCHAR *)templine);
  102.  strcpy((DEFCHAR *)curr->spec,(DEFCHAR *)spec);
  103.  curr->length = strlen((DEFCHAR *)templine);
  104.  curr->base = base;
  105.  curr->off = off;
  106.  memcpy(curr->attr,attr,sizeof(COLOUR_ATTR));
  107. #ifdef TRACE
  108.  trace_return();
  109. #endif
  110.  return(RC_OK);
  111. }
  112. /***********************************************************************/
  113. #ifdef HAVE_PROTO
  114. RESERVED *find_reserved_line(CHARTYPE scrno,bool find_by_row,ROWTYPE row,short base,short off)
  115. #else
  116. RESERVED *find_reserved_line(scrno,find_by_row,row,base,off)
  117. CHARTYPE scrno;
  118. bool find_by_row;
  119. ROWTYPE row;
  120. short base,off;
  121. #endif
  122. /***********************************************************************/
  123. {
  124. /*-------------------------- external data ----------------------------*/
  125. /*--------------------------- local data ------------------------------*/
  126.  RESERVED *curr=SCREEN_FILE(scrno)->first_reserved;
  127. /*--------------------------- processing ------------------------------*/
  128. #ifdef TRACE
  129.  trace_function("reserved.c:find_reserved_line");
  130. #endif
  131.  while(curr != NULL)
  132.    {
  133.     if (find_by_row)
  134.       {
  135.        if (curr->base == POSITION_TOP
  136.        &&  row == curr->off-1)
  137.           break;
  138.        if (curr->base == POSITION_BOTTOM
  139.        &&  row == (curr->off+screen[scrno].rows[WINDOW_FILEAREA]))
  140.           break;
  141.        if (curr->base == POSITION_MIDDLE
  142.        &&  row == (curr->off+(screen[scrno].rows[WINDOW_FILEAREA]/2))-1)
  143.           break;
  144.       }
  145.     else
  146.       {
  147.        if (curr->base == base
  148.        &&  curr->off == off)
  149.           break;
  150.       }
  151.     curr = curr->next;
  152.    }
  153. #ifdef TRACE
  154.  trace_return();
  155. #endif
  156.  return(curr);
  157. }
  158. /***********************************************************************/
  159. #ifdef HAVE_PROTO
  160. short delete_reserved_line(short base,short off)
  161. #else
  162. short delete_reserved_line(base,off)
  163. short base,off;
  164. #endif
  165. /***********************************************************************/
  166. {
  167. /*-------------------------- external data ----------------------------*/
  168. /*--------------------------- local data ------------------------------*/
  169.  RESERVED *curr=NULL;
  170. /*--------------------------- processing ------------------------------*/
  171. #ifdef TRACE
  172.  trace_function("reserved.c:delete_reserved_line");
  173. #endif
  174.  if ((curr = find_reserved_line(current_screen,FALSE,0,base,off)) == NULL)
  175.    {
  176.     display_error(64,(CHARTYPE *)"",FALSE);
  177. #ifdef TRACE
  178.     trace_return();
  179. #endif
  180.     return(RC_NO_LINES_CHANGED);
  181.    }
  182.  if (curr->line != NULL)
  183.     (*the_free)(curr->line);
  184.  if (curr->spec != NULL)
  185.     (*the_free)(curr->spec);
  186.  if (curr->attr != NULL)
  187.     (*the_free)(curr->attr);
  188.  rll_del(&CURRENT_FILE->first_reserved,NULL,curr,DIRECTION_FORWARD);
  189. #ifdef TRACE
  190.  trace_return();
  191. #endif
  192.  return(RC_OK);
  193. }
  194.