tcs: clean up old port code, and avoid writing 0 to stdout

This commit is contained in:
BurnZeZ 2018-12-26 04:47:22 +00:00
parent 27921a1ba0
commit c650a7db0c
11 changed files with 94 additions and 181 deletions

View file

@ -15,6 +15,7 @@ void uksc_in(int fd, long *notused, struct convert *out);
void uksc_out(Rune *base, int n, long *notused);
void html_in(int fd, long *notused, struct convert *out);
void html_out(Rune *base, int n, long *notused);
void unhtml_in(int fd, long *notused, struct convert *out);
void tune_in(int fd, long *notused, struct convert *out);
void tune_out(Rune *base, int n, long *notused);

View file

@ -1,12 +1,6 @@
#ifdef PLAN9
#include <u.h>
#include <libc.h>
#include <bio.h>
#else
#include <stdio.h>
#include <unistd.h>
#include "plan9.h"
#endif
#include "hdr.h"
#include "conv.h"
#include "big5.h"
@ -44,8 +38,8 @@ big5proc(int c, Rune **r, long input_loc)
else {
nerrors++;
if(squawk)
EPR "%s: bad big5 glyph (from 0x%x,0x%lx) near byte %ld in %s\n",
argv0, lastc, cold, input_loc, file);
warn("bad big5 glyph (from 0x%x,0x%lx) near byte %ld in %s",
lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
state = state0;
@ -56,8 +50,8 @@ big5proc(int c, Rune **r, long input_loc)
else {
nerrors++;
if(squawk)
EPR "%s: bad big5 font %d (from 0x%x,0x%lx) near byte %ld in %s\n",
argv0, lastc-161, lastc, cold, input_loc, file);
warn("bad big5 font %d (from 0x%x,0x%lx) near byte %ld in %s",
lastc-161, lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
state = state0;
@ -71,8 +65,8 @@ big5proc(int c, Rune **r, long input_loc)
if(ch < 0){
nerrors++;
if(squawk)
EPR "%s: unknown big5 %ld (from 0x%x,0x%lx) near byte %ld in %s\n",
argv0, n, lastc, cold, input_loc, file);
warn("unknown big5 %ld (from 0x%x,0x%lx) near byte %ld in %s",
n, lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
} else
@ -151,7 +145,7 @@ big5_out(Rune *base, int n, long *)
}
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;

View file

@ -1,12 +1,6 @@
#ifdef PLAN9
#include <u.h>
#include <libc.h>
#include <bio.h>
#else
#include <stdio.h>
#include <unistd.h>
#include "plan9.h"
#endif
#include "hdr.h"
#include "conv.h"
#include "gb.h"
@ -40,7 +34,7 @@ gbproc(int c, Rune **r, long input_loc)
else {
nerrors++;
if(squawk)
EPR "%s: bad gb glyph %d (from 0x%x,0x%lx) near byte %ld in %s\n", argv0, c-0xA0, lastc, cold, input_loc, file);
warn("bad gb glyph %d (from 0x%x,0x%lx) near byte %ld in %s", c-0xA0, lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
state = state0;
@ -50,7 +44,7 @@ gbproc(int c, Rune **r, long input_loc)
if(ch < 0){
nerrors++;
if(squawk)
EPR "%s: unknown gb %ld (from 0x%x,0x%lx) near byte %ld in %s\n", argv0, n, lastc, cold, input_loc, file);
warn("unknown gb %ld (from 0x%x,0x%lx) near byte %ld in %s", n, lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
} else
@ -120,7 +114,7 @@ gb_out(Rune *base, int n, long *)
continue;
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;

View file

@ -1,12 +1,6 @@
#ifdef PLAN9
#include <u.h>
#include <libc.h>
#include <bio.h>
#else
#include <stdio.h>
#include <unistd.h>
#include "plan9.h"
#endif
#include "hdr.h"
#include "conv.h"
#include "gbk.h"
@ -39,7 +33,7 @@ gbkproc(int c, Rune **r, long input_loc)
if(ch < 0){
nerrors++;
if(squawk)
EPR "%s: bad gbk glyph %d (from 0x%x,0x%lx) near byte %ld in %s\n", argv0, (c & 0xFF), lastc, cold, input_loc, file);
warn("bad gbk glyph %d (from 0x%x,0x%lx) near byte %ld in %s", (c & 0xFF), lastc, cold, input_loc, file);
if(!clean)
emit(BADMAP);
state = state0;
@ -111,7 +105,7 @@ gbk_out(Rune *base, int n, long *)
continue;
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;

View file

@ -1,12 +1,6 @@
#ifdef PLAN9
#include <u.h>
#include <libc.h>
#include <bio.h>
#else
#include <stdio.h>
#include <unistd.h>
#include "plan9.h"
#endif
#include "hdr.h"
#include "conv.h"
#include "kuten208.h"
@ -47,7 +41,7 @@ again:
}
if(c < 0x21){ /* guard against bogus characters in JIS mode */
if(squawk)
EPR "%s: non-JIS character %02x in %s near byte %ld\n", argv0, c, file, input_loc);
warn("non-JIS character %02x in %s near byte %ld", c, file, input_loc);
emit(c);
return;
}
@ -74,7 +68,7 @@ again:
case state4: /* two part char */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s", file);
c = 0x21 | (lastc&0x80);
}
if(CANS2J(lastc, c)){ /* ms dos sjis */
@ -86,14 +80,14 @@ again:
if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
nerrors++;
if(squawk)
EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
} else {
if(l < 0){
l = -l;
if(squawk)
EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
}
emit(l);
}
@ -160,7 +154,7 @@ again:
case state4: /* two part char */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s", file);
c = 0x21 | (lastc&0x80);
}
if(CANS2J(lastc, c)){ /* ms dos sjis */
@ -170,7 +164,7 @@ again:
} else {
nerrors++;
if(squawk)
EPR "%s: illegal byte pair (0x%x,0x%x) near byte %ld in %s\n", argv0, lastc, c, input_loc, file);
warn("illegal byte pair (0x%x,0x%x) near byte %ld in %s", lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
state = state0;
@ -179,14 +173,14 @@ again:
if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
nerrors++;
if(squawk)
EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
} else {
if(l < 0){
l = -l;
if(squawk)
EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
}
emit(l);
}
@ -216,7 +210,7 @@ ujis(int c, Rune **r, long input_loc)
if(c == 0x8e){ /* codeset 2 */
nerrors++;
if(squawk)
EPR "%s: unknown codeset 2 near byte %ld in %s\n", argv0, input_loc, file);
warn("unknown codeset 2 near byte %ld in %s", input_loc, file);
if(!clean)
emit(BADMAP);
return;
@ -232,21 +226,21 @@ ujis(int c, Rune **r, long input_loc)
case state1: /* two part char */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s", file);
c = 0xA1;
}
n = (lastc&0x7F)*100 + (c&0x7F) - 3232; /* kuten208 */
if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
nerrors++;
if(squawk)
EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
} else {
if(l < 0){
l = -l;
if(squawk)
EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
}
emit(l);
}
@ -256,12 +250,12 @@ ujis(int c, Rune **r, long input_loc)
case state2: /* three part char, part #2 */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s\n", argv0, file);
c = 0xA1;
}
if(c < 0xa1 || c > 0xfe){
if(squawk)
EPR "%s: invalid byte 0x%x in codeset 3\n", argv0, c);
warn("invalid byte 0x%x in codeset 3\n", argv0, c);
state = state0;
}else{
lastc = c;
@ -272,12 +266,12 @@ ujis(int c, Rune **r, long input_loc)
case state3: /* three part char, part #3 */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s\n", argv0, file);
c = 0xA1;
}
if(c < 0xa1 || c > 0xfe){
if(squawk)
EPR "%s: invalid byte 0x%x in codeset 3\n", argv0, c);
warn("invalid byte 0x%x in codeset 3\n", argv0, c);
state = state0;
return;
}
@ -286,14 +280,14 @@ ujis(int c, Rune **r, long input_loc)
if((n >= KUTEN212MAX) || ((l = tabkuten212[n]) == -1)){
nerrors++;
if(squawk)
EPR "%s: unknown kuten212 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
warn("unknown kuten212 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
} else {
if(l < 0){
l = -l;
if(squawk)
EPR "%s: ambiguous kuten212 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
warn("ambiguous kuten212 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
}
emit(l);
}
@ -359,7 +353,7 @@ again:
case state4: /* two part char */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s", file);
c = 0x21 | (lastc&0x80);
}
if((lastc&0x80) != (c&0x80)){ /* guard against latin1 in jis */
@ -371,14 +365,14 @@ again:
if((n >= KUTEN208MAX) || ((l = tabkuten208[n]) == -1)){
nerrors++;
if(squawk)
EPR "%s: unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
warn("unknown kuten208 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
} else {
if(l < 0){
l = -l;
if(squawk)
EPR "%s: ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s\n", argv0, n, l, input_loc, file);
warn("ambiguous kuten208 %d (mapped to 0x%lx) near byte %ld in %s", n, l, input_loc, file);
}
emit(l);
}
@ -494,7 +488,7 @@ jisjis_out(Rune *base, int n, long *)
continue;
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;
@ -532,7 +526,7 @@ msjis_out(Rune *base, int n, long *)
continue;
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;
@ -567,7 +561,7 @@ ujis_out(Rune *base, int n, long *)
continue;
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;

View file

@ -1,12 +1,6 @@
#ifdef PLAN9
#include <u.h>
#include <libc.h>
#include <bio.h>
#else
#include <stdio.h>
#include <unistd.h>
#include "plan9.h"
#endif
#include "hdr.h"
#include "conv.h"
#include "ksc.h"
@ -58,14 +52,14 @@ ukscproc(int c, Rune **r, long input_loc)
case cs1last: /* 2nd byte of codeset 1 (KSC 5601) */
if(c < 0){
if(squawk)
EPR "%s: unexpected EOF in %s\n", argv0, file);
warn("unexpected EOF in %s", file);
c = 0x21 | (lastc&0x80);
}
n = ((lastc&0x7f)-33)*94 + (c&0x7f)-33;
if((n >= ksc5601max) || ((l = tabksc5601[n]) < 0)){
nerrors++;
if(squawk)
EPR "%s: unknown ksc5601 %d (from 0x%x,0x%x) near byte %ld in %s\n", argv0, n, lastc, c, input_loc, file);
warn("unknown ksc5601 %d (from 0x%x,0x%x) near byte %ld in %s", n, lastc, c, input_loc, file);
if(!clean)
emit(BADMAP);
} else {
@ -75,8 +69,7 @@ ukscproc(int c, Rune **r, long input_loc)
return;
default:
if(squawk)
EPR "%s: ukscproc: unknown state %d\n",
argv0, init);
warn("ukscproc: unknown state %d", init);
}
}
@ -145,7 +138,7 @@ uksc_out(Rune *base, int n, long *)
continue;
}
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, r);
warn("rune 0x%x not in output cs", r);
nerrors++;
if(clean)
continue;

View file

@ -37,10 +37,4 @@ extern char obuf[UTFmax*N]; /* maximum bloat from N runes */
#define BYTEBADMAP ('?') /* badmap but has to fit in a byte */
#define ESC 033
#ifdef PLAN9
#define EPR fprint(2,
#define EXIT(n,s) exits(s)
#else
#define EPR fprintf(stderr,
#define EXIT(n,s) exit(n)
#endif
void warn(char*, ...);

View file

@ -1,23 +0,0 @@
typedef unsigned short Rune; /* 16 bits */
typedef unsigned char uchar;
#define Runeerror 0x80 /* decoding error in UTF */
#define Runeself 0x80 /* rune and UTF sequences are the same (<) */
#define UTFmax 6 /* maximum bytes per rune */
/*
plan 9 argument parsing
*/
#define ARGBEGIN for((argv0? 0: (argv0= *argv)),argv++,argc--;\
argv[0] && argv[0][0]=='-' && argv[0][1];\
argc--, argv++) {\
char *_args, *_argt, _argc;\
_args = &argv[0][1];\
if(_args[0]=='-' && _args[1]==0){\
argc--; argv++; break;\
}\
_argc=0;while(*_args) switch(_argc= *_args++)
#define ARGEND }
#define ARGF() (_argt=_args, _args="",\
(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
#define ARGC() _argc
extern char *argv0;

View file

@ -1,17 +1,6 @@
#ifndef PLAN9
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include "plan9.h"
#else /* PLAN9 */
#include <u.h>
#include <libc.h>
#include <bio.h>
#endif /* PLAN9 */
#include "cyrillic.h"
#include "misc.h"
#include "ms.h"
@ -32,15 +21,12 @@ char *argv0;
Rune runes[N];
char obuf[UTFmax*N]; /* maximum bloat from N runes */
long tab[NRUNE];
#ifndef PLAN9
extern char version[];
#endif
void intable(int, long *, struct convert *);
void unicode_in(int, long *, struct convert *);
void unicode_out(Rune *, int, long *);
int
void
main(int argc, char **argv)
{
char *from = "utf";
@ -77,7 +63,7 @@ main(int argc, char **argv)
squawk = 1;
if(listem){
list();
EXIT(0, 0);
exits(nil);
}
if(!from || !to)
usage();
@ -90,14 +76,8 @@ main(int argc, char **argv)
if(*argv){
while(*argv){
file = *argv;
#ifndef PLAN9
if((fd = open(*argv, 0)) < 0){
EPR "%s: %s: %s\n", argv0, *argv, strerror(errno));
#else /* PLAN9 */
if((fd = open(*argv, OREAD)) < 0){
EPR "%s: %s: %r\n", argv0, *argv);
#endif /* PLAN9 */
EXIT(1, "open failure");
sysfatal("%s: %r", *argv);
}
PROC
close(fd);
@ -108,19 +88,18 @@ main(int argc, char **argv)
PROC
}
if(verbose)
EPR "%s: %ld input bytes, %ld runes, %ld output bytes (%ld errors)\n", argv0,
warn("%ld input bytes, %ld runes, %ld output bytes (%ld errors)",
ninput, nrunes, noutput, nerrors);
EXIT(((nerrors && squawk)? 1:0), ((nerrors && squawk)? "conversion error":0));
return(0); /* shut up compiler */
exits((nerrors && squawk)? "conversion error":nil);
}
void
usage(void)
{
EPR "Usage: %s [-slv] [-f cs] [-t cs] [file ...]\n", argv0);
fprint(2, "Usage: %s [-slv] [-f cs] [-t cs] [file ...]\n", argv0);
verbose = 1;
list();
EXIT(1, "usage");
exits("usage");
}
void
@ -129,28 +108,41 @@ list(void)
struct convert *c;
char ch = verbose?'\t':' ';
#ifndef PLAN9
EPR "%s version = '%s'\n", argv0, version);
#endif
if(verbose)
EPR "character sets:\n");
fprint(2, "character sets:\n");
else
EPR "cs:");
fprint(2, "cs:");
for(c = convert; c->name; c++){
if((c->flags&From) && c[1].name && (strcmp(c[1].name, c->name) == 0)){
EPR "%c%s", ch, c->name);
fprint(2, "%c%s", ch, c->name);
c++;
} else if(c->flags&Table)
EPR "%c%s", ch, c->name);
fprint(2, "%c%s", ch, c->name);
else if(c->flags&From)
EPR "%c%s(from)", ch, c->name);
fprint(2, "%c%s(from)", ch, c->name);
else
EPR "%c%s(to)", ch, c->name);
fprint(2, "%c%s(to)", ch, c->name);
if(verbose)
EPR "\t%s\n", c->chatter);
fprint(2, "\t%s\n", c->chatter);
}
if(!verbose)
EPR "\n");
fprint(2, "\n");
}
void
warn(char *fmt, ...)
{
va_list arg;
char buf[1024]; /* arbitrary */
int n;
if((n = snprint(buf, sizeof(buf), "%s: ", argv0)) < 0)
sysfatal("snprint: %r");
va_start(arg, fmt);
vseprint(buf+n, buf+sizeof(buf), fmt, arg);
va_end(arg);
fprint(2, "%s\n", buf);
}
char*
@ -188,8 +180,7 @@ conv(char *name, int from)
if(((c->flags&From) == 0) == (from == 0))
return(c);
}
EPR "%s: charset `%s' unknown\n", argv0, name);
EXIT(1, "unknown character set");
sysfatal("charset `%s' unknown", name);
return(0); /* just shut the compiler up */
}
@ -320,7 +311,8 @@ unicode_out_be(Rune *base, int n, long *)
nrunes += n;
n = p - (uchar*)base;
noutput += n;
write(1, (char *)base, n);
if(n > 0)
write(1, base, n);
}
void
@ -347,7 +339,8 @@ unicode_out_le(Rune *base, int n, long *)
nrunes += n;
n = p - (uchar*)base;
noutput += n;
write(1, (char *)base, n);
if(n > 0)
write(1, (char *)base, n);
}
void
@ -378,7 +371,7 @@ intable(int fd, long *table, struct convert *out)
c = table[*p];
if(c < 0){
if(squawk)
EPR "%s: bad char 0x%x near byte %zd in %s\n", argv0, *p, ninput+(p-e), file);
warn("bad char 0x%x near byte %zd in %s", *p, ninput+(p-e), file);
nerrors++;
if(clean)
continue;
@ -389,14 +382,8 @@ intable(int fd, long *table, struct convert *out)
OUT(out, runes, r-runes);
}
OUT(out, runes, 0);
if(n < 0){
#ifdef PLAN9
EPR "%s: input read: %r\n", argv0);
#else
EPR "%s: input read: %s\n", argv0, strerror(errno));
#endif
EXIT(1, "input read error");
}
if(n < 0)
sysfatal("input read: %r");
}
void
@ -420,7 +407,7 @@ outtable(Rune *base, int n, long *map)
c = -1;
if(c < 0){
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, base[i]);
warn("rune 0x%x not in output cs", base[i]);
nerrors++;
if(clean)
continue;
@ -429,7 +416,8 @@ outtable(Rune *base, int n, long *map)
*p++ = c;
}
noutput += p-obuf;
write(1, obuf, p-obuf);
if(p > obuf)
write(1, obuf, p-obuf);
}
int

View file

@ -160,7 +160,7 @@ tune_in(int fd, long *, struct convert *out)
default:
if(c >= 0xe200 && c <= 0xe3ff){
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, c);
warn("rune 0x%x not in output cs", c);
nerrors++;
if(clean)
break;
@ -221,7 +221,7 @@ tune_out(Rune *r, int n, long *)
}
}else if(lastr && lastr != Runeerror && (*r == 0x00b2/*²*/ || *r == 0x00b3/*³*/ || *r == 0x2074/*⁴*/)){
if(squawk)
EPR "%s: character <U+%.4X, U+%.4X> not in output cs\n", argv0, lastr, *r);
warn("character <U+%.4X, U+%.4X> not in output cs", lastr, *r);
lastr = clean ? 0 : Runeerror;
nerrors++;
}else{
@ -302,5 +302,6 @@ tune_out(Rune *r, int n, long *)
state = 0;
}
noutput += p-obuf;
write(1, obuf, p-obuf);
if(p > obuf)
write(1, obuf, p-obuf);
}

View file

@ -1,16 +1,6 @@
#ifdef PLAN9
#include <u.h>
#include <libc.h>
#include <bio.h>
#else
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "plan9.h"
#endif
#include "hdr.h"
/*
@ -40,7 +30,7 @@ utf_in(int fd, long *, struct convert *out)
c = our_mbtowc(&l, buf+i, tot-i);
if(c == -1){
if(squawk)
EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput+i);
warn("bad UTF sequence near byte %ld in input", ninput+i);
if(clean){
i++;
continue;
@ -74,7 +64,8 @@ utf_out(Rune *base, int n, long *)
p += our_wctomb(p, *r);
}
noutput += p-obuf;
write(1, obuf, p-obuf);
if(p > obuf)
write(1, obuf, p-obuf);
}
void
@ -92,7 +83,7 @@ isoutf_in(int fd, long *, struct convert *out)
c = isochartorune(&runes[j], buf+i);
if(runes[j] == Runeerror){
if(squawk)
EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput+i);
warn("bad UTF sequence near byte %ld in input", ninput+i);
if(clean){
i++;
continue;
@ -123,7 +114,8 @@ isoutf_out(Rune *base, int n, long *)
for(r = base, p = obuf; n-- > 0; r++)
p += runetoisoutf(p, r);
noutput += p-obuf;
write(1, obuf, p-obuf);
if(p > obuf)
write(1, obuf, p-obuf);
}
@ -291,10 +283,6 @@ fullisorune(char *str, int n)
return 0;
}
#ifdef PLAN9
int errno;
#endif
enum
{
T1 = 0x00,
@ -326,10 +314,6 @@ enum
Wchar3 = (1UL<<(Bit3+2*Bitx))-1,
Wchar4 = (1UL<<(Bit4+3*Bitx))-1,
Wchar5 = (1UL<<(Bit5+4*Bitx))-1,
#ifndef EILSEQ
EILSEQ = 123,
#endif /* EILSEQ */
};
int
@ -478,6 +462,5 @@ our_mbtowc(unsigned long *p, char *s, unsigned n)
return 1;
bad:
errno = EILSEQ;
return -1;
}