Commit | Line | Data |
---|---|---|
f3ed775e DG |
1 | /* |
2 | * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
82a3637f DG |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; only version 2 | |
7 | * of the License. | |
f3ed775e DG |
8 | * |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
19 | #include <stdlib.h> | |
679b4943 | 20 | #include <ctype.h> |
f3ed775e | 21 | |
db758600 | 22 | #include <common/error.h> |
f3ed775e | 23 | |
beb8c75a | 24 | #include "conf.h" |
679b4943 | 25 | #include "utils.h" |
f3ed775e | 26 | |
f3ed775e DG |
27 | /* |
28 | * get_session_name | |
29 | * | |
30 | * Return allocated string with the session name found in the config | |
31 | * directory. | |
32 | */ | |
33 | char *get_session_name(void) | |
34 | { | |
35 | char *path, *session_name = NULL; | |
36 | ||
37 | /* Get path to config file */ | |
58a97671 | 38 | path = config_get_default_path(); |
f3ed775e DG |
39 | if (path == NULL) { |
40 | goto error; | |
41 | } | |
42 | ||
43 | /* Get session name from config */ | |
44 | session_name = config_read_session_name(path); | |
45 | if (session_name == NULL) { | |
58a97671 | 46 | goto error; |
f3ed775e DG |
47 | } |
48 | ||
3183dbb0 | 49 | DBG2("Config file path found: %s", path); |
cd80958d | 50 | DBG("Session name found: %s", session_name); |
f3ed775e | 51 | return session_name; |
3183dbb0 DG |
52 | |
53 | error: | |
54 | return NULL; | |
f3ed775e | 55 | } |
679b4943 SM |
56 | |
57 | ||
58 | /* | |
59 | * list_cmd_options | |
60 | * | |
61 | * Prints a simple list of the options available to a command. This is intended | |
62 | * to be easily parsed for bash completion. | |
63 | */ | |
64 | void list_cmd_options(FILE *ofp, struct poptOption *options) | |
65 | { | |
66 | int i; | |
67 | struct poptOption *option = NULL; | |
68 | ||
69 | for (i = 0; options[i].longName != NULL; i++) { | |
70 | option = &options[i]; | |
71 | ||
72 | fprintf(ofp, "--%s\n", option->longName); | |
73 | ||
74 | if (isprint(option->shortName)) { | |
75 | fprintf(ofp, "-%c\n", option->shortName); | |
76 | } | |
77 | } | |
78 | } |