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 #include "src/stdio/printf_core/printf_main.h" 10 11 #include "src/__support/arg_list.h" 12 #include "src/__support/macros/config.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 LIBC_NAMESPACE_DECL { 21 namespace printf_core { 22 printf_main(Writer * writer,const char * __restrict str,internal::ArgList & args)23int printf_main(Writer *writer, const char *__restrict str, 24 internal::ArgList &args) { 25 Parser<internal::ArgList> parser(str, args); 26 int result = 0; 27 for (FormatSection cur_section = parser.get_next_section(); 28 !cur_section.raw_string.empty(); 29 cur_section = parser.get_next_section()) { 30 if (cur_section.has_conv) 31 result = convert(writer, cur_section); 32 else 33 result = writer->write(cur_section.raw_string); 34 35 if (result < 0) 36 return result; 37 } 38 39 return writer->get_chars_written(); 40 } 41 42 } // namespace printf_core 43 } // namespace LIBC_NAMESPACE_DECL 44