summaryrefslogtreecommitdiffstats
path: root/kxsldbg/kxsldbgpart/libxsldbg/options_unix.cpp
blob: 27c7d2f1c3cd5bf5870a2134b0f17874172a2ad2 (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

/***************************************************************************
                          options_unix.c  -  *nix specific option functions
                             -------------------
    begin                : Tue Jan 29 2002
    copyright            : (C) 2001 by Keith Isdale
    email                : k_isdale@tpg.com.au
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <libxml/parser.h>
#include <stdlib.h>
#include <string.h>
#include "xsldbg.h"
#include "options.h"

  /**
   * optionsPlatformInit:
   *
   * Intialize the platform specific options module
   *
   *  This is a platform specific interface
   *
   * Returns 1 if sucessful
   *         0 otherwise  
   */
int
optionsPlatformInit(void)
{
    return 1;
}


  /**
   * optionsPlatformFree:
   *
   * Free memory used by the platform specific options module
   *
   *  This is a platform specific interface
   *
   */
void
optionsPlatformFree(void)
{
    /* empty */
}

  /**
   * optionsConfigFileName:
   * 
   * Returns A copy of the file name that will be used to load xsldbgs
   *           configuration from,
   *         NULL otherwise
   */
xmlChar *
optionsConfigFileName(void)
{
    xmlChar *result = NULL;
    const char *homeDir = getenv("HOME");
    const char *configName = "xsldbg.rc";
    int bufferSize = 0;

    if (homeDir) {
        /* give ourselves a bit of room to move */
        bufferSize = strlen(homeDir) + strlen(configName) + 10;
        result = (xmlChar *) xmlMalloc(bufferSize);
        snprintf((char *) result, bufferSize, "%s/%s", homeDir,
                 configName);
    }
    return result;
}


  /**
   * optionsLoad:
   *
   * Load options from configuration file/registry
   *
   * This is a platform specific interface
   * 
   * Returns 1 if able to load options
   *         0 otherwise
   */
int
optionsLoad(void)
{
    int result = 0;
    xmlDocPtr doc = xmlParseFile((char *) optionsConfigFileName());

    if (doc)
        result = optionsReadDoc(doc);
    return 0;
}


  /**
   * optionsSave:
   *
   * Save options to configuration file/registry
   *
   * This is a platform specific interface
   * 
   * Returns 1 if able to save options
   *         0 otherwise
   */
int
optionsSave(void)
{
    return optionsSavetoFile(optionsConfigFileName());
}