static uint8_t *parse_instrs(char *text, int *len, void *context, void (*IVError)(void *context, char *, int)) { short numberstack[256]; int npos = 0, nread, i; int push_left = 0, push_size = 0; char *pt; char *end, *bend, *brack; int icnt = 0, imax = (int)(strlen(text) / 2), val; uint8_t *instrs = malloc(imax); for (pt = text; *pt; ++pt) { npos = 0; while (npos < 256) { while (*pt == ' ' || *pt == '\t') ++pt; if (isdigit(*pt) || *pt == '-') { val = strtol(pt, &end, 0); if (val > 32767 || val < -32768) { IVError(context, "A value must be between [-32768,32767]", (int)(pt - text)); return (NULL); } pt = end; numberstack[npos++] = val; } else break; } while (*pt == ' ' || *pt == '\t') ++pt; if (npos == 0 && (*pt == '\r' || *pt == '\n' || *pt == '\0')) continue; nread = 0; if (push_left == -1) { /* we need a push count */ if (npos == 0) IVError(context, "Expected a number for a push count", (int)(pt - text)); else if (numberstack[0] > 255 || numberstack[0] <= 0) { IVError(context, "The push count must be a number between 0 and 255", (int)(pt - text)); return (NULL); } else { nread = 1; instrs[icnt++] = numberstack[0]; push_left = numberstack[0]; } } if (push_left != 0 && push_left < npos - nread && (*pt == '\r' || *pt == '\n' || *pt == '\0')) { IVError(context, "More pushes specified than needed", (int)(pt - text)); return (NULL); } while (push_left > 0 && nread < npos) { if (push_size == 2) { instrs[icnt++] = numberstack[nread] >> 8; instrs[icnt++] = numberstack[nread++] & 0xff; } else if (numberstack[0] > 255 || numberstack[0] < 0) { IVError(context, "A value to be pushed by a byte push must be between 0 and 255", (int)(pt - text)); return (NULL); } else instrs[icnt++] = numberstack[nread++]; --push_left; }
uint8_t *_IVParse(SplineFont *sf, char *text, int *len, void (*IVError) (void *, char *, int), void *iv) { short numberstack[256]; int npos=0, nread, i; int push_left=0, push_size=0; char *pt; char *end, *bend, *brack; int icnt=0, imax=strlen(text)/2, val, temp; uint8_t *instrs=malloc(imax); for (pt=text; *pt; ++pt) { npos=0; while (npos<256) { while (*pt==' ' || *pt=='\t') ++pt; if (isdigit(*pt) || *pt=='-') { val=strtol(pt, &end, 0); if (val>32767 || val<-32768) { IVError(iv,"A value must be between [-32768,32767]", pt-text); return (NULL); } pt=end; if (*pt=='@') { /* a delta control byte */ if (val>8 || val<-8 || val==0) { IVError(iv,"A value must be between [-8,-1] or [1,8]", pt-text); return (NULL); } pt++; if (!isdigit(*pt)) { IVError(iv,"Number expected",pt-text); return (NULL); } temp=val; val=strtol(pt, &end, 0); if (val>15 || val<0) { IVError(iv,"A value must be between [0,15]",pt-text); return (NULL); } val *= 16; if (temp<0) temp += 8; else temp += 7; val += temp; pt=end; } numberstack[npos++]=val; } else if (strnmatch(pt, "cvt", 3)==0) { pt += 3; while (*pt==' ' || *pt=='\t') ++pt; if (*pt != '(') { IVError(iv, "Missing left parenthesis in command to get a cvt index", pt-text); return (NULL); } temp=strtol(pt+1, &end, 0); pt=end; while (*pt==' ' || *pt=='\t') ++pt; if (*pt != ')') { IVError(iv, "Missing right paren in command to get a cvt index", pt-text); return (NULL); } numberstack[npos++]=TTF__getcvtval(sf, temp); ++pt; } else break; } while (*pt==' ' || *pt=='\t') ++pt; if (npos==0 && (*pt=='\n' || *pt=='\0')) continue; nread=0; if (push_left==-1) { /* we need a push count */ if (npos==0) IVError(iv, "Expected a number for a push count", pt-text); else if (numberstack[0]>255 || numberstack[0] <= 0) { IVError(iv, "The push count must be a number between 0 and 255", pt-text); return (NULL); } else { nread=1; instrs[icnt++]=numberstack[0]; push_left=numberstack[0]; } } if (push_left != 0 && push_left<npos-nread && (*pt=='\n' || *pt=='\0')) { IVError(iv, "More pushes specified than needed", pt-text); return (NULL); } while (push_left>0 && nread<npos) { if (push_size==2) { instrs[icnt++]=numberstack[nread] >> 8; instrs[icnt++]=numberstack[nread++]&0xff; } else if (numberstack[0]>255 || numberstack[0]<0) { IVError(iv, "A value to be pushed by a byte push must be between 0 and 255", pt-text); return (NULL); } else instrs[icnt++]=numberstack[nread++]; --push_left; }