]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
2f21f44505ce3aa18617e4c9301e936d76b40699
1 /* mhpath.c -- print full pathnames of nmh messages and folders
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
9 #include "sbr/seq_save.h"
10 #include "sbr/smatch.h"
11 #include "sbr/m_convert.h"
12 #include "sbr/getfolder.h"
13 #include "sbr/folder_read.h"
14 #include "sbr/folder_realloc.h"
15 #include "sbr/folder_free.h"
16 #include "sbr/context_save.h"
17 #include "sbr/context_find.h"
18 #include "sbr/ambigsw.h"
20 #include "sbr/print_version.h"
21 #include "sbr/print_help.h"
22 #include "sbr/error.h"
25 #include "sbr/m_maildir.h"
27 #define MHPATH_SWITCHES \
28 X("version", 0, VERSIONSW) \
29 X("help", 0, HELPSW) \
31 #define X(sw, minchars, id) id,
32 DEFINE_SWITCH_ENUM(MHPATH
);
35 #define X(sw, minchars, id) { sw, minchars, id },
36 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
40 main(int argc
, char **argv
)
43 char *cp
, *maildir
, *folder
= NULL
;
45 char **arguments
, buf
[BUFSIZ
];
46 struct msgs_array msgs
= { 0, 0, NULL
};
49 if (nmh_init(argv
[0], true, false)) { return 1; }
51 arguments
= getarguments (invo_name
, argc
, argv
, 1);
57 while ((cp
= *argp
++)) {
59 switch (smatch (++cp
, switches
)) {
61 ambigsw (cp
, switches
);
64 die("-%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 die("only one folder at a time!");
79 folder
= pluspath (cp
);
81 app_msgarg(&msgs
, cp
);
84 if (!context_find ("path"))
85 free (path ("./", TFOLDER
));
88 folder
= getfolder (1);
89 maildir
= m_maildir (folder
);
91 /* If no messages are given, print folder pathname */
97 if (chdir (maildir
) == NOTOK
)
98 adios (maildir
, "unable to change directory to");
100 /* read folder and create message structure */
101 if (!(mp
= folder_read (folder
, 1)))
102 die("unable to read folder %s", folder
);
105 * We need to make sure there is message status space
106 * for all the message numbers from 1 to "new" since
107 * mhpath can select empty slots. If we are adding
108 * space at the end, we go ahead and add 10 slots.
110 if (mp
->hghmsg
>= mp
->hghoff
) {
111 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
112 die("unable to allocate folder storage");
113 } else if (mp
->lowoff
> 1) {
114 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
115 die("unable to allocate folder storage");
118 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
120 /* parse all the message ranges/sequences and set SELECTED */
121 for (i
= 0; i
< msgs
.size
; i
++)
122 if (!m_convert (mp
, msgs
.msgs
[i
]))
125 seq_setprev (mp
); /* set the previous-sequence */
127 /* print the path of all selected messages */
128 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
129 if (is_selected (mp
, i
))
130 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
132 seq_save (mp
); /* synchronize message sequences */
133 context_save (); /* save the context file */
134 folder_free (mp
); /* free folder/message structure */