mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Add NetBSD support
This commit is contained in:
parent
2fdc19e7a7
commit
23ae9dfceb
4020 changed files with 8955 additions and 8128 deletions
|
@ -16,7 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/pcmpgtb.h"
|
||||
#include "libc/intrin/pmovmskb.h"
|
||||
#include "libc/intrin/psubb.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/bsf.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/thompike.h"
|
||||
#include "libc/unicode/unicode.h"
|
||||
|
||||
|
@ -24,25 +29,31 @@
|
|||
* Returns monospace display width of UTF-8 string.
|
||||
*
|
||||
* - Control codes are discounted
|
||||
*
|
||||
* - ANSI escape sequences are discounted
|
||||
*
|
||||
* - East asian glyphs, emoji, etc. count as two
|
||||
*
|
||||
* @param s is NUL-terminated string
|
||||
* @param n is max bytes to consider
|
||||
* @param o is offset for doing tabs
|
||||
* @return monospace display width
|
||||
*/
|
||||
int strnwidth(const char *s, size_t n) {
|
||||
int strnwidth(const char *s, size_t n, size_t o) {
|
||||
size_t i;
|
||||
wint_t c, w;
|
||||
unsigned l, r;
|
||||
unsigned l, r, k;
|
||||
enum { kAscii, kUtf8, kEsc, kCsi } t;
|
||||
for (w = r = t = l = 0; n--;) {
|
||||
if ((c = *s++ & 0xff)) {
|
||||
for (w = r = t = l = i = 0; i < n;) {
|
||||
if ((c = s[i++] & 0xff)) {
|
||||
switch (t) {
|
||||
case kAscii:
|
||||
if (0x20 <= c && c <= 0x7E || c == '\t') {
|
||||
if (0x20 <= c && c <= 0x7E) {
|
||||
++l;
|
||||
} else if (c == '\t') {
|
||||
if ((k = (o + i - 1) & 7)) {
|
||||
l += 8 - k;
|
||||
} else {
|
||||
l += 8;
|
||||
}
|
||||
} else if (c == 033) {
|
||||
t = kEsc;
|
||||
} else if (c >= 0300) {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
/**
|
||||
* Returns monospace display width of UTF-16 or UCS-2 string.
|
||||
*/
|
||||
int strnwidth16(const char16_t *p, size_t n) {
|
||||
int strnwidth16(const char16_t *p, size_t n, size_t o) {
|
||||
size_t l;
|
||||
wint_t wc;
|
||||
l = 0;
|
||||
|
|
|
@ -26,8 +26,9 @@
|
|||
* - East asian glyphs, emoji, etc. count as two
|
||||
*
|
||||
* @param s is NUL-terminated string
|
||||
* @param o is string offset for computing tab widths
|
||||
* @return monospace display width
|
||||
*/
|
||||
int strwidth(const char *s) {
|
||||
return strnwidth(s, -1);
|
||||
int strwidth(const char *s, size_t o) {
|
||||
return strnwidth(s, -1, 0);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@
|
|||
/**
|
||||
* Returns monospace display width of UTF-16 or UCS-2 string.
|
||||
*/
|
||||
int strwidth16(const char16_t *s) {
|
||||
return strnwidth16(s, SIZE_MAX);
|
||||
int strwidth16(const char16_t *s, size_t o) {
|
||||
return strnwidth16(s, SIZE_MAX, o);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
COSMOPOLITAN_C_START_
|
||||
|
||||
int wcwidth(wchar_t) pureconst;
|
||||
int wcswidth(const wchar_t *) strlenesque;
|
||||
int wcsnwidth(const wchar_t *, size_t) strlenesque;
|
||||
int strwidth(const char *) strlenesque;
|
||||
int strnwidth(const char *, size_t) strlenesque;
|
||||
int strwidth16(const char16_t *) strlenesque;
|
||||
int strnwidth16(const char16_t *, size_t) strlenesque;
|
||||
int wcswidth(const wchar_t *, size_t) strlenesque;
|
||||
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
|
||||
int strwidth(const char *, size_t) strlenesque;
|
||||
int strnwidth(const char *, size_t, size_t) strlenesque;
|
||||
int strwidth16(const char16_t *, size_t) strlenesque;
|
||||
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
/**
|
||||
* Returns monospace display width of wide character string.
|
||||
*/
|
||||
int wcsnwidth(const wchar_t *pwcs, size_t n) {
|
||||
int wcsnwidth(const wchar_t *pwcs, size_t n, size_t o) {
|
||||
int w, width = 0;
|
||||
for (; *pwcs && n-- > 0; pwcs++) {
|
||||
if ((w = wcwidth(*pwcs)) < 0) {
|
||||
|
|
|
@ -22,6 +22,6 @@
|
|||
/**
|
||||
* Returns monospace display width of wide character string.
|
||||
*/
|
||||
int wcswidth(const wchar_t *pwcs) {
|
||||
return wcsnwidth(pwcs, SIZE_MAX);
|
||||
int wcswidth(const wchar_t *pwcs, size_t o) {
|
||||
return wcsnwidth(pwcs, SIZE_MAX, o);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue