Lines Matching +full:double +full:- +full:buffering

12  * CSV encoder generates comma-separated value files for specific
18 * <total-blocks>4</total-blocks>
19 * <used-blocks>4</used-blocks>
20 * <available-blocks>0</available-blocks>
21 * <used-percent>100</used-percent>
22 * <mounted-on>/proc</mounted-on>
27 * #+name,total-blocks,used-blocks,available-blocks,used-percent,mounted-on
33 * buffering.
37 * - Fields containing a line-break, double-quote or commas should be
40 * - A (double) quote character in a field must be represented by two
41 * (double) quote characters.
42 * - Leading and trialing whitespace require fields be quoted.
44 * Cheesy, but simple. The RFC also requires MS-DOS end-of-line,
46 * in a DOS-friendly world, but then again, we make spaceships based
71 * - The path holds the path we are matching against
72 * - This is given as input via "options" and does not change
74 * - The stack holds the current names of the open elements
75 * - The "open" operations push, while the "close" pop
76 * - Turns out, at this point, the stack is unused, but I've
80 * - The leafs record the current set of leaf
81 * - A key from the parent list counts as a leaf (unless CF_NO_KEYS)
82 * - Once the path is matched, all other leafs at that level are leafs
83 * - Leafs are recorded to get the header comment accurately recorded
84 * - Once the first line is emited, the set of leafs _cannot_ change
151 #define CF_DOS_NEWLINE (1<<4) /* Generate CR-NL, just like MS-DOS */
167 if (csv == NULL || !(csv->c_flags & CF_DEBUG)) in csv_dbg()
186 return -1; 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()
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()
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()
246 csv->c_stack_depth += 1; in csv_stack_push()
257 csv->c_stack_depth -= 1; in csv_stack_pop()
277 if (csv->c_flags & CF_NO_QUOTES) /* User doesn't want quotes */ in csv_quote_flags()
287 else if (isspace((int) value[len - 1])) /* Trailing whitespace */ in csv_quote_flags()
293 csv_dbg(xop, csv, "csv: quote flags [%s] -> %x (%zu/%zu)\n", in csv_quote_flags()
311 xo_buf_append(xbp, cp, np - cp); in csv_escape()
314 xo_buf_append(xbp, cp, ep - cp); in csv_escape()
325 if (csv->c_flags & CF_DOS_NEWLINE) in csv_append_newline()
333 * this is the first line and "no-header" isn't given, make a 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()
369 if (lp->f_flags & LF_HAS_VALUE) { in csv_emit_record()
370 value = xo_buf_data(&csv->c_value_buf, lp->f_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()
402 lp->f_flags &= ~LF_HAS_VALUE; in csv_emit_record()
403 lp->f_value = 0; 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()
425 if (csv->c_flags & CF_RECORD_DATA) { in csv_open_level()
426 csv->c_flags &= ~CF_RECORD_DATA; 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()
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()
449 csv->c_flags |= CF_RECORD_DATA; in csv_open_level()
466 if (csv->c_flags & CF_RECORD_DATA) { in csv_close_level()
467 csv->c_flags &= ~CF_RECORD_DATA; in csv_close_level()
471 const char *path_top = csv_path_top(csv, -1); 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()
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()
503 const char *fname = xo_buf_data(xbp, lp->f_name); in csv_leaf_num()
509 if (csv->c_flags & CF_LEAFS_DONE) in csv_leaf_num()
510 return -1; 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()
522 return -1; /* No luck; bail */ 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()
537 lp->f_name = xo_buf_offset(xbp); in csv_leaf_num()
543 lp->f_flags |= LF_KEY; in csv_leaf_num()
546 fnum, name, cp, lp->f_flags); in csv_leaf_num()
558 xo_buffer_t *xbp = &csv->c_value_buf; in csv_leaf_set()
560 lp->f_value = xo_buf_offset(xbp); in csv_leaf_set()
561 lp->f_flags |= LF_HAS_VALUE; in csv_leaf_set()
567 value, cp, lp->f_flags); in csv_leaf_set()
598 csv->c_flags |= CF_LEAFS_DONE; in csv_record_leafs()
629 return -1; 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()
660 * -libxo encoder=csv:kw=val:kw=val:kw=val,pretty
661 * -libxo encoder=csv+kw=val+kw=val+kw=val,pretty
685 return -1; in csv_options()
687 csv->c_flags |= CF_HAS_PATH; /* Yup, we have an explicit path now */ in csv_options()
694 return -1; in csv_options()
696 } else if (xo_streq(cp, "no-keys")) { in csv_options()
697 csv->c_flags |= CF_NO_KEYS; in csv_options()
698 } else if (xo_streq(cp, "no-header")) { in csv_options()
699 csv->c_flags |= CF_NO_HEADER; in csv_options()
700 } else if (xo_streq(cp, "value-only")) { in csv_options()
701 csv->c_flags |= CF_VALUE_ONLY; in csv_options()
703 csv->c_flags |= CF_DOS_NEWLINE; in csv_options()
704 } else if (xo_streq(cp, "no-quotes")) { in csv_options()
705 csv->c_flags |= CF_NO_QUOTES; in csv_options()
707 csv->c_flags |= CF_DEBUG; in csv_options()
709 xo_warn_hc(xop, -1, in csv_options()
711 return -1; in csv_options()
729 if (!(csv->c_flags & CF_RECORD_DATA)) in csv_data()
737 leaf_t *lp = &csv->c_leaf[fnum]; in csv_data()
752 xo_buffer_t *xbp = csv ? &csv->c_data : NULL; in csv_handler()
760 return -1; in csv_handler()
794 case XO_OP_STRING: /* Quoted UTF-8 string */ in csv_handler()
803 rc = write(1, xbp->xb_bufp, xbp->xb_curp - xbp->xb_bufp); in csv_handler()
830 arg->xei_handler = csv_handler; in xo_encoder_library_init()
831 arg->xei_version = XO_ENCODER_VERSION; in xo_encoder_library_init()