MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / read_asc

Method read_asc

src/openboardview/FileFormats/ASCFile.cpp:102–136  ·  view source on GitHub ↗

* Read one of the *.asc file * pins.asc, parts.asc (not supported), nets.asc (not supported), nails.asc, format.asc * *.bom files not supported either */

Source from the content-addressed store, hash-verified

100 * *.bom files not supported either
101 */
102bool ASCFile::read_asc(const filesystem::path &filepath, void (ASCFile::*parser)(char *&, char *&, char *&, char *&, line_iterator_t&)) {
103 if (filepath.empty()) return false;
104 std::vector<char> buf = file_as_buffer(filepath, error_msg);
105 if (buf.empty()) return false;
106
107 ENSURE_OR_FAIL(buf.size() > 4, error_msg, return false);
108 size_t file_buf_size = 3 * (1 + buf.size());
109 file_buf = (char *)calloc(1, file_buf_size);
110 ENSURE_OR_FAIL(file_buf != nullptr, error_msg, return false);
111
112 std::copy(buf.begin(), buf.end(), file_buf);
113 file_buf[buf.size()] = 0;
114 // This is for fixing degenerate utf8
115 char *arena = &file_buf[buf.size() + 1];
116 char *arena_end = file_buf + file_buf_size - 1;
117 *arena_end = 0;
118
119 std::vector<char *> lines;
120 stringfile(file_buf, lines);
121
122 std::vector<char *>::iterator line_it = lines.begin();
123 while (line_it != lines.end()) {
124 char *line = *line_it;
125 ++line_it;
126
127 while (isspace((uint8_t)*line)) line++;
128 if (!line[0]) continue;
129
130 char *p = line;
131 char *s = nullptr;
132
133 (this->*parser)(p, s, arena, arena_end, line_it);
134 }
135 return true;
136}
137
138/*
139 * Updates element counts

Callers

nothing calls this directly

Calls 2

file_as_bufferFunction · 0.85
stringfileFunction · 0.85

Tested by

no test coverage detected