projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
This is mmh-0.2
[mmh]
/
uip
/
new.c
diff --git
a/uip/new.c
b/uip/new.c
index
a79845c
..
90e2da7
100644
(file)
--- a/
uip/new.c
+++ b/
uip/new.c
@@
-10,15
+10,16
@@
** Inspired by Luke Mewburn's new: http://www.mewburn.net/luke/src/new
*/
** Inspired by Luke Mewburn's new: http://www.mewburn.net/luke/src/new
*/
+#include <h/mh.h>
+#include <h/crawl_folders.h>
+#include <h/utils.h>
#include <sys/types.h>
#include <sys/types.h>
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#include <h/mh.h>
-#include <h/crawl_folders.h>
-#include <h/utils.h>
+#include <unistd.h>
+#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define MODESW 0
static struct swit switches[] = {
#define MODESW 0
@@
-160,7
+161,7
@@
get_msgnums(char *folder, char *sequences[])
case BODY:
case BODYEOF:
case BODY:
case BODYEOF:
- adios(NULL, "no blank lines are permitted in %s",
+ adios(EX_DATAERR, NULL, "no blank lines are permitted in %s",
seqfile);
/* fall */
seqfile);
/* fall */
@@
-168,7
+169,7
@@
get_msgnums(char *folder, char *sequences[])
break;
default:
break;
default:
- adios(NULL, "%s is poorly formatted", seqfile);
+ adios(EX_SOFTWARE, NULL, "%s is poorly formatted", seqfile);
}
break; /* break from for loop */
}
}
break; /* break from for loop */
}
@@
-256,7
+257,7
@@
check_folders(struct node **first, struct node **last,
} else {
fp = fopen(folders, "r");
if (fp == NULL) {
} else {
fp = fopen(folders, "r");
if (fp == NULL) {
- adios(NULL, "failed to read %s", folders);
+ adios(EX_IOERR, NULL, "failed to read %s", folders);
}
while (vfgets(fp, &line) == OK) {
len = strlen(line) - 1;
}
while (vfgets(fp, &line) == OK) {
len = strlen(line) - 1;
@@
-311,7
+312,11
@@
doit(char *cur, char *folders, char *sequences[])
struct node *first, *cur_node, *node, *last = NULL, *prev;
size_t folder_len;
int count, total = 0;
struct node *first, *cur_node, *node, *last = NULL, *prev;
size_t folder_len;
int count, total = 0;
- char *command = NULL, *sequences_s = NULL;
+ char *sequences_s = NULL;
+ int argc = 0;
+ char *argv[MAXARGS];
+ char **seqp;
+ char buf[BUFSIZ];
if (cur == NULL || cur[0] == '\0') {
cur = "inbox";
if (cur == NULL || cur[0] == '\0') {
cur = "inbox";
@@
-383,14
+388,15
@@
doit(char *cur, char *folders, char *sequences[])
}
fflush(stdout);
}
fflush(stdout);
- /*
- ** TODO: Split enough of scan.c out so that we can
- ** call it here.
- */
- command = concat("scan +", node->n_name, " ",
- sequences_s, (void *)NULL);
- system(command);
- free(command);
+ argc = 0;
+ argv[argc++] = "scan";
+ snprintf(buf, sizeof buf, "+%s", node->n_name);
+ argv[argc++] = buf;
+ for (seqp=sequences; *seqp; seqp++) {
+ argv[argc++] = *seqp;
+ }
+ argv[argc] = (char *)NULL;
+ execprog(*argv, argv);
} else {
if (node->n_field == NULL) {
continue;
} else {
if (node->n_field == NULL) {
continue;
@@
-452,28
+458,28
@@
main(int argc, char **argv)
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
- done(1);
+ exit(EX_USAGE);
case UNKWNSW:
case UNKWNSW:
- adios(NULL, "-%s unknown", cp);
+ adios(EX_USAGE, NULL, "-%s unknown", cp);
case HELPSW:
snprintf(help, sizeof(help),
"%s [switches] [sequences]",
invo_name);
print_help(help, switches, 1);
case HELPSW:
snprintf(help, sizeof(help),
"%s [switches] [sequences]",
invo_name);
print_help(help, switches, 1);
- done(1);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
case VERSIONSW:
print_version(invo_name);
case VERSIONSW:
print_version(invo_name);
- done(1);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
case FOLDERSSW:
if (!(folders = *argp++) || *folders == '-')
case FOLDERSSW:
if (!(folders = *argp++) || *folders == '-')
- adios(NULL, "missing argument to %s",
+ adios(EX_USAGE, NULL, "missing argument to %s",
argp[-2]);
continue;
case MODESW:
if (!(invo_name = *argp++) || *invo_name == '-')
argp[-2]);
continue;
case MODESW:
if (!(invo_name = *argp++) || *invo_name == '-')
- adios(NULL, "missing argument to %s",
+ adios(EX_USAGE, NULL, "missing argument to %s",
argp[-2]);
invo_name = mhbasename(invo_name);
continue;
argp[-2]);
invo_name = mhbasename(invo_name);
continue;
@@
-507,7
+513,7
@@
main(int argc, char **argv)
/* no sequence arguments; use unseen */
if ((unseen = context_find(usequence))) {
if (!*unseen) {
/* no sequence arguments; use unseen */
if ((unseen = context_find(usequence))) {
if (!*unseen) {
- adios(NULL, "profile entry %s set, but empty, and no sequences given", usequence);
+ adios(EX_CONFIG, NULL, "profile entry %s set, but empty, and no sequences given", usequence);
}
} else {
unseen = seq_unseen; /* use default */
}
} else {
unseen = seq_unseen; /* use default */
@@
-521,7
+527,7
@@
main(int argc, char **argv)
folder = doit(context_find(curfolder), folders, sequences);
if (folder == NULL) {
folder = doit(context_find(curfolder), folders, sequences);
if (folder == NULL) {
- done(0);
+ exit(EX_OK);
return 1;
}
return 1;
}
@@
-545,6
+551,5
@@
main(int argc, char **argv)
context_save();
context_save();
- done(0);
- return 1;
+ return 0;
}
}