svn commit: r250876 - head/contrib/flex

Jung-uk Kim jkim at FreeBSD.org
Tue May 21 19:20:04 UTC 2013


Author: jkim
Date: Tue May 21 19:20:03 2013
New Revision: 250876
URL: http://svnweb.freebsd.org/changeset/base/250876

Log:
  Do not use log10(3) to get rid of libm dependency.  It is really not useful.

Modified:
  head/contrib/flex/buf.c
  head/contrib/flex/flexdef.h
  head/contrib/flex/main.c

Modified: head/contrib/flex/buf.c
==============================================================================
--- head/contrib/flex/buf.c	Tue May 21 19:17:02 2013	(r250875)
+++ head/contrib/flex/buf.c	Tue May 21 19:20:03 2013	(r250876)
@@ -95,7 +95,7 @@ struct Buf *buf_linedir (struct Buf *buf
 
     t = flex_alloc (strlen ("#line \"\"\n")          +   /* constant parts */
                     2 * strlen (filename)            +   /* filename with possibly all backslashes escaped */
-                    (int) (1 + log10 (abs (lineno))) +   /* line number */
+                    NUMCHARLINES                     +   /* line number */
                     1);                                  /* NUL */
     if (!t)
       flexfatal (_("Allocation of buffer for line directive failed"));

Modified: head/contrib/flex/flexdef.h
==============================================================================
--- head/contrib/flex/flexdef.h	Tue May 21 19:17:02 2013	(r250875)
+++ head/contrib/flex/flexdef.h	Tue May 21 19:20:03 2013	(r250876)
@@ -61,7 +61,6 @@ char *alloca ();
 #include <setjmp.h>
 #include <ctype.h>
 #include <string.h>
-#include <math.h>
 #endif
 #ifdef HAVE_ASSERT_H
 #include <assert.h>
@@ -171,6 +170,9 @@ char *alloca ();
  */
 #define NUMDATALINES 10
 
+/* Number of characters to print a line number, i.e., 1 + log10(INT_MAX) */
+#define NUMCHARLINES 10
+
 /* transition_struct_out() definitions. */
 #define TRANS_STRUCT_PRINT_LENGTH 14
 

Modified: head/contrib/flex/main.c
==============================================================================
--- head/contrib/flex/main.c	Tue May 21 19:17:02 2013	(r250875)
+++ head/contrib/flex/main.c	Tue May 21 19:20:03 2013	(r250876)
@@ -451,7 +451,7 @@ void check_options ()
              char *str, *fmt = "#define %s %d\n";
              size_t strsz;
 
-             str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2);
+             str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + NUMCHARLINES + 2);
              if (!str)
                flexfatal(_("allocation of macro definition failed"));
              snprintf(str, strsz, fmt,      scname[i], i - 1);


More information about the svn-src-head mailing list