181 {
183 printf("error: too many arguments\n");
184 status = -1;
185 }
186 return status == 0;
187}
188
189
190
191
192
193
194int main(
int argc,
const char *argv[])
195{
197 int status = 0;
199 return status;
200
201
202
203 bool is_demo = args.
filename ==
nullptr;
204
205
206 char demo_yaml[] = ""
207 "doe: a deer, a female deer\n"
208 "ray: a drop of golden sun\n"
209 "me : a name I call myself\n"
210 "far: a long long way to run\n"
211 "";
212
213
215 const int demo_expected[] = {
230 };
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
252
253 const char *filename = args.
filename;
254 std::vector<char> yaml_file;
256
257 if(is_demo)
258 {
259 yaml = demo_yaml;
260 filename = "demo";
261 }
262 else
263 {
265 if(filename_ == "-" || filename_ == "stdin")
267 else
270 }
271
276
278
279
280
281
283 {
285 return 1;
286 }
287 else
288 {
290 return 1;
291 }
292
293 if( ! is_demo)
294 {
296 {
301 }
302 return 0;
303 }
304
305
306 bool success = true;
307
308
309
310 char flags[100];
312 pos < sz;
313 ++pos, ++evt)
314 {
315 bool ok = (result.
events[pos] == demo_expected[pos]);
316
318 {
319
321 printf(
"pos=%zu\tevent[%zu]:\t%.*s = 0x%08x", pos, evt,
static_cast<int>(len), flags, result.
events[pos]);
322 }
324 {
325 int offset = result.
events[pos + 1];
326 int length = result.
events[pos + 2];
328
329 const char *ptr = in_arena ? result.
arena.data() : yaml.
str;
330 const char *str = ptr + offset;
332 printf("\tstr=(%d,%d)\t'%.*s'", offset, length, length, str);
333 ok = ok && (offset == demo_expected[pos + 1]);
334 ok = ok && (length == demo_expected[pos + 2]);
int32_t evt_size
data type for integer events size.
void events_ints_print(csubstr parsed_yaml, csubstr arena, ievt::evt_bits const *evts, ievt::evt_bits evts_sz)
Print integer events to stdout.
evt_size estimate_events_ints_size(csubstr src)
Read YAML source and, without undergoing a full parse, estimate the size of the integer buffer requir...
void file_get_contents(const char *filename, FILE *fp, size_t filesz, void *buf, size_t bufsz)
load a file of specified size from disk into an existing contiguous buffer.
void stdin_get_contents(ContiguousContainer *cont, FILE *f=stdin)
load a file from stdin (or similar stream-like file) and return a newly created ContiguousContainer w...
substr to_substr(char(&s)[N]) noexcept
csubstr to_csubstr(const char(&s)[N]) noexcept
basic_substring< char > substr
a mutable string view
int main(int argc, const char *argv[])
bool parse_in_place(const char *filename, c4::substr yaml, IntsResult *result)
c4::yml::extra::EventHandlerInts handler
bool parse_or_resize_and_then_parse(const char *filename, c4::csubstr yaml, IntsResult *result)
std::vector< char > yaml
source buffer
std::vector< evt_bits > events
result buffer with events
std::vector< char > arena
arena to place out-of-source filtered scalars or tags
void resize_buffers(c4::yml::extra::evt_size esz, size_t arena_size)
size_t size() const noexcept
evt_size required_size_events() const
get the size needed for the event buffer from the previous parse