2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
15 #define CKILL 006 /* @ => <CLOSE> */
16 #define CERASE 001 /* # => <CTRL A> */
18 int wtuser
; /* waiting for user input */
19 int sigint
; /* sensed an interrupt */
22 struct swit switches
[] = {
23 "erase chr", 2, /* 0 */ /* "2" can become "0",since no ed */
24 "kill chr", 0, /* 1 */
29 extern int errno
; /* MLW 4bsd does not have errno defined in errno.h */
30 extern char _sobuf
[]; /* MLW standard out buffer */
36 char tmpfil
[32], *drft
, name
[NAMESZ
], field
[BUFSIZ
];
40 register int i
, state
;
43 char *arguments
[50], **argp
;
47 setbuf(stdout
, _sobuf
);
49 skill
= 0; exitstat
= 0;
50 cp
= r1bindex(argv
[0], '/');
51 if((cp
= m_find(cp
)) != NULL
) {
52 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
53 ap
= copyip(ap
, arguments
);
56 VOID
copyip(argv
+1, ap
);
61 switch(smatch(++cp
, switches
)) {
62 case -2:ambigsw(cp
, switches
); /* ambiguous */
65 case -1:fprintf(stderr
, "prompter: -%s unknown\n", cp
);
67 case 0: if(!(erasep
= *argp
++)) { /* -erase */
68 missing
: fprintf(stderr
, "prompter: Missing argument for %s switch\n", argp
[-2]);
72 case 1: if(!(killp
= *argp
++)) /* -kill */
76 case 2: help("prompter [switches]",
83 fprintf(stderr
, "prompter: missing skeleton\n");
86 if((in
= fopen(drft
, "r")) == NULL
) {
87 fprintf(stderr
, "Can't open %s\n", drft
);
90 VOID
copy(makename("prmt", ".tmp"), copy("/tmp/", tmpfil
));
91 if((out
= fopen(tmpfil
, "w")) == NULL
) {
92 fprintf(stderr
, "Can't create %s\n", tmpfil
);
95 VOID
chmod(tmpfil
, 0700);
96 VOID
signal(SIGINT
, sig
);
100 sg
.sg_kill
= killp
? chrcnv(killp
) : skill
;
101 sg
.sg_erase
= erasep
? chrcnv(erasep
) : serase
;
102 /*** stty(0, &sg); ***/
103 ioctl(0, TIOCSETN
, &sg
);
104 if(killp
|| erasep
) {
105 printf("Erase Char="); chrdisp(sg
.sg_erase
);
106 printf("; Kill Line="); chrdisp(sg
.sg_kill
);
107 printf(".\n"); VOID
fflush(stdout
);
110 for(;;) switch(state
= m_getfld(state
,name
,field
,sizeof field
,in
)) {
115 if(field
[0] != '\n' || field
[1] != 0) {
116 printf("%s:%s", name
, field
);
117 fprintf(out
, "%s:%s", name
, field
);
118 while(state
== FLDPLUS
) {
119 state
=m_getfld(state
,name
,field
,sizeof field
,in
);
121 fprintf(out
, "%s", field
);
124 printf("%s: ", name
);
129 if(i
== 0 && (field
[0] == '\n' || !field
[0]))
131 fprintf(out
, "%s:", name
);
133 if(field
[0] != ' ' && field
[0] != '\t')
136 } while(i
== 1 && (i
= getln(field
)) >= 0);
148 body
: fputs("--------\n", out
);
149 printf("--------\n");
155 } while(state
== BODY
&&
156 (state
=m_getfld(state
,name
,field
,sizeof field
,in
)));
157 printf("\n--------Enter additional text\n\n");
169 fprintf(stderr
, "Bad format file!\n");
175 printf("--------\n"); VOID
fflush(stdout
);
177 out
= fopen(tmpfil
, "r");
179 in
= fopen(drft
, "w"); /* Truncate prior to copy back */
181 if((i
= read(fileno(out
), field
, sizeof field
)) > 0)
182 if(write(fileno(in
), field
, i
) != i
) {
183 fprintf(stderr
, "Write error to ");
187 while(i
== sizeof field
);
201 if(killp
|| erasep
) {
203 sg
.sg_erase
= serase
;
204 /*** stty(0, &sg); ***/
205 ioctl(0, TIOCSETN
, &sg
);
223 /*** fprintf(stderr,"getchar()=\\%o,errno=%d,EINTR=%d\n",c,errno,EINTR);/***/
254 VOID
signal(SIGINT
, sig
);
268 if((c
= *cp
++) != '\\')
271 while(*cp
&& *cp
!= '\n') {
285 printf("<CTRL-%c>", c
+ '@');