修复了关于 snprintf 的错误(不支持长度推导)
This commit is contained in:
@@ -21,7 +21,9 @@ def vsprintf(buf: t.CChar | t.CPtr, rule: str, *args) -> t.CInt:
|
||||
return vsnprintf(buf, 0x7FFFFFFF, rule, args)
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, *args) -> t.CInt | t.CExport:
|
||||
if buf is None or fmt is None or size == 0: return 0
|
||||
if fmt is None: return 0
|
||||
if buf is None or size == 0:
|
||||
return vsnprintf(None, 0, fmt, args)
|
||||
return vsnprintf(buf, size, fmt, args)
|
||||
|
||||
# Check floating-point special values (IEEE 754)
|
||||
@@ -39,7 +41,17 @@ def _check_special_float(fv: t.CDouble) -> t.CInt:
|
||||
return 3
|
||||
|
||||
def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.CPtr) -> t.CInt | t.CExport:
|
||||
if buf is None or fmt is None or size == 0: return 0
|
||||
if fmt is None: return 0
|
||||
# 长度探测模式:buf is None 时只计算格式化后长度,不实际写入
|
||||
# _step=0 使 ptr 不前进,反复写入同一个 dummy 字节(无害),write_count 正确累加
|
||||
count_mode: t.CInt = 0
|
||||
_step: t.CInt = 1
|
||||
_dummy: t.CChar = '\0'
|
||||
if buf is None or size == 0:
|
||||
count_mode = 1
|
||||
_step = 0
|
||||
buf = c.Addr(_dummy)
|
||||
size = 0x7FFFFFFF
|
||||
ptr: t.CChar | t.CPtr = buf
|
||||
write_count: t.CInt = 0
|
||||
temp: t.CArray[t.CChar, 68]
|
||||
@@ -48,7 +60,7 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
if c.Deref(fmt) != 37:
|
||||
ptr[0] = c.Deref(fmt)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fmt += 1
|
||||
else:
|
||||
fmt += 1
|
||||
@@ -121,7 +133,7 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
ptr_i: t.CInt = va_arg(ap)
|
||||
ptr[0] = t.CChar(ptr_i)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
else:
|
||||
ptr_i: t.CInt = va_arg(ap)
|
||||
elif c.Deref(fmt) == 115:
|
||||
@@ -137,19 +149,19 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while c.Deref(s) != 0 and write_count < size - 1:
|
||||
ptr[0] = c.Deref(s)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
s += 1
|
||||
if left_align and width > slen:
|
||||
pad_count = width - slen
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 100 or c.Deref(fmt) == 105:
|
||||
if is_long_long or is_size or is_long:
|
||||
@@ -192,26 +204,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 117:
|
||||
if is_long or is_long_long or is_size:
|
||||
@@ -230,26 +242,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 120:
|
||||
if is_long or is_long_long or is_size:
|
||||
@@ -280,35 +292,35 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if prefix_len > 0:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 120
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if pad_zero and width > effective_len:
|
||||
pad_count = width - effective_len
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > effective_len:
|
||||
pad_count = width - effective_len
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 88:
|
||||
if is_long or is_long_long or is_size:
|
||||
@@ -339,35 +351,35 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if prefix_len > 0:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 88
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if pad_zero and width > effective_len:
|
||||
pad_count = width - effective_len
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > effective_len:
|
||||
pad_count = width - effective_len
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 111:
|
||||
if is_long or is_long_long or is_size:
|
||||
@@ -397,26 +409,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 98:
|
||||
if is_long or is_long_long or is_size:
|
||||
@@ -446,26 +458,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 112:
|
||||
ptr_val: t.CUInt64T = t.CUInt64T(va_arg(ap, t.CPtr))
|
||||
@@ -500,26 +512,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while i > 0 and write_count < size - 1:
|
||||
i -= 1
|
||||
ptr[0] = temp[i]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > i:
|
||||
pad_count = width - i
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 102 or c.Deref(fmt) == 70:
|
||||
f_upper: t.CInt = 1 if c.Deref(fmt) == 70 else 0
|
||||
@@ -540,23 +552,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while f_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
f_pad -= 1
|
||||
if f_sp == 2:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif f_sp == 1 and show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif f_sp == 1 and space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fi_c: t.CInt = 0
|
||||
while fi_c < 3 and write_count < size - 1:
|
||||
fc: t.CInt = 0
|
||||
@@ -580,14 +592,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
fc -= 32
|
||||
ptr[0] = t.CChar(fc)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fi_c += 1
|
||||
if left_align and width > f_total_len:
|
||||
f_pad = width - f_total_len
|
||||
while f_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
f_pad -= 1
|
||||
fmt += 1
|
||||
continue
|
||||
@@ -595,18 +607,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fv = 0.0 - fv
|
||||
elif show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
di: t.CInt = 0
|
||||
work: t.CDouble = fv
|
||||
if work < 1.0:
|
||||
@@ -635,25 +647,25 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > f_total:
|
||||
pad_count = width - f_total
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
while di > 0 and write_count < size - 1:
|
||||
di -= 1
|
||||
ptr[0] = temp[di]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if precision > 0:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 46
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fi: t.CInt = 0
|
||||
while fi < precision and fi < TEMP_BUF_SIZE - 1:
|
||||
temp[fi] = t.CChar(frac_part % 10 + 48)
|
||||
@@ -666,18 +678,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
fi -= 1
|
||||
ptr[0] = temp[fi]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif alt_form:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 46
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > f_total:
|
||||
pad_count = width - f_total
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 101 or c.Deref(fmt) == 69:
|
||||
if precision < 0: precision = 6
|
||||
@@ -698,23 +710,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while e_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
e_pad -= 1
|
||||
if e_sp == 2:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif e_sp == 1 and show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif e_sp == 1 and space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
ei_c: t.CInt = 0
|
||||
while ei_c < 3 and write_count < size - 1:
|
||||
ec: t.CInt = 0
|
||||
@@ -738,14 +750,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
ec -= 32
|
||||
ptr[0] = t.CChar(ec)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
ei_c += 1
|
||||
if left_align and width > e_total_len:
|
||||
e_pad = width - e_total_len
|
||||
while e_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
e_pad -= 1
|
||||
fmt += 1
|
||||
continue
|
||||
@@ -753,18 +765,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fv = 0.0 - fv
|
||||
elif show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
exp10: t.CInt = 0
|
||||
if fv != 0.0:
|
||||
while fv >= 10.0:
|
||||
@@ -799,24 +811,24 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > e_total:
|
||||
pad_count = width - e_total
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if write_count < size - 1:
|
||||
ptr[0] = t.CChar(int_digit + 48)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if precision > 0:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 46
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fi: t.CInt = 0
|
||||
while fi < precision and fi < TEMP_BUF_SIZE - 1:
|
||||
temp[fi] = t.CChar(frac_p % 10 + 48)
|
||||
@@ -829,20 +841,20 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
fi -= 1
|
||||
ptr[0] = temp[fi]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif alt_form:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 46
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 101 if e_upper == 0 else 69
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45 if exp10 < 0 else 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
exp_abs: t.CUInt64T = t.CUInt64T(exp10) if exp10 >= 0 else t.CUInt64T(0 - exp10)
|
||||
ei: t.CInt = 0
|
||||
if exp_abs == 0:
|
||||
@@ -861,13 +873,13 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
ei -= 1
|
||||
ptr[0] = temp[ei]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > e_total:
|
||||
pad_count = width - e_total
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 103 or c.Deref(fmt) == 71:
|
||||
if precision < 0: precision = 6
|
||||
@@ -889,23 +901,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while g_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
g_pad -= 1
|
||||
if g_sp == 2:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif g_sp == 1 and show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif g_sp == 1 and space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
gi_c: t.CInt = 0
|
||||
while gi_c < 3 and write_count < size - 1:
|
||||
gc: t.CInt = 0
|
||||
@@ -929,14 +941,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
gc -= 32
|
||||
ptr[0] = t.CChar(gc)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
gi_c += 1
|
||||
if left_align and width > g_total_len:
|
||||
g_pad = width - g_total_len
|
||||
while g_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
g_pad -= 1
|
||||
fmt += 1
|
||||
continue
|
||||
@@ -944,18 +956,18 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fv = 0.0 - fv
|
||||
elif show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fv_orig: t.CDouble = fv
|
||||
exp10: t.CInt = 0
|
||||
if fv != 0.0:
|
||||
@@ -1064,30 +1076,30 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
if pad_zero and width > g_total:
|
||||
pad_count = width - g_total
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
gi: t.CInt = 0
|
||||
while gi < g_len and write_count < size - 1:
|
||||
ptr[0] = temp[gi]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
gi += 1
|
||||
if g_use_e:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 101 if g_upper == 0 else 69
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45 if exp10 < 0 else 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
exp_abs: t.CUInt64T = t.CUInt64T(exp10) if exp10 >= 0 else t.CUInt64T(0 - exp10)
|
||||
ei: t.CInt = 0
|
||||
if exp_abs == 0:
|
||||
@@ -1106,13 +1118,13 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
ei -= 1
|
||||
ptr[0] = temp[ei]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > g_total:
|
||||
pad_count = width - g_total
|
||||
while pad_count > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
pad_count -= 1
|
||||
elif c.Deref(fmt) == 97 or c.Deref(fmt) == 65:
|
||||
a_upper: t.CInt = 1 if c.Deref(fmt) == 65 else 0
|
||||
@@ -1132,23 +1144,23 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while a_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_pad -= 1
|
||||
if a_sp == 2:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif a_sp == 1 and show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif a_sp == 1 and space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
ai_c: t.CInt = 0
|
||||
while ai_c < 3 and write_count < size - 1:
|
||||
ac: t.CInt = 0
|
||||
@@ -1172,14 +1184,14 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
ac -= 32
|
||||
ptr[0] = t.CChar(ac)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
ai_c += 1
|
||||
if left_align and width > a_total_len:
|
||||
a_pad = width - a_total_len
|
||||
while a_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_pad -= 1
|
||||
fmt += 1
|
||||
continue
|
||||
@@ -1255,55 +1267,55 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
while a_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_pad -= 1
|
||||
if a_neg:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 45
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif show_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
elif space_sign:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if pad_zero and width > a_content_len:
|
||||
a_pad = width - a_content_len
|
||||
while a_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_pad -= 1
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 48
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
if a_upper:
|
||||
ptr[0] = 88
|
||||
else:
|
||||
ptr[0] = 120
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
ptr[0] = t.CChar(a_leading + 48)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if a_has_dot:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 46
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_hj: t.CInt = 0
|
||||
while a_hj < a_hd_count and write_count < size - 1:
|
||||
ptr[0] = temp[a_hj]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_hj += 1
|
||||
if write_count < size - 1:
|
||||
if a_upper:
|
||||
@@ -1311,26 +1323,26 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
else:
|
||||
ptr[0] = 112
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if write_count < size - 1:
|
||||
if a_esign:
|
||||
ptr[0] = 45
|
||||
else:
|
||||
ptr[0] = 43
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_ek: t.CInt = a_ecount
|
||||
while a_ek > 0 and write_count < size - 1:
|
||||
a_ek -= 1
|
||||
ptr[0] = temp[60 + a_ek]
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
if left_align and width > a_content_len:
|
||||
a_pad = width - a_content_len
|
||||
while a_pad > 0 and write_count < size - 1:
|
||||
ptr[0] = 32
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
a_pad -= 1
|
||||
elif c.Deref(fmt) == 110:
|
||||
if is_long_long or is_long:
|
||||
@@ -1353,12 +1365,12 @@ def vsnprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, ap: t.CChar | t.C
|
||||
if write_count < size - 1:
|
||||
ptr[0] = 37
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
else:
|
||||
if write_count < size - 1:
|
||||
ptr[0] = c.Deref(fmt)
|
||||
write_count += 1
|
||||
ptr += 1
|
||||
ptr += _step
|
||||
fmt += 1
|
||||
ptr[0] = 0
|
||||
return write_count
|
||||
|
||||
Reference in New Issue
Block a user