MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / query_graph_tree_rows_text

Function query_graph_tree_rows_text

src/mcp/mcp.c:5820–5877  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5818}
5819
5820static char *query_graph_tree_rows_text(const cbm_cypher_result_t *result, int row_offset,
5821 int row_count, bool allow_directory) {
5822 cbm_sb_t sb;
5823 cbm_sb_init(&sb);
5824 bool cell_count_safe = row_count > 0 && result->col_count > 0 &&
5825 (size_t)row_count <= SIZE_MAX / (size_t)result->col_count;
5826 size_t cell_count = cell_count_safe ? (size_t)row_count * (size_t)result->col_count : 0;
5827 cell_count_safe = cell_count_safe && cell_count <= SIZE_MAX / sizeof(const char *);
5828 const char **cells =
5829 cell_count_safe ? (const char **)malloc(cell_count * sizeof(*cells)) : NULL;
5830 if (cells) {
5831 for (int row = 0; row < row_count; row++) {
5832 for (int col = 0; col < result->col_count; col++) {
5833 cells[(size_t)row * (size_t)result->col_count + (size_t)col] =
5834 result->rows[row_offset + row][col];
5835 }
5836 }
5837 if (allow_directory) {
5838 bool *prefix_cols = calloc((size_t)result->col_count, sizeof(*prefix_cols));
5839 if (prefix_cols) {
5840 for (int col = 0; col < result->col_count; col++) {
5841 prefix_cols[col] = query_graph_semantic_prefix_column(result->columns[col]);
5842 }
5843 cbm_tree_table_rows_profiled(&sb, "rows", row_count,
5844 (const char *const *)result->columns,
5845 result->col_count, cells, NULL, prefix_cols);
5846 free(prefix_cols);
5847 } else {
5848 cbm_tree_table_rows(&sb, "rows", row_count, (const char *const *)result->columns,
5849 result->col_count, cells);
5850 }
5851 } else {
5852 cbm_tree_table_header(&sb, "rows", row_count, (const char *const *)result->columns,
5853 result->col_count);
5854 for (int row = 0; row < row_count; row++) {
5855 cbm_tree_row_begin(&sb);
5856 for (int col = 0; col < result->col_count; col++) {
5857 cbm_tree_cell_str(&sb,
5858 cells[(size_t)row * (size_t)result->col_count + (size_t)col],
5859 col == 0);
5860 }
5861 cbm_tree_row_end(&sb);
5862 }
5863 }
5864 free(cells);
5865 } else {
5866 cbm_tree_table_header(&sb, "rows", row_count, (const char *const *)result->columns,
5867 result->col_count);
5868 for (int row = 0; row < row_count; row++) {
5869 cbm_tree_row_begin(&sb);
5870 for (int col = 0; col < result->col_count; col++) {
5871 cbm_tree_cell_str(&sb, result->rows[row_offset + row][col], col == 0);
5872 }
5873 cbm_tree_row_end(&sb);
5874 }
5875 }
5876 return cbm_sb_finish(&sb);
5877}

Callers 1

Calls 9

cbm_sb_initFunction · 0.85
cbm_tree_table_rowsFunction · 0.85
cbm_tree_table_headerFunction · 0.85
cbm_tree_row_beginFunction · 0.85
cbm_tree_cell_strFunction · 0.85
cbm_tree_row_endFunction · 0.85
cbm_sb_finishFunction · 0.85

Tested by

no test coverage detected