4 #include "../common/common.h"
8 #define isspace risspace
13 return(r==' ' || r=='\t' || r=='\n' || r == '\r' || r=='\f');
21 /* skip over initial white space */
24 if (r == '\n') inputlineno++;
26 } while (r>=0 && isspace(r));
29 } else if (!isspace(r)) {
37 asc2dig(char c, int base) {
38 if (c >= '0' && c <= '9'){
39 if (base == 8 && c > '7') return(-1);
44 if (c >= 'a' && c <= 'f') return(10 + c - 'a');
45 else if (c >= 'A' && c <= 'F') return(10 + c - 'A');
51 /* get a string of type: "d" for decimal integer, "u" for unsigned,
52 * "s" for string", "c" for char,
53 * return the number of characters gotten for the field. If nothing
54 * was gotten and the end of file was reached, a negative value
55 * from the Bgetrune is returned.
59 Bgetfield(Biobuf *bp, int type, void *thing, int size) {
63 int sindex = 0, i, j, n = 0;
66 BOOLEAN bailout = FALSE;
72 /* skip over initial white space */
78 while (!bailout && (r = Bgetrune(bp))>=0) {
95 if ((r == 'x' || r == 'X') && base == 8) {
100 if ((dig = asc2dig(r, base)) == -1) bailout = TRUE;
101 else n = dig + (n * base);
103 if (r < 0) return(-1);
104 *(int *)thing = (negate)?-n:n;
108 while (!bailout && (r = Bgetrune(bp))>=0) {
117 if ((r == 'x' || r == 'X') && base == 8) {
122 if ((dig = asc2dig(r, base)) == -1) bailout = TRUE;
123 else u = dig + (n * base);
126 if (r < 0) return(-1);
131 while ((size>j+UTFmax) && (r = Bgetrune(bp))>=0 && !isspace(r)) {
133 i = runetochar(&(((char *)thing)[j]), &R);
137 ((char *)thing)[j++] = '\0';
138 if (r < 0) return(-1);
142 if ((r = Bgetrune(bp))>=0) {
147 if (r <= 0) return(-1);
153 if (r < 0 && sindex == 0)
155 else if (bailout && sindex == 1) {