extern int isdigit()

global int strtoui (char *s) {
  /* convert a string to unsigned integer. return zero if no digits
  found within a preset string length limit */

  int limit
  int rv

  limit = 255   /* let's not look too far for digits */
  rv = 0

  s = s - 1
  repeat {
    s = s + 1
    limit = limit - 1
  } until (limit == 0 || isdigit(*s))
  if (limit == 0) {
    return 0             /* panic - no digits found! */
  }
  limit = 10
  /* this could even be 5, as it's only an int: 65535 max */

  while (isdigit(*s) && limit > 0) {
    rv = rv * 10         /* shift left a digit, first pass result will be 0 */
    rv = rv + *s - '0'   /* add on this digit */
    s = s + 1
    limit = limit - 1
  }
  return rv
}
