Delete old wcwidth() implementation

This shaves away 144kb of bss memory from every binary linking printf at
the expense of slightly increased binary footprint. Kudos for Byron Lai.
This commit is contained in:
Justine Tunney 2023-10-14 03:06:11 -07:00
parent 2db2f40a98
commit a657f3e878
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
15 changed files with 11 additions and 814 deletions

View file

@ -1,204 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/macros.internal.h"
#include "libc/sysv/consts/nr.h"
#include "libc/nexgen32e/kompressor.h"
#include "libc/sysv/consts/madv.h"
.rodata.cst4
kCombiningCharsBits:
.long 114752 * 8
.endobj kCombiningCharsBits,globl,hidden
.previous
.initbss 400,_init_kCombiningChars
kCombiningChars:
.zero 114752
.endobj kCombiningChars,globl,hidden
.previous
.init.start 400,_init_kCombiningChars
push %rsi
mov $1203,%edx
call lz4cpy
mov %rax,%rdi
pop %rsi
add $1208,%rsi
.init.end 400,_init_kCombiningChars
// o/tool/build/lz4toasm.com
// -o o/libc/str/CombiningChars.s
// -s kCombiningChars
// o/libc/str/CombiningChars.bin.lz4
.initro 400,_init_kCombiningChars
kCombiningCharsLz4:
.byte 0x1f,0x00,0x01,0x00,0x4c,0x19,0xff,0x01 #  Lλ
.byte 0x00,0x0f,0x30,0x00,0x0f,0x2f,0xf8,0x03 # 0 /°
.byte 0x22,0x00,0x0d,0x10,0xfe,0x49,0x00,0x23 #. I .
.byte 0xbf,0xb6,0x0e,0x00,0x42,0x3f,0x00,0xff # B λ
.byte 0x17,0x39,0x00,0x00,0x5e,0x00,0x17,0x01 #9  ^ 
.byte 0x28,0x00,0x92,0xc0,0xbf,0x9f,0x3d,0x00 #( Æƒ= 
.byte 0x00,0x00,0x80,0x02,0x86,0x00,0x17,0x07 #  Çå 
.byte 0x1a,0x00,0x13,0xff,0x28,0x00,0x91,0xf8 # λ( æ°
.byte 0x0f,0x20,0x00,0x00,0xc0,0xfb,0xef,0x3e #   >
.byte 0x0e,0x00,0x1b,0x0e,0x8a,0x00,0x26,0xff # è &λ
.byte 0xff,0x37,0x00,0xa2,0x14,0xfe,0x21,0xfe #λ7 ó!
.byte 0x00,0x0c,0x00,0x00,0x00,0x02,0x10,0x00 #     
.byte 0x40,0x10,0x1e,0x20,0x00,0x10,0x00,0x23 #@   .
.byte 0x40,0x06,0x10,0x00,0x20,0x86,0x39,0x1a #@  å9
.byte 0x00,0x24,0x23,0x00,0x10,0x00,0x21,0xbe # $.  !
.byte 0x21,0x20,0x00,0x13,0xfc,0x30,0x00,0x41 #!  0 A
.byte 0x90,0x1e,0x20,0x40,0x40,0x00,0x13,0x04 #É @@ 
.byte 0x5e,0x00,0x22,0x01,0x20,0x08,0x00,0x13 #^ .  
.byte 0x11,0x93,0x00,0x38,0xc1,0x3d,0x60,0x60 #ô 8=``
.byte 0x00,0x31,0x90,0x40,0x30,0x40,0x00,0x13 # 1É@0@ ‼
.byte 0x00,0x0f,0x01,0x13,0x18,0x70,0x00,0x06 # p 
.byte 0x9f,0x00,0x27,0x04,0x5c,0x0d,0x00,0x48 #ƒ \ H
.byte 0xf2,0x07,0x80,0x7f,0x1d,0x00,0x45,0xf2 #Ç E
.byte 0x1f,0x00,0x3f,0x0d,0x00,0x43,0x03,0x00 #  C 
.byte 0x00,0xa0,0x57,0x00,0x50,0xfe,0x7f,0xdf # áW P
.byte 0xe0,0xff,0x41,0x01,0x28,0x1f,0x40,0x2f #αλA(@/
.byte 0x00,0xff,0x00,0xe0,0xfd,0x66,0x00,0x00 # λ α²f  
.byte 0x00,0xc3,0x01,0x00,0x1e,0x00,0x64,0x20 #   d
.byte 0x00,0x20,0xcc,0x01,0x0b,0x0f,0xd2,0x01 # 
.byte 0x1d,0x06,0x66,0x00,0x1f,0x00,0x01,0x00 #f   
.byte 0x62,0x13,0x1c,0x04,0x00,0x26,0x0c,0x00 #b & 
.byte 0x42,0x01,0x52,0xb0,0x3f,0x40,0xfe,0x0f #BR@
.byte 0xe8,0x00,0x1a,0x78,0x2e,0x00,0x26,0x60 #Φ x. &`
.byte 0x00,0x85,0x01,0x04,0x14,0x00,0x4f,0x87 # à Oç
.byte 0x01,0x04,0x0e,0x60,0x00,0x07,0x22,0x80 #` .Ç
.byte 0x09,0x08,0x00,0x63,0x40,0x7f,0xe5,0x1f # c@σ
.byte 0xf8,0x9f,0x2a,0x01,0x05,0x8e,0x01,0x11 #°ƒ*Ä
.byte 0x0f,0x06,0x00,0x32,0xd0,0x17,0x04,0x70 # 2p
.byte 0x02,0x01,0xd0,0x01,0x23,0x3c,0x3b,0x32 #.<;2
.byte 0x00,0x13,0xa3,0xde,0x01,0x2f,0xf0,0xcf # ú/
.byte 0x58,0x00,0x00,0x6f,0xf7,0xff,0xfd,0x21 #X  oλ²!
.byte 0x10,0x03,0x8c,0x01,0x0c,0x1f,0xfb,0x1f #î
.byte 0x01,0x2e,0x52,0xf8,0x00,0x00,0x00,0x7c #.R°   |
.byte 0x0b,0x00,0x2c,0xdf,0xff,0x62,0x00,0x2f # ,λb /
.byte 0x01,0x00,0x01,0x00,0xff,0x6b,0x1d,0x80 #  λkÇ
.byte 0xff,0x01,0x1c,0x80,0xa2,0x01,0x0f,0x68 #λÇóh
.byte 0x00,0x32,0x19,0x3c,0x0e,0x00,0x2f,0x06 # 2< /
.byte 0x00,0x01,0x00,0xff,0xff,0xff,0xff,0xff #  λλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xb3,0x20,0x80,0xf7,0xf6,0x12,0x28 #λ Ç÷(
.byte 0xc0,0x00,0xfb,0x12,0x0f,0x33,0x00,0x0c # 3 
.byte 0x23,0x44,0x08,0xf4,0x11,0x0b,0x18,0x00 #.D 
.byte 0x11,0x30,0x60,0x0f,0x11,0x03,0x70,0x0f #0`p
.byte 0x62,0xc0,0x3f,0x00,0x00,0x80,0xff,0x4c #b  ÇλL
.byte 0x00,0x02,0x10,0x14,0x20,0xc8,0x33,0x06 #  3
.byte 0x00,0x05,0x29,0x13,0x52,0x7e,0x66,0x00 # )R~f 
.byte 0x08,0x10,0xf8,0x13,0x02,0x11,0x00,0x21 #° !
.byte 0x9d,0xc1,0x43,0x12,0x2f,0x30,0x40,0x7c #¥C/0@|
.byte 0x00,0x0a,0x2f,0x20,0x21,0x96,0x0a,0xff # / !ûλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xdb,0x1f,0x40,0x60,0x1f,0x4b,0x2f,0x00 #@`K/ 
.byte 0x00,0x06,0x1a,0x08,0x1f,0x80,0x3f,0x00 # Ç 
.byte 0x0c,0x1f,0x0e,0x7f,0x00,0x2c,0x1f,0x20 # ,
.byte 0x1d,0x00,0x09,0x0e,0x3e,0x1c,0x2f,0xc0 # >/
.byte 0x07,0xdd,0x01,0xbd,0x22,0x6e,0xf0,0x23 #.n.
.byte 0x1e,0x0f,0x1c,0x00,0x01,0x1f,0x60,0x64 # `d
.byte 0x00,0x34,0x1f,0xf0,0x44,0x00,0x30,0x05 # 4D 0
.byte 0xf4,0x20,0x0b,0x18,0x00,0x1a,0x02,0xb1 #  
.byte 0x1e,0x03,0x72,0x1c,0x24,0x78,0x26,0xda #r$x&
.byte 0x01,0x00,0xf0,0x0c,0x33,0x80,0xef,0x1f # 3Ç
.byte 0x2e,0x00,0x13,0x08,0x52,0x0d,0x48,0xc0 #. RH
.byte 0x7f,0x00,0x1e,0x66,0x02,0x1f,0xd3,0xe4 # fΣ
.byte 0x02,0x01,0x36,0x80,0xf8,0x07,0xc0,0x20 #6Ç°
.byte 0x00,0x7e,0x00,0x3f,0xc0,0x1f,0x1f,0xc7 # ~ 
.byte 0x02,0x06,0x19,0x5c,0x28,0x03,0x3f,0xf8 #\(°
.byte 0x85,0x0d,0xb1,0x1c,0x0b,0x22,0xb0,0x01 #à.
.byte 0xa3,0x0d,0x04,0x30,0x00,0x19,0xa7,0xde #ú0 º
.byte 0x00,0x29,0x28,0xbf,0x78,0x20,0x2f,0xbc # )(x /
.byte 0x0f,0x38,0x0e,0x0d,0x1f,0xff,0xf4,0x1c #8λ
.byte 0x20,0x20,0xf0,0x0c,0x74,0x00,0x11,0xfe # t 
.byte 0xd2,0x02,0x52,0xf8,0x79,0x80,0x00,0x7e #R°yÇ ~
.byte 0x4c,0x03,0x3f,0xfc,0x7f,0x03,0x4c,0x00 #LL 
.byte 0x1f,0x17,0x7f,0xb1,0x00,0x5b,0xfc,0xff # [λ
.byte 0xff,0xfc,0x6d,0x20,0x00,0x26,0x7e,0xb4 #λm  &~
.byte 0x21,0x00,0x1f,0xa3,0x58,0x00,0x18,0x1f #! úX 
.byte 0x18,0x23,0x07,0xff,0xff,0x96,0x2f,0xff #.λλû/λ
.byte 0x01,0xfb,0x0d,0xff,0xff,0xff,0xff,0xff #λλλλλ
.byte 0xff,0xc9,0x04,0xf0,0x0a,0x1f,0x7f,0x1c #λ
.byte 0x19,0x70,0x04,0x08,0x00,0x1f,0x07,0x30 #p 0
.byte 0x18,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλ
.byte 0xff,0xff,0x96,0x2f,0x60,0x0f,0x5f,0x25 #λλû/`_%
.byte 0xff,0xff,0x87,0x5d,0x03,0xf8,0xff,0xe7 #λλç]°λτ
.byte 0x0f,0x30,0x34,0x05,0x66,0x37,0x0f,0xba #04f7
.byte 0x14,0xe2,0x01,0x01,0x00,0x12,0x7f,0x2d #Γ -
.byte 0x3a,0x20,0x1f,0x20,0x01,0x26,0x3f,0xf8 #: &°
.byte 0xfe,0xff,0xc0,0x00,0x97,0x5f,0x7f,0xff #λ ù_λ
.byte 0xff,0xf9,0xdb,0x13,0x0e,0x0e,0x1f,0x7f #λ
.byte 0xb9,0x1a,0x24,0x0f,0xda,0x01,0xa9,0x0a #$
.byte 0xf4,0x00,0x3f,0xf0,0x07,0x00,0x01,0x00 #   
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0x46,0x57,0x02,0x00 #λλλλFW 
.byte 0x00,0x00,0xff,0x01,0x00,0x0c,0x20,0x00 #  λ   
.byte 0x1f,0xff,0x01,0x00,0x07,0x50,0xff,0xff #λ Pλλ
.byte 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00
.endobj kCombiningCharsLz4,globl,hidden
.previous

View file

@ -1,93 +0,0 @@
// o/$(MODE)/tool/build/lz4toasm.com -o o/$(MODE)/libc/str/EastAsianWidth.s -s kEastAsianWidth o/$(MODE)/libc/str/EastAsianWidth.bin.lz4
#include "libc/nexgen32e/kompressor.h"
#include "libc/macros.internal.h"
.rodata
.balign 4
kEastAsianWidthBits:
.long 32768 * 8
.endobj kEastAsianWidthBits,globl,hidden
.previous
.initbss 500,_init_kEastAsianWidth
kEastAsianWidth:
.zero 32768
.endobj kEastAsianWidth,globl,hidden
.previous
.init.start 500,_init_kEastAsianWidth
push %rsi
mov $500,%edx
call lz4cpy
mov %rax,%rdi
pop %rsi
add $504,%rsi
.init.end 500,_init_kEastAsianWidth
.initro 500,_init_kEastAsianWidth
kEastAsianWidthLz4:
.byte 0x1f,0x00,0x01,0x00,0xff,0xff,0x0e,0x17 #  λλ
.byte 0xff,0x01,0x00,0x0f,0x30,0x01,0xff,0x12 #λ 0λ
.byte 0xaf,0x88,0x99,0xf0,0xad,0xae,0xfb,0x2b #»êÖ¡«+
.byte 0x00,0x81,0xfb,0x13,0x01,0xf6,0x3f,0x0c # ü÷?
.byte 0x00,0x06,0x1a,0x00,0x04,0x2f,0x1e,0x09 #  /
.byte 0x5c,0x00,0x2d,0x43,0x60,0x00,0x00,0x30 #\ -C`  0
.byte 0xa9,0x02,0x10,0x0f,0x06,0x00,0xf3,0x0d # 
.byte 0x80,0x00,0x00,0x08,0x00,0x02,0x0c,0x00 #Ç    
.byte 0x60,0x30,0x40,0x10,0x00,0x00,0x04,0x2c #`0@►  ♦,
.byte 0x24,0x20,0x0c,0x00,0x00,0x00,0x01,0x00 #$     
.byte 0x00,0x00,0x50,0xb8,0x33,0x00,0x10,0xe0 #  P3 α
.byte 0x11,0x00,0x1f,0x80,0x00,0x01,0x58,0x12 # Ç X
.byte 0x18,0x07,0x00,0x1f,0x21,0xb0,0x03,0x55 # !U
.byte 0x16,0xfb,0xb2,0x03,0x3f,0x0f,0x00,0xff #? λ
.byte 0x01,0x00,0x06,0x11,0x3f,0x35,0x01,0x03 # ?5
.byte 0x0d,0x00,0x4e,0x7f,0xfe,0xff,0xff,0x0b # Nλλ
.byte 0x00,0x41,0xff,0xff,0xff,0xe0,0x06,0x00 # Aλλλα 
.byte 0x07,0x13,0x00,0x11,0x7f,0x06,0x00,0x17 #  
.byte 0x07,0x5e,0x00,0x02,0x12,0x00,0x2f,0x00 #^  / 
.byte 0xff,0x01,0x00,0xff,0xff,0xff,0x5d,0x0e #λ λλλ]
.byte 0xa0,0x07,0x0f,0x01,0x00,0xff,0xff,0xff #á λλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xbe #λλλλλλλ
.byte 0x13,0x1f,0x67,0x0e,0x0f,0x0c,0x13,0x83 #gâ
.byte 0x1f,0x1f,0x60,0x13,0x3d,0x0f,0x63,0x06 #`=c
.byte 0xff,0xff,0xff,0xff,0xff,0x66,0x2f,0x0f #λλλλλf/
.byte 0x00,0x01,0x00,0xff,0xff,0xf9,0x04,0xb0 #  λλ
.byte 0x1a,0x2f,0xd1,0xe0,0x00,0x1d,0xff,0x10 #/α λ
.byte 0x0f,0xa8,0x15,0x21,0x0f,0xa2,0x00,0x50 #¿§!ó P
.byte 0x12,0x03,0xa6,0x00,0x3f,0xf7,0xff,0x7f #ª ?λ
.byte 0xd9,0x04,0x00,0x08,0xcd,0x19,0x1b,0x01 # 
.byte 0x1c,0x00,0x2f,0x7f,0x00,0x01,0x00,0xff # /  λ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xf8,0x1f,0x0f,0x80 #λλλλ°Ç
.byte 0x18,0xff,0xff,0xf1,0x0f,0x00,0x03,0x4c #λλ± L
.byte 0x1f,0x07,0x04,0x08,0xff,0xff,0xff,0xff #λλλλ
.byte 0x92,0x0f,0xc5,0x04,0x10,0x03,0x27,0x16 #Æ'
.byte 0x4f,0x07,0x00,0xf0,0x00,0x6b,0x1b,0x1f #O  k
.byte 0x0f,0x04,0x10,0xff,0xff,0xff,0xff,0xff #λλλλλ
.byte 0xff,0xff,0x94,0x1f,0x10,0x19,0x00,0x05 #λλö 
.byte 0x0f,0x22,0x39,0x05,0x29,0x40,0xfe,0xd5 #.9)@■╒
.byte 0x0c,0x12,0x07,0x14,0x08,0x6f,0x0f,0xff #oλ
.byte 0x01,0x03,0x00,0x3f,0x60,0x08,0x04,0x34 # ?`4
.byte 0x01,0xe0,0xbf,0x10,0x08,0x15,0xdf,0x36 #α§6
.byte 0x38,0x10,0x87,0x08,0x00,0x15,0x11,0x64 #8ç §d
.byte 0x08,0x1f,0xfd,0x40,0x08,0x03,0x15,0x9f #²@§ƒ
.byte 0xad,0x38,0x11,0x78,0x4d,0x1f,0x10,0x04 #¡8xM
.byte 0xf3,0x39,0x07,0xb4,0x00,0x1c,0xf8,0x6a #9 °j
.byte 0x1f,0x05,0xde,0x38,0x6f,0x10,0x27,0x00 #8o' 
.byte 0x00,0x18,0xf0,0x81,0x0d,0x0a,0x0f,0x9e # ü
.byte 0x08,0x12,0x18,0xe0,0x8f,0x00,0x20,0x7b #αÅ  {
.byte 0xfc,0x06,0x00,0x20,0xe7,0xc7,0x05,0x00 #  τ 
.byte 0x0f,0xe0,0x1f,0x01,0x5f,0x0f,0x07,0x07 #α_
.byte 0x00,0x3f,0xe0,0x20,0x9b,0x0f,0x01,0x00 # ?α ¢ 
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0x0b,0x1f,0x3f,0xfc,0x1f,0xff,0xff,0xff #?λλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff #λλλλλλλλ
.byte 0xff,0xff,0xff,0xff,0xff,0x08,0x50,0xff #λλλλλPλ
.byte 0xff,0xff,0xff,0x3f,0x00,0x00,0x00,0x00
.endobj kEastAsianWidthLz4,globl,hidden
.previous

View file

@ -138,11 +138,6 @@ ssize_t strfmon(char *, size_t, const char *, ...);
long a64l(const char *);
char *l64a(long);
char *strntolower(char *, size_t) libcesque;
char *strtolower(char *) libcesque paramsnonnull();
char *strntoupper(char *, size_t) libcesque;
char *strtoupper(char *) libcesque paramsnonnull();
typedef unsigned mbstate_t;
wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t);

View file

@ -93,32 +93,6 @@ $(LIBC_STR_A_OBJS): private \
-Wframe-larger-than=4096 \
-Walloca-larger-than=4096
o/$(MODE)/libc/str/eastasianwidth.bin: \
libc/str/eastasianwidth.txt \
o/$(MODE)/tool/decode/mkwides.com
@$(COMPILE) -AMKWIDES -T$@ o/$(MODE)/tool/decode/mkwides.com -o $@ $<
o/$(MODE)/libc/str/eastasianwidth.bin.lz4: \
o/$(MODE)/libc/str/eastasianwidth.bin \
o/$(MODE)/third_party/lz4cli/lz4cli.com
@$(COMPILE) -ALZ4 -T$@ o/$(MODE)/third_party/lz4cli/lz4cli.com -q -f -9 --content-size $< $@
o/$(MODE)/libc/str/eastasianwidth.s: \
o/$(MODE)/libc/str/eastasianwidth.bin.lz4 \
o/$(MODE)/tool/build/lz4toasm.com
@$(COMPILE) -ABIN2ASM -T$@ o/$(MODE)/tool/build/lz4toasm.com -s kEastAsianWidth -o $@ $<
o/$(MODE)/libc/str/combiningchars.bin: \
libc/str/strdata.txt \
o/$(MODE)/tool/decode/mkcombos.com
@$(COMPILE) -AMKCOMBOS -T$@ o/$(MODE)/tool/decode/mkcombos.com -o $@ $<
o/$(MODE)/libc/str/combiningchars.bin.lz4: \
o/$(MODE)/libc/str/combiningchars.bin \
o/$(MODE)/third_party/lz4cli/lz4cli.com
@$(COMPILE) -ALZ4 -T$@ o/$(MODE)/third_party/lz4cli/lz4cli.com -q -f -9 --content-size $< $@
o/$(MODE)/libc/str/combiningchars.s: \
o/$(MODE)/libc/str/combiningchars.bin.lz4 \
o/$(MODE)/tool/build/lz4toasm.com
@$(COMPILE) -ABIN2ASM -T$@ o/$(MODE)/tool/build/lz4toasm.com -s kCombiningChars -o $@ $<
LIBC_STR_LIBS = $(foreach x,$(LIBC_STR_ARTIFACTS),$($(x)))
LIBC_STR_SRCS = $(foreach x,$(LIBC_STR_ARTIFACTS),$($(x)_SRCS))
LIBC_STR_HDRS = $(foreach x,$(LIBC_STR_ARTIFACTS),$($(x)_HDRS))

View file

@ -1,34 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
char *strntolower(char *s, size_t n) {
unsigned char *p = (unsigned char *)s;
for (;;) {
if (n-- && *p) {
if ('A' <= *p && *p <= 'Z') {
*p += 'a' - 'A';
}
++p;
} else {
break;
}
}
return s;
}

View file

@ -1,36 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
/**
* Mutates string to ASCII uppercase w/ limit.
*
* @praam s is string
* @praam n is max bytes to consider
* @return string
*/
char *strntoupper(char *s, size_t n) {
size_t i;
for (i = 0; s[i] && i < n; ++i) {
if ('a' <= s[i] && s[i] <= 'z') {
s[i] -= 'a' - 'A';
}
}
return s;
}

View file

@ -1,35 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
/**
* Mutates string to ASCII lowercase.
*
* @praam s is string
* @return string
*/
char *strtolower(char *s) {
size_t i;
for (i = 0; s[i]; ++i) {
if ('A' <= s[i] && s[i] <= 'Z') {
s[i] += 'a' - 'A';
}
}
return s;
}

View file

@ -1,35 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
/**
* Mutates string to ASCII uppercase.
*
* @praam s is string
* @return string
*/
char *strtoupper(char *s) {
size_t i;
for (i = 0; s[i]; ++i) {
if ('a' <= s[i] && s[i] <= 'z') {
s[i] -= 'a' - 'A';
}
}
return s;
}

View file

@ -21,33 +21,10 @@
#include "libc/str/unicode.h"
#include "libc/str/wcwidth_osx.internal.h"
extern const uint8_t kEastAsianWidth[];
extern const uint32_t kEastAsianWidthBits;
extern const uint8_t kCombiningChars[];
extern const uint32_t kCombiningCharsBits;
/**
* Returns cell width of monospace character.
*/
int wcwidth(wchar_t c) {
#if defined(__x86_64__) && !defined(__chibicc__)
if (LIKELY(32 <= c && c < 127)) {
return 1;
} else if (!c) {
return 0;
} else if ((uint32_t)c > 0x10FFFD || //
(0 < c && c < 32) || //
(0x7f <= c && c < 0xA0)) {
return -1;
} else if ((0 <= c && c < kCombiningCharsBits) &&
!!(kCombiningChars[c >> 3] & (1 << (c & 7)))) {
return 0;
} else if (0 <= c && c < kEastAsianWidthBits) {
return 1 + !!(kEastAsianWidth[c >> 3] & (1 << (c & 7)));
} else {
return 1;
}
#else
int res;
if (LIKELY(32 <= c && c < 127)) return 1;
if (VERY_UNLIKELY((uint32_t)c >= 0x100000)) {
@ -60,5 +37,4 @@ int wcwidth(wchar_t c) {
if (iswcntrl(c)) return -1;
}
return res;
#endif
}

View file

@ -1,63 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
TEST(strtolower, testAligned) {
EXPECT_STREQ("azcdabcdabcdabcd", strtolower(gc(strdup("AZCDabcdABCDabcd"))));
EXPECT_STREQ("azcdabcdabcdabcdabcdabcdabcdabcd",
strtolower(gc(strdup("AZCDabcdABCDabcdABCDabcdABCDabcd"))));
}
TEST(strtolower, testUnaligned) {
EXPECT_STREQ("1", strtolower(gc(strdup("1"))));
EXPECT_STREQ(
"zcdabcdabcdabcdabcdabcdabcdabc",
strtolower((char *)gc(strdup("AZCDabcdABCDabcdABCDabcdABCDabc")) + 1));
}
TEST(strtoupper, testAligned) {
EXPECT_STREQ("AZCDABCDABCDABCD", strtoupper(gc(strdup("AZCDabcdABCDabcd"))));
EXPECT_STREQ("AZCDABCDABCDABCDABCDABCDABCDABCD",
strtoupper(gc(strdup("AZCDabcdABCDabcdABCDabcdABCDabcd"))));
}
TEST(strtoupper, testUnaligned) {
EXPECT_STREQ("1", strtoupper(gc(strdup("1"))));
EXPECT_STREQ(
"ZCDABCDABCDABCDABCDABCDABCDABC",
strtoupper((char *)gc(strdup("AZCDabcdABCDabcdABCDabcdABCDabc")) + 1));
}
BENCH(strtolower, bench) {
size_t size = FRAMESIZE;
char *data = gc(malloc(size));
EZBENCH2(
"strtolower",
{
rngset(data, size, _rand64, -1);
data[size - 1] = 0;
},
strtolower(data));
}

View file

@ -36,6 +36,7 @@
TEST(connect, nonblocking) {
if (IsFreebsd()) return; // TODO(jart): why did this start flaking?
if (IsOpenbsd()) return; // TODO(jart): why did this start freezing?
char buf[16] = {0};
atomic_uint *sem = _mapshared(sizeof(unsigned));
uint32_t addrsize = sizeof(struct sockaddr_in);

View file

@ -1,33 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(strntolower, test) {
char s[128] = "ABCD";
strntolower(s, -1);
EXPECT_STREQ("abcd", s);
}
TEST(strntolower, testLong) {
char s[128] = "ABCDabcdABCDabcdABCDabcdABCDabcdABCDabcd";
strntolower(s, -1);
EXPECT_STREQ("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", s);
}

View file

@ -1,122 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/fileno.h"
#include "third_party/getopt/getopt.internal.h"
#include "third_party/zlib/zlib.h"
#include "tool/decode/lib/bitabuilder.h"
static size_t linecap;
static FILE *fin, *fout;
static uint32_t bit, maxbit;
static struct BitaBuilder *bitset;
static char *line, *tok, *s1, *category, *g_inpath, *g_outpath;
wontreturn void ShowUsage(FILE *f, int rc) {
fprintf(f, "Usage: %s [-o OUTPUT] [INPUT]\n", "Usage",
program_invocation_name);
exit(rc);
}
void GetOpts(int argc, char *argv[]) {
int opt;
g_inpath = "/dev/stdin";
g_outpath = "/dev/stdout";
while ((opt = getopt(argc, argv, "?ho:")) != -1) {
switch (opt) {
case 'o':
g_outpath = optarg;
break;
case 'h':
case '?':
ShowUsage(stdout, EXIT_SUCCESS);
default:
ShowUsage(stderr, EX_USAGE);
}
}
if (argc - optind) {
g_inpath = argv[optind];
}
}
/**
* Builds sparse unicode dataset for combining codepoints, e.g.
*
* UNDERLINING
*
* - COMBINING MACRON BELOW U+0331 (\xCC\xB1)
* e.g. A̱ḆC̱Ḏ (too short) 41CCB1 42CCB1 43CCB1 44CCB1
*
* - COMBINING DOUBLE MACRON BELOW U+035F (\xCD\x9F)
* e.g. A͟B͟C͟D͟ (too long) 41CD9F 42CD9F 43CD9F 44CD9F
*
* - DOUBLE PLUS COMBINING MACRON BELOW 3×U+035F + 1×U+0331
* e.g. A͟B͟C͟Ḏ (just right) 41CCB1 42CCB1 43CCB1 44CD9F
*
* STRIKETHROUGH
*
* - COMBINING LONG STROKE OVERLAY U+0336 (\xCC\xB6)
* e.g. A̶B̶C̶D̶ 41CCB6 42CCB6 43CCB6 44CCB6
*
* - COMBINING SHORT STROKE OVERLAY U+0335 (\xCC\xB5)
* e.g. A̵B̵C̵D̵ 41CCB5 42CCB5 43CCB5 44CCB5
*
* - COMBINING SHORT SOLIDUS OVERLAY U+0337 (\xCC\xB7)
* e.g. A̷B̷C̷D̷ 41CCB7 42CCB7 43CCB7 44CCB7
*
* - COMBINING LONG SOLIDUS OVERLAY U+0338 (\xCC\xB8)
* e.g. A̸B̸C̸D̸ 41CCB8 42CCB8 43CCB8 44CCB8
*
* @see unicode.org/reports/tr11/#Definitions
* @see https://www.compart.com/en/unicode/category/Sk (Modifier Symbol)
*/
int main(int argc, char *argv[]) {
GetOpts(argc, argv);
CHECK_NOTNULL(fin = fopen(g_inpath, "r"));
bitset = bitabuilder_new();
while ((getline(&line, &linecap, fin)) != -1) {
tok = line;
s1 = strsep(&tok, ";");
strsep(&tok, ";");
category = strsep(&tok, ";");
if (!s1 || !category) continue;
bit = strtol(s1, NULL, 16);
if (bit != 0x00AD &&
((0x1160 <= bit && bit <= 0x11FF) ||
(strcmp(category, "Me") == 0 || strcmp(category, "Mn") == 0 ||
strcmp(category, "Cf") == 0))) {
maxbit = max(bit, maxbit);
CHECK(bitabuilder_setbit(bitset, bit));
}
}
CHECK_NOTNULL(fout = fopen(g_outpath, "wb"));
CHECK(bitabuilder_fwrite(bitset, fout));
bitabuilder_free(&bitset);
return fclose(fin) | fclose(fout);
}

View file

@ -1,104 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "third_party/getopt/getopt.internal.h"
#include "tool/decode/lib/bitabuilder.h"
static FILE *fin, *fout;
static char width, *line;
static size_t linecap, i, x, y;
static struct BitaBuilder *bitset;
static char *g_inpath, *g_outpath;
wontreturn void ShowUsage(FILE *f, int rc) {
fprintf(f, "Usage: %s [-o OUTPUT] [INPUT]\n", "Usage",
program_invocation_name);
exit(rc);
}
void GetOpts(int argc, char *argv[]) {
int opt;
g_inpath = "/dev/stdin";
g_outpath = "/dev/stdout";
while ((opt = getopt(argc, argv, "?ho:")) != -1) {
switch (opt) {
case 'o':
g_outpath = optarg;
break;
case 'h':
case '?':
ShowUsage(stdout, EXIT_SUCCESS);
default:
ShowUsage(stderr, EX_USAGE);
}
}
if (argc - optind) {
g_inpath = argv[optind];
}
}
/**
* Converts official UNICODE monospace widths (yup) to a bitset.
*
* (°°) ̲̲̲
* -
*
* 172kB TXT 32kB bits 525 bytes lz4
*
* @note this tool may print binary to stdout
* @see libc/kompressor/lz4decode.c
* @see tool/viz/bing.c
* @see tool/viz/fold.c
* @see unicode.org/reports/tr11/#Definitions
*/
int main(int argc, char *argv[]) {
GetOpts(argc, argv);
bitset = bitabuilder_new();
CHECK_NOTNULL(fin = fopen(g_inpath, "r"));
while ((getline(&line, &linecap, fin)) != -1) {
x = 0;
y = 0;
if (sscanf(line, "%x..%x;%c", &x, &y, &width) != 3) {
if (sscanf(line, "%x;%c", &x, &width) == 2) {
y = x;
} else {
continue;
}
}
CHECK_LE(x, y);
if (width == 'F' /* full-width */ || width == 'W' /* wide */) {
for (i = x; i <= y; ++i) {
CHECK(bitabuilder_setbit(bitset, i));
}
}
}
CHECK_NOTNULL(fout = fopen(g_outpath, "wb"));
CHECK(bitabuilder_fwrite(bitset, fout));
bitabuilder_free(&bitset);
return fclose(fin) | fclose(fout);
}

View file

@ -315,6 +315,16 @@ static struct timespec GetGraceTime(void) {
return timespec_sub(deadline_, timespec_real());
}
static char *strntoupper(char *s, size_t n) {
size_t i;
for (i = 0; s[i] && i < n; ++i) {
if ('a' <= s[i] && s[i] <= 'z') {
s[i] -= 'a' - 'A';
}
}
return s;
}
static int GetNamedVector(const struct NamedVector *choices, size_t n,
const char *s) {
int i;