Commit 2ab1e3f5 2ab1e3f527f2ea2e055d5b66f1f51b9f9b3b3ce8 by Sergey Poznyakoff

Reverted changes

1 parent 4c1a994b
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007 2 Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
45 #include <mailutils/mailbox.h> 45 #include <mailutils/mailbox.h>
46 #include <mailutils/nls.h> 46 #include <mailutils/nls.h>
47 #include <mailutils/argcv.h> 47 #include <mailutils/argcv.h>
48 #include "mu_umaxtostr.h"
49 48
50 #define ARG_LOG_FACILITY 1 49 #define ARG_LOG_FACILITY 1
51 #define ARG_LOCK_FLAGS 2 50 #define ARG_LOCK_FLAGS 2
...@@ -56,20 +55,6 @@ ...@@ -56,20 +55,6 @@
56 #define ARG_SHOW_OPTIONS 7 55 #define ARG_SHOW_OPTIONS 7
57 #define ARG_LICENSE 8 56 #define ARG_LICENSE 8
58 #define ARG_MAILBOX_TYPE 9 57 #define ARG_MAILBOX_TYPE 9
59 #define ARG_FILE_OPTION 10
60 #define ARG_LINE_OPTION 11
61
62 static struct argp_option mu_locus_argp_options[] =
63 {
64 { "FILE", ARG_FILE_OPTION, "STRING", OPTION_HIDDEN,
65 "File name where the following options appeared "
66 "(empty string for command line)", 0 },
67 { "LINE", ARG_LINE_OPTION, "NUMBER", OPTION_HIDDEN,
68 "Line number where the following options appeared", 0 },
69 { NULL, 0, NULL, 0, NULL, 0 }
70 };
71
72
73 58
74 static struct argp_option mu_common_argp_options[] = 59 static struct argp_option mu_common_argp_options[] =
75 { 60 {
...@@ -145,30 +130,16 @@ static struct argp_option mu_daemon_argp_option[] = { ...@@ -145,30 +130,16 @@ static struct argp_option mu_daemon_argp_option[] = {
145 { NULL, 0, NULL, 0, NULL, 0 } 130 { NULL, 0, NULL, 0, NULL, 0 }
146 }; 131 };
147 132
148 static error_t mu_locus_argp_parser (int key, char *arg,
149 struct argp_state *state);
150 static error_t mu_common_argp_parser (int key, char *arg, 133 static error_t mu_common_argp_parser (int key, char *arg,
151 struct argp_state *state); 134 struct argp_state *state);
152 static error_t mu_daemon_argp_parser (int key, char *arg, 135 static error_t mu_daemon_argp_parser (int key, char *arg,
153 struct argp_state *state); 136 struct argp_state *state);
154 137
155 struct argp mu_locus_argp = {
156 mu_locus_argp_options,
157 mu_locus_argp_parser
158 };
159
160 struct argp mu_common_argp = { 138 struct argp mu_common_argp = {
161 mu_common_argp_options, 139 mu_common_argp_options,
162 mu_common_argp_parser, 140 mu_common_argp_parser,
163 }; 141 };
164 142
165 struct argp_child mu_locus_argp_child = {
166 &mu_locus_argp,
167 0,
168 NULL,
169 0,
170 };
171
172 struct argp_child mu_common_argp_child = { 143 struct argp_child mu_common_argp_child = {
173 &mu_common_argp, 144 &mu_common_argp,
174 0, 145 0,
...@@ -411,49 +382,6 @@ mu_check_option (char *name) ...@@ -411,49 +382,6 @@ mu_check_option (char *name)
411 } 382 }
412 383
413 static error_t 384 static error_t
414 mu_locus_argp_parser (int key, char *arg, struct argp_state *state)
415 {
416 static char *file_name = NULL;
417 static char *line_num;
418
419 switch (key)
420 {
421 case ARGP_KEY_INIT:
422 state->flags |= ARGP_NO_ERRS;
423 break;
424
425 case ARG_FILE_OPTION:
426 free (file_name);
427 file_name = arg[0] ? arg : NULL;
428 /*FIXME: This doesn't work
429 if (!file_name)
430 state->flags &= ~(ARGP_NO_ERRS|ARGP_NO_EXIT);*/
431 break;
432
433 case ARG_LINE_OPTION:
434 free (line_num);
435 line_num = arg;
436 break;
437
438 case ARGP_KEY_ERROR:
439 state->flags &= ~(ARGP_NO_ERRS|ARGP_NO_EXIT);
440 if (file_name)
441 argp_error(state,
442 "%s:%s: unknown option `%s'", file_name, line_num,
443 state->argv[state->next-1]);
444 else
445 argp_error(state,
446 "unknown option `%s'",
447 state->argv[state->next-1]);
448 /* FALL THROUGH */
449 default:
450 return ARGP_ERR_UNKNOWN;
451 }
452 return 0;
453 }
454
455
456 static error_t
457 mu_common_argp_parser (int key, char *arg, struct argp_state *state) 385 mu_common_argp_parser (int key, char *arg, struct argp_state *state)
458 { 386 {
459 int err = 0; 387 int err = 0;
...@@ -663,16 +591,7 @@ read_rc (const char *progname, const char *name, const char *capa[], ...@@ -663,16 +591,7 @@ read_rc (const char *progname, const char *name, const char *capa[],
663 int x_argc = *argc; 591 int x_argc = *argc;
664 char **x_argv = *argv; 592 char **x_argv = *argv;
665 char* rcfile = mu_tilde_expansion (name, "/", NULL); 593 char* rcfile = mu_tilde_expansion (name, "/", NULL);
666 size_t line = 0; 594
667
668 #define XPAND(n) \
669 x_argv = realloc (x_argv, (x_argc + n) * sizeof (x_argv[0])); \
670 if (!x_argv) \
671 { \
672 fprintf (stderr, _("%s: not enough memory\n"), progname); \
673 exit (1); \
674 }
675
676 if (!rcfile) 595 if (!rcfile)
677 return; 596 return;
678 597
...@@ -682,17 +601,12 @@ read_rc (const char *progname, const char *name, const char *capa[], ...@@ -682,17 +601,12 @@ read_rc (const char *progname, const char *name, const char *capa[],
682 free(rcfile); 601 free(rcfile);
683 return; 602 return;
684 } 603 }
685 604
686 XPAND (2);
687 x_argv[x_argc++] = "--FILE";
688 x_argv[x_argc++] = strdup (rcfile);
689
690 while (getline (&buf, &n, fp) > 0) 605 while (getline (&buf, &n, fp) > 0)
691 { 606 {
692 char *kwp, *p; 607 char *kwp, *p;
693 int len; 608 int len;
694 609
695 line++;
696 for (kwp = buf; *kwp && isspace (*kwp); kwp++) 610 for (kwp = buf; *kwp && isspace (*kwp); kwp++)
697 ; 611 ;
698 612
...@@ -748,7 +662,7 @@ read_rc (const char *progname, const char *name, const char *capa[], ...@@ -748,7 +662,7 @@ read_rc (const char *progname, const char *name, const char *capa[],
748 { 662 {
749 int i, n_argc = 0; 663 int i, n_argc = 0;
750 char **n_argv; 664 char **n_argv;
751 665
752 if (mu_argcv_get (p, "", NULL, &n_argc, &n_argv)) 666 if (mu_argcv_get (p, "", NULL, &n_argc, &n_argv))
753 { 667 {
754 mu_argcv_free (n_argc, n_argv); 668 mu_argcv_free (n_argc, n_argv);
...@@ -757,10 +671,14 @@ read_rc (const char *progname, const char *name, const char *capa[], ...@@ -757,10 +671,14 @@ read_rc (const char *progname, const char *name, const char *capa[],
757 linebuf = NULL; 671 linebuf = NULL;
758 continue; 672 continue;
759 } 673 }
760 674 x_argv = realloc (x_argv,
761 XPAND (n_argc + 2); 675 (x_argc + n_argc) * sizeof (x_argv[0]));
762 x_argv[x_argc++] = "--LINE"; 676 if (!x_argv)
763 x_argv[x_argc++] = strdup (mu_umaxtostr (0, line)); 677 {
678 fprintf (stderr, _("%s: not enough memory\n"), progname);
679 exit (1);
680 }
681
764 for (i = 0; i < n_argc; i++) 682 for (i = 0; i < n_argc; i++)
765 x_argv[x_argc++] = mu_tilde_expansion (n_argv[i], "/", NULL); 683 x_argv[x_argc++] = mu_tilde_expansion (n_argv[i], "/", NULL);
766 684
...@@ -771,12 +689,8 @@ read_rc (const char *progname, const char *name, const char *capa[], ...@@ -771,12 +689,8 @@ read_rc (const char *progname, const char *name, const char *capa[],
771 linebuf = NULL; 689 linebuf = NULL;
772 } 690 }
773 fclose (fp); 691 fclose (fp);
774 free (rcfile); 692 free(rcfile);
775 693
776 XPAND (2);
777 x_argv[x_argc++] = "--FILE";
778 x_argv[x_argc++] = "";
779
780 *argc = x_argc; 694 *argc = x_argc;
781 *argv = x_argv; 695 *argv = x_argv;
782 } 696 }
...@@ -903,7 +817,6 @@ struct argp_capa { ...@@ -903,7 +817,6 @@ struct argp_capa {
903 char *capability; 817 char *capability;
904 struct argp_child *child; 818 struct argp_child *child;
905 } mu_argp_capa[MU_MAX_CAPA] = { 819 } mu_argp_capa[MU_MAX_CAPA] = {
906 {"locus", &mu_locus_argp_child},
907 {"common", &mu_common_argp_child}, 820 {"common", &mu_common_argp_child},
908 {"license", &mu_license_argp_child}, 821 {"license", &mu_license_argp_child},
909 {"mailbox", &mu_mailbox_argp_child}, 822 {"mailbox", &mu_mailbox_argp_child},
...@@ -949,10 +862,9 @@ mu_build_argp (const struct argp *template, const char *capa[]) ...@@ -949,10 +862,9 @@ mu_build_argp (const struct argp *template, const char *capa[])
949 const struct argp_option *opt; 862 const struct argp_option *opt;
950 struct argp *argp; 863 struct argp *argp;
951 int group = 0; 864 int group = 0;
952 const char *cs; 865
953
954 /* Count the capabilities. */ 866 /* Count the capabilities. */
955 for (n = 1; capa && capa[n]; n++) 867 for (n = 0; capa && capa[n]; n++)
956 ; 868 ;
957 if (template->children) 869 if (template->children)
958 for (; template->children[n].argp; n++) 870 for (; template->children[n].argp; n++)
...@@ -979,15 +891,14 @@ mu_build_argp (const struct argp *template, const char *capa[]) ...@@ -979,15 +891,14 @@ mu_build_argp (const struct argp *template, const char *capa[])
979 891
980 group++; 892 group++;
981 893
982 /* Append any capabilities to the children or options, as appropriate. 894 /* Append any capabilities to the children or options, as appropriate. */
983 "locus" is always added */ 895 for (n = 0; capa && capa[n]; n++)
984 for (cs = "locus", n = 0; cs; cs = capa[n++])
985 { 896 {
986 struct argp_child *child = find_argp_child (cs); 897 struct argp_child *child = find_argp_child (capa[n]);
987 if (!child) 898 if (!child)
988 { 899 {
989 mu_error (_("INTERNAL ERROR: requested unknown argp capability %s (please report)"), 900 mu_error (_("INTERNAL ERROR: requested unknown argp capability %s (please report)"),
990 cs); 901 capa[n]);
991 abort (); 902 abort ();
992 } 903 }
993 ap[nchild] = *child; 904 ap[nchild] = *child;
......