char OSISReferenceLinks::processText(std::string &text, const SWKey *key, const SWModule *module) { (void) key; (void) module; if (option) return 0; std::string token; bool intoken = false; bool stripThisToken = false; std::string orig = text; const char *from = orig.c_str(); for (text = ""; *from; ++from) { if (*from == '<') { intoken = true; token = ""; continue; } else if (*from == '>') { // process tokens intoken = false; if (std::strncmp(token.c_str(), "reference", 9) && std::strncmp(token.c_str(), "/reference", 10)) { text.push_back('<'); text.append(token); text.push_back('>'); } else { XMLTag tag; tag = token.c_str(); if (!tag.isEndTag() && type == tag.getAttribute("type") && (!subType.size() || subType == tag.getAttribute("subType"))) { stripThisToken = true; continue; } else if (tag.isEndTag() && stripThisToken) { stripThisToken = false; continue; } text.push_back('<'); text.append(token); text.push_back('>'); } continue; } if (intoken) { //copy token token.push_back(*from); } else { //copy text which is not inside a token text.push_back(*from); } } return 0; }
char OSISFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; bool hide = false; SWBuf tagText; XMLTag startTag; SWBuf refs = ""; int footnoteNum = 1; char buf[254]; SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; parser = new VerseKey(); } *parser = key->getText(); SWBuf orig = text; const char *from = orig.c_str(); XMLTag tag; bool strongsMarkup = false; for (text = ""; *from; ++from) { // remove all newlines temporarily to fix kjv2003 module if ((*from == 10) || (*from == 13)) { if ((text.length()>1) && (text[text.length()-2] != ' ') && (*(from+1) != ' ')) text.append(' '); continue; } if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; if (!strncmp(token, "note", 4) || !strncmp(token.c_str(), "/note", 5)) { tag = token; if (!tag.isEndTag()) { if (tag.getAttribute("type") && (!strcmp("x-strongsMarkup", tag.getAttribute("type")) || !strcmp("strongsMarkup", tag.getAttribute("type"))) // deprecated ) { tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... /> strongsMarkup = true; } if (!tag.isEmpty()) { // if ((!tag.isEmpty()) || (SWBuf("strongsMarkup") == tag.getAttribute("type"))) { refs = ""; startTag = tag; hide = true; tagText = ""; continue; } } if (hide && tag.isEndTag()) { if (module->isProcessEntryAttributes() && !strongsMarkup) { //don`t parse strongsMarkup to EntryAttributes as Footnote sprintf(buf, "%i", footnoteNum++); StringList attributes = startTag.getAttributeNames(); for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) { module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str()); } module->getEntryAttributes()["Footnote"][buf]["body"] = tagText; startTag.setAttribute("swordFootnote", buf); if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) { if (!refs.length()) refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } } hide = false; if (option || (startTag.getAttribute("type") && !strcmp(startTag.getAttribute("type"), "crossReference"))) { // we want the tag in the text; crossReferences are handled by another filter text.append(startTag); // text.append(tagText); // we don't put the body back in because it is retrievable from EntryAttributes["Footnotes"][]["body"]. } else continue; } strongsMarkup = false; } // if not a heading token, keep token in text //if ((!strcmp(tag.getName(), "reference")) && (!tag.isEndTag())) { // SWBuf osisRef = tag.getAttribute("osisRef"); if (!strncmp(token, "reference", 9)) { if (refs.length()) { refs.append("; "); } const char* attr = strstr(token.c_str() + 9, "osisRef=\""); const char* end = attr ? strchr(attr+9, '"') : 0; if (attr && end) { refs.append(attr+9, end-(attr+9)); } } if (!hide) { text.append('<'); text.append(token); text.append('>'); } else { tagText.append('<'); tagText.append(token); tagText.append('>'); } continue; } if (intoken) { //copy token token.append(*from); } else if (!hide) { //copy text which is not inside a token text.append(*from); } else tagText.append(*from); } delete parser; return 0; }
char ThMLHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; bool isheader = false; bool hide = false; bool preverse = false; bool withinDiv = false; SWBuf header; int headerNum = 0; int pvHeaderNum = 0; char buf[254]; XMLTag startTag; SWBuf orig = text; const char *from = orig.c_str(); XMLTag tag; for (text = ""; *from; ++from) { if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; if (!strnicmp(token.c_str(), "div", 3) || !strnicmp(token.c_str(), "/div", 4)) { withinDiv = (!strnicmp(token.c_str(), "div", 3)); tag = token; if (hide && tag.isEndTag()) { if (module->isProcessEntryAttributes() && (option || (!preverse))) { if (preverse) { sprintf(buf, "%i", pvHeaderNum++); module->getEntryAttributes()["Heading"]["Preverse"][buf] = header; } else { sprintf(buf, "%i", headerNum++); module->getEntryAttributes()["Heading"]["Interverse"][buf] = header; if (option) { // we want the tag in the text text.append(header); } } StringList attributes = startTag.getAttributeNames(); for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) { module->getEntryAttributes()["Heading"][buf][it->c_str()] = startTag.getAttribute(it->c_str()); } } hide = false; if (!option || preverse) { // we don't want the tag in the text anymore preverse = false; continue; } preverse = false; } if (tag.getAttribute("class") && ((!stricmp(tag.getAttribute("class"), "sechead")) || (!stricmp(tag.getAttribute("class"), "title")))) { isheader = true; if (!tag.isEndTag()) { //start tag if (!tag.isEmpty()) { startTag = tag; /* how do we tell a ThML preverse title from one that should be in the text? probably if any text is before the title... just assuming all are preverse for now } if (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse")) { */ hide = true; preverse = true; header = ""; continue; } // move back up under startTag = tag } /* this is where non-preverse will go eventually if (!tag.isEndTag()) { //start tag hide = true; header = ""; if (option) { // we want the tag in the text text.append('<'); text.append(token); text.append('>'); } continue; } */ } else isheader = false; } if (withinDiv && isheader) { header.append('<'); header.append(token); header.append('>'); } else { // if not a heading token, keep token in text if (!hide) { text.append('<'); text.append(token); text.append('>'); } } continue; } if (intoken) { //copy token token.append(*from); } else if (!hide) { //copy text which is not inside a token text.append(*from); } else header.append(*from); } return 0; }
char ThMLFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; bool hide = false; SWBuf tagText; XMLTag startTag; SWBuf refs = ""; int footnoteNum = 1; char buf[254]; SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; parser = new VerseKey(); } *parser = key->getText(); SWBuf orig = text; const char *from = orig.c_str(); for (text = ""; *from; from++) { if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; XMLTag tag(token); if (!strcmp(tag.getName(), "note")) { if (!tag.isEndTag()) { if (!tag.isEmpty()) { refs = ""; startTag = tag; hide = true; tagText = ""; continue; } } if (hide && tag.isEndTag()) { if (module->isProcessEntryAttributes()) { SWBuf fc = module->getEntryAttributes()["Footnote"]["count"]["value"]; footnoteNum = (fc.length()) ? atoi(fc.c_str()) : 0; sprintf(buf, "%i", ++footnoteNum); module->getEntryAttributes()["Footnote"]["count"]["value"] = buf; StringList attributes = startTag.getAttributeNames(); for (StringList::iterator it = attributes.begin(); it != attributes.end(); it++) { module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str()); } module->getEntryAttributes()["Footnote"][buf]["body"] = tagText; startTag.setAttribute("swordFootnote", buf); if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) { if (!refs.length()) refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } } hide = false; if ((option) || ((startTag.getAttribute("type") && (!strcmp(startTag.getAttribute("type"), "crossReference"))))) { // we want the tag in the text; crossReferences are handled by another filter text += startTag; text.append(tagText); } else continue; } } // if not a note token, keep token in text if ((!strcmp(tag.getName(), "scripRef")) && (!tag.isEndTag())) { SWBuf osisRef = tag.getAttribute("passage"); if (refs.length()) refs += "; "; refs += osisRef; } if (!hide) { text += '<'; text.append(token); text += '>'; } else { tagText += '<'; tagText.append(token); tagText += '>'; } continue; } if (intoken) { //copy token token += *from; } else if (!hide) { //copy text which is not inside a token text += *from; } else tagText += *from; } delete parser; return 0; }
bool OSISHeadings::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { MyUserData *u = (MyUserData *)userData; XMLTag tag(token); SWBuf name = tag.getName(); // we only care about titles and divs or if we're already in a heading // // are we currently in a heading? if (u->currentHeadingName.size()) { u->heading.append(u->lastTextNode); if (name == u->currentHeadingName) { if (tag.isEndTag(u->sID)) { if (!u->depth-- || u->sID) { // see comment below about preverse div changed and needing to preserve the <title> container tag for old school pre-verse titles // we've just finished a heading. It's all stored up in u->heading bool canonical = (SWBuf("true") == u->currentHeadingTag.getAttribute("canonical")); bool preverse = (SWBuf("x-preverse") == u->currentHeadingTag.getAttribute("subType") || SWBuf("x-preverse") == u->currentHeadingTag.getAttribute("subtype")); // do we want to put anything in EntryAttributes? if (u->module->isProcessEntryAttributes() && (option || canonical || !preverse)) { SWBuf buf; buf.appendFormatted("%i", u->headerNum++); // leave the actual <title...> wrapper in if we're part of an old school preverse title // because now frontend have to deal with preverse as a div which may or may not include <title> elements // and they can't simply wrap all preverse material in <h1>, like they probably did previously SWBuf heading; if (u->currentHeadingName == "title") { XMLTag wrapper = u->currentHeadingTag; if (SWBuf("x-preverse") == wrapper.getAttribute("subType")) wrapper.setAttribute("subType", 0); else if (SWBuf("x-preverse") == wrapper.getAttribute("subtype")) wrapper.setAttribute("subtype", 0); heading = wrapper; heading += u->heading; heading += tag; } else heading = u->heading; u->module->getEntryAttributes()["Heading"][(preverse)?"Preverse":"Interverse"][buf] = heading; StringList attributes = u->currentHeadingTag.getAttributeNames(); for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) { u->module->getEntryAttributes()["Heading"][buf][it->c_str()] = u->currentHeadingTag.getAttribute(it->c_str()); } } // do we want the heading in the body? if (!preverse && (option || canonical)) { buf.append(u->currentHeadingTag); buf.append(u->heading); buf.append(tag); } u->suspendTextPassThru = false; u->clear(); } } else u->depth++; } u->heading.append(tag); return true; } // are we a title or a preverse div? else if ( name == "title" || (name == "div" && ( SWBuf("x-preverse") == tag.getAttribute("subType") || SWBuf("x-preverse") == tag.getAttribute("subtype")))) { u->currentHeadingName = name; u->currentHeadingTag = tag; u->heading = ""; u->sID = u->currentHeadingTag.getAttribute("sID"); u->depth = 0; u->suspendTextPassThru = true; return true; } return false; }
void x86_mce_callback_register(x86_mce_callback_t cbfunc) { mc_callback_bank_extended = cbfunc; } /* Machine check recoverable judgement callback handler * It is used to judge whether an UC error is recoverable by software */ static mce_recoverable_t mc_recoverable_scan = NULL; void mce_recoverable_register(mce_recoverable_t cbfunc) { mc_recoverable_scan = cbfunc; } /* Judging whether to Clear Machine Check error bank callback handler * According to Intel latest MCA OS Recovery Writer's Guide, * whether the error MCA bank needs to be cleared is decided by the mca_source * and MCi_status bit value. */ static mce_need_clearbank_t mc_need_clearbank_scan = NULL; void mce_need_clearbank_register(mce_need_clearbank_t cbfunc) { mc_need_clearbank_scan = cbfunc; } /* Utility function to perform MCA bank telemetry readout and to push that * telemetry towards an interested dom0 for logging and diagnosis. * The caller - #MC handler or MCA poll function - must arrange that we * do not migrate cpus. */ /* XXFM Could add overflow counting? */ /* Add out_param clear_bank for Machine Check Handler Caller. * For Intel latest CPU, whether to clear the error bank status needs to * be judged by the callback function defined above. */ mctelem_cookie_t mcheck_mca_logout(enum mca_source who, cpu_banks_t bankmask, struct mca_summary *sp, cpu_banks_t* clear_bank) { struct vcpu *v = current; struct domain *d; uint64_t gstatus, status, addr, misc; struct mcinfo_global mcg; /* on stack */ struct mcinfo_common *mic; struct mcinfo_global *mig; /* on stack */ mctelem_cookie_t mctc = NULL; uint32_t uc = 0, pcc = 0, recover, need_clear = 1 ; struct mc_info *mci = NULL; mctelem_class_t which = MC_URGENT; /* XXXgcc */ unsigned int cpu_nr; int errcnt = 0; int i; enum mca_extinfo cbret = MCA_EXTINFO_IGNORED; cpu_nr = smp_processor_id(); BUG_ON(cpu_nr != v->processor); mca_rdmsrl(MSR_IA32_MCG_STATUS, gstatus); memset(&mcg, 0, sizeof (mcg)); mcg.common.type = MC_TYPE_GLOBAL; mcg.common.size = sizeof (mcg); if (v != NULL && ((d = v->domain) != NULL)) { mcg.mc_domid = d->domain_id; mcg.mc_vcpuid = v->vcpu_id; } else { mcg.mc_domid = -1; mcg.mc_vcpuid = -1; } mcg.mc_gstatus = gstatus; /* MCG_STATUS */ switch (who) { case MCA_MCE_HANDLER: case MCA_MCE_SCAN: mcg.mc_flags = MC_FLAG_MCE; which = MC_URGENT; break; case MCA_POLLER: case MCA_RESET: mcg.mc_flags = MC_FLAG_POLLED; which = MC_NONURGENT; break; case MCA_CMCI_HANDLER: mcg.mc_flags = MC_FLAG_CMCI; which = MC_NONURGENT; break; default: BUG(); } /* Retrieve detector information */ x86_mc_get_cpu_info(cpu_nr, &mcg.mc_socketid, &mcg.mc_coreid, &mcg.mc_core_threadid, &mcg.mc_apicid, NULL, NULL, NULL); /* If no mc_recovery_scan callback handler registered, * this error is not recoverable */ recover = (mc_recoverable_scan)? 1: 0; for (i = 0; i < 32 && i < nr_mce_banks; i++) { struct mcinfo_bank mcb; /* on stack */ /* Skip bank if corresponding bit in bankmask is clear */ if (!test_bit(i, bankmask)) continue; mca_rdmsrl(MSR_IA32_MC0_STATUS + i * 4, status); if (!(status & MCi_STATUS_VAL)) continue; /* this bank has no valid telemetry */ /* For Intel Latest CPU CMCI/MCE Handler caller, we need to * decide whether to clear bank by MCi_STATUS bit value such as * OVER/UC/EN/PCC/S/AR */ if ( mc_need_clearbank_scan ) need_clear = mc_need_clearbank_scan(who, status); /* If this is the first bank with valid MCA DATA, then * try to reserve an entry from the urgent/nonurgent queue * depending on whethere we are called from an exception or * a poller; this can fail (for example dom0 may not * yet have consumed past telemetry). */ if (errcnt == 0) { if ((mctc = mctelem_reserve(which)) != NULL) { mci = mctelem_dataptr(mctc); mcinfo_clear(mci); } } memset(&mcb, 0, sizeof (mcb)); mcb.common.type = MC_TYPE_BANK; mcb.common.size = sizeof (mcb); mcb.mc_bank = i; mcb.mc_status = status; /* form a mask of which banks have logged uncorrected errors */ if ((status & MCi_STATUS_UC) != 0) uc |= (1 << i); /* likewise for those with processor context corrupt */ if ((status & MCi_STATUS_PCC) != 0) pcc |= (1 << i); if (recover && uc) /* uc = 1, recover = 1, we need not panic. */ recover = mc_recoverable_scan(status); addr = misc = 0; if (status & MCi_STATUS_ADDRV) { mca_rdmsrl(MSR_IA32_MC0_ADDR + 4 * i, addr); d = maddr_get_owner(addr); if (d != NULL && (who == MCA_POLLER || who == MCA_CMCI_HANDLER)) mcb.mc_domid = d->domain_id; } if (status & MCi_STATUS_MISCV) mca_rdmsrl(MSR_IA32_MC0_MISC + 4 * i, misc); mcb.mc_addr = addr; mcb.mc_misc = misc; if (who == MCA_CMCI_HANDLER) { mca_rdmsrl(MSR_IA32_MC0_CTL2 + i, mcb.mc_ctrl2); rdtscll(mcb.mc_tsc); } /* Increment the error count; if this is the first bank * with a valid error then add the global info to the mcinfo. */ if (errcnt++ == 0 && mci != NULL) x86_mcinfo_add(mci, &mcg); /* Add the bank data */ if (mci != NULL) x86_mcinfo_add(mci, &mcb); if (mc_callback_bank_extended && cbret != MCA_EXTINFO_GLOBAL) { cbret = mc_callback_bank_extended(mci, i, status);
char OSISMorphSegmentation::processText(SWBuf &text, const SWKey * /*key*/, const SWModule *module) { SWBuf token; bool intoken = false; bool hide = false; SWBuf orig( text ); const char *from = orig.c_str(); XMLTag tag; SWBuf tagText = ""; unsigned int morphemeNum = 0; bool inMorpheme = false; SWBuf buf; for (text = ""; *from; ++from) { if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; if (!strncmp(token.c_str(), "seg ", 4) || !strncmp(token.c_str(), "/seg", 4)) { tag = token; if (!tag.isEndTag() && tag.getAttribute("type") && !strcmp("morph", tag.getAttribute("type"))) { //<seg type="morph"> start tag hide = !option; //only hide if option is Off tagText = ""; inMorpheme = true; } if (tag.isEndTag()) { buf.setFormatted("%.3d", morphemeNum++); module->getEntryAttributes()["Morpheme"][buf]["body"] = tagText; inMorpheme = false; } if (hide) { //hides start and end tags as long as hide is set if (tag.isEndTag()) { //</seg> hide = false; } continue; //leave out the current token } } //end of seg tag handling text.append('<'); text.append(token); text.append('>'); if (inMorpheme) { tagText.append('<'); tagText.append(token); tagText.append('>'); } hide = false; continue; } //end of intoken part if (intoken) { //copy token token.append(*from); } else { //copy text which is not inside of a tag text.append(*from); if (inMorpheme) { tagText.append(*from); } } } return 0; }