static void yaml_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *s; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("Short JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } s = (p ? p->longname : fname); if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoString(ctx->dest, "\n"); appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); } else ctx->first = bms_del_member(ctx->first, ctx->level); ctx->valconverter = NULL; ctx->fname = s; ctx->valconverter = (p ? p->converter : NULL); }
static void json_aestart(void *state, bool isnull) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->remove) return; if (IS_INDENTED_ARRAY(ctx->current_list) && ctx->wlist_level == 1) { if (!bms_is_member(ctx->level, ctx->first)) appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE) { appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level) * INDENT_STEP); } } else { if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE && !ctx->last_elem_is_object) appendStringInfoChar(ctx->dest, ' '); } } ctx->first = bms_del_member(ctx->first, ctx->level); }
static void xml_aestart(void *state, bool isnull) { pgspParserContext *ctx = (pgspParserContext *)state; char *tag; /* * The "Trigger" in "Triggers", "Plan" in "Plans" and "Item" nodes are * implicitly represented in JSON format. Restore them for XML format. */ ctx->level++; if (bms_is_member(ctx->level, ctx->not_item)) { if (ctx->processing == P_Plan) tag = "<Plan>"; else tag = "<Trigger>"; } else tag = "<Item>"; appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level + 1) * INDENT_STEP); appendStringInfoString(ctx->dest, tag); }
static void xml_arrend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level + 1) * INDENT_STEP); }
static void yaml_aestart(void *state, bool isnull) { pgspParserContext *ctx = (pgspParserContext *)state; appendStringInfoString(ctx->dest, "\n"); bms_del_member(ctx->first, ctx->level); appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); appendStringInfoString(ctx->dest, "- "); }
/* YAML */ static void yaml_objstart(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->fname) { if (ctx->dest->len > 0) appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level - 1) * INDENT_STEP); appendStringInfoString(ctx->dest, "- "); appendStringInfoString(ctx->dest, ctx->fname); appendStringInfoString(ctx->dest, ":\n"); appendStringInfoSpaces(ctx->dest, (ctx->level + 1) * INDENT_STEP); ctx->fname = NULL; } ctx->level++; ctx->first = bms_add_member(ctx->first, ctx->level); }
static void xml_objend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); ctx->level--; ctx->first = bms_del_member(ctx->first, ctx->level); ctx->last_elem_is_object = true; }
static void json_arrend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->mode == PGSP_JSON_INFLATE && ctx->last_elem_is_object) { appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level - 1) * INDENT_STEP); } appendStringInfoChar(ctx->dest, ']'); ctx->level--; }
static void json_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *fn; ctx->remove = false; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } ctx->remove = (ctx->mode == PGSP_JSON_NORMALIZE && (!p || !p->normalize_use)); if (ctx->remove) return; if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, '\n'); } else ctx->first = bms_del_member(ctx->first, ctx->level); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); if (!p || !p->longname) fn = fname; else if (ctx->mode == PGSP_JSON_INFLATE) fn = p->longname; else fn = p->shortname; escape_json(ctx->dest, fn); ctx->fname = fn; ctx->valconverter = (p ? p->converter : NULL); appendStringInfoChar(ctx->dest, ':'); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, ' '); }
static void json_objend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->mode == PGSP_JSON_INFLATE) { if (!bms_is_member(ctx->level, ctx->first)) appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level - 1) * INDENT_STEP); } appendStringInfoChar(ctx->dest, '}'); ctx->level--; ctx->last_elem_is_object = true; ctx->first = bms_del_member(ctx->first, ctx->level); ctx->fname = NULL; }
static void json_arrend(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; if (IS_INDENTED_ARRAY(ctx->current_list)) ctx->wlist_level--; if (ctx->mode == PGSP_JSON_INFLATE && (IS_INDENTED_ARRAY(ctx->current_list) ? ctx->wlist_level == 0 : ctx->last_elem_is_object)) { appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level - 1) * INDENT_STEP); } appendStringInfoChar(ctx->dest, ']'); ctx->level--; }
static void xml_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *s; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("Short JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } s = (p ? p->longname : fname); /* * save current process context * There's no problem if P_Plan appears recursively. */ if (p && (p->tag == P_Plan || p->tag == P_Triggers)) ctx->processing = p->tag; appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level + 1) * INDENT_STEP); ctx->valconverter = NULL; appendStringInfoChar(ctx->dest, '<'); appendStringInfoString(ctx->dest, escape_xml(hyphenate_words(ctx, s))); appendStringInfoChar(ctx->dest, '>'); ctx->valconverter = (p ? p->converter : NULL); /* * If the object field name is Plan or Triggers, the value should be an * array and the items are tagged by other than "Item". "Item"s appear * only in Output field. */ if (p && (p->tag == P_Plans || p->tag == P_Triggers)) ctx->not_item = bms_add_member(ctx->not_item, ctx->level + 1); else ctx->not_item = bms_del_member(ctx->not_item, ctx->level + 1); }
static void pairingheap_dump_recurse(StringInfo buf, pairingheap_node *node, void (*dumpfunc) (pairingheap_node *node, StringInfo buf, void *opaque), void *opaque, int depth, pairingheap_node *prev_or_parent) { while (node) { Assert(node->prev_or_parent == prev_or_parent); appendStringInfoSpaces(buf, depth * 4); dumpfunc(node, buf, opaque); appendStringInfoString(buf, "\n"); if (node->first_child) pairingheap_dump_recurse(buf, node->first_child, dumpfunc, opaque, depth + 1, node); prev_or_parent = node; node = node->next_sibling; } }
static JsQuery* joinJsQuery(JsQueryItemType type, JsQuery *jq1, JsQuery *jq2) { JsQuery *out; StringInfoData buf; int32 left, right, chld; JsQueryItem v; initStringInfo(&buf); enlargeStringInfo(&buf, VARSIZE_ANY(jq1) + VARSIZE_ANY(jq2) + 4 * sizeof(int32) + VARHDRSZ); appendStringInfoSpaces(&buf, VARHDRSZ); /* form jqiAnd/jqiOr header */ appendStringInfoChar(&buf, (char)type); alignStringInfoInt(&buf); /* nextPos field of header*/ chld = 0; /* actual value, not a fake */ appendBinaryStringInfo(&buf, (char*)&chld, sizeof(chld)); left = buf.len; appendBinaryStringInfo(&buf, (char*)&left /* fake value */, sizeof(left)); right = buf.len; appendBinaryStringInfo(&buf, (char*)&right /* fake value */, sizeof(right)); /* dump left and right subtree */ jsqInit(&v, jq1); chld = copyJsQuery(&buf, &v); *(int32*)(buf.data + left) = chld; jsqInit(&v, jq2); chld = copyJsQuery(&buf, &v); *(int32*)(buf.data + right) = chld; out = (JsQuery*)buf.data; SET_VARSIZE(out, buf.len); return out; }
/* JSON */ static void json_objstart(void *state) { pgspParserContext *ctx = (pgspParserContext *)state; if (ctx->mode == PGSP_JSON_INFLATE) { if (!ctx->fname && ctx->dest->len > 0) { appendStringInfoChar(ctx->dest, '\n'); appendStringInfoSpaces(ctx->dest, (ctx->level) * INDENT_STEP); } ctx->fname = NULL; } appendStringInfoChar(ctx->dest, '{'); ctx->level++; ctx->first = bms_add_member(ctx->first, ctx->level); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, '\n'); }
Datum jsquery_not(PG_FUNCTION_ARGS) { JsQuery *jq = PG_GETARG_JSQUERY(0); JsQuery *out; StringInfoData buf; int32 arg, chld; JsQueryItem v; initStringInfo(&buf); enlargeStringInfo(&buf, VARSIZE_ANY(jq) + 4 * sizeof(int32) + VARHDRSZ); appendStringInfoSpaces(&buf, VARHDRSZ); /* form jsquery header */ appendStringInfoChar(&buf, (char)jqiNot); alignStringInfoInt(&buf); /* nextPos field of header*/ chld = 0; /* actual value, not a fake */ appendBinaryStringInfo(&buf, (char*)&chld, sizeof(chld)); arg = buf.len; appendBinaryStringInfo(&buf, (char*)&arg /* fake value */, sizeof(arg)); jsqInit(&v, jq); chld = copyJsQuery(&buf, &v); *(int32*)(buf.data + arg) = chld; out = (JsQuery*)buf.data; SET_VARSIZE(out, buf.len); PG_FREE_IF_COPY(jq, 0); PG_RETURN_JSQUERY(out); }
static void dumpXMLNodeDebugInternal(char *data, XMLNodeOffset off, XMLNodeOffset offParent, StringInfo output, unsigned short level) { XMLNodeHdr node = (XMLNodeHdr) (data + off); XMLNodeOffset offRel = offParent - off; char *str; unsigned int size; appendStringInfoSpaces(output, level); switch (node->kind) { case XMLNODE_ELEMENT: size = getXMLNodeSize(node, true); appendStringInfo(output, "%s (abs: %u , rel: %u , size: %u)\n", XNODE_ELEMENT_NAME((XMLCompNodeHdr) node), off, offRel, size); { XMLCompNodeHdr element = (XMLCompNodeHdr) node; if (element->children > 0) { unsigned short i; unsigned short bwidth = XNODE_GET_REF_BWIDTH(element); char *refPtr = XNODE_FIRST_REF(element); for (i = 0; i < element->children; i++) { XMLNodeOffset offRel = readXMLNodeOffset(&refPtr, bwidth, true); dumpXMLNodeDebugInternal(data, off - offRel, off, output, level + 1); } } } break; case XMLNODE_ATTRIBUTE: str = XNODE_CONTENT(node); break; case XMLNODE_COMMENT: str = "<comment>"; break; case XMLNODE_CDATA: str = "CDATA"; break; case XMLNODE_PI: str = "PI"; break; case XMLNODE_TEXT: str = "<text>"; break; default: elog(ERROR, "unrecognized node kind %u", node->kind); break; } if (node->kind != XMLNODE_ELEMENT) { size = getXMLNodeSize(node, true); if (node->kind == XMLNODE_ATTRIBUTE) { appendStringInfoChar(output, '@'); } appendStringInfo(output, "%s (abs: %u , rel: %u , size: %u)\n", str, off, offRel, size); } }
static void json_ofstart(void *state, char *fname, bool isnull) { word_table *p; pgspParserContext *ctx = (pgspParserContext *)state; char *fn; ctx->remove = false; p = search_word_table(propfields, fname, ctx->mode); if (!p) { ereport(DEBUG1, (errmsg("JSON parser encoutered unknown field name: \"%s\".", fname), errdetail_log("INPUT: \"%s\"", ctx->org_string))); } ctx->remove = (ctx->mode == PGSP_JSON_NORMALIZE && (!p || !p->normalize_use)); if (ctx->remove) return; if (!bms_is_member(ctx->level, ctx->first)) { appendStringInfoChar(ctx->dest, ','); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, '\n'); } else ctx->first = bms_del_member(ctx->first, ctx->level); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoSpaces(ctx->dest, ctx->level * INDENT_STEP); /* * We intentionally let some property names not have a short name. Use long * name for the cases. */ if (!p || !p->longname) fn = fname; else if (ctx->mode == PGSP_JSON_INFLATE || !(p->shortname && p->shortname[0])) fn = p->longname; else fn = p->shortname; escape_json(ctx->dest, fn); ctx->fname = fn; ctx->valconverter = (p ? p->converter : NULL); appendStringInfoChar(ctx->dest, ':'); if (ctx->mode == PGSP_JSON_INFLATE) appendStringInfoChar(ctx->dest, ' '); if (p && IS_INDENTED_ARRAY(p->tag)) { ctx->current_list = p->tag; ctx->list_fname = fname; ctx->wlist_level = 0; } }