• more unsigned → unsigned int
• more int → bool • more regression tests: check if the utf8-hack flag is really disabled at non-interactive startup, enabled at interactive startup, if the current locale is a UTF-8 one • make the mksh-local multibyte handling functions globally accessible, change their names, syntax and semantics a little (XXX more work needed) • optimise • utf_wctomb: src → dst, as we’re writing to that char array (pasto?) • edit.c:x_e_getmbc(): if the second byte of a 2- or 3-byte multibyte sequence is invalid utf-8, ungetc it (not possible for the 3rd byte yet) • edit.c:x_zotc3(): easier (and faster) handling of UTF-8 • implement, document and test for base-1 numbers: they just get the ASCII (8-bit) or Unicode (UTF-8) value of the octet(s) after the ‘1#’, or do the same as print \x## or \u#### (depending on the utf8-hack flag), plus support the PUA assignment of EF80‥EFFF for the MirBSD encoding “hack” (print doesn’t, as it has \x## and \u#### to distinguish, but we cannot use base-0 numbers which I had planned to use for raw octets first, as they are used internally): http://thread.gmane.org/gmane.os.miros.general/7938 • as an application example, add a hexdumper to the regression tests ☺
This commit is contained in:
38
shf.c
38
shf.c
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.18 2008/04/19 17:21:55 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.19 2008/04/19 22:15:05 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@@ -31,7 +31,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
||||
/* Done before open so if alloca fails, fd won't be lost. */
|
||||
shf = (struct shf *) alloc(sizeof(struct shf) + bsize, ATEMP);
|
||||
shf->areap = ATEMP;
|
||||
shf->buf = (unsigned char *) &shf[1];
|
||||
shf->buf = (unsigned char *)&shf[1];
|
||||
shf->bsize = bsize;
|
||||
shf->flags = SHF_ALLOCS;
|
||||
/* Rest filled in by reopen. */
|
||||
@@ -92,13 +92,13 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
|
||||
|
||||
if (shf) {
|
||||
if (bsize) {
|
||||
shf->buf = (unsigned char *) alloc(bsize, ATEMP);
|
||||
shf->buf = (unsigned char *)alloc(bsize, ATEMP);
|
||||
sflags |= SHF_ALLOCB;
|
||||
} else
|
||||
shf->buf = NULL;
|
||||
} else {
|
||||
shf = (struct shf *) alloc(sizeof(struct shf) + bsize, ATEMP);
|
||||
shf->buf = (unsigned char *) &shf[1];
|
||||
shf = (struct shf *)alloc(sizeof(struct shf) + bsize, ATEMP);
|
||||
shf->buf = (unsigned char *)&shf[1];
|
||||
sflags |= SHF_ALLOCS;
|
||||
}
|
||||
shf->areap = ATEMP;
|
||||
@@ -191,7 +191,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
||||
buf = alloc(bsize, shf->areap);
|
||||
}
|
||||
shf->fd = -1;
|
||||
shf->buf = shf->rp = shf->wp = (unsigned char *) buf;
|
||||
shf->buf = shf->rp = shf->wp = (unsigned char *)buf;
|
||||
shf->rnleft = bsize;
|
||||
shf->rbsize = bsize;
|
||||
shf->wnleft = bsize - 1; /* space for a '\0' */
|
||||
@@ -314,7 +314,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
||||
shf->flags &= ~SHF_READING;
|
||||
}
|
||||
if (shf->flags & SHF_STRING) {
|
||||
unsigned char *nbuf;
|
||||
unsigned char *nbuf;
|
||||
|
||||
/* Note that we assume SHF_ALLOCS is not set if SHF_ALLOCB
|
||||
* is set... (changing the shf pointer could cause problems)
|
||||
@@ -323,7 +323,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
||||
!(shf->flags & SHF_ALLOCB))
|
||||
return EOF;
|
||||
/* allocate more space for buffer */
|
||||
nbuf = (unsigned char *) aresize(shf->buf, shf->wbsize * 2,
|
||||
nbuf = (unsigned char *)aresize(shf->buf, shf->wbsize * 2,
|
||||
shf->areap);
|
||||
shf->rp = nbuf + (shf->rp - shf->buf);
|
||||
shf->wp = nbuf + (shf->wp - shf->buf);
|
||||
@@ -477,7 +477,7 @@ shf_getse(char *buf, int bsize, struct shf *shf)
|
||||
return buf == orig_buf ? NULL : buf;
|
||||
}
|
||||
}
|
||||
end = (unsigned char *) memchr((char *) shf->rp, '\n',
|
||||
end = (unsigned char *)memchr((char *) shf->rp, '\n',
|
||||
shf->rnleft);
|
||||
ncopy = end ? end - shf->rp + 1 : shf->rnleft;
|
||||
if (ncopy > bsize)
|
||||
@@ -850,7 +850,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
||||
else if ((sizeof (int) < sizeof (long)) && (c == 'd'))
|
||||
lnum = (long) va_arg(args, int);
|
||||
else
|
||||
lnum = va_arg(args, unsigned);
|
||||
lnum = va_arg(args, unsigned int);
|
||||
switch (c) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
@@ -916,7 +916,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
||||
case 's':
|
||||
if (!(s = va_arg(args, const char *)))
|
||||
s = "(null)";
|
||||
len = ksh_mbswidth(s);
|
||||
len = utf_mbswidth(s);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
@@ -978,18 +978,14 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
||||
field = 0;
|
||||
|
||||
if (precision > 0) {
|
||||
const char *q = s;
|
||||
|
||||
nwritten += precision;
|
||||
if (Flag(FUTFHACK)) {
|
||||
const char *q = s;
|
||||
while (precision-- > 0)
|
||||
utf_cptradj(q, &q);
|
||||
do {
|
||||
shf_putc(*s, shf);
|
||||
} while (++s < q);
|
||||
} else while (precision-- > 0) {
|
||||
while (precision-- > 0)
|
||||
utf_cptradj(q, &q);
|
||||
do {
|
||||
shf_putc(*s, shf);
|
||||
s++;
|
||||
}
|
||||
} while (++s < q);
|
||||
}
|
||||
if (field > 0) {
|
||||
nwritten += field;
|
||||
|
Reference in New Issue
Block a user