]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
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_setprev.h"
10 #include "sbr/seq_save.h"
11 #include "sbr/smatch.h"
12 #include "sbr/m_convert.h"
13 #include "sbr/getfolder.h"
14 #include "sbr/folder_read.h"
15 #include "sbr/folder_realloc.h"
16 #include "sbr/folder_free.h"
17 #include "sbr/context_save.h"
18 #include "sbr/context_find.h"
19 #include "sbr/ambigsw.h"
21 #include "sbr/print_version.h"
22 #include "sbr/print_help.h"
23 #include "sbr/error.h"
26 #include "sbr/m_maildir.h"
28 #define MHPATH_SWITCHES \
29 X("version", 0, VERSIONSW) \
30 X("help", 0, HELPSW) \
32 #define X(sw, minchars, id) id,
33 DEFINE_SWITCH_ENUM(MHPATH
);
36 #define X(sw, minchars, id) { sw, minchars, id },
37 DEFINE_SWITCH_ARRAY(MHPATH
, switches
);
41 main(int argc
, char **argv
)
44 char *cp
, *maildir
, *folder
= NULL
;
46 char **arguments
, buf
[BUFSIZ
];
47 struct msgs_array msgs
= { 0, 0, NULL
};
50 if (nmh_init(argv
[0], true, false)) { return 1; }
52 arguments
= getarguments (invo_name
, argc
, argv
, 1);
58 while ((cp
= *argp
++)) {
60 switch (smatch (++cp
, switches
)) {
62 ambigsw (cp
, switches
);
65 die("-%s unknown", cp
);
68 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
70 print_help (buf
, switches
, 1);
73 print_version(invo_name
);
77 if (*cp
== '+' || *cp
== '@') {
79 die("only one folder at a time!");
80 folder
= pluspath (cp
);
82 app_msgarg(&msgs
, cp
);
85 if (!context_find ("path"))
86 free (path ("./", TFOLDER
));
89 folder
= getfolder (1);
90 maildir
= m_maildir (folder
);
92 /* If no messages are given, print folder pathname */
98 if (chdir (maildir
) == NOTOK
)
99 adios (maildir
, "unable to change directory to");
101 /* read folder and create message structure */
102 if (!(mp
= folder_read (folder
, 1)))
103 die("unable to read folder %s", folder
);
106 * We need to make sure there is message status space
107 * for all the message numbers from 1 to "new" since
108 * mhpath can select empty slots. If we are adding
109 * space at the end, we go ahead and add 10 slots.
111 if (mp
->hghmsg
>= mp
->hghoff
) {
112 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
113 die("unable to allocate folder storage");
114 } else if (mp
->lowoff
> 1) {
115 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
116 die("unable to allocate folder storage");
119 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
121 /* parse all the message ranges/sequences and set SELECTED */
122 for (i
= 0; i
< msgs
.size
; i
++)
123 if (!m_convert (mp
, msgs
.msgs
[i
]))
126 seq_setprev (mp
); /* set the previous-sequence */
128 /* print the path of all selected messages */
129 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
130 if (is_selected (mp
, i
))
131 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
133 seq_save (mp
); /* synchronize message sequences */
134 context_save (); /* save the context file */
135 folder_free (mp
); /* free folder/message structure */