inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) { assert(node->type() == node_element); // Print element name and attributes, if any if (!(flags & print_no_indenting)) { //out = fill_chars(out, indent, Ch('\t')); out = fill_chars(out, indent, Ch(' ')); out = fill_chars(out, indent, Ch(' ')); } *out = Ch('<'), ++out; out = copy_chars(node->name(), node->name() + node->name_size(), out); out = print_attributes(out, node); // If node is childless if (node->value_size() == 0 && !node->first_node()) { // Print childless node tag ending *out = Ch('/'), ++out; *out = Ch('>'), ++out; } else { // Print normal node tag ending *out = Ch('>'), ++out; // Test if node contains a single data node only (and no other nodes) xml_node<Ch> *child = node->first_node(); if (!child) { // If node has no children, only print its value without indenting out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out); } else if (child->next_sibling() == 0 && child->type() == node_data) { // If node has a sole data child, only print its value without indenting out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out); } else { // Print all children with full indenting if (!(flags & print_no_indenting)) *out = Ch('\n'), ++out; out = print_children(out, node, flags, indent + 1); if (!(flags & print_no_indenting)) { //out = fill_chars(out, indent, Ch('\t')); out = fill_chars(out, indent, Ch(' ')); out = fill_chars(out, indent, Ch(' ')); } } // Print node end *out = Ch('<'), ++out; *out = Ch('/'), ++out; out = copy_chars(node->name(), node->name() + node->name_size(), out); *out = Ch('>'), ++out; } return out; }
void poss_macro_expand(TokenStream& tok, char*&q, char*& p) { char temp_buff[TT_BUFFSIZE]; char token[MAX_IDEN_SIZE]; p = copy_token(p,token); // is it a macro? Otherwise just copy out.... if (tok.macro_attempt_process(p,temp_buff,token)) q = copy_chars(q,temp_buff); else q = copy_chars(q,token); }
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) { assert(node->type() == node_pi); if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t')); *out = Ch('<'), ++out; *out = Ch('?'), ++out; out = copy_chars(node->name(), node->name() + node->name_size(), out); *out = Ch(' '), ++out; out = copy_chars(node->value(), node->value() + node->value_size(), out); *out = Ch('?'), ++out; *out = Ch('>'), ++out; return out; }
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags) { for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) { if (attribute->name() && attribute->value()) { // Print attribute name *out = Ch(' '), ++out; out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out); *out = Ch('='), ++out; // Print attribute value using appropriate quote type if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size())) { *out = Ch('\''), ++out; out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out); *out = Ch('\''), ++out; } else { *out = Ch('"'), ++out; out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out); *out = Ch('"'), ++out; } } } return out; }
static inline void move_chars(struct part *p, int x, int y, int nx, int ny) { if (LEN(y) - x <= 0) return; copy_chars(p, nx, ny, LEN(y) - x, &POS(x, y)); SLEN(y, x); move_links(p, x, y, nx, ny); }
char *substitute(TokenStream& tok, char *buff, char **actual_args, char *subst) //---------------------------------------------------------------------------- { char temp_buff[TT_BUFFSIZE],args_buff[STRSIZE]; char *p = subst, *q = temp_buff; while (*p) { if (*p == ARG_MARKER) { // ie. 1..NARGS char *arg = actual_args[p[1]-1]; // get following (one-based) argument // stringize or token-pasting operator suppresses arg expansion // *fix 1.2.2a Token-pasting can operate the _other way_ of course! if (p > subst && (p[-1]=='#' || p[2]=='#')) { bool stringize = p[-1] == '#' && (p-1 == subst || p[-2] != '#'); // the last char(s) were '#' - discard them! if (stringize) { q--; *q++ = '\"'; } else if (p[-1]=='#') q -= 2; // copy the substitution, without expanding the argument q = (stringize? stringify : copy_chars)(q,arg); if (stringize) *q++ = '\"'; p += 2; // skip the special marker _and_ the arg index // ignore '##' afterwards, unless it's followed by a parameter.... if (p[0] == '#' && p[1] == '#' && p[2] != ARG_MARKER) p+= 2; } else { // must expand any arguments first! macro_substitute(tok,arg,args_buff); q = copy_chars(q,args_buff); p += 2; } } else *q++ = *p++; } *q = '\0'; macro_substitute(tok,temp_buff,buff); return buff; }
static inline void shift_chars(struct part *p, int y, int s) { chr *a; int l = LEN(y); if ((unsigned)l > MAXINT / sizeof(chr)) overalloc(); a = mem_alloc(l * sizeof(chr)); memcpy(a, &POS(0, y), l * sizeof(chr)); set_hchars(p, 0, y, s, (p->data->data[y].c << 11) | ' '); copy_chars(p, s, y, l, a); mem_free(a); move_links(p, 0, y, s, y); }
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) { assert(node->type() == node_comment); if (!(flags & print_no_indenting)) out = fill_chars(out, indent << 1, Ch(RAPIDXML_IC)); *out = Ch('<'), ++out; *out = Ch('!'), ++out; *out = Ch('-'), ++out; *out = Ch('-'), ++out; out = copy_chars(node->value(), node->value() + node->value_size(), out); *out = Ch('-'), ++out; *out = Ch('-'), ++out; *out = Ch('>'), ++out; return out; }
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) { assert(node->type() == node_doctype); if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t')); *out = Ch('<'), ++out; *out = Ch('!'), ++out; *out = Ch('D'), ++out; *out = Ch('O'), ++out; *out = Ch('C'), ++out; *out = Ch('T'), ++out; *out = Ch('Y'), ++out; *out = Ch('P'), ++out; *out = Ch('E'), ++out; *out = Ch(' '), ++out; out = copy_chars(node->value(), node->value() + node->value_size(), out); *out = Ch('>'), ++out; return out; }
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent) { assert(node->type() == node_cdata); if (!(flags & print_no_indenting)) out = fill_chars(out, indent, Ch('\t')); *out = Ch('<'); ++out; *out = Ch('!'); ++out; *out = Ch('['); ++out; *out = Ch('C'); ++out; *out = Ch('D'); ++out; *out = Ch('A'); ++out; *out = Ch('T'); ++out; *out = Ch('A'); ++out; *out = Ch('['); ++out; out = copy_chars(node->value(), node->value() + node->value_size(), out); *out = Ch(']'); ++out; *out = Ch(']'); ++out; *out = Ch('>'); ++out; return out; }
char *massage_subst_string(char *buff, char **args, char *str) { char *p = str, *q = buff; int i; char token[MAX_IDEN_SIZE]; while (*p) { // *fix 1.2.2 Argument may begin with '_' as well as a letter! while (*p && !iscsymf(*p)) { // *fix 1.2.2 (Eric)..quoted strings are copied verbatim if (*p == '\"') { copy_quote(q,p); break; } if (p[0] == '#' && p[1] == '#') { // *fix 1.2.2 (Eric) Skip whitespace before and after the ## while (q > buff && isspace(q[-1])) --q; // *change 1.2.2 keep token-pasting operator... *q++ = *p++; *q++ = *p++; while (isspace(*p)) ++p; } else *q++ = *p++; } if (*p == 0) break; //...pick up the identifier, and check it against the map p = copy_token(p,token); i = index_into(args,token); i++; //...if it is indeed a formal argument, then encode as the byte index, //...otherwise just copy to output buffer. // *change 1.2.2b (Eric) encode as unique macro-arg marker followed by byte index if (i > 0) { *q++ = ARG_MARKER; *q++ = (char)i; } else q = copy_chars(q,token); } *q = '\0'; return buff; }
out = print_node(out, child, flags, indent); return out; } // Print attributes of the node template<class OutIt, class Ch> inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags) { Q_UNUSED(flags) for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute()) { if (attribute->name() && attribute->value()) { // Print attribute name *out = Ch(' '), ++out; out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out); *out = Ch('='), ++out; // Print attribute value using appropriate quote type if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size())) { *out = Ch('\''), ++out; out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out); *out = Ch('\''), ++out; } else { *out = Ch('"'), ++out; out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out); *out = Ch('"'), ++out; } }
// copy_string(): create a copy of a string on the specified heap. A // pointer to the copy is returned. char *copy_string(NAMemory *heap, const char *src) { return copy_chars(heap, src, (src ? strlen(src) : 0), TRUE); }