void text_printf (TEXT *t, char *format, ...) { va_list v; char *s; va_start (v, format); vasprintf (&s, format, v); text_append (t, s); free (s); va_end (v); }
/* 2106 */ int abort_empty_line (ELEMENT **current_inout, char *additional_text) { ELEMENT *current = *current_inout; int retval; ELEMENT *last_child = last_contents_child (current); if (!additional_text) additional_text = ""; if (last_child && (last_child->type == ET_empty_line || last_child->type == ET_empty_line_after_command || last_child->type == ET_empty_spaces_before_argument || last_child->type == ET_empty_spaces_after_close_brace)) { debug ("ABORT EMPTY additional text |%s| " "current |%s|", additional_text, last_child->text.text); text_append (&last_child->text, additional_text); // FIXME: How and when is this condition exactly met? if (last_child->text.end == 0) //2121 { // 'extra' stuff destroy_element (pop_element_from_contents (current)); } else if (last_child->type == ET_empty_line) //2132 { if (begin_paragraph_p (current)) last_child->type = ET_empty_spaces_before_paragraph; else destroy_element (pop_element_from_contents (current)); } else if (last_child->type == ET_empty_line_after_command) { last_child->type = ET_empty_spaces_after_command; } retval = 1; } else retval = 0; *current_inout = current; return retval; }
Text* collision_ray_scene_invert_glsl_code(const Scene* scene) { const Scene* base_scene = (const Scene*)scene->data; return text_append( base_scene->ray_collision_fn_glsl_code(base_scene), text( "if (type == 1) {\n" " type = 2;\n" " normal *= -1;\n" "} else if (type == 2) {\n" " type = 1;\n" " normal *= -1;\n" "}\n" ) ); }
/* 835 */ ELEMENT * parse_texi_file (char *filename) { char *linep, *line = 0; ELEMENT *root = new_element (ET_text_root); ELEMENT *preamble = 0; input_push_file (filename); /* Check for preamble. */ do { ELEMENT *l; /* FIXME: _next_text isn't used in Perl. */ line = next_text (); if (!line) abort (); /* Empty file? */ linep = line; linep += strspn (linep, whitespace_chars); if (*linep && !looking_at (linep, "\\input")) { /* This line is not part of the preamble. Shove back into input stream. */ input_push_text (line); break; } if (!preamble) preamble = new_element (ET_preamble); l = new_element (ET_preamble_text); text_append (&l->text, line); add_to_element_contents (preamble, l); } while (1); if (preamble) add_to_element_contents (root, preamble); root = parse_texi (root); return root; } /* 916 */
/* * Handle the expat characterData event. */ static void characterData(IterParser *self, const XML_Char *text, int len) { /* If we've already had an error in a previous call, don't make things worse. */ if (PyErr_Occurred() != NULL) { XML_StopParser(self->parser, 0); return; } if (self->text_size == 0) { self->last_line = (unsigned long)XML_GetCurrentLineNumber( self->parser); self->last_col = (unsigned long)XML_GetCurrentColumnNumber( self->parser); } if (self->keep_text) { (void)text_append(self, text, (Py_ssize_t)len); } }
/* Add TEXT to the contents of CURRENT, maybe starting a new paragraph. */ ELEMENT * merge_text (ELEMENT *current, char *text) { int no_merge_with_following_text = 0; int leading_spaces = strspn (text, whitespace_chars); ELEMENT *last_child = last_contents_child (current); /* Is there a non-whitespace character in the line? */ if (text[leading_spaces]) { char *additional = 0; if (last_child && (last_child->type == ET_empty_line_after_command || last_child->type == ET_empty_line_after_command || last_child->type == ET_empty_spaces_before_argument || last_child->type == ET_empty_spaces_after_close_brace)) { no_merge_with_following_text = 1; } if (leading_spaces) { additional = malloc (leading_spaces + 1); if (!additional) abort (); memcpy (additional, text, leading_spaces); additional[leading_spaces] = '\0'; } if (abort_empty_line (¤t, additional)) text += leading_spaces; free (additional); current = begin_paragraph (current); } if (last_contents_child (current) /* There is a difference between the text being defined and empty, and not defined at all. The latter is true for 'brace_command_arg' elements. We need to make sure that we initialize all elements with text_append (&e->text, "") where we want merging with following text. */ && last_contents_child (current)->text.space > 0 && !strchr (last_contents_child (current)->text.text, '\n') && !no_merge_with_following_text) { /* Append text to contents */ ELEMENT *last_child = last_contents_child (current); text_append (&last_child->text, text); debug ("MERGED TEXT: %s|||", text); } else { ELEMENT *e = new_element (ET_NONE); text_append (&e->text, text); add_to_element_contents (current, e); debug ("NEW TEXT: %s|||", text); } return current; }
/* Called from 'big_loop' in parser.c. Return 1 if we find menu syntax to process, otherwise return 0. */ int handle_menu (ELEMENT **current_inout, char **line_inout) { ELEMENT *current = *current_inout; char *line = *line_inout; int retval = 1; // 4052 /* A "*" at the start of a line beginning a menu entry. */ if (*line == '*' && current->type == ET_preformatted && (current->parent->type == ET_menu_comment || current->parent->type == ET_menu_entry_description) && current->contents.number > 0 && last_contents_child(current)->type == ET_empty_line) { ELEMENT *star; debug ("MENU STAR"); abort_empty_line (¤t, 0); line++; /* Past the '*'. */ star = new_element (ET_menu_star); text_append (&star->text, "*"); add_to_element_contents (current, star); /* The ET_menu_star element won't appear in the final tree. */ } // 4067 /* A space after a "*" at the beginning of a line. */ else if (strchr (whitespace_chars, *line) && current->contents.number > 0 && last_contents_child(current)->type == ET_menu_star) { ELEMENT *menu_entry, *leading_text, *entry_name; int leading_spaces; debug ("MENU ENTRY (certainly)"); leading_spaces = strspn (line, whitespace_chars); destroy_element (pop_element_from_contents (current)); if (current->type == ET_preformatted && current->parent->type == ET_menu_comment) { ELEMENT *menu = current->parent->parent; /* Remove an empty ET_preformatted, and an empty ET_menu_comment. */ if (current->contents.number == 0) { pop_element_from_contents (current->parent); if (current->parent->contents.number == 0) { pop_element_from_contents (menu); destroy_element (current->parent); } destroy_element (current); } current = menu; } else { /* current should be ET_preformatted, 1st parent ET_menu_entry_description, 2nd parent ET_menu_entry, 3rd parent @menu. */ current = current->parent->parent->parent; } if (pop_context () != ct_preformatted) abort (); // bug menu_entry = new_element (ET_menu_entry); leading_text = new_element (ET_menu_entry_leading_text); entry_name = new_element (ET_menu_entry_name); add_to_element_contents (current, menu_entry); add_to_element_args (menu_entry, leading_text); add_to_element_args (menu_entry, entry_name); current = entry_name; text_append (&leading_text->text, "*"); text_append_n (&leading_text->text, line, leading_spaces); line += leading_spaces; } // 4116 /* A "*" followed by anything other than a space. */ else if (current->contents.number > 0 && last_contents_child(current)->type == ET_menu_star) { debug ("ABORT MENU STAR"); destroy_element (pop_element_from_contents (current)); } // 4122 /* After a separator in a menu. */ else if (current->args.number > 0 && last_args_child (current)->type == ET_menu_entry_separator) { ELEMENT *last_child; char *separator; last_child = last_args_child (current); separator = last_child->text.text; /* Separator is "::". */ if (!strcmp (separator, ":") && *line == ':') { text_append (&last_child->text, ":"); line++; /* Whitespace following the "::" is subsequently appended to the separator element. */ } /* A "." not followed by a space. Not a separator. */ else if (!strcmp (separator, ".") && !strchr (whitespace_chars, *line)) { pop_element_from_args (current); current = last_args_child (current); merge_text (current, last_child->text.text); destroy_element (last_child); } else if (strchr (whitespace_chars_except_newline, *line)) { int n; n = strspn (line, whitespace_chars_except_newline); text_append_n (&last_child->text, line, n); line += n; } else if (!strncmp (separator, "::", 2)) { ELEMENT *entry_name; debug ("MENU NODE no entry %s", separator); entry_name = args_child_by_index (current, -2); /* Change it from ET_menu_entry_name (i.e. the label). */ entry_name->type = ET_menu_entry_node; current = enter_menu_entry_node (current); } /* End of the label. Begin the element for the destination. */ else if (*separator == ':') { ELEMENT *entry_node; debug ("MENU ENTRY %s", separator); entry_node = new_element (ET_menu_entry_node); add_to_element_args (current, entry_node); current = entry_node; } else { debug ("MENU NODE"); current = enter_menu_entry_node (current); } } else retval = 0; *current_inout = current; *line_inout = line; return retval; }
static void append_character(Rune c){ text_append(line, &c, 1); }