Example #1
0
bool LoadVarFile(const char *name, VectorMap<String, String>& _var)
{
	try {
		VectorMap<String, String> var;
		String env = LoadFile(name);
		CParser p(env);
		while(!p.IsEof()) {
			String v = p.ReadId();
			p.Char('=');
			if(p.IsString())
				var.GetAdd(v) = p.ReadString();
			else {
				String ln;
				while(p.PeekChar() != '\r' && p.PeekChar() != '\n' && p.PeekChar() != ';')
					ln.Cat(p.GetChar());
				var.GetAdd(v) = ln;
				p.Spaces();
			}
			p.Char(';');
		}
		_var = pick(var);
		return true;
	}
	catch(...) {
		return false;
	}
}
Example #2
0
ValueMap Result::LoadPage(const CommitFilter& f) {
	SQLR * Select(SqlAll(RESULT),UID,CMT,BRANCH,CLIENT_ID)
	       .From(
	           Select(UID.As("FILTER"))
	           .From(COMMITS)
	           .Where(f)
	           .OrderBy(Descending(DT))
	           .Limit(f.offset, f.limit)
	           .AsTable("FILTER_TABLE")
	       )
	       .InnerJoin(COMMITS).On(SqlId("FILTER")==UID)
	       .LeftJoin(RESULT).On(CMT_UID == UID)
	       .LeftJoin(CLIENT).On(ID == CLIENT_ID)
	       .OrderBy(Descending(DT));
	VectorMap<Tuple2<String, int>,ValueMap> rows;
	SortedIndex<int> clients;
	VectorMap<String, ValueMap> commits;
	ValueArray v_clients;
	ValueMap v_commits;
	ValueMap vm;
	while (SQLR.Fetch(vm)){
		SetComputedAttributes(vm);
		String uid = vm["UID"];
		int cid = vm["CLIENT_ID"];
		rows.Add(MakeTuple(uid, cid), vm);
		clients.FindAdd(cid);
		ValueMap& commit = commits.GetAdd(uid);
		commit.Set("CMT", vm["CMT"]);
		commit.Set("BRANCH", vm["BRANCH"]);
	}
	ValueMap results;
	for(int i = 0; i<commits.GetCount() ; ++i){
		v_commits.Add(commits.GetKey(i), commits[i]);
		vm.Clear();
		for(int j = 0; j < clients.GetCount(); ++j){
			if(!IsNull(clients[j]))
				vm.Add(clients[j], rows.GetAdd(MakeTuple(commits.GetKey(i), clients[j])));
		}
		results.Add(commits.GetKey(i), vm);
	}
	for(int i = (!clients.IsEmpty() && IsNull(clients[0]))?1:0; i < clients.GetCount(); i++)
		v_clients.Add(clients[i]);
	ValueMap res;
	res.Set("RESULTS", results);
	res.Set("COMMITS", v_commits);
	res.Set("CLIENTS", v_clients);
	res.Set("ALLCLIENTS", Client::LoadAll());
	return res;
}
Example #3
0
void HelpWin::SyncDocTree() {
	ClearTree();
	VectorMap<String, Vector<String> > map;
	String pdir = GetFileFolder(GetExeFilePath()) + "/";
	for(FindFile ff(AppendFileName(pdir, "*.tpp")); ff; ff.Next())
		if(ff.IsFolder()) {
			String group = GetFileTitle(ff.GetName());
			String dir = AppendFileName(pdir, ff.GetName());
			for(FindFile ft(AppendFileName(dir, "*.tpp")); ft; ft.Next()) {
				if(ft.IsFile()) {
					if(String(ft.GetName()).Mid(0, 1) != "_") map.GetAdd(group).Add(GetFileTitle(ft.GetName()));
				}
			}
		}
	for(int i = 0; i < map.GetCount(); i++) {
		Vector<String>& group = map[i];
		int pid;
		pid = AddTree(0, commonImg::group_1_16(), "topic://" + GetExeTitle() + "/" + map.GetKey(i), map.GetKey(i));
		for(int j = 0; j < group.GetCount(); j++) {
			String t = "topic://" + GetExeTitle() + "/" + map.GetKey(i) + "/" + group[j];
			String u = GetTopicTitle(GetFileFolder(GetExeFilePath()) + "/" + map.GetKey(i) + ".tpp/" + group[j] + ".tpp");
			AddTree(pid, commonImg::commonImg::commonImg::topic_1_16(), t, u);
		}
	}
	FinishTree();
}
Example #4
0
void BenchNTL2(const char *file, Stream& out) {
	FileIn in(file);
	if (!in) {
		out << "Cannot open input file.\n";
		return;
	}

	VectorMap<String, int> map;
	
	for(;;) {
		int c = in.Get();
		if(c < 0) break;
		if(IsAlpha(c) || c == '_') {
			String id;
			id.Cat(c);
			c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '_')) {
				id.Cat(c);
				c = in.Get();
			}
			map.GetAdd(id, 0)++;
		}
		else
		if(IsDigit(c))
			do c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '.'));
	}

	Vector<int> order = GetSortOrder(map.GetKeys());
	for(int i = 0; i < order.GetCount(); i++)
		out << ~map.GetKey(order[i]) << ": " << map[order[i]] << '\n';
}
Example #5
0
void Themed::LoadTheme(const char *dir)
{
	theme.Clear();
	FindFile ff(AppendFileName(dir, "*.class"));
	while(ff) {
		String cls = ToLower(GetFileTitle(ff.GetName()));
		theme.GetAdd(cls).Load(dir, cls);
		ff.Next();
	}
}
Example #6
0
void sOptimizedTextRenderer::DrawChar(int x, int _y, int chr, int width, Font font, Color color)
{
	LTIMING("DrawChar");
	if(y != _y) {
		Flush();
		y = _y;
	}
	Chrs *c;
	{
		LTIMING("Map");
		c = &cache.GetAdd(MakeTuple(font, color));
	}
	if(c->x.GetCount() && c->x.Top() > x) {
		Flush();
		c = &cache.GetAdd(MakeTuple(font, color));
	}
	c->text.Cat(chr);
	c->x.Add(x);
}
Example #7
0
void MakeMap(VectorMap<String, int>& map, const XmlNode& n, const String& path, int& tag_count, int& other_count)
{
	if(map.GetCount() > 1000)
		return;
	for(int i = 0; i < n.GetCount(); i++) {
		const Tuple2<int, String> *m = FindTuple(mm, __countof(mm), n[i].GetType());
		if(m) {
			count.GetAdd(m->b, 0)++;
			count.GetAdd(String(m->b) + ".len", 0) += n[i].GetText().GetCount();
		}
		if(n[i].IsTag()) {
			String np = path + "/" + n[i].GetTag();
			map.GetAdd(np, 0)++;
			MakeMap(map, n[i], np, tag_count, other_count);
			count.GetAdd("attr", 0) += n[i].GetAttrCount();
		}
		else
			map.GetAdd(path + ':' + (m ? m->b : "?"), 0)++;
	}
}
Example #8
0
void LoadProp(FileIn& in, VectorMap<String, String>& prop)
{
	while(!in.IsEof()) {
		String ln = in.GetLine();
		CParser p(ln);
		if(p.Char(';'))
			break;
		if(p.IsId()) {
			String& d = prop.GetAdd(p.ReadId());
			p.SkipSpaces();
			d = p.GetPtr();
		}
	}
}
Example #9
0
void AppendFiles(VectorMap<String, ClipData>& clip, const Vector<String>& files)
{
	WString wfiles;
	for(int i = 0; i < files.GetCount(); i++)
		wfiles << files[i].ToWString() << "\0";
	sDROPFILES h;
	h.unicode = true;
	h.offset = sizeof(h);
    GetCursorPos(&h.pt);
    h.nc = TRUE;
    String data;
	data.Cat((byte *)&h, sizeof(h));
	data.Cat((byte *)~wfiles, 2 * (wfiles.GetCount() + 1));
	clip.GetAdd("files") = ClipData(data);
}
Example #10
0
void BenchNTL(const char *file) {
	FileIn in(file);
	if (!in) {
		std::cout << "Cannot open input file.\n";
		return;
	}

	VectorMap<String, Vector<int> > map;
	int line = 1;

	for(;;) {
		int c = in.Get();
		if(c < 0) break;
		if(IsAlpha(c) || c == '_') {
			String id;
			id.Cat(c);
			c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '_')) {
				id.Cat(c);
				c = in.Get();
			}
			map.GetAdd(id).Add(line);
		}
		else
		if(IsDigit(c))
			do c = in.Get();
			while(c >= 0 && (IsAlNum(c) || c == '.'));
		if(c == '\n')
			++line;
	}

	Vector<int> order = GetSortOrder(map.GetKeys());
#ifndef NO_OUTPUT
	for(int i = 0; i < order.GetCount(); i++) {
		std::cout << ~map.GetKey(order[i]) << ": ";
		const Vector<int>& l = map[order[i]];
		for(int i = 0; i < l.GetCount(); i++) {
			if(i) std::cout << ", ";
			std::cout << l[i];
		}
		std::cout << '\n';
	}
#endif
}
Example #11
0
int main(int argc, const char *argv[])
{
	int n;
	VectorMap<String, int> map;
	Cout() << "   lines   words   bytes file\n";
	int total_lines = 0;
	int total_words = 0;
	int total_bytes = 0;
	for(int i = 1; i < argc; i++) {
		String f = LoadFile(argv[i]);
		int lines = 0;
		int words = 0;
		const char *q = f;
		for(;;) {
			int c = *q;
			if(IsAlpha(c)) {
				const char *b = q++;
				while(IsAlNum(*q)) q++;
				map.GetAdd(String(b, q), 0)++;
				words++;
			}
			else {
				if(!c) break;
				if(c == '\n')
					++lines;
				q++;
			}
		}
		Cout() << Format("%8d%8d%8d %s\n", lines, words, f.GetCount(), argv[i]);
		total_lines += lines;
		total_words += words;
		total_bytes += f.GetCount();
	}
	Vector<int> order = GetSortOrder(map.GetKeys());
#ifndef NOOUTPUT
	Cout() << Format("--------------------------------------%8d%8d%8d total\n", total_lines, total_words, total_bytes);

	for(int i = 0; i < order.GetCount(); i++)
		Cout() << map.GetKey(order[i]) << ": " << map[order[i]] << '\n';
#endif
	return 0;
}
Example #12
0
void IdeIconDes::Save()
{
	if(format == 1) {
		for(int i = 0; i < GetCount(); i++) {
			Image m = GetImage(i);
			Point p = m.Get2ndSpot();
			if(m.GetKind() == IMAGE_ALPHA || p.x || p.y) {
				if(PromptYesNo("Legacy file format does not support images "
				               "with full alpha channel or 2nd hotspot - "
				               "the information would be lost.&"
				               "Do you wish to convert the file to the new format?")) {
					format = 0;
				}
				break;
			}
		}
	}
	StoreToGlobal(*this, "icondes-ctrl");
	Array<ImlImage> m;
	VectorMap<Size, Image> exp;
	String folder = GetFileFolder(filename);
	for(int i = 0; i < GetCount(); i++) {
		ImlImage& c = m.Add();
		c.name = GetName(i);
		c.image = GetImage(i);
		c.exp = GetExport(i);
		if(c.exp) {
			Size sz = c.image.GetSize();
			exp.GetAdd(sz) = c.image;
			PNGEncoder png;
			SaveChangedFile(AppendFileName(folder, String().Cat() << "icon" << sz.cx << 'x' << sz.cy << ".png"),
			                png.SaveString(c.image));
		}
	}
	String d = SaveIml(m, format);
	if(!SaveChangedFileFinish(filename, d))
		return;
	filetime = FileGetTime(filename);
	if(exp.GetCount())
		SaveChangedFile(AppendFileName(folder, "icon.ico"), WriteIcon(exp.GetValues()));
}
Example #13
0
void Puzzle::LeftDown(Point p, dword)
{
    if(Move(p.x / 32, p.y / 32)) {
        moves++;
        Status();
        int n = size.cx * size.cy - 1;
        for(int i = 0; i < n; i++)
            if(box[i] != i + 1)
                return;
        String dim;
        int& sm = score.GetAdd(String().Cat() << size.cx << "x" << size.cy);
        if(moves < sm) {
            sm = moves;
            PromptOK(t_("You win with the new best score!"));
        }
        else
            PromptOK(t_("You win!"));
        Generate();
    }
    else
        BeepExclamation();
}
Example #14
0
void GatherMethods(const String& type, VectorMap<String, bool>& inherited, bool g, Index<String>& done)
{
	if(done.Find(type) >= 0) return;
	done.Add(type);
	int q = CodeBase().Find(type);
	if(q < 0) return;
	const Array<CppItem>& n = CodeBase()[q];
	Index<String> set;
	for(int i = 0; i < n.GetCount(); i++) {
		const CppItem& m = n[i];
		if(set.Find(m.qitem) < 0) {
			set.Add(m.qitem);
			if(m.IsType()) {
				Vector<String> base = Split(m.qptype, ';');
				for(int i = 0; i < base.GetCount(); i++)
					GatherMethods(base[i], inherited, true, done);
			}
			if(m.IsCode() && g) {
				bool& virt = inherited.GetAdd(m.qitem);
				virt = virt || m.virt;
			}
		}
	}
}
Example #15
0
void MakeTutorial()
{
	String log = LoadFile(GetStdLogPath());
	StringStream ss(log);

	VectorMap<String, Vector<Tuple<int, String>>> logline;
	
	String path;
	int    line;

	while(!ss.IsEof()) {
		String ln = ss.GetLine();
		if(ln.StartsWith("-=>")) {
			SplitTo(ln.Mid(4), '@', path, ln);
			line = atoi(ln) - 1;
		}
		else
		if(path.GetCount())
			logline.GetAdd(path).Add(MakeTuple(line, ln));
	}
	
	for(auto&& f : ~logline) {
		Vector<String> src = Split(Filter(LoadFile(f.key), [] (int c) { return c == '\r' ? 0 : c; }), '\n', false);
		int i = 0;
		int logi = 0;
		bool wasdoc = false;
		Vector<String> code;
		while(i < src.GetCount()) {
			String block;
			while(i < src.GetCount() && TrimLeft(src[i]).StartsWith("///")) {
				FlushCode(code);
				Vector<String> logblock;
				while(logi < f.value.GetCount() && f.value[logi].a <= i)
					logblock.Add(f.value[logi++].b);
				FlushLog(logblock);
				
				String line = src[i++];
				int q = line.FindAfter("///");
				if(TrimRight(line).GetCount() > q) {
					if(block.GetCount())
						block << ' ';
					block << TrimBoth(line.Mid(q));
				}
				else
					FlushDoc(block);
				wasdoc = true;
			}
			FlushDoc(block);
			while(i < src.GetCount() && !TrimLeft(src[i]).StartsWith("///")) {
				String tl = TrimLeft(src[i]);
				if(!tl.StartsWith("#if") && !tl.StartsWith("#end"))
					code.Add(src[i]);
				i++;
			}
			DUMPC(code);
			if(!wasdoc)
				code.Clear();
		}
	}
	
	LOG("--------------------------------------------");
	LOG(out);
	
	LOG("--------------------------------------------");
	LOG(qtf);
	
	RichEditWithToolBar edit;
	edit.SetReadOnly();
	edit <<= qtf;
	TopWindow win;
	win.Add(edit.SizePos());
	win.Run();
}
Example #16
0
void ClassTheme::Load(const char *dir, const char *cls)
{
	String imgdir = AppendFileName(dir, String(cls) + ".image");
	FindFile ff(AppendFileName(imgdir, "*.png"));
	while(ff) {
		Vector<String> v = Split(ff.GetName(), '.');
		if(v.GetCount() == 6) {
			Image m = StreamRaster::LoadFileAny(AppendFileName(imgdir, ff.GetName()));
			ImageBuffer b(m);
			b.SetHotSpot(Point(atoi(v[1]), atoi(v[2])));
			b.Set2ndSpot(Point(atoi(v[3]), atoi(v[4])));
			m = b;
			int q = v[0].Find('-');
			if(q >= 0)
				child.GetAdd(v[0].Mid(0, q)).image.GetAdd(v[0].Mid(q + 1)) = m;
			else
				data.image.GetAdd(v[0]) = m;
		}
		ff.Next();
	}
	FileIn in(AppendFileName(dir, String(cls) + ".class"));
	if(!in) return;
	LoadProp(in, data.property);
	while(!in.IsEof()) {
		String ln = in.GetLine();
		CParser p(ln);
		if(p.IsId()) {
			String id = p.ReadId();
			ChildThemeData& m = child.GetAdd(id);
			while(!p.IsEof()) {
				if(p.Id("left")) {
					Point pt = ReadNums(p);
					m.pos.x = Ctrl::PosLeft(pt.x, pt.y);
				}
				else
				if(p.Id("right")) {
					Point pt = ReadNums(p);
					m.pos.x = Ctrl::PosRight(pt.x, pt.y);
				}
				else
				if(p.Id("hsize")) {
					Point pt = ReadNums(p);
					m.pos.x = Ctrl::PosSize(pt.x, pt.y);
				}
				else
				if(p.Id("hcenter")) {
					Point pt = ReadNums(p);
					m.pos.x = Ctrl::PosCenter(pt.x, pt.y);
				}
				else
				if(p.Id("top")) {
					Point pt = ReadNums(p);
					m.pos.y = Ctrl::PosLeft(pt.x, pt.y);
				}
				else
				if(p.Id("bottom")) {
					Point pt = ReadNums(p);
					m.pos.y = Ctrl::PosRight(pt.x, pt.y);
				}
				else
				if(p.Id("vsize")) {
					Point pt = ReadNums(p);
					m.pos.y = Ctrl::PosSize(pt.x, pt.y);
				}
				else
				if(p.Id("vcenter")) {
					Point pt = ReadNums(p);
					m.pos.y = Ctrl::PosCenter(pt.x, pt.y);
				}
			}
			LoadProp(in, m.property);
		}
	}
}
Example #17
0
void Append(VectorMap<String, ClipData>& data, const WString& text)
{
	data.GetAdd("text", ClipData(text, sText));
	data.GetAdd("wtext", ClipData(text, sWText));
}
Example #18
0
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;
	}
}