1
1
#ifndef JIM_H_
2
2
#define JIM_H_
3
3
4
- #ifndef JIM_STACK_CAPACITY
5
- #define JIM_STACK_CAPACITY 128
6
- #endif // JIM_STACK_CAPACITY
4
+ #ifndef JIM_SCOPES_CAPACITY
5
+ #define JIM_SCOPES_CAPACITY 128
6
+ #endif // JIM_SCOPES_CAPACITY
7
7
8
8
typedef void * Jim_Sink ;
9
9
typedef size_t (* Jim_Write )(const void * ptr , size_t size , size_t nmemb , Jim_Sink sink );
10
10
11
11
typedef enum {
12
12
JIM_OK = 0 ,
13
13
JIM_WRITE_ERROR ,
14
- JIM_STACK_OVERFLOW ,
15
- JIM_STACK_UNDERFLOW ,
14
+ JIM_SCOPES_OVERFLOW ,
15
+ JIM_SCOPES_UNDERFLOW ,
16
16
JIM_OUT_OF_SCOPE_KEY ,
17
17
JIM_DOUBLE_KEY
18
18
} Jim_Error ;
@@ -34,8 +34,8 @@ typedef struct {
34
34
Jim_Sink sink ;
35
35
Jim_Write write ;
36
36
Jim_Error error ;
37
- Jim_Scope stack [ JIM_STACK_CAPACITY ];
38
- size_t stack_size ;
37
+ Jim_Scope scopes [ JIM_SCOPES_CAPACITY ];
38
+ size_t scopes_size ;
39
39
} Jim ;
40
40
41
41
void jim_null (Jim * jim );
@@ -67,36 +67,36 @@ static size_t jim_strlen(const char *s)
67
67
return count ;
68
68
}
69
69
70
- static void jim_stack_push (Jim * jim , Jim_Scope_Kind kind )
70
+ static void jim_scope_push (Jim * jim , Jim_Scope_Kind kind )
71
71
{
72
72
if (jim -> error == JIM_OK ) {
73
- if (jim -> stack_size < JIM_STACK_CAPACITY ) {
74
- jim -> stack [jim -> stack_size ].kind = kind ;
75
- jim -> stack [jim -> stack_size ].tail = 0 ;
76
- jim -> stack [jim -> stack_size ].key = 0 ;
77
- jim -> stack_size += 1 ;
73
+ if (jim -> scopes_size < JIM_SCOPES_CAPACITY ) {
74
+ jim -> scopes [jim -> scopes_size ].kind = kind ;
75
+ jim -> scopes [jim -> scopes_size ].tail = 0 ;
76
+ jim -> scopes [jim -> scopes_size ].key = 0 ;
77
+ jim -> scopes_size += 1 ;
78
78
} else {
79
- jim -> error = JIM_STACK_OVERFLOW ;
79
+ jim -> error = JIM_SCOPES_OVERFLOW ;
80
80
}
81
81
}
82
82
}
83
83
84
- static void jim_stack_pop (Jim * jim )
84
+ static void jim_scope_pop (Jim * jim )
85
85
{
86
86
if (jim -> error == JIM_OK ) {
87
- if (jim -> stack_size > 0 ) {
88
- jim -> stack_size -- ;
87
+ if (jim -> scopes_size > 0 ) {
88
+ jim -> scopes_size -- ;
89
89
} else {
90
- jim -> error = JIM_STACK_UNDERFLOW ;
90
+ jim -> error = JIM_SCOPES_UNDERFLOW ;
91
91
}
92
92
}
93
93
}
94
94
95
- static Jim_Scope * jim_stack_top (Jim * jim )
95
+ static Jim_Scope * jim_current_scope (Jim * jim )
96
96
{
97
97
if (jim -> error == JIM_OK ) {
98
- if (jim -> stack_size > 0 ) {
99
- return & jim -> stack [jim -> stack_size - 1 ];
98
+ if (jim -> scopes_size > 0 ) {
99
+ return & jim -> scopes [jim -> scopes_size - 1 ];
100
100
}
101
101
}
102
102
@@ -135,7 +135,7 @@ static int jim_get_utf8_char_len(unsigned char ch)
135
135
void jim_element_begin (Jim * jim )
136
136
{
137
137
if (jim -> error == JIM_OK ) {
138
- Jim_Scope * scope = jim_stack_top (jim );
138
+ Jim_Scope * scope = jim_current_scope (jim );
139
139
if (scope && scope -> tail && !scope -> key ) {
140
140
jim_write_cstr (jim , "," );
141
141
}
@@ -145,7 +145,7 @@ void jim_element_begin(Jim *jim)
145
145
void jim_element_end (Jim * jim )
146
146
{
147
147
if (jim -> error == JIM_OK ) {
148
- Jim_Scope * scope = jim_stack_top (jim );
148
+ Jim_Scope * scope = jim_current_scope (jim );
149
149
if (scope ) {
150
150
scope -> tail = 1 ;
151
151
scope -> key = 0 ;
@@ -161,10 +161,10 @@ const char *jim_error_string(Jim_Error error)
161
161
return "There is no error. The developer of this software just had a case of \"Task failed successfully\" https://i.imgur.com/Bdb3rkq.jpg - Please contact the developer and tell them that they are very lazy for not checking errors properly." ;
162
162
case JIM_WRITE_ERROR :
163
163
return "Write error" ;
164
- case JIM_STACK_OVERFLOW :
165
- return "Stack Overflow" ;
166
- case JIM_STACK_UNDERFLOW :
167
- return "Stack Underflow" ;
164
+ case JIM_SCOPES_OVERFLOW :
165
+ return "Stack of Scopes Overflow" ;
166
+ case JIM_SCOPES_UNDERFLOW :
167
+ return "Stack of Scopes Underflow" ;
168
168
case JIM_OUT_OF_SCOPE_KEY :
169
169
return "Out of Scope key" ;
170
170
case JIM_DOUBLE_KEY :
@@ -316,7 +316,7 @@ void jim_array_begin(Jim *jim)
316
316
if (jim -> error == JIM_OK ) {
317
317
jim_element_begin (jim );
318
318
jim_write_cstr (jim , "[" );
319
- jim_stack_push (jim , JIM_ARRAY_SCOPE );
319
+ jim_scope_push (jim , JIM_ARRAY_SCOPE );
320
320
}
321
321
}
322
322
@@ -325,7 +325,7 @@ void jim_array_end(Jim *jim)
325
325
{
326
326
if (jim -> error == JIM_OK ) {
327
327
jim_write_cstr (jim , "]" );
328
- jim_stack_pop (jim );
328
+ jim_scope_pop (jim );
329
329
jim_element_end (jim );
330
330
}
331
331
}
@@ -335,15 +335,15 @@ void jim_object_begin(Jim *jim)
335
335
if (jim -> error == JIM_OK ) {
336
336
jim_element_begin (jim );
337
337
jim_write_cstr (jim , "{" );
338
- jim_stack_push (jim , JIM_OBJECT_SCOPE );
338
+ jim_scope_push (jim , JIM_OBJECT_SCOPE );
339
339
}
340
340
}
341
341
342
342
void jim_member_key (Jim * jim , const char * str , const unsigned int * size )
343
343
{
344
344
if (jim -> error == JIM_OK ) {
345
345
jim_element_begin (jim );
346
- Jim_Scope * scope = jim_stack_top (jim );
346
+ Jim_Scope * scope = jim_current_scope (jim );
347
347
if (scope && scope -> kind == JIM_OBJECT_SCOPE ) {
348
348
if (!scope -> key ) {
349
349
jim_string_no_element (jim , str , size );
@@ -362,7 +362,7 @@ void jim_object_end(Jim *jim)
362
362
{
363
363
if (jim -> error == JIM_OK ) {
364
364
jim_write_cstr (jim , "}" );
365
- jim_stack_pop (jim );
365
+ jim_scope_pop (jim );
366
366
jim_element_end (jim );
367
367
}
368
368
}
0 commit comments