1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003 Stuart D. Brorson.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 /*------------------------------------------------------------------
21 * This file holds fcns involved in manipulating the STRING_LIST
22 * structure. STRING_LIST is basically a linked list of strings
24 *------------------------------------------------------------------*/
34 /*------------------------------------------------------------------
35 * Gattrib specific includes
36 *------------------------------------------------------------------*/
37 #include <libgeda/libgeda.h> /* geda library fcns */
38 #include "../include/struct.h" /* typdef and struct declarations */
39 #include "../include/prototype.h" /* function prototypes */
40 #include "../include/globals.h"
44 /*------------------------------------------------------------------
45 * This returns a pointer to a new STRING_LIST object.
46 *------------------------------------------------------------------*/
47 STRING_LIST
*s_string_list_new() {
48 STRING_LIST
*local_string_list
;
50 local_string_list
= malloc(sizeof(STRING_LIST
));
51 local_string_list
->data
= NULL
;
52 local_string_list
->next
= NULL
;
53 local_string_list
->prev
= NULL
;
54 local_string_list
->pos
= -1; /* can look for this later . . . */
56 return local_string_list
;
60 /*------------------------------------------------------------------
61 * This fcn inserts the item into a char* list. It first cycles through the
62 * list to make sure that there are no duplications. The list is assumed
63 * to be a STRING_LIST:
71 *------------------------------------------------------------------*/
72 void s_string_list_add_item(STRING_LIST
*list
, int *count
, char *item
) {
74 gchar
*trial_item
= NULL
;
76 STRING_LIST
*local_list
;
78 /* First check to see if list is empty. Handle insertion of first item
79 into empty list separately. (Is this necessary?) */
80 if (list
->data
== NULL
) {
82 printf("In s_string_list_add_item, about to place first item in list.\n");
84 list
->data
= (gchar
*) u_basic_strdup(item
);
86 list
->prev
= NULL
; /* this may have already been initialized. . . . */
87 list
->pos
= (int) count
; /* This enumerates the pos on the list. Value is reset later by sorting. */
88 (*count
)++; /* increment count to 1 */
92 /* Otherwise, loop through list looking for duplicates */
94 while (list
!= NULL
) {
95 trial_item
= (gchar
*) u_basic_strdup(list
->data
);
96 if (strcmp(trial_item
, item
) == 0) {
97 /* Found item already in list. Just return. */
106 /* If we are here, it's 'cause we didn't find the item pre-existing in the list. */
107 /* In this case, we insert it. */
109 local_list
= malloc(sizeof(STRING_LIST
)); /* allocate space for this list entry */
110 local_list
->data
= (gchar
*) u_basic_strdup(item
); /* copy data into list */
111 local_list
->next
= NULL
;
112 local_list
->prev
= prev
; /* point this item to last entry in old list */
113 prev
->next
= local_list
; /* make last item in old list point to this one. */
114 local_list
->pos
= (int) count
; /* This enumerates the pos on the list. Value is reset later by sorting. */
115 (*count
)++; /* increment count */
121 /*------------------------------------------------------------------
122 * This fcn looks for item in the list. It returns 1 if item is
123 * present, 0 if absent.
124 *------------------------------------------------------------------*/
125 int s_string_list_in_list(STRING_LIST
*list
, char *item
) {
127 gchar
*trial_item
= NULL
;
129 /* First check to see if list is empty. If empty, return
130 * 0 automatically. (I probably don't need to handle this
132 if (list
->data
== NULL
) {
136 /* Otherwise, loop through list looking for duplicates */
137 while (list
!= NULL
) {
138 trial_item
= (gchar
*) u_basic_strdup(list
->data
);
139 if (strcmp(trial_item
, item
) == 0) {
140 /* Found item already in list. return 1. */
148 /* If we are here, it's 'cause we didn't find the item
149 * pre-existing in the list. In this case, return 0 */
156 /*------------------------------------------------------------------
157 * This fcn takes the master comp list sheet_head->master_comp_list_head
158 * and sorts it in this order:
159 * <all refdeses in alphabetical order>
160 * Right now it does nothing other than fill in the "position"
161 * and "length" variables.
162 *------------------------------------------------------------------*/
163 void s_string_list_sort_master_comp_list() {
165 STRING_LIST
*local_list
;
167 /* Here's where we do the sort. The sort is done using a fcn found on the web. */
168 local_list
= sheet_head
->master_comp_list_head
;
169 local_list
= listsort(local_list
, 0, 1);
171 /* Do this after sorting is done. This resets the order of the individual items
173 while (local_list
!= NULL
) { /* make sure item is not null */
175 if (local_list
->next
!= NULL
) {
177 local_list
= local_list
->next
;
179 break; /* leave loop *before* iterating to NULL EOL marker */
183 /* Now go to first item in local list and reassign list head to new first element */
184 while (local_list
->prev
!= NULL
) {
185 local_list
= local_list
->prev
;
188 sheet_head
->master_comp_list_head
= local_list
;
193 /*------------------------------------------------------------------
194 * This fcn takes the master comp attrib list sheet_head->master_comp_attrib_list_head
195 * and sorts it in this order:
196 * <all refdeses in alphabetical order>
197 * Right now it does nothing other than fill in the "position"
198 * and "length" variables.
199 *------------------------------------------------------------------*/
200 void s_string_list_sort_master_comp_attrib_list() {
202 STRING_LIST
*local_list
;
204 /* Here's where we do the sort */
207 * Note that this sort is TBD -- it is more than just an alphabetic sort 'cause we want
208 * certain attribs to go first.
212 /* Do this after sorting is done. This resets the order of the individual items
214 local_list
= sheet_head
->master_comp_attrib_list_head
;
215 while (local_list
!= NULL
) {
218 local_list
= local_list
->next
;
224 /*------------------------------------------------------------------
225 * This fcn takes the master net list sheet_head->master_net_list_head
226 * and sorts it in this order:
227 * <all nets in alphabetical order>
228 *------------------------------------------------------------------*/
229 void s_string_list_sort_master_net_list() {
231 STRING_LIST
*local_list
;
234 /* Do this after sorting is done. This resets the order of the individual items
236 local_list
= sheet_head
->master_net_list_head
;
237 while (local_list
!= NULL
) {
240 local_list
= local_list
->next
;
246 /*------------------------------------------------------------------
247 * This fcn takes the master net attrib list sheet_head->master_net_attrib_list_head
248 * and sorts it in this order:
249 * value, footprint, model-name, file, <all other attribs in alphabetical order>
250 *------------------------------------------------------------------*/
251 void s_string_list_sort_master_net_attrib_list() {
253 STRING_LIST
*local_list
;
256 /* Do this after sorting is done. This resets the order of the individual items
258 local_list
= sheet_head
->master_net_attrib_list_head
;
259 while (local_list
!= NULL
) {
262 local_list
= local_list
->next
;
269 /*------------------------------------------------------------------
270 * This fcn takes the master pin list sheet_head->master_pin_list_head
271 * and sorts it in this order:
272 * <all refdeses in alphabetical order>
273 * Right now it does nothing other than fill in the "position"
274 * and "length" variables.
275 *------------------------------------------------------------------*/
276 void s_string_list_sort_master_pin_list() {
278 STRING_LIST
*local_list
;
280 /* Here's where we do the sort. The sort is done using a fcn found on the web. */
281 local_list
= sheet_head
->master_pin_list_head
;
282 local_list
= listsort(local_list
, 0, 1);
284 /* Do this after sorting is done. This resets the order of the individual items
286 while (local_list
!= NULL
) { /* make sure item is not null */
288 if (local_list
->next
!= NULL
) {
290 local_list
= local_list
->next
;
292 break; /* leave loop *before* iterating to NULL EOL marker */
296 /* Now go to first item in local list and reassign list head to new first element */
297 while (local_list
->prev
!= NULL
) {
298 local_list
= local_list
->prev
;
301 sheet_head
->master_pin_list_head
= local_list
;
306 /*------------------------------------------------------------------
307 * This fcn takes the master pin attrib list sheet_head->master_pin_attrib_list_head
308 * and sorts it in this order:
309 * <all pin attribs in alphabetical order>
310 * Right now it does nothing other than fill in the "position"
311 * and "length" variables.
312 *------------------------------------------------------------------*/
313 void s_string_list_sort_master_pin_attrib_list() {
315 STRING_LIST
*local_list
;
317 /* Here's where we do the sort */
320 * Note that this sort is TBD -- it is more than just an alphabetic sort 'cause we want
321 * certain attribs to go first.
325 /* Do this after sorting is done. This resets the order of the individual items
327 local_list
= sheet_head
->master_pin_attrib_list_head
;
328 while (local_list
!= NULL
) {
331 local_list
= local_list
->next
;