Removed configure flag --disable-locale and have it always enabled.
[mmh] / uip / mhpath.c
1 /*
2 ** mhpath.c -- print full pathnames of nmh messages and folders
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <h/utils.h>
11
12 static struct swit switches[] = {
13 #define VERSIONSW 0
14         { "Version", 0 },
15 #define HELPSW  1
16         { "help", 0 },
17         { NULL, 0 }
18 };
19
20 int
21 main(int argc, char **argv)
22 {
23         int i;
24         char *cp, *maildir, *folder = NULL;
25         char **argp;
26         char **arguments, buf[BUFSIZ];
27         struct msgs_array msgs = { 0, 0, NULL };
28         struct msgs *mp;
29
30         setlocale(LC_ALL, "");
31         invo_name = mhbasename(argv[0]);
32
33         /* read user profile/context */
34         context_read();
35
36         arguments = getarguments(invo_name, argc, argv, 1);
37         argp = arguments;
38
39         /*
40         ** Parse arguments
41         */
42         while ((cp = *argp++)) {
43                 if (*cp == '-') {
44                         switch (smatch(++cp, switches)) {
45                         case AMBIGSW:
46                                 ambigsw(cp, switches);
47                                 done(1);
48                         case UNKWNSW:
49                                 adios(NULL, "-%s unknown", cp);
50
51                         case HELPSW:
52                                 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
53                                 print_help(buf, switches, 1);
54                                 done(1);
55                         case VERSIONSW:
56                                 print_version(invo_name);
57                                 done(1);
58                         }
59                 }
60                 if (*cp == '+' || *cp == '@') {
61                         if (folder)
62                                 adios(NULL, "only one folder at a time!");
63                         else
64                                 folder = getcpy(expandfol(cp));
65                 } else
66                         app_msgarg(&msgs, cp);
67         }
68
69         if (!folder)
70                 folder = getcurfol();
71         maildir = toabsdir(folder);
72
73         /* If no messages are given, print folder pathname */
74         if (!msgs.size) {
75                 printf("%s\n", maildir);
76                 done(0);
77         }
78
79         if (chdir(maildir) == NOTOK)
80                 adios(maildir, "unable to change directory to");
81
82         /* read folder and create message structure */
83         if (!(mp = folder_read(folder)))
84                 adios(NULL, "unable to read folder %s", folder);
85
86         /*
87         ** We need to make sure there is message status space
88         ** for all the message numbers from 1 to one beyond last since
89         ** mhpath can select empty slots.  If we are adding
90         ** space at the end, we go ahead and add 10 slots.
91         */
92         if (mp->hghmsg >= mp->hghoff) {
93                 if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10)))
94                         adios(NULL, "unable to allocate folder storage");
95         } else if (mp->lowoff > 1) {
96                 if (!(mp = folder_realloc(mp, 1, mp->hghoff)))
97                         adios(NULL, "unable to allocate folder storage");
98         }
99         /*
100         ** TODO: As folder_realloc() checks itself if the realloc
101         ** really is necesary, why don't we then:
102         **    if (!(mp = folder_realloc (mp, 1, mp->hghmsg+1)))
103         **        adios (NULL, "unable to allocate folder storage");
104         ** ? This at least appears most clear to me. -- meillo
105         */
106
107
108         mp->msgflags |= ALLOW_BEYOND;  /* allow the beyond sequence */
109
110         /* parse all the message ranges/sequences and set SELECTED */
111         for (i = 0; i < msgs.size; i++)
112                 if (!m_convert(mp, msgs.msgs[i]))
113                         done(1);
114
115         seq_setprev(mp);  /* set the previous-sequence */
116
117         /* print the path of all selected messages */
118         for (i = mp->lowsel; i <= mp->hghsel; i++)
119                 if (is_selected(mp, i))
120                         printf("%s/%s\n", mp->foldpath, m_name(i));
121
122         seq_save(mp);  /* synchronize message sequences */
123         context_save();  /* save the context file */
124         folder_free(mp);  /* free folder/message structure */
125         done(0);
126         return 1;
127 }