changeset 5932:51cbaa2539f4

[project @ 2006-08-16 06:55:23 by jwe]
author jwe
date Wed, 16 Aug 2006 06:55:23 +0000
parents 25da9a7d5f6d
children 1bcd9dd629c3
files src/ChangeLog src/parse.y
diffstat 2 files changed, 36 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-16  John W. Eaton  <jwe@octave.org>
+
+	* parse.y (gobble_leading_white_space): New arg, SKIP_CODE.
+	Change all uses.
+
 2006-08-15  John W. Eaton  <jwe@octave.org>
 
 	* help.cc (help_from_file): Call get_help_from_file with new file
--- a/src/parse.y
+++ b/src/parse.y
@@ -3003,14 +3003,28 @@
 // grab them all at once.  If UPDATE_POS is TRUE, line and column
 // number information is updated.  If SAVE_COPYRIGHT is TRUE, then
 // comments that are recognized as a copyright notice are saved in the
-// comment buffer.
+// comment buffer.  If SKIP_CODE is TRUE, then ignore code, otherwise
+// stop at the first non-whitespace character that is not part of a
+// comment.
+
+// FIXME -- skipping code will fail for something like this:
+//
+//   function foo (x)
+//     fprintf ('%d\n', x);
+//
+//   % This is the help for foo.
+//
+// because we recognize the '%' in the fprintf format as a comment
+// character.  Fixing this will probably require actually parsing the
+// file properly.
 
 // FIXME -- grab_help_text() in lex.l duplicates some of this
 // code!
 
 static std::string
 gobble_leading_white_space (FILE *ffile, bool in_parts,
-			    bool update_pos, bool save_copyright)
+			    bool update_pos, bool save_copyright,
+			    bool skip_code)
 {
   std::string help_txt;
 
@@ -3111,10 +3125,15 @@
 	      continue;
 
 	    default:
-	      if (update_pos)
-		current_input_column--;
-	      ungetc (c, ffile);
-	      goto done;
+	      if (skip_code)
+		continue;
+	      else
+		{
+		  if (update_pos)
+		    current_input_column--;
+		  ungetc (c, ffile);
+		  goto done;
+		}
 	    }
 	}
     }
@@ -3132,8 +3151,8 @@
 	}
 
       if (in_parts && help_txt.empty ())
-	help_txt = gobble_leading_white_space (ffile, in_parts,
-					       update_pos, false);
+	help_txt = gobble_leading_white_space (ffile, in_parts, update_pos,
+					       false, skip_code);
     }
 
   return help_txt;
@@ -3157,7 +3176,7 @@
 	{
 	  unwind_protect::add (safe_fclose, fptr);
 
-	  retval = gobble_leading_white_space (fptr, true, true, false);
+	  retval = gobble_leading_white_space (fptr, true, true, false, true);
 
 	  unwind_protect::run ();
 	}
@@ -3180,7 +3199,7 @@
 
   long pos = ftell (ffile);
 
-  gobble_leading_white_space (ffile, false, false, false);
+  gobble_leading_white_space (ffile, false, false, false, false);
 
   char buf [10];
   fgets (buf, 10, ffile);
@@ -3280,14 +3299,14 @@
 	  reset_parser ();
 
 	  std::string txt
-	    = gobble_leading_white_space (ffile, true, true, true);
+	    = gobble_leading_white_space (ffile, true, true, true, false);
 
 	  help_buf.push (txt);
 
 	  octave_comment_buffer::append (txt);
 
 	  // FIXME -- this should not be necessary.
-	  gobble_leading_white_space (ffile, false, true, false);
+	  gobble_leading_white_space (ffile, false, true, false, false);
 
 	  int status = yyparse ();