]>
diplodocus.org Git - nmh/blob - docs/historical/2.9BSD/cmds/comp.c
21 "edit [<editor>]", 0, /* 1 */
22 "quit [delete]", 0, /* 2 */
23 "send [verbose]", 0, /* 3 */
28 struct swit switches
[] = {
29 "editor editor", 0, /* 0 */
30 "form formfile", 0, /* 1 */
42 int use
, cnt
, status
, intr
;
43 char buf
[BUFSIZ
], *ed
, *file
, *form
;
44 static char path
[128];
46 char *arguments
[50], **argp
;
48 /*** setbuf(stdout, _sobuf); ***/
52 form
= 0; use
= 0; file
= 0; ed
= 0;
53 cp
= r1bindex(argv
[0], '/');
54 if((cp
= m_find(cp
)) != NULL
) {
55 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
56 ap
= copyip(ap
, arguments
);
63 switch(smatch(++cp
, switches
)) {
64 case -2:ambigsw(cp
, switches
); /* ambiguous */
67 case -1:fprintf(stderr
, "comp: -%s unknown\n", cp
);
69 case 0: if(!(ed
= *argp
++)) { /* -editor */
70 missing
: fprintf(stderr
, "comp: Missing argument for %s switch\n", argp
[-2]);
74 case 1: if(!(form
= *argp
++)) /* -form */
77 case 2: use
= 1; continue; /* -use */
78 case 3: use
= 0; continue; /* -nouse */
79 case 4: help("comp [file] [switches]",
87 if((in
= open(m_maildir(form
), 0)) < 0) {
88 fprintf(stderr
, "comp: Can't open form file: %s\n", form
);
91 } else if((in
= open(m_maildir(components
), 0)) < 0 &&
92 (in
= open(stdcomps
, 0)) < 0) {
93 fprintf(stderr
, "comp: Can't open default components file!!\n");
98 copy(m_maildir(file
), path
);
99 if((out
= open(path
, 0)) >= 0) {
100 cp
= concat("\n\"", path
, "\" exists; delete? ", 0);
101 if(use
|| fdcompare(in
, out
))
103 while((status
= gans(cp
, anyul
)) == 3)
113 fprintf(stderr
, "comp: \"%s\" doesn't exist!\n", path
);
116 if((out
= creat(path
, m_gmprot())) < 0) {
117 fprintf(stderr
, "comp: Can't create \"%s\"\n", path
);
121 if(cnt
= read(in
, buf
, sizeof buf
))
122 write(out
, buf
, cnt
);
123 while(cnt
== sizeof buf
);
127 if(m_edit(&ed
, path
, use
, NONE
) < 0)
130 fprintf(stderr
, "!! Test Version of SEND Being Run !!\n");
131 fprintf(stderr
, " Send verbose !\n\n");
135 if(!(argp
= getans("\nWhat now? ", aleqs
)))
137 switch(smatch(*argp
, aleqs
)) {
138 case 0: showfile(path
); /* list */
140 case 1: if(*++argp
) /* edit */
142 if(m_edit(&ed
, path
, use
, NONE
) == -1)
145 case 2: if(*++argp
&& *argp
[0] == 'd') /* quit */
146 if(unlink(path
) == -1) {
147 fprintf(stderr
, "Can't unlink %s ", path
);
151 case 3: if(*++argp
) cp
= *argp
; else cp
= ""; /* send */
152 if(! m_send(cp
, path
))
154 default:fprintf(stderr
, "comp: illegal option\n"); /*##*/