当前位置: 首页>>代码示例>>C++>>正文


C++ xnmalloc函数代码示例

本文整理汇总了C++中xnmalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ xnmalloc函数的具体用法?C++ xnmalloc怎么用?C++ xnmalloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xnmalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_insert_any_remove_reverse

/* Inserts strings into a set in each possible order, then
   removes them in reverse order, up to a specified maximum
   size. */
static void
test_insert_any_remove_reverse (void)
{
  const int max_elems = 7;
  int cnt;

  for (cnt = 0; cnt <= max_elems; cnt++)
    {
      int *insertions, *deletions;
      unsigned int permutation_cnt;
      int i;

      insertions = xnmalloc (cnt, sizeof *insertions);
      deletions = xnmalloc (cnt, sizeof *deletions);
      for (i = 0; i < cnt; i++)
        insertions[i] = i;

      for (permutation_cnt = 0;
           permutation_cnt == 0 || next_permutation (insertions, cnt);
           permutation_cnt++)
        {
          memcpy (deletions, insertions, sizeof *insertions * cnt);
          reverse (deletions, cnt);

          test_insert_delete (insertions, deletions, cnt);
        }
      check (permutation_cnt == factorial (cnt));

      free (insertions);
      free (deletions);
    }
}
开发者ID:student-t,项目名称:PSPP,代码行数:35,代码来源:stringi-set-test.c

示例2: xstring_init

struct _xstring* xstring_init(void)
{
	struct _xstring *p = (struct _xstring *) xnmalloc(sizeof(struct _xstring));
	bzero(p, sizeof(struct _xstring));

	p->cur_size		= INIT_STRING_LENGTH;
	p->content		= (char *) xnmalloc(p->cur_size * sizeof(char));
	p->keycode		= (KeyCode *) xnmalloc(p->cur_size * sizeof(KeyCode));
	p->keycode_modifiers	= (int *) xnmalloc(p->cur_size * sizeof(int));

	bzero(p->content, p->cur_size * sizeof(char));
	bzero(p->keycode, p->cur_size * sizeof(KeyCode));
	bzero(p->keycode_modifiers, p->cur_size * sizeof(int));

	// Functions mapping
	p->clear		= xstring_clear;
	p->is_space_last	= xstring_is_space_last;
	p->set_key_code		= xstring_set_key_code;
	p->set_content		= xstring_set_content;
	p->changecase_content = xstring_changecase_content;
	p->add_symbol		= xstring_add_symbol;
	p->del_symbol		= xstring_del_symbol;
	p->uninit		= xstring_uninit;

	return p;
}
开发者ID:voidptr,项目名称:xneur-option,代码行数:26,代码来源:xstring.c

示例3: test_random_sequence

/* Inserts and removes strings in a set, in random order. */
static void
test_random_sequence (void)
{
  const int max_elems = 64;
  const int max_trials = 8;
  int cnt;

  for (cnt = 0; cnt <= max_elems; cnt += 2)
    {
      int *insertions, *deletions;
      int trial;
      int i;

      insertions = xnmalloc (cnt, sizeof *insertions);
      deletions = xnmalloc (cnt, sizeof *deletions);
      for (i = 0; i < cnt; i++)
        insertions[i] = i;
      for (i = 0; i < cnt; i++)
        deletions[i] = i;

      for (trial = 0; trial < max_trials; trial++)
        {
          random_shuffle (insertions, cnt, sizeof *insertions);
          random_shuffle (deletions, cnt, sizeof *deletions);

          test_insert_delete (insertions, deletions, cnt);
        }

      free (insertions);
      free (deletions);
    }
}
开发者ID:student-t,项目名称:PSPP,代码行数:33,代码来源:stringi-set-test.c

示例4: xkeymap_init

struct _xkeymap* xkeymap_init(void)
{
	struct _xkeymap *p = (struct _xkeymap *) xnmalloc(sizeof(struct _xkeymap));
	bzero(p, sizeof(struct _xkeymap));

	p->latin_group = 0;
	p->latin_group_mask = 0;				// Define latin group mask
	
	p->alphabet = xnmalloc(1);
	
	if (!xkeymap_init_keymaps(p))
		return NULL;
	
	if (!xkeymap_locale_create(p))
		return NULL;
	
	if (!xkeymap_define_latin_group(p))
		return NULL;
	
	p->get_ascii = xkeymap_get_ascii;
	p->get_cur_ascii_char = xkeymap_get_cur_ascii_char;
	p->convert_text_to_ascii = xkeymap_convert_text_to_ascii;
	p->store_keymaps = xkeymap_store_keymaps;
	p->char_to_keycode = xkeymap_char_to_keycode;
	return p;
}
开发者ID:voidptr,项目名称:xneur-option,代码行数:26,代码来源:xkeymap.c

示例5: relation_transpose

void
relation_transpose (relation *R_arg, relation_node n)
{
  relation r = *R_arg;
  /* The result. */
  relation new_R = xnmalloc (n, sizeof *new_R);
  /* END_R[I] -- next entry of NEW_R[I]. */
  relation end_R = xnmalloc (n, sizeof *end_R);
  /* NEDGES[I] -- total size of NEW_R[I]. */
  size_t *nedges = xcalloc (n, sizeof *nedges);
  relation_node i;
  relation_node j;

  if (trace_flag & trace_sets)
    {
      fputs ("relation_transpose: input\n", stderr);
      relation_print (r, n, stderr);
    }

  /* Count. */
  for (i = 0; i < n; i++)
    if (r[i])
      for (j = 0; r[i][j] != END_NODE; ++j)
        ++nedges[r[i][j]];

  /* Allocate. */
  for (i = 0; i < n; i++)
    {
      relation_node *sp = NULL;
      if (nedges[i] > 0)
        {
          sp = xnmalloc (nedges[i] + 1, sizeof *sp);
          sp[nedges[i]] = END_NODE;
        }
      new_R[i] = sp;
      end_R[i] = sp;
    }

  /* Store. */
  for (i = 0; i < n; i++)
    if (r[i])
      for (j = 0; r[i][j] != END_NODE; ++j)
        *end_R[r[i][j]]++ = i;

  free (nedges);
  free (end_R);

  /* Free the input: it is replaced with the result. */
  for (i = 0; i < n; i++)
    free (r[i]);
  free (r);

  if (trace_flag & trace_sets)
    {
      fputs ("relation_transpose: output\n", stderr);
      relation_print (new_R, n, stderr);
    }

  *R_arg = new_R;
}
开发者ID:AnotherView,项目名称:bison,代码行数:60,代码来源:relation.c

示例6: xkeymap_store_keymaps

static void xkeymap_store_keymaps(struct _xkeymap *p, int group)
{
	int min_keycode, max_keycode, keysyms_per_keycode;
	KeySym *keymap;
	XDisplayKeycodes (main_window->display, &min_keycode, &max_keycode);
	keymap = XGetKeyboardMapping (main_window->display, min_keycode, max_keycode - min_keycode + 1, &keysyms_per_keycode);
	
	p->min_keycode = min_keycode;
	p->max_keycode = max_keycode;
	if (p->total_key_arrays < group) 
		p->total_key_arrays = group;
	
	p->alphabet = xnrealloc(p->alphabet, (group + 1) * sizeof(struct _xkeymap_alpha));
	p->alphabet[group] = xnmalloc((max_keycode + 1) * sizeof(struct _xkeymap_alpha));
		
	for (int i = min_keycode; i <= max_keycode; i++) 
	{
		int  j;
		p->alphabet[group][i].lower_sym = xnmalloc(1);
		p->alphabet[group][i].lower_sym[0] = NULLSYM;
		p->alphabet[group][i].upper_sym = xnmalloc(1);
		p->alphabet[group][i].upper_sym[0] = NULLSYM;
		for (j = group*2; j <= group*2 + 1; j++) 
		{
			KeySym ks = keymap[j];

			int groups[4] = {0x00000000, 0x00002000, 0x00004000, 0x00006000};
			if (ks != NoSymbol)
			{
				XEvent event = create_basic_event();
				event.xkey.keycode		= i;
				event.xkey.state		= groups[group];
				if (j == group*2 + 1)
					event.xkey.state |= ShiftMask;
				int nbytes;
    			char str[256+1];
				nbytes = XLookupString ((XKeyEvent *) &event, str, 256, &ks, NULL);
				
				if (nbytes > 0)
				{
					if (j == group*2)
					{
						p->alphabet[group][i].lower_sym = xnmalloc(nbytes+1);
						strncpy(p->alphabet[group][i].lower_sym, str, nbytes+1);
						p->alphabet[group][i].lower_sym[nbytes] = NULLSYM;
					}
					else
					{
						p->alphabet[group][i].upper_sym = xnmalloc(nbytes+1);
						strncpy(p->alphabet[group][i].upper_sym, str, nbytes+1);
						p->alphabet[group][i].upper_sym[nbytes] = NULLSYM;
					}
				}
			}
		}
		keymap += keysyms_per_keycode;
    }
}
开发者ID:voidptr,项目名称:xneur-option,代码行数:58,代码来源:xkeymap.c

示例7: readtokens

size_t
readtokens (FILE *stream,
            size_t projected_n_tokens,
            const char *delim,
            size_t n_delim,
            char ***tokens_out,
            size_t **token_lengths)
{
  token_buffer tb, *token = &tb;
  char **tokens;
  size_t *lengths;
  size_t sz;
  size_t n_tokens;

  if (projected_n_tokens == 0)
    projected_n_tokens = 64;
  else
    projected_n_tokens++;       /* add one for trailing NULL pointer */

  sz = projected_n_tokens;
  tokens = xnmalloc (sz, sizeof *tokens);
  lengths = xnmalloc (sz, sizeof *lengths);

  n_tokens = 0;
  init_tokenbuffer (token);
  for (;;)
    {
      char *tmp;
      size_t token_length = readtoken (stream, delim, n_delim, token);
      if (n_tokens >= sz)
        {
          tokens = x2nrealloc (tokens, &sz, sizeof *tokens);
          lengths = xnrealloc (lengths, sz, sizeof *lengths);
        }

      if (token_length == (size_t) -1)
        {
          /* don't increment n_tokens for NULL entry */
          tokens[n_tokens] = NULL;
          lengths[n_tokens] = 0;
          break;
        }
      tmp = xnmalloc (token_length + 1, sizeof *tmp);
      lengths[n_tokens] = token_length;
      tokens[n_tokens] = memcpy (tmp, token->buffer, token_length + 1);
      n_tokens++;
    }

  free (token->buffer);
  *tokens_out = tokens;
  if (token_lengths != NULL)
    *token_lengths = lengths;
  else
    free (lengths);
  return n_tokens;
}
开发者ID:SamB,项目名称:debian-coreutils,代码行数:56,代码来源:readtokens.c

示例8: allocate_storage

static void
allocate_storage (void)
{
  allocate_itemsets ();

  shiftset = xnmalloc (nsyms, sizeof *shiftset);
  redset = xnmalloc (nrules, sizeof *redset);
  state_hash_new ();
  shift_symbol = xnmalloc (nsyms, sizeof *shift_symbol);
}
开发者ID:a170785,项目名称:buildroot,代码行数:10,代码来源:LR0.c

示例9: nonterminals_reduce

static void
nonterminals_reduce (void)
{
  /* Map the nonterminals to their new index: useful first, useless
     afterwards.  Kept for later report.  */

  symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap);
  symbol_number n = ntokens;
  symbol_number i;
  for (i = ntokens; i < nsyms; i++)
    if (bitset_test (V, i))
      nontermmap[i - ntokens] = n++;
  for (i = ntokens; i < nsyms; i++)
    if (!bitset_test (V, i))
      {
        nontermmap[i - ntokens] = n++;
        if (symbols[i]->status != used)
          complain (&symbols[i]->location, Wother,
                    _("nonterminal useless in grammar: %s"),
                    symbols[i]->tag);
      }


  /* Shuffle elements of tables indexed by symbol number.  */
  {
    symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted);

    for (i = ntokens; i < nsyms; i++)
      symbols[i]->number = nontermmap[i - ntokens];
    for (i = ntokens; i < nsyms; i++)
      symbols_sorted[nontermmap[i - ntokens] - ntokens] = symbols[i];
    for (i = ntokens; i < nsyms; i++)
      symbols[i] = symbols_sorted[i - ntokens];
    free (symbols_sorted);
  }

  {
    rule_number r;
    for (r = 0; r < nrules; ++r)
      {
        item_number *rhsp;
        for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
          if (ISVAR (*rhsp))
            *rhsp =  symbol_number_as_item_number (nontermmap[*rhsp
                                                              - ntokens]);
      }
    accept->number = nontermmap[accept->number - ntokens];
  }

  nsyms -= nuseless_nonterminals;
  nvars -= nuseless_nonterminals;

  free (nontermmap);
}
开发者ID:epicgithub,项目名称:VisualBison,代码行数:54,代码来源:reduce.c

示例10: derives_compute

void
derives_compute (void)
{
  symbol_number i;
  rule_number r;
  rule **q;

  /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
     whose LHS is NTERM.  */
  rule_list **dset = xcalloc (nvars, sizeof *dset);

  /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
     Instead of performing NRULES allocations for each, have an array
     indexed by rule numbers.  */
  rule_list *delts = xnmalloc (nrules, sizeof *delts);

  for (r = nrules - 1; r >= 0; --r)
    {
      symbol_number lhs = rules[r].lhs->number;
      rule_list *p = &delts[r];
      /* A new LHS is found.  */
      p->next = dset[lhs - ntokens];
      p->value = &rules[r];
      dset[lhs - ntokens] = p;
    }

  /* DSET contains what we need under the form of a linked list.  Make
     it a single array.  */

  derives = xnmalloc (nvars, sizeof *derives);
  q = xnmalloc (nvars + nrules, sizeof *q);

  for (i = ntokens; i < nsyms; i++)
    {
      rule_list *p = dset[i - ntokens];
      derives[i - ntokens] = q;
      while (p)
        {
          *q++ = p->value;
          p = p->next;
        }
      *q++ = NULL;
    }

  if (trace_flag & trace_sets)
    print_derives ();

  free (dset);
  free (delts);
}
开发者ID:AnotherView,项目名称:bison,代码行数:50,代码来源:derives.c

示例11: elog_setoverride

/* sets a pattern to override the severity stated by the program
 * or application for an error. The pattern is applied to the event text
 * each time _send() is called. Each override will take some space
 * so unused ones should be discarded with _rmoverride().
 * returns 1 if successfully added to list, or 0 if unable to add.
 */
int elog_setoverride(enum elog_severity severity,	/* severity level */
		     char *re_pattern			/* reg exp pattern */ )
{
     int r;
     char errbuf[ELOG_STRLEN];
     struct elog_overridedat *over;

     elog_checkinit();

     /* severity in range? */
     if (severity >= ELOG_NSEVERITIES || severity < 0)
	  return 0;

     over = xnmalloc(sizeof(struct elog_overridedat));
     if ((r = regcomp(&over->pattern, re_pattern, (REG_EXTENDED|REG_NOSUB)))) {
	  regerror(r, &over->pattern, errbuf, ELOG_STRLEN);
	  elog_printf(ERROR, "elog_setoverride() problem with key "
		      "pattern: %s\nError is %s\n", re_pattern, errbuf);
	  nfree(over);
	  return 0;
     }

     over->severity = severity;
     tree_add(elog_override, xnstrdup(re_pattern), over);

     return 1;
}
开发者ID:SystemGarden,项目名称:habitat,代码行数:33,代码来源:elog.c

示例12: get_file_content

char* get_file_content(const char *file_name)
{
	struct stat sb;

	if (stat(file_name, &sb) != 0 || sb.st_size < 0)
		return NULL;

	FILE *stream = fopen(file_name, "rb");
	if (stream == NULL)
		return NULL;

	unsigned int file_len = sb.st_size;
	
	char *content = (char *) xnmalloc((file_len + 2) * sizeof(char)); // + 1 '\n' + 1 '\0'
	if (fread(content, 1, file_len, stream) != file_len)
	{
		free(content);
		fclose(stream);
		return NULL;
	}

	content[file_len] = '\n';
	content[file_len + 1] = '\0';
	fclose(stream);

	return content;
}
开发者ID:voidptr,项目名称:xneur-option,代码行数:27,代码来源:xnconfig_files.c

示例13: test_insert_ordered

/* Inserts strings into a map in ascending order, then delete in ascending
   order. */
static void
test_insert_ordered (void)
{
  const int max_elems = 64;
  int *values;
  struct string_map map;
  int i;

  string_map_init (&map);
  values = xnmalloc (max_elems, sizeof *values);
  for (i = 0; i < max_elems; i++)
    {
      values[i] = i | random_value (i, 4);
      string_map_insert_nocopy (&map, xstrdup (make_key (values[i])),
                                xstrdup (make_value (values[i])));
      check_string_map (&map, values, i + 1);
    }
  for (i = 0; i < max_elems; i++)
    {
      string_map_delete (&map, make_key (i));
      check_string_map (&map, values + i + 1, max_elems - i - 1);
    }
  string_map_destroy (&map);
  free (values);
}
开发者ID:RobertDash,项目名称:pspp,代码行数:27,代码来源:string-map-test.c

示例14: convert_text_to_translit

char* convert_text_to_translit(const char *text)
{
	int i, j, len = strlen(text);

	char *trans_text = (char *)xnmalloc((len * 3 + 1) * sizeof(char));

	for(i = 0, j = 0; i < len; i++)
	{
		if (isascii(text[i]))
		{
			trans_text[j++] = text[i];
			continue;
		}

		const char *new_symbol = get_translit(&text[i]);

		for(; i < len - 1; i++)
		{
			if (isascii(text[i + 1]))
				break;
			if (get_translit(&text[i + 1]) != NULLSYM)
				break;
		}

		while (*new_symbol != NULLSYM)
		{
			trans_text[j++] = *new_symbol;
			new_symbol++;
		}
	}

	trans_text[j] = NULLSYM;
	return trans_text;
}
开发者ID:voidptr,项目名称:xneur-option,代码行数:34,代码来源:conversion.c

示例15: backtrace_log

void backtrace_log(int retval, const char *fn,
		   const char *file, int lineno)
{
	struct backtrace_data *btd;
	struct error_frame *ef;

	btd = pthread_getspecific(btkey);
	if (btd == NULL)
		btd = &main_btd;

	ef = xnmalloc(sizeof(*ef));
	if (ef == NULL)
		return;

	ef->retval = retval;
	ef->lineno = lineno;
	ef->fn = fn;
	ef->file = file;

	write_lock(&btd->lock);

	if (btd->inner == NULL)
		/* Fire the hook for the inner trace. */
		error_hook(ef);

	ef->next = btd->inner;
	btd->inner = ef;

	write_unlock(&btd->lock);
}
开发者ID:BhargavKola,项目名称:xenomai-forge,代码行数:30,代码来源:debug.c


注:本文中的xnmalloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。