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 2006-2008 University of Washington
8 * Copyright 2013-2014 Eduardo Chappa
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_passfile
[] = N_("missing argument for option \"-passfile\"");
60 static char args_err_non_abs_passfile
[] = N_("argument to \"-passfile\" should be fully-qualified");
62 static char args_err_missing_sort
[] = N_("missing argument for option \"-sort\"");
63 static char args_err_missing_flag_arg
[] = N_("missing argument for flag \"%c\"");
64 static char args_err_missing_flag_num
[] = N_("Non numeric argument for flag \"%c\"");
65 static char args_err_missing_debug_num
[] = N_("Non numeric argument for \"%s\"");
66 static char args_err_missing_url
[] = N_("missing URL for \"-url\"");
67 static char args_err_missing_attachment
[] = N_("missing attachment for \"%s\"");
68 static char args_err_conflict
[] = N_("conflicting action: \"%s\"");
69 static char args_err_unknown
[] = N_("unknown flag \"%c\"");
70 static char args_err_I_error
[] = N_("-I argument \"%s\": %s");
71 static char args_err_d_error
[] = N_("-d argument \"%s\": %s");
72 static char args_err_internal
[] = "%s";
73 static char args_err_missing_copyprc
[] = N_("missing argument for option \"-copy_pinerc\"\nUsage: pine -copy_pinerc <local_pinerc> <remote_pinerc>");
74 static char args_err_missing_copyabook
[] = N_("missing argument for option \"-copy_abook\"\nUsage: pine -copy_abook <local_abook> <remote_abook>");
77 static char *args_pine_args
[] = {
78 N_("Possible Starting Arguments for Alpine program:"),
80 N_(" Argument\tMeaning"),
81 N_(" <addrs>...\tGo directly into composer sending to given address"),
82 N_("\t\tList multiple addresses with a single space between them."),
83 N_("\t\tStandard input redirection is allowed with addresses."),
84 N_("\t\tNote: Places addresses in the \"To\" field only."),
85 N_(" -attach <file>\tGo directly into composer with given file"),
86 N_(" -attachlist <file-list>"),
87 N_(" -attach_and_delete <file>"),
88 N_("\t\tGo to composer, attach file, delete when finished"),
89 N_("\t\tNote: Attach options can't be used if -f, -F"),
90 N_("\t\tadded to Attachment list. Attachlist must be the last"),
91 N_("\t\toption on the command line"),
92 N_(" -bail\t\tExit if pinerc file doesn't already exist"),
94 N_(" -d n\t\tDebug - set debug level to 'n', or use the following:"),
95 N_(" -d keywords...\tflush,timestamp,imap=0..4,tcp,numfiles=0..31,verbose=0..9"),
97 N_(" -f <folder>\tFolder - give folder name to open"),
98 N_(" -c <number>\tContext - which context to apply to -f arg"),
99 N_(" -F <file>\tFile - give file name to open and page through and"),
100 N_("\t\tforward as email."),
101 N_(" -h \t\tHelp - give this list of options"),
102 N_(" -k \t\tKeys - Force use of function keys"),
103 N_(" -z \t\tSuspend - allow use of ^Z suspension"),
104 N_(" -r \t\tRestricted - can only send mail to oneself"),
105 N_(" -sort <sort>\tSort - Specify sort order of folder:"),
106 N_("\t\t\tarrival, subject, threaded, orderedsubject, date,"),
107 N_("\t\t\tfrom, size, score, to, cc, /reverse"),
108 N_(" -i\t\tIndex - Go directly to index, bypassing main menu"),
109 N_(" -I <keystroke_list> Initial keystrokes to be executed"),
110 N_(" -n <number>\tEntry in index to begin on"),
111 N_(" -o \t\tReadOnly - Open first folder read-only"),
112 N_(" -conf\t\tConfiguration - Print out fresh global configuration. The"),
113 N_("\t\tvalues of your global configuration affect all Alpine users"),
114 N_("\t\ton your system unless they have overridden the values in their"),
115 N_("\t\tpinerc files."),
116 N_(" -pinerc <file>\tConfiguration - Put fresh pinerc configuration in <file>"),
117 N_(" -p <pinerc>\tUse alternate .pinerc file"),
118 #if !defined(DOS) && !defined(OS2)
119 N_(" -P <pine.conf>\tUse alternate pine.conf file"),
121 N_(" -aux <aux_files_dir>\tUse this with remote pinerc"),
122 N_(" -P <pine.conf>\tUse pine.conf file for default settings"),
123 N_(" -nosplash \tDisable the PC-Alpine splash screen"),
126 #if defined(APPLEKEYCHAIN) || (WINCRED > 0)
127 N_(" -erase_stored_passwords\tEliminate any stored passwords"),
131 N_(" -passfile <fully_qualified_filename>\tSet the password file to something other"),
132 N_("\t\tthan the default"),
133 #endif /* PASSFILE */
135 #ifdef LOCAL_PASSWD_CACHE
136 N_(" -nowrite_password_cache\tRead from a password cache if there is one, but"),
137 N_("\t\t\t\tnever offer to write a password to the cache"),
138 #endif /* LOCAL_PASSWD_CACHE */
140 N_(" -x <config>\tUse configuration exceptions in <config>."),
141 N_("\t\tExceptions are used to override your default pinerc"),
142 N_("\t\tsettings for a particular platform, can be a local file or"),
143 N_("\t\ta remote folder."),
144 N_(" -v \t\tVersion - show version information"),
145 N_(" -version\tVersion - show version information"),
146 N_(" -supported\tList supported options"),
147 N_(" -url <url>\tOpen the given URL"),
148 N_("\t\tNote: Can't be used if -f, -F"),
149 N_("\t\tStandard input redirection is not allowed with URLs."),
150 N_("\t\tFor mailto URLs, 'body='text should be used in place of"),
151 N_("\t\tinput redirection."),
152 N_(" -copy_pinerc <local_pinerc> <remote_pinerc> copy local pinerc to remote"),
153 N_(" -copy_abook <local_abook> <remote_abook> copy local addressbook to remote"),
154 N_(" -convert_sigs -p <pinerc> convert signatures to literal signatures"),
155 #if defined(_WINDOWS)
156 N_(" -install \tPrompt for some basic setup information"),
157 N_(" -uninstall \tRemove traces of Alpine from Windows system settings"),
158 N_(" -registry <cmd>\tWhere cmd is set,noset,clear,clearsilent,dump"),
160 " -<option>=<value> Assign <value> to the pinerc option <option>",
161 "\t\t e.g. -signature-file=sig1",
162 "\t\t e.g. -color-style=no-color",
163 "\t\t e.g. -feature-list=enable-sigdashes",
164 "\t\t Note: feature-list is additive.",
165 "\t\t You may leave off the \"feature-list=\" part of that,",
166 "\t\t e.g. -enable-sigdashes",
173 * Parse the command line args.
175 * Args: pine_state -- The pine_state structure to put results in
176 * argc, argv -- The obvious
177 * addrs -- Pointer to address list that we set for caller
179 * Result: command arguments parsed
180 * possible printing of help for command line
181 * various flags in pine_state set
182 * returns the string name of the first folder to open
186 pine_args(struct pine
*pine_state
, int argc
, char **argv
, ARGDATA_S
*args
)
192 char *cmd_list
= NULL
;
193 char *debug_str
= NULL
;
195 char *pinerc_file
= NULL
;
201 int do_can_suspend
= 0;
203 struct variable
*vars
= pine_state
->vars
;
207 memset(args
, 0, sizeof(ARGDATA_S
));
208 args
->action
= aaFolder
;
210 pine_state
->pine_name
= (lc
= last_cmpnt(argv
[0])) ? lc
: (lc
= argv
[0]);
212 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%.*s", pine_state
->pine_name
- argv
[0], argv
[0]);
213 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
214 pine_state
->pine_dir
= cpystr(tmp_20k_buf
);
217 /* while more arguments with leading - */
218 Loop
: while(--ac
> 0)
220 /* while more chars in this argument */
222 /* check for pinerc options */
223 if(pinerc_cmdline_opt(*av
)){
224 goto Loop
; /* done with this arg, go to next */
226 /* then other multi-char options */
227 else if(strcmp(*av
, "conf") == 0){
229 goto Loop
; /* done with this arg, go to next */
231 else if(strcmp(*av
, "pinerc") == 0){
235 display_args_err(_(args_err_missing_pinerc
), NULL
, 1);
241 #if defined(DOS) || defined(OS2)
242 else if(strcmp(*av
, "aux") == 0){
244 if((str
= *++av
) != NULL
)
245 pine_state
->aux_files_dir
= cpystr(str
);
248 display_args_err(_(args_err_missing_aux
), NULL
, 1);
254 else if(strcmp(*av
, "nosplash") == 0)
255 goto Loop
; /* already taken care of in WinMain */
258 #if defined(APPLEKEYCHAIN) || (WINCRED > 0)
259 else if(strcmp(*av
, "erase_stored_passwords") == 0){
261 erase_windows_credentials();
263 macos_erase_keychain();
267 #endif /* defined(APPLEKEYCHAIN) || (WINCRED > 0) */
270 else if(strcmp(*av
, "passfile") == 0){
272 if((str
= *++av
) != NULL
){
273 if(!is_absolute_path(str
)){
274 display_args_err(_(args_err_non_abs_passfile
),
279 if(pine_state
->passfile
)
280 fs_give((void **)&pine_state
->passfile
);
282 pine_state
->passfile
= cpystr(str
);
287 display_args_err(_(args_err_missing_passfile
), NULL
, 1);
293 #endif /* PASSFILE */
295 #ifdef LOCAL_PASSWD_CACHE
296 else if(strcmp(*av
, "nowrite_password_cache") == 0){
297 ps_global
->nowrite_password_cache
= 1;
300 #endif /* LOCAL_PASSWD_CACHE */
302 else if(strcmp(*av
, "convert_sigs") == 0){
303 ps_global
->convert_sigs
= 1;
306 else if(strcmp(*av
, "supported") == 0){
307 ps_global
->dump_supported_options
= 1;
310 else if(strcmp(*av
, "copy_pinerc") == 0){
311 if(args
->action
== aaFolder
&& !args
->data
.folder
){
312 args
->action
= aaPrcCopy
;
315 args
->data
.copy
.local
= *++av
;
316 args
->data
.copy
.remote
= *++av
;
319 display_args_err(_(args_err_missing_copyprc
), NULL
, 1);
324 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-copy_pinerc");
325 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
326 display_args_err(tmp_20k_buf
, NULL
, 1);
332 else if(strcmp(*av
, "copy_abook") == 0){
333 if(args
->action
== aaFolder
&& !args
->data
.folder
){
334 args
->action
= aaAbookCopy
;
337 args
->data
.copy
.local
= *++av
;
338 args
->data
.copy
.remote
= *++av
;
341 display_args_err(_(args_err_missing_copyabook
), NULL
, 1);
346 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-copy_abook");
347 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
348 display_args_err(tmp_20k_buf
, NULL
, 1);
354 else if(strcmp(*av
, "sort") == 0){
357 COM_SORT_KEY
= cpystr(sort
);
360 display_args_err(_(args_err_missing_sort
), NULL
, 1);
366 else if(strcmp(*av
, "url") == 0){
367 if(args
->action
== aaFolder
&& !args
->data
.folder
){
368 args
->action
= aaURL
;
370 args
->url
= cpystr(*++av
);
373 display_args_err(_(args_err_missing_url
), NULL
, 1);
378 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-url");
379 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
380 display_args_err(tmp_20k_buf
, NULL
, 1);
386 else if(strcmp(*av
, "attach") == 0){
387 if((args
->action
== aaFolder
&& !args
->data
.folder
)
388 || args
->action
== aaMail
389 || args
->action
== aaURL
){
390 if(args
->action
!= aaURL
)
391 args
->action
= aaMail
;
393 args_add_attach(&args
->data
.mail
.attachlist
,
397 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attach");
398 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
399 display_args_err(tmp_20k_buf
, NULL
, 1);
404 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attach");
405 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
406 display_args_err(tmp_20k_buf
, NULL
, 1);
412 else if(strcmp(*av
, "attachlist") == 0){
413 if((args
->action
== aaFolder
&& !args
->data
.folder
)
414 || args
->action
== aaMail
415 || args
->action
== aaURL
){
416 if(args
->action
!= aaURL
)
417 args
->action
= aaMail
;
420 if(can_access(*(av
+1), READ_ACCESS
) == 0){
422 args_add_attach(&args
->data
.mail
.attachlist
,
431 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attachList");
432 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
433 display_args_err(tmp_20k_buf
, NULL
, 1);
438 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attachList");
439 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
440 display_args_err(tmp_20k_buf
, NULL
, 1);
446 else if(strcmp(*av
, "attach_and_delete") == 0){
447 if((args
->action
== aaFolder
&& !args
->data
.folder
)
448 || args
->action
== aaMail
449 || args
->action
== aaURL
){
450 if(args
->action
!= aaURL
)
451 args
->action
= aaMail
;
453 args_add_attach(&args
->data
.mail
.attachlist
,
457 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_attachment
), "-attach_and_delete");
458 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
459 display_args_err(tmp_20k_buf
, NULL
, 1);
464 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-attach_and_delete");
465 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
466 display_args_err(tmp_20k_buf
, NULL
, 1);
472 else if(strcmp(*av
, "bail") == 0){
473 pine_state
->exit_if_no_pinerc
= 1;
476 else if(strcmp(*av
, "version") == 0){
481 else if(strcmp(*av
, "install") == 0){
482 pine_state
->install_flag
= 1;
483 pine_state
->update_registry
= UREG_ALWAYS_SET
;
486 else if(strcmp(*av
, "uninstall") == 0){
488 * Blast password cache, clear registry settings
491 erase_windows_credentials();
493 mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0);
496 else if(strcmp(*av
, "registry") == 0){
498 if(!strucmp(*++av
, "set")){
499 pine_state
->update_registry
= UREG_ALWAYS_SET
;
501 else if(!strucmp(*av
, "noset")){
502 pine_state
->update_registry
= UREG_NEVER_SET
;
504 else if(!strucmp(*av
, "clear")){
505 if(!mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0))
507 _("Alpine related Registry values removed."),
511 _("Not all Alpine related Registry values could be removed"),
515 else if(!strucmp(*av
, "clearsilent")){
516 mswin_reg(MSWR_OP_BLAST
, MSWR_NULL
, NULL
, 0);
519 else if(!strucmp(*av
, "dump")){
520 char **pRegistry
= mswin_reg_dump();
523 display_args_err(NULL
, pRegistry
, 0);
524 free_list_array(&pRegistry
);
529 display_args_err(_("unknown registry command"),
535 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_flag_arg
), c
);
536 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
537 display_args_err(tmp_20k_buf
, NULL
, 1);
544 /* single char flags */
549 break; /* break back to inner-while */
557 pine_state
->restricted
= 1;
560 pine_state
->open_readonly_on_startup
= 1;
563 pine_state
->start_in_index
= 1;
567 break; /* break back to inner-while */
568 /* these take arguments */
569 case 'f': case 'F': case 'p': case 'I':
570 case 'c': case 'd': case 'P': case 'x': /* string args */
571 case 'n': /* integer args */
576 else if(c
== 'f' || c
== 'F')
579 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_flag_arg
), c
);
580 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
581 display_args_err(tmp_20k_buf
, NULL
, 1);
588 if(args
->action
== aaFolder
&& !args
->data
.folder
){
589 args
->data
.folder
= cpystr(str
);
592 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-f");
593 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
594 display_args_err(tmp_20k_buf
, NULL
, 1);
600 if(args
->action
== aaFolder
&& !args
->data
.folder
){
601 args
->action
= aaMore
;
602 args
->data
.file
= cpystr(str
);
605 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), "-F");
606 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
607 display_args_err(tmp_20k_buf
, NULL
, 1);
620 char path
[MAXPATH
], dir
[MAXPATH
];
622 if(IS_REMOTE(str
) || is_absolute_path(str
)){
623 strncpy(path
, str
, sizeof(path
)-1);
624 path
[sizeof(path
)-1] = '\0';
627 getcwd(dir
, sizeof(path
));
628 build_path(path
, dir
, str
, sizeof(path
));
632 * Pinerc used to be the name of the pinerc
633 * file. Now, since the pinerc can be remote,
634 * we've replaced the variable pinerc with the
635 * structure prc. Unfortunately, other parts of
636 * pine rely on the fact that pinerc is the
637 * name of the pinerc _file_, and use the
638 * directory that the pinerc file is located
639 * in for their own purposes. We keep that so
640 * things will keep working.
643 if(!IS_REMOTE(path
)){
644 if(pine_state
->pinerc
)
645 fs_give((void **)&pine_state
->pinerc
);
647 pine_state
->pinerc
= cpystr(path
);
651 * Last one wins. This would be the place where
652 * we put multiple pinercs in a list if we
653 * were to allow that.
656 free_pinerc_s(&pine_state
->prc
);
658 pine_state
->prc
= new_pinerc_s(path
);
664 char path
[MAXPATH
], dir
[MAXPATH
];
666 if(IS_REMOTE(str
) || is_absolute_path(str
)){
667 strncpy(path
, str
, sizeof(path
)-1);
668 path
[sizeof(path
)-1] = '\0';
671 getcwd(dir
, sizeof(path
));
672 build_path(path
, dir
, str
, sizeof(path
));
675 if(pine_state
->pconf
)
676 free_pinerc_s(&pine_state
->pconf
);
678 pine_state
->pconf
= new_pinerc_s(path
);
684 pine_state
->exceptions
= cpystr(str
);
688 if(!isdigit((unsigned char)str
[0])){
689 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
690 _(args_err_missing_flag_num
), c
);
691 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
692 display_args_err(tmp_20k_buf
, NULL
, 1);
697 pine_state
->init_context
= (short) atoi(str
);
701 if(!isdigit((unsigned char)str
[0])){
702 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
703 _(args_err_missing_flag_num
), c
);
704 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
705 display_args_err(tmp_20k_buf
, NULL
, 1);
710 pine_state
->start_entry
= atoi(str
);
711 if(pine_state
->start_entry
< 1)
712 pine_state
->start_entry
= 1;
720 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_unknown
), c
);
721 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
722 display_args_err(tmp_20k_buf
, NULL
, 1);
729 else if(args
->action
== aaMail
730 || (args
->action
== aaFolder
&& !args
->data
.folder
)){
731 STRLIST_S
*stp
, **slp
;
733 args
->action
= aaMail
;
735 stp
= new_strlist(*av
);
737 for(slp
= &args
->data
.mail
.addrlist
; *slp
; slp
= &(*slp
)->next
)
743 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_conflict
), *av
);
744 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
745 display_args_err(tmp_20k_buf
, NULL
, 1);
758 COM_INIT_CMD_LIST
= parse_list(cmd_list
, commas
+1, 0, &error
);
760 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_I_error
), cmd_list
, error
);
761 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
762 display_args_err(tmp_20k_buf
, NULL
, 1);
768 pine_state
->debug_nfiles
= NUMDEBUGFILES
;
770 if(debug_str
&& process_debug_str(debug_str
))
773 if(lc
&& strncmp(lc
, ALPINE_FKEY_NAME
, sizeof(ALPINE_FKEY_NAME
) - 1) == 0)
776 if(do_use_fk
|| do_can_suspend
){
786 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
787 list
[sizeof(list
)-1] = '\0';
790 strncat(list
, "use-function-keys", sizeof(list
)-strlen(list
)-1);
791 list
[sizeof(list
)-1] = '\0';
796 strncat(list
, ",", sizeof(list
)-strlen(list
)-1);
797 list
[sizeof(list
)-1] = '\0';
800 strncat(list
, "enable-suspend", sizeof(list
)-strlen(list
)-1);
801 list
[sizeof(list
)-1] = '\0';
808 pine_state
->feat_list_back_compat
= parse_list(list
,commas
+1,0,&error
);
810 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, args_err_internal
, error
);
811 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
812 display_args_err(tmp_20k_buf
, NULL
, 1);
817 if(((do_conf
? 1 : 0)+(pinerc_file
? 1 : 0)) > 1){
818 display_args_err(_("May only have one of -conf and -pinerc"),
830 extern char datestamp
[], hoststamp
[];
833 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "Alpine %s (%s %s) built %s on %s",
835 SYSTYPE
? SYSTYPE
: "?",
836 get_alpine_revision_string(rev
, sizeof(rev
)),
837 datestamp
, hoststamp
);
838 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
839 display_args_err(tmp_20k_buf
, NULL
, 0);
847 dump_new_pinerc(pinerc_file
);
850 * Don't NULL out argv[0] or we might crash in unexpected ways. In OS X, we were
851 * crashing when opening attachments because of this.
853 if(ac
<= 0 && av
!= argv
)
859 * Returns 0 if ok, -1 if error.
862 process_debug_str(char *debug_str
)
866 int new_style_debug_arg
= 0;
873 if(!isdigit((unsigned char)debug_str
[0]))
874 new_style_debug_arg
++;
876 if(new_style_debug_arg
){
881 list
= parse_list(debug_str
, commas
+1, 0, &error
);
883 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_d_error
), debug_str
, error
);
884 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
885 display_args_err(tmp_20k_buf
, NULL
, 1);
890 for(p
= list
; *p
; p
++){
891 if(struncmp(*p
, "timestamp", 9) == 0){
892 ps_global
->debug_timestamp
= 1;
894 else if(struncmp(*p
, "imap", 4) == 0){
896 if(!*q
|| !*(q
+1) || *q
!= '=' ||
897 !isdigit((unsigned char)*(q
+1))){
898 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
899 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
900 display_args_err(tmp_20k_buf
, NULL
, 1);
905 ps_global
->debug_imap
= MIN(5,MAX(0,i
));
908 else if(struncmp(*p
, "flush", 5) == 0){
909 ps_global
->debug_flush
= 1;
911 else if(struncmp(*p
, "tcp", 3) == 0){
912 ps_global
->debug_tcp
= 1;
914 else if(struncmp(*p
, "verbose", 7) == 0){
916 if(!*q
|| !*(q
+1) || *q
!= '=' ||
917 !isdigit((unsigned char)*(q
+1))){
918 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
919 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
920 display_args_err(tmp_20k_buf
, NULL
, 1);
926 else if(struncmp(*p
, "numfiles", 8) == 0){
928 if(!*q
|| !*(q
+1) || *q
!= '=' ||
929 !isdigit((unsigned char)*(q
+1))){
930 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
931 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
932 display_args_err(tmp_20k_buf
, NULL
, 1);
937 ps_global
->debug_nfiles
= MIN(31,MAX(0,i
));
940 else if(struncmp(*p
, "malloc", 6) == 0){
942 if(!*q
|| !*(q
+1) || *q
!= '=' ||
943 !isdigit((unsigned char)*(q
+1))){
944 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
945 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
946 display_args_err(tmp_20k_buf
, NULL
, 1);
951 ps_global
->debug_malloc
= MIN(63,MAX(0,i
));
954 #if defined(ENABLE_LDAP) && defined(LDAP_DEBUG)
955 else if(struncmp(*p
, "ldap", 4) == 0){
957 if(!*q
|| !*(q
+1) || *q
!= '=' ||
958 !isdigit((unsigned char)*(q
+1))){
959 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _(args_err_missing_debug_num
), *p
);
960 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
961 display_args_err(tmp_20k_buf
, NULL
, 1);
971 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown debug keyword \"%s\""), *p
);
972 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
973 display_args_err(tmp_20k_buf
, NULL
, 1);
978 free_list_array(&list
);
982 debug
= atoi(debug_str
);
984 ps_global
->debug_imap
= 5;
986 ps_global
->debug_imap
= 4;
988 ps_global
->debug_imap
= 3;
990 ps_global
->debug_imap
= 2;
992 ps_global
->debug_imap
= 1;
995 ps_global
->debug_timestamp
= 1;
998 ps_global
->debug_flush
= 1;
1002 if(!new_style_debug_arg
){
1004 ps_global
->debug_malloc
=
1005 (debug
<= DEFAULT_DEBUG
) ? 1 : (debug
< 9) ? 2 : 3;
1006 #else /* !CSRIMALLOC */
1009 ps_global
->debug_malloc
= 2;
1010 #else /* !HAVE_SMALLOC */
1013 ps_global
->debug_malloc
= 32;
1015 #endif /* HAVE_SMALLOC */
1016 #endif /* CSRIMALLOC */
1021 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, _("unknown flag \"d\", debugging not compiled in"));
1022 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
1023 display_args_err(tmp_20k_buf
, NULL
, 1);
1033 args_add_attach(PATMT
**alpp
, char *s
, int deleted
)
1035 PATMT
*atmp
, **atmpp
;
1037 atmp
= (PATMT
*) fs_get(sizeof(PATMT
));
1038 memset(atmp
, 0, sizeof(PATMT
));
1039 atmp
->filename
= cpystr(s
);
1041 #if defined(DOS) || defined(OS2)
1042 (void) removing_quotes(atmp
->filename
);
1046 atmp
->flags
|= A_TMP
;
1048 for(atmpp
= alpp
; *atmpp
; atmpp
= &(*atmpp
)->next
)
1055 /*----------------------------------------------------------------------
1056 print a few lines of help for command line arguments
1060 Result: prints help messages
1061 ----------------------------------------------------------------------*/
1072 /** print out possible starting arguments... **/
1075 * display_args_err expects already translated input
1076 * so we need to translate a line at a time. Since
1077 * the 1st and 3rd args are zero it is ok to call it
1080 * Windows expects the full block of text so we'll pass
1084 for(a
=args_pine_args
; a
&& *a
; a
++){
1086 display_args_err(NULL
, pp
, 0);
1089 display_args_err(NULL
, args_pine_args
, 0);
1096 /*----------------------------------------------------------------------
1097 write argument error to the display...
1101 Result: prints help messages
1102 ----------------------------------------------------------------------*/
1104 display_args_err(char *s
, char **a
, int err
)
1106 char errstr
[256], *errp
;
1107 FILE *fp
= err
? stderr
: stdout
;
1111 snprintf(errp
= errstr
, sizeof(errstr
), "%s: %s", _("Argument Error"), s
);
1112 errstr
[sizeof(errstr
)-1] = '\0';
1119 mswin_messagebox(errp
, err
);
1126 fprintf(fp
, "%s\n", errp
);
1129 fprintf(fp
, "%s\n", *a
++);
1135 * The argument is an argument from the command line. We check to see
1136 * if it is specifying an alternate value for one of the options that is
1137 * normally set in pinerc. If so, we return 1 and set the appropriate
1138 * values in the variables array.
1141 * varname=value1,value2,value3
1142 * feature-list=featurename these are just a special
1143 * feature-list=featurename1,featurename2 case of above
1144 * featurename This is equivalent to above
1148 pinerc_cmdline_opt(char *arg
)
1160 for(v
= ps_global
->vars
; v
->name
!= NULL
; v
++){
1161 if(v
->is_used
&& struncmp(v
->name
, arg
, strlen(v
->name
)) == 0){
1162 p1
= arg
+ strlen(v
->name
);
1164 /*----- Skip to '=' -----*/
1165 while(*p1
&& (*p1
== '\t' || *p1
== ' '))
1169 char buf
[MAILTMPLEN
];
1171 snprintf(buf
, sizeof(buf
), _("Missing \"=\" after -%s\n"), v
->name
);
1172 buf
[sizeof(buf
)-1] = '\0';
1173 exceptional_exit(buf
, -1);
1181 /* no match, check for a feature name used directly */
1182 if(v
->name
== NULL
){
1186 if(struncmp(arg
, "no-", 3) == 0)
1191 for(i
= 0; (feat
= feature_list(i
)) != NULL
; i
++){
1192 if(strucmp(featname
, feat
->name
) == 0){
1193 v
= &(ps_global
->vars
)[V_FEATURE_LIST
];
1203 if(v
->is_obsolete
|| !v
->is_user
){
1204 char buf
[MAILTMPLEN
];
1207 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is obsolete\n"), v
->name
);
1209 snprintf(buf
, sizeof(buf
), _("Option \"%s\" is not user settable\n"), v
->name
);
1211 exceptional_exit(buf
, -1);
1216 oldlvalue
= v
->cmdline_val
.l
;
1217 v
->cmdline_val
.l
= NULL
;
1219 else if(v
->cmdline_val
.p
)
1220 fs_give((void **) &(v
->cmdline_val
.p
));
1222 /*----- Matched a variable, get its value ----*/
1223 while(*p1
== ' ' || *p1
== '\t')
1229 v
->cmdline_val
.l
= (char **)fs_get(2 * sizeof(char *));
1231 * we let people leave off the quotes on command line so that
1232 * they don't have to mess with shell quoting
1234 v
->cmdline_val
.l
[0] = cpystr("");
1235 v
->cmdline_val
.l
[1] = NULL
;
1237 free_list_array(&oldlvalue
);
1240 v
->cmdline_val
.p
= cpystr("");
1245 /*--value is non-empty--*/
1246 if(*value
== '"' && !v
->is_list
){
1248 for(p1
= value
; *p1
&& *p1
!= '"'; p1
++);
1252 removing_trailing_white_space(value
);
1254 removing_trailing_white_space(value
);
1262 for(p1
=value
; *p1
; p1
++){ /* generous count of list elements */
1263 if(*p1
== '"') /* ignore ',' if quoted */
1264 was_quoted
= (was_quoted
) ? 0 : 1;
1266 if(*p1
== ',' && !was_quoted
)
1270 lvalue
= parse_list(value
, count
, 0, &error
);
1272 char buf
[MAILTMPLEN
];
1274 snprintf(buf
, sizeof(buf
), "%s in %s = \"%s\"\n", error
, v
->name
, value
);
1275 buf
[sizeof(buf
)-1] = '\0';
1276 exceptional_exit(buf
, -1);
1279 * Special case: turn "" strings into empty strings.
1280 * This allows users to turn off default lists. For example,
1281 * if smtp-server is set then a user could override smtp-server
1282 * with smtp-server="".
1284 for(i
= 0; lvalue
[i
]; i
++)
1285 if(lvalue
[i
][0] == '"' &&
1286 lvalue
[i
][1] == '"' &&
1287 lvalue
[i
][2] == '\0')
1288 lvalue
[i
][0] = '\0';
1293 char **combinedlvalue
;
1296 /* combine old and new cmdline lists */
1297 for(count
= 0, i
= 0; oldlvalue
[i
]; i
++, count
++)
1300 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, count
++)
1303 combinedlvalue
= (char **) fs_get((count
+1) * sizeof(char *));
1304 memset(combinedlvalue
, 0, (count
+1) * sizeof(*combinedlvalue
));
1306 for(i
= 0, j
= 0; oldlvalue
[i
]; i
++, j
++)
1307 combinedlvalue
[j
] = cpystr(oldlvalue
[i
]);
1309 for(i
= 0; lvalue
&& lvalue
[i
]; i
++, j
++)
1310 combinedlvalue
[j
] = cpystr(lvalue
[i
]);
1312 v
->cmdline_val
.l
= combinedlvalue
;
1314 fs_give((void **) &oldlvalue
);
1316 fs_give((void **) &lvalue
);
1319 v
->cmdline_val
.l
= lvalue
;
1322 v
->cmdline_val
.p
= cpystr(value
);