2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
gbx_api.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
This program 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 General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_API_C
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_common_case.h"
|
2008-06-11 12:44:50 +02:00
|
|
|
#include "gb_common_buffer.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gb_alloc.h"
|
2012-08-25 00:29:53 +02:00
|
|
|
#include "gb_list.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "gbx_class.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_event.h"
|
|
|
|
#include "gbx_stack.h"
|
|
|
|
#include "gbx_stream.h"
|
|
|
|
#include "gbx_library.h"
|
|
|
|
#include "gbx_watch.h"
|
|
|
|
#include "gbx_project.h"
|
|
|
|
#include "gbx_eval.h"
|
|
|
|
#include "gbx_local.h"
|
|
|
|
#include "gb_hash.h"
|
|
|
|
#include "gb_file.h"
|
|
|
|
#include "gbx_number.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
#include "gbx_string.h"
|
|
|
|
#include "gbx_date.h"
|
|
|
|
#include "gbx_regexp.h"
|
|
|
|
#include "gbx_c_array.h"
|
|
|
|
#include "gbx_c_timer.h"
|
|
|
|
#include "gbx_component.h"
|
|
|
|
#include "gbx_c_gambas.h"
|
2010-12-21 15:05:42 +01:00
|
|
|
#include "gbx_c_observer.h"
|
2010-02-21 19:15:16 +01:00
|
|
|
#include "gbx_debug.h"
|
2010-04-05 19:02:16 +02:00
|
|
|
#include "gbx_c_file.h"
|
2012-05-23 21:26:15 +02:00
|
|
|
#include "gbx_extern.h"
|
|
|
|
#include "gbx_compare.h"
|
|
|
|
#include "gbx_subr.h"
|
|
|
|
#include "gbx_math.h"
|
|
|
|
#include "gbx_struct.h"
|
2012-05-08 17:32:33 +02:00
|
|
|
#include "gbx_signal.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#include "gambas.h"
|
|
|
|
#include "gbx_api.h"
|
|
|
|
|
|
|
|
typedef
|
2012-02-19 17:13:38 +01:00
|
|
|
struct {
|
|
|
|
OBJECT *object;
|
|
|
|
CLASS_DESC_METHOD *desc;
|
|
|
|
}
|
|
|
|
GB_API_FUNCTION;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-08-25 17:13:39 +02:00
|
|
|
const void *const GAMBAS_Api[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)GB_VERSION,
|
|
|
|
|
|
|
|
(void *)GB_GetInterface,
|
|
|
|
|
|
|
|
(void *)GB_Hook,
|
|
|
|
|
|
|
|
(void *)GB_LoadComponent,
|
|
|
|
(void *)COMPONENT_exist,
|
|
|
|
(void *)GB_CurrentComponent,
|
|
|
|
(void *)COMPONENT_get_info,
|
2012-05-08 17:32:33 +02:00
|
|
|
(void *)COMPONENT_signal,
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
(void *)GB_Push,
|
|
|
|
(void *)GB_GetFunction,
|
|
|
|
(void *)GB_Call,
|
|
|
|
(void *)GB_GetClassInterface,
|
|
|
|
(void *)GB_GetProperty,
|
|
|
|
(void *)GB_SetProperty,
|
2012-08-26 03:54:57 +02:00
|
|
|
(void *)GB_Serialize,
|
|
|
|
(void *)GB_UnSerialize,
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
(void *)WATCH_one_loop,
|
2012-08-25 00:29:53 +02:00
|
|
|
(void *)GB_Wait,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)EVENT_post,
|
|
|
|
(void *)EVENT_post2,
|
|
|
|
(void *)CTIMER_every,
|
|
|
|
(void *)GB_Raise,
|
2012-02-25 02:35:55 +01:00
|
|
|
(void *)GB_RaiseBegin,
|
|
|
|
(void *)GB_RaiseEnd,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)EVENT_post_event,
|
|
|
|
(void *)EVENT_check_post,
|
|
|
|
(void *)GB_CanRaise,
|
|
|
|
(void *)GB_GetEvent,
|
|
|
|
(void *)GB_GetLastEventName,
|
|
|
|
(void *)CTIMER_raise,
|
|
|
|
(void *)GB_Stopped,
|
|
|
|
|
|
|
|
(void *)GB_NParam,
|
|
|
|
(void *)GB_Conv,
|
|
|
|
(void *)GB_GetUnknown,
|
|
|
|
|
|
|
|
(void *)GB_Error,
|
|
|
|
(void *)ERROR_propagate,
|
2012-08-15 19:02:22 +02:00
|
|
|
(void *)GB_Deprecated,
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
(void *)GB_GetClass,
|
|
|
|
(void *)GB_GetClassName,
|
|
|
|
(void *)GB_ExistClass,
|
|
|
|
(void *)CLASS_find_global,
|
|
|
|
(void *)GB_ExistClassLocal,
|
|
|
|
(void *)CLASS_find,
|
|
|
|
(void *)GB_Is,
|
|
|
|
(void *)GB_Ref,
|
|
|
|
(void *)GB_Unref,
|
|
|
|
(void *)GB_UnrefKeep,
|
|
|
|
(void *)GB_Detach,
|
|
|
|
(void *)GB_Attach,
|
|
|
|
(void *)OBJECT_parent,
|
2012-07-13 01:34:14 +02:00
|
|
|
(void *)GB_Create,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)GB_New,
|
|
|
|
(void *)CLASS_auto_create,
|
|
|
|
(void *)GB_CheckObject,
|
|
|
|
|
|
|
|
(void *)GB_GetEnum,
|
|
|
|
(void *)GB_StopEnum,
|
2012-09-06 18:20:54 +02:00
|
|
|
(void *)GB_BeginEnum,
|
|
|
|
(void *)GB_EndEnum,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)GB_NextEnum,
|
|
|
|
(void *)GB_StopAllEnum,
|
|
|
|
|
|
|
|
(void *)GB_Return,
|
|
|
|
(void *)GB_ReturnInteger,
|
|
|
|
(void *)GB_ReturnLong,
|
|
|
|
(void *)GB_ReturnPointer,
|
|
|
|
(void *)GB_ReturnBoolean,
|
|
|
|
(void *)GB_ReturnDate,
|
|
|
|
(void *)GB_ReturnObject,
|
|
|
|
(void *)GB_ReturnNull,
|
|
|
|
(void *)GB_ReturnFloat,
|
|
|
|
(void *)GB_ReturnVariant,
|
|
|
|
(void *)GB_ReturnConvVariant,
|
2012-08-18 15:06:58 +02:00
|
|
|
(void *)GB_ReturnBorrow,
|
|
|
|
(void *)GB_ReturnRelease,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)GB_ReturnPtr,
|
|
|
|
(void *)GB_ReturnSelf,
|
|
|
|
|
|
|
|
(void *)GB_ReturnString,
|
|
|
|
(void *)GB_ReturnVoidString,
|
|
|
|
(void *)GB_ReturnConstString,
|
|
|
|
(void *)GB_ReturnConstZeroString,
|
|
|
|
(void *)GB_ReturnNewString,
|
|
|
|
(void *)GB_ReturnNewZeroString,
|
|
|
|
|
|
|
|
(void *)STRING_new,
|
|
|
|
(void *)GB_NewZeroString,
|
|
|
|
(void *)GB_TempString,
|
|
|
|
(void *)GB_FreeString,
|
2012-07-15 15:07:57 +02:00
|
|
|
(void *)STRING_free_later,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)STRING_extend,
|
|
|
|
(void *)STRING_add,
|
|
|
|
(void *)STRING_add_char,
|
|
|
|
(void *)GB_StringLength,
|
|
|
|
(void *)GB_ToZeroString,
|
|
|
|
(void *)REGEXP_match,
|
|
|
|
(void *)NUMBER_from_string,
|
|
|
|
(void *)GB_NumberToString,
|
|
|
|
(void *)LOCAL_gettext,
|
|
|
|
|
|
|
|
(void *)STRING_subst,
|
|
|
|
(void *)STRING_subst_add,
|
|
|
|
(void *)STRING_make,
|
|
|
|
(void *)GB_ConvString,
|
|
|
|
(void *)STRING_conv_file_name,
|
|
|
|
(void *)GB_RealFileName,
|
|
|
|
|
|
|
|
(void *)GB_LoadFile,
|
|
|
|
(void *)STREAM_unmap,
|
|
|
|
(void *)GB_TempDir,
|
|
|
|
(void *)GB_TempFile,
|
|
|
|
(void *)GB_CopyFile,
|
|
|
|
(void *)GB_BrowseProject,
|
|
|
|
|
|
|
|
(void *)GB_Store,
|
|
|
|
(void *)GB_StoreString,
|
|
|
|
(void *)GB_StoreObject,
|
|
|
|
(void *)GB_StoreVariant,
|
2009-08-03 00:48:08 +02:00
|
|
|
(void *)VALUE_read,
|
2010-07-19 14:33:57 +02:00
|
|
|
(void *)GB_BorrowValue,
|
|
|
|
(void *)GB_ReleaseValue,
|
2012-08-29 23:02:09 +02:00
|
|
|
(void *)COMPARE_variant,
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)DATE_split,
|
|
|
|
(void *)DATE_make,
|
|
|
|
(void *)DATE_from_time,
|
|
|
|
(void *)DATE_timer,
|
|
|
|
|
|
|
|
(void *)GB_Watch,
|
|
|
|
|
|
|
|
(void *)GB_Eval,
|
|
|
|
|
|
|
|
(void *)GB_Alloc,
|
|
|
|
(void *)GB_Free,
|
|
|
|
(void *)GB_Realloc,
|
|
|
|
|
|
|
|
(void *)GB_NewArray,
|
|
|
|
(void *)ARRAY_delete,
|
|
|
|
(void *)GB_CountArray,
|
|
|
|
(void *)GB_Add,
|
|
|
|
(void *)ARRAY_insert_many,
|
|
|
|
(void *)ARRAY_remove_many,
|
|
|
|
|
|
|
|
(void *)GB_SubCollectionNew,
|
|
|
|
(void *)GB_SubCollectionAdd,
|
|
|
|
(void *)GB_SubCollectionRemove,
|
|
|
|
(void *)GB_SubCollectionGet,
|
|
|
|
(void *)GB_SubCollectionContainer,
|
|
|
|
|
|
|
|
(void *)GB_tolower,
|
|
|
|
(void *)GB_toupper,
|
|
|
|
(void *)strcasecmp,
|
|
|
|
(void *)strncasecmp,
|
|
|
|
|
|
|
|
(void *)GB_AppName,
|
|
|
|
(void *)GB_AppTitle,
|
|
|
|
(void *)GB_AppVersion,
|
|
|
|
(void *)GB_AppPath,
|
|
|
|
(void *)GB_AppStartupClass,
|
|
|
|
|
|
|
|
(void *)GB_SystemCharset,
|
|
|
|
(void *)LOCAL_get_lang,
|
|
|
|
(void *)GB_SystemDomainName,
|
|
|
|
(void *)GB_IsRightToLeft,
|
|
|
|
(void *)GB_SystemPath,
|
2012-08-25 00:29:53 +02:00
|
|
|
(void *)FILE_init,
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
(void *)GB_ArrayNew,
|
|
|
|
(void *)GB_ArrayCount,
|
|
|
|
(void *)GB_ArrayAdd,
|
|
|
|
(void *)GB_ArrayGet,
|
|
|
|
(void *)GB_ArrayType,
|
|
|
|
|
|
|
|
(void *)GB_CollectionNew,
|
|
|
|
(void *)GB_CollectionCount,
|
|
|
|
(void *)GB_CollectionSet,
|
|
|
|
(void *)GB_CollectionGet,
|
|
|
|
(void *)GB_CollectionEnum,
|
|
|
|
|
|
|
|
(void *)GB_HashTableNew,
|
|
|
|
(void *)HASH_TABLE_delete,
|
|
|
|
(void *)HASH_TABLE_size,
|
|
|
|
(void *)GB_HashTableAdd,
|
|
|
|
(void *)GB_HashTableRemove,
|
|
|
|
(void *)GB_HashTableGet,
|
|
|
|
(void *)GB_HashTableEnum,
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-04-05 19:02:16 +02:00
|
|
|
(void *)GB_StreamGet,
|
2012-02-19 17:13:38 +01:00
|
|
|
(void *)GB_StreamSetBytesRead,
|
|
|
|
(void *)GB_StreamSetSwapping,
|
|
|
|
(void *)GB_StreamBlock,
|
|
|
|
(void *)GB_StreamRead,
|
|
|
|
(void *)GB_StreamWrite,
|
2012-08-25 17:13:39 +02:00
|
|
|
(void *)STREAM_get_readable,
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
(void *)STRING_start_len,
|
|
|
|
(void *)STRING_end,
|
|
|
|
(void *)STRING_make,
|
|
|
|
|
|
|
|
(void *)DEBUG_get_current_position,
|
2012-05-20 19:58:34 +02:00
|
|
|
(void *)DEBUG_enter_event_loop,
|
|
|
|
(void *)DEBUG_leave_event_loop,
|
2012-05-08 17:32:33 +02:00
|
|
|
|
|
|
|
(void *)SIGNAL_register,
|
|
|
|
(void *)SIGNAL_unregister,
|
2012-08-25 00:29:53 +02:00
|
|
|
|
|
|
|
(void *)LIST_insert,
|
|
|
|
(void *)LIST_remove,
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
NULL
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
2012-05-24 02:31:57 +02:00
|
|
|
const void *GAMBAS_DebugApi[] =
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
(void *)GB_DebugGetExec,
|
|
|
|
(void *)STACK_get_frame,
|
|
|
|
(void *)ERROR_print_at,
|
|
|
|
(void *)ERROR_save,
|
|
|
|
(void *)ERROR_restore,
|
|
|
|
(void *)VALUE_to_string,
|
|
|
|
(void *)LOCAL_format_date,
|
|
|
|
(void *)LOCAL_format_number,
|
|
|
|
(void *)DEBUG_get_value,
|
2009-08-24 16:19:32 +02:00
|
|
|
(void *)DEBUG_set_value,
|
2007-12-30 17:41:49 +01:00
|
|
|
(void *)CARRAY_get_value,
|
[DEVELOPMENT ENVIRONMENT]
* NEW: The debug window has a button to switch between "normal view" and
"symbol view". In "normal view", array and collection contents are
displayed. If the object is not an array or a collection, then all
non-hidden symbols are displayed. In "symbol view", all objects symbols
are displayed, whatever the object type is.
[INTERPRETER]
* NEW: The debugger now can display collection-like objects. An object can
be displayed like a collection if it has a Count property, is enumerable,
has a _get special method taking a string, and has a Key property that
returns the key of the last enumerated element.
[GB.DEBUG]
* NEW: The debugger now can display collection-like objects. An object can
be displayed like a collection if it has a Count property, is enumerable,
has a _get special method taking a string, and has a Key property that
returns the key of the last enumerated element.
[GB.FORM]
* BUG: GridView.Clear resets the height of all rows to the default value.
git-svn-id: svn://localhost/gambas/trunk@4558 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-03-17 03:05:31 +01:00
|
|
|
(void *)DEBUG_enum_keys,
|
2007-12-30 17:41:49 +01:00
|
|
|
(void *)CLASS_get_next_sorted_symbol,
|
2009-02-16 22:39:07 +01:00
|
|
|
(void *)DEBUG_get_object_access_type,
|
2009-07-29 02:16:48 +02:00
|
|
|
(void *)DEBUG_find_class,
|
2011-03-16 23:16:19 +01:00
|
|
|
(void *)CARRAY_get_array_bounds,
|
2007-12-30 17:41:49 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-07-03 00:38:29 +02:00
|
|
|
void *GAMBAS_JitApi[] =
|
2012-05-23 21:26:15 +02:00
|
|
|
{
|
|
|
|
(void *)EXEC_release,
|
|
|
|
(void *)RELEASE_many,
|
|
|
|
|
|
|
|
(void *)EXEC_push_unknown,
|
|
|
|
(void *)EXEC_push_array,
|
|
|
|
|
|
|
|
(void *)EXEC_pop_unknown,
|
|
|
|
(void *)EXEC_pop_array,
|
|
|
|
|
|
|
|
(void *)CENUM_create,
|
|
|
|
(void *)EXEC_enum_first,
|
|
|
|
(void *)EXEC_enum_next,
|
|
|
|
|
|
|
|
(void *)EXEC_new,
|
|
|
|
(void *)EXEC_enter_quick,
|
|
|
|
(void *)EXEC_enter,
|
|
|
|
(void *)EXEC_native_quick,
|
|
|
|
(void *)EXEC_native,
|
|
|
|
(void *)EXEC_call_native,
|
|
|
|
(void *)EXEC_function_real,
|
|
|
|
(void *)EXEC_leave_keep,
|
|
|
|
(void *)EXEC_leave_drop,
|
|
|
|
(void *)EXEC_function_loop,
|
|
|
|
|
|
|
|
(void *)EXEC_special,
|
|
|
|
(void *)EXEC_object_variant,
|
|
|
|
(void *)EXEC_object_other,
|
|
|
|
|
2012-06-15 03:27:31 +02:00
|
|
|
(void *)EXTERN_get_function_info,
|
2012-05-23 21:26:15 +02:00
|
|
|
(void *)EXTERN_call,
|
2012-06-20 00:08:59 +02:00
|
|
|
(void *)EXTERN_make_callback,
|
2012-05-23 21:26:15 +02:00
|
|
|
|
|
|
|
(void *)STRING_new,
|
|
|
|
(void *)STRING_new_temp_value,
|
|
|
|
(void *)STRING_free_real,
|
|
|
|
(void *)STRING_free_later,
|
|
|
|
(void *)STRING_compare,
|
|
|
|
(void *)STRING_equal_ignore_case_same,
|
|
|
|
(void *)STRING_conv,
|
|
|
|
|
|
|
|
(void *)OBJECT_comp_value,
|
|
|
|
(void *)COMPARE_object,
|
|
|
|
(void *)CLASS_inherits,
|
|
|
|
(void *)OBJECT_create,
|
|
|
|
(void *)CLASS_free,
|
|
|
|
(void *)SYMBOL_find,
|
|
|
|
|
|
|
|
(void *)CARRAY_get_array_class,
|
|
|
|
(void *)CARRAY_get_data_multi,
|
|
|
|
(void *)CARRAY_create_static,
|
|
|
|
(void *)CSTRUCT_create_static,
|
|
|
|
|
|
|
|
(void *)REGEXP_scan,
|
|
|
|
|
|
|
|
(void *)VALUE_convert,
|
|
|
|
(void *)VALUE_to_string,
|
|
|
|
(void *)VALUE_convert_float,
|
|
|
|
(void *)VALUE_convert_variant,
|
|
|
|
(void *)VALUE_convert_string,
|
|
|
|
(void *)VALUE_is_null,
|
|
|
|
(void *)VALUE_undo_variant,
|
|
|
|
|
|
|
|
(void *)NUMBER_from_string,
|
|
|
|
(void *)NUMBER_int_to_string,
|
|
|
|
|
|
|
|
(void *)LOCAL_format_number,
|
|
|
|
|
|
|
|
(void *)DATE_to_string,
|
|
|
|
(void *)DATE_from_string,
|
|
|
|
(void *)DATE_comp,
|
|
|
|
(void *)DATE_timer,
|
|
|
|
(void *)DATE_now,
|
|
|
|
(void *)DATE_add,
|
|
|
|
(void *)DATE_diff,
|
|
|
|
|
|
|
|
(void *)randomize,
|
|
|
|
(void *)rnd,
|
|
|
|
|
|
|
|
(void *)THROW,
|
2012-06-15 03:27:31 +02:00
|
|
|
(void *)ERROR_panic,
|
2012-05-23 21:26:15 +02:00
|
|
|
(void *)ERROR_propagate,
|
|
|
|
(void *)ERROR_reset,
|
|
|
|
(void *)ERROR_set_last,
|
|
|
|
(void *)ERROR_lock,
|
|
|
|
(void *)ERROR_unlock,
|
|
|
|
|
|
|
|
(void *)TYPE_get_name,
|
|
|
|
|
|
|
|
(void *)SUBR_not,
|
|
|
|
(void *)SUBR_and_,
|
|
|
|
(void *)SUBR_cat,
|
|
|
|
(void *)SUBR_file,
|
|
|
|
(void *)SUBR_like,
|
|
|
|
(void *)SUBR_string,
|
|
|
|
(void *)SUBR_upper,
|
|
|
|
(void *)SUBR_instr,
|
|
|
|
(void *)SUBR_subst,
|
|
|
|
(void *)SUBR_replace,
|
|
|
|
(void *)SUBR_split,
|
|
|
|
(void *)SUBR_strcomp,
|
|
|
|
(void *)SUBR_sconv,
|
|
|
|
(void *)SUBR_abs,
|
|
|
|
(void *)SUBR_int,
|
|
|
|
(void *)SUBR_fix,
|
|
|
|
(void *)SUBR_sgn,
|
|
|
|
(void *)SUBR_min_max,
|
|
|
|
(void *)SUBR_choose,
|
|
|
|
(void *)SUBR_bit,
|
|
|
|
(void *)SUBR_is_type,
|
|
|
|
(void *)SUBR_hex_bin,
|
|
|
|
(void *)SUBR_val,
|
|
|
|
(void *)SUBR_format,
|
|
|
|
(void *)SUBR_year,
|
|
|
|
(void *)SUBR_week,
|
|
|
|
(void *)SUBR_date,
|
|
|
|
(void *)SUBR_time,
|
|
|
|
(void *)SUBR_eval,
|
|
|
|
(void *)SUBR_debug,
|
|
|
|
(void *)SUBR_wait,
|
|
|
|
(void *)SUBR_open,
|
|
|
|
(void *)SUBR_close,
|
|
|
|
(void *)SUBR_input,
|
|
|
|
(void *)SUBR_linput,
|
|
|
|
(void *)SUBR_print,
|
|
|
|
(void *)SUBR_read,
|
|
|
|
(void *)SUBR_write,
|
|
|
|
(void *)SUBR_flush,
|
|
|
|
(void *)SUBR_lock,
|
|
|
|
(void *)SUBR_inp_out,
|
|
|
|
(void *)SUBR_eof,
|
|
|
|
(void *)SUBR_lof,
|
|
|
|
(void *)SUBR_seek,
|
|
|
|
(void *)SUBR_kill,
|
|
|
|
(void *)SUBR_move,
|
|
|
|
(void *)SUBR_exist,
|
|
|
|
(void *)SUBR_access,
|
|
|
|
(void *)SUBR_stat,
|
|
|
|
(void *)SUBR_dfree,
|
|
|
|
(void *)SUBR_temp,
|
|
|
|
(void *)SUBR_isdir,
|
|
|
|
(void *)SUBR_dir,
|
|
|
|
(void *)SUBR_rdir,
|
|
|
|
(void *)SUBR_exec,
|
|
|
|
(void *)SUBR_alloc,
|
|
|
|
(void *)SUBR_free,
|
|
|
|
(void *)SUBR_realloc,
|
|
|
|
(void *)SUBR_strptr,
|
|
|
|
(void *)SUBR_collection,
|
|
|
|
(void *)SUBR_tr,
|
|
|
|
(void *)SUBR_quote,
|
|
|
|
(void *)SUBR_unquote,
|
|
|
|
(void *)SUBR_ptr,
|
|
|
|
|
|
|
|
(void *)CLASS_load_from_jit,
|
|
|
|
(void *)CLASS_run_inits,
|
|
|
|
|
|
|
|
(void *)DEBUG_get_current_position,
|
2012-07-03 00:38:29 +02:00
|
|
|
(void *)NULL, // Later set to DEBUG.Profile.Add
|
2012-05-23 21:26:15 +02:00
|
|
|
|
|
|
|
(void *)EXEC_quit,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool GAMBAS_DoNotRaiseEvent = FALSE;
|
|
|
|
bool GAMBAS_StopEvent = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static bool _event_stopped = FALSE;
|
2012-08-24 04:32:23 +02:00
|
|
|
static int _raise_event_level = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-04-05 19:02:16 +02:00
|
|
|
#define CATCH_ERROR \
|
2012-02-19 17:13:38 +01:00
|
|
|
bool ret = FALSE; \
|
|
|
|
TRY
|
|
|
|
|
2010-04-05 19:02:16 +02:00
|
|
|
#define END_CATCH_ERROR \
|
2012-02-19 17:13:38 +01:00
|
|
|
CATCH \
|
|
|
|
{ \
|
|
|
|
ret = TRUE; \
|
|
|
|
EXEC_set_native_error(TRUE); \
|
|
|
|
} \
|
|
|
|
END_TRY \
|
|
|
|
return ret;
|
2011-05-16 04:16:22 +02:00
|
|
|
|
|
|
|
#define CATCH_ERROR_INT \
|
2012-02-19 17:13:38 +01:00
|
|
|
int ret = 0; \
|
|
|
|
TRY
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
#define END_CATCH_ERROR_INT \
|
2012-02-19 17:13:38 +01:00
|
|
|
CATCH \
|
|
|
|
{ \
|
|
|
|
ret = -1; \
|
|
|
|
EXEC_set_native_error(TRUE); \
|
|
|
|
} \
|
|
|
|
END_TRY \
|
|
|
|
return ret;
|
2010-04-05 19:02:16 +02:00
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_GetInterface(const char *name, int version, void *iface)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-01-17 00:12:10 +01:00
|
|
|
GB_LoadComponent(name);
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (LIBRARY_get_interface_by_name(name, version, iface))
|
|
|
|
ERROR_panic("Cannot find interface of library '%s'", name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_Hook(int type, void *hook)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
void *old_hook;
|
|
|
|
void **phook = (void **)(void *)&EXEC_Hook;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if ((type < 0) || (type > GB_HOOK_MAX))
|
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
type--;
|
|
|
|
old_hook = phook[type];
|
|
|
|
if (hook)
|
|
|
|
phook[type] = hook;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return old_hook;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_LoadComponent(const char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CATCH_ERROR
|
|
|
|
{
|
|
|
|
COMPONENT *comp = COMPONENT_create(name);
|
|
|
|
COMPONENT_load(comp);
|
|
|
|
}
|
|
|
|
END_CATCH_ERROR
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void push(int nval, va_list args)
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
TYPE type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
STACK_check(nval);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
while (nval)
|
|
|
|
{
|
|
|
|
type = va_arg(args, int);
|
|
|
|
SP->type = type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case T_INTEGER:
|
|
|
|
case T_BOOLEAN:
|
|
|
|
SP->_integer.value = va_arg(args, int);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_LONG:
|
|
|
|
SP->_long.value = va_arg(args, int64_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRING:
|
|
|
|
SP->type = T_CSTRING;
|
|
|
|
SP->_string.addr = va_arg(args, char *);
|
|
|
|
SP->_string.start = 0;
|
|
|
|
SP->_string.len = va_arg(args, int);
|
|
|
|
if (SP->_string.len <= 0 && SP->_string.addr)
|
|
|
|
SP->_string.len = strlen(SP->_string.addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
SP->_float.value = va_arg(args, double);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_OBJECT:
|
|
|
|
SP->_object.object = va_arg(args, void *);
|
|
|
|
OBJECT_REF(SP->_object.object, "push");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERROR_panic("GB.Push: unknown datatype");
|
|
|
|
break;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
SP++;
|
|
|
|
nval--;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Push(int nval, ...)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
va_list args;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
va_start(args, nval);
|
|
|
|
push(nval, args);
|
|
|
|
va_end(args);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-02 02:46:00 +02:00
|
|
|
void GB_GetProperty(void *object, const char *property)
|
|
|
|
{
|
|
|
|
static bool init = FALSE;
|
2012-02-19 17:13:38 +01:00
|
|
|
static GB_FUNCTION func;
|
2011-05-02 02:46:00 +02:00
|
|
|
|
|
|
|
if (!init)
|
|
|
|
{
|
|
|
|
GB_GetFunction(&func, (void *)CLASS_find("Object"), "GetProperty", NULL, NULL);
|
|
|
|
init = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GB_Push(2, GB_T_OBJECT, object, GB_T_STRING, property, strlen(property));
|
|
|
|
GB_Call(&func, 2, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_SetProperty(void *object, const char *property, ...)
|
|
|
|
{
|
|
|
|
static bool init = FALSE;
|
2012-02-19 17:13:38 +01:00
|
|
|
static GB_FUNCTION func;
|
2011-05-02 02:46:00 +02:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
va_list args;
|
2011-05-02 02:46:00 +02:00
|
|
|
|
|
|
|
if (!init)
|
|
|
|
{
|
|
|
|
GB_GetFunction(&func, (void *)CLASS_find("Object"), "SetProperty", NULL, NULL);
|
|
|
|
init = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GB_Push(2, GB_T_OBJECT, object, GB_T_STRING, property, strlen(property));
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
va_start(args, property);
|
|
|
|
push(1, args);
|
|
|
|
va_end(args);
|
2011-05-02 02:46:00 +02:00
|
|
|
|
|
|
|
GB_Call(&func, 3, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_CanRaise(void *object, int event_id)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
ushort *event_tab;
|
|
|
|
int func_id;
|
|
|
|
COBSERVER *obs;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!object || !OBJECT_has_events(object))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
LIST_for_each(obs, OBJECT_event(object)->observer)
|
|
|
|
{
|
|
|
|
if (OBJECT_active_parent(obs) && obs->event && obs->event[event_id])
|
2012-02-19 17:13:38 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2012-02-19 17:13:38 +01:00
|
|
|
|
|
|
|
if (!OBJECT_active_parent(object))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
event_tab = OBJECT_event(object)->event;
|
|
|
|
func_id = event_tab[event_id];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return (func_id != 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int get_event_func_id(ushort *event_tab, int event_id)
|
|
|
|
{
|
|
|
|
int func_id;
|
|
|
|
|
|
|
|
if (!event_tab)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
func_id = event_tab[event_id];
|
|
|
|
if (!func_id)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return func_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool raise_event(OBJECT *observer, void *object, int func_id, int nparam)
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
bool stop_event;
|
2007-12-30 17:41:49 +01:00
|
|
|
CLASS *class;
|
2012-02-19 17:13:38 +01:00
|
|
|
CLASS_DESC_METHOD *desc;
|
|
|
|
void *old_last;
|
|
|
|
bool result;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
func_id--;
|
|
|
|
|
|
|
|
if (OBJECT_is_class(observer))
|
2010-01-01 15:55:13 +01:00
|
|
|
class = (CLASS *)observer; //OBJECT_class(object);
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
2010-01-01 15:55:13 +01:00
|
|
|
class = OBJECT_class(observer);
|
|
|
|
|
|
|
|
desc = &class->table[func_id].desc->method;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
old_last = EVENT_Last;
|
|
|
|
EVENT_Last = object;
|
2010-12-21 15:05:42 +01:00
|
|
|
//OBJECT_REF(object, "raise_event");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
// if (arg)
|
|
|
|
// {
|
|
|
|
// EXEC_dup(nparam);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// va_start(args, nparam);
|
|
|
|
// push(nparam, args);
|
|
|
|
// va_end(args);
|
|
|
|
// }
|
|
|
|
|
|
|
|
stop_event = GAMBAS_StopEvent;
|
|
|
|
GAMBAS_StopEvent = FALSE;
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
EXEC_public_desc(class, observer, desc, nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (RP->type == T_VOID)
|
|
|
|
result = FALSE;
|
|
|
|
else
|
|
|
|
result = RP->_boolean.value != 0;
|
|
|
|
|
|
|
|
if (GAMBAS_StopEvent)
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
GAMBAS_StopEvent = stop_event;
|
2010-12-21 15:05:42 +01:00
|
|
|
|
|
|
|
//OBJECT_UNREF(object, "raise_event");
|
2007-12-30 17:41:49 +01:00
|
|
|
EVENT_Last = old_last;
|
|
|
|
|
|
|
|
EXEC_release_return_value();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If nparam < 0, the args are already on the stack
|
|
|
|
|
2012-02-25 02:35:55 +01:00
|
|
|
static GB_RAISE_HANDLER *_GB_Raise_handler = NULL;
|
2011-08-23 14:51:25 +02:00
|
|
|
|
|
|
|
static void error_GB_Raise()
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
void *object = (void *)ERROR_handler->arg1;
|
|
|
|
|
|
|
|
RELEASE_MANY(SP, (int)(ERROR_handler->arg2));
|
|
|
|
OBJECT_UNREF(object, "error_GB_Raise");
|
2012-02-25 02:35:55 +01:00
|
|
|
|
2012-08-24 04:32:23 +02:00
|
|
|
_raise_event_level--;
|
|
|
|
|
|
|
|
if (_GB_Raise_handler && _GB_Raise_handler->level == _raise_event_level)
|
2012-02-25 02:35:55 +01:00
|
|
|
{
|
|
|
|
(*_GB_Raise_handler->callback)(_GB_Raise_handler->data);
|
|
|
|
_GB_Raise_handler = _GB_Raise_handler->old;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_RaiseBegin(GB_RAISE_HANDLER *handler)
|
|
|
|
{
|
|
|
|
handler->old = _GB_Raise_handler;
|
2012-08-24 04:32:23 +02:00
|
|
|
handler->level = _raise_event_level;
|
2012-02-25 02:35:55 +01:00
|
|
|
_GB_Raise_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_RaiseEnd(GB_RAISE_HANDLER *handler)
|
|
|
|
{
|
|
|
|
_GB_Raise_handler = handler->old;
|
2011-08-23 14:51:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_Raise(void *object, int event_id, int nparam, ...)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
OBJECT *parent;
|
|
|
|
int func_id;
|
|
|
|
int result;
|
|
|
|
va_list args;
|
|
|
|
bool arg;
|
|
|
|
COBSERVER *obs;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (GAMBAS_DoNotRaiseEvent)
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!OBJECT_is_valid(object) || !OBJECT_has_events(object))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
OBJECT_REF(object, "GB_Raise");
|
|
|
|
|
|
|
|
arg = nparam < 0;
|
|
|
|
nparam = abs(nparam);
|
2011-08-23 14:51:25 +02:00
|
|
|
|
2012-08-24 04:32:23 +02:00
|
|
|
_raise_event_level++;
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
ON_ERROR_2(error_GB_Raise, object, nparam)
|
2011-08-23 14:51:25 +02:00
|
|
|
{
|
2008-12-31 16:55:40 +01:00
|
|
|
if (!arg)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-12-31 16:55:40 +01:00
|
|
|
va_start(args, nparam);
|
|
|
|
push(nparam, args);
|
|
|
|
va_end(args);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-12-31 16:55:40 +01:00
|
|
|
|
|
|
|
result = FALSE;
|
|
|
|
|
|
|
|
// Observers before
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-12-31 16:55:40 +01:00
|
|
|
LIST_for_each(obs, OBJECT_event(object)->observer)
|
2008-07-19 23:53:22 +02:00
|
|
|
{
|
2008-12-31 16:55:40 +01:00
|
|
|
parent = OBJECT_active_parent(obs);
|
|
|
|
if (!parent)
|
|
|
|
continue;
|
|
|
|
if (obs->after)
|
|
|
|
continue;
|
2010-12-21 15:05:42 +01:00
|
|
|
//if (obs->object != object)
|
|
|
|
// continue;
|
2008-12-31 16:55:40 +01:00
|
|
|
|
|
|
|
func_id = get_event_func_id(obs->event, event_id);
|
|
|
|
if (!func_id)
|
|
|
|
continue;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-07-19 23:53:22 +02:00
|
|
|
if (!OBJECT_is_valid(parent))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-12-31 16:55:40 +01:00
|
|
|
OBJECT_detach(object);
|
|
|
|
continue;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-12-31 16:55:40 +01:00
|
|
|
|
|
|
|
EXEC_dup(nparam);
|
|
|
|
result = raise_event(parent, object, func_id, nparam);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
goto __RETURN;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-12-31 16:55:40 +01:00
|
|
|
|
|
|
|
// Parent
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-12-31 16:55:40 +01:00
|
|
|
parent = OBJECT_active_parent(object);
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
func_id = get_event_func_id(OBJECT_event(object)->event, event_id);
|
|
|
|
if (func_id)
|
|
|
|
{
|
|
|
|
#if DEBUG_EVENT
|
2010-03-19 17:31:50 +01:00
|
|
|
CLASS *class = OBJECT_class(object);
|
2008-12-31 16:55:40 +01:00
|
|
|
printf("GB_Raise(%p, %d, %s)\n", object, event_id, class->event[event_id].name);
|
|
|
|
printf("func_id = %d parent = (%s %p)\n", func_id, parent->class->name, parent);
|
|
|
|
if (OBJECT_is_locked(parent))
|
|
|
|
printf("parent is locked!\n");
|
|
|
|
fflush(NULL);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-12-31 16:55:40 +01:00
|
|
|
if (!OBJECT_is_valid(parent))
|
|
|
|
OBJECT_detach(object);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EXEC_dup(nparam);
|
|
|
|
result = raise_event(parent, object, func_id, nparam);
|
|
|
|
if (result)
|
|
|
|
goto __RETURN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Observers after
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-12-31 16:55:40 +01:00
|
|
|
LIST_for_each(obs, OBJECT_event(object)->observer)
|
2008-07-19 23:53:22 +02:00
|
|
|
{
|
2008-12-31 16:55:40 +01:00
|
|
|
parent = OBJECT_active_parent(obs);
|
|
|
|
if (!parent)
|
|
|
|
continue;
|
|
|
|
if (!obs->after)
|
|
|
|
continue;
|
2010-12-21 15:05:42 +01:00
|
|
|
//if (obs->object != object)
|
|
|
|
// continue;
|
2008-12-31 16:55:40 +01:00
|
|
|
|
|
|
|
func_id = get_event_func_id(obs->event, event_id);
|
|
|
|
if (!func_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!OBJECT_is_valid(parent))
|
|
|
|
{
|
|
|
|
OBJECT_detach(object);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXEC_dup(nparam);
|
|
|
|
result = raise_event(parent, object, func_id, nparam);
|
|
|
|
if (result)
|
|
|
|
goto __RETURN;
|
2008-07-19 23:53:22 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__RETURN:
|
|
|
|
|
2008-12-31 16:55:40 +01:00
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
OBJECT_UNREF(object, "GB_Raise");
|
|
|
|
}
|
2011-08-23 14:51:25 +02:00
|
|
|
END_ERROR
|
|
|
|
|
2012-08-24 04:32:23 +02:00
|
|
|
_raise_event_level--;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_GetFunction(GB_FUNCTION *_func, void *object, const char *name, const char *sign, const char *type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
GB_API_FUNCTION *func = (GB_API_FUNCTION *)_func;
|
|
|
|
char len_min, nparam, npvar;
|
|
|
|
TYPE *tsign;
|
|
|
|
TYPE tret;
|
|
|
|
int index;
|
|
|
|
CLASS *class;
|
|
|
|
int kind;
|
|
|
|
CLASS_DESC *desc;
|
|
|
|
bool error;
|
2011-09-02 18:44:20 +02:00
|
|
|
const char *err;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (OBJECT_is_class(object))
|
|
|
|
{
|
|
|
|
class = (CLASS *)object;
|
|
|
|
kind = CD_STATIC_METHOD;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
class = OBJECT_class(object);
|
|
|
|
kind = CD_METHOD;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
CLASS_load(class);
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
index = CLASS_find_symbol(class, name);
|
|
|
|
if (index == NO_SYMBOL)
|
2011-09-02 18:44:20 +02:00
|
|
|
{
|
|
|
|
err = "Symbol not found";
|
2012-02-19 17:13:38 +01:00
|
|
|
goto _NOT_FOUND;
|
2011-09-02 18:44:20 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
desc = class->table[index].desc;
|
|
|
|
if (CLASS_DESC_get_type(desc) != kind)
|
2011-09-02 18:44:20 +02:00
|
|
|
{
|
|
|
|
err = kind == CD_METHOD ? "Not a method" : "Not a static method";
|
2012-02-19 17:13:38 +01:00
|
|
|
goto _NOT_FOUND;
|
2011-09-02 18:44:20 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (sign)
|
|
|
|
{
|
|
|
|
TYPE_signature_length(sign, &len_min, &nparam, &npvar);
|
|
|
|
tsign = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (nparam)
|
|
|
|
{
|
|
|
|
ALLOC(&tsign, nparam * sizeof(TYPE), "GB_GetFunction");
|
|
|
|
tsign = TYPE_transform_signature(&tsign, sign, nparam);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
error = TYPE_compare_signature(desc->method.signature, desc->method.npmax, tsign, nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (nparam)
|
|
|
|
FREE(&tsign, "GB_GetFunction");
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
err = "Parameters do not match";
|
|
|
|
goto _NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (type)
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
tret = TYPE_from_string(&type);
|
|
|
|
if (tret != desc->method.type)
|
|
|
|
{
|
|
|
|
if (tret == T_VOID)
|
|
|
|
err = "Must be a procedure";
|
2007-12-30 17:41:49 +01:00
|
|
|
else if (desc->method.type == T_VOID)
|
2012-02-19 17:13:38 +01:00
|
|
|
err = "Must be a function";
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
2011-09-02 18:44:20 +02:00
|
|
|
err = "Return type does not match";
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
goto _NOT_FOUND;
|
2012-02-19 17:13:38 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-08-14 12:07:29 +02:00
|
|
|
func->object = kind == CD_STATIC_METHOD ? NULL : object;
|
2012-02-19 17:13:38 +01:00
|
|
|
func->desc = &desc->method;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!func->desc)
|
|
|
|
abort();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
_NOT_FOUND:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
GB_Error("Unable to find method &1 in class &2. &3", name, class->name, err);
|
|
|
|
func->object = NULL;
|
|
|
|
func->desc = NULL;
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_GetClassInterface(void *_class, const char *_name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CLASS_DESC *desc;
|
2007-12-30 17:41:49 +01:00
|
|
|
int index;
|
|
|
|
CLASS *class = (CLASS *)_class;
|
|
|
|
int len = strlen(_name);
|
|
|
|
char name[len + 4];
|
|
|
|
|
|
|
|
CLASS_load(class);
|
|
|
|
|
2008-02-19 00:07:24 +01:00
|
|
|
strcpy(name, "_@");
|
|
|
|
strcat(name, _name);
|
2008-01-05 02:18:28 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
index = CLASS_find_symbol(class, name);
|
|
|
|
if (index == NO_SYMBOL)
|
|
|
|
goto __NOT_FOUND;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
desc = class->table[index].desc;
|
|
|
|
if (CLASS_DESC_get_type(desc) != CD_CONSTANT)
|
|
|
|
goto __NOT_FOUND;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (desc->constant.type != T_POINTER)
|
|
|
|
goto __NOT_FOUND;
|
|
|
|
|
|
|
|
return desc->constant.value._pointer;
|
|
|
|
|
|
|
|
__NOT_FOUND:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
GB_VALUE *GB_Call(GB_FUNCTION *_func, int nparam, int release)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
GB_API_FUNCTION *func = (GB_API_FUNCTION *)_func;
|
|
|
|
bool stop_event;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-04-02 03:15:31 +02:00
|
|
|
if (!func || !func->desc)
|
2007-12-30 17:41:49 +01:00
|
|
|
GB_Error("Unknown function call");
|
2009-07-26 14:38:20 +02:00
|
|
|
//TEMP.type = GB_T_NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
stop_event = GAMBAS_StopEvent;
|
2010-01-01 15:55:13 +01:00
|
|
|
EXEC_public_desc(func->desc->class, func->object, func->desc, nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
_event_stopped = GAMBAS_StopEvent;
|
|
|
|
GAMBAS_StopEvent = stop_event;
|
|
|
|
|
|
|
|
if (release)
|
|
|
|
EXEC_release_return_value();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UNBORROW(RP);
|
|
|
|
TEMP = *RP;
|
|
|
|
RP->type = T_VOID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return (GB_VALUE *)&TEMP;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_GetEvent(void *class, char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CLASS_DESC_EVENT *cd;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
cd = CLASS_get_event_desc((CLASS *)class, name);
|
|
|
|
if (!cd)
|
|
|
|
return (-1);
|
|
|
|
else
|
2012-08-20 20:05:25 +02:00
|
|
|
return cd->index;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *GB_GetLastEventName()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
return EVENT_Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_Stopped(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
return _event_stopped;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_NParam(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return EXEC_unknown_nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 19:29:00 +02:00
|
|
|
/*bool GB_IsProperty(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return FALSE; //EXEC_unknown_property;
|
2011-07-03 19:29:00 +02:00
|
|
|
}*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *GB_GetUnknown(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return EXEC_unknown_name;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Error(const char *error, ...)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
va_list args;
|
|
|
|
char *arg[4];
|
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
EXEC_set_native_error(FALSE);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
va_start(args, error);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
arg[i] = va_arg(args, char *);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ERROR_define(error, arg);
|
|
|
|
EXEC_set_native_error(TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-08-15 19:02:22 +02:00
|
|
|
void GB_Deprecated(const char *msg, const char *func, const char *repl)
|
|
|
|
{
|
|
|
|
if (EXEC_debug)
|
|
|
|
GB_Error("&1: &2 is deprecated. Use &3 instead", msg, func, repl);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "%s: %s is deprecated. Use %s instead\n", msg, func, repl);
|
|
|
|
}
|
2012-07-14 04:49:57 +02:00
|
|
|
|
2009-06-28 00:02:18 +02:00
|
|
|
#if DEBUG_REF
|
|
|
|
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
|
|
|
static void print_stack_backtrace()
|
|
|
|
{
|
|
|
|
void *trace[16];
|
|
|
|
char **messages = (char **)NULL;
|
|
|
|
int i, trace_size = 0;
|
|
|
|
|
|
|
|
trace_size = backtrace(trace, 16);
|
|
|
|
messages = backtrace_symbols(trace, trace_size);
|
|
|
|
//printf("[bt] Execution path:\n");
|
|
|
|
for (i=0; i<trace_size; ++i)
|
|
|
|
fprintf(stderr, "[bt] %s\n", messages[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Ref(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
#if TRACE_MEMORY
|
|
|
|
CLASS *save = CP;
|
|
|
|
CP = NULL;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (object)
|
2009-06-28 00:02:18 +02:00
|
|
|
{
|
|
|
|
#if DEBUG_REF
|
2010-05-27 00:01:28 +02:00
|
|
|
//print_stack_backtrace();
|
2009-06-28 00:02:18 +02:00
|
|
|
#endif
|
2012-02-19 17:13:38 +01:00
|
|
|
OBJECT_REF(object, "GB_Ref");
|
2009-06-28 00:02:18 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
#if TRACE_MEMORY
|
|
|
|
CP = save;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Unref(void **object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
#if TRACE_MEMORY
|
|
|
|
CLASS *save = CP;
|
|
|
|
CP = NULL;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (*object)
|
2009-06-28 00:02:18 +02:00
|
|
|
{
|
|
|
|
#if DEBUG_REF
|
2010-05-27 00:01:28 +02:00
|
|
|
//print_stack_backtrace();
|
2009-06-28 00:02:18 +02:00
|
|
|
#endif
|
2012-02-19 17:13:38 +01:00
|
|
|
OBJECT_UNREF(*object, "GB_Unref");
|
2009-06-28 00:02:18 +02:00
|
|
|
}
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
#if TRACE_MEMORY
|
|
|
|
CP = save;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_UnrefKeep(void **object, int delete)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
#if TRACE_MEMORY
|
|
|
|
CLASS *save = CP;
|
|
|
|
CP = NULL;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (*object != NULL)
|
|
|
|
{
|
2009-06-28 00:02:18 +02:00
|
|
|
#if DEBUG_REF
|
2010-05-27 00:01:28 +02:00
|
|
|
//print_stack_backtrace();
|
2009-06-28 00:02:18 +02:00
|
|
|
#endif
|
2012-02-19 17:13:38 +01:00
|
|
|
if (delete)
|
|
|
|
{
|
|
|
|
OBJECT_UNREF(*object, "GB_UnrefKeep");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OBJECT_UNREF_KEEP(*object, "GB_UnrefKeep");
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
#if TRACE_MEMORY
|
|
|
|
CP = save;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Detach(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (object)
|
2009-06-28 00:02:18 +02:00
|
|
|
{
|
|
|
|
#if DEBUG_REF
|
2010-05-27 00:01:28 +02:00
|
|
|
//print_stack_backtrace();
|
2009-06-28 00:02:18 +02:00
|
|
|
#endif
|
2012-02-19 17:13:38 +01:00
|
|
|
OBJECT_detach(object);
|
2009-06-28 00:02:18 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Attach(void *object, void *parent, const char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (object)
|
2009-06-28 00:02:18 +02:00
|
|
|
{
|
|
|
|
#if DEBUG_REF
|
2010-05-27 00:01:28 +02:00
|
|
|
//print_stack_backtrace();
|
2009-06-28 00:02:18 +02:00
|
|
|
#endif
|
2012-02-19 17:13:38 +01:00
|
|
|
OBJECT_attach(object, parent, name);
|
2009-06-28 00:02:18 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_StopEnum(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
/* Do not forget than even if we stop the enumeration, the return value
|
|
|
|
of _next will be converted
|
|
|
|
*/
|
|
|
|
//VALUE_default(&TEMP, *GAMBAS_ReturnType);
|
|
|
|
TEMP.type = T_VOID;
|
|
|
|
EXEC_enum->stop = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_GetEnum(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return (void *)&EXEC_enum->data;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *_enum_object;
|
|
|
|
|
2012-09-06 18:20:54 +02:00
|
|
|
void *GB_BeginEnum(void *enum_object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-09-06 18:20:54 +02:00
|
|
|
CENUM *old = EXEC_enum;
|
2012-02-19 17:13:38 +01:00
|
|
|
EXEC_enum = NULL;
|
|
|
|
_enum_object = enum_object;
|
2012-09-06 18:20:54 +02:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_EndEnum(void *old_enum)
|
|
|
|
{
|
|
|
|
EXEC_enum = old_enum;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_NextEnum(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
EXEC_enum = CENUM_get_next(EXEC_enum);
|
|
|
|
if (!EXEC_enum)
|
|
|
|
return TRUE;
|
|
|
|
if (EXEC_enum->enum_object == _enum_object)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_StopAllEnum(void *enum_object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-09-06 18:20:54 +02:00
|
|
|
void *save = GB_BeginEnum(enum_object);
|
2012-02-19 17:13:38 +01:00
|
|
|
while (!GB_NextEnum())
|
|
|
|
GB_StopEnum();
|
2012-09-06 18:20:54 +02:00
|
|
|
GB_EndEnum(save);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 00:48:08 +02:00
|
|
|
void GB_Return(GB_TYPE type, ...)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL
|
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
VALUE *ret = &TEMP;
|
|
|
|
va_list args;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
va_start(args, type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->type = type;
|
|
|
|
if (TYPE_is_object(type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_integer.value = va_arg(args, int) ? (-1) : 0;
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BYTE:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_integer.value = va_arg(args, int);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SHORT:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_integer.value = va_arg(args, int);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__INTEGER:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_integer.value = va_arg(args, int);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_long.value = va_arg(args, int64_t);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_single.value = va_arg(args, double);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__FLOAT:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_float.value = va_arg(args, double);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_date.date = va_arg(args, int);
|
|
|
|
ret->_date.time = va_arg(args, int);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_object.object = va_arg(args, void *);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
__POINTER:
|
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_pointer.value = va_arg(args, void *);
|
|
|
|
goto __CONV;
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__CLASS:
|
2012-02-19 17:13:38 +01:00
|
|
|
ret->_class.class = va_arg(args, CLASS *);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CONV:
|
|
|
|
__STRING:
|
|
|
|
__VOID:
|
|
|
|
__VARIANT:
|
|
|
|
__FUNCTION:
|
|
|
|
__NULL:
|
2012-02-19 17:13:38 +01:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnInteger(int val)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TEMP.type = T_INTEGER;
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP._integer.value = val;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnLong(int64_t val)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TEMP.type = T_LONG;
|
|
|
|
TEMP._long.value = val;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnPointer(void *val)
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TEMP.type = T_POINTER;
|
|
|
|
TEMP._pointer.value = val;
|
2008-01-17 22:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
void GB_ReturnSingle(float val)
|
|
|
|
{
|
|
|
|
TEMP.type = T_SINGLE;
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP._single.value = val;
|
2010-11-16 02:49:18 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnFloat(double val)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TEMP.type = T_FLOAT;
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP._float.value = val;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnDate(GB_DATE *date)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-12-24 03:02:05 +01:00
|
|
|
TEMP.type = T_DATE;
|
2011-10-24 21:33:41 +02:00
|
|
|
if (date)
|
|
|
|
{
|
|
|
|
TEMP._date.date = date->value.date;
|
|
|
|
TEMP._date.time = date->value.time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TEMP._date.date = 0;
|
|
|
|
TEMP._date.time = 0;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnBoolean(int val)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TEMP.type = T_BOOLEAN;
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP._boolean.value = val ? -1 : 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnObject(void *val)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (val == NULL)
|
|
|
|
GB_ReturnNull();
|
|
|
|
else
|
2010-04-26 11:36:47 +02:00
|
|
|
{
|
|
|
|
TEMP.type = T_OBJECT; //OBJECT_class(val);
|
|
|
|
TEMP._object.object = val;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
void GB_ReturnVariant(GB_VARIANT_VALUE *val)
|
|
|
|
{
|
|
|
|
TEMP._variant.type = T_VARIANT;
|
|
|
|
|
|
|
|
if (!val)
|
|
|
|
{
|
|
|
|
TEMP._variant.vtype = T_NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
//VALUE_read(&TEMP, value, type);
|
2010-05-22 20:02:34 +02:00
|
|
|
TEMP._variant.vtype = val->type;
|
|
|
|
if (TEMP._variant.vtype == T_VOID)
|
|
|
|
TEMP._variant.vtype = T_NULL;
|
|
|
|
|
|
|
|
VARIANT_copy_value(&TEMP._variant, (VARIANT *)val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-14 02:06:51 +01:00
|
|
|
void GB_ReturnConvVariant(void)
|
|
|
|
{
|
2012-08-20 23:09:27 +02:00
|
|
|
BORROW(&TEMP);
|
2011-11-14 02:06:51 +01:00
|
|
|
VALUE_conv(&TEMP, T_VARIANT);
|
2012-08-20 23:09:27 +02:00
|
|
|
UNBORROW(&TEMP);
|
2011-11-14 02:06:51 +01:00
|
|
|
}
|
|
|
|
|
2012-08-18 15:06:58 +02:00
|
|
|
void GB_ReturnBorrow(void)
|
|
|
|
{
|
|
|
|
BORROW(&TEMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_ReturnRelease(void)
|
|
|
|
{
|
|
|
|
UNBORROW(&TEMP);
|
|
|
|
}
|
2011-11-14 02:06:51 +01:00
|
|
|
|
2009-08-03 00:48:08 +02:00
|
|
|
void GB_ReturnPtr(GB_TYPE type, void *value)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (type == T_VOID)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
if (!value)
|
|
|
|
VALUE_default(&TEMP, type);
|
|
|
|
else
|
2012-02-19 17:13:38 +01:00
|
|
|
VALUE_read(&TEMP, value, type);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 15:13:47 +01:00
|
|
|
void GB_ReturnSelf(void *object)
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (object)
|
|
|
|
GB_ReturnObject(object);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TEMP.type = T_CLASS;
|
|
|
|
TEMP._class.class = NULL;
|
|
|
|
}
|
2008-02-21 15:13:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *GB_ToZeroString(GB_STRING *src)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
char *str;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
str = STRING_new_temp(src->value.addr + src->value.start, src->value.len);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (str == NULL)
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return str;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnString(char *str)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP.type = T_STRING;
|
|
|
|
TEMP._string.addr = str;
|
|
|
|
TEMP._string.start = 0;
|
|
|
|
TEMP._string.len = STRING_length(str);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (TEMP._string.len == 0)
|
|
|
|
TEMP._string.addr = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnConstString(const char *str, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP.type = T_CSTRING;
|
|
|
|
TEMP._string.addr = (char *)str;
|
|
|
|
TEMP._string.start = 0;
|
|
|
|
TEMP._string.len = len;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (TEMP._string.len == 0)
|
|
|
|
TEMP._string.addr = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnConstZeroString(const char *str)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
int len;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (str)
|
|
|
|
len = strlen(str);
|
|
|
|
else
|
|
|
|
len = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
GB_ReturnConstString(str, len);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnNewString(const char *src, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
if (len <= 0)
|
2010-05-23 13:07:14 +02:00
|
|
|
{
|
2010-05-23 20:59:11 +02:00
|
|
|
if (*src)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
ERROR_warning("please use GB.ReturnNewZeroString() instead of GB.ReturnNewString()");
|
|
|
|
len = strlen(src);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-24 16:52:20 +02:00
|
|
|
GB_ReturnVoidString();
|
2010-08-28 14:33:05 +02:00
|
|
|
return;
|
2010-05-23 20:59:11 +02:00
|
|
|
}
|
2010-05-23 13:07:14 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
GB_ReturnString(STRING_new_temp(src, len));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnNewZeroString(const char *src)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
GB_ReturnString(STRING_new_temp_zero(src));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_ReturnNull(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
TEMP.type = T_NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2011-10-24 16:52:20 +02:00
|
|
|
void GB_ReturnVoidString(void)
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
STRING_void_value(&TEMP);
|
2011-10-24 16:52:20 +02:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_GetClass(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (object)
|
|
|
|
return OBJECT_class(object);
|
|
|
|
else
|
|
|
|
return EXEC.class;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *GB_GetClassName(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CLASS *class = GB_GetClass(object);
|
|
|
|
return class->name;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_Is(void *object, void *class)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CLASS *ob_class;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!object)
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ob_class = OBJECT_class(object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return ((ob_class == class) || CLASS_inherits(ob_class, class));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_LoadFile(const char *path, int lenp, char **addr, int *len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
bool ret = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
//fprintf(stderr, "GB_LoadFile: %.*s\n", lenp ? lenp : strlen(path), path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
TRY
|
|
|
|
{
|
|
|
|
*addr = 0;
|
|
|
|
*len = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
STREAM_map(STRING_conv_file_name(path, lenp), addr, len);
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
if (*addr)
|
|
|
|
STREAM_unmap(*addr, *len);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
EXEC_set_native_error(TRUE);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
END_TRY
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return ret;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-17 12:57:55 +02:00
|
|
|
bool GB_ExistFile(const char *path)
|
|
|
|
{
|
|
|
|
return FILE_exist(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Store(GB_TYPE type, GB_VALUE *src, void *dst)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (src != NULL)
|
|
|
|
VALUE_write((VALUE *)src, dst, type);
|
|
|
|
else
|
|
|
|
VALUE_free(dst, type);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_StoreString(GB_STRING *src, char **dst)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
STRING_unref(dst);
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
*dst = STRING_new(src->value.addr + src->value.start, src->value.len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*dst = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_StoreObject(GB_OBJECT *src, void **dst)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
void *object;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (src)
|
|
|
|
object = src->value;
|
|
|
|
else
|
|
|
|
object = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (object)
|
|
|
|
OBJECT_REF(object, "GB_StoreObject");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
OBJECT_UNREF(*dst, "GB_StoreObject");
|
|
|
|
*dst = object;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_StoreVariant(GB_VARIANT *src, void *dst)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
/*GB_Store(GB_T_VARIANT, (GB_VALUE *)src, dst);*/
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
VALUE_write((VALUE *)src, dst, T_VARIANT);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
/*VARIANT_keep((VARIANT *)&src->value);
|
|
|
|
VARIANT_free((VARIANT *)dst);
|
|
|
|
*((VARIANT *)dst) = *((VARIANT *)&src->value);*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VARIANT_free((VARIANT *)dst);
|
|
|
|
((VARIANT *)dst)->type = T_NULL;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-07-19 14:33:57 +02:00
|
|
|
void GB_BorrowValue(GB_VALUE *value)
|
|
|
|
{
|
|
|
|
BORROW((VALUE *)value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_ReleaseValue(GB_VALUE *value)
|
|
|
|
{
|
|
|
|
RELEASE((VALUE *)value);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-11-05 00:53:39 +01:00
|
|
|
void GB_Watch(int fd, int flag, void *callback, intptr_t param)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
HOOK_DEFAULT(watch, WATCH_watch)(fd, flag, callback, param);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-13 01:34:14 +02:00
|
|
|
void *GB_Create(void *class, const char *name, void *parent)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2011-05-16 04:16:22 +02:00
|
|
|
void *object;
|
|
|
|
|
2012-07-13 01:34:14 +02:00
|
|
|
object = OBJECT_new(class, name, parent);
|
|
|
|
OBJECT_UNREF_KEEP(object, "GB_Create");
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *GB_New(void *class, const char *name, void *parent)
|
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (name && !parent)
|
|
|
|
{
|
|
|
|
parent = OP;
|
|
|
|
if (!parent)
|
|
|
|
parent = CP;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!((CLASS *)class)->no_create)
|
2012-07-09 19:10:21 +02:00
|
|
|
{
|
|
|
|
int nparam = 0;
|
|
|
|
if (!name && parent)
|
|
|
|
{
|
|
|
|
nparam = (int)(intptr_t)parent;
|
|
|
|
parent = NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:34:14 +02:00
|
|
|
return OBJECT_create(class, name, parent, nparam);
|
2012-07-09 19:10:21 +02:00
|
|
|
}
|
2012-02-19 17:13:38 +01:00
|
|
|
else
|
2012-07-13 01:34:14 +02:00
|
|
|
return GB_Create(class, name, parent);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_CheckObject(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CLASS *class;
|
|
|
|
|
|
|
|
if (object == NULL)
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
class = OBJECT_class(object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (class->check && (*(class->check))(object))
|
|
|
|
{
|
|
|
|
GB_Error((char *)E_IOBJECT);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *GB_AppName(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return PROJECT_name;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *GB_AppPath(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return PROJECT_path;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *GB_AppTitle(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return LOCAL_gettext(PROJECT_title);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *GB_AppVersion(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return PROJECT_version;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-10-15 02:23:11 +02:00
|
|
|
void *GB_AppStartupClass(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return PROJECT_class;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_Eval(void *expr, void *func)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-08-29 22:51:10 +02:00
|
|
|
bool err = EVAL_expression((EXPRESSION *)expr, (EVAL_FUNCTION)func);
|
2012-02-19 17:13:38 +01:00
|
|
|
|
2010-08-29 22:51:10 +02:00
|
|
|
EXEC_set_native_error(err);
|
2012-02-19 17:13:38 +01:00
|
|
|
|
2010-08-29 22:51:10 +02:00
|
|
|
if (err)
|
2012-02-19 17:13:38 +01:00
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
|
|
|
return &TEMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Alloc(void **addr, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
ALLOC(addr, len, "GB_Alloc");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Free(void **addr)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
FREE(addr, "GB_Free");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_Realloc(void **addr, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
REALLOC(addr, len, "GB_Realloc");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_Conv(GB_VALUE *arg, GB_TYPE type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CATCH_ERROR
|
|
|
|
{
|
|
|
|
VALUE_conv((VALUE *)arg, (GB_TYPE)type);
|
|
|
|
}
|
|
|
|
END_CATCH_ERROR
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_StringLength(const char *str)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return STRING_length(str);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_NumberToString(int local, double value, const char *format, char **str, int *len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return
|
|
|
|
LOCAL_format_number
|
|
|
|
(
|
|
|
|
value,
|
|
|
|
format ? LF_USER : LF_GENERAL_NUMBER,
|
|
|
|
format,
|
|
|
|
format ? strlen(format) : 0,
|
|
|
|
str, len, local != 0
|
|
|
|
);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_HashTableNew(GB_HASHTABLE *hash, int mode)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
HASH_TABLE_create((HASH_TABLE **)hash, sizeof(void *), mode);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_HashTableAdd(GB_HASHTABLE hash, const char *key, int len, void *data)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (len <= 0)
|
|
|
|
len = strlen(key);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
*((void **)HASH_TABLE_insert((HASH_TABLE *)hash, key, len)) = data;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_HashTableRemove(GB_HASHTABLE hash, const char *key, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
if (len <= 0)
|
|
|
|
len = strlen(key);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
HASH_TABLE_remove((HASH_TABLE *)hash, key, len);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_HashTableGet(GB_HASHTABLE hash, const char *key, int len, void **data)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
void **pdata;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (len <= 0)
|
|
|
|
len = strlen(key);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
pdata = (void **)HASH_TABLE_lookup((HASH_TABLE *)hash, key, len);
|
|
|
|
if (pdata)
|
|
|
|
{
|
|
|
|
*data = *pdata;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_HashTableEnum(GB_HASHTABLE hash, GB_HASHTABLE_ENUM_FUNC func)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
HASH_ENUM iter;
|
|
|
|
void **data;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
CLEAR(&iter);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
data = (void **)HASH_TABLE_next((HASH_TABLE *)hash, &iter);
|
|
|
|
if (!data)
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
(*func)(*data);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_NewArray(void *pdata, int size, int count)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
ARRAY_create_with_size(pdata, size, 16);
|
|
|
|
if (count)
|
2011-07-29 23:13:08 +02:00
|
|
|
ARRAY_add_data(pdata, count, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_CountArray(void *data)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return ARRAY_count(data);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *GB_Add(void *pdata)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return ARRAY_add_void_size(pdata);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
char *GB_NewZeroString(char *src)
|
2010-05-22 20:02:34 +02:00
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
return STRING_new_zero(src);
|
2010-05-22 20:02:34 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
char *GB_TempString(char *src, int len)
|
2008-03-19 15:32:30 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return STRING_new_temp(src, len);
|
2008-03-19 15:32:30 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void GB_FreeString(char **str)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
STRING_unref(str);
|
|
|
|
*str = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_ConvString(char **result, const char *str, int len, const char *src, const char *dst)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
CATCH_ERROR
|
|
|
|
{
|
|
|
|
STRING_conv(result, str, len, src, dst, TRUE);
|
|
|
|
}
|
|
|
|
END_CATCH_ERROR
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *GB_SystemCharset(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return LOCAL_is_UTF8 ? "UTF-8" : LOCAL_encoding;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-06-11 12:44:50 +02:00
|
|
|
char *GB_SystemDomainName(void)
|
|
|
|
{
|
|
|
|
char host[256], domain[256];
|
|
|
|
|
|
|
|
if (gethostname(host, sizeof(host) - 1))
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if (getdomainname(domain, sizeof(domain) - 1))
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if ((strlen(host) + strlen(domain)) > COMMON_BUF_MAX)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
*COMMON_buffer = 0;
|
2008-12-01 01:30:11 +01:00
|
|
|
if (*domain && strcmp(domain, "(none)"))
|
2008-06-11 12:44:50 +02:00
|
|
|
{
|
|
|
|
strcpy(COMMON_buffer, domain);
|
|
|
|
strcat(COMMON_buffer, ".");
|
|
|
|
}
|
|
|
|
strcat(COMMON_buffer, host);
|
|
|
|
|
|
|
|
return COMMON_buffer;
|
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_IsRightToLeft(void)
|
2008-03-18 11:04:10 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return LOCAL_local.rtl;
|
2008-03-18 11:04:10 +01:00
|
|
|
}
|
|
|
|
|
2011-03-24 03:15:32 +01:00
|
|
|
char *GB_SystemPath(void)
|
|
|
|
{
|
|
|
|
return PROJECT_exec_path;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-10-30 01:54:18 +01:00
|
|
|
/*void GB_StreamInit(GB_STREAM *stream, int fd)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
STREAM *s = (STREAM *)stream;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
s->type = &STREAM_direct;
|
|
|
|
s->direct.fd = fd;
|
2008-10-30 01:54:18 +01:00
|
|
|
}*/
|
|
|
|
|
2010-04-05 19:02:16 +02:00
|
|
|
GB_STREAM *GB_StreamGet(void *object)
|
|
|
|
{
|
|
|
|
return (GB_STREAM *)CSTREAM_stream(object);
|
|
|
|
}
|
|
|
|
|
2008-10-30 01:54:18 +01:00
|
|
|
void GB_StreamSetBytesRead(GB_STREAM *stream, int length)
|
|
|
|
{
|
|
|
|
STREAM_eff_read = length;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-11-05 00:53:39 +01:00
|
|
|
void GB_StreamSetSwapping(GB_STREAM *stream, int swap)
|
|
|
|
{
|
|
|
|
((STREAM *)stream)->common.swap = swap;
|
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_StreamBlock(GB_STREAM *stream, int block)
|
2008-11-05 00:53:39 +01:00
|
|
|
{
|
2008-11-08 15:55:03 +01:00
|
|
|
STREAM *st = (STREAM *)stream;
|
2011-05-16 04:16:22 +02:00
|
|
|
bool old = STREAM_is_blocking(st);
|
2008-11-08 15:55:03 +01:00
|
|
|
STREAM_blocking(st, block);
|
2008-11-05 00:53:39 +01:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2010-04-05 19:02:16 +02:00
|
|
|
int GB_StreamRead(GB_STREAM *stream, void *addr, int len)
|
|
|
|
{
|
2011-05-16 04:16:22 +02:00
|
|
|
CATCH_ERROR_INT
|
2010-04-05 19:02:16 +02:00
|
|
|
{
|
2010-04-06 19:00:25 +02:00
|
|
|
if (len < 0)
|
|
|
|
ret = STREAM_read_max((STREAM *)stream, addr, -len);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STREAM_read((STREAM *)stream, addr, len);
|
|
|
|
ret = STREAM_eff_read;
|
|
|
|
}
|
2010-04-05 19:02:16 +02:00
|
|
|
}
|
2011-05-16 04:16:22 +02:00
|
|
|
END_CATCH_ERROR_INT
|
2010-04-05 19:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int GB_StreamWrite(GB_STREAM *stream, void *addr, int len)
|
|
|
|
{
|
2011-05-16 04:16:22 +02:00
|
|
|
CATCH_ERROR_INT
|
2010-04-05 19:02:16 +02:00
|
|
|
{
|
|
|
|
STREAM_write((STREAM *)stream, addr, len);
|
|
|
|
ret = len;
|
|
|
|
}
|
2011-05-16 04:16:22 +02:00
|
|
|
END_CATCH_ERROR_INT
|
2010-04-05 19:02:16 +02:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_tolower(int c)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return tolower(c);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int GB_toupper(int c)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return toupper(c);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-01-01 19:45:35 +01:00
|
|
|
char *GB_TempDir(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
return FILE_make_temp(NULL, NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-01-01 19:45:35 +01:00
|
|
|
char *GB_TempFile(const char *pattern)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
return FILE_make_temp(&len, pattern);
|
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_CopyFile(const char *src, const char *dst)
|
2010-01-01 19:45:35 +01:00
|
|
|
{
|
2010-08-29 22:51:10 +02:00
|
|
|
CATCH_ERROR
|
2010-01-01 19:45:35 +01:00
|
|
|
{
|
|
|
|
FILE_copy(src, dst);
|
|
|
|
}
|
2010-08-29 22:51:10 +02:00
|
|
|
END_CATCH_ERROR
|
2010-01-01 19:45:35 +01:00
|
|
|
}
|
|
|
|
|
2010-04-05 03:44:43 +02:00
|
|
|
#if 0
|
|
|
|
int GB_FindFile(const char *dir, int recursive, int follow, void (*found)(const char *))
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char *pattern;
|
|
|
|
int len_pattern;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
TRY
|
|
|
|
{
|
|
|
|
if (recursive)
|
|
|
|
FILE_recursive_dir(dir, found, NULL, 0, follow);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_dir_first(dir, NULL, 0);
|
|
|
|
while (!FILE_dir_next(&pattern, &len_pattern))
|
|
|
|
{
|
|
|
|
if (!LOCAL_is_UTF8)
|
|
|
|
{
|
2011-09-21 11:42:19 +02:00
|
|
|
if (STRING_conv(&str, pattern, len_pattern, LOCAL_encoding, SC_UTF8, FALSE))
|
2010-04-05 03:44:43 +02:00
|
|
|
STRING_new(&str, pattern, len_pattern);
|
|
|
|
else
|
|
|
|
STRING_ref(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
STRING_new(&str, pattern, len_pattern);
|
|
|
|
|
|
|
|
(*found)(str);
|
|
|
|
STRING_unref(&str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
GAMBAS_Error = TRUE;
|
|
|
|
}
|
|
|
|
END_TRY;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GB_StatFile(const char *path, GB_FILE_STAT *info, int follow)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
TRY
|
|
|
|
{
|
|
|
|
FILE_stat(path, (FILE_STAT *)info, follow);
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
GAMBAS_Error = TRUE;
|
|
|
|
}
|
|
|
|
END_TRY;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *GB_RealFileName(const char *name, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
char *path = STRING_conv_file_name(name, len);
|
|
|
|
char *real;
|
|
|
|
char *temp;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!STREAM_in_archive(path))
|
|
|
|
return path;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
temp = FILE_make_temp(NULL, NULL);
|
|
|
|
real = STRING_new_temp(NULL, strlen(temp) + strlen(path) + strlen("/data/"));
|
|
|
|
snprintf(real, strlen(temp) + strlen(path) + strlen("/data/") + 1, "%s/data/%s", temp, path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
if (!FILE_exist(real))
|
|
|
|
{
|
|
|
|
TRY
|
|
|
|
{
|
|
|
|
FILE_make_path_dir(real);
|
|
|
|
FILE_copy(path, real);
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
real = path;
|
|
|
|
}
|
|
|
|
END_TRY
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
return real;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-04-05 03:44:43 +02:00
|
|
|
static GB_BROWSE_CALLBACK _browse_project_func;
|
|
|
|
|
|
|
|
static void project_file_found(const char *path)
|
|
|
|
{
|
|
|
|
FILE_STAT info;
|
|
|
|
|
|
|
|
FILE_stat(path, &info, FALSE);
|
|
|
|
(*_browse_project_func)(path, info.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GB_BrowseProject(GB_BROWSE_CALLBACK func)
|
|
|
|
{
|
|
|
|
ARCHIVE *arch = NULL;
|
|
|
|
|
|
|
|
ARCHIVE_get_current(&arch);
|
|
|
|
if (!arch || (arch == ARCHIVE_main && !EXEC_arch))
|
|
|
|
{
|
|
|
|
_browse_project_func = func;
|
|
|
|
FILE_recursive_dir(PROJECT_path, project_file_found, NULL, 0, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ARCHIVE_browse(arch, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *GB_CurrentComponent()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-02-19 17:13:38 +01:00
|
|
|
ARCHIVE *arch;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-19 17:13:38 +01:00
|
|
|
ARCHIVE_get_current(&arch);
|
|
|
|
return arch->name ? arch->name : "";
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-01-17 00:12:10 +01:00
|
|
|
|
|
|
|
void *GB_DebugGetExec(void)
|
|
|
|
{
|
|
|
|
return &EXEC_current;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_ExistClass(const char *name)
|
2009-01-17 00:12:10 +01:00
|
|
|
{
|
|
|
|
return CLASS_look_global(name, strlen(name)) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
bool GB_ExistClassLocal(const char *name)
|
2009-01-17 00:12:10 +01:00
|
|
|
{
|
|
|
|
return CLASS_look(name, strlen(name)) != NULL;
|
|
|
|
}
|
2011-09-07 14:38:29 +02:00
|
|
|
|
2012-08-25 00:29:53 +02:00
|
|
|
void GB_Wait(int delay)
|
2011-09-07 14:38:29 +02:00
|
|
|
{
|
2012-08-25 00:29:53 +02:00
|
|
|
struct timespec rem;
|
|
|
|
double wait;
|
|
|
|
double stop, time;
|
2011-09-07 14:38:29 +02:00
|
|
|
|
2012-08-25 00:29:53 +02:00
|
|
|
DEBUG_enter_event_loop();
|
|
|
|
|
|
|
|
if (delay == 0)
|
|
|
|
{
|
|
|
|
HOOK_DEFAULT(wait, WATCH_wait)(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wait = delay / 1000.0;
|
|
|
|
|
|
|
|
DATE_timer(&stop, FALSE);
|
|
|
|
stop += wait;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
HOOK_DEFAULT(wait, WATCH_wait)((int)(wait * 1000 + 0.5));
|
|
|
|
|
|
|
|
if (DATE_timer(&time, FALSE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
wait = stop - time;
|
|
|
|
if (wait <= 0.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
rem.tv_sec = 0;
|
|
|
|
rem.tv_nsec = 1000000;
|
|
|
|
nanosleep(&rem, &rem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_leave_event_loop();
|
|
|
|
}
|
2012-08-26 03:54:57 +02:00
|
|
|
|
|
|
|
bool GB_Serialize(const char *path, GB_VALUE *value)
|
|
|
|
{
|
|
|
|
STREAM stream;
|
|
|
|
|
|
|
|
CATCH_ERROR
|
|
|
|
{
|
|
|
|
STREAM_open(&stream, path, ST_CREATE);
|
|
|
|
STREAM_write_type(&stream, T_VARIANT, (VALUE *)value);
|
|
|
|
STREAM_close(&stream);
|
|
|
|
}
|
|
|
|
END_CATCH_ERROR
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GB_UnSerialize(const char *path, GB_VALUE *value)
|
|
|
|
{
|
|
|
|
STREAM stream;
|
|
|
|
|
|
|
|
CATCH_ERROR
|
|
|
|
{
|
|
|
|
STREAM_open(&stream, path, ST_READ);
|
|
|
|
STREAM_read_type(&stream, T_VARIANT, (VALUE *)value);
|
|
|
|
STREAM_close(&stream);
|
|
|
|
}
|
|
|
|
END_CATCH_ERROR
|
|
|
|
}
|
2012-09-04 01:40:59 +02:00
|
|
|
|