130296Ssam /*
230296Ssam * Copyright (c) 1986 Regents of the University of California.
330296Ssam * All rights reserved. The Berkeley software License Agreement
430296Ssam * specifies the terms and conditions for redistribution.
530296Ssam *
6*41348Ssklower * @(#)kdb_input.c 7.5 (Berkeley) 05/03/90
730296Ssam */
830109Ssam
930109Ssam #include "../kdb/defs.h"
1030109Ssam
1130109Ssam char line[LINSIZ];
12*41348Ssklower char *kdblp;
13*41348Ssklower char kdbpeekc,kdblastc = EOR;
1430109Ssam
1530109Ssam /* input routines */
1630109Ssam
kdbeol(c)17*41348Ssklower kdbeol(c)
1830109Ssam char c;
1930109Ssam {
2030109Ssam return (c==EOR || c==';');
2130109Ssam }
2230109Ssam
kdbrdc()23*41348Ssklower kdbrdc()
2430109Ssam {
2530109Ssam do
26*41348Ssklower (void) kdbreadchar();
27*41348Ssklower while (kdblastc==SP || kdblastc==TB);
28*41348Ssklower return (kdblastc);
2930109Ssam }
3030109Ssam
kdbreadchar()31*41348Ssklower kdbreadchar()
3230109Ssam {
3330109Ssam static char *erase = "\b \b";
3430109Ssam
35*41348Ssklower if (kdblp==0) {
36*41348Ssklower kdblp=line;
3730109Ssam do {
38*41348Ssklower (void) kdbreadc(kdblp);
39*41348Ssklower if (kdbmkfault)
40*41348Ssklower kdberror((char *)0);
41*41348Ssklower switch (*kdblp) {
4239060Smarc case CTRL('h'): case 0177:
43*41348Ssklower if (kdblp > line)
44*41348Ssklower kdbwrite(erase, 3), kdblp--;
4530109Ssam break;
4639060Smarc case CTRL('u'):
47*41348Ssklower while (kdblp > line)
48*41348Ssklower kdbwrite(erase, 3), kdblp--;
4930109Ssam break;
5039060Smarc case CTRL('r'):
5130109Ssam kdbwrite("^R\n", 3);
52*41348Ssklower if (kdblp > line)
53*41348Ssklower kdbwrite(line, kdblp-line);
5430109Ssam break;
5539060Smarc case CTRL('w'):
56*41348Ssklower if (kdblp <= line)
5730109Ssam break;
5830109Ssam do {
59*41348Ssklower if (!isspace(*kdblp))
6030109Ssam goto erasenb;
6130109Ssam kdbwrite(erase, 3);
62*41348Ssklower } while (--kdblp > line);
6330109Ssam break;
6430109Ssam erasenb:
6530109Ssam do
6630109Ssam kdbwrite(erase, 3);
67*41348Ssklower while (--kdblp > line && !isspace(*kdblp));
6830109Ssam break;
6930109Ssam default:
70*41348Ssklower kdbecho(*kdblp++);
7130109Ssam break;
7230109Ssam }
73*41348Ssklower } while (kdblp == line || kdblp[-1] != EOR);
74*41348Ssklower *kdblp=0; kdblp=line;
7530109Ssam }
76*41348Ssklower if (kdblastc = kdbpeekc)
77*41348Ssklower kdbpeekc=0;
78*41348Ssklower else if (kdblastc = *kdblp)
79*41348Ssklower kdblp++;
80*41348Ssklower return (kdblastc);
8130109Ssam }
8230109Ssam
8330109Ssam static
kdbecho(c)84*41348Ssklower kdbecho(c)
8530109Ssam char c;
8630109Ssam {
8730109Ssam char buf[2];
8830109Ssam
8930109Ssam if (c==0177 || (c<SP && c != TB && c != EOR)) {
9030109Ssam buf[0] = '^';
9130109Ssam buf[1] = c ^ 0100;
9230109Ssam kdbwrite(buf, 2);
9330109Ssam } else
9430109Ssam kdbwrite(&c, 1);
9530109Ssam }
9630109Ssam
kdbnextchar()97*41348Ssklower kdbnextchar()
9830109Ssam {
9930109Ssam
100*41348Ssklower if (kdbeol(kdbrdc())) {
101*41348Ssklower kdblp--;
10230109Ssam return (0);
10330109Ssam }
104*41348Ssklower return (kdblastc);
10530109Ssam }
10630109Ssam
kdbquotchar()107*41348Ssklower kdbquotchar()
10830109Ssam {
10930109Ssam
110*41348Ssklower if (kdbreadchar()=='\\')
111*41348Ssklower return (kdbreadchar());
112*41348Ssklower if (kdblastc=='\'')
11330109Ssam return (0);
114*41348Ssklower return (kdblastc);
11530109Ssam }
11630109Ssam
kdbgetformat(deformat)117*41348Ssklower kdbgetformat(deformat)
11830109Ssam char *deformat;
11930109Ssam {
12030109Ssam register char *fptr;
12130109Ssam register int quote;
12230109Ssam
12330120Ssam fptr=deformat; quote=0;
124*41348Ssklower while ((quote ? kdbreadchar()!=EOR : !kdbeol(kdbreadchar())))
125*41348Ssklower if ((*fptr++ = kdblastc)=='"')
12630109Ssam quote = ~quote;
127*41348Ssklower kdblp--;
12830109Ssam if (fptr!=deformat)
12930109Ssam *fptr++ = '\0';
13030109Ssam }
131