1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: arg.c 900 2008-01-05 01:13:26Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2020 Eduardo Chappa
8 * Copyright 2006-2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 /*======================================================================
20 Command line argument parsing functions
26 #include "../pith/state.h"
27 #include "../pith/init.h"
28 #include "../pith/conf.h"
29 #include "../pith/list.h"
30 #include "../pith/util.h"
31 #include "../pith/help.h"
36 #include "xoauth2conf.h"
38 int process_debug_str(char *);
39 void args_add_attach(PATMT
**, char *, int);
40 int pinerc_cmdline_opt(char *);
41 void display_config_options(char *, char *);
43 extern char configoptions
[];
46 * Name started as to invoke function key mode
48 #define ALPINE_FKEY_NAME "alpinef"
51 * Various error and informational strings..
53 /* TRANSLATORS: This is a list of errors printed when something goes wrong
54 early on with the argument list. Be careful not to change literal
55 option names mentioned in the strings. */
56 static char args_err_missing_pinerc
[] = N_("missing argument for option \"-pinerc\" (use - for standard out)");
57 #if defined(DOS) || defined(OS2)
58 static char args_err_missing_aux
[] = N_("missing argument for option \"-aux\"");
61 static char args_err_missing_smimedir
[] = N_("missing argument for option \"-smimedir\"");
62 static char args_err_non_abs_smimedir
[] = N_("argument to \"-smimedir\" should be fully-qualified");
65 static char args_err_missing_passfile
[] = N_("missing argument for option \"-passfile\"");
66 static char args_err_non_abs_passfile
[] = N_("argument to \"-passfile\" should be fully-qualified");
68 static char args_err_missing_pwdcertdir
[] = N_("missing argument for option \"-pwdcertdir\"");
69 static char args_err_non_abs_pwdcertdir
[] = N_("argument to \"-pwdcertdir\" should be fully-qualified");
70 #endif /* SMIME inside PASSFILE */
72 static char args_err_missing_sort
[] = N_("missing argument for option \"-sort\"");
73 static char args_err_missing_flag_arg
[] = N_("missing argument for flag \"%c\"");
74 static char args_err_missing_flag_num
[] = N_("Non numeric argument for flag \"%c\"");
75 static char args_err_missing_debug_num
[] = N_("Non numeric argument for \"%s\"");
76 static char args_err_missing_url
[] = N_("missing URL for \"-url\"");
77 static char args_err_missing_attachment
[] = N_("missing attachment for \"%s\"");
78 static char args_err_conflict
[] = N_("conflicting action: \"%s\"");
79 static char args_err_unknown
[] = N_("unknown flag \"%c\"");
80 static char args_err_I_error
[] = N_("-I argument \"%s\": %s");
81 static char args_err_d_error
[] = N_("-d argument \"%s\": %s");
82 static char args_err_internal
[] = "%s";
83 static char args_err_missing_copyprc
[] = N_("missing argument for option \"-copy_pinerc\"\nUsage: pine -copy_pinerc <local_pinerc> <remote_pinerc>");
84 static char args_err_missing_copyabook
[] = N_("missing argument for option \"-copy_abook\"\nUsage: pine -copy_abook <local_abook> <remote_abook>");
85 static char args_err_missing_server_name
[] = N_("missing server name. Example: -xoauth2-server Gmail");
86 static char args_err_missing_client_id
[] = N_("missing client-id name. Example: -xoauth2-client-id 760.someserver.com");
87 static char args_err_missing_client_secret
[] = N_("missing client-secret name. Example: -xoauth2-client-secret V56i0fa_");
88 static char args_err_missing_tenant
[] = N_("missing tenant value. Example: -xoauth2-tenant common");
89 static char args_err_missing_user
[] = N_("missing username value. Example: -xoauth2-user user@example.com");
90 static char args_err_missing_xoauth_option
[] = N_("at least one of the arguments -xoauth2-server, or -xoauth2-client-id, xoauth2-tenant, or -xoauth2-client-secret is missing.");
92 static char *args_pine_args
[] = {
93 N_("Possible Starting Arguments for Alpine program:"),
95 N_(" Argument\tMeaning"),
96 N_(" <addrs>...\tGo directly into composer sending to given address"),
97 N_("\t\tList multiple addresses with a single space between them."),
98 N_("\t\tStandard input redirection is allowed with addresses."),
99 N_("\t\tNote: Places addresses in the \"To\" field only."),
100 N_(" -attach <file>\tGo directly into composer with given file"),
101 N_(" -attachlist <file-list>"),
102 N_(" -attach_and_delete <file>"),
103 N_("\t\tGo to composer, attach file, delete when finished"),
104 N_("\t\tNote: Attach options can't be used if -f, -F"),
105 N_("\t\tadded to Attachment list. Attachlist must be the last"),
106 N_("\t\toption on the command line"),
107 N_(" -bail\t\tExit if pinerc file doesn't already exist"),
109 N_(" -d n\t\tDebug - set debug level to 'n', or use the following:"),
110 N_(" -d keywords...\tflush,timestamp,imap=0..4,tcp,numfiles=0..31,verbose=0..9"),
112 N_(" -f <folder>\tFolder - give folder name to open"),
113 N_(" -c <number>\tContext - which context to apply to -f arg"),
114 N_(" -F <file>\tFile - give file name to open and page through and"),
115 N_("\t\tforward as email."),
116 N_(" -h \t\tHelp - give this list of options"),
117 N_(" -k \t\tKeys - Force use of function keys"),
118 N_(" -z \t\tSuspend - allow use of ^Z suspension"),
119 N_(" -r \t\tRestricted - can only send mail to oneself"),
120 N_(" -sort <sort>\tSort - Specify sort order of folder:"),
121 N_("\t\t\tarrival, subject, threaded, orderedsubject, date,"),
122 N_("\t\t\tfrom, size, score, to, cc, /reverse"),
123 N_(" -i\t\tIndex - Go directly to index, bypassing main menu"),
124 N_(" -I <keystroke_list> Initial keystrokes to be executed"),
125 N_(" -n <number>\tEntry in index to begin on"),
126 N_(" -o \t\tReadOnly - Open first folder read-only"),
127 N_(" -conf\t\tConfiguration - Print out fresh global configuration. The"),
128 N_("\t\tvalues of your global configuration affect all Alpine users"),
129 N_("\t\ton your system unless they have overridden the values in their"),
130 N_("\t\tpinerc files."),
131 N_(" -pinerc <file>\tConfiguration - Put fresh pinerc configuration in <file>"),
132 N_(" -p <pinerc>\tUse alternate .pinerc file"),
133 #if !defined(DOS) && !defined(OS2)
134 N_(" -P <pine.conf>\tUse alternate pine.conf file"),
136 N_(" -aux <aux_files_dir>\tUse this with remote pinerc"),
137 N_(" -P <pine.conf>\tUse pine.conf file for default settings"),
138 N_(" -nosplash \tDisable the PC-Alpine splash screen"),
141 #if defined(APPLEKEYCHAIN) || (WINCRED > 0)
142 N_(" -erase_stored_passwords\tEliminate any stored passwords"),
146 N_(" -smimedir <fully_qualified_path>\tdirectory where smime personal certificates are saved"),
150 N_(" -passfile <fully_qualified_filename>\tSet the password file to something other"),
151 N_("\t\tthan the default"),
153 N_(" -pwdcertdir <fully_qualified_path>\tSet the directory to store a personal"),
154 N_("\t\tkey and certificate to encrypt and decrypt your password file."),
155 #endif /* SMIME inside PASSFILE */
156 #endif /* PASSFILE */
158 #ifdef LOCAL_PASSWD_CACHE
159 N_(" -nowrite_password_cache\tRead from a password cache if there is one, but"),
160 N_("\t\t\t\tnever offer to write a password to the cache"),
161 #endif /* LOCAL_PASSWD_CACHE */
163 N_(" -x <config>\tUse configuration exceptions in <config>."),
164 N_("\t\tExceptions are used to override your default pinerc"),
165 N_("\t\tsettings for a particular platform, can be a local file or"),
166 N_("\t\ta remote folder."),
167 N_(" -v \t\tVersion - show version information"),
168 N_(" -version\tVersion - show version information"),
169 N_(" -supported\tList supported options"),
170 N_(" -url <url>\tOpen the given URL"),
171 N_("\t\tNote: Can't be used if -f, -F"),
172 N_("\t\tStandard input redirection is not allowed with URLs."),
173 N_("\t\tFor mailto URLs, 'body='text should be used in place of"),
174 N_("\t\tinput redirection."),
175 N_(" -copy_pinerc <local_pinerc> <remote_pinerc> copy local pinerc to remote"),
176 N_(" -copy_abook <local_abook> <remote_abook> copy local addressbook to remote"),
177 N_(" -convert_sigs -p <pinerc> convert signatures to literal signatures"),
178 #if defined(_WINDOWS)
179 N_(" -install \tPrompt for some basic setup information"),
180 N_(" -uninstall \tRemove traces of Alpine from Windows system settings"),
181 N_(" -registry <cmd>\tWhere cmd is set,noset,clear,clearsilent,dump"),
183 N_(" -xoauth2-server <value>"),
184 N_(" -xoauth2-client-id <value>"),
185 N_(" -xoauth2-client-secret <value>"),
186 N_("\tNote: All of -xoauth options above must be used, if any of them is used"),
187 " -<option>=<value> Assign <value> to the pinerc option <option>",
188 "\t\t e.g. -signature-file=sig1",
189 "\t\t e.g. -color-style=no-color",
190 "\t\t e.g. -feature-list=enable-sigdashes",
191 "\t\t Note: feature-list is additive.",
192 "\t\t You may leave off the \"feature-list=\" part of that,",
193 "\t\t e.g. -enable-sigdashes",
198 display_config_options(char *configopts
, char *defprefix
)
200 char *copts
= configopts
? cpystr(configopts
) : NULL
;
201 char **options
= NULL
;
202 char *s
, *t
, *prefix
;
203 int len
, nlines
, pending
;
205 for(nlines
= 0, s
= copts
; s
!= NULL
; nlines
++){
209 options
= fs_get((nlines
/2 + 4)*sizeof(char *)); /* 4 in worst case scenario */
210 memset((void *) options
, 0, (nlines
/2 + 4)*sizeof(char *));
211 for(s
= copts
, len
= 0, nlines
= 0; s
!= NULL
; ){
213 prefix
= len
== 0 ? (nlines
== 0 ? defprefix
: " ") : " ";
214 if((s
= strchr(s
, '\'')) != NULL
){
215 t
= strchr(s
+1, '\'');
217 if(!strncmp(s
+1, "CFLAGS=", 7)
218 || !strncmp(s
+1, "CC=", 3)
219 || !strncmp(s
+1, "LIBS=", 5)
220 || !strncmp(s
+1, "CPP=", 4)
221 || !strncmp(s
+1, "CPPFLAGS=", 9)
222 || !strncmp(s
+1, "LT_SYS_LIBRARY_PATH=", 20)
223 || !strncmp(s
+1, "LDFLAGS=", 8)){
224 display_args_err(s
+1, NULL
, 0);
229 if(len
+ strlen(prefix
) + strlen(s
+1) > 74 ){
231 options
[nlines
] = fs_get((strlen(prefix
) + strlen(s
+1) + 3)*sizeof(char));
232 sprintf(options
[nlines
++], "%s%s \\", prefix
, s
+1);
235 strcat(options
[nlines
++], " \\");
242 options
[nlines
] = fs_get(76*sizeof(char));
243 *options
[nlines
] = '\0';
245 strcat(options
[nlines
], prefix
);
246 strcat(options
[nlines
], s
+1);
247 len
= strlen(options
[nlines
]);
252 s
= t
? t
+ 1 : NULL
;
255 display_args_err(NULL
, options
, 0);
256 free_list_array(&options
);
257 fs_give((void **) &copts
);
261 * Parse the command line args.
263 * Args: pine_state -- The pine_state structure to put results in
264 * argc, argv -- The obvious
265 * addrs -- Pointer to address list that we set for caller
267 * Result: command arguments parsed
268 * possible printing of help for command line
269 * various flags in pine_state set
270 * returns the string name of the first folder to open
274 pine_args(struct pine
*pine_state
, int argc
, char **argv
, ARGDATA_S
*args
)
280 char *cmd_list
= NULL
;
281 char *debug_str
= NULL
;
283 char *pinerc_file
= NULL
;
290 int do_can_suspend
= 0;
292 struct variable
*vars
= pine_state
->vars
;
296 memset(args
, 0, sizeof(ARGDATA_S
));
297 args
->action
= aaFolder
;
298 memset((void *) &x
, 0, sizeof(XOAUTH2_INFO_S
));
300 pine_state
->pine_name
= (lc
= last_cmpnt(argv
[0])) ? lc
: (lc
= argv
[0]);
302 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%.*s", pine_state
->pine_name
- argv
[0], argv
[0]);
303 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
304 pine_state
->pine_dir
= cpystr(tmp_20k_buf
);
307 /* while more arguments with leading - */
308 Loop
: while(--ac
> 0)
310 /* while more chars in this argument */
312 /* check for pinerc options */
313 if(pinerc_cmdline_opt(*av
)){
314 goto Loop
; /* done with this arg, go to next */
316 /* then other multi-char options */
317 else if(strcmp(*av
, "conf") == 0){
319 goto Loop
; /* done with this arg, go to next */
321 else if(strcmp(*av
, "pinerc") == 0){
325 display_args_err(_(args_err_missing_pinerc
), NULL
, 1);
331 #if defined(DOS) || defined(OS2)
332 else if(strcmp(*av
, "aux") == 0){
334 if((str
= *++av
) != NULL
)
335 pine_state
->aux_files_dir
= cpystr(str
);
338 display_args_err(_(args_err_missing_aux
), NULL
, 1);
344 else if(strcmp(*av
, "nosplash") == 0)
345 goto Loop
; /* already taken care of in WinMain */
348 #if defined(APPLEKEYCHAIN) || (WINCRED > 0)
349 else if(strcmp(*av
, "erase_stored_passwords") == 0){
351 erase_windows_credentials();
353 macos_erase_keychain();
357 #endif /* defined(APPLEKEYCHAIN) || (WINCRED > 0) */
360 else if(strcmp(*av
, "smimedir") == 0){
362 if((str
= *++av
) != NULL
){
363 if(!is_absolute_path(str
)){
364 display_args_err(_(args_err_non_abs_smimedir
),
369 if(pine_state
->smimedir
)
370 fs_give((void **)&pine_state
->smimedir
);
372 pine_state
->smimedir
= cpystr(str
);
377 display_args_err(_(args_err_missing_smimedir
), NULL
, 1);
385 else if(strcmp(*av
, "passfile") == 0){
387 if((str
= *++av
) != NULL
){
388 if(!is_absolute_path(str
)){
389 display_args_err(_(args_err_non_abs_passfile
),
394 if(pine_state
->passfile
)
395 fs_give((void **)&pine_state
->passfile
);
397 pine_state
->passfile
= cpystr(str
);
402 display_args_err(_(args_err_missing_passfile
), NULL
, 1);
409 else if(strcmp(*av
, "pwdcertdir") == 0){
411 if((str
= *++av
) != NULL
){
412 if(!is_absolute_path(str
)){
413 display_args_err(_(args_err_non_abs_pwdcertdir
),
418 if(pine_state
->pwdcertdir
)
419 fs_give((void **)&pine_state
->pwdcertdir
);
421 pine_state
->pwdcertdir
= cpystr(str
);
426 display_args_err(_(args_err_missing_pwdcertdir
), NULL
, 1);
432 #endif /* SMIME inside PASSFILE */
433 #endif /* PASSFILE */
435 #ifdef LOCAL_PASSWD_CACHE
436 else if(strcmp(*av
, "nowrite_password_cache") == 0){
437 ps_global
->nowrite_password_cache
= 1;
440 #endif /* LOCAL_PASSWD_CACHE */
442 else if(strcmp(*av
, "convert_sigs") == 0){
443 ps_global
->convert_sigs
= 1;
446 else if(strcmp(*av
, "supported") == 0){
447 ps_global
->dump_supported_options
= 1;
450 else if(strcmp(*av
, "copy_pinerc") == 0){
451 if(args
->action
== aaFolder
&& !args
->data
.folder
){
452 args
->action
= aaPrcCopy
;
455 args
->data
.copy
.local
= *++av
;
456 args
->data
.copy
.remote
= *++av
;
459 display_args_err(_(args_err_missing_copyprc
), NULL
, 1);
464 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-copy_pinerc");
465 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
466 display_args_err(tmp_20k_buf
, NULL
, 1);
472 else if(strcmp(*av
, "copy_abook") == 0){
473 if(args
->action
== aaFolder
&& !args
->data
.folder
){
474 args
->action
= aaAbookCopy
;
477 args
->data
.copy
.local
= *++av
;
478 args
->data
.copy
.remote
= *++av
;
481 display_args_err(_(args_err_missing_copyabook
), NULL
, 1);
486 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-copy_abook");
487 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
488 display_args_err(tmp_20k_buf
, NULL
, 1);
494 else if(strcmp(*av
, "sort") == 0){
497 COM_SORT_KEY
= cpystr(sort
);
500 display_args_err(_(args_err_missing_sort
), NULL
, 1);
506 else if(strcmp(*av
, "url") == 0){
507 if(args
->action
== aaFolder
&& !args
->data
.folder
){
508 args
->action
= aaURL
;
510 args
->url
= cpystr(*++av
);
513 display_args_err(_(args_err_missing_url
), NULL
, 1);
518 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-url");
519 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
520 display_args_err(tmp_20k_buf
, NULL
, 1);
526 else if(strcmp(*av
, "attach") == 0){
527 if((args
->action
== aaFolder
&& !args
->data
.folder
)
528 || args
->action
== aaMail
529 || args
->action
== aaURL
){
530 if(args
->action
!= aaURL
)
531 args
->action
= aaMail
;
533 args_add_attach(&args
->data
.mail
.attachlist
,
537 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attach");
538 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
539 display_args_err(tmp_20k_buf
, NULL
, 1);
544 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attach");
545 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
546 display_args_err(tmp_20k_buf
, NULL
, 1);
552 else if(strcmp(*av
, "attachlist") == 0){
553 if((args
->action
== aaFolder
&& !args
->data
.folder
)
554 || args
->action
== aaMail
555 || args
->action
== aaURL
){
556 if(args
->action
!= aaURL
)
557 args
->action
= aaMail
;
560 if(can_access(*(av
+1), READ_ACCESS
) == 0){
562 args_add_attach(&args
->data
.mail
.attachlist
,
571 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attachList");
572 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
573 display_args_err(tmp_20k_buf
, NULL
, 1);
578 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attachList");
579 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
580 display_args_err(tmp_20k_buf
, NULL
, 1);
586 else if(strcmp(*av
, "attach_and_delete") == 0){
587 if((args
->action
== aaFolder
&& !args
->data
.folder
)
588 || args
->action
== aaMail
589 || args
->action
== aaURL
){
590 if(args
->action
!= aaURL
)
591 args
->action
= aaMail
;
593 args_add_attach(&args
->data
.mail
.attachlist
,
597 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attach_and_delete");
598 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
599 display_args_err(tmp_20k_buf
, NULL
, 1);
604 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attach_and_delete");
605 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
606 display_args_err(tmp_20k_buf
, NULL
, 1);
612 else if(strcmp(*av
, "bail") == 0){
613 pine_state
->exit_if_no_pinerc
= 1;
616 else if(strcmp(*av
, "version") == 0){
620 else if(strcmp(*av
, "xoauth2-server") == 0){
622 if((str
= *++av
) != NULL
){
624 fs_give((void **) &x
.name
);
625 x
.name
= cpystr(str
);
629 display_args_err(_(args_err_missing_server_name
), NULL
, 1);
634 else if(strcmp(*av
, "xoauth2-client-id") == 0){
636 if((str
= *++av
) != NULL
){
638 fs_give((void **) &x
.client_id
);
639 x
.client_id
= cpystr(str
);
643 display_args_err(_(args_err_missing_client_id
), NULL
, 1);
648 else if(strcmp(*av
, "xoauth2-client-secret") == 0){
650 if((str
= *++av
) != NULL
){
652 fs_give((void **) &x
.client_secret
);
653 x
.client_secret
= cpystr(str
);
657 display_args_err(_(args_err_missing_client_secret
), NULL
, 1);
662 else if(strcmp(*av
, "xoauth2-tenant") == 0){
664 if((str
= *++av
) != NULL
){
666 fs_give((void **) &x
.tenant
);
667 x
.tenant
= cpystr(str
);
671 display_args_err(_(args_err_missing_tenant
), NULL
, 1);
676 else if(strcmp(*av
, "xoauth2-user") == 0){
678 if((str
= *++av
) != NULL
){
680 fs_give((void **) &x
.users
);
681 x
.users
= cpystr(str
);
685 display_args_err(_(args_err_missing_user
), NULL
, 1);
691 else if(strcmp(*av
, "install") == 0){
692 pine_state
->install_flag
= 1;
693 pine_state
->update_registry
= UREG_ALWAYS_SET
;
696 else if(strcmp(*av
, "uninstall") == 0){
698 * Blast password cache, clear registry settings
701 erase_windows_credentials();
703 mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0);
706 else if(strcmp(*av
, "registry") == 0){
708 if(!strucmp(*++av
, "set")){
709 pine_state
->update_registry
= UREG_ALWAYS_SET
;
711 else if(!strucmp(*av
, "noset")){
712 pine_state
->update_registry
= UREG_NEVER_SET
;
714 else if(!strucmp(*av
, "clear")){
715 if(!mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0))
717 _("Alpine related Registry values removed."),
721 _("Not all Alpine related Registry values could be removed"),
725 else if(!strucmp(*av
, "clearsilent")){
726 mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0);
729 else if(!strucmp(*av
, "dump")){
730 char **pRegistry
= mswin_reg_dump();
733 display_args_err(NULL
, pRegistry
, 0);
734 free_list_array(&pRegistry
);
739 display_args_err(_("unknown registry command"),
745 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_flag_arg
), c
);
746 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
747 display_args_err(tmp_20k_buf
, NULL
, 1);
754 /* single char flags */
759 break; /* break back to inner-while */
767 pine_state
->restricted
= 1;
770 pine_state
->open_readonly_on_startup
= 1;
773 pine_state
->start_in_index
= 1;
777 break; /* break back to inner-while */
778 /* these take arguments */
779 case 'f': case 'F': case 'p': case 'I':
780 case 'c': case 'd': case 'P': case 'x': /* string args */
781 case 'n': /* integer args */
786 else if(c
== 'f' || c
== 'F')
789 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_flag_arg
), c
);
790 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
791 display_args_err(tmp_20k_buf
, NULL
, 1);
798 if(args
->action
== aaFolder
&& !args
->data
.folder
){
799 args
->data
.folder
= cpystr(str
);
802 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-f");
803 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
804 display_args_err(tmp_20k_buf
, NULL
, 1);
810 if(args
->action
== aaFolder
&& !args
->data
.folder
){
811 args
->action
= aaMore
;
812 args
->data
.file
= cpystr(str
);
815 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-F");
816 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
817 display_args_err(tmp_20k_buf
, NULL
, 1);
830 char path
[MAXPATH
], dir
[MAXPATH
];
832 if(IS_REMOTE(str
) || is_absolute_path(str
)){
833 strncpy(path
, str
, sizeof(path
)-1);
834 path
[sizeof(path
)-1] = '\0';
837 if(getcwd(dir
, sizeof(path
)) != NULL
)
838 build_path(path
, dir
, str
, sizeof(path
));
840 alpine_panic(_("getcwd() call failed while parsing argument (1)"));
844 * Pinerc used to be the name of the pinerc
845 * file. Now, since the pinerc can be remote,
846 * we've replaced the variable pinerc with the
847 * structure prc. Unfortunately, other parts of
848 * pine rely on the fact that pinerc is the
849 * name of the pinerc _file_, and use the
850 * directory that the pinerc file is located
851 * in for their own purposes. We keep that so
852 * things will keep working.
855 if(!IS_REMOTE(path
)){
856 if(pine_state
->pinerc
)
857 fs_give((void **)&pine_state
->pinerc
);
859 pine_state
->pinerc
= cpystr(path
);
863 * Last one wins. This would be the place where
864 * we put multiple pinercs in a list if we
865 * were to allow that.
868 free_pinerc_s(&pine_state
->prc
);
870 pine_state
->prc
= new_pinerc_s(path
);
876 char path
[MAXPATH
], dir
[MAXPATH
];
878 if(IS_REMOTE(str
) || is_absolute_path(str
)){
879 strncpy(path
, str
, sizeof(path
)-1);
880 path
[sizeof(path
)-1] = '\0';
883 if(getcwd(dir
, sizeof(path
)) != NULL
)
884 build_path(path
, dir
, str
, sizeof(path
));
886 alpine_panic(_("getcwd() call failed while parsing argument (2)"));
889 if(pine_state
->pconf
)
890 free_pinerc_s(&pine_state
->pconf
);
892 pine_state
->pconf
= new_pinerc_s(path
);
898 pine_state
->exceptions
= cpystr(str
);
902 if(!isdigit((unsigned char)str
[0])){
903 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
904 _(args_err_missing_flag_num
), c
);
905 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
906 display_args_err(tmp_20k_buf
, NULL
, 1);
911 pine_state
->init_context
= (short) atoi(str
);
915 if(!isdigit((unsigned char)str
[0])){
916 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
917 _(args_err_missing_flag_num
), c
);
918 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
919 display_args_err(tmp_20k_buf
, NULL
, 1);
924 pine_state
->start_entry
= atoi(str
);
925 if(pine_state
->start_entry
< 1)
926 pine_state
->start_entry
= 1;
934 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_unknown
), c
);
935 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
936 display_args_err(tmp_20k_buf
, NULL
, 1);
943 else if(args
->action
== aaMail
944 || (args
->action
== aaFolder
&& !args
->data
.folder
)){
945 STRLIST_S
*stp
, **slp
;
947 args
->action
= aaMail
;
949 stp
= new_strlist(*av
);
951 for(slp
= &args
->data
.mail
.addrlist
; *slp
; slp
= &(*slp
)->next
)
957 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), *av
);
958 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
959 display_args_err(tmp_20k_buf
, NULL
, 1);
972 COM_INIT_CMD_LIST
= parse_list(cmd_list
, commas
+1, 0, &error
);
974 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_I_error
), cmd_list
, error
);
975 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
976 display_args_err(tmp_20k_buf
, NULL
, 1);
982 pine_state
->debug_nfiles
= NUMDEBUGFILES
;
984 if(debug_str
&& process_debug_str(debug_str
))
987 if(lc
&& strncmp(lc
, ALPINE_FKEY_NAME
, sizeof(ALPINE_FKEY_NAME
) - 1) == 0)
990 if(do_use_fk
|| do_can_suspend
){
1000 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
1001 list
[sizeof(list
)-1] = '\0';
1004 strncat(list
, "use-function-keys", sizeof(list
)-strlen(list
)-1);
1005 list
[sizeof(list
)-1] = '\0';
1010 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
1011 list
[sizeof(list
)-1] = '\0';
1014 strncat(list
, "enable-suspend", sizeof(list
)-strlen(list
)-1);
1015 list
[sizeof(list
)-1] = '\0';
1022 pine_state
->feat_list_back_compat
= parse_list(list
,commas
+1,0,&error
);
1024 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, args_err_internal
, error
);
1025 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1026 display_args_err(tmp_20k_buf
, NULL
, 1);
1031 if(((do_conf
? 1 : 0)+(pinerc_file
? 1 : 0)) > 1){
1032 display_args_err(_("May only have one of -conf and -pinerc"),
1037 if(do_help
|| usage
)
1045 tmp2
= xoauth_config_line(&x
);
1047 tmp1
= fs_get((strlen(ps_global
->vars
[V_XOAUTH2_INFO
].name
) + strlen(tmp2
) + 2)*sizeof(char));
1049 sprintf(tmp1
,"%s=%s", ps_global
->vars
[V_XOAUTH2_INFO
].name
, tmp2
);
1050 pinerc_cmdline_opt(tmp1
);
1051 fs_give((void **) &tmp1
);
1053 fs_give((void **) &tmp2
);
1058 extern char datestamp
[], hoststamp
[];
1061 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "Alpine %s (%s %s) built %s on %s",
1063 SYSTYPE
? SYSTYPE
: "?",
1064 get_alpine_revision_string(rev
, sizeof(rev
)),
1065 datestamp
, hoststamp
);
1066 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1067 display_args_err(tmp_20k_buf
, NULL
, 0);
1069 display_args_err(_("Alpine was built with the following options:"), NULL
, 0);
1070 display_config_options(configoptions
, "./configure ");
1079 dump_new_pinerc(pinerc_file
);
1082 * Don't NULL out argv[0] or we might crash in unexpected ways. In OS X, we were
1083 * crashing when opening attachments because of this.
1085 if(ac
<= 0 && av
!= argv
)
1091 * Returns 0 if ok, -1 if error.
1094 process_debug_str(char *debug_str
)
1098 int new_style_debug_arg
= 0;
1099 char *q
= debug_str
;
1105 if(!isdigit((unsigned char)debug_str
[0]))
1106 new_style_debug_arg
++;
1108 if(new_style_debug_arg
){
1113 list
= parse_list(debug_str
, commas
+1, 0, &error
);
1115 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_d_error
), debug_str
, error
);
1116 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1117 display_args_err(tmp_20k_buf
, NULL
, 1);
1122 for(p
= list
; *p
; p
++){
1123 if(struncmp(*p
, "timestamp", 9) == 0){
1124 ps_global
->debug_timestamp
= 1;
1126 else if(struncmp(*p
, "imap", 4) == 0){
1128 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1129 !isdigit((unsigned char)*(q
+1))){
1130 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1131 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1132 display_args_err(tmp_20k_buf
, NULL
, 1);
1137 ps_global
->debug_imap
= MIN(5,MAX(0,i
));
1140 else if(struncmp(*p
, "flush", 5) == 0){
1141 ps_global
->debug_flush
= 1;
1143 else if(struncmp(*p
, "tcp", 3) == 0
1144 || struncmp(*p
, "tcpdebug", 8) == 0){
1145 ps_global
->debug_tcp
= 1;
1147 else if(struncmp(*p
, "verbose", 7) == 0){
1149 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1150 !isdigit((unsigned char)*(q
+1))){
1151 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1152 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1153 display_args_err(tmp_20k_buf
, NULL
, 1);
1159 else if(struncmp(*p
, "numfiles", 8) == 0){
1161 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1162 !isdigit((unsigned char)*(q
+1))){
1163 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1164 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1165 display_args_err(tmp_20k_buf
, NULL
, 1);
1170 ps_global
->debug_nfiles
= MIN(31,MAX(0,i
));
1173 else if(struncmp(*p
, "malloc", 6) == 0){
1175 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1176 !isdigit((unsigned char)*(q
+1))){
1177 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1178 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1179 display_args_err(tmp_20k_buf
, NULL
, 1);
1184 ps_global
->debug_malloc
= MIN(63,MAX(0,i
));
1187 #if defined(ENABLE_LDAP) && defined(LDAP_DEBUG)
1188 else if(struncmp(*p
, "ldap", 4) == 0){
1190 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1191 !isdigit((unsigned char)*(q
+1))){
1192 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1193 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1194 display_args_err(tmp_20k_buf
, NULL
, 1);
1204 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown debug keyword \"%s\""), *p
);
1205 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1206 display_args_err(tmp_20k_buf
, NULL
, 1);
1211 free_list_array(&list
);
1215 debug
= atoi(debug_str
);
1217 ps_global
->debug_imap
= 5;
1219 ps_global
->debug_imap
= 4;
1221 ps_global
->debug_imap
= 3;
1223 ps_global
->debug_imap
= 2;
1225 ps_global
->debug_imap
= 1;
1228 ps_global
->debug_timestamp
= 1;
1231 ps_global
->debug_flush
= 1;
1235 if(usage
>= 0) ps_global
->write_debug_file
++;
1236 if(!new_style_debug_arg
){
1238 ps_global
->debug_malloc
=
1239 (debug
<= DEFAULT_DEBUG
) ? 1 : (debug
< 9) ? 2 : 3;
1240 #else /* !CSRIMALLOC */
1243 ps_global
->debug_malloc
= 2;
1244 #else /* !HAVE_SMALLOC */
1247 ps_global
->debug_malloc
= 32;
1249 #endif /* HAVE_SMALLOC */
1250 #endif /* CSRIMALLOC */
1255 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown flag \"d\", debugging not compiled in"));
1256 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1257 display_args_err(tmp_20k_buf
, NULL
, 1);
1267 args_add_attach(PATMT
**alpp
, char *s
, int deleted
)
1269 PATMT
*atmp
, **atmpp
;
1271 atmp
= (PATMT
*) fs_get(sizeof(PATMT
));
1272 memset(atmp
, 0, sizeof(PATMT
));
1273 atmp
->filename
= cpystr(s
);
1275 #if defined(DOS) || defined(OS2)
1276 (void) removing_quotes(atmp
->filename
);
1280 atmp
->flags
|= A_TMP
;
1282 for(atmpp
= alpp
; *atmpp
; atmpp
= &(*atmpp
)->next
)
1289 /*----------------------------------------------------------------------
1290 print a few lines of help for command line arguments
1294 Result: prints help messages
1295 ----------------------------------------------------------------------*/
1306 /** print out possible starting arguments... **/
1309 * display_args_err expects already translated input
1310 * so we need to translate a line at a time. Since
1311 * the 1st and 3rd args are zero it is ok to call it
1314 * Windows expects the full block of text so we'll pass
1318 for(a
=args_pine_args
; a
&& *a
; a
++){
1320 display_args_err(NULL
, pp
, 0);
1323 display_args_err(NULL
, args_pine_args
, 0);
1330 /*----------------------------------------------------------------------
1331 write argument error to the display...
1335 Result: prints help messages
1336 ----------------------------------------------------------------------*/
1338 display_args_err(char *s
, char **a
, int err
)
1340 char errstr
[256], *errp
;
1341 FILE *fp
= err
? stderr
: stdout
;
1345 snprintf(errp
= errstr
, sizeof(errstr
), "%s: %s", _("Argument Error"), s
);
1346 errstr
[sizeof(errstr
)-1] = '\0';
1353 mswin_messagebox(errp
, err
);
1360 fprintf(fp
, "%s\n", errp
);
1363 fprintf(fp
, "%s\n", *a
++);
1369 * The argument is an argument from the command line. We check to see
1370 * if it is specifying an alternate value for one of the options that is
1371 * normally set in pinerc. If so, we return 1 and set the appropriate
1372 * values in the variables array.
1375 * varname=value1,value2,value3
1376 * feature-list=featurename these are just a special
1377 * feature-list=featurename1,featurename2 case of above
1378 * featurename This is equivalent to above
1382 pinerc_cmdline_opt(char *arg
)
1394 if((value
= strchr(arg
, '=')) != NULL
){
1401 for(v
= ps_global
->vars
; v
->name
!= NULL
; v
++){
1402 if(v
->is_used
&& strucmp(v
->name
, arg
) == 0){
1403 p1
= arg
+ strlen(v
->name
);
1404 if(i
> 0) arg
[i
] = '=';
1406 /*----- Skip to '=' -----*/
1407 while(*p1
&& (*p1
== '\t' || *p1
== ' '))
1411 char buf
[MAILTMPLEN
];
1413 snprintf(buf
, sizeof(buf
), _("Missing \"=\" after -%s\n"), v
->name
);
1414 buf
[sizeof(buf
)-1] = '\0';
1415 exceptional_exit(buf
, -1);
1424 if(i
> 0) arg
[i
] = '=';
1426 /* no match, check for a feature name used directly */
1427 if(v
->name
== NULL
){
1431 if(struncmp(arg
, "no-", 3) == 0)
1436 for(i
= 0; (feat
= feature_list(i
)) != NULL
; i
++){
1437 if(strucmp(featname
, feat
->name
) == 0){
1438 v
= &(ps_global
->vars
)[V_FEATURE_LIST
];
1448 if(v
->is_obsolete
|| !v
->is_user
){
1449 char buf
[MAILTMPLEN
];
1452 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is obsolete\n"), v
->name
);
1454 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is not user settable\n"), v
->name
);
1456 exceptional_exit(buf
, -1);
1461 oldlvalue
= v
->cmdline_val
.l
;
1462 v
->cmdline_val
.l
= NULL
;
1464 else if(v
->cmdline_val
.p
)
1465 fs_give((void **) &(v
->cmdline_val
.p
));
1467 /*----- Matched a variable, get its value ----*/
1468 while(*p1
== ' ' || *p1
== '\t')
1474 v
->cmdline_val
.l
= (char **)fs_get(2 * sizeof(char *));
1476 * we let people leave off the quotes on command line so that
1477 * they don't have to mess with shell quoting
1479 v
->cmdline_val
.l
[0] = cpystr("");
1480 v
->cmdline_val
.l
[1] = NULL
;
1482 free_list_array(&oldlvalue
);
1485 v
->cmdline_val
.p
= cpystr("");
1490 /*--value is non-empty--*/
1491 if(*value
== '"' && !v
->is_list
){
1493 for(p1
= value
; *p1
&& *p1
!= '"'; p1
++)
1498 removing_trailing_white_space(value
);
1500 removing_trailing_white_space(value
);
1508 for(p1
=value
; *p1
; p1
++){ /* generous count of list elements */
1509 if(*p1
== '"') /* ignore ',' if quoted */
1510 was_quoted
= (was_quoted
) ? 0 : 1;
1512 if(*p1
== ',' && !was_quoted
)
1516 lvalue
= parse_list(value
, count
, 0, &error
);
1518 char buf
[MAILTMPLEN
];
1520 snprintf(buf
, sizeof(buf
), "%s in %s = \"%s\"\n", error
, v
->name
, value
);
1521 buf
[sizeof(buf
)-1] = '\0';
1522 exceptional_exit(buf
, -1);
1525 * Special case: turn "" strings into empty strings.
1526 * This allows users to turn off default lists. For example,
1527 * if smtp-server is set then a user could override smtp-server
1528 * with smtp-server="".
1530 for(i
= 0; lvalue
[i
]; i
++)
1531 if(lvalue
[i
][0] == '"' &&
1532 lvalue
[i
][1] == '"' &&
1533 lvalue
[i
][2] == '\0')
1534 lvalue
[i
][0] = '\0';
1539 char **combinedlvalue
;
1542 /* combine old and new cmdline lists */
1543 for(count
= 0, i
= 0; oldlvalue
[i
]; i
++, count
++)
1546 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, count
++)
1549 combinedlvalue
= (char **) fs_get((count
+1) * sizeof(char *));
1550 memset(combinedlvalue
, 0, (count
+1) * sizeof(*combinedlvalue
));
1552 for(i
= 0, j
= 0; oldlvalue
[i
]; i
++, j
++)
1553 combinedlvalue
[j
] = cpystr(oldlvalue
[i
]);
1555 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, j
++)
1556 combinedlvalue
[j
] = cpystr(lvalue
[i
]);
1558 v
->cmdline_val
.l
= combinedlvalue
;
1560 fs_give((void **) &oldlvalue
);
1562 fs_give((void **) &lvalue
);
1565 v
->cmdline_val
.l
= lvalue
;
1568 v
->cmdline_val
.p
= cpystr(value
);