• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Virtual machine Management Terminal User Interface


Commit MetaInfo

Révision4b5982f92602d2d3cd3d5d55717701ab55a5f344 (tree)
l'heure2022-07-31 21:39:28
AuteurKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Message de Log

Initial Implement: KeyVal_RegistData / KeyVal_SearchItem / KeyVal_GetData function.

Change Summary

Modification

--- a/src/common.c
+++ b/src/common.c
@@ -26,7 +26,7 @@
2626 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
2727
2828
29-#define VMTUI_SRC_
29+#define VMTUI_SRC_COMMON
3030 #include "vmtui.h"
3131
3232
--- a/src/common.h
+++ b/src/common.h
@@ -30,7 +30,7 @@
3030
3131 #include "vmtui.h"
3232
33-#ifdef VMTUI_SRC_
33+#ifdef VMTUI_SRC_COMMON
3434 #define VMTUI_COMMON_EXTERN
3535 #else
3636 #define VMTUI_COMMON_EXTERN extern
--- a/src/keyval.c
+++ b/src/keyval.c
@@ -33,7 +33,6 @@
3333 clear
3434 delete
3535 modify
36-append
3736 */
3837
3938 /* ===========================================================================*/
@@ -43,6 +42,134 @@ append
4342
4443 /* ===========================================================================*/
4544 VMTUI_KEYVAL_EXTERN
45+KeyVal_Item *
46+ KeyVal_SearchItem(
47+ KeyVal_Info *p_kvinfo,
48+ char *pstr_key,
49+ KeyVal_Item *p_parent ) {
50+
51+ int i_cnt;
52+ DWord dw_hash;
53+ KeyVal_Item *p_item;
54+
55+ if( NULL == p_kvinfo ) {
56+ return NULL;
57+ }
58+
59+ if( NULL == pstr_key ) {
60+ return NULL;
61+ }
62+
63+ dw_hash = Common_CalcDJBhash( pstr_key );
64+
65+ for( i_cnt = 0; i_cnt < p_kvinfo->i_used; i_cnt++ ) {
66+ p_item = (p_kvinfo->p_items + i_cnt);
67+
68+ if(( NULL != p_parent ) && ( p_item->pv_parent != (void *)p_parent ))
69+ { continue; }
70+
71+ if( p_item->dw_keyhash == dw_hash ) {
72+ if( ! strncmp( p_item->str_key, pstr_key, KEYVAL_MAXLEN_KEY ) ) {
73+ return p_item;
74+ }
75+ }
76+ }
77+
78+ return NULL;
79+}
80+
81+/* ===========================================================================*/
82+VMTUI_KEYVAL_EXTERN
83+KeyVal_Data *
84+ KeyVal_GetData(
85+ KeyVal_Info *p_kvinfo,
86+ char *pstr_key,
87+ KeyVal_Item *p_parent ) {
88+
89+ KeyVal_Item *p_item;
90+
91+ if( NULL == p_kvinfo ) {
92+ return NULL;
93+ }
94+
95+ if( NULL == pstr_key ) {
96+ return NULL;
97+ }
98+
99+ p_item = KeyVal_SearchItem( p_kvinfo, pstr_key, p_parent );
100+ if( NULL == p_item ) {
101+ return NULL;
102+ }
103+
104+ return &(p_item->value);
105+}
106+
107+/* ===========================================================================*/
108+VMTUI_KEYVAL_EXTERN
109+int
110+ KeyVal_RegistData(
111+ KeyVal_Info *p_kvinfo,
112+ char *pstr_key,
113+ KeyVal_Data *p_value,
114+ KeyVal_Item *p_parent ) {
115+
116+ int i_allocs;
117+ KeyVal_Item *p_item;
118+
119+ if( NULL == p_kvinfo ) {
120+ return -0x01;
121+ }
122+
123+ if( NULL == pstr_key ) {
124+ return -0x02;
125+ }
126+
127+ if( NULL == p_value ) {
128+ return -0x03;
129+ }
130+
131+ // Extend Item Memory ---
132+ if( p_kvinfo->i_allocs == p_kvinfo->i_used ) {
133+ i_allocs = p_kvinfo->i_allocs + KEYVAL_DEFAULT_ALLOCS;
134+ p_item = (KeyVal_Item *)realloc( p_kvinfo->p_items, i_allocs );
135+ if( NULL == p_item ) {
136+ return -0x04;
137+ }
138+
139+ memset( (p_item + p_kvinfo->i_allocs), 0x00, sizeof( KeyVal_Info ) * KEYVAL_DEFAULT_ALLOCS );
140+
141+ p_kvinfo->i_allocs = i_allocs;
142+ p_kvinfo->p_items = p_item;
143+
144+ p_item = NULL;
145+ }
146+
147+ // Check duplicate key ---
148+ p_item = KeyVal_SearchItem( p_kvinfo, pstr_key, p_parent );
149+
150+ if( NULL == p_item ) {
151+ // Append Value ----
152+ p_item = (p_kvinfo->p_items + p_kvinfo->i_used);
153+
154+ p_kvinfo->i_used++;
155+
156+ // Set Key string ---
157+ strncpy( p_item->str_key, pstr_key, sizeof( KEYVAL_MAXLEN_KEY ) );
158+ p_item->dw_keyhash = Common_CalcDJBhash( pstr_key );
159+ }
160+
161+ assert( NULL != p_item );
162+
163+ memcpy( &(p_item->value), p_value, sizeof( KeyVal_Data ) );
164+
165+ p_item->pv_parent = (void *)p_parent;
166+
167+ return 0x00;
168+}
169+
170+
171+/* ===========================================================================*/
172+VMTUI_KEYVAL_EXTERN
46173 int
47174 KeyVal_Init(
48175 KeyVal_Info *p_keyval,
--- a/src/keyval.h
+++ b/src/keyval.h
@@ -37,6 +37,12 @@
3737 typedef struct {
3838 Byte b_type;
3939
40+ #define KEYVAL_TYPE_NONE 0x00
41+ #define KEYVAL_TYPE_INT 0x01
42+ #define KEYVAL_TYPE_DWORD 0x02
43+ #define KEYVAL_TYPE_STRING 0x03
44+ #define KEYVAL_TYPE_STRPTR 0x04
45+
4046 union {
4147 int i_val;
4248 DWord dw_val;
@@ -45,22 +51,30 @@ typedef struct {
4551 };
4652 } KeyVal_Data;
4753
54+#define IS_KEYVAL_TYPE_NONE(n) (KEYVAL_TYPE_NONE==((n).b_type))
55+#define IS_KEYVAL_TYPE_NONE_P(n) (KEYVAL_TYPE_NONE==((n)->b_type))
56+#define IS_KEYVAL_TYPE_INT(n) (KEYVAL_TYPE_INT==((n).b_type))
57+#define IS_KEYVAL_TYPE_INT_P(n) (KEYVAL_TYPE_INT==((n)->b_type))
58+#define IS_KEYVAL_TYPE_DWORD(n) (KEYVAL_TYPE_DWORD==((n).b_type))
59+#define IS_KEYVAL_TYPE_DWORD_P(n) (KEYVAL_TYPE_DWORD==((n)->b_type))
60+#define IS_KEYVAL_TYPE_STRING(n) (KEYVAL_TYPE_STRING==((n).b_type))
61+#define IS_KEYVAL_TYPE_STRING_P(n) (KEYVAL_TYPE_STRING==((n)->b_type))
62+
63+#define KEYVAL_DATA_INT(n) (n).i_val
64+#define KEYVAL_DATA_INT_P(n) (n)->i_val
65+#define KEYVAL_DATA_DWORD(n) (n).dw_val
66+#define KEYVAL_DATA_DWORD_P(n) (n)->dw_val
67+#define KEYVAL_DATA_STR(n) (n).str_val
68+#define KEYVAL_DATA_STR_P(n) (n)->str_val
4869
4970 typedef struct {
50- Byte b_depth;
51-
52- #define KEYVAL_TYPE_NONE 0x00
53- #define KEYVAL_TYPE_INT 0x01
54- #define KEYVAL_TYPE_DWORD 0x02
55- #define KEYVAL_TYPE_STRING 0x03
56- #define KEYVAL_TYPE_STRPTR 0x04
57-
5871 DWord dw_keyhash;
59- int i_child;
60- int i_next;
61-
6272 char str_key[KEYVAL_MAXLEN_KEY];
6373
74+ KeyVal_Data value;
75+
76+ void *pv_parent;
77+
6478 } KeyVal_Item;
6579
6680 typedef struct {
@@ -74,6 +88,15 @@ typedef struct {
7488 #else
7589 #define VMTUI_KEYVAL_EXTERN extern
7690 #endif
91+VMTUI_KEYVAL_EXTERN KeyVal_Item *KeyVal_SearchItem(
92+ KeyVal_Info *p_kvinfo, char *pstr_key,
93+ KeyVal_Item *p_parent );
94+VMTUI_KEYVAL_EXTERN KeyVal_Data *KeyVal_GetData(
95+ KeyVal_Info *p_kvinfo, char *pstr_key,
96+ KeyVal_Item *p_parent );
97+VMTUI_KEYVAL_EXTERN int KeyVal_RegistData(
98+ KeyVal_Info *p_kvinfo, char *pstr_key,
99+ KeyVal_Data *p_value, KeyVal_Item *p_parent );
77100 VMTUI_KEYVAL_EXTERN int KeyVal_Init( KeyVal_Info *p_keyval, int i_allocs );
78101 VMTUI_KEYVAL_EXTERN int KeyVal_Term( KeyVal_Info *p_keyval );
79102