String ReadPropertyParam(CParser& p) { const char *b = p.GetPtr(); int level = 0; while(!p.IsEof()) { if(p.IsChar(';')) break; if(p.IsChar(')') && level == 0) break; if(p.Char(')')) { if(level == 0) break; level--; } else if(p.Char('(')) level++; else p.SkipTerm(); } return TrimLeft(TrimRight(String(b, p.GetPtr()))); }
NAMESPACE_UPP Value ParseJSON(CParser& p) { p.UnicodeEscape(); if(p.IsNumber()) return p.ReadDouble(); if(p.IsString()) return p.ReadString(); if(p.Id("null")) return Null; if(p.Id("true")) return true; if(p.Id("false")) return false; if(p.Char('{')) { ValueMap m; if(!p.IsChar('}')) do { String key = p.ReadString(); p.PassChar(':'); m.Add(key, ParseJSON(p)); } while(p.Char(',')); p.PassChar('}'); return m; } if(p.Char('[')) { ValueArray va; if(!p.IsChar(']')) do va.Add(ParseJSON(p)); while(p.Char(',')); p.PassChar(']'); return va; } p.ThrowError("Unrecognized JSON element"); return Null; }
static void ReadMacro(CParser& p) { IdeMacro macro; if(p.IsString()) { macro.menu = p.ReadString(); if(p.Char(':')) macro.submenu = p.ReadString(); } if(!p.IsChar('{')) macro.hotkey = ParseKeyDesc(p); EscLambda& l = macro.code.CreateLambda(); const char *t = p.GetPtr(); l.filename = p.GetFileName(); l.line = p.GetLine(); if(!p.Char('{')) p.ThrowError("missing '{'"); SkipBlock(p); l.code = String(t, p.GetPtr()); Array<IdeMacro>& mlist = UscMacros(); if(macro.hotkey) { int f = FindFieldIndex(mlist, &IdeMacro::hotkey, macro.hotkey); if(f >= 0) { PutConsole(NFormat("%s(%d): duplicate macro hotkey %s\n", l.filename, l.line, GetKeyDesc(macro.hotkey))); const EscLambda& lambda = UscMacros()[f].code.GetLambda(); PutConsole(NFormat("%s(%d): previously defined here\n", lambda.filename, lambda.line)); } } if(!IsNull(macro.menu)) { for(int i = 0; i < mlist.GetCount(); i++) if(mlist[i].menu == macro.menu && mlist[i].submenu == macro.submenu) { PutConsole(NFormat("%s(%d): duplicate macro menu item (%s:%s)\n", l.filename, l.line, macro.menu, macro.submenu)); const EscLambda& lambda = UscMacros()[i].code.GetLambda(); PutConsole(NFormat("%s(%d): previously defined here\n", lambda.filename, lambda.line)); break; } } mlist.Add(macro); }
void ScanIML(CParser& parser, Array<ImlImage>& out_images, VectorMap<String, String>& out_settings) { String name, bid; bool exp = false; while(!parser.IsEof()) { if((bid = parser.ReadId()) == "IMAGE_META") { parser.Char('('); if(parser.IsString()) name = parser.ReadString(); else name = parser.ReadId(); parser.PassChar(','); String value = parser.ReadString(); parser.PassChar(')'); out_settings.Add(name, value); if(value == "exp") exp = true; } else if(bid == "IMAGE_BEGIN" && parser.Char('(') && !IsNull(name = parser.ReadId()) && parser.Char(')')) { String encoded_data; out_settings.GetAdd("wince_16bit", "0"); String id; bool first = true; while((id = parser.ReadId()) == "IMAGE_SCAN" && parser.Char('(')) { bool first_in_row = true; while(parser.IsChar('\"')) { String scan = parser.ReadOneString(); if(!first && first_in_row) encoded_data.Cat('\x80'); first_in_row = first = false; encoded_data.Cat(scan); } if(!parser.Char(')')) break; } AlphaImageInfo image; bool accepted = false; if(parser.Char('(') && parser.ReadId() == name && parser.Char(',')) if(id == "IMAGE_END" && (image.size.cx = parser.ReadInt()) > 0 && parser.Char(',') && (image.size.cy = parser.ReadInt()) > 0 && parser.Char(')')) { accepted = true; } else if(id == "IMAGE_PACKED" && parser.IsChar('\"')) { String d = parser.ReadOneString(); if(parser.Char(')')) { StringStream ss(d); ss % image; if(!ss.IsError()) accepted = true; } } if(name.GetLength() >= 6 && !memcmp(name, "_java_", 6)) accepted = false; if(accepted) { if(name.GetLength() >= 4 && !memcmp(name, "im__", 4)) name = Null; Image m = RLEToAlpha(encoded_data, image.size); ImageBuffer ib(m); ib.SetHotSpot(image.hotspot); m = ib; ImlImage& c = out_images.Add(); c.name = name; c.image = m; c.exp = exp; exp = false; } } else if(bid == "IMAGE_BEGIN16" && parser.Char('(') && !IsNull(name = parser.ReadId()) && parser.Char(')')) { //TODO: FIX THESE!!! out_settings.GetAdd("wince_16bit", "1"); String encoded_data; String id; bool first = true; while((id = parser.ReadId()) == "IMAGE_SCAN16" && parser.Char('(') && parser.Char('L')) { bool first_in_row = true; while(parser.Char('\"')) { CParser::Pos pos = parser.GetPos(); const char *end; end = pos.ptr; // TODO - remove String scan; // TODO = GetUnicodeScan(pos.ptr, &end); pos.ptr = end; parser.SetPos(pos); if(!parser.Char('\"')) break; if(!first && first_in_row) encoded_data.Cat('\x80'); first_in_row = first = false; encoded_data.Cat(scan); } if(!parser.Char(')')) break; } AlphaImageInfo idata; bool accepted = false; if(id == "IMAGE_END16" && parser.Char('(') && parser.ReadId() == name && parser.Char(',') && (idata.size.cx = parser.ReadInt()) > 0 && parser.Char(',') && (idata.size.cy = parser.ReadInt()) > 0 && parser.Char(',') && !IsNull(idata.hotspot.x = parser.ReadInt()) && parser.Char(',') && !IsNull(idata.hotspot.y = parser.ReadInt()) && parser.Char(')')) { accepted = true; } if(accepted) { if(name.GetLength() >= 4 && !memcmp(name, "im__", 4)) name = Null; Image m = RLEToAlpha(encoded_data, idata.size); ImageBuffer ib(m); ib.SetHotSpot(idata.hotspot); m = ib; ImlImage& c = out_images.Add(); c.name = name; c.image = m; c.exp = exp; exp = false; } } else break; } }