Blob
1 /*2 *3 * debugger4 *5 */7 #include "defs.h"8 #include "fns.h"10 Rune line[LINSIZ];11 extern int infile;12 Rune *lp;13 int peekc,lastc = EOR;14 int eof;16 /* input routines */18 int19 eol(int c)20 {21 return(c==EOR || c==';');22 }24 int25 rdc(void)26 {27 do {28 readchar();29 } while (lastc==SPC || lastc==TB);30 return(lastc);31 }33 void34 reread(void)35 {36 peekc = lastc;37 }39 void40 clrinp(void)41 {42 flush();43 lp = 0;44 peekc = 0;45 }47 int48 readrune(int fd, Rune *r)49 {50 char buf[UTFmax];51 int i;53 for(i=0; i<UTFmax && !fullrune(buf, i); i++)54 if(read(fd, buf+i, 1) <= 0)55 return -1;56 chartorune(r, buf);57 return 1;58 }60 int61 readchar(void)62 {63 Rune *p;65 if (eof)66 lastc=0;67 else if (peekc) {68 lastc = peekc;69 peekc = 0;70 }71 else {72 if (lp==0) {73 for (p = line; p < &line[LINSIZ-1]; p++) {74 eof = readrune(infile, p) <= 0;75 if (mkfault) {76 eof = 0;77 error(0);78 }79 if (eof) {80 p--;81 break;82 }83 if (*p == EOR) {84 if (p <= line)85 break;86 if (p[-1] != '\\')87 break;88 p -= 2;89 }90 }91 p[1] = 0;92 lp = line;93 }94 if ((lastc = *lp) != 0)95 lp++;96 }97 return(lastc);98 }100 int101 nextchar(void)102 {103 if (eol(rdc())) {104 reread();105 return(0);106 }107 return(lastc);108 }110 int111 quotchar(void)112 {113 if (readchar()=='\\')114 return(readchar());115 else if (lastc=='\'')116 return(0);117 else118 return(lastc);119 }121 void122 getformat(char *deformat)123 {124 char *fptr;125 BOOL quote;126 Rune r;128 fptr=deformat;129 quote=FALSE;130 while ((quote ? readchar()!=EOR : !eol(readchar()))){131 r = lastc;132 fptr += runetochar(fptr, &r);133 if (lastc == '"')134 quote = ~quote;135 }136 lp--;137 if (fptr!=deformat)138 *fptr = '\0';139 }141 /*142 * check if the input line if of the form:143 * <filename>:<digits><verb> ...144 *145 * we handle this case specially because we have to look ahead146 * at the token after the colon to decide if it is a file reference147 * or a colon-command with a symbol name prefix.148 */150 int151 isfileref(void)152 {153 Rune *cp;155 for (cp = lp-1; *cp && !strchr(CMD_VERBS, *cp); cp++)156 if (*cp == '\\' && cp[1]) /* escape next char */157 cp++;158 if (*cp && cp > lp-1) {159 while (*cp == ' ' || *cp == '\t')160 cp++;161 if (*cp++ == ':') {162 while (*cp == ' ' || *cp == '\t')163 cp++;164 if (isdigit(*cp))165 return 1;166 }167 }168 return 0;169 }