void
ppl_min_for_le_pointset (ppl_Pointset_Powerset_C_Polyhedron_t ps,
			 ppl_Linear_Expression_t le, Value res)
{
  ppl_Coefficient_t num, denom;
  Value dv, nv;
  int minimum, err;

  value_init (nv);
  value_init (dv);
  ppl_new_Coefficient (&num);
  ppl_new_Coefficient (&denom);
  err = ppl_Pointset_Powerset_C_Polyhedron_minimize (ps, le, num, denom, &minimum);

  if (err > 0)
    {
      ppl_Coefficient_to_mpz_t (num, nv);
      ppl_Coefficient_to_mpz_t (denom, dv);
      gcc_assert (value_notzero_p (dv));
      value_division (res, nv, dv);
    }

  value_clear (nv);
  value_clear (dv);
  ppl_delete_Coefficient (num);
  ppl_delete_Coefficient (denom);
}
value value_cons(value op1, value op2)
{
	value res = value_init_nil();
	if (op2.type == VALUE_NIL) {
		res = value_init(VALUE_PAR);
		res.core.u_p->head = value_set(op1);
	} else if (op2.type == VALUE_ARY) {
		size_t length = value_length(op2) + 1;
		value array[length];
		array[0] = op1;
		size_t i;
		for (i = 1; i < length; ++i)
			array[i] = op2.core.u_a.a[i-1];
		res = value_set_ary(array, length);
	} else if (op2.type == VALUE_LST) {
		res = value_init(VALUE_LST);
		res.core.u_l[0] = value_set(op1);
		res.core.u_l[1] = value_set(op2);
	} else if (op2.type == VALUE_PAR) {
		res = value_init(VALUE_PAR);
		res.core.u_l[0] = value_set(op1);
		res.core.u_l[1] = value_set(op2);
	} else {
		value_error(1, "Type Error: cons() is undefined where op2 is %ts (nil, array or list expected).", op2);
		res = value_init_error();
	}
	
	return res;
}
Exemple #3
0
static double compute_enode(enode *p, Value *list_args) {
  
  int i;
  Value m, param;
  double res=0.0;
    
  if (!p)
    return(0.);

  value_init(m);
  value_init(param);

  if (p->type == polynomial) {
    if (p->size > 1)
                 value_assign(param,list_args[p->pos-1]);
    
    /* Compute the polynomial using Horner's rule */
    for (i=p->size-1;i>0;i--) {
      res +=compute_evalue(&p->arr[i],list_args);
      res *=VALUE_TO_DOUBLE(param);
    }
    res +=compute_evalue(&p->arr[0],list_args);
  }
  else if (p->type == periodic) {
    value_assign(m,list_args[p->pos-1]);
    
    /* Choose the right element of the periodic */
    value_set_si(param,p->size);
    value_pmodulus(m,m,param);
    res = compute_evalue(&p->arr[VALUE_TO_INT(m)],list_args);
  }
  value_clear(m);
  value_clear(param);
  return res;
} /* compute_enode */
/** 
 * Computes the overall period of the variables I for (MI) mod |d|, where M is
 * a matrix and |d| a vector. Produce a diagonal matrix S = (s_k) where s_k is
 * the overall period of i_k 
 * @param M the set of affine functions of I (row-vectors)
 * @param d the column-vector representing the modulos
*/
Matrix * affine_periods(Matrix * M, Matrix * d) {
  Matrix * S;
  unsigned int i,j;
  Value tmp;
  Value * periods = (Value *)malloc(sizeof(Value) * M->NbColumns);
  value_init(tmp);
  for(i=0; i< M->NbColumns; i++) {
    value_init(periods[i]);
    value_set_si(periods[i], 1);
  }
  for (i=0; i<M->NbRows; i++) {
    for (j=0; j< M->NbColumns; j++) {
      value_gcd(tmp, d->p[i][0], M->p[i][j]);
      value_divexact(tmp, d->p[i][0], tmp);
      value_lcm(periods[j], periods[j], tmp);
     }
  }
  value_clear(tmp);

  /* 2- build S */
  S = Matrix_Alloc(M->NbColumns, M->NbColumns);
  for (i=0; i< M->NbColumns; i++) 
    for (j=0; j< M->NbColumns; j++)
      if (i==j) value_assign(S->p[i][j],periods[j]);
      else value_set_si(S->p[i][j], 0);

  /* 3- clean up */
  for(i=0; i< M->NbColumns; i++) value_clear(periods[i]);
  free(periods);
  return S;
} /* affine_periods */
Exemple #5
0
/*---------------------------------------------------------------------*/
static int exist_points(int pos,Polyhedron *Pol,Value *context) {
  
  Value LB, UB, k,tmp;
  
  value_init(LB); value_init(UB); 
  value_init(k);  value_init(tmp);
  value_set_si(LB,0);
  value_set_si(UB,0);
  
  /* Problem if UB or LB is INFINITY */
  if (lower_upper_bounds(pos,Pol,context,&LB,&UB) !=0) {
    errormsg1("exist_points", "infdom", "infinite domain");
    value_clear(LB);
    value_clear(UB);
    value_clear(k);
    value_clear(tmp);
    return -1;
  }
  value_set_si(context[pos],0);
  if(value_lt(UB,LB)) {
    value_clear(LB); 
    value_clear(UB);
    value_clear(k);
    value_clear(tmp);
    return 0;
  }  
  if (!Pol->next) {
    value_subtract(tmp,UB,LB);
    value_increment(tmp,tmp);
    value_clear(UB);
    value_clear(LB);
    value_clear(k);
    return (value_pos_p(tmp));
  }
  
  for (value_assign(k,LB);value_le(k,UB);value_increment(k,k)) {
    
    /* insert k in context */
    value_assign(context[pos],k);    
    if (exist_points(pos+1,Pol->next,context) > 0 ) {
      value_clear(LB); value_clear(UB);
      value_clear(k); value_clear(tmp);
      return 1;
    }
  }   
  /* Reset context */
  value_set_si(context[pos],0);
  value_clear(UB); value_clear(LB);
  value_clear(k); value_clear(tmp);
  return 0;
}
Exemple #6
0
int main(int argc, char* argv[]) {

    value_t values[6][MAX_VALUES];
    for(int i = 0; i < 6; i++) {
        for(int j = 0; j < MAX_VALUES; j++) {
            values[i][j] = value_init(-1, -1);
        }
    }

    int (*types[6])(int n);
    types[0] = triangle;
    types[1] = square;
    types[2] = pentagonal;
    types[3] = hexagonal;
    types[4] = heptagonal;
    types[5] = octagonal;

    // generate a full list of each type between 1000 and 10,000
    for(int i = 0; i < 6; i++) {
        int n = 1;
        int v = 0;
        int value_ptr = 0;
        do {
            v = (*types[i])(n);
            if(v >= 1000 && v < 10000) {
                values[i][value_ptr] = value_init(n, v);
                value_ptr++;
            }
            n++;
        } while(v < 10000);
    }

    // recursively generate chains of the numbers until the correct chain is found
    int remaining[6] = { -1 };
    for(int i = 1; i < 6; i++) {
        remaining[i] = i;
    }
    for(int i = 0; i < MAX_VALUES; i++) {
        if(values[0][i].n == -1) break;

        char chain[6][5] = { { '\0' } };
        sprintf(chain[0], "%i", values[0][i].v);

        cyclic(values, remaining, chain, 1);
    }

    return 0;
}
Exemple #7
0
int test_memory()
{
	int i, j;
	value var, ten = value_set_long(10);
	value container = value_init_nil();

	printf("testing memory\n");
	
	var.type = VALUE_VAR;
	var.core.u_var = "x";
	
	for (i = 1; i < 10000000; i *= 2) {
		container = value_init(VALUE_MPZ);
		size_t start = usec();
		for (j = 0; j < i; ++j) {
			value_add_now(&container, ten);
		}
		
		
		value_clear(&container);
		size_t finish = usec();
		printf("time to do and clear %d elements: %ld usec\n", i, (unsigned long) finish - start);
	}
	
//	size_t time = usec();
//	while (usec() - time < 5000000) ;
	
	return 0;
}
static int
fetch_simple_param(enum tof type, struct process *proc,
                   struct fetch_context *context,
                   struct value_dict *arguments,
                   struct arg_type_info *info, int own,
                   struct value *valuep)
{
    /* Arrays decay into pointers per C standard.  We check for
     * this here, because here we also capture arrays that come
     * from parameter packs.  */
    if (info->type == ARGTYPE_ARRAY) {
        struct arg_type_info *tmp = malloc(sizeof(*tmp));
        if (tmp != NULL) {
            type_init_pointer(tmp, info, own);
            tmp->lens = info->lens;
            info = tmp;
            own = 1;
        }
    }

    struct value value;
    value_init(&value, proc, NULL, info, own);
    if (fetch_arg_next(context, type, proc, info, &value) < 0)
        return -1;

    if (val_dict_push_next(arguments, &value) < 0) {
        value_destroy(&value);
        return -1;
    }

    if (valuep != NULL)
        *valuep = value;

    return 0;
}
Exemple #9
0
void Matrix_Extend(Matrix *Mat, unsigned NbRows)
{
  Value *p, **q;
  int i,j;

  q = (Value **)realloc(Mat->p, NbRows * sizeof(*q));
  if(!q) {
    errormsg1("Matrix_Extend", "outofmem", "out of memory space");
    return;
  }
  Mat->p = q;
  if (Mat->p_Init_size < NbRows * Mat->NbColumns) {
    p = (Value *)realloc(Mat->p_Init, NbRows * Mat->NbColumns * sizeof(Value));
    if(!p) {
      errormsg1("Matrix_Extend", "outofmem", "out of memory space");
      return;
    }
    Mat->p_Init = p;
    Vector_Set(Mat->p_Init + Mat->NbRows*Mat->NbColumns, 0,
	       Mat->p_Init_size - Mat->NbRows*Mat->NbColumns);
    for (i = Mat->p_Init_size; i < Mat->NbColumns*NbRows; ++i)
	value_init(Mat->p_Init[i]);
    Mat->p_Init_size = Mat->NbColumns*NbRows;
  } else
    Vector_Set(Mat->p_Init + Mat->NbRows*Mat->NbColumns, 0,
	       (NbRows - Mat->NbRows) * Mat->NbColumns);
  for (i=0;i<NbRows;i++) {
    Mat->p[i] = Mat->p_Init + (i * Mat->NbColumns);
  }
  Mat->NbRows = NbRows;
}
Exemple #10
0
/* Converts TEXT to a value.

   VAL will be initialised and filled by this function.
   It is the caller's responsibility to destroy VAL when no longer needed.
   VAR must be the variable with which VAL is associated.

   On success, VAL is returned, NULL otherwise.
*/
union value *
text_to_value (const gchar *text,
	       const struct variable *var,
	       union value *val)
{
  const struct fmt_spec *format = var_get_print_format (var);
  int width = var_get_width (var);

  if ( format->type != FMT_A)
    {
      if ( ! text ) return NULL;

      {
	const gchar *s = text;
	while (*s)
	  {
	    if ( !isspace (*s))
	      break;
	    s++;
	  }

	if ( !*s) return NULL;
      }
    }

  value_init (val, width);
  free (data_in (ss_cstr (text), UTF8, format->type, val, width,
                 var_get_encoding (var)));

  return val;
}
Exemple #11
0
/* 
 * Return the component of 'p' with minimum non-zero absolute value. 'index'
 * points to the component index that has the minimum value. If no such value
 * and index is found, Value 1 is returned.
 */
void Vector_Min_Not_Zero(Value *p,unsigned length,int *index,Value *min)
{
  Value aux;
  int i;
  
  
  i = First_Non_Zero(p, length);
  if (i == -1) {
    value_set_si(*min,1);
    return;
  }
  *index = i;
  value_absolute(*min, p[i]);
  value_init(aux);
  for (i = i+1; i < length; i++) {
    if (value_zero_p(p[i]))
      continue;
    value_absolute(aux, p[i]);
    if (value_lt(aux,*min)) {
      value_assign(*min,aux);
      *index = i;
    }  
  }
  value_clear(aux);
} /* Vector_Min_Not_Zero */
Exemple #12
0
/*--------------------------------------------------------------*/
int Polyhedron_Not_Empty(Polyhedron *P,Polyhedron *C,int MAXRAYS) {

  int res,i;
  Value *context;
  Polyhedron *L;
  
  POL_ENSURE_FACETS(P);
  POL_ENSURE_VERTICES(P);
  POL_ENSURE_FACETS(C);
  POL_ENSURE_VERTICES(C);

  /* Create a context vector size dim+2 and set it to all zeros */
  context = (Value *) malloc((P->Dimension+2)*sizeof(Value));
  
  /* Initialize array 'context' */
  for (i=0;i<(P->Dimension+2);i++) 
    value_init(context[i]);
  
  Vector_Set(context,0,(P->Dimension+2));
  
  /* Set context[P->Dimension+1] = 1  (the constant) */
  value_set_si(context[P->Dimension+1],1);
  
  L = Polyhedron_Scan(P,C,MAXRAYS);
  res = exist_points(1,L,context);
  Domain_Free(L);
  
  /* Clear array 'context' */
  for (i=0;i<(P->Dimension+2);i++) 
    value_clear(context[i]);
  free(context);
  return res;
}
/* Return TRUE if VE contains a text which is not valid for VAR or if it
   contains the SYSMIS value */
static gboolean
value_entry_contains_invalid (PsppireValueEntry *ve, const struct variable *var)
{
  gboolean result = FALSE;

  if (var) 
    {
      union value val;
      const int width = var_get_width (var);
      value_init (&val, width);

      if ( psppire_value_entry_get_value (ve, &val, width))
	{
	  if (var_is_value_missing (var, &val, MV_SYSTEM))
	    {
	      result = TRUE;
	    }
	}
      else
	result = TRUE;

      value_destroy (&val, width);
    }

  return result;
}
Exemple #14
0
/* 
 * Given matrices 'Mat1' and 'Mat2', compute the matrix product and store in 
 * matrix 'Mat3' 
 */
void Matrix_Product(Matrix *Mat1,Matrix *Mat2,Matrix *Mat3) {
  
  int Size, i, j, k;
  unsigned NbRows, NbColumns;
  Value **q1, **q2, *p1, *p3,sum;
  
  NbRows    = Mat1->NbRows;
  NbColumns = Mat2->NbColumns;
  
  Size      = Mat1->NbColumns;
  if(Mat2->NbRows!=Size||Mat3->NbRows!=NbRows||Mat3->NbColumns!=NbColumns) {
    fprintf(stderr, "? Matrix_Product : incompatable matrix dimension\n");
    return;
  }     
  value_init(sum); 
  p3 = Mat3->p_Init;
  q1 = Mat1->p;
  q2 = Mat2->p;
  
  /* Mat3[i][j] = Sum(Mat1[i][k]*Mat2[k][j] where sum is over k = 1..nbrows */
  for (i=0;i<NbRows;i++) {
    for (j=0;j<NbColumns;j++) {
      p1 = *(q1+i);
      value_set_si(sum,0);
      for (k=0;k<Size;k++) {
	value_addmul(sum, *p1, *(*(q2+k)+j));
	p1++;
      }
      value_assign(*p3,sum);
      p3++;
    }
  }
  value_clear(sum); 
  return;
} /* Matrix_Product */
Exemple #15
0
int main(int argc, char * argv[]) {

   // init

   util_init();
   my_random_init(); // for opening book

   printf("Toga II 1.2.1a UCI based on Fruit 2.1 by Thomas Gaksch and Fabien Letouzey. Settings by Dieter Eberle\n");

   // early initialisation (the rest is done after UCI options are parsed in protocol.cpp)

   option_init();

   square_init();
   piece_init();
   pawn_init_bit();
   value_init();
   vector_init();
   attack_init();
   move_do_init();

   random_init();
   hash_init();

   trans_init(Trans);
   book_init();

   // loop

   loop();

   return EXIT_SUCCESS;
}
Exemple #16
0
Slapi_Value *
slapi_value_init_string_passin(Slapi_Value *v, char *s)
{
    value_init(v,NULL,CSN_TYPE_UNKNOWN,NULL);
	slapi_value_set_string_passin(v,s);
	return v;
}
Exemple #17
0
int main(int argc, char *argv[]) {

	// init

	util_init();
	my_random_init(); // for opening book

	printf(
		"Gambit Fruit based on Fruit 2.1 and Toga by Ryan Benitez, Thomas Gaksch and Fabien Letouzey\nEdit by Evgeniy Zheltonozhskiy\n");

	// early initialisation (the rest is done after UCI options are parsed in protocol.cpp)

	option_init();

	square_init();
	piece_init();
	pawn_init_bit();
	value_init();
	vector_init();
	attack_init();
	move_do_init();

	random_init();
	hash_init();

	trans_init(Trans);
	book_init();

	// loop
	loop();

	return EXIT_SUCCESS;
}
Exemple #18
0
static ppl_Pointset_Powerset_C_Polyhedron_t
dr_equality_constraints (graphite_dim_t dim,
		         graphite_dim_t pos, graphite_dim_t nb_subscripts)
{
  ppl_Polyhedron_t subscript_equalities;
  ppl_Pointset_Powerset_C_Polyhedron_t res;
  Value v, v_op;
  graphite_dim_t i;

  value_init (v);
  value_init (v_op);
  value_set_si (v, 1);
  value_set_si (v_op, -1);

  ppl_new_C_Polyhedron_from_space_dimension (&subscript_equalities, dim, 0);
  for (i = 0; i < nb_subscripts; i++)
    {
      ppl_Linear_Expression_t expr;
      ppl_Constraint_t cstr;
      ppl_Coefficient_t coef;

      ppl_new_Coefficient (&coef);
      ppl_new_Linear_Expression_with_dimension (&expr, dim);

      ppl_assign_Coefficient_from_mpz_t (coef, v);
      ppl_Linear_Expression_add_to_coefficient (expr, pos + i, coef);
      ppl_assign_Coefficient_from_mpz_t (coef, v_op);
      ppl_Linear_Expression_add_to_coefficient (expr, pos + i + nb_subscripts,
						coef);

      ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_EQUAL);
      ppl_Polyhedron_add_constraint (subscript_equalities, cstr);

      ppl_delete_Linear_Expression (expr);
      ppl_delete_Constraint (cstr);
      ppl_delete_Coefficient (coef);
    }

  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron
    (&res, subscript_equalities);
  value_clear (v);
  value_clear (v_op);
  ppl_delete_Polyhedron (subscript_equalities);

  return res;
}
Exemple #19
0
/* 
 * Compute GCD of 'a' and 'b' 
 */
void Gcd(Value a,Value b,Value *result) {

  Value acopy, bcopy;

  value_init(acopy);
  value_init(bcopy);
  value_assign(acopy,a);
  value_assign(bcopy,b);
  while(value_notzero_p(acopy)) { 
    value_modulus(*result,bcopy,acopy);      
    value_assign(bcopy,acopy);                     
    value_assign(acopy,*result);                   
  }
  value_absolute(*result,bcopy);
  value_clear(acopy);
  value_clear(bcopy);
} /* Gcd */
void count(mpz_t states,int argc, char **argv, int lanes[NLANES][L], int filaments, int noconsts)
{
	
	int i,j;
	//int temp[500];
	int** constraints;
	Value *test;
	char* total;
	unsigned NbRows, NbColumns;
    Value cb;
    Polyhedron *A;
    Matrix *M;
    struct barvinok_options *options = barvinok_options_new_with_defaults();
	NbRows=0;
    argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL);
    //printf("length 1st lane: %d\n", lanes[0][1]);
    
	constraints= malloc(noconsts*sizeof(int *));
	//printf("%lu\n",(filaments+2)*(noconsts));
	for (i=0;i<noconsts;i++){
		constraints[i]=(int*)malloc(sizeof(int)*(filaments+2));
		for(j=0;j<filaments+2;j++){
			constraints[i][j]=0;
			//printf("%d %d %d\n",i,j,constraints[i][j]);
		}
	}
	//printf("from count: fils %d noconsts %d\n",filaments,noconsts);
    gen_constraints(constraints,lanes,filaments,noconsts);
    dump_to_file(constraints,filaments,noconsts);

	
	value_init(cb);
	total=malloc(sizeof(char)*500);
	get_popen_data(total);
    //A = Constraints2Polyhedron(M, options->MaxRays);
   
    
    //value_print(stdout, P_VALUE_FMT, cb);
    mpz_set_str(cb,total,10);
    free(total);
    //printf("%s\n%d\n",total,strlen(total));	
	//gmp_printf("%Zd\n",states);
    //printf("%d\n",tot_int);
    if (options->print_stats)
	barvinok_stats_print(options->stats, stdout);
    value_clear(cb);
    //value_clear(test);
   
    barvinok_options_free(options);
    for (i=0;i<noconsts;i++){
		free(constraints[i]);
	}
	free(constraints);
    
    
   
}
Exemple #21
0
/*
 * The string is passed in by value.
 */
void
valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn)
{
	Slapi_Value v;
	value_init(&v,NULL,t,csn);
	slapi_value_set_string(&v,s);
    valuearray_add_value(&vs->va,&v);
	value_done(&v);
}
enum lp_result PL_polyhedron_opt(Polyhedron *P, Value *obj, Value denom,
				enum lp_dir dir, Value *opt)
{
    int i;
    int first = 1;
    Value val, d;
    enum lp_result res = lp_empty;

    POL_ENSURE_VERTICES(P);
    if (emptyQ(P))
	return res;

    value_init(val);
    value_init(d);
    for (i = 0; i < P->NbRays; ++ i) {
	Inner_Product(P->Ray[i]+1, obj, P->Dimension+1, &val);
	if (value_zero_p(P->Ray[i][0]) && value_notzero_p(val)) {
	    res = lp_unbounded;
	    break;
	}
	if (value_zero_p(P->Ray[i][1+P->Dimension])) {
	    if ((dir == lp_min && value_neg_p(val)) ||
		(dir == lp_max && value_pos_p(val))) {
		res = lp_unbounded;
		break;
	    }
	} else {
	    res = lp_ok;
	    value_multiply(d, denom, P->Ray[i][1+P->Dimension]);
	    if (dir == lp_min)
		mpz_cdiv_q(val, val, d);
	    else
		mpz_fdiv_q(val, val, d);
	    if (first || (dir == lp_min ? value_lt(val, *opt) :
				          value_gt(val, *opt)))
		value_assign(*opt, val);
	    first = 0;
	}
    }
    value_clear(d);
    value_clear(val);

    return res;
}
int
ppl_lexico_compare_linear_expressions (ppl_Linear_Expression_t a,
				       ppl_Linear_Expression_t b)
{
  ppl_dimension_type min_length, length1, length2;
  ppl_dimension_type i;
  ppl_Coefficient_t c;
  int res;
  Value va, vb;

  ppl_Linear_Expression_space_dimension (a, &length1);
  ppl_Linear_Expression_space_dimension (b, &length2);
  ppl_new_Coefficient (&c);
  value_init (va);
  value_init (vb);

  if (length1 < length2)
    min_length = length1;
  else
    min_length = length2;

  for (i = 0; i < min_length; i++)
    {
      ppl_Linear_Expression_coefficient (a, i, c);
      ppl_Coefficient_to_mpz_t (c, va);
      ppl_Linear_Expression_coefficient (b, i, c);
      ppl_Coefficient_to_mpz_t (c, vb);
      res = value_compare (va, vb);

      if (res == 0)
	continue;

      value_clear (va);
      value_clear (vb);
      ppl_delete_Coefficient (c);
      return res;
    }

  value_clear (va);
  value_clear (vb);
  ppl_delete_Coefficient (c);
  return length1 - length2;
}
Exemple #24
0
/* 
 * Find the longest sum of consecutive primes that add up to a prime number 
 * below one million.
 */
int consecutive_primes()
{
	value primes = value_init(VALUE_ARY);
	value i, million = value_set_long(1000000);
	for (i = value_set_long(0); value_lt(i, million); value_inc_now(&i))
		if (value_probab_prime_p(i))
			value_append_now(&primes, i);
	
	return 0;
}
Exemple #25
0
void
gnm_init (void)
{
	static gboolean inited = FALSE;
	if (inited)
		return;
	inited = TRUE;

	libgoffice_init ();
	_gnm_register_resource ();
	if (gdk_screen_get_default ()) {
		/* Only when we have a gui.  */
		gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (),
						  "/org/gnumeric/gnumeric/icons");
	}
	gnm_register_ui_files ();
	go_plugin_service_define ("function_group",
		&gnm_plugin_service_function_group_get_type);
	go_plugin_service_define ("ui",
		&gnm_plugin_service_ui_get_type);
	go_plugin_service_define ("solver",
		&gnm_plugin_service_solver_get_type);
	go_plugin_loader_module_register_version ("gnumeric", GNM_VERSION_FULL);

	g_object_new (GNM_APP_TYPE, NULL);
	mathfunc_init ();

	gnm_style_init ();
	gnm_conf_init ();
	gnm_color_init ();
	gnm_font_init ();	/* requires config */

	value_init ();
	parse_util_init ();
	_gnm_expr_init ();
	gnm_sheet_cell_init ();
	clipboard_init ();
	dependent_types_init ();
	gnm_rendered_value_init ();
	functions_init ();
	print_init ();
	gnm_autofill_init ();
	sheet_objects_init ();
	_gnm_hlink_init ();

	/* The statically linked in file formats */
	gnm_xml_sax_read_init ();
	gnm_xml_sax_write_init ();
	stf_init ();

	/* Make sure that images will be displayed with the correct
	 resolution, see #628472 */
	go_image_set_default_dpi (gnm_app_display_dpi_get (TRUE),
	                          gnm_app_display_dpi_get (FALSE));
}
/* Called whenever the group variable entry widget's contents change */
static void
on_grp_var_change (GtkEntry *entry, PsppireDialogActionIndepSamps *act)
{
  PsppireDialogAction *da = PSPPIRE_DIALOG_ACTION (act);
  const gchar *text = gtk_entry_get_text (entry);

  const struct variable *v = psppire_dict_lookup_var (da->dict, text);

  gtk_widget_set_sensitive (act->define_groups_button, v != NULL);

  if (act->grp_var)
    {
      int width = var_get_width (act->grp_var);
      value_destroy (&act->cut_point, width);
      value_destroy (&act->grp_val[0], width);
      value_destroy (&act->grp_val[1], width);
    }

  if (v)
    {
      const int width = var_get_width (v);
      value_init (&act->cut_point, width);
      value_init (&act->grp_val[0], width);
      value_init (&act->grp_val[1], width);

      if (width == 0)
        {
          act->cut_point.f  = SYSMIS;
          act->grp_val[0].f = SYSMIS;
          act->grp_val[1].f = SYSMIS;
        }
      else
        {
          act->cut_point.short_string[0] = '\0';
          act->grp_val[0].short_string[0] = '\0';
          act->grp_val[1].short_string[0] = '\0';
        }
    }

  act->grp_var = v;
}
Exemple #27
0
/* Parse all the labels for the VAR_CNT variables in VARS and add
   the specified labels to those variables.  */
static int
get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt,
           const char *dict_encoding)
{
  /* Parse all the labels and add them to the variables. */
  do
    {
      enum { MAX_LABEL_LEN = 255 };
      int width = var_get_width (vars[0]);
      union value value;
      struct string label;
      size_t trunc_len;
      size_t i;

      /* Set value. */
      value_init (&value, width);
      if (!parse_value (lexer, &value, vars[0]))
        {
          value_destroy (&value, width);
          return 0;
        }
      lex_match (lexer, T_COMMA);

      /* Set label. */
      if (lex_token (lexer) != T_ID && !lex_force_string (lexer))
        {
          value_destroy (&value, width);
          return 0;
        }

      ds_init_substring (&label, lex_tokss (lexer));

      trunc_len = utf8_encoding_trunc_len (ds_cstr (&label), dict_encoding,
                                           MAX_LABEL_LEN);
      if (ds_length (&label) > trunc_len)
	{
	  msg (SW, _("Truncating value label to %d bytes."), MAX_LABEL_LEN);
	  ds_truncate (&label, trunc_len);
	}

      for (i = 0; i < var_cnt; i++)
        var_replace_value_label (vars[i], &value, ds_cstr (&label));

      ds_destroy (&label);
      value_destroy (&value, width);

      lex_get (lexer);
      lex_match (lexer, T_COMMA);
    }
  while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD);

  return 1;
}
void
ppl_set_inhomogeneous_gmp (ppl_Linear_Expression_t e, Value x)
{
  Value v0, v1;
  ppl_Coefficient_t c;

  value_init (v0);
  value_init (v1);
  ppl_new_Coefficient (&c);

  ppl_Linear_Expression_inhomogeneous_term (e, c);
  ppl_Coefficient_to_mpz_t (c, v1);
  value_oppose (v1, v1);
  value_assign (v0, x);
  value_addto (v0, v0, v1);
  ppl_assign_Coefficient_from_mpz_t (c, v0);
  ppl_Linear_Expression_add_to_inhomogeneous (e, c);

  value_clear (v0);
  value_clear (v1);
  ppl_delete_Coefficient (c);
}
Exemple #29
0
void
valueset_remove_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s)
{
	Slapi_Value v;
	Slapi_Value *removed;
	value_init(&v,NULL,CSN_TYPE_NONE,NULL);
	slapi_value_set_string(&v,s);
	removed = valuearray_remove_value(a, vs->va, &v);
	if(removed) {
		slapi_value_free(&removed);
	}
	value_done(&v);
}
void
ppl_set_coef_gmp (ppl_Linear_Expression_t e, ppl_dimension_type i, Value x)
{
  Value v0, v1;
  ppl_Coefficient_t c;

  value_init (v0);
  value_init (v1);
  ppl_new_Coefficient (&c);

  ppl_Linear_Expression_coefficient (e, i, c);
  ppl_Coefficient_to_mpz_t (c, v1);
  value_oppose (v1, v1);
  value_assign (v0, x);
  value_addto (v0, v0, v1);
  ppl_assign_Coefficient_from_mpz_t (c, v0);
  ppl_Linear_Expression_add_to_coefficient (e, i, c);

  value_clear (v0);
  value_clear (v1);
  ppl_delete_Coefficient (c);
}