help-flex
[Top][All Lists]
Advanced

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

Re: skelout patch


From: John W. Millaway
Subject: Re: skelout patch
Date: Fri, 10 May 2002 12:01:03 -0700 (PDT)

I see what the bug is. The default skel array does not contain newlines, but
your skel does, naturally. It has been fixed.  The solution was to eat the
newlines before processing the buffer. Thank you for bringing this bug to our
attention!

FYI, here is the cvs diff:


Index: flexdef.h
===================================================================
RCS file: /usr/local/cvsroot/flex/flexdef.h,v
retrieving revision 2.64
diff -c -r2.64 flexdef.h
*** flexdef.h   19 Apr 2002 22:20:24 -0000      2.64
--- flexdef.h   10 May 2002 19:00:48 -0000
***************
*** 1058,1061 ****
--- 1058,1064 ----
  extern jmp_buf flex_main_jmp_buf;
  #define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1)

+ /* Removes all \n and \r chars from tail of str. returns str. */
+ extern char* chomp(char* str);
+
  #endif /* not defined FLEXDEF_H */
Index: misc.c
===================================================================
RCS file: /usr/local/cvsroot/flex/misc.c,v
retrieving revision 2.55
diff -c -r2.55 misc.c
*** misc.c      19 Apr 2002 22:20:24 -0000      2.55
--- misc.c      10 May 2002 19:00:49 -0000
***************
*** 796,802 ****
        while ( skelfile ?
                (fgets( buf, MAXLINE, skelfile ) != NULL) :
                ((buf = (char *) skel[skel_ind++]) != 0) )
!               { /* copy from skel array */
                if ( buf[0] == '%' )
                        { /* control line */
                        /* print the control line as a comment. */
--- 796,807 ----
        while ( skelfile ?
                (fgets( buf, MAXLINE, skelfile ) != NULL) :
                ((buf = (char *) skel[skel_ind++]) != 0) )
!               {
!
!               if (skelfile )
!                       chomp(buf);
!
!               /* copy from skel array */
                if ( buf[0] == '%' )
                        { /* control line */
                        /* print the control line as a comment. */
***************
*** 915,917 ****
--- 920,941 ----
        while ( rp < rp_end )
                *rp++ = 0;
        }
+
+ /* Remove all '\n' and '\r' characters, if any, from the end of str.
+  * str can be any null-terminated string, or NULL.
+  * returns str. */
+ char* chomp(char* str){
+     char* p=str;
+     if (!str || !*str)  /* s is null or empty string */
+         return str;
+
+     /* find end of string minus one*/
+     while (*p)
+         ++p;
+     --p;
+
+     /* eat newlines */
+     while (p >= str && (*p == '\r' || *p == '\n'))
+         *p-- = 0;
+     return str;
+ }


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Mother's Day is May 12th!
http://shopping.yahoo.com



reply via email to

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