OSDN Git Service

こっそり、気持ち程度の日本語化しました (UTF-8 / Windows 環境用)。
[ring-lang-081/annotated-ring-with-OmegaT.git] / source / src / ring_item.c
1 /*
2 **  Copyright (c) 2013-2019 Mahmoud Fayed <msfclipper@yahoo.com> 
3 **  Header Files 
4 */
5 #include "ring.h"
6
7 RING_API Item * ring_item_new_gc ( void *pState,int ItemType )
8 {
9         Item *pItem  ;
10         pItem = (Item *) ring_state_malloc(pState,sizeof(Item));
11         if ( pItem == NULL ) {
12                 printf( RING_OOM ) ;
13                 exit(0);
14         }
15         /* Set Type */
16         pItem->nType = ITEMTYPE_NOTHING ;
17         /* Delete pointer information */
18         pItem->data.pPointer = NULL ;
19         pItem->nObjectType = 0 ;
20         /* Delete number information */
21         pItem->data.dNumber = 0 ;
22         pItem->data.iNumber = 0 ;
23         pItem->NumberFlag = ITEM_NUMBERFLAG_NOTHING ;
24         /* Reference Count */
25         ring_vm_gc_cleardata(pItem);
26         ring_item_settype_gc(pState,pItem,ItemType);
27         return pItem ;
28 }
29
30 RING_API Item * ring_item_delete_gc ( void *pState,Item *pItem )
31 {
32         assert(pItem != NULL);
33         ring_vm_gc_deleteitem_gc(pState,pItem);
34         return NULL ;
35 }
36
37 RING_API void ring_item_print ( Item *pItem )
38 {
39         int ItemType  ;
40         assert(pItem != NULL);
41         ItemType = pItem->nType ;
42         switch ( ItemType ) {
43                 case ITEMTYPE_NOTHING :
44                         /* Work */
45                         break ;
46                 case ITEMTYPE_STRING :
47                         /* Work */
48                         ring_string_print(pItem->data.pString);
49                         break ;
50                 case ITEMTYPE_NUMBER :
51                         /* Work */
52                         if ( pItem->NumberFlag == ITEM_NUMBERFLAG_INT ) {
53                                 printf( "%d\n ",pItem->data.iNumber ) ;
54                         } else {
55                                 printf( "%f \n",pItem->data.dNumber ) ;
56                         }
57                         break ;
58                 case ITEMTYPE_POINTER :
59                         /* Work */
60                         printf( "%p",pItem->data.pPointer ) ;
61                         break ;
62                 case ITEMTYPE_LIST :
63                         /* Work */
64                         ring_list_print(pItem->data.pList);
65                         break ;
66         }
67 }
68
69 RING_API void ring_item_content_delete_gc ( void *pState,Item *pItem )
70 {
71         assert(pItem != NULL);
72         switch ( pItem->nType ) {
73                 case ITEMTYPE_STRING :
74                         /* Work */
75                         pItem->data.pString = ring_string_delete_gc(pState,pItem->data.pString);
76                         break ;
77                 case ITEMTYPE_LIST :
78                         /* Work */
79                         pItem->data.pList = ring_list_delete_gc(pState,pItem->data.pList);
80                         break ;
81         }
82         /* Set Type */
83         pItem->nType = ITEMTYPE_NOTHING ;
84         /* Delete pointer information */
85         pItem->data.pPointer = NULL ;
86         pItem->nObjectType = 0 ;
87         /* Delete number information */
88         pItem->data.dNumber = 0 ;
89         pItem->data.iNumber = 0 ;
90         pItem->NumberFlag = ITEM_NUMBERFLAG_NOTHING ;
91 }
92
93 RING_API void ring_item_settype_gc ( void *pState,Item *pItem,int ItemType )
94 {
95         assert(pItem != NULL);
96         /* When we set the type we remove the current content at first */
97         ring_item_content_delete_gc(pState,pItem);
98         switch ( ItemType ) {
99                 case ITEMTYPE_NOTHING :
100                         pItem->nType = ITEMTYPE_NOTHING ;
101                         break ;
102                 case ITEMTYPE_STRING :
103                         pItem->nType = ITEMTYPE_STRING ;
104                         pItem->data.pString = ring_string_new_gc(pState,"");
105                         break ;
106                 case ITEMTYPE_NUMBER :
107                         pItem->nType = ITEMTYPE_NUMBER ;
108                         pItem->data.dNumber = 0 ;
109                         pItem->data.iNumber = 0 ;
110                         break ;
111                 case ITEMTYPE_POINTER :
112                         pItem->nType = ITEMTYPE_POINTER ;
113                         pItem->data.pPointer = NULL ;
114                         pItem->nObjectType = 0 ;
115                         break ;
116                 case ITEMTYPE_LIST :
117                         pItem->nType = ITEMTYPE_LIST ;
118                         pItem->data.pList = ring_list_new_gc(pState,0);
119                         break ;
120                 case ITEMTYPE_FUNCPOINTER :
121                         pItem->nType = ITEMTYPE_FUNCPOINTER ;
122                         pItem->data.pFunc = NULL ;
123                         break ;
124         }
125 }
126 /*
127 **  Functions to deal with array of items 
128 **  int 
129 */
130
131 RING_API void ring_itemarray_setint_gc ( void *pState,Item pList[], int index ,int number )
132 {
133         ring_item_settype_gc(pState,&pList[index],ITEMTYPE_NUMBER);
134         pList[index].data.iNumber = number ;
135         pList[index].NumberFlag = ITEM_NUMBERFLAG_INT ;
136 }
137 /* Pointers */
138
139 RING_API void ring_itemarray_setpointer_gc ( void *pState,Item pList[], int index ,void *pValue )
140 {
141         ring_item_settype_gc(pState,&pList[index],ITEMTYPE_POINTER);
142         pList[index].data.pPointer = pValue ;
143         pList[index].nObjectType = 0 ;
144 }
145 /* double */
146
147 RING_API void ring_itemarray_setdouble_gc ( void *pState,Item pList[], int index ,double number )
148 {
149         ring_item_settype_gc(pState,&pList[index],ITEMTYPE_NUMBER);
150         pList[index].data.dNumber = number ;
151         pList[index].NumberFlag = ITEM_NUMBERFLAG_DOUBLE ;
152 }
153 #define ring_list_getint(pList,index) ( ring_list_getitem(pList,index)->data.iNumber )
154 #define ring_list_getpointer(pList,index) ( ring_list_getitem(pList,index)->data.pPointer )
155 #define ring_list_getfuncpointer(pList,index) ( ring_list_getitem(pList,index)->data.pFunc )
156 #define ring_list_callfuncpointer(pList,index,x) ( ring_list_getitem(pList,index)->data.pFunc(x) )
157 #define ring_list_getdouble(pList,index) ring_list_getitem(pList,index)->data.dNumber
158 #define ring_list_getstring(pList,index) ( ring_string_get(ring_item_getstring(ring_list_getitem(pList,index))) )
159 #define ring_list_getstringobject(pList,index) ( ring_item_getstring(ring_list_getitem(pList,index)) )
160 #define ring_list_getstringsize(pList,index) ( ring_string_size(ring_item_getstring(ring_list_getitem(pList,index))) )
161 /* String */
162
163 RING_API void ring_itemarray_setstring_gc ( void *pState,Item pList[], int index ,const char *str )
164 {
165         ring_item_settype_gc(pState,&pList[index],ITEMTYPE_STRING);
166         ring_string_set_gc(pState,pList[index].data.pString ,str);
167 }
168
169 RING_API void ring_itemarray_setstring2_gc ( void *pState,Item pList[], int index ,const char *str,int nStrSize )
170 {
171         ring_item_settype_gc(pState,&pList[index],ITEMTYPE_STRING);
172         ring_string_set2_gc(pState,pList[index].data.pString ,str,nStrSize);
173 }
174 /* Functions to deal with one item */
175
176 RING_API void ring_item_setstring_gc ( void *pState,Item *pItem,const char *cStr )
177 {
178         ring_item_settype_gc(pState,pItem,ITEMTYPE_STRING);
179         ring_string_set_gc(pState,ring_item_getstring(pItem),cStr);
180 }
181
182 RING_API void ring_item_setstring2_gc ( void *pState,Item *pItem,const char *cStr,int nStrSize )
183 {
184         ring_item_settype_gc(pState,pItem,ITEMTYPE_STRING);
185         ring_string_set2_gc(pState,ring_item_getstring(pItem),cStr,nStrSize);
186 }
187
188 RING_API void ring_item_setdouble_gc ( void *pState,Item *pItem,double x )
189 {
190         ring_item_settype_gc(pState,pItem,ITEMTYPE_NUMBER);
191         pItem->data.dNumber = x ;
192         pItem->NumberFlag = ITEM_NUMBERFLAG_DOUBLE ;
193 }
194
195 RING_API void ring_item_setpointer_gc ( void *pState,Item *pItem,void *pValue )
196 {
197         ring_item_settype_gc(pState,pItem,ITEMTYPE_POINTER);
198         pItem->data.pPointer = pValue ;
199         pItem->nObjectType = 0 ;
200 }
201
202 RING_API void ring_item_setint_gc ( void *pState,Item *pItem,int x )
203 {
204         ring_item_settype_gc(pState,pItem,ITEMTYPE_NUMBER);
205         pItem->data.iNumber = x ;
206         pItem->NumberFlag = ITEM_NUMBERFLAG_INT ;
207 }
208 /* Functions without state pointer */
209
210 RING_API Item * ring_item_new ( int ItemType )
211 {
212         return ring_item_new_gc(NULL,ItemType) ;
213 }
214
215 RING_API Item * ring_item_delete ( Item *pItem )
216 {
217         return ring_item_delete_gc(NULL,pItem) ;
218 }
219
220 RING_API void ring_item_settype ( Item *pItem,int ItemType )
221 {
222         ring_item_settype_gc(NULL,pItem,ItemType);
223 }
224
225 RING_API void ring_item_content_delete ( Item *pItem )
226 {
227         ring_item_content_delete_gc(NULL,pItem);
228 }
229 /*
230 **  Functions to deal with array of items 
231 **  int 
232 */
233
234 RING_API void ring_itemarray_setint ( Item pList[], int index ,int number )
235 {
236         ring_itemarray_setint_gc(NULL,pList,index,number);
237 }
238 /* Pointers */
239
240 RING_API void ring_itemarray_setpointer ( Item pList[], int index ,void *pValue )
241 {
242         ring_itemarray_setpointer_gc(NULL,pList,index,pValue);
243 }
244 /* double */
245
246 RING_API void ring_itemarray_setdouble ( Item pList[], int index ,double number )
247 {
248         ring_itemarray_setdouble_gc(NULL,pList,index,number);
249 }
250 /* String */
251
252 RING_API void ring_itemarray_setstring ( Item pList[], int index ,const char *str )
253 {
254         ring_itemarray_setstring_gc(NULL,pList,index,str);
255 }
256
257 RING_API void ring_itemarray_setstring2 ( Item pList[], int index ,const char *str,int nStrSize )
258 {
259         ring_itemarray_setstring2_gc(NULL,pList,index,str,nStrSize);
260 }
261 /* Functions to deal with one item */
262
263 RING_API void ring_item_setstring ( Item *pItem,const char *cStr )
264 {
265         ring_item_setstring_gc(NULL,pItem,cStr);
266 }
267
268 RING_API void ring_item_setdouble ( Item *pItem,double x )
269 {
270         ring_item_setdouble_gc(NULL,pItem,x);
271 }
272
273 RING_API void ring_item_setpointer ( Item *pItem,void *pValue )
274 {
275         ring_item_setpointer_gc(NULL,pItem,pValue);
276 }
277
278 RING_API void ring_item_setint ( Item *pItem,int x )
279 {
280         ring_item_setint_gc(NULL,pItem,x);
281 }
282
283 RING_API void ring_item_setstring2 ( Item *pItem,const char *cStr,int nStrSize )
284 {
285         ring_item_setstring2_gc(NULL,pItem,cStr,nStrSize);
286 }