Beispiel #1
0
int disrsi_(

  int       stream,
  int      *negate,
  unsigned *value,
  unsigned  count)

  {
  int  c;
  unsigned locval;
  unsigned ndigs;
  char  *cp;
  char  scratch[DIS_BUFSIZ+1];

  assert(negate != NULL);
  assert(value != NULL);
  assert(count);
  assert(stream >= 0);
  assert(dis_getc != NULL);
  assert(dis_gets != NULL);

  memset(scratch, 0, DIS_BUFSIZ+1);
  if (dis_umaxd == 0)
    disiui_();

  switch (c = (*dis_getc)(stream))
    {

    case '-':

    case '+':

      *negate = c == '-';

      if ((*dis_gets)(stream, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count >= dis_umaxd)
        {
        if (count > dis_umaxd)
          goto overflow;

        if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if (((c = *cp++) < '0') || (c > '9'))
          {
          return(DIS_NONDIGIT);
          }

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;

      return (DIS_SUCCESS);

      break;

    case '0':

      return (DIS_LEADZRO);

      break;

    case '1':

    case '2':

    case '3':

    case '4':

    case '5':

    case '6':

    case '7':

    case '8':

    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if ((*dis_gets)(stream, scratch + 1, count - 1) != (int)count - 1)
          {
          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= dis_umaxd)
          {
          if (count > dis_umaxd)
            break;

          *cp = c;

          if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }    /* END if (count > 1) */

      return(disrsi_(stream, negate, value, ndigs));

      /*NOTREACHED*/

      break;

    case - 1:

      return(DIS_EOD);

      /*NOTREACHED*/

      break;

    case -2:

      return(DIS_EOF);

      /*NOTREACHED*/

      break;

    default:

      return(DIS_NONDIGIT);

      /*NOTREACHED*/

      break;
    }

  *negate = FALSE;

overflow:

  *value = UINT_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsi_() */
Beispiel #2
0
int disrsl_(

  struct tcp_chan *chan,
  int             *negate,
  unsigned long   *value,
  unsigned long    count)

  {
  int            c;
  unsigned long  locval;
  unsigned long  ndigs;
  char          *cp;
  char           scratch[DIS_BUFSIZ];

  assert(negate != NULL);
  assert(value != NULL);
  assert(count);

  memset(scratch, 0, sizeof(scratch));

  if (ulmaxdigs == 0)
    {
    cp = discul_(scratch + sizeof(scratch) - 1, ULONG_MAX, &ulmaxdigs);

    ulmax = (char *)calloc(1, ulmaxdigs);

    if (ulmax == NULL)
      {
      return(DIS_NOMALLOC);
      }

    memcpy(ulmax, cp, ulmaxdigs);

    if (dis_umaxd == 0)
      disiui_();
    }

  if (count >= ulmaxdigs)
    {
    if (count > ulmaxdigs)
      goto overflow;

    if (memcmp(scratch, ulmax, ulmaxdigs) > 0)
      goto overflow;
    }

  c = tcp_getc(chan);

  /* FORMAT:  +2+1+0+0+64+2079+22+251175826.teva.westgrid.ubc2+362+21+8Job_Name+02+11run32_.2557+02+ ... */

  switch (c)
    {

    case '-':

    case '+':

      *negate = (c == '-');

      if (tcp_gets(chan, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count >= ulmaxdigs)
        {
        if (count > ulmaxdigs)
          goto overflow;

        if (memcmp(scratch, ulmax, ulmaxdigs) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if ((c = *cp++) < '0' || c > '9')
          {
          return(DIS_NONDIGIT);
          }

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;

      return(DIS_SUCCESS);

      /*NOTREACHED*/

      break;

    case '0':

      return(DIS_LEADZRO);

      /*NOTREACHED*/

      break;

    case '1':

    case '2':

    case '3':

    case '4':

    case '5':

    case '6':

    case '7':

    case '8':

    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if (tcp_gets(chan, scratch + 1, count - 1) != (int)count - 1)
          {
          /* FAILURE */

          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= ulmaxdigs)
          {
          if (count > ulmaxdigs)
            break;

          *cp = c;

          if (memcmp(scratch, ulmax, ulmaxdigs) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            /* FAILURE */
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }

      return(disrsl_(chan, negate, value, ndigs));

      /*NOTREACHED*/

      break;

    case - 1:

      /* FAILURE */

      return(DIS_EOD);

      /*NOTREACHED*/

      break;

    case -2:

      /* FAILURE */

      return(DIS_EOF);

      /*NOTREACHED*/

      break;

    default:

      /* FAILURE */

      return(DIS_NONDIGIT);

      /*NOTREACHED*/

      break;
    }  /* END switch (c) */

  *negate = FALSE;

overflow:

  *value = ULONG_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsl_() */
Beispiel #3
0
int disrsi_(

  struct tcp_chan *chan,
  int             *negate,
  unsigned        *value,
  unsigned         count)

  {
  int       c;
  unsigned  locval;
  unsigned  ndigs;
  char     *cp = NULL;
  char      scratch[DIS_BUFSIZ];

  if (negate == NULL)
    return DIS_INVALID;
  if (value == NULL)
    return DIS_INVALID;
  if (count == 0)
    return DIS_INVALID;

  memset(scratch, 0, sizeof(scratch));

  if (dis_umaxd == 0)
    disiui_();
  
  if (count > sizeof(scratch) - 1)
    return DIS_INVALID;

  switch (c = tcp_getc(chan))
    {

    case '-':
    case '+':

      *negate = c == '-';

      if (tcp_gets(chan, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count > dis_umaxd)
        goto overflow;
      if (count == dis_umaxd)
        {
        if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if (((c = *cp++) < '0') || (c > '9'))
          return(DIS_NONDIGIT);

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;
      return (DIS_SUCCESS);
      break;

    case '0':
      return (DIS_LEADZRO);
      break;

    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if (tcp_gets(chan, scratch + 1, count - 1) != (int)count - 1)
          {
          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= dis_umaxd)
          {
          if (count > dis_umaxd)
            break;

          *cp = c;

          if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }    /* END if (count > 1) */

      return(disrsi_(chan, negate, value, ndigs));
      break;

    case -1:
      return(DIS_EOD);
      break;

    case -2:
      return(DIS_EOF);
      break;

    default:

      return(DIS_NONDIGIT);
      break;
    }

  *negate = FALSE;

overflow:

  *value = UINT_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsi_() */