~ubuntu-branches/ubuntu/raring/lurker/raring

« back to all changes in this revision

Viewing changes to index/params.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Meurer
  • Date: 2004-09-26 16:27:51 UTC
  • Revision ID: james.westby@ubuntu.com-20040926162751-z1ohcjltv7ojtg6z
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: params.cpp,v 1.11 2004/08/27 17:53:44 terpstra Exp $
 
2
 *  
 
3
 *  params.cpp - Parse the config file for helper scripts
 
4
 *  
 
5
 *  Copyright (C) 2002 - Wesley W. Terpstra
 
6
 *  
 
7
 *  License: GPL
 
8
 *  
 
9
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 
10
 *  
 
11
 *    This program is free software; you can redistribute it and/or modify
 
12
 *    it under the terms of the GNU General Public License as published by
 
13
 *    the Free Software Foundation; version 2.
 
14
 *    
 
15
 *    This program is distributed in the hope that it will be useful,
 
16
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *    GNU General Public License for more details.
 
19
 *    
 
20
 *    You should have received a copy of the GNU General Public License
 
21
 *    along with this program; if not, write to the Free Software
 
22
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 */
 
24
 
 
25
#define _XOPEN_SOURCE 500
 
26
#define _FILE_OFFSET_BITS 64
 
27
 
 
28
#include <ConfigFile.h>
 
29
 
 
30
#include <iostream>
 
31
#include <vector>
 
32
 
 
33
#include <unistd.h>
 
34
 
 
35
using namespace std;
 
36
 
 
37
void help(const char* name)
 
38
{
 
39
        cerr << "Lurker-params (v" << VERSION << ") parses params from the config file.\n";
 
40
        cerr << "\n";
 
41
        cerr << "Usage: " << name << " -c <config-file> -f <locale>\n";
 
42
        cerr << "                         [-d -a -n -e -x -m -i -w -h -r -g]\n";
 
43
        cerr << "\n";
 
44
        cerr << "\t-c <config-file> Use this config file for lurker settings\n";
 
45
        cerr << "\t-f <locale>      Output the fields for this locale\n";
 
46
        cerr << "\t-d               Output only the dbdir parameter\n";
 
47
        cerr << "\t-a               Output only the archive parameter\n";
 
48
        cerr << "\t-n               Output only the administrator name\n";
 
49
        cerr << "\t-e               Output only the administrator email address\n";
 
50
        cerr << "\t-x               Output only the xslt processing command\n";
 
51
        cerr << "\t-m               Output only the mime pgp verifying command\n";
 
52
        cerr << "\t-i               Output only the inline pgp verifying command\n";
 
53
        cerr << "\t-w               Output only the web_cache state\n";
 
54
        cerr << "\t-h               Output only the hide_email state\n";
 
55
        cerr << "\t-r               Output only the raw_email state\n";
 
56
        cerr << "\t-g               Output only the regroupable state\n";
 
57
        cerr << "\n";
 
58
        cerr << "Output various lurker settings from the config file for use in shell scripts.\n";
 
59
        cerr << "Do not use sed/grep/etc, instead use this as it respects include.\n";
 
60
        cerr << "\n";
 
61
}
 
62
 
 
63
int main(int argc, char** argv)
 
64
{
 
65
        int c;
 
66
        
 
67
        const char* config        = 0;
 
68
        int         fields        = 0;
 
69
        bool        dbdir         = false;
 
70
        bool        archive       = false;
 
71
        bool        admin_name    = false;
 
72
        bool        admin_address = false;
 
73
        bool        xslt          = false;
 
74
        bool        pgpv_mime     = false;
 
75
        bool        pgpv_inline   = false;
 
76
        bool        web_cache     = false;
 
77
        bool        hide_email    = false;
 
78
        bool        raw_email     = false;
 
79
        bool        regroupable   = false;
 
80
        string lc;
 
81
        
 
82
        while ((c = getopt(argc, (char*const*)argv, "c:f:danexmiwhrg?")) != -1)
 
83
        {
 
84
                switch ((char)c)
 
85
                {
 
86
                case 'c':
 
87
                        config = optarg;
 
88
                        break;
 
89
                case 'f':
 
90
                        lc = optarg;
 
91
                        break;
 
92
                case 'd':
 
93
                        ++fields;
 
94
                        dbdir = true;
 
95
                        break;
 
96
                case 'a':
 
97
                        ++fields;
 
98
                        archive = true;
 
99
                        break;
 
100
                case 'n':
 
101
                        ++fields;
 
102
                        admin_name = true;
 
103
                        break;
 
104
                case 'e':
 
105
                        ++fields;
 
106
                        admin_address = true;
 
107
                        break;
 
108
                case 'x':
 
109
                        ++fields;
 
110
                        xslt = true;
 
111
                        break;
 
112
                case 'm':
 
113
                        ++fields;
 
114
                        pgpv_mime = true;
 
115
                        break;
 
116
                case 'i':
 
117
                        ++fields;
 
118
                        pgpv_inline = true;
 
119
                        break;
 
120
                case 'w':
 
121
                        ++fields;
 
122
                        web_cache = true;
 
123
                        break;
 
124
                case 'h':
 
125
                        ++fields;
 
126
                        hide_email = true;
 
127
                        break;
 
128
                case 'r':
 
129
                        ++fields;
 
130
                        raw_email = true;
 
131
                        break;
 
132
                case 'g':
 
133
                        ++fields;
 
134
                        regroupable = true;
 
135
                        break;
 
136
                default:
 
137
                        help(argv[0]);
 
138
                        return 1;
 
139
                }
 
140
        }
 
141
        
 
142
        if (!config || optind < argc)
 
143
        {
 
144
                help(argv[0]);
 
145
                return 1;
 
146
        }
 
147
        
 
148
        if (fields >= 2)
 
149
        {
 
150
                cerr << "Please either retrieval all fields or exactly one.\n";
 
151
                return 1;
 
152
        }
 
153
        
 
154
        Config cfg;
 
155
        if (cfg.load(config) != 0)
 
156
        {
 
157
                cerr << cfg.getError() << flush;
 
158
                return 1;
 
159
        }
 
160
        
 
161
        if (!fields || dbdir)         cout << cfg.dbdir         << "\n";
 
162
        if (!fields || archive)       cout << cfg.archive(lc)   << "\n";
 
163
        if (!fields || admin_name)    cout << cfg.admin_name(lc)<< "\n";
 
164
        if (!fields || admin_address) cout << cfg.admin_address << "\n";
 
165
        if (!fields || xslt)          cout << cfg.xslt          << "\n";
 
166
        if (!fields || pgpv_mime)     cout << cfg.pgpv_mime     << "\n";
 
167
        if (!fields || pgpv_inline)   cout << cfg.pgpv_inline   << "\n";
 
168
        if (!fields || web_cache)     cout << (cfg.web_cache?"on":"off") << "\n";
 
169
        if (!fields || hide_email)    cout << (cfg.hide_email?"on":"off") << "\n";
 
170
        if (!fields || raw_email)     cout << (cfg.raw_email?"on":"off") << "\n";
 
171
        if (!fields || regroupable)   cout << (cfg.regroupable?"on":"off") << "\n";
 
172
        
 
173
        return 0;
 
174
}