static void open_section (AnjutaPluginDescriptionParser *parser, const char *name) { int n; if (parser->n_allocated_sections == parser->df->n_sections) grow_sections (parser); if (parser->current_section == 0 && parser->df->sections[0].section_name == 0 && parser->df->sections[0].n_lines == 0) { if (!name) g_warning ("non-initial NULL section\n"); /* The initial section was empty. Piggyback on it. */ parser->df->sections[0].section_name = g_quark_from_string (name); return; } n = parser->df->n_sections++; if (name) parser->df->sections[n].section_name = g_quark_from_string (name); else parser->df->sections[n].section_name = 0; parser->df->sections[n].n_lines = 0; parser->df->sections[n].lines = NULL; parser->current_section = n; parser->n_allocated_lines = 0; grow_lines (parser); }
static AnjutaPluginDescriptionLine * new_line (AnjutaPluginDescriptionParser *parser) { AnjutaPluginDescriptionSection *section; AnjutaPluginDescriptionLine *line; section = &parser->df->sections[parser->current_section]; if (parser->n_allocated_lines == section->n_lines) grow_lines (parser); line = §ion->lines[section->n_lines++]; memset (line, 0, sizeof (AnjutaPluginDescriptionLine)); return line; }
static GnomeThemeFileLine * new_line (GnomeThemeFileParser *parser) { GnomeThemeFileSection *section; GnomeThemeFileLine *line; section = &parser->df->sections[parser->current_section]; if (parser->n_allocated_lines == section->n_lines) grow_lines (parser); line = §ion->lines[section->n_lines++]; memset (line, 0, sizeof (GnomeThemeFileLine)); return line; }
int MiniConsole::grow(int glines, int gbuffer) { /* * grow of a specified amount of lines or bytes the * current line and text buffers; i.e.: make room * to support glines more lines and gbuffer more characters. * * grow values can be negative. in this case, the current * buffers will be shrunk of the specified amounts. * * consistency will be preserved by deleting a certain amount * of lines: the older ones. * * a zero amount for a value imply the line or buffer arrays * to remain untouched. * */ /* FINISH ME AND TEST ME */ int gb,gl; gb=grow_buffer(gbuffer); gl=grow_lines (glines); return !( gb==0 && 0==gl );// 0 if both 0 }
int MiniConsole::reformat(int newlwidth) { /* * This method reformats the whole buffer array; that is, it recomputes * line information for it, thus updating the whole line array contents. * It may fail, in the case a new line width (smaller) is desired, because * more line information would be needed. * * If the new lines are longer than before, then it could not fail. * Upon a successful execution, the width is updated. * * */ int nls; if(newlwidth==lwidth)return 0;//are we sure? if(newlwidth< lwidth) { // realloc needed if ( ( nls=lines_count(buffer, newlwidth) + 1 ) < lsize ) if ( grow_lines( nls )!=0 )return -1; } if(newlwidth> lwidth || ( lines_count(buffer, newlwidth) + 1 < lsize ) ) { // no realloc, no risk fim::string buf=buffer; if(((int)buf.size())==((int)(bp-buffer))) { ccol=0;cline=0;lwidth=newlwidth;*line=buffer;bp=buffer; // the easy way add(buf.c_str());// by adding a very big chunk of text, we make sure it gets formatted. return 0; } // if some error happened in buf string initialization, we return -1 return -1; } return -1; }