static void assure_1_view(void) { if (!active_view) { new_sheet(); new_standard_view (0); // status_setup(); } }
int buffer_add_sheet(buffer *b, int n) { int i; char name[1000]; if (n < 0 || n > b->nsht) return b->nsht; b->nsht++; b->sht = (sheet *)MwRealloc(b->sht, b->nsht*sizeof(sheet)); for (i = b->nsht-1; i > n; i--) { b->sht[i] = b->sht[i-1]; } b->sht[n] = new_sheet(); MwFree(b->sht[n].name); for (i = b->nsht; i < 1000; i++) { sprintf(name, _("Sheet %d"), i); if (!sheet_name_taken(b, name)) break; } b->sht[n].name = MwStrdup(name); return b->nsht; }
static void load_register_sheet(const gchar *dirname, const gchar *filename) { xmlDocPtr doc; xmlNsPtr ns; xmlNodePtr node, contents,subnode,root; char *tmp; gchar *name = NULL, *description = NULL; int name_score = -1; int descr_score = -1; Sheet *sheet = NULL; GSList *sheetp; /* the XML fun begins here. */ doc = xmlParseFile(filename); if (!doc) return; root = doc->root; while (root && (root->type != XML_ELEMENT_NODE)) root=root->next; if (!root) return; if (!(ns = xmlSearchNsByHref(doc,root, "http://www.lysator.liu.se/~alla/dia/dia-sheet-ns"))) { g_warning("could not find sheet namespace"); xmlFreeDoc(doc); return; } if ((root->ns != ns) || (strcmp(root->name,"sheet"))) { g_warning("root element was %s -- expecting sheet", doc->root->name); xmlFreeDoc(doc); return; } for (node = root->childs; node != NULL; node = node->next) { if (node->type != XML_ELEMENT_NODE) continue; if (node->ns == ns && !strcmp(node->name, "name")) { gint score; /* compare the xml:lang property on this element to see if we get a * better language match. LibXML seems to throw away attribute * namespaces, so we use "lang" instead of "xml:lang" */ tmp = xmlGetProp(node, "xml:lang"); if (!tmp) tmp = xmlGetProp(node, "lang"); score = intl_score_locale(tmp); if (tmp) free(tmp); if (name_score < 0 || score < name_score) { name_score = score; if (name) free(name); name = xmlNodeGetContent(node); } } else if (node->ns == ns && !strcmp(node->name, "description")) { gint score; /* compare the xml:lang property on this element to see if we get a * better language match. LibXML seems to throw away attribute * namespaces, so we use "lang" instead of "xml:lang" */ tmp = xmlGetProp(node, "xml:lang"); if (!tmp) tmp = xmlGetProp(node, "lang"); score = intl_score_locale(tmp); g_free(tmp); if (descr_score < 0 || score < descr_score) { descr_score = score; if (description) free(description); description = xmlNodeGetContent(node); } } else if (node->ns == ns && !strcmp(node->name, "contents")) { contents = node; } } if (!contents) { g_warning("no contents in sheet %s.", filename); xmlFreeDoc(doc); if (name) free(name); if (description) free(description); return; } sheetp = get_sheets_list(); while (sheetp) { if (sheetp->data && !strcmp(((Sheet *)(sheetp->data))->name,name)) { sheet = sheetp->data; break; } sheetp = sheetp->next; } if (!sheet) sheet = new_sheet(name,description); for (node = contents->childs ; node != NULL; node = node->next) { ObjectType *obj_type; SheetObject *sheet_obj; gboolean isobject = FALSE,isshape = FALSE; gchar *iconname = NULL; int subdesc_score = -1; gchar *objdesc = NULL, *objicon = NULL; gint intdata = 0; gchar *chardata = NULL; if (node->type != XML_ELEMENT_NODE) continue; if (node->ns != ns) continue; if (!strcmp(node->name,"object")) { isobject = TRUE; } else if (!strcmp(node->name,"shape")) { isshape = TRUE; } if (isobject) { tmp = xmlGetProp(node,"intdata"); if (tmp) { char *p; intdata = (gint)strtol(tmp,&p,0); if (*p != 0) intdata = 0; free(tmp); } chardata = xmlGetProp(node,"chardata"); /* TODO.... */ if (chardata) free(chardata); } if (isobject || isshape) { for (subnode = node->childs; subnode != NULL ; subnode = subnode->next) { if (subnode->ns == ns && !strcmp(subnode->name, "description")) { gint score; /* compare the xml:lang property on this element to see if we get a * better language match. LibXML seems to throw away attribute * namespaces, so we use "lang" instead of "xml:lang" */ tmp = xmlGetProp(subnode, "xml:lang"); if (!tmp) tmp = xmlGetProp(subnode, "lang"); score = intl_score_locale(tmp); if (tmp) free(tmp); if (subdesc_score < 0 || score < subdesc_score) { subdesc_score = score; if (objdesc) free(objdesc); objdesc = xmlNodeGetContent(subnode); } } else if (subnode->ns == ns && !strcmp(subnode->name,"icon")) { tmp = xmlNodeGetContent(subnode); iconname = g_strconcat(dirname,G_DIR_SEPARATOR_S,tmp,NULL); if (tmp) free(tmp); } } tmp = xmlGetProp(node,"name"); sheet_obj = g_new(SheetObject,1); sheet_obj->object_type = g_strdup(tmp); sheet_obj->description = objdesc; sheet_obj->pixmap = NULL; sheet_obj->user_data = (void *)intdata; /* XXX modify user_data type ? */ sheet_obj->pixmap_file = iconname; if (isshape) { ShapeInfo *info = shape_info_getbyname(tmp); if (info) { if (!sheet_obj->description) sheet_obj->description = g_strdup(info->description); if (!sheet_obj->pixmap_file && !sheet_obj->pixmap) sheet_obj->pixmap_file = info->icon; sheet_obj->user_data = (void *)info; } else { /* Somehow, this shape is unknown */ g_free(sheet_obj->description); g_free(sheet_obj->pixmap_file); g_free(sheet_obj->object_type); g_free(sheet_obj); if (tmp) free(tmp); continue; } } else { if (shape_info_getbyname(tmp)) { g_warning("Object_type(%s) is really a shape, not an object..",tmp); /* maybe I should listen to what others say, after all, and dump this shape/object distinction ? */ } if (!object_get_type(tmp)) { g_free(sheet_obj->description); g_free(sheet_obj->pixmap_file); g_free(sheet_obj->object_type); g_free(sheet_obj); if (tmp) free(tmp); continue; } } if (tmp) free(tmp); /* we don't need to fix up the icon and descriptions for simple objects, since they don't have their own description, and their icon is already automatically handled. */ sheet_append_sheet_obj(sheet,sheet_obj); } } if (sheet) register_sheet(sheet); xmlFreeDoc(doc); }
Animation::Animation(const CC_show& show, NotifyStatus notifyStatus, NotifyErrorList notifyErrorList) : numpts(show.GetNumPoints()), pts(numpts), curr_cmds(numpts), curr_sheetnum(0), mCollisionAction(NULL) { // the variables are persistant through the entire compile process. AnimationVariables variablesStates; for (auto curr_sheet = show.GetSheetBegin(); curr_sheet != show.GetSheetEnd(); ++curr_sheet) { if (!curr_sheet->IsInAnimation()) continue; // Now parse continuity AnimateCompile comp(show, variablesStates); std::vector<std::vector<std::shared_ptr<AnimateCommand> > > theCommands(numpts); for (auto& current_symbol : k_symbols) { if (curr_sheet->ContinuityInUse(current_symbol)) { auto& current_continuity = curr_sheet->GetContinuityBySymbol(current_symbol); std::string tmpBuffer(current_continuity.GetText()); yyinputbuffer = tmpBuffer.c_str(); if (notifyStatus) { std::string message("Compiling \""); message += curr_sheet->GetName().substr(0,32); message += ("\" "); message += GetNameForSymbol(current_symbol).substr(0,32); message += ("..."); notifyStatus(message); } // parse out the error if (parsecontinuity() != 0) { // Supply a generic parse error ContToken dummy; comp.RegisterError(ANIMERR_SYNTAX, &dummy); } for (unsigned j = 0; j < numpts; j++) { if (curr_sheet->GetPoint(j).GetSymbol() == current_symbol) { theCommands[j] = comp.Compile(curr_sheet, j, current_symbol, ParsedContinuity); } } while (ParsedContinuity) { ContProcedure* curr_proc = ParsedContinuity->next; delete ParsedContinuity; ParsedContinuity = curr_proc; } } } // Handle points that don't have continuity (shouldn't happen) if (notifyStatus) { std::string message("Compiling \""); message += curr_sheet->GetName().substr(0,32); message += ("\"..."); notifyStatus(message); } for (unsigned j = 0; j < numpts; j++) { if (theCommands[j].empty()) { theCommands[j] = comp.Compile(curr_sheet, j, MAX_NUM_SYMBOLS, NULL); } } if (!comp.Okay() && notifyErrorList) { std::string message("Errors for \""); message += curr_sheet->GetName().substr(0,32); message += ("\""); if (notifyErrorList(comp.GetErrorMarkers(), std::distance(show.GetSheetBegin(), curr_sheet), message)) { break; } } std::vector<AnimatePoint> thePoints(numpts); for (unsigned i = 0; i < numpts; i++) { thePoints.at(i) = curr_sheet->GetPosition(i); } AnimateSheet new_sheet(thePoints, theCommands, curr_sheet->GetName(), curr_sheet->GetBeats()); sheets.push_back(new_sheet); } }