Use new configuration functions.
Showing
5 changed files
with
20 additions
and
87 deletions
... | @@ -81,7 +81,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -81,7 +81,7 @@ opt_handler (int key, char *arg, void *unused) |
81 | break; | 81 | break; |
82 | 82 | ||
83 | case 'c': | 83 | case 'c': |
84 | changecur = arg[0] == 'y'; | 84 | changecur = is_true(arg); |
85 | break; | 85 | break; |
86 | 86 | ||
87 | case '+': | 87 | case '+': |
... | @@ -98,7 +98,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -98,7 +98,7 @@ opt_handler (int key, char *arg, void *unused) |
98 | break; | 98 | break; |
99 | 99 | ||
100 | case 'T': | 100 | case 'T': |
101 | truncate_source = arg[0] == 'y'; | 101 | truncate_source = is_true(arg); |
102 | break; | 102 | break; |
103 | 103 | ||
104 | case 'w': | 104 | case 'w': |
... | @@ -243,7 +243,7 @@ main (int argc, char **argv) | ... | @@ -243,7 +243,7 @@ main (int argc, char **argv) |
243 | } | 243 | } |
244 | 244 | ||
245 | if (changecur) | 245 | if (changecur) |
246 | mh_save_context (); | 246 | mh_global_save_state (); |
247 | 247 | ||
248 | mailbox_close (output); | 248 | mailbox_close (output); |
249 | mailbox_destroy (&output); | 249 | mailbox_destroy (&output); | ... | ... |
... | @@ -97,7 +97,7 @@ mh_argp_parse (int argc, char **argv, | ... | @@ -97,7 +97,7 @@ mh_argp_parse (int argc, char **argv, |
97 | data.handler = handler; | 97 | data.handler = handler; |
98 | data.doc = argp_doc; | 98 | data.doc = argp_doc; |
99 | 99 | ||
100 | p = mh_profile_value (program_invocation_short_name, NULL); | 100 | p = mh_global_profile_get (program_invocation_short_name, NULL); |
101 | if (p) | 101 | if (p) |
102 | { | 102 | { |
103 | int _argc; | 103 | int _argc; | ... | ... |
... | @@ -23,12 +23,6 @@ | ... | @@ -23,12 +23,6 @@ |
23 | #include <sys/stat.h> | 23 | #include <sys/stat.h> |
24 | #include <stdarg.h> | 24 | #include <stdarg.h> |
25 | 25 | ||
26 | char *current_folder = NULL; | ||
27 | size_t current_message = 0; | ||
28 | mh_context_t *context; | ||
29 | mh_context_t *profile; | ||
30 | mh_context_t *sequences; | ||
31 | |||
32 | char mh_list_format[] = | 26 | char mh_list_format[] = |
33 | "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>" | 27 | "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>" |
34 | "%02(mon{date})/%02(mday{date})" | 28 | "%02(mon{date})/%02(mday{date})" |
... | @@ -61,70 +55,8 @@ mh_init () | ... | @@ -61,70 +55,8 @@ mh_init () |
61 | void | 55 | void |
62 | mh_init2 () | 56 | mh_init2 () |
63 | { | 57 | { |
64 | char *mh_sequences_name; | 58 | mh_current_folder (); |
65 | char *seq_name, *ctx_name; | 59 | mh_global_sequences_get ("cur", NULL); |
66 | char *p; | ||
67 | |||
68 | mu_path_folder_dir = mh_get_dir (); | ||
69 | p = getenv ("CONTEXT"); | ||
70 | if (!p) | ||
71 | p = "context"; | ||
72 | ctx_name = mh_expand_name (p, 0); | ||
73 | context = mh_context_create (ctx_name, 1); | ||
74 | mh_context_read (context); | ||
75 | |||
76 | if (current_folder) | ||
77 | current_folder = mu_tilde_expansion (current_folder, "/", NULL); | ||
78 | else | ||
79 | current_folder = mh_context_get_value (context, "Current-Folder", | ||
80 | mh_profile_value ("Inbox", | ||
81 | "inbox")); | ||
82 | |||
83 | mh_sequences_name = mh_profile_value ("mh-sequences", MH_SEQUENCES_FILE); | ||
84 | p = mh_expand_name (current_folder, 0); | ||
85 | asprintf (&seq_name, "%s/%s", p, mh_sequences_name); | ||
86 | free (p); | ||
87 | sequences = mh_context_create (seq_name, 1); | ||
88 | if (mh_context_read (sequences) == 0) | ||
89 | { | ||
90 | p = mh_context_get_value (sequences, "cur", "0"); | ||
91 | current_message = strtoul (p, NULL, 10); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | char * | ||
96 | mh_profile_value (char *name, char *defval) | ||
97 | { | ||
98 | return mh_context_get_value (profile, name, defval); | ||
99 | } | ||
100 | |||
101 | void | ||
102 | mh_read_profile () | ||
103 | { | ||
104 | char *p; | ||
105 | |||
106 | p = getenv ("MH"); | ||
107 | if (p) | ||
108 | p = mu_tilde_expansion (p, "/", NULL); | ||
109 | else | ||
110 | { | ||
111 | char *home = mu_get_homedir (); | ||
112 | if (!home) | ||
113 | abort (); /* shouldn't happen */ | ||
114 | asprintf (&p, "%s/%s", home, MH_USER_PROFILE); | ||
115 | free (home); | ||
116 | } | ||
117 | profile = mh_context_create (p, 1); | ||
118 | mh_context_read (profile); | ||
119 | } | ||
120 | |||
121 | void | ||
122 | mh_save_context () | ||
123 | { | ||
124 | char buf[64]; | ||
125 | snprintf (buf, sizeof buf, "%d", current_message); | ||
126 | mh_context_set_value (sequences, "cur", buf); | ||
127 | mh_context_write (sequences); | ||
128 | } | 60 | } |
129 | 61 | ||
130 | int | 62 | int |
... | @@ -207,7 +139,7 @@ mh_is_my_name (char *name) | ... | @@ -207,7 +139,7 @@ mh_is_my_name (char *name) |
207 | } | 139 | } |
208 | 140 | ||
209 | int | 141 | int |
210 | mh_check_folder (char *pathname) | 142 | mh_check_folder (char *pathname, int confirm) |
211 | { | 143 | { |
212 | char *p; | 144 | char *p; |
213 | struct stat st; | 145 | struct stat st; |
... | @@ -221,10 +153,10 @@ mh_check_folder (char *pathname) | ... | @@ -221,10 +153,10 @@ mh_check_folder (char *pathname) |
221 | { | 153 | { |
222 | if (errno == ENOENT) | 154 | if (errno == ENOENT) |
223 | { | 155 | { |
224 | if (mh_getyn ("Create folder \"%s\"", p)) | 156 | if (!confirm || mh_getyn ("Create folder \"%s\"", p)) |
225 | { | 157 | { |
226 | int perm = 0711; | 158 | int perm = 0711; |
227 | char *pb = mh_profile_value ("Folder-Protect", NULL); | 159 | char *pb = mh_global_profile_get ("Folder-Protect", NULL); |
228 | if (pb) | 160 | if (pb) |
229 | perm = strtoul (pb, NULL, 8); | 161 | perm = strtoul (pb, NULL, 8); |
230 | if (mkdir (p, perm)) | 162 | if (mkdir (p, perm)) |
... | @@ -354,7 +286,7 @@ mh_open_folder (const char *folder, int create) | ... | @@ -354,7 +286,7 @@ mh_open_folder (const char *folder, int create) |
354 | int flags = MU_STREAM_READ; | 286 | int flags = MU_STREAM_READ; |
355 | 287 | ||
356 | name = mh_expand_name (folder, 1); | 288 | name = mh_expand_name (folder, 1); |
357 | if (create && mh_check_folder (name)) | 289 | if (create && mh_check_folder (name, 1)) |
358 | exit (0); | 290 | exit (0); |
359 | 291 | ||
360 | if (mailbox_create_default (&mbox, name)) | 292 | if (mailbox_create_default (&mbox, name)) |
... | @@ -381,7 +313,7 @@ mh_open_folder (const char *folder, int create) | ... | @@ -381,7 +313,7 @@ mh_open_folder (const char *folder, int create) |
381 | char * | 313 | char * |
382 | mh_get_dir () | 314 | mh_get_dir () |
383 | { | 315 | { |
384 | char *mhdir = mh_profile_value ("Path", "Mail"); | 316 | char *mhdir = mh_global_profile_get ("Path", "Mail"); |
385 | if (mhdir[0] != '/') | 317 | if (mhdir[0] != '/') |
386 | { | 318 | { |
387 | char *p = mu_get_homedir (); | 319 | char *p = mu_get_homedir (); | ... | ... |
... | @@ -27,8 +27,8 @@ static char args_doc[] = "messages folder [folder...]"; | ... | @@ -27,8 +27,8 @@ static char args_doc[] = "messages folder [folder...]"; |
27 | static struct argp_option options[] = { | 27 | static struct argp_option options[] = { |
28 | {"folder", 'f', "FOLDER", 0, "Specify folder to operate upon"}, | 28 | {"folder", 'f', "FOLDER", 0, "Specify folder to operate upon"}, |
29 | {"draft", 'd', NULL, 0, "Use <mh-dir>/draft as the source message"}, | 29 | {"draft", 'd', NULL, 0, "Use <mh-dir>/draft as the source message"}, |
30 | {"link", 'l', "BOOL", OPTION_ARG_OPTIONAL, "Preserve the source folder copy"}, | 30 | {"link", 'l', "BOOL", OPTION_ARG_OPTIONAL, "(not implemented) Preserve the source folder copy"}, |
31 | {"preserve", 'p', "BOOL", OPTION_ARG_OPTIONAL, "Try to preserve message sequence numbers"}, | 31 | {"preserve", 'p', "BOOL", OPTION_ARG_OPTIONAL, "(not implemented) Try to preserve message sequence numbers"}, |
32 | {"source", 's', "FOLDER", 0, "Specify source folder. FOLDER will became the current folder after the program exits."}, | 32 | {"source", 's', "FOLDER", 0, "Specify source folder. FOLDER will became the current folder after the program exits."}, |
33 | {"src", 0, NULL, OPTION_ALIAS, NULL}, | 33 | {"src", 0, NULL, OPTION_ALIAS, NULL}, |
34 | {"file", 'F', "FILE", 0, "Use FILE as the source message"}, | 34 | {"file", 'F', "FILE", 0, "Use FILE as the source message"}, |
... | @@ -136,11 +136,11 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -136,11 +136,11 @@ opt_handler (int key, char *arg, void *unused) |
136 | break; | 136 | break; |
137 | 137 | ||
138 | case 'l': | 138 | case 'l': |
139 | link_flag = arg[0] == 'y'; | 139 | link_flag = is_true(arg); |
140 | break; | 140 | break; |
141 | 141 | ||
142 | case 'p': | 142 | case 'p': |
143 | preserve_flag = arg[0] == 'y'; | 143 | preserve_flag = is_true(arg); |
144 | break; | 144 | break; |
145 | 145 | ||
146 | case 's': | 146 | case 's': |
... | @@ -158,7 +158,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -158,7 +158,7 @@ opt_handler (int key, char *arg, void *unused) |
158 | } | 158 | } |
159 | 159 | ||
160 | void | 160 | void |
161 | _close_folder (void *unuses, mailbox_t mbox) | 161 | _close_folder (void *unused, mailbox_t mbox) |
162 | { | 162 | { |
163 | mailbox_close (mbox); | 163 | mailbox_close (mbox); |
164 | mailbox_destroy (&mbox); | 164 | mailbox_destroy (&mbox); | ... | ... |
... | @@ -82,7 +82,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -82,7 +82,7 @@ opt_handler (int key, char *arg, void *unused) |
82 | break; | 82 | break; |
83 | 83 | ||
84 | case 'c': | 84 | case 'c': |
85 | clear = arg[0] == 'y'; | 85 | clear = is_true(arg); |
86 | break; | 86 | break; |
87 | 87 | ||
88 | case 'F': | 88 | case 'F': |
... | @@ -94,7 +94,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -94,7 +94,7 @@ opt_handler (int key, char *arg, void *unused) |
94 | break; | 94 | break; |
95 | 95 | ||
96 | case 'H': | 96 | case 'H': |
97 | header = arg[0] == 'y'; | 97 | header = is_true(arg); |
98 | break; | 98 | break; |
99 | 99 | ||
100 | case 'w': | 100 | case 'w': |
... | @@ -107,7 +107,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -107,7 +107,7 @@ opt_handler (int key, char *arg, void *unused) |
107 | break; | 107 | break; |
108 | 108 | ||
109 | case 'r': | 109 | case 'r': |
110 | reverse = arg[0] == 'y'; | 110 | reverse = is_true(arg); |
111 | break; | 111 | break; |
112 | 112 | ||
113 | case 'i': | 113 | case 'i': |
... | @@ -210,6 +210,7 @@ scan (mailbox_t mbox) | ... | @@ -210,6 +210,7 @@ scan (mailbox_t mbox) |
210 | for (i = 1; i <= total; i++) | 210 | for (i = 1; i <= total; i++) |
211 | list_message (mbox, i, buffer, width); | 211 | list_message (mbox, i, buffer, width); |
212 | clear_screen (); | 212 | clear_screen (); |
213 | mh_global_save_state (); | ||
213 | return 0; | 214 | return 0; |
214 | } | 215 | } |
215 | 216 | ... | ... |
-
Please register or sign in to post a comment