axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] [axiom] Undefined Chunks behavior


From: root
Subject: [Axiom-developer] [axiom] Undefined Chunks behavior
Date: Mon, 18 Nov 2002 22:54:08 -0500

Norman,

I have included two patch files you can apply to change the
behavior for undefined chunks. Previously undefined chunks
generated an error and were elided from the output. Now they are
complained about but included in the output surrounded by 
the << and >> symbols which should recreate the original input.

This seems to do the "least harm" to the file as it reproduces
what it doesn't understand.

The change is explained in the nw file.

To fix these you only need to cd to the noweb/src/c directory
and type:
  patch <modules.c.patch
  patch <modules.nw.patch

(actually, you can feed this original mail file to patch 
and it will "do the right thing" but you probably already 
know that).

I've included both because I ran into a catch-22 when I tried
to notangle modules.nw without having a running notangle.
Clearly that won't be a problem for you.

Tim

======================== modules.nw.patch =============================
--- modules.nw.tpd      Mon Nov 18 20:56:03 2002
+++ modules.nw  Mon Nov 18 21:59:57 2002
@@ -197,11 +197,17 @@
 out as a special case.
 This change probably blows the case where the module being expanded is
 empty.
+
+If the lookup fails then the module (or chunk) is an undefined name.
+We complain about it but want to output the original source.
+We just wrap it in the bogus chunk name in the angle brackets 
+that it must have had in the input and output it. (Tim Daly Nov 13, 2002)
 <<expand a module>>=
 newmod = lookup(p->contents);
 if (newmod==NULL) {
-    errormsg (Error, "undefined chunk name: @<<%s@>>", p->contents);
+    errormsg (Error, "ignoring undefined chunk name: @<<%s@>>", p->contents);
     error=Error;
+    printf("@<<%s@>>",p->contents);
 } else {
     int retcode;
     if (*locformat == 0 && partial_distance == 0) {


======================== modules.c.patch ==============================
--- modules.c   Wed Mar 28 13:49:22 2001
+++ modules.c.tpd       Mon Nov 18 22:26:35 2002
@@ -1,4 +1,3 @@
-#line 50 "modules.nw"
 static char rcsid[] = "$Id: modules.nw,v 2.16 2001/03/28 18:44:46 nr Exp nr $";
 static char rcsname[] = "$Name: v2_10a $";
 #include <stdio.h>
@@ -11,18 +10,14 @@
 #include "columns.h"
 #include "strsave.h"
 
-#line 110 "modules.nw"
 static struct modpart *
 newmodpart(int type, char *s, Location *loc);   /* create a new module part */
 
 static
 void append(Module mp, struct modpart *p);
-#line 227 "modules.nw"
 static int seekcycle(Module mp, Parent parent);
-#line 132 "modules.nw"
 static char *lastfilename = 0;
 static int lastlineno = -1;
-#line 41 "modules.nw"
 Module newmodule (char *modname) {
     Module p = (Module) malloc (sizeof (struct module));
     checkptr(p);
@@ -31,12 +26,10 @@
     p->head = p->tail = NULL;
     return p;
 }
-#line 74 "modules.nw"
 void add_part (Module mp, char *s, Parttype type, Location *loc) {
     struct modpart *p = newmodpart(type,s,loc);
     append (mp,p);
 }
-#line 79 "modules.nw"
 static struct modpart *
 newmodpart(int type, char *s, Location *loc) {
     struct modpart *p = (struct modpart *) malloc (sizeof (struct modpart));
@@ -44,19 +37,15 @@
     p->ptype = type;
     if (s) {
         p->contents = strsave(s);
-        
-#line 104 "modules.nw"
-{ int k = strlen(p->contents)-1;
-  if (p->contents[k] == '\n') p->contents[k] = '\0';
-  else impossible("input line doesn't end with newline");
-}
-#line 87 "modules.nw"
+        { int k = strlen(p->contents)-1;
+          if (p->contents[k] == '\n') p->contents[k] = '\0';
+          else impossible("input line doesn't end with newline");
+        }
     }
     if (loc) p->loc = *loc;
     p->next = NULL;
     return p;
 }
-#line 93 "modules.nw"
 static
 void append(Module mp, struct modpart *p) {
     /* append p to mp's list of modparts */
@@ -67,12 +56,10 @@
         mp->tail = p;
     }
 }
-#line 137 "modules.nw"
 void resetloc(void) {
   lastfilename = 0;
   lastlineno = -1;
 }
-#line 145 "modules.nw"
 int expand (Module mp, int indent, int partial_distance, Parent parent,  
             char *locformat, FILE *out) {
     struct modpart *p;
@@ -80,69 +67,51 @@
     int error=Normal;
     struct parent thismodule; /* the value only matters when we're expanding a 
module */
 
-    
-#line 219 "modules.nw"
-thismodule.this = mp;
-thismodule.parent = parent;
-#line 153 "modules.nw"
-    
-#line 222 "modules.nw"
-if (seekcycle(mp, parent)) {
-    errormsg(Error, "<<%s>>", mp->name);
-    return Error;
-}
+    thismodule.this = mp;
+    thismodule.parent = parent;
+    if (seekcycle(mp, parent)) {
+        errormsg(Error, "<<%s>>", mp->name);
+        return Error;
+    }
 
-#line 155 "modules.nw"
     for (p=mp->head; p!=NULL; p=p->next) {
         switch (p->ptype) {
-            case STRING:  
-#line 176 "modules.nw"
-if (*(p->contents) != '\0') {
-    if (*locformat) {
-        if (printloc(out,locformat,p->loc,partial_distance) && (p != mp->head))
-              indent_for(partial_distance, out);
-    } else if (partial_distance == 0) {
-        indent_for(indent, out);
-        partial_distance = indent;
-    }
-    fprintf(out,"%s",p->contents);
-    partial_distance = limitcolumn(p->contents, partial_distance);
-}
-#line 157 "modules.nw"
-                                            ;  break;
-            case MODULE:  
-#line 201 "modules.nw"
-newmod = lookup(p->contents);
-if (newmod==NULL) {
-    errormsg (Error, "undefined chunk name: <<%s>>", p->contents);
-    error=Error;
-} else {
-    int retcode;
-    if (*locformat == 0 && partial_distance == 0) {
-        indent_for(indent, out);
-        partial_distance = indent;
-    }
-    retcode = expand (newmod, partial_distance, partial_distance,
-                      &thismodule, locformat, out);
-    if (retcode > error) error = retcode;
-}
-partial_distance = limitcolumn(p->contents, partial_distance + 2) + 2; 
-                                /* account for surrounding brackets */
-#line 158 "modules.nw"
-                                             ; break;
-            case NEWLINE: 
-#line 188 "modules.nw"
-partial_distance = 0;
-putc('\n', out);
-lastlineno++;
-#line 159 "modules.nw"
-                                             ; break;
+            case STRING:  if (*(p->contents) != '\0') {
+                              if (*locformat) {
+                                  if 
(printloc(out,locformat,p->loc,partial_distance) && (p != mp->head))
+                                        indent_for(partial_distance, out);
+                              } else if (partial_distance == 0) {
+                                  indent_for(indent, out);
+                                  partial_distance = indent;
+                              }
+                              fprintf(out,"%s",p->contents);
+                              partial_distance = limitcolumn(p->contents, 
partial_distance);
+                          };  break;
+            case MODULE:  newmod = lookup(p->contents);
+                          if (newmod==NULL) {
+                              errormsg (Error, "ignoring undefined chunk name: 
<<%s>>", p->contents);
+                              error=Error;
+                              printf("<<%s>>",p->contents);
+                          } else {
+                              int retcode;
+                              if (*locformat == 0 && partial_distance == 0) {
+                                  indent_for(indent, out);
+                                  partial_distance = indent;
+                              }
+                              retcode = expand (newmod, partial_distance, 
partial_distance,
+                                                &thismodule, locformat, out);
+                              if (retcode > error) error = retcode;
+                          }
+                          partial_distance = limitcolumn(p->contents, 
partial_distance + 2) + 2; 
+                                                          /* account for 
surrounding brackets */; break;
+            case NEWLINE: partial_distance = 0;
+                          putc('\n', out);
+                          lastlineno++;; break;
             default: impossible("bad part type");
         }
     }
     return error;
 }
-#line 229 "modules.nw"
 static int seekcycle(Module mp, Parent parent) {
     if (parent == NULL) {
         return 0;
@@ -155,57 +124,45 @@
         return 0;
     }
 }
-#line 251 "modules.nw"
 int printloc(FILE *fp, char *fmt, Location loc, int partial) {
     char *p;
     if (*fmt
     && (loc.filename!=lastfilename || lastlineno != loc.lineno)) {
         if (partial) putc('\n',fp);
-        
-#line 263 "modules.nw"
-for (p = fmt; *p; p++) {
-    if (*p == '%') {
-        switch (*++p) {
-            case '%': putc('%', fp);                             break;
-            case 'N': putc('\n', fp);                            break;
-            case 'F': fprintf(fp, "%s", loc.filename);           break;
-            case 'L': fprintf(fp, "%d", loc.lineno);             break;
-            case '-': case '+': 
-                        if (isdigit(p[1]) && p[2] == 'L') {
-                          fprintf(fp, "%d", *p == '+' ? loc.lineno + (p[1] - 
'0')
-                                                      : loc.lineno - (p[1] - 
'0'));
-                          p += 2;
-                        } else
-                          
-#line 283 "modules.nw"
-{ static int complained = 0;
-  if (!complained) {
-    errormsg(Error,"Bad format sequence ``%%%c'' in -L%s",*p,fmt);
-    complained = 1;
-  }
-}
-#line 277 "modules.nw"
-                      break;            
-            default:  
-#line 283 "modules.nw"
-{ static int complained = 0;
-  if (!complained) {
-    errormsg(Error,"Bad format sequence ``%%%c'' in -L%s",*p,fmt);
-    complained = 1;
-  }
-}
-#line 278 "modules.nw"
-                                                                break;
+        for (p = fmt; *p; p++) {
+            if (*p == '%') {
+                switch (*++p) {
+                    case '%': putc('%', fp);                             break;
+                    case 'N': putc('\n', fp);                            break;
+                    case 'F': fprintf(fp, "%s", loc.filename);           break;
+                    case 'L': fprintf(fp, "%d", loc.lineno);             break;
+                    case '-': case '+': 
+                                if (isdigit(p[1]) && p[2] == 'L') {
+                                  fprintf(fp, "%d", *p == '+' ? loc.lineno + 
(p[1] - '0')
+                                                              : loc.lineno - 
(p[1] - '0'));
+                                  p += 2;
+                                } else
+                                  { static int complained = 0;
+                                    if (!complained) {
+                                      errormsg(Error,"Bad format sequence 
``%%%c'' in -L%s",*p,fmt);
+                                      complained = 1;
+                                    }
+                                  }
+                              break;            
+                    default:  { static int complained = 0;
+                                if (!complained) {
+                                  errormsg(Error,"Bad format sequence ``%%%c'' 
in -L%s",*p,fmt);
+                                  complained = 1;
+                                }
+                              }   break;
+                }
+            } else putc(*p, fp);
         }
-    } else putc(*p, fp);
-}
-#line 257 "modules.nw"
         lastfilename = loc.filename;
         lastlineno = loc.lineno;
         return 1;
     } else return 0;
 }
-#line 309 "modules.nw"
 void remove_final_newline (Module mp) {
         /* remove trailing newline that must be in module */
     if (mp->tail==NULL) /* module has no text */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]