⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xscanf.c

📁 ATMEL单片机可用的文件系统源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
      /*---------------------------------------------------------------*/
      /* Get the actual number, as a sequence of digits.               */
      /*---------------------------------------------------------------*/
      count = get_num(stream, s, &index, c_i, count, 8, curr_ptr,
                      width, _PLUS, which_pointer);

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 10 handles the 'u' specifier.                             */
    /*-----------------------------------------------------------------*/
    case 10:
    {
      void *curr_ptr;
      int which_pointer;

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        if (value == DEFAULT_VALUE)
        {
          which_pointer = U_INT;
          curr_ptr = va_arg(args, unsigned int *);
        }
        else if (value == l_VALUE)
        {
          which_pointer = U_LONG_INT;
          curr_ptr = va_arg(args, unsigned long *);
        }
        else
        {
          which_pointer = U_SHORT_INT;
          curr_ptr = va_arg(args, unsigned short *);
        }
        ++vars_assigned;
      }

      c_i = ignore_plus(stream, s, &index, &count, c_i);

      /*---------------------------------------------------------------*/
      /* Get the actual number, as a sequence of digits.               */
      /*---------------------------------------------------------------*/
      count = get_num(stream, s, &index, c_i, count, 10, curr_ptr,
                      width, _PLUS, which_pointer);

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 11 handles the 's' specifier.                             */
    /*-----------------------------------------------------------------*/
    case 11:
    {
      int cnt = 0;
      char *curr_ptr;

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        curr_ptr = va_arg(args, char *);
        ++vars_assigned;
      }

      for (; !isspace(c_i) && c_i != EOF; ++count, ++cnt)
      {
        if (store && (width > cnt || !width))
          *curr_ptr++ = c_i;
        c_i = get_char(stream, s, &index);
      }
      if (store)
        *curr_ptr = '\0';
      put_char(stream, &index, c_i);

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 12 handles the 'p' specifier.                             */
    /*-----------------------------------------------------------------*/
    case 12:
    {
      int *curr_ptr;

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        curr_ptr = va_arg(args, int *);
        ++vars_assigned;
      }
      else
        curr_ptr = &UnusedInt;

      /*---------------------------------------------------------------*/
      /* Get the actual number, as a sequence of digits.               */
      /*---------------------------------------------------------------*/
      count = get_num(stream, s, &index, c_i, count, 16, curr_ptr,
                      width, _PLUS, INT);

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 13 handles the 'x'('X') specifier.                        */
    /*-----------------------------------------------------------------*/
    case 13:
    {
      void *curr_ptr;
      int which_pointer;

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        if (value == DEFAULT_VALUE)
        {
          which_pointer = U_INT;
          curr_ptr = va_arg(args, unsigned int *);
        }
        else if (value == l_VALUE)
        {
          which_pointer = U_LONG_INT;
          curr_ptr = va_arg(args, unsigned long *);
        }
        else if (value == h_VALUE)
        {
          which_pointer = U_SHORT_INT;
          curr_ptr = va_arg(args, unsigned short *);
        }
        ++vars_assigned;
      }
      else
      {
        which_pointer = INT;
        curr_ptr = &UnusedInt;
      }

      c_i = ignore_plus(stream, s, &index, &count, c_i);

      /*---------------------------------------------------------------*/
      /* If c_i is 0, ignore the leading 0x or 0X if ther is one.      */
      /*---------------------------------------------------------------*/
      if (c_i == '0')
      {
        ++count;
        c_i = get_char(stream, s, &index);
        if (c_i == 'x' || c_i == 'X')
        {
          ++count;
          c_i = get_char(stream, s, &index);
        }
      }

      /*---------------------------------------------------------------*/
      /* Get the actual number, as a sequence of digits.               */
      /*---------------------------------------------------------------*/
      count = get_num(stream, s, &index, c_i, count, 16, curr_ptr,
                      width, _PLUS, which_pointer);

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 14 handles the '[' specifier, the scanset.                */
    /*-----------------------------------------------------------------*/
    case 14:
    {
      int neg = FALSE, size = 0, cnt = 0;
      char *scanset, *c_ptr, *curr_ptr;

      /*---------------------------------------------------------------*/
      /* Check for 'not' flag.                                         */
      /*---------------------------------------------------------------*/
      if (*format == '^')
      {
        ++format;
        neg = TRUE;
      }

      /*---------------------------------------------------------------*/
      /* Beginning of the scanset.                                     */
      /*---------------------------------------------------------------*/
      scanset = (char *)format;
      if (*format == ']')
      {
        ++format;
        ++size;
      }

      for (; *format != ']'; ++format, ++size)
      {
        /*-------------------------------------------------------------*/
        /* If the NULL character is specified in format, stop.         */
        /*-------------------------------------------------------------*/
        if (!(*format))
          return vars_assigned ? vars_assigned : EOF;
      }

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
        curr_ptr = va_arg(args, char *);

      for (; cnt < width || !width; ++curr_ptr, ++cnt, ++count)
      {
        c_i = get_char(stream, s, &index);

        /*-------------------------------------------------------------*/
        /* Read in width chrs or, if not mentioned, till end of input. */
        /*-------------------------------------------------------------*/
        if (c_i != '\0')
        {
          c_ptr = memchr(scanset, c_i, (size_t)size);

          /*-----------------------------------------------------------*/
          /* If the input character doesn't match the scanset, stop.   */
          /*-----------------------------------------------------------*/
          if ((neg && c_ptr) || (!neg && !c_ptr))
            break;

          if (store)
            *curr_ptr = c_i;
        }
        else
          break;
      }

      /*---------------------------------------------------------------*/
      /* String must end with a NULL character.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        *curr_ptr = '\0';
        ++vars_assigned;
      }

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 15 handles the 'n' specifier.                             */
    /*-----------------------------------------------------------------*/
    case 15:
    {
      int *curr_ptr;

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        curr_ptr = va_arg(args, int *);
        *curr_ptr = count;
      }

      state = 0;
      break;
    }

    /*-----------------------------------------------------------------*/
    /* State 16 handles the 'c' specifier.                             */
    /*-----------------------------------------------------------------*/
    case 16:
    {
      int cnt = 0;
      char *curr_ptr;

      /*---------------------------------------------------------------*/
      /* Set curr_ptr to the appropriate value.                        */
      /*---------------------------------------------------------------*/
      if (store)
      {
        curr_ptr = va_arg(args, char *);
        ++vars_assigned;
      }

      /*---------------------------------------------------------------*/
      /* Read in at least one character.                               */
      /*---------------------------------------------------------------*/
      width = width ? width : 1;
      for (; cnt < width; ++cnt, ++count)
      {
        c = get_char(stream, s, &index);
        if (store)
          *curr_ptr = c;
      }

      state = 0;
      break;
    }

    default:
      break;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -