void IndexClient() { /// .Index and client types /// In order to store elements to `Index`, they type must be `Moveable`, have deep copy and /// defined the `operator==` and a `GetHashValue` function or method to compute the hash /// code. It is recommended to use `CombineHash` to combine hash values of types that /// already provide `GetHashValue`: struct Person : Moveable<Person> { String name; String surname; unsigned GetHashValue() const { return CombineHash(name, surname); } bool operator==(const Person& b) const { return name == b.name && surname == b.surname; } Person(String name, String surname) : name(name), surname(surname) {} Person() {} }; Index<Person> p; p.Add(Person("John", "Smith")); p.Add(Person("Paul", "Carpenter")); p.Add(Person("Carl", "Engles")); DUMP(p.Find(Person("Paul", "Carpenter"))); /// }
String MakeBuild::OutDir(const Index<String>& cfg, const String& package, const VectorMap<String, String>& bm, bool use_target) { Index<String> excl; excl.Add(bm.Get("BUILDER", "GCC")); excl.Add("MSC"); LocalHost().AddFlags(excl); Vector<String> x; bool dbg = cfg.Find("DEBUG_FULL") >= 0 || cfg.Find("DEBUG_MINIMAL") >= 0; if(cfg.Find("DEBUG") >= 0) { excl.Add("BLITZ"); if(cfg.Find("BLITZ") < 0) x.Add("NOBLITZ"); } else if(dbg) x.Add("RELEASE"); if(use_target) excl.Add("MAIN"); for(int i = 0; i < cfg.GetCount(); i++) if(excl.Find(cfg[i]) < 0) x.Add(cfg[i]); Sort(x); for(int i = 0; i < x.GetCount(); i++) x[i] = InitCaps(x[i]); String outdir = GetVar("OUTPUT"); if(output_per_assembly) outdir = AppendFileName(outdir, GetVarsName()); if(!use_target) outdir = AppendFileName(outdir, package); outdir = AppendFileName(outdir, GetFileTitle(method) + "." + Join(x, ".")); outdir = Filter(outdir, CharFilterSlash); return outdir; }
void CodeBrowser::Load() { String find = ToUpper((String)~search); String match = ToUpper((String)~search_scope); String pm = GetPm(); Vector<String> txt; Vector<Value> ndx; Index<int> fi; Index<String> fs; for(int i = 0; i < CodeBase().GetCount(); i++) { String s = CodeBase().GetKey(i); const Array<CppItem>& n = CodeBase()[i]; if(s.GetCount()) if(MatchCib(s, match) && (MatchCib(s, find) || HasItem(n, find)) && MatchPm(n, pm)) { txt.Add(s); ndx.Add(s); } for(int i = 0; i < n.GetCount(); i++) { int f = n[i].file; if(fi.Find(f) < 0) { String s = GetFileText(GetSourceFilePath(f)); if(s.StartsWith(pm) && MatchCib(s, match) && (IsNull(find) || MatchCib(s, find) || n[i].uname.StartsWith(find))) { txt.Add(s); ndx.Add(f); fs.Add(s); fi.Add(f); } } } } const Workspace& wspc = GetIdeWorkspace(); for(int i = 0; i < wspc.GetCount(); i++) { String pn = wspc[i]; const Package& p = wspc.GetPackage(i); String pp = PackageDirectory(pn); for(int j = 0; j < p.GetCount(); j++) if(!p[j].separator) { String fn = AppendFileName(pp, p[j]); String s = GetFileText(AppendFileName(pn, p[j])); if(fs.Find(s) < 0 && (IsNull(find) || MatchCib(s, find)) && MatchCib(s, match) && MatchPm(fn, pm)) { int f = GetSourceFileIndex(SourcePath(pn, p[j])); txt.Add(s); ndx.Add(f); fs.Add(s); } } } IndexSort(txt, ndx, ScopeLess()); Value key = scope.GetKey(); int sc = scope.GetCursorSc(); scope.Clear(); for(int i = 0; i < txt.GetCount(); i++) scope.Add(IsString(ndx[i]) ? ndx[i] : Null, txt[i], ndx[i]); if(scope.FindSetCursor(key)) scope.ScCursor(sc); // clear.Enable(IsSearch()); }
bool Thread::Run(Callback _cb) { LLOG("Thread::Run"); AtomicInc(sThreadCount); if(!threadr) #ifndef CPU_BLACKFIN threadr = sMain = true; #else { threadr = true; //the sMain replacement #ifdef PLATFORM_POSIX pthread_t thid = pthread_self(); vm.Enter(); if(threadsv.Find(thid) < 0){ //thread not yet present, mark present threadsv.Add(thid); } else RLOG("BUG: Multiple Add in Mt.cpp"); vm.Leave(); #endif } #endif Detach(); Callback *cb = new Callback(_cb); #ifdef PLATFORM_WIN32 handle = (HANDLE)_beginthreadex(0, 0, sThreadRoutine, cb, 0, ((unsigned int *)(&thread_id))); #endif #ifdef PLATFORM_POSIX if(pthread_create(&handle, 0, sThreadRoutine, cb)) handle = 0; #endif return handle; }
void ToIndex(GtkTargetList *target_list, Index<String>& ndx) { gint n; GtkTargetEntry *t = gtk_target_table_new_from_list(target_list, &n); for(int i = 0; i < n; i++) ndx.Add(t[i].target); gtk_target_table_free(t, n); gtk_target_list_unref(target_list); }
void LoadFonts(DropList *face, Index<String>& fni, bool fixed) { for(int i = 0; i < Font::GetFaceCount(); i++) if(!!(Font::GetFaceInfo(i) & Font::FIXEDPITCH) == fixed) { String n = Font::GetFaceName(i); if(fni.Find(n) < 0) { fni.Add(n); face->Add(i, n); } } }
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; }
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; }
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; } } } }
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(); }
void SelectPackageDlg::SyncList() { String n = GetCurrentName(); int asc = alist.GetScroll(); int csc = clist.GetSbPos(); packages.Clear(); String s = ~search; int f = ~filter; Index<String> added; for(int i = 0; i < min((f & FIRST) ? 1 : data.GetCount(), data.GetCount()); i++) { const ArrayMap<String, PkData>& nest = data[i]; for(int i = 0; i < nest.GetCount(); i++) { const PkData& d = nest[i]; if(!nest.IsUnlinked(i) && d.ispackage && (!(f & MAIN) || d.main) && ToUpper(d.package + d.description + d.nest).Find(s) >= 0 && added.Find(d.package) < 0) { packages.Add() = d; added.Add(d.package); } } } Sort(packages); alist.Clear(); clist.Clear(); ListCursor(); static PackageDisplay pd, bpd; bpd.fnt.Bold(); for(int i = 0; i < packages.GetCount(); i++) { const PkInfo& pkg = packages[i]; Image icon = pkg.icon; if(IsNull(icon)) icon = pkg.main ? IdeImg::MainPackage() : IdeImg::Package(); clist.Add(pkg.package, icon); alist.Add(pkg.package, pkg.nest, pkg.description, icon); alist.SetDisplay(alist.GetCount() - 1, 0, pkg.main ? bpd : pd); } if(!alist.FindSetCursor(n)) alist.GoBegin(); if(!clist.FindSetCursor(n) && clist.GetCount()) clist.SetCursor(0); alist.ScrollTo(asc); clist.SetSbPos(csc); alist.HeaderTab(0).SetText("Package (" + AsString(alist.GetCount()) + ")"); }
void SelectPackageDlg::ScanFolder(const String& path, ArrayMap<String, PkData>& nd, const String& nest, Index<String>& dir_exists, const String& prefix) { for(FindFile ff(AppendFileName(path, "*.*")); ff; ff.Next()) if(ff.IsFolder() && !ff.IsHidden()) { dir_exists.Add(ff.GetPath()); String p = ff.GetPath(); bool nw = nd.Find(p) < 0; // Do we have any info loaded about this package? PkData& d = nd.GetAdd(ff.GetPath()); d.package = prefix + ff.GetName(); d.nest = nest; if(nw) { // No cached info available about the folder d.ispackage = IsLetter(*d.package) && d.package.Find('.') < 0; // First heuristic guess d.main = d.ispackage && prefix.GetCount() == 0; // Expect it is main } } }
void LoadPPConfig() { for(int i = 0; i < sAllMacros.GetCount(); i++) if(sAllMacros[i].segment_id == 0 && !sAllMacros.IsUnlinked(i)) sAllMacros.Unlink(i); s_namespace_macro.Clear(); s_namespace_end_macro.Clear(); StringStream ss(sDefs); int linei = 0; while(!ss.IsEof()) { String l = ss.GetLine(); try { CParser p(l); if(p.Char('#')) { if(p.Id("define")) { CppMacro def; String id = def.Define(p.GetPtr()); if(id.GetCount()) { PPMacro m; m.segment_id = 0; m.line = linei; m.macro = def; sAllMacros.Put(id, m); if(findarg(TrimBoth(def.body), "}", "};") >= 0) s_namespace_end_macro.Add(id); try { CParser p(def.body); if(p.Id("namespace") && p.IsId()) { String n = p.ReadId(); if(p.Char('{') && p.IsEof()) s_namespace_macro.Add(id, n); } } catch(CParser::Error) {} } } } } catch(CParser::Error) {} linei++; } }
void GatherSources(const String& master_path, const String& path_, Vector<int>& parents) { RHITCOUNT("GatherSources"); String path = NormalizeSourcePath(path_); if(sSrcFile.Find(path) >= 0) return; int ii = sSrcFile.GetCount(); for(int i = 0; i < parents.GetCount(); i++) sIncludes.Add(MAKEQWORD(parents[i], ii)); sSrcFile.Add(path, master_path); parents.Add(ii); const PPFile& f = GetPPFile(path); for(int i = 0; i < f.includes.GetCount(); i++) { String p = GetIncludePath(f.includes[i], GetFileFolder(path)); if(p.GetCount()) GatherSources(master_path, p, parents); } parents.Drop(); }
String Parser::SimpleType() { if(Key(tk_struct) || Key(tk_class) || Key(tk_union) || Key(tk_enum) || Key(tk_typename)) { if(lex.IsId() || lex == t_dblcolon) Name(); if(lex == '{') EatBody(); return Null; } if(Key(tk_bool) || Key(tk_float) || Key(tk_double) || Key(tk_void)) return Null; bool sgn = Key(tk_signed) || Key(tk_unsigned); if(Key(tk_long)) { Key(tk_int); return Null; } if(Key(tk_short)) { Key(tk_int); return Null; } if(Key(tk_int) || Key(tk_char) || Key(tk___int8) || Key(tk___int16) || Key(tk___int32) || Key(tk___int64)) return Null; if(sgn) return Null; const char *p = lex.Pos(); int cs = 0; Index<int> cix; Key(t_dblcolon); Check(lex.IsId(), "Name expected"); while(lex.IsId()) { if(cix.Find(lex) >= 0) cs++; else cix.Add(lex); ++lex; if(lex == '<') TemplateParams(); if(Key(t_dblcolon)) Key('~'); else break; } return cs ? String(p, lex.Pos()) : String(); }
void Load(const char *dir) { Index<String> exist; FindFile ff(AppendFileName(dir, "*.tpp")); while(ff) { if(ff.IsFolder()) { String s = GetFileTitle(ff.GetName()); group.Add(s, AttrText(TppName(s)).SetFont(StdFont().Bold())); exist.Add(s); } ff.Next(); } static const char *h[4] = { "src.tpp", "srcdoc.tpp", "srcimp.tpp", "app.tpp" }; for(int i = 0; i < __countof(h); i++) { String s = GetFileTitle(h[i]); if(exist.Find(s) < 0) group.Add(s, TppName(s) + " (new)"); } group.Add(Null, "<other new>"); group.GoBegin(); }
Vector<String> HelpTopicEnumTextFolders() { Index<String> out; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) { String drl = map.GetKey(i); String space, nesting, topic; HelpParseDPP(drl, space, nesting, topic); const HelpTopicInfo& info = map[i]; String folder = GetTextFolder(nesting, info.decl_module, info.text_folder); if(out.Find(folder) < 0) { out.Add(folder); LLOG("HelpTopicSave: folder = " << folder); } } Vector<String> list = out.PickKeys(); Sort(list, StdLess<String>()); return list; }
void WorkspaceWork::SavePackage() { if(IsNull(actualpackage) || actualpackage == METAPACKAGE) return; InvalidatePackageInfo(actualpackage); String pp = PackagePathA(actualpackage); RealizePath(pp); if(organizer && backup.Find(pp) < 0) { Backup& b = backup.Add(pp); FindFile ff(pp); if(ff) { b.time = ff.GetLastWriteTime(); b.data = LoadFile(pp); } else b.data = String::GetVoid(); } actual.Save(pp); String init; String mnm = Filter('_' + actualpackage + "_icpp_init_stub", CharFilterMacro); init << "#ifndef " << mnm << "\r\n"; init << "#define " << mnm << "\r\n"; Index<String> once; for(int i = 0; i < actual.uses.GetCount(); i++) { String u = actual.uses[i].text; if(once.Find(u) < 0) { once.Add(u); init << "#include \"" << actual.uses[i].text << "/init\"\r\n"; } } for(int i = 0; i < actual.GetCount(); i++) { String f = actual[i]; if(ToLower(GetFileExt(f)) == ".icpp") init << "#define BLITZ_INDEX__ " << "F" << MD5String(f) << "\r\n" << "#include \"" << f << "\"\r\n" << "#undef BLITZ_INDEX__\r\n"; } init << "#endif\r\n"; SaveChangedFile(SourcePath(actualpackage, "init"), init); }
void CodeBrowser::LoadScope() { String find = ToUpper((String)~search); Value key = item.GetKey(); int sc = item.GetCursorSc(); item.Clear(); if(!scope.IsCursor()) return; Value x = scope.Get(2); int file = IsNumber(x) ? (int)x : -1; String scope = file < 0 ? String(x) : String(); int q = CodeBase().Find(scope); bool filematch = file >= 0 && MatchCib(GetFileText(GetSourceFilePath(file)), find); bool scopematch = !filematch && MatchCib(scope, find); if(q >= 0) { const Array<CppItem>& n = CodeBase()[q]; VectorMap<String, bool> inherited; if(file < 0) GatherMethods(scope, inherited, false); Index<String> set; for(int i = 0; i < n.GetCount(); i++) { CppItemInfo m; (CppItem&) m = n[i]; if((find.GetCount() && m.uname.StartsWith(find) || filematch && m.file == file || scopematch) && set.Find(m.qitem) < 0) { set.Add(m.qitem); int q = inherited.Find(m.qitem); if(q >= 0) { m.over = true; m.virt = m.virt || inherited[q]; } item.Add(m.qitem, RawToValue(m)); } } } item.Sort(1, sort ? ItemCompareLexical : ItemCompare); if(item.FindSetCursor(key)) item.ScCursor(sc); // clear.Enable(IsSearch()); }
void DocDir::Refresh(const String& package) { FindFile ff(DocFile(package, "dir.h")); if(!ff) { RebuildDir(package); return; } FileTime dirtime = ff.GetLastWriteTime(); ff.Search(DocFile(package, "links")); if(ff && ff.GetLastWriteTime() > dirtime) { RebuildDir(package); return; } const ArrayMap<DocKey, Entry>& p = dir.GetAdd(package); Index<String> dfn; for(int i = 0; i < p.GetCount(); i++) if(p[i].type == NORMAL || p[i].type == EXTERNAL) dfn.Add(p[i].text); ff.Search(DocFile(package, "*.dpp")); int count = 0; while(ff) { DocKey key; if(dfn.Find(ff.GetName()) >= 0) if(ff.GetLastWriteTime() > dirtime) { RebuildDir(package); return; } else count++; else if(ReadDocHeader(DocFile(package, ff.GetName()), key) >= 0) { RebuildDir(package); return; } ff.Next(); } if(count != dfn.GetCount()) RebuildDir(package); }
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 HelpTopicLoad(String text_module, String data, Index<String> *topics_loaded) { const int *x = GetAllLanguages(); Vector<int> llist; while(*x) llist.Add(*x++); Index<String> lnames; while(lnames.GetCount() < llist.GetCount()) lnames.Add(GetLangIdent(llist[lnames.GetCount()])); int language = 0; CParser parser(data); while(!parser.IsEof()) { parser.Spaces(); if(parser.IsId()) { String id = parser.ReadId(); enum { DECL_NONE, DECL_HTB, DECL_HT, DECL_I } decl = DECL_NONE; if(id == "HELP_TOPIC_BEGIN") decl = DECL_HTB; else if(id == "HELP_TOPIC") decl = DECL_HT; else if(id == "ITEM") decl = DECL_I; if(decl != DECL_NONE) { parser.PassChar('('); String space = "AppDoc", nesting, topic; if(decl != DECL_HTB) { space = parser.ReadOneString(); parser.PassChar(','); nesting = parser.ReadOneString(); parser.PassChar(','); } topic = parser.ReadOneString(); parser.PassChar(','); if(decl == DECL_HTB) { String langid = parser.ReadId(); int lx = lnames.Find(langid); if(lx < 0) parser.ThrowError(NFormat("invalid language code: %d", language)); language = llist[lx]; } else { String lang = parser.ReadOneString(); language = LNGFromText(lang); } String title; if(decl != DECL_I) { parser.PassChar(','); title = parser.ReadOneString(); } parser.PassChar(')'); parser.Id("EXTERNAL"); String text; while(parser.IsId() && ((id = parser.ReadId()) == "HELP_TOPIC_TEXT" || id == "HELP_TEXT" || id == "TEXT")) { parser.PassChar('('); text.Cat(parser.ReadString()); parser.PassChar(')'); } if(id == "HELP_TOPIC_END") { parser.PassChar('('); parser.PassChar(')'); } else if(id == "END_ITEM" || id == "HELP_END") ; else parser.ThrowError(NFormat("HELP_TOPIC_END/END_ITEM expected, found: %s", StringSample(parser.GetPtr(), 10))); String drl = HelpFormatDPP(space, nesting, topic); HelpTopicSet(drl, text_module, language, title, text); if(topics_loaded) topics_loaded->FindAdd(drl); } else parser.ThrowError(NFormat("HELP_TOPIC_BEGIN/HELP_TOPIC/ITEM expected, found: %s", id)); } else parser.ThrowError(NFormat("identifier expected, found: %s", StringSample(parser.GetPtr(), 20))); } }
void TopicEditor::FixTopic() { String nest; if(!EditText(nest, "Fix topic", "Nest")) return; CppBase& base = CodeBase(); int q = base.Find(nest); if(q < 0) { Exclamation("Nest not found"); return; } Array<CppItem>& n = base[q]; Index<String> natural; Vector<String> link; for(int i = 0; i < n.GetCount(); i++) { const CppItem& m = n[i]; String nat; if(m.virt) nat << "virtual "; if(m.kind == CLASSFUNCTION || m.kind == CLASSFUNCTIONTEMPLATE) nat << "static "; nat << m.natural; natural.Add(nat); link.Add(MakeCodeRef(nest, n[i].qitem)); } RichText result; const RichText& txt = editor.Get(); bool started = false; int l, h; if(editor.GetSelection(l, h)) { l = txt.FindPart(l); h = txt.FindPart(h); } else { l = 0; h = txt.GetPartCount(); } for(int i = 0; i < txt.GetPartCount(); i++) if(txt.IsPara(i)) { RichPara p = txt.Get(i); if(i >= l && i < h) { WString h = p.GetText(); String nat; const wchar *s = h; while(*s) if(*s == 160 || *s == ' ') { nat.Cat(' '); while(*s == 160 || *s == ' ') s++; } else nat.Cat(*s++); int q = nat.GetCount() ? natural.Find(nat) : -1; if(q >= 0) { started = true; const CppItem& m = n[q]; RichText h = ParseQTF(styles + ("[s7; &]" + CreateQtf(link[q], n[q].name, m, GetLang(), true))); if(h.GetPartCount()) h.RemovePart(h.GetPartCount() - 1); result.CatPick(pick(h)); } else if(!started || p.GetLength()) result.Cat(p); } else result.Cat(p); } else { RichTable b; b <<= txt.GetTable(i); result.CatPick(pick(b)); } RichPara empty; result.Cat(empty); editor.BeginOp(); editor.SetSelection(0, txt.GetLength()); editor.PasteText(result); }
bool MakeBuild::Build(const Workspace& wspc, String mainparam, String outfile, bool clear_console) { String hfile = outfile + ".xxx"; SaveFile(hfile, ""); FileTime start_time = GetFileTime(hfile); // Defensive way to get correct filetime of start DeleteFile(hfile); ClearErrorEditor(); BeginBuilding(true, clear_console); bool ok = true; if(wspc.GetCount()) { for(int i = 0; i < wspc.GetCount(); i++) { const Package& pk = wspc.package[i]; for(int j = 0; j < pk.GetCount(); j++) if(pk[j] == "main.conf") { String pn = wspc[i]; String p = SourcePath(pn, "main.conf"); main_conf << "// " << pn << "\r\n" << LoadFile(p) << "\r\n"; PutConsole("Found " + p); } } if(main_conf.GetCount()) { VectorMap<String, String> bm = GetMethodVars(method); One<Host> host = CreateHost(false); One<Builder> b = CreateBuilder(~host); if(b) { Index<String> mcfg = PackageConfig(wspc, 0, bm, mainparam, *host, *b, NULL); String outdir = OutDir(mcfg, wspc[0], bm, false); String path = AppendFileName(outdir, "main.conf.h"); RealizePath(path); SaveChangedFile(path, main_conf); PutConsole("Saving " + path); add_includes << outdir << ';'; } } Vector<int> build_order; if(GetTargetMode().linkmode != 2) { for(int i = 1; i < wspc.GetCount(); i++) build_order.Add(i); } else { Index<int> remaining; for(int i = 1; i < wspc.GetCount(); i++) remaining.Add(i); while(!remaining.IsEmpty()) { int t; for(t = 0; t < remaining.GetCount(); t++) { const Package& pk = wspc.package[remaining[t]]; bool delay = false; for(int u = 0; u < pk.uses.GetCount(); u++) if(remaining.Find(wspc.package.Find(pk.uses[u].text)) >= 0) { delay = true; break; } if(!delay) break; } if(t >= remaining.GetCount()) t = 0; build_order.Add(remaining[t]); remaining.Remove(t); } } String mainpackage = wspc[0]; Vector<String> linkfile; String linkopt = GetMethodVars(method).Get(targetmode ? "RELEASE_LINK" : "DEBUG_LINK", Null); if(linkopt.GetCount()) linkopt << ' '; ok = true; int ms = msecs(); for(int i = 0; i < build_order.GetCount() && (ok || !stoponerrors); i++) { int px = build_order[i]; ok = BuildPackage(wspc, px, i, build_order.GetCount() + 1, mainparam, Null, linkfile, linkopt) && ok; if(msecs() - ms >= 200) { DoProcessEvents(); ms = msecs(); } } if(ok || !stoponerrors) { ok = BuildPackage(wspc, 0, build_order.GetCount(), build_order.GetCount() + 1, mainparam, outfile, linkfile, linkopt, ok) && ok; // Set the time of target to start-time, so that if any file changes during // compilation, it is recompiled during next build SetFileTime(target, start_time); } } EndBuilding(ok); ReQualifyCodeBase(); SetErrorEditor(); return ok; }
const FlatPP& GetFlatPPFile(const char *path) { Index<String> visited; visited.Add(path); return GetFlatPPFile(path, visited); }
void Navigator::Search() { sortitems.Check(sorting); int sc = scope.GetScroll(); String key = scope.GetKey(); String s = TrimBoth(~search); String search_name, search_nest; bool wholeclass = false; bool both = false; navigator_global = false; if(s.Find('.') >= 0) { Vector<String> h = Split((String)~search, '.'); if(*s.Last() == '.') search_nest = Join(h, "::"); else { search_name = h.Pop(); if(h.GetCount()) search_nest = Join(h, "::"); } wholeclass = *s == '.' && search_nest.GetCount(); } else { search_name = search_nest = ~search; both = true; } s = Join(Split(s, '.'), "::") + (s.EndsWith(".") ? "::" : ""); int lineno = StrInt(s); gitem.Clear(); nitem.Clear(); if(IsNull(theide->editfile)) return; int fileii = GetSourceFileIndex(theide->editfile); if(!IsNull(lineno)) { NavItem& m = nitem.Add(); m.type = "Go to line " + AsString(lineno); m.kind = KIND_LINE; m.line = lineno; gitem.Add(Null).Add(&m); } else if(IsNull(s) && !sorting) { const CppBase& b = CodeBase(); for(int i = 0; i < b.GetCount(); i++) { String nest = b.GetKey(i); const Array<CppItem>& ci = b[i]; for(int j = 0; j < ci.GetCount(); j++) { const CppItem& m = ci[j]; if(m.file == fileii) { NavItem& n = nitem.Add(); n.Set(m); n.nest = nest; n.decl_line = m.line; n.decl_file = m.file; n.decl = !m.impl; NavLine& l = n.linefo.Add(); l.impl = m.impl; l.file = m.file; l.line = m.line; } } } Sort(nitem, FieldRelation(&NavItem::line, StdLess<int>())); NavGroup(true); } else { navigator_global = true; const CppBase& b = CodeBase(); String usearch_nest = ToUpper(search_nest); String usearch_name = ToUpper(search_name); ArrayMap<String, NavItem> imap; bool local = sorting && IsNull(s); VectorMap<String, int> nest_pass; for(int pass = -1; pass < 2; pass++) { for(int i = 0; i < b.GetCount(); i++) { String nest = b.GetKey(i); bool foundnest = (wholeclass ? pass < 0 ? false : pass ? ToUpper(nest) == usearch_nest : nest == search_nest : pass < 0 ? nest == search_nest : (pass ? ToUpper(nest).Find(usearch_nest) >= 0 : nest.StartsWith(search_nest))) && nest.Find('@') < 0; if(local || foundnest || both) { const Array<CppItem>& ci = b[i]; for(int j = 0; j < ci.GetCount(); j++) { const CppItem& m = ci[j]; if(local ? m.file == fileii : m.uname.Find('@') < 0 && (pass < 0 ? m.name == search_name : pass ? m.uname.Find(usearch_name) >= 0 : m.name.StartsWith(search_name)) || both && foundnest) { String key = nest + '\1' + m.qitem; int q = nest_pass.Find(nest); int p = pass; if(q < 0) // We do not want classes to be split based on pass nest_pass.Add(nest, pass); else p = nest_pass[q]; q = imap.Find(key); if(q < 0) { NavItem& ni = imap.Add(key); ni.Set(m); ni.nest = nest; ni.decl_line = ni.line; ni.decl_file = ni.file; ni.decl = !ni.impl; ni.pass = p; NavLine& l = ni.linefo.Add(); l.impl = m.impl; l.file = m.file; l.line = m.line; } else { NavItem& mm = imap[q]; if(!m.impl && (!mm.decl || CombineCompare(mm.decl_file, m.file)(mm.decl_line, m.line) < 0)) { mm.decl = true; mm.decl_line = m.line; mm.decl_file = m.file; mm.natural = m.natural; } NavLine& l = mm.linefo.Add(); l.impl = m.impl; l.file = m.file; l.line = m.line; } } } } } } nitem = imap.PickValues(); NavGroup(false); SortByKey(gitem); Vector<String> keys = gitem.PickKeys(); Vector<Vector<NavItem *> > values = gitem.PickValues(); IndexSort(keys, values); for(int i = 0; i < keys.GetCount(); i++) keys[i].Remove(0); VectorMap<String, Vector<NavItem *> > h(pick(keys), pick(values)); gitem = pick(h); for(int i = 0; i < gitem.GetCount(); i++) Sort(gitem[i], sorting ? SortByNames : SortByLines); } scope.Clear(); scope.Add(Null); Index<String> done; for(int i = 0; i < gitem.GetCount(); i++) { String s = gitem.GetKey(i); if(done.Find(s) < 0) { done.Add(s); scope.Add(s); } } scope.ScrollTo(sc); if(!navigator_global || !scope.FindSetCursor(key)) scope.GoBegin(); }