1 /*
2 * Copyright (c) 2000 Andrew Ferguson <andrew@owsla.cjb.net>
3 * Copyright (c) 1998 Sasha Vasko <sasha at aftercode.net>
4 *
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.
9 *
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.
14 *
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-1307, USA.
18 *
19 */
20
21
22 #define LOCAL_DEBUG
23
24 #include "../configure.h"
25
26 #include "../libAfterStep/asapp.h"
27 #include "../libAfterStep/afterstep.h"
28 #include "../libAfterStep/parser.h"
29 #include "../libAfterStep/hints.h"
30
31 #include "afterconf.h"
32
33 /*****************************************************************************
34 *
35 * This routine is responsible for reading and parsing the config file
36 *
37 ****************************************************************************/
38 TermDef AnimateResizeTerms[] = {
39 {TF_NO_MYNAME_PREPENDING, "Twist", 5, TT_FLAG, ANIMATE_ResizeTwist_ID,
40 NULL}
41 ,
42 {TF_NO_MYNAME_PREPENDING, "Flip", 4, TT_FLAG, ANIMATE_ResizeFlip_ID, NULL}
43 ,
44 {TF_NO_MYNAME_PREPENDING, "Turn", 4, TT_FLAG, ANIMATE_ResizeTurn_ID, NULL}
45 ,
46 {TF_NO_MYNAME_PREPENDING, "Zoom", 4, TT_FLAG, ANIMATE_ResizeZoom_ID, NULL}
47 ,
48 {TF_NO_MYNAME_PREPENDING, "Zoom3D", 6, TT_FLAG, ANIMATE_ResizeZoom3D_ID,
49 NULL}
50 ,
51 {TF_NO_MYNAME_PREPENDING, "Random", 6, TT_FLAG, ANIMATE_ResizeRandom_ID,
52 NULL}
53 ,
54 {0, NULL, 0, 0, 0} /* end of structure */
55 };
56
57 SyntaxDef AnimateResizeSyntax = {
58 '\0',
59 '\n',
60 AnimateResizeTerms,
61 7,
62 ' ',
63 "",
64 "\t",
65 "Module:Animate AnimateResize modes",
66 "AnimateTypes",
67 "animation modes used in the Animate module's config",
68 NULL,
69 0
70 };
71
72 TermDef AnimateTerms[] = {
73 {0, "Color", 5, TT_COLOR, ANIMATE_COLOR_ID, NULL}
74 ,
75 {0, "Delay", 5, TT_INTEGER, ANIMATE_DELAY_ID, NULL}
76 ,
77 {0, "Iterations", 10, TT_INTEGER, ANIMATE_ITERATIONS_ID, NULL}
78 ,
79 {0, "Twist", 5, TT_INTEGER, ANIMATE_TWIST_ID, NULL}
80 ,
81 {0, "Width", 5, TT_INTEGER, ANIMATE_WIDTH_ID, NULL}
82 ,
83 {0, "Resize", 6, TT_FLAG, ANIMATE_RESIZE_ID, &AnimateResizeSyntax}
84 ,
85 {0, NULL, 0, 0, 0} /* end of structure */
86
87 };
88
89 SyntaxDef AnimateSyntax = {
90 '\n',
91 '\0',
92 AnimateTerms,
93 7,
94 ' ',
95 "",
96 "\t",
97 "Module:Animate",
98 "Animate",
99 "AfterStep module animating windows being iconified/deiconified",
100 NULL,
101 0
102 };
103
104
105
CreateAnimateConfig()106 AnimateConfig *CreateAnimateConfig ()
107 {
108 AnimateConfig *config =
109 (AnimateConfig *) safecalloc (1, sizeof (AnimateConfig));
110
111 config->iterations = ANIMATE_DEFAULT_ITERATIONS;
112 config->delay = ANIMATE_DEFAULT_DELAY;
113 return config;
114 }
115
DestroyAnimateConfig(AnimateConfig * config)116 void DestroyAnimateConfig (AnimateConfig * config)
117 {
118 if (config->color)
119 free (config->color);
120 DestroyFreeStorage (&(config->more_stuff));
121 free (config);
122 }
123
ParseAnimateOptions(const char * filename,char * myname)124 AnimateConfig *ParseAnimateOptions (const char *filename, char *myname)
125 {
126 ConfigData cd;
127 ConfigDef *AnimateConfigReader;
128 AnimateConfig *config = CreateAnimateConfig ();
129
130 FreeStorageElem *Storage = NULL, *pCurr;
131 ConfigItem item;
132
133 cd.filename = filename;
134 AnimateConfigReader =
135 InitConfigReader (myname, &AnimateSyntax, CDT_Filename, cd, NULL);
136
137 if (!AnimateConfigReader)
138 return config;
139
140 item.memory = NULL;
141 PrintConfigReader (AnimateConfigReader);
142 ParseConfig (AnimateConfigReader, &Storage);
143
144 /* getting rid of all the crap first */
145 StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);
146
147 for (pCurr = Storage; pCurr; pCurr = pCurr->next) {
148 if (pCurr->term == NULL)
149 continue;
150
151 {
152 if (!ReadConfigItem (&item, pCurr))
153 continue;
154
155 switch (pCurr->term->id) {
156 case ANIMATE_COLOR_ID:
157 config->color = item.data.string;
158 break;
159 case ANIMATE_DELAY_ID:
160 set_flags (config->set_flags, ANIMATE_SET_DELAY);
161 config->delay = (int)item.data.integer;
162 break;
163 case ANIMATE_ITERATIONS_ID:
164 set_flags (config->set_flags, ANIMATE_SET_ITERATIONS);
165 config->iterations = (int)item.data.integer;
166 break;
167 case ANIMATE_TWIST_ID:
168 config->twist = (int)item.data.integer;
169 set_flags (config->set_flags, ANIMATE_SET_TWIST);
170 break;
171 case ANIMATE_WIDTH_ID:
172 config->width = (int)item.data.integer;
173 set_flags (config->set_flags, ANIMATE_SET_WIDTH);
174 break;
175 case ANIMATE_RESIZE_ID:
176 if (pCurr->sub && pCurr->sub->term) {
177 set_flags (config->set_flags, ANIMATE_SET_RESIZE);
178 config->resize = pCurr->sub->term->id - ANIMATE_RESIZE_ID_START;
179 }
180 break;
181 default:
182 item.ok_to_free = 1;
183 }
184 }
185 }
186
187 ReadConfigItem (&item, NULL);
188 DestroyConfig (AnimateConfigReader);
189 DestroyFreeStorage (&Storage);
190 return config;
191
192 }
193
194 /* returns:
195 * 0 on success
196 * 1 if data is empty
197 * 2 if ConfigWriter cannot be initialized
198 *
199 */
200 int
WriteAnimateOptions(const char * filename,char * myname,AnimateConfig * config,unsigned long flags)201 WriteAnimateOptions (const char *filename, char *myname,
202 AnimateConfig * config, unsigned long flags)
203 {
204 ConfigDef *AnimateConfigWriter = NULL;
205 FreeStorageElem *Storage = NULL, **tail = &Storage;
206 ConfigData cd;
207
208 if (config == NULL)
209 return 1;
210
211 cd.filename = filename;
212 if ((AnimateConfigWriter =
213 InitConfigWriter (myname, &AnimateSyntax, CDT_Filename,
214 cd)) == NULL)
215 return 2;
216
217 CopyFreeStorage (&Storage, config->more_stuff);
218
219 /* building free storage here */
220
221 /* color */
222 tail =
223 String2FreeStorage (&AnimateSyntax, tail, config->color,
224 ANIMATE_COLOR_ID);
225
226 /* delay */
227 tail =
228 Integer2FreeStorage (&AnimateSyntax, tail, NULL, config->delay,
229 ANIMATE_DELAY_ID);
230
231 /* iterations */
232 tail =
233 Integer2FreeStorage (&AnimateSyntax, tail, NULL, config->iterations,
234 ANIMATE_ITERATIONS_ID);
235
236 /* twist */
237 tail =
238 Integer2FreeStorage (&AnimateSyntax, tail, NULL, config->twist,
239 ANIMATE_TWIST_ID);
240
241 /* width */
242 tail =
243 Integer2FreeStorage (&AnimateSyntax, tail, NULL, config->width,
244 ANIMATE_WIDTH_ID);
245
246 /* resize */
247 if (config->resize < ANIMATE_RESIZE_ID_END - ANIMATE_RESIZE_ID_START) {
248 FreeStorageElem **d_tail = tail;
249
250 tail = Flag2FreeStorage (&AnimateSyntax, tail, ANIMATE_RESIZE_ID);
251 if (*d_tail)
252 Flag2FreeStorage (&AnimateResizeSyntax, &((*d_tail)->sub),
253 config->resize + ANIMATE_RESIZE_ID_START);
254 }
255
256 /* writing config into the file */
257 WriteConfig (AnimateConfigWriter, Storage, CDT_Filename, &cd, flags);
258 DestroyFreeStorage (&Storage);
259 DestroyConfig (AnimateConfigWriter);
260
261 if (Storage) {
262 show_error
263 ("Config Writing warning: Not all Free Storage discarded! Trying again...");
264 DestroyFreeStorage (&Storage);
265 show_error ((Storage != NULL) ? " failed." : " success.");
266 }
267 return 0;
268 }
269