cprover
Loading...
Searching...
No Matches
file_converter.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Convert file contents to C strings
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "file_converter.h"
13
14#include <filesystem>
15#include <fstream> // IWYU pragma: keep
16#include <iostream>
17#include <string>
18
19int main(int argc, char *argv[])
20{
21 // --line applies to the input files that follow it: the flag is acted upon
22 // as argv is scanned left to right, so it must precede those files (the
23 // build always passes it first).
24 bool line_marker = false;
25
26 // Emit a character-array initialiser rather than a string literal: string
27 // literals are limited to 65536 characters after concatenation (a limit
28 // clang enforces under -pedantic), whereas a character array has no such
29 // limit. The enclosing braces are supplied here.
30 std::cout << '{';
31
32 for(int i = 1; i < argc; ++i)
33 {
34 const std::string arg = argv[i];
35
36 if(arg == "--line")
37 {
38 line_marker = true;
39 continue;
40 }
41
42 std::ifstream input_file(arg);
43
44 if(!input_file)
45 {
46 std::cerr << "Failed to open " << arg << '\n';
47 return 1;
48 }
49
51 input_file,
52 std::cout,
53 line_marker,
54 std::filesystem::path{arg}.filename().string());
55 }
56
57 // null terminator, closing brace and a trailing newline
58 std::cout << "0}\n";
59
60 return 0;
61}
int main()
Definition example.cpp:18
Convert file contents to a C character-array initialiser.
void file_converter_append(std::istream &in, std::ostream &out, bool line_marker, const std::string &file_name)
Append the contents of in to out as the body of a C character-array initialiser; the enclosing braces...