1 /*
2 * Copyright (c) 2012 Sasha Vasko <sasha at aftercode.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19 #define LOCAL_DEBUG
20
21 #include "../configure.h"
22 #include "../libAfterStep/asapp.h"
23 #include "../libAfterStep/afterstep.h"
24 #include "../libAfterStep/mystyle.h"
25 #include "../libAfterStep/parser.h"
26 #include "../libAfterStep/balloon.h"
27
28 #include "afterconf.h"
29
30 /*****************************************************************************
31 *
32 * This routine is responsible for reading and parsing the config file
33 *
34 ****************************************************************************/
35
36 extern SyntaxDef AlignSyntax;
37
38
39 /*#define ASMOUNT_FEEL_TERMS \
40 ASCF_DEFINE_KEYWORD(ASMOUNT, TF_DONT_SPLIT , Action , TT_TEXT, NULL), \
41 ASCF_DEFINE_KEYWORD(ASMOUNT, 0 , FillRowsFirst , TT_FLAG, NULL), \
42 ASCF_DEFINE_KEYWORD(ASMOUNT, 0 , UseSkipList , TT_FLAG, NULL)
43 */
44 #define ASMOUNT_LOOK_TERMS \
45 ASCF_DEFINE_KEYWORD_S(ASMOUNT, 0 , Align , TT_FLAG , &AlignSyntax,ASMountConfig), \
46 ASCF_DEFINE_KEYWORD (ASMOUNT, 0 , Bevel , TT_FLAG , &BevelSyntax), \
47 ASCF_DEFINE_KEYWORD_S(ASMOUNT, 0 , MountedBevel , TT_FLAG , &BevelSyntax,ASMountConfig), \
48 ASCF_DEFINE_KEYWORD_S(ASMOUNT, 0 , UnmountedBevel , TT_FLAG , &BevelSyntax,ASMountConfig), \
49 ASCF_DEFINE_KEYWORD_S(ASMOUNT, TF_QUOTES_OPTIONAL, MountedStyle , TT_QUOTED_TEXT , NULL,ASMountConfig), \
50 ASCF_DEFINE_KEYWORD_S(ASMOUNT, TF_QUOTES_OPTIONAL, UnmountedStyle , TT_QUOTED_TEXT , NULL,ASMountConfig), \
51 ASCF_DEFINE_KEYWORD (ASMOUNT, 0 , ShapeToContents , TT_FLAG , NULL), \
52 ASCF_DEFINE_KEYWORD (ASMOUNT, 0 , ShowHints , TT_FLAG , NULL)
53
54 #define ASMOUNT_PRIVATE_TERMS \
55 ASCF_DEFINE_KEYWORD_S(ASMOUNT, 0 , TileSize , TT_GEOMETRY , NULL,ASMountConfig), \
56 ASCF_DEFINE_KEYWORD (ASMOUNT, 0 , Vertical , TT_FLAG , NULL)
57
58
59 TermDef ASMountFeelTerms[] = {
60 /* Feel */
61 // ASMOUNT_FEEL_TERMS,
62 BALLOON_FEEL_TERMS,
63 {0, NULL, 0, 0, 0}
64 };
65
66 TermDef ASMountLookTerms[] = {
67 /* Look */
68 ASMOUNT_LOOK_TERMS,
69 /* now special cases that should be processed by it's own handlers */
70 BALLOON_LOOK_TERMS,
71 {0, NULL, 0, 0, 0}
72 };
73
74 TermDef ASMountPrivateTerms[] = {
75 ASMOUNT_PRIVATE_TERMS,
76 BALLOON_FLAG_TERM,
77 {0, NULL, 0, 0, 0}
78 };
79
80 #define ASMOUNT_ALL_TERMS ASMOUNT_PRIVATE_TERMS, ASMOUNT_LOOK_TERMS
81
82
83 TermDef ASMountDefaultsTerms[] = {
84
85 ASMOUNT_ALL_TERMS,
86 /* now special cases that should be processed by it's own handlers */
87 BALLOON_TERMS,
88 INCLUDE_MODULE_DEFAULTS_END,
89 {0, NULL, 0, 0, 0}
90 };
91
92 SyntaxDef ASMountDefaultsSyntax =
93 { '\n', '\0', ASMountDefaultsTerms, 0, ' ', "", "\t",
94 "Module:ASMount_defaults", "ASMount",
95 "AfterStep module for mounting/unmounting volumes", NULL, 0
96 };
97
98
99 TermDef ASMountTerms[] = {
100 INCLUDE_MODULE_DEFAULTS (&ASMountDefaultsSyntax),
101
102 ASMOUNT_ALL_TERMS,
103
104 /* including MyStyles definitions processing */
105 INCLUDE_MYSTYLE,
106 /* now special cases that should be processed by it's own handlers */
107 BALLOON_TERMS,
108 {0, NULL, 0, 0, 0}
109 };
110
111
112 SyntaxDef ASMountFeelSyntax =
113 { '\n', '\0', ASMountFeelTerms, 0, '\t', "", "\t", "ASMountFeel",
114 "ASMountFeel",
115 "AfterStep Volumes manager module feel", NULL, 0
116 };
117
118 SyntaxDef ASMountLookSyntax =
119 { '\n', '\0', ASMountLookTerms, 0, '\t', "", "\t", "ASMountLook",
120 "ASMountLook",
121 "AfterStep Volumes manager module look", NULL, 0
122 };
123
124 SyntaxDef ASMountPrivateSyntax =
125 { '\n', '\0', ASMountPrivateTerms, 0, '\t', "", "\t", "ASMount",
126 "ASMount", "AfterStep Volumes manager module",
127 NULL, 0
128 };
129
130 SyntaxDef ASMountSyntax =
131 { '\n', '\0', ASMountTerms, 0, ' ', "", "\t", "Module:ASMount",
132 "ASMount",
133 "AfterStep module for management of storage volumes", NULL, 0
134 };
135
136
137 flag_options_xref ASMountFlags[] = {
138 ASCF_DEFINE_MODULE_FLAG_XREF (ASMOUNT, Vertical, ASMountConfig),
139 ASCF_DEFINE_MODULE_FLAG_XREF (ASMOUNT, ShapeToContents, ASMountConfig),
140 ASCF_DEFINE_MODULE_FLAG_XREF (ASMOUNT, ShowHints, ASMountConfig),
141 {0, 0, 0}
142 };
143
144 static void InitASMountConfig (ASModuleConfig * asm_config,
145 Bool free_resources);
146 void ASMount_fs2config (ASModuleConfig * asmodule_config,
147 FreeStorageElem * Storage);
148 void MergeASMountOptions (ASModuleConfig * to, ASModuleConfig * from);
149
150
151 static ASModuleConfigClass _asmount_config_class = { CONFIG_ASMount_ID,
152 0,
153 sizeof (ASMountConfig),
154 "asmount",
155 InitASMountConfig,
156 ASMount_fs2config,
157 MergeASMountOptions,
158 &ASMountSyntax,
159 &ASMountLookSyntax,
160 &ASMountFeelSyntax,
161 ASMountFlags,
162 offsetof (ASMountConfig, set_flags),
163
164 ASDefaultBalloonTypes
165 };
166
getASMountConfigClass()167 ASModuleConfigClass *getASMountConfigClass ()
168 {
169 return &_asmount_config_class;
170 }
171
172
173 static void
InitASMountConfig(ASModuleConfig * asm_config,Bool free_resources)174 InitASMountConfig (ASModuleConfig * asm_config, Bool free_resources)
175 {
176 ASMountConfig *config = AS_ASMOUNT_CONFIG (asm_config);
177
178 if (config) {
179 if (free_resources) {
180 destroy_string (&(config->MountedStyle));
181 destroy_string (&(config->UnmountedStyle));
182 }
183 config->flags = 0;
184 init_asgeometry (&(config->TileSize));
185 config->MountedBevel = config->UnmountedBevel = DEFAULT_TBAR_HILITE;
186 }
187 }
188
PrintASMountConfig(ASMountConfig * config)189 void PrintASMountConfig (ASMountConfig * config)
190 {
191 fprintf (stderr, "ASMountConfig = %p;\n", config);
192 if (config == NULL)
193 return;
194
195 fprintf (stderr, "ASMountConfig.flags = 0x%lX;\n", config->flags);
196 fprintf (stderr, "ASMountConfig.set_flags = 0x%lX;\n",
197 config->set_flags);
198 ASCF_PRINT_FLAG_KEYWORD (stderr, ASMOUNT, config, ShapeToContents);
199 ASCF_PRINT_FLAG_KEYWORD (stderr, ASMOUNT, config, Vertical);
200 ASCF_PRINT_GEOMETRY_KEYWORD (stderr, ASMOUNT, config, TileSize);
201
202 ASCF_PRINT_FLAGS_KEYWORD (stderr, ASMOUNT, config, Align);
203 ASCF_PRINT_FLAGS_KEYWORD (stderr, ASMOUNT, config, MountedBevel);
204 ASCF_PRINT_FLAGS_KEYWORD (stderr, ASMOUNT, config, UnmountedBevel);
205
206 ASCF_PRINT_STRING_KEYWORD (stderr, ASMOUNT, config, UnmountedStyle);
207 ASCF_PRINT_STRING_KEYWORD (stderr, ASMOUNT, config, MountedStyle);
208 }
209
210 void
ASMount_fs2config(ASModuleConfig * asmodule_config,FreeStorageElem * Storage)211 ASMount_fs2config (ASModuleConfig * asmodule_config,
212 FreeStorageElem * Storage)
213 {
214 FreeStorageElem *pCurr;
215 ConfigItem item;
216 ASMountConfig *config = AS_ASMOUNT_CONFIG (asmodule_config);
217
218 if (config == NULL)
219 return;
220
221 item.memory = NULL;
222 for (pCurr = Storage; pCurr; pCurr = pCurr->next) {
223 if (pCurr->term == NULL)
224 continue;
225
226 if (pCurr->term->type == TT_FLAG) {
227 if (pCurr->term->id == ASMOUNT_Bevel_ID) {
228 set_scalar_value (&(config->MountedBevel),
229 ParseBevelOptions (pCurr->sub),
230 &(config->set_flags), ASMOUNT_Bevel);
231 config->UnmountedBevel = config->MountedBevel;
232 }
233 } else {
234 if (!ReadConfigItem (&item, pCurr))
235 continue;
236
237 item.ok_to_free = 1;
238 }
239 }
240
241 ReadConfigItem (&item, NULL);
242 }
243
244 void
MergeASMountOptions(ASModuleConfig * asm_to,ASModuleConfig * asm_from)245 MergeASMountOptions (ASModuleConfig * asm_to, ASModuleConfig * asm_from)
246 {
247 START_TIME (option_time);
248
249 ASMountConfig *to = AS_ASMOUNT_CONFIG (asm_to);
250 ASMountConfig *from = AS_ASMOUNT_CONFIG (asm_from);
251
252 if (to && from) {
253 ASCF_MERGE_FLAGS (to, from);
254 ASCF_MERGE_GEOMETRY_KEYWORD (ASMOUNT, to, from, TileSize);
255 ASCF_MERGE_STRING_KEYWORD (ASMOUNT, to, from, MountedStyle);
256 ASCF_MERGE_STRING_KEYWORD (ASMOUNT, to, from, UnmountedStyle);
257 }
258 SHOW_TIME ("to parsing", option_time);
259 }
260
DigestASMountAlign(ASMountConfig * Config,ASFlagType align)261 ASFlagType DigestASMountAlign (ASMountConfig * Config, ASFlagType align)
262 {
263 return align;
264 }
265
266 void
CheckASMountConfigSanity(ASMountConfig * Config,ASGeometry * default_tile_size)267 CheckASMountConfigSanity (ASMountConfig * Config,
268 ASGeometry * default_tile_size)
269 {
270 if (Config == NULL)
271 Config =
272 AS_ASMOUNT_CONFIG (create_ASModule_config
273 (getASMountConfigClass ()));
274
275 if (default_tile_size && default_tile_size->flags != 0)
276 Config->TileSize = *default_tile_size;
277 }
278