char* format_string(char* id, float args[], int n, int* new_size) {
	int total_size = 0;
	total_size += 1 + strlen(id);

	char new_args[6][4];
	static char ans[TOTAL_RESPONSE_SIZE];
	strcat(ans, id);
	strcat(ans, (char*) ":");

	int i = 0;
	float item;
	char dummy[3 + MAX_RESPONSE_DEPTH];
	for(; i < n; i++) {
		item = args[i];
		float_string(item, dummy, MAX_RESPONSE_DEPTH);
		total_size += 1 + strlen(dummy);
		strcat(ans, dummy);
		if(i == n - 1)
			strcat(ans, (char*) ";");
		else
			strcat(ans, (char*) ":");
	}

	total_size += 1;
	*new_size = total_size;

	return ans;
}
Example #2
0
/* actual test that check if the float represented by float_string(m, d) is
 * output as the same string by CTPL */
static gboolean
test_float (glong m,
            glong d)
{
  gchar    *ctpl_f;
  gchar    *real_f;
  gboolean  ret = FALSE;
  gchar    *env;
  GError   *err = NULL;
  
  real_f = float_string (m, d);
  env = g_strconcat ("float = ", real_f, ";", NULL);
  ctpl_f = ctpltest_parse_string ("{float}", env, &err);
  if (! ctpl_f) {
    g_warning ("Failed to parse test template: %s", err->message);
    g_error_free (err);
  } else {
    /* strip extra .0 if present */
    rstripstr (real_f, ".0");
    ret = strcmp (real_f, ctpl_f) == 0;
    
    if (! ret) {
      fprintf (stderr, "** %s expected, got %s\n", real_f, ctpl_f);
    }
#ifdef LOGFILE
    {
      static glong n = 0;
      
      if (n == 100000) {
        fprintf (LOGFILE, "%s =\n%s\n", real_f, ctpl_f);
        n = 0;
      } else {
        n++;
      }
    }
#endif
  }
  g_free (env);
  g_free (ctpl_f);
  g_free (real_f);
  
  return ret;
}