nyctergatis.com

Contact

Projects
Sysquake Remote Live
NME
PDF
Hike
Sudoku
GifBuilder
jpeglib for Palm OS
MySQL Client
Cross-GCC for Mac OS
NMETest.c
Go to the documentation of this file.
00001 
00008 /* License: new BSD license (see header file) */
00009 
00010 #include "NMETest.h"
00011 
00020 static NMEErr encodeURLFunNull(NMEConstText link, NMEInt linkLen,
00021         NMEContext *context, void *data)
00022 {
00023     return kNMEErrOk;
00024 }
00025 
00036 static NMEErr encodeCharFunNull(NMEConstText src, NMEInt srcLen, NMEInt *srcIx,
00037         NMEContext *context,
00038         void *data)
00039 {
00040     (*srcIx)++;
00041     return kNMEErrOk;
00042 }
00043 
00044 NMEOutputFormat const NMEOutputFormatTest =
00045 {
00046     "", // space
00047     0,  // indentSpaces
00048     10, // defFontSize
00049     '%',    // ctrlChar
00050     "+;%{L}\n", "-;%{L}\n", // doc
00051     10, // highest heading level
00052     "+%%{l} %%H %{l} %{i};%{L}\n", "-%%{l} %%H %{l} %{i};%{L}\n",   // heading
00053     "+ par;%{L}\n", "- par;%{L}\n", // par
00054     "", // line break
00055     "+ pre;%{L}\n", "- pre;%{L}\n", // pre
00056     "+ preline;%{L}\n", "- preline;%{L}\n", // pre line
00057     FALSE,  // sublistInListItem
00058     "+%%{l} %%U %{l};%{L}\n", "-%%{l} %%U %{l};%{L}\n", // UL
00059     "+%%{l} %%u %{l} %{i};%{L}\n", "-%%{l} %%u %{l} %{i};%{L}\n",   // UL line
00060     "+%%{l} %%O %{l};%{L}\n", "-%%{l} %%O %{l};%{L}\n", // OL
00061     "+%%{l} %%o %{l} %{i};%{L}\n", "-%%{l} %%o %{l} %{i};%{L}\n",   // OL line
00062     "+%%{l} %%D %{l};%{L}\n", "-%%{l} %%D %{l};%{L}\n", // DL
00063     "+%%{l} %%t %{l} %{i};%{L}\n", "-%%{l} %%t %{l} %{i};%{L}\n",   // DT
00064     "", // emptyDT
00065     "+%%{l} %%d %{l} %{i};%{L}\n", "-%%{l} %%d %{l} %{i};%{L}\n",   // DD
00066     "+%%{l} %%I %{l};%{L}\n", "-%%{l} %%I %{l};%{L}\n", // indented section
00067     "+%%{l} %%i %{l} %{i};%{L}\n", "-%%{l} %%i %{l} %{i};%{L}\n",   // indented par
00068     "+ T;%{L}\n", "- T;%{L}\n", // table
00069     "+  t;%{L}\n", "-  t;%{L}\n",   // table row
00070     "+   th;%{L}\n", "-   th;%{L}\n",   // table header cell
00071     "+   td;%{L}\n", "-   td;%{L}\n",   // table normal cell
00072     "", // hr
00073     "+*;%{L}\n", "-*;%{L}\n",   // bold
00074     "+/;%{L}\n", "-/;%{L}\n",   // italic
00075     "+_;%{L}\n", "-_;%{L}\n",   // underline
00076     "+^;%{L}\n", "-^;%{L}\n",   // superscript
00077     "+,;%{L}\n", "-,;%{L}\n",   // subscript
00078     "+#;%{L}\n", "-#;%{L}\n",   // monospace
00079     "+a;%{L}\n", "", "-a;%{L}\n", FALSE,    // link
00080     "+i;%{L}\n", "", "-i;%{L}\n", FALSE, TRUE,  // image
00081     NULL,   // interwikis
00082     encodeURLFunNull, NULL, // encodeURLFun
00083     encodeCharFunNull, NULL,    // char encoder
00084     encodeCharFunNull, NULL,    // char pre encoder
00085     -1, NULL, NULL, // no wordwrap
00086     NULL, NULL, // char hook
00087     NULL, NULL, NULL, NULL, // process hooks
00088     NULL,   // plugins
00089     NULL,   // autoconverts
00090     NULL, NULL  // getVar
00091 };
00092 
00093 NMEErr NMETest(NMEConstText output, NMEInt outputLength, NMEInt *lineNumber)
00094 {
00095     // Output is parsed line by line. When an end-of-construct line is parsed,
00096     // it's compared against the last one still considered. If they match, the
00097     // start line is discarded; otherwise, an error is returned.
00098     
00099     NMEInt currentLine; // offset of current line
00100     NMEInt i;   // used for comparison
00101     
00102 #define kMaxDepth 32
00103     // 2 * kMaxNesting + style number + doc root + margin
00104     // (2* for lists + list items; margin to produce more useful output in case of bug)
00105     NMEInt startOffset[kMaxDepth];
00106     NMEInt depth;
00107     
00108     for (currentLine = 0, depth = 0; currentLine < outputLength; )
00109     {
00110         if (output[currentLine] == '-')
00111         {
00112             if (depth < 0)
00113                 return kNMEErrSuperfluousEndTag;
00114             currentLine++;
00115             for (i = 0;
00116                     currentLine + i < outputLength
00117                         && output[currentLine + i] != '\n' && output[currentLine + i] != ';';
00118                     i++)
00119                 if (output[currentLine + i] != output[startOffset[depth - 1] + i])
00120                     return kNMEErrBadNesting;
00121             if (output[startOffset[depth - 1] + i] != output[currentLine + i])
00122                 return kNMEErrBadNesting;
00123             currentLine += i;
00124             depth--;
00125         }
00126         else
00127         {
00128             if (depth >= kMaxDepth)
00129                 return kNMEErrInternal;
00130             startOffset[depth++] = currentLine + 1; // skip +
00131             // skip until semicolon
00132             while (currentLine < outputLength
00133                     && output[currentLine] != '\n' && output[currentLine] != ';')
00134                 currentLine++;
00135         }
00136         
00137         // decode line number and skip end of line
00138         for (*lineNumber = 0;
00139                 currentLine < outputLength && output[currentLine] != '\n';
00140                 currentLine++)
00141             if (output[currentLine] >= '0' && output[currentLine] <= '9')
00142                 *lineNumber = 10 * *lineNumber + output[currentLine] - '0';
00143         if (currentLine < outputLength && output[currentLine] == '\n')
00144             currentLine++;
00145     }
00146     
00147     if (depth > 0)
00148         return kNMEErrMissingEndTag;
00149     else
00150         return kNMEErrOk;
00151 }
Generated by Doxygen.
Copyright 2007-2013, Yves Piguet.
All rights reserved.