/* * process embedded links and images */ static int linkylinky(int image, MMIOT *f) { int start = mmiottell(f); Footnote link; linkytype *tag; if ( !linkykey(image, &link, f) ) { mmiotseek(f, start); return 0; } if ( image ) tag = &imaget; else if ( (f->flags & NO_PSEUDO_PROTO) || (tag = extratag(link.link)) == 0 ) tag = &linkt; if ( f->flags & tag-> flags ) { mmiotseek(f, start); return 0; } if ( tag->link_pfx ) { Qstring(tag->link_pfx, f); if ( f->base && (T(link.link)[tag->szpat] == '/') ) puturl(f->base, strlen(f->base), f); puturl(T(link.link) + tag->szpat, S(link.link) - tag->szpat, f); Qstring(tag->link_sfx, f); if ( tag->WxH && link.height && link.width ) { Qprintf(f," height=\"%d\"", link.height); Qprintf(f, " width=\"%d\"", link.width); } if ( S(link.title) ) { Qstring(" title=\"", f); reparse(T(link.title), S(link.title), INSIDE_TAG, f); Qchar('"', f); } Qstring(tag->text_pfx, f); reparse(T(link.tag), S(link.tag), tag->flags, f); Qstring(tag->text_sfx, f); } else Qwrite(T(link.link) + tag->szpat, S(link.link) - tag->szpat, f); return 1; }
KstViewLabel::KstViewLabel(const QDomElement& e) : KstBorderedViewObject(e) { // some defaults and invariants _fallThroughTransparency = false; _container = false; _type = "Label"; _editTitle = i18n("Edit Label"); _dataPrecision = 8; _interpret = true; _replace = true; _rotation = 0.0; _labelMargin = 0; _justify = 0L; _fontName = KstApp::inst()->defaultFont(); _fontSize = -1; setFontSize(0); _standardActions |= Delete | Edit | Rename; _parsed = 0L; _isResizable = false; reparse(); // read the properties QDomNode n = e.firstChild(); while (!n.isNull()) { QDomElement el = n.toElement(); if (!el.isNull()) { if (metaObject()->findProperty(el.tagName().latin1(), true) > -1) { setProperty(el.tagName().latin1(), QVariant(el.text())); } } n = n.nextSibling(); } }
fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */ /* anchor = 1 for anchored matches, else 0 */ { Node *p, *p1; fa *f; p = reparse(s); p1 = op2(CAT, op2(STAR, op2(ALL, NIL, NIL), NIL), p); /* put ALL STAR in front of reg. exp. */ p1 = op2(CAT, p1, op2(FINAL, NIL, NIL)); /* put FINAL after reg. exp. */ poscnt = 0; penter(p1); /* enter parent pointers and leaf indices */ if ((f = (fa *) calloc(1, sizeof(fa) + poscnt*sizeof(rrow))) == NULL) overflo("out of space for fa"); f->accept = poscnt-1; /* penter has computed number of positions in re */ cfoll(f, p1); /* set up follow sets */ freetr(p1); if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL) overflo("out of space in makedfa"); if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL) overflo("out of space in makedfa"); *f->posns[1] = 0; f->initstat = makeinit(f, anchor); f->anchor = anchor; f->restr = (uschar *) tostring(s); return f; }
bool KstViewLabel::readConfigWidget(QWidget *w) { ViewLabelWidget *widget = dynamic_cast<ViewLabelWidget*>(w); if (!widget) { return false; } _txt = widget->_text->text(); // No, this is broken. It kills latex. #if 0 // Replace tabs and newlines in text edit box with \n and \t _txt.replace(QString("\n"), "\\n"); _txt.replace(QString("\t"), "\\t"); #endif setDataPrecision(widget->_precision->value()); setRotation(widget->_rotation->value()); setFontSize(widget->_fontSize->value()); setHorizJustifyWrap(widget->_horizontal->currentItem()); setForegroundColor(widget->_fontColor->color()); setFontName(widget->_font->currentFont().toString()); setTransparent(widget->_transparent->isChecked()); setBorderWidth(widget->_border->value()); setBorderColor(widget->_boxColors->color()); setBackgroundColor(widget->_boxColors->color()); setLabelMargin(widget->_margin->value()); reparse(); // calls setDirty() return true; }
void KstPlotLabel::setInterpreted(bool interpreted) { if (_interpret != interpreted) { _interpret = interpreted; reparse(); //setDirty(true); } }
void EventMonitorEntry::internalUpdate() { writeLockInputsAndOutputs(); if (!_pExpression) { reparse(); } VectorPtr xv = *_xVector; VectorPtr yv = *_yVector; int ns = 1; for (VectorMap::ConstIterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) { ns = qMax(ns, i.value()->length()); } double *rawValuesX = 0L; double *rawValuesY = 0L; if (xv && yv) { if (xv->resize(ns)) { rawValuesX = xv->value(); } if (yv->resize(ns)) { rawValuesY = yv->value(); } } Equations::Context ctx; ctx.sampleCount = ns; ctx.x = 0.0; if (needToEvaluate()) { if (_pExpression) { for (ctx.i = _numDone; ctx.i < ns; ++ctx.i) { const double value = _pExpression->value(&ctx); if (value != 0.0) { // The expression evaluates to true log(ctx.i); if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 1.0; } } else { if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 0.0; } } } _numDone = ns; logImmediately(); } } else { _numDone = ns; } unlockInputsAndOutputs(); return; }
bool KstViewLabel::readConfigWidget(QWidget *w, bool editMultipleMode) { ViewLabelWidget *widget = dynamic_cast<ViewLabelWidget*>(w); if (!widget) { return false; } if (!editMultipleMode || widget->_text->text().compare(QString(" ")) != 0) { _txt = widget->_text->text(); } if (!editMultipleMode || widget->_precision->value() != widget->_precision->minValue()) { setDataPrecision(widget->_precision->value()); } if (!editMultipleMode || widget->_rotation->value() != widget->_rotation->minValue()) { setRotation(widget->_rotation->value()); } if (!editMultipleMode || widget->_fontSize->value() != widget->_fontSize->minValue()) { setFontSize(widget->_fontSize->value()); } if (!editMultipleMode || widget->_horizontal->currentText().compare(QString(" ")) != 0) { setHorizJustifyWrap(widget->_horizontal->currentItem()); } if (!editMultipleMode || widget->_fontColor->color() != QColor()) { setForegroundColor(widget->_fontColor->color()); } if (!editMultipleMode || widget->_font->currentText().compare(QString(" ")) != 0) { setFontName(widget->_font->currentFont()); } if (!editMultipleMode || widget->_transparent->state() != QButton::NoChange) { setTransparent(widget->_transparent->isChecked()); } if (!editMultipleMode || widget->_border->value() != widget->_border->minValue()) { setBorderWidth(widget->_border->value()); } if (!editMultipleMode || widget->_changedFgColor) { setBorderColor(widget->_boxColors->foreground()); } if (!editMultipleMode || widget->_changedBgColor) { setBackgroundColor(widget->_boxColors->background()); } if (!editMultipleMode || widget->_margin->value() != widget->_margin->minValue()) { setLabelMargin(widget->_margin->value()); } reparse(); // calls setDirty() return true; }
static void PressedTemplate (EditorWidget w, XtPointer client_data, XtPointer call_data) { PressedData data = (PressedData) call_data; FinishEditorActions (); replace_focus_by_template (current_focus -> node -> nodenr, data -> y); reparse (); UpdateEditorWidgets (); };
void KstViewLabel::setText(const QString& text) { if (_txt != text) { _txt = text; _scalarsUsed.clear(); _stringsUsed.clear(); _vectorsUsed.clear(); reparse(); // calls setDirty() } }
void KstPlotLabel::setText(const QString& text) { if (_txt != text) { _txt = text; _scalarsUsed.clear(); _stringsUsed.clear(); _vectorsUsed.clear(); reparse(); computeTextSize(); //setDirty(true); } }
void KstViewLabel::readBinary(QDataStream& str) { KstBorderedViewObject::readBinary(str); bool b; str >> _rotation >> _txt >> _fontName >> b; _replace = b; str >> b; _interpret = b; str >> b; _justify = b; reparse(); // FIXME: this should go away and updateFromAspect should be // overridden. this hack fails when dragging a label // from a smaller parent to a larger one }
void KstPlotLabel::save(QTextStream &ts, const QString& indent, bool save_pos) { reparse(); QString l2 = indent + " "; ts << indent << "<text>" << QStyleSheet::escape(_txt) << "</text>" << endl; if (_interpret) { ts << indent << "<interpret/>" << endl; } ts << indent << "<rotation>" << _rotation << "</rotation>" << endl; if (save_pos) { ts << indent << "<justify>" << _justify << "</justify>" << endl; } ts << indent << "<fontfamily>" << QStyleSheet::escape(_fontName) << "</fontfamily>" << endl; ts << indent << "<size>" << _fontSize << "</size>" << endl; }
void KstPlotLabel::commonConstructor(const QString& txt, const QString& font, int fontSize, KstLJustifyType justify, float rotation) { _txt = txt; _interpret = true; _replace = true; _rotation = rotation; _sinr = fabs(sin(_rotation * M_PI / 180.0)); _cosr = fabs(cos(_rotation * M_PI / 180.0)); _justify = justify; _fontName = font; _fontSize = fontSize; _absFontSize = fontSize;// + KstSettings::globalSettings()->plotFontSize; _parsed = 0L; reparse(); computeTextSize(); }
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL) { connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse())); connect(this, SIGNAL(textChanged()), this, SLOT(reparse())); QColor textColor = palette().color(QPalette::Text); qreal h, s, l, a; textColor.getHslF(&h, &s, &l, &a); // I use dark themes if (l <= 0.3) { // very dark text. get a brigth background addColor(QColor(Qt::red).lighter(120)); addColor(QColor(Qt::green).lighter(120)); addColor(QColor(Qt::blue).lighter(120)); } else if (l <= 0.6) { // moderated dark text. get a somewhat brigth background addColor(QColor(Qt::red).lighter(60)); addColor(QColor(Qt::green).lighter(60)); addColor(QColor(Qt::blue).lighter(60)); } else { addColor(QColor(Qt::red).darker(120)); addColor(QColor(Qt::green).darker(120)); addColor(QColor(Qt::blue).darker(120)); } // light text. get a dark background. setFocusPolicy(Qt::StrongFocus); }
/* Smarty-pants-style chrome for quotes, -, ellipses, and (r)(c)(tm) */ static int smartypants(int c, int *flags, MMIOT *f) { int i; if ( f->flags & DENY_SMARTY ) return 0; for ( i=0; i < NRSMART; i++) if ( (c == smarties[i].c0) && islike(f, smarties[i].pat) ) { if ( smarties[i].entity ) Qprintf(f, "&%s;", smarties[i].entity); shift(f, smarties[i].shift); return 1; } switch (c) { case '<' : return 0; case '\'': if ( smartyquote(flags, 's', f) ) return 1; break; case '"': if ( smartyquote(flags, 'd', f) ) return 1; break; case '`': if ( peek(f, 1) == '`' ) { int j = 2; while ( (c=peek(f,j)) != EOF ) { if ( c == '\\' ) j += 2; else if ( c == '`' ) break; else if ( c == '\'' && peek(f, j+1) == '\'' ) { Qstring("“", f); reparse(cursor(f)+1, j-2, 0, f); Qstring("”", f); shift(f,j+1); return 1; } else ++j; } } break; } return 0; } /* smartypants */
/* public interface for reparse() */ int mkd_text(char *bfr, int size, FILE *output, int flags) { MMIOT f; ___mkd_initmmiot(&f, 0); f.flags = flags & USER_FLAGS; reparse(bfr, size, 0, &f); emblock(&f); if ( flags & CDATA_OUTPUT ) ___mkd_xml(T(f.out), S(f.out), output); else fwrite(T(f.out), S(f.out), 1, output); ___mkd_freemmiot(&f, 0); return 0; }
TranslationUnitUpdateResult TranslationUnitUpdater::update(UpdateMode mode) { createIndexIfNeeded(); switch (mode) { case UpdateMode::AsNeeded: recreateAndParseIfNeeded(); reparseIfNeeded(); break; case UpdateMode::ParseIfNeeded: recreateAndParseIfNeeded(); break; case UpdateMode::ForceReparse: reparse(); break; } return m_out; }
void KstViewLabel::setupConnections() { for (KstScalarMap::iterator i = _scalarsUsed.begin(); i != _scalarsUsed.end(); ++i) { disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse())); connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse())); } for (KstStringMap::iterator i = _stringsUsed.begin(); i != _stringsUsed.end(); ++i) { disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse())); connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse())); } for (KstVectorMap::iterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) { disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse())); connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse())); } }
KstViewLabel::KstViewLabel(const QString& txt, KstLJustifyType justify, float rotation) : KstBorderedViewObject("Label") { _fallThroughTransparency = false; _container = false; _dataPrecision = 8; _txt = txt; _interpret = true; _replace = true; _rotation = rotation; _justify = justify; _fontName = KstApp::inst()->defaultFont(); _fontSize = -1; setFontSize(0); _standardActions |= Delete | Edit | Rename; _parsed = 0L; _labelMargin = 0; _isResizable = false; reparse(); computeTextSize(_parsed); }
KstViewLabel::KstViewLabel(const KstViewLabel& label) : KstBorderedViewObject(label) { _dataPrecision = label._dataPrecision; _interpret = label._interpret; _replace = label._replace; _rotation = label._rotation; _labelMargin = label._labelMargin; _justify = label._justify; _fontName = label._fontName; _fontSize = label._fontSize; _absFontSize = label._absFontSize; _txt = label._txt; _standardActions |= Delete | Edit | Rename; _parsed = 0L; reparse(); // these always have these values _type = "Label"; }
static void definitionlist(Paragraph *p, MMIOT *f) { Line *tag; if ( p ) { Qstring("<dl>\n", f); for ( ; p ; p = p->next) { for ( tag = p->text; tag; tag = tag->next ) { Qstring("<dt>", f); reparse(T(tag->text), S(tag->text), 0, f); Qstring("</dt>\n", f); } htmlify(p->down, "dd", f); } Qstring("</dl>", f); } }
static int test_TERM_CharSym(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[0]->tok.c, 'a'); free_tree(tree); return 0; } static int test_TERM_Minus(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "-"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->tok.sym, Minus); TA_CHAR_EQ(tree->children[0]->tok.c, '-'); free_tree(tree); return 0; } static int test_TERM_Caret(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "^"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->tok.sym, Caret); TA_CHAR_EQ(tree->children[0]->tok.c, '^'); free_tree(tree); return 0; } static int test_TERM_Dot(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "."; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->tok.sym, Dot); TA_CHAR_EQ(tree->children[0]->tok.c, '.'); free_tree(tree); return 0; } static int test_TERM_Special(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "\\w"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->tok.sym, Special); TA_CHAR_EQ(tree->children[0]->tok.c, 'w'); free_tree(tree); return 0; } static int test_TERM_Subexpr(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "(a+)"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[1]->nt, REGEXnt); free_tree(tree); return 0; } static int test_TERM_Class(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "[abc]"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->production, 3); TA_INT_EQ(tree->children[1]->nt, CLASSnt); free_tree(tree); return 0; } static int test_TERM_NClass(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "[^abc]"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = TERM(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, TERMnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->production, 4); TA_INT_EQ(tree->children[1]->nt, CLASSnt); free_tree(tree); return 0; } static int test_EXPR_Term(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); free_tree(tree); return 0; } static int test_EXPR_Plus(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a+"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 2); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TEST_ASSERT(tree->children[1]->tok.sym == Plus); free_tree(tree); return 0; } static int test_EXPR_PlusQuestion(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a+?"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TEST_ASSERT(tree->children[1]->tok.sym == Plus); TEST_ASSERT(tree->children[2]->tok.sym == Question); free_tree(tree); return 0; } static int test_EXPR_Star(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a*"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 2); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TEST_ASSERT(tree->children[1]->tok.sym == Star); free_tree(tree); return 0; } static int test_EXPR_StarQuestion(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a*?"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TEST_ASSERT(tree->children[1]->tok.sym == Star); TEST_ASSERT(tree->children[2]->tok.sym == Question); free_tree(tree); return 0; } static int test_EXPR_Question(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a?"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 2); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TEST_ASSERT(tree->children[1]->tok.sym == Question); free_tree(tree); return 0; } static int test_EXPR_QuestionQuestion(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a??"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = EXPR(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, EXPRnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TEST_ASSERT(tree->children[1]->tok.sym == Question); TEST_ASSERT(tree->children[2]->tok.sym == Question); free_tree(tree); return 0; } static int test_SUB_Normal(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = SUB(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, SUBnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->nt, EXPRnt); TA_INT_EQ(tree->children[0]->nchildren, 1); free_tree(tree); return 0; } static int test_SUB_Concat(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "ab"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = SUB(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, SUBnt); TA_INT_EQ(tree->nchildren, 2); TA_INT_EQ(tree->children[0]->nt, EXPRnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TA_INT_EQ(tree->children[1]->nt, SUBnt); TA_INT_EQ(tree->children[1]->nchildren, 1); TA_INT_EQ(tree->children[1]->children[0]->nt, EXPRnt); free_tree(tree); return 0; } static int test_REGEX_Normal(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = REGEX(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, REGEXnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->nt, SUBnt); TA_INT_EQ(tree->children[0]->nchildren, 1); free_tree(tree); return 0; } static int test_REGEX_Alternate(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a|b"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = REGEX(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, REGEXnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[0]->nt, SUBnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TA_INT_EQ(tree->children[1]->tok.sym, Pipe); TA_INT_EQ(tree->children[2]->nt, REGEXnt); TA_INT_EQ(tree->children[2]->nchildren, 1); TA_INT_EQ(tree->children[2]->children[0]->nt, SUBnt); free_tree(tree); return 0; } static int test_CLASS_range(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a-b"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = CLASS(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, CLASSnt); TA_INT_EQ(tree->nchildren, 2); TA_INT_EQ(tree->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[0]->tok.c, 'a'); TA_INT_EQ(tree->children[1]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[1]->tok.c, 'b'); free_tree(tree); return 0; } static int test_CLASS_range_range(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a-b1-2"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = CLASS(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, CLASSnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[0]->tok.c, 'a'); TA_INT_EQ(tree->children[1]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[1]->tok.c, 'b'); TA_INT_EQ(tree->children[2]->nt, CLASSnt); TA_INT_EQ(tree->children[2]->nchildren, 2); TA_INT_EQ(tree->children[2]->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[2]->children[0]->tok.c, '1'); TA_INT_EQ(tree->children[2]->children[1]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[2]->children[1]->tok.c, '2'); free_tree(tree); return 0; } static int test_CLASS_single(void) { char *accept[] = {".", "+", "*", "?", "(", ")", "|"}; for (size_t i = 0; i < nelem(accept); i++) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = accept[i]; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = CLASS(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, CLASSnt); TA_INT_EQ(tree->nchildren, 1); TA_INT_EQ(tree->children[0]->tok.sym, CharSym); TA_INT_EQ(tree->children[0]->tok.c, accept[i][0]); free_tree(tree); } return 0; } static int test_CLASS_single_hyphen(void) { Lexer l; l.tok = (Token){.sym=0, .c=0}; l.input.str = "a-"; l.input.wstr = NULL; l.index = 0; l.nbuf = 0; nextsym(&l); PTree *tree = CLASS(&l); expect(Eof, &l); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, CLASSnt); TA_INT_EQ(tree->nchildren, 2); TA_INT_EQ(tree->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[0]->tok.c, 'a'); TA_INT_EQ(tree->children[1]->nt, CLASSnt); TA_INT_EQ(tree->children[1]->nchildren, 1); TA_INT_EQ(tree->children[1]->children[0]->tok.sym, Minus); free_tree(tree); return 0; } static int test_reparse(void) { PTree *tree = reparse("a+|b*"); TA_PTR_NE(tree, NULL); TA_INT_EQ(tree->nt, REGEXnt); TA_INT_EQ(tree->nchildren, 3); TA_INT_EQ(tree->children[0]->nt, SUBnt); TA_INT_EQ(tree->children[0]->nchildren, 1); TA_INT_EQ(tree->children[0]->children[0]->nt, EXPRnt); TA_INT_EQ(tree->children[0]->children[0]->nchildren, 2); TA_INT_EQ(tree->children[0]->children[0]->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[0]->children[0]->children[0]->nchildren, 1); TA_INT_EQ(tree->children[0]->children[0]->children[0]->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[0]->children[0]->children[0]->children[0]->tok.c, 'a'); TA_INT_EQ(tree->children[0]->children[0]->children[1]->tok.sym, Plus); TA_INT_EQ(tree->children[1]->tok.sym, Pipe); TA_INT_EQ(tree->children[2]->nt, REGEXnt); TA_INT_EQ(tree->children[2]->nchildren, 1); TA_INT_EQ(tree->children[2]->children[0]->nt, SUBnt); TA_INT_EQ(tree->children[2]->children[0]->nchildren, 1); TA_INT_EQ(tree->children[2]->children[0]->children[0]->nt, EXPRnt); TA_INT_EQ(tree->children[2]->children[0]->children[0]->nchildren, 2); TA_INT_EQ(tree->children[2]->children[0]->children[0]->children[0]->nt, TERMnt); TA_INT_EQ(tree->children[2]->children[0]->children[0]->children[0]->nchildren, 1); TA_INT_EQ(tree->children[2]->children[0]->children[0]->children[0]->children[0]->tok.sym, CharSym); TA_CHAR_EQ(tree->children[2]->children[0]->children[0]->children[0]->children[0]->tok.c, 'b'); TA_INT_EQ(tree->children[2]->children[0]->children[0]->children[1]->tok.sym, Star); free_tree(tree); return 0; }
KstObject::UpdateType EventMonitorEntry::update(int updateCounter) { Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); bool force = dirty(); setDirty(false); if (KstObject::checkUpdateCounter(updateCounter) && !force) { return lastUpdateResult(); } writeLockInputsAndOutputs(); if (!_pExpression) { reparse(); } KstVectorPtr xv = *_xVector; KstVectorPtr yv = *_yVector; int ns = 1; for (KstVectorMap::ConstIterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) { ns = qMax(ns, i.value()->length()); } double *rawValuesX = 0L; double *rawValuesY = 0L; if (xv && yv) { if (xv->resize(ns)) { rawValuesX = xv->value(); } if (yv->resize(ns)) { rawValuesY = yv->value(); } } Equation::Context ctx; ctx.sampleCount = ns; ctx.x = 0.0; if (needToEvaluate()) { if (_pExpression) { for (ctx.i = _numDone; ctx.i < ns; ++ctx.i) { const double value = _pExpression->value(&ctx); if (value != 0.0) { // The expression evaluates to true log(ctx.i); if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 1.0; } } else { if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 0.0; } } } _numDone = ns; logImmediately(); } } else { _numDone = ns; } if (xv) { xv->setDirty(); xv->update(updateCounter); } if (yv) { yv->setDirty(); yv->update(updateCounter); } unlockInputsAndOutputs(); return setLastUpdateResult(NO_CHANGE); }
void KstViewLabel::setText(const QString& text) { if (_txt != text) { _txt = text; reparse(); // calls setDirty() } }
void KstViewLabel::resize(const QSize& size) { KstBorderedViewObject::resize(size); if (!_parsed) { reparse(); } }
void KstViewLabel::setInterpreted(bool interpreted) { if (_interpret != interpreted) { _interpret = interpreted; reparse(); // calls setDirty(); } }
void KstViewLabel::save(QTextStream &ts, const QString& indent) { reparse(); ts << indent << "<" << type() << ">" << endl; KstBorderedViewObject::save(ts, indent + " "); ts << indent << "</" << type() << ">" << endl; }
static void Escape () { FinishEditorActions (); reparse (); UpdateEditorWidgets (); };
QSize KstViewLabel::sizeForText(const QRect& w) { double x_s, y_s; x_s = y_s = _fontSize + (double)KstSettings::globalSettings()->plotFontSize; int x_pix = w.width(); int y_pix = w.height(); if (x_pix < y_pix) { x_s *= x_pix/540.0; y_s *= y_pix/748.0; } else { y_s *= y_pix/540.0; x_s *= x_pix/748.0; } _absFontSize = int((x_s + y_s)/2.0); if (_absFontSize < KstSettings::globalSettings()->plotFontMinSize) { _absFontSize = KstSettings::globalSettings()->plotFontMinSize; } if (!_parsed) { reparse(); } if (_parsed) { computeTextSize(_parsed); } QSize sz(kMax(1, _textWidth), kMax(1, _textHeight)); if (int(_rotation) != 0 && int(_rotation) != 180) { QPointArray pts(4); pts[0] = QPoint(0, 0); pts[1] = QPoint(0, _textHeight); pts[2] = QPoint(_textWidth, _textHeight); pts[3] = QPoint(_textWidth, 0); double theta = M_PI * (int(_rotation) % 360) / 180; double sina = sin(theta); double cosa = cos(theta); QWMatrix m(cosa, sina, -sina, cosa, 0.0, 0.0); pts = m.map(pts); if (_parent) { QRect r(position(), pts.boundingRect().size()); r.setSize(r.size() + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10)); sz = r.intersect(_parent->geometry()).size(); } else { sz = pts.boundingRect().size(); sz += QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10); } } else { if (_parent) { QRect r(position(), sz); r.setSize(r.size() + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10)); sz = r.intersect(_parent->geometry()).size(); } } return sz; }
static void text(MMIOT *f) { int c, j; int rep; int smartyflags = 0; while ( (c = pull(f)) != EOF ) { if ( smartypants(c, &smartyflags, f) ) continue; switch (c) { case 0: break; case '>': if ( tag_text(f) ) Qstring(">", f); else Qchar(c, f); break; case '"': if ( tag_text(f) ) Qstring(""", f); else Qchar(c, f); break; case '!': if ( peek(f,1) == '[' ) { pull(f); if ( tag_text(f) || !linkylinky(1, f) ) Qstring("![", f); } else Qchar(c, f); break; case '[': if ( tag_text(f) || !linkylinky(0, f) ) Qchar(c, f); break; #if SUPERSCRIPT case '^': if ( isthisspace(f,-1) || isthisspace(f,1) ) Qchar(c,f); else { char *sup = cursor(f); int len = 0; Qstring("<sup>",f); while ( !isthisspace(f,1+len) ) { ++len; } shift(f,len); reparse(sup, len, 0, f); Qstring("</sup>", f); } break; #endif case '_': #if RELAXED_EMPHASIS /* If RELAXED_EMPHASIS, underscores don't count when * they're in the middle of a word. */ if ( (isthisspace(f,-1) && isthisspace(f,1)) || (isalnum(peek(f,-1)) && isalnum(peek(f,1))) ) { Qchar(c, f); break; } /* else fall into the regular old emphasis case */ #endif case '*': if ( tag_text(f) ) Qchar(c, f); else { for (rep = 1; peek(f,1) == c; pull(f) ) ++rep; Qem(f,c,rep); } break; case '`': if ( tag_text(f) ) Qchar(c, f); else { Qstring("<code>", f); if ( peek(f, 1) == '`' ) { pull(f); code(2, f); } else code(1, f); Qstring("</code>", f); } break; case '\\': switch ( c = pull(f) ) { case '&': Qstring("&", f); break; case '<': Qstring("<", f); break; case '\\': case '>': case '#': case '.': case '-': case '+': case '{': case '}': case ']': case '(': case ')': case '"': case '\'': case '!': case '[': case '*': case '_': case '`': Qchar(c, f); break; default: Qchar('\\', f); if ( c != EOF ) shift(f,-1); break; } break; case '<': if ( !maybe_tag_or_link(f) ) Qstring("<", f); break; case '&': j = (peek(f,1) == '#' ) ? 2 : 1; while ( isalnum(peek(f,j)) ) ++j; if ( peek(f,j) != ';' ) Qstring("&", f); else Qchar(c, f); break; default: Qchar(c, f); break; } } } /* text */