Re: CVS: commit uwog abiword-plugins/tools/abimathview/xp AbiMathView.cpp

From: J.M. Maurer <j.m.maurer_at_student.utwente.nl>
Date: Sat Aug 20 2005 - 13:00:46 CEST

This commit finally removes the need to have a itex2MML binary in place.
I'm really happy with it (heck, i needed to learn yacc for it); the only
tiny uglyness is that itex2MML is really designed internally to work on
a FILE *. So for now the text to convert is placed in a tmpfile, which
is removed after the conversion.

Feel free to come up with better solutions

marc

On Sat, 2005-08-20 at 10:48 +0000, cvs@abisource.com wrote:
> Update of /cvsroot/abiword-plugins/tools/abimathview/xp
> In directory abiword.snt.utwente.nl:/tmp/cvs-serv3134
>
> Modified Files:
> AbiMathView.cpp
> Log Message:
> Remove the need to popen itex2MML... w00t!
>
>
>
> Index: AbiMathView.cpp
> ===================================================================
> RCS file: /cvsroot/abiword-plugins/tools/abimathview/xp/AbiMathView.cpp,v
> retrieving revision 1.26
> retrieving revision 1.27
> diff -u -d -r1.26 -r1.27
> --- AbiMathView.cpp 17 Aug 2005 22:33:52 -0000 1.26
> +++ AbiMathView.cpp 20 Aug 2005 10:48:09 -0000 1.27
> @@ -103,7 +103,6 @@
> sz1 = reinterpret_cast<const char*>(pSz);
> pE = reinterpret_cast<AbiMathViewEntityMapItem **>(reinterpret_cast<void ** >(const_cast<void *>(pEnt)));
> sz2 = (*pE)->szEntity;
> - // printf("Compare sz1 %s to sz2 %s \n",sz1,sz2);
> return UT_strcmp(sz1,sz2);
> }
>
> @@ -872,55 +871,50 @@
> pMathView->resetRootElement();
> }
>
> +extern "C"
> +{
> + extern void yyrestart(FILE *input_file);
> + extern int yyparse(char **str);
> +}
> +
> bool GR_MathManager::convert(UT_uint32 iConType, UT_ByteBuf & From, UT_ByteBuf & To)
> {
> + XAP_App * pApp = XAP_App::getApp();
> + XAP_Frame * pFrame = pApp->getLastFocussedFrame();
> +
> if (iConType != 0)
> {
> return false;
> }
>
> - UT_UTF8String sLatex;
> - UT_UTF8String sMathML;
> - UT_UCS4_mbtowc myWC;
> - UT_UTF8String sCommand;
> + /* TODO: rewrite itex2MML to be able to use the From buffer directly
> + instread of through a FILE* */
>
> - sLatex.appendBuf(From, myWC);
> - sCommand = "itex2MML <<FREDDDYYYY\n";
> - sCommand += sLatex;
> - sCommand += "\n";
> - sCommand += "FREDDDYYYY\n";
> - fflush(stdin);
> - FILE * psRes = popen(sCommand.utf8_str(),"r");
> + FILE *tmp = tmpfile();
> + fwrite(From.getPointer(0), From.getLength(), 1, tmp);
> + fflush(tmp);
> + rewind(tmp);
> + yyrestart(tmp);
>
> - XAP_App * pApp = XAP_App::getApp();
> - XAP_Frame * pFrame = pApp->getLastFocussedFrame();
> - if (psRes == NULL)
> + char *mathml = 0;
> + int res = yyparse(&mathml);
> + fclose(tmp);
> +
> + if (res != 0)
> {
> - pFrame->showMessageBox("itex2MML convertor not found on your system.\n Please install itex2MML \n",
> + pFrame->showMessageBox("TODO: give proper error message!\n",
> XAP_Dialog_MessageBox::b_O,
> XAP_Dialog_MessageBox::a_OK);
> return false;
> }
>
> - char FullLine[1003]; /* FIXME: bad bad fixed size array */
> - UT_uint32 numRead = 1000;
> - while (numRead == 1000)
> - {
> - numRead = fread(&FullLine,1,1000,psRes);
> - FullLine[numRead] =0;
> - sMathML += FullLine;
> - }
> -
> - //
> - // Fixme! Find out how to extract the error message.
> - //
> -
> - pclose(psRes);
> -
> + UT_UTF8String sMathML(mathml);
> + FREEP(mathml);
> +
> if (sMathML.size() == 0)
> {
> - UT_UTF8String sErrMessage = "Error converting:\n";
> - sErrMessage += sLatex;
> + UT_UTF8String sErrMessage = "Error converting: <todo>\n";
> + //sErrMessage += sLatex;
> sErrMessage += "\n";
> // sErrMessage += FullLine;
> pFrame->showMessageBox(sErrMessage.utf8_str(),
> @@ -931,7 +925,7 @@
>
> char * szRawChars = NULL;
> szRawChars = const_cast<char *>(sMathML.utf8_str());
> - printf("Input MathML %s \n",szRawChars);
> + UT_DEBUGMSG(("Input MathML %s \n", szRawChars));
>
> char * psz0 = szRawChars;
> char * psz1 = szRawChars;
> @@ -968,7 +962,7 @@
> {
> pszNew[i] = psz1[1+i];
> }
> - printf("Extracted entity %s \n",pszNew);
> + UT_DEBUGMSG(("Extracted entity %s \n", pszNew));
>
> char * szEntVal = NULL;
> UT_sint32 pos = m_vecEntityMap.binarysearch(reinterpret_cast<void *>(pszNew),compareEntities);
>
> -----------------------------------------------
> To unsubscribe from this list, send a message to
> abisource-cvs-commit-request@abisource.com with the word
> unsubscribe in the message body.
>
Received on Sat Aug 20 12:59:19 2005

This archive was generated by hypermail 2.1.8 : Sat Aug 20 2005 - 12:59:20 CEST