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 getcwd(dir
, sizeof(path
));
694 build_path(path
, dir
, str
, sizeof(path
));
698 * Pinerc used to be the name of the pinerc
699 * file. Now, since the pinerc can be remote,
700 * we've replaced the variable pinerc with the
701 * structure prc. Unfortunately, other parts of
702 * pine rely on the fact that pinerc is the
703 * name of the pinerc _file_, and use the
704 * directory that the pinerc file is located
705 * in for their own purposes. We keep that so
706 * things will keep working.
709 if(!IS_REMOTE(path
)){
710 if(pine_state
->pinerc
)
711 fs_give((void **)&pine_state
->pinerc
);
713 pine_state
->pinerc
= cpystr(path
);
717 * Last one wins. This would be the place where
718 * we put multiple pinercs in a list if we
719 * were to allow that.
722 free_pinerc_s(&pine_state
->prc
);
724 pine_state
->prc
= new_pinerc_s(path
);
730 char path
[MAXPATH
], dir
[MAXPATH
];
732 if(IS_REMOTE(str
) || is_absolute_path(str
)){
733 strncpy(path
, str
, sizeof(path
)-1);
734 path
[sizeof(path
)-1] = '\0';
737 getcwd(dir
, sizeof(path
));
738 build_path(path
, dir
, str
, sizeof(path
));
741 if(pine_state
->pconf
)
742 free_pinerc_s(&pine_state
->pconf
);
744 pine_state
->pconf
= new_pinerc_s(path
);
750 pine_state
->exceptions
= cpystr(str
);
754 if(!isdigit((unsigned char)str
[0])){
755 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
756 _(args_err_missing_flag_num
), c
);
757 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
758 display_args_err(tmp_20k_buf
, NULL
, 1);
763 pine_state
->init_context
= (short) atoi(str
);
767 if(!isdigit((unsigned char)str
[0])){
768 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
769 _(args_err_missing_flag_num
), c
);
770 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
771 display_args_err(tmp_20k_buf
, NULL
, 1);
776 pine_state
->start_entry
= atoi(str
);
777 if(pine_state
->start_entry
< 1)
778 pine_state
->start_entry
= 1;
786 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_unknown
), c
);
787 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
788 display_args_err(tmp_20k_buf
, NULL
, 1);
795 else if(args
->action
== aaMail
796 || (args
->action
== aaFolder
&& !args
->data
.folder
)){
797 STRLIST_S
*stp
, **slp
;
799 args
->action
= aaMail
;
801 stp
= new_strlist(*av
);
803 for(slp
= &args
->data
.mail
.addrlist
; *slp
; slp
= &(*slp
)->next
)
809 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), *av
);
810 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
811 display_args_err(tmp_20k_buf
, NULL
, 1);
824 COM_INIT_CMD_LIST
= parse_list(cmd_list
, commas
+1, 0, &error
);
826 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_I_error
), cmd_list
, error
);
827 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
828 display_args_err(tmp_20k_buf
, NULL
, 1);
834 pine_state
->debug_nfiles
= NUMDEBUGFILES
;
836 if(debug_str
&& process_debug_str(debug_str
))
839 if(lc
&& strncmp(lc
, ALPINE_FKEY_NAME
, sizeof(ALPINE_FKEY_NAME
) - 1) == 0)
842 if(do_use_fk
|| do_can_suspend
){
852 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
853 list
[sizeof(list
)-1] = '\0';
856 strncat(list
, "use-function-keys", sizeof(list
)-strlen(list
)-1);
857 list
[sizeof(list
)-1] = '\0';
862 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
863 list
[sizeof(list
)-1] = '\0';
866 strncat(list
, "enable-suspend", sizeof(list
)-strlen(list
)-1);
867 list
[sizeof(list
)-1] = '\0';
874 pine_state
->feat_list_back_compat
= parse_list(list
,commas
+1,0,&error
);
876 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, args_err_internal
, error
);
877 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
878 display_args_err(tmp_20k_buf
, NULL
, 1);
883 if(((do_conf
? 1 : 0)+(pinerc_file
? 1 : 0)) > 1){
884 display_args_err(_("May only have one of -conf and -pinerc"),
896 extern char datestamp
[], hoststamp
[];
899 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "Alpine %s (%s %s) built %s on %s",
901 SYSTYPE
? SYSTYPE
: "?",
902 get_alpine_revision_string(rev
, sizeof(rev
)),
903 datestamp
, hoststamp
);
904 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
905 display_args_err(tmp_20k_buf
, NULL
, 0);
913 dump_new_pinerc(pinerc_file
);
916 * Don't NULL out argv[0] or we might crash in unexpected ways. In OS X, we were
917 * crashing when opening attachments because of this.
919 if(ac
<= 0 && av
!= argv
)
925 * Returns 0 if ok, -1 if error.
928 process_debug_str(char *debug_str
)
932 int new_style_debug_arg
= 0;
939 if(!isdigit((unsigned char)debug_str
[0]))
940 new_style_debug_arg
++;
942 if(new_style_debug_arg
){
947 list
= parse_list(debug_str
, commas
+1, 0, &error
);
949 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_d_error
), debug_str
, error
);
950 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
951 display_args_err(tmp_20k_buf
, NULL
, 1);
956 for(p
= list
; *p
; p
++){
957 if(struncmp(*p
, "timestamp", 9) == 0){
958 ps_global
->debug_timestamp
= 1;
960 else if(struncmp(*p
, "imap", 4) == 0){
962 if(!*q
|| !*(q
+1) || *q
!= '=' ||
963 !isdigit((unsigned char)*(q
+1))){
964 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
965 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
966 display_args_err(tmp_20k_buf
, NULL
, 1);
971 ps_global
->debug_imap
= MIN(5,MAX(0,i
));
974 else if(struncmp(*p
, "flush", 5) == 0){
975 ps_global
->debug_flush
= 1;
977 else if(struncmp(*p
, "tcp", 3) == 0){
978 ps_global
->debug_tcp
= 1;
980 else if(struncmp(*p
, "verbose", 7) == 0){
982 if(!*q
|| !*(q
+1) || *q
!= '=' ||
983 !isdigit((unsigned char)*(q
+1))){
984 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
985 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
986 display_args_err(tmp_20k_buf
, NULL
, 1);
992 else if(struncmp(*p
, "numfiles", 8) == 0){
994 if(!*q
|| !*(q
+1) || *q
!= '=' ||
995 !isdigit((unsigned char)*(q
+1))){
996 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
997 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
998 display_args_err(tmp_20k_buf
, NULL
, 1);
1003 ps_global
->debug_nfiles
= MIN(31,MAX(0,i
));
1006 else if(struncmp(*p
, "malloc", 6) == 0){
1008 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1009 !isdigit((unsigned char)*(q
+1))){
1010 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1011 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1012 display_args_err(tmp_20k_buf
, NULL
, 1);
1017 ps_global
->debug_malloc
= MIN(63,MAX(0,i
));
1020 #if defined(ENABLE_LDAP) && defined(LDAP_DEBUG)
1021 else if(struncmp(*p
, "ldap", 4) == 0){
1023 if(!*q
|| !*(q
+1) || *q
!= '=' ||
1024 !isdigit((unsigned char)*(q
+1))){
1025 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
1026 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1027 display_args_err(tmp_20k_buf
, NULL
, 1);
1037 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown debug keyword \"%s\""), *p
);
1038 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1039 display_args_err(tmp_20k_buf
, NULL
, 1);
1044 free_list_array(&list
);
1048 debug
= atoi(debug_str
);
1050 ps_global
->debug_imap
= 5;
1052 ps_global
->debug_imap
= 4;
1054 ps_global
->debug_imap
= 3;
1056 ps_global
->debug_imap
= 2;
1058 ps_global
->debug_imap
= 1;
1061 ps_global
->debug_timestamp
= 1;
1064 ps_global
->debug_flush
= 1;
1068 if(!new_style_debug_arg
){
1070 ps_global
->debug_malloc
=
1071 (debug
<= DEFAULT_DEBUG
) ? 1 : (debug
< 9) ? 2 : 3;
1072 #else /* !CSRIMALLOC */
1075 ps_global
->debug_malloc
= 2;
1076 #else /* !HAVE_SMALLOC */
1079 ps_global
->debug_malloc
= 32;
1081 #endif /* HAVE_SMALLOC */
1082 #endif /* CSRIMALLOC */
1087 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown flag \"d\", debugging not compiled in"));
1088 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1089 display_args_err(tmp_20k_buf
, NULL
, 1);
1099 args_add_attach(PATMT
**alpp
, char *s
, int deleted
)
1101 PATMT
*atmp
, **atmpp
;
1103 atmp
= (PATMT
*) fs_get(sizeof(PATMT
));
1104 memset(atmp
, 0, sizeof(PATMT
));
1105 atmp
->filename
= cpystr(s
);
1107 #if defined(DOS) || defined(OS2)
1108 (void) removing_quotes(atmp
->filename
);
1112 atmp
->flags
|= A_TMP
;
1114 for(atmpp
= alpp
; *atmpp
; atmpp
= &(*atmpp
)->next
)
1121 /*----------------------------------------------------------------------
1122 print a few lines of help for command line arguments
1126 Result: prints help messages
1127 ----------------------------------------------------------------------*/
1138 /** print out possible starting arguments... **/
1141 * display_args_err expects already translated input
1142 * so we need to translate a line at a time. Since
1143 * the 1st and 3rd args are zero it is ok to call it
1146 * Windows expects the full block of text so we'll pass
1150 for(a
=args_pine_args
; a
&& *a
; a
++){
1152 display_args_err(NULL
, pp
, 0);
1155 display_args_err(NULL
, args_pine_args
, 0);
1162 /*----------------------------------------------------------------------
1163 write argument error to the display...
1167 Result: prints help messages
1168 ----------------------------------------------------------------------*/
1170 display_args_err(char *s
, char **a
, int err
)
1172 char errstr
[256], *errp
;
1173 FILE *fp
= err
? stderr
: stdout
;
1177 snprintf(errp
= errstr
, sizeof(errstr
), "%s: %s", _("Argument Error"), s
);
1178 errstr
[sizeof(errstr
)-1] = '\0';
1185 mswin_messagebox(errp
, err
);
1192 fprintf(fp
, "%s\n", errp
);
1195 fprintf(fp
, "%s\n", *a
++);
1201 * The argument is an argument from the command line. We check to see
1202 * if it is specifying an alternate value for one of the options that is
1203 * normally set in pinerc. If so, we return 1 and set the appropriate
1204 * values in the variables array.
1207 * varname=value1,value2,value3
1208 * feature-list=featurename these are just a special
1209 * feature-list=featurename1,featurename2 case of above
1210 * featurename This is equivalent to above
1214 pinerc_cmdline_opt(char *arg
)
1226 if((value
= strchr(arg
, '=')) != NULL
){
1233 for(v
= ps_global
->vars
; v
->name
!= NULL
; v
++){
1234 if(v
->is_used
&& strucmp(v
->name
, arg
) == 0){
1235 p1
= arg
+ strlen(v
->name
);
1236 if(i
> 0) arg
[i
] = '=';
1238 /*----- Skip to '=' -----*/
1239 while(*p1
&& (*p1
== '\t' || *p1
== ' '))
1243 char buf
[MAILTMPLEN
];
1245 snprintf(buf
, sizeof(buf
), _("Missing \"=\" after -%s\n"), v
->name
);
1246 buf
[sizeof(buf
)-1] = '\0';
1247 exceptional_exit(buf
, -1);
1256 if(i
> 0) arg
[i
] = '=';
1258 /* no match, check for a feature name used directly */
1259 if(v
->name
== NULL
){
1263 if(struncmp(arg
, "no-", 3) == 0)
1268 for(i
= 0; (feat
= feature_list(i
)) != NULL
; i
++){
1269 if(strucmp(featname
, feat
->name
) == 0){
1270 v
= &(ps_global
->vars
)[V_FEATURE_LIST
];
1280 if(v
->is_obsolete
|| !v
->is_user
){
1281 char buf
[MAILTMPLEN
];
1284 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is obsolete\n"), v
->name
);
1286 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is not user settable\n"), v
->name
);
1288 exceptional_exit(buf
, -1);
1293 oldlvalue
= v
->cmdline_val
.l
;
1294 v
->cmdline_val
.l
= NULL
;
1296 else if(v
->cmdline_val
.p
)
1297 fs_give((void **) &(v
->cmdline_val
.p
));
1299 /*----- Matched a variable, get its value ----*/
1300 while(*p1
== ' ' || *p1
== '\t')
1306 v
->cmdline_val
.l
= (char **)fs_get(2 * sizeof(char *));
1308 * we let people leave off the quotes on command line so that
1309 * they don't have to mess with shell quoting
1311 v
->cmdline_val
.l
[0] = cpystr("");
1312 v
->cmdline_val
.l
[1] = NULL
;
1314 free_list_array(&oldlvalue
);
1317 v
->cmdline_val
.p
= cpystr("");
1322 /*--value is non-empty--*/
1323 if(*value
== '"' && !v
->is_list
){
1325 for(p1
= value
; *p1
&& *p1
!= '"'; p1
++)
1330 removing_trailing_white_space(value
);
1332 removing_trailing_white_space(value
);
1340 for(p1
=value
; *p1
; p1
++){ /* generous count of list elements */
1341 if(*p1
== '"') /* ignore ',' if quoted */
1342 was_quoted
= (was_quoted
) ? 0 : 1;
1344 if(*p1
== ',' && !was_quoted
)
1348 lvalue
= parse_list(value
, count
, 0, &error
);
1350 char buf
[MAILTMPLEN
];
1352 snprintf(buf
, sizeof(buf
), "%s in %s = \"%s\"\n", error
, v
->name
, value
);
1353 buf
[sizeof(buf
)-1] = '\0';
1354 exceptional_exit(buf
, -1);
1357 * Special case: turn "" strings into empty strings.
1358 * This allows users to turn off default lists. For example,
1359 * if smtp-server is set then a user could override smtp-server
1360 * with smtp-server="".
1362 for(i
= 0; lvalue
[i
]; i
++)
1363 if(lvalue
[i
][0] == '"' &&
1364 lvalue
[i
][1] == '"' &&
1365 lvalue
[i
][2] == '\0')
1366 lvalue
[i
][0] = '\0';
1371 char **combinedlvalue
;
1374 /* combine old and new cmdline lists */
1375 for(count
= 0, i
= 0; oldlvalue
[i
]; i
++, count
++)
1378 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, count
++)
1381 combinedlvalue
= (char **) fs_get((count
+1) * sizeof(char *));
1382 memset(combinedlvalue
, 0, (count
+1) * sizeof(*combinedlvalue
));
1384 for(i
= 0, j
= 0; oldlvalue
[i
]; i
++, j
++)
1385 combinedlvalue
[j
] = cpystr(oldlvalue
[i
]);
1387 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, j
++)
1388 combinedlvalue
[j
] = cpystr(lvalue
[i
]);
1390 v
->cmdline_val
.l
= combinedlvalue
;
1392 fs_give((void **) &oldlvalue
);
1394 fs_give((void **) &lvalue
);
1397 v
->cmdline_val
.l
= lvalue
;
1400 v
->cmdline_val
.p
= cpystr(value
);