Lines Matching refs:csv
164 csv_dbg (xo_handle_t *xop UNUSED, csv_private_t *csv UNUSED, in csv_dbg()
167 if (csv == NULL || !(csv->c_flags & CF_DEBUG)) in csv_dbg()
184 csv_private_t *csv = xo_realloc(NULL, sizeof(*csv)); in csv_create() local
185 if (csv == NULL) in csv_create()
188 bzero(csv, sizeof(*csv)); in csv_create()
189 xo_buf_init(&csv->c_data); in csv_create()
190 xo_buf_init(&csv->c_name_buf); in csv_create()
191 xo_buf_init(&csv->c_value_buf); in csv_create()
193 xo_buf_init(&csv->c_stack_buf); in csv_create()
196 xo_set_private(xop, csv); in csv_create()
205 csv_destroy (xo_handle_t *xop UNUSED, csv_private_t *csv) in csv_destroy() argument
208 xo_buf_cleanup(&csv->c_data); in csv_destroy()
209 xo_buf_cleanup(&csv->c_name_buf); in csv_destroy()
210 xo_buf_cleanup(&csv->c_value_buf); in csv_destroy()
212 xo_buf_cleanup(&csv->c_stack_buf); in csv_destroy()
215 if (csv->c_leaf) in csv_destroy()
216 xo_free(csv->c_leaf); in csv_destroy()
217 if (csv->c_path_buf) in csv_destroy()
218 xo_free(csv->c_path_buf); in csv_destroy()
226 csv_path_top (csv_private_t *csv, ssize_t delta) in csv_path_top() argument
228 if (!(csv->c_flags & CF_HAS_PATH) || csv->c_path == NULL) in csv_path_top()
231 ssize_t cur = csv->c_path_cur + delta; in csv_path_top()
236 return csv->c_path[cur].pf_name; in csv_path_top()
243 csv_stack_push (csv_private_t *csv UNUSED, const char *name UNUSED) in csv_stack_push()
246 csv->c_stack_depth += 1; in csv_stack_push()
254 csv_stack_pop (csv_private_t *csv UNUSED, const char *name UNUSED) in csv_stack_pop()
257 csv->c_stack_depth -= 1; in csv_stack_pop()
271 csv_quote_flags (xo_handle_t *xop UNUSED, csv_private_t *csv UNUSED, in csv_quote_flags()
277 if (csv->c_flags & CF_NO_QUOTES) /* User doesn't want quotes */ in csv_quote_flags()
293 csv_dbg(xop, csv, "csv: quote flags [%s] -> %x (%zu/%zu)\n", in csv_quote_flags()
323 csv_append_newline (xo_buffer_t *xbp, csv_private_t *csv) in csv_append_newline() argument
325 if (csv->c_flags & CF_DOS_NEWLINE) in csv_append_newline()
337 csv_emit_record (xo_handle_t *xop, csv_private_t *csv) in csv_emit_record() argument
339 csv_dbg(xop, csv, "csv: emit: ...\n"); in csv_emit_record()
346 if (csv->c_leaf_depth == 0) in csv_emit_record()
349 if (!(csv->c_flags & (CF_HEADER_DONE | CF_NO_HEADER))) { in csv_emit_record()
350 csv->c_flags |= CF_HEADER_DONE; in csv_emit_record()
352 for (fnum = 0; fnum < csv->c_leaf_depth; fnum++) { in csv_emit_record()
353 lp = &csv->c_leaf[fnum]; in csv_emit_record()
354 const char *name = xo_buf_data(&csv->c_name_buf, lp->f_name); in csv_emit_record()
357 xo_buf_append(&csv->c_data, ",", 1); in csv_emit_record()
359 xo_buf_append(&csv->c_data, name, strlen(name)); in csv_emit_record()
362 csv_append_newline(&csv->c_data, csv); in csv_emit_record()
365 for (fnum = 0; fnum < csv->c_leaf_depth; fnum++) { in csv_emit_record()
366 lp = &csv->c_leaf[fnum]; in csv_emit_record()
370 value = xo_buf_data(&csv->c_value_buf, lp->f_value); in csv_emit_record()
375 quote_flags = csv_quote_flags(xop, csv, value); in csv_emit_record()
378 xo_buf_append(&csv->c_data, ",", 1); in csv_emit_record()
381 xo_buf_append(&csv->c_data, "\"", 1); in csv_emit_record()
384 csv_escape(&csv->c_data, value, strlen(value)); in csv_emit_record()
386 xo_buf_append(&csv->c_data, value, strlen(value)); in csv_emit_record()
389 xo_buf_append(&csv->c_data, "\"", 1); in csv_emit_record()
392 csv_append_newline(&csv->c_data, csv); in csv_emit_record()
399 for (fnum = 0; fnum < csv->c_leaf_depth; fnum++) { in csv_emit_record()
400 lp = &csv->c_leaf[fnum]; in csv_emit_record()
406 xo_buf_reset(&csv->c_value_buf); in csv_emit_record()
412 csv->c_flags |= CF_LEAFS_DONE; in csv_emit_record()
421 csv_open_level (xo_handle_t *xop UNUSED, csv_private_t *csv, in csv_open_level() argument
425 if (csv->c_flags & CF_RECORD_DATA) { in csv_open_level()
426 csv->c_flags &= ~CF_RECORD_DATA; in csv_open_level()
427 csv_emit_record(xop, csv); in csv_open_level()
431 const char *path_top = csv_path_top(csv, 0); in csv_open_level()
435 if (instance && !(csv->c_flags & CF_HAS_PATH)) { in csv_open_level()
436 csv_dbg(xop, csv, "csv: recording (no-path) ...\n"); in csv_open_level()
437 csv->c_flags |= CF_RECORD_DATA; in csv_open_level()
441 csv->c_path_cur += 1; /* Advance to next path member */ in csv_open_level()
443 csv_dbg(xop, csv, "csv: match: [%s] (%zd/%zd)\n", name, in csv_open_level()
444 csv->c_path_cur, csv->c_path_max); in csv_open_level()
447 if (csv->c_path_cur == csv->c_path_max) { in csv_open_level()
448 csv_dbg(xop, csv, "csv: recording ...\n"); in csv_open_level()
449 csv->c_flags |= CF_RECORD_DATA; in csv_open_level()
454 csv_stack_push(csv, name); in csv_open_level()
463 csv_close_level (xo_handle_t *xop UNUSED, csv_private_t *csv, const char *name) in csv_close_level() argument
466 if (csv->c_flags & CF_RECORD_DATA) { in csv_close_level()
467 csv->c_flags &= ~CF_RECORD_DATA; in csv_close_level()
468 csv_emit_record(xop, csv); in csv_close_level()
471 const char *path_top = csv_path_top(csv, -1); in csv_close_level()
472 csv_dbg(xop, csv, "csv: close: [%s] [%s] (%zd)\n", name, in csv_close_level()
473 path_top ?: "", csv->c_path_cur); in csv_close_level()
477 csv->c_path_cur -= 1; in csv_close_level()
482 csv_stack_pop(csv, name); in csv_close_level()
493 csv_leaf_num (xo_handle_t *xop UNUSED, csv_private_t *csv, in csv_leaf_num() argument
498 xo_buffer_t *xbp = &csv->c_name_buf; in csv_leaf_num()
500 for (fnum = 0; fnum < csv->c_leaf_depth; fnum++) { in csv_leaf_num()
501 lp = &csv->c_leaf[fnum]; in csv_leaf_num()
509 if (csv->c_flags & CF_LEAFS_DONE) in csv_leaf_num()
514 if (csv->c_leaf_depth + 1 >= csv->c_leaf_max) { in csv_leaf_num()
516 ssize_t new_max = csv->c_leaf_max * 2; in csv_leaf_num()
520 lp = xo_realloc(csv->c_leaf, new_max * sizeof(*lp)); in csv_leaf_num()
525 bzero(&lp[csv->c_leaf_max], csv->c_leaf_max * sizeof(*lp)); in csv_leaf_num()
528 csv->c_leaf = lp; in csv_leaf_num()
529 csv->c_leaf_max = new_max; in csv_leaf_num()
532 lp = &csv->c_leaf[csv->c_leaf_depth++]; in csv_leaf_num()
534 lp->f_depth = csv->c_stack_depth; in csv_leaf_num()
545 csv_dbg(xop, csv, "csv: leaf: name: %zd [%s] [%s] %x\n", in csv_leaf_num()
555 csv_leaf_set (xo_handle_t *xop UNUSED, csv_private_t *csv, leaf_t *lp, in csv_leaf_set() argument
558 xo_buffer_t *xbp = &csv->c_value_buf; in csv_leaf_set()
566 csv_dbg(xop, csv, "csv: leaf: value: [%s] [%s] %x\n", in csv_leaf_set()
575 csv_record_leafs (xo_handle_t *xop, csv_private_t *csv, const char *leafs_raw) in csv_record_leafs() argument
591 csv_dbg(xop, csv, "adding leaf: [%s]\n", cp); in csv_record_leafs()
592 csv_leaf_num(xop, csv, cp, 0); in csv_record_leafs()
598 csv->c_flags |= CF_LEAFS_DONE; in csv_record_leafs()
608 csv_record_path (xo_handle_t *xop, csv_private_t *csv, const char *path_raw) in csv_record_path() argument
640 csv_dbg(xop, csv, "path: [%s]\n", cp); in csv_record_path()
645 if (csv->c_path) /* In case two paths are given */ in csv_record_path()
646 xo_free(csv->c_path); in csv_record_path()
647 if (csv->c_path_buf) /* In case two paths are given */ in csv_record_path()
648 xo_free(csv->c_path_buf); in csv_record_path()
650 csv->c_path_buf = path_buf; in csv_record_path()
651 csv->c_path = path; in csv_record_path()
652 csv->c_path_max = count; in csv_record_path()
653 csv->c_path_cur = 0; in csv_record_path()
664 csv_options (xo_handle_t *xop, csv_private_t *csv, in csv_options() argument
684 if (vp != NULL && csv_record_path(xop, csv, vp)) in csv_options()
687 csv->c_flags |= CF_HAS_PATH; /* Yup, we have an explicit path now */ in csv_options()
693 if (vp != NULL && csv_record_leafs(xop, csv, vp)) in csv_options()
697 csv->c_flags |= CF_NO_KEYS; in csv_options()
699 csv->c_flags |= CF_NO_HEADER; in csv_options()
701 csv->c_flags |= CF_VALUE_ONLY; in csv_options()
703 csv->c_flags |= CF_DOS_NEWLINE; in csv_options()
705 csv->c_flags |= CF_NO_QUOTES; in csv_options()
707 csv->c_flags |= CF_DEBUG; in csv_options()
723 csv_data (xo_handle_t *xop UNUSED, csv_private_t *csv UNUSED, in csv_data()
727 csv_dbg(xop, csv, "data: [%s]=[%s] %llx\n", name, value, (unsigned long long) flags); in csv_data()
729 if (!(csv->c_flags & CF_RECORD_DATA)) in csv_data()
733 int fnum = csv_leaf_num(xop, csv, name, flags); in csv_data()
737 leaf_t *lp = &csv->c_leaf[fnum]; in csv_data()
738 csv_leaf_set(xop, csv, lp, value); in csv_data()
751 csv_private_t *csv = private; in csv_handler() local
752 xo_buffer_t *xbp = csv ? &csv->c_data : NULL; in csv_handler()
754 csv_dbg(xop, csv, "op %s: [%s] [%s]\n", xo_encoder_op_name(op), in csv_handler()
759 if (csv == NULL && op != XO_OP_CREATE) in csv_handler()
768 rc = csv_options(xop, csv, value, ':'); in csv_handler()
772 rc = csv_options(xop, csv, value, '+'); in csv_handler()
781 rc = csv_open_level(xop, csv, name, 0); in csv_handler()
785 rc = csv_open_level(xop, csv, name, 1); in csv_handler()
791 rc = csv_close_level(xop, csv, name); in csv_handler()
796 rc = csv_data(xop, csv, name, value, flags); in csv_handler()
811 csv_destroy(xop, csv); in csv_handler()