summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r--tools/lib/h5tools_str.c97
1 files changed, 46 insertions, 51 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c
index 205dffe..299f5bf 100644
--- a/tools/lib/h5tools_str.c
+++ b/tools/lib/h5tools_str.c
@@ -610,6 +610,32 @@ h5tools_print_char(h5tools_str_t *str, const h5tool_format_t *info, char ch)
}
}
}
+void
+h5tools_str_indent(h5tools_str_t *str, const h5tool_format_t *info,
+ h5tools_context_t *ctx)
+{
+ int i, indentlevel = 0;
+
+ /* Write new prefix */
+ if (ctx->indent_level >= 0) {
+ indentlevel = ctx->indent_level;
+ }
+ else {
+ /*
+ * This is because sometimes we don't print out all the header
+ * info for the data (like the tattr-2.ddl example). If that happens
+ * the ctx->indent_level is negative so we need to skip the above and
+ * just print out the default indent levels.
+ */
+ indentlevel = ctx->default_indent_level;
+ }
+
+ for (i = 0; i < indentlevel; i++) {
+ h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
+ }
+
+// ctx->need_prefix = 0;
+}
/*-------------------------------------------------------------------------
* Function: h5tools_str_sprint
@@ -951,25 +977,17 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
nmembs = H5Tget_nmembers(type);
h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{"));
+ ctx->indent_level++;
+
for (j = 0; j < nmembs; j++) {
if (j)
- h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", " OPTIONAL_LINE_BREAK));
-
- /* RPM 2000-10-31
- * If the previous character is a line-feed (which is true when
- * h5dump is running) then insert some white space for
- * indentation. Be warned that column number calculations will be
- * incorrect and that object indices at the beginning of the line
- * will be missing (h5dump doesn't display them anyway). */
- if (ctx->indent_level >= 0 && str->len && str->s[str->len - 1] == '\n') {
- int x;
-
- h5tools_str_append(str, OPT(info->line_pre, ""), "");
-
- for (x = 0; x < ctx->indent_level + 1; x++)
- h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
- }
+ h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", "OPTIONAL_LINE_BREAK));
+ else
+ h5tools_str_append(str, "%s", OPT(info->cmpd_end, ""));
+ if(info->arr_linebreak)
+ h5tools_str_indent(str, info, ctx);
+
/* The name */
name = H5Tget_member_name(type, j);
h5tools_str_append(str, OPT(info->cmpd_name, ""), name);
@@ -979,31 +997,19 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
offset = H5Tget_member_offset(type, j);
memb = H5Tget_member_type(type, j);
- ctx->indent_level++;
h5tools_str_sprint(str, info, container, memb, cp_vp + offset, ctx);
- ctx->indent_level--;
H5Tclose(memb);
}
+ ctx->indent_level--;
- /* RPM 2000-10-31
- * If the previous character is a line feed (which is true when
- * h5dump is running) then insert some white space for indentation.
- * Be warned that column number calculations will be incorrect and
- * that object indices at the beginning of the line will be missing
- * (h5dump doesn't display them anyway). */
- h5tools_str_append(str, "%s", OPT(info->cmpd_end, ""));
-
- if (ctx->indent_level >= 0 && str->len && str->s[str->len - 1] == '\n') {
- int x;
-
- h5tools_str_append(str, OPT(info->line_pre, ""), "");
- for (x = 0; x < ctx->indent_level; x++)
- h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
+ if(info->arr_linebreak) {
+ h5tools_str_append(str, "%s", OPT(info->cmpd_end, ""));
+ h5tools_str_indent(str, info, ctx);
}
-
h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}"));
+
}
else if (H5Tget_class(type) == H5T_ENUM) {
char enum_name[1024];
@@ -1084,7 +1090,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
else if (H5Tget_class(type) == H5T_ARRAY) {
int k, ndims;
hsize_t i, dims[H5S_MAX_RANK], temp_nelmts;
- static int is_next_arry_elmt=0;
+ static int is_next_arry_elmt = 0;
/* Get the array's base datatype for each element */
memb = H5Tget_super(type);
@@ -1103,6 +1109,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
/* Print the opening bracket */
h5tools_str_append(str, "%s", OPT(info->arr_pre, "["));
+ ctx->indent_level++;
+
for (i = 0; i < nelmts; i++) {
if (i)
h5tools_str_append(str, "%s", OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK));
@@ -1111,14 +1119,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
int x;
h5tools_str_append(str, "%s", "\n");
+ h5tools_str_indent(str, info, ctx);
- /* need to indent some more here*/
- if (ctx->indent_level >= 0)
- if (!info->pindex)
- h5tools_str_append(str, "%s", OPT(info->line_pre, ""));
-
- for (x = 0; x < ctx->indent_level + 1; x++)
- h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
} /* end if */
else if (i && info->arr_sep) {
/* if next element begin, add next line with indent */
@@ -1127,13 +1129,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
is_next_arry_elmt = 0;
h5tools_str_append(str, "%s", "\n ");
+ h5tools_str_indent(str, info, ctx);
- if (ctx->indent_level >= 0)
- if (!info->pindex)
- h5tools_str_append(str, "%s", OPT(info->line_pre, ""));
-
- for (x = 0; x < ctx->indent_level + 1; x++)
- h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
}
/* otherwise just add space */
else
@@ -1141,15 +1138,13 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai
} /* end else if */
- ctx->indent_level++;
-
/* Dump values in an array element */
is_next_arry_elmt = 0; /* dump all values in the array element, so turn it off */
h5tools_str_sprint(str, info, container, memb, cp_vp + i * size, ctx);
-
- ctx->indent_level--;
} /* end for */
+ ctx->indent_level--;
+
/* Print the closing bracket */
h5tools_str_append(str, "%s", OPT(info->arr_suf, "]"));
is_next_arry_elmt = 1; /* set for begining of next array element */