]>
diplodocus.org Git - nmh/blob - uip/mhpath.c
3 * mhpath.c -- print full pathnames of nmh messages and folders
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.
15 static struct swit switches
[] = {
24 * Add space for message/sequence names
25 * by MAXMSGS at a time.
31 main(int argc
, char **argv
)
33 int i
, maxmsgs
, nummsgs
;
34 char *cp
, *maildir
, *folder
= NULL
;
36 char **arguments
, buf
[BUFSIZ
];
40 setlocale(LC_ALL
, "");
42 invo_name
= r1bindex (argv
[0], '/');
44 /* read user profile/context */
47 arguments
= getarguments (invo_name
, argc
, argv
, 1);
51 * Allocate initial space to record message
56 msgs
= (char **) mh_xmalloc ((size_t) (maxmsgs
* sizeof(*msgs
)));
61 while ((cp
= *argp
++)) {
63 switch (smatch (++cp
, switches
)) {
65 ambigsw (cp
, switches
);
68 adios (NULL
, "-%s unknown", cp
);
71 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
73 print_help (buf
, switches
, 1);
76 print_version(invo_name
);
80 if (*cp
== '+' || *cp
== '@') {
82 adios (NULL
, "only one folder at a time!");
84 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
87 * if necessary, reallocate space for
88 * message/sequence names
90 if (nummsgs
>= maxmsgs
) {
92 msgs
= (char **) mh_xrealloc (msgs
,
93 (size_t) (maxmsgs
* sizeof(*msgs
)));
99 if (!context_find ("path"))
100 free (path ("./", TFOLDER
));
103 folder
= getfolder (1);
104 maildir
= m_maildir (folder
);
106 /* If no messages are given, print folder pathname */
108 printf ("%s\n", maildir
);
112 if (chdir (maildir
) == NOTOK
)
113 adios (maildir
, "unable to change directory to");
115 /* read folder and create message structure */
116 if (!(mp
= folder_read (folder
)))
117 adios (NULL
, "unable to read folder %s", folder
);
120 * We need to make sure there is message status space
121 * for all the message numbers from 1 to "new" since
122 * mhpath can select empty slots. If we are adding
123 * space at the end, we go ahead and add 10 slots.
125 if (mp
->hghmsg
>= mp
->hghoff
) {
126 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
127 adios (NULL
, "unable to allocate folder storage");
128 } else if (mp
->lowoff
> 1) {
129 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
130 adios (NULL
, "unable to allocate folder storage");
133 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
135 /* parse all the message ranges/sequences and set SELECTED */
136 for (i
= 0; i
< nummsgs
; i
++)
137 if (!m_convert (mp
, msgs
[i
]))
140 seq_setprev (mp
); /* set the previous-sequence */
142 /* print the path of all selected messages */
143 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
144 if (is_selected (mp
, i
))
145 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
147 seq_save (mp
); /* synchronize message sequences */
148 context_save (); /* save the context file */
149 folder_free (mp
); /* free folder/message structure */