From: Adam Dickmeiss Date: Tue, 24 Sep 2013 13:05:26 +0000 (+0200) Subject: yaz-client: display MAB records YAZ-689 X-Git-Tag: v4.2.69~14 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=73d18d08ae7ac42589508fb6f8db854087a3de78;p=yaz-moved-to-github.git yaz-client: display MAB records YAZ-689 Thanks for Heiko Jansen for this patch. --- diff --git a/client/client.c b/client/client.c index a115f2b..18c763a 100644 --- a/client/client.c +++ b/client/client.c @@ -842,6 +842,50 @@ static void print_record(const char *buf, size_t len) printf("\n"); } +static void print_mab_record(const char *buf, size_t len) +{ + size_t i; + size_t last_linebreak = 0; + size_t last_subfield = 0; + for (i = 0; i < len; i++) + { + // line break after header + if ( i == 24 ) + { + printf("\n"); + last_linebreak = i - 1; + } + + // space between field and content + if ( i > 24 && i - last_linebreak == 5 ) + printf(" "); + + // space after subfield + if ( last_subfield != 0 && i - last_subfield == 2 ) + printf(" "); + + if ((buf[i] <= 126 && buf[i] >= 32) || strchr("\n\r\t\f", buf[i])) + printf("%c", buf[i]); + else if ( buf[i] == 29 ) // record separator + printf("\n"); + else if ( buf[i] == 30 ) // field separator + { + printf("\n"); + last_linebreak = i; + } + else if ( buf[i] == 31 ) // subfield + { + // space before subfields; except first one + if ( i > 24 && i - last_linebreak > 5 ) + printf(" "); + printf("$"); + last_subfield = i; + } + else + printf("\\X%02X", ((const unsigned char *)buf)[i]); + } +} + static void print_xml_record(const char *buf, size_t len) { int has_printed = 0; @@ -930,7 +974,7 @@ static void display_record(Z_External *r) } else if (!oid_oidcmp(oid, yaz_oid_recsyn_mab)) { - print_record(octet_buf, octet_len); + print_mab_record(octet_buf, octet_len); } else {