-int tarval_snprintf(char *buf, size_t len, tarval *tv)
-{
- static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
-
- const char *str;
- char tv_buf[100];
- const tarval_mode_info *mode_info;
- const char *prefix, *suffix;
-
- ANNOUNCE();
-
- mode_info = tv->mode->tv_priv;
- if (! mode_info)
- mode_info = &default_info;
- prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
- suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
-
- switch (get_mode_sort(tv->mode))
- {
- case irms_int_number:
- case irms_character:
- switch (mode_info->mode_output) {
-
- case TVO_DECIMAL:
- str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
- break;
-
- case TVO_OCTAL:
- str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
- break;
-
- case TVO_HEX:
- case TVO_NATIVE:
- default:
- str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
- break;
- }
- return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
-
- case irms_float_number:
- switch (mode_info->mode_output) {
- case TVO_HEX:
- return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_PACKED), suffix);
-
- case TVO_HEXFLOAT:
- return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_HEX), suffix);
-
- case TVO_FLOAT:
- case TVO_NATIVE:
- default:
- return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_DEC), suffix);
- }
- break;
-
- case irms_reference:
- if (tv == tarval_P_void) return snprintf(buf, len, "NULL");
- if (tv->value != NULL)
- if (tarval_is_entity(tv)) {
- if (get_entity_peculiarity((entity *)tv->value) != peculiarity_description)
- return snprintf(buf, len, "%s%s%s", prefix, get_entity_ld_name((entity *)tv->value), suffix);
- else {
- if (mode_info->mode_output == TVO_NATIVE)
- return snprintf(buf, len, "NULL");
- else
- return snprintf(buf, len, "0");
- }
- }
- else {
- if (len > tv->length) {
- memcpy(buf, tv->value, tv->length);
- buf[tv->length] = '\0';
- }
- else {
- /* truncated */
- memcpy(buf, tv->value, len-1);
- buf[len-1] = '\0';
- }
- return tv->length;
+int tarval_snprintf(char *buf, size_t len, tarval *tv) {
+ static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
+
+ const char *str;
+ char tv_buf[100];
+ const tarval_mode_info *mode_info;
+ const char *prefix, *suffix;
+
+ mode_info = tv->mode->tv_priv;
+ if (! mode_info)
+ mode_info = &default_info;
+ prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
+ suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
+
+ switch (get_mode_sort(tv->mode)) {
+ case irms_reference:
+ if (tv == tv->mode->null) return snprintf(buf, len, "NULL");
+ /* fall through */
+ case irms_int_number:
+ switch (mode_info->mode_output) {
+
+ case TVO_DECIMAL:
+ str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC, mode_is_signed(tv->mode));
+ break;
+
+ case TVO_OCTAL:
+ str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT, 0);
+ break;
+
+ case TVO_HEX:
+ case TVO_NATIVE:
+ default:
+ str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX, 0);
+ break;
+ }
+ return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
+
+ case irms_float_number:
+ switch (mode_info->mode_output) {
+ case TVO_HEX:
+ return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_PACKED), suffix);
+
+ case TVO_HEXFLOAT:
+ return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_HEX), suffix);
+
+ case TVO_FLOAT:
+ case TVO_NATIVE:
+ default:
+ return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_DEC), suffix);
+ }
+ break;
+
+ case irms_internal_boolean:
+ switch (mode_info->mode_output) {
+
+ case TVO_DECIMAL:
+ case TVO_OCTAL:
+ case TVO_HEX:
+ case TVO_BINARY:
+ return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
+
+ case TVO_NATIVE:
+ default:
+ return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
+ }
+
+ case irms_control_flow:
+ case irms_memory:
+ case irms_auxiliary:
+ if (tv == tarval_bad)
+ return snprintf(buf, len, "<TV_BAD>");
+ if (tv == tarval_undefined)
+ return snprintf(buf, len, "<TV_UNDEF>");
+ if (tv == tarval_unreachable)
+ return snprintf(buf, len, "<TV_UNREACHABLE>");
+ if (tv == tarval_reachable)
+ return snprintf(buf, len, "<TV_REACHABLE>");
+ return snprintf(buf, len, "<TV_??""?>");