1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: gentee 18.10.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov
13 * Contributors: SWR
14 *
15 * Summary:
16 *
17 ******************************************************************************/
18
19 #ifndef _COMMON_H_
20 #define _COMMON_H_
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif // __cplusplus
25 #include "types.h"
26
27 #define MEM_EDGE 0xFFFF // Alloc from heap if the memory size
28 // is less or equal than MEM_EDGE
29 #define MEM_HEAPSIZE 0x40000 // The minimum size of the heap
30
31
32 /*--------------------------------------------------------------------------
33 The each memory block begins two bytes.
34 1. The number of heap ( from 0 to MAX_BYTE ).
35 2. The id of block size. The block doesn't belong to any heap if it equals
36 MAX_BYTE.
37 If the block is free then it contains the next free block with the same id.
38 */
39 //--------------------------------------------------------------------------
40
41 pvoid STDCALL mem_alloc( pvmEngine pThis, uint size );
42 pvoid STDCALL mem_copy( pvmEngine pThis, pvoid dest, pvoid src, uint len );
43 uint STDCALL mem_copyuntilzero( pvmEngine pThis, pubyte dest, pubyte src );
44 uint STDCALL mem_deinit( pvmEngine pThis );
45 uint STDCALL mem_free( pvmEngine pThis, pvoid ptr );
46 uint STDCALL mem_getsize( pvmEngine pThis, pvoid ptr );
47 uint STDCALL mem_init( pvmEngine pThis );
48 uint STDCALL mem_len( pvmEngine pThis, pvoid data );
49 void STDCALL mem_move( pvmEngine pThis, pvoid dest, pvoid src, uint len );
50 pvoid STDCALL mem_zero( pvmEngine pThis, pvoid dest, uint len );
51 void STDCALL mem_zeroui( pvmEngine pThis, puint dest, uint len );
52 int STDCALL mem_cmp( pvmEngine pThis, pvoid dest, pvoid src, uint len );
53
54
55
56 //--------------------------------------------------------------------------
57
58 pbuf STDCALL buf_alloc( pvmEngine pThis, pbuf pb, uint size );
59
60 pbuf STDCALL buf_append( pvmEngine pThis, pbuf pb, pubyte src, uint size );
61 pbuf STDCALL buf_appendch( pvmEngine pThis, pbuf pb, ubyte val );
62 pbuf STDCALL buf_appenduint( pvmEngine pThis, pbuf pb, uint val );
63 pbuf STDCALL buf_appendushort( pvmEngine pThis, pbuf pb, ushort val );
64 pbuf STDCALL buf_copy( pvmEngine pThis, pbuf pb, pubyte src, uint size );
65 pbuf STDCALL buf_copyzero( pvmEngine pThis, pbuf pb, pubyte src );
66 void STDCALL buf_delete( pvmEngine pThis, pbuf pb );
67 pbuf STDCALL buf_expand( pvmEngine pThis, pbuf pb, uint size );
68 pbuf STDCALL buf_init( pvmEngine pThis, pbuf pb );
69 pbuf STDCALL buf_insert( pvmEngine pThis, pbuf pb, uint off, pubyte data, uint size );
70 uint STDCALL buf_len( pvmEngine pThis, pbuf pb );
71 pubyte STDCALL buf_ptr( pvmEngine pThis, pbuf pb );
72 pbuf STDCALL buf_reserve( pvmEngine pThis, pbuf pb, uint size );
73 pbuf STDCALL buf_setlen( pvmEngine pThis, pbuf pb, uint size );
74
75 //--------------------------------------------------------------------------
76
77 pvoid STDCALL arr_append( pvmEngine pThis, parr pa );
78 uint STDCALL arr_appenditems( pvmEngine pThis, parr pa, uint count );
79 void STDCALL arr_appendnum( pvmEngine pThis, parr pa, uint val );
80 uint STDCALL arr_count( pvmEngine pThis, parr pa );
81 uint STDCALL arr_getuint( pvmEngine pThis, parr pa, uint num );
82 void STDCALL arr_init( pvmEngine pThis, parr pa, uint size );
83 void STDCALL arr_delete( pvmEngine pThis, parr pa );
84 pvoid STDCALL arr_ptr( pvmEngine pThis, parr pa, uint num );
85 void STDCALL arr_reserve( pvmEngine pThis, parr pa, uint count );
86 void STDCALL arr_setuint( pvmEngine pThis, parr pa, uint num, uint value );
87 void STDCALL arr_step( pvmEngine pThis, parr pa, uint count );
88
89 /*-----------------------------------------------------------------------------
90 *
91 * ID: strtrimflags 19.10.06 0.0.A.
92 *
93 * Summary: Flags for str_trim
94 *
95 -----------------------------------------------------------------------------*/
96
97 #define TRIM_ONE 0x0001 // Delete just one character
98 #define TRIM_RIGHT 0x0002 // Trim the right characters
99
100 //--------------------------------------------------------------------------
101
102 #define str_delete buf_delete
103 #define str_ptr( x ) ( x )->data
104 #define str_reserve buf_reserve
105
106 pstr STDCALL str_copyzero( pvmEngine pThis, pstr ps, pubyte src );
107 pstr STDCALL str_copy( pvmEngine pThis, pstr dest, pstr src );
108 pstr STDCALL str_init( pvmEngine pThis, pstr ps );
109 uint STDCALL str_len( pvmEngine pThis, pstr ps );
110 pstr STDCALL str_setlen( pvmEngine pThis, pstr ps, uint len );
111 pstr STDCALL str_new( pvmEngine pThis, pubyte ptr );
112
113 //--------------------------------------------------------------------------
114
115 puint STDCALL collect_add( pvmEngine pThis, pcollect pclt, puint input, uint type );
116 pubyte STDCALL collect_addptr( pvmEngine pThis, pcollect pclt, pubyte ptr );
117 pubyte STDCALL collect_index( pvmEngine pThis, pcollect pclt, uint index );
118 uint STDCALL collect_gettype( pvmEngine pThis, pcollect pclt, uint index );
119 uint STDCALL collect_count( pvmEngine pThis, pcollect pclt );
120 void STDCALL collect_delete( pvmEngine pThis, pcollect pclt );
121
122 //--------------------------------------------------------------------------
123
124 #define HASH_SIZE 4096
125 phashitem STDCALL hash_create( pvmEngine pThis, phash ph, pubyte name );
126 void STDCALL hash_init( pvmEngine pThis, phash ph, uint size );
127 void STDCALL hash_delete( pvmEngine pThis, phash ph );
128
129
130 //--------------------------------------------------------------------------
131
132 void STDCALL crc_init( pvmEngine pThis );
133 uint STDCALL crc( pvmEngine pThis, pubyte data, uint size, uint seed );
134
135 //--------------------------------------------------------------------------
136
137 pbuf STDCALL file2buf( pvmEngine pThis, pstr name, pbuf ret, uint pos );
138 uint STDCALL buf2file( pvmEngine pThis, pstr name, pbuf ret );
139
140 #include "windows.h"
141 #include <stdio.h>
142 #include <conio.h>
143
144
145 #define os_alloc malloc
146 #define os_free free
147
148 #define os_crlsection_delete DeleteCriticalSection
149 #define os_crlsection_enter EnterCriticalSection
150 #define os_crlsection_init InitializeCriticalSection
151 #define os_crlsection_leave LeaveCriticalSection
152
153 uint STDCALL os_fileclose( uint handle );
154 pstr STDCALL os_filefullname( pvmEngine pThis, pstr filename, pstr result );
155 uint STDCALL os_fileopen( pstr name, uint flag );
156 uint STDCALL os_fileread( uint handle, pubyte data, uint size );
157 ulong64 STDCALL os_filesize( uint handle );
158 uint STDCALL os_filewrite( uint handle, pubyte data, uint size );
159
160 #ifdef __cplusplus
161 }
162 #endif // __cplusplus
163
164 #endif // _COMMON_H_
165