MCPcopy Create free account
hub / github.com/F-Stack/f-stack / csv_options

Function csv_options

tools/libxo/encoder/csv/enc_csv.c:663–716  ·  view source on GitHub ↗

* Extract the option values. The format is: * -libxo encoder=csv:kw=val:kw=val:kw=val,pretty * -libxo encoder=csv+kw=val+kw=val+kw=val,pretty */

Source from the content-addressed store, hash-verified

661 * -libxo encoder=csv+kw=val+kw=val+kw=val,pretty
662 */
663static int
664csv_options (xo_handle_t *xop, csv_private_t *csv,
665 const char *raw_opts, char opts_char)
666{
667 ssize_t len = strlen(raw_opts);
668 char *options = alloca(len + 1);
669 memcpy(options, raw_opts, len);
670 options[len] = '\0';
671
672 char *cp, *ep, *np, *vp;
673 for (cp = options, ep = options + len + 1; cp && cp < ep; cp = np) {
674 np = strchr(cp, opts_char);
675 if (np)
676 *np++ = '\0';
677
678 vp = strchr(cp, '=');
679 if (vp)
680 *vp++ = '\0';
681
682 if (xo_streq(cp, "path")) {
683 /* Record the path */
684 if (vp != NULL && csv_record_path(xop, csv, vp))
685 return -1;
686
687 csv->c_flags |= CF_HAS_PATH; /* Yup, we have an explicit path now */
688
689 } else if (xo_streq(cp, "leafs")
690 || xo_streq(cp, "leaf")
691 || xo_streq(cp, "leaves")) {
692 /* Record the leafs */
693 if (vp != NULL && csv_record_leafs(xop, csv, vp))
694 return -1;
695
696 } else if (xo_streq(cp, "no-keys")) {
697 csv->c_flags |= CF_NO_KEYS;
698 } else if (xo_streq(cp, "no-header")) {
699 csv->c_flags |= CF_NO_HEADER;
700 } else if (xo_streq(cp, "value-only")) {
701 csv->c_flags |= CF_VALUE_ONLY;
702 } else if (xo_streq(cp, "dos")) {
703 csv->c_flags |= CF_DOS_NEWLINE;
704 } else if (xo_streq(cp, "no-quotes")) {
705 csv->c_flags |= CF_NO_QUOTES;
706 } else if (xo_streq(cp, "debug")) {
707 csv->c_flags |= CF_DEBUG;
708 } else {
709 xo_warn_hc(xop, -1,
710 "unknown encoder option value: '%s'", cp);
711 return -1;
712 }
713 }
714
715 return 0;
716}
717
718/*
719 * Handler for incoming data values. We just record each leaf name and

Callers 1

csv_handlerFunction · 0.85

Calls 6

strchrFunction · 0.85
xo_streqFunction · 0.85
csv_record_pathFunction · 0.85
csv_record_leafsFunction · 0.85
xo_warn_hcFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected