Esempio n. 1
0
/*
 * Walker function to find a function call which is supposed to write
 * database.
 */
static bool function_call_walker(Node *node, void *context)
{
	SelectContext	*ctx = (SelectContext *) context;

	if (node == NULL)
		return false;

	if (IsA(node, FuncCall))
	{
		FuncCall *fcall = (FuncCall *)node;
		char *fname;
		int length = list_length(fcall->funcname);

		if (length > 0)
		{
			if (length == 1)	/* no schema qualification? */
			{
				fname = strVal(linitial(fcall->funcname));
			}
			else
			{
				fname = strVal(lsecond(fcall->funcname));		/* with schema qualification */
			}

			pool_debug("function_call_walker: function name: %s", fname);

			/*
			 * Check white list if any.
			 */
			if (pool_config->num_white_function_list > 0)
			{
				/* Search function in the white list regex patterns */
				if (pattern_compare(fname, WHITELIST, "white_function_list") == 1) {
					/* If the function is found in the white list, we can ignore it */
					return raw_expression_tree_walker(node, function_call_walker, context);
				}
				/*
				 * Since the function was not found in white list, we
				 * have found a writing function.
				 */
				ctx->has_function_call = true;
				return false;
			}

			/*
			 * Check black list if any.
			 */
			if (pool_config->num_black_function_list > 0)
			{
				/* Search function in the black list regex patterns */
				if (pattern_compare(fname, BLACKLIST, "black_function_list") == 1) {
					/* Found. */
					ctx->has_function_call = true;
					return false;
				}
			}
		}
	}
	return raw_expression_tree_walker(node, function_call_walker, context);
}
Esempio n. 2
0
word_hyphenation_t* hyphenate_word(const unichar* word, const pattern_list_t* pattern_list, unichar marker)
{
	if (!word || !pattern_list) 
		return 0;
	
	std::basic_string<unichar> word_string;
	word_string.push_back(marker);
	word_string.append(word);
	word_string.push_back(marker);

	word_hyphenation_t* wh = new word_hyphenation_t;
	wh->mask = 0;
	wh->mask_size = 0;
	
	std::vector<unsigned char> levels;
	levels.assign(word_string.size(), 0);
	
	for (size_t i = 0; i < word_string.size()-2; ++i)
	{
		std::vector<pattern_t*>::const_iterator pattern_iter = pattern_list->list.begin();
		for (size_t count = 1; count <= word_string.size()-i; ++count)
		{
			pattern_t pattern_from_word;
			pattern_from_word.str = word_string.substr(i, count);
			if (pattern_compare(&pattern_from_word, *pattern_iter))
				continue;
			pattern_iter = std::lower_bound(pattern_iter, pattern_list->list.end(), &pattern_from_word, pattern_compare);
			if (pattern_iter == pattern_list->list.end())
				break;
			if (!pattern_compare(&pattern_from_word, *pattern_iter)) 
			{
				for (size_t level_i = 0; level_i < (*pattern_iter)->levels.size(); ++level_i)
				{
					unsigned char l = (*pattern_iter)->levels[level_i];
					if (l > levels[i+level_i]) 
						levels[i+level_i] = l;
				}
			}
		}
	}

	wh->mask_size = levels.size()-2;
	wh->mask = new unsigned char[wh->mask_size];
	for (size_t i = 0; i < wh->mask_size; ++i)
	{
		if (levels[i+1] % 2 && i) 
			wh->mask[i] = 1;
		else 
			wh->mask[i] = 0;
	}
	
	return wh;
}
Esempio n. 3
0
FcFontSet * fcinfo(const FcConfig *config, const FcPattern *pattern, 
                   FcBool remove_duplicities, int argnum, ...)
{
  va_list va;
  const char *elements[argnum + 1];
  int a;

  FcFontSet *fontset;
  FcObjectSet *objectset;

  FcInit();
  objectset = FcObjectSetCreate();

  va_start(va, argnum);
  for (a = 0; a < argnum; a++)
  {
    elements[a] = va_arg(va, const char *);
    FcObjectSetAdd(objectset, elements[a]);
  }
  va_end(va);

  fontset = FcFontList((FcConfig *)config, (FcPattern *)pattern, objectset);
  elements[argnum] = NULL;
  font_set_sort(fontset, elements);

  FcObjectSetDestroy(objectset);

  if (remove_duplicities)
  {
    FcFontSet *result = FcFontSetCreate();
    int f;
    FcPattern *added = NULL;

    /* fontlist is linearly ordered */
    f = 0;
    while (f < fontset->nfont)
    {
      FcFontSetAdd(result, FcPatternDuplicate(fontset->fonts[f]));
      added = fontset->fonts[f++];
      while (f < fontset->nfont &&
             !pattern_compare(&fontset->fonts[f], &added, elements))
        f++;
    }

    FcFontSetDestroy(fontset);
    return result;
  }

  return fontset;
}
Esempio n. 4
0
/*
 * Walker function to find a function call which is supposed to write
 * database.
 */
static bool
function_call_walker(Node *node, void *context)
{
	SelectContext *ctx = (SelectContext *) context;

	if (node == NULL)
		return false;

	if (IsA(node, FuncCall))
	{
		FuncCall   *fcall = (FuncCall *) node;
		char	   *fname;
		int			length = list_length(fcall->funcname);

		if (length > 0)
		{
			if (length == 1)	/* no schema qualification? */
			{
				fname = strVal(linitial(fcall->funcname));
			}
			else
			{
				fname = strVal(lsecond(fcall->funcname));	/* with schema
															 * qualification */
			}

			ereport(DEBUG1,
					(errmsg("function call walker, function name: \"%s\"", fname)));

			if (ctx->pg_terminate_backend_pid == 0 && strcmp("pg_terminate_backend", fname) == 0)
			{
				if (list_length(fcall->args) == 1)
				{
					Node	   *arg = linitial(fcall->args);

					if (IsA(arg, A_Const) &&
						((A_Const *) arg)->val.type == T_Integer)
					{
						ctx->pg_terminate_backend_pid = ((A_Const *) arg)->val.val.ival;
						ereport(DEBUG1,
								(errmsg("pg_terminate_backend pid = %d", ctx->pg_terminate_backend_pid)));
					}
				}
			}

			/*
			 * Check white list if any.
			 */
			if (pool_config->num_white_function_list > 0)
			{
				/* Search function in the white list regex patterns */
				if (pattern_compare(fname, WHITELIST, "white_function_list") == 1)
				{
					/*
					 * If the function is found in the white list, we can
					 * ignore it
					 */
					return raw_expression_tree_walker(node, function_call_walker, context);
				}

				/*
				 * Since the function was not found in white list, we have
				 * found a writing function.
				 */
				ctx->has_function_call = true;
				return false;
			}

			/*
			 * Check black list if any.
			 */
			if (pool_config->num_black_function_list > 0)
			{
				/* Search function in the black list regex patterns */
				if (pattern_compare(fname, BLACKLIST, "black_function_list") == 1)
				{
					/* Found. */
					ctx->has_function_call = true;
					return false;
				}
			}
		}
	}
	return raw_expression_tree_walker(node, function_call_walker, context);
}