Exemple #1
0
void
array_test (void)
{
  int n = 1;
  array_t *a = array_from_str ("0x1xx0x1");
  array_t *b = array_from_str ("01xx10x1");
  array_isect (a, b, n, a);
  char *s = array_to_str (a, n, false);
  print_safe (s);
  free (s);
  free (a);
  free (b);

  a = array_from_str ("01xx0011,xxxx1011");
  s = array_to_str (a, 2, false);
  print_safe (s);
  free (s);
  free (a);

  a = array_from_str ("11000001,10001000,00011111,001101xx");
  s = array_to_str (a, 4, true);
  print_safe (s);
  free (s);
  free (a);
}
Exemple #2
0
int
main (void)
{
  //array_test ();
  array_t *a = array_from_str ("1000xxxx,11110000");
  char *s = array_to_str (a, 2, false);
  printf ("Before: %s\n", s);
  free (s);
  array_shift_left (a, 2, 4, 8, BIT_X);
  s = array_to_str (a, 2, false);
  printf ("After: %s\n", s);
  free (s);
  array_free (a);
  //hs_test ();
  return 0;
}
Exemple #3
0
Fichier : tf.c Projet : NetSys/sts
static void
rule_print (const struct rule *r, const struct tf *tf)
{
  printf ("Rule %u\nIn: ", r->idx);
  print_ports (r->in, tf);
  printf ("Out: ");
  print_ports (r->out, tf);
  if (r->match) {
    char *match = array_to_str (DATA_ARR (r->match), data_arrs_len, true);
    printf ("Match: %s\n", match);
    free (match);
    if (r->mask) {
      char *mask = array_to_str (DATA_ARR (r->mask), data_arrs_len, false);
      char *rewrite = array_to_str (DATA_ARR (r->rewrite), data_arrs_len, false);
      printf ("Mask: %s\nRewrite: %s\n", mask, rewrite);
      free (mask);
      free (rewrite);
    }
    //printf ("Deps:\n");
    //deps_print (r->deps);
  }
  printf ("-----\n");
}
Exemple #4
0
Fichier : hs.c Projet : NetSys/sts
static char *
vec_to_str (const struct hs_vec *v, int len, char *res)
{
  if (!v->diff) *res++ = '(';
  for (int i = 0; i < v->used; i++) {
    bool diff = v->diff && v->diff[i].used;
    if (i) res += sprintf (res, " + ");
    char *s = array_to_str (v->elems[i], len, true);
    if (diff) *res++ = '(';
    res += sprintf (res, "%s", s);
    free (s);
    if (diff) {
      res += sprintf (res, " - ");
      res = vec_to_str (&v->diff[i], len, res);
      *res++ = ')';
    }
  }
  if (!v->diff) *res++ = ')';
  *res = 0;
  return res;
}
Exemple #5
0
char *me_change_string(char *string, int opt, me_t * me)
{
	void *f = NULL, *f_prim = NULL;
	char *sep_ptr;
	char *str = NULL;

	char **names = NULL;
	int count = 0;

	char *f_prim_str = NULL;

	char *vars_str = NULL;

	double res = 0, res_prim = 0;

	debug(NULL, "me_change_string: Entered: %s\n", string);

	if (!me || !string)
		return NULL;

	sep_ptr = str_find_sep(string);
	if (sep_ptr)
		string = sep_ptr;

	if (!strlen(string))
		return NULL;

	f = evaluator_create(string);
	if (!f)
		return NULL;

	evaluator_get_variables(f, &names, &count);

	if (!names)
		goto cleanup;

	vars_str =
	    array_to_str((void **)names, count, (char *(*)(void *))strdup);
	if (!vars_str)
		goto cleanup;

	f_prim = evaluator_derivative_x(f);

	if (!f_prim)
		goto cleanup;

	f_prim_str = evaluator_get_string(f_prim);

	res = evaluator_evaluate_x_y_z(f, me->x, me->y, me->z);
	res_prim = evaluator_evaluate_x_y_z(f_prim, me->x, me->y, me->z);

	str =
	    str_unite("f(x,y,z)=%f ... vars={%s} ::: f'(x)=%s=%f", res,
		      vars_str, f_prim_str, res_prim);

 cleanup:
	if (f_prim)
		evaluator_destroy(f_prim);

	if (f)
		evaluator_destroy(f);

	if (vars_str)
		free(vars_str);

	return str;
}