EnglishРусский  

   ..

   arr.g

   arrstr.g

   arrustr.g

   buf.g

   console.g

   fcopy.g

   ffind.g

   file.g

   hash.g

   math.g

   process.g

   search.g

   stack.g

   stdlib.g

   str.g

   stradv.g

   strfile.g

   system.g

   ustr.g

The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

source\lib\stdlib\system.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2004-2008, 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 * Author: Alexander Krivonogov ( algen )
 11 *
 12 ******************************************************************************/
 13 
 14 /*-----------------------------------------------------------------------------
 15 * Id: system L "System"
 16 * 
 17 * Summary: System functions.
 18 *
 19 * List: *,max,min,
 20         *Callback and search features,callback,freecallback,getid,
 21         *Type functions,destroy,new,sizeof,type_delete,type_hasdelete,
 22         type_hasinit,type_init  
 23 * 
 24 -----------------------------------------------------------------------------*/
 25 
 26 define <export>
 27 {
 28 /*-----------------------------------------------------------------------------
 29 * Id: getidflags D
 30 * 
 31 * Summary: Flags for getid function.
 32 *
 33 -----------------------------------------------------------------------------*/
 34     GETID_METHOD   = 0x01 // Search method. Specify the main type of the /
 35                           // method as the first parameter in the collection.  
 36     GETID_OPERATOR = 0x02 // Search operator. You can specify the operator in /
 37                           // name as is. For example, #b(+=).
 38     GETID_OFTYPE   = 0x04 // Specify this flag if you want to describe /
 39                   // parameters with types of items (of type). In this case, /
 40                   // collection must contains pairs - idtype and idoftype.
 41 //-----------------------------------------------------------------------------
 42 }
 43 
 44 /*-----------------------------------------------------------------------------
 45 * Id: max F
 46 *
 47 * Summary: Determining the largest of two numbers. 
 48 *  
 49 * Params: left - The first compared number of the uint type. 
 50           right - The second compared number of the uint type. 
 51 * 
 52 * Return: The largest of two numbers.
 53 *
 54 -----------------------------------------------------------------------------*/
 55 
 56 func  uint  max( uint left, uint right )
 57 {
 58    return ?( left > right, left, right )
 59 }
 60 
 61 /*-----------------------------------------------------------------------------
 62 * Id: min F
 63 *
 64 * Summary: Determining the smallest of two numbers. 
 65 *  
 66 * Params: left - The first compared number of the uint type. 
 67           right - The second compared number of the uint type. 
 68 * 
 69 * Return: The smallest of two numbers.
 70 *
 71 -----------------------------------------------------------------------------*/
 72 
 73 func  uint  min( uint left, uint right )
 74 {
 75    return ?( left < right, left, right )
 76 }
 77 
 78 /*-----------------------------------------------------------------------------
 79 * Id: max_1 F8
 80 *
 81 * Summary: Determining the largest of two int numbers. 
 82 *  
 83 * Params: left - The first compared number of the int type. 
 84           right - The second compared number of the int type. 
 85 * 
 86 * Return: The largest of two int numbers.
 87 *
 88 -----------------------------------------------------------------------------*/
 89 
 90 func  uint  max( int left, int right )
 91 {
 92    return ?( left > right, left, right )
 93 }
 94 
 95 /*-----------------------------------------------------------------------------
 96 * Id: min_1 F8
 97 *
 98 * Summary: Determining the smallest of two int numbers. 
 99 *  
100 * Params: left - The first compared number of the int type. 
101           right - The second compared number of the int type. 
102 * 
103 * Return: The smallest of two int numbers.
104 *
105 -----------------------------------------------------------------------------*/
106 
107 func  uint  min( int left, int right )
108 {
109    return ?( left < right, left, right )
110 }
111 
112 /*-----------------------------------------------------------------------------
113 * Id: new F
114 *
115 * Summary: Creating an object. The function creates an object of the specified
116            type.   
117 *  
118 * Params: objtype - The identifier or the name of a type. 
119 * 
120 * Return: The pointer to the created object.
121 *
122 -----------------------------------------------------------------------------*/
123 
124 func uint new( uint objtype )
125 {
126    return new( objtype, 0 )
127 }
128 
129 /*-----------------------------------------------------------------------------
130 * Id: new_1 F8
131 *
132 * Summary: The function creates an object with specifing the count and the 
133            type of its items.   
134 *  
135 * Params: objtype - The identifier or the name of a type.
136           oftype - The type of object's items. 
137           count - The initial count of object's items. 
138 * 
139 * Return: The pointer to the created object.
140 *
141 -----------------------------------------------------------------------------*/
142 
143 func uint new( uint objtype, uint oftype, uint count )
144 {
145    uint ret funcof
146    
147    ret = new( objtype, 0 )
148    if oftype && funcof = getid("oftype", 1 /*GETID_METHOD*/, 
149                                  %{ objtype, uint } )  
150    {
151       funcof->func( ret, oftype )
152    }
153    if count && funcof = getid("array", 1 /*GETID_METHOD*/, %{ objtype, uint } )  
154    {
155       funcof->func( ret, count )
156    }
157    return ret
158 }
159 
160 /*
161 50             push eax
162 55             push ebp
163 53             push ebx
164 8B DC          mov  ebx, esp
165 83 C3 XX       add  ebx, ( parsize * 4 + 0Ch )
166 8B EB          mov  ebp, ebx 
167 83 ED XX       sub  ebp, ( parsize * 4 )
168 3B EB          cmp  ebp, ebx
169 74 08          je   endcopy 
170 8B 03          mov  eax, [ebx] 
171 50             push eax
172 83 EB 04       sub  ebx, 4 
173 EB F4          jmp  copy 
174 83 ED 04       sub  ebp, 4
175 55             push ebp 
176 68 01 01 00 00 push id
177 ba XX XX XX XX mov  edx,  &ge_call
178 ff d2          call edx
179 83 C4 XX       add  esp, ( parsize + 2 )* 4 
180 5B             pop ebx
181 5D             pop ebp
182 58             pop eax 
183 C2 XX          ret ( parsize * 4 )
184 00
185 */
186 
187 import "kernel32.dll"
188 {
189 uint VirtualAlloc( uint, uint, uint, uint )
190 uint VirtualFree( uint, uint, uint )
191 }
192 
193 /*-----------------------------------------------------------------------------
194 * Id: callback F
195 *
196 * Summary: Create a callback function. This function allows you to use gentee
197            functions as callback functions. For example, gentee function 
198            can be specified as a message handler for windows. 
199 *  
200 * Params: idfunc - Identifier ( address ) of gentee function that will be /
201                    callback function.
202           parsize - The summary size of parameters (number of uint values). /
203           One parameter uint = 1 (uint = 1). uint + uint = 2, uint + long = 3. 
204 * 
205 * Return: You can use the return value as the callback address. You have to 
206           free it with #a(freecallback) function when you don't need this
207           callback function. 
208 *
209 -----------------------------------------------------------------------------*/
210 
211 func uint callback( uint idfunc, uint parsize )
212 {     
213    buf  bc = '\h
214 50            
215 55            
216 53            
217 8B DC         
218 83 C3 \(byte( parsize * 4 + 0x0C ))      
219 8B EB         
220 83 ED \(byte( parsize * 4 ))      
221 3B EB         
222 74 08         
223 8B 03         
224 50            
225 83 EB 04      
226 EB F4         
227 83 ED 04      
228 55            
229 68 \( idfunc )
230 b8 \( calladdr() )
231 ff d0
232 83 C4 \(byte( ( parsize + 2 )* 4 ))      
233 5B            
234 5D            
235 58            
236 C2 \( parsize * 4 )         
237 00
238 '
239 // ba \( calladdr() ) till 12.01.09
240 // ff d2         
241    uint pmem
242    pmem = VirtualAlloc( 0, *bc, 0x3000,  0x40 )
243    //print( "mem = \(hex2strl(pmem))\n" )
244    mcopy( pmem, bc.ptr(), *bc )      
245    return pmem
246    
247 }
248 
249 /*-----------------------------------------------------------------------------
250 ** Id: freecallback F
251 *
252 * Summary: Free a created callback function.  
253 *  
254 * Params: pmem - The pointer that was returned by #a(callback) function.
255 * 
256 -----------------------------------------------------------------------------*/
257 
258 func freecallback( uint pmem )
259 {
260    VirtualFree( pmem, 0, 0x8000 )   
261 }
262 
263 
264