void SerializePPFiles(Stream& s) { s % sAllMacros % sPPfile % sPPserial; if(s.IsLoading()) LoadPPConfig(); #if 0 if(s.IsLoading()) { _DBG_ DDUMP(sPPfile.GetCount()); DDUMP(sAllMacros.GetCount()); DDUMP(sPPserial); Index<int> psegment; for(int i = 0; i < sPPfile.GetCount(); i++) { const PPFile& p = sPPfile[i]; for(int j = 0; j < p.item.GetCount(); j++) psegment.FindAdd(p.item[j].segment_id); } DDUMP(psegment.GetCount()); int n = 0; _DBG_ Index<int> msegment; for(int i = 0; i < sAllMacros.GetCount(); i++) { _DBG_ if(sAllMacros.IsUnlinked(i)) n++; else msegment.FindAdd(sAllMacros[i].segment_id); } DLOG("UNLINKED " << n); DLOG("Segments " << msegment.GetCount()); }
void Ide::ExportProject(const String& ep, bool all, bool gui, bool deletedir) { SaveFile(false); ::Workspace wspc; wspc.Scan(main); Index<String> used; HdependClearDependencies(); for(int i = 0; i < wspc.GetCount(); i++) { const Package& p = wspc.GetPackage(i); String pn = wspc[i]; for(int j = 0; j < p.GetCount(); j++) { const Package::File& f = p[j]; if(!f.separator) { String p = SourcePath(pn, f); used.FindAdd(p); Vector<String> d = HdependGetDependencies(p); for(int q = 0; q < d.GetCount(); q++) used.FindAdd(d[q]); for(int q = 0; q < f.depends.GetCount(); q++) used.FindAdd(SourcePath(pn, f.depends[q].text)); } } } if(FileExists(ep)) { if(gui && !PromptYesNo(DeQtf(ep) + " is existing file.&" "Do you want to delete it?")) return; FileDelete(ep); } if(deletedir && DirectoryExists(ep)) { if(gui && !PromptYesNo(DeQtf(ep) + " is existing directory.&" "Do you want to replace it?")) return; DeleteFolderDeep(ep); } Progress pi("Exporting project"); pi.SetTotal(wspc.GetCount()); for(int i = 0; i < wspc.GetCount(); i++) { if(gui && pi.StepCanceled()) return; CopyFolder(AppendFileName(ep, wspc[i]), PackageDirectory(wspc[i]), used, all, true); } Vector<String> upp = GetUppDirs(); for(int i = 0; i < upp.GetCount(); i++) { if(gui && pi.StepCanceled()) return; String d = upp[i]; FindFile ff(AppendFileName(d, "*")); while(ff) { if(ff.IsFile()) { String fn = ff.GetName(); String path = AppendFileName(d, fn); if(all || used.Find(path) >= 0) CopyFile(AppendFileName(ep, fn), path, true); } ff.Next(); } CopyFolder(AppendFileName(ep, wspc[i]), PackageDirectory(wspc[i]), used, all, true); } ExportMakefile(ep); }
PPMacro *FindPPMacro(const String& id, Index<int>& segment_id, int& segmenti) { Index<int> undef; PPMacro *r; int best; for(int pass = 0; pass < 2; pass++) { r = NULL; best = segmenti; int line = -1; int q = sAllMacros.Find(id); while(q >= 0) { PPMacro& m = sAllMacros[q]; if(m.macro.IsUndef()) { if(pass == 0 && segment_id.Find(m.segment_id) >= 0) undef.FindAdd(m.segment_id); // cancel out undefined macro... } else if(pass == 0 || m.segment_id == 0 || undef.Find(m.undef_segment_id) < 0) { int si = m.segment_id == 0 ? INT_MAX : segment_id.Find(m.segment_id); // defs macros always override if(si > best || si >= 0 && si == best && m.line > line) { best = si; line = m.line; r = &m; } } q = sAllMacros.FindNext(q); } if(undef.GetCount() == 0) break; } segmenti = best; return r; }
Vector<String> HelpTopicEnumDeclModules() { Index<String> modmap; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) modmap.FindAdd(map[i].decl_module); Vector<String> mm = modmap.PickKeys(); Sort(mm, StdLess<String>()); return mm; }
NAMESPACE_UPP void RichTxt::GetAllLanguages(Index<int>& all) const { for(int i = 0; i < part.GetCount(); i++) { if(IsTable(i)) { const RichTable& tab = part[i].Get<RichTable>(); for(int i = 0; i < tab.GetRows(); i++) for(int j = 0; j < tab.GetColumns(); j++) if(tab(i, j)) tab[i][j].text.GetAllLanguages(all); } else { RichPara p = Get(i, RichStyle::GetDefault()); all.FindAdd(p.format.language); for(int i = 0; i < p.GetCount(); i++) all.FindAdd(p[i].format.language); } } }
void RichQtfParser::FinishOldTable() { FinishCell(); Index<int> pos; Vector<int> srow; RichTable& t = Table(); Tab& b = table.Top(); for(int i = 0; i < t.GetRows(); i++) { int& s = srow.Add(); s = 0; int nx = b.rown[i]; for(int j = 0; j < nx; j++) s += t.GetSpan(i, j).cx; int xn = 0; for(int j = 0; j < nx; j++) { pos.FindAdd(xn * 10000 / s); xn += t.GetSpan(i, j).cx; } } Vector<int> h = pos.PickKeys(); if(h.GetCount() == 0) Error("table"); Sort(h); pos = pick(h); pos.Add(10000); RichTable tab; tab.SetFormat(t.GetFormat()); for(int i = 0; i < pos.GetCount() - 1; i++) { tab.AddColumn(pos[i + 1] - pos[i]); } for(int i = 0; i < t.GetRows(); i++) { int s = srow[i]; int nx = b.rown[i]; int xn = 0; int xi = 0; for(int j = 0; j < nx; j++) { Size span = t.GetSpan(i, j); xn += span.cx; int nxi = pos.Find(xn * 10000 / s); tab.SetPick(i, xi, t.GetPick(i, j)); tab.SetFormat(i, xi, t.GetFormat(i, j)); tab.SetSpan(i, xi, max(span.cy - 1, 0), nxi - xi - 1); xi = nxi; } } table.Drop(); if(table.GetCount()) table.Top().text.CatPick(pick(tab)); else target.CatPick(pick(tab)); oldtab = false; }
virtual bool operator()(int pos, const RichPara& para)// A++ bug here.... { if(!IsNull(para.format.label)) { AddLinkRef(link, para.format.label); ref.FindAdd(para.format.label); } for(int i = 0; i < para.part.GetCount(); i++) if(para.part[i].IsText()) { const wchar *s = para.part[i].text; for(;;) { while(!IsLetter(*s) && !IsDigit(*s) && *s) s++; if(*s == '\0') break; StringBuffer sb; while(IsLetter(*s) || IsDigit(*s)) sb.Cat(ToAscii(ToLower(*s++))); words.FindAdd(TopicWordIndex(sb)); } } return false; }
void Ide::DoDirDiff() { Index<String> dir; Vector<String> d = GetUppDirs(); for(int i = 0; i < d.GetCount(); i++) dir.FindAdd(d[i]); FindFile ff(ConfigFile("*.bm")); while(ff) { VectorMap<String, String> var; LoadVarFile(ff.GetPath(), var); Vector<String> p = Split(var.Get("UPP", String()), ';'); for(int i = 0; i < p.GetCount(); i++) dir.FindAdd(p[i]); ff.Next(); } String n = GetFileFolder(editfile); if(n.GetCount()) dir.FindAdd(n); SortIndex(dir); static DirDiffDlg dlg; dlg.diff.WhenLeftLine = THISBACK1(GotoDirDiffLeft, &dlg); dlg.diff.WhenRightLine = THISBACK1(GotoDirDiffRight, &dlg); for(int i = 0; i < dir.GetCount(); i++) { dlg.Dir1AddList(dir[i]); dlg.Dir2AddList(dir[i]); } if(d.GetCount()) dlg.Dir1(d[0]); if(!dlg.IsOpen()) { dlg.SetFont(veditorfont); dlg.Maximize(); dlg.Title("Compare directories"); dlg.OpenMain(); } else dlg.SetFocus(); }
Vector<int> HelpTopicEnumLang() { Index<int> lngmap; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) { const HelpTopicInfo& topic = map[i]; for(int l = 0; l < topic.language.GetCount(); l++) lngmap.FindAdd(topic.language[l]); } Vector<int> lng = lngmap.PickKeys(); Sort(lng); return lng; }
Vector<String> HelpTopicEnumSpace() { const HelpTopicInfoMap& map = HelpTopicMap(); Index<String> spaces; for(int i = 0; i < map.GetCount(); i++) { String space, nesting, topic; HelpParseDPP(map.GetKey(i), space, nesting, topic); spaces.FindAdd(space); } Vector<String> splist = spaces.PickKeys(); Sort(splist, StdLess<String>()); return splist; }
void ExtToMime::Load(const char *fn) { FileIn in(fn); if(in) while(!in.IsEof()) { String ln = TrimLeft(TrimRight(in.GetLine())); if(ln[0] != '#') { int q = ln.Find(':'); if(q >= 0) { String h = ln.Mid(0, q); int w = h.Find('/'); if(w >= 0) { int x = ln.Find("*.", q); if(x >= 0) { String ext = ln.Mid(x + 2); if(ext.GetCount() && map.Find(ext) < 0) map.Add(ext, MAKELONG(minor.FindAdd(h.Mid(w + 1)), major.FindAdd(h.Mid(0, w)))); } } } } } }
void SearchForFiles(Index<String>& files, String dir, String mask, int readonly, Progress& pi) { FindFile ff(AppendFileName(dir, "*.*")); while(ff) { if(ff.IsFolder() && *ff.GetName() != '.') SearchForFiles(files, AppendFileName(dir, ff.GetName()), mask, readonly, pi); else if(ff.IsFile() && PatternMatchMulti(mask, ff.GetName())) { if(IsNull(readonly) || !!readonly == !!ff.IsReadOnly()) { if(pi.StepCanceled()) return; files.FindAdd(AppendFileName(dir, ff.GetName())); } } ff.Next(); } }
Index<int> GetLngSet() { CriticalSection::Lock __(slng); Index<int> ndx; Array<LngModule>& ma = sMod(); for(int i = 0; i < ma.GetCount(); i++) { LngModule& m = ma[i]; for(int j = 0; j < m.map.GetCount(); j++) { Vector<LngRec>& lr = m.map[j]; for(int k = 0; k < lr.GetCount(); k++) ndx.FindAdd(lr[k].lang); } } return ndx; }
Vector<String> HelpTopicEnumNesting(String sp) { const HelpTopicInfoMap& map = HelpTopicMap(); Index<String> nest; for(int i = 0; i < map.GetCount(); i++) { String space, nesting, topic; HelpParseDPP(map.GetKey(i), space, nesting, topic); if(IsNull(sp) || sp == space) nest.FindAdd(nesting); } Vector<String> nelist = nest.PickKeys(); Sort(nelist, StdLess<String>()); return nelist; }
Vector<String> Workspace::GetAllAccepts(int pk) const { Index<String> accepts; Index<int> pkg; pkg.Add(pk); for(int i = 0; i < pkg.GetCount(); i++) { const Package& p = package[pkg[i]]; FindAppend(accepts, p.accepts); for(int u = 0; u < p.uses.GetCount(); u++) { int f = package.Find(UnixPath(p.uses[u].text)); if(f >= 0) pkg.FindAdd(f); } } return accepts.PickKeys(); }
virtual bool operator()(int pos, const RichPara& para) { for(int i = 0; i < para.GetCount(); i++) { String l = para[i].format.link; if(!IsNull(l)) { if(l[0] == ':') { int q = reflink->Find(l); int w = q; if(q < 0) q = reflink->Find(l + "::class"); if(q < 0) q = reflink->Find(l + "::struct"); if(q < 0) q = reflink->Find(l + "::union"); if(q >= 0) l = (*reflink)[q]; } link.FindAdd(Nvl(reflink->Get(l, Null), l)); } } return false; }
STDMETHODIMP UDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect) { GuiLock __; LLOG("DragEnter " << pt); data = pDataObj; data->AddRef(); fmt.Clear(); IEnumFORMATETC *fe; if(!ctrl || pDataObj->EnumFormatEtc(DATADIR_GET, &fe) != NOERROR) { *pdwEffect = DROPEFFECT_NONE; return NOERROR; } FORMATETC fmtetc; while(fe->Next(1, &fmtetc, 0) == S_OK) { fmt.FindAdd(FromWin32CF(fmtetc.cfFormat)); if(fmtetc.ptd) CoTaskMemFree(fmtetc.ptd); } fe->Release(); DnD(pt, false, pdwEffect, grfKeyState); return NOERROR; }
void IndexTutorial() { /// .`Index` /// `Index` is the the foundation of all U++ associative operations and is one of defining /// features of U++. /// `Index` is a container very similar to the plain `Vector` (it is random access array of /// elements with fast addition at the end) with one additional feature - it is able to fast /// retrieve position of element with required value using `Find` method: Index<String> ndx; ndx.Add("alfa"); ndx.Add("beta"); ndx.Add("gamma"); ndx.Add("delta"); ndx.Add("kappa"); DUMP(ndx); DUMP(ndx.Find("beta")); /// If element is not present in `Index`, `Find` returns a negative value: DUMP(ndx.Find("something")); /// Any element can be replaced using `Set` method: ndx.Set(1, "alfa"); DUMP(ndx); /// If there are more elements with the same value, they can be iterated using `FindNext` /// method: int fi = ndx.Find("alfa"); while(fi >= 0) { DUMP(fi); fi = ndx.FindNext(fi); } /// `FindAdd` method retrieves position of element like `Find`, but if element is not /// present in `Index`, it is added: DUMP(ndx.FindAdd("one")); DUMP(ndx.FindAdd("two")); DUMP(ndx.FindAdd("three")); DUMP(ndx.FindAdd("two")); DUMP(ndx.FindAdd("three")); DUMP(ndx.FindAdd("one")); /// Removing elements from random access sequence tends to be expensive, that is why rather /// than remove, `Index` supports `Unlink` and `UnlinkKey` operations, which retain the /// element in `Index` but make it invisible for `Find` operation: ndx.Unlink(2); ndx.UnlinkKey("kappa"); DUMP(ndx.Find(ndx[2])); DUMP(ndx.Find("kappa")); /// You can test whether element at given position is unlinked using `IsUnlinked` method DUMP(ndx.IsUnlinked(1)); DUMP(ndx.IsUnlinked(2)); /// Unlinked positions can be reused by `Put` method: ndx.Put("foo"); DUMP(ndx); DUMP(ndx.Find("foo")); /// You can also remove all unlinked elements from `Index` using `Sweep` method: ndx.Sweep(); DUMP(ndx); /// Operations directly removing or inserting elements of Index are expensive, but /// available too: ndx.Remove(1); DUMP(ndx); /// ndx.RemoveKey("two"); DUMP(ndx); /// ndx.Insert(0, "insert"); DUMP(ndx); /// PickKeys operation allows you to obtain Vector of elements of Index in low /// constant time operation (while destroying source Index) Vector<String> d = ndx.PickKeys(); DUMP(d); /// Pick-assigning `Vector` to `Index` is supported as well: d[0] = "test"; ndx = pick(d); DUMP(ndx); /// }
void Draw::SetDevice(const char *s) { DrawLock __; static Index<String> map; device = map.FindAdd(s) + 1; LoadCaps(); }
Vector<String> CppBuilder::CustomStep(const String& pf, const String& package_, bool& error) { String package = Nvl(package_, mainpackage); String path = (*pf == '.' && pf[1] != '.') ? target : SourcePath(package, pf); String file = GetHostPath(path); String ext = ToLower(GetFileExt(pf)); if(ext == ".ext") { Vector<String> files; Vector<String> dirs; sGatherAllExt(files, dirs, GetFileFolder(path), ""); Index<String> pkg_files; Package pkg; pkg.Load(PackagePath(package)); for(int i = 0; i < pkg.GetCount(); i++) pkg_files.Add(pkg[i]); Index<String> out; Index<String> include_path; String f = LoadFile(path); try { CParser p(f); while(!p.IsEof()) { if(p.Id("files")) { Vector<String> e = ReadPatterns(p); for(int i = 0; i < files.GetCount(); i++) for(int j = 0; j < e.GetCount(); j++) { String f = files[i]; if(PatternMatch(e[j], f) && pkg_files.Find(f) < 0) out.FindAdd(f); } } if(p.Id("exclude")) { ExtExclude(p, out); } if(p.Id("include_path")) { Vector<String> e = ReadPatterns(p); for(int j = 0; j < e.GetCount(); j++) { String ee = e[j]; if(ee.Find('*') >= 0) for(int i = 0; i < dirs.GetCount(); i++) { String d = dirs[i]; if(PatternMatch(e[j], d)) { include_path.FindAdd(d); } } else include_path.Add(ee); } } if(p.Id("exclude_path")) { ExtExclude(p, include_path); } if(p.Id("includes")) { Vector<String> e = ReadPatterns(p); for(int i = 0; i < files.GetCount(); i++) for(int j = 0; j < e.GetCount(); j++) { String f = files[i]; if(PatternMatch(e[j], f) && pkg_files.Find(f) < 0) include_path.FindAdd(GetFileFolder(f)); } } } } catch(CParser::Error) { PutConsole("Invalid .ext file"); error = true; return Vector<String>(); } for(int i = 0; i < include_path.GetCount(); i++) include.Add(NormalizePath(include_path[i], GetFileFolder(path))); Vector<String> o; for(int i = 0; i < out.GetCount(); i++) o.Add(SourcePath(package, out[i])); return o; } for(int i = 0; i < wspc.GetCount(); i++) { const Array< ::CustomStep >& mv = wspc.GetPackage(i).custom; for(int j = 0; j < mv.GetCount(); j++) { const ::CustomStep& m = mv[j]; if(MatchWhen(m.when, config.GetKeys()) && m.MatchExt(ext)) { VectorMap<String, String> mac; AddPath(mac, "PATH", file); AddPath(mac, "RELPATH", pf); AddPath(mac, "DIR", GetFileFolder(PackagePath(package))); AddPath(mac, "FILEDIR", GetFileFolder(file)); AddPath(mac, "PACKAGE", package); mac.Add("FILE", GetFileName(file)); mac.Add("TITLE", GetFileTitle(file)); AddPath(mac, "EXEPATH", GetHostPath(target)); AddPath(mac, "EXEDIR", GetHostPath(GetFileFolder(target))); mac.Add("EXEFILE", GetFileName(target)); mac.Add("EXETITLE", GetFileTitle(target)); AddPath(mac, "OUTDIR", GetHostPath(outdir)); //BW AddPath(mac, "OUTDIR", GetHostPath(GetFileFolder(target))); AddPath(mac, "OUTFILE", GetHostPath(GetFileName(target))); AddPath(mac, "OUTTITLE", GetHostPath(GetFileTitle(target))); mac.Add("INCLUDE", Join(include, ";")); Vector<String> out = Cuprep(m.output, mac, include); bool dirty = out.IsEmpty(); for(int i = 0; !dirty && i < out.GetCount(); i++) dirty = (GetFileTime(file) > GetFileTime(out[i])); if(dirty) { HdependTimeDirty(); PutConsole(GetFileName(file)); Vector<String> cmd = Cuprep(m.command, mac, include); String cmdtext; for(int c = 0; c < cmd.GetCount(); c++) { PutVerbose(cmd[c]); if(!Cd(cmd[c]) && !Cp(cmd[c], package, error)) { String ctext = cmd[c]; const char *cm = ctext; if(*cm == '?') cm++; if(*ctext != '?' && Execute(cm)) { for(int t = 0; t < out.GetCount(); t++) DeleteFile(out[t]); PutConsole("FAILED: " + ctext); error = true; return Vector<String>(); } } } } return out; } } } Vector<String> out; out.Add(path); return out; }
Index<String> MakeBuild::PackageConfig(const Workspace& wspc, int package, const VectorMap<String, String>& bm, String mainparam, Host& host, Builder& b, String *target) { String packagepath = PackagePath(wspc[package]); const Package& pkg = wspc.package[package]; Index<String> cfg; mainparam << ' ' << bm.Get(targetmode ? "RELEASE_FLAGS" : "DEBUG_FLAGS", NULL); cfg = SplitFlags(mainparam, package == 0, wspc.GetAllAccepts(package)); cfg.FindAdd(bm.Get("BUILDER", "GCC")); const TargetMode& m = GetTargetMode(); if(targetmode == 0) cfg.FindAdd("DEBUG"); switch(m.linkmode) { case 2: cfg.FindAdd("SO"); case 1: cfg.FindAdd("SHARED"); } if(targetmode == 2) cfg.FindAdd("FORCE_SPEED"); if(targetmode == 3) cfg.FindAdd("FORCE_SIZE"); int q = m.package.Find(wspc[package]); if(q >= 0) { const PackageMode& p = m.package[q]; switch(p.debug >= 0 ? p.debug : m.def.debug) { case 1: cfg.FindAdd("DEBUG_MINIMAL"); break; case 2: cfg.FindAdd("DEBUG_FULL"); break; } if(!pkg.noblitz && (p.blitz >= 0 ? p.blitz : m.def.blitz)) cfg.FindAdd("BLITZ"); } else { switch(m.def.debug) { case 1: cfg.FindAdd("DEBUG_MINIMAL"); break; case 2: cfg.FindAdd("DEBUG_FULL"); break; } if(!pkg.noblitz && m.def.blitz) cfg.FindAdd("BLITZ"); } host.AddFlags(cfg); b.AddFlags(cfg); for(int i = 0; i < pkg.flag.GetCount(); i++) { if(MatchWhen(pkg.flag[i].when, cfg.GetKeys())) cfg.Add(pkg.flag[i].text); } if(target) *target = Gather(pkg.target, cfg.GetKeys(), true); return cfg; }