This commit is contained in:
lzwdgc 2024-02-01 03:44:09 +03:00
parent 31123f11fa
commit 748d1c2ff3

View file

@ -22,6 +22,8 @@
#include <primitives/sw/settings.h> #include <primitives/sw/settings.h>
#include <primitives/sw/cl.h> #include <primitives/sw/cl.h>
#include <fstream>
#pragma pack(push, 1) #pragma pack(push, 1)
struct script { struct script {
uint32_t file_size; uint32_t file_size;
@ -36,42 +38,66 @@ int main(int argc, char *argv[]) {
cl::ParseCommandLineOptions(argc, argv); cl::ParseCommandLineOptions(argc, argv);
auto func = [](auto &&fn) { auto func = [](auto filename) {
primitives::templates2::mmap_file<uint8_t> f{fn}; primitives::templates2::mmap_file<uint8_t> f{filename};
stream s{f}; stream s{f};
script scr = s; script scr = s;
auto text = s.span<uint8_t>(scr.raw_text_size);
uint32_t max_nlines = s;
auto rest = s.span<uint32_t>(max_nlines);
std::vector<std::string_view> lines; std::vector<std::string_view> lines;
lines.reserve(scr.nlines); int sz{};
for (int i = 0; i < scr.nlines; ++i) { for (int i = 0; i < scr.nlines; ++i) {
lines.emplace_back((const char *)f.p + sizeof(script) + rest[i]); sz += lines.emplace_back((const char *)f.p + sizeof(script) + sz).size() + 1;
} }
int a = 5;
a++;
// write script // write script
/*{ {
filename += ".txt"; filename += ".txt";
std::ofstream ofile(filename); if (std::ofstream ofile(filename); ofile) {
if (ofile) std::string indent, space = " "s;
ofile << ctx.getText(); auto inc = [&]() {
indent += space;
};
auto dec = [&]() {
if (!indent.empty()) {
indent.resize(indent.size() - space.size());
return true;
}
return false;
};
int procs{};
for (auto &&l : lines) {
auto proc = l.starts_with("PROC"sv);
auto end = l == "END"sv;
auto lbrace = l == "{"sv;
auto rbrace = l == "}"sv;
if (rbrace) {
if (!dec()) {
ofile << "// script2txt2 comment: unbalanced!\n";
}
}
if (end && procs) {
if (!dec()) {
ofile << "// script2txt2 comment: unbalanced!\n";
}
} }
// write function calls ofile << indent << l << "\n";
{
std::ofstream functions("functions.txt", std::ios::app); if (end && indent.empty()) {
if (functions) //ofile << "\n";
{ }
for (auto &f : driver.functions) if (end && procs) {
{ procs = 0;
std::string f2(f.size(), 0); }
std::transform(f.begin(), f.end(), f2.begin(), tolower); if (lbrace || proc) {
functions << f2 << "\n"; indent += space;
}
if (proc) {
procs = 1;
}
}
} }
} }
}*/
}; };
if (fs::is_regular_file(p)) { if (fs::is_regular_file(p)) {