00001
00054
00055
00056
00057
00058 #include <stdlib.h>
00059 #include <stdio.h>
00060 #include <string.h>
00061 #include "NME.h"
00062 #include "NMEAutolink.h"
00063 #include "NMEPluginRot13.h"
00064 #include "NMEPluginReverse.h"
00065 #include "NMEPluginUppercase.h"
00066 #include "NMEPluginCalendar.h"
00067 #include "NMEPluginRaw.h"
00068 #include "NMEPluginTOC.h"
00069
00071 #define SIZE (128 * 1024)
00072
00073
00074
00076 static NMEEncodeCharDict const xmlCharDict[] =
00077 {
00078 {'<', "<"},
00079 {'&', "&"},
00080 {0, NULL}
00081 };
00082
00084 static NMEOutputFormat const NMEOutputFormatSlidesHTML =
00085 {
00086 " ",
00087 2,
00088 0,
00089 '%',
00090
00091
00092
00093 "<style type=\"text/css\">\n"
00094
00095 "div.SL *,div.FSL *,div.TSL * {background:inherit;color:white}\n"
00096 "div.TSL h1,div.SL h2,div.SL h3,div.SL h4{color:white}\n"
00097 "div.SL,div.TSL {background:#000099;width:300pt;height:200pt;\n"
00098 "padding:20pt;margin:10pt;page-break-inside:avoid;position:relative}\n"
00099 "div.FSL{position:absolute;bottom:10px;right:10px}\n"
00100 "div.SL h1,div.SL h2,div.SL h3,div.SL p,div.SL dl,div.SL dt,div.SL ul,div.SL table,div.SL td,div.SL th,div.SL address{font-family:verdana,arial,sans-serif}\n"
00101 "div.SL h1,div.SL h2,div.TSL h1,div.TSL h2{text-align:center}\n"
00102 "div.TSL h1{font-size: 20pt;margin-top:50pt}\n"
00103 "div.SL h2{font-size:18pt}\n"
00104 "div.SL h3{font-size:13pt}\n"
00105 "div.TSL p,div.SL p,div.SL dl,div.SL dt,div.SL ul,div.SL table,div.SL td,div.SL th,div.SL pre,div.SL address{font-size:11pt;line-height:1.3;\n"
00106 "margin-top:3pt;margin-bottom:6pt}\n"
00107 "div.SL p,div.SL dl,div.SL ul{text-align:justify}\n"
00108 "div.SL table{border-style=solid;border-width=1px;border-color=white}\n"
00109 "div.FSL p{font-size:9pt;color:#6666ff}\n"
00110 "div.TSL p{text-align:center}\n"
00111 "</style>\n"
00112 "<div class=\"TSL\">\n",
00113 "</div>"
00114
00115 ,
00116 4,
00117 "%%{l=2&i>1}<div class=\"FSL\"><p>%{i-1}</p></div>\n%%"
00118 "%%{l=2}</div>\n<div class=\"SL\">\n%%"
00119 "<h%{l}%%{s>0} style=\"font-size:%{l=1&3*s|l=2&2*s|l=3&3*s/2|5*s/4}pt\"%%>"
00120 "%%{x}<a name=\"h%{o}\">%%",
00121 "%%{x}</a>%%"
00122 "</h%{l}>\n",
00123 "<p%%{s>0} style=\"font-size:%{s}pt\"%%>", "</p>\n",
00124 "<br />",
00125 "<pre%%{s>0} style=\"font-size:%{s}pt\"%%>\n", "</pre>\n",
00126 "", "\n",
00127 "<ul>\n", "</ul>\n",
00128 "<li%%{s>0} style=\"font-size:%{s}pt\"%%>", "</li>\n",
00129 "<ol>\n", "</ol>\n",
00130 "<li%%{s>0} style=\"font-size:%{s}pt\"%%>", "</li>\n",
00131 "<dl>\n", "</dl>\n",
00132 "<dt%%{s>0} style=\"font-size:%{s}pt\"%%>", "</dt>\n",
00133 NULL,
00134 "<dd%%{s>0} style=\"font-size:%{s}pt\"%%>", "</dd>\n",
00135 "<div style=\"margin-left:2em%%{s>0}; font-size:%{s}pt%%\">\n",
00136 "</div>\n",
00137 "<p%%{s>0} style=\"font-size:%{s}pt\"%%>", "</p>\n",
00138 "<table align=\"center\">\n", "</table>\n",
00139 "<tr>", "</tr>\n",
00140 "<th%%{s>0} style=\"font-size:%{s}pt\"%%>", "</th>\n",
00141 "<td%%{s>0} style=\"font-size:%{s}pt\"%%>", "</td>\n",
00142 "<hr />\n",
00143 "<b>", "</b>",
00144 "<i>", "</i>",
00145 "<u>", "</u>",
00146 "<sup>", "</sup>",
00147 "<sub>", "</sub>",
00148 "<tt>", "</tt>",
00149 "<a href=\"", "</a>", "\">", FALSE,
00150 "<img src=\"", "\" />", "\" alt=\"", FALSE, TRUE,
00151 NULL,
00152 NULL, NULL,
00153 NMEEncodeCharFunDict, (void *)xmlCharDict,
00154 NMEEncodeCharFunDict, (void *)xmlCharDict,
00155 70, NULL, NULL,
00156 NULL, NULL,
00157 NULL, NULL, NULL, NULL,
00158 NULL,
00159 NULL,
00160 NULL, NULL
00161 };
00162
00164 static NMEOutputFormat const NMEOutputFormatMediawiki =
00165 {
00166 " ",
00167 0,
00168 10,
00169 '%',
00170 "", "",
00171 6,
00172 "%%{l}=%%", "%%{l}=%%\n",
00173 "", "\n\n",
00174 "<br>",
00175 "", "\n",
00176 " ", "\n",
00177 "", "%%{l=1}\n%%",
00178 "%%{l}*%% ", "\n",
00179 "", "%%{l=1}\n%%",
00180 "%%{l}#%% ", "\n",
00181 "", "%%{l=1}\n%%",
00182 "%%{l};%% ", "\n",
00183 NULL,
00184 ": ", "\n",
00185 "", "%%{l=1}\n%%",
00186 "%%{l}:%% ", "\n",
00187 "{|\n", "|}\n",
00188 "|-\n", "",
00189 "!", "\n",
00190 "|", "\n",
00191 "----\n\n",
00192 "'''", "'''",
00193 "''", "''",
00194 "__", "__",
00195 "<sup>", "</sup>",
00196 "<sub>", "</sub>",
00197 "<code>", "</code>",
00198 "[", "]", "|", FALSE,
00199 "[[Image:", "]]", "|", FALSE, TRUE,
00200 NULL,
00201 NULL, NULL,
00202 NULL, NULL,
00203 NULL, NULL,
00204 65, NULL, NULL,
00205 NULL, NULL,
00206 NULL, NULL, NULL, NULL,
00207 NULL,
00208 NULL,
00209 NULL, NULL
00210 };
00211
00213 static NMEEncodeCharDict const jspwikiCharDict[] =
00214 {
00215 {'*', "~*"},
00216 {'#', "~#"},
00217 {'\\', "~\\"},
00218 {'_', "~_"},
00219 {'!', "~!"},
00220 {'{', "~{"},
00221 {'}', "~}"},
00222 {'~', "~~"},
00223 {0, NULL}
00224 };
00225
00227 static NMEOutputFormat const NMEOutputFormatJSPWiki =
00228 {
00229 " ",
00230 0,
00231 10,
00232 '?',
00233 "", "",
00234 3,
00235 "??{4-l}!?? ", "\n",
00236 "", "\n\n",
00237 "\\\\",
00238 "{{{\n", "}}}\n\n",
00239 "", "\n",
00240 "", "??{l=1}\n??",
00241 "??{l}*?? ", "\n",
00242 "", "??{l=1}\n??",
00243 "??{l}#?? ", "\n",
00244 "", "??{l=1}\n??",
00245 "%%(text-indent:?{20*l}px)\n__", ":__ ",
00246 "%%(text-indent:?{20*l}px)\n",
00247 "", "\n%%\n\n",
00248 "", "",
00249 "%%(text-indent:?{20*l}px)\n", "\n%%\n\n",
00250 "", "\n",
00251 "", "\n",
00252 "|| ", "",
00253 "| ", "",
00254 "----\n\n",
00255 "__", "__",
00256 "''", "''",
00257 "%%(text-decoration:underline)", "%%",
00258 "%%(vertical-align:sup)", "%%",
00259 "%%(vertical-align:sub)", "%%",
00260 "{{", "}}",
00261 "[", "]", "|", TRUE,
00262 "", "", NULL, FALSE, FALSE,
00263 NULL,
00264 NULL, NULL,
00265 NMEEncodeCharFunDict, (void *)jspwikiCharDict,
00266 NULL, NULL,
00267 65, NULL, NULL,
00268 NULL, NULL,
00269 NULL, NULL, NULL, NULL,
00270 NULL,
00271 NULL,
00272 NULL, NULL
00273 };
00274
00276 static NMEPluginTocData tocData;
00277
00279 static NMEPlugin const pluginsHTML[] =
00280 {
00281 NMEPluginReverseEntry,
00282 NMEPluginRot13Entry,
00283 NMEPluginUppercaseEntry,
00284 NMEPluginRawEntry("rawinpar", kNMEPluginOptDefault),
00285 NMEPluginRawEntry("rawoutpar", kNMEPluginOptBetweenPar),
00286 NMEPluginCalendarEntry,
00287 NMEPluginTOCEntry(&tocData),
00288
00289 NMEPluginTableEnd
00290 };
00291
00293 static NMEPlugin const plugins[] =
00294 {
00295 NMEPluginReverseEntry,
00296 NMEPluginRot13Entry,
00297 NMEPluginUppercaseEntry,
00298 NMEPluginCalendarEntry,
00299
00300 NMEPluginTableEnd
00301 };
00302
00304 static NMEAutoconvert autoconverts[16];
00305
00307 static NMEInterwiki const interwikis[] =
00308 {
00309 {"Dictionary:",
00310 "http://www.dict.org/bin/Dict?Database=*&Form=Dict1&Strategy=*&Query="},
00311 {"Foldoc:", "http://www.foldoc.org/foldoc/foldoc.cgi?"},
00312 {"Google:", "http://www.google.com/search?q="},
00313 {"WhoIs:", "http://www.whois.sc/"},
00314 {"WikiPedia:", "http://en.wikipedia.org/wiki/"},
00315 {NULL, NULL}
00316 };
00317
00319 typedef struct
00320 {
00321 NMEInt nesting;
00322 } HookDumpData;
00323
00325 static NMEErr hookDump(NMEInt level,
00326 NMEInt item,
00327 NMEBoolean enter,
00328 NMEConstText markup,
00329 NMEInt srcIndex,
00330 NMEContext *context,
00331 void *data)
00332 {
00333 if (!enter)
00334 ((HookDumpData *)data)->nesting--;
00335 printf("%*s", 2 * ((HookDumpData *)data)->nesting, " ");
00336 if (level > 0)
00337 printf("%-4s L%d %c %5d\n", markup, level, enter ? '<' : '>', srcIndex);
00338 else
00339 printf("%-4s %c %5d\n", markup, enter ? '<' : '>', srcIndex);
00340 if (enter)
00341 ((HookDumpData *)data)->nesting++;
00342 return kNMEErrOk;
00343 }
00344
00346 typedef struct
00347 {
00348 NMEInt index;
00349 NMEInt length;
00350 NMEConstText begin;
00351 NMEConstText end;
00352 NMEBoolean done;
00353 } HookEditData;
00354
00356 static NMEErr hookEdit(NMEInt level,
00357 NMEInt item,
00358 NMEBoolean enter,
00359 NMEConstText markup,
00360 NMEInt srcIndex,
00361 NMEContext *context,
00362 void *data)
00363 {
00364 HookEditData *hookEditData = (HookEditData *)data;
00365 NMEErr err;
00366
00367 if (!hookEditData->done
00368 && srcIndex >= hookEditData->index)
00369 {
00370 if (srcIndex < hookEditData->index + hookEditData->length)
00371 {
00372 if (!NMEAddString(hookEditData->begin, -1, '\0', context))
00373 return kNMEErrNotEnoughMemory;
00374 err = NMECopySource(hookEditData->length - (hookEditData->index - srcIndex),
00375 TRUE, TRUE, context);
00376 if (err != kNMEErrOk)
00377 return err;
00378 if (!NMEAddString(hookEditData->end, -1, '\0', context))
00379 return kNMEErrNotEnoughMemory;
00380 }
00381
00382 hookEditData->done = TRUE;
00383 }
00384 return kNMEErrOk;
00385 }
00386
00388 #define kHookCheckMaxDepth 256
00390 typedef struct
00391 {
00392 NMEInt lastSrcIndex;
00393 NMEInt depth;
00394 struct
00395 {
00396 NMEChar hook;
00397 NMEInt level;
00398 NMEInt item;
00399 NMEConstText markup;
00400 NMEInt srcIndex;
00401 } stack[kHookCheckMaxDepth];
00402 } HookCheckData;
00403
00405 static NMEErr hookCheck(NMEChar hook,
00406 NMEInt level,
00407 NMEInt item,
00408 NMEBoolean enter,
00409 NMEConstText markup,
00410 NMEInt srcIndex,
00411 HookCheckData *hookCheckData)
00412 {
00413 if (srcIndex < hookCheckData->lastSrcIndex)
00414 fprintf(stderr, "Last srcIndex = %d\n", hookCheckData->lastSrcIndex);
00415 else if (!enter && hookCheckData->depth <= 0)
00416 fprintf(stderr, "Outside any structure\n");
00417 else if (!enter
00418 && (hookCheckData->stack[hookCheckData->depth - 1].hook != hook
00419 || hookCheckData->stack[hookCheckData->depth - 1].level != level
00420 || hookCheckData->stack[hookCheckData->depth - 1].item != item
00421 || strcmp(hookCheckData->stack[hookCheckData->depth - 1].markup, markup)))
00422 {
00423 fprintf(stderr, "Nonmatching exit:\n");
00424 fprintf(stderr, " hook = %c, level = %d, item = %d, markup = \"%s\", srcIndex = %d\n",
00425 hookCheckData->stack[hookCheckData->depth - 1].hook,
00426 hookCheckData->stack[hookCheckData->depth - 1].level,
00427 hookCheckData->stack[hookCheckData->depth - 1].item,
00428 hookCheckData->stack[hookCheckData->depth - 1].markup,
00429 hookCheckData->stack[hookCheckData->depth - 1].srcIndex);
00430 }
00431 else if (enter && hookCheckData->depth >= kHookCheckMaxDepth)
00432 fprintf(stderr, "Nesting too deep\n");
00433 else if (enter)
00434 {
00435 hookCheckData->stack[hookCheckData->depth].hook = hook;
00436 hookCheckData->stack[hookCheckData->depth].level = level;
00437 hookCheckData->stack[hookCheckData->depth].item = item;
00438 hookCheckData->stack[hookCheckData->depth].markup = markup;
00439 hookCheckData->stack[hookCheckData->depth].srcIndex = srcIndex;
00440 hookCheckData->depth++;
00441 return kNMEErrOk;
00442 }
00443 else
00444 {
00445 hookCheckData->depth--;
00446 return kNMEErrOk;
00447 }
00448
00449 fprintf(stderr, "Hook = %c, level = %d, item = %d, %s, markup = \"%s\", srcIndex = %d\n",
00450 hook, level, item, enter ? "enter" : "exit", markup, srcIndex);
00451
00452 return kNMEErrInternal;
00453 }
00454
00456 static NMEErr divHookCheck(NMEInt level,
00457 NMEInt item,
00458 NMEBoolean enter,
00459 NMEConstText markup,
00460 NMEInt srcIndex,
00461 NMEContext *context,
00462 void *data)
00463 {
00464 return hookCheck('d', level, item, enter, markup, srcIndex, (HookCheckData *)data);
00465 }
00466
00468 static NMEErr parHookCheck(NMEInt level,
00469 NMEInt item,
00470 NMEBoolean enter,
00471 NMEConstText markup,
00472 NMEInt srcIndex,
00473 NMEContext *context,
00474 void *data)
00475 {
00476 return hookCheck('p', level, item, enter, markup, srcIndex, (HookCheckData *)data);
00477 }
00478
00480 static NMEErr spanHookCheck(NMEInt level,
00481 NMEInt item,
00482 NMEBoolean enter,
00483 NMEConstText markup,
00484 NMEInt srcIndex,
00485 NMEContext *context,
00486 void *data)
00487 {
00488 return hookCheck('s', level, item, enter, markup, srcIndex, (HookCheckData *)data);
00489 }
00490
00495
00496 NMEErr encodeURLEasylink(NMEConstText link, NMEInt linkLen,
00497 NMEContext *context, void *data)
00498 {
00499 NMEInt i, j;
00500 NMEConstText format = (NMEConstText)data;
00501 #define isAlphaNum(c) \
00502 ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z' \
00503 || (c) >= '0' && (c) <= '9')
00504 #define toHexa(d) \
00505 ((d) >= 10 ? (d) + ('a' - 10) : (d) + '0')
00506
00507
00508 for (i = 0; i < linkLen && isAlphaNum(link[i]); i++)
00509 ;
00510 if (i < linkLen && link[i] == ':')
00511 {
00512
00513 if (!NMEAddString(link, linkLen, 0, context))
00514 return kNMEErrNotEnoughMemory;
00515 return kNMEErrOk;
00516 }
00517
00518 for (i = 0; format[i]; i++)
00519 if (format[i] == '$')
00520 {
00521 for (j = 0; j < linkLen; j++)
00522 if (isAlphaNum(link[j]) || link[j] == '-' || link[j] == ',' || link[j] == '.'
00523 || link[j] == '\'' || link[j] == '(' || link[j] == ')'
00524 || link[j] == ':')
00525 {
00526 if (!NMEAddString(&link[j], 1, 0, context))
00527 return kNMEErrNotEnoughMemory;
00528 }
00529 else if (link[j] == '_' || link[j] == ' ')
00530 {
00531 if (!NMEAddString("_", 1, 0, context))
00532 return kNMEErrNotEnoughMemory;
00533 }
00534 else if (link[j] & 0x80)
00535 {
00536 char e[3];
00537 e[0] = '%';
00538 e[1] = toHexa((link[j] >> 4) & 0x0f);
00539 e[2] = toHexa(link[j] & 0x0f);
00540 if (!NMEAddString(e, 3, 0, context))
00541 return kNMEErrNotEnoughMemory;
00542 }
00543 }
00544 else if (!NMEAddString(&format[i], 1, 0, context))
00545 return kNMEErrNotEnoughMemory;
00546
00547 return kNMEErrOk;
00548 }
00549
00551 int main(int argc, char **argv)
00552 {
00553 NMEText src = NULL, buf, dest;
00554 NMEInt srcLen, destLen;
00555 NMEOutputFormat outputFormat = NMEOutputFormatHTML;
00556 NMEInt options = kNMEProcessOptDefault;
00557 NMEBoolean autoURLLink = FALSE, autoCCLink = FALSE;
00558 int i;
00559 int fontSize = 0;
00560 HookDumpData hookDumpData;
00561 HookTOCData hookTOCData;
00562 HookEditData hookEditData;
00563 HookCheckData hookCheckData;
00564 NMEErr err;
00565
00566 outputFormat.plugins = pluginsHTML;
00567
00568 for (i = 1; i < argc; i++)
00569 if (!strcmp(argv[i], "--body"))
00570 options |= kNMEProcessOptNoPreAndPost;
00571 else if (!strcmp(argv[i], "--1eol"))
00572 options |= kNMEProcessOptNoMultilinePar;
00573 else if (!strcmp(argv[i], "--2eol"))
00574 options &= ~kNMEProcessOptNoMultilinePar;
00575 else if (!strcmp(argv[i], "--xref"))
00576 options |= kNMEProcessOptXRef;
00577 else if (!strcmp(argv[i], "--autocclink"))
00578 autoCCLink = TRUE;
00579 else if (!strcmp(argv[i], "--autourllink"))
00580 autoURLLink = TRUE;
00581 else if (!strcmp(argv[i], "--nme"))
00582 {
00583 outputFormat = NMEOutputFormatNME;
00584 outputFormat.plugins = plugins;
00585 }
00586 else if (!strcmp(argv[i], "--html"))
00587 {
00588 outputFormat = NMEOutputFormatHTML;
00589 outputFormat.plugins = pluginsHTML;
00590 }
00591 else if (!strcmp(argv[i], "--slides"))
00592 {
00593 outputFormat = NMEOutputFormatSlidesHTML;
00594 outputFormat.plugins = pluginsHTML;
00595 }
00596 else if (!strcmp(argv[i], "--jspwiki"))
00597 {
00598 outputFormat = NMEOutputFormatJSPWiki;
00599 outputFormat.plugins = plugins;
00600 }
00601 else if (!strcmp(argv[i], "--latex"))
00602 {
00603 outputFormat = NMEOutputFormatLaTeX;
00604 outputFormat.plugins = plugins;
00605 }
00606 else if (!strcmp(argv[i], "--mediawiki"))
00607 {
00608 outputFormat = NMEOutputFormatMediawiki;
00609 outputFormat.plugins = plugins;
00610 }
00611 else if (!strcmp(argv[i], "--null"))
00612 {
00613 outputFormat = NMEOutputFormatNull;
00614 outputFormat.plugins = NULL;
00615 }
00616 else if (!strcmp(argv[i], "--rtf"))
00617 {
00618 outputFormat = NMEOutputFormatRTF;
00619 outputFormat.plugins = plugins;
00620 }
00621 else if (!strcmp(argv[i], "--editfrag") && i + 4 < argc)
00622 {
00623 outputFormat.parHookFun = hookEdit;
00624 hookEditData.index = strtol(argv[++i], NULL, 0);
00625 hookEditData.length = strtol(argv[++i], NULL, 0);
00626 hookEditData.begin = argv[++i];
00627 hookEditData.end = argv[++i];
00628 hookEditData.done = FALSE;
00629 outputFormat.hookData = (void *)&hookEditData;
00630 }
00631 else if (!strcmp(argv[i], "--structpar"))
00632 {
00633 outputFormat = NMEOutputFormatNull;
00634 outputFormat.parHookFun = hookDump;
00635 outputFormat.divHookFun = NULL;
00636 hookDumpData.nesting = 0;
00637 outputFormat.hookData = (void *)&hookDumpData;
00638 }
00639 else if (!strcmp(argv[i], "--structdiv"))
00640 {
00641 outputFormat = NMEOutputFormatNull;
00642 outputFormat.parHookFun = NULL;
00643 outputFormat.divHookFun = hookDump;
00644 hookDumpData.nesting = 0;
00645 outputFormat.hookData = (void *)&hookDumpData;
00646 }
00647 else if (!strcmp(argv[i], "--checkhooks"))
00648 {
00649 outputFormat = NMEOutputFormatNull;
00650 outputFormat.divHookFun = divHookCheck;
00651 outputFormat.parHookFun = parHookCheck;
00652 outputFormat.spanHookFun = spanHookCheck;
00653 hookCheckData.lastSrcIndex = 0;
00654 hookCheckData.depth = 0;
00655 outputFormat.hookData = (void *)&hookCheckData;
00656 }
00657 else if (!strcmp(argv[i], "--easylink"))
00658 {
00659 outputFormat.encodeURLFun = encodeURLEasylink;
00660 outputFormat.encodeURLData = argv[++i];
00661 }
00662 else if (!strcmp(argv[i], "--text"))
00663 {
00664 outputFormat = NMEOutputFormatText;
00665 outputFormat.plugins = plugins;
00666 }
00667 else if (!strcmp(argv[i], "--textc"))
00668 {
00669 outputFormat = NMEOutputFormatTextCompact;
00670 outputFormat.plugins = plugins;
00671 }
00672 else if (!strcmp(argv[i], "--man"))
00673 {
00674 outputFormat = NMEOutputFormatMan;
00675 outputFormat.plugins = plugins;
00676 }
00677 else if (!strcmp(argv[i], "--fontsize") && i + 1 < argc)
00678 fontSize = strtol(argv[++i], NULL, 0);
00679 else if (!strcmp(argv[i], "--headernum1"))
00680 options |= kNMEProcessOptH1Num;
00681 else if (!strcmp(argv[i], "--headernum2"))
00682 options |= kNMEProcessOptH2Num;
00683 else if (!strcmp(argv[i], "--strictcreole"))
00684 options |= kNMEProcessOptNoUnderline | kNMEProcessOptNoMonospace
00685 | kNMEProcessOptNoSubSuperscript | kNMEProcessOptNoIndentedPar
00686 | kNMEProcessOptNoDL | kNMEProcessOptVerbatimMono;
00687 else if (!strcmp(argv[i], "--toc"))
00688 NMESetTOCOutputFormat(&outputFormat, &hookTOCData);
00689 else
00690 {
00691 if (strcmp(argv[i], "--help"))
00692 fprintf(stderr, "Unknown option %s\n", argv[i]);
00693 fprintf(stderr, "Usage: %s [options]\n"
00694 "Filter NME stdin and renders it to another format.\n"
00695 "--1eol single eol as paragraph breaks\n"
00696 "--2eol double eol as paragraph breaks (default)\n"
00697 "--autocclink automatic conversion of camelCase words to links\n"
00698 "--autourllink automatic conversion of URLs to links\n"
00699 "--body naked body without header and footer\n"
00700 "--checkhooks check hooks\n"
00701 "--easylink format links are converted as follows: letters, digits,\n"
00702 " hyphens commas, dots, apostrophes, parentheses,\n"
00703 " colons and underscores are preserved, spaces are\n"
00704 " converted to underscores, non-ascii characters are\n"
00705 " URL-encoded, other characters are ignored, and the\n"
00706 " output link is obtained by replacing the dollar\n"
00707 " character in format with the processed link (e.g.\n"
00708 " format could be '/wiki/$.html').\n"
00709 " URL are used verbatim.\n"
00710 "--editfrag i l b e edit a fragment of the source code; in output,\n"
00711 " replace what corresponds to input fragment starting\n"
00712 " at i of length l with this unmodified input fragment\n"
00713 " surrounded by b and e\n"
00714 "--headernum1 numbering of level-1 headers\n"
00715 "--headernum2 numbering of level-2 headers\n"
00716 "--fontsize s font size (0=default)\n"
00717 "--help this help message\n"
00718 "--html HTML output (default)\n"
00719 "--jspwiki JSPWiki output\n"
00720 "--latex LaTeX output\n"
00721 "--man man page output\n"
00722 "--mediawiki MediaWiki output\n"
00723 "--nme NME output\n"
00724 "--null no output (still process input)\n"
00725 "--strictcreole disable monospace, underline, subscript,\n"
00726 " superscript, definition lists, and indented\n"
00727 " paragraphs; and enable nowiki monospace\n"
00728 "--structdiv display division structure\n"
00729 "--structpar display paragraph structure\n"
00730 "--rtf RTF output\n"
00731 "--slides HTML slides output\n"
00732 "--text plain text output\n"
00733 "--textc compact plain text output\n"
00734 "--xref headings have hyperlink target labels\n",
00735 argv[0]);
00736 exit(0);
00737 }
00738
00739 outputFormat.interwikis = interwikis;
00740 if (autoCCLink || autoURLLink)
00741 {
00742 int n = 0;
00743
00744 if (autoCCLink)
00745 autoconverts[n++].cb = NMEAutoconvertCamelCase;
00746 if (autoURLLink)
00747 autoconverts[n++].cb = NMEAutoconvertURL;
00748
00749 outputFormat.autoconverts = autoconverts;
00750 }
00751
00752 src = malloc(SIZE);
00753 if (!src)
00754 exit(1);
00755 srcLen = fread(src, 1, SIZE, stdin);
00756 if (srcLen < 0)
00757 {
00758 free(src);
00759 exit(2);
00760 }
00761
00762 buf = malloc(SIZE);
00763 if (!buf)
00764 exit(1);
00765
00766 tocData.src = src;
00767 tocData.srcLen = srcLen;
00768
00769 err = NMEProcess(src, srcLen,
00770 buf, SIZE,
00771 options, "\n", &outputFormat, fontSize,
00772 &dest, &destLen, NULL);
00773
00774 if (err == kNMEErrOk)
00775 printf("%.*s", destLen, dest);
00776 else
00777 printf("Error %d\n", err);
00778
00779 free((void *)buf);
00780 free((void *)src);
00781
00782 return 0;
00783 }