]>
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.
14 static struct swit switches
[] = {
23 * Add space for message/sequence names
24 * by MAXMSGS at a time.
30 main(int argc
, char **argv
)
32 int i
, maxmsgs
, nummsgs
;
33 char *cp
, *maildir
, *folder
= NULL
;
35 char **arguments
, buf
[BUFSIZ
];
39 setlocale(LC_ALL
, "");
41 invo_name
= r1bindex (argv
[0], '/');
43 /* read user profile/context */
46 arguments
= getarguments (invo_name
, argc
, argv
, 1);
50 * Allocate initial space to record message
55 if (!(msgs
= (char **) malloc ((size_t) (maxmsgs
* sizeof(*msgs
)))))
56 adios (NULL
, "unable to allocate storage");
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 if (!(msgs
= (char **) realloc (msgs
,
93 (size_t) (maxmsgs
* sizeof(*msgs
)))))
94 adios (NULL
, "unable to reallocate msgs storage ");
100 if (!context_find ("path"))
101 free (path ("./", TFOLDER
));
104 folder
= getfolder (1);
105 maildir
= m_maildir (folder
);
107 /* If no messages are given, print folder pathname */
109 printf ("%s\n", maildir
);
113 if (chdir (maildir
) == NOTOK
)
114 adios (maildir
, "unable to change directory to");
116 /* read folder and create message structure */
117 if (!(mp
= folder_read (folder
)))
118 adios (NULL
, "unable to read folder %s", folder
);
121 * We need to make sure there is message status space
122 * for all the message numbers from 1 to "new" since
123 * mhpath can select empty slots. If we are adding
124 * space at the end, we go ahead and add 10 slots.
126 if (mp
->hghmsg
>= mp
->hghoff
) {
127 if (!(mp
= folder_realloc (mp
, 1, mp
->hghmsg
+ 10)))
128 adios (NULL
, "unable to allocate folder storage");
129 } else if (mp
->lowoff
> 1) {
130 if (!(mp
= folder_realloc (mp
, 1, mp
->hghoff
)))
131 adios (NULL
, "unable to allocate folder storage");
134 mp
->msgflags
|= ALLOW_NEW
; /* allow the "new" sequence */
136 /* parse all the message ranges/sequences and set SELECTED */
137 for (i
= 0; i
< nummsgs
; i
++)
138 if (!m_convert (mp
, msgs
[i
]))
141 seq_setprev (mp
); /* set the previous-sequence */
143 /* print the path of all selected messages */
144 for (i
= mp
->lowsel
; i
<= mp
->hghsel
; i
++)
145 if (is_selected (mp
, i
))
146 printf ("%s/%s\n", mp
->foldpath
, m_name (i
));
148 seq_save (mp
); /* synchronize message sequences */
149 context_save (); /* save the context file */
150 folder_free (mp
); /* free folder/message structure */