10 void badcmd(ParseState *ps, const char *fmt, ...) {
17 int ps_word(ParseState *ps) {
19 if (!ps->remain) return 0;
20 space= strchr(ps->remain, ' ');
21 ps->thisword= ps->remain;
23 ps->lthisword= space - ps->thisword;
24 ps->remain= space + 1;
26 ps->lthisword= strlen(ps->remain);
32 int ps_needword(ParseState *ps) {
33 if (!ps_word(ps)) { badcmd(ps,"too few args"); return 0; }
37 int ps_neednumber(ParseState *ps, long *r, long mi, long mx, const char *wh) {
41 if (!ps_needword(ps)) return 0;
42 errno= 0; v= strtol(ps->thisword,&ep,0);
43 if (errno || ep != ps->thisword + ps->lthisword) {
44 badcmd(ps,"invalid number for %s",wh);
47 if (v < mi || v > mx) {
48 badcmd(ps,"%s %ld out of range %ld..%ld",wh,v,mi,mx);
55 int ps_neednoargs(ParseState *ps) {
57 badcmd(ps,"too many arguments");
63 int ps_needhextoend(ParseState *ps, Byte *d, int *len_io) {
64 Byte *d_begin, *d_end;
71 if (!ps->remain) { badcmd(ps,"need hex data block"); return 0; }
73 if (!ps_word(ps)) break;
74 while (ps->lthisword > 0) {
75 if (ps->lthisword & 1) {
76 badcmd(ps,"hex data block with odd number of digits in part");
79 buf[0]= ps->thisword[0];
80 buf[1]= ps->thisword[1];
81 if (d >= d_end) { badcmd(ps,"hex data block too long"); return 0; }
82 *d++= strtoul(buf,&ep,16);
83 if (*ep) { badcmd(ps,"invalid digit in hex data block"); return 0; }
93 int lstrstrcmp(const char *a, int la, const char *b) {
97 minl= la < lb ? la : lb;
101 return (la < lb ? -1 :
105 int thiswordstrcmp(ParseState *ps, const char *b) {
106 return lstrstrcmp(ps->thisword, ps->lthisword, b);