rsc | 84114f0 | 2004-04-19 19:30:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * debugger |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include "defs.h" |
| 8 | #include "fns.h" |
| 9 | |
| 10 | Rune line[LINSIZ]; |
| 11 | extern int infile; |
| 12 | Rune *lp; |
| 13 | int peekc,lastc = EOR; |
| 14 | int eof; |
| 15 | |
| 16 | /* input routines */ |
| 17 | |
| 18 | int |
| 19 | eol(int c) |
| 20 | { |
| 21 | return(c==EOR || c==';'); |
| 22 | } |
| 23 | |
| 24 | int |
| 25 | rdc(void) |
| 26 | { |
| 27 | do { |
| 28 | readchar(); |
| 29 | } while (lastc==SPC || lastc==TB); |
| 30 | return(lastc); |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | reread(void) |
| 35 | { |
| 36 | peekc = lastc; |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | clrinp(void) |
| 41 | { |
| 42 | flush(); |
| 43 | lp = 0; |
| 44 | peekc = 0; |
| 45 | } |
| 46 | |
| 47 | int |
| 48 | readrune(int fd, Rune *r) |
| 49 | { |
| 50 | char buf[UTFmax]; |
| 51 | int i; |
| 52 | |
| 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 | } |
| 59 | |
| 60 | int |
| 61 | readchar(void) |
| 62 | { |
| 63 | Rune *p; |
| 64 | |
| 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 | } |
| 99 | |
| 100 | int |
| 101 | nextchar(void) |
| 102 | { |
| 103 | if (eol(rdc())) { |
| 104 | reread(); |
| 105 | return(0); |
| 106 | } |
| 107 | return(lastc); |
| 108 | } |
| 109 | |
| 110 | int |
| 111 | quotchar(void) |
| 112 | { |
| 113 | if (readchar()=='\\') |
| 114 | return(readchar()); |
| 115 | else if (lastc=='\'') |
| 116 | return(0); |
| 117 | else |
| 118 | return(lastc); |
| 119 | } |
| 120 | |
| 121 | void |
| 122 | getformat(char *deformat) |
| 123 | { |
| 124 | char *fptr; |
| 125 | BOOL quote; |
| 126 | Rune r; |
| 127 | |
| 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 | } |
| 140 | |
| 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 ahead |
| 146 | * at the token after the colon to decide if it is a file reference |
| 147 | * or a colon-command with a symbol name prefix. |
| 148 | */ |
| 149 | |
| 150 | int |
| 151 | isfileref(void) |
| 152 | { |
| 153 | Rune *cp; |
| 154 | |
| 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 | } |