comparison mcabber/mcabber/modules.c @ 1736:15e1f3957786

Misc. small style changes (I.e. line length < 80 whenever possible)
author Mikael Berthe <mikael@lilotux.net>
date Sat, 06 Mar 2010 19:21:05 +0100
parents 5093b5ca1572
children 7ee390513463
comparison
equal deleted inserted replaced
1735:5093b5ca1572 1736:15e1f3957786
63 63
64 if (!arg || !*arg) 64 if (!arg || !*arg)
65 return "Missing module name"; 65 return "Missing module name";
66 66
67 { // Check if module is already loaded 67 { // Check if module is already loaded
68 GSList *lmod = g_slist_find_custom(loaded_modules, arg, module_list_comparator); 68 GSList *lmod = g_slist_find_custom(loaded_modules, arg,
69 module_list_comparator);
69 70
70 if (lmod) { 71 if (lmod) {
71 loaded_module_t *module = lmod->data; 72 loaded_module_t *module = lmod->data;
72 73
73 if (manual) { 74 if (manual) {
74 if (!module->locked) { 75 if (!module->locked) {
75 module->locked = TRUE; 76 module->locked = TRUE;
76 module->refcount += 1; 77 module->refcount += 1;
77 return force ? NULL : "Module is already automatically loaded, marked as manually loaded"; 78 return force ? NULL : "Module is already automatically loaded, "
79 "marked as manually loaded";
78 } else 80 } else
79 return force ? NULL : "Module is already loaded"; 81 return force ? NULL : "Module is already loaded";
80 } else { 82 } else {
81 module->refcount += 1; 83 module->refcount += 1;
82 return NULL; 84 return NULL;
105 if (!force) { 107 if (!force) {
106 g_free(varname); 108 g_free(varname);
107 return "Module provides no information structure"; 109 return "Module provides no information structure";
108 } 110 }
109 111
110 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: Module provides no information structure."); 112 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: "
113 "Module provides no information structure.");
111 } 114 }
112 115
113 g_free(varname); 116 g_free(varname);
114 info = var; 117 info = var;
115 } 118 }
120 if (!force) { 123 if (!force) {
121 g_module_close(mod); 124 g_module_close(mod);
122 return "Module requires newer version of mcabber"; 125 return "Module requires newer version of mcabber";
123 } 126 }
124 127
125 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: Module requires newer version of mcabber."); 128 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: "
129 "Module requires newer version of mcabber.");
126 } 130 }
127 131
128 // Load dependencies 132 // Load dependencies
129 if (info && info->requires) { 133 if (info && info->requires) {
130 const gchar **dep; 134 const gchar **dep;
132 for (dep = info->requires; *dep; ++dep) { 136 for (dep = info->requires; *dep; ++dep) {
133 const gchar *err = module_load(*dep, FALSE, FALSE); 137 const gchar *err = module_load(*dep, FALSE, FALSE);
134 138
135 if (err) { 139 if (err) {
136 GSList *mel; 140 GSList *mel;
137 scr_LogPrint(LPRINT_LOGNORM, "Error loading dependency module %s: %s.", *dep, err); 141 scr_LogPrint(LPRINT_LOGNORM, "Error loading dependency module %s: %s.",
142 *dep, err);
138 143
139 // Unload already loaded dependencies 144 // Unload already loaded dependencies
140 for (mel = deps; mel; mel = mel->next) { 145 for (mel = deps; mel; mel = mel->next) {
141 gchar *ldmname = mel->data; 146 gchar *ldmname = mel->data;
142 err = module_unload(ldmname, FALSE, FALSE); 147 err = module_unload(ldmname, FALSE, FALSE);
143 scr_LogPrint(LPRINT_LOGNORM, "Error unloading dependency module %s: %s.", ldmname, err); 148 scr_LogPrint(LPRINT_LOGNORM,
149 "Error unloading dependency module %s: %s.",
150 ldmname, err);
144 g_free(ldmname); 151 g_free(ldmname);
145 } 152 }
146 g_slist_free(deps); 153 g_slist_free(deps);
147 154
148 // Unload module 155 // Unload module
149 if (!g_module_close(mod)) 156 if (!g_module_close(mod))
150 scr_LogPrint(LPRINT_LOGNORM, "Error unloading module %s: %s.", arg, g_module_error()); 157 scr_LogPrint(LPRINT_LOGNORM, "Error unloading module %s: %s.",
158 arg, g_module_error());
151 return "Dependency problems"; 159 return "Dependency problems";
152 } 160 }
153 161
154 deps = g_slist_append(deps, g_strdup(*dep)); 162 deps = g_slist_append(deps, g_strdup(*dep));
155 } 163 }
198 206
199 // Check if user can unload this module 207 // Check if user can unload this module
200 if (manual) { 208 if (manual) {
201 if (!module->locked) { 209 if (!module->locked) {
202 if (force) 210 if (force)
203 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: Manually unloading automatically loaded module."); 211 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: "
212 "Manually unloading automatically loaded module.");
204 else 213 else
205 return "Module is not loaded manually"; 214 return "Module is not loaded manually";
206 } 215 }
207 module->locked = FALSE; 216 module->locked = FALSE;
208 } 217 }
209 218
210 // Check refcount 219 // Check refcount
211 module->refcount -= 1; 220 module->refcount -= 1;
212 if (module->refcount > 0) { 221 if (module->refcount > 0) {
213 if (force) 222 if (force)
214 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: Refcount is not zero (%u).", module->refcount); 223 scr_LogPrint(LPRINT_LOGNORM, "Forced to ignore error: "
224 "Refcount is not zero (%u).", module->refcount);
215 else 225 else
216 return manual ? "Module is required by some other modules" : NULL; 226 return manual ? "Module is required by some other modules" : NULL;
217 } 227 }
218 228
219 info = module->info; 229 info = module->info;
232 GSList *dep; 242 GSList *dep;
233 for (dep = module->dependencies; dep; dep = dep->next) { 243 for (dep = module->dependencies; dep; dep = dep->next) {
234 gchar *ldmname = dep->data; 244 gchar *ldmname = dep->data;
235 const gchar *err = module_unload(ldmname, FALSE, FALSE); 245 const gchar *err = module_unload(ldmname, FALSE, FALSE);
236 if (err) // XXX 246 if (err) // XXX
237 scr_LogPrint(LPRINT_LOGNORM, "Error unloading automatically loaded module %s: %s.", ldmname, err); 247 scr_LogPrint(LPRINT_LOGNORM,
248 "Error unloading automatically loaded module %s: %s.",
249 ldmname, err);
238 g_free(ldmname); 250 g_free(ldmname);
239 } 251 }
240 g_slist_free(module->dependencies); 252 g_slist_free(module->dependencies);
241 module->dependencies = NULL; 253 module->dependencies = NULL;
242 } 254 }
281 message = g_string_new("Loaded modules:\n"); 293 message = g_string_new("Loaded modules:\n");
282 for (mel = loaded_modules; mel; mel = mel -> next) { 294 for (mel = loaded_modules; mel; mel = mel -> next) {
283 loaded_module_t *module = mel->data; 295 loaded_module_t *module = mel->data;
284 GSList *dep; 296 GSList *dep;
285 297
286 g_string_append_printf(message, format, module->name, module->refcount, module->locked ? 'M' : 'A'); 298 g_string_append_printf(message, format, module->name, module->refcount,
299 module->locked ? 'M' : 'A');
287 300
288 // Append loaded module dependencies 301 // Append loaded module dependencies
289 if (module->dependencies) { 302 if (module->dependencies) {
290 g_string_append(message, " depends: "); 303 g_string_append(message, " depends: ");
291 304
347 if (err) 360 if (err)
348 scr_LogPrint(LPRINT_LOGNORM, "* Module unloading failed: %s.", err); 361 scr_LogPrint(LPRINT_LOGNORM, "* Module unloading failed: %s.", err);
349 } 362 }
350 } 363 }
351 364
352 /* vim: set expandtab cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ 365 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */