2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "libs/fvwmlib.h"
24 typedef struct str_struct
26 struct str_struct
*next
;
31 /* split string val into a list of str's, each containing
32 an ordinary substring or a variable reference of the form $(bla).
33 The list is appended to pre, the last list entry is returned.
36 split_string (char *val
, str
*pre
)
38 char *s
= NULL
, *t
= NULL
;
52 /* append the part before $( */
53 curr
->next
= (str
*) safemalloc (sizeof (str
));
56 curr
->s
= safestrdup (v
);
60 /* append the variable reference, silently omit the ) */
61 curr
->next
= (str
*) safemalloc (sizeof (str
));
65 curr
->s
= safestrdup (s
+ 2);
73 /* append the part after the last variable reference */
74 curr
->next
= (str
*) safemalloc (sizeof (str
));
77 curr
->s
= safestrdup (v
);
87 combine_string (str
*p
)
93 for (l
= 1, r
= p
; r
!= NULL
; r
= r
->next
)
97 res
= (char *) safemalloc (l
* sizeof (char));
99 for (r
= p
; r
!= NULL
; r
= next
)
111 recursive_replace (GtkWidget
*d
, char *val
)
113 str
*head
, *r
, *tail
, *next
;
116 head
= (str
*) safemalloc (sizeof (str
));
118 head
->s
= safestrdup("");
121 split_string (val
, head
);
122 for (r
= head
; r
->next
!= NULL
; r
= r
->next
)
127 nval
= (char *) gtk_object_get_data (GTK_OBJECT (d
), next
->s
);
130 /* this changes r->next, thus freeing next is safe */
131 tail
= split_string (nval
, r
);
132 tail
->next
= next
->next
;
142 return combine_string (head
);