]> granicus.if.org Git - yasm/commitdiff
Use autoconf to determine when to include our implementation of strdup, so
authorPeter Johnson <peter@tortall.net>
Thu, 28 Jun 2001 08:48:32 +0000 (08:48 -0000)
committerPeter Johnson <peter@tortall.net>
Thu, 28 Jun 2001 08:48:32 +0000 (08:48 -0000)
remove util.c and create strdup.c.  Make util.h, strdup.c, and several source
files use config.h defines.

svn path=/trunk/yasm/; revision=61

13 files changed:
configure.ac
configure.in
include/util.h
libyasm/errwarn.c
libyasm/util.h
modules/parsers/nasm/token.l.in
src/Makefile.am
src/errwarn.c
src/parsers/nasm/token.l.in
src/token.l.in
src/util.c [deleted file]
src/util.h
util.h

index 1decd3f0902750cf40710ab310993d20b4f666db..c2104189bcf7ec1e46c40e502dc8fa80f2d0d51f 100644 (file)
@@ -10,4 +10,8 @@ AM_PROG_LEX
 AC_PROG_YACC
 AC_PROG_INSTALL
 
+AC_HEADER_STDC
+AC_CHECK_FUNCS(memcpy)
+AC_REPLACE_FUNCS(strdup)
+
 AC_OUTPUT(Makefile src/Makefile        include/Makefile)
index 1decd3f0902750cf40710ab310993d20b4f666db..c2104189bcf7ec1e46c40e502dc8fa80f2d0d51f 100644 (file)
@@ -10,4 +10,8 @@ AM_PROG_LEX
 AC_PROG_YACC
 AC_PROG_INSTALL
 
+AC_HEADER_STDC
+AC_CHECK_FUNCS(memcpy)
+AC_REPLACE_FUNCS(strdup)
+
 AC_OUTPUT(Makefile src/Makefile        include/Makefile)
index 33377ab9072e9f1271190137a15046f3f6ce94c4..df5fe7f4b9fc01efe4a383d479d7f26e0d85800a 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: util.h,v 1.1 2001/06/13 05:24:50 peter Exp $
- * Various utility functions for ANSI C compatibility header file
+/* $Id: util.h,v 1.2 2001/06/28 08:48:32 peter Exp $
+ * Defines prototypes for replacement functions if needed.
  *
  *  Copyright (C) 2001  Peter Johnson
  *
@@ -22,6 +22,8 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
-char *y_strdup(char *str);
+#ifndef HAVE_STRDUP
+char *strdup(const char *str);
+#endif
 
 #endif
index b0e7fd7fc31e86f348ddef51afedbac16c4be676..a93409101a6c0377f51abec0f0dd6a475ab3fddc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: errwarn.c,v 1.10 2001/06/13 06:05:08 peter Exp $
+/* $Id: errwarn.c,v 1.11 2001/06/28 08:48:32 peter Exp $
  * Error and warning reporting and related functions.
  *
  *  Copyright (C) 2001  Peter Johnson
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <stdio.h>
+
+#ifdef STDC_HEADERS
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#endif
+
 #include <ctype.h>
+
+#include "util.h"
+
 #include "errwarn.h"
 #include "globals.h"
-#include "util.h"
 
 unsigned int error_count = 0;
 unsigned int warning_count = 0;
@@ -132,7 +142,7 @@ static char *process_argtypes(char *src, char *argtypes)
            }
        }
     } else {
-       dest = y_strdup(src);
+       dest = strdup(src);
        if(!dest)
            Fatal(FATAL_NOMEM);
     }
index 33377ab9072e9f1271190137a15046f3f6ce94c4..df5fe7f4b9fc01efe4a383d479d7f26e0d85800a 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: util.h,v 1.1 2001/06/13 05:24:50 peter Exp $
- * Various utility functions for ANSI C compatibility header file
+/* $Id: util.h,v 1.2 2001/06/28 08:48:32 peter Exp $
+ * Defines prototypes for replacement functions if needed.
  *
  *  Copyright (C) 2001  Peter Johnson
  *
@@ -22,6 +22,8 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
-char *y_strdup(char *str);
+#ifndef HAVE_STRDUP
+char *strdup(const char *str);
+#endif
 
 #endif
index 7aa6cc96e6ba1c8d4987b8095253405803829b43..520c33f7cc80cc7a76972cf18916668aa4763036 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: token.l.in,v 1.6 2001/06/13 05:43:59 mu Exp $
+/* $Id: token.l.in,v 1.7 2001/06/28 08:48:32 peter Exp $
  * Main lexer
  *
  *  Copyright (C) 2001  Peter Johnson
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 %{
-#include <stdlib.h>
-#include <string.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+#include "util.h"
+
 #include "symrec.h"
 #include "bytecode.h"
 #include "errwarn.h"
-#include "util.h"
 #include "bison.tab.h"
 
 %}
@@ -90,14 +98,14 @@ WS       [ \t\r]
 <DIRECTIVE2>{WS}+   ;
 <DIRECTIVE>[a-z]+   {
     BEGIN DIRECTIVE2;
-    yylval.str_val = y_strdup(yytext);
+    yylval.str_val = strdup(yytext);
     if(!yylval.str_val)
        Fatal(FATAL_NOMEM);
     return DIRECTIVE_NAME;
 }
     /* everything printable except for ' ', '[' and ']'. */
 <DIRECTIVE2>[!-@a-z\\^-`{|}~]+ {
-    yylval.str_val = y_strdup(yytext);
+    yylval.str_val = strdup(yytext);
     if(!yylval.str_val)
        Fatal(FATAL_NOMEM);
     return DIRECTIVE_VAL;
@@ -222,7 +230,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
 
     /* special non-local ..@label */
 \.\.@[a-z0-9_$#@~.?]+ {
-    yylval.syminfo.name = y_strdup (yytext);
+    yylval.syminfo.name = strdup (yytext);
     if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     yylval.syminfo.line = line_number;
 
@@ -234,7 +242,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
     if (locallabel_base == NULL) 
     {
        Warning (WARN_NO_BASE_LABEL, (char *)NULL, yytext);
-       yylval.syminfo.name = y_strdup (yytext);
+       yylval.syminfo.name = strdup (yytext);
        if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     }
     else
@@ -256,7 +264,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
 
     /* label */
 [a-z_?][a-z0-9_$#@~.?]* {
-    yylval.syminfo.name = y_strdup (yytext);
+    yylval.syminfo.name = strdup (yytext);
     if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     yylval.syminfo.line = line_number;
 
index 5879564c65d2f28f3659a8b00cb94c446c3ec448..f7333354dbc6555240ff66ae6db0897618170c67 100644 (file)
@@ -8,8 +8,7 @@ yasm_SOURCES = \
        bytecode.c              \
        errwarn.c               \
        main.c                  \
-       symrec.c                \
-       util.c
+       symrec.c
 
 noinst_SCRIPTS = gen_instr.pl
 
index b0e7fd7fc31e86f348ddef51afedbac16c4be676..a93409101a6c0377f51abec0f0dd6a475ab3fddc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: errwarn.c,v 1.10 2001/06/13 06:05:08 peter Exp $
+/* $Id: errwarn.c,v 1.11 2001/06/28 08:48:32 peter Exp $
  * Error and warning reporting and related functions.
  *
  *  Copyright (C) 2001  Peter Johnson
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <stdio.h>
+
+#ifdef STDC_HEADERS
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#endif
+
 #include <ctype.h>
+
+#include "util.h"
+
 #include "errwarn.h"
 #include "globals.h"
-#include "util.h"
 
 unsigned int error_count = 0;
 unsigned int warning_count = 0;
@@ -132,7 +142,7 @@ static char *process_argtypes(char *src, char *argtypes)
            }
        }
     } else {
-       dest = y_strdup(src);
+       dest = strdup(src);
        if(!dest)
            Fatal(FATAL_NOMEM);
     }
index 7aa6cc96e6ba1c8d4987b8095253405803829b43..520c33f7cc80cc7a76972cf18916668aa4763036 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: token.l.in,v 1.6 2001/06/13 05:43:59 mu Exp $
+/* $Id: token.l.in,v 1.7 2001/06/28 08:48:32 peter Exp $
  * Main lexer
  *
  *  Copyright (C) 2001  Peter Johnson
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 %{
-#include <stdlib.h>
-#include <string.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+#include "util.h"
+
 #include "symrec.h"
 #include "bytecode.h"
 #include "errwarn.h"
-#include "util.h"
 #include "bison.tab.h"
 
 %}
@@ -90,14 +98,14 @@ WS       [ \t\r]
 <DIRECTIVE2>{WS}+   ;
 <DIRECTIVE>[a-z]+   {
     BEGIN DIRECTIVE2;
-    yylval.str_val = y_strdup(yytext);
+    yylval.str_val = strdup(yytext);
     if(!yylval.str_val)
        Fatal(FATAL_NOMEM);
     return DIRECTIVE_NAME;
 }
     /* everything printable except for ' ', '[' and ']'. */
 <DIRECTIVE2>[!-@a-z\\^-`{|}~]+ {
-    yylval.str_val = y_strdup(yytext);
+    yylval.str_val = strdup(yytext);
     if(!yylval.str_val)
        Fatal(FATAL_NOMEM);
     return DIRECTIVE_VAL;
@@ -222,7 +230,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
 
     /* special non-local ..@label */
 \.\.@[a-z0-9_$#@~.?]+ {
-    yylval.syminfo.name = y_strdup (yytext);
+    yylval.syminfo.name = strdup (yytext);
     if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     yylval.syminfo.line = line_number;
 
@@ -234,7 +242,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
     if (locallabel_base == NULL) 
     {
        Warning (WARN_NO_BASE_LABEL, (char *)NULL, yytext);
-       yylval.syminfo.name = y_strdup (yytext);
+       yylval.syminfo.name = strdup (yytext);
        if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     }
     else
@@ -256,7 +264,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
 
     /* label */
 [a-z_?][a-z0-9_$#@~.?]* {
-    yylval.syminfo.name = y_strdup (yytext);
+    yylval.syminfo.name = strdup (yytext);
     if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     yylval.syminfo.line = line_number;
 
index 7aa6cc96e6ba1c8d4987b8095253405803829b43..520c33f7cc80cc7a76972cf18916668aa4763036 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: token.l.in,v 1.6 2001/06/13 05:43:59 mu Exp $
+/* $Id: token.l.in,v 1.7 2001/06/28 08:48:32 peter Exp $
  * Main lexer
  *
  *  Copyright (C) 2001  Peter Johnson
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 %{
-#include <stdlib.h>
-#include <string.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+#include "util.h"
+
 #include "symrec.h"
 #include "bytecode.h"
 #include "errwarn.h"
-#include "util.h"
 #include "bison.tab.h"
 
 %}
@@ -90,14 +98,14 @@ WS       [ \t\r]
 <DIRECTIVE2>{WS}+   ;
 <DIRECTIVE>[a-z]+   {
     BEGIN DIRECTIVE2;
-    yylval.str_val = y_strdup(yytext);
+    yylval.str_val = strdup(yytext);
     if(!yylval.str_val)
        Fatal(FATAL_NOMEM);
     return DIRECTIVE_NAME;
 }
     /* everything printable except for ' ', '[' and ']'. */
 <DIRECTIVE2>[!-@a-z\\^-`{|}~]+ {
-    yylval.str_val = y_strdup(yytext);
+    yylval.str_val = strdup(yytext);
     if(!yylval.str_val)
        Fatal(FATAL_NOMEM);
     return DIRECTIVE_VAL;
@@ -222,7 +230,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
 
     /* special non-local ..@label */
 \.\.@[a-z0-9_$#@~.?]+ {
-    yylval.syminfo.name = y_strdup (yytext);
+    yylval.syminfo.name = strdup (yytext);
     if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     yylval.syminfo.line = line_number;
 
@@ -234,7 +242,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
     if (locallabel_base == NULL) 
     {
        Warning (WARN_NO_BASE_LABEL, (char *)NULL, yytext);
-       yylval.syminfo.name = y_strdup (yytext);
+       yylval.syminfo.name = strdup (yytext);
        if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     }
     else
@@ -256,7 +264,7 @@ gs  { yylval.int_val = 5; return REG_GS; }
 
     /* label */
 [a-z_?][a-z0-9_$#@~.?]* {
-    yylval.syminfo.name = y_strdup (yytext);
+    yylval.syminfo.name = strdup (yytext);
     if (yylval.syminfo.name == NULL) Fatal (FATAL_NOMEM);
     yylval.syminfo.line = line_number;
 
diff --git a/src/util.c b/src/util.c
deleted file mode 100644 (file)
index 52496cc..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* $Id: util.c,v 1.1 2001/06/13 05:24:50 peter Exp $
- * Various utility functions for ANSI C compatibility
- *
- *  Copyright (C) 2001  Peter Johnson
- *
- *  This file is part of YASM.
- *
- *  YASM is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  YASM is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-#include <stdlib.h>
-#include <string.h>
-#include "util.h"
-
-char *y_strdup(char *str)
-{
-    size_t len;
-    char *copy;
-
-    len = strlen(str) + 1;
-    if((copy = malloc(len)) == NULL)
-       return (char *)NULL;
-    memcpy(copy, str, len);
-    return copy;
-}
index 33377ab9072e9f1271190137a15046f3f6ce94c4..df5fe7f4b9fc01efe4a383d479d7f26e0d85800a 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: util.h,v 1.1 2001/06/13 05:24:50 peter Exp $
- * Various utility functions for ANSI C compatibility header file
+/* $Id: util.h,v 1.2 2001/06/28 08:48:32 peter Exp $
+ * Defines prototypes for replacement functions if needed.
  *
  *  Copyright (C) 2001  Peter Johnson
  *
@@ -22,6 +22,8 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
-char *y_strdup(char *str);
+#ifndef HAVE_STRDUP
+char *strdup(const char *str);
+#endif
 
 #endif
diff --git a/util.h b/util.h
index 33377ab9072e9f1271190137a15046f3f6ce94c4..df5fe7f4b9fc01efe4a383d479d7f26e0d85800a 100644 (file)
--- a/util.h
+++ b/util.h
@@ -1,5 +1,5 @@
-/* $Id: util.h,v 1.1 2001/06/13 05:24:50 peter Exp $
- * Various utility functions for ANSI C compatibility header file
+/* $Id: util.h,v 1.2 2001/06/28 08:48:32 peter Exp $
+ * Defines prototypes for replacement functions if needed.
  *
  *  Copyright (C) 2001  Peter Johnson
  *
@@ -22,6 +22,8 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
-char *y_strdup(char *str);
+#ifndef HAVE_STRDUP
+char *strdup(const char *str);
+#endif
 
 #endif