static int insert_var(RStr *output, FmtInfo *fi, int pn) { switch(fi->cvt_spec) { case 'm': expanding_strcat(output,tf_mipname()); /* calling module */ break; case 't': expanding_strcat(output,tf_strgettime()); /* current simulator time */ break; case '%': expanding_strcat(output,"%"); /* percent sign */ break; default: /* don't need this check if checktf errors */ if(strchr(has_nfld,fi->cvt_spec)) { char *text; /* translate x's to h's for hex; NC segfaults if you don't */ if(fi->cvt_spec=='x') fi->cvt_spec='h'; if(fi->cvt_spec=='X') fi->cvt_spec='H'; text= format_val(fi, fi->cvt_spec=='s' ? tf_getcstringp(pn) : tf_strgetp(pn,fi->cvt_spec)); expanding_strcat(output,text); free(text); pn++; } } return pn; }
/* * format function */ char *format(char *mipname) { int num_args, cur_arg, len, i, j; char *fmt_str, *ptr, c; num_args = tf_nump(); cur_arg = 3; len = sprintf (format_buffer, " "); fmt_str = tf_getcstringp(ARG2); ptr = format_buffer + len; while (1) { c = *fmt_str++; if (c == 0) break; if (c == '%') { c = *fmt_str++; switch (c) { case 'b': len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'b')); ptr = ptr + len; cur_arg++; break; case 'o': len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'o')); ptr = ptr + len; cur_arg++; break; case 'd': len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'd')); ptr = ptr + len; cur_arg++; break; case 'h': len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'h')); ptr = ptr + len; cur_arg++; break; case 'e': len = sprintf (ptr, "%e", tf_getrealp(cur_arg)); ptr = ptr + len; cur_arg++; break; case 'f': len = sprintf (ptr, "%e", tf_getrealp(cur_arg)); ptr = ptr + len; cur_arg++; break; case 't': len = sprintf (ptr, "%d", tf_gettime()); ptr = ptr + len; break; case 's': len = sprintf (ptr, "%s", tf_strgetp(cur_arg, 'e')); ptr = ptr + len; cur_arg++; break; case 'm': len = sprintf (ptr, "%s", mipname); ptr = ptr + len; break; case '%': *ptr++ = '%'; break; } } else { *ptr++ = c; } } *ptr++ = '\0'; return format_buffer; }