]> diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/write.c
Added start_test/finish_test to a bunch of tests.
[nmh] / docs / historical / SRI-NOSC / write.c
1 #include "mh.h"
2 #include "signals.h"
3
4
5 char draft[],
6 components[],
7 stdcomps[],
8 sysed[],
9 #ifdef PROMPT
10 prmtproc[],
11 #endif
12 sndproc[];
13
14 int fout;
15
16 char *anyus[] {
17 "no", 0,
18 "yes", 0,
19 "use", 0,
20 "show", 0,
21 0,
22 };
23
24 char *anyv[] {
25 "no", 0,
26 "yes", 0,
27 "verbose", 0,
28 0,
29 };
30
31 struct swit switches[] {
32 "editor editor", 0, /* 0 */
33 "form formfile", 0, /* 1 */
34 "use", 0, /* 2 */
35 "nouse", 0, /* 3 */
36 "help", 4, /* 4 */
37 0, 0
38 };
39
40 main(argc, argv)
41 char *argv[];
42 {
43 register char *cp;
44 register int in, out;
45 int use, cnt, status, intr;
46 char buf[512], path[128], *ed, *file, *vec[10], *form;
47 char *inp, *ap;
48 char *arguments[50], **argp;
49
50 fout = dup(1);
51 #ifdef NEWS
52 m_news();
53 #endif
54 form = use = file = ed = 0;
55 ap = cp = argv[0];
56 while(*cp)
57 if(*cp++ == '/')
58 ap = cp;
59 inp = ap;
60 if((cp = m_find(ap)) != -1) {
61 ap = brkstring(cp = getcpy(cp), " ", '\n');
62 ap = copyip(ap, arguments);
63 } else
64 ap = arguments;
65 copyip(argv+1, ap);
66 argp = arguments;
67 while(cp = *argp++) {
68 if(*cp == '-') {
69 switch(smatch(++cp, switches)) {
70 case -2:ambigsw(cp, switches); /* ambiguous */
71 goto leave;
72 /* unknown */
73 case -1:printf("-%s unknown\n", cp);
74 goto leave;
75 case 0: if(!(ed = *argp++)) { /* -editor */
76 missing: printf("Missing argument for %s switch\n", argp[-2]);
77 goto leave;
78 }
79 continue;
80 case 1: if(!(form = *argp++)) /* -form */
81 goto missing;
82 continue;
83 case 2: use = 1; continue; /* -use */
84 case 3: use = 0; continue; /* -nouse */
85 case 4: help(concat( inp, " [file] [switches]", 0),
86 switches);
87 goto leave;
88 }
89 }
90 file = cp;
91 }
92 if(form) {
93 if((in = open(m_maildir(form), 0)) < 0) {
94 printf("Can't open form file: %s\n", form);
95 goto leave;
96 }
97 } else if((in = open(m_maildir(components), 0)) < 0 &&
98 (in = open(stdcomps, 0)) < 0) {
99 printf("Can't open default components file!!\n");
100 goto leave;
101 }
102 if(!file)
103 file = draft;
104 copy(m_maildir(file), path);
105 if((out = open(path, 0)) >= 0) {
106 if(use || fdcompare(in, out))
107 goto editit;
108 /*
109 cp = concat("\"", path, "\" exists; delete? ", 0);
110 while((status = gans(cp, anyus)) == 3)
111 showfile(path);
112 if(status == 2) {
113 use++;
114 goto editit;
115 }
116 if(status == 0)
117 goto leave;
118 */
119 close(out);
120 } else if(use) {
121 printf("\"%s\" doesn't exist!\n", path);
122 goto leave;
123 }
124 if((out = creat(path, m_gmprot())) < 0) {
125 printf("Can't create \"%s\"\n", path);
126 goto leave;
127 }
128 do
129 if(cnt = read(in, buf, sizeof buf))
130 write(out, buf, cnt);
131 while(cnt == sizeof buf);
132 close(in);
133 editit:
134 close(out);
135 if(!ed && (ed = m_find("editor")) == -1)
136 #ifdef PROMPT
137 ed = prmtproc;
138 #else
139 ed = sysed;
140 #endif
141 intr = signal(SIGINT, 1);
142 if((in = fork()) == 0) {
143 m_update();
144 flush();
145 execlsrh(ed, path, 0);
146 printf("Can't exec editor!!\n");
147 flush(); exit(1);
148 } else if(in == -1) {
149 printf("No forks!\n");
150 goto leave;
151 } else
152 while((out = waita(&status)) != -1 && out != in) ;
153 if(status) {
154 printf("[command aborted--%s ", file);
155 if(!use && status > 0377) {
156 unlink(path);
157 printf("deleted]\n");
158 } else
159 printf("preserved]\n");
160 goto leave;
161 }
162 signal(SIGINT, intr);
163 #ifdef TEST
164 printf("!! Test Version of SEND Being Run !!\n");
165 printf(" Send verbose !\n\n");
166 #endif
167 /* in = concat("Send \"", file, "\"? ", 0); */
168 in = "Send? ";
169 /*** printf("Send \"%s\"? ", file); ***/
170 if((out = gans(in, anyv)) > 0) {
171 in = 0;
172 vec[in++] = "mh-sndproc";
173 vec[in++] = path;
174 if(out == 2)
175 vec[in++] = "-verbose";
176 vec[in++] = 0;
177 m_update();
178 flush();
179 execv(sndproc, vec);
180 printf("Can't exec send process.\n");
181 }
182 leave:
183 m_update();
184 flush();
185 }
186
187
188
189
190