-# $OpenBSD: Makefile,v 1.18 2020/07/30 17:45:44 millert Exp $
+# $OpenBSD: Makefile,v 1.19 2024/06/03 00:55:05 millert Exp $
+WARNINGS=Yes
PROG= awk
SRCS= awkgram.tab.c lex.c b.c main.c parse.c proctab.c tran.c lib.c run.c
LDADD= -lm
-/* $OpenBSD: b.c,v 1.52 2024/05/04 22:59:21 millert Exp $ */
+/* $OpenBSD: b.c,v 1.53 2024/06/03 00:55:05 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
fa *fatab[NFA];
int nfatab = 0; /* entries in fatab */
-extern int u8_nextlen(const char *s);
-
-
/* utf-8 mechanism:
For most of Awk, utf-8 strings just "work", since they look like
static int get_gototab(fa*, int, int);
static int set_gototab(fa*, int, int, int);
static void clear_gototab(fa*, int);
-extern int u8_rune(int *, const char *);
static int *
intalloc(size_t n, const char *f)
/* in the parsing of regular expressions, metacharacters like . have */
/* to be seen literally; \056 is not a metacharacter. */
-int hexstr(const uschar **pp, int max) /* find and eval hex string at pp, return new p */
+static int
+hexstr(const uschar **pp, int max) /* find and eval hex string at pp, return new p */
{ /* only pick up one 8-bit byte (2 chars) */
const uschar *p;
int n = 0;
-/* $OpenBSD: lex.c,v 1.32 2023/11/25 16:31:33 millert Exp $ */
+/* $OpenBSD: lex.c,v 1.33 2024/06/03 00:55:05 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
}
}
-extern int runetochar(char *str, int c);
-
int string(void)
{
int c, n;
-/* $OpenBSD: lib.c,v 1.57 2024/05/05 02:55:34 jsg Exp $ */
+/* $OpenBSD: lib.c,v 1.58 2024/06/03 00:55:05 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
#include <math.h>
#include "awk.h"
-extern int u8_nextlen(const char *s);
-
char EMPTY[] = { '\0' };
FILE *infile = NULL;
bool innew; /* true = infile has not been read by readrec */
error();
}
-void error()
+void error(void)
{
extern Node *curnode;
-/* $OpenBSD: proto.h,v 1.23 2023/11/22 01:01:21 millert Exp $ */
+/* $OpenBSD: proto.h,v 1.24 2024/06/03 00:55:05 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
extern FILE *popen(const char *, const char *);
extern int pclose(FILE *);
+extern int u8_nextlen(const char *s);
+extern int u8_rune(int *, const char *);
+extern int runetochar(char *str, int c);
+
extern const char *flags2str(int flags);
-/* $OpenBSD: run.c,v 1.86 2024/05/04 22:59:21 millert Exp $ */
+/* $OpenBSD: run.c,v 1.87 2024/06/03 00:55:05 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
/* is s the beginning of a valid utf-8 string? */
/* return length 1..4 if yes, 0 if no */
-int u8_isutf(const char *s)
+static int u8_isutf(const char *s)
{
int n, ret;
unsigned char c;
}
/* return number of utf characters or single non-utf bytes */
-int u8_strlen(const char *s)
+static int u8_strlen(const char *s)
{
int i, len, n, totlen;
unsigned char c;
}
/* convert utf-8 char number in a string to its byte offset */
-int u8_char2byte(const char *s, int charnum)
+static int u8_char2byte(const char *s, int charnum)
{
int n;
int bytenum = 0;
}
/* convert byte offset in s to utf-8 char number that starts there */
-int u8_byte2char(const char *s, int bytenum)
+static int u8_byte2char(const char *s, int bytenum)
{
int i, len, b;
int charnum = 0; /* BUG: what origin? */
return(z);
}
-int has_utf8(char *s) /* return 1 if s contains any utf-8 (2 bytes or more) character */
+static int has_utf8(char *s) /* return 1 if s contains any utf-8 (2 bytes or more) character */
{
int n;
if (prec > u8_strlen(t))
prec = u8_strlen(t);
pad = wid>prec ? wid - prec : 0; // has to be >= 0
- int i, k, n;
+ int i, precb;
if (ljust) { // print prec chars from t, then pad blanks
- n = u8_char2byte(t, prec);
- for (k = 0; k < n; k++) {
- //putchar(t[k]);
- *p++ = t[k];
+ precb = u8_char2byte(t, prec);
+ for (i = 0; i < precb; i++) {
+ //putchar(t[i]);
+ *p++ = t[i];
}
for (i = 0; i < pad; i++) {
//printf(" ");
//printf(" ");
*p++ = ' ';
}
- n = u8_char2byte(t, prec);
- for (k = 0; k < n; k++) {
- //putchar(t[k]);
- *p++ = t[k];
+ precb = u8_char2byte(t, prec);
+ for (i = 0; i < precb; i++) {
+ //putchar(t[i]);
+ *p++ = t[i];
}
}
*p = 0;
size_t n = 0;
wchar_t wc;
const size_t sz = awk_mb_cur_max;
- int unused;
if (sz == 1) {
buf = tostring(s);
/* upper/lower character may be shorter/longer */
buf = tostringN(s, strlen(s) * sz + 1);
- (void) mbtowc(NULL, NULL, 0); /* reset internal state */
- /*
- * Reset internal state here too.
- * Assign result to avoid a compiler warning. (Casting to void
- * doesn't work.)
- * Increment said variable to avoid a different warning.
- */
- unused = wctomb(NULL, L'\0');
- unused++;
+ /* reset internal state */
+ if (mbtowc(NULL, NULL, 0) == -1 || wctomb(NULL, L'\0') == -1)
+ FATAL("unable to reset character conversion state");
ps = s;
pbuf = buf;
-/* $OpenBSD: tran.c,v 1.39 2024/05/04 22:59:21 millert Exp $ */
+/* $OpenBSD: tran.c,v 1.40 2024/06/03 00:55:05 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
if ((flags & flagtab[i].value) != 0) {
len = snprintf(cp, sizeof(buf) - (cp - buf),
"%s%s", cp > buf ? "|" : "", flagtab[i].name);
- if (len < 0 || len >= sizeof(buf) - (cp - buf))
+ if (len < 0 || (size_t)len >= sizeof(buf) - (cp - buf))
FATAL("out of space in flags2str");
cp += len;
}