コード例 #1
0
ファイル: libcrange.c プロジェクト: realpdm/libcrange
libcrange* libcrange_new(apr_pool_t* pool, const char* config_file)
{
    libcrange* lr;

    if (!initd) {
        initd = 1;
        apr_initialize();
        atexit(apr_terminate);
    }

    lr = apr_palloc(pool, sizeof(libcrange));
    lr->pool = pool;
    lr->caches = set_new(pool, 0);
    lr->default_domain = NULL;
    lr->funcdir = LIBCRANGE_FUNCDIR;
    lr->want_caching = 1;
    lr->config_file = config_file ? config_file : LIBCRANGE_CONF;
    lr->functions = set_new(pool, 0);
    lr->perl_functions = NULL;
    lr->vars = set_new(pool, 0);

    if (access(lr->config_file, R_OK) != 0)
        return lr; /* no config file, don't load any modules */

    if (parse_config_file(lr) < 0)
        return NULL;

    return lr;
}
コード例 #2
0
ファイル: main.c プロジェクト: pronan/c_data_structures
static void
test_set(void) {
    char *keys1[] = {"a", "b", "r", "a", "c", "a", "d", "a", "b", "r", "a"};
    char *keys2[] = {"a", "l", "a", "c", "a", "z", "a", "m"};
    SetObject *a = set_new();
    SetObject *b = set_new();
    set_addfrom(a, (void**)keys1, 11);
    set_addfrom(b, (void**)keys2, 8);
    set_print(a); // { 'c', 'd', 'r', 'a', 'b', }
    set_print(b); // { 'c', 'l', 'm', 'a', 'z', }
    set_print(set_rsub(a, b)); //{ 'd', 'b', 'r', }
    set_print(set_ror(a, b)); //{ 'a', 'b', 'c', 'd', 'l', 'm', 'r', 'z', }
    set_print(set_rand(a, b)); //{ 'c', 'a', }
    set_print(set_rxor(a, b)); //{ 'b', 'd', 'l', 'm', 'r', 'z', }
    set_ior(a, b);
    set_print(a);
    set_isub(a, b);
    set_print(a);
    set_ixor(a, b);
    set_print(a);
    set_iand(a, b);
    set_print(a);
    set_free(a);
    set_free(b);
    char *keys3[] = {"a", "b"};
    char *keys4[] = {"a", "b", "d", "c", "e", "f", "g", "h"};
    SetObject *c = set_new();
    SetObject *d = set_new();
    set_addfrom(c, (void**)keys3, 2);
    set_addfrom(d, (void**)keys4, 8);
    set_print(set_xor(c, d));
    set_print(set_and(c, d));
    set_print(set_sub(c, d));
}
コード例 #3
0
ファイル: flow.c プロジェクト: EIREXE/Quakeforge-gcw0
static flowvar_t *
new_flowvar (void)
{
	flowvar_t *var;
	ALLOC (256, flowvar_t, vars, var);
	var->use = set_new ();
	var->define = set_new ();
	return var;
}
コード例 #4
0
ファイル: main.c プロジェクト: lorvis/study
int main()
{
    printf("Hello world!\n");
    set_t * set_A = set_new(10);
    set_t * set_B = set_new(7);
    set_t * set_C;
    set_add_range(set_A,0,11);
    set_add_range(set_B,3,5);
    puts("\n\n Set_A after add");
    set_print_out(set_A);
    set_delete_range(set_A,3,11);
    puts("\n\n Set_A after delete");
    set_print_out(set_A);
    puts("\n\n Set_B after add");
    set_print_out(set_B);
    set_C = set_merge(set_A,set_B,"none");
    puts("\n\n Set_C - result of merge");
    set_print_out(set_C);
    set_delete_range(set_A,0,10);
    set_add_range(set_A,4,7);
    puts("\n\n another set_A");
    set_print_out(set_A);
    set_delete(set_C);
    set_A = _set_intersection(set_A,set_B,"del 1");
    puts("\n\n set_A after intersection with set_B");
    set_print_out(set_A);
    puts("\n\n set_A size after intersection \n");
    set_print_size(set_A);
    set_delete_range(set_A,4,5);
    set_add_range(set_A,1,1);
        set_add_range(set_A,3,4);
    puts("\n\n another set_A");
    set_print_out(set_A);
     puts("\n\n set_B");
    set_print_out(set_B);
    set_C = set_absolute_complement(set_A,set_B,"none");
    puts("\n\n set_C - absolute_complement of set_A and set_B");
    set_print_out(set_C);

    printf("\n Power of set_C = %i",set_measure_power(set_C));
    set_delete(set_C);
    set_add_range(set_A,0,10);
    puts("\n\n set_A");
    set_print_out(set_A);
    set_delete_range(set_B,3,5);
    set_add_range(set_B,2,4);
    puts("\n\n set_B");
    set_print_out(set_B);
    set_C = set_relative_complement(set_A,set_B,"none");
    puts("\n\n set_C - relative_complement of set_A and set_B");
    set_print_out(set_C);
    set_delete(set_A);
    set_delete(set_B);
    set_delete(set_C);
    return 0;
}
コード例 #5
0
ファイル: flow.c プロジェクト: EIREXE/Quakeforge-gcw0
static void
flow_uninit_scan_statements (flownode_t *node, set_t *defs, set_t *uninit)
{
	set_t      *stuse;
	set_t      *stdef;
	statement_t *st;
	set_iter_t *var_i;
	flowvar_t  *var;
	operand_t  *op;

	// defs holds only reaching definitions. make it hold only reaching
	// uninitialized definitions
	set_intersection (defs, uninit);
	stuse = set_new ();
	stdef = set_new ();
	for (st = node->sblock->statements; st; st = st->next) {
		flow_analyze_statement (st, stuse, stdef, 0, 0);
		for (var_i = set_first (stuse); var_i; var_i = set_next (var_i)) {
			var = node->graph->func->vars[var_i->element];
			if (set_is_intersecting (defs, var->define)) {
				def_t      *def = flowvar_get_def (var);
				if (def) {
					if (options.warnings.uninited_variable) {
						warning (st->expr, "%s may be used uninitialized",
								 def->name);
					}
				} else {
					bug (st->expr, "st %d, uninitialized temp %s",
						 st->number, operand_string (var->op));
				}
			}
			// avoid repeat warnings in this node
			set_difference (defs, var->define);
		}
		for (var_i = set_first (stdef); var_i; var_i = set_next (var_i)) {
			var = node->graph->func->vars[var_i->element];
			// kill any reaching uninitialized definitions for this variable
			set_difference (defs, var->define);
			if (var->op->op_type == op_temp) {
				op = var->op;
				if (op->o.tempop.alias) {
					var = op->o.tempop.alias->o.tempop.flowvar;
					if (var)
						set_difference (defs, var->define);
				}
				for (op = op->o.tempop.alias_ops; op; op = op->next) {
					var = op->o.tempop.flowvar;
					if (var)
						set_difference (defs, var->define);
				}
			}
		}
	}
	set_delete (stuse);
	set_delete (stdef);
}
コード例 #6
0
ファイル: tw.c プロジェクト: Alberne/tinyprograme
//设置优惠活动 
struct sales_promotion *get_promotion() 
{
	static struct sales_promotion *promotions;
        struct promotion_one_info *p; //临时变量  
    	struct set_t *pset; //临时变量
    	int i;  
    	static struct sales_products discount_promotion[] = { //折扣商品信息
		{"ITEM00002", 1},
		{"ITEM00001", 1}
		//{"ITEM00003", 0},
		//{"ITEM00004", 0}
	};
	static struct sales_products one_free_promotion[] = { //买二送一商品信息
		{"ITEM00001", 1},
		{"ITEM00003", 1}
		//{"ITEM00003", 0}
	};
	 
    	PNEW(promotions, 1, struct sales_promotion *);
	promotions->promotion_all_info = NULL;
	
        /*假设当前有以下两种活动*
         *  1. 买二送一活动
         *  2. 9.5折优惠 */
    	promotions->priority = FREE_ONE;  //当某种商品满足两种优惠时,优先选则活动一
     
        /*首先设置优惠活动1信息*/
     	PNEW(p, 1, struct promotion_one_info *);
     	p->next_promotion = promotions->promotion_all_info;
     	promotions->promotion_all_info = p;
     	p->type = FREE_ONE;
     	strcpy(p->statement, "买二送一活动");
     	pset = set_new(100, compare_product, hashcode);
     	p->sales_set = pset; 

     	for(i = 0; i < array_len(one_free_promotion); i++) {
     		set_put(pset, &one_free_promotion[i]);		 		 
     	}
 
     	/*其次设置优惠活动2信息*/ 
	 PNEW(p, 1, struct promotion_one_info *); //分配活动2商品所需的内存
	 //链表头插法
	 p->next_promotion = promotions->promotion_all_info;
	 promotions->promotion_all_info = p;
	 p->type = DISCOUNT;
	 strcpy(p->statement, "9.5折优惠");
	 pset = set_new(100, compare_product, hashcode);
	 p->sales_set = pset;

	 for(i = 0; i < array_len(discount_promotion); i++) {
		 set_put(pset, &discount_promotion[i]);
	 }
	 
	 return promotions;
}
コード例 #7
0
ファイル: test-set.c プロジェクト: dlove24/dl-calg
void test_set_intersection (void) {
  int numbers1[] = {1, 2, 3, 4, 5, 6, 7};
  int numbers2[] = {5, 6, 7, 8, 9, 10, 11};
  int result[] = {5, 6, 7};
  int i;
  Set* set1;
  Set* set2;
  Set* result_set;
  size_t allocated;

  /* Create the first set */

  set1 = set_new (int_hash, int_equal);

  for (i = 0; i < 7; ++i) {
    set_insert (set1, &numbers1[i]);
    }

  /* Create the second set */

  set2 = set_new (int_hash, int_equal);

  for (i = 0; i < 7; ++i) {
    set_insert (set2, &numbers2[i]);
    }

  /* Perform the intersection */

  result_set = set_intersection (set1, set2);

  assert (set_num_entries (result_set) == 3);

  for (i = 0; i < 3; ++i) {
    assert (set_query (result_set, &result[i]) != 0);
    }

  /* Test out of memory scenario */

  alloc_test_set_limit (0);
  assert (set_intersection (set1, set2) == NULL);

  /* Can allocate set, can't copy all values */

  alloc_test_set_limit (2 + 2);
  allocated = alloc_test_get_allocated();
  assert (set_intersection (set1, set2) == NULL);
  assert (alloc_test_get_allocated() == allocated);

  set_free (set1);
  set_free (set2);
  set_free (result_set);
  }
コード例 #8
0
ファイル: aoi.c プロジェクト: ChowZenki/aoi
struct aoi_space * 
aoi_create(aoi_Alloc alloc, void *ud) {
	struct aoi_space *space = alloc(ud, NULL, sizeof(*space));
	space->alloc = alloc;
	space->alloc_ud = ud;
	space->object = map_new(space);
	space->watcher_static = set_new(space);
	space->marker_static = set_new(space);
	space->watcher_move = set_new(space);
	space->marker_move = set_new(space);
	space->hot = NULL;
	return space;
}
コード例 #9
0
ファイル: range.c プロジェクト: anthonybishopric/libcrange
range* range_from_braces(range_request* rr,
                         const range* r1, const range* r2, const range* r3)
{
    int i, j, k;
    set_element** m1;
    set_element** m2;
    set_element** m3;
    set* temp = NULL;
    range* bigrange;
    char* bundle;
    apr_pool_t* pool = range_request_pool(rr);
    
    if(r1->nodes->members == 0) {
        if(!temp) {
            temp = set_new(pool, 1);
            set_add(temp, "", NULL);
        }
        m1 = set_members(temp);
    } else m1 = set_members(r1->nodes);

    if(r2->nodes->members == 0) {
        if(!temp) {
            temp = set_new(pool, 1);
            set_add(temp, "", NULL);
        }
        m2 = set_members(temp);
    } else m2 = set_members(r2->nodes);

    if(r3->nodes->members == 0) {
        if(!temp) {
            temp = set_new(pool, 1);
            set_add(temp, "", NULL);
        }
        m3 = set_members(temp);
    } else m3 = set_members(r3->nodes);

    bigrange = range_new(rr);

    for(i = 0; m1[i]; i++)
        for(j = 0; m2[j]; j++)
            for(k = 0; m3[k]; k++) {
                bundle = apr_pstrcat(pool,
                                    m1[i]->name, m2[j]->name,
                                     m3[k]->name, NULL);
                range_add(bigrange, bundle);
            }

    if (temp) set_destroy(temp);
    bigrange->quoted = r1->quoted || r2->quoted || r3->quoted;
    return bigrange;
}
コード例 #10
0
ファイル: resolved-link.c プロジェクト: nmartensen/systemd
static int link_update_dnssec_negative_trust_anchors(Link *l) {
        _cleanup_strv_free_ char **ntas = NULL;
        _cleanup_set_free_free_ Set *ns = NULL;
        char **i;
        int r;

        assert(l);

        r = sd_network_link_get_dnssec_negative_trust_anchors(l->ifindex, &ntas);
        if (r == -ENODATA) {
                r = 0;
                goto clear;
        }
        if (r < 0)
                goto clear;

        ns = set_new(&dns_name_hash_ops);
        if (!ns)
                return -ENOMEM;

        STRV_FOREACH(i, ntas) {
                r = set_put_strdup(ns, *i);
                if (r < 0)
                        return r;
        }
コード例 #11
0
ファイル: localectl.c プロジェクト: ariscop/systemd
static int list_vconsole_keymaps(sd_bus *bus, char **args, unsigned n) {
        _cleanup_strv_free_ char **l = NULL;
        const char *dir;

        keymaps = set_new(string_hash_func, string_compare_func);
        if (!keymaps)
                return log_oom();

        NULSTR_FOREACH(dir, KBD_KEYMAP_DIRS)
                nftw(dir, nftw_cb, 20, FTW_MOUNT|FTW_PHYS);

        l = set_get_strv(keymaps);
        if (!l) {
                set_free_free(keymaps);
                return log_oom();
        }

        set_free(keymaps);

        if (strv_isempty(l)) {
                log_error("Couldn't find any console keymaps.");
                return -ENOENT;
        }

        strv_sort(l);

        pager_open_if_enabled();

        strv_print(l);

        return 0;
}
コード例 #12
0
ファイル: localectl.c プロジェクト: ariscop/systemd
static int list_locales(sd_bus *bus, char **args, unsigned n) {
        _cleanup_set_free_ Set *locales;
        _cleanup_strv_free_ char **l = NULL;
        int r;

        locales = set_new(string_hash_func, string_compare_func);
        if (!locales)
                return log_oom();

        r = add_locales_from_archive(locales);
        if (r < 0 && r != -ENOENT)
                return r;

        r = add_locales_from_libdir(locales);
        if (r < 0)
                return r;

        l = set_get_strv(locales);
        if (!l)
                return log_oom();

        strv_sort(l);

        pager_open_if_enabled();

        strv_print(l);

        return 0;
}
コード例 #13
0
ファイル: cube.c プロジェクト: SpectreV/HPowerEstimator
ace_cube_t * ace_cube_dup(ace_cube_t * cube) {
	int i;
	ace_cube_t * cube_copy;

	assert(cube != NULL);
	assert(cube->num_literals > 0);

	cube_copy = malloc(sizeof(ace_cube_t));
	cube_copy->static_prob = cube->static_prob;
	cube_copy->num_literals = cube->num_literals;
	cube_copy->cube = set_new (2 * cube->num_literals);
	for (i = 0; i < cube->num_literals; i++) {
		switch (node_get_literal (cube->cube, i)) {
		case ZERO:
			set_insert(cube_copy->cube, 2 * i);
			set_remove(cube_copy->cube, 2 * i + 1);
			break;
		case ONE:
			set_remove(cube_copy->cube, 2 * i);
			set_insert(cube_copy->cube, 2 * i + 1);
			break;
		case TWO:
			set_insert(cube_copy->cube, 2 * i);
			set_insert(cube_copy->cube, 2 * i + 1);
			break;
		default:
			fail("Bad literal.");
		}
	}

	return (cube_copy);
}
コード例 #14
0
ファイル: coredumpctl.c プロジェクト: gcampax/systemd
static Set *new_matches(void) {
        Set *set;
        char *tmp;
        int r;

        set = set_new(trivial_hash_func, trivial_compare_func);
        if (!set) {
                log_oom();
                return NULL;
        }

        tmp = strdup("MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1");
        if (!tmp) {
                log_oom();
                set_free(set);
                return NULL;
        }

        r = set_consume(set, tmp);
        if (r < 0) {
                log_error("failed to add to set: %s", strerror(-r));
                set_free(set);
                return NULL;
        }

        return set;
}
コード例 #15
0
ファイル: cliquer_graph.c プロジェクト: AlessiaWent/igraph
/*
 * graph_resize()
 *
 * Resizes graph g to given size.  If size > g->n, the new vertices are
 * not connected to any others and their weights are set to 1.
 * If size < g->n, the last g->n - size vertices are removed.
 */
void graph_resize(graph_t *g, int size) {
	int i;

	ASSERT(g!=NULL);
	ASSERT(g->n > 0);
	ASSERT(size > 0);

	if (g->n == size)
		return;

	/* Free/alloc extra edge-sets */
	for (i=size; i < g->n; i++)
		set_free(g->edges[i]);
	g->edges=realloc(g->edges, size * sizeof(set_t));
	for (i=g->n; i < size; i++)
		g->edges[i]=set_new(size);

	/* Resize original sets */
	for (i=0; i < MIN(g->n,size); i++) {
		g->edges[i]=set_resize(g->edges[i],size);
	}

	/* Weights */
	g->weights=realloc(g->weights,size * sizeof(int));
	for (i=g->n; i<size; i++)
		g->weights[i]=1;
	
	g->n=size;
	return;
}
コード例 #16
0
ファイル: compiler.c プロジェクト: gundermanc/gunderscript
/**
 * Creates a new compiler object that will contain the current state of the
 * compiler and its data structures.
 * returns: new compiler object, or NULL if the allocation fails.
 */
Compiler * compiler_new(VM * vm) {

  assert(vm != NULL);

  Compiler * compiler = calloc(1, sizeof(Compiler));

  /* check for failed allocation */
  if(compiler == NULL) {
    return NULL;
  }

  /* TODO: make this stack auto expand when full */
  compiler->compiledScripts = set_new();
  compiler->symTableStk = stk_new(maxFuncDepth);
  compiler->vm = vm;

  /* check for further malloc errors */
  if(compiler->compiledScripts == NULL
     || compiler->symTableStk == NULL 
     || vm_buffer(compiler->vm) == NULL) {
    compiler_free(compiler);
    return NULL;
  }

  return compiler;
}
コード例 #17
0
ファイル: compiler.c プロジェクト: VeloxAmbitum/gunderscript
/**
 * Creates a new compiler object that will contain the current state of the
 * compiler and its data structures.
 * returns: new compiler object, or NULL if the allocation fails.
 */
Compiler * compiler_new(VM * vm) {

  assert(vm != NULL);

  Compiler * compiler = calloc(1, sizeof(Compiler));

  /* check for failed allocation */
  if(compiler == NULL) {
    return NULL;
  }

  /* TODO: make this stack auto expand when full */
  compiler->compiledScripts = set_new();
  compiler->symTableStk = stk_new(maxFuncDepth);
  compiler->functionHT = ht_new(COMPILER_INITIAL_HTSIZE, COMPILER_HTBLOCKSIZE, COMPILER_HTLOADFACTOR);
  compiler->outBuffer = buffer_new(bufferBlockSize, bufferBlockSize);
  compiler->vm = vm;

  /* check for further malloc errors */
  if(compiler->compiledScripts == NULL
     || compiler->symTableStk == NULL 
     || compiler->functionHT == NULL 
     || compiler->outBuffer == NULL) {
    compiler_free(compiler);
    return NULL;
  }

  return compiler;
}
コード例 #18
0
ファイル: test-set.c プロジェクト: dlove24/dl-calg
void test_set_free_function (void) {
  Set* set;
  int i;
  int* value;

  /* Create a set and fill it with 1000 values */

  set = set_new (int_hash, int_equal);

  set_register_free_function (set, free_value);

  allocated_values = 0;

  for (i = 0; i < 1000; ++i) {
    value = new_value (i);

    set_insert (set, value);
    }

  assert (allocated_values == 1000);

  /* Test removing a value */

  i = 500;
  set_remove (set, &i);

  assert (allocated_values == 999);

  /* Test freeing the set */

  set_free (set);

  assert (allocated_values == 0);
  }
コード例 #19
0
ファイル: test-set.c プロジェクト: dlove24/dl-calg
void test_set_to_array (void) {
  Set* set;
  int values[100];
  int** array;
  int i;

  /* Create a set containing pointers to all entries in the "values"
   * array. */

  set = set_new (pointer_hash, pointer_equal);

  for (i = 0; i < 100; ++i) {
    values[i] = 1;
    set_insert (set, &values[i]);
    }

  array = (int**) set_to_array (set);

  /* Check the array */

  for (i = 0; i < 100; ++i) {
    assert (*array[i] == 1);
    *array[i] = 0;
    }

  /* Test out of memory scenario */

  alloc_test_set_limit (0);
  assert (set_to_array (set) == NULL);

  free (array);
  set_free (set);
  }
コード例 #20
0
ファイル: reorder.c プロジェクト: dimpase/autocliquer
/*
 * reorder_set()
 *
 * Reorders the set s with a function  i -> order[i].
 *
 * Note: Assumes that order is the same size as SET_MAX_SIZE(s).
 */
void reorder_set(set_t s,int *order) {
        set_t tmp;
        int i,j;
        setelement e;

        ASSERT(reorder_is_bijection(order,SET_MAX_SIZE(s)));

        tmp=set_new(SET_MAX_SIZE(s));

        for (i=0; i<(SET_MAX_SIZE(s)/ELEMENTSIZE); i++) {
                e=s[i];
                if (e==0)
                        continue;
                for (j=0; j<ELEMENTSIZE; j++) {
                        if (e&1) {
                                SET_ADD_ELEMENT(tmp,order[i*ELEMENTSIZE+j]);
                        }
                        e = e>>1;
                }
        }
        if (SET_MAX_SIZE(s)%ELEMENTSIZE) {
                e=s[i];
                for (j=0; j<(SET_MAX_SIZE(s)%ELEMENTSIZE); j++) {
                        if (e&1) {
                                SET_ADD_ELEMENT(tmp,order[i*ELEMENTSIZE+j]);
                        }
                        e = e>>1;
                }
        }
コード例 #21
0
ファイル: locale-util.c プロジェクト: floppym/systemd
int get_locales(char ***ret) {
        _cleanup_set_free_ Set *locales = NULL;
        _cleanup_strv_free_ char **l = NULL;
        int r;

        locales = set_new(&string_hash_ops);
        if (!locales)
                return -ENOMEM;

        r = add_locales_from_archive(locales);
        if (r < 0 && r != -ENOENT)
                return r;

        r = add_locales_from_libdir(locales);
        if (r < 0)
                return r;

        l = set_get_strv(locales);
        if (!l)
                return -ENOMEM;

        strv_sort(l);

        *ret = TAKE_PTR(l);

        return 0;
}
コード例 #22
0
ファイル: coredumpctl.c プロジェクト: ringlej/systemd
static Set *new_matches(void) {
        Set *set;
        char *tmp;
        int r;

        set = set_new(NULL);
        if (!set) {
                log_oom();
                return NULL;
        }

        tmp = strdup("MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1");
        if (!tmp) {
                log_oom();
                set_free(set);
                return NULL;
        }

        r = set_consume(set, tmp);
        if (r < 0) {
                log_error_errno(r, "failed to add to set: %m");
                set_free(set);
                return NULL;
        }

        return set;
}
コード例 #23
0
ファイル: nodescf.c プロジェクト: VertiPub/libcrange
static vips* _empty_vips(range_request* rr)
{
    apr_pool_t* pool = range_request_pool(rr);
    vips* v = apr_palloc(pool, sizeof(*v));
    v->vips = v->viphosts = set_new(pool, 0);
    return v;
}
コード例 #24
0
ファイル: shadow.c プロジェクト: aweits/nss-pam-ldapd
void shadow_init(void)
{
  int i;
  SET *set;
  /* set up search bases */
  if (shadow_bases[0] == NULL)
    for (i = 0; i < NSS_LDAP_CONFIG_MAX_BASES; i++)
      shadow_bases[i] = nslcd_cfg->bases[i];
  /* set up scope */
  if (shadow_scope == LDAP_SCOPE_DEFAULT)
    shadow_scope = nslcd_cfg->scope;
  /* set up attribute list */
  set = set_new();
  attmap_add_attributes(set, attmap_shadow_uid);
  attmap_add_attributes(set, attmap_shadow_userPassword);
  attmap_add_attributes(set, attmap_shadow_shadowLastChange);
  attmap_add_attributes(set, attmap_shadow_shadowMax);
  attmap_add_attributes(set, attmap_shadow_shadowMin);
  attmap_add_attributes(set, attmap_shadow_shadowWarning);
  attmap_add_attributes(set, attmap_shadow_shadowInactive);
  attmap_add_attributes(set, attmap_shadow_shadowExpire);
  attmap_add_attributes(set, attmap_shadow_shadowFlag);
  shadow_attrs = set_tolist(set);
  if (shadow_attrs == NULL)
  {
    log_log(LOG_CRIT, "malloc() failed to allocate memory");
    exit(EXIT_FAILURE);
  }
  set_free(set);
}
コード例 #25
0
ファイル: localectl.c プロジェクト: felipec/udev-fc
static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
        char _cleanup_strv_free_ **l = NULL;
        char **i;

        keymaps = set_new(string_hash_func, string_compare_func);
        if (!keymaps)
                return log_oom();

        nftw("/usr/share/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
        nftw("/usr/lib/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
        nftw("/lib/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);

        l = set_get_strv(keymaps);
        if (!l) {
                set_free_free(keymaps);
                return log_oom();
        }

        set_free(keymaps);

        if (strv_isempty(l)) {
                log_error("Couldn't find any console keymaps.");
                return -ENOENT;
        }

        strv_sort(l);

        pager_open_if_enabled();

        STRV_FOREACH(i, l)
                puts(*i);


        return 0;
}
コード例 #26
0
ファイル: killall.c プロジェクト: kwirk/systemd
void broadcast_signal(int sig, bool wait_for_exit) {
        sigset_t mask, oldmask;
        Set *pids = NULL;

        if (wait_for_exit)
                pids = set_new(trivial_hash_func, trivial_compare_func);

        assert_se(sigemptyset(&mask) == 0);
        assert_se(sigaddset(&mask, SIGCHLD) == 0);
        assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) == 0);

        if (kill(-1, SIGSTOP) < 0 && errno != ESRCH)
                log_warning("kill(-1, SIGSTOP) failed: %m");

        killall(sig, pids);

        if (kill(-1, SIGCONT) < 0 && errno != ESRCH)
                log_warning("kill(-1, SIGCONT) failed: %m");

        if (wait_for_exit)
                wait_for_children(pids, &mask);

        assert_se(sigprocmask(SIG_SETMASK, &oldmask, NULL) == 0);

        set_free(pids);
}
コード例 #27
0
ファイル: sqlite.c プロジェクト: anthonybishopric/libcrange
static set* _get_clusters(range_request* rr)
{
    const char** all_clusters = _all_clusters(rr);
    const char** p_cl = all_clusters;
    apr_pool_t* pool = range_request_pool(rr);
    set* node_cluster = set_new(pool, 40000);

    if(p_cl == NULL) {
        return node_cluster;
    }

    while (*p_cl) {
        range* nodes_r = _expand_cluster(rr, *p_cl, "CLUSTER");
        const char** nodes = range_get_hostnames(pool, nodes_r);
        const char** p_nodes = nodes;

        while (*p_nodes) {
            apr_array_header_t* clusters = set_get_data(node_cluster, *p_nodes);

            if (!clusters) {
                clusters = apr_array_make(pool, 1, sizeof(char*));
                set_add(node_cluster, *p_nodes, clusters);
            }

            *(const char**)apr_array_push(clusters) = *p_cl;
            ++p_nodes;
        }
        ++p_cl;
    }

    return node_cluster;
}
コード例 #28
0
ファイル: tw.c プロジェクト: Alberne/tinyprograme
int main(int argc, char *argv[]) {
	
	//从收银系统导入商品库存数据 
	struct set_t *products; //库存商品集合 
	struct sales_promotion *product_promotion; //优惠活动信息
	char shopping[] = "[\
				'ITEM00001-3',\
				'ITEM00002-2',\
				'ITEM00003-6'\
			]"; /*购物车商品*/
	
	
	struct set_t *shopping_set; //购物车商品集合
	
	shopping_set = set_new(100, compare_product, hashcode);
	//取得库存商品,打印小票时需要
	products = get_products();
	
	//取得优惠活动信息,结算时需要
	product_promotion = get_promotion();
    
	//取得购物车商品集合,结算时需要
    	prase_JSON_array(shopping, shopping_set, pack_cart); 
	 
	//结算
	pay(products, product_promotion, shopping_set);
	
	return 0;
}
コード例 #29
0
ファイル: test_set.c プロジェクト: hoyeonKim/glean
/* 0 files to go -> "0s " */
TEST word_adds_find_dupes() {
    set *s = set_new(2, dumb_hash, cmp);
    int duplicates[word_count];
    bzero(duplicates, word_count * sizeof(int));

    for (int i=0; i<word_count; i++) {
        char *w = words[i];
        ASSERT(w);
        if (set_known(s, w)) {
            duplicates[i] = 1;
        } else {
            if (set_store(s, (void *) w) == TABLE_SET_FAIL) FAIL();
        }
    }

    for (int i=0; i<word_count; i++) {
        if (0) printf("%d - %s %d\n", i, words[i], duplicates[i]);
    }

    for (int i=0; i<18; i++) {
        ASSERT_EQm("none of the first 18 are duplicates", 0, duplicates[i]);
    }

    ASSERT_EQm("words[19] (\"onion\") is a dup", 1, duplicates[19]);
    ASSERT_EQm("the last word (\"fennel\") is a dup", 1, duplicates[word_count - 1]);

    set_free(s, NULL);
    PASS();
}
コード例 #30
0
ファイル: flow.c プロジェクト: EIREXE/Quakeforge-gcw0
static void
flow_kill_aliases (set_t *kill, flowvar_t *var, const set_t *uninit)
{
	operand_t  *op;
	set_t      *tmp;

	set_union (kill, var->define);
	op = var->op;
	tmp = set_new ();
	if (op->op_type == op_temp) {
		if (op->o.tempop.alias) {
			op = op->o.tempop.alias;
			var = op->o.tempop.flowvar;
			if (var)
				set_union (tmp, var->define);
		}
		for (op = op->o.tempop.alias_ops; op; op = op->next) {
			var = op->o.tempop.flowvar;
			if (var)
				set_union (tmp, var->define);
		}
	} else if (op->op_type == op_def) {
		def_visit_all (op->o.def, 1, flow_kill_aliases_visit, tmp);
		// don't allow aliases to kill definitions in the entry dummy block
		set_difference (tmp, uninit);
	}
	// merge the alias kills with the current def's kills
	set_union (kill, tmp);
}