Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support unsigned char #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions include/qrintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,28 +443,28 @@ static inline qrintf_chk_t _qrintf_chk_long_long_core(qrintf_chk_t ctx, int fill
return ctx;
}

static inline qrintf_nck_t _qrintf_nck_hhd(qrintf_nck_t ctx, char v)
static inline qrintf_nck_t _qrintf_nck_hhd(qrintf_nck_t ctx, signed char v)
{
unsigned char val = v >= 0 ? v : -(unsigned char)v;
int sign = v < 0;
if (sizeof(char) < sizeof(long long)) {
if (sizeof(signed char) < sizeof(long long)) {
return _qrintf_nck_long_core(ctx, 0, 0, (unsigned long)val, sign);
}
else {
assert(sizeof(char) == sizeof(long long));
assert(sizeof(signed char) == sizeof(long long));
return _qrintf_nck_long_long_core(ctx, 0, 0, (unsigned long long)val, sign);
}
}

static inline qrintf_nck_t _qrintf_nck_width_hhd(qrintf_nck_t ctx, int fill_ch, int width, char v)
static inline qrintf_nck_t _qrintf_nck_width_hhd(qrintf_nck_t ctx, int fill_ch, int width, signed char v)
{
unsigned char val = v >= 0 ? v : -(unsigned char)v;
int sign = v < 0;
if (sizeof(char) < sizeof(long long)) {
if (sizeof(signed char) < sizeof(long long)) {
return _qrintf_nck_long_core(ctx, fill_ch, width, (unsigned long)val, sign);
}
else {
assert(sizeof(char) == sizeof(long long));
assert(sizeof(signed char) == sizeof(long long));
return _qrintf_nck_long_long_core(ctx, fill_ch, width, (unsigned long long)val, sign);
}
}
Expand Down Expand Up @@ -993,28 +993,28 @@ static inline qrintf_nck_t _qrintf_nck_width_zx(qrintf_nck_t ctx, int fill_ch, i
return ctx;
}

static inline qrintf_chk_t _qrintf_chk_hhd(qrintf_chk_t ctx, char v)
static inline qrintf_chk_t _qrintf_chk_hhd(qrintf_chk_t ctx, signed char v)
{
unsigned char val = v >= 0 ? v : -(unsigned char)v;
int sign = v < 0;
if (sizeof(char) < sizeof(long long)) {
if (sizeof(signed char) < sizeof(long long)) {
return _qrintf_chk_long_core(ctx, 0, 0, (unsigned long)val, sign);
}
else {
assert(sizeof(char) == sizeof(long long));
assert(sizeof(signed char) == sizeof(long long));
return _qrintf_chk_long_long_core(ctx, 0, 0, (unsigned long long)val, sign);
}
}

static inline qrintf_chk_t _qrintf_chk_width_hhd(qrintf_chk_t ctx, int fill_ch, int width, char v)
static inline qrintf_chk_t _qrintf_chk_width_hhd(qrintf_chk_t ctx, int fill_ch, int width, signed char v)
{
unsigned char val = v >= 0 ? v : -(unsigned char)v;
int sign = v < 0;
if (sizeof(char) < sizeof(long long)) {
if (sizeof(signed char) < sizeof(long long)) {
return _qrintf_chk_long_core(ctx, fill_ch, width, (unsigned long)val, sign);
}
else {
assert(sizeof(char) == sizeof(long long));
assert(sizeof(signed char) == sizeof(long long));
return _qrintf_chk_long_long_core(ctx, fill_ch, width, (unsigned long long)val, sign);
}
}
Expand Down
8 changes: 5 additions & 3 deletions misc/gen-qrintf.h.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
sub build_d {
return build_mt(template => << 'EOT', escape_func => undef)->(@_);
? my ($check, $type, $suffix) = @_;
? my $unsigned_type = $type;
? $unsigned_type =~ s/^(signed )?/unsigned /g;
static inline qrintf_<?= $check ?>_t _qrintf_<?= $check ?>_<?= $suffix ?>(qrintf_<?= $check ?>_t ctx, <?= $type ?> v)
{
unsigned <?= $type ?> val = v >= 0 ? v : -(unsigned <?= $type ?>)v;
<?= $unsigned_type ?> val = v >= 0 ? v : -(<?= $unsigned_type ?>)v;
int sign = v < 0;
if (sizeof(<?= $type ?>) < sizeof(long long)) {
return _qrintf_<?= $check ?>_long_core(ctx, 0, 0, (unsigned long)val, sign);
Expand All @@ -42,7 +44,7 @@ sub build_d {

static inline qrintf_<?= $check ?>_t _qrintf_<?= $check ?>_width_<?= $suffix ?>(qrintf_<?= $check ?>_t ctx, int fill_ch, int width, <?= $type ?> v)
{
unsigned <?= $type ?> val = v >= 0 ? v : -(unsigned <?= $type ?>)v;
<?= $unsigned_type ?> val = v >= 0 ? v : -(<?= $unsigned_type ?>)v;
int sign = v < 0;
if (sizeof(<?= $type ?>) < sizeof(long long)) {
return _qrintf_<?= $check ?>_long_core(ctx, fill_ch, width, (unsigned long)val, sign);
Expand Down Expand Up @@ -564,7 +566,7 @@ sub build_x {
}

? for my $check (qw(nck chk)) {
<?= $build_d->($check, "char", "hhd") ?>
<?= $build_d->($check, "signed char", "hhd") ?>
<?= $build_d->($check, "short", "hd") ?>
<?= $build_d->($check, "int", "d",) ?>
<?= $build_d->($check, "long", "ld") ?>
Expand Down