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

Function csv_record_path

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

* Record the requested path elements. The input should be a set of * container or instances names, separated by slashes. */

Source from the content-addressed store, hash-verified

605 * container or instances names, separated by slashes.
606 */
607static int
608csv_record_path (xo_handle_t *xop, csv_private_t *csv, const char *path_raw)
609{
610 int count;
611 char *cp, *ep, *np;
612 ssize_t len = strlen(path_raw);
613 char *path_buf = xo_realloc(NULL, len + 1);
614
615 memcpy(path_buf, path_raw, len + 1);
616
617 for (cp = path_buf, ep = path_buf + len, count = 2;
618 cp && cp < ep; cp = np) {
619 np = strchr(cp, '/');
620 if (np) {
621 np += 1;
622 count += 1;
623 }
624 }
625
626 path_frame_t *path = xo_realloc(NULL, sizeof(path[0]) * count);
627 if (path == NULL) {
628 xo_failure(xop, "allocation failure for path '%s'", path_buf);
629 return -1;
630 }
631
632 bzero(path, sizeof(path[0]) * count);
633
634 for (count = 0, cp = path_buf; cp && cp < ep; cp = np) {
635 path[count++].pf_name = cp;
636
637 np = strchr(cp, '/');
638 if (np)
639 *np++ = '\0';
640 csv_dbg(xop, csv, "path: [%s]\n", cp);
641 }
642
643 path[count].pf_name = NULL;
644
645 if (csv->c_path) /* In case two paths are given */
646 xo_free(csv->c_path);
647 if (csv->c_path_buf) /* In case two paths are given */
648 xo_free(csv->c_path_buf);
649
650 csv->c_path_buf = path_buf;
651 csv->c_path = path;
652 csv->c_path_max = count;
653 csv->c_path_cur = 0;
654
655 return 0;
656}
657
658/*
659 * Extract the option values. The format is:

Callers 1

csv_optionsFunction · 0.85

Calls 5

strchrFunction · 0.85
xo_failureFunction · 0.85
bzeroFunction · 0.85
csv_dbgFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected