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