void print_data(string tag, string type, int *dims) { string fmt; size_t dlen; char buf[BUFLEN]; /* danger: buffer overflow */ byte *dat, *dp; bool Qprint; Qprint = !(*testtag && streq(tag,testtag)==0); /* if only print testtag... */ fmt = find_fmt(type); dlen = get_dlen(instr, tag); dat = (byte*) allocate(dlen); get_data_sub(instr, tag, type, dat, dims, FALSE); if (streq(type, CharType) && Qprint) (void) outstr(dims != NULL ? "\"" : "\'"); for (dp = dat; dp < dat + dlen; ) { /* loop over data array */ if (streq(type, AnyType)) { /* output generic data? */ sprintf(buf, fmt, *((byte *) dp)); dp += sizeof(byte); } else if (streq(type, CharType)) { /* output readable chars? */ sprintf(buf, fmt, *((char *) dp)); dp += sizeof(char); } else if (streq(type, ByteType)) { /* output bytes of data? */ sprintf(buf, fmt, *((byte *) dp)); dp += sizeof(byte); } else if (streq(type, ShortType)) { /* output short integers? */ sprintf(buf, fmt, *((short *) dp)); dp += sizeof(short); } else if (streq(type, IntType)) { /* output standard ints? */ sprintf(buf, fmt, *((int *) dp)); dp += sizeof(int); } else if (streq(type, LongType)) { /* output long integers? */ sprintf(buf, fmt, *((long *) dp)); dp += sizeof(long); } else if (streq(type, HalfpType)) { /* output short int? */ sprintf(buf, fmt, *((short *) dp)); dp += sizeof(short); } else if (streq(type, FloatType)) { /* output floating point? */ sprintf(buf, fmt, *((float *) dp)); dp += sizeof(float); } else if (streq(type, DoubleType)) { /* output double numbers? */ sprintf(buf, fmt, *((double *) dp)); dp += sizeof(double); } else error("print_data: type %s unknown\n", type); if (Qprint) if (! outstr(buf)) break; } if (streq(type, CharType) && Qprint) (void) outstr(dims != NULL ? "\"" : "\'"); if (xml && Qprint) { sprintf(buf," </%s>",tag); outstr(buf); } free((char *)dat); }
void print_data(string tag, string type, int *dims) { int dlen; byte *dat, *dp; char *tp, buf[128]; string pad, fmt; dlen = get_length(instr, tag); dat = (byte *) allocate(dlen); get_data_sub(instr, tag, type, dims, dat, NULL); if (streq(type, CharType) && dims != NULL && dims[1] == 0) { (void) outstr(" \""); pad = ""; } else pad = " "; tp = type; /* start type string scan */ for (dp = dat; dp < dat + dlen; ) { /* loop over data array */ if (! outstr(pad)) /* print pad before data */ break; fmt = type_fmt(tp, !maxprec); /* get proper format */ if (tp[0] == AnyType[0]) { /* output generic data? */ sprintf(buf, fmt, *((byte *) dp)); dp += sizeof(byte); } else if (tp[0] == CharType[0]) { /* output readable chars? */ sprintf(buf, fmt, *((char *) dp)); dp += sizeof(char); } else if (tp[0] == ByteType[0]) { /* output bytes of data? */ sprintf(buf, fmt, *((byte *) dp)); dp += sizeof(byte); } else if (tp[0] == ShortType[0]) { /* output short integers? */ sprintf(buf, fmt, *((short *) dp)); dp += sizeof(short); } else if (tp[0] == IntType[0]) { /* output standard ints? */ sprintf(buf, fmt, *((int *) dp)); dp += sizeof(int); } else if (tp[0] == LongType[0]) { /* output long integers? */ sprintf(buf, fmt, *((long *) dp)); dp += sizeof(long); } else if (tp[0] == FloatType[0]) { /* output floating point? */ sprintf(buf, fmt, *((float *) dp)); dp += sizeof(float); } else if (tp[0] == DoubleType[0]) { /* output double numbers? */ sprintf(buf, fmt, *((double *) dp)); dp += sizeof(double); } else error("print_data: type %s unknown\n", type); if (! outstr(buf)) break; tp = (*(tp + 1) != (char) NULL ? tp + 1 : type); } if (streq(type, CharType) && dims != NULL && dims[1] == 0) (void) outstr("\""); free(dat); }