ZealOS/docs/Home/Net/Utilities/JSON/JSON.CC.html
TomAwezome 1b75d91002 Fix Mount AHCI Port selection.
Add arg to SATARep to specify drive types to show.
Add checks in AHCIPortInit to verify port signatures, add helper method to get signatures from port.
2021-08-02 16:40:05 -04:00

335 lines
29 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.13">
<style type="text/css">
body {background-color:#fef1f0;}
.cF0{color:#000000;background-color:#fef1f0;}
.cF1{color:#0148a4;background-color:#fef1f0;}
.cF2{color:#3b7901;background-color:#fef1f0;}
.cF3{color:#057c7e;background-color:#fef1f0;}
.cF4{color:#bb2020;background-color:#fef1f0;}
.cF5{color:#9e42ae;background-color:#fef1f0;}
.cF6{color:#b57901;background-color:#fef1f0;}
.cF7{color:#b2b6af;background-color:#fef1f0;}
.cF8{color:#555753;background-color:#fef1f0;}
.cF9{color:#678fbb;background-color:#fef1f0;}
.cFA{color:#82bc49;background-color:#fef1f0;}
.cFB{color:#0097a2;background-color:#fef1f0;}
.cFC{color:#e26a6a;background-color:#fef1f0;}
.cFD{color:#c671bc;background-color:#fef1f0;}
.cFE{color:#c7ab00;background-color:#fef1f0;}
.cFF{color:#fef1f0;background-color:#fef1f0;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> JSONT_INVALID </span><span class=cFE>0</span><span class=cF0>
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_STRING </span><span class=cFE>1</span><span class=cF0>
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_INTEGER </span><span class=cFE>2</span><span class=cF0>
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_FLOAT </span><span class=cFE>3</span><span class=cF0>
<a name="l5"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_ARRAY </span><span class=cFE>4</span><span class=cF0>
<a name="l6"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_BOOL </span><span class=cFE>5</span><span class=cF0>
<a name="l7"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_OBJ </span><span class=cFE>6</span><span class=cF0>
<a name="l8"></a>#</span><span class=cF1>define</span><span class=cF0> JSONT_NULL </span><span class=cFE>7</span><span class=cF0>
<a name="l9"></a>
<a name="l10"></a>#</span><span class=cF1>define</span><span class=cF0> JSON_HASHTABLE_SIZE </span><span class=cFE>1024</span><span class=cF0>
<a name="l11"></a>
<a name="l12"></a>#</span><span class=cF1>define</span><span class=cF0> HTT_JSON </span><span class=cFE>0x00100</span><span class=cF0> </span><span class=cF2>//identical to HTT_DICT_WORD</span><span class=cF0>
<a name="l13"></a>
<a name="l14"></a></span><span class=cF1>class</span><span class=cF0> CJSONDataEntry:</span><span class=cF9>CQueue</span><span class=cF0>
<a name="l15"></a>{
<a name="l16"></a> </span><span class=cF1>U8</span><span class=cF0> type;
<a name="l17"></a>
<a name="l18"></a> </span><span class=cF9>I64</span><span class=cF0> int_data;
<a name="l19"></a> </span><span class=cF1>F64</span><span class=cF0> float_data;
<a name="l20"></a> </span><span class=cF1>U8</span><span class=cF0> *string_data;
<a name="l21"></a> </span><span class=cF1>Bool</span><span class=cF0> bool_data;
<a name="l22"></a> CJSONDataEntry *list_data;
<a name="l23"></a> </span><span class=cF9>CHashTable</span><span class=cF0> *hash_table;
<a name="l24"></a>};
<a name="l25"></a>
<a name="l26"></a></span><span class=cF1>class</span><span class=cF0> CJSONDataHash:</span><span class=cF9>CHash</span><span class=cF0>
<a name="l27"></a>{
<a name="l28"></a> CJSONDataEntry *data;
<a name="l29"></a>};
<a name="l30"></a>
<a name="l31"></a></span><span class=cF1>U8</span><span class=cF0> **JSONGetKeys(</span><span class=cF9>CHashTable</span><span class=cF0> *table)
<a name="l32"></a>{
<a name="l33"></a> </span><span class=cF9>I64</span><span class=cF0> i, count = </span><span class=cFE>0</span><span class=cF0>;
<a name="l34"></a> </span><span class=cF9>CHash</span><span class=cF0> *temp_hash;
<a name="l35"></a> </span><span class=cF1>U8</span><span class=cF0> **keys;
<a name="l36"></a> </span><span class=cF9>I64</span><span class=cF0> key_index = </span><span class=cFE>0</span><span class=cF0>;
<a name="l37"></a>
<a name="l38"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt;= table-&gt;mask; i++) </span><span class=cF2>//mask is table length 0-based</span><span class=cF0>
<a name="l39"></a> </span><span class=cF1>if</span><span class=cF0> (temp_hash = table-&gt;body[i]) </span><span class=cF2>//if temp_hash exists</span><span class=cF0>
<a name="l40"></a> count++;
<a name="l41"></a>
<a name="l42"></a> keys = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0>*</span><span class=cF7>)</span><span class=cF0> * count); </span><span class=cF2>// alloc string list</span><span class=cF0>
<a name="l43"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt;= table-&gt;mask; i++)
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (temp_hash = table-&gt;body[i])
<a name="l45"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l46"></a> keys[key_index] = </span><span class=cF5>StrNew</span><span class=cF0>(temp_hash-&gt;str);</span><span class=cF2>//add key string to list</span><span class=cF0>
<a name="l47"></a> key_index++;
<a name="l48"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l49"></a>
<a name="l50"></a> </span><span class=cF1>return</span><span class=cF0> keys;
<a name="l51"></a>}
<a name="l52"></a>
<a name="l53"></a></span><span class=cF1>U0</span><span class=cF0> JSONIndentLine(</span><span class=cF9>I64</span><span class=cF0> indent)
<a name="l54"></a>{
<a name="l55"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l56"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>for (i = 0; i &lt; indent; i++) {&quot; &quot;;}</span><span class=cF0>
<a name="l57"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; indent; i++) </span><span class=cF7>{</span><span class=cF6>&quot;</span><span class=cF0> </span><span class=cF6>&quot;</span><span class=cF0>;</span><span class=cF7>}</span><span class=cF0>
<a name="l58"></a>
<a name="l59"></a>}
<a name="l60"></a>
<a name="l61"></a></span><span class=cF1>U0</span><span class=cF0> JSONDataRep(CJSONDataEntry *data, </span><span class=cF9>I64</span><span class=cF0> indent=</span><span class=cFE>0</span><span class=cF0>)
<a name="l62"></a>{
<a name="l63"></a> </span><span class=cF1>U8</span><span class=cF0> **keys;</span><span class=cF2>// = JSONGetKeys(data-&gt;hash_table);</span><span class=cF0>
<a name="l64"></a> </span><span class=cF9>I64</span><span class=cF0> index;
<a name="l65"></a> </span><span class=cF9>I64</span><span class=cF0> count;</span><span class=cF2>// = MSize(keys) / sizeof(U8*);</span><span class=cF0>
<a name="l66"></a> CJSONDataEntry *entry;</span><span class=cF2>// = data-&gt;list_data-&gt;next;//one after head.</span><span class=cF0>
<a name="l67"></a> CJSONDataHash *temp_hash;
<a name="l68"></a>
<a name="l69"></a> JSONIndentLine(indent);
<a name="l70"></a>
<a name="l71"></a> </span><span class=cF1>switch</span><span class=cF0> (data-&gt;type)
<a name="l72"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l73"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_INVALID:
<a name="l74"></a> </span><span class=cF6>&quot;Invalid JSON.\n&quot;</span><span class=cF0>;
<a name="l75"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l76"></a>
<a name="l77"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_STRING:
<a name="l78"></a> </span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>, data-&gt;string_data;
<a name="l79"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l80"></a>
<a name="l81"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_INTEGER:
<a name="l82"></a> </span><span class=cF6>&quot;%d\n&quot;</span><span class=cF0>, data-&gt;int_data;
<a name="l83"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l84"></a>
<a name="l85"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_FLOAT:
<a name="l86"></a> </span><span class=cF6>&quot;%.9f\n&quot;</span><span class=cF0>, data-&gt;float_data;
<a name="l87"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l88"></a>
<a name="l89"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_BOOL:
<a name="l90"></a> </span><span class=cF6>&quot;%Z\n&quot;</span><span class=cF0>, data-&gt;bool_data, </span><span class=cF6>&quot;ST_FALSE_TRUE&quot;</span><span class=cF0>;
<a name="l91"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l92"></a>
<a name="l93"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_NULL:
<a name="l94"></a> </span><span class=cF6>&quot;Null.\n&quot;</span><span class=cF0>;
<a name="l95"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l96"></a>
<a name="l97"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_ARRAY:
<a name="l98"></a> </span><span class=cF6>&quot;Array:\n&quot;</span><span class=cF0>;
<a name="l99"></a> JSONIndentLine(indent);
<a name="l100"></a> </span><span class=cF6>&quot;[\n&quot;</span><span class=cF0>;
<a name="l101"></a> entry = data-&gt;list_data-&gt;next;</span><span class=cF2>//one after head.</span><span class=cF0>
<a name="l102"></a> </span><span class=cF1>while</span><span class=cF0> (entry != data-&gt;list_data)</span><span class=cF2>//head ignored, stop on head.</span><span class=cF0>
<a name="l103"></a> {
<a name="l104"></a> JSONDataRep(entry, indent + </span><span class=cFE>1</span><span class=cF0>); </span><span class=cF2>// recursive Rep on the list entry</span><span class=cF0>
<a name="l105"></a> entry = entry-&gt;next;
<a name="l106"></a> }
<a name="l107"></a> JSONIndentLine(indent);
<a name="l108"></a> </span><span class=cF6>&quot;]\n&quot;</span><span class=cF0>;
<a name="l109"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF1>case</span><span class=cF0> JSONT_OBJ:
<a name="l112"></a> </span><span class=cF6>&quot;Object.\n&quot;</span><span class=cF0>;
<a name="l113"></a> JSONIndentLine(indent);
<a name="l114"></a> </span><span class=cF6>&quot;{\n&quot;</span><span class=cF0>;
<a name="l115"></a>
<a name="l116"></a> keys = JSONGetKeys(data-&gt;hash_table);
<a name="l117"></a> count = </span><span class=cF5>MSize</span><span class=cF0>(keys) / </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0>*);
<a name="l118"></a>
<a name="l119"></a> </span><span class=cF1>for</span><span class=cF0> (index = </span><span class=cFE>0</span><span class=cF0>; index &lt; count; index++)
<a name="l120"></a> {
<a name="l121"></a> JSONIndentLine(indent);
<a name="l122"></a> </span><span class=cF6>&quot;Key: %s\n&quot;</span><span class=cF0>, keys[index];
<a name="l123"></a> temp_hash = </span><span class=cF5>HashFind</span><span class=cF0>(keys[index], data-&gt;hash_table, HTT_JSON);
<a name="l124"></a> JSONDataRep(temp_hash-&gt;data, indent + </span><span class=cFE>1</span><span class=cF0>);
<a name="l125"></a> }
<a name="l126"></a> JSONIndentLine(indent);
<a name="l127"></a> </span><span class=cF6>&quot;}\n&quot;</span><span class=cF0>;
<a name="l128"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l129"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l130"></a>}
<a name="l131"></a>
<a name="l132"></a>CJSONDataEntry *JSONParse(</span><span class=cF9>CCompCtrl</span><span class=cF0> *cc)
<a name="l133"></a>{
<a name="l134"></a> CJSONDataEntry *result = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CJSONDataEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l135"></a> </span><span class=cF9>I64</span><span class=cF0> tk, last_tk;
<a name="l136"></a> </span><span class=cF1>Bool</span><span class=cF0> is_done = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l137"></a> CJSONDataEntry *temp_entry;</span><span class=cF2>// = JSONParse(cc);</span><span class=cF0>
<a name="l138"></a> CJSONDataHash *temp_hash = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CJSONDataHash</span><span class=cF7>)</span><span class=cF0>);
<a name="l139"></a>
<a name="l140"></a> </span><span class=cF1>while</span><span class=cF0> (tk = </span><span class=cF5>Lex</span><span class=cF7>(</span><span class=cF0>cc</span><span class=cF7>)</span><span class=cF0>)
<a name="l141"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l142"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>ClassRep(cc);</span><span class=cF0>
<a name="l143"></a> </span><span class=cF1>switch</span><span class=cF0> (tk)
<a name="l144"></a> {
<a name="l145"></a>
<a name="l146"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'}'</span><span class=cF0>:
<a name="l147"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected Value, got '}'.&quot;</span><span class=cF0>);
<a name="l148"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>TK_STR</span><span class=cF0>:
<a name="l149"></a> result-&gt;type = JSONT_STRING;
<a name="l150"></a> result-&gt;string_data = </span><span class=cF5>StrNew</span><span class=cF0>(cc-&gt;cur_str);
<a name="l151"></a>
<a name="l152"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l153"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l154"></a>
<a name="l155"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>TK_I64</span><span class=cF0>: </span><span class=cF2>//todo, LexExcept on 0x or 0b vals.</span><span class=cF0>
<a name="l156"></a> result-&gt;type = JSONT_INTEGER;
<a name="l157"></a> result-&gt;int_data = cc-&gt;cur_i64;
<a name="l158"></a>
<a name="l159"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>LexPush(cc);</span><span class=cF0>
<a name="l160"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>&quot;got hex val, token string is %s\n&quot;,cc-&gt;cur_str;</span><span class=cF0>
<a name="l161"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>ClassRep(cc);</span><span class=cF0>
<a name="l162"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>Break;</span><span class=cF0>
<a name="l163"></a>
<a name="l164"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l165"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l166"></a>
<a name="l167"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>TK_F64</span><span class=cF0>:
<a name="l168"></a> result-&gt;type = JSONT_FLOAT;
<a name="l169"></a> result-&gt;float_data = cc-&gt;cur_f64;
<a name="l170"></a>
<a name="l171"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l172"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l173"></a>
<a name="l174"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>TK_IDENT</span><span class=cF0>:
<a name="l175"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>cc-&gt;cur_str, </span><span class=cF6>&quot;true&quot;</span><span class=cF7>)</span><span class=cF0> ||
<a name="l176"></a> !</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>cc-&gt;cur_str, </span><span class=cF6>&quot;false&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l177"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l178"></a> result-&gt;type = JSONT_BOOL;
<a name="l179"></a>
<a name="l180"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>cc-&gt;cur_str, </span><span class=cF6>&quot;true&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l181"></a> result-&gt;bool_data = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l182"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>cc-&gt;cur_str, </span><span class=cF6>&quot;false&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l183"></a> result-&gt;bool_data = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l184"></a>
<a name="l185"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l186"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>cc-&gt;cur_str, </span><span class=cF6>&quot;null&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l188"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l189"></a> result-&gt;type = JSONT_NULL;
<a name="l190"></a>
<a name="l191"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l192"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l193"></a>
<a name="l194"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l195"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l196"></a>
<a name="l197"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'['</span><span class=cF0>:
<a name="l198"></a> result-&gt;type = JSONT_ARRAY;
<a name="l199"></a> result-&gt;list_data = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CJSONDataEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l200"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(result-&gt;list_data);
<a name="l201"></a>
<a name="l202"></a>lex_listitem:
<a name="l203"></a></span><span class=cF2>/*</span><span class=cF0>
<a name="l204"></a> </span><span class=cF2>CCompCtrl* temp_cc = NULL;</span><span class=cF0>
<a name="l205"></a> </span><span class=cF2>MemCopy(temp_cc, cc, CompCtrlSize(cc));</span><span class=cF0>
<a name="l206"></a> </span><span class=cF2>tk = Lex(temp_cc);</span><span class=cF0>
<a name="l207"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>CompCtrlDel(temp_cc);</span><span class=cF0>
<a name="l208"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l209"></a> last_tk = tk;
<a name="l210"></a> </span><span class=cF5>LexPush</span><span class=cF0>(cc);
<a name="l211"></a> tk = </span><span class=cF5>Lex</span><span class=cF0>(cc);
<a name="l212"></a>
<a name="l213"></a> </span><span class=cF1>if</span><span class=cF0> (last_tk == </span><span class=cF6>','</span><span class=cF0> &amp;&amp; tk == </span><span class=cF6>']'</span><span class=cF0>)
<a name="l214"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected List value, got ']'&quot;</span><span class=cF0>);
<a name="l215"></a>
<a name="l216"></a> </span><span class=cF1>if</span><span class=cF0> (tk == </span><span class=cF6>']'</span><span class=cF0>)
<a name="l217"></a> </span><span class=cF1>goto</span><span class=cF0> lex_listdone;
<a name="l218"></a>
<a name="l219"></a> </span><span class=cF1>if</span><span class=cF0> (tk == </span><span class=cF6>','</span><span class=cF0>)
<a name="l220"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected List Value, got comma.&quot;</span><span class=cF0>);
<a name="l221"></a>
<a name="l222"></a> </span><span class=cF5>LexPopRestore</span><span class=cF0>(cc);
<a name="l223"></a> temp_entry = JSONParse(cc);
<a name="l224"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(temp_entry, result-&gt;list_data-&gt;last);
<a name="l225"></a>
<a name="l226"></a> tk = </span><span class=cF5>Lex</span><span class=cF0>(cc);
<a name="l227"></a> </span><span class=cF1>if</span><span class=cF0> (tk == </span><span class=cF6>','</span><span class=cF0>)
<a name="l228"></a> </span><span class=cF1>goto</span><span class=cF0> lex_listitem;
<a name="l229"></a>
<a name="l230"></a>lex_listdone:
<a name="l231"></a>
<a name="l232"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>LexPopNoRestore(cc);</span><span class=cF0>
<a name="l233"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l234"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l235"></a>
<a name="l236"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'{'</span><span class=cF0>:
<a name="l237"></a> result-&gt;type = JSONT_OBJ;
<a name="l238"></a> result-&gt;hash_table = </span><span class=cF5>HashTableNew</span><span class=cF0>(JSON_HASHTABLE_SIZE);
<a name="l239"></a>
<a name="l240"></a>lex_objkey:
<a name="l241"></a> </span><span class=cF2>//lex next. expect TK_STR. Make a temp_hash.</span><span class=cF0>
<a name="l242"></a> last_tk = tk;
<a name="l243"></a> tk = </span><span class=cF5>Lex</span><span class=cF0>(cc);
<a name="l244"></a>
<a name="l245"></a> </span><span class=cF1>if</span><span class=cF0> (last_tk == </span><span class=cF6>','</span><span class=cF0> &amp;&amp; tk == </span><span class=cF6>'}'</span><span class=cF0>)
<a name="l246"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected Key after comma.&quot;</span><span class=cF0>);
<a name="l247"></a>
<a name="l248"></a> </span><span class=cF1>if</span><span class=cF0> (tk == </span><span class=cF6>'}'</span><span class=cF0>)
<a name="l249"></a> </span><span class=cF1>goto</span><span class=cF0> lex_objdone;
<a name="l250"></a>
<a name="l251"></a> </span><span class=cF1>if</span><span class=cF0> (tk != </span><span class=cF3>TK_STR</span><span class=cF0>)
<a name="l252"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected Key String.&quot;</span><span class=cF0>);
<a name="l253"></a>
<a name="l254"></a> temp_hash = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CJSONDataHash</span><span class=cF7>)</span><span class=cF0>);
<a name="l255"></a>
<a name="l256"></a> </span><span class=cF2>//set hash type and StrNew with cc-&gt;cur_str into hash str.</span><span class=cF0>
<a name="l257"></a> temp_hash-&gt;type = HTT_JSON;
<a name="l258"></a> temp_hash-&gt;str = </span><span class=cF5>StrNew</span><span class=cF0>(cc-&gt;cur_str);
<a name="l259"></a>
<a name="l260"></a> </span><span class=cF2>//lex next. expect ':'. </span><span class=cF0>
<a name="l261"></a> tk = </span><span class=cF5>Lex</span><span class=cF0>(cc);
<a name="l262"></a> </span><span class=cF1>if</span><span class=cF0> (tk != </span><span class=cF6>':'</span><span class=cF0>)
<a name="l263"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected ':' after Key String.&quot;</span><span class=cF0>);
<a name="l264"></a>
<a name="l265"></a> </span><span class=cF2>//now expect JSONDataEntry-able value next.</span><span class=cF0>
<a name="l266"></a> </span><span class=cF2>//Recursive JSONParse into hash data member.</span><span class=cF0>
<a name="l267"></a> temp_hash-&gt;data = JSONParse(cc);
<a name="l268"></a>
<a name="l269"></a> </span><span class=cF2>//JSONParse leaves off on the last token. e.g. int, tk will</span><span class=cF0>
<a name="l270"></a> </span><span class=cF2>//still be TK_I64.</span><span class=cF0>
<a name="l271"></a>
<a name="l272"></a> </span><span class=cF2>//add hash to result hash_table.</span><span class=cF0>
<a name="l273"></a> </span><span class=cF5>HashAdd</span><span class=cF0>(temp_hash, result-&gt;hash_table);
<a name="l274"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>&quot;Debugging.\nHash added with str:%s.\n&quot;,temp_hash-&gt;str;</span><span class=cF0>
<a name="l275"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>ClassRep(temp_hash-&gt;data);</span><span class=cF0>
<a name="l276"></a>
<a name="l277"></a> </span><span class=cF2>//lex next. expect ',' or '}'.</span><span class=cF0>
<a name="l278"></a> tk = </span><span class=cF5>Lex</span><span class=cF0>(cc);
<a name="l279"></a> </span><span class=cF1>if</span><span class=cF0> (tk != </span><span class=cF6>','</span><span class=cF0> &amp;&amp; tk != </span><span class=cF6>'}'</span><span class=cF0>)
<a name="l280"></a> </span><span class=cF5>LexExcept</span><span class=cF0>(cc, </span><span class=cF6>&quot;Expected ',' or '}' after Object Value.&quot;</span><span class=cF0>);
<a name="l281"></a> </span><span class=cF2>//if ',' ... Terry's parsing code would imply labels and gotos.</span><span class=cF0>
<a name="l282"></a> </span><span class=cF2>//i wonder if there's a better, less BASIC way.</span><span class=cF0>
<a name="l283"></a> </span><span class=cF1>if</span><span class=cF0> (tk == </span><span class=cF6>','</span><span class=cF0>)
<a name="l284"></a> </span><span class=cF1>goto</span><span class=cF0> lex_objkey;
<a name="l285"></a>lex_objdone:
<a name="l286"></a>
<a name="l287"></a> is_done = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l288"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l289"></a> }
<a name="l290"></a>
<a name="l291"></a> </span><span class=cF1>if</span><span class=cF0> (is_done)
<a name="l292"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l293"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l294"></a>
<a name="l295"></a> </span><span class=cF1>return</span><span class=cF0> result;
<a name="l296"></a>}
<a name="l297"></a>
<a name="l298"></a></span><span class=cF1>U0</span><span class=cF0> Test(</span><span class=cF1>U8</span><span class=cF0> *filename)
<a name="l299"></a>{
<a name="l300"></a> </span><span class=cF9>CCompCtrl</span><span class=cF0> *cc = </span><span class=cF5>CompCtrlNew</span><span class=cF0>(</span><span class=cF5>MStrPrint</span><span class=cF7>(</span><span class=cF6>&quot;#include \&quot;%s\&quot;&quot;</span><span class=cF0>, filename</span><span class=cF7>)</span><span class=cF0>);
<a name="l301"></a> CJSONDataEntry *result = JSONParse(cc);
<a name="l302"></a>
<a name="l303"></a> JSONDataRep(result);
<a name="l304"></a>}
<a name="l305"></a>
<a name="l306"></a></span><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF3>__DIR__</span><span class=cF0>);
<a name="l307"></a>Test(</span><span class=cF6>&quot;JSON1.TXT&quot;</span><span class=cF0>);</span></pre></body>
</html>