fatbase

portable OpenBSD tools
git clone git://git.2f30.org/fatbase.git
Log | Files | Refs

commit fb2850ba8cbf9831d6a14dbff9525f0bbda7726f
parent 6df6d7bdd444c5e86f203f52c0b0e53baa883ce1
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri Nov 21 21:54:09 +0100

lex: improve Makefile

Diffstat:
lex/Makefile | 46+++++++++++++++++-----------------------------
lex/Makefile.bak | 50--------------------------------------------------
lex/initscan.c | 2+-
lex/scan.l | 2+-
lex/strlcpy.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
lex/yylex.c | 2+-
6 files changed, 68 insertions(+), 82 deletions(-)
diff --git a/lex/Makefile b/lex/Makefile @@ -1,34 +1,22 @@ -# $OpenBSD: Makefile,v 1.11 2013/06/18 17:38:46 robert Exp $ -# -# By default, flex will be configured to generate 8-bit scanners only if the -# -8 flag is given. If you want it to always generate 8-bit scanners, add -# "-DDEFAULT_CSIZE=256" to CFLAGS. Note that doing so will double the size -# of all uncompressed scanners. -# -# If on your system you have trouble building flex due to 8-bit character -# problems, remove the -8 from FLEX_FLAGS and the "#define FLEX_8_BIT_CHARS" -# from the beginning of flexdef.h. -# -# To bootstrap lex, cp initscan.c to scan.c and run make. +OBJ = scan.o ytab.o skel.o ccl.o dfa.o ecs.o gen.o main.o misc.o nfa.o sym.o tblcmp.o \ + yylex.o strlcpy.o +TARG = lex +LDLIBS = -build: libl clean - # parse.c - ../yacc/yacc -o parse.c -d parse.y - cc -c parse.c - # bootstrap -# cp initscan.c scan.c - flex -t -p scan.l > scan.c - cc -c scan.c - # skel.c +all: ytab.c skel.c scan.c $(TARG) + +ytab.c ytab.h: parse.y + $(YACC) -d parse.y + mv y.tab.c ytab.c + mv y.tab.h ytab.h + +skel.c: flex.skl sh mkskel.sh flex.skl > skel.c - cc -c skel.c - # compile *.c - cc -c ccl.c dfa.c ecs.c gen.c main.c misc.c nfa.c parse.c sym.c tblcmp.c \ - yylex.c - cc -o lex *.o -libl: - cc -c libmain.c libyywrap.c +scan.c: scan.l + $(LEX) -t -p scan.l > scan.c + +include ../std.mk clean: - rm -f *.o lex scan.c skel.c parse.c parse.h + rm -f $(TARG) $(OBJ) ytab.[ch] skel.c scan.c diff --git a/lex/Makefile.bak b/lex/Makefile.bak @@ -1,50 +0,0 @@ -# $OpenBSD: Makefile,v 1.11 2013/06/18 17:38:46 robert Exp $ -# -# By default, flex will be configured to generate 8-bit scanners only if the -# -8 flag is given. If you want it to always generate 8-bit scanners, add -# "-DDEFAULT_CSIZE=256" to CFLAGS. Note that doing so will double the size -# of all uncompressed scanners. -# -# If on your system you have trouble building flex due to 8-bit character -# problems, remove the -8 from FLEX_FLAGS and the "#define FLEX_8_BIT_CHARS" -# from the beginning of flexdef.h. -# -# To bootstrap lex, cp initscan.c to scan.c and run make. - -PROG= lex -CFLAGS+=-I. -I${.CURDIR} -SRCS= ccl.c dfa.c ecs.c gen.c main.c misc.c nfa.c parse.c sym.c tblcmp.c \ - yylex.c -OBJS+= scan.o skel.o -CLEANFILES+=parse.c parse.h scan.c skel.c y.tab.c y.tab.h -LDADD= -ll -DPADD= ${LIBL} - -MAN = flex.1 - -LINKS= ${BINDIR}/lex ${BINDIR}/flex \ - ${BINDIR}/lex ${BINDIR}/flex++ -MLINKS= flex.1 lex.1 flex.1 flex++.1 - -parse.h parse.c: parse.y - ${YACC} -d ${.ALLSRC} - mv y.tab.c parse.c - mv y.tab.h parse.h - -skel.c: flex.skl mkskel.sh - sh ${.CURDIR}/mkskel.sh ${.CURDIR}/flex.skl > skel.c - -scan.c: scan.l - flex -t -p ${.CURDIR}/scan.l > scan.c - -scan.o: parse.c - -includes: -.if !exists(${DESTDIR}/usr/include/g++) - ${INSTALL} -d -o root -g bin -m 755 \ - ${DESTDIR}/usr/include/g++ -.endif - ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \ - ${.CURDIR}/FlexLexer.h ${DESTDIR}/usr/include/g++/ - -.include <bsd.prog.mk> diff --git a/lex/initscan.c b/lex/initscan.c @@ -1279,7 +1279,7 @@ char *yytext; /* $Header: /cvs/src/usr.bin/lex/initscan.c,v 1.14 2013/11/04 17:03:32 millert Exp $ */ #include "flexdef.h" -#include "parse.h" +#include "ytab.h" #define ACTION_ECHO add_action( yytext ) #define ACTION_IFDEF(def, should_define) \ diff --git a/lex/scan.l b/lex/scan.l @@ -37,7 +37,7 @@ /* $Header: /cvs/src/usr.bin/lex/scan.l,v 1.9 2006/12/06 05:03:29 ray Exp $ */ #include "flexdef.h" -#include "parse.h" +#include "ytab.h" #define ACTION_ECHO add_action( yytext ) #define ACTION_IFDEF(def, should_define) \ diff --git a/lex/strlcpy.c b/lex/strlcpy.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <string.h> +#include <sys/types.h> + +#include "util.h" + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + return(s - src - 1); /* count does not include NUL */ +} diff --git a/lex/yylex.c b/lex/yylex.c @@ -37,7 +37,7 @@ #include <ctype.h> #include "flexdef.h" -#include "parse.h" +#include "ytab.h" /* yylex - scan for a regular expression token */