From fb034884ace42e8b0041c155bb93286d9ca504f2 Mon Sep 17 00:00:00 2001 From: Scott Kostyshak Date: Tue, 3 Dec 2013 02:15:08 -0500 Subject: [PATCH] Fix noweb2lyx, Literate, and listerrors examples This is a manual lyx2lyx fix. Some of the problematic chunks are not correctly converted with lyx2lyx so this commit manually converts them to ERT. For more details, see: http://marc.info/?t=137702744100010&r=1&w=2 --- development/autotests/revertedTests | 6 - lib/examples/Literate.lyx | 1330 ++++++++++++++++++--------- lib/examples/listerrors.lyx | 680 +++++++++----- lib/examples/noweb2lyx.lyx | 788 ++++++++++------ 4 files changed, 1823 insertions(+), 981 deletions(-) diff --git a/development/autotests/revertedTests b/development/autotests/revertedTests index 1105ebe471..2249fcd706 100644 --- a/development/autotests/revertedTests +++ b/development/autotests/revertedTests @@ -41,12 +41,6 @@ export/examples/hu/example_raw_dvi3 export/examples/hu/splash_pdf5 export/examples/hu/splash_dvi3 # -export/examples/Literate_pdf -export/examples/Literate_pdf2 -export/examples/Literate_pdf5 -export/examples/noweb2lyx_pdf -export/examples/noweb2lyx_pdf2 -export/examples/noweb2lyx_pdf5 export/examples/es/europeCV_pdf5 export/examples/fa/splash_pdf5 # See http://www.lyx.org/trac/ticket/8823 diff --git a/lib/examples/Literate.lyx b/lib/examples/Literate.lyx index bcf37a358d..050963611c 100644 --- a/lib/examples/Literate.lyx +++ b/lib/examples/Literate.lyx @@ -1,5 +1,5 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 448 +\lyxformat 474 \begin_document \begin_header \textclass article @@ -34,13 +34,16 @@ noweb \use_geometry false \use_package amsmath 0 \use_package amssymb 0 +\use_package cancel 0 \use_package esint 0 \use_package mathdots 1 \use_package mathtools 0 \use_package mhchem 1 +\use_package stackrel 0 +\use_package stmaryrd 0 \use_package undertilde 0 \cite_engine basic -\cite_engine_type numerical +\cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false @@ -172,132 +175,180 @@ The filter is required to read from standard input, parse for error messages Algorithm \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function bodies \end_layout -\begin_layout Chunk +\end_inset + int \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + main (int argc, char **argv) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (argc == 2) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + switch (argv[1][0]) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + case 'n': \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + case 'x': \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + case 'a': \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + case 's': \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + case 'b': \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + case 'g': \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + default: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function prototypes \end_layout -\begin_layout Chunk +\end_inset + int main (int argc, char **argv); \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Section @@ -311,28 +362,38 @@ We resort to some global variables to allow access from several different input. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char buffer[200][200]; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout int last_buf_line; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout int last_err_line; -\begin_inset Newline newline +\end_layout + +\begin_layout Plain Layout + +int err_line;@ +\end_layout + \end_inset -int err_line; -\begin_inset Newline newline -\end_inset -@ \end_layout \begin_layout Section @@ -363,37 +424,53 @@ This function has been slightly changed from EW's original to make scanning \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function bodies \end_layout -\begin_layout Chunk +\end_inset + void \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + output_error (int buf_size, int error_line, char *tool) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + int i; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + fprintf(stdout, "! Build Error: ==> %s ==> \backslash n", tool); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + fprintf(stdout, " ... \backslash n @@ -403,50 +480,69 @@ nl.%d ... n", error_line); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + for (i=0; i>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function prototypes \end_layout -\begin_layout Chunk +\end_inset + void output_error (int buf_size, int error_line, char *tool); \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Section @@ -462,40 +558,57 @@ Both noweave and notangle routines, always output one single line for each of the file. \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Scan input for noweb error messages \end_layout -\begin_layout Chunk +\end_inset + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + while (fgets(buffer[0], 200, stdin)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (noweb_try(0)) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + output_error(1, err_line, "noweb"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -507,88 +620,111 @@ The examination itself is very inefficient. array. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char *noweb_msgs[] = { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "couldn't open file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "couldn't open temporary file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "error writing temporary file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "ill-formed option", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "unknown option", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "Bad format sequence", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "Can't open output file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "Can't open temporary file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "Capacity exceeded:", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "Ignoring unknown option -", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "This can't happen:", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + "non-numeric line number in" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + }; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char *noweb_msgs_mimic_gcc[] = { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + ": unescaped << in documentation chunk" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + }; \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -608,214 +744,279 @@ A noweb error message can be any string that contains a matching pair of > >, or any of the above strings \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout + +<>= +\end_layout + +\begin_layout Plain Layout + +int noweb_try (int buf_line) +\end_layout + +\begin_layout Plain Layout + +{ +\end_layout + +\begin_layout Plain Layout + + char *s, *t, *b; +\end_layout + +\begin_layout Plain Layout + + int i; +\end_layout + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk -<>= -\begin_inset Newline newline -\end_inset - -int -\begin_inset Newline newline -\end_inset - -noweb_try (int buf_line) -\begin_inset Newline newline -\end_inset - -{ -\begin_inset Newline newline -\end_inset - - char *s, *t, *b; -\begin_inset Newline newline -\end_inset - - int i; -\begin_inset Newline newline -\end_inset - - -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout b = buffer[buf_line]; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout err_line = 0; -\begin_inset Newline newline -\end_inset +\end_layout +\begin_layout Plain Layout -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout for (i=0; i<1; i++) { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout s = (char *)strstr (b, noweb_msgs_mimic_gcc[i]); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if (s != NULL) { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout t = (char *)strchr(buffer[buf_line], ':'); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout err_line = atoi(t+1); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout t = buffer[buf_line]; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout ++s; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout while (*(t++) = *(s++)); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout return 1; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout s = (char *)strstr(b, "<<"); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if (s != NULL) { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout s = (char *)strstr(s+2, ">>"); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if (s != NULL) { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout return 1; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } else { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout for (i = 0; i < 12; ++i) { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout s = (char *)strstr (b, noweb_msgs[i]); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if (s != NULL) { -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout return 1; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout return 0; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout -\begin_layout Chunk +\end_inset + + +\end_layout + +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + int noweb_try (int buf_line); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard The xlc compiler always outputs one single line for each error found, thus to scan the buffer for xlc error messages it is enough to exam one input line at a time. \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Scan input for xlc error messages \end_layout -\begin_layout Chunk +\end_inset + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + while (fgets(buffer[last_buf_line], 200, stdin)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (xlc_try(0)) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + output_error(1, err_line, "xlc"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -833,94 +1034,126 @@ line The following routine tests if a given buffer line matches this criteria: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + int \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + xlc_try (int buf_line) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char *s, *t; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + t = buffer[buf_line]; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + s = t+1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + while (*s != '"' && *s != ' ' && *s != ' \backslash 0') \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + s++; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (*t != '"' || *s != '"' || strncmp(s+1, ", line ", 7) != 0) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + return 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + s += 8; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + err_line = atoi(s); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + return 1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function prototypes \end_layout -\begin_layout Chunk +\end_inset + int xlc_try (int buf_line); \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -959,210 +1192,246 @@ Every gcc error message contains a string with no space followed by a . \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Scan input for gcc error messages \end_layout -\begin_layout Chunk +\end_inset + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char *s, *t; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + while (fgets(buffer[last_buf_line], 200, stdin)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** Skip lines until I find an error */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + s = (char *)strpbrk(buffer[last_buf_line], " :"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (s == NULL || *s == ' ') \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + continue; /* No gcc error found here */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + do { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** OK It is an error message, get line number */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + err_line = atoi(s+1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (last_err_line == 0 || last_err_line == err_line) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_err_line = err_line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + continue; /* It's either a header or a continuation, don't output yet */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** Completed the scan of one error message, output it to LyX */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + discharge_buffer(1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } while (fgets(buffer[last_buf_line], 200, stdin)); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** EOF completes the scan of whatever was being scanned */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + discharge_buffer(0); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +gcc error message criteria is to find a "...:999:" or a "...: " \end_layout -\begin_layout Chunk +\end_inset + /****** Search first ":" in the error number */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + s = (char *)strpbrk(buffer[last_buf_line], " :"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line++; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (s == NULL || *s == ' ') \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** Search second ":" in the error number */ \end_layout -\begin_layout Chunk -t = (char *)strpbrk(s+1, " :"); -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout -if (t == NULL || *t == ' ') -\begin_inset Newline newline -\end_inset - - <> -\begin_inset Newline newline -\end_inset - -/****** Verify if is all digits between ":" */ -\begin_inset Newline newline -\end_inset - -if (t != s+1+strspn(s+1, "0123456789")) -\begin_inset Newline newline -\end_inset - - <> -\begin_inset Newline newline -\end_inset - -@ +t = (char *)strpbrk(s+1, " :");if (t == NULL || *t == ' ') <>/****** + Verify if is all digits between ":" */if (t != s+1+strspn(s+1, "0123456789")) + <>@ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + err_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + discharge_buffer(1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + continue; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -1181,108 +1450,144 @@ last line In those cases we empty the buffer completely. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + void \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + discharge_buffer (int save_last) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (last_err_line != 0) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + clean_gcc_messages(); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (save_last != 0) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + output_error(last_buf_line-1, last_err_line, "gcc"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + strcpy (buffer[0], buffer[last_buf_line-1]); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_err_line = err_line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + ++last_buf_line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + clean_gcc_messages(); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + output_error(last_buf_line-1, last_err_line, "gcc"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_err_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function prototypes \end_layout -\begin_layout Chunk +\end_inset + void discharge_buffer (int save_last); \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -1310,120 +1615,165 @@ More could be done. \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function bodies \end_layout -\begin_layout Chunk +\end_inset + void \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + clean_gcc_messages () \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + int index; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char search [30]; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char *tail, *head; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + int search_len = sprintf(search, ".nw:%d:", last_err_line); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + for (index = 0; index < last_buf_line-1; index++) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + tail = (char *)strstr (buffer[index], search); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if ( tail == NULL) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + tail = (char *) strstr (buffer[index], ".nw:"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (tail) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + tail += 4; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + tail += search_len; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (tail != NULL) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + head = buffer[index]; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + while (*(head++) = *(tail++)); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Function prototypes \end_layout -\begin_layout Chunk +\end_inset + void clean_gcc_messages (); \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -1432,50 +1782,70 @@ To combine the scan of noweb error messages and xlc error messages is very We just try each one for every input line: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout + <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 0; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout while (fgets(buffer[0], 200, stdin)) { -\begin_inset Newline newline -\end_inset +\end_layout - if (noweb_try(0)) -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout - output_error(1, err_line, "noweb"); -\begin_inset Newline newline -\end_inset + if (noweb_try(0)) +\end_layout - else if (xlc_try(0)) -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout - output_error(1, err_line, "xlc"); -\begin_inset Newline newline -\end_inset + output_error(1, err_line, "noweb"); +\end_layout - } -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout + + else if (xlc_try(0)) +\end_layout + +\begin_layout Plain Layout + + output_error(1, err_line, "xlc"); +\end_layout + +\begin_layout Plain Layout + + } +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard To combine the scan of noweb error messages and gcc error messages is simple if we realize that it is not possible to find a noweb error message in @@ -1484,166 +1854,221 @@ To combine the scan of noweb error messages and gcc error messages is simple the beginning of the scan: \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Solaris and Linux systems using both noweb and gcc \end_layout -\begin_layout Chunk +\end_inset + { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + char *s, *t; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_buf_line = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + while (fgets(buffer[last_buf_line], 200, stdin)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** Skip lines until I find an error */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (last_buf_line == 0 && noweb_try(0)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + output_error(1, err_line, "noweb"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + continue; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + s = (char *)strpbrk(buffer[last_buf_line], " :"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (s == NULL || *s == ' ') \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + continue; /* No gcc error found here */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + do { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** OK It is an error, get line number */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + err_line = atoi(s+1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if (last_err_line == 0 || last_err_line == err_line) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + last_err_line = err_line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + continue; /* It's either a header or a continuation, don't output yet */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** Completed the scan of one error message, output it to LyX */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + discharge_buffer(1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + break; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } while (fgets(buffer[last_buf_line], 200, stdin)); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + /****** EOF completes the scan of whatever was being scanned */ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + discharge_buffer(0); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + } \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Section Wrapping the code into a file \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +listerrors.c \end_layout -\begin_layout Chunk +\end_inset + #include \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + #include \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + <> \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard @@ -1675,32 +2100,47 @@ listerrors.c option to gcc. \end_layout -\begin_layout Chunk -<>= +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +build-script \end_layout -\begin_layout Chunk +\end_inset + #!/bin/sh \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if [ -z "$NOWEB_SOURCE" ]; then NOWEB_SOURCE=Literate.nw; fi \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + if [ -z "$NOWEB_OUTPUT_DIR" ]; then NOWEB_OUTPUT_DIR=.; fi \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + notangle -L -Rlisterrors.c ${NOWEB_SOURCE} > ${NOWEB_OUTPUT_DIR}/listerrors.c \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + gcc -g -o listerrors listerrors.c \end_layout -\begin_layout Chunk -@ +\end_inset + + \end_layout \begin_layout Standard diff --git a/lib/examples/listerrors.lyx b/lib/examples/listerrors.lyx index e3628d00ad..aed3ecb92e 100644 --- a/lib/examples/listerrors.lyx +++ b/lib/examples/listerrors.lyx @@ -1,5 +1,5 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 448 +\lyxformat 474 \begin_document \begin_header \textclass article @@ -48,13 +48,16 @@ noweb \use_geometry false \use_package amsmath 0 \use_package amssymb 0 +\use_package cancel 0 \use_package esint 0 \use_package mathdots 1 \use_package mathtools 0 \use_package mhchem 1 +\use_package stackrel 0 +\use_package stmaryrd 0 \use_package undertilde 0 \cite_engine basic -\cite_engine_type numerical +\cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false @@ -314,118 +317,127 @@ listerrors available for all other platforms. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout #!/usr/bin/python -tt \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """reformat noweb and compiler errors for LyX. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout Expects to read from stdin and output to stdout. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout __author__ = "Kayvan A. Sylvan " \end_layout -\begin_layout Chunk +\begin_layout Plain Layout __date__ = "$Date: 2005/07/18 09:42:26 $" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout __version__ = "$Revision: 1.5 $" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout __credits__ = """Edmar Wienskoski Jr. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout original Literate support for LyX. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout Bernard Michael Hurley \end_layout -\begin_layout Chunk +\begin_layout Plain Layout modifications to original listerrors.""" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout __copyright__ = "Copyright 2002 - Kayvan Sylvan." \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout import sys, string \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if __name__ == "__main__": \end_layout -\begin_layout Chunk +\begin_layout Plain Layout main() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Section LaTeX style error message \end_layout @@ -434,40 +446,46 @@ LaTeX style error message The following function mimics the TeX error message format. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def write_error(msg, tool = "noweb", line_number = 1): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """Write out the given message in TeX error style. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout called like: write_error(msg, tool, line_number).""" -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout print "! Build Error: ==> %s ==> \backslash n" % (tool), -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout print " ... \backslash @@ -476,40 +494,52 @@ n nl.%d ... \backslash n" % (line_number), -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if type(msg) == type("str"): # simple string -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout print msg -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout else: # some kind of list (sequence or tuple) -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout for m in msg: -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if m != "": print m, -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout print -\begin_inset Newline newline -\end_inset +\end_layout +\begin_layout Plain Layout -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ %def write_error \end_layout +\end_inset + + +\end_layout + \begin_layout Section Filtering errors \end_layout @@ -536,127 +566,148 @@ pushline set of functions: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout __lines = [] # lines pushed back \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def getline(file = sys.stdin): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """read a line from internal stack or from file. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout optional file argument defaults to sys.stdin.""" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout global __lines \end_layout -\begin_layout Chunk +\begin_layout Plain Layout lines = __lines \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if lines: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout line = lines.pop() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout else: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout line = file.readline() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout return line \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def getline \end_layout +\end_inset + + +\end_layout + \begin_layout Standard And now for the corresponding pushline function: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def pushline(line): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "push a line onto the pushback stack." \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout global __lines -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout lines = __lines -\begin_inset Newline newline -\end_inset +\end_layout - lines.append(line) -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout +lines.append(line) +\end_layout -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout + +\end_layout + +\begin_layout Plain Layout @ %def pushline \end_layout +\end_inset + + +\end_layout + \begin_layout Standard The main() entry point function is extremely simple. Note that this version of @@ -674,92 +725,113 @@ listerrors \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def main(): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """Entry point for listerrors. Takes no options. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout Reads stdin and writes to stdout. Filter errors""" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout while 1: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout line = getline() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if line == "": break \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def main \end_layout +\end_inset + + +\end_layout + \begin_layout Standard For each line read in, we need to find out if it matches any of our tools (noweb, gcc, etc.) and act accordingly. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout try_patterns_dispatch = [ noweb_try, gcc_try, xlc_try ] -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout for predicate in try_patterns_dispatch: -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if predicate(line): break -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Section Different Error Formats \end_layout @@ -779,65 +851,74 @@ Noweb errors are output on a single line, so examining just the current line is enough. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def noweb_try(line): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """see if line is a noweb error. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout Returns 1 on success, 0 otherwise. Outputs on stdout.""" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 0 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout return retval \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def noweb_try \end_layout +\end_inset + + +\end_layout + \begin_layout Standard First, we look for the \begin_inset Quotes eld @@ -851,214 +932,247 @@ unescaped < < in documentation chunk This is the only message with an associated line number from noweb. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if string.find(line, ": unescaped << in documentation chunk") != -1: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout line_parts = string.split(line, ':') \end_layout -\begin_layout Chunk +\begin_layout Plain Layout num_str = line_parts[1] \end_layout -\begin_layout Chunk +\begin_layout Plain Layout num_len = len(num_str) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout i = 0 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout while i < num_len and (num_str[i] in string.digits): i = i + 1 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if i == num_len: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout write_error(":" + line_parts[2], "noweb", int(num_str)) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 1 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard Some noweb messages are simply about undefined chunks. These can be seen by looking for matching double-angle-brackets. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (not retval): -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout left = string.find(line, "<<") -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if (left != -1) and ((left + 2) < len(line)) and \backslash -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout (string.find(line[left+2:], ">>") != -1): -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout write_error(line, "noweb"); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout retval = 1; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard Finally, here is an additional list of explicit strings to check for. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (not retval): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout msgs_to_try = ("couldn't open file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "couldn't open temporary file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "error writing temporary file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "ill-formed option", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "unknown option", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "Bad format sequence", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "Can't open output file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "Can't open temporary file", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "Capacity exceeded:", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "Ignoring unknown option -", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "This can't happen:", \end_layout -\begin_layout Chunk +\begin_layout Plain Layout "non-numeric line number in") \end_layout -\begin_layout Chunk +\begin_layout Plain Layout for msg in msgs_to_try: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if string.find(line, msg) != -1: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout write_error(line, "noweb") \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 1 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout break \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Subsection gcc errors \end_layout @@ -1071,224 +1185,276 @@ The gcc errors can be multi-line, with the following format: foo.c: In function `main': \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout foo.c:3: `bar' undeclared (first use in this function) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout foo.c:3: (Each undeclared identifier is reported only once \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout foo.c:3: for each function it appears in.) -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout foo.c:3: parse error before `x' \end_layout +\end_inset + + +\end_layout + \begin_layout Standard In order to parse this, the gcc error handler has to look ahead and return any and all lines that do not match the expected pattern. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def gcc_try(line): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """See if line is a gcc error. Read ahead to handle all the lines. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout Returns 1 on success, 0 otherwise. Outputs on stdout.""" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 0 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout return retval \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def gcc_try \end_layout +\end_inset + + +\end_layout + \begin_layout Standard The error message starts with a gcc header (as above) without an associated line number. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout first_space = string.find(line, ' ') -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if first_space > 1: # The smallest would be "X: " -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if line[first_space - 1] == ':': -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout header_to_see = line[:first_space - 1] -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout next_line = getline() -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if next_line and next_line[:first_space - 1] == header_to_see: -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout num_end = first_space -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout while next_line[num_end] in string.digits: num_end = num_end + 1 -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if num_end > first_space: # good! -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout <> -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout else: # oops! Not a gcc error. -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout pushline(next_line) -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout elif next_line: -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout pushline(next_line) # return this line to input stream -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard At the point in the code that we know that we are in the middle of an error message, we do the following: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout num_str = next_line[first_space:num_end] \end_layout -\begin_layout Chunk +\begin_layout Plain Layout msgs = [line[first_space:]] \end_layout -\begin_layout Chunk +\begin_layout Plain Layout msgs.append(next_line[num_end + 1:]) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout header_to_see = next_line[:num_end] \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next_line = getline() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout while next_line and next_line[:num_end] == header_to_see: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout msgs.append(next_line[num_end + 1:]) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next_line = getline() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if next_line: pushline(next_line) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout write_error(msgs, "gcc", int(num_str)) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 1 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Subsection xlc errors \end_layout @@ -1319,110 +1485,119 @@ re \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout def xlc_try(line): \end_layout -\begin_layout Chunk +\begin_layout Plain Layout """see if line is an xlc error. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout Returns 1 on success, 0 otherwise. Outputs on stdout.""" \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 0 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if line[0] == '"': # This is the first character of all xlc errors \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next_quote = string.find(line, '"', 1) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout first_space = string.find(line, ' ') \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (next_quote != -1) and (first_space > next_quote): # no space inisde quotes \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if line[first_space - 1:first_space + 6] == ", line ": \end_layout -\begin_layout Chunk +\begin_layout Plain Layout num_start = num_end = first_space + 6 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout while line[num_end] in string.digits: num_end = num_end + 1 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if num_end > num_start: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout write_error(line, "xlc", int(line[num_start : num_end])) \end_layout -\begin_layout Chunk +\begin_layout Plain Layout retval = 1 \end_layout -\begin_layout Chunk +\begin_layout Plain Layout return retval \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def xlc_try \end_layout +\end_inset + + +\end_layout + \begin_layout Section Extracting the code \end_layout @@ -1456,41 +1631,50 @@ notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$2 sh This section defines our build-script, which extracts the code. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout #!/bin/sh \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if [ -z "$NOWEB_SOURCE" ]; then NOWEB_SOURCE=listerrors.nw; fi \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if [ -z "$NOWEB_OUTPUT_DIR" ]; then NOWEB_OUTPUT_DIR=.; fi \end_layout -\begin_layout Chunk +\begin_layout Plain Layout notangle -Rlisterrors ${NOWEB_SOURCE} > ${NOWEB_OUTPUT_DIR}/listerrors \end_layout -\begin_layout Chunk +\begin_layout Plain Layout chmod +x ${NOWEB_OUTPUT_DIR}/listerrors \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Section Indices \end_layout diff --git a/lib/examples/noweb2lyx.lyx b/lib/examples/noweb2lyx.lyx index 9c4b723124..c951a89b5b 100644 --- a/lib/examples/noweb2lyx.lyx +++ b/lib/examples/noweb2lyx.lyx @@ -1,5 +1,5 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 448 +\lyxformat 474 \begin_document \begin_header \textclass article @@ -44,13 +44,16 @@ noweb \use_geometry false \use_package amsmath 0 \use_package amssymb 0 +\use_package cancel 0 \use_package esint 0 \use_package mathdots 1 \use_package mathtools 0 \use_package mhchem 1 +\use_package stackrel 0 +\use_package stmaryrd 0 \use_package undertilde 0 \cite_engine basic -\cite_engine_type numerical +\cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false @@ -148,101 +151,109 @@ noweb file to LyX. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +noweb2lyx.in \end_layout -\begin_layout Chunk +\end_inset #!@PERL@ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Copyright (C) 1999 Kayvan A. Sylvan \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # You are free to use and modify this code under the terms of \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # the GNU General Public Licence version 2 or later. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Written with assistance from: \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Edmar Wienskoski Jr. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # Amir Karger \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # $Id: noweb2lyx.lyx,v 1.5 2005/07/18 09:42:27 jamatos Exp $ \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # NOTE: This file was automatically generated from noweb2lyx.lyx using noweb. \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -262,20 +273,26 @@ noweb @ Here is some documentation. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open -\end_layout - -\begin_layout Chunk +\begin_layout Plain Layout We can do arbitrary LaTeX code here. -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout [... blah blah blah ...] \end_layout +\end_inset + + +\end_layout + \begin_layout Standard Code chunks look like this: \end_layout @@ -509,64 +526,72 @@ With all that preamble out of the way, we now have the basic high-level outline for our code: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Convert noweb to LyX \end_layout -\begin_layout Chunk +\end_inset if (!$post_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if ((!$pre_only) && (!$post_only)) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (!$pre_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -580,31 +605,35 @@ In this section, we present the code that performs the task of creating This algorithm is outlined in the code that follows: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout inputline: while() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (/^ \backslash @@ -619,24 +648,24 @@ s* >=/) { # Beginning of a noweb chunk \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } elsif (/^@ \backslash s+(.*)/) { # Beginning of a documentation chunk \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT $1; # We do not need the ``@'' part \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } elsif (/ \backslash @@ -649,39 +678,39 @@ s+(.*)/) { # Beginning of a documentation chunk ]/) { # noweb quoted code \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT; # Just let the line pass through \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -690,12 +719,16 @@ In the code above, we do some pre-processing of the noweb ``[[...]]'' construct. constructs. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout s/ \backslash @@ -704,16 +737,23 @@ s/ [.+? \backslash ]{2,}/{$&}/g; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout print OUTPUT; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard While reading in the \family roman @@ -752,29 +792,37 @@ noweb code chunk, we transform it into a form that is usable by reLyX. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Read in and output the noweb code chunk \end_layout -\begin_layout Chunk +\end_inset <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -854,44 +902,52 @@ to read and write files. no need to create a temporary file. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Setup INPUT and OUTPUT \end_layout -\begin_layout Chunk +\end_inset if ($pre_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files($input_file, $output_file); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $relyx_file = "temp$$"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files($input_file, $relyx_file); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -927,43 +983,52 @@ status collapsed , which we define below: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout sub setup_files { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout my($in, $out) = @_; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout open(INPUT, "<$in") || die "Cannot read $in: $! \backslash n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout open(OUTPUT, ">$out") || die "Cannot write $out: $! \backslash n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout + +@ %def setup_files +\end_layout + +\end_inset + -@ %def setup_files \end_layout \begin_layout Subsection @@ -979,83 +1044,110 @@ After we see the beginning of the chunk, we need to read in and save the rest of the chunk for output. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Save the beginning of the chunk to savedchunk \end_layout -\begin_layout Chunk +\end_inset $savedchunk = $_; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $endLine = ""; \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout chunkline: while () { -\begin_inset Newline newline -\end_inset +\end_layout - last chunkline if /^@ +\begin_layout Plain Layout + + last chunkline if /^@ \backslash s+/; -\begin_inset Newline newline -\end_inset +\end_layout - $savedchunk .= $_; -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout + + $savedchunk .= $_; +\end_layout + +\begin_layout Plain Layout }; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout switch: { -\begin_inset Newline newline -\end_inset +\end_layout - if (/^@ +\begin_layout Plain Layout + + if (/^@ \backslash s+$/) {$savedchunk .= $_; last switch; } -\begin_inset Newline newline -\end_inset +\end_layout - if (/^@ +\begin_layout Plain Layout + + if (/^@ \backslash s+%def.*$/) {$savedchunk .= $_; last switch; } -\begin_inset Newline newline -\end_inset +\end_layout - if (/^@ +\begin_layout Plain Layout + + if (/^@ \backslash s+(.*)$/) {$savedchunk .= "@ \backslash n"; $endLine = "$1 \backslash n"; } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Subsection Printing out the chunk \end_layout @@ -1064,12 +1156,20 @@ Printing out the chunk The final piece of the first pass of the conversion is done by this code. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +print out the chunk in a reLyXskip block \end_layout -\begin_layout Chunk +\end_inset print OUTPUT " \backslash @@ -1080,12 +1180,12 @@ begin{reLyXskip} n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT $savedchunk; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT " \backslash @@ -1098,14 +1198,14 @@ n n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT "$endLine"; \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1173,24 +1273,32 @@ status collapsed files. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Close INPUT and OUTPUT \end_layout -\begin_layout Chunk +\end_inset close(INPUT); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout close(OUTPUT); \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -1242,24 +1350,32 @@ In order to run reLyX, we need to know the article class of the input document For this, we need to parse the intermediate file. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Run reLyX on intermediate file \end_layout -\begin_layout Chunk +\end_inset <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1353,34 +1469,42 @@ noweb2lyx on itself and a produce a quite reasonable LyX file. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Parse for document class \end_layout -\begin_layout Chunk +\end_inset open(INPUT, "<$relyx_file") || \end_layout -\begin_layout Chunk +\begin_layout Plain Layout die "Cannot read $relyx_file: $! \backslash n"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $class = "article"; # default if none found \end_layout -\begin_layout Chunk +\begin_layout Plain Layout parse: while() { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (/ \backslash @@ -1389,34 +1513,34 @@ parse: while() { docu[m]entclass{(.*)}/) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $class = $1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout last parse; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout close(INPUT); \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -1427,30 +1551,43 @@ Running reLyX with the corresponding literate document layout Now that we know what the document class ought to be, we do: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout $doc_class = "literate-" . $class; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout die "reLyX returned non-zero: $! \backslash n" -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout if (system("reLyX -c $doc_class $relyx_file")); -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard reLyX performs the main bulk of the translation work. Note that if the ``literate- @@ -1475,54 +1612,62 @@ We need to perform some post-processing of what reLyX produces in order The outline of the post-processing steps are: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Fix up LyX file \end_layout -\begin_layout Chunk +\end_inset <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout line: while() \end_layout -\begin_layout Chunk +\begin_layout Plain Layout { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT; # default \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <> \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1661,39 +1806,47 @@ status collapsed is taken care of by this code: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Setup INPUT and OUTPUT for the final output \end_layout -\begin_layout Chunk +\end_inset if ($post_only) { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files("$input_file", "$output_file"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &setup_files("$relyx_file.lyx", "$output_file"); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -1705,12 +1858,20 @@ Now, as we outlined before, the final step is transforming the code-chunks which have been put into a LaTeX layout by LyX into the Chunk layout. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Fix code chunks in latex layout \end_layout -\begin_layout Chunk +\end_inset if (/ \backslash @@ -1719,53 +1880,53 @@ if (/ latex latex/) { # Beginning of some latex code \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if (($line = ) =~ /^ \backslash s*<> \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout # print the \backslash latex latex line + next line \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT "$_$line"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard @@ -1773,16 +1934,20 @@ When we are sure that we are in a code chunk, we must read in the rest of the code chunk and output a chunk layout for it: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $savedchunk = " \backslash @@ -1793,54 +1958,74 @@ layout Chunk n \backslash n$line"; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout codeline: while () { -\begin_inset Newline newline -\end_inset +\end_layout - $savedchunk .= $_; -\begin_inset Newline newline -\end_inset +\begin_layout Plain Layout - last codeline if /^@ + $savedchunk .= $_; +\end_layout + +\begin_layout Plain Layout + + last codeline if /^@ \backslash s+/; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout }; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout print OUTPUT $savedchunk; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout <> -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ \end_layout +\end_inset + + +\end_layout + \begin_layout Standard Okay, now we just need to eat the rest of the latex layout. There should only be a few different types of lines for us to match: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Slurp up to the end of the latex layout \end_layout -\begin_layout Chunk +\end_inset slurp: while () { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout last slurp if / \backslash @@ -1849,7 +2034,7 @@ slurp: while () { latex /; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next slurp if / \backslash @@ -1858,26 +2043,26 @@ latex /; newline/; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next slurp if /^ \backslash s*$/; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout warn "confused by line: $_"; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Subsection @@ -1913,12 +2098,20 @@ noweb when it generates the final LaTeX code. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Fix [[var]] noweb construct \end_layout -\begin_layout Chunk +\end_inset if (/ \backslash @@ -1931,7 +2124,7 @@ if (/ ]/) { # special code for [[var]] \end_layout -\begin_layout Chunk +\begin_layout Plain Layout s/ \backslash @@ -1958,24 +2151,24 @@ latex default n/g; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print OUTPUT; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout next line; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -1986,19 +2179,27 @@ Cleaning up intermediate files The cleanup code is very simple: \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +Clean up \end_layout -\begin_layout Chunk +\end_inset system("rm -f $relyx_file*") unless ($post_only || $pre_only); \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Section @@ -2015,123 +2216,138 @@ noweb2lyx files in the import pipeline. \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset ERT +status open + +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage() if ($#ARGV < 1); # zero or one argument \end_layout -\begin_layout Chunk +\begin_layout Plain Layout if ($ARGV[0] eq "-pre") { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage unless ($#ARGV == 2); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $input_file = $ARGV[1]; $output_file = $ARGV[2]; $pre_only = 1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } elsif ($ARGV[0] eq "-post") { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage unless ($#ARGV == 2); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $input_file = $ARGV[1]; $output_file = $ARGV[2]; $post_only = 1; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } else { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout &usage unless ($#ARGV == 1); \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $input_file = $ARGV[0]; $output_file = $ARGV[1]; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout $pre_only = 0; $post_only = 0; \end_layout -\begin_layout Chunk +\begin_layout Plain Layout } \end_layout -\begin_layout Chunk +\begin_layout Plain Layout @ %def input_file output_file pre_only post_only \end_layout -\begin_layout Chunk +\begin_layout Plain Layout <>= \end_layout -\begin_layout Chunk +\begin_layout Plain Layout sub usage() { \end_layout -\begin_layout Chunk +\begin_layout Plain Layout print "Usage: noweb2lyx [-pre | -post] input-file output-file \end_layout -\begin_layout Chunk +\begin_layout Plain Layout -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout If -pre is specified, only pre-processes the input-file for reLyX. -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout Similarly, in the case of -post, post-processes reLyX output. -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout In case of bugs, Email Kayvan Sylvan . \backslash n"; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout exit; -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout } -\begin_inset Newline newline -\end_inset +\end_layout + +\begin_layout Plain Layout @ %def usage \end_layout +\end_inset + + +\end_layout + \begin_layout Section Generating the \noun on @@ -2163,34 +2379,42 @@ build-script notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$2 sh \end_layout -\begin_layout Chunk +\begin_layout Standard +\begin_inset Flex Chunk +status open -<>= +\begin_layout Plain Layout + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout +build-script \end_layout -\begin_layout Chunk +\end_inset PREFIX=/usr \end_layout -\begin_layout Chunk +\begin_layout Plain Layout notangle -Rnoweb2lyx.in noweb2lyx.nw > noweb2lyx.in \end_layout -\begin_layout Chunk +\begin_layout Plain Layout sed -e "s=@PERL@=$PREFIX/bin/perl=" noweb2lyx.in > noweb2lyx \end_layout -\begin_layout Chunk +\begin_layout Plain Layout chmod +x noweb2lyx \end_layout -\begin_layout Chunk +\end_inset + -@ \end_layout \begin_layout Standard