Add editor modelines; Adjust whitespace as needed.
[metze/wireshark/wip.git] / ui / persfilepath_opt.c
1 /* persfilepath_opt.c
2  * Routines to handle command-line options to set paths for directories
3  * containing personal files (configuration, saved captures)
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <string.h>
27 #include <ctype.h>
28 #include <errno.h>
29
30 #include <glib.h>
31
32 #include <wsutil/filesystem.h>
33
34 #include "ui/persfilepath_opt.h"
35
36 /*
37  * process command line option that affects the paths of the directories
38  * used for personal files (configuration, saved captures)
39  */
40 gboolean
41 persfilepath_opt(int opt _U_, const char *optstr)
42 {
43     gchar *p, *colonp;
44
45     colonp = strchr(optstr, ':');
46     if (colonp == NULL) {
47         return FALSE;
48     }
49
50     p = colonp;
51     *p++ = '\0';
52
53     /*
54     * Skip over any white space (there probably won't be any, but
55     * as we allow it in the preferences file, we might as well
56     * allow it here).
57     */
58     while (isspace((guchar)*p))
59         p++;
60     if (*p == '\0') {
61         /*
62          * Put the colon back, so if our caller uses, in an
63          * error message, the string they passed us, the message
64          * looks correct.
65          */
66         *colonp = ':';
67         return FALSE;
68     }
69
70     /* directory should be existing */
71     /* XXX - is this a requirement? */
72     if(test_for_directory(p) != EISDIR) {
73         /*
74          * Put the colon back, so if our caller uses, in an
75          * error message, the string they passed us, the message
76          * looks correct.
77          */
78         *colonp = ':';
79         return FALSE;
80     }
81
82     if (strcmp(optstr,"persconf") == 0) {
83         set_persconffile_dir(p);
84     } else if (strcmp(optstr,"persdata") == 0) {
85         set_persdatafile_dir(p);
86     } else {
87         /* XXX - might need to add the temp file path */
88         return FALSE;
89     }
90     *colonp = ':'; /* put the colon back */
91     return TRUE;
92 }
93
94 /*
95  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
96  *
97  * Local variables:
98  * c-basic-offset: 4
99  * tab-width: 8
100  * indent-tabs-mode: nil
101  * End:
102  *
103  * vi: set shiftwidth=4 tabstop=8 expandtab:
104  * :indentSize=4:tabSize=8:noTabs=true:
105  */