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()); }
ArrayMap<String, EscValue> TemplateDlg::MakeVars() { const PackageTemplate& tp = ActualTemplate(); ArrayMap<String, EscValue> var = MakeVars0(); for(int i = 0; i < tp.item.GetCount(); i++) var.Add(tp.item[i].id, EscFromStdValue(~ctrl[i])); StdLib(var); return var; }
void TemplateDlg::EnterTemplate() { const PackageTemplate& tp = ActualTemplate(); ArrayMap<String, EscValue> var; var.Add("PACKAGE", (String)~package); StdLib(var); label.Clear(); ctrl.Clear(); Point pos = templist.GetRect().BottomLeft(); pos.y += 8; int cx = cancel.GetRect().right - pos.x; for(int i = 0; i < tp.item.GetCount(); i++) { const TemplateItem& m = tp.item[i]; if(m.type == TEMPLATEITEM_OPTION) ctrl.Create<Option>().SetLabel(m.label); else { label.Add().SetLabel(m.label).LeftPos(pos.x, cx).TopPos(pos.y); Add(label.Top()); pos.y += label.Top().GetMinSize().cy; switch(m.type) { case TEMPLATEITEM_ID: { EditField *e = new EditField; e->SetFilter(IdFilter); ctrl.Add(e); break; } case TEMPLATEITEM_FILENAME: { EditField *e = new EditField; e->SetFilter(FilenameFilter); ctrl.Add(e); break; } case TEMPLATEITEM_SELECT: { DropList *d = new DropList; for(int i = 0; i < m.value.GetCount(); i++) d->Add(i, m.value[i]); if(m.value.GetCount()) d->SetIndex(0); ctrl.Add(d); break; } case TEMPLATEITEM_TEXT: { EditField *e = new EditField; ctrl.Add(e); break; } } } Add(ctrl.Top()); ctrl.Top() << ~delay; ctrl.Top().LeftPos(pos.x, cx).TopPos(pos.y); pos.y += ctrl.Top().GetMinSize().cy + 6; ctrl.Top().ClearModify(); } Inits(); Preview(); }
String GetSegmentFile(int segment_id) { for(int i = 0; i < sPPfile.GetCount(); i++) { const Array<PPItem>& m = sPPfile[i].item; for(int j = 0; j < m.GetCount(); j++) if(m[j].type == PP_DEFINES && m[j].segment_id == segment_id) return sPPfile.GetKey(i); } return "<not found>"; }
void sPut(String& qtf, ArrayMap<String, FileStat>& pfs, ArrayMap<String, FileStat>& all) { FileStat pall; for(int i = 0; i < pfs.GetCount(); i++) { FileStat& fs = pfs[i]; sPut(pfs.GetKey(i), qtf, fs); pall.Add(fs); all.GetAdd(pfs.GetKey(i)).Add(fs); } sPut("All files", qtf, pall); qtf << "}}&&"; }
ArrayMap<String, EscValue> TemplateDlg::MakeVars0() { ArrayMap<String, EscValue> var; String n = ~package; int q = n.ReverseFind('/'); var.Add("PACKAGE", q >= 0 ? n.Mid(q + 1) : n); var.Add("PACKAGE_TOUPPER", ToUpper(n)); var.Add("PACKAGE_TOUPPER_CAPS", ToUpper_Caps(n)); var.Add("DESCRIPTION", String(~description)); return var; }
Speller *sGetSpeller(int lang) { static ArrayMap<int, Speller> speller; int q = speller.Find(lang); if(q < 0) { String pp = spell_path; DoSpellerPath(pp, GetExeDirFile("scd")); DoSpellerPath(pp, ConfigFile("scd")); pp << spell_path << ';' << getenv("LIB") << ';' << getenv("PATH") << ';'; String path = GetFileOnPath(ToLower(LNGAsText(lang)) + ".udc", pp); if(IsNull(path)) path = GetFileOnPath(ToLower(LNGAsText(lang)) + ".scd", pp); if(IsNull(path)) return NULL; FileIn in(path); if(!in) return NULL; q = speller.GetCount(); Speller& f = speller.Add(lang); FileIn user(sUserFile(lang)); while(!user.IsEof()) { String s = user.GetLine(); if(!s.IsEmpty()) f.user.Add(FromUtf8(s)); } if(in.Get() != 255) f.SetOld(LoadFile(path)); else { f.path = path; int n = in.GetL(); LLOG("Found scd file " << path << " blocks " << n); if(n > 0 && n < 100000) { for(int i = 0; i < n; i++) { SpellBlock& b = f.block.Add(); b.first = in.Get(in.Get()); b.ctrl_len = in.GetL(); b.text_len = in.GetL(); } if(in.IsEof()) f.block.Clear(); else { int off = (int)in.GetPos(); for(int i = 0; i < n; i++) { SpellBlock& b = f.block[i]; b.offset = off; off += b.ctrl_len + b.text_len; } } } } } return &speller[q]; }
void PPSync(const String& include_path) { LLOG("* PPSync"); sIncludePath.Clear(); sFlatPP.Clear(); sInclude_Path = include_path; }
void CleanPP() { sAllMacros.Clear(); sPPfile.Clear(); sPPserial = 0; LoadPPConfig(); }
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 Data::Dump() { DUMP(sz); DUMP(text); LOG("lang: " << LNGAsText(lang)); DUMPC(vector); LOG("score: "); for(int i = 0; i < score.GetCount(); i++) LOG(" " << score.GetKey(i) << " ..... " << score[i]); LOG("map: "); for(int i = 0; i < map.GetCount(); i++) LOG(" " << map.GetKey(i) << " ..... " << map[i]); LOG("sizemap: "); for(int i = 0; i < sizemap.GetCount(); i++) LOG(" " << sizemap.GetKey(i) << " ..... " << sizemap[i]); DUMP(number); DUMP(option); }
const PPFile& GetPPFile(const char *path) { LTIMING("GetPPFile"); Time tm = GetFileTimeCached(path); PPFile& f = sPPfile.GetPut(path); LLOG("GetPPFile " << path << ", " << f.filetime << ", " << tm); if(f.filetime != tm) { f.filetime = tm; FileIn in(path); f.Parse(in); } return f; }
const FlatPP& GetFlatPPFile(const char *path, Index<String>& visited) { LTIMING("GetFlatPPFile"); LLOG("GetFlatPPFile " << path); int q = sFlatPP.Find(path); if(q >= 0) { LLOG("From cache"); return sFlatPP[q]; } FlatPP& fp = sFlatPP.Add(path); const PPFile& pp = GetPPFile(path); int n = visited.GetCount(); visited.FindAdd(path); for(int i = 0; i < pp.item.GetCount(); i++) { const PPItem& m = pp.item[i]; if(m.type == PP_INCLUDE) { String s = GetIncludePath(m.text, GetFileFolder(path)); LLOG("#include " << m.text << " -> " << s); if(s.GetCount() && visited.Find(s) < 0) { visited.Add(s); const FlatPP& pp = GetFlatPPFile(s, visited); for(int i = 0; i < pp.segment_id.GetCount(); i++) fp.segment_id.FindAdd(pp.segment_id[i]); for(int i = 0; i < pp.usings.GetCount(); i++) fp.usings.FindAdd(pp.usings[i]); } } else if(m.type == PP_DEFINES) fp.segment_id.FindAdd(m.segment_id); else if(m.type == PP_USING) fp.usings.FindAdd(m.text); } visited.Trim(n); return fp; }
void SweepPPFiles(const Index<String>& keep) { Index<int> pp_segment_id; int unlinked_count = 0; for(int i = 0; i < sPPfile.GetCount(); i++) if(sPPfile.IsUnlinked(i)) unlinked_count++; else if(keep.Find(sPPfile.GetKey(i)) < 0) { unlinked_count++; sPPfile.Unlink(i); } else { const PPFile& p = sPPfile[i]; for(int j = 0; j < p.item.GetCount(); j++) pp_segment_id.FindAdd(p.item[j].segment_id); } if(unlinked_count > sPPfile.GetCount() / 2) { CleanPP(); return; } unlinked_count = 0; for(int i = 0; i < sAllMacros.GetCount(); i++) { if(sAllMacros.IsUnlinked(i)) unlinked_count++; else if(sAllMacros[i].segment_id && pp_segment_id.Find(sAllMacros[i].segment_id) < 0) { sAllMacros.Unlink(i); unlinked_count++; } if(unlinked_count > sAllMacros.GetCount() / 2) { CleanPP(); return; } } }
static void doTest(ArrayMap<Foo> &am, Map &m, int k, int v) { cout << "Updating with (" << k << ", " << v << ")" << endl; am.set(k, am.get(k) + v); m[k] = m[k] + v; set<int> visited; for (int i = 0; i < 10000; ++i) { if (visited.end() != visited.find(i)) continue; visited.insert(i); const int kk = am.minKey() + ::rand() % ((am.maxKey() - am.minKey()) * 2); const int r1 = am.get(kk), r2 = m[kk]; if (r1 != r2) { cerr << "For " << kk << ": am -> " << r1 << " != " << r2 << " <- m" << endl; } } }
void DockWindow::SerializeLayout(Stream &s, bool withsavedlayouts) { StopHighlight(false); int cnt = 0; s.Magic(); // Groups ArrayMap<String, Vector<int> > groups; if (s.IsStoring()) for (int i = 0; i < dockers.GetCount(); i++) { String g = dockers[i]->GetGroup(); if (!g.IsEmpty()) { int ix = groups.Find(g); if (ix < 0) { groups.Add(dockers[i]->GetGroup(), Vector<int>()); ix = groups.GetCount() - 1; } groups[ix].Add(i); } } s % groups; if (s.IsLoading()) { ClearLayout(); for (int i = 0; i < dockers.GetCount(); i++) dockers[i]->SetGroup(Null); for (int i = 0; i < groups.GetCount(); i++) { Vector<int> &v = groups[i]; const String &g = groups.GetKey(i); for (int j = 0; j < v.GetCount(); j++) { int ix = v[j]; if (ix >= 0 && ix < dockers.GetCount()) dockers[ix]->SetGroup(g); } } } if (s.IsStoring()) { // Write docked for (int i = 0; i < 4; i++) { DockPane &pane = dockpane[i]; int fsz = dockframe[i].IsShown() ? dockframe[i].GetSize() : 0; s / fsz % pane; DockCont *dc = dynamic_cast<DockCont *>(pane.GetFirstChild()); for (int j = 0; dc && j < pane.GetCount(); j++) { s % *dc; dc = dynamic_cast<DockCont *>(dc->GetNext()); } } cnt = 0; // Count Floating for (int i = 0; i < conts.GetCount(); i++) if (conts[i].IsFloating()) cnt++; // Write Floating s / cnt; for (int i = 0; i < conts.GetCount(); i++) { if (conts[i].IsFloating()) { conts[i].Serialize(s); conts[i].SerializePlacement(s, false); } } // Write Autohidden for (int i = 0; i < 4; i++) { cnt = hideframe[i].GetCount(); s / cnt; for (int j = 0; j < hideframe[i].GetCount(); j++) { int ix = FindDocker(&hideframe[i].GetCtrl(j)->Get(0)); if (ix >= 0) s / ix; } } } else { // Read docked for (int i = 0; i < 4; i++) { DockPane &pane = dockpane[i]; dockframe[i].Hide(); int fsz; s / fsz % pane; for (int j = 0; j < pane.GetCount(); j++) { DockCont *dc = CreateContainer(); s % *dc; dc->StateDocked(*this); pane << *dc; } if (fsz && pane.GetCount()) { dockframe[i].SetSize(fsz); dockframe[i].Show(); } else dockframe[i].SetSize(0); } // Read floating s / cnt; for (int i = 0; i < cnt; i++) { DockCont *dc = CreateContainer(); dc->Serialize(s); FloatContainer(*dc); dc->SerializePlacement(s, false); } // Read Autohidden for (int i = 0; i < 4; i++) { s / cnt; for (int j = 0; j < cnt; j++) { int ix; s / ix; if (ix >= 0 && ix < dockers.GetCount()) AutoHide(i, *dockers[ix]); } } // Clear empty containers for (int i = conts.GetCount()-1; i >= 0; i--) { if (!conts.GetCount()) CloseContainer(conts[i]); } RefreshLayout(); } bool haslay = withsavedlayouts; s % haslay; if (withsavedlayouts && (s.IsStoring() || haslay)) s % layouts; s.Magic(); }
// get a list of connected serial ports // for old-style serials, check if something is connected // for usb ones, return also a description ArrayMap<String, String> Serial::GetSerialPorts(void) { const char *sysClassTTY = "/sys/class/tty/"; ArrayMap<String, String> res; // first, scan all tty devices and dereference symlinks FindFile ff(AppendFileName(sysClassTTY, "*")); while (ff) { if (ff.IsSymLink()) { // it's a symlink // get the device name String devName = ff.GetName(); // build the full path of it String serial = AppendFileName(sysClassTTY, devName); // look for its driver, skip if none String devPath = AppendFileName(serial, "device"); // it must be a symlink.... if (__IsSymLink(devPath)) { // get the driver path String drvLink = AppendFileName(devPath, "driver"); // it must be a symlink too... if (__IsSymLink(drvLink)) { // get link target String drvName = GetFileName(GetSymLinkPath(drvLink)); if (!drvName.IsEmpty()) { // build the full device name devName = AppendFileName("/dev", devName); // now if driver is 'serial8250' we check if // the port responds if (drvName == "serial8250") { // Try to open the device int fd = open(devName, O_RDWR | O_NONBLOCK | O_NOCTTY); if (fd >= 0) { // Get serial_info struct serial_struct serinfo; if (ioctl(fd, TIOCGSERIAL, &serinfo) == 0) { // If device type is no PORT_UNKNOWN we accept the port if (serinfo.type != PORT_UNKNOWN) res.Add(devName, ""); } close(fd); } } // otherwise, just add the device to result else res.Add(devName, drvName); } } } } ff.Next(); } return res; }
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(); }