Commit d48d97e1 authored by Pekka Pessi's avatar Pekka Pessi

su_tag.h: added size_tag_class and usize_tag_class.

darcs-hash:20061205171153-65a35-8b5b8266f91b77273bf53110d04f0342a29ac4e8.gz
parent c2954bdf
......@@ -176,6 +176,10 @@ su_inline tag_value_t tag_int_v(int v) { return (tag_value_t)v; }
su_inline tag_value_t tag_int_vr(int *vp) { return (tag_value_t)vp; }
su_inline tag_value_t tag_uint_v(unsigned v) { return (tag_value_t)v; }
su_inline tag_value_t tag_uint_vr(unsigned *vp) { return (tag_value_t)vp; }
su_inline tag_value_t tag_usize_v(usize_t v) { return (tag_value_t)v; }
su_inline tag_value_t tag_usize_vr(usize_t *vp) { return (tag_value_t)vp; }
su_inline tag_value_t tag_size_v(size_t v) { return (tag_value_t)v; }
su_inline tag_value_t tag_size_vr(size_t *vp) { return (tag_value_t)vp; }
su_inline tag_value_t tag_bool_v(int v) { return v != 0; }
su_inline tag_value_t tag_bool_vr(int *vp) { return (tag_value_t)vp; }
su_inline tag_value_t tag_ptr_v(void *v) { return (tag_value_t)v; }
......
......@@ -53,6 +53,8 @@ SOFIA_BEGIN_DECLS
#define INTTAG_TYPEDEF(t) TAG_TYPEDEF(t, int)
#define UINTTAG_TYPEDEF(t) TAG_TYPEDEF(t, uint)
#define USIZETAG_TYPEDEF(t) TAG_TYPEDEF(t, usize)
#define SIZETAG_TYPEDEF(t) TAG_TYPEDEF(t, size)
#define BOOLTAG_TYPEDEF(t) TAG_TYPEDEF(t, bool)
#define PTRTAG_TYPEDEF(t) TAG_TYPEDEF(t, ptr)
#define SOCKETTAG_TYPEDEF(t) TAG_TYPEDEF(t, socket)
......@@ -81,6 +83,8 @@ struct tag_class_s {
SOFIAPUBVAR tag_class_t end_tag_class[];
SOFIAPUBVAR tag_class_t int_tag_class[];
SOFIAPUBVAR tag_class_t uint_tag_class[];
SOFIAPUBVAR tag_class_t usize_tag_class[];
SOFIAPUBVAR tag_class_t size_tag_class[];
SOFIAPUBVAR tag_class_t bool_tag_class[];
SOFIAPUBVAR tag_class_t ptr_tag_class[];
SOFIAPUBVAR tag_class_t socket_tag_class[];
......
......@@ -39,6 +39,7 @@
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <limits.h>
#if defined(va_copy)
/* Xyzzy */
......@@ -1257,6 +1258,109 @@ tag_class_t uint_tag_class[1] =
}};
/* ====================================================================== */
/* size tag - pass size_t value @NEW_1_12_5 */
static
int t_size_snprintf(tagi_t const *t, char b[], size_t size)
{
return snprintf(b, size, MOD_ZU, (size_t)t->t_value);
}
static
int t_size_ref_set(tag_type_t tt, void *ref, tagi_t const value[])
{
*(size_t *)ref = (size_t)value->t_value;
return 1;
}
static
int t_size_scan(tag_type_t tt, su_home_t *home,
char const *s,
tag_value_t *return_value)
{
unsigned longlong value;
char *rest;
value = strtoull(s, &rest, 0);
if (s != rest && value <= SIZE_MAX) {
*return_value = (tag_value_t)value;
return 1;
}
else {
*return_value = (tag_value_t)0;
return -1;
}
}
/** Tag class for tags with size_t value. @NEW_1_12_5 */
tag_class_t size_tag_class[1] =
{{
sizeof(int_tag_class),
/* tc_next */ NULL,
/* tc_len */ NULL,
/* tc_move */ NULL,
/* tc_xtra */ NULL,
/* tc_dup */ NULL,
/* tc_free */ NULL,
/* tc_find */ NULL,
/* tc_snprintf */ t_size_snprintf,
/* tc_filter */ NULL,
/* tc_ref_set */ t_size_ref_set,
/* tc_scan */ t_size_scan,
}};
/* ====================================================================== */
/* usize tag - pass usize_t value */
static
int t_usize_ref_set(tag_type_t tt, void *ref, tagi_t const value[])
{
*(usize_t *)ref = (usize_t)value->t_value;
return 1;
}
static
int t_usize_scan(tag_type_t tt, su_home_t *home,
char const *s,
tag_value_t *return_value)
{
unsigned longlong value;
char *rest;
value = strtoull(s, &rest, 0);
if (s != rest && value <= USIZE_MAX) {
*return_value = (tag_value_t)value;
return 1;
}
else {
*return_value = (tag_value_t)0;
return -1;
}
}
/** Tag class for tags with usize_t value. @NEW_1_12_5 */
tag_class_t usize_tag_class[1] =
{{
sizeof(int_tag_class),
/* tc_next */ NULL,
/* tc_len */ NULL,
/* tc_move */ NULL,
/* tc_xtra */ NULL,
/* tc_dup */ NULL,
/* tc_free */ NULL,
/* tc_find */ NULL,
/* tc_snprintf */ t_size_snprintf,
/* tc_filter */ NULL,
/* tc_ref_set */ t_usize_ref_set,
/* tc_scan */ t_usize_scan,
}};
/* ====================================================================== */
/* bool tag - pass boolean value */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment