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