From: Peter Johnson Date: Thu, 28 Jun 2001 08:48:32 +0000 (-0000) Subject: Use autoconf to determine when to include our implementation of strdup, so X-Git-Tag: v0.1.0~450 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b932274826502ec8715c1195771263b1c7cda74;p=yasm Use autoconf to determine when to include our implementation of strdup, so 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 --- diff --git a/configure.ac b/configure.ac index 1decd3f0..c2104189 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/configure.in b/configure.in index 1decd3f0..c2104189 100644 --- a/configure.in +++ b/configure.in @@ -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) diff --git a/include/util.h b/include/util.h index 33377ab9..df5fe7f4 100644 --- a/include/util.h +++ b/include/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 diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index b0e7fd7f..a9340910 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -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 @@ -19,14 +19,24 @@ * 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 + +#ifdef STDC_HEADERS #include #include #include +#endif + #include + +#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); } diff --git a/libyasm/util.h b/libyasm/util.h index 33377ab9..df5fe7f4 100644 --- a/libyasm/util.h +++ b/libyasm/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 diff --git a/modules/parsers/nasm/token.l.in b/modules/parsers/nasm/token.l.in index 7aa6cc96..520c33f7 100644 --- a/modules/parsers/nasm/token.l.in +++ b/modules/parsers/nasm/token.l.in @@ -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 @@ -20,12 +20,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ %{ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +# include +#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] {WS}+ ; [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 ']'. */ [!-@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/Makefile.am b/src/Makefile.am index 5879564c..f7333354 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,8 +8,7 @@ yasm_SOURCES = \ bytecode.c \ errwarn.c \ main.c \ - symrec.c \ - util.c + symrec.c noinst_SCRIPTS = gen_instr.pl diff --git a/src/errwarn.c b/src/errwarn.c index b0e7fd7f..a9340910 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -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 @@ -19,14 +19,24 @@ * 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 + +#ifdef STDC_HEADERS #include #include #include +#endif + #include + +#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); } diff --git a/src/parsers/nasm/token.l.in b/src/parsers/nasm/token.l.in index 7aa6cc96..520c33f7 100644 --- a/src/parsers/nasm/token.l.in +++ b/src/parsers/nasm/token.l.in @@ -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 @@ -20,12 +20,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ %{ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +# include +#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] {WS}+ ; [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 ']'. */ [!-@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/token.l.in b/src/token.l.in index 7aa6cc96..520c33f7 100644 --- a/src/token.l.in +++ b/src/token.l.in @@ -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 @@ -20,12 +20,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ %{ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +# include +#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] {WS}+ ; [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 ']'. */ [!-@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 index 52496ccd..00000000 --- a/src/util.c +++ /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 -#include -#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; -} diff --git a/src/util.h b/src/util.h index 33377ab9..df5fe7f4 100644 --- a/src/util.h +++ b/src/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 diff --git a/util.h b/util.h index 33377ab9..df5fe7f4 100644 --- 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