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-2016 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"
38 int process_debug_str(char *);
39 void args_add_attach(PATMT
**, char *, int);
40 int pinerc_cmdline_opt(char *);
44 * Name started as to invoke function key mode
46 #define ALPINE_FKEY_NAME "alpinef"
49 * Various error and informational strings..
51 /* TRANSLATORS: This is a list of errors printed when something goes wrong
52 early on with the argument list. Be careful not to change literal
53 option names mentioned in the strings. */
54 static char args_err_missing_pinerc
[] = N_("missing argument for option \"-pinerc\" (use - for standard out)");
55 #if defined(DOS) || defined(OS2)
56 static char args_err_missing_aux
[] = N_("missing argument for option \"-aux\"");
59 static char args_err_missing_smimedir
[] = N_("missing argument for option \"-smimedir\"");
60 static char args_err_non_abs_smimedir
[] = N_("argument to \"-smimedir\" should be fully-qualified");
63 static char args_err_missing_passfile
[] = N_("missing argument for option \"-passfile\"");
64 static char args_err_non_abs_passfile
[] = N_("argument to \"-passfile\" should be fully-qualified");
66 static char args_err_missing_pwdcertdir
[] = N_("missing argument for option \"-pwdcertdir\"");
67 static char args_err_non_abs_pwdcertdir
[] = N_("argument to \"-pwdcertdir\" should be fully-qualified");
68 #endif /* SMIME inside PASSFILE */
70 static char args_err_missing_sort
[] = N_("missing argument for option \"-sort\"");
71 static char args_err_missing_flag_arg
[] = N_("missing argument for flag \"%c\"");
72 static char args_err_missing_flag_num
[] = N_("Non numeric argument for flag \"%c\"");
73 static char args_err_missing_debug_num
[] = N_("Non numeric argument for \"%s\"");
74 static char args_err_missing_url
[] = N_("missing URL for \"-url\"");
75 static char args_err_missing_attachment
[] = N_("missing attachment for \"%s\"");
76 static char args_err_conflict
[] = N_("conflicting action: \"%s\"");
77 static char args_err_unknown
[] = N_("unknown flag \"%c\"");
78 static char args_err_I_error
[] = N_("-I argument \"%s\": %s");
79 static char args_err_d_error
[] = N_("-d argument \"%s\": %s");
80 static char args_err_internal
[] = "%s";
81 static char args_err_missing_copyprc
[] = N_("missing argument for option \"-copy_pinerc\"\nUsage: pine -copy_pinerc <local_pinerc> <remote_pinerc>");
82 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_pine_args
[] = {
86 N_("Possible Starting Arguments for Alpine program:"),
88 N_(" Argument\tMeaning"),
89 N_(" <addrs>...\tGo directly into composer sending to given address"),
90 N_("\t\tList multiple addresses with a single space between them."),
91 N_("\t\tStandard input redirection is allowed with addresses."),
92 N_("\t\tNote: Places addresses in the \"To\" field only."),
93 N_(" -attach <file>\tGo directly into composer with given file"),
94 N_(" -attachlist <file-list>"),
95 N_(" -attach_and_delete <file>"),
96 N_("\t\tGo to composer, attach file, delete when finished"),
97 N_("\t\tNote: Attach options can't be used if -f, -F"),
98 N_("\t\tadded to Attachment list. Attachlist must be the last"),
99 N_("\t\toption on the command line"),
100 N_(" -bail\t\tExit if pinerc file doesn't already exist"),
102 N_(" -d n\t\tDebug - set debug level to 'n', or use the following:"),
103 N_(" -d keywords...\tflush,timestamp,imap=0..4,tcp,numfiles=0..31,verbose=0..9"),
105 N_(" -f <folder>\tFolder - give folder name to open"),
106 N_(" -c <number>\tContext - which context to apply to -f arg"),
107 N_(" -F <file>\tFile - give file name to open and page through and"),
108 N_("\t\tforward as email."),
109 N_(" -h \t\tHelp - give this list of options"),
110 N_(" -k \t\tKeys - Force use of function keys"),
111 N_(" -z \t\tSuspend - allow use of ^Z suspension"),
112 N_(" -r \t\tRestricted - can only send mail to oneself"),
113 N_(" -sort <sort>\tSort - Specify sort order of folder:"),
114 N_("\t\t\tarrival, subject, threaded, orderedsubject, date,"),
115 N_("\t\t\tfrom, size, score, to, cc, /reverse"),
116 N_(" -i\t\tIndex - Go directly to index, bypassing main menu"),
117 N_(" -I <keystroke_list> Initial keystrokes to be executed"),
118 N_(" -n <number>\tEntry in index to begin on"),
119 N_(" -o \t\tReadOnly - Open first folder read-only"),
120 N_(" -conf\t\tConfiguration - Print out fresh global configuration. The"),
121 N_("\t\tvalues of your global configuration affect all Alpine users"),
122 N_("\t\ton your system unless they have overridden the values in their"),
123 N_("\t\tpinerc files."),
124 N_(" -pinerc <file>\tConfiguration - Put fresh pinerc configuration in <file>"),
125 N_(" -p <pinerc>\tUse alternate .pinerc file"),
126 #if !defined(DOS) && !defined(OS2)
127 N_(" -P <pine.conf>\tUse alternate pine.conf file"),
129 N_(" -aux <aux_files_dir>\tUse this with remote pinerc"),
130 N_(" -P <pine.conf>\tUse pine.conf file for default settings"),
131 N_(" -nosplash \tDisable the PC-Alpine splash screen"),
134 #if defined(APPLEKEYCHAIN) || (WINCRED > 0)
135 N_(" -erase_stored_passwords\tEliminate any stored passwords"),
139 N_(" -smimedir <fully_qualified_path>\tdirectory where smime personal certificates are saved"),
143 N_(" -passfile <fully_qualified_filename>\tSet the password file to something other"),
144 N_("\t\tthan the default"),
146 N_(" -pwdcertdir <fully_qualified_path>\tSet the directory to store a personal"),
147 N_("\t\tkey and certificate to encrypt and decrypt your password file."),
148 #endif /* SMIME inside PASSFILE */
149 #endif /* PASSFILE */
151 #ifdef LOCAL_PASSWD_CACHE
152 N_(" -nowrite_password_cache\tRead from a password cache if there is one, but"),
153 N_("\t\t\t\tnever offer to write a password to the cache"),
154 #endif /* LOCAL_PASSWD_CACHE */
156 N_(" -x <config>\tUse configuration exceptions in <config>."),
157 N_("\t\tExceptions are used to override your default pinerc"),
158 N_("\t\tsettings for a particular platform, can be a local file or"),
159 N_("\t\ta remote folder."),
160 N_(" -v \t\tVersion - show version information"),
161 N_(" -version\tVersion - show version information"),
162 N_(" -supported\tList supported options"),
163 N_(" -url <url>\tOpen the given URL"),
164 N_("\t\tNote: Can't be used if -f, -F"),
165 N_("\t\tStandard input redirection is not allowed with URLs."),
166 N_("\t\tFor mailto URLs, 'body='text should be used in place of"),
167 N_("\t\tinput redirection."),
168 N_(" -copy_pinerc <local_pinerc> <remote_pinerc> copy local pinerc to remote"),
169 N_(" -copy_abook <local_abook> <remote_abook> copy local addressbook to remote"),
170 N_(" -convert_sigs -p <pinerc> convert signatures to literal signatures"),
171 #if defined(_WINDOWS)
172 N_(" -install \tPrompt for some basic setup information"),
173 N_(" -uninstall \tRemove traces of Alpine from Windows system settings"),
174 N_(" -registry <cmd>\tWhere cmd is set,noset,clear,clearsilent,dump"),
176 " -<option>=<value> Assign <value> to the pinerc option <option>",
177 "\t\t e.g. -signature-file=sig1",
178 "\t\t e.g. -color-style=no-color",
179 "\t\t e.g. -feature-list=enable-sigdashes",
180 "\t\t Note: feature-list is additive.",
181 "\t\t You may leave off the \"feature-list=\" part of that,",
182 "\t\t e.g. -enable-sigdashes",
189 * Parse the command line args.
191 * Args: pine_state -- The pine_state structure to put results in
192 * argc, argv -- The obvious
193 * addrs -- Pointer to address list that we set for caller
195 * Result: command arguments parsed
196 * possible printing of help for command line
197 * various flags in pine_state set
198 * returns the string name of the first folder to open
202 pine_args(struct pine
*pine_state
, int argc
, char **argv
, ARGDATA_S
*args
)
208 char *cmd_list
= NULL
;
209 char *debug_str
= NULL
;
211 char *pinerc_file
= NULL
;
217 int do_can_suspend
= 0;
219 struct variable
*vars
= pine_state
->vars
;
223 memset(args
, 0, sizeof(ARGDATA_S
));
224 args
->action
= aaFolder
;
226 pine_state
->pine_name
= (lc
= last_cmpnt(argv
[0])) ? lc
: (lc
= argv
[0]);
228 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%.*s", pine_state
->pine_name
- argv
[0], argv
[0]);
229 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
230 pine_state
->pine_dir
= cpystr(tmp_20k_buf
);
233 /* while more arguments with leading - */
234 Loop
: while(--ac
> 0)
236 /* while more chars in this argument */
238 /* check for pinerc options */
239 if(pinerc_cmdline_opt(*av
)){
240 goto Loop
; /* done with this arg, go to next */
242 /* then other multi-char options */
243 else if(strcmp(*av
, "conf") == 0){
245 goto Loop
; /* done with this arg, go to next */
247 else if(strcmp(*av
, "pinerc") == 0){
251 display_args_err(_(args_err_missing_pinerc
), NULL
, 1);
257 #if defined(DOS) || defined(OS2)
258 else if(strcmp(*av
, "aux") == 0){
260 if((str
= *++av
) != NULL
)
261 pine_state
->aux_files_dir
= cpystr(str
);
264 display_args_err(_(args_err_missing_aux
), NULL
, 1);
270 else if(strcmp(*av
, "nosplash") == 0)
271 goto Loop
; /* already taken care of in WinMain */
274 #if defined(APPLEKEYCHAIN) || (WINCRED > 0)
275 else if(strcmp(*av
, "erase_stored_passwords") == 0){
277 erase_windows_credentials();
279 macos_erase_keychain();
283 #endif /* defined(APPLEKEYCHAIN) || (WINCRED > 0) */
286 else if(strcmp(*av
, "smimedir") == 0){
288 if((str
= *++av
) != NULL
){
289 if(!is_absolute_path(str
)){
290 display_args_err(_(args_err_non_abs_smimedir
),
295 if(pine_state
->smimedir
)
296 fs_give((void **)&pine_state
->smimedir
);
298 pine_state
->smimedir
= cpystr(str
);
303 display_args_err(_(args_err_missing_smimedir
), NULL
, 1);
311 else if(strcmp(*av
, "passfile") == 0){
313 if((str
= *++av
) != NULL
){
314 if(!is_absolute_path(str
)){
315 display_args_err(_(args_err_non_abs_passfile
),
320 if(pine_state
->passfile
)
321 fs_give((void **)&pine_state
->passfile
);
323 pine_state
->passfile
= cpystr(str
);
328 display_args_err(_(args_err_missing_passfile
), NULL
, 1);
335 else if(strcmp(*av
, "pwdcertdir") == 0){
337 if((str
= *++av
) != NULL
){
338 if(!is_absolute_path(str
)){
339 display_args_err(_(args_err_non_abs_pwdcertdir
),
344 if(pine_state
->pwdcertdir
)
345 fs_give((void **)&pine_state
->pwdcertdir
);
347 pine_state
->pwdcertdir
= cpystr(str
);
352 display_args_err(_(args_err_missing_pwdcertdir
), NULL
, 1);
358 #endif /* SMIME inside PASSFILE */
359 #endif /* PASSFILE */
361 #ifdef LOCAL_PASSWD_CACHE
362 else if(strcmp(*av
, "nowrite_password_cache") == 0){
363 ps_global
->nowrite_password_cache
= 1;
366 #endif /* LOCAL_PASSWD_CACHE */
368 else if(strcmp(*av
, "convert_sigs") == 0){
369 ps_global
->convert_sigs
= 1;
372 else if(strcmp(*av
, "supported") == 0){
373 ps_global
->dump_supported_options
= 1;
376 else if(strcmp(*av
, "copy_pinerc") == 0){
377 if(args
->action
== aaFolder
&& !args
->data
.folder
){
378 args
->action
= aaPrcCopy
;
381 args
->data
.copy
.local
= *++av
;
382 args
->data
.copy
.remote
= *++av
;
385 display_args_err(_(args_err_missing_copyprc
), NULL
, 1);
390 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-copy_pinerc");
391 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
392 display_args_err(tmp_20k_buf
, NULL
, 1);
398 else if(strcmp(*av
, "copy_abook") == 0){
399 if(args
->action
== aaFolder
&& !args
->data
.folder
){
400 args
->action
= aaAbookCopy
;
403 args
->data
.copy
.local
= *++av
;
404 args
->data
.copy
.remote
= *++av
;
407 display_args_err(_(args_err_missing_copyabook
), NULL
, 1);
412 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-copy_abook");
413 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
414 display_args_err(tmp_20k_buf
, NULL
, 1);
420 else if(strcmp(*av
, "sort") == 0){
423 COM_SORT_KEY
= cpystr(sort
);
426 display_args_err(_(args_err_missing_sort
), NULL
, 1);
432 else if(strcmp(*av
, "url") == 0){
433 if(args
->action
== aaFolder
&& !args
->data
.folder
){
434 args
->action
= aaURL
;
436 args
->url
= cpystr(*++av
);
439 display_args_err(_(args_err_missing_url
), NULL
, 1);
444 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-url");
445 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
446 display_args_err(tmp_20k_buf
, NULL
, 1);
452 else if(strcmp(*av
, "attach") == 0){
453 if((args
->action
== aaFolder
&& !args
->data
.folder
)
454 || args
->action
== aaMail
455 || args
->action
== aaURL
){
456 if(args
->action
!= aaURL
)
457 args
->action
= aaMail
;
459 args_add_attach(&args
->data
.mail
.attachlist
,
463 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attach");
464 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
465 display_args_err(tmp_20k_buf
, NULL
, 1);
470 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attach");
471 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
472 display_args_err(tmp_20k_buf
, NULL
, 1);
478 else if(strcmp(*av
, "attachlist") == 0){
479 if((args
->action
== aaFolder
&& !args
->data
.folder
)
480 || args
->action
== aaMail
481 || args
->action
== aaURL
){
482 if(args
->action
!= aaURL
)
483 args
->action
= aaMail
;
486 if(can_access(*(av
+1), READ_ACCESS
) == 0){
488 args_add_attach(&args
->data
.mail
.attachlist
,
497 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attachList");
498 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
499 display_args_err(tmp_20k_buf
, NULL
, 1);
504 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attachList");
505 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
506 display_args_err(tmp_20k_buf
, NULL
, 1);
512 else if(strcmp(*av
, "attach_and_delete") == 0){
513 if((args
->action
== aaFolder
&& !args
->data
.folder
)
514 || args
->action
== aaMail
515 || args
->action
== aaURL
){
516 if(args
->action
!= aaURL
)
517 args
->action
= aaMail
;
519 args_add_attach(&args
->data
.mail
.attachlist
,
523 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attach_and_delete");
524 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
525 display_args_err(tmp_20k_buf
, NULL
, 1);
530 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attach_and_delete");
531 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
532 display_args_err(tmp_20k_buf
, NULL
, 1);
538 else if(strcmp(*av
, "bail") == 0){
539 pine_state
->exit_if_no_pinerc
= 1;
542 else if(strcmp(*av
, "version") == 0){
547 else if(strcmp(*av
, "install") == 0){
548 pine_state
->install_flag
= 1;
549 pine_state
->update_registry
= UREG_ALWAYS_SET
;
552 else if(strcmp(*av
, "uninstall") == 0){
554 * Blast password cache, clear registry settings
557 erase_windows_credentials();
559 mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0);
562 else if(strcmp(*av
, "registry") == 0){
564 if(!strucmp(*++av
, "set")){
565 pine_state
->update_registry
= UREG_ALWAYS_SET
;
567 else if(!strucmp(*av
, "noset")){
568 pine_state
->update_registry
= UREG_NEVER_SET
;
570 else if(!strucmp(*av
, "clear")){
571 if(!mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0))
573 _("Alpine related Registry values removed."),
577 _("Not all Alpine related Registry values could be removed"),
581 else if(!strucmp(*av
, "clearsilent")){
582 mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0);
585 else if(!strucmp(*av
, "dump")){
586 char **pRegistry
= mswin_reg_dump();
589 display_args_err(NULL
, pRegistry
, 0);
590 free_list_array(&pRegistry
);
595 display_args_err(_("unknown registry command"),
601 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_flag_arg
), c
);
602 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
603 display_args_err(tmp_20k_buf
, NULL
, 1);
610 /* single char flags */
615 break; /* break back to inner-while */
623 pine_state
->restricted
= 1;
626 pine_state
->open_readonly_on_startup
= 1;
629 pine_state
->start_in_index
= 1;
633 break; /* break back to inner-while */
634 /* these take arguments */
635 case 'f': case 'F': case 'p': case 'I':
636 case 'c': case 'd': case 'P': case 'x': /* string args */
637 case 'n': /* integer args */
642 else if(c
== 'f' || c
== 'F')
645 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_flag_arg
), c
);
646 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
647 display_args_err(tmp_20k_buf
, NULL
, 1);
654 if(args
->action
== aaFolder
&& !args
->data
.folder
){
655 args
->data
.folder
= cpystr(str
);
658 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-f");
659 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
660 display_args_err(tmp_20k_buf
, NULL
, 1);
666 if(args
->action
== aaFolder
&& !args
->data
.folder
){
667 args
->action
= aaMore
;
668 args
->data
.file
= cpystr(str
);
671 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-F");
672 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
673 display_args_err(tmp_20k_buf
, NULL
, 1);
686 char path
[MAXPATH
], dir
[MAXPATH
];
688 if(IS_REMOTE(str
) || is_absolute_path(str
)){
689 strncpy(path
, str
, sizeof(path
)-1);
690 path
[sizeof(path
)-1] = '\0';
693 if(getcwd(dir
, sizeof(path
)) != NULL
)
694 build_path(path
, dir
, str
, sizeof(path
));
696 alpine_panic(_("getcwd() call failed while parsing argument (1)"));
700 * Pinerc used to be the name of the pinerc
701 * file. Now, since the pinerc can be remote,
702 * we've replaced the variable pinerc with the
703 * structure prc. Unfortunately, other parts of
704 * pine rely on the fact that pinerc is the
705 * name of the pinerc _file_, and use the
706 * directory that the pinerc file is located
707 * in for their own purposes. We keep that so
708 * things will keep working.
711 if(!IS_REMOTE(path
)){
712 if(pine_state
->pinerc
)
713 fs_give((void **)&pine_state
->pinerc
);
715 pine_state
->pinerc
= cpystr(path
);
719 * Last one wins. This would be the place where
720 * we put multiple pinercs in a list if we
721 * were to allow that.
724 free_pinerc_s(&pine_state
->prc
);
726 pine_state
->prc
= new_pinerc_s(path
);
732 char path
[MAXPATH
], dir
[MAXPATH
];
734 if(IS_REMOTE(str
) || is_absolute_path(str
)){
735 strncpy(path
, str
, sizeof(path
)-1);
736 path
[sizeof(path
)-1] = '\0';
739 if(getcwd(dir
, sizeof(path
)) != NULL
)
740 build_path(path
, dir
, str
, sizeof(path
));
742 alpine_panic(_("getcwd() call failed while parsing argument (2)"));
745 if(pine_state
->pconf
)
746 free_pinerc_s(&pine_state
->pconf
);
748 pine_state
->pconf
= new_pinerc_s(path
);
754 pine_state
->exceptions
= cpystr(str
);
758 if(!isdigit((unsigned char)str
[0])){
759 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
760 _(args_err_missing_flag_num
), c
);
761 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
762 display_args_err(tmp_20k_buf
, NULL
, 1);
767 pine_state
->init_context
= (short) atoi(str
);
771 if(!isdigit((unsigned char)str
[0])){
772 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
773 _(args_err_missing_flag_num
), c
);
774 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
775 display_args_err(tmp_20k_buf
, NULL
, 1);
780 pine_state
->start_entry
= atoi(str
);
781 if(pine_state
->start_entry
< 1)
782 pine_state
->start_entry
= 1;
790 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_unknown
), c
);
791 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
792 display_args_err(tmp_20k_buf
, NULL
, 1);
799 else if(args
->action
== aaMail
800 || (args
->action
== aaFolder
&& !args
->data
.folder
)){
801 STRLIST_S
*stp
, **slp
;
803 args
->action
= aaMail
;
805 stp
= new_strlist(*av
);
807 for(slp
= &args
->data
.mail
.addrlist
; *slp
; slp
= &(*slp
)->next
)
813 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), *av
);
814 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
815 display_args_err(tmp_20k_buf
, NULL
, 1);
828 COM_INIT_CMD_LIST
= parse_list(cmd_list
, commas
+1, 0, &error
);
830 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_I_error
), cmd_list
, error
);
831 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
832 display_args_err(tmp_20k_buf
, NULL
, 1);
838 pine_state
->debug_nfiles
= NUMDEBUGFILES
;
840 if(debug_str
&& process_debug_str(debug_str
))
843 if(lc
&& strncmp(lc
, ALPINE_FKEY_NAME
, sizeof(ALPINE_FKEY_NAME
) - 1) == 0)
846 if(do_use_fk
|| do_can_suspend
){
856 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
857 list
[sizeof(list
)-1] = '\0';
860 strncat(list
, "use-function-keys", sizeof(list
)-strlen(list
)-1);
861 list
[sizeof(list
)-1] = '\0';
866 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
867 list
[sizeof(list
)-1] = '\0';
870 strncat(list
, "enable-suspend", sizeof(list
)-strlen(list
)-1);
871 list
[sizeof(list
)-1] = '\0';
878 pine_state
->feat_list_back_compat
= parse_list(list
,commas
+1,0,&error
);
880 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, args_err_internal
, error
);
881 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
882 display_args_err(tmp_20k_buf
, NULL
, 1);
887 if(((do_conf
? 1 : 0)+(pinerc_file
? 1 : 0)) > 1){
888 display_args_err(_("May only have one of -conf and -pinerc"),
900 extern char datestamp
[], hoststamp
[];
903 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "Alpine %s (%s %s) built %s on %s",
905 SYSTYPE
? SYSTYPE
: "?",
906 get_alpine_revision_string(rev
, sizeof(rev
)),
907 datestamp
, hoststamp
);
908 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
909 display_args_err(tmp_20k_buf
, NULL
, 0);
917 dump_new_pinerc(pinerc_file
);
920 * Don't NULL out argv[0] or we might crash in unexpected ways. In OS X, we were
921 * crashing when opening attachments because of this.
923 if(ac
<= 0 && av
!= argv
)
929 * Returns 0 if ok, -1 if error.
932 process_debug_str(char *debug_str
)
936 int new_style_debug_arg
= 0;
943 if(!isdigit((unsigned char)debug_str
[0]))
944 new_style_debug_arg
++;
946 if(new_style_debug_arg
){
951 list
= parse_list(debug_str
, commas
+1, 0, &error
);
953 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_d_error
), debug_str
, error
);
954 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
955 display_args_err(tmp_20k_buf
, NULL
, 1);
960 for(p
= list
; *p
; p
++){
961 if(struncmp(*p
, "timestamp", 9) == 0){
962 ps_global
->debug_timestamp
= 1;
964 else if(struncmp(*p
, "imap", 4) == 0){
966 if(!*q
|| !*(q
+1) || *q
!= '=' ||
967 !isdigit((unsigned char)*(q
+1))){
968 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
969 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
970 display_args_err(tmp_20k_buf
, NULL
, 1);
975 ps_global
->debug_imap
= MIN(5,MAX(0,i
));
978 else if(struncmp(*p
, "flush", 5) == 0){
979 ps_global
->debug_flush
= 1;
981 else if(struncmp(*p
, "tcp", 3) == 0){
982 ps_global
->debug_tcp
= 1;
984 else if(struncmp(*p
, "verbose", 7) == 0){
986 if(!*q
|| !*(q
+1) || *q
!= '=' ||
987 !isdigit((unsigned char)*(q
+1))){
988 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
989 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
990 display_args_err(tmp_20k_buf
, NULL
, 1);
996 else if(struncmp(*p
, "numfiles", 8) == 0){
998 if(!*q
|| !*(q
+1) || *q
!= '=' ||
999 !isdigit((unsigned char)*(q
+1))){
1000 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1001 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1002 display_args_err(tmp_20k_buf
, NULL
, 1);
1007 ps_global
->debug_nfiles
= MIN(31,MAX(0,i
));
1010 else if(struncmp(*p
, "malloc", 6) == 0){
1012 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1013 !isdigit((unsigned char)*(q
+1))){
1014 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1015 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1016 display_args_err(tmp_20k_buf
, NULL
, 1);
1021 ps_global
->debug_malloc
= MIN(63,MAX(0,i
));
1024 #if defined(ENABLE_LDAP) && defined(LDAP_DEBUG)
1025 else if(struncmp(*p
, "ldap", 4) == 0){
1027 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1028 !isdigit((unsigned char)*(q
+1))){
1029 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1030 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1031 display_args_err(tmp_20k_buf
, NULL
, 1);
1041 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown debug keyword \"%s\""), *p
);
1042 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1043 display_args_err(tmp_20k_buf
, NULL
, 1);
1048 free_list_array(&list
);
1052 debug
= atoi(debug_str
);
1054 ps_global
->debug_imap
= 5;
1056 ps_global
->debug_imap
= 4;
1058 ps_global
->debug_imap
= 3;
1060 ps_global
->debug_imap
= 2;
1062 ps_global
->debug_imap
= 1;
1065 ps_global
->debug_timestamp
= 1;
1068 ps_global
->debug_flush
= 1;
1072 if(!new_style_debug_arg
){
1074 ps_global
->debug_malloc
=
1075 (debug
<= DEFAULT_DEBUG
) ? 1 : (debug
< 9) ? 2 : 3;
1076 #else /* !CSRIMALLOC */
1079 ps_global
->debug_malloc
= 2;
1080 #else /* !HAVE_SMALLOC */
1083 ps_global
->debug_malloc
= 32;
1085 #endif /* HAVE_SMALLOC */
1086 #endif /* CSRIMALLOC */
1091 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown flag \"d\", debugging not compiled in"));
1092 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1093 display_args_err(tmp_20k_buf
, NULL
, 1);
1103 args_add_attach(PATMT
**alpp
, char *s
, int deleted
)
1105 PATMT
*atmp
, **atmpp
;
1107 atmp
= (PATMT
*) fs_get(sizeof(PATMT
));
1108 memset(atmp
, 0, sizeof(PATMT
));
1109 atmp
->filename
= cpystr(s
);
1111 #if defined(DOS) || defined(OS2)
1112 (void) removing_quotes(atmp
->filename
);
1116 atmp
->flags
|= A_TMP
;
1118 for(atmpp
= alpp
; *atmpp
; atmpp
= &(*atmpp
)->next
)
1125 /*----------------------------------------------------------------------
1126 print a few lines of help for command line arguments
1130 Result: prints help messages
1131 ----------------------------------------------------------------------*/
1142 /** print out possible starting arguments... **/
1145 * display_args_err expects already translated input
1146 * so we need to translate a line at a time. Since
1147 * the 1st and 3rd args are zero it is ok to call it
1150 * Windows expects the full block of text so we'll pass
1154 for(a
=args_pine_args
; a
&& *a
; a
++){
1156 display_args_err(NULL
, pp
, 0);
1159 display_args_err(NULL
, args_pine_args
, 0);
1166 /*----------------------------------------------------------------------
1167 write argument error to the display...
1171 Result: prints help messages
1172 ----------------------------------------------------------------------*/
1174 display_args_err(char *s
, char **a
, int err
)
1176 char errstr
[256], *errp
;
1177 FILE *fp
= err
? stderr
: stdout
;
1181 snprintf(errp
= errstr
, sizeof(errstr
), "%s: %s", _("Argument Error"), s
);
1182 errstr
[sizeof(errstr
)-1] = '\0';
1189 mswin_messagebox(errp
, err
);
1196 fprintf(fp
, "%s\n", errp
);
1199 fprintf(fp
, "%s\n", *a
++);
1205 * The argument is an argument from the command line. We check to see
1206 * if it is specifying an alternate value for one of the options that is
1207 * normally set in pinerc. If so, we return 1 and set the appropriate
1208 * values in the variables array.
1211 * varname=value1,value2,value3
1212 * feature-list=featurename these are just a special
1213 * feature-list=featurename1,featurename2 case of above
1214 * featurename This is equivalent to above
1218 pinerc_cmdline_opt(char *arg
)
1230 if((value
= strchr(arg
, '=')) != NULL
){
1237 for(v
= ps_global
->vars
; v
->name
!= NULL
; v
++){
1238 if(v
->is_used
&& strucmp(v
->name
, arg
) == 0){
1239 p1
= arg
+ strlen(v
->name
);
1240 if(i
> 0) arg
[i
] = '=';
1242 /*----- Skip to '=' -----*/
1243 while(*p1
&& (*p1
== '\t' || *p1
== ' '))
1247 char buf
[MAILTMPLEN
];
1249 snprintf(buf
, sizeof(buf
), _("Missing \"=\" after -%s\n"), v
->name
);
1250 buf
[sizeof(buf
)-1] = '\0';
1251 exceptional_exit(buf
, -1);
1260 if(i
> 0) arg
[i
] = '=';
1262 /* no match, check for a feature name used directly */
1263 if(v
->name
== NULL
){
1267 if(struncmp(arg
, "no-", 3) == 0)
1272 for(i
= 0; (feat
= feature_list(i
)) != NULL
; i
++){
1273 if(strucmp(featname
, feat
->name
) == 0){
1274 v
= &(ps_global
->vars
)[V_FEATURE_LIST
];
1284 if(v
->is_obsolete
|| !v
->is_user
){
1285 char buf
[MAILTMPLEN
];
1288 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is obsolete\n"), v
->name
);
1290 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is not user settable\n"), v
->name
);
1292 exceptional_exit(buf
, -1);
1297 oldlvalue
= v
->cmdline_val
.l
;
1298 v
->cmdline_val
.l
= NULL
;
1300 else if(v
->cmdline_val
.p
)
1301 fs_give((void **) &(v
->cmdline_val
.p
));
1303 /*----- Matched a variable, get its value ----*/
1304 while(*p1
== ' ' || *p1
== '\t')
1310 v
->cmdline_val
.l
= (char **)fs_get(2 * sizeof(char *));
1312 * we let people leave off the quotes on command line so that
1313 * they don't have to mess with shell quoting
1315 v
->cmdline_val
.l
[0] = cpystr("");
1316 v
->cmdline_val
.l
[1] = NULL
;
1318 free_list_array(&oldlvalue
);
1321 v
->cmdline_val
.p
= cpystr("");
1326 /*--value is non-empty--*/
1327 if(*value
== '"' && !v
->is_list
){
1329 for(p1
= value
; *p1
&& *p1
!= '"'; p1
++)
1334 removing_trailing_white_space(value
);
1336 removing_trailing_white_space(value
);
1344 for(p1
=value
; *p1
; p1
++){ /* generous count of list elements */
1345 if(*p1
== '"') /* ignore ',' if quoted */
1346 was_quoted
= (was_quoted
) ? 0 : 1;
1348 if(*p1
== ',' && !was_quoted
)
1352 lvalue
= parse_list(value
, count
, 0, &error
);
1354 char buf
[MAILTMPLEN
];
1356 snprintf(buf
, sizeof(buf
), "%s in %s = \"%s\"\n", error
, v
->name
, value
);
1357 buf
[sizeof(buf
)-1] = '\0';
1358 exceptional_exit(buf
, -1);
1361 * Special case: turn "" strings into empty strings.
1362 * This allows users to turn off default lists. For example,
1363 * if smtp-server is set then a user could override smtp-server
1364 * with smtp-server="".
1366 for(i
= 0; lvalue
[i
]; i
++)
1367 if(lvalue
[i
][0] == '"' &&
1368 lvalue
[i
][1] == '"' &&
1369 lvalue
[i
][2] == '\0')
1370 lvalue
[i
][0] = '\0';
1375 char **combinedlvalue
;
1378 /* combine old and new cmdline lists */
1379 for(count
= 0, i
= 0; oldlvalue
[i
]; i
++, count
++)
1382 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, count
++)
1385 combinedlvalue
= (char **) fs_get((count
+1) * sizeof(char *));
1386 memset(combinedlvalue
, 0, (count
+1) * sizeof(*combinedlvalue
));
1388 for(i
= 0, j
= 0; oldlvalue
[i
]; i
++, j
++)
1389 combinedlvalue
[j
] = cpystr(oldlvalue
[i
]);
1391 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, j
++)
1392 combinedlvalue
[j
] = cpystr(lvalue
[i
]);
1394 v
->cmdline_val
.l
= combinedlvalue
;
1396 fs_give((void **) &oldlvalue
);
1398 fs_give((void **) &lvalue
);
1401 v
->cmdline_val
.l
= lvalue
;
1404 v
->cmdline_val
.p
= cpystr(value
);