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-2013 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, mark@rexx.org http://www.rexx.org/
34 */
35
36
37 #include <the.h>
38 #include <proto.h>
39
40 /***********************************************************************/
41 #ifdef HAVE_PROTO
add_reserved_line(CHARTYPE * spec,CHARTYPE * line,short base,short off,COLOUR_ATTR * attr,bool autoscroll)42 RESERVED *add_reserved_line(CHARTYPE *spec,CHARTYPE *line,short base,short off,COLOUR_ATTR *attr, bool autoscroll)
43 #else
44 RESERVED *add_reserved_line(spec,line,base,off,attr,autoscroll)
45 CHARTYPE *spec,*line;
46 short base;
47 short off;
48 COLOUR_ATTR *attr;
49 bool autoscroll;
50 #endif
51 /***********************************************************************/
52 {
53 RESERVED *curr=NULL;
54 CHARTYPE *templine=line;
55
56 TRACE_FUNCTION( "reserved.c:add_reserved_line" );
57 /*
58 * First check if the row already has a reserved line on it...
59 */
60 if ( ( curr = find_reserved_line( current_screen, FALSE, 0, base, off ) ) != NULL )
61 delete_reserved_line( base, off );
62 curr = rll_add( CURRENT_FILE->first_reserved, CURRENT_FILE->first_reserved, sizeof(RESERVED) );
63 if ( CURRENT_FILE->first_reserved == NULL )
64 CURRENT_FILE->first_reserved = curr;
65 if ( templine == NULL )
66 templine = (CHARTYPE *)"";
67 if ( ( curr->line = (CHARTYPE *)(*the_malloc)( ( strlen( (DEFCHAR *)templine ) + 1 ) * sizeof(CHARTYPE) ) ) == NULL )
68 {
69 display_error( 30, (CHARTYPE *)"", FALSE );
70 TRACE_RETURN();
71 return(NULL);
72 }
73 if ( ( curr->disp = (CHARTYPE *)(*the_malloc)( ( strlen( (DEFCHAR *)templine ) + 1 ) * sizeof(CHARTYPE) ) ) == NULL )
74 {
75 display_error( 30, (CHARTYPE *)"", FALSE );
76 TRACE_RETURN();
77 return(NULL);
78 }
79 if ( ( curr->highlighting = (chtype *)(*the_malloc)( ( strlen( (DEFCHAR *)templine ) + 1 ) * sizeof(chtype) ) ) == NULL )
80 {
81 display_error( 30, (CHARTYPE *)"", FALSE );
82 TRACE_RETURN();
83 return(NULL);
84 }
85 if ( ( curr->spec = (CHARTYPE *)(*the_malloc)( ( strlen( (DEFCHAR *)spec ) + 1 ) * sizeof(CHARTYPE) ) ) == NULL )
86 {
87 display_error( 30, (CHARTYPE *)"", FALSE );
88 TRACE_RETURN();
89 return(NULL);
90 }
91 if ( ( curr->attr = (COLOUR_ATTR *)(*the_malloc)( sizeof(COLOUR_ATTR) ) ) == NULL )
92 {
93 display_error( 30, (CHARTYPE *)"", FALSE );
94 TRACE_RETURN();
95 return(NULL);
96 }
97 strcpy( (DEFCHAR *)curr->line, (DEFCHAR *)templine );
98 strcpy( (DEFCHAR *)curr->spec, (DEFCHAR *)spec );
99 curr->length = strlen( (DEFCHAR *)templine );
100 curr->base = base;
101 curr->off = off;
102 curr->autoscroll = autoscroll;
103 memcpy( curr->attr, attr, sizeof(COLOUR_ATTR) );
104 parse_reserved_line( curr );
105 TRACE_RETURN();
106 return(curr);
107 }
108 /***********************************************************************/
109 #ifdef HAVE_PROTO
find_reserved_line(CHARTYPE scrno,bool find_by_row,ROWTYPE row,short base,short off)110 RESERVED *find_reserved_line(CHARTYPE scrno,bool find_by_row,ROWTYPE row,short base,short off)
111 #else
112 RESERVED *find_reserved_line(scrno,find_by_row,row,base,off)
113 CHARTYPE scrno;
114 bool find_by_row;
115 ROWTYPE row;
116 short base,off;
117 #endif
118 /***********************************************************************/
119 {
120 RESERVED *curr=SCREEN_FILE(scrno)->first_reserved;
121
122 TRACE_FUNCTION( "reserved.c:find_reserved_line" );
123 while( curr != NULL )
124 {
125 if ( find_by_row )
126 {
127 if ( curr->base == POSITION_TOP
128 && row == curr->off - 1 )
129 break;
130 if ( curr->base == POSITION_BOTTOM
131 && row == ( curr->off + screen[scrno].rows[WINDOW_FILEAREA] ) )
132 break;
133 if ( curr->base == POSITION_MIDDLE
134 && row == ( curr->off + (screen[scrno].rows[WINDOW_FILEAREA]/2) ) - 1 )
135 break;
136 }
137 else
138 {
139 if ( curr->base == base
140 && curr->off == off )
141 break;
142 }
143 curr = curr->next;
144 }
145 TRACE_RETURN();
146 return(curr);
147 }
148 /***********************************************************************/
149 #ifdef HAVE_PROTO
delete_reserved_line(short base,short off)150 short delete_reserved_line(short base,short off)
151 #else
152 short delete_reserved_line(base,off)
153 short base,off;
154 #endif
155 /***********************************************************************/
156 {
157 RESERVED *curr=NULL;
158
159 TRACE_FUNCTION( "reserved.c:delete_reserved_line" );
160 if ( ( curr = find_reserved_line( current_screen, FALSE, 0, base, off ) ) == NULL )
161 {
162 display_error( 64, (CHARTYPE *)"", FALSE );
163 TRACE_RETURN();
164 return(RC_NO_LINES_CHANGED);
165 }
166 if ( curr->line != NULL )
167 (*the_free)(curr->line);
168 if ( curr->disp != NULL )
169 (*the_free)(curr->disp);
170 if ( curr->highlighting != NULL )
171 (*the_free)(curr->highlighting);
172 if ( curr->spec != NULL )
173 (*the_free)(curr->spec);
174 if ( curr->attr != NULL )
175 (*the_free)(curr->attr);
176 rll_del( &CURRENT_FILE->first_reserved, NULL, curr, DIRECTION_FORWARD );
177 TRACE_RETURN();
178 return(RC_OK);
179 }
180