BracketResult LaTeXParser::matchBracket(const QStringList& textLines, int &l, int &pos) { BracketResult result; TodoResult todo; if((getTextLine(textLines, l))[pos] == '[') { result.option = Parser::matchBracket(textLines, '[', l, pos); int p = 0; while(l < textLines.size()) { if((p = processTextline(getTextLine(textLines, l), todo).indexOf('{', pos)) != -1) { pos = p; break; } else { pos = 0; ++l; } } } if((getTextLine(textLines, l))[pos] == '{') { result.line = l; result.col = pos; result.value = Parser::matchBracket(textLines, '{', l, pos); } return result; }
void test() { int multipnm=1; job_t job; while (multipnm==1) { job_init(&job); job.cfg.out_format=XML; job.cfg.cfilter = filter; job.src.fname = "patch00000.pgm"; // TODO multipnm=readpgm(job.src.fname, &job.src.p, job.cfg.verbose); if (multipnm<0) break; pgm2asc(&job); int linecounter = 0; const char *line; line = getTextLine(linecounter++); while (line) { //fputs(line, stdout); //Interpret line here line = getTextLine(linecounter++); } free_textlines(); job_free(&job); } return; }
/* subject of change, we need more output for XML (ToDo) */ char* print_output(job_t *job) { int linecounter = 0; const char *line; char** lines; char* output; int i = 0, j, n = 0; assert(job); /* TODO: replace getTextLine-loop(line) by output_text() (libs have to use pipes) simplify code 2010-09-26 */ linecounter = 0; lines = (char**) malloc(job->res.lines.num); line = getTextLine(&(job->res.linelist), linecounter++); while (line) { n += strlen(line) + 1; lines[i] = (char*) malloc(strlen(line)); strcpy(lines[i++], line); /* notice: decode() is shiftet to getTextLine since 0.38 */ if (job->cfg.out_format==HTML) fputs("<br />",stdout); if (job->cfg.out_format!=XML) fputc('\n', stdout); line = getTextLine(&(job->res.linelist), linecounter++); } // free_textlines(&(job->res.linelist)); output = (char*) malloc(n); strcpy(output, lines[0]); for(j = 1; j < i; j++) { strcat(output, "\n"); strcat(output, lines[j]); } return output; }
void clbr::ClbrFile::ruleMetaData() { assert(_cRule); if (moreData()) _cRule->setCurResCount(_textStream->Read32()); if (moreData()) _cRule->setOrigResCount(_textStream->Read32()); unsigned int numInfoLines; if (moreData()) numInfoLines = _textStream->Read32(); _cRule->setTimeStamp(getTextLine()); for (unsigned int i = 0; i < numInfoLines; i++) { _cRule->addDescrString(getTextLine()); } }
bool clbr::ClbrFile::checkCNnP() { int nextChar; std::string cnLine; if (moreData()) nextChar = _inStream->GetC(); if (isdigit(nextChar) || ('-' == (char) nextChar)) { _inStream->Ungetch((char) nextChar); return true; } else if ('C' != (char) nextChar) { _inStream->Ungetch((char) nextChar);// - should be a property! } else { if (moreData()) nextChar = _inStream->GetC(); if ('N' != (char) nextChar) { _inStream->Ungetch((char) nextChar);// - should be a property! } else { readCN(); return true; } } std::string property = getTextLine();// TODO parse a property return false; }
/* ** bmp8 must be grayscale ** (x1,y1) and (x2,y2) from top left of bitmap */ void jocr_single_word_from_bmp8(char *text,int maxlen,WILLUSBITMAP *bmp8, int x1,int y1,int x2,int y2,int allow_spaces, int std_proc) { job_t *job,_job; int i,w,h,dw,dh,bw; unsigned char *src,*dst; // static char *funcname="jocr_single_word_from_bmp8"; char *buf; int pgm2asc(job_t *job); char *getTextLine(int); if (x1>x2) { w=x1; x1=x2; x2=w; } w=x2-x1+1; bw=w/40; if (bw<6) bw=6; dw=w+bw*2; if (y1>y2) { h=y1; y1=y2; y2=h; } h=y2-y1+1; dh=h+bw*2; job=&_job; job_init(job); job_init_image(job); // willus_mem_alloc_warn((void **)&job->src.p.p,w*h,funcname,10); /* Must use malloc since job_free_image counts on this. */ job->src.p.p=malloc(dw*dh); job->src.p.x=dw; job->src.p.y=dh; job->src.p.bpp=1; src=bmp_rowptr_from_top(bmp8,y1)+x1; memset(job->src.p.p,255,dw*dh); dst=(unsigned char *)job->src.p.p + dw*bw + bw; for (i=y1;i<=y2;i++,dst+=dw,src+=bmp8->width) memcpy(dst,src,w); pgm2asc(job); buf=getTextLine(0); if (buf) { strncpy(text,buf,maxlen-1); text[maxlen-1]='\0'; if (std_proc) ocr_text_proc(text,allow_spaces); } else text[0]='\0'; // willus_mem_free((double **)&job->src.p.p,funcname); job_free_image(job); }
/* subject of change, we need more output for XML (ToDo) */ void print_output(job_t *job) { int linecounter = 0; const char *line; assert(job); linecounter = 0; line = getTextLine(linecounter++); while (line) { /* notice: decode() is shiftet to getTextLine since 0.38 */ fputs(line, stdout); if (job->cfg.out_format==HTML) fputs("<br />",stdout); if (job->cfg.out_format!=XML) fputc('\n', stdout); line = getTextLine(linecounter++); } free_textlines(); }
/* subject of change, we need more output for XML (ToDo) */ void print_output(job_t *job) { int linecounter = 0; const char *line; assert(job); /* TODO: replace getTextLine-loop(line) by output_text() (libs have to use pipes) simplify code 2010-09-26 */ linecounter = 0; line = getTextLine(&(job->res.linelist), linecounter++); while (line) { /* notice: decode() is shiftet to getTextLine since 0.38 */ fputs(line, stdout); if (job->cfg.out_format==HTML) fputs("<br />",stdout); if (job->cfg.out_format!=XML) fputc('\n', stdout); line = getTextLine(&(job->res.linelist), linecounter++); } free_textlines(&(job->res.linelist)); }
int DATA::getIntLine(char * line) { // get text from line char * text = getTextLine(line); char * ptr = text; // convert to an int and clean up extra data int returnInt; returnInt = 0; while (*ptr >= '0' && *ptr <= '9') { returnInt = (returnInt * 10) + *ptr++ - '0'; } delete [] text; return returnInt; }
float SvgTextEntry::getTextLineX(int index) { SvgTextLine *line; line=getTextLine(index); if (line) { Svg2DVector vec; vec.setX(line->getX()); vec.setY(line->getY()); m_matrix->transformVector(&vec); return vec.getX(); } return 0; }
int main(int argc, char **argv, char **envp) { init(); welcomeScreen(); shellPrompt(); while (TRUE) { userInput = getchar(); switch (userInput) { case '\n': shellPrompt(); break; default: getTextLine(); handleUserCommand(); shellPrompt(); break; } } printf("\n"); return 0; }
int main(int argc, char **argv, char **envp) { init(); welcomeScreen(); shellPrompt(); // prints the prompt while (TRUE) { userInput = getchar(); switch (userInput) { case '\n': // if the user hits the enter key shellPrompt(); // nothing happens break; default: getTextLine(); // store user input in buffer handleUserCommand(); // execute user command shellPrompt(); // print the prompt break; } } printf("\n"); return 0; }
ParserOutput* BibTeXParser::parse() { BibTeXParserOutput *parserOutput = new BibTeXParserOutput(); qCDebug(LOG_KILE_PARSER); static QRegExp reItem("^(\\s*)@([a-zA-Z]+)"); static QRegExp reSpecial("string|preamble|comment"); QString s, key; int col = 0, startcol, startline = 0; // emit(parsingStarted(m_doc->lines())); for(int i = 0; i < m_textLines.size(); ++i) { if(!m_parserThread->shouldContinueDocumentParsing()) { qCDebug(LOG_KILE_PARSER) << "stopping..."; delete(parserOutput); return Q_NULLPTR; } // emit(parsingUpdate(i)); s = getTextLine(m_textLines, i); if((s.indexOf(reItem) != -1) && !reSpecial.exactMatch(reItem.cap(2).toLower())) { qCDebug(LOG_KILE_PARSER) << "found: " << reItem.cap(2); //start looking for key key = ""; bool keystarted = false; int state = 0; startcol = reItem.cap(1).length(); col = startcol + reItem.cap(2).length(); while(col < static_cast<int>(s.length())) { ++col; if(col == static_cast<int>(s.length())) { do { ++i; s = getTextLine(m_textLines, i); } while((s.length() == 0) && (i < m_textLines.size())); if(i == m_textLines.size()) { break; } col = 0; } if(state == 0) { if(s[col] == '{') { state = 1; } else if(!s[col].isSpace()) { break; } } else if(state == 1) { if(s[col] == ',') { key = key.trimmed(); qCDebug(LOG_KILE_PARSER) << "found: " << key; parserOutput->bibItems.append(key); parserOutput->structureViewItems.push_back(new StructureViewItem(key, startline+1, startcol, KileStruct::BibItem, 0, startline+1, startcol, "viewbib", reItem.cap(2).toLower())); break; } else { key += s[col]; if(!keystarted) { startcol = col; startline = i; } keystarted = true; } } } } } return parserOutput;; }
//FIXME: this has to be completely rewritten! ParserOutput* LaTeXParser::parse() { LaTeXParserOutput *parserOutput = new LaTeXParserOutput(); qCDebug(LOG_KILE_PARSER) << m_textLines; QMap<QString,KileStructData>::const_iterator it; static QRegExp reCommand("(\\\\[a-zA-Z]+)\\s*\\*?\\s*(\\{|\\[)"); static QRegExp reRoot("\\\\documentclass|\\\\documentstyle"); static QRegExp reBD("\\\\begin\\s*\\{\\s*document\\s*\\}"); static QRegExp reReNewCommand("\\\\renewcommand.*$"); static QRegExp reNumOfParams("\\s*\\[([1-9]+)\\]"); static QRegExp reNumOfOptParams("\\s*\\[([1-9]+)\\]\\s*\\[([^\\{]*)\\]"); // the quantifier * isn't used by mistake, because also emtpy optional brackets are correct. int tagStart, bd = 0; int tagEnd, tagLine = 0, tagCol = 0; int tagStartLine = 0, tagStartCol = 0; BracketResult result; QString m, s, shorthand; bool foundBD = false; // found \begin { document } bool fire = true; //whether or not we should emit a foundItem signal bool fireSuspended; // found an item, but it should not be fired (this time) TodoResult todo; // emit(parsingStarted(m_doc->lines())); for(int i = 0; i < m_textLines.size(); ++i) { if(!m_parserThread->shouldContinueDocumentParsing()) { qCDebug(LOG_KILE_PARSER) << "stopping..."; delete(parserOutput); return Q_NULLPTR; } // emit(parsingUpdate(i)); tagStart = tagEnd = 0; fire = true; s = processTextline(getTextLine(m_textLines, i), todo); if(todo.type != -1 && m_showStructureTodo) { QString folder = (todo.type == KileStruct::ToDo) ? "todo" : "fixme"; parserOutput->structureViewItems.push_back(new StructureViewItem(todo.comment, i+1, todo.colComment, todo.type, KileStruct::Object, i+1, todo.colTag, QString(), folder)); } if(s.isEmpty()) { continue; } //ignore renewcommands s.remove(reReNewCommand); //find all commands in this line while(tagStart != -1) { if((!foundBD) && ((bd = s.indexOf(reBD, tagEnd)) != -1)) { qCDebug(LOG_KILE_PARSER) << "\tfound \\begin{document}"; foundBD = true; parserOutput->preamble.clear(); //FIXME: improve this if(bd == 0) { if(i - 1 >= 0) { for(int j = 0; j <= i - 1; ++j) { parserOutput->preamble += getTextLine(m_textLines, j) + '\n'; } } } else { if(i - 1 >= 0) { for(int j = 0; j <= i - 1; ++j) { parserOutput->preamble += getTextLine(m_textLines, j) + '\n'; } } parserOutput->preamble += getTextLine(m_textLines, i).left(bd) + '\n'; } } if((!foundBD) && (s.indexOf(reRoot, tagEnd) != -1)) { qCDebug(LOG_KILE_PARSER) << "\tsetting m_bIsRoot to true"; tagEnd += reRoot.cap(0).length(); parserOutput->bIsRoot = true; } tagStart = reCommand.indexIn(s, tagEnd); m.clear(); shorthand.clear(); if(tagStart != -1) { tagEnd = tagStart + reCommand.cap(0).length()-1; //look up the command in the dictionary it = m_dictStructLevel.constFind(reCommand.cap(1)); //if it is was a structure element, find the title (or label) if(it != m_dictStructLevel.constEnd()) { tagLine = i+1; tagCol = tagEnd+1; tagStartLine = tagLine; tagStartCol = tagStart+1; if(reCommand.cap(1) != "\\frame") { result = matchBracket(m_textLines, i, tagEnd); m = result.value.trimmed(); shorthand = result.option.trimmed(); if(i >= tagLine) { //matching brackets spanned multiple lines s = getTextLine(m_textLines, i); } if(result.line > 0 || result.col > 0) { tagLine = result.line + 1; tagCol = result.col + 1; } //qCDebug(LOG_KILE_PARSER) << "\tgrabbed: " << reCommand.cap(1) << "[" << shorthand << "]{" << m << "}"; } else { m = i18n("Frame"); } } //title (or label) found, add the element to the listview if(!m.isNull()) { // no problems so far ... fireSuspended = false; // remove trailing ./ if((*it).type & (KileStruct::Input | KileStruct::Graphics)) { if(m.left(2) == "./") { m = m.mid(2, m.length() - 2); } } // update parameter for environments, because only // floating environments and beamer frames are passed if ( (*it).type == KileStruct::BeginEnv ) { if ( m=="figure" || m=="figure*" || m=="table" || m=="table*" ) { it = m_dictStructLevel.constFind("\\begin{" + m +'}'); } else if(m == "asy") { it = m_dictStructLevel.constFind("\\begin{" + m +'}'); parserOutput->asyFigures.append(m); } else if(m == "frame") { const QString untitledFrameDisplayName = i18n("Frame"); it = m_dictStructLevel.constFind("\\begin{frame}"); if(tagEnd+1 < s.size() && s.at(tagEnd+1) == '{') { tagEnd++; result = matchBracket(m_textLines, i, tagEnd); m = result.value.trimmed(); if(m.isEmpty()) { m = untitledFrameDisplayName; } } else { m = untitledFrameDisplayName; } } else if(m=="block" || m=="exampleblock" || m=="alertblock") { const QString untitledBlockDisplayName = i18n("Untitled Block"); it = m_dictStructLevel.constFind("\\begin{block}"); if(tagEnd+1 < s.size() && s.at(tagEnd+1) == '{') { tagEnd++; result = matchBracket(m_textLines, i, tagEnd); m = result.value.trimmed(); if(m.isEmpty()) { m = untitledBlockDisplayName; } } else { m = untitledBlockDisplayName; } } else { fireSuspended = true; // only floats and beamer frames, no other environments } } // tell structure view that a floating environment or a beamer frame must be closed else if ( (*it).type == KileStruct::EndEnv ) { if ( m=="figure" || m== "figure*" || m=="table" || m=="table*" || m=="asy") { it = m_dictStructLevel.constFind("\\end{float}"); } else if(m == "frame") { it = m_dictStructLevel.constFind("\\end{frame}"); } else { fireSuspended = true; // only floats, no other environments } } // sectioning commands else if((*it).type == KileStruct::Sect) { if(!shorthand.isEmpty()) { m = shorthand; } } // update the label list else if((*it).type == KileStruct::Label) { parserOutput->labels.append(m); // label entry as child of sectioning if(m_showSectioningLabels) { parserOutput->structureViewItems.push_back(new StructureViewItem(m, tagLine, tagCol, KileStruct::Label, KileStruct::Object, tagStartLine, tagStartCol, "label", "root")); fireSuspended = true; } } // update the references list else if((*it).type == KileStruct::Reference) { // m_references.append(m); //fireSuspended = true; // don't emit references } // update the dependencies else if((*it).type == KileStruct::Input) { // \input- or \include-commands can be used without extension. So we check // if an extension exists. If not the default extension is added // ( LaTeX reference says that this is '.tex'). This assures that // all files, which are listed in the structure view, have an extension. QString ext = QFileInfo(m).completeSuffix(); if(ext.isEmpty()) { m += m_extensions->latexDocumentDefault(); } parserOutput->deps.append(m); } // update the referenced Bib files else if((*it).type == KileStruct::Bibliography) { qCDebug(LOG_KILE_PARSER) << "===TeXInfo::updateStruct()===appending Bibiliograph file(s) " << m; QStringList bibs = m.split(','); QString biblio; // assure that all files have an extension QString bibext = m_extensions->bibtexDefault(); int bibextlen = bibext.length(); uint cumlen = 0; int nextbib = 0; // length to add to jump to the next bibliography for(int b = 0; b < bibs.count(); ++b) { nextbib = 0; biblio=bibs[b]; parserOutput->bibliography.append(biblio); if(biblio.left(2) == "./") { nextbib += 2; biblio = biblio.mid(2, biblio.length() - 2); } if(biblio.right(bibextlen) != bibext) { biblio += bibext; nextbib -= bibextlen; } parserOutput->deps.append(biblio); parserOutput->structureViewItems.push_back(new StructureViewItem(biblio, tagLine, tagCol+cumlen, (*it).type, (*it).level, tagStartLine, tagStartCol, (*it).pix, (*it).folder)); cumlen += biblio.length() + 1 + nextbib; } fire = false; } // update the bibitem list else if((*it).type == KileStruct::BibItem) { //qCDebug(LOG_KILE_PARSER) << "\tappending bibitem " << m; parserOutput->bibItems.append(m); } // update the package list else if((*it).type == KileStruct::Package) { QStringList pckgs = m.split(','); uint cumlen = 0; for(int p = 0; p < pckgs.count(); ++p) { QString package = pckgs[p].trimmed(); if(!package.isEmpty()) { parserOutput->packages.append(package); // hidden, so emit is useless // emit( foundItem(package, tagLine, tagCol+cumlen, (*it).type, (*it).level, tagStartLine, tagStartCol, (*it).pix, (*it).folder) ); cumlen += package.length() + 1; } } fire = false; } // newcommand found, add it to the newCommands list else if((*it).type & (KileStruct::NewCommand | KileStruct::NewEnvironment)) { QString optArg, mandArgs; //find how many parameters this command takes if(s.indexOf(reNumOfParams, tagEnd + 1) != -1) { bool ok; int noo = reNumOfParams.cap(1).toInt(&ok); if(ok) { if(s.indexOf(reNumOfOptParams, tagEnd + 1) != -1) { qCDebug(LOG_KILE_PARSER) << "Opt param is " << reNumOfOptParams.cap(2) << "%EOL"; noo--; // if we have an opt argument, we have one mandatory argument less, and noo=0 can't occur because then latex complains (and we don't macht them with reNumOfParams either) optArg = '[' + reNumOfOptParams.cap(2) + ']'; } for(int noo_index = 0; noo_index < noo; ++noo_index) { mandArgs += '{' + s_bullet + '}'; } } if(!optArg.isEmpty()) { if((*it).type == KileStruct::NewEnvironment) { parserOutput->newCommands.append(QString("\\begin{%1}%2%3").arg(m).arg(optArg).arg(mandArgs)); } else { parserOutput->newCommands.append(m + optArg + mandArgs); } } } if((*it).type == KileStruct::NewEnvironment) { parserOutput->newCommands.append(QString("\\begin{%1}%3").arg(m).arg(mandArgs)); parserOutput->newCommands.append(QString("\\end{%1}").arg(m)); } else { parserOutput->newCommands.append(m + mandArgs); } //FIXME set tagEnd to the end of the command definition break; } // and some other commands, which don't need special actions: // \caption, ... // qCDebug(LOG_KILE_PARSER) << "\t\temitting: " << m; if(fire && !fireSuspended) { parserOutput->structureViewItems.push_back(new StructureViewItem(m, tagLine, tagCol, (*it).type, (*it).level, tagStartLine, tagStartCol, (*it).pix, (*it).folder)); } } //if m } // if tagStart } // while tagStart } //for qCDebug(LOG_KILE_PARSER) << "done"; return parserOutput; }