<commit_before><?php
/*
 * PHP-GTK - The PHP language bindings for GTK+
 *
 * Copyright (C) 2001 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id$ */

/*======================================================================*\
	Function: convert_typename
	Purpose:  Converts a typename to the uppercased and underscored
			  version used for type conversion macros and enum/flag
			  names.
\*======================================================================*/
function convert_typename($typename)
{
	preg_match_all('![A-Z]+[^A-Z]*!', $typename, $match);
	return '_' . strtoupper(implode('_', $match[0]));
}

/*======================================================================*\
	Function: enum_name
	Purpose:  Creates a GTK_TYPE_* name from the give typename
\*======================================================================*/
function enum_name($typename)
{
	$proper = convert_typename($typename);
	if (strlen($proper) > 4 && substr($proper, 0, 4) == '_GTK')
		return 'GTK_TYPE' . substr($proper, 4);
	else
		return 'GTK_TYPE' . $proper;
}

/*======================================================================*\
	Class:   Var_List
	Purpose: Format C variable list 
\*======================================================================*/
class Var_List {
	var $vars = array();

	function add($c_type, $name)
	{
		$this->vars[$c_type][] = $name;
	}

	function to_string()
	{
		$result = array();
		foreach (array_keys($this->vars) as $c_type)
			$result[] = "\t$c_type " . implode(', ', $this->vars[$c_type]) .  ";\n";
		if (count($result)) {
			$result[] = "\n";
			return implode('', $result);
		} else
			return '';
	}
}

/*======================================================================*\
	Class:    Arg_Type
	Purpose:  Base class for argument type handlers
\*======================================================================*/
class Arg_Type {
	function write_param($type, $name, $default, $null_ok, &$var_list,
						 &$parse_list, &$arg_list, &$extra_pre_code, &$extra_post_code, $in_constructor)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}
	
	function write_return($type, &$var_list, $separate)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}

	function write_to_prop($obj, $name, $source)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}

	function write_from_prop($name)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}
}

class None_Arg extends Arg_Type {
	function write_return($type, &$var_list, $separate)
	{
		return "	%s;\n" .
			   "	RETURN_NULL();";
	}
}

class String_Arg extends Arg_Type {
	function write_param($type, $name, $default, $null_ok, &$var_list,
						 &$parse_list, &$arg_list, &$extra_pre_code, &$extra_post_code, $in_constructor)
	{
		if (isset($default)) {
			if ($default != 'NULL')
				$default = '"' . $default . '"';
			$var_list->add('char', '*' . $name . ' = ' . $default);
		} else
			$var_list->add('char', '*' . $name);
		$parse_list[] 	= '&' . $name;

		if (strtoupper(substr(PHP_OS, 0,3) == "WIN")) {
			$var_list->add('gchar', '*utf8_' . $name);
			$arg_list[]   = 'utf8_' . $name;
			$extra_post_code[]   = "\tg_free(utf8_$name);\n";
			$extra_pre_code[] = "\tutf8_$name = g_convert($name, strlen($name), \"UTF-8\", \"CP1252\", NULL, NULL, NULL);\n";
		} else
			$arg_list[] = $name;

		return 's';
	}
	
	function write_return($type, &$var_list, $separate)
	{
		if (in_array($type, array('const-gchar*', 'const-char*', 'static_string'))) {
			$var_list->add('const gchar', '*ret');<commit_msg>Fix for crash in ctree under windows, This was a problem with the UTF-8 stuff on windows.<commit_after><?php
/*
 * PHP-GTK - The PHP language bindings for GTK+
 *
 * Copyright (C) 2001 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id$ */

/*======================================================================*\
	Function: convert_typename
	Purpose:  Converts a typename to the uppercased and underscored
			  version used for type conversion macros and enum/flag
			  names.
\*======================================================================*/
function convert_typename($typename)
{
	preg_match_all('![A-Z]+[^A-Z]*!', $typename, $match);
	return '_' . strtoupper(implode('_', $match[0]));
}

/*======================================================================*\
	Function: enum_name
	Purpose:  Creates a GTK_TYPE_* name from the give typename
\*======================================================================*/
function enum_name($typename)
{
	$proper = convert_typename($typename);
	if (strlen($proper) > 4 && substr($proper, 0, 4) == '_GTK')
		return 'GTK_TYPE' . substr($proper, 4);
	else
		return 'GTK_TYPE' . $proper;
}

/*======================================================================*\
	Class:   Var_List
	Purpose: Format C variable list 
\*======================================================================*/
class Var_List {
	var $vars = array();

	function add($c_type, $name)
	{
		$this->vars[$c_type][] = $name;
	}

	function to_string()
	{
		$result = array();
		foreach (array_keys($this->vars) as $c_type)
			$result[] = "\t$c_type " . implode(', ', $this->vars[$c_type]) .  ";\n";
		if (count($result)) {
			$result[] = "\n";
			return implode('', $result);
		} else
			return '';
	}
}

/*======================================================================*\
	Class:    Arg_Type
	Purpose:  Base class for argument type handlers
\*======================================================================*/
class Arg_Type {
	function write_param($type, $name, $default, $null_ok, &$var_list,
						 &$parse_list, &$arg_list, &$extra_pre_code, &$extra_post_code, $in_constructor)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}
	
	function write_return($type, &$var_list, $separate)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}

	function write_to_prop($obj, $name, $source)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}

	function write_from_prop($name)
	{
		trigger_error("This is an abstract class", E_USER_ERROR);
	}
}

class None_Arg extends Arg_Type {
	function write_return($type, &$var_list, $separate)
	{
		return "	%s;\n" .
			   "	RETURN_NULL();";
	}
}

class String_Arg extends Arg_Type {
	function write_param($type, $name, $default, $null_ok, &$var_list,
						 &$parse_list, &$arg_list, &$extra_pre_code, &$extra_post_code, $in_constructor)
	{
		if (isset($default)) {
			if ($default != 'NULL')
				$default = '"' . $default . '"';
			$var_list->add('char', '*' . $name . ' = ' . $default);
		} else
			$var_list->add('char', '*' . $name);
		$parse_list[] 	= '&' . $name;

		if (strtoupper(substr(PHP_OS, 0,3) == "WIN")) {
			$var_list->add('gchar', '*utf8_' . $name . ' = NULL');
			$arg_list[]   = 'utf8_' . $name;
			$extra_post_code[]   = "\tif (utf8_$name) g_free(utf8_$name);\n";
			$extra_pre_code[] = "\tif ($name) utf8_$name = g_convert($name, strlen($name), \"UTF-8\", \"CP1252\", NULL, NULL, NULL);\n";
		} else
			$arg_list[] = $name;

		return 's';
	}
	
	function write_return($type, &$var_list, $separate)
	{
		if (in_array($type, array('const-gchar*', 'const-char*', 'static_string'))) {
			$var_list->add('const gchar', '*ret');
{'fraction_non_alphanumeric': 0.2731262270470031, 'fraction_numerical': 0.008546021480540478, 'mean_word_length': 4.674967234600262, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '202188', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2675, 'n_words': 744}