]>
diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/cmds/dist.c
2 static char sccsid
[] = "@(#)dist.c 4.1 2/23/83";
31 "edit [<editor>]", 0, /* 1 */
32 "quit [delete]", 0, /* 2 */
33 "send [verbose]", 0, /* 3 */
40 int inplace
; /* preserve links in anno */
42 struct swit switches
[] = {
43 "annotate", 0, /* 0 */
44 "noannotate", 0, /* 1 */
45 "editor editor", 0, /* 2 */
46 "form formfile", 0, /* 3 */
48 "noinplace", 0, /* 5 */
56 char *folder
, *maildir
, *msgs
[100], *ed
, *form
;
58 register char *cp
, **ap
;
61 int pid
, wpid
, status
;
62 char *arguments
[50], **argp
;
67 anot
= 0; folder
= 0; curf
= 0; msgp
= 0; ed
= 0; form
= 0;
68 cp
= r1bindex(argv
[0], '/');
69 if((cp
= m_find(cp
)) != NULL
) {
70 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
71 ap
= copyip(ap
, arguments
);
78 switch(smatch(++cp
, switches
)) {
79 case -2:ambigsw(cp
, switches
); /* ambiguous */
82 case -1:fprintf(stderr
, "dist: -%s unknown\n", cp
);
84 case 0: anot
= 1; continue; /* -annotate */
85 case 1: anot
= 0; continue; /* -noannotate */
86 case 2: if(!(ed
= *argp
++)) { /* -editor */
87 missing
: fprintf(stderr
, "dist: Missing argument for %s switch\n", argp
[-2]);
91 case 3: if(!(form
= *argp
++)) /* -form */
94 case 4: inplace
= 1; continue; /* -inplace */
95 case 5: inplace
= 0; continue; /* -noinplace */
97 case 6: help("dist [+folder] [msg] [switches]",
103 fprintf(stderr
, "Only one folder at a time.\n");
111 msgs
[msgp
++] = "cur";
113 folder
= m_getfolder();
114 maildir
= m_maildir(folder
);
115 if(chdir(maildir
) < 0) {
116 fprintf(stderr
, "Can't chdir to: ");
120 if(!(mp
= m_gmsg(folder
))) {
121 fprintf(stderr
, "Can't read folder!?\n");
124 if(mp
->hghmsg
== 0) {
125 fprintf(stderr
, "No messages in \"%s\".\n", folder
);
128 for(msgnum
= 0; msgnum
< msgp
; msgnum
++)
129 if(!m_convert((cp
= msgs
[msgnum
])))
131 if(mp
->numsel
== 0) {
132 fprintf(stderr
, "dist: Tuna Melt\n"); /* never get here */
136 fprintf(stderr
, "Only one message at a time.\n");
140 if((in
= open(m_maildir(form
), 0)) < 0) {
141 fprintf(stderr
, "dist: Can't open form file: %s\n", form
);
144 } else if(/***(in = open(m_maildir(distcomps), 0)) < 0 && ***/
145 (in
= open(stddcomps
, 0)) < 0) {
146 fprintf(stderr
, "dist: Can't open default components file!!\n");
149 copy(m_maildir(draft
), drft
);
150 if((out
= open(drft
, 0)) >= 0) {
151 if(!fdcompare(in
, out
)) {
152 cp
= concat("\"", drft
, "\" exists; Delete? ", 0);
153 while((msgnum
= gans(cp
, anyl
)) == 2)
160 if((out
= creat(drft
, m_gmprot())) < 0) {
161 fprintf(stderr
, "Can't create \"%s\"\n", drft
);
166 if((in
= open(cp
= m_name(mp
->lowsel
), 0)) < 0) {
167 fprintf(stderr
, "Can't open message \"%s\"\n", cp
);
174 m_replace(pfolder
, folder
);
175 if(mp
->lowsel
!= mp
->curmsg
)
176 m_setcur(mp
->lowsel
);
177 if(m_edit(&ed
, drft
, NOUSE
, NONE
) < 0)
180 fprintf(stderr
, "!! Test Version of SEND Being Run !!\n");
181 fprintf(stderr
, " Send verbose !\n\n");
185 if(!(argp
= getans("\nWhat now? ", aleqs
)))
187 switch(smatch(*argp
, aleqs
)) {
188 case 0: showfile(drft
); /* list */
190 case 1: if(*++argp
) /* edit */
192 if(m_edit(&ed
, drft
, NOUSE
, NONE
) == -1)
195 case 2: if(*++argp
&& *argp
[0] == 'd') /* quit */
196 if(unlink(drft
) == -1) {
197 fprintf(stderr
, "Can't unlink %s ", drft
);
201 case 3: if(*++argp
) cp
= *argp
; else cp
= ""; /* send */
203 if(!mp
->msgflags
&READONLY
) { /* annotate first */
205 while((pid
= fork()) == -1) sleep(5);
207 while(wpid
=wait((int *)NULL
)!= -1 && wpid
!= pid
);
213 if(!m_send(cp
, drft
))
215 default:fprintf(stderr
, "dist: illegal option\n"); /*##*/
232 if((i
= read(in
, buf
, sizeof buf
)) > 0)
234 while(i
== sizeof buf
);
241 char name
[NAMESZ
], field
[256];
242 register int ind
, state
;
245 if(stat(drft
, field
) != -1) {
246 fprintf(stderr
, "%s not sent-- no annotations made.\n", drft
);
249 text
= copy(drft
, field
);
253 while(--text
>= field
&& *text
!= '/');
260 if((in
= fopen(field
, "r")) == NULL
) {
261 fprintf(stderr
, "Can't open %s\n", field
);
266 for(;;) switch(state
= m_getfld(state
, name
, field
, sizeof field
, in
)) {
271 if(uleq(name
, "distribute-to") ||
272 uleq(name
, "distribute-cc") == 0) {
274 text
= add(name
, text
);
275 text
= add(":", text
);
277 text
= add(field
, text
);
286 fprintf(stderr
, "Getfld returned %d\n", state
);
292 annotate(m_name(mp
->lowsel
), "Distributed", text
, inplace
);