CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <fstream> // IWYU pragma: keep
13#include <iostream>
14#include <string>
15
16static void convert_line(const std::string &line)
17{
18 std::cout << "\"";
19
20 for(std::size_t i = 0; i < line.size(); i++)
21 {
22 const char ch = line[i];
23 if(ch == '\\')
24 std::cout << "\\\\";
25 else if(ch == '"')
26 std::cout << "\\\"";
27 else if(ch == '\r' || ch == '\n')
28 {
29 }
30 else if((ch & 0x80) != 0)
31 {
32 std::cout << "\\x" << std::hex << (unsigned(ch) & 0xff) << std::dec;
33 }
34 else
35 std::cout << ch;
36 }
37
38 std::cout << "\\n\"\n";
39}
40
41int main(int argc, char *argv[])
42{
43 std::string line;
44
45 for(int i = 1; i < argc; ++i)
46 {
47 std::ifstream input_file(argv[i]);
48
49 if(!input_file)
50 {
51 std::cerr << "Failed to open " << argv[i] << '\n';
52 return 1;
53 }
54
55 while(getline(input_file, line))
56 convert_line(line);
57 }
58
59 return 0;
60}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
int main()
Definition example.cpp:18
static void convert_line(const std::string &line)