| 4175 | } |
| 4176 | |
| 4177 | staticfn void |
| 4178 | readobjnam_parse_charges(struct _readobjnam_data *d) |
| 4179 | { |
| 4180 | if (strlen(d->bp) > 1 && (d->p = strrchr(d->bp, '(')) != 0) { |
| 4181 | boolean keeptrailingchars = TRUE; |
| 4182 | int idx = 0; |
| 4183 | |
| 4184 | if (d->p > d->bp && d->p[-1] == ' ') |
| 4185 | idx = -1; |
| 4186 | d->p[idx] = '\0'; /* terminate bp */ |
| 4187 | ++d->p; /* advance past '(' */ |
| 4188 | if (!strncmpi(d->p, "lit)", 4)) { |
| 4189 | d->islit = 1; |
| 4190 | d->p += 4 - 1; /* point at ')' */ |
| 4191 | } else { |
| 4192 | d->spe = atoi(d->p); |
| 4193 | while (digit(*d->p)) |
| 4194 | d->p++; |
| 4195 | if (*d->p == ':') { |
| 4196 | d->p++; |
| 4197 | d->rechrg = d->spe; |
| 4198 | d->spe = atoi(d->p); |
| 4199 | while (digit(*d->p)) |
| 4200 | d->p++; |
| 4201 | } |
| 4202 | if (*d->p != ')') { |
| 4203 | d->spe = d->rechrg = 0; |
| 4204 | /* mis-matched parentheses; rest of string will be ignored |
| 4205 | * [probably we should restore everything back to '(' |
| 4206 | * instead since it might be part of "named ..."] |
| 4207 | */ |
| 4208 | keeptrailingchars = FALSE; |
| 4209 | } else { |
| 4210 | d->spesgn = 1; |
| 4211 | } |
| 4212 | } |
| 4213 | if (keeptrailingchars) { |
| 4214 | char *pp = eos(d->bp); |
| 4215 | |
| 4216 | /* 'pp' points at 'pb's terminating '\0', |
| 4217 | 'p' points at ')' and will be incremented past it */ |
| 4218 | do { |
| 4219 | *pp++ = *++d->p; |
| 4220 | } while (*d->p); |
| 4221 | } |
| 4222 | } |
| 4223 | /* |
| 4224 | * otmp->spe is type schar, so we don't want spe to be any bigger or |
| 4225 | * smaller. Also, spe should always be positive --some cheaters may |
| 4226 | * try to confuse atoi(). |
| 4227 | */ |
| 4228 | if (d->spe < 0) { |
| 4229 | d->spesgn = -1; /* cheaters get what they deserve */ |
| 4230 | d->spe = abs(d->spe); |
| 4231 | } |
| 4232 | /* cap on obj->spe is independent of (and less than) SCHAR_LIM */ |
| 4233 | if (d->spe > SPE_LIM) |
| 4234 | d->spe = SPE_LIM; /* slime mold uses d.ftype, so not affected */ |
no test coverage detected