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 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <cx/string.h>
34 #include <cx/utils.h>
35
36 #include <libidav/utils.h>
37
38 #include "assistant.h"
39
40 char* assistant_getcfg(
const char *cfgname) {
41 cxmutstr line;
42 char *value =
NULL;
43 while(!value) {
44 printf(
"%s: ", cfgname);
45 fflush(stdout);
46 line = util_readline(stdin);
47 if(line.length ==
0 || !line.ptr) {
48 fprintf(stderr,
"%s must be not empty\n", cfgname);
49 continue;
50 }
51
52 value = line.ptr;
53 break;
54 }
55 return value;
56 }
57
58 char* assistant_getoptcfg(
const char *cfgname) {
59 cxmutstr line;
60 char *value =
NULL;
61 while(!value) {
62 printf(
"%s (optional): ", cfgname);
63 fflush(stdout);
64 line = util_readline(stdin);
65 if(line.length ==
0 || !line.ptr) {
66 if(line.ptr) {
67 free(line.ptr);
68 }
69 break;
70 }
71
72 value = line.ptr;
73 break;
74 }
75 return value;
76 }
77
78 char* assistant_gethiddenoptcfg(
const char *cfgname) {
79 printf(
"%s (optional): ", cfgname);
80 fflush(stdout);
81 char *pw = util_password_input(
"");
82 if(pw[
0] ==
0) {
83 free(pw);
84 pw =
NULL;
85 }
86 return pw;
87 }
88
89
90 char* assistant_getdefcfg(
const char *cfgname,
const char *defval) {
91 cxmutstr line;
92 char *value =
NULL;
93 while(!value) {
94 printf(
"%s (default: %s): ", cfgname, defval);
95 fflush(stdout);
96 line = util_readline(stdin);
97 if(line.length ==
0 || !line.ptr) {
98 if(line.ptr) {
99 free(line.ptr);
100 }
101 break;
102 }
103
104 value = line.ptr;
105 break;
106 }
107 return value ? value : strdup(defval);
108 }
109