Line data Source code
1 : /** \file generate_errno_info.cpp
2 : * \brief Generates errno_info.hpp from the configured errno name list.
3 : * \author Jared Males
4 : */
5 :
6 : #include <cerrno>
7 : #include <cstring>
8 : #include <fstream>
9 : #include <iostream>
10 : #include <vector>
11 : #include <string>
12 : #include <format>
13 : #include <algorithm>
14 :
15 0 : int main()
16 : {
17 :
18 0 : std::ifstream fin;
19 :
20 0 : std::vector<std::string> ERRNOS, errnos;
21 0 : fin.open("c++11_errnos.txt");
22 0 : while(fin)
23 : {
24 0 : std::string EN;
25 0 : fin >> EN;
26 0 : if(fin)
27 : {
28 0 : ERRNOS.push_back(EN);
29 0 : std::string en = EN;
30 0 : std::transform(en.begin(), en.end(), en.begin(),[](unsigned char c){ return std::tolower(c); });
31 0 : errnos.push_back(en);
32 0 : }
33 0 : }
34 :
35 0 : std::ofstream fout;
36 0 : fout.open("errno_info.hpp");
37 :
38 0 : fout << "//This is a generated file\n";
39 0 : fout << "//Only used during code generation\n";
40 0 : fout << "//It should not be installed\n";
41 0 : fout << '\n';
42 0 : fout << "#include <vector>\n";
43 0 : fout << "#include <string>\n\n";
44 0 : fout << "void errno_info( std::vector<std::string> & ERRNOs, std::vector<int> & EVALs, std::vector<std::string> & errnos, std::vector<std::string> & msgs)\n";
45 0 : fout << "{\n";
46 0 : for(size_t n = 0; n < errnos.size(); ++n)
47 : {
48 0 : fout << " #ifdef " << ERRNOS[n] << '\n';
49 0 : fout << " ERRNOs.push_back(\"" + ERRNOS[n] + "\");\n";
50 0 : fout << " EVALs.push_back(" + ERRNOS[n] + ");\n";
51 0 : fout << " errnos.push_back(\"" + errnos[n] + "\");\n";
52 0 : fout << " msgs.push_back(strerror(" + ERRNOS[n] + "));\n";
53 0 : fout << " #endif\n\n";
54 : }
55 :
56 0 : fout << "}\n";
57 :
58 0 : fout.close();
59 :
60 0 : return 0;
61 0 : }
|