455 lines
11 KiB
Diff
455 lines
11 KiB
Diff
SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
|
|
SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
|
|
|
SPDX-License-Identifier: CDDL-1.0
|
|
|
|
From 508eb06d40498acf954fc51ecb9171d2ce2236f6 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= <andrius@stikonas.eu>
|
|
Date: Wed, 27 Jan 2021 00:40:19 +0000
|
|
Subject: [PATCH] Workaround for lex to work with mes libc.
|
|
|
|
Similarly to yacc, remove wchar. See yacc patch for further
|
|
information.
|
|
|
|
---
|
|
lex/Makefile.mk | 2 +-
|
|
lex/allprint.c | 6 ++--
|
|
lex/ldefs.c | 8 -----
|
|
lex/main.c | 1 +
|
|
lex/parser.y | 77 +++++++++++++++++++++++++++++++++++--------------
|
|
lex/reject.c | 1 -
|
|
lex/sub1.c | 44 ++++++++++++++++++----------
|
|
lex/sub3.c | 2 +-
|
|
8 files changed, 89 insertions(+), 52 deletions(-)
|
|
|
|
diff --git lex/Makefile.mk lex/Makefile.mk
|
|
index 577f7cb..a413867 100644
|
|
--- lex/Makefile.mk
|
|
+++ lex/Makefile.mk
|
|
@@ -1,4 +1,4 @@
|
|
-XOBJ = main.o sub1.o sub2.o sub3.o header.o wcio.o parser.o getopt.o lsearch.o
|
|
+XOBJ = main.o sub1.o sub2.o sub3.o header.o parser.o getopt.o lsearch.o
|
|
|
|
LOBJ = allprint.o libmain.o reject.o yyless.o yywrap.o \
|
|
allprint_w.o reject_w.o yyless_w.o reject_e.o yyless_e.o
|
|
diff --git lex/allprint.c lex/allprint.c
|
|
index 6e82495..cb0c6bb 100644
|
|
--- lex/allprint.c
|
|
+++ lex/allprint.c
|
|
@@ -42,8 +42,6 @@
|
|
#include <sys/euc.h>
|
|
#include <widec.h>
|
|
#endif
|
|
-#include <wctype.h>
|
|
-#include <wchar.h>
|
|
|
|
extern FILE *yyout;
|
|
|
|
@@ -78,10 +76,10 @@ allprint(CHR c)
|
|
fprintf(yyout, "\\_");
|
|
break;
|
|
default:
|
|
- if (!iswprint(c))
|
|
+ if (!iwprint(c))
|
|
fprintf(yyout, "\\x%-2x", (int)c);
|
|
else
|
|
- putwc(c, yyout);
|
|
+ putc(c, yyout);
|
|
break;
|
|
}
|
|
}
|
|
diff --git lex/ldefs.c lex/ldefs.c
|
|
index ff99665..c5dcbaf 100644
|
|
--- lex/ldefs.c
|
|
+++ lex/ldefs.c
|
|
@@ -43,7 +43,6 @@
|
|
#ifdef __sun
|
|
#include <widec.h>
|
|
#endif
|
|
-#include <wctype.h>
|
|
|
|
#define CHR wchar_t
|
|
#define BYTE char
|
|
@@ -296,13 +295,6 @@ int mn1(int a, intptr_t d);
|
|
int mn0(int a);
|
|
int dupl(int n);
|
|
|
|
-#undef getwc
|
|
-#define getwc(f) lex_getwc(f)
|
|
-extern wint_t lex_getwc(FILE *);
|
|
-#undef putwc
|
|
-#define putwc(c, f) lex_putwc(c, f)
|
|
-extern wint_t lex_putwc(wchar_t, FILE *);
|
|
-
|
|
#undef index
|
|
#define index lex_index
|
|
|
|
diff --git lex/main.c lex/main.c
|
|
index 8aee8ea..52c892a 100644
|
|
--- lex/main.c
|
|
+++ lex/main.c
|
|
@@ -38,6 +38,7 @@
|
|
* Sccsid @(#)main.c 1.9 (gritter) 11/26/05
|
|
*/
|
|
|
|
+#include <getopt.h>
|
|
#include <string.h>
|
|
#include "once.h"
|
|
#include "sgs.h"
|
|
diff --git lex/parser.y lex/parser.y
|
|
index b8618e3..34a7e9a 100644
|
|
--- lex/parser.y
|
|
+++ lex/parser.y
|
|
@@ -43,7 +43,6 @@
|
|
void yyerror(char *);
|
|
|
|
#include <ctype.h>
|
|
-#include <wchar.h>
|
|
#include <inttypes.h>
|
|
#ifndef __sun
|
|
#define wcsetno(c) 0
|
|
@@ -289,6 +288,19 @@ r: CHAR
|
|
;
|
|
|
|
%%
|
|
+
|
|
+/*
|
|
+Copy multibyte string into char string.
|
|
+Mes C library does not support wide strings, and fprintf truncates all strings to 1 character.
|
|
+This happens because wchar_t strings have 0 in a second byte.
|
|
+*/
|
|
+int
|
|
+wstrcpy(char const *destination, wchar_t const *source) {
|
|
+ int i = 0;
|
|
+ do {
|
|
+ destination[i]=source[i];
|
|
+ } while (source[i++] != 0);
|
|
+}
|
|
int
|
|
yylex(void)
|
|
{
|
|
@@ -353,7 +365,7 @@ yylex(void)
|
|
(*(p+2) == 'O')) {
|
|
if(lgatflg)
|
|
error("Too late for %%pointer");
|
|
- while(*p && !iswspace(*p))
|
|
+ while(*p && !isspace(*p))
|
|
p++;
|
|
isArray = 0;
|
|
continue;
|
|
@@ -397,7 +409,7 @@ yylex(void)
|
|
(*(p+2) == 'R')) {
|
|
if(lgatflg)
|
|
error("Too late for %%array");
|
|
- while(*p && !iswspace(*p))
|
|
+ while(*p && !isspace(*p))
|
|
p++;
|
|
isArray = 1;
|
|
continue;
|
|
@@ -426,7 +438,7 @@ yylex(void)
|
|
if(handleeuc)
|
|
error("\
|
|
Character table (%t) is supported only in ASCII compatibility mode.\n");
|
|
- ZCH = wcstol(p+2, NULL, 10);
|
|
+ ZCH = strtol(p+2, NULL, 10);
|
|
if (ZCH < NCH) ZCH = NCH;
|
|
if (ZCH > 2*NCH) error("ch table needs redeclaration");
|
|
chset = TRUE;
|
|
@@ -438,13 +450,13 @@ Character table (%t) is supported only in ASCII compatibility mode.\n");
|
|
continue;
|
|
}
|
|
while(digit(*p)) p++;
|
|
- if(!iswspace(*p)) error("bad translation format");
|
|
- while(iswspace(*p)) p++;
|
|
+ if(!isspace(*p)) error("bad translation format");
|
|
+ while(isspace(*p)) p++;
|
|
t = p;
|
|
while(*t){
|
|
c = ctrans(&t);
|
|
if(ctable[(unsigned)c]){
|
|
- if (iswprint(c))
|
|
+ if (isprint(c))
|
|
warning("Character '%lc' used twice",c);
|
|
|
|
else
|
|
@@ -485,8 +497,12 @@ Character table (%t) is supported only in ASCII compatibility mode.\n");
|
|
while(getl(p) && scomp(p, L_PctCbr) != 0)
|
|
if(p[0]=='/' && p[1]=='*')
|
|
cpycom(p);
|
|
- else
|
|
- fprintf(fout,"%ls\n",p);
|
|
+ else {
|
|
+ char p2[100];
|
|
+ wstrcpy(p2, p);
|
|
+ fprintf(fout,"%ls\n",p2);
|
|
+ memset(p2, 0, sizeof p2);
|
|
+ }
|
|
if(p[0] == '%') continue;
|
|
if (*p) error("EOF before %%%%");
|
|
else error("EOF before %%}");
|
|
@@ -501,12 +517,12 @@ Character table (%t) is supported only in ASCII compatibility mode.\n");
|
|
start:
|
|
lgate();
|
|
|
|
- while(*p && !iswspace(*p) && ((*p) != (wchar_t)',')) p++;
|
|
+ while(*p && !isspace(*p) && ((*p) != (wchar_t)',')) p++;
|
|
n = TRUE;
|
|
while(n){
|
|
- while(*p && (iswspace(*p) || ((*p) == (wchar_t)','))) p++;
|
|
+ while(*p && (isspace(*p) || ((*p) == (wchar_t)','))) p++;
|
|
t = p;
|
|
- while(*p && !iswspace(*p) && ((*p) != (wchar_t)',')) {
|
|
+ while(*p && !isspace(*p) && ((*p) != (wchar_t)',')) {
|
|
if(!isascii(*p))
|
|
error("None-ASCII characters in start condition.");
|
|
p++;
|
|
@@ -516,7 +532,10 @@ start:
|
|
if (*t == 0) continue;
|
|
i = sptr*2;
|
|
if(!ratfor)fprintf(fout,"# ");
|
|
- fprintf(fout,"define %ls %d\n",t,i);
|
|
+ char t2[100];
|
|
+ wstrcpy(t2, t);
|
|
+ fprintf(fout,"define %ls %d\n",t2,i);
|
|
+ memset(t2, 0, sizeof t2);
|
|
scopy(t,sp);
|
|
sname[sptr] = sp;
|
|
/* XCU4: save exclusive flag with start name */
|
|
@@ -537,14 +556,20 @@ start:
|
|
case ' ': case '\t': /* must be code */
|
|
lgate();
|
|
if( p[1]=='/' && p[2]=='*' ) cpycom(p);
|
|
- else fprintf(fout, "%ls\n",p);
|
|
+
|
|
+ else {
|
|
+ char p2[100];
|
|
+ wstrcpy(p2, p);
|
|
+ fprintf(fout, "%ls\n",p2);
|
|
+ memset(p2, 0, sizeof p2);
|
|
+ }
|
|
continue;
|
|
case '/': /* look for comments */
|
|
lgate();
|
|
if((*(p+1))=='*') cpycom(p);
|
|
/* FALLTHRU */
|
|
default: /* definition */
|
|
- while(*p && !iswspace(*p)) p++;
|
|
+ while(*p && !isspace(*p)) p++;
|
|
if(*p == 0)
|
|
continue;
|
|
prev = *p;
|
|
@@ -557,7 +582,7 @@ start:
|
|
}
|
|
} else { /* still sect 1, but prev != '\n' */
|
|
p = bptr;
|
|
- while(*p && iswspace(*p)) p++;
|
|
+ while(*p && isspace(*p)) p++;
|
|
if(*p == 0)
|
|
warning("No translation given - null string assumed");
|
|
scopy(p,token);
|
|
@@ -632,8 +657,11 @@ start:
|
|
while(!eof&& getl(buf) && scomp(L_PctCbr,buf)!=0)
|
|
if(buf[0]=='/' && buf[1]=='*')
|
|
cpycom(buf);
|
|
- else
|
|
- fprintf(fout,"%ls\n",buf);
|
|
+ else {
|
|
+ char buf2[100];
|
|
+ wstrcpy(buf2, p);
|
|
+ fprintf(fout,"%ls\n",buf2);
|
|
+ }
|
|
continue;
|
|
}
|
|
if(peek == '%'){
|
|
@@ -944,9 +972,16 @@ Character range specified between different codesets.");
|
|
else
|
|
fprintf(fout,
|
|
"\n# line %d \"%s\"\n", yyline-1, sargv[optind]);
|
|
- fprintf(fout,"%ls\n",buf);
|
|
- while(getl(buf) && !eof)
|
|
- fprintf(fout,"%ls\n",buf);
|
|
+ char buf2[100];
|
|
+ wstrcpy(buf2, buf);
|
|
+ fprintf(fout,"%ls\n",buf2);
|
|
+ memset(buf2, 0, sizeof buf2);
|
|
+ while(getl(buf) && !eof) {
|
|
+ wstrcpy(buf2, buf);
|
|
+ fprintf(fout,"%ls\n",buf2);
|
|
+ memset(buf2, 0, sizeof buf2);
|
|
+ }
|
|
+ memset(buf2, 0, sizeof buf2);
|
|
}
|
|
|
|
return(freturn(0));
|
|
diff --git lex/reject.c lex/reject.c
|
|
index 31928e7..ef08c57 100644
|
|
--- lex/reject.c
|
|
+++ lex/reject.c
|
|
@@ -38,7 +38,6 @@
|
|
#include <euc.h>
|
|
#include <widec.h>
|
|
#else /* !sun */
|
|
-#include <wchar.h>
|
|
#endif /* !sun */
|
|
#include <limits.h>
|
|
#endif
|
|
diff --git lex/sub1.c lex/sub1.c
|
|
index b867948..eead84b 100644
|
|
--- lex/sub1.c
|
|
+++ lex/sub1.c
|
|
@@ -38,7 +38,6 @@
|
|
|
|
#include "ldefs.c"
|
|
#include <limits.h>
|
|
-#include <wchar.h>
|
|
#include <ctype.h>
|
|
#include <stdarg.h>
|
|
|
|
@@ -394,6 +393,19 @@ cclinter(int sw)
|
|
}
|
|
}
|
|
|
|
+int
|
|
+mbtowc(wchar_t *pwc, const char *s, size_t n)
|
|
+{
|
|
+ if (s != 0) {
|
|
+ if (n < 1)
|
|
+ return -1;
|
|
+ if (pwc != 0)
|
|
+ *pwc = *s & 0377;
|
|
+ return *s != '\0';
|
|
+ } else
|
|
+ return 0;
|
|
+}
|
|
+
|
|
int
|
|
usescape(int c)
|
|
{
|
|
@@ -546,7 +558,7 @@ cpyact(void)
|
|
break;
|
|
case ';':
|
|
if (brac == 0) {
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
putc('\n', fout);
|
|
return (1);
|
|
}
|
|
@@ -558,26 +570,26 @@ cpyact(void)
|
|
case '}':
|
|
brac--;
|
|
if (brac == 0) {
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
putc('\n', fout);
|
|
return (1);
|
|
}
|
|
break;
|
|
case '/':
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
c = gch();
|
|
if (c != '*')
|
|
goto swt;
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
savline = yyline;
|
|
while (c = gch()) {
|
|
while (c == '*') {
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
if ((c = gch()) == '/') {
|
|
putc('/', fout);
|
|
while ((c = gch()) == ' ' ||
|
|
c == '\t' || c == '\n')
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
goto swt;
|
|
}
|
|
}
|
|
@@ -590,16 +602,16 @@ cpyact(void)
|
|
case '\'': /* character constant */
|
|
case '"': /* character string */
|
|
mth = c;
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
while (c = gch()) {
|
|
if (c == '\\') {
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
c = gch();
|
|
}
|
|
else
|
|
if (c == mth)
|
|
goto loop;
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
if (c == '\n') {
|
|
yyline--;
|
|
error(
|
|
@@ -620,7 +632,7 @@ cpyact(void)
|
|
loop:
|
|
if (c != ' ' && c != '\t' && c != '\n')
|
|
sw = FALSE;
|
|
- putwc(c, fout);
|
|
+ putc(c, fout);
|
|
if (peek == '\n' && !brac && copy_line) {
|
|
putc('\n', fout);
|
|
return (1);
|
|
@@ -636,7 +648,7 @@ gch(void)
|
|
int c;
|
|
prev = pres;
|
|
c = pres = peek;
|
|
- peek = pushptr > pushc ? *--pushptr : getwc(fin);
|
|
+ peek = pushptr > pushc ? *--pushptr : getc(fin);
|
|
while (peek == EOF) {
|
|
if (no_input) {
|
|
if (!yyline)
|
|
@@ -650,7 +662,7 @@ gch(void)
|
|
if (fin == NULL)
|
|
error("Cannot open file -- %s",
|
|
sargv[optind]);
|
|
- peek = getwc(fin);
|
|
+ peek = getc(fin);
|
|
} else
|
|
break;
|
|
} else {
|
|
@@ -856,11 +868,11 @@ allprint(CHR c)
|
|
printf("\\_");
|
|
break;
|
|
default:
|
|
- if (!iswprint(c)) {
|
|
+ if (!isprint(c)) {
|
|
printf("\\x%-2x", c); /* up to fashion. */
|
|
charc += 3;
|
|
} else
|
|
- putwc(c, stdout);
|
|
+ putc(c, stdout);
|
|
break;
|
|
}
|
|
charc++;
|
|
@@ -903,7 +915,7 @@ sect1dump(void)
|
|
allprint(i);
|
|
putchar(' ');
|
|
iswprint(ctable[i]) ?
|
|
- putwc(ctable[i], stdout) :
|
|
+ putc(ctable[i], stdout) :
|
|
printf("%d", ctable[i]);
|
|
putchar('\n');
|
|
}
|
|
diff --git lex/sub3.c lex/sub3.c
|
|
index 186bcbc..aa07f66 100644
|
|
--- lex/sub3.c
|
|
+++ lex/sub3.c
|
|
@@ -147,7 +147,7 @@ remch(wchar_t c)
|
|
*/
|
|
if (!handleeuc) {
|
|
if (!isascii(c))
|
|
- if (iswprint(c))
|
|
+ if (isprint(c))
|
|
warning(
|
|
"Non-ASCII character '%lc' in pattern; use -w or -e lex option.", c);
|
|
else warning(
|
|
--
|
|
2.26.2
|
|
|