Date: Fri, 5 Jul 1996 20:58:48 -0700 From: Sean Eric Fagan <sef@kithrup.com> To: hackers@freebsd.org Subject: patches to mail -- thoughts, comments? Message-ID: <199607060358.UAA22247@kithrup.com>
next in thread | raw e-mail | index | archive | help
This adds a "|" command to Mail. I'm not extremely happy with it, mind you,
which is why I'm soliciting comments ;).
These are relative to my sources, but should apply with some fuzz to stock
freebsd sources ;).
*** /usr/src/usr.bin/mail/cmd2.c Sat Jun 12 07:50:30 1993
--- cmd2.c Fri Jul 5 20:56:28 1996
***************
*** 145,150 ****
--- 145,156 ----
return save1(str, 0, "copy", saveignore);
}
+ pipeto(str)
+ char str[];
+ {
+ return save1(str, 0, "pipe", saveignore);
+ }
+
/*
* Save/copy the indicated messages at the end of the passed file name.
* If mark is true, mark the message "saved."
***************
*** 157,166 ****
register int *ip;
register struct message *mp;
char *file, *disp;
! int f, *msgvec;
FILE *obuf;
msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
if ((file = snarf(str, &f)) == NOSTR)
return(1);
if (!f) {
--- 163,174 ----
register int *ip;
register struct message *mp;
char *file, *disp;
! int f, *msgvec, dopipe;
FILE *obuf;
msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
+ dopipe = !strcmp(cmd, "pipe");
+
if ((file = snarf(str, &f)) == NOSTR)
return(1);
if (!f) {
***************
*** 173,187 ****
}
if (f && getmsglist(str, msgvec, 0) < 0)
return(1);
if ((file = expand(file)) == NOSTR)
return(1);
printf("\"%s\" ", file);
fflush(stdout);
! if (access(file, 0) >= 0)
disp = "[Appended]";
else
disp = "[New file]";
! if ((obuf = Fopen(file, "a")) == NULL) {
perror(NOSTR);
return(1);
}
--- 181,218 ----
}
if (f && getmsglist(str, msgvec, 0) < 0)
return(1);
+ if (!dopipe) {
if ((file = expand(file)) == NOSTR)
return(1);
printf("\"%s\" ", file);
+ } else if (file[0] == *(file + strlen(file) - 1)) {
+ char delim = file[0];
+ char *endstr = file + strlen(file) - 1;
+ /*
+ * pipes are a special case... we want to remove any
+ * delimitting quotes, so we check for file[0] equal
+ * to '\'' or '"'; if it is, and the last character is
+ * the same, then we remove them.
+ */
+ if (delim == '"' || delim == '\'') {
+ memmove (file, file+1, endstr - file);
+ file[strlen(file)] = 0;
+ }
+ }
+
fflush(stdout);
! if (dopipe)
! disp = "[Pipe]";
! else if (access(file, 0) >= 0)
disp = "[Appended]";
else
disp = "[New file]";
! if (dopipe) {
! if ((obuf = Popen(file, "w")) == NULL) {
! perror(NOSTR);
! return(1);
! }
! } else if ((obuf = Fopen(file, "a")) == NULL) {
perror(NOSTR);
return(1);
}
***************
*** 190,196 ****
touch(mp);
if (send(mp, obuf, ignore, NOSTR) < 0) {
perror(file);
! Fclose(obuf);
return(1);
}
if (mark)
--- 221,227 ----
touch(mp);
if (send(mp, obuf, ignore, NOSTR) < 0) {
perror(file);
! (dopipe ? Pclose : Fclose)(obuf);
return(1);
}
if (mark)
***************
*** 199,205 ****
fflush(obuf);
if (ferror(obuf))
perror(file);
! Fclose(obuf);
printf("%s\n", disp);
return(0);
}
--- 230,236 ----
fflush(obuf);
if (ferror(obuf))
perror(file);
! (dopipe ? Pclose : Fclose)(obuf);
printf("%s\n", disp);
return(0);
}
*** /usr/src/usr.bin/mail/cmdtab.c Sat Jun 12 07:50:29 1993
--- cmdtab.c Thu Jul 4 16:21:20 1996
***************
*** 53,58 ****
--- 53,59 ----
extern int folders(), igfield(), Type(), retfield(), more(), More();
extern int saveigfield(), saveretfield();
extern int unread(); /* , Header(); */
+ extern int pipeto();
struct cmd cmdtab[] = {
"next", next, NDMLIST, 0, MMNDEL,
***************
*** 82,87 ****
--- 83,89 ----
"chdir", schdir, M|RAWLIST, 0, 1,
"cd", schdir, M|RAWLIST, 0, 1,
"save", save, STRLIST, 0, 0,
+ "|", pipeto, STRLIST, 0, 0,
"source", source, M|RAWLIST, 1, 1,
"set", set, M|RAWLIST, 0, 1000,
"shell", dosh, I|NOLIST, 0, 0,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607060358.UAA22247>
