1 //===-- Starting point for printf -------------------------------*- 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_PRINTF_CORE_PRINTF_MAIN_H
10 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
11 
12 #include "src/__support/arg_list.h"
13 #include "src/stdio/printf_core/converter.h"
14 #include "src/stdio/printf_core/core_structs.h"
15 #include "src/stdio/printf_core/parser.h"
16 #include "src/stdio/printf_core/writer.h"
17 
18 #include <stddef.h>
19 
20 namespace __llvm_libc {
21 namespace printf_core {
22 
23 int printf_main(Writer *writer, const char *__restrict str,
24                 internal::ArgList &args) {
25   Parser parser(str, args);
26 
27   for (FormatSection cur_section = parser.get_next_section();
28        cur_section.raw_len > 0; cur_section = parser.get_next_section()) {
29     if (cur_section.has_conv)
30       convert(writer, cur_section);
31     else
32       writer->write(cur_section.raw_string, cur_section.raw_len);
33   }
34 
35   return writer->get_chars_written();
36 }
37 
38 } // namespace printf_core
39 } // namespace __llvm_libc
40 
41 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
42