summaryrefslogtreecommitdiffstats
path: root/kxsldbg/kxsldbgpart/libxsldbg/options.cpp
blob: 525c3728328e3d03b3e9e6872a9ac1ad178502a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902

/***************************************************************************
                          options.c  -  provide the implementation for option
                                           related functions
                             -------------------
    begin                : Sat Nov 10 2001
    copyright            : (C) 2001 by Keith Isdale
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "xsldbg.h"
#include "xsldbgthread.h"
#include "options.h"
#include "arraylist.h"
#include "xsldbgmsg.h"
#include "utils.h"
#include <kglobal.h>
#include <kstandarddirs.h> 
#include <tqfileinfo.h>
#include <tqstringlist.h>


/* keep track of our integer/boolean options */
static int intOptions[OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID + 1];

/* make use that use of options are safe by only copying
   critical values from intVolitleOptions just before stylesheet is started
 */
int intVolitileOptions[OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID + 1];

/* keep track of our string options */
static xmlChar *stringOptions[OPTIONS_LAST_STRING_OPTIONID -
                              OPTIONS_FIRST_STRING_OPTIONID + 1];

/* keep track of our parameters */
static arrayListPtr parameterList;

/* what are the expressions to be printed out when xsldbg stops */
static arrayListPtr watchExpressionList;


/* the names for our options
   Items that start with *_ are options that CANNOT be used by the user
  Once you set an option you need to give a run command to activate
  new settings */
const char *optionNames[] = {
    "xinclude",                 /* Use xinclude during xml parsing */
    "docbook",                  /* Use of docbook sgml parsing */
    "timing",                   /* Use of timing */
    "profile",                  /* Use of profiling */
    "valid",                    /* Enable file validation */
    "out",                      /* Enable output to stdout */
    "html",                     /* Enable the use of html parsing */
    "debug",                    /* Enable the use of xml tree debugging */
    "shell",                    /* Enable the use of debugger shell */
    "gdb",                      /* Run in gdb modem prints more messages */
    "preferhtml",               /* Prefer html output for search results */
    "autoencode",               /* Try to use the encoding from the stylesheet */
    "utf8input",                /* All input from "user" will be in UTF-8 */
    "stdout",                   /* Print all error messages to  stdout, 
				 * normally error messages go to stderr */
    "autorestart",		/* When finishing the debug of a XSLT script 
				   automaticly restart at the beginning */
    "verbose",                  /* Be verbose with messages */
    "repeat",                   /* The number of times to repeat */
    "*_trace_*",                /* Trace execution */
    "*_walkspeed_*",            /* How fast do we walk through code */
    "catalogs",                 /* do we use catalogs in SGML_CATALOG_FILES */
    "output",                   /* what is the output file name */
    "source",                   /* The stylesheet source to use */
    "docspath",                 /* Path of xsldbg's documentation */
    "catalognames",             /* The names of the catalogs to use when the catalogs option is active */
    "encoding",                 /* What encoding to use for standard output */
    "searchresultspath",        /* Where do we store the results of search */
    "data",                     /* The xml data file to use */
    NULL                        /* indicate end of list */
};



// find the translated help documentation directory
// langLookupDir code modified from langLookup function in tdebase/khelpcenter/view.cpp 

static TQString langLookupDir( const TQString &fname )
{
    TQStringList search;

    // assemble the local search paths
    TQStringList localDoc = TDEGlobal::dirs()->resourceDirs("html");
    // also look in each of the TDEDIR paths
    TQString kdeDirs = getenv("TDEDIRS");
    TQStringList kdeDirsList = TQStringList::split(":", kdeDirs);
    if (!kdeDirs.isEmpty() && !kdeDirsList.isEmpty()){
	for (TQStringList::iterator it = kdeDirsList.begin(); it != kdeDirsList.end(); it++)
          localDoc.append((*it) + "/share/doc/tde/HTML/") ;
    }

    // look up the different languages
    for (uint id=0; id < localDoc.count(); id++)
    {
        TQStringList langs = TDEGlobal::locale()->languageList();
        langs.append( "en" );
        langs.remove( "C" );
        TQStringList::ConstIterator lang;
        for (lang = langs.begin(); lang != langs.end(); ++lang)
            search.append(TQString("%1%2/%3/%4").arg(localDoc[id]).arg(*lang).arg("xsldbg").arg(fname));
    }

    // try to locate the file
    TQStringList::Iterator it;
    for (it = search.begin(); it != search.end(); ++it)
    {
	TQString baseDir = (*it).left((*it).findRev('/')) ;
	TQFileInfo info(baseDir + "/"+ fname);
	if (info.exists() && info.isFile() && info.isReadable())
	  return baseDir;
    }

    return TQString();
}


/** 
 * optionsInit:
 *
 * Intialize the options module
 *
 * Returns 1 on success,
 *         0 otherwise
 */
int
optionsInit(void)
{
    int optionId;

    for (optionId = 0;
         optionId <= OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID; optionId++) {
        intOptions[optionId] = 0;
        intVolitileOptions[optionId] = 0;
    }

    for (optionId = 0;
         optionId <= OPTIONS_LAST_STRING_OPTIONID - OPTIONS_FIRST_STRING_OPTIONID;
         optionId++) {
        stringOptions[optionId] = NULL;
    }

    /* init our parameter list */
    parameterList = arrayListNew(10, (freeItemFunc) optionsParamItemFree);

    /* setup the docs path */
    optionsSetStringOption(OPTIONS_DOCS_PATH, (const xmlChar*)(langLookupDir("xsldbghelp.xml").utf8().data()));

    optionsSetIntOption(OPTIONS_TRACE, TRACE_OFF);
    optionsSetIntOption(OPTIONS_WALK_SPEED, WALKSPEED_STOP);
    /* always try to use encoding if found */
    optionsSetIntOption(OPTIONS_AUTOENCODE, 1);
    /* start up with auto restart turned off */
    optionsSetIntOption(OPTIONS_AUTORESTART, 0); 	
    /* start up with gdb mode turned on */
    optionsSetIntOption(OPTIONS_GDB, 1); 	
    /* start up with output mode turned on */
    optionsSetIntOption(OPTIONS_OUT, 1); 	
    /* start up with validation turned on */
    optionsSetIntOption(OPTIONS_VALID, 1); 	
    /* start up with xinclude turned on */
    optionsSetIntOption(OPTIONS_XINCLUDE, 1); 	

    /* set output default as standard output. Must be changed if not using
     * xsldbg's command line. Or the tty command is used */
    optionsSetStringOption(OPTIONS_OUTPUT_FILE_NAME, NULL);

    /* init our list of expressions to watch which are only a list of 
     strings ie xmlChar*'s  */
    watchExpressionList = arrayListNew(10, (freeItemFunc) xmlFree);

    return (parameterList && watchExpressionList);
}


/**
 * optionsFree:
 *
 * Free memory used by the options module
 */
void
optionsFree(void)
{
    int string_option;

    for (string_option = OPTIONS_FIRST_STRING_OPTIONID;
         string_option <= OPTIONS_LAST_STRING_OPTIONID; string_option++) {
        optionsSetStringOption(OptionTypeEnum(string_option), NULL);
    }

    /* Free up memory used by parameters and watches*/
    arrayListFree(parameterList);
    arrayListFree(watchExpressionList);
    parameterList = NULL;
    watchExpressionList = NULL;
}


  /**
   * optionsGetOptionID:
   * @optionName : A valid option name see documentation for "setoption" 
   *        command and program usage documentation
   *
   * Find the option id for a given option name
   *
   * Returns The optionID for @optionName if successful, where  
   *             OPTIONS_FIRST_OPTIONID<= optionID <= OPTIONS_LAST_OPTIONID,
   *         otherwise returns -1
   */
int
optionsGetOptionID(xmlChar * optionName)
{
    int result = -1;
    int optID = lookupName(optionName, (xmlChar **) optionNames);

    if (optID >= 0) {
        result = optID + OPTIONS_FIRST_OPTIONID;
    }

    return result;
}


  /**
   * optionsGetOptionName:
   * @ID : A valid option ID
   *
   * Get the name text for an option
   *
   * Returns The name of option if @ID is valid, 
   *         NULL otherwise 
   */
const xmlChar *
optionsGetOptionName(OptionTypeEnum ID)
{
    const xmlChar *result = 0;
    if ( (ID >= OPTIONS_FIRST_OPTIONID) && (ID <= OPTIONS_LAST_OPTIONID)){
	/* An option ID is always valid at the moment */
	result = (const xmlChar *) optionNames[ID - OPTIONS_FIRST_OPTIONID];
    }

    return result;
}


/**
 * optionsSetIntOption:
 * @optionType: A valid boolean option
 * @value: 1 to enable, 0 otherwise
 *
 * Set the state of a boolean xsldbg option to @value
 *
 * Returns 1 on success,
 *         0 otherwise
 */
int
optionsSetIntOption(OptionTypeEnum optionType, int value)
{
    int type = optionType, result = 1;

    if ((type >= OPTIONS_FIRST_INT_OPTIONID) && (type <= OPTIONS_LAST_INT_OPTIONID)) {
        /* make sure that use of options are safe by only copying
         * critical values from intVolitleOptions just before 
         * stylesheet is started
         */
        intVolitileOptions[type - OPTIONS_FIRST_INT_OPTIONID] = value;

        /* the following types must be activated imediately */
        switch (type) {

            case OPTIONS_TRACE:
            case OPTIONS_WALK_SPEED:
            case OPTIONS_GDB:
                intOptions[type - OPTIONS_FIRST_INT_OPTIONID] = value;
                break;

            default:
                break;
        }
    } else {
	if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
	     xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid boolean/integer option.\n").arg(xsldbgText(optionNames[type - OPTIONS_FIRST_OPTIONID])));
	}else{
#ifdef WITH_XSLDBG_DEBUG_PROCESS
	    xsldbgGenericErrorFunc(TQString("Error: Invalid arguments for the command %1.\n").arg("setoption"));
#endif
	}
        result = 0;
    }
    return result;
}


/**
 * optionsGetIntOption:
 * @optionType: A valid boolean option to query
 *
 * Return the state of a boolean option
 *
 * Returns The state of a boolean xsldbg option. 
 *         ie 1 for enabled , 0 for disabled
 */
int
optionsGetIntOption(OptionTypeEnum optionType)
{
    int type = optionType, result = 0;

    if ((type >= OPTIONS_FIRST_INT_OPTIONID) && (type <= OPTIONS_LAST_INT_OPTIONID)) {
        result = intOptions[type - OPTIONS_FIRST_INT_OPTIONID];
    } else {
	if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
	    xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid boolean/integer option.\n").arg(xsldbgText(optionNames[type - OPTIONS_FIRST_OPTIONID])));
	}else{
#ifdef WITH_XSLDBG_DEBUG_PROCESS
	    xsldbgGenericErrorFunc(TQString("Error: Invalid arguments for the command %1.\n").arg("options"));
#endif
	}
    }
    return result;
}



/**
 * optionsSetStringOption:
 * @optionType: A valid string option
 * @value: The value to copy
 *
 * Set value for a string xsldbg option to @value. 
 * Any memory used currently by option @optionType will be freed
 *
 * Returns 1 on success,
 *         0 otherwise
 */
int
optionsSetStringOption(OptionTypeEnum optionType, const xmlChar * value)
{
    int type = optionType, result = 0;

    if ((type >= OPTIONS_FIRST_STRING_OPTIONID) &&
        (type <= OPTIONS_LAST_STRING_OPTIONID)) {
        int optionId = type - OPTIONS_FIRST_STRING_OPTIONID;

        if (stringOptions[optionId])
            xmlFree(stringOptions[optionId]);
        if (value)
            stringOptions[optionId] =
                (xmlChar *) xmlMemStrdup((char *) value);
        else                    /* we want to be able to provide a NULL value */
            stringOptions[optionId] = NULL;
        result = 1;
    } else{
	if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
	    xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid string xsldbg option.\n").arg(xsldbgText(optionNames[type - OPTIONS_LAST_OPTIONID])));
	}else{
#ifdef WITH_XSLDBG_DEBUG_PROCESS
	    xsldbgGenericErrorFunc(TQString("Error: Invalid arguments for the command %1.\n").arg("setoption"));
#endif
	}
    }
    return result;
}


/**
 * optionsGetStringOption:
 * @optionType: A valid string option 
 *
 * Get value for a string xsldbg option of @optionType

 * Returns current option value which may be NULL
 */
const xmlChar *
optionsGetStringOption(OptionTypeEnum optionType)
{
    int type = optionType;
    xmlChar *result = NULL;

    if ((type >= OPTIONS_FIRST_STRING_OPTIONID) &&
        (type <= OPTIONS_LAST_STRING_OPTIONID)) {
        int optionId = type - OPTIONS_FIRST_STRING_OPTIONID;
        result = stringOptions[optionId];
    } else{
	if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
	    xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid string xsldbg option.\n").arg(xsldbgText(optionNames[type - OPTIONS_FIRST_OPTIONID])));
	}else{
#ifdef WITH_XSLDBG_DEBUG_PROCESS
	    xsldbgGenericErrorFunc(TQString("Error: Invalid arguments for the command %1.\n").arg("options"));
#endif
	}
    }
    return result;
}


  /**
   * optionsCopyVolitleOptions:
   *
   * Copy volitile options to the working area for xsldbg to be used
   *   just after xsldbg starts its processing loop
   */
void
optionsCopyVolitleOptions(void)
{
    int optionId;

    for (optionId = 0;
         optionId <= OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID; optionId++) {
        intOptions[optionId] = intVolitileOptions[optionId];
    }
}


/**
 * optionsParamItemNew:
 * @name: Is valid 
 * @value: Is valid 
 *
 * Create a new libxslt parameter item
 * Returns non-null if sucessful
 *         NULL otherwise
 */
parameterItemPtr
optionsParamItemNew(const xmlChar * name, const xmlChar * value)
{
    parameterItemPtr result = NULL;

    if (name) {
        result = (parameterItem *) xmlMalloc(sizeof(parameterItem));
        if (result) {
            result->name = (xmlChar *) xmlMemStrdup((char *) name);
            if (value)
                result->value = (xmlChar *) xmlMemStrdup((char *) value);
            else
                result->value = (xmlChar *) xmlMemStrdup("");
            result->intValue = -1;
        }
    }
    return result;
}


/**
 * optionsParamItemFree:
 * @item: Is valid
 *
 * Free memory used by libxslt parameter item @item
 */
void
optionsParamItemFree(parameterItemPtr item)
{
    if (item) {
        if (item->name)
            xmlFree(item->name);
        if (item->value)
            xmlFree(item->value);
	xmlFree(item);
    }
    
}


/**
 * optionsGetParamItemList:
 *
 * Return the list of libxlt parameters
 *
 * Returns The list of parameters to provide to libxslt when doing 
 *           stylesheet transformation if successful
 *        NULL otherwise
 */
arrayListPtr
optionsGetParamItemList(void)
{
    return parameterList;
}


/**
 * optionsPrintParam:
 * @paramId: 0 =< paramID < arrayListCount(getParamList())
 * 
 * Print parameter information
 *
 * Returns 1 on success,
 *         0 otherwise
 */
int
optionsPrintParam(int paramId)
{
    int result = 0;
    parameterItemPtr paramItem =
        (parameterItemPtr) arrayListGet(optionsGetParamItemList(),
                                        paramId);

    if (paramItem && paramItem->name && paramItem->value) {
        xsldbgGenericErrorFunc(i18n(" Parameter %1 %2=\"%3\"\n").arg(paramId).arg(xsldbgText(paramItem->name)).arg(xsldbgText(paramItem->value)));
        result = 1;
    }
    return result;
}


/**
 * optionsPrintParamList:
 *
 * Prints all items in parameter list
 *
 * Returns 1 on success,
 *         0 otherwise
 */
int
optionsPrintParamList(void)
{
    int result = 1;
    int paramIndex = 0;
    int itemCount = arrayListCount(optionsGetParamItemList());

    if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
        if (itemCount > 0) {
            while (result && (paramIndex < itemCount)) {
                result = optionsPrintParam(paramIndex++);
            }
        }
    } else {
        if (itemCount > 0) {
            xsltGenericError(xsltGenericErrorContext, "\n");
            while (result && (paramIndex < itemCount)) {
                result = optionsPrintParam(paramIndex++);
            }
        } else
            xsldbgGenericErrorFunc(i18n("\nNo parameters present.\n"));
    }
    return result;
}


  /**
   * optionsNode:
   * @optionType : Is valid, option to convert to a xmlNodePtr 
   *
   * Convert option into a xmlNodePtr
   *
   * Returns the option @optionType as a xmlNodePtr if successful,
   *          NULL otherwise
   */
xmlNodePtr
optionsNode(OptionTypeEnum optionType)
{
    xmlNodePtr node = NULL;
    char numberBuffer[10];
    int result = 1;

    numberBuffer[0] = '\0';
    if (optionType <= OPTIONS_VERBOSE) {
        /* integer option */
        node = xmlNewNode(NULL, (xmlChar *) "intoption");
        if (node) {
            snprintf(numberBuffer, sizeof(numberBuffer), "%d",
                     optionsGetIntOption(optionType));
            result = result && (xmlNewProp
                                (node, (xmlChar *) "name",
                                 (xmlChar *) optionNames[optionType -
                                                         OPTIONS_XINCLUDE])
                                != NULL);
            if (result)
                result = result && (xmlNewProp(node, (xmlChar *) "value",
                                               (xmlChar *) numberBuffer) !=
                                    NULL);
            if (!result) {
                xmlFreeNode(node);
                node = NULL;
            }

        }
    } else {
        /* string option */
        node = xmlNewNode(NULL, (xmlChar *) "stringoption");
        if (node) {
            result = result && (xmlNewProp
                                (node, (xmlChar *) "name",
                                 (xmlChar *) optionNames[optionType -
                                                         OPTIONS_XINCLUDE])
                                != NULL);
            if (result) {
                if (optionsGetStringOption(optionType))
                    result = result && (xmlNewProp
                                        (node, (xmlChar *) "value",
                                         optionsGetStringOption
                                         (optionType)) != NULL);
                else
                    result = result && (xmlNewProp
                                        (node, (xmlChar *) "value",
                                         (xmlChar *) "") != NULL);
            }

            if (!result) {
                xmlFreeNode(node);
                node = NULL;
            }

        }
    }
    return node;
}


  /**
   * optionsReadDoc:
   * @doc : Is valid xsldbg config document, in the format as indicated 
   *        by config.dtd
   *
   * Read options from document provided. 
   *
   * Returns 1 if able to read @doc and load options found,
   *         0 otherwise
   */
int
optionsReadDoc(xmlDocPtr doc)
{
    int result = 1;
    xmlChar *name, *value;
    int optID;
    xmlNodePtr node;

    /* very primative search for config node
     * we skip the DTD and then go straight to the first child of 
     * config node */
    if (doc && doc->children->next && doc->children->next->children) {
        /* find the first configuration option */
        node = doc->children->next->children;
        while (node && result) {
            if (node->type == XML_ELEMENT_NODE) {
                if (xmlStrCmp(node->name, "intoption") == 0) {
                    name = xmlGetProp(node, (xmlChar *) "name");
                    value = xmlGetProp(node, (xmlChar *) "value");
                    if (name && value && (atoi((char *) value) >= 0)) {
                        optID = lookupName(name, (xmlChar **) optionNames);
                        if (optID >= 0)
                            result =
                                optionsSetIntOption(OptionTypeEnum(optID + OPTIONS_XINCLUDE),
                                                    atoi((char *) value));
                    }
                    if (name)
                        xmlFree(name);
                    if (value)
                        xmlFree(value);
                } else if (xmlStrCmp(node->name, "stringoption") == 0) {
                    name = xmlGetProp(node, (xmlChar *) "name");
                    value = xmlGetProp(node, (xmlChar *) "value");
                    if (name && value) {
                        optID = lookupName(name, (xmlChar **) optionNames);
                        if (optID >= 0)
                            result =
                                optionsSetStringOption(OptionTypeEnum(optID + OPTIONS_XINCLUDE),
                                                       value);
                    }
                    if (name)
                        xmlFree(name);
                    if (value)
                        xmlFree(value);
                }
            }
            node = node->next;
        }
    }
    return result;
}



/**
 * optionsSavetoFile:
 * @fileName : Must be NON NULL be a local file that can be written to
 *
 * Save configuation to file specified
 *
 * Returns 1 if able to save options to @fileName,
 *         0 otherwise
 */
int
optionsSavetoFile(xmlChar * fileName)
{
    int result = 0;
    int optionIndex = 0;
    xmlDocPtr configDoc;
    xmlNodePtr rootNode;
    xmlNodePtr node = NULL;

    if (!fileName) {
#ifdef WITH_XSLDBG_DEBUG_PROCESS
        xsltGenericError(xsltGenericErrorContext,
                         "Error: NULL file name provided\n");
#endif
        return result;
    }

    configDoc = xmlNewDoc((xmlChar *) "1.0");
    rootNode = xmlNewNode(NULL, (xmlChar *) "config");

    if (configDoc && rootNode) {
        xmlCreateIntSubset(configDoc, (xmlChar *) "config", (xmlChar *)
                           "-//xsldbg//DTD config XML V1.0//EN",
                           (xmlChar *) "config.dtd");
        xmlAddChild((xmlNodePtr) configDoc, rootNode);

        /*now to do the work of adding configuration items */
        for (optionIndex = OPTIONS_XINCLUDE;
             optionIndex <= OPTIONS_DATA_FILE_NAME; optionIndex++) {
            result = 1;
            if (optionNames[optionIndex - OPTIONS_XINCLUDE][0] == '*')
                continue;       /* don't save non user options */

            node = optionsNode(OptionTypeEnum(optionIndex));
            if (node)
                xmlAddChild(rootNode, node);
            else {
                result = 0;
                break;
            }
        }

        if (result) {
            /* so far so good, now to serialize it to disk */
            if (!xmlSaveFormatFile((char *) fileName, configDoc, 1))
                result = 0;
        }

        xmlFreeDoc(configDoc);
    } else {

        if (configDoc)
            xmlFreeDoc(configDoc);

        if (rootNode)
            xmlFreeNode(rootNode);

    }

    return result;
}



  /**
   * optionsConfigState:
   * @value : Is valid
   *
   * Set/Get the state of configuration loading/saving
   *
   * Returns The current/new value of configuration flag. Where
   *         @value means:
   *           OPTIONS_CONFIG_READVALUE : No change return current 
   *               value of read configuration flag
   *           OPTIONS_CONFIG_WRITING  : Clear flag and return 
   *               OPTIONS_CONFIG_WRITING which mean configuration 
   *               file is being written
   *           OPTIONS_CONFIG_READING : Set flag and return 
   *               OPTIONS_CONFIG_READING, which means configuration
   *               file is being read
   *           OPTIONS_CONFIG_IDLE : We are neither reading or writing 
   *               configuration and return OPTIONS_CONFIG_IDLE
   */
int
optionsConfigState(OptionsConfigState value)
{
    int result = OPTIONS_CONFIG_IDLE;

    /* work around as some compiler refuse to switch on enums */
    int configValue = value;

    /* hold the current state of configuration reading/writing */
    static int configState = OPTIONS_CONFIG_IDLE;

    switch (configValue) {
        case OPTIONS_CONFIG_READVALUE:
            /* read the current value only */
            result = configState;
            break;

        case OPTIONS_CONFIG_READING:
        case OPTIONS_CONFIG_WRITING:
            /* update the value */
            result = configValue;
            configState = configValue;
            break;
    }

    return result;
}

  /**
   * optionsAddWatch:
   * @xPath : A valid xPath to evaluate in a context and 
   *          has not already been addded
   *
   * Add xPath to be evaluated and printed out each time the debugger stops
   *
   * Returns 1 if able to add xPath to watched
   *         0 otherwise
   */
  int optionsAddWatch(const xmlChar* xPath)
{
  int result = 0;
  if (!xPath || (xmlStrlen(xPath) == 0)){
#ifdef WITH_XSLDBG_DEBUG_PROCESS
           xsltGenericError(xsltGenericErrorContext,
			    "Error: Invalid XPath supplied\n");
#endif
  } else{
    if (optionsGetWatchID(xPath) == 0){
      xmlChar * nameCopy = xmlStrdup(xPath);
      if (nameCopy){
	arrayListAdd(watchExpressionList, nameCopy);
	result = 1;
      }
    }
  }

  return result;
}


  /** 
   * optionsGetWatchID:
   * @xPath : A valid watch expression that has already been added
   *
   * Finds the ID of watch expression previously added
   *
   * Returns 0 if not found, 
   *         otherwise returns the ID of watch expression
   */
  int optionsGetWatchID(const xmlChar* xPath)
{
  int result = 0, counter;
  xmlChar* watchExpression;
  if (!xPath){
#ifdef WITH_XSLDBG_DEBUG_PROCESS
           xsltGenericError(xsltGenericErrorContext,
		       "Error: Invalid xPath supplied\n");
#endif
  } else{
    for ( counter = 0; 
	  counter < arrayListCount(watchExpressionList); 
				   counter++){
      watchExpression = (xmlChar*)arrayListGet(watchExpressionList, counter);
      if (watchExpression){
	if (xmlStrEqual(xPath, watchExpression)){
	  result = counter + 1;
	  break;
	}
      }else{
	break;
      }
    }	    
  }
 
 return result;
}

  /**
   * optionsRemoveWatch:
   * @watchID : A valid watchID as indicated by last optionsPrintWatches
   * @showWarnings : Print more error messages if 1, 
   *                  print less if 0
   *
   * Remove the watch with given ID from our list of expressions to watch
   *
   * Returns 1 if able to remove to watch expression
   *         0 otherwise
   */
  int optionsRemoveWatch(int watchID)
{
  return arrayListDelete(watchExpressionList, watchID - 1);
}

  /**
   * optionsGetWatchList:
   * 
   * Return the current list of expressions to watch
   *
   * Return the current list of expressions to watch
   */
  arrayListPtr optionsGetWatchList()
{
  return watchExpressionList;
}