]> git.lyx.org Git - lyx.git/blobdiff - lib/examples/Literate.lyx
chkconfig.ltx: add lh fonts
[lyx.git] / lib / examples / Literate.lyx
index d990a5863b84ed8e3fb15ce39bb783e092873316..bcf37a358d7c912f858c7051a6d4c767911a598d 100644 (file)
-#LyX 1.3 created this file. For more info see http://www.lyx.org/
-\lyxformat 221
-\textclass literate-article
+#LyX 2.1 created this file. For more info see http://www.lyx.org/
+\lyxformat 448
+\begin_document
+\begin_header
+\textclass article
+\use_default_options false
+\begin_modules
+noweb
+\end_modules
+\maintain_unincluded_children false
 \language english
+\language_package default
 \inputencoding default
-\fontscheme default
+\fontencoding global
+\font_roman default
+\font_sans default
+\font_typewriter default
+\font_math auto
+\font_default_family default
+\use_non_tex_fonts false
+\font_sc false
+\font_osf false
+\font_sf_scale 100
+\font_tt_scale 100
 \graphics default
+\default_output_format default
+\output_sync 0
+\bibtex_command default
+\index_command default
 \paperfontsize default
 \spacing single
-\papersize Default
-\paperpackage a4
-\use_geometry 0
-\use_amsmath 0
-\use_natbib 0
-\use_numerical_citations 0
+\use_hyperref false
+\papersize default
+\use_geometry false
+\use_package amsmath 0
+\use_package amssymb 0
+\use_package esint 0
+\use_package mathdots 1
+\use_package mathtools 0
+\use_package mhchem 1
+\use_package undertilde 0
+\cite_engine basic
+\cite_engine_type numerical
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
 \paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 0
+\index Index
+\shortcut idx
+\color #008000
+\end_index
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
-\defskip medskip
+\paragraph_indentation default
 \quotes_language english
-\quotes_times 2
 \papercolumns 1
 \papersides 1
 \paperpagestyle default
+\tracking_changes false
+\output_changes false
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict false
+\end_header
 
-\layout Title
+\begin_body
 
+\begin_layout Title
 LyX and Literate Programming
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 An example program
-\layout Author
+\end_layout
 
+\begin_layout Author
 Edmar Wienskoski Jr.
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 edmar-w-jr@technologist.com
 \begin_inset Foot
-collapsed true
-
-\layout Standard
+status collapsed
 
+\begin_layout Plain Layout
 Modified by Bernard Michael Hurley bernardh@westherts.ac.uk ---- Don't blame
  Edmar for any errors that have crept in!
-\end_inset 
+\end_layout
 
+\end_inset
 
-\layout Abstract
 
+\end_layout
 
-\series bold 
+\begin_layout Abstract
+
+\series bold
 Note:
-\series default 
+\series default
  This example program is provided for educational use only.
  The functionality in this C program has been superceded by the equivalent
  Python code in 
-\emph on 
+\emph on
 examples/listerrors.lyx
-\emph default 
+\emph default
  which should be installed in the LyX scripts directory.
-\layout Date
-
+\end_layout
 
+\begin_layout Date
 \begin_inset ERT
-status Collapsed
+status collapsed
+
+\begin_layout Plain Layout
 
-\layout Standard
 
-\backslash 
+\backslash
 today
-\end_inset 
+\end_layout
 
+\end_inset
 
-\layout Standard
 
+\end_layout
 
-\begin_inset LatexCommand \tableofcontents{}
+\begin_layout Standard
+\begin_inset CommandInset toc
+LatexCommand tableofcontents
 
-\end_inset 
+\end_inset
 
 
-\layout Section
+\end_layout
 
+\begin_layout Section
 Introduction
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 After typesetting a document, LyX scans the LaTeX log file looking for errors.
  For each error found, the line number is obtained and a error box is displayed
  in the LyX screen at that position.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 To use this feature to view compilation errors while working with literate
  documents, we need a program that filters the compilation errors and puts
  them in a format suitable for LyX reading it.
  
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 In this document we present a filter that recognizes compilation error messages
  from noweb, gnu C, and the IBM C compiler (xlc).
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The filter is required to read from standard input, parse for error messages
  and copy the error messages to the standard output.
  During the output process, the filter must present the error messages in
@@ -106,426 +166,764 @@ The filter is required to read from standard input, parse for error messages
  read other formats as well (like gcc error messages for example).
  This mechanism is necessary to fully explore the literate programming tool's
  capabilities.
-\layout Section
+\end_layout
 
+\begin_layout Section
 Algorithm
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function bodies>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 int
-\newline 
+\end_layout
+
+\begin_layout Chunk
 main (int argc, char **argv)
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   if (argc == 2) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     switch (argv[1][0]) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     case 'n':
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<Scan input for noweb error messages>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     case 'x':
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<Scan input for xlc error messages>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     case 'a':
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<AIX system using both noweb and xlc>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     case 's':
-\newline 
+\end_layout
+
+\begin_layout Chunk
     case 'b':
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<Solaris and Linux systems using both noweb and gcc>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     case 'g':
-\newline 
+\end_layout
+
+\begin_layout Chunk
     default:
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<Scan input for gcc error messages>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     }
-\newline 
+\end_layout
+
+\begin_layout Chunk
   } else {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     <<Scan input for gcc error messages>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function prototypes>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 int main (int argc, char **argv);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Section
+\end_layout
 
+\begin_layout Section
 Data Structures
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 We resort to some global variables to allow access from several different
  routines.
  These are the buffer and related pointers used during the parse of the
  input.
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Global variables>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 char    buffer[200][200];
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 int     last_buf_line;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 int     last_err_line;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 int     err_line;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 @ 
-\layout Section
+\end_layout
 
+\begin_layout Section
 The output format
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The output format mimics the TeX error messages format.
  This function prints a number of lines residing in the global variable
  
-\family typewriter 
+\family typewriter
 buffer
-\family default 
+\family default
 , a program name and line number.
  There is no special requirement on the input strings, they can be anything.
 \begin_inset Foot
-collapsed true
-
-\layout Standard
+status collapsed
 
+\begin_layout Plain Layout
 This function has been slightly changed from EW's original to make scanning
  a bit easier with LaTeX::scanLogFile().
  The test has been added because LyX can crash if empty lines are allowed
  here --- I can't figure out why! --- BMH
-\end_inset 
+\end_layout
+
+\end_inset
 
 
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function bodies>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 void
-\newline 
+\end_layout
+
+\begin_layout Chunk
 output_error (int buf_size, int error_line, char *tool)
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   int     i;
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
   fprintf(stdout, "! Build Error: ==> %s ==>
-\backslash 
+\backslash
 n", tool);
-\newline 
+\end_layout
+
+\begin_layout Chunk
   fprintf(stdout, " ...
-\backslash 
+\backslash
 n
-\backslash 
+\backslash
 nl.%d ...
-\backslash 
+\backslash
 n", error_line);
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
   for (i=0; i<buf_size; i++)
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (strlen(buffer[i]) != 0)
-\newline 
+\end_layout
+
+\begin_layout Chunk
       fprintf(stdout, "%s", buffer[i]);
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
   fprintf(stdout, "
-\backslash 
+\backslash
 n");
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function prototypes>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 void output_error (int buf_size, int error_line, char *tool);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Section
+\end_layout
 
+\begin_layout Section
 Functions Implementation
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Both noweave and notangle routines, always output one single line for each
  error found, thus to scan the buffer for noweb error messages is enough
  to exam one input line at a time.
  Note that the noweb software does not provide a line error number, so all
  errors boxes related to noweb messages will be displayed at the beginning
  of the file.
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Scan input for noweb error messages>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   last_buf_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   while (fgets(buffer[0], 200, stdin)) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (noweb_try(0))
-\newline 
+\end_layout
+
+\begin_layout Chunk
       output_error(1, err_line, "noweb");
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The examination itself is very inefficient.
  Unfortunately noweb doesn't have any characteristic that would help to
  identify one of its error messages.
  The solution is to collect all possible output messages in an array of
  strings, and turn the examination process into a linear search in this
  array.
-\layout Scrap
+\end_layout
+
+\begin_layout Chunk
+
+\end_layout
 
+\begin_layout Chunk
 <<Global variables>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 char *noweb_msgs[] = {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "couldn't open file",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "couldn't open temporary file",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "error writing temporary file",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "ill-formed option",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "unknown option",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "Bad format sequence",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "Can't open output file",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "Can't open temporary file",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "Capacity exceeded:",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "Ignoring unknown option -",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "This can't happen:",
-\newline 
+\end_layout
+
+\begin_layout Chunk
   "non-numeric line number in"
-\newline 
+\end_layout
+
+\begin_layout Chunk
 };
-\newline 
+\end_layout
+
+\begin_layout Chunk
 
-\newline 
+\end_layout
+
+\begin_layout Chunk
 char *noweb_msgs_mimic_gcc[] = {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   ": unescaped << in documentation chunk"
-\newline 
+\end_layout
+
+\begin_layout Chunk
 };
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A noweb error message can be any string that contains a matching pair of
- < <\SpecialChar ~
-\SpecialChar ~
-\SpecialChar ~
+ < <
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
 > >, or any of the above strings
-\layout Scrap
+\end_layout
+
+\begin_layout Chunk
+
+\end_layout
 
+\begin_layout Chunk
 <<Function bodies>>=
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 int
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 noweb_try (int buf_line)
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   char    *s, *t, *b;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   int     i; 
-\newline 
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
 
-\newline 
   b = buffer[buf_line];
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   err_line = 0;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
 
-\newline 
   for (i=0; i<1; i++) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
       s = (char *)strstr (b, noweb_msgs_mimic_gcc[i]);
-\newline 
+\begin_inset Newline newline
+\end_inset
+
       if (s != NULL) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         t = (char *)strchr(buffer[buf_line], ':');
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         err_line = atoi(t+1);
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         t = buffer[buf_line];
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         ++s;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         while (*(t++) = *(s++));
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         return 1;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
       }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   s = (char *)strstr(b, "<<");
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   if (s != NULL) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
     s = (char *)strstr(s+2, ">>");
-\newline 
+\begin_inset Newline newline
+\end_inset
+
     if (s != NULL) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
       return 1;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
     }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   } else { 
-\newline 
+\begin_inset Newline newline
+\end_inset
+
      for (i = 0; i < 12; ++i) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         s = (char *)strstr (b, noweb_msgs[i]);
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         if (s != NULL) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
            return 1;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
         }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
     }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   return 0;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function prototypes>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 int noweb_try (int buf_line);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\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.
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Scan input for xlc error messages>>= 
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   last_buf_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   while (fgets(buffer[last_buf_line], 200, stdin)) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (xlc_try(0))
-\newline 
+\end_layout
+
+\begin_layout Chunk
       output_error(1, err_line, "xlc");
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A xlc error message is easy to identify.
  Every error message starts with a quoted string with no spaces, a comma,
  a space, the word 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 line
 \begin_inset Quotes erd
-\end_inset 
+\end_inset
 
 , a space, and some variable text.
  The following routine tests if a given buffer line matches this criteria:
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
+
+\end_layout
+
+\begin_layout Chunk
+
+\end_layout
+
+\begin_layout Chunk
 <<Function bodies>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 int 
-\newline 
+\end_layout
+
+\begin_layout Chunk
 xlc_try (int buf_line)
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   char    *s, *t;
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
   t = buffer[buf_line];
-\newline 
+\end_layout
+
+\begin_layout Chunk
   s = t+1;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   while (*s != '"' && *s != ' ' && *s != '
-\backslash 
+\backslash
 0')
-\newline 
+\end_layout
+
+\begin_layout Chunk
     s++;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   if (*t != '"' || *s != '"' || strncmp(s+1, ", line ", 7) != 0)
-\newline 
+\end_layout
+
+\begin_layout Chunk
     return 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   s += 8;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   err_line = atoi(s);
-\newline 
+\end_layout
+
+\begin_layout Chunk
   return 1;
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function prototypes>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 int xlc_try (int buf_line);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The gcc compiler error messages are more complicated to scan.
  Each error can span more than one line in the buffer.
  The good news is that every buffer line on each error has the same pattern,
@@ -535,15 +933,16 @@ The gcc compiler error messages are more complicated to scan.
  At the time they differ, all the accumulated lines, except the last one,
  will belong to one single error message, which now can be output-ed to
  LyX.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Every gcc error message contains a string with no space followed by a 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 :
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 .
  If the next character is a space, then this line is a header of a error
@@ -551,446 +950,785 @@ Every gcc error message contains a string with no space followed by a
  where the error was found.
  Otherwise, the next thing is a integer number followed by another 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 :
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 .
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Scan input for gcc error messages>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   char    *s, *t;
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
   last_buf_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   while (fgets(buffer[last_buf_line], 200, stdin)) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     /****** Skip lines until I find an error */
-\newline 
+\end_layout
+
+\begin_layout Chunk
     s = (char *)strpbrk(buffer[last_buf_line], " :");
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (s == NULL || *s == ' ')
-\newline 
+\end_layout
+
+\begin_layout Chunk
       continue; /* No gcc error found here */
-\newline 
+\end_layout
+
+\begin_layout Chunk
     do {
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<gcc error message criteria is to find a "...:999:" or a "...: ">>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       /****** OK It is an error message, get line number */
-\newline 
+\end_layout
+
+\begin_layout Chunk
       err_line = atoi(s+1);
-\newline 
+\end_layout
+
+\begin_layout Chunk
       if (last_err_line == 0 || last_err_line == err_line) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
         last_err_line = err_line;
-\newline 
+\end_layout
+
+\begin_layout Chunk
         continue; /* It's either a header or a continuation, don't output
  yet */
-\newline 
+\end_layout
+
+\begin_layout Chunk
       }
-\newline 
+\end_layout
+
+\begin_layout Chunk
       /****** Completed the scan of one error message, output it to LyX
  */
-\newline 
+\end_layout
+
+\begin_layout Chunk
       discharge_buffer(1);
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     } while (fgets(buffer[last_buf_line], 200, stdin));
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
   /****** EOF completes the scan of whatever was being scanned */
-\newline 
+\end_layout
+
+\begin_layout Chunk
   discharge_buffer(0);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<gcc error message criteria is to find a "...:999:" or a "...: ">>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 /****** Search first ":" in the error number */
-\newline 
+\end_layout
+
+\begin_layout Chunk
 s = (char *)strpbrk(buffer[last_buf_line], " :");
-\newline 
+\end_layout
+
+\begin_layout Chunk
 last_buf_line++;
-\newline 
+\end_layout
+
+\begin_layout Chunk
 if (s == NULL || *s == ' ') 
-\newline 
+\end_layout
+
+\begin_layout Chunk
   <<No gcc error found here, but it might terminate the scanning of a previous
  one>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
 /****** Search second ":" in the error number */
-\newline 
+\end_layout
+
+\begin_layout Chunk
 t = (char *)strpbrk(s+1, " :");
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 if (t == NULL || *t == ' ')
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   <<No gcc error found here, but it might terminate the scanning of a previous
  one>>
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 /****** Verify if is all digits between ":" */
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 if (t != s+1+strspn(s+1, "0123456789")) 
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   <<No gcc error found here, but it might terminate the scanning of a previous
  one>>
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
+
+\end_layout
+
+\begin_layout Chunk
+
+\end_layout
+
+\begin_layout Chunk
 <<No gcc error found here, but it might terminate the scanning of a previous
  one>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   err_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   discharge_buffer(1);
-\newline 
+\end_layout
+
+\begin_layout Chunk
   continue;
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 As we mentioned, when the scan of one gcc error message is completed everything
  in the buffer except the last line is one single error message.
  But if the scan terminates with a EOF or through finding one line that
  does not match the gcc error message criteria, then there is no 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 last line
 \begin_inset Quotes erd
-\end_inset 
+\end_inset
 
  in the buffer to be concerned with.
  In those cases we empty the buffer completely.
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
+
+\end_layout
+
+\begin_layout Chunk
+
+\end_layout
+
+\begin_layout Chunk
 <<Function bodies>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 void
-\newline 
+\end_layout
+
+\begin_layout Chunk
 discharge_buffer (int save_last)
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
  if (last_err_line != 0) { 
-\newline 
+\end_layout
+
+\begin_layout Chunk
    clean_gcc_messages();
-\newline 
+\end_layout
+
+\begin_layout Chunk
    if (save_last != 0) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
       output_error(last_buf_line-1, last_err_line, "gcc");
-\newline 
+\end_layout
+
+\begin_layout Chunk
       strcpy (buffer[0], buffer[last_buf_line-1]);
-\newline 
+\end_layout
+
+\begin_layout Chunk
       last_err_line = err_line;
-\newline 
+\end_layout
+
+\begin_layout Chunk
       last_buf_line = 1;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     } else { 
-\newline 
+\end_layout
+
+\begin_layout Chunk
       ++last_buf_line;
-\newline 
+\end_layout
+
+\begin_layout Chunk
       clean_gcc_messages();
-\newline 
+\end_layout
+
+\begin_layout Chunk
       output_error(last_buf_line-1, last_err_line, "gcc");
-\newline 
+\end_layout
+
+\begin_layout Chunk
       last_err_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
       last_buf_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     }
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function prototypes>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 void discharge_buffer (int save_last);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The next function 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 cleans
 \begin_inset Quotes erd
-\end_inset 
+\end_inset
 
  superfluous information from gcc messages, namely the name of the noweb
  file and the line number of the Error.
 \begin_inset Foot
-collapsed true
-
-\layout Standard
+status collapsed
 
+\begin_layout Plain Layout
 More could be done.
  For instance, some way of distinguishing between gcc Errors and Warnings
  should be devised.
-\end_inset 
+\end_layout
+
+\end_inset
 
 
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function bodies>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 void
-\newline 
+\end_layout
+
+\begin_layout Chunk
 clean_gcc_messages ()
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   int index;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   char search [30]; 
-\newline 
+\end_layout
+
+\begin_layout Chunk
   char *tail, *head; 
-\newline 
+\end_layout
+
+\begin_layout Chunk
   int search_len = sprintf(search, ".nw:%d:", last_err_line);
-\newline 
+\end_layout
+
+\begin_layout Chunk
   
-\newline 
+\end_layout
+
+\begin_layout Chunk
   for (index = 0; index < last_buf_line-1; index++) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     tail = (char *)strstr (buffer[index], search);
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if ( tail == NULL) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
        tail = (char *) strstr (buffer[index], ".nw:");
-\newline 
+\end_layout
+
+\begin_layout Chunk
        if (tail) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
           tail += 4;
-\newline 
+\end_layout
+
+\begin_layout Chunk
        }
-\newline 
+\end_layout
+
+\begin_layout Chunk
     } else {
-\newline 
+\end_layout
+
+\begin_layout Chunk
        tail += search_len;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     }
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (tail != NULL) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
        head = buffer[index];
-\newline 
+\end_layout
+
+\begin_layout Chunk
        while (*(head++) = *(tail++));
-\newline 
+\end_layout
+
+\begin_layout Chunk
     }
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Function prototypes>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 void clean_gcc_messages ();
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 To combine the scan of noweb error messages and xlc error messages is very
  simple.
  We just try each one for every input line:
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<AIX system using both noweb and xlc>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   last_buf_line = 0;
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   while (fgets(buffer[0], 200, stdin)) {
-\newline 
+\begin_inset Newline newline
+\end_inset
+
     if (noweb_try(0))
-\newline 
+\begin_inset Newline newline
+\end_inset
+
       output_error(1, err_line, "noweb");
-\newline 
+\begin_inset Newline newline
+\end_inset
+
     else if (xlc_try(0))
-\newline 
+\begin_inset Newline newline
+\end_inset
+
       output_error(1, err_line, "xlc");
-\newline 
+\begin_inset Newline newline
+\end_inset
+
   }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 }
-\newline 
+\begin_inset Newline newline
+\end_inset
+
 @
-\layout Standard
+\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
  the middle of a gcc error message.
  So we just repeat the gcc procedure and test for noweb error messages in
  the beginning of the scan:
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<Solaris and Linux systems using both noweb and gcc>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 {
-\newline 
+\end_layout
+
+\begin_layout Chunk
   char    *s, *t;
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
   last_buf_line = 0;
-\newline 
+\end_layout
+
+\begin_layout Chunk
   while (fgets(buffer[last_buf_line], 200, stdin)) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
     /****** Skip lines until I find an error */
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (last_buf_line == 0 && noweb_try(0)) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
       output_error(1, err_line, "noweb");
-\newline 
+\end_layout
+
+\begin_layout Chunk
       continue;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     }
-\newline 
+\end_layout
+
+\begin_layout Chunk
     s = (char *)strpbrk(buffer[last_buf_line], " :");
-\newline 
+\end_layout
+
+\begin_layout Chunk
     if (s == NULL || *s == ' ')
-\newline 
+\end_layout
+
+\begin_layout Chunk
       continue; /* No gcc error found here */
-\newline 
+\end_layout
+
+\begin_layout Chunk
     do {
-\newline 
+\end_layout
+
+\begin_layout Chunk
       <<gcc error message criteria is to find a "...:999:" or a "...: ">>
-\newline 
+\end_layout
+
+\begin_layout Chunk
       /****** OK It is an error, get line number */
-\newline 
+\end_layout
+
+\begin_layout Chunk
       err_line = atoi(s+1);
-\newline 
+\end_layout
+
+\begin_layout Chunk
       if (last_err_line == 0 || last_err_line == err_line) {
-\newline 
+\end_layout
+
+\begin_layout Chunk
         last_err_line = err_line;
-\newline 
+\end_layout
+
+\begin_layout Chunk
         continue; /* It's either a header or a continuation, don't output
  yet */
-\newline 
+\end_layout
+
+\begin_layout Chunk
       }
-\newline 
+\end_layout
+
+\begin_layout Chunk
       /****** Completed the scan of one error message, output it to LyX
  */
-\newline 
+\end_layout
+
+\begin_layout Chunk
       discharge_buffer(1);
-\newline 
+\end_layout
+
+\begin_layout Chunk
       break;
-\newline 
+\end_layout
+
+\begin_layout Chunk
     } while (fgets(buffer[last_buf_line], 200, stdin));
-\newline 
+\end_layout
+
+\begin_layout Chunk
   }
-\newline 
+\end_layout
+
+\begin_layout Chunk
   /****** EOF completes the scan of whatever was being scanned */
-\newline 
+\end_layout
+
+\begin_layout Chunk
   discharge_buffer(0);
-\newline 
+\end_layout
+
+\begin_layout Chunk
 }
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Section
+\end_layout
 
+\begin_layout Section
 Wrapping the code into a file
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<listerrors.c>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 #include <stdio.h>
-\newline 
+\end_layout
+
+\begin_layout Chunk
 #include <strings.h>       
-\newline 
+\end_layout
+
+\begin_layout Chunk
  
-\newline 
+\end_layout
+
+\begin_layout Chunk
 <<Global variables>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
 <<Function prototypes>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
 <<Function bodies>>
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 To build this program, we want to add the 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 -L
 \begin_inset Quotes erd
-\end_inset 
+\end_inset
 
  option in the tangle command to force gdb to load the file 
-\family typewriter 
+\family typewriter
 Literate.nw
-\family default 
+\family default
  instead of 
-\family typewriter 
+\family typewriter
 listerrors.c
-\family default 
+\family default
 .
  In accordance with this, we pass the 
 \begin_inset Quotes eld
-\end_inset 
+\end_inset
 
 -g
 \begin_inset Quotes erd
-\end_inset 
+\end_inset
 
  option to gcc.
-\layout Scrap
+\end_layout
 
+\begin_layout Chunk
 <<build-script>>=
-\newline 
+\end_layout
+
+\begin_layout Chunk
 #!/bin/sh
-\newline 
+\end_layout
+
+\begin_layout Chunk
 if [ -z "$NOWEB_SOURCE" ]; then NOWEB_SOURCE=Literate.nw; fi
-\newline 
-notangle -L -Rlisterrors.c ${NOWEB_SOURCE} > listerrors.c
-\newline 
+\end_layout
+
+\begin_layout Chunk
+if [ -z "$NOWEB_OUTPUT_DIR" ]; then NOWEB_OUTPUT_DIR=.; fi
+\end_layout
+
+\begin_layout Chunk
+notangle -L -Rlisterrors.c ${NOWEB_SOURCE} > ${NOWEB_OUTPUT_DIR}/listerrors.c
+\end_layout
+
+\begin_layout Chunk
 gcc -g -o listerrors listerrors.c
-\newline 
+\end_layout
+
+\begin_layout Chunk
 @
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 This project can be tangled and compiled from LyX if you set 
-\family typewriter 
+\family typewriter
 
-\backslash 
+\backslash
 build_command
-\family default 
- to call a generic script that always extracts a scrap named 
-\family typewriter 
+\family default
+ to call a generic script that always extracts a chunk named 
+\family typewriter
 build-script
-\family default 
+\family default
  and executes it.
  Here is a example of such generic script:
-\layout LyX-Code
+\end_layout
 
+\begin_layout LyX-Code
 #!/bin/sh
-\newline 
-notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 sh
-\layout LyX-Code
+\begin_inset Newline newline
+\end_inset
+
+notangle -Rbuild-script $1 | env NOWEB_SOURCE=$1 NOWEB_OUTPUT_DIR=$r sh
+\end_layout
+
+\begin_layout LyX-Code
+
+\end_layout
 
-\the_end
+\end_body
+\end_document