]>
diplodocus.org Git - nmh/blob - docs/historical/2.9BSD/cmds/prompter.c
10 int wtuser
; /* waiting for user input */
11 int sigint
; /* sensed an interrupt */
14 struct swit switches
[] = {
15 "erase chr", 2, /* 0 */ /* "2" can become "0",since no ed */
16 "kill chr", 0, /* 1 */
24 char tmpfil
[32], *drft
, name
[NAMESZ
], field
[BUFSIZ
];
28 register int i
, state
;
31 char *arguments
[50], **argp
;
33 int status
, pid
, wpid
, intr
;
36 setbuf(stdout
, _sobuf
);
38 skill
= 0; exitstat
= 0;
39 cp
= r1bindex(argv
[0], '/');
40 if((cp
= m_find(cp
)) != NULL
) {
41 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
42 ap
= copyip(ap
, arguments
);
49 switch(smatch(++cp
, switches
)) {
50 case -2:ambigsw(cp
, switches
); /* ambiguous */
53 case -1:fprintf(stderr
, "prompter: -%s unknown\n", cp
);
55 case 0: if(!(erasep
= *argp
++)) { /* -erase */
56 missing
: fprintf(stderr
, "prompter: Missing argument for %s switch\n", argp
[-2]);
60 case 1: if(!(killp
= *argp
++)) /* -kill */
64 case 2: help("prompter [switches]",
71 fprintf(stderr
, "prompter: missing skeleton\n");
74 if((in
= fopen(drft
, "r")) == NULL
) {
75 fprintf(stderr
, "Can't open %s\n", drft
);
78 copy(makename("prmt", ".tmp"), copy("/tmp/", tmpfil
));
79 if((out
= fopen(tmpfil
, "w")) == NULL
) {
80 fprintf(stderr
, "Can't create %s\n", tmpfil
);
88 sg
.sg_kill
= killp
? chrcnv(killp
) : skill
;
89 sg
.sg_erase
= erasep
? chrcnv(erasep
) : serase
;
90 /*** stty(0, &sg); ***/
91 ioctl(0, TIOCSETN
, &sg
);
93 printf("Erase Char="); chrdisp(sg
.sg_erase
);
94 printf("; Kill Line="); chrdisp(sg
.sg_kill
);
95 printf(".\n"); fflush(stdout
);
98 for(;;) switch(state
= m_getfld(state
,name
,field
,sizeof field
,in
)) {
103 if(field
[0] != '\n' || field
[1] != 0) {
104 printf("%s:%s", name
, field
);
105 fprintf(out
, "%s:%s", name
, field
);
106 while(state
== FLDPLUS
) {
107 state
=m_getfld(state
,name
,field
,sizeof field
,in
);
109 printf(out
, "%s", field
);
112 printf("%s: ", name
);
117 if(i
== 0 && (field
[0] == '\n' || !field
[0]))
119 fprintf(out
, "%s:", name
);
121 if(field
[0] != ' ' && field
[0] != '\t')
124 } while(i
== 1 && (i
= getln(field
)) >= 0);
136 body
: fputs("--------\n", out
);
137 printf("--------\n");
143 } while(state
== BODY
&&
144 (state
=m_getfld(state
,name
,field
,sizeof field
,in
)));
145 printf("\n--------Enter additional text\n\n");
157 fprintf(stderr
, "Bad format file!\n");
163 printf("--------\n"); fflush(stdout
);
165 out
= fopen(tmpfil
, "r");
167 in
= fopen(drft
, "w"); /* Truncate prior to copy back */
169 if((i
= read(fileno(out
), field
, sizeof field
)) > 0)
170 write(fileno(in
), field
, i
);
171 while(i
== sizeof field
);
185 if(killp
|| erasep
) {
187 sg
.sg_erase
= serase
;
188 /*** stty(0, &sg); ***/
189 ioctl(0, TIOCSETN
, &sg
);
207 /*** fprintf(stderr,"getchar()=\\%o,errno=%d,EINTR=%d\n",c,errno,EINTR);/***/
252 if((c
= *cp
++) != '\\')
255 while(*cp
&& *cp
!= '\n') {
269 printf("<CTRL-%c>", c
+ '@');