1 /*
2 Copyright 2007, 2008, 2009, 2010 Geyer Klaus
3
4 This file is part of Cat'sEyE.
5
6 Cat'sEyE is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Cat'sEyE is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Cat'sEyE. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21
22 #include <stdio.h>
23 #include <gtk/gtk.h>
24 #include <ctype.h> //convert char to lower-char
25 #include <string.h>
26 #include <stdlib.h>
27
28 #include "userdata.h"
29 #include "confighandling.h"
30 #include "confighandlingDefinitions.h"
31 #include "listitems.h"
32 #include "mytrace.h"
33 #include "helpers.h"
34 #include "CreateUsercommandDialog.h"
35
36 #include "allInclude.h"
37
38 //int openfiles = 0; //for debuging info. counts the currently opened files, opened with this set of functions.
39
40
41
42 ////////////////////////////////////////////////////////////////////////////////////////////
43 ////////////////XML ConfigFile handling ///////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////////////////////////////
45 /*
46 Some facts:
47 the new config file has xml format.
48 We will not open the file every time we want some values from it, but we store all the
49 information in lists. When we know when we loaded the file the last time and know when
50 the file was changed last we can decide to reload the whole file.
51
52 about the xml parsing thing:
53 While walking throght the xml file we will come up in the foundstart-callback of the xml parser.
54 But we need to know if the found starting string is supported by the state we are currently in.
55 With state, we mean e.g. that we currently reading in the properties of the dailog, question or the value and name of an option.
56 All this states have valid keywords, others can not be assigned to any property of our internal lists.
57
58 Allright then, the state is stored with the help of _Items_XML_Relation - structure which is stored in
59 _Parser_Mode_Struct - structure which helps us to communicate between the callbacks.
60 To find out which keywords are valid for our current state we have a function: 'getValidKeyWordsForState'.
61 Giving this function the _Items_XML_Relation - structure will give you a pointer to _OptionsList - structure
62 where only the gstrName is filled with the valid keywords. We decided to use this structure because many things we
63 need (e.g. searching for a name, new item does not need to fill all member variables available) are already implemented.
64
65 The first idea was to search the begining of some blocks before proceeding with the xml parser. But this wasnt a good idea.
66 When there are syntax errors in the file the parser gives us a message including the linenumber, but this is never the right line
67 as we searched for some string in the file before.
68 Further more, when we come to the end string of a block (e.g. CatsEyEBookmarks) the parser reports an error because there is block closed
69 which was never opened (in his point of view).
70
71 So, the new method starts loading the whole file, with all information, from the begining of the file.
72 From now on it is impossible to load specific blocks such as bookmarks, configurations, commands.
73 */
74
75
76 void Usercommand_FoundStartCallback(struct _Parser_Mode_Struct *info);
77 void Usercommand_FoundEndCallback(struct _Parser_Mode_Struct *info, const char *element_name);
78 void freeRelicts(struct _Parser_Mode_Struct *info);
79 void configFileHandling_Init();
80 int configFileHandling_validateDialogEntityItem (struct _DialogEntityList *dialogItem);
81 int Usercommands_loadUserCommandsFromFile (struct myFiles_struct *myFilestru, gboolean bMakeItThreadSave);
82 int Bookmarks_loadBookmarksFromFile (struct myFiles_struct *myFilestru, gboolean bMakeItThreadSave);
83 int configFileHandling_saveGlobalConfigStructAsXMLConfigFile (FILE *configFile);
84 int configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile (FILE *configFile);
85 int configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile (FILE *configFile);
86
87
88
89
90 void debugOut_PrintLists();
91
92 ///////////////////////////////////
93 //// Some Globals /////////////////
94
95 struct _UserCommandList *g_UserCommandList;
96 struct UserDataList *g_UserDataList; //used wthin the contextmenu
97 struct _OptionsList *g_OptionsList;
98 struct _OptionsList *g_BookMarkList;
99 static GString *g_gstrConfigFile;
100 time_t g_timeChanged; //the configfiles files time stamp
101 extern GtkWindow *win;
102 static int g_preventFromReload; //if this is 1, the list (g_OptionsList, g_BookMarkList and g_UserCommandList)
103 //will not be deleted, nor reloaded!
104 //this flag is set and unset primaly in the property page.
105
106
107
108 ///////////////////////////////////
109 /////////////////////////////////////
110 //// functions //////////////////
111
configFileHandling_Init()112 void configFileHandling_Init(){
113 TRACEIT (7, "configFileHandling_Init start");
114 //called at startup
115 g_UserCommandList = NULL;
116 //g_UserCommandsForMarkedItems = NULL;
117 g_UserDataList=NULL;
118 g_OptionsList = NULL;
119 g_BookMarkList = NULL;
120 g_gstrConfigFile = NULL;
121 g_timeChanged=0; //the configfiles files time stamp
122 g_preventFromReload = 0;
123
124 //set default config file name
125 configFileHandling_defineConfigFileName (NULL);
126
127 //g_string_assign(g_gstrConfigFile,"/wurzel/TEMP/test.conf");
128
129 TRACEIT (7, "configFileHandling_Init end");
130
131 }
132
133
configFileHandling_clearForShutdown()134 void configFileHandling_clearForShutdown(){
135 TRACEIT (7, "configFileHandling_clearForShutdown start");
136 //frees all memory
137 if (NULL != g_gstrConfigFile){
138 g_string_free(g_gstrConfigFile, TRUE);
139 g_gstrConfigFile = NULL;
140 }
141 if (g_OptionsList != NULL){
142 OptionsList_freeList (&g_OptionsList);
143 g_OptionsList = NULL;
144 }
145 if (g_BookMarkList != NULL){
146 OptionsList_freeList (&g_BookMarkList);
147 g_BookMarkList = NULL;
148 }
149 if (g_UserCommandList != NULL){
150 UserCommandList_freeList (&g_UserCommandList);
151 g_UserCommandList = NULL;
152 }
153 //if (g_UserCommandsForMarkedItems != NULL){
154 // UserCommandList_freeList (&g_UserCommandsForMarkedItems);
155 // UserCommandList_freeList = NULL;
156 //}
157 if (g_UserDataList != NULL){
158 UserDataList_DeleteList (&g_UserDataList);
159 }
160
161 TRACEIT (7, "configFileHandling_clearForShutdown end");
162 }
163
164
configFileHandling_defineConfigFileName(const char * ccpFileName)165 int configFileHandling_defineConfigFileName (const char *ccpFileName){
166 //sets g_gstrConfigFile to the given name, thats all.
167 //ccpFileName can be NULL; in this case the default name is generated and loaded
168 GString *gstrBuf = g_string_sized_new (10);
169
170 if (ccpFileName == NULL){
171 //define the default name for the file
172 getHomeDirectory (gstrBuf);
173 checkPathForLastChar(gstrBuf);
174 g_string_append(gstrBuf,CONFIG_FILE_TYPES);
175 }
176 else{
177 g_string_assign (gstrBuf, ccpFileName);
178 }
179
180 if (g_gstrConfigFile == NULL){
181 g_gstrConfigFile = g_string_new (gstrBuf->str);
182 }
183 else{
184 g_string_assign (g_gstrConfigFile, gstrBuf->str);
185 }
186
187 g_string_free (gstrBuf, TRUE);
188 return 0;
189 }
190
191
configFileHandling_getConfigFileName()192 const char *configFileHandling_getConfigFileName (){
193 if (g_gstrConfigFile == NULL){
194 return NULL;
195 }
196 return (const char *)g_gstrConfigFile->str;
197 }
198
199
configFileHandling_setPreventReloadFlag(int iValue)200 void configFileHandling_setPreventReloadFlag (int iValue){
201 TRACEIT (10, "configFileHandling_setPreventReloadFlag start");
202 if (iValue == 0){
203 g_preventFromReload = 0;
204 }
205 else{
206 g_preventFromReload = 1;
207 }
208
209 TRACEIT (10, "configFileHandling_setPreventReloadFlag end");
210 }
211
212
configFileHandling_loadConfigFile(gboolean bIgnoreTimeStamp,gboolean bMakeItThreadSave)213 int configFileHandling_loadConfigFile(gboolean bIgnoreTimeStamp, gboolean bMakeItThreadSave){
214 TRACEIT (7, "configFileHandling_loadConfigFile start");
215 //loads the configfile and stores all information to our UsercommandList g_UserCommandList
216 //when the list was filled before, it checks if the configfile has changed meanwhile and then
217 //decides wether to reaload the information or not.
218 //If bIgnoreTimeStamp is true, the file is loaded in all cases
219 //However, if g_preventFromReload is 1, nothing is done, as it is expected that the property page is open which may need the pointer!
220
221 //return: -1=error, 0=ok
222
223 if (g_gstrConfigFile == NULL){
224 TRACEIT (2, "configFileHandling_loadConfigFile end, not correctly initialized");
225 return -1;
226 }
227 if (g_preventFromReload == 1){
228 TRACEIT (10, "configFileHandling_loadConfigFile end, prevent flag set");
229 return 0;
230 }
231
232 struct myFiles_struct *myFilestru=NULL;
233 struct FileAttributs attribs;
234 GString *gstrBuf=g_string_sized_new(10);
235
236 //check for the last change
237 fileAttributesGet( &attribs, g_gstrConfigFile->str, NULL);
238 if (attribs.gstrLinkTarget){
239 g_string_free(attribs.gstrLinkTarget, TRUE);
240 }
241
242 myFilestru = myFiles_openFile(g_gstrConfigFile->str, "r");
243 if (myFilestru == NULL){
244 g_string_free(gstrBuf, TRUE);
245 TRACEIT (2, "configFileHandling_loadConfigFile end, error opening the configfile:");
246 TRACEIT (2, g_gstrConfigFile->str);
247 return -1;
248 }
249
250 //when we come up here we can start to load the file
251 if (bIgnoreTimeStamp || g_timeChanged < attribs.utchanged) {
252 TRACEIT (7, "configFileHandling_loadConfigFile start loading file");
253
254 //delete the lists first
255 if (g_UserCommandList != NULL){
256 UserCommandList_freeList(&g_UserCommandList);
257 g_UserCommandList = NULL;
258 }
259
260 Options_CreateDefaultList (); //this will delete the list first
261
262 if (g_BookMarkList != NULL){
263 OptionsList_freeList(&g_BookMarkList);
264 g_BookMarkList = NULL;
265 }
266
267 struct _Items_XML_Relation Items_XML_Relation;
268
269 //XML PARSER START
270
271 //our relation struct stores information about where we are in the tree
272 XMLRelation_eraseAll(&Items_XML_Relation);
273
274 //our parser struct holds the information where to store the infos from the parser and all that.
275 struct _Parser_Mode_Struct modeStruct;
276 modeStruct.storageList = NULL;
277 modeStruct.relation = &Items_XML_Relation;
278 modeStruct.currentListItem = NULL;
279 modeStruct.currentOptionBlock=NULL; //used in Usercommand section
280 modeStruct.iCurrentListType = CONFIGFILE_LOAD_NOTHING; //see enum
281 modeStruct.bMakeItThreadSave = bMakeItThreadSave;
282 modeStruct.cppAttributeValues = NULL;
283 modeStruct.cppAttributeNames = NULL;
284 modeStruct.functionStartNotification = NULL;
285 modeStruct.functionStopNotification = NULL;
286 modeStruct.functionTextNotification = NULL; //this function handles the Option-Blocks (the only block we use to store information)
287
288 // debugOut_PrintLists();
289
290 XMLParser_ParseFileFile (myFilestru, &modeStruct, bMakeItThreadSave);
291
292 freeRelicts ( &modeStruct );
293 g_timeChanged = attribs.utchanged;
294 }
295
296 configFileHandling_validateUsercommandList(bMakeItThreadSave);
297
298 g_string_free(gstrBuf, TRUE);
299 myFiles_closeFile(myFilestru);
300
301 TRACEIT (10, "configFileHandling_loadConfigFile end");
302 return 0;
303 }
304
305
configFileHandling_validateUsercommandList(gboolean bMakeItThreadSave)306 void configFileHandling_validateUsercommandList(gboolean bMakeItThreadSave){
307 // to be a valid usercommand, the following criteria must be true:
308 // it must have:
309 // gstrName, glistTargets, gstrCommand
310
311 TRACEIT (7, "configFileHandling_validateUsercommandList start");
312
313 if (g_UserCommandList == NULL){
314 TRACEIT (7, "configFileHandling_validateUsercommandList end, nothing to validate");
315 return;
316 }
317
318 struct _UserCommandList *usercommandList = g_UserCommandList;
319 struct _DialogEntityList *dialogList = NULL;
320 int iDialogIsValid;
321
322 while (usercommandList){
323 //we first need to validate the dialog entities, if there are some
324 dialogList = usercommandList->DialogEntityList;
325
326 iDialogIsValid = 1;
327 while (dialogList){
328 if (0 == configFileHandling_validateDialogEntityItem(dialogList)){
329 iDialogIsValid=0;
330 //break;
331 }
332 dialogList = dialogList->nextItem;
333 }
334 if (iDialogIsValid == 0){
335 usercommandList->iValid = 0;
336 usercommandList = usercommandList->nextItem;
337 continue;
338 }
339
340 //minimum requirements for a command:
341 if (usercommandList->gstrName==NULL || usercommandList->glistTargets==NULL || usercommandList->gstrCommand){
342 usercommandList->iValid = 0;
343 usercommandList = usercommandList->nextItem;
344 continue;
345 }
346 usercommandList->iValid = 1;
347
348 usercommandList = usercommandList->nextItem;
349 }
350 TRACEIT (7, "configFileHandling_validateUsercommandList end");
351 }
352
353
configFileHandling_validateDialogEntityItem(struct _DialogEntityList * dialogItem)354 int configFileHandling_validateDialogEntityItem (struct _DialogEntityList *dialogItem){
355 //return: -1=error, 0=invalid 1=valid
356 //only checks one item for validation
357 if (dialogItem == NULL){
358 TRACEIT (2, "configFileHandling_validateDialogEntityItem end, parameter NULL");
359 return -1;
360 }
361 int iRet = 0;
362
363 if (dialogItem->iType == -1){
364 dialogItem->iValid=0;
365 iRet=0;
366 }
367 if (dialogItem->iType == USERDIALOG_ENTITY_TYPE_QUESTION){
368 if ( dialogItem->gstrLabel != NULL && dialogItem->gstrVarIdentifier != NULL ){
369 iRet=1;
370 }
371 }
372 else if (dialogItem->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
373 if ( dialogItem->gstrLabel != NULL && dialogItem->gstrVarIdentifier != NULL ){
374 iRet=1;
375 }
376 }
377 else if (dialogItem->iType == USERDIALOG_ENTITY_TYPE_TEXT){
378 //gstrLabel can be NULL even if iValid of Object Text is 1, this is because
379 //we want to be able to lead an empty text
380 //if ( dialogItem->gstrLabel != NULL){
381 iRet=1;
382 //}
383 }
384 else if (dialogItem->iType == USERDIALOG_ENTITY_TYPE_FILECHOOSER || dialogItem->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER){
385 if ( dialogItem->gstrLabel != NULL && dialogItem->gstrVarIdentifier != NULL ){
386 iRet=1;
387 }
388 }
389 else if (dialogItem->iType == USERDIALOG_ENTITY_TYPE_SEPARATOR){
390 iRet=1;
391 }
392
393 if (iRet == 1){
394 dialogItem->iValid=1;
395 }
396
397 return iRet;
398 }
399
400
configFileHandling_saveGlobalStructsAsXMLConfigFile(const char * ccpFileName,gboolean bMakeThreadSave)401 int configFileHandling_saveGlobalStructsAsXMLConfigFile (const char *ccpFileName, gboolean bMakeThreadSave){
402 /*saves the global structs:
403 struct _UserCommandList *g_UserCommandList;
404 struct _OptionsList *g_OptionsList;
405 struct _OptionsList *g_BookMarkList;
406 to the filename specified by ccpFileName
407 ccpFileName can be NULL, in this case g_gstrConfigFile is used
408
409 return: 0=ok, -1=error
410
411 we do not check for existance of the file, we just overwrite it
412 */
413 TRACEIT (10, "configFileHandling_saveGlobalStructsAsXMLConfigFile start");
414 if (ccpFileName == NULL){
415 if (g_gstrConfigFile == NULL){
416 TRACEIT (3, "configFileHandling_saveGlobalStructsAsXMLConfigFile parameter NULL");
417 return -1;
418 }
419 ccpFileName = g_gstrConfigFile->str;
420 }
421 FILE *configFile = fopen (ccpFileName, "w+");
422 if (configFile == NULL){
423 if (bMakeThreadSave)
424 myWrap_gdk_threads_enter("configFileHandling_saveGlobalStructsAsXMLConfigFile");
425 MyMessageWidget (win, "error", "Error opening config file for writing.\nPlease check permission and the existance of the path.");
426 if (bMakeThreadSave)
427 myWrap_gdk_threads_leave("configFileHandling_saveGlobalStructsAsXMLConfigFile");
428 TRACEIT (4, "configFileHandling_saveGlobalStructsAsXMLConfigFile unable to create file");
429 return -1;
430 }
431
432 fprintf (configFile, "<%s>\n", XMLTAG_MAIN);
433
434 configFileHandling_saveGlobalConfigStructAsXMLConfigFile (configFile);
435 configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile (configFile);
436 configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile (configFile);
437
438 fprintf (configFile, "</%s>\n", XMLTAG_MAIN);
439
440 fclose (configFile);
441
442 TRACEIT (10, "configFileHandling_saveGlobalStructsAsXMLConfigFile end");
443 return 0;
444 }
445
446
configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile(FILE * configFile)447 int configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile (FILE *configFile){
448 TRACEIT (10, "configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile start");
449 if (configFile == NULL){
450 TRACEIT (2, "configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile parameter NULL");
451 return -1;
452 }
453 if (g_UserCommandList == NULL){
454 TRACEIT (10, "configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile end, no g_UserCommandList defined");
455 return -1;
456 }
457 struct _UserCommandList *UserCommandListBuf = UserCommandList_getFirstItem (g_UserCommandList);
458 struct _DialogEntityList *DialogEntityListBuf = NULL;
459 GString *gstrBuf = g_string_sized_new (10);
460 GList *glistBuf = NULL;
461
462 fprintf (configFile, "<%s>\n", XMLTAG_USERCOMMANDS);
463 while (UserCommandListBuf){
464 fprintf (configFile, "<%s>\n", XMLTAG_USERCOMMAND);
465
466 //Name
467 if (UserCommandListBuf->gstrName){
468 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_NAME, NULL, UserCommandListBuf->gstrName->str);
469 }
470 //Command
471 if (UserCommandListBuf->gstrCommand){
472 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_COMMAND, NULL, UserCommandListBuf->gstrCommand->str);
473 }
474 //Targets
475 if (UserCommandListBuf->glistTargets){
476 glistBuf = UserCommandListBuf->glistTargets;
477 while (glistBuf){
478 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_TARGET, NULL, ((GString *)glistBuf->data)->str);
479 glistBuf = glistBuf->next;
480 }
481 }
482 //DefaultCommand
483 if (UserCommandListBuf->iIsDefaultCommand == 1){
484 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_DEFAULTCOMMAND, NULL, "true");
485 }
486 //Actionnote
487 if (UserCommandListBuf->option_gstrActionnote){
488 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_ACTIONNOTE, NULL, UserCommandListBuf->option_gstrActionnote->str);
489 }
490 //Quitreply
491 if (UserCommandListBuf->option_gstrQuitreply){
492 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_QUITREPLY, NULL, UserCommandListBuf->option_gstrQuitreply->str);
493 }
494 //Calltype
495 if (UserCommandListBuf->option_iCallType == USERCOMMAND_CALLTYPE_ALL){
496 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_CALLTYPE, NULL, "all");
497 }
498 else if (UserCommandListBuf->option_iCallType == USERCOMMAND_CALLTYPE_EACH){
499 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_CALLTYPE, NULL, "each");
500 }
501 else if (UserCommandListBuf->option_iCallType == USERCOMMAND_CALLTYPE_LIST){
502 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_CALLTYPE, NULL, "list");
503 }
504 //listWidgets label
505 if (UserCommandListBuf->option_gstrLabel){
506 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_LISTLABEL, NULL, UserCommandListBuf->option_gstrLabel->str);
507 }
508 //listWidgets caption
509 if (UserCommandListBuf->option_gstrCaption){
510 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_LISTCAPTION, NULL, UserCommandListBuf->option_gstrCaption->str);
511 }
512 //Dialog caption
513 if (UserCommandListBuf->gstrDialogCaption){
514 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_DIALOGCAPTION, NULL, UserCommandListBuf->gstrDialogCaption->str);
515 }
516 //Dialog label
517 if (UserCommandListBuf->gstrDialogLabel){
518 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_DIALOGLABEL, NULL, UserCommandListBuf->gstrDialogLabel->str);
519 }
520
521 //DialogEntities
522 DialogEntityListBuf = UserCommandListBuf->DialogEntityList;
523 while (DialogEntityListBuf){
524 if (DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_QUESTION){
525 g_string_append_printf (gstrBuf, "<%s type=\"%s\">", XMLTAG_OBJECT, XMLTAG_QUESTION);
526 }
527 else if (DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
528 g_string_append_printf (gstrBuf, "<%s type=\"%s\">", XMLTAG_OBJECT, XMLTAG_CHECKBOX);
529 }
530 else if (DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_TEXT){
531 g_string_append_printf (gstrBuf, "<%s type=\"%s\">", XMLTAG_OBJECT, XMLTAG_TEXT);
532 }
533 else if (DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_FILECHOOSER){
534 g_string_append_printf (gstrBuf, "<%s type=\"%s\">", XMLTAG_OBJECT, XMLTAG_FILECHOOSER);
535 }
536 else if (DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER){
537 g_string_append_printf (gstrBuf, "<%s type=\"%s\">", XMLTAG_OBJECT, XMLTAG_DIRCHOOSER);
538 }
539 else if (DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_SEPARATOR){
540 g_string_append_printf (gstrBuf, "<%s type=\"%s\">", XMLTAG_OBJECT, XMLTAG_SEPARATOR);
541 }
542 else {
543 TRACEIT (4, "configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile type of dialog entity unknown in usercommand list, ignoring");
544 continue;
545 }
546 //labelText
547 if (DialogEntityListBuf->gstrLabel){
548 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_LABELTEXT, NULL, DialogEntityListBuf->gstrLabel->str );
549 }
550 //varID
551 if (DialogEntityListBuf->gstrVarIdentifier){
552 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_VARID, NULL, DialogEntityListBuf->gstrVarIdentifier->str );
553 }
554 //predefine
555 if (DialogEntityListBuf->gstrPredefine){
556 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_PREDEFINE, NULL, DialogEntityListBuf->gstrPredefine->str );
557 }
558 //TrueValue
559 if (DialogEntityListBuf->gstrAdditional1 && DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
560 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_TRUEVALUE, NULL, DialogEntityListBuf->gstrAdditional1->str );
561 }
562 //ButtonText
563 else if (DialogEntityListBuf->gstrAdditional1 && ( DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_FILECHOOSER || DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER)){
564 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_BUTTONTEXT, NULL, DialogEntityListBuf->gstrAdditional1->str );
565 }
566 //FalseValue
567 if (DialogEntityListBuf->gstrAdditional2 && DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
568 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_FALSEVALUE, NULL, DialogEntityListBuf->gstrAdditional2->str );
569 }
570 //ChooserCaption
571 else if (DialogEntityListBuf->gstrAdditional2 && ( DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_FILECHOOSER || DialogEntityListBuf->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER)){
572 createUserCommand_createXMLOptionString (gstrBuf, XMLTAG_CHOOSERCAPTION, NULL, DialogEntityListBuf->gstrAdditional2->str );
573 }
574
575 g_string_append_printf (gstrBuf, "</%s>\n",XMLTAG_OBJECT);
576 DialogEntityListBuf = DialogEntityListBuf->nextItem;
577 }
578 fprintf (configFile, "%s\n", gstrBuf->str);
579 g_string_erase (gstrBuf, 0, -1);
580
581 fprintf (configFile, "</%s>\n", XMLTAG_USERCOMMAND);
582 UserCommandListBuf = UserCommandListBuf->nextItem;
583 }
584 fprintf (configFile, "</%s>\n", XMLTAG_USERCOMMANDS);
585
586 g_string_free (gstrBuf, TRUE);
587 TRACEIT (10, "configFileHandling_saveGlobalUsercommandStructAsXMLConfigFile end");
588 return 0;
589 }
590
591
configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile(FILE * configFile)592 int configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile (FILE *configFile){
593 TRACEIT (10, "configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile start");
594 if (configFile == NULL){
595 TRACEIT (2, "configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile parameter NULL");
596 return -1;
597 }
598 if (g_BookMarkList == NULL){
599 TRACEIT (10, "configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile end, no g_BookMarkList defined");
600 return -1;
601 }
602 struct _OptionsList *BookMarkListBuf = OptionsList_getFirstItem (g_BookMarkList);
603
604 GString *gstrBuf = g_string_sized_new (10);
605
606 fprintf (configFile, "<%s>\n", XMLTAG_BOOKMARKS);
607 while (BookMarkListBuf){
608 createUserCommand_createXMLOptionString (gstrBuf,
609 /*(BookMarkListBuf->gstrID==NULL)?NULL:BookMarkListBuf->gstrID->str,*/
610 NULL,
611 (BookMarkListBuf->gstrName==NULL)?NULL:BookMarkListBuf->gstrName->str,
612 (BookMarkListBuf->gstrValue==NULL)?NULL:BookMarkListBuf->gstrValue->str);
613 g_string_append (gstrBuf, "\n");
614 BookMarkListBuf = BookMarkListBuf->nextItem;
615 }
616 fprintf (configFile, "%s</%s>\n", gstrBuf->str, XMLTAG_BOOKMARKS);
617
618 g_string_free (gstrBuf, TRUE);
619 TRACEIT (10, "configFileHandling_saveGlobalBookmarkStructAsXMLConfigFile end");
620 return 0;
621 }
622
623
configFileHandling_saveGlobalConfigStructAsXMLConfigFile(FILE * configFile)624 int configFileHandling_saveGlobalConfigStructAsXMLConfigFile (FILE *configFile){
625 TRACEIT (10, "configFileHandling_saveGlobalConfigStructAsXMLConfigFile start");
626 if (configFile == NULL){
627 TRACEIT (2, "configFileHandling_saveGlobalConfigStructAsXMLConfigFile parameter NULL");
628 return -1;
629 }
630 if (g_OptionsList == NULL){
631 TRACEIT (10, "configFileHandling_saveGlobalConfigStructAsXMLConfigFile end, no options defined");
632 return -1;
633 }
634 struct _OptionsList *OptionsListBuf = OptionsList_getFirstItem (g_OptionsList);
635
636 GString *gstrBuf = g_string_sized_new (10);
637
638 //XMLTAG_OPTIONS "CatsEyEOptions"
639
640 fprintf (configFile, "<%s>\n", XMLTAG_OPTIONS);
641 while (OptionsListBuf){
642 createUserCommand_createXMLOptionString (gstrBuf,
643 (OptionsListBuf->gstrID==NULL)?NULL:OptionsListBuf->gstrID->str,
644 (OptionsListBuf->gstrName==NULL)?NULL:OptionsListBuf->gstrName->str,
645 (OptionsListBuf->gstrValue==NULL)?NULL:OptionsListBuf->gstrValue->str);
646 g_string_append (gstrBuf, "\n");
647 OptionsListBuf = OptionsListBuf->nextItem;
648 }
649 fprintf (configFile, "%s</%s>\n", gstrBuf->str, XMLTAG_OPTIONS);
650
651 g_string_free (gstrBuf, TRUE);
652 TRACEIT (10, "configFileHandling_saveGlobalConfigStructAsXMLConfigFile end");
653 return 0;
654 }
655
656
debugOut_PrintLists()657 void debugOut_PrintLists(){
658 TRACEIT (5, "debugOut_PrintLists start");
659
660 printf("--------------------START DEBUG OUT XML FILES ------------------\n");
661
662 if (g_gstrConfigFile){
663 printf("file loaded: %s\n",g_gstrConfigFile->str);
664 }
665 else{
666 printf("NO file loaded\n");
667 }
668
669 if (g_OptionsList){
670 OptionsList_DebugOut_printList(g_OptionsList);
671 }
672 else{
673 printf("g_OptionsList == NULL\n");
674 }
675 if (g_BookMarkList){
676 OptionsList_DebugOut_printList(g_BookMarkList);
677 }
678 else{
679 printf("g_BookMarkList == NULL\n");
680 }
681 if (g_UserCommandList){
682 UserCommandList_DebugOut_printList(g_UserCommandList);
683 }
684 else{
685 printf("g_UserCommandList == NULL\n");
686 }
687
688 printf("--------------------END DEBUG OUT XML FILES ------------------\n");
689
690 TRACEIT (5, "debugOut_PrintLists end");
691 }
692
693
XMLRelation_eraseAll(struct _Items_XML_Relation * relation)694 int XMLRelation_eraseAll(struct _Items_XML_Relation *relation){
695 TRACEIT (7, "XMLRelation_eraseAll start");
696 //simply writes false to all members to relation
697
698 relation->bUnKnownBlock=FALSE;
699 relation->bCatsEyEBlock=FALSE;
700 relation->bCatsEyEBookMarksBlock=FALSE;
701 relation->bCatsEyEOptionsBlock=FALSE;
702 relation->bCatsEyEUserCommandsBlock=FALSE;
703 relation->bUserCommandBlock=FALSE;
704 relation->bObjectBlock=FALSE;
705 relation->bOptionBlock=FALSE;
706 relation->bIDBlock=FALSE;
707 relation->bNameBlock=FALSE;
708 relation->bValueBlock=FALSE;
709
710 relation->iRelation = 0;
711
712
713 TRACEIT (7, "XMLRelation_eraseAll end");
714 return 0;
715 }
716
717
XMLRelation_accumulateRelations(struct _Items_XML_Relation * relation)718 int XMLRelation_accumulateRelations(struct _Items_XML_Relation *relation){
719 TRACEIT (7, "XMLRelation_accumulateRelations start");
720 //return: -1=error, 0=ok
721 if (relation == NULL){
722 TRACEIT(2, "XMLRelation_accumulateRelations end, Parameter NULL");
723 return -1;
724 }
725 //we have 19 bools, this makes 19 bits!! How big is an int? We assume that an integer is never less than 20 bytes.
726 //in most cases it is 4 bytes which is 32 bits.
727 int iRelations=0;
728
729 iRelations |= relation->bUnKnownBlock<<0; //0 /1
730 iRelations |= relation->bCatsEyEBlock<<1; //1 /2 we are in <CatsEyE> - Block
731 iRelations |= relation->bCatsEyEBookMarksBlock<<2; //2 /4
732 iRelations |= relation->bCatsEyEOptionsBlock<<3; //3 /8 we are in <CatsEyEOptions> - Block
733 iRelations |= relation->bCatsEyEUserCommandsBlock<<4; //4 /16
734 iRelations |= relation->bUserCommandBlock<<5; //5 /32 we are in <Usercommand>-Block (within <CatsEyEUsercommands>)
735 iRelations |= relation->bObjectBlock<<6; //6 /64
736 iRelations |= relation->bOptionBlock<<7; //7 /128 we are in <Option> - Block (within <CatsEyEOptions>-Block)
737 iRelations |= relation->bIDBlock<<8; //8 /256
738 iRelations |= relation->bNameBlock<<9; //9 /512
739 iRelations |= relation->bValueBlock<<10; //10 /1024
740
741 relation->iRelation = iRelations;
742
743
744 TRACEIT (7, "XMLRelation_accumulateRelations end");
745 return 0;
746 }
747
748
UserCommandList_DebugOut_printList(struct _UserCommandList * theList)749 void UserCommandList_DebugOut_printList(struct _UserCommandList *theList){
750 TRACEIT (7, "UserCommandList_DebugOut_printList start");
751 if (theList == NULL){
752 printf("UserCommandList_DebugOut_printList list: parameter NULL\n");
753 return;
754 }
755 struct _UserCommandList *bufList=UserCommandList_getFirstItem(theList);
756
757 printf("\n------------------START OUTPUT USERCOMMANDS------------------------\n");
758 while (bufList){
759 printf("____ NEXT ITEM: ____\n");
760
761 printf ("iIsDefaultCommand = %d\n",bufList->iIsDefaultCommand);
762
763 if (bufList->gstrName){
764 printf("gstrName: %s\n",bufList->gstrName->str);
765 }
766 else {
767 printf("gstrName not set\n");
768 }
769
770 if (bufList->gstrCommand){
771 printf("gstrCommand: %s\n",bufList->gstrCommand->str);
772 }
773 else {
774 printf("gstrCommand not set\n");
775 }
776
777 if (bufList->gstrDialogCaption){
778 printf("gstrDialogCaption: %s\n",bufList->gstrDialogCaption->str);
779 }
780 else {
781 printf("gstrDialogCaption not set\n");
782 }
783
784 if (bufList->gstrDialogLabel){
785 printf("gstrDialogLabel: %s\n",bufList->gstrDialogLabel->str);
786 }
787 else {
788 printf("gstrDialogLabel not set\n");
789 }
790
791 if (bufList->option_gstrQuitreply){
792 printf("option_gstrQuitreply: %s\n",bufList->option_gstrQuitreply->str);
793 }
794 else {
795 printf("option_gstrQuitreply not set\n");
796 }
797
798 if (bufList->option_gstrActionnote){
799 printf("option_gstrActionnote: %s\n",bufList->option_gstrActionnote->str);
800 }
801 else {
802 printf("option_gstrActionnote not set\n");
803 }
804
805 if (bufList->option_gstrCaption){
806 printf("option_gstrCaption: %s\n",bufList->option_gstrCaption->str);
807 }
808 else {
809 printf("option_gstrCaption not set\n");
810 }
811
812 if (bufList->option_gstrLabel){
813 printf("option_gstrLabel: %s\n",bufList->option_gstrLabel->str);
814 }
815 else {
816 printf("option_gstrLabel not set\n");
817 }
818
819 printf ("option_iCallType = %d\n",bufList->option_iCallType);
820
821 GList *gListBuf = bufList->glistTargets;
822
823 printf("Target List _______________ START\n");
824 while (gListBuf){
825 printf("Target: %s\n",((GString *)(gListBuf->data))->str);
826
827 gListBuf = gListBuf->next;
828 }
829 printf("Target List _______________ END\n");
830
831
832 if (bufList->DialogEntityList){
833 DialogEntityList_DebugOut_printList ( bufList->DialogEntityList);
834 }
835 else{
836 printf("No DialogEntities defined\n");
837 }
838
839 bufList = bufList->nextItem;
840 }
841 printf("------------------END OUTPUT USERCOMMANDS------------------------\n\n");
842
843
844 TRACEIT (7, "UserCommandList_DebugOut_printList end");
845 }
846
847
DialogEntityList_DebugOut_printList(struct _DialogEntityList * theList)848 void DialogEntityList_DebugOut_printList(struct _DialogEntityList *theList){
849 TRACEIT (7, "DialogEntityList_DebugOut_printList start");
850 if (theList == NULL){
851 printf("DialogEntityList list: parameter NULL\n");
852 return;
853 }
854 struct _DialogEntityList *bufList=DialogEntityList_getFirstItem(theList);
855
856 printf("\n------------------START OUTPUT DialogEntityList------------------------\n");
857 while (bufList){
858 printf("____ NEXT ITEM: ____\n");
859 printf ("iType = %d\n",bufList->iType);
860 printf ("iValid = %d\n",bufList->iValid);
861
862
863 if (bufList->gstrVarIdentifier){
864 printf("gstrVarIdentifier: %s\n",bufList->gstrVarIdentifier->str);
865 }
866 else {
867 printf("gstrVarIdentifier not set\n");
868 }
869
870 if (bufList->gstrLabel){
871 printf("gstrLabel: %s\n",bufList->gstrLabel->str);
872 }
873 else {
874 printf("gstrLabel not set\n");
875 }
876
877 if (bufList->gstrPredefine){
878 printf("gstrPredefine: %s\n",bufList->gstrPredefine->str);
879 }
880 else {
881 printf("gstrPredefine not set\n");
882 }
883
884 if (bufList->gstrAdditional1){
885 printf("gstrAdditional1: %s\n",bufList->gstrAdditional1->str);
886 }
887 else {
888 printf("gstrAdditional1 not set\n");
889 }
890
891 if (bufList->gstrAdditional2){
892 printf("gstrAdditional2: %s\n",bufList->gstrAdditional2->str);
893 }
894 else {
895 printf("gstrAdditional2 not set\n");
896 }
897
898 bufList = bufList->nextItem;
899 }
900 printf("------------------END OUTPUT DialogEntityList------------------------\n\n");
901
902 TRACEIT (7, "DialogEntityList_DebugOut_printList end");
903 }
904
905
OptionsList_DebugOut_printList(struct _OptionsList * theList)906 void OptionsList_DebugOut_printList(struct _OptionsList *theList){
907 TRACEIT (7, "OptionsList_DebugOut_printList start");
908 if (theList == NULL){
909 printf("Options list: parameter NULL\n");
910 return;
911 }
912 struct _OptionsList *bufList=OptionsList_getFirstItem(theList);
913
914 printf("\n------------------START OUTPUT OPTIONSLIST------------------------\n");
915 while (bufList){
916 printf("____ NEXT ITEM: ____\n");
917 if (bufList->gstrID){
918 printf("gstrID: %s\n",bufList->gstrID->str);
919 }
920 else {
921 printf("gstrID not set\n");
922 }
923
924 if (bufList->gstrName){
925 printf("gstrName: %s\n",bufList->gstrName->str);
926 }
927 else {
928 printf("gstrName not set\n");
929 }
930
931 if (bufList->gstrValue){
932 printf("gstrValue: %s\n",bufList->gstrValue->str);
933 }
934 else {
935 printf("gstrValue not set\n");
936 }
937 bufList = bufList->nextItem;
938 }
939 printf("------------------END OUTPUT OPTIONSLIST------------------------\n\n");
940
941 TRACEIT (7, "OptionsList_DebugOut_printList end");
942 }
943
944
XMLParser_getValidKeyWordsForState(struct _Items_XML_Relation * relation)945 struct _OptionsList *XMLParser_getValidKeyWordsForState(struct _Items_XML_Relation *relation){
946 TRACEIT (7, "XMLParser_getValidKeyWordsForState start");
947 //returns NULL on error.
948 if (relation == NULL){
949 TRACEIT(2, "XMLParser_getValidKeyWordsForState end, Parameter NULL");
950 return NULL;
951 }
952
953 struct _OptionsList *TagList = NULL;
954 /*
955 gboolean bUnKnownBlock; //0 /1
956 gboolean bCatsEyEBlock; //1 /2 we are in <CatsEyE> - Block
957 gboolean bCatsEyEBookMarksBlock; //2 /4
958 gboolean bCatsEyEOptionsBlock; //3 /8 we are in <CatsEyEOptions> - Block
959 gboolean bCatsEyEUserCommandsBlock; //4 /16
960 gboolean bUserCommandBlock; //5 /32 we are in <Usercommand>-Block (within <CatsEyEUsercommands>)
961 gboolean bObjectBlock; //6 /64
962 gboolean bOptionBlock; //7 /128 we are in <Option> - Block (within <CatsEyEOptions>-Block)
963 gboolean bIDBlock; //8 /256
964 gboolean bNameBlock; //9 /512
965 gboolean bValueBlock; //10 /1024
966 */
967
968 if (relation->bUnKnownBlock==TRUE ){
969 TRACEIT(4, "XMLParser_getValidKeyWordsForState end, not in a valid block (1)");
970 return NULL;
971 }
972
973 //before we start to fill the list we have to transform the relation structure to somewhat more handy.
974 //we do not only need to check for truevalues but also for the false ones to determine the right keywords.
975 //I think the easiest way is to bitwise accumulate the bools in the relation structure
976 if (0!=XMLRelation_accumulateRelations(relation)){
977 TRACEIT(4, "XMLParser_getValidKeyWordsForState end, error accumulating realtion bools");
978 return NULL;
979 }
980 int iRelation = relation->iRelation;
981
982 //'CatsEyE'
983 if ( iRelation == 0 ){
984 OptionsList_addItem(&TagList, NULL, XMLTAG_MAIN, NULL); //"CatsEyE"
985 }
986 //'CatsEyEBookmarks', 'CatsEyEOptions', 'CatsEyEUsercommands'
987 if ( iRelation == (2) ){
988 OptionsList_addItem(&TagList, NULL, XMLTAG_BOOKMARKS, NULL); //"CatsEyEBookmarks"
989 OptionsList_addItem(&TagList, NULL, XMLTAG_OPTIONS, NULL); //"CatsEyEOptions"
990 OptionsList_addItem(&TagList, NULL, XMLTAG_USERCOMMANDS, NULL); //"CatsEyEUsercommands"
991 }
992 //'Usercommand'
993 if ( (2 + 16) == iRelation ){
994 OptionsList_addItem(&TagList, NULL, XMLTAG_USERCOMMAND, NULL); //"Usercommand"
995 }
996 //'Object'
997 if ( (2 + 16 + 32) == iRelation ){
998 OptionsList_addItem(&TagList, NULL, XMLTAG_OBJECT, NULL); //"Object"
999 }
1000 //'Option'
1001 if ( (2 + 4) == iRelation ||
1002 (2 + 8) == iRelation ||
1003 (2 + 16 + 32) == iRelation ||
1004 (2 + 16 + 32 + 64) == iRelation
1005 ){
1006 OptionsList_addItem(&TagList, NULL, XMLTAG_OPTION, NULL); //"Option"
1007 }
1008 //'ID'
1009 if ( (2 + 4 + 128) == iRelation ||
1010 (2 + 8 + 128) == iRelation ||
1011 (2 + 16 + 32 + 128) == iRelation ||
1012 //(iRelation & (2 + 16 + 32 + 64) ) == iRelation ||
1013 (2 + 16 + 32 + 64 + 128) == iRelation
1014 ){
1015 OptionsList_addItem(&TagList, NULL, XMLTAG_ID, NULL); //"ID"
1016 }
1017
1018 //'Name', 'Value'
1019 if ( (2 + 4 + 128) == iRelation ||
1020 (2 + 8 + 128) == iRelation ||
1021 (2 + 16 + 32 + 128) == iRelation ||
1022 (2 + 16 + 32 + 64 + 128) == iRelation
1023 ){
1024 OptionsList_addItem(&TagList, NULL, XMLTAG_NAME, NULL); //"Name"
1025 OptionsList_addItem(&TagList, NULL, XMLTAG_VALUE, NULL); //"Value"
1026 }
1027
1028
1029 TRACEIT (7, "XMLParser_getValidKeyWordsForState end");
1030 if (TagList)
1031 return OptionsList_getFirstItem(TagList);
1032 else
1033 return NULL;
1034 }
1035
1036
Usercommand_FoundStartCallback(struct _Parser_Mode_Struct * info)1037 void Usercommand_FoundStartCallback(struct _Parser_Mode_Struct *info){
1038 TRACEIT (7, "Usercommand_FoundStartCallback start");
1039 //when we come up here we know, that the current state is valid (stored in info->relation.
1040 //here we do only react on the current state. This means we reserver memory when needed.
1041 //this function us used for <CatsEyEUsercommands> which includes <Usercommand>,<Option> and <Object>
1042
1043 //Each time we found a <Usercommand>-Block we reserve memory for one item (_UserCommandList), the pointer to
1044 //this structure (which is not yet added to the storageList) is saved in currentListItem
1045
1046 //When we find an Object-Block we reserve the memory for _DialogEntityList in currentListItem->DialogEntityList (_UserCommandList)
1047
1048 //if we find an <Option>-Block we reserve memory for one item (_OptionsList) and store
1049 //the pointer in modeStruct.currentOptionBlock to collect the data
1050 if (info == NULL){
1051 TRACEIT (2, "Usercommand_FoundStartCallback end, parameter NULL");
1052 return;
1053 }
1054
1055 const char **cppAttribNames = info->cppAttributeValues;
1056 const char **cppAttribValues = info->cppAttributeNames;
1057 //GString *gstrBuf=g_string_sized_new(10);
1058 const char *cpType=NULL;
1059 int iType = -1;
1060
1061 //<Usercommand>-Block
1062 if ( info->relation->iRelation == (2 + 16 + 32)
1063 ){
1064 if (info->currentListItem != NULL){ //this is some Error, we try to free it
1065 TRACEIT (2, "Usercommand_FoundStartCallback Error, info->currentListItem isnt NULL, trying to free it");
1066 //free(info->currentListItem);
1067 UserCommandList_freeList((struct _UserCommandList **)&info->currentListItem);
1068 }
1069 UserCommandList_addItem((struct _UserCommandList **)&info->currentListItem, "Usercommand_FoundStartCallback");
1070 }
1071
1072 //<Option>-Block
1073 else if ( info->relation->iRelation == (2 + 16 + 32 + 128) ||
1074 info->relation->iRelation == (2 + 16 + 32 + 64 + 128)
1075 ){
1076 if (info->currentOptionBlock != NULL){ //this is some Error, we try to free it
1077 TRACEIT (2, "Usercommand_FoundStartCallback Error, info->currentOptionBlock isnt NULL, trying to free it");
1078 OptionsList_freeList (&(info->currentOptionBlock));
1079 }
1080 OptionsList_addItem (&(info->currentOptionBlock), NULL, NULL, NULL);
1081 }
1082
1083 //<Object>-Block
1084 else if ( info->relation->iRelation == (2 + 16 + 32 + 64)
1085 ){
1086 if (info->currentListItem == NULL){
1087 TRACEIT (4, "Usercommand_FoundStartCallback Error, info->currentListItem is NULL, OBJECT block was unsuspected");
1088 }
1089 else if (cppAttribNames == NULL || cppAttribValues == NULL){
1090 TRACEIT (4, "Usercommand_FoundStartCallback Error,No attributes defined in ObjectBlock, define attribute type");
1091 }
1092 else{
1093 //we now search for the type of the object (qestion, checkbox, text, file/dirchooser)
1094 while (*cppAttribValues != NULL){
1095 //if we want to have caseinsensitive comparision at this point uncomment the following lines
1096 //but mind, that stcmp(...) has to compare the right strings
1097 //g_string_assign(gstrBuf, cppAttribNames);
1098 //cpBuf = g_utf8_strdown( gstrBuf->str,-1);
1099 //if (cpBuf){
1100 // g_string_assign(gstrBuf, cpBuf);
1101 // g_free(cpBuf);
1102 //}
1103 if (0==strcmp (*cppAttribValues, XMLTAG_TYPE)){ //"type"
1104 cpType = *cppAttribNames;
1105 }
1106 cppAttribNames++;
1107 cppAttribValues++;
1108 }
1109 if (cpType){
1110 if (0==strcmp (cpType, XMLTAG_QUESTION) ){ //"question"
1111 iType = USERDIALOG_ENTITY_TYPE_QUESTION;
1112 }
1113 else if (0==strcmp (cpType, XMLTAG_CHECKBOX) ){ //"checkbox"
1114 iType = USERDIALOG_ENTITY_TYPE_CHECKBOX;
1115 }
1116 else if (0==strcmp (cpType, XMLTAG_TEXT) ){ //"text"
1117 iType = USERDIALOG_ENTITY_TYPE_TEXT;
1118 }
1119 else if (0==strcmp (cpType, XMLTAG_FILECHOOSER) ){ //"filechooser"
1120 iType = USERDIALOG_ENTITY_TYPE_FILECHOOSER;
1121 }
1122 else if (0==strcmp (cpType, XMLTAG_DIRCHOOSER) ){ //"dirchooser"
1123 iType = USERDIALOG_ENTITY_TYPE_DIRCHOOSER;
1124 }
1125 else if (0==strcmp (cpType, XMLTAG_SEPARATOR) ){ //"separator"
1126 iType = USERDIALOG_ENTITY_TYPE_SEPARATOR;
1127 }
1128 }
1129 DialogEntityList_addItem( &(((struct _UserCommandList *)(info->currentListItem))->DialogEntityList), iType );
1130 }
1131 }
1132
1133 TRACEIT (7, "Usercommand_FoundStartCallback end");
1134 return;
1135 }
1136
1137
Usercommand_FoundEndCallback(struct _Parser_Mode_Struct * info,const char * element_name)1138 void Usercommand_FoundEndCallback(struct _Parser_Mode_Struct *info, const char *element_name){
1139 TRACEIT (7, "Usercommand_FoundEndCallback start");
1140 //When comming from <Object> we have nothing to do, as all the information is allready stored in _usercommandList->Dialog..
1141
1142 //when comming from an <Option> Block, we can be in <UserCommand> or <Object>
1143 //and we have to add the information in info->currentOptionBlock to info->currentListItem (_UserCommandList)
1144 //or info->currentListItem->DialogEntityList (_DialogEntityList), then, FREE the currentOptionBlock!! and set the pointer to NULL
1145
1146 //when we leave <UserCommand> copy the currentItem to the storageList (do not copy the content readress the next/Prev members)
1147 //and set the currentItem to NULL
1148
1149 //we also can be in an Option block, with ID, Name and Value properties, but this doesnt bother us in here.
1150
1151 if (info == NULL || element_name == NULL){
1152 TRACEIT (2, "Usercommand_FoundEndCallback end, parameter NULL");
1153 return;
1154 }
1155 if (info->storageList == NULL || info->currentListItem==NULL || info->relation==NULL ){
1156 /*if (info->storageList == NULL ){
1157 printf("storageList == NULL\n");
1158 }
1159 if (info->currentListItem == NULL ){
1160 printf("currentListItem == NULL\n");
1161 }
1162 if (info->relation == NULL ){
1163 printf("relation == NULL\n");
1164 }*/
1165 TRACEIT(2, "Usercommand_FoundEndCallback end, parameter 2 NULL");
1166 return;
1167 }
1168
1169 int iRelation = info->relation->iRelation;
1170 struct _UserCommandList *currentListItem = (struct _UserCommandList *)info->currentListItem;
1171 struct _OptionsList *currentOptionBlock = info->currentOptionBlock;
1172 char *cbuf=NULL;
1173
1174 if (0 == strcmp(element_name, XMLTAG_OBJECT)){ //nothing to do, but lets check if the option block has quit
1175 if (info->currentOptionBlock != NULL){ //this should not happen, however, the info stored in here is not used, we free it
1176 TRACEIT (4, "Usercommand_FoundEndCallback leaving Object block, but an Option block is still active");
1177 free(info->currentOptionBlock);
1178 info->currentOptionBlock = NULL;
1179 }
1180 //return;
1181 }
1182 else if ( ( iRelation==(0) || iRelation==(2) || iRelation==(2+16) ) &&
1183 ( 0==strcmp(element_name, XMLTAG_MAIN) || 0==strcmp(element_name, XMLTAG_USERCOMMANDS) || 0==strcmp(element_name, XMLTAG_USERCOMMAND) )
1184 ){ //we save the current state of the usercommand to our list.
1185 if (info->currentListItem != NULL){
1186 UserCommandList_addItemAsCopy((struct _UserCommandList **)info->storageList, currentListItem);
1187 info->currentListItem = NULL;
1188 if (info->currentOptionBlock != NULL){
1189 //now free the option list
1190 OptionsList_freeList ( &(info->currentOptionBlock) );
1191 info->currentOptionBlock=NULL;
1192 }
1193 }
1194 }
1195 else if (0 == strcmp(element_name, XMLTAG_OPTION)){
1196 if ( info->currentOptionBlock == NULL){
1197 TRACEIT (4, "Usercommand_FoundEndCallback end, empty Option block? Can not continue");
1198 return;
1199 }
1200 if (info->currentOptionBlock->gstrID == NULL){
1201 TRACEIT (4, "Usercommand_FoundEndCallback end, No ID defined in option block");
1202 OptionsList_freeList ( &(info->currentOptionBlock) );
1203 info->currentOptionBlock=NULL;
1204 return;
1205 }
1206 if (info->currentOptionBlock->gstrValue == NULL){
1207 TRACEIT (4, "Usercommand_FoundEndCallback end, No value defined in option block");
1208 OptionsList_freeList ( &(info->currentOptionBlock) );
1209 info->currentOptionBlock=NULL;
1210 return;
1211 }
1212 if ( iRelation == (2 + 16 + 32 ) ){ //usercommand block, store currentOption to currentListItem
1213 //we check for the ID (stored in currentOption) for valid names to identify the right varible to store the information to
1214 if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_DEFAULTCOMMAND)){ //"Defaultcommand"
1215 cbuf = currentOptionBlock->gstrValue->str;
1216 if ( 0==strcmp(cbuf, "True") || 0==strcmp(cbuf, "true") || 0==strcmp(cbuf, "TRUE") ){
1217 currentListItem->iIsDefaultCommand = 1;
1218 }
1219 else{
1220 currentListItem->iIsDefaultCommand = 0;
1221 }
1222 }
1223 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_NAME)){
1224 UserCommandList_editItem(currentListItem, -1, currentOptionBlock->gstrValue->str, NULL, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1225 }
1226 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_TARGET)){ //"Target"
1227 UserCommandList_editItem(currentListItem, -1, NULL, currentOptionBlock->gstrValue->str, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1228 }
1229 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_COMMAND)){ //"Command"
1230 UserCommandList_editItem(currentListItem, -1, NULL, NULL, currentOptionBlock->gstrValue->str, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1231 }
1232 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_CALLTYPE)){ //"Calltype"
1233 cbuf = currentOptionBlock->gstrValue->str;
1234 if ( 0==strcmp(cbuf, "all") || 0==strcmp(cbuf, "All") || 0==strcmp(cbuf, "ALL") ){
1235 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, USERCOMMAND_CALLTYPE_ALL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1236 }
1237 else if ( 0==strcmp(cbuf, "each") || 0==strcmp(cbuf, "Each") || 0==strcmp(cbuf, "EACH") ){
1238 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, USERCOMMAND_CALLTYPE_EACH, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1239 }
1240 else if ( 0==strcmp(cbuf, "list") || 0==strcmp(cbuf, "List") || 0==strcmp(cbuf, "LIST") ){
1241 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, USERCOMMAND_CALLTYPE_LIST, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1242 }
1243 else {
1244 TRACEIT (4, "Usercommand_FoundEndCallback unknown calltype, expected all, each or list");
1245 TRACEIT (4, "But got:");
1246 TRACEIT (4, cbuf);
1247 }
1248 }
1249 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_QUITREPLY)){ //"OptionQuitreply"
1250 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, -1, currentOptionBlock->gstrValue->str, NULL, NULL, NULL, NULL, NULL, NULL);
1251 }
1252 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_ACTIONNOTE)){ //"OptionActionnote"
1253 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, -1, NULL, currentOptionBlock->gstrValue->str, NULL, NULL, NULL, NULL, NULL);
1254 }
1255 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_LISTCAPTION)){ //"OptionCaption"
1256 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, -1, NULL, NULL, currentOptionBlock->gstrValue->str, NULL, NULL, NULL, NULL);
1257 }
1258 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_LISTLABEL)){ //"OptionLabel"
1259 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, -1, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL, NULL, NULL);
1260 }
1261 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_DIALOGCAPTION)){ //"DialogCaption"
1262 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, -1, NULL, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL, NULL);
1263 }
1264 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_DIALOGLABEL)){ //"DialogLabel"
1265 UserCommandList_editItem(currentListItem, -1, NULL, NULL, NULL, -1, NULL, NULL, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL);
1266 }
1267 else {
1268 TRACEIT (4, "Usercommand_FoundEndCallback unknown ID for 2 + 16 + 32, expected OptionQuitreply, OptionActionnote, OptionCaption, OptionLabel");
1269 TRACEIT (4, "But got:");
1270 TRACEIT (4, currentOptionBlock->gstrID->str);
1271 }
1272 }
1273 else if ( iRelation == (2 + 16 + 32 + 64 ) ){ //object block, store currentOption to currentListItem->DialogEntityList
1274 if ( ((struct _UserCommandList *)(info->currentListItem))->DialogEntityList == NULL){
1275 TRACEIT (2, "Usercommand_FoundEndCallback end, Dialog pointer is NULL but we are in a dialog section, weird!");
1276 return;
1277 }
1278 if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_VARID)){ //"VarID"
1279 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, currentOptionBlock->gstrValue->str, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1280 }
1281 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_LABELTEXT)){ //"LabelText"
1282 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, NULL, currentOptionBlock->gstrValue->str, NULL, NULL, NULL, NULL, NULL, NULL);
1283 }
1284 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_PREDEFINE)){ //"Predefine"
1285 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL, NULL, NULL, NULL);
1286 }
1287 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_TRUEVALUE)){ //"TrueValue"
1288 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, NULL, NULL, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL, NULL);
1289 }
1290 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_BUTTONTEXT)){ //"ButtonText"
1291 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, NULL, NULL, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL, NULL);
1292 }
1293 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_FALSEVALUE)){ //"FalseValue"
1294 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, NULL, NULL, NULL, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL);
1295 }
1296 else if ( 0 == strcmp(currentOptionBlock->gstrID->str, XMLTAG_CHOOSERCAPTION)){ //"ChooserCaption"
1297 DialogEntityList_editLastItem(currentListItem->DialogEntityList, -1, NULL, NULL, NULL, NULL, NULL, NULL, currentOptionBlock->gstrValue->str, NULL);
1298 }
1299 else {
1300 TRACEIT (4, "Usercommand_FoundEndCallback unknown ID for 2 + 16 + 32 + 64: expected: VarID, LabelText, Predefine, TrueValue, ButtonText, FalseValue or ChooserCaption");
1301 TRACEIT (4, "But got:");
1302 TRACEIT (4, currentOptionBlock->gstrID->str);
1303 }
1304 }
1305 if (info->currentOptionBlock != NULL){
1306 //now free the option list
1307 OptionsList_freeList ( &(info->currentOptionBlock) );
1308 info->currentOptionBlock=NULL;
1309 }
1310 }
1311 TRACEIT (7, "Usercommand_FoundEndCallback end");
1312 }
1313
1314
Options_FoundStartCallback(struct _Parser_Mode_Struct * info)1315 void Options_FoundStartCallback(struct _Parser_Mode_Struct *info){
1316 TRACEIT (7, "Options_FoundStartCallback start");
1317 //when we come up here we know, that the current state is valid (stored in info->relation.
1318 //here we do only react on the current state. This means we reserver memory when needed.
1319 //this function us used for <CatsEyEOptions> and <CatsEyEBookmarks>
1320
1321 //Each time we found a <Option>-Block we reserve memory for one item (_Options_List), the pointer to
1322 //this structure (which is not yet added to the storageList) is saved in currentListItem
1323 if (info == NULL){
1324 TRACEIT (2, "Options_FoundStartCallback end, parameter NULL");
1325 return;
1326 }
1327
1328 if (info->relation->iRelation == (2 + 8 + 128) || //options block
1329 info->relation->iRelation == (2 + 4 + 128) //bookmark block
1330 ){
1331 if (info->currentListItem != NULL){ //this is some Error, we try to free it
1332 TRACEIT (2, "Options_FoundStartCallback Error, info->currentListItem isnt NULL, trying to free it");
1333 OptionsList_freeList ((struct _OptionsList **)&(info->currentListItem));
1334 }
1335 OptionsList_addItem ( (struct _OptionsList **)&(info->currentListItem), NULL, NULL, NULL);
1336 //printf("Options_FoundStartCalback: Item added to OptionsList\n");
1337 }
1338 //printf("Options_FoundStartCallback, ends: info->relation->iRelation = %d\n",info->relation->iRelation);
1339 TRACEIT (7, "Options_FoundStartCallback end");
1340 }
1341
1342
Options_FoundEndCallback(struct _Parser_Mode_Struct * info,const char * element_name)1343 void Options_FoundEndCallback(struct _Parser_Mode_Struct *info, const char *element_name){
1344 TRACEIT (7, "Options_FoundEndCallback start");
1345 //when info->currentListItem isnt NULL, it is suspected to be a valid item for the options list
1346 //WE DELETE the currentListItem in here.
1347 //However, we have to check its validation before adding it to the list, as some options may need
1348 //defined information or may not be allowed to exist more than once.
1349
1350 if (info == NULL || element_name==NULL){
1351 TRACEIT (2, "Options_FoundEndCallback end, Parameter NULL");
1352 return;
1353 }
1354 if (info->relation == NULL || info->storageList == NULL || info->currentListItem==NULL ){
1355 if (info->relation == NULL){
1356 TRACEIT (2, "Options_FoundEndCallback relation==0");
1357 }
1358 if (info->storageList == NULL){
1359 TRACEIT (2, "Options_FoundEndCallback storageList==0");
1360 }
1361 if (info->currentListItem == NULL){
1362 TRACEIT (2, "Options_FoundEndCallback currentListItem==0");
1363 }
1364
1365 if (info->currentListItem!=NULL){
1366 OptionsList_freeList( (struct _OptionsList **)&(info->currentListItem) );
1367 }
1368 TRACEIT (2, "Options_FoundEndCallback end, Parameter 2 NULL");
1369 return;
1370 }
1371 struct _OptionsList *currentListItem = (struct _OptionsList *)info->currentListItem;
1372 struct _OptionsList **OptionsList = (struct _OptionsList **)info->storageList;
1373 struct _OptionsList *BufObject=NULL;
1374
1375 int SingleOrMulti=0; //0=unknown/notfound/invalid, 1=found/single, 2=found/multi //multi means that the key can exists multiple times
1376
1377 if (info->relation->iRelation == (2 + 8) ){ //supposed to leav option block from options block
1378 //check if the ID is known:
1379 if (0 == strcmp (STANDARDEDITORKEY, currentListItem->gstrID->str) && currentListItem->gstrName!=NULL && currentListItem->gstrValue!=NULL){
1380 SingleOrMulti=1;
1381 }
1382 else if (0 == strcmp (SAVEPATHESONEXIT, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1383 SingleOrMulti=1;
1384 }
1385 else if (0 == strcmp (TERMINALKEY, currentListItem->gstrID->str) && currentListItem->gstrName!=NULL && currentListItem->gstrValue!=NULL){
1386 SingleOrMulti=1;
1387 }
1388 else if (0 == strcmp (STANDARDSTARTDIRECTORY, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1389 SingleOrMulti=1;
1390 }
1391 else if (0 == strcmp (COLOR_ITEMS_DEFAULT, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1392 SingleOrMulti=1;
1393 }
1394 else if (0 == strcmp (COLOR_DIRECTORIES, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1395 SingleOrMulti=1;
1396 }
1397 else if (0 == strcmp (COLOR_LINKS, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1398 SingleOrMulti=1;
1399 }
1400 else if (0 == strcmp (COLOR_ITEMS_MISSING, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1401 SingleOrMulti=1;
1402 }
1403 else if (0 == strcmp (STARTDIRECTORIESLEFTKEY, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1404 SingleOrMulti=2;
1405 }
1406 else if (0 == strcmp (STARTDIRECTORIESLEFTKEY, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1407 SingleOrMulti=2;
1408 }
1409 else if (0 == strcmp (PREVIEWSIZE, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1410 SingleOrMulti=1;
1411 }
1412 else if (0 == strcmp (PREVIEWTYPES, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1413 SingleOrMulti=1;
1414 }
1415 else if (0 == strcmp (SAVESESSIONMINUTESTYPES, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1416 SingleOrMulti=1;
1417 }
1418 else if (0 == strcmp (COLUMN_ORDER, currentListItem->gstrID->str) && currentListItem->gstrValue!=NULL){
1419 SingleOrMulti=1;
1420 }
1421 else{
1422 TRACEIT (5, "Options_FoundEndCallback unknown parameter or incomplete values");
1423 TRACEIT (5, "Element Name:");
1424 TRACEIT (5, element_name);
1425 if (currentListItem->gstrID){
1426 TRACEIT (5, "currentListItem->gstrID:");
1427 TRACEIT (5, currentListItem->gstrID->str);
1428 }
1429 else{
1430 TRACEIT (5, "No ID defined");
1431 }
1432 if (currentListItem->gstrValue){
1433 TRACEIT (5, "currentListItem->gstrValue:");
1434 TRACEIT (5, currentListItem->gstrValue->str);
1435 }
1436 else{
1437 TRACEIT (5, "No Value defined");
1438 }
1439 }
1440 }
1441 else if (info->relation->iRelation == (2 + 4) ){ //supposed to leaved option block from Bookmarks block
1442 if (currentListItem->gstrName != NULL && currentListItem->gstrValue != NULL){
1443 SingleOrMulti=2;
1444 }
1445 }
1446
1447 if (SingleOrMulti == 1){
1448 BufObject = OptionsList_getItemByID(*OptionsList, currentListItem->gstrID->str);
1449 if (BufObject == NULL){
1450 OptionsList_addItem(OptionsList, currentListItem->gstrID==NULL?NULL:currentListItem->gstrID->str,
1451 currentListItem->gstrName==NULL?NULL:currentListItem->gstrName->str,
1452 currentListItem->gstrValue==NULL?NULL:currentListItem->gstrValue->str);
1453 }
1454 else{
1455 OptionsList_editItem(BufObject, currentListItem->gstrID==NULL?NULL:currentListItem->gstrID->str,
1456 currentListItem->gstrName==NULL?NULL:currentListItem->gstrName->str,
1457 currentListItem->gstrValue==NULL?NULL:currentListItem->gstrValue->str);
1458 //TRACEIT (5, "Options_FoundEndCallback found another instance of a single option, last wins");
1459 }
1460 OptionsList_freeList( (struct _OptionsList **)&(info->currentListItem) );
1461 info->currentListItem = NULL;
1462 }
1463 else if (SingleOrMulti == 2){
1464 //printf("Options_FoundEndCallback multi2 adding item\n");
1465 OptionsList_addItem(OptionsList, currentListItem->gstrID==NULL?NULL:currentListItem->gstrID->str,
1466 currentListItem->gstrName==NULL?NULL:currentListItem->gstrName->str,
1467 currentListItem->gstrValue==NULL?NULL:currentListItem->gstrValue->str);
1468 OptionsList_freeList( (struct _OptionsList **)&(info->currentListItem) );
1469 info->currentListItem = NULL;
1470 }
1471
1472 TRACEIT (7, "Options_FoundEndCallback end");
1473 }
1474
1475
Options_FoundTextCallback(struct _Parser_Mode_Struct * info,const char * text)1476 void Options_FoundTextCallback(struct _Parser_Mode_Struct *info, const char *text){
1477 TRACEIT (7, "Options_FoundTextCallback start");
1478 //We do not longer only handle options and bookmarks in here but all <Option> Blocks we use
1479 //including the Option blocks in the usercommand/dialog sections
1480
1481 //this means, we only check for 256m 512 or 1024 in iRelation (wich holds the information about where we are)
1482 //and react to that.
1483
1484 //However, option and bookmark block store their OptionsList in currentListItem, while
1485 //the commandblock store it in currentOptionBlock, we distinguish this with the help of
1486 //iCurrentListType
1487
1488
1489 //no:
1490 //////we are here for the options and bookmarks, so the only valid relation modes are:
1491 //////( 2 + 8 + 128 + 256 ) ( 2 + 8 + 128 + 512 ) ( 2 + 8 + 128 + 1024 )
1492
1493 if (info == NULL || text == NULL){
1494 TRACEIT (2, "Options_FoundTextCallback end, Parameter NULL");
1495 return;
1496 }
1497
1498 struct _Items_XML_Relation *relation = (struct _Items_XML_Relation *)info->relation;
1499 if (info->relation==NULL){
1500 TRACEIT (2, "Options_FoundTextCallback end, Parameter 2 NULL");
1501 return;
1502 }
1503 struct _OptionsList *optionList = NULL;
1504 if (info->iCurrentListType == CONFIGFILE_LOAD_OPTIONS || info->iCurrentListType==CONFIGFILE_LOAD_BOOKMARKS){
1505 optionList = (struct _OptionsList *)info->currentListItem;
1506 }
1507 else if (info->iCurrentListType == CONFIGFILE_LOAD_USERCOMMANDS){
1508 optionList = info->currentOptionBlock;
1509 }
1510
1511 if (optionList == NULL){ //we can come up here when there is text (e.g. a newline) where we do not prepared for text
1512 /*
1513 TRACEIT (2, "Options_FoundTextCallback end, Parameter 3 NULL");
1514 if (info->iCurrentListType == CONFIGFILE_LOAD_OPTIONS){
1515 TRACEIT(2, "Options_FoundTextCallback comming from CONFIGFILE_LOAD_OPTIONS");
1516 }
1517 if (info->iCurrentListType == CONFIGFILE_LOAD_BOOKMARKS){
1518 TRACEIT(2, "Options_FoundTextCallback comming from CONFIGFILE_LOAD_BOOKMARKS");
1519 }
1520 if (info->iCurrentListType == CONFIGFILE_LOAD_USERCOMMANDS){
1521 TRACEIT(2, "Options_FoundTextCallback comming from CONFIGFILE_LOAD_USERCOMMANDS");
1522 }*/
1523 TRACEIT (7, "Options_FoundTextCallback end 2");
1524 return;
1525 }
1526
1527 if ( 256 & relation->iRelation ){ //ID
1528 TRACEIT (6, "Options_FoundTextCallback editItem at optionList ID:");
1529 TRACEIT (6, text);
1530 OptionsList_editItem( optionList, text, NULL, NULL);
1531 }
1532 if ( 512 & relation->iRelation ){ //Name
1533 TRACEIT (6, "Options_FoundTextCallback editItem at optionList Name:");
1534 TRACEIT (6, text);
1535 OptionsList_editItem( optionList, NULL, text, NULL);
1536 }
1537 if ( 1024 & relation->iRelation ){ //Value
1538 TRACEIT (6, "Options_FoundTextCallback editItem at optionList Value:");
1539 TRACEIT (6, text);
1540 OptionsList_editItem( optionList, NULL, NULL, text);
1541 }
1542
1543 TRACEIT (7, "Options_FoundTextCallback end");
1544 }
1545
1546
UserCommandList_addItem(struct _UserCommandList ** theList,const char * ccpSource)1547 int UserCommandList_addItem(struct _UserCommandList **theList, const char *ccpSource){
1548 TRACEIT (7, "UserCommandList_addItem start");
1549 //return: -1=error, 0=ok
1550
1551 if (theList == NULL){
1552 TRACEIT (2, "UserCommandList_addItem end, parameter NULL");
1553 return -1;
1554 }
1555
1556 struct _UserCommandList *newItem = malloc (sizeof (struct _UserCommandList));
1557 struct _UserCommandList *bufItem = NULL;
1558 if (newItem == NULL){
1559 TRACEIT (2, "UserCommandList_addItem Could not allocate memory");
1560 return -1;
1561 }
1562 /*if (ccpSource != NULL){
1563 char cbuf[301];
1564 snprintf(cbuf, 300,"%s added new item:%p",ccpSource, newItem);
1565 TRACEIT (4, cbuf);
1566 }*/
1567
1568
1569 //default values for member
1570 newItem->iIsDefaultCommand = 0;
1571 newItem->iValid = 0;
1572 newItem->gstrName =NULL;
1573 newItem->glistTargets =NULL;
1574 newItem->gstrCommand =NULL;
1575 newItem->DialogEntityList =NULL;
1576 newItem->gstrDialogCaption =NULL;
1577 newItem->gstrDialogLabel =NULL;
1578 newItem->option_iCallType =USERCOMMAND_CALLTYPE_ALL;
1579 newItem->option_gstrQuitreply =NULL;
1580 newItem->option_gstrActionnote =NULL;
1581 newItem->option_gstrCaption =NULL;
1582 newItem->option_gstrLabel =NULL;
1583 newItem->gstrWorkingDir =NULL;
1584
1585 newItem->nextItem = NULL;
1586 newItem->prevItem = NULL;
1587
1588 //store the new item
1589 if (*theList == NULL){ //brand new list
1590 *theList = newItem;
1591 }
1592 else{
1593 bufItem = UserCommandList_getLastItem (*theList);
1594 if (bufItem == NULL){
1595 TRACEIT (2, "UserCommandList_addItem error, its no new list, but I also cant find the last item");
1596 free(newItem);
1597 return -1;
1598 }
1599
1600 bufItem->nextItem = newItem;
1601 newItem->prevItem = bufItem;
1602 }
1603
1604 TRACEIT (7, "UserCommandList_addItem end");
1605 return 0;
1606 }
1607
1608
UserCommandList_clearTargets(struct _UserCommandList * theItem)1609 int UserCommandList_clearTargets(struct _UserCommandList *theItem){
1610 TRACEIT (10, "UserCommandList_clearTargets start");
1611 if (theItem == NULL ){
1612 TRACEIT (2, "UserCommandList_clearTargets end, PARAMETER NULL");
1613 return -1;
1614 }
1615 if (theItem->glistTargets){
1616 g_list_foreach(theItem->glistTargets, (GFunc) GListFreeGStrings, NULL);
1617 g_list_free(theItem->glistTargets);
1618 }
1619 theItem->glistTargets = NULL;
1620 TRACEIT (10, "UserCommandList_clearTargets end");
1621 return 0;
1622 }
1623
1624
UserCommandList_deleteItem(struct _UserCommandList * theItem)1625 struct _UserCommandList *UserCommandList_deleteItem(struct _UserCommandList *theItem){
1626 //deletes theItem and returns the new begining of the list,
1627 //if theItem was the last item NULL is returned
1628 TRACEIT (7, "UserCommandList_deleteItem start");
1629 struct _UserCommandList *bufList = NULL;
1630 if (theItem == NULL ){
1631 TRACEIT (2, "UserCommandList_deleteItem end, PARAMETER NULL");
1632 return NULL;
1633 }
1634 if (theItem->nextItem){
1635 theItem->nextItem->prevItem = theItem->prevItem;
1636 bufList = theItem->nextItem;
1637 }
1638 if (theItem->prevItem){
1639 theItem->prevItem->nextItem = theItem->nextItem;
1640 bufList = theItem->prevItem;
1641 }
1642
1643 if (bufList){
1644 bufList = UserCommandList_getFirstItem (bufList);
1645 }
1646
1647
1648 if (theItem->gstrName){
1649 g_string_free(theItem->gstrName, TRUE);
1650 }
1651 if (theItem->glistTargets){
1652 g_list_foreach(theItem->glistTargets, (GFunc) GListFreeGStrings, NULL);
1653 g_list_free(theItem->glistTargets);
1654 }
1655 if (theItem->gstrCommand){
1656 g_string_free(theItem->gstrCommand, TRUE);
1657 }
1658 if (theItem->gstrDialogCaption){
1659 g_string_free(theItem->gstrDialogCaption, TRUE);
1660 }
1661 if (theItem->gstrDialogLabel){
1662 g_string_free(theItem->gstrDialogLabel, TRUE);
1663 }
1664 if (theItem->option_gstrQuitreply){
1665 g_string_free(theItem->option_gstrQuitreply, TRUE);
1666 }
1667 if (theItem->option_gstrActionnote){
1668 g_string_free(theItem->option_gstrActionnote, TRUE);
1669 }
1670 if (theItem->option_gstrCaption){
1671 g_string_free(theItem->option_gstrCaption, TRUE);
1672 }
1673 if (theItem->option_gstrLabel){
1674 g_string_free(theItem->option_gstrLabel, TRUE);
1675 }
1676 if (theItem->DialogEntityList){
1677 DialogEntityList_freeList ( &(theItem->DialogEntityList));
1678 }
1679 if (theItem->gstrWorkingDir){
1680 g_string_free(theItem->gstrWorkingDir, TRUE);
1681 }
1682
1683
1684 free(theItem);
1685
1686 TRACEIT (7, "UserCommandList_deleteItem end");
1687 return bufList;
1688 }
1689
1690
UserCommandList_freeList(struct _UserCommandList ** theList)1691 int UserCommandList_freeList(struct _UserCommandList **theList){
1692 TRACEIT (7, "UserCommandList_freeList start");
1693 //has to free _DialogEntityList and glistTargets too.
1694 //return: -1=error, 0=ok
1695 if (theList == NULL){
1696 TRACEIT (2, "UserCommandList_freeList end, parameter NULL");
1697 return -1;
1698 }
1699
1700 struct _UserCommandList *firstItem=UserCommandList_getFirstItem(*theList);
1701 struct _UserCommandList *bufItem=firstItem;
1702
1703 if (firstItem == NULL){
1704 TRACEIT (2, "UserCommandList_freeList end, could not get first item in list");
1705 return -1;
1706 }
1707
1708 while (bufItem){
1709 if (bufItem->gstrName){
1710 g_string_free(bufItem->gstrName, TRUE);
1711 }
1712 if (bufItem->glistTargets){
1713 g_list_foreach(bufItem->glistTargets, (GFunc) GListFreeGStrings, NULL);
1714 g_list_free(bufItem->glistTargets);
1715 }
1716 if (bufItem->gstrCommand){
1717 g_string_free(bufItem->gstrCommand, TRUE);
1718 }
1719 if (bufItem->gstrDialogCaption){
1720 g_string_free(bufItem->gstrDialogCaption, TRUE);
1721 }
1722 if (bufItem->gstrDialogLabel){
1723 g_string_free(bufItem->gstrDialogLabel, TRUE);
1724 }
1725 if (bufItem->option_gstrQuitreply){
1726 g_string_free(bufItem->option_gstrQuitreply, TRUE);
1727 }
1728 if (bufItem->option_gstrActionnote){
1729 g_string_free(bufItem->option_gstrActionnote, TRUE);
1730 }
1731 if (bufItem->option_gstrCaption){
1732 g_string_free(bufItem->option_gstrCaption, TRUE);
1733 }
1734 if (bufItem->option_gstrLabel){
1735 g_string_free(bufItem->option_gstrLabel, TRUE);
1736 }
1737 if (bufItem->DialogEntityList){
1738 DialogEntityList_freeList ( &(bufItem->DialogEntityList));
1739 }
1740 if (bufItem->gstrWorkingDir){
1741 g_string_free(bufItem->gstrWorkingDir, TRUE);
1742 }
1743
1744 firstItem = bufItem->nextItem;
1745 free(bufItem);
1746 bufItem = firstItem;
1747 }
1748 *theList=NULL;
1749
1750 TRACEIT (7, "UserCommandList_freeList end");
1751 return 0;
1752 }
1753
1754
UserCommandList_editItem(struct _UserCommandList * theItem,int iIsDefaultCommand,const char * cpName,const char * cpTarget,const char * cpCommand,int iCallType,const char * cpOptionQuitreply,const char * cpOptionActionnote,const char * cpOptionCaption,const char * cpOptionLabel,const char * cpDialogCaption,const char * cpDialogLabel,const char * cpWorkingDir)1755 int UserCommandList_editItem(struct _UserCommandList *theItem, int iIsDefaultCommand, const char *cpName, const char *cpTarget, const char *cpCommand, int iCallType, const char *cpOptionQuitreply, const char *cpOptionActionnote, const char *cpOptionCaption, const char *cpOptionLabel, const char *cpDialogCaption, const char *cpDialogLabel, const char *cpWorkingDir){
1756 TRACEIT (7, "UserCommandList_editItem start");
1757 //return: -1=error, 0=ok
1758 //the target amy be added to the GList
1759 if (theItem == NULL){
1760 TRACEIT (2, "UserCommandList_editItem parameter NULL");
1761 return -1;
1762 }
1763
1764 if (cpOptionActionnote){
1765 if (theItem->option_gstrActionnote){
1766 g_string_assign(theItem->option_gstrActionnote, cpOptionActionnote);
1767 }
1768 else{
1769 theItem->option_gstrActionnote = g_string_new(cpOptionActionnote);
1770 }
1771 }
1772 if (cpOptionCaption){
1773 if (theItem->option_gstrCaption){
1774 g_string_assign(theItem->option_gstrCaption, cpOptionCaption);
1775 }
1776 else{
1777 theItem->option_gstrCaption = g_string_new(cpOptionCaption);
1778 }
1779 }
1780 if (cpOptionLabel){
1781 if (theItem->option_gstrLabel){
1782 g_string_assign(theItem->option_gstrLabel, cpOptionLabel);
1783 }
1784 else{
1785 theItem->option_gstrLabel = g_string_new(cpOptionLabel);
1786 }
1787 }
1788 if (cpDialogCaption){
1789 if (theItem->gstrDialogCaption){
1790 g_string_assign(theItem->gstrDialogCaption, cpDialogCaption);
1791 }
1792 else{
1793 theItem->gstrDialogCaption = g_string_new(cpDialogCaption);
1794 }
1795 }
1796 if (cpDialogLabel){
1797 if (theItem->gstrDialogLabel){
1798 g_string_assign(theItem->gstrDialogLabel, cpDialogLabel);
1799 }
1800 else{
1801 theItem->gstrDialogLabel = g_string_new(cpDialogLabel);
1802 }
1803 }
1804 if (iIsDefaultCommand != -1){
1805 theItem->iIsDefaultCommand = iIsDefaultCommand;
1806 }
1807 if (cpName){
1808 if (theItem->gstrName){
1809 g_string_assign(theItem->gstrName, cpName);
1810 }
1811 else{
1812 theItem->gstrName = g_string_new(cpName);
1813 }
1814 }
1815 if (cpTarget){
1816 theItem->glistTargets = g_list_append (theItem->glistTargets, g_string_new(cpTarget));
1817 }
1818 if (cpCommand){
1819 if (theItem->gstrCommand){
1820 g_string_assign(theItem->gstrCommand, cpCommand);
1821 }
1822 else{
1823 theItem->gstrCommand = g_string_new(cpCommand);
1824 }
1825 }
1826 if (iCallType != -1){
1827 theItem->option_iCallType = iCallType;
1828 }
1829 if (cpOptionQuitreply){
1830 if (theItem->option_gstrQuitreply){
1831 g_string_assign(theItem->option_gstrQuitreply, cpOptionQuitreply);
1832 }
1833 else{
1834 theItem->option_gstrQuitreply = g_string_new(cpOptionQuitreply);
1835 }
1836 }
1837 if (cpWorkingDir){
1838 if (theItem->gstrWorkingDir){
1839 g_string_assign(theItem->gstrWorkingDir, cpWorkingDir);
1840 }
1841 else{
1842 theItem->gstrWorkingDir = g_string_new(cpWorkingDir);
1843 }
1844 }
1845
1846 TRACEIT (7, "UserCommandList_editItem end");
1847 return 0;
1848 }
1849
1850
UserCommandList_deleteItemElement(struct _UserCommandList * theItem,int iName,int iTarget,int iCommand,int iOptionQuitreply,int iOptionActionnote,int iOptionCaption,int iOptionLabel,int iDialogCaption,int iDialogLabel,int iWorkingDir)1851 int UserCommandList_deleteItemElement(struct _UserCommandList *theItem, int iName, int iTarget, int iCommand, int iOptionQuitreply, int iOptionActionnote, int iOptionCaption, int iOptionLabel, int iDialogCaption, int iDialogLabel, int iWorkingDir){
1852 //deletes the GStrings fo the elements specified in the parameters
1853 //0=do nothing, 1=delete this element
1854 TRACEIT (7, "UserCommandList_deleteItemElement start");
1855 //return: -1=error, 0=ok
1856 //the target amy be added to the GList
1857 if (theItem == NULL){
1858 TRACEIT (2, "UserCommandList_deleteItemElement parameter NULL");
1859 return -1;
1860 }
1861
1862 if (1==iOptionActionnote){
1863 if (theItem->option_gstrActionnote){
1864 g_string_free(theItem->option_gstrActionnote, TRUE);
1865 theItem->option_gstrActionnote = NULL;
1866 }
1867 }
1868 if (1==iOptionCaption){
1869 if (theItem->option_gstrCaption){
1870 g_string_free(theItem->option_gstrCaption, TRUE);
1871 theItem->option_gstrCaption = NULL;
1872 }
1873 }
1874 if (1==iOptionLabel){
1875 if (theItem->option_gstrLabel){
1876 g_string_free(theItem->option_gstrLabel, TRUE);
1877 theItem->option_gstrLabel = NULL;
1878 }
1879 }
1880 if (1==iDialogCaption){
1881 if (theItem->gstrDialogCaption){
1882 g_string_free(theItem->gstrDialogCaption, TRUE);
1883 theItem->gstrDialogCaption = NULL;
1884 }
1885 }
1886 if (1==iDialogLabel){
1887 if (theItem->gstrDialogLabel){
1888 g_string_free(theItem->gstrDialogLabel, TRUE);
1889 theItem->gstrDialogLabel = NULL;
1890 }
1891 }
1892 if (1==iName){
1893 if (theItem->gstrName){
1894 g_string_free(theItem->gstrName, TRUE);
1895 theItem->gstrName = NULL;
1896 }
1897 }
1898 if (1==iTarget){
1899 UserCommandList_clearTargets (theItem);
1900 }
1901 if (1==iCommand){
1902 if (theItem->gstrCommand){
1903 g_string_free(theItem->gstrCommand, TRUE);
1904 theItem->gstrCommand = NULL;
1905 }
1906 }
1907 if (1==iOptionQuitreply){
1908 if (theItem->option_gstrQuitreply){
1909 g_string_free(theItem->option_gstrQuitreply, TRUE);
1910 theItem->option_gstrQuitreply = NULL;
1911 }
1912 }
1913 if (1==iWorkingDir){
1914 if (theItem->gstrWorkingDir){
1915 g_string_free(theItem->gstrWorkingDir, TRUE);
1916 theItem->gstrWorkingDir = NULL;
1917 }
1918 }
1919
1920 TRACEIT (7, "UserCommandList_deleteItemElement end");
1921 return 0;
1922 }
1923
1924
UserCommandList_addItemAsCopy(struct _UserCommandList ** theList,struct _UserCommandList * theNewItem)1925 int UserCommandList_addItemAsCopy(struct _UserCommandList **theList, struct _UserCommandList *theNewItem){
1926 TRACEIT (7, "UserCommandList_addItemAsCopy start");
1927 //simply adds theNewItem to theList, this will preserve us to copy the whole content of hte list (which holds 2 lists by its own!)
1928 //you can give a second list to 'theNewItem', then, the two lists merge.
1929 //return: -1=error, 0=ok
1930 if (theList == NULL || theNewItem==NULL){
1931 TRACEIT (2, "UserCommandList_addItemAsCopy end, parameter NULL");
1932 return -1;
1933 }
1934
1935 if (*theList==NULL){ //Brand new list, in this case we start one
1936 *theList = theNewItem;
1937 TRACEIT (7, "UserCommandList_addItemAsCopy end, started new list");
1938 return 0;
1939 }
1940
1941 struct _UserCommandList *bufItem = NULL;
1942
1943 bufItem = UserCommandList_getLastItem (*theList);
1944 if (bufItem == NULL){
1945 TRACEIT (2, "UserCommandList_addItemAsCopy error, I cant find the last item from first list");
1946 return -1;
1947 }
1948
1949 theNewItem = UserCommandList_getFirstItem(theNewItem);
1950 if (theNewItem == NULL){
1951 TRACEIT (2, "UserCommandList_addItemAsCopy error, I cant find the last item from second list");
1952 return -1;
1953 }
1954
1955 bufItem->nextItem = theNewItem;
1956 theNewItem->prevItem = bufItem;
1957 //theNewItem->nextItem = NULL; //do not do this, as we may want to add a List with more than one item
1958
1959 TRACEIT (7, "UserCommandList_addItemAsCopy end");
1960 return 0;
1961 }
1962
1963
UserCommandList_getLastItem(struct _UserCommandList * theList)1964 struct _UserCommandList *UserCommandList_getLastItem (struct _UserCommandList *theList){
1965 TRACEIT (7, "UserCommandList_getLastItem start");
1966 //return: NULL:error
1967 if (theList == NULL){
1968 TRACEIT (2, "UserCommandList_getLastItem end, parameter NULL");
1969 return NULL;
1970 }
1971
1972 while (theList->nextItem){
1973 theList = theList->nextItem;
1974 }
1975
1976 TRACEIT (7, "UserCommandList_getLastItem end");
1977 return theList;
1978 }
1979
1980
UserCommandList_getFirstItem(struct _UserCommandList * theList)1981 struct _UserCommandList *UserCommandList_getFirstItem (struct _UserCommandList *theList){
1982 TRACEIT (7, "UserCommandList_getFirstItem start");
1983 //return: NULL:error
1984 if (theList == NULL){
1985 TRACEIT (2, "UserCommandList_getFirstItem end, parameter NULL");
1986 return NULL;
1987 }
1988
1989 while (theList->prevItem){
1990 theList = theList->prevItem;
1991 }
1992
1993 TRACEIT (7, "UserCommandList_getFirstItem end");
1994 return theList;
1995 }
1996
1997
UserCommandList_copyItemToList(struct _UserCommandList ** theList,struct _UserCommandList * NewItem)1998 int UserCommandList_copyItemToList (struct _UserCommandList **theList, struct _UserCommandList *NewItem){
1999 //real copy
2000 //return: -1=error, 0=ok
2001 //gets a Listpointer and a allready existing item (in another list) and copies (this means realy copy, allocating new memory)
2002 //the content of the newItem to the end of theList.
2003 //only one item is copied from NewItem, no matter if this is a list for its own.
2004
2005 if (theList == NULL || NewItem == NULL){
2006 TRACEIT (2, "UserCommandList_copyItemToList end, parameter NULL");
2007 return -1;
2008 }
2009 struct _UserCommandList *buflist = NULL;
2010 GList *glistBuf = NULL;
2011
2012 UserCommandList_addItem ( theList , "UserCommandList_copyItemToList");
2013
2014 buflist = UserCommandList_getLastItem(*theList);
2015 if (buflist == NULL){
2016 TRACEIT (3, "UserCommandList_copyItemToList end, error retrieving last item of list");
2017 return -1;
2018 }
2019
2020 buflist->iValid = NewItem->iValid;
2021 buflist->iIsDefaultCommand = NewItem->iIsDefaultCommand;
2022 if (NewItem->gstrName){
2023 buflist->gstrName = g_string_new(NewItem->gstrName->str);
2024 }
2025 if (NewItem->gstrCommand){
2026 buflist->gstrCommand = g_string_new(NewItem->gstrCommand->str);
2027 }
2028 if (NewItem->gstrDialogCaption){
2029 buflist->gstrDialogCaption = g_string_new(NewItem->gstrDialogCaption->str);
2030 }
2031 if (NewItem->gstrDialogLabel){
2032 buflist->gstrDialogLabel = g_string_new(NewItem->gstrDialogLabel->str);
2033 }
2034 if (NewItem->option_gstrQuitreply){
2035 buflist->option_gstrQuitreply = g_string_new(NewItem->option_gstrQuitreply->str);
2036 }
2037 if (NewItem->option_gstrActionnote){
2038 buflist->option_gstrActionnote = g_string_new(NewItem->option_gstrActionnote->str);
2039 }
2040 if (NewItem->option_gstrCaption){
2041 buflist->option_gstrCaption = g_string_new(NewItem->option_gstrCaption->str);
2042 }
2043 if (NewItem->option_gstrLabel){
2044 buflist->option_gstrLabel = g_string_new(NewItem->option_gstrLabel->str);
2045 }
2046 if (NewItem->gstrWorkingDir){
2047 buflist->gstrWorkingDir = g_string_new(NewItem->gstrWorkingDir->str);
2048 }
2049 buflist->option_iCallType = NewItem->option_iCallType;
2050
2051 if (NewItem->glistTargets){
2052 glistBuf = g_list_first(NewItem->glistTargets);
2053 while (glistBuf){
2054 UserCommandList_editItem(buflist, -1, NULL, ((GString *)(glistBuf->data))->str, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
2055 glistBuf = glistBuf->next;
2056 }
2057 }
2058
2059 struct _DialogEntityList *DialogEntityList = NewItem->DialogEntityList;
2060 struct _DialogEntityList *DialogEntityListBuf = NULL;
2061 while (DialogEntityList){
2062 DialogEntityList_addItem(&(buflist->DialogEntityList), DialogEntityList->iType);
2063 DialogEntityList_editLastItem (buflist->DialogEntityList, -1,
2064 (DialogEntityList->gstrVarIdentifier)?DialogEntityList->gstrVarIdentifier->str:NULL,
2065 (DialogEntityList->gstrLabel)?DialogEntityList->gstrLabel->str:NULL,
2066 DialogEntityList->wdgtLabel,
2067 (DialogEntityList->gstrPredefine)?DialogEntityList->gstrPredefine->str:NULL,
2068 DialogEntityList->wdgtEntryBox,
2069 (DialogEntityList->gstrAdditional1)?DialogEntityList->gstrAdditional1->str:NULL,
2070 (DialogEntityList->gstrAdditional2)?DialogEntityList->gstrAdditional2->str:NULL,
2071 DialogEntityList->wdgtAdditional1);
2072
2073 DialogEntityListBuf = DialogEntityList_getLastItem (buflist->DialogEntityList);
2074 if (DialogEntityListBuf == NULL){
2075 TRACEIT(2, "UserCommandList_copyItemToList unable to retrieve last item of list");
2076 }
2077 else{
2078 DialogEntityListBuf->iValid = DialogEntityList->iValid;
2079 }
2080 DialogEntityList = DialogEntityList->nextItem;
2081 }
2082 return 0;
2083 }
2084
2085
UserCommandList_ItemHasTarget(struct _UserCommandList * theItem,char * cpTarget)2086 gboolean UserCommandList_ItemHasTarget (struct _UserCommandList *theItem, char *cpTarget){
2087 //returns TRUE if theItem has the target cpTarget
2088 //otherwise FALSE is returned
2089
2090 if (theItem == NULL || cpTarget == NULL){
2091 TRACEIT (2, "UserCommandList_ItemHasTarget end, Parameter NULL");
2092 return FALSE;
2093 }
2094 gboolean bRet = FALSE;
2095
2096 char *cpDownString1 = NULL;
2097 char *cpDownString2 = NULL;
2098
2099 GList *gListBuf = g_list_first (theItem->glistTargets);
2100 while (gListBuf){
2101 cpDownString1 = g_ascii_strdown ( ((GString *)(gListBuf->data))->str, strlen(((GString *)(gListBuf->data))->str));
2102 cpDownString2 = g_ascii_strdown (cpTarget, strlen(cpTarget));
2103 if ( cpDownString1!=NULL && cpDownString2!=NULL && 0==strcmp( cpDownString1, cpDownString2)) {
2104 if (cpDownString1)
2105 g_free(cpDownString1);
2106 if (cpDownString2)
2107 g_free(cpDownString2);
2108 bRet = TRUE;
2109 break;
2110 }
2111 if (cpDownString1)
2112 g_free(cpDownString1);
2113 if (cpDownString2)
2114 g_free(cpDownString2);
2115 gListBuf = gListBuf->next;
2116 }
2117 return bRet;
2118 }
2119
2120
UserCommandList_getCommandsForTarget(struct _UserCommandList * theWholeList,char * cpTarget)2121 GList *UserCommandList_getCommandsForTarget (struct _UserCommandList *theWholeList, char *cpTarget){
2122 TRACEIT (7, "UserCommandList_getCommandsForTarget start");
2123 //return: NULL=error
2124 //searches the listitems in theWholeList for their targets to equal cpTarget and creates a new GList
2125 //which stores the pointer to the listitems matching.
2126 //YOU HAVE TO FREE THIS LIST SEPERATLY, but not their userdata, as they are the pointer from the other list, use 'g_list_free(LIST)'
2127
2128 GList *glistItems = NULL;
2129 struct _UserCommandList *bufList = NULL;
2130 GList *gListBuf = NULL;
2131
2132 if (theWholeList == NULL || cpTarget == NULL){
2133 TRACEIT(2, "UserCommandList_getCommandsForTarget end, Parameter NULL");
2134 return NULL;
2135 }
2136
2137 bufList = UserCommandList_getFirstItem(theWholeList);
2138 if (bufList == NULL){
2139 TRACEIT(2, "UserCommandList_getCommandsForTarget end, could not get first item of list");
2140 return NULL;
2141 }
2142
2143 while (bufList){
2144 gListBuf = g_list_first (bufList->glistTargets);
2145 while (gListBuf){
2146 if ( 0==strcmp( ((GString *)(gListBuf->data))->str, cpTarget)) {
2147 //UserCommandList_copyItemToList (&NewList, bufList);
2148 glistItems = g_list_append (glistItems, (void *)bufList);
2149 }
2150 gListBuf = gListBuf->next;
2151 }
2152 bufList = bufList->nextItem;
2153 }
2154 TRACEIT (7, "UserCommandList_getCommandsForTarget end");
2155 return glistItems;
2156 }
2157
2158
DialogEntityList_addItem(struct _DialogEntityList ** theList,int iType)2159 int DialogEntityList_addItem(struct _DialogEntityList **theList, int iType){
2160 TRACEIT (7, "DialogEntityList_addItem start");
2161 //if iType == -1, its unknown
2162 //return: -1=error, 0=ok
2163 if (theList == NULL){
2164 TRACEIT (2, "DialogEntityList_addItem end, parameter NULL");
2165 return -1;
2166 }
2167
2168 struct _DialogEntityList *newItem = malloc (sizeof (struct _DialogEntityList));
2169 struct _DialogEntityList *bufItem = NULL;
2170 if (newItem == NULL){
2171 TRACEIT (2, "DialogEntityList_addItem Could not allocate memory");
2172 return -1;
2173 }
2174
2175 //default values for member
2176 newItem->iType = iType;
2177 newItem->iValid = 0;
2178 newItem->gstrVarIdentifier = NULL;
2179 newItem->gstrVarValue = NULL;
2180 newItem->gstrLabel = NULL;
2181 newItem->wdgtLabel = NULL;
2182 newItem->gstrPredefine = NULL;
2183 newItem->wdgtEntryBox = NULL;
2184 newItem->gstrAdditional1 = NULL;
2185 newItem->gstrAdditional2 = NULL;
2186 newItem->wdgtAdditional1 = NULL;
2187 newItem->wdgtAdditional2 = NULL;
2188
2189 newItem->nextItem = NULL;
2190 newItem->prevItem = NULL;
2191
2192 //store the new item
2193 if (*theList == NULL){ //brand new list
2194 *theList = newItem;
2195 }
2196 else{
2197 bufItem = DialogEntityList_getLastItem (*theList);
2198 if (bufItem == NULL){
2199 TRACEIT (2, "DialogEntityList_addItem error, its no new list, but I also cant find the last item");
2200 free(newItem);
2201 return -1;
2202 }
2203
2204 bufItem->nextItem = newItem;
2205 newItem->prevItem = bufItem;
2206 }
2207
2208 TRACEIT (7, "DialogEntityList_addItem end");
2209 return 0;
2210 }
2211
2212
DialogEntityList_freeList(struct _DialogEntityList ** theList)2213 int DialogEntityList_freeList(struct _DialogEntityList **theList){
2214 TRACEIT (7, "DialogEntityList_freeList start");
2215 if (theList == NULL){
2216 TRACEIT (2, "DialogEntityList_freeList end, parameter NULL");
2217 return -1;
2218 }
2219
2220 struct _DialogEntityList *firstItem=DialogEntityList_getFirstItem(*theList);
2221 struct _DialogEntityList *bufItem=firstItem;
2222
2223 if (firstItem == NULL){
2224 TRACEIT (2, "DialogEntityList_freeList end, could not get first item in list");
2225 return -1;
2226 }
2227
2228 while (bufItem){
2229 if (bufItem->gstrVarIdentifier){
2230 g_string_free(bufItem->gstrVarIdentifier, TRUE);
2231 }
2232 if (bufItem->gstrVarValue){
2233 g_string_free(bufItem->gstrVarValue, TRUE);
2234 }
2235 if (bufItem->gstrLabel){
2236 g_string_free(bufItem->gstrLabel, TRUE);
2237 }
2238 if (bufItem->gstrPredefine){
2239 g_string_free(bufItem->gstrPredefine, TRUE);
2240 }
2241 if (bufItem->gstrAdditional1){
2242 g_string_free(bufItem->gstrAdditional1, TRUE);
2243 }
2244 if (bufItem->gstrAdditional2){
2245 g_string_free(bufItem->gstrAdditional2, TRUE);
2246 }
2247 if (bufItem->wdgtLabel){
2248 g_object_unref(bufItem->wdgtLabel);
2249 }
2250 if (bufItem->wdgtEntryBox){
2251 g_object_unref(bufItem->wdgtEntryBox);
2252 }
2253 if (bufItem->wdgtAdditional1){
2254 g_object_unref(bufItem->wdgtAdditional1);
2255 }
2256 if (bufItem->wdgtAdditional2){
2257 g_object_unref(bufItem->wdgtAdditional2);
2258 }
2259
2260 firstItem = bufItem->nextItem;
2261 free(bufItem);
2262 bufItem = firstItem;
2263 }
2264 *theList = NULL;
2265
2266 TRACEIT (7, "DialogEntityList_freeList end");
2267 return 0;
2268 }
2269
2270
DialogEntityList_editItem(struct _DialogEntityList * theItem,int iType,char * cpVarID,char * cpLabel,GtkWidget * wdgtLabel,char * cpPredefine,GtkWidget * wdgtEntryBox,char * cpAdd1,char * cpAdd2,GtkWidget * wdgtAdd1)2271 int DialogEntityList_editItem(struct _DialogEntityList *theItem, int iType, char *cpVarID, char *cpLabel, GtkWidget *wdgtLabel, char *cpPredefine, GtkWidget *wdgtEntryBox, char *cpAdd1, char *cpAdd2, GtkWidget *wdgtAdd1 ){
2272 TRACEIT (7, "DialogEntityList_editItem start");
2273 //return: -1=error, 0=ok
2274 //changes the content of the given item
2275
2276 if (theItem == NULL){
2277 TRACEIT(2, "DialogEntityList_editItem end, parameter NULL");
2278 return -1;
2279 }
2280
2281
2282 if (iType != -1){
2283 theItem->iType = iType;
2284 }
2285 if (cpVarID){
2286 if (theItem->gstrVarIdentifier){
2287 g_string_assign(theItem->gstrVarIdentifier, cpVarID);
2288 }
2289 else{
2290 theItem->gstrVarIdentifier = g_string_new(cpVarID);
2291 }
2292 }
2293 if (cpLabel){
2294 if (theItem->gstrLabel){
2295 g_string_assign(theItem->gstrLabel, cpLabel);
2296 }
2297 else{
2298 theItem->gstrLabel = g_string_new(cpLabel);
2299 }
2300 }
2301 if (cpPredefine){
2302 if (theItem->gstrPredefine){
2303 g_string_assign(theItem->gstrPredefine, cpPredefine);
2304 }
2305 else{
2306 theItem->gstrPredefine = g_string_new(cpPredefine);
2307 }
2308 }
2309 if (cpAdd1){
2310 if (theItem->gstrAdditional1){
2311 g_string_assign(theItem->gstrAdditional1, cpAdd1);
2312 }
2313 else{
2314 theItem->gstrAdditional1 = g_string_new(cpAdd1);
2315 }
2316 }
2317 if (cpAdd2){
2318 if (theItem->gstrAdditional2){
2319 g_string_assign(theItem->gstrAdditional2, cpAdd2);
2320 }
2321 else{
2322 theItem->gstrAdditional2 = g_string_new(cpAdd2);
2323 }
2324 }
2325 if (wdgtLabel){
2326 if (theItem->wdgtLabel){
2327 g_object_unref(theItem->wdgtLabel);
2328 }
2329 theItem->wdgtLabel = wdgtLabel;
2330 }
2331 if (wdgtEntryBox){
2332 if (theItem->wdgtEntryBox){
2333 g_object_unref(theItem->wdgtEntryBox);
2334 }
2335 theItem->wdgtEntryBox = wdgtEntryBox;
2336 }
2337 if (wdgtAdd1){
2338 if (theItem->wdgtAdditional1){
2339 g_object_unref(theItem->wdgtAdditional1);
2340 }
2341 theItem->wdgtAdditional1 = wdgtAdd1;
2342 }
2343
2344 TRACEIT (7, "DialogEntityList_editItem end");
2345 return 0;
2346 }
2347
2348
DialogEntityList_editLastItem(struct _DialogEntityList * theList,int iType,char * cpVarID,char * cpLabel,GtkWidget * wdgtLabel,char * cpPredefine,GtkWidget * wdggtEntryBox,char * cpAdd1,char * cpAdd2,GtkWidget * wdgtAdd1)2349 int DialogEntityList_editLastItem(struct _DialogEntityList *theList, int iType, char *cpVarID, char *cpLabel, GtkWidget *wdgtLabel, char *cpPredefine, GtkWidget *wdggtEntryBox, char *cpAdd1, char *cpAdd2, GtkWidget *wdgtAdd1 ){
2350 TRACEIT (7, "DialogEntityList_editLastItem start");
2351 //return: -1=error, 0=ok
2352 //searches the last item in the list and changes its content
2353
2354 if (theList == NULL){
2355 TRACEIT(2, "DialogEntityList_editItem end, parameter NULL");
2356 return -1;
2357 }
2358 struct _DialogEntityList *bufItem = DialogEntityList_getLastItem(theList);
2359
2360 DialogEntityList_editItem(bufItem, iType, cpVarID, cpLabel, wdgtLabel, cpPredefine, wdggtEntryBox, cpAdd1, cpAdd2, wdgtAdd1);
2361
2362 TRACEIT (7, "DialogEntityList_editLastItem end");
2363 return 0;
2364
2365 }
2366
2367
DialogEntityList_getLastItem(struct _DialogEntityList * theList)2368 struct _DialogEntityList *DialogEntityList_getLastItem(struct _DialogEntityList *theList){
2369 TRACEIT (7, "DialogEntityList_getLastItem start");
2370 //return: NULL:error
2371 if (theList == NULL){
2372 TRACEIT (2, "DialogEntityList_getLastItem end, parameter NULL");
2373 return NULL;
2374 }
2375
2376 while (theList->nextItem){
2377 theList = theList->nextItem;
2378 }
2379
2380 TRACEIT (7, "DialogEntityList_getLastItem end");
2381 return theList;
2382 }
2383
2384
DialogEntityList_getFirstItem(struct _DialogEntityList * theList)2385 struct _DialogEntityList *DialogEntityList_getFirstItem(struct _DialogEntityList *theList){
2386 TRACEIT (7, "DialogEntityList_getFirstItem start");
2387 //return: NULL:error
2388 if (theList == NULL){
2389 TRACEIT (2, "DialogEntityList_getLastItem end, parameter NULL");
2390 return NULL;
2391 }
2392
2393 while (theList->prevItem){
2394 theList = theList->prevItem;
2395 }
2396
2397 TRACEIT (7, "DialogEntityList_getFirstItem end");
2398 return theList;
2399 }
2400
2401
XMLRelation_updateByElement(struct _Items_XML_Relation * relation,const char * cpElement,gboolean bStartEnd,gboolean bMakeItThreadSave)2402 int XMLRelation_updateByElement(struct _Items_XML_Relation *relation, const char *cpElement, gboolean bStartEnd, gboolean bMakeItThreadSave){
2403 TRACEIT (7, "XMLRelation_updateByElement start");
2404 //updates the relation bools in respect to cpElement and bStartEnd
2405 //if bStartEnd is true, its starting, new value of relation bool is TRUE, otherwise its FALSE
2406 //return: -1=error, 0=notfound, 1=found/updated, ////// NO::::2=unknown state, but bools are valid again
2407 if (relation == NULL || cpElement == NULL){
2408 TRACEIT (2, "XMLRelation_updateByElement end, Parameter NULL");
2409 return -1;
2410 }
2411 int ret = 1;
2412
2413 struct _OptionsList *KeyWords = NULL;
2414
2415 //printf("XMLRelation_updateByElement: relationPointer: %p", relation);
2416 //when we are in end-mode, the keyword may not be known. (Indeed, our function is not made for end-mode operation but only for start-mode)
2417 //end mode operation is much work, as any of the keywords can end without closing one of the items opened in between.
2418 //so we skipp this tests in case we are in end-mode
2419 if (bStartEnd == TRUE){
2420 KeyWords = XMLParser_getValidKeyWordsForState(relation);
2421 if (KeyWords == NULL){
2422 TRACEIT (4, "XMLRelation_updateByElement end, context error:");
2423 TRACEIT (4, cpElement);
2424 /*
2425 if (relation == NULL){
2426 printf("WHY DIDNT I GOT AN ERROR?\n");
2427 }else{
2428 printf("relation = %d\n",relation->iRelation);
2429 }*/
2430 return 0;
2431 }
2432 if ( NULL == OptionsList_getItemByName (KeyWords, cpElement) ){
2433 TRACEIT (4, "XMLRelation_updateByElement end, element name not known in this context:");
2434 TRACEIT (4, cpElement);
2435 OptionsList_freeList(&KeyWords);
2436 return 0;
2437 }
2438 }
2439
2440 gboolean *theBoolToChange = NULL;
2441
2442 //we do not need to check all circumstances as we allready made sure the new element name is available in the current relation.
2443 //all we have to do is to change the value of the right bool:
2444
2445 if (0 == strcmp ("CatsEyE", cpElement)){
2446 theBoolToChange = &(relation->bCatsEyEBlock);
2447 }
2448 else if (0 == strcmp ("CatsEyEBookmarks", cpElement)){
2449 theBoolToChange = &(relation->bCatsEyEBookMarksBlock);
2450 }
2451 else if (0 == strcmp ("CatsEyEOptions", cpElement)){
2452 theBoolToChange = &(relation->bCatsEyEOptionsBlock);
2453 }
2454 else if (0 == strcmp ("CatsEyEUsercommands", cpElement)){
2455 theBoolToChange = &(relation->bCatsEyEUserCommandsBlock);
2456 }
2457 else if (0 == strcmp ("Option", cpElement)){
2458 theBoolToChange = &(relation->bOptionBlock);
2459 }
2460 else if (0 == strcmp ("ID", cpElement)){
2461 theBoolToChange = &(relation->bIDBlock);
2462 }
2463 else if (0 == strcmp ("Name", cpElement)){
2464 theBoolToChange = &(relation->bNameBlock);
2465 }
2466 else if (0 == strcmp ("Value", cpElement)){
2467 theBoolToChange = &(relation->bValueBlock);
2468 }
2469 else if (0 == strcmp ("Usercommand", cpElement)){
2470 theBoolToChange = &(relation->bUserCommandBlock);
2471 }
2472 else if (0 == strcmp ("Object", cpElement)){
2473 theBoolToChange = &(relation->bObjectBlock);
2474 }
2475
2476 if (theBoolToChange != NULL){
2477 if (*theBoolToChange == bStartEnd){
2478 TRACEIT (4, "XMLRelation_updateByNewElement Trying to enter relation we are allready in (enter or leave):");
2479 TRACEIT (4, cpElement);
2480 }
2481 *theBoolToChange = bStartEnd;
2482 }
2483
2484 XMLRelation_accumulateRelations(relation);
2485
2486 //now we check if the current state is valid
2487 //int iValid = 0;
2488
2489 if ( ( 0 ) == relation->iRelation ||
2490 ( 2 ) == relation->iRelation ||
2491 ( 2 + 4 ) == relation->iRelation ||
2492 ( 2 + 4 + 128 ) == relation->iRelation ||
2493 ( 2 + 4 + 128 + 256 ) == relation->iRelation ||
2494 ( 2 + 4 + 128 + 512 ) == relation->iRelation ||
2495 ( 2 + 4 + 128 + 1024 ) == relation->iRelation ||
2496 ( 2 + 8 ) == relation->iRelation ||
2497 ( 2 + 8 + 128 ) == relation->iRelation ||
2498 ( 2 + 8 + 128 + 256 ) == relation->iRelation ||
2499 ( 2 + 8 + 128 + 512 ) == relation->iRelation ||
2500 ( 2 + 8 + 128 + 1024 ) == relation->iRelation ||
2501 ( 2 + 16 ) == relation->iRelation ||
2502 ( 2 + 16 + 32 ) == relation->iRelation ||
2503 ( 2 + 16 + 32 + 64) == relation->iRelation ||
2504 ( 2 + 16 + 32 + 64 + 128 ) == relation->iRelation ||
2505 ( 2 + 16 + 32 + 64 + 128 + 256 ) == relation->iRelation ||
2506 ( 2 + 16 + 32 + 64 + 128 + 512 ) == relation->iRelation ||
2507 ( 2 + 16 + 32 + 64 + 128 + 1024 ) == relation->iRelation ||
2508 ( 2 + 16 + 32 + 128) == relation->iRelation ||
2509 ( 2 + 16 + 32 + 128 + 256 ) == relation->iRelation ||
2510 ( 2 + 16 + 32 + 128 + 512 ) == relation->iRelation ||
2511 ( 2 + 16 + 32 + 128 + 1024 ) == relation->iRelation
2512 ){
2513 relation->bUnKnownBlock = FALSE;
2514 ret=1; //everything is fine
2515 }
2516 else{
2517 relation->bUnKnownBlock = TRUE;
2518 ret=2; //errorcode for block error
2519 }
2520
2521 /*
2522 //now, if the relation is not valid, we make it valid.
2523 //e.g. when we expect closing some option block but the file closed the command block or even the catseye block
2524 //before, we have to close the optionsblock - bool and all others too.
2525 if (relation->bUnKnownBlock == FALSE){
2526
2527 }
2528 */
2529
2530 XMLRelation_accumulateRelations(relation);
2531 if (KeyWords){
2532 OptionsList_freeList(&KeyWords);
2533 }
2534
2535 TRACEIT (7, "XMLRelation_updateByElement end");
2536 return 1;
2537 }
2538
2539
XMLParser_foundStart(GMarkupParseContext * context,const gchar * element_name,const gchar ** attribute_names,const gchar ** attribute_values,gpointer data,GError ** error)2540 void XMLParser_foundStart (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error){
2541 TRACEIT (7, "XMLParser_foundStart start");
2542 struct _Parser_Mode_Struct *info = (struct _Parser_Mode_Struct *)data;
2543 if (info == NULL){
2544 TRACEIT (2, "XMLParser_foundStart end, Parameter NULL");
2545 return;
2546 }
2547
2548 struct _Items_XML_Relation *relation = (struct _Items_XML_Relation *)info->relation;
2549 if (info->relation==NULL || relation==NULL){
2550 TRACEIT (2, "XMLParser_foundStart end, Parameter 2 NULL");
2551 return;
2552 }
2553
2554 //is the element name valid in our current relation?
2555 if (1!=XMLRelation_updateByElement (relation, element_name, TRUE, info->bMakeItThreadSave)){
2556 TRACEIT (4, "XMLParser_foundStart end, error while parsing configfile");
2557 return;
2558 }
2559 //printf("foundstart: name: %s\n",element_name);
2560 //store the attributes to the info structm this is used in UserCommand part, where the <Object> Block has a type attribute to identify the object e.g. as question
2561 info->cppAttributeValues = attribute_values;
2562 info->cppAttributeNames = attribute_names;
2563
2564 //the rest is done within this notification functions
2565 //but we have to set them first in order to the mode we are in
2566 if (info->functionStartNotification != NULL){
2567 info->functionStartNotification = NULL;
2568 }
2569
2570 if ( relation->iRelation & (4) ){ //bookmarks block
2571 info->functionStartNotification = Options_FoundStartCallback;
2572 info->iCurrentListType = CONFIGFILE_LOAD_BOOKMARKS;
2573 info->storageList = (void *)&g_BookMarkList;
2574 }
2575 else if ( relation->iRelation & (8) ){ //options block
2576 info->functionStartNotification = Options_FoundStartCallback;
2577 info->iCurrentListType = CONFIGFILE_LOAD_OPTIONS;
2578 info->storageList = (void *)&g_OptionsList;
2579 }
2580 else if ( relation->iRelation & (16) ){ //usercommands block
2581 info->functionStartNotification = Usercommand_FoundStartCallback;
2582 info->iCurrentListType = CONFIGFILE_LOAD_USERCOMMANDS;
2583 info->storageList = (void *)&g_UserCommandList;
2584 }
2585
2586 if (NULL != info->functionStartNotification){
2587 info->functionStartNotification( info );
2588 }
2589
2590 //MyMessageWidget(NULL,"XMLParser_foundStart",(char *)element_name);
2591
2592 TRACEIT (7, "XMLParser_foundStart end");
2593 return;
2594 }
2595
2596
XMLParser_foundEnd(GMarkupParseContext * context,const gchar * element_name,gpointer data,GError ** error)2597 void XMLParser_foundEnd (GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error){
2598 TRACEIT (7, "XMLParser_foundEnd start");
2599 //struct AllInformationAllUseStruct *info = (struct AllInformationAllUseStruct *)data;
2600 struct _Parser_Mode_Struct *info = (struct _Parser_Mode_Struct *)data;
2601 if (info == NULL){
2602 TRACEIT (2, "XMLParser_foundEnd end, Parameter NULL");
2603 return;
2604 }
2605 struct _Items_XML_Relation *relation = info->relation;
2606 if ( info->relation==NULL){
2607 TRACEIT (2, "XMLParser_foundEnd end, Parameter 2 NULL");
2608 return;
2609 }
2610
2611 //now we can update the relation
2612 if (1!=XMLRelation_updateByElement (relation, element_name, FALSE, info->bMakeItThreadSave)){
2613 TRACEIT (4, "XMLParser_foundEnd end, error while parsing configfile");
2614 return;
2615 }
2616 //printf("foundEnd: name: %s\n",element_name);
2617 //Now the end-function can handle the new state
2618 //but we have to set them first in order to the mode we are in
2619 if (info->functionStopNotification != NULL){
2620 info->functionStopNotification = NULL;
2621 }
2622
2623 if ( relation->iRelation & (4) ){ //bookmarks block
2624 info->functionStopNotification = Options_FoundEndCallback;
2625 }
2626 else if ( relation->iRelation & (8) ){ //options block
2627 info->functionStopNotification = Options_FoundEndCallback;
2628 }
2629 else if ( relation->iRelation & (16) ){ //usercommands block
2630 info->functionStopNotification = Usercommand_FoundEndCallback;
2631 }
2632 else{
2633 info->iCurrentListType = CONFIGFILE_LOAD_NOTHING;
2634 freeRelicts(info);
2635 info->storageList = NULL;
2636 }
2637
2638 if (NULL != info->functionStopNotification){
2639 info->functionStopNotification( info, element_name );
2640 }
2641
2642 //MyMessageWidget(NULL,"XMLParser_foundEnd",(char *)element_name);
2643
2644 TRACEIT (7, "XMLParser_foundEnd end");
2645 return;
2646 }
2647
2648
XMLParser_foundText(GMarkupParseContext * context,const gchar * text,gsize text_len,gpointer data,GError ** error)2649 void XMLParser_foundText (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer data, GError **error){
2650 TRACEIT (7, "XMLParser_foundText start");
2651 if (text_len < 1){
2652 TRACEIT (6, "XMLParser_foundText end, no text found, why we are here?");
2653 return;
2654 }
2655
2656 struct _Parser_Mode_Struct *info = (struct _Parser_Mode_Struct *)data;
2657 if (info == NULL){
2658 TRACEIT (2, "XMLParser_foundText end, Parameter NULL");
2659 return;
2660 }
2661
2662 struct _Items_XML_Relation *relation = (struct _Items_XML_Relation *)info->relation;
2663 if ( info->relation==NULL){
2664 TRACEIT (2, "XMLParser_foundText end, Parameter 2 NULL");
2665 return;
2666 }
2667
2668 char *buf = malloc(sizeof(char) * (text_len+2));
2669 memcpy(buf, text, text_len);
2670 buf[text_len]='\0';
2671 //printf("foundText: text: %s\n",buf);
2672 //char buf2[1500];
2673 //sprintf(buf2, "textlen=%d\ntext=%s",text_len,buf);
2674
2675 //MyMessageWidget(NULL,"foundtext",buf2);
2676
2677 //Now the text-function can handle the new state
2678 //but we have to set them first in order to the mode we are in
2679 if (info->functionTextNotification != NULL){
2680 info->functionTextNotification = NULL;
2681 }
2682
2683 if ( relation->iRelation & (4) ){ //bookmarks block
2684 info->functionTextNotification = Options_FoundTextCallback;
2685 }
2686 else if ( relation->iRelation & (8) ){ //options block
2687 info->functionTextNotification = Options_FoundTextCallback;
2688 }
2689 else if ( relation->iRelation & (16) ){ //usercommands block
2690 info->functionTextNotification = Options_FoundTextCallback;
2691 }
2692
2693 if (NULL != info->functionTextNotification){
2694 info->functionTextNotification( info, buf );
2695 }
2696
2697 free(buf);
2698
2699 TRACEIT (7, "XMLParser_foundText end");
2700 }
2701
2702
XMLParser_ParseFileFile(struct myFiles_struct * myFilestru,struct _Parser_Mode_Struct * modeStruct,gboolean bMakeItThreadSave)2703 int XMLParser_ParseFileFile (struct myFiles_struct *myFilestru, struct _Parser_Mode_Struct *modeStruct, gboolean bMakeItThreadSave){
2704 TRACEIT (7, "XMLParser_ParseFileFile start");
2705 //myFiles_struct has to be an opened filepointer.
2706 //the file has to be xml style, we do not manipulate the filepointer before sending lines to the parser.
2707 //this means we DO NOT rewind the filepointer.
2708 //return: 0=ok, -1=error
2709 if (myFilestru==NULL || myFilestru->File == NULL){
2710 TRACEIT (2, "XMLParser_ParseFileFile end, PARAMETER NULL");
2711 return -1;
2712 }
2713 if (modeStruct==NULL || modeStruct->relation==NULL){
2714 TRACEIT (2, "XMLParser_ParseFileFile end, PARAMETER 2 NULL");
2715 return -1;
2716 }
2717
2718 GString *gstrBuf=g_string_sized_new(10);
2719
2720 //fill the parser struct.
2721 GMarkupParser Parser;
2722 Parser.start_element = XMLParser_foundStart;
2723 Parser.end_element = XMLParser_foundEnd;
2724 Parser.text = XMLParser_foundText;
2725 Parser.passthrough = NULL;
2726 Parser.error = NULL;
2727 GError *err=NULL;
2728
2729 //create parser
2730 GMarkupParseContext *cont = g_markup_parse_context_new (&Parser, 0, (void *)modeStruct, NULL); //G_MARKUP_TREAT_CDATA_AS_TEXT
2731
2732 //lets start parsing
2733 char line[5001];
2734 while ( NULL != fgets(line, 5000, myFilestru->File)){
2735 if (FALSE == g_markup_parse_context_parse (cont, line, strlen(line), &err)){
2736 g_string_printf(gstrBuf, "Error parsing configfile:\n %s\n\nError:\n%d\t%s", myFilestru->gstrFileName->str, err->code, err->message);
2737 if (bMakeItThreadSave == TRUE)
2738 myWrap_gdk_threads_enter("XMLParser_ParseFileFile 2");
2739
2740 MyMessageWidget(NULL, "Parser Error", gstrBuf->str);
2741
2742 if (bMakeItThreadSave == TRUE)
2743 myWrap_gdk_threads_leave("XMLParser_ParseFileFile 2");
2744
2745 TRACEIT (5, "XMLParser_ParseFileFile Error parsing configfile:");
2746 TRACEIT (5, gstrBuf->str);
2747 break;
2748 }
2749 //debugOut_PrintLists();
2750 }
2751
2752 g_markup_parse_context_free (cont);
2753 g_string_free(gstrBuf, TRUE);
2754
2755 TRACEIT (7, "XMLParser_ParseFileFile end");
2756 return 0;
2757 }
2758
2759
Options_CreateDefaultList()2760 int Options_CreateDefaultList (){
2761 TRACEIT (7, "Options_CreateDefaultList start");
2762
2763 GString *gstrBuf = g_string_sized_new(20);
2764 getHomeDirectory(gstrBuf);
2765
2766 if (g_OptionsList != NULL){
2767 OptionsList_freeList (&g_OptionsList);
2768 }
2769
2770 OptionsList_addItem(&g_OptionsList, STANDARDSTARTDIRECTORY, NULL, gstrBuf->str);
2771 OptionsList_addItem(&g_OptionsList, COLOR_ITEMS_DEFAULT, NULL, DEFAULT_COLOR_ITEMS_DEFAULT);
2772 OptionsList_addItem(&g_OptionsList, COLOR_DIRECTORIES, NULL, DEFAULT_COLOR_DIRECTORIES);
2773 OptionsList_addItem(&g_OptionsList, COLOR_LINKS, NULL, DEFAULT_COLOR_LINKS);
2774 OptionsList_addItem(&g_OptionsList, COLOR_ITEMS_MISSING, NULL, DEFAULT_COLOR_ITEMS_MISSING);
2775
2776 g_string_free(gstrBuf, TRUE);
2777
2778 TRACEIT (7, "Options_CreateDefaultList end");
2779 return 0;
2780 }
2781
2782
OptionsList_getItemByName(struct _OptionsList * OptionsList,const char * cpName)2783 struct _OptionsList *OptionsList_getItemByName(struct _OptionsList *OptionsList, const char *cpName){
2784 TRACEIT (7, "OptionsList_getItemByName start");
2785 //return NULL=error, not found, or pointer to listitem
2786 if (OptionsList == NULL || cpName == NULL){
2787 TRACEIT (2, "OptionsList_getItemByName end, Parameter NULL");
2788 return NULL;
2789 }
2790
2791 struct _OptionsList *bufList = OptionsList_getFirstItem(OptionsList);
2792
2793 while (bufList){
2794 if (bufList->gstrName){
2795 if (0 == strcmp(bufList->gstrName->str, cpName)){
2796 return bufList;
2797 }
2798 }
2799 bufList = bufList->nextItem;
2800 }
2801
2802 TRACEIT (7, "OptionsList_getItemByName end");
2803 return NULL;
2804 }
2805
2806
OptionsList_getItemByID(struct _OptionsList * OptionsList,const char * cpID)2807 struct _OptionsList *OptionsList_getItemByID(struct _OptionsList *OptionsList, const char *cpID){
2808 TRACEIT (7, "OptionsList_getItemByID start");
2809 //return NULL=error, not found, or pointer to listitem
2810 if (OptionsList == NULL || cpID == NULL){
2811 TRACEIT (2, "OptionsList_getItemByID end, Parameter NULL");
2812 return NULL;
2813 }
2814
2815 struct _OptionsList *bufList = OptionsList_getFirstItem(OptionsList);
2816
2817 while (bufList){
2818 if (bufList->gstrID){
2819 if (0 == strcmp(bufList->gstrID->str, cpID)){
2820 return bufList;
2821 }
2822 }
2823 bufList = bufList->nextItem;
2824 }
2825
2826 TRACEIT (7, "OptionsList_getItemByID end");
2827 return NULL;
2828 }
2829
2830
OptionsList_getValueAndNextItemByID(struct _OptionsList * StartItem,struct _OptionsList ** NextItem,const char * cpID)2831 const char *OptionsList_getValueAndNextItemByID (struct _OptionsList *StartItem, struct _OptionsList **NextItem, const char *cpID){
2832 TRACEIT (7, "OptionsList_getValueAndNextItemByID start");
2833 //returns the value of the first item in StartItem list with ID cpID
2834 //and sets NextItem to the next item which has the same ID
2835 //example
2836 //if StartItem has cpID, it returns StartItems value, then searches for the next occurence of ID staring with the item next to StartItem
2837 //and writes its adress to NextItem
2838 //so, you can use NextItem as StartItem for future calls to this function and get one value after another
2839 //if StartItem does not if cpID, it searches for the first occurence of cpID in the list, returns its value, searches for the next occurence
2840 //and writes this pointer to NextItem
2841 if (StartItem == NULL || cpID == NULL || NextItem==NULL){
2842 TRACEIT (2, "OptionsList_getValueAndNextItemByID end, Parameter NULL");
2843 return NULL;
2844 }
2845
2846 *NextItem = NULL;
2847 const char *ccpBuf = NULL;
2848 //search first occurence of cpID
2849 while (StartItem){
2850 if (StartItem->gstrID){
2851 if (0 == strcmp(StartItem->gstrID->str, cpID)){
2852 if (StartItem->gstrValue){
2853 ccpBuf = (const char *)StartItem->gstrValue->str;
2854 break;
2855 }
2856 }
2857 }
2858 StartItem = StartItem->nextItem;
2859 }
2860
2861 //search for the next cpID item
2862 if (StartItem){
2863 StartItem = StartItem->nextItem;
2864 while (StartItem){
2865 if (StartItem->gstrID){
2866 if (0 == strcmp(StartItem->gstrID->str, cpID)){
2867 *NextItem = StartItem;
2868 break;
2869 }
2870 }
2871 StartItem = StartItem->nextItem;
2872 }
2873 }
2874
2875 TRACEIT (7, "OptionsList_getValueAndNextItemByID end");
2876 return ccpBuf;
2877 }
2878
2879
OptionsList_getNameByID(struct _OptionsList * OptionsList,const char * cpID)2880 const char *OptionsList_getNameByID (struct _OptionsList *OptionsList, const char *cpID){
2881 TRACEIT (7, "OptionsList_getNameByID start");
2882 //return NULL=error, not found, or pointer to listitem
2883 if (cpID == NULL){
2884 TRACEIT (2, "OptionsList_getNameByID end, Parameter cpID NULL");
2885 return NULL;
2886 }
2887 if (OptionsList == NULL){
2888 TRACEIT (6, "OptionsList_getNameByID end, Parameter OptionsList NULL, no configfile found?");
2889 return NULL;
2890 }
2891
2892 struct _OptionsList *bufList = OptionsList_getFirstItem(OptionsList);
2893
2894 while (bufList){
2895 if (bufList->gstrID){
2896 if (0 == strcmp(bufList->gstrID->str, cpID)){
2897 if (bufList->gstrName){
2898 TRACEIT (7, "OptionsList_getNameByID end");
2899 return (const char *)bufList->gstrName->str;
2900 }
2901 else{
2902 TRACEIT (6, "OptionsList_getNameByID end, value not set");
2903 return NULL;
2904 }
2905 }
2906 }
2907 bufList = bufList->nextItem;
2908 }
2909
2910 TRACEIT (7, "OptionsList_getNameByID end not found");
2911 return NULL;
2912 }
2913
2914
OptionsList_GetIntValueByID(struct _OptionsList * OptionsList,const char * cpID,int iDefault)2915 int OptionsList_GetIntValueByID (struct _OptionsList *OptionsList, const char *cpID, int iDefault){
2916 TRACEIT (10, "OptionsList_GetIntValueByID start");
2917 if (OptionsList == NULL || cpID == NULL){
2918 TRACEIT (2, "OptionsList_GetIntValueByID Parameter NULL");
2919 return iDefault;
2920 }
2921
2922 const char *ccpValue = NULL;
2923 int iValue = iDefault;
2924 ccpValue = OptionsList_getValueByID (OptionsList, cpID);
2925 if (ccpValue != NULL){
2926 sscanf (ccpValue, "%d", &iValue);
2927 }
2928
2929 TRACEIT (10, "OptionsList_GetIntValueByID end");
2930 return iValue;
2931 }
2932
2933
OptionsList_getValueByID(struct _OptionsList * OptionsList,const char * cpID)2934 const char *OptionsList_getValueByID (struct _OptionsList *OptionsList, const char *cpID){
2935 TRACEIT (7, "OptionsList_getValueByID start");
2936 //return NULL=error, not found, or pointer to listitem
2937 if (cpID == NULL){
2938 TRACEIT (2, "OptionsList_getValueByID end, Parameter cpID NULL");
2939 return NULL;
2940 }
2941 if (OptionsList == NULL){
2942 TRACEIT (6, "OptionsList_getValueByID end, Parameter OptionsList NULL, no configfile found?");
2943 return NULL;
2944 }
2945
2946
2947 struct _OptionsList *bufList = OptionsList_getFirstItem(OptionsList);
2948
2949 while (bufList){
2950 if (bufList->gstrID){
2951 if (0 == strcmp(bufList->gstrID->str, cpID)){
2952 if (bufList->gstrValue){
2953 TRACEIT (7, "OptionsList_getValueByID end");
2954 return (const char *)bufList->gstrValue->str;
2955 }
2956 else{
2957 TRACEIT (6, "OptionsList_getValueByID end, value not set");
2958 return NULL;
2959 }
2960 }
2961 }
2962 bufList = bufList->nextItem;
2963 }
2964
2965 TRACEIT (7, "OptionsList_getValueByID end not found");
2966 return NULL;
2967 }
2968
2969
2970
OptionsList_editItem(struct _OptionsList * OptionsList,const char * cpID,const char * cpName,const char * cpValue)2971 int OptionsList_editItem(struct _OptionsList *OptionsList, const char*cpID, const char *cpName, const char *cpValue){
2972 TRACEIT (7, "OptionsList_editItem start");
2973 if (OptionsList == NULL){
2974 TRACEIT(2, "OptionsList_editItem end, PARAMETER NULL");
2975 return -1;
2976 }
2977 if (cpID != NULL){
2978 if (OptionsList->gstrID != NULL){
2979 g_string_assign(OptionsList->gstrID, cpID);
2980 }
2981 else{
2982 OptionsList->gstrID = g_string_new(cpID);
2983 }
2984 }
2985 if (cpName != NULL){
2986 if (OptionsList->gstrName != NULL){
2987 g_string_assign(OptionsList->gstrName, cpName);
2988 }
2989 else{
2990 OptionsList->gstrName = g_string_new(cpName);
2991 }
2992 }
2993 if (cpValue != NULL){
2994 if (OptionsList->gstrValue != NULL){
2995 g_string_assign(OptionsList->gstrValue, cpValue);
2996 }
2997 else{
2998 OptionsList->gstrValue = g_string_new(cpValue);
2999 }
3000 }
3001
3002 TRACEIT (7, "OptionsList_editItem end");
3003 return 0;
3004 }
3005
3006
OptionsList_addItem(struct _OptionsList ** OptionsList,const char * cpID,const char * cpName,const char * cpValue)3007 int OptionsList_addItem(struct _OptionsList **OptionsList, const char*cpID, const char *cpName, const char *cpValue){
3008 TRACEIT (7, "OptionsList_addItem start");
3009 //cpName and/or cpvalue can be NULL, in this case, the GString pointer (either gstrName or gstrValue become NULL)
3010 //if *OptionsList is NULL, a new list is created.
3011 //return: -1=error, 0=ok
3012
3013 if (OptionsList == NULL){
3014 TRACEIT(2, "OptionsList_addItem end, PARAMETER NULL");
3015 return -1;
3016 }
3017
3018 struct _OptionsList *newItem = malloc( sizeof(struct _OptionsList) );
3019 struct _OptionsList *bufList;
3020
3021 newItem->gstrID = NULL;
3022 newItem->gstrName = NULL;
3023 newItem->gstrValue = NULL;
3024 newItem->nextItem = NULL;
3025 newItem->prevItem = NULL;
3026
3027 if (cpID != NULL){
3028 newItem->gstrID = g_string_new(cpID);
3029 }
3030 if (cpName != NULL){
3031 newItem->gstrName = g_string_new(cpName);
3032 }
3033 if (cpValue != NULL){
3034 newItem->gstrValue = g_string_new(cpValue);
3035 }
3036
3037 if (*OptionsList == NULL){
3038 //brand new list
3039 *OptionsList = newItem;
3040 }
3041 else{
3042 //new item at end of list
3043 bufList = OptionsList_getLastItem(*OptionsList);
3044 if (bufList != NULL){
3045 bufList->nextItem = newItem;
3046 newItem->prevItem = bufList;
3047 }
3048 else{
3049 TRACEIT(2, "OptionsList_addItem weird error");
3050 }
3051 }
3052
3053 TRACEIT (7, "OptionsList_addItem end");
3054 return 0;
3055 }
3056
3057
OptionsList_getLastItem(struct _OptionsList * thelist)3058 struct _OptionsList *OptionsList_getLastItem(struct _OptionsList *thelist){
3059 TRACEIT (7, "OptionsList_getLastItem start");
3060
3061 if (thelist == NULL){
3062 TRACEIT (2, "OptionsList_getLastItem end, PARAMETER NULL");
3063 return NULL;
3064 }
3065
3066 struct _OptionsList *bufList = thelist;
3067
3068 while (bufList->nextItem){
3069 bufList = bufList->nextItem;
3070 }
3071
3072 TRACEIT (7, "OptionsList_getLastItem end");
3073 return bufList;
3074 }
3075
3076
OptionsList_getFirstItem(struct _OptionsList * thelist)3077 struct _OptionsList *OptionsList_getFirstItem(struct _OptionsList *thelist){
3078 TRACEIT (7, "OptionsList_getFirstItem start");
3079 if (thelist == NULL){
3080 TRACEIT (2, "OptionsList_getFirstItem end, PARAMETER NULL");
3081 return NULL;
3082 }
3083
3084 struct _OptionsList *bufList = thelist;
3085
3086 while (bufList->prevItem){
3087 bufList = bufList->prevItem;
3088 }
3089
3090 TRACEIT (7, "OptionsList_getFirstItem end");
3091 return bufList;
3092 }
3093
3094
OptionsList_deleteItem(struct _OptionsList * theItem)3095 struct _OptionsList *OptionsList_deleteItem(struct _OptionsList *theItem){
3096 //deletes theItem and returns the new begining of the list,
3097 //if theItem was the last item NULL is returned
3098 TRACEIT (7, "OptionsList_deleteItem start");
3099 struct _OptionsList *bufList = NULL;
3100 if (theItem == NULL){
3101 TRACEIT (2, "OptionsList_deleteItem end, PARAMETER NULL");
3102 return NULL;
3103 }
3104 if (theItem->nextItem){
3105 theItem->nextItem->prevItem = theItem->prevItem;
3106 bufList = theItem->nextItem;
3107 }
3108 if (theItem->prevItem){
3109 theItem->prevItem->nextItem = theItem->nextItem;
3110 bufList = theItem->prevItem;
3111 }
3112
3113 if (bufList){
3114 bufList = OptionsList_getFirstItem (bufList);
3115 }
3116
3117 if (theItem->gstrID){
3118 g_string_free(theItem->gstrID, TRUE);
3119 }
3120 if (theItem->gstrName){
3121 g_string_free(theItem->gstrName, TRUE);
3122 }
3123 if (theItem->gstrValue){
3124 g_string_free(theItem->gstrValue, TRUE);
3125 }
3126 free(theItem);
3127
3128 TRACEIT (7, "OptionsList_getFirstItem end");
3129 return bufList;
3130 }
3131
3132
OptionsList_freeList(struct _OptionsList ** thelist)3133 void OptionsList_freeList(struct _OptionsList **thelist){
3134 TRACEIT (7, "OptionsList_freeList start");
3135 if (thelist == NULL){
3136 TRACEIT (2, "OptionsList_freeList end, PARAMETER NULL");
3137 return;
3138 }
3139
3140 struct _OptionsList *bufList = OptionsList_getFirstItem(*thelist);
3141 struct _OptionsList *buf2List=NULL;
3142
3143 while (bufList){
3144 if (bufList->gstrID){
3145 g_string_free(bufList->gstrID, TRUE);
3146 }
3147 if (bufList->gstrName){
3148 g_string_free(bufList->gstrName, TRUE);
3149 }
3150 if (bufList->gstrValue){
3151 g_string_free(bufList->gstrValue, TRUE);
3152 }
3153 buf2List=bufList;
3154 bufList = bufList->nextItem;
3155 free(buf2List);
3156 }
3157 *thelist = NULL;
3158
3159 TRACEIT (7, "OptionsList_freeList end");
3160 }
3161
3162
freeRelicts(struct _Parser_Mode_Struct * info)3163 void freeRelicts(struct _Parser_Mode_Struct *info){
3164 TRACEIT (7, "freeRelicts start");
3165 //deletes currentItems in this struct if necessary
3166 if (info == NULL){
3167 TRACEIT (2,"freeRelicts end, parameter NULL");
3168 return;
3169 }
3170
3171 if (info->currentListItem){
3172 if (info->iCurrentListType == CONFIGFILE_LOAD_OPTIONS || info->iCurrentListType == CONFIGFILE_LOAD_BOOKMARKS){
3173 OptionsList_freeList((struct _OptionsList **)&(info->currentListItem));
3174 //info->currentListItem = NULL;
3175 }
3176 else if ( info->iCurrentListType == CONFIGFILE_LOAD_USERCOMMANDS){
3177 UserCommandList_freeList ((struct _UserCommandList **)&(info->currentListItem));
3178 //info->currentListItem = NULL;
3179 }
3180 else {
3181 TRACEIT(3, "freeRelicts could not determine currentList item to free it But NULL it anyway. THIS DEFINITLY WILL CREATE A MEMORYLEAK! There is something wrong in here.");
3182 info->currentListItem = NULL;
3183 }
3184 }
3185 if (info->currentOptionBlock){
3186 OptionsList_freeList((struct _OptionsList **)&(info->currentOptionBlock));
3187 //info->currentOptionBlock = NULL;
3188 }
3189 TRACEIT (7, "freeRelicts end");
3190 }
3191
3192 ////////////////////////////////////////////////////////////////////////////////////////////
3193 ////////////////////////////////////////////////////////////////////////////////////////////
3194 ////////////////////////////////////////////////////////////////////////////////////////////
3195 ////////////////NEW FILE HANDLING ///////////////////////////////////////////
3196 ////////////////////////////////////////////////////////////////////////////////////////////
3197 ////////////////////////////////////////////////////////////////////////////////////////////
3198 ////////////////////////////////////////////////////////////////////////////////////////////
3199
myFiles_SaveFileSimpleSave(char * cpLine,char * Mode)3200 int myFiles_SaveFileSimpleSave(char *cpLine, char *Mode){
3201 if (cpLine == NULL || Mode==NULL){
3202 TRACEIT(2, "myFiles_SaveFileSimpleSave parameter NULL");
3203 return -1;
3204 }
3205 struct myFiles_struct *stru = myFiles_openSaveFile(Mode);
3206 if(stru){
3207 myFiles_SaveValueToFile(stru, cpLine);
3208 myFiles_closeFile(stru);
3209 return 0;
3210 }
3211 return -1;
3212 }
3213
3214
myFiles_openSaveFile(char * cpMode)3215 struct myFiles_struct *myFiles_openSaveFile(char *cpMode){
3216 TRACEIT(10,"myFiles_saveFile start");
3217 if (cpMode==NULL){
3218 TRACEIT(2, "myFiles_openSaveFile parameter NULL");
3219 return NULL;
3220 }
3221
3222 GString *SaveFile=g_string_sized_new(20);
3223 getHomeDirectory (SaveFile);
3224 checkPathForLastChar(SaveFile);
3225 g_string_append(SaveFile,SAVE_FILE);
3226
3227 struct myFiles_struct *stru;
3228 stru = myFiles_openFile(SaveFile->str, cpMode);
3229
3230 g_string_free(SaveFile,TRUE);
3231 TRACEIT(10,"myFiles_saveFile ends");
3232 return stru;
3233 }
3234
3235
myFiles_SaveFileSimpleGetValue(char * Identifier,GString * Value)3236 int myFiles_SaveFileSimpleGetValue(char *Identifier, GString *Value){
3237 //return 1-> found, return !=0 Not found
3238 //All spaces are cut within Value
3239 TRACEIT(10,"myFiles_SaveFileSimpleGetValue start");
3240 if (Identifier == NULL){
3241 TRACEIT(10,"myFiles_SaveFileSimpleGetValue ends, parameter NULL");
3242 return -1;
3243 }
3244 if (Value == NULL){
3245 TRACEIT(10,"myFiles_SaveFileSimpleGetValue ends, parameter NULL");
3246 return -1;
3247 }
3248
3249 struct myFiles_struct *stru = myFiles_openSaveFile("r");
3250 if (stru == NULL){
3251 TRACEIT(10,"myFiles_SaveFileSimpleGetValue ends, error opening configfile");
3252 return -1;
3253 }
3254
3255 if (myFiles_getValueFromIdentifier(stru, Identifier, 0) == 1){
3256 g_string_assign(Value, stru->gstrValue->str);
3257 myFiles_closeFile(stru);
3258 cutSpacesFromGString(Value);
3259 if (strlen(Value->str) == 0){
3260 return 0; //not found
3261 }
3262 return 1; //All good, found
3263 }
3264 if (stru){
3265 myFiles_closeFile(stru);
3266 }
3267 TRACEIT(10,"myFiles_SaveFileSimpleGetValue ends");
3268 return 0; //not found
3269 }
3270
3271
myFiles_openFile(char * FileName,char * cpMode)3272 struct myFiles_struct *myFiles_openFile(char *FileName, char *cpMode){
3273 TRACEIT(10,"myFiles_openFile start");
3274 if (FileName == NULL || cpMode==NULL){
3275 TRACEIT(3,"myFiles_openFile end, parameter NULL");
3276 //g_string_free(gstrBuf,TRUE);
3277 return NULL;
3278 }
3279 GString *gstrBuf = g_string_sized_new(10);
3280
3281 FILE *pFile;
3282 pFile = fopen(FileName,cpMode);
3283
3284 if (pFile == NULL){
3285 g_string_sprintf(gstrBuf,"myFiles_openFile end, Error opening file %s",FileName);
3286 TRACEIT(3,gstrBuf->str);
3287 g_string_free(gstrBuf,TRUE);
3288 return NULL;
3289 }
3290 // openfiles++;
3291 // printf("Opened files: %i\n",openfiles);
3292 struct myFiles_struct *stru= malloc(sizeof(struct myFiles_struct));
3293 if (stru == NULL){
3294 fclose(pFile);
3295 // openfiles--;
3296 // printf("Opened files: %i\n",openfiles);
3297 g_string_free(gstrBuf,TRUE);
3298 TRACEIT(1,"myFiles_openFile end, FATAL ERROR, MEMORYALLOCATION");
3299 return NULL;
3300 }
3301
3302 stru->File = pFile;
3303 stru->gstrFileName = g_string_new(FileName);
3304 stru->gstrIdentifier = g_string_sized_new(20);
3305 stru->gstrValue = g_string_sized_new(20);
3306 stru->allreadystarted=0;
3307
3308 g_string_free(gstrBuf,TRUE);
3309 TRACEIT(10,"myFiles_openFile end");
3310 return stru;
3311 }
3312
3313
myFiles_closeFile(struct myFiles_struct * fileInfo)3314 int myFiles_closeFile(struct myFiles_struct *fileInfo){
3315 TRACEIT(10,"myFiles_closeFile start");
3316 if (fileInfo == NULL){
3317 TRACEIT(3,"myFiles_closeFile end fileInfo parameter == NULL");
3318 return -1;
3319 }
3320
3321 if (fileInfo->File != NULL){
3322 // openfiles--;
3323 // printf("Opened files: %i\n",openfiles);
3324 fclose(fileInfo->File);
3325 }
3326 if (fileInfo->gstrFileName != NULL)
3327 g_string_free(fileInfo->gstrFileName, TRUE);
3328 if (fileInfo->gstrIdentifier != NULL)
3329 g_string_free(fileInfo->gstrIdentifier, TRUE);
3330 if (fileInfo->gstrValue != NULL)
3331 g_string_free(fileInfo->gstrValue, TRUE);
3332
3333 free(fileInfo);
3334
3335 TRACEIT(10,"myFiles_closeFile end");
3336 return 0;
3337 }
3338
3339
myFiles_getValueFromIdentifier(struct myFiles_struct * fileInfo,char * cpIdentifier,int again)3340 int myFiles_getValueFromIdentifier(struct myFiles_struct *fileInfo, char *cpIdentifier, int again){
3341 TRACEIT(10,"myFiles_getValueFromIdentifier start");
3342 if (fileInfo == NULL){
3343 TRACEIT(3,"myFiles_getValueFromIdentifier end fileInfo parameter == NULL");
3344 return -1;
3345 }
3346 if (cpIdentifier == NULL){
3347 TRACEIT(3,"myFiles_getValueFromIdentifier ends cpIdentifier parameter == NULL");
3348 return -1;
3349 }
3350 if (fileInfo->File == NULL){
3351 TRACEIT(3,"myFiles_getValueFromIdentifier ends No file opened");
3352 return -2;
3353 }
3354 char bufLine[5001];
3355 char *buf;
3356 gchar *cpctype=NULL;
3357 GString *gstrCType = g_string_sized_new(15);
3358
3359 g_string_assign( gstrCType, cpIdentifier);
3360 cpctype = g_utf8_strdown( gstrCType->str, -1); //we use only lower case letters!
3361 if (cpctype == NULL){
3362 g_string_free(gstrCType, TRUE);
3363 TRACEIT(10,"myFiles_getValueFromIdentifier end");
3364 return 0;
3365 }
3366 g_string_assign(gstrCType, cpctype);
3367 g_free(cpctype);
3368 cpctype=NULL;
3369
3370 g_string_append(gstrCType,TYPESEPARATOR);
3371 fileInfo->allreadystarted=0;
3372 if (again == 0){
3373 fseek(fileInfo->File,0,SEEK_SET);
3374 }
3375 while(1){
3376 if (feof(fileInfo->File))
3377 break;
3378 fgets(bufLine,5000,fileInfo->File);
3379 if ( strncmp(bufLine,gstrCType->str,strlen(gstrCType->str)) == 0 ){
3380 buf = strchr(bufLine,'\n');
3381 if (buf != NULL){
3382 *buf='\0';
3383 }
3384 g_string_assign(fileInfo->gstrValue,bufLine);
3385 cutTapsFromGString(fileInfo->gstrValue);
3386 g_string_assign(fileInfo->gstrIdentifier,gstrCType->str);
3387 g_string_erase(fileInfo->gstrValue,0,strlen(gstrCType->str));
3388
3389 //now, in the case it is a new usercommand it is possible that the information is spread over several lines
3390 //this function will care of this
3391 //newUsercommandReadOverSeveralLines(fileInfo->File,fileInfo->gstrValue->str);
3392 //we decided not to do something like this, but create a program to edit the config file, then it is not
3393 //longer necessary to edit the configfile directly.
3394
3395 g_string_free(gstrCType, TRUE);
3396 TRACEIT(10,"myFiles_getValueFromIdentifier ends 1 ");
3397 return 1; //found
3398 }
3399 };
3400 g_string_free(gstrCType, TRUE);
3401 TRACEIT(10,"myFiles_getValueFromIdentifier end");
3402 return 0;
3403 }
3404
3405
myFiles_SeparateMultiValue(struct myFiles_struct * fileInfo,GString * name,GString * command,int ModusSingleOrPair)3406 int myFiles_SeparateMultiValue(struct myFiles_struct *fileInfo, GString *name, GString *command, int ModusSingleOrPair){
3407 // ModusSingleOrPair == 1 -> Pair, == 0 -> Single
3408 // leading spaces are removed from command, but not from name
3409 TRACEIT(10,"myFiles_SeparateMultiValue start");
3410 if (name == NULL || fileInfo == NULL){
3411 TRACEIT(10,"myFiles_SeparateMultiValue ends");
3412 return -1;
3413 }
3414 if (fileInfo->gstrValue == NULL || fileInfo->gstrIdentifier == NULL){
3415 TRACEIT(10,"myFiles_SeparateMultiValue ends");
3416 return -2;
3417 }
3418
3419 char *buf1=NULL;
3420 char *buf2=NULL;
3421 GString *gstrCType=g_string_sized_new(15);
3422
3423 const char sep[] = PROGRAMSEPERATOR;
3424 if (fileInfo->allreadystarted == 0){
3425 buf1 = (char *)strtok(fileInfo->gstrValue->str,sep);
3426 if (ModusSingleOrPair==1){
3427 buf2 = (char *)strtok(NULL,sep);
3428 }
3429 fileInfo->allreadystarted = 1;
3430 }
3431 else{
3432 buf1 = (char *)strtok(NULL,sep);
3433 if (ModusSingleOrPair==1){
3434 buf2 = (char *)strtok(NULL,sep);
3435 }
3436 }
3437
3438 if (buf1 == NULL || (ModusSingleOrPair == 1 && buf2 == NULL)){
3439 g_string_assign(gstrCType, fileInfo->gstrIdentifier->str);
3440 g_string_truncate(gstrCType, strlen(gstrCType->str)-strlen(TYPESEPARATOR));
3441 if (1 == myFiles_getValueFromIdentifier(fileInfo, gstrCType->str, 1)){
3442 TRACEIT(10,"getOneCommandAfterEachOther recursively ends");
3443 return myFiles_SeparateMultiValue(fileInfo, name, command, ModusSingleOrPair);
3444 }
3445 TRACEIT(10,"getOneCommandAfterEachOther ends");
3446 return 0; //Nothing found
3447 }
3448 else{
3449 if (buf1[strlen(buf1)-1]=='\n'){
3450 buf1[strlen(buf1)-1] = '\0';
3451 }
3452 if (ModusSingleOrPair == 1){
3453 if (buf2[strlen(buf2)-1]=='\n'){
3454 buf2[strlen(buf2)-1] = '\0';
3455 }
3456 }
3457 g_string_assign(name,buf1);
3458 if (ModusSingleOrPair == 1){
3459 g_string_assign(command,buf2);
3460 cutLeadingSpacesFromGString(command);
3461 }
3462
3463 TRACEIT(10,"getOneCommandAfterEachOther ends");
3464 return 1; //found
3465 }
3466 }
3467
3468
myFiles_findStringInFile(struct myFiles_struct * fileInfo,char * cpString)3469 int myFiles_findStringInFile(struct myFiles_struct *fileInfo, char *cpString){
3470 //this will NOT rewind the file !!
3471 //return: -1=error, 0=notfound, 1=found
3472 TRACEIT(10,"myFiles_findStringInFile start");
3473 if (fileInfo==NULL || cpString==NULL){
3474 TRACEIT(2,"myFiles_findStringInFile end, Parameter NULL");
3475 return -1;
3476 }
3477 if (fileInfo->File == NULL){
3478 TRACEIT(2,"myFiles_findStringInFile end, Parameter 2 NULL");
3479 return -1;
3480 }
3481
3482 char bufLine[5001];
3483
3484 while(1){
3485 if (feof(fileInfo->File))
3486 break;
3487 fgets(bufLine,5000,fileInfo->File);
3488 if ( strstr( bufLine, cpString ) != NULL ){
3489
3490 TRACEIT(10,"myFiles_getValueFromIdentifier ends 1 ");
3491 return 1; //found
3492 }
3493 }
3494
3495 TRACEIT(10,"myFiles_findStringInFile end");
3496 return 0; //not found
3497 }
3498
3499
myFiles_SaveValueToFile(struct myFiles_struct * fileInfo,char * cpLine)3500 int myFiles_SaveValueToFile(struct myFiles_struct *fileInfo, char* cpLine){
3501 TRACEIT(10,"myFiles_SaveValueToFile start");
3502 if (fileInfo == NULL){
3503 TRACEIT(3,"myFiles_SaveValueToFile end fileInfo parameter == NULL");
3504 return -1;
3505 }
3506 if (cpLine == NULL){
3507 TRACEIT(3,"myFiles_SaveValueToFile ends cpLine parameter == NULL");
3508 return -1;
3509 }
3510 if (fileInfo->File == NULL){
3511 TRACEIT(3,"myFiles_SaveValueToFile ends No file opened");
3512 return -2;
3513 }
3514
3515 fputs(cpLine,fileInfo->File);
3516 fputc('\n',fileInfo->File);
3517
3518 TRACEIT(10,"myFiles_SaveValueToFile ends");
3519 return 0;
3520 }
3521
3522