2 /* Copyright (c) 1995, 2001, 2003 by Arkkra Enterprises */
3 /* All rights reserved */
5 /* functions for manipulating the main list of structs, allocating,
6 * inserting and deleting. */
15 /* allocate a new MAINLL struct and return a pointer to it */
18 newMAINLLstruct(structtype
, lineno
)
20 int structtype
; /* what kind to allocate: S_SSV, S_BAR, etc */
21 int lineno
; /* input line number that caused this call */
24 struct MAINLL
*new_p
; /* the newly allocated struct */
27 debug(4, "newMAINLLstruct lineno=%d structtype=%d", lineno
, structtype
);
29 /* allocate the struct */
30 CALLOC(MAINLL
, new_p
, 1);
32 /* fill in the type to say which union member will be used */
33 new_p
->str
= (short) structtype
;
35 /* initialize link pointers to point nowhere */
36 new_p
->next
= new_p
->prev
= (struct MAINLL
*) 0;
39 /* now allocate and initialize the proper S_* struct */
43 CALLOC(SSV
, new_p
->u
.ssv_p
, 1);
47 CALLOC(STAFF
, new_p
->u
.staff_p
, 1);
51 CALLOC(BAR
, new_p
->u
.bar_p
, 1);
55 CALLOC(LINE
, new_p
->u
.line_p
, 1);
59 CALLOC(CURVE
, new_p
->u
.curve_p
, 1);
63 CALLOC(PRHEAD
, new_p
->u
.prhead_p
, 1);
67 CALLOC(CHHEAD
, new_p
->u
.chhead_p
, 1);
71 CALLOC(FEED
, new_p
->u
.feed_p
, 1);
72 /* negative value for margin means use score parameter */
73 new_p
->u
.feed_p
->rightmargin
= -1.0;
74 new_p
->u
.feed_p
->leftmargin
= -1.0;
78 CALLOC(BLOCKHEAD
, new_p
->u
.blockhead_p
, 1);
82 CALLOC(CLEFSIG
, new_p
->u
.clefsig_p
, 1);
86 pfatal("unknown structure type %d requested", structtype
);
90 /* remember the user's input file and line number,
91 * so in case we have to print an error message later,
92 * we know which line number to print */
93 new_p
->inputlineno
= (short) lineno
;
94 new_p
->inputfile
= Curr_filename
;
96 /* return the newly allocated struct */
101 /* insert MAINLL struct into main list, after an arbitrary existing struct. */
102 /* If where to insert is NULL, put at beginning of list */
105 insertMAINLL(info_p
, where
)
107 struct MAINLL
*info_p
; /* what to insert */
108 struct MAINLL
*where
; /* put it right after this one in the list */
111 if (info_p
== where
) {
112 /* Any bug that gets us here would cause an infinite loop */
113 pfatal("attempt to insert a MAINLL after itself");
116 /* if where is NULL, this means to insert at beginning of list */
117 if (where
== (struct MAINLL
*) 0) {
118 if (Mainllhc_p
!= (struct MAINLL
*) 0) {
119 Mainllhc_p
->prev
= info_p
;
121 info_p
->prev
= (struct MAINLL
*) 0;
122 info_p
->next
= Mainllhc_p
;
127 /* standard linked list stuff --
128 * fix up the next and prev pointers */
129 info_p
->next
= where
->next
;
130 info_p
->prev
= where
;
131 if (where
->next
!= (struct MAINLL
*) 0) {
132 where
->next
->prev
= info_p
;
134 where
->next
= info_p
;
137 /* if we just added to the very end of the list, need to adjust the
139 if ( (Mainlltc_p
== (struct MAINLL
*) 0) || (where
== Mainlltc_p
) ) {
145 /* unlink a MAINLL struct from the main list
146 * (probably for re-inserting elsewhere). The struct is not freed. */
149 unlinkMAINLL(which_p
)
151 struct MAINLL
*which_p
; /* the one to unlink */
154 if (which_p
->prev
!= (struct MAINLL
*) 0) {
155 which_p
->prev
->next
= which_p
->next
;
157 if (which_p
->next
!= (struct MAINLL
*) 0) {
158 which_p
->next
->prev
= which_p
->prev
;
161 /* if this happened to be the tail cell, need to fix up */
162 if (Mainlltc_p
== which_p
) {
163 Mainlltc_p
= which_p
->prev
;
166 /* likewise for head cell */
167 if (Mainllhc_p
== which_p
) {
168 Mainllhc_p
= which_p
->next
;