1 /*******************************************************************************
2 * Copyright (c) 2013-2021, Andrés Martinelli <andmarti@gmail.com> *
3 * All rights reserved. *
4 * *
5 * This file is a part of SC-IM *
6 * *
7 * SC-IM is a spreadsheet program that is based on SC. The original authors *
8 * of SC are James Gosling and Mark Weiser, and mods were later added by *
9 * Chuck Martin. *
10 * *
11 * Redistribution and use in source and binary forms, with or without *
12 * modification, are permitted provided that the following conditions are met: *
13 * 1. Redistributions of source code must retain the above copyright *
14 * notice, this list of conditions and the following disclaimer. *
15 * 2. Redistributions in binary form must reproduce the above copyright *
16 * notice, this list of conditions and the following disclaimer in the *
17 * documentation and/or other materials provided with the distribution. *
18 * 3. All advertising materials mentioning features or use of this software *
19 * must display the following acknowledgement: *
20 * This product includes software developed by Andrés Martinelli *
21 * <andmarti@gmail.com>. *
22 * 4. Neither the name of the Andrés Martinelli nor the *
23 * names of other contributors may be used to endorse or promote products *
24 * derived from this software without specific prior written permission. *
25 * *
26 * THIS SOFTWARE IS PROVIDED BY ANDRES MARTINELLI ''AS IS'' AND ANY *
27 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
29 * DISCLAIMED. IN NO EVENT SHALL ANDRES MARTINELLI BE LIABLE FOR ANY *
30 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;*
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
36 *******************************************************************************/
37
38 /**
39 * \file marks.c
40 * \author Andrés Martinelli <andmarti@gmail.com>
41 * \date 2017-07-18
42 * \brief TODO Write a tbrief file description.
43 */
44
45 #include <stdlib.h>
46 #include "marks.h"
47 #include "macros.h"
48
49 #define NUM_MARKS 128
50 static struct mark * marks;
51
52 // 'a' - 'z' = 26
53 // '0' - '1' = 10
54 /**
55 * \brief TODO Document create_mark_array()
56 *
57 * \return none
58 */
59
create_mark_array()60 void create_mark_array() {
61 marks = (struct mark *) calloc(NUM_MARKS, sizeof(struct mark) );
62 return;
63 }
64
65 /**
66 * \brief TODO Document free_marks_array()
67 *
68 * \return none
69 */
70
free_marks_array()71 void free_marks_array() {
72 free(marks);
73 return;
74 }
75
76 /**
77 * \brief TODO Document get_mark()
78 *
79 * \details 'a' = 97
80 * \param[in] c
81 *
82 * \return none
83 */
84
get_mark(char c)85 struct mark * get_mark(char c) {
86 return (marks + c);
87 }
88
89 /**
90 * \brief TODO Document set_range_mark()
91 *
92 * \param[in] c
93 * \param[in] s
94 *
95 * \return none
96 */
97
set_range_mark(char c,struct srange * s)98 void set_range_mark(char c, struct srange * s) {
99 // Delete marked ranges when recording a new one with same char
100 del_ranges_by_mark(c);
101
102 (marks + c)->rng = s;
103 (marks + c)->row = -1;
104 (marks + c)->col = -1;
105 return;
106 }
107
108 /**
109 * \brief TODO Document set_cell_mark()
110 *
111 * \return none
112 */
113
set_cell_mark(char c,int row,int col)114 void set_cell_mark(char c, int row, int col) {
115 // Delete marked ranges when recording a new one with same char
116 del_ranges_by_mark(c);
117
118 (marks + c)->rng = NULL;
119 (marks + c)->row = row;
120 (marks + c)->col = col;
121 return;
122 }
123
124 /**
125 * \brief TODO Document fix_marks()
126 *
127 * \param[in] deltar
128 * \param[in] deltac
129 * \param[in] row_desde
130 * \param[in] row_hasta
131 * \param[in] coldesde
132 * \param[in] col_hasta
133 *
134 * \return none
135 */
136
fix_marks(int deltar,int deltac,int row_desde,int row_hasta,int col_desde,int col_hasta)137 void fix_marks(int deltar, int deltac, int row_desde, int row_hasta, int col_desde, int col_hasta) {
138 int i;
139 for (i = 0; i < NUM_MARKS-1; i++) {
140 struct mark * m = marks + i;
141 if (m->row >= row_desde && m->row <= row_hasta &&
142 m->col >= col_desde && m->col <= col_hasta ) {
143 m->row += deltar;
144 m->col += deltac;
145 if (m->row < 0) m->row = 0;
146 if (m->col < 0) m->col = 0;
147 }
148 }
149 return;
150 }
151
152