3 * mhpath.c -- print full pathnames of nmh messages and folders
10 static struct swit switches[] = {
19 * Add space for message/sequence names
20 * by MAXMSGS at a time.
26 main(int argc, char **argv)
28 int i, maxmsgs, nummsgs;
29 char *cp, *maildir, *folder = NULL;
31 char **arguments, buf[BUFSIZ];
35 setlocale(LC_ALL, "");
37 invo_name = r1bindex (argv[0], '/');
39 /* read user profile/context */
42 arguments = getarguments (invo_name, argc, argv, 1);
46 * Allocate initial space to record message
51 if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs)))))
52 adios (NULL, "unable to allocate storage");
57 while ((cp = *argp++)) {
59 switch (smatch (++cp, switches)) {
61 ambigsw (cp, switches);
64 adios (NULL, "-%s unknown", cp);
67 snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
69 print_help (buf, switches, 1);
72 print_version(invo_name);
76 if (*cp == '+' || *cp == '@') {
78 adios (NULL, "only one folder at a time!");
80 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
83 * if necessary, reallocate space for
84 * message/sequence names
86 if (nummsgs >= maxmsgs) {
88 if (!(msgs = (char **) realloc (msgs,
89 (size_t) (maxmsgs * sizeof(*msgs)))))
90 adios (NULL, "unable to reallocate msgs storage ");
96 if (!context_find ("path"))
97 free (path ("./", TFOLDER));
100 folder = getfolder (1);
101 maildir = m_maildir (folder);
103 /* If no messages are given, print folder pathname */
105 printf ("%s\n", maildir);
109 if (chdir (maildir) == NOTOK)
110 adios (maildir, "unable to change directory to");
112 /* read folder and create message structure */
113 if (!(mp = folder_read (folder)))
114 adios (NULL, "unable to read folder %s", folder);
117 * We need to make sure there is message status space
118 * for all the message numbers from 1 to "new" since
119 * mhpath can select empty slots. If we are adding
120 * space at the end, we go ahead and add 10 slots.
122 if (mp->hghmsg >= mp->hghoff) {
123 if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10)))
124 adios (NULL, "unable to allocate folder storage");
125 } else if (mp->lowoff > 1) {
126 if (!(mp = folder_realloc (mp, 1, mp->hghoff)))
127 adios (NULL, "unable to allocate folder storage");
130 mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */
132 /* parse all the message ranges/sequences and set SELECTED */
133 for (i = 0; i < nummsgs; i++)
134 if (!m_convert (mp, msgs[i]))
137 seq_setprev (mp); /* set the previous-sequence */
139 /* print the path of all selected messages */
140 for (i = mp->lowsel; i <= mp->hghsel; i++)
141 if (is_selected (mp, i))
142 printf ("%s/%s\n", mp->foldpath, m_name (i));
144 seq_save (mp); /* synchronize message sequences */
145 context_save (); /* save the context file */
146 folder_free (mp); /* free folder/message structure */