Skip to content

Commit 3ac29cb

Browse files
committed
Rebased against awk from OpenBSD 6.2.
2 parents 0efd9e7 + b55e3d6 commit 3ac29cb

10 files changed

Lines changed: 205 additions & 15 deletions

File tree

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# $OpenBSD: Makefile,v 1.13 2013/07/28 18:10:16 miod Exp $
1+
# $OpenBSD: Makefile,v 1.16 2017/07/10 21:30:37 espie Exp $
22

33
PROG= awk
4-
SRCS= ytab.c lex.c b.c main.c parse.c proctab.c tran.c lib.c run.c reallocarray.c
4+
SRCS= ytab.c lex.c b.c main.c parse.c proctab.c tran.c lib.c run.c reallocarray.c strlcpy.c strlcat.c
55
PKG_CONFIG?= pkg-config
66
LDADD= -lm
77
DPADD= ${LIBM}
@@ -22,9 +22,9 @@ $(PROG): proctab.c
2222
$(CC) $(CFLAGS) $(SRCS) $(LDFLAGS) $(LDADD) -o $(PROG)
2323

2424
ytab.c ytab.h: awkgram.y
25-
${YACC} -d ${CURDIR}/awkgram.y
26-
mv y.tab.c ytab.c
27-
mv y.tab.h ytab.h
25+
${YACC} -o ytab.c -d ${CURDIR}/awkgram.y
26+
27+
BUILDFIRST = ytab.h
2828

2929
proctab.c: ytab.h maketab.c
3030
${HOSTCC} ${HOSTCFLAGS} ${CURDIR}/maketab.c -o maketab

lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: lib.c,v 1.22 2016/04/12 19:43:38 millert Exp $ */
1+
/* $OpenBSD: lib.c,v 1.23 2017/09/25 17:36:35 krw Exp $ */
22
/****************************************************************
33
Copyright (C) Lucent Technologies 1997
44
All Rights Reserved

proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: proto.h,v 1.9 2011/09/28 19:27:18 millert Exp $ */
1+
/* $OpenBSD: proto.h,v 1.10 2017/09/25 17:36:35 krw Exp $ */
22
/****************************************************************
33
Copyright (C) Lucent Technologies 1997
44
All Rights Reserved

reallocarray.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ reallocarray(void *optr, size_t nmemb, size_t size)
3636
}
3737
return realloc(optr, size * nmemb);
3838
}
39-
DEF_WEAK(reallocarray);

run.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: run.c,v 1.40 2015/12/16 19:44:42 tb Exp $ */
1+
/* $OpenBSD: run.c,v 1.41 2017/09/15 14:19:56 ajacoutot Exp $ */
22
/****************************************************************
33
Copyright (C) Lucent Technologies 1997
44
All Rights Reserved
@@ -1545,7 +1545,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
15451545
break;
15461546
case FXOR:
15471547
if (nextarg == 0) {
1548-
WARNING("or requires two arguments; returning 0");
1548+
WARNING("xor requires two arguments; returning 0");
15491549
u = 0;
15501550
break;
15511551
}
@@ -1556,7 +1556,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
15561556
break;
15571557
case FLSHIFT:
15581558
if (nextarg == 0) {
1559-
WARNING("or requires two arguments; returning 0");
1559+
WARNING("lshift requires two arguments; returning 0");
15601560
u = 0;
15611561
break;
15621562
}
@@ -1567,7 +1567,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
15671567
break;
15681568
case FRSHIFT:
15691569
if (nextarg == 0) {
1570-
WARNING("or requires two arguments; returning 0");
1570+
WARNING("rshift requires two arguments; returning 0");
15711571
u = 0;
15721572
break;
15731573
}

stdlib.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef _COMPAT_STDLIB_H_xxx
2+
#define _COMPAT_STDLIB_H_xxx
3+
4+
#undef __need_malloc_and_calloc
5+
#include_next <stdlib.h>
6+
7+
/* $OpenBSD: stdlib.h,v 1.72 2017/09/05 03:16:13 schwarze Exp $ */
8+
/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
9+
10+
/*-
11+
* Copyright (c) 1990 The Regents of the University of California.
12+
* All rights reserved.
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, are permitted provided that the following conditions
16+
* are met:
17+
* 1. Redistributions of source code must retain the above copyright
18+
* notice, this list of conditions and the following disclaimer.
19+
* 2. Redistributions in binary form must reproduce the above copyright
20+
* notice, this list of conditions and the following disclaimer in the
21+
* documentation and/or other materials provided with the distribution.
22+
* 3. Neither the name of the University nor the names of its contributors
23+
* may be used to endorse or promote products derived from this software
24+
* without specific prior written permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36+
* SUCH DAMAGE.
37+
*
38+
* @(#)stdlib.h 5.13 (Berkeley) 6/4/91
39+
*/
40+
41+
void *reallocarray(void *, size_t, size_t);
42+
43+
#endif

string.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef _COMPAT_STRING_H_
2+
#define _COMPAT_STRING_H_
3+
4+
#include_next <string.h>
5+
6+
/* $OpenBSD: string.h,v 1.32 2017/09/05 03:16:13 schwarze Exp $ */
7+
/* $NetBSD: string.h,v 1.6 1994/10/26 00:56:30 cgd Exp $ */
8+
9+
/*-
10+
* Copyright (c) 1990 The Regents of the University of California.
11+
* All rights reserved.
12+
*
13+
* Redistribution and use in source and binary forms, with or without
14+
* modification, are permitted provided that the following conditions
15+
* are met:
16+
* 1. Redistributions of source code must retain the above copyright
17+
* notice, this list of conditions and the following disclaimer.
18+
* 2. Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimer in the
20+
* documentation and/or other materials provided with the distribution.
21+
* 3. Neither the name of the University nor the names of its contributors
22+
* may be used to endorse or promote products derived from this software
23+
* without specific prior written permission.
24+
*
25+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35+
* SUCH DAMAGE.
36+
*
37+
* @(#)string.h 5.10 (Berkeley) 3/9/91
38+
*/
39+
40+
size_t strlcat(char *, const char *, size_t);
41+
size_t strlcpy(char *, const char *, size_t);
42+
43+
#endif /* _STRING_H_ */

strlcat.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */
2+
3+
/*
4+
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include <sys/types.h>
20+
#include <string.h>
21+
22+
/*
23+
* Appends src to string dst of size dsize (unlike strncat, dsize is the
24+
* full size of dst, not space left). At most dsize-1 characters
25+
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
26+
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
27+
* If retval >= dsize, truncation occurred.
28+
*/
29+
size_t
30+
strlcat(char *dst, const char *src, size_t dsize)
31+
{
32+
const char *odst = dst;
33+
const char *osrc = src;
34+
size_t n = dsize;
35+
size_t dlen;
36+
37+
/* Find the end of dst and adjust bytes left but don't go past end. */
38+
while (n-- != 0 && *dst != '\0')
39+
dst++;
40+
dlen = dst - odst;
41+
n = dsize - dlen;
42+
43+
if (n-- == 0)
44+
return(dlen + strlen(src));
45+
while (*src != '\0') {
46+
if (n != 0) {
47+
*dst++ = *src;
48+
n--;
49+
}
50+
src++;
51+
}
52+
*dst = '\0';
53+
54+
return(dlen + (src - osrc)); /* count does not include NUL */
55+
}

strlcpy.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */
2+
3+
/*
4+
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include <sys/types.h>
20+
#include <string.h>
21+
22+
/*
23+
* Copy string src to buffer dst of size dsize. At most dsize-1
24+
* chars will be copied. Always NUL terminates (unless dsize == 0).
25+
* Returns strlen(src); if retval >= dsize, truncation occurred.
26+
*/
27+
size_t
28+
strlcpy(char *dst, const char *src, size_t dsize)
29+
{
30+
const char *osrc = src;
31+
size_t nleft = dsize;
32+
33+
/* Copy as many bytes as will fit. */
34+
if (nleft != 0) {
35+
while (--nleft != 0) {
36+
if ((*dst++ = *src++) == '\0')
37+
break;
38+
}
39+
}
40+
41+
/* Not enough room in dst, add NUL and traverse rest of src. */
42+
if (nleft == 0) {
43+
if (dsize != 0)
44+
*dst = '\0'; /* NUL-terminate dst */
45+
while (*src++)
46+
;
47+
}
48+
49+
return(src - osrc - 1); /* count does not include NUL */
50+
}

ytab.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef union {
4545
char *s;
4646
} YYSTYPE;
4747
#endif /* !YYSTYPE_IS_DECLARED */
48-
#line 49 "y.tab.c"
48+
#line 49 "ytab.c"
4949

5050
/* compatibility with bison */
5151
#ifdef YYPARSE_PARAM
@@ -2558,7 +2558,7 @@ void checkdup(Node *vl, Cell *cp) /* check if name already in list */
25582558
}
25592559
}
25602560
}
2561-
#line 2562 "y.tab.c"
2561+
#line 2562 "ytab.c"
25622562

25632563
#if YYDEBUG
25642564
#include <stdio.h> /* needed for printf */
@@ -3355,7 +3355,7 @@ case 184:
33553355
#line 443 "/home/dima/Development/lok/awkgram.y"
33563356
{ yyval.p = notnull(yystack.l_mark[-1].p); }
33573357
break;
3358-
#line 3359 "y.tab.c"
3358+
#line 3359 "ytab.c"
33593359
}
33603360
yystack.s_mark -= yym;
33613361
yystate = *yystack.s_mark;

0 commit comments

Comments
 (0)