Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- Starting point for scanf --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_SCANF_MAIN_H
10#define LLVM_LIBC_SRC_STDIO_SCANF_CORE_SCANF_MAIN_H
11
12#include "src/__support/arg_list.h"
13#include "src/__support/macros/config.h"
14#include "src/stdio/scanf_core/converter.h"
15#include "src/stdio/scanf_core/core_structs.h"
16#include "src/stdio/scanf_core/parser.h"
17#include "src/stdio/scanf_core/reader.h"
18
19#include <stddef.h>
20
21namespace LIBC_NAMESPACE_DECL {
22namespace scanf_core {
23
24template <typename T>
25int scanf_main(Reader<T> *reader, const char *__restrict str,
26 internal::ArgList &args) {
27 Parser<internal::ArgList> parser(str, args);
28 int ret_val = READ_OK;
29 int conversions = 0;
30 for (FormatSection cur_section = parser.get_next_section();
31 !cur_section.raw_string.empty() && ret_val == READ_OK;
32 cur_section = parser.get_next_section()) {
33 if (cur_section.has_conv) {
34 ret_val = convert(reader, cur_section);
35 // The %n (current position) conversion doesn't increment the number of
36 // assignments.
37 if (cur_section.conv_name != 'n')
38 conversions += ret_val == READ_OK ? 1 : 0;
39 } else {
40 ret_val = raw_match(reader, cur_section.raw_string);
41 }
42 }
43
44 return conversions;
45}
46
47} // namespace scanf_core
48} // namespace LIBC_NAMESPACE_DECL
49
50#endif // LLVM_LIBC_SRC_STDIO_SCANF_CORE_SCANF_MAIN_H
51

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libc/src/stdio/scanf_core/scanf_main.h