get rid of piForeach

apply some code analyzer recommendations
ICU flag now check if libicu exists
prepare for more accurate growth of containers (limited PoT, then constantly increase size)
This commit is contained in:
2024-11-20 20:01:47 +03:00
parent 24112498ce
commit caa7880cc4
40 changed files with 415 additions and 320 deletions

View File

@@ -152,7 +152,7 @@ PIMap<PIString, PIStringList> qt_filters;
PIString findLib(const PIString & l) {
if (PIFile::isExists(l)) return l;
piForeachC(PIString & s, lib_dirs) {
for (const auto & s: lib_dirs) {
if (PIFile::isExists(s + l)) return s + l;
if (win_target || l.toLowerCase().endsWith("dll")) {
PIFile::FileInfo info(l);
@@ -308,13 +308,13 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
}
if (!otool.isEmpty()) {
lines = filter(execute(otool + " -L \"" + file + "\""), "(");
piForeach(PIString & l, lines) {
for (auto & l: lines) {
l = l.left(l.find('('));
l.trim(); //.append('.').prepend('.');
}
}
}
piForeachC(PIString & sl, lines) {
for (const auto & sl: lines) {
PIString l = sl.trimmed();
if (!otool.isEmpty()) {
PIString fname = frameworkName(l);
@@ -367,7 +367,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
}
PIVector<PIString> clibs = cur_libs.toVector();
if (!clibs.isEmpty()) piCout << " new dependencies:\n -" << PIStringList(clibs).join("\n - ");
piForeachC(PIString & l, clibs) {
for (const auto & l: clibs) {
procLdd(l, false, cur_depth);
}
}
@@ -402,7 +402,7 @@ void procQt() {
PIDir(qt_plugins_dir).make(true);
PIDir(qt_qml_dir).make(true);
}
piForeach(PIString l, vsl) {
for (auto l: vsl) {
if (l.trim().contains("Qt version")) {
l.cutLeft(l.find("Qt version") + 10).trim();
PIString qv = l.takeWord();
@@ -411,7 +411,7 @@ void procQt() {
piCout << "Qt" << qv << "in" << qloc;
PIString qdir;
PIStringList suffixes({".", "..", "qt5", "../qt5", "qt6", "../qt6"});
piForeachC(PIString s, suffixes) {
for (const auto & s: suffixes) {
PIString qd = qloc + "/" + s + "/plugins/";
if (piDebug) PICout(AddSpaces) << "Qt plugins root try" << qd << "...";
if (PIDir::isExists(qd + "platforms")) {
@@ -422,14 +422,14 @@ void procQt() {
piCout << " no";
}
if (qdir.isEmpty()) break;
piForeachC(PIString & plugin, pdirs) {
for (const auto & plugin: pdirs) {
PIStringList filters = qt_filters[plugin];
piCout << "PLUG" << plugin << filters;
piForeachC(PIString & f, filters) {
for (const auto & f: filters) {
if (f.isEmpty()) continue;
copyWildcard(qdir + "plugins/" + plugin + "/" + f, qt_plugins_dir + plugin);
PIVector<PIFile::FileInfo> copied = PIDir(qt_plugins_dir + plugin).entries();
piForeachC(PIFile::FileInfo & fi, copied) {
for (const auto & fi: copied) {
if (fi.isFile()) {
procLdd(fi.path);
plugin_libs << fi.path;
@@ -441,7 +441,7 @@ void procQt() {
if (q.isEmpty()) continue;
copyWildcard(qdir + "qml/" + q + "/*", qt_qml_dir + q);
PIVector<PIFile::FileInfo> copied = PIDir(qt_qml_dir + q).allEntries();
piForeachC(PIFile::FileInfo & fi, copied) {
for (const auto & fi: copied) {
if (fi.isFile()) {
procLdd(fi.path);
plugin_libs << fi.path;
@@ -481,11 +481,11 @@ void patchNameTool() {
PIFile::FileInfo fi;
patch_list = input_files;
patch_list << plugin_libs;
piForeach(PIString l, clibs) {
for (const auto & l: clibs) {
fi.path = l;
patch_list << (out_dir + fi.name());
}
piForeach(PIString local_lib, patch_list) {
for (const auto & local_lib: patch_list) {
execute("chmod +w \"" + local_lib + "\"");
fi.path = local_lib;
cmd = nametool + " -id \"@executable_path/../Frameworks/" + fi.name() + "\"";
@@ -493,15 +493,15 @@ void patchNameTool() {
// piCout << " " << cmd;
execute(cmd);
}
piForeach(PIString f, flibs) {
for (const auto & f: flibs) {
PIString fl = findLib(frameworkName(f));
if (fl.isEmpty()) continue;
patch_list << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
// PICout(DefaultControls) << "map" << f << "->" << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
}
piForeach(PIString local_lib, patch_list) {
for (const auto & local_lib: patch_list) {
dlibs = filter(execute(otool + " -L \"" + local_lib + "\""), "(");
piForeach(PIString & l, dlibs) {
for (auto & l: dlibs) {
l = l.left(l.find('('));
l.trim();
}
@@ -509,7 +509,7 @@ void patchNameTool() {
execute("chmod +w \"" + local_lib + "\"");
}
piCout << "patch" << local_lib;
piForeach(PIString sys_lib, dlibs) {
for (auto sys_lib: dlibs) {
sys_lib.cutRight(1).trim();
fi.path = sys_lib;
libname = fi.name();
@@ -536,7 +536,7 @@ void patchNameTool() {
}
}
}
piForeach(PIString bin, input_files) {
for (const auto & bin: input_files) {
cmd = nametool + " -add_rpath \"@executable_path/../Frameworks\"";
cmd += " \"" + bin + "\"" + ign_err_suffix;
execute(cmd);
@@ -559,9 +559,9 @@ void patchRPathFile(const PIFile::FileInfo & file) {
void patchRPath() {
PIStringList dirs({out_dir, target_dir, qt_plugins_dir, qt_qml_dir});
dirs.removeDuplicates().removeStrings(PIString());
piForeachC(PIString & d, dirs) {
for (const auto & d: dirs) {
PIVector<PIFile::FileInfo> files = PIDir(d).allEntries();
piForeachC(PIFile::FileInfo & f, files) {
for (const auto & f: files) {
if (f.isDir()) continue;
patchRPathFile(f.path);
}
@@ -649,7 +649,7 @@ int main(int argc, char * argv[]) {
if (!qroot.endsWith("/")) qroot.append("/");
lib_dirs << (qroot + "bin") << (qroot + "lib") << (qroot + "Frameworks");
}
piForeach(PIString & s, lib_dirs) {
for (auto & s: lib_dirs) {
s.trim();
if (!s.endsWith("/")) s += "/";
}
@@ -669,7 +669,7 @@ int main(int argc, char * argv[]) {
styles = cli.argumentValue("Styles").split(",");
if (styles.isEmpty()) styles << "";
PIStringList qpd = cli.argumentValue("qt-plugins").toLowerCase().split(DELIM).removeAll("");
piForeachC(PIString & qp, qpd) {
for (const auto & qp: qpd) {
int _i = qp.find('=');
if (_i < 0) continue;
PIString pname = qp.left(_i).trim();
@@ -739,7 +739,7 @@ int main(int argc, char * argv[]) {
checkQtLib(f);
});
}
piForeach(PIString & s, add_libs) {
for (auto & s: add_libs) {
if (s.isEmpty()) continue;
PIString alib = findLib(s);
if (alib.isEmpty()) continue;
@@ -752,7 +752,7 @@ int main(int argc, char * argv[]) {
if (is_deps) { // if Qt in system, then no plugins copy
PIVector<PIString> qlibs = qt_libs.toVector();
piCout << "check for installed Qt" << qlibs;
piForeach(PIString l, qlibs) {
for (const auto & l: qlibs) {
if (procDpkg(l)) {
piCout << "system Qt found!";
need_qt_plugins = false;
@@ -783,7 +783,7 @@ int main(int argc, char * argv[]) {
out_dir.replaceAll("/", "\\");
#endif
PIVector<PIString> clibs = all_libs.toVector();
piForeach(PIString l, clibs) {
for (auto l: clibs) {
PIFile::FileInfo fi;
fi.path = l;
#ifdef WINDOWS
@@ -803,7 +803,7 @@ int main(int argc, char * argv[]) {
}
}
PIVector<PIString> fwdirs = frameworks.toVector();
piForeachC(PIString & f, fwdirs) {
for (const auto & f: fwdirs) {
PIString fd = findLib(f);
if (!fd.isEmpty()) {
piCout << "copy framework" << f;

View File

@@ -78,7 +78,7 @@ void Daemon::Remote::termTimerTick() {
void Daemon::Remote::startAction(Daemon::PacketType a, const PIString & dir, const PIStringList & fl) {
_fl = fl;
if (!dir.isEmpty())
piForeach(PIString & s, _fl)
for (auto & s: _fl)
s.prepend(dir);
// piCout << "send" << _fl;
action = a;
@@ -122,7 +122,7 @@ void Daemon::Remote::updateDirEntries() {
// piCout << dir_my;
if (!dir_my.isExists()) dir_my = PIDir::current();
my_filelist = dir_my.entries();
piForeach(PIFile::FileInfo & f, my_filelist)
for (auto & f: my_filelist)
f.path = f.name();
}
@@ -325,7 +325,7 @@ Daemon::~Daemon() {
dtimer.stopAndWait();
requestCloseShell();
PIVector<Remote *> rl = remotes.values();
piForeach(Remote * r, rl) {
for (auto * r: rl) {
r->shellClose();
delete r;
}
@@ -554,7 +554,7 @@ void Daemon::timerEvent(int delim) {
screen->lock();
list_daemons->content.clear();
availableDaemons();
piForeachC(PIString & i, available_daemons)
for (const auto & i: available_daemons)
list_daemons->content << TileList::Row(i, CellFormat());
screen->unlock();
if (delim == 5 && mode == rmInformation) {
@@ -570,7 +570,7 @@ void Daemon::timerEvent(int delim) {
PIStringList Daemon::availableDaemons() {
available_daemons.clear();
lock();
piForeachC(PIPeer::PeerInfo & p, allPeers()) {
for (const auto & p: allPeers()) {
if (!p.name.startsWith(pisd_prefix)) continue;
available_daemons << p.name.mid(6);
}

View File

@@ -15,7 +15,7 @@ PIStringList FileManager::TileDir::selectedNames() const {
PIStringList ret;
PIMutexLocker ml(e_mutex);
PIVector<int> sind = selected.toVector();
piForeachC(int i, sind)
for (const auto i: sind)
ret << entries[i].name();
ret.removeOne("..");
return ret;
@@ -181,7 +181,7 @@ void FileManager::TileDir::buildNames() {
CharFlags cf = 0;
Color cc = Default;
PIString fcol, scol;
piForeachC(PIFile::FileInfo & e, entries) {
for (const auto & e: entries) {
if (e.isDir()) {
t = '/';
cf = Bold;
@@ -258,7 +258,7 @@ FileManager::FileManager() {
labels->direction = Horizontal;
PIVector<SSPair> ll;
ll << SSPair(" Esc", "Exit") << SSPair(" F5", "Copy") << SSPair(" F6", "Move") << SSPair(" F7", "MkDir") << SSPair(" F8", "Delete");
piForeachC(SSPair & l, ll) {
for (const auto & l: ll) {
tl = new TileSimple();
labels->addTile(tl);
tl->content << TileSimple::Row(l.first, CellFormat(White, Transparent, Bold));
@@ -315,7 +315,7 @@ PIStringList FileManager::selectedRemote() const {
PIStringList ret;
panels[1]->lock();
PIVector<int> sil = panels[1]->selected.toVector();
piForeachC(int i, sil)
for (const auto i: sil)
ret << panels[1]->entries[i].path;
panels[1]->unlock();
return ret;

View File

@@ -197,7 +197,7 @@ public:
// "]"
,
CellFormat());
piForeachC(PIPeer::PeerInfo & p, daemon_.allPeers())
for (const auto & p: daemon_.allPeers())
peers_tl->content << TileList::Row(p.name + " | d = " + PIString::fromNumber(p.dist) + " | p = " +
PIString::fromNumber(p.ping()) + " | n = " + PIString::fromBool(p.isNeighbour()),
CellFormat());
@@ -206,7 +206,7 @@ public:
peerinfo_tl->content << TileSimple::Row("Name: " + pi.name, CellFormat());
peerinfo_tl->content << TileSimple::Row("Addreses: " + PIString::fromNumber(pi.addresses.size()), CellFormat());
peerinfo_tl->content << TileSimple::Row("Neighbours: " + pi.neighbours.join(", "), CellFormat());
piForeachC(PIPeer::PeerInfo::PeerAddress & a, pi.addresses)
for (const auto & a: pi.addresses)
addrs_tl->content << TileList::Row(a.address.toString() + " | p = " + PIString::fromNumber(a.ping) +
" | a = " + PIString::fromBool(a.isAvailable()),
CellFormat());
@@ -217,7 +217,7 @@ public:
s += " -> " + pp->name;
peermap << s;
}
piForeachC(PIString & s, peermap)
for (const auto & s: peermap)
peermap_tl->content << TileList::Row(s, CellFormat());
updatePeerDiag(peerdiagdata_tl, daemon_.diagnosticData());
updatePeerDiag(peerdiagservice_tl, daemon_.diagnosticService());
@@ -238,9 +238,9 @@ public:
tile->content << TileList::Row("PID: " + PIString::fromNumber(sys_mon.statistic().ID), CellFormat());
tile->content << TileList::Row(line, CellFormat());
tile->content << TileList::Row("Threads:", CellFormat());
piForeachC(PISystemMonitor::ThreadStats & t, ts)
for (const auto & t: ts)
maxlen = piMaxi(maxlen, t.name.length());
piForeachC(PISystemMonitor::ThreadStats & t, ts) {
for (const auto & t: ts) {
line = PIString::fromNumber(++num).expandLeftTo(2, ' ') + ": ";
line += PIString(t.name).expandRightTo(maxlen, ' ') + ": k ";
PIString ns = PIString::fromNumber(t.cpu_load_kernel, 'f', 2);
@@ -256,7 +256,7 @@ public:
if (tinfo->visible) updateSysMon();
}
EVENT_HANDLER(void, menuRequest) {
piForeach(PIScreenTile * t, mtiles)
for (auto * t: mtiles)
t->hide();
daemon_.disconnect();
tmenu->show();
@@ -265,7 +265,7 @@ public:
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e) {
if (t == tmenu) {
if (e.type == TileList::RowPressed) {
piForeach(PIScreenTile * t, mtiles)
for (auto * t: mtiles)
t->hide();
switch (e.data.toInt()) {
case 0: tinfo->show(); break;

View File

@@ -130,7 +130,7 @@ void removeFiles(const PIDir & dir, PIStringList l) {
l.removeAll("..");
PIString ap = dir.absolutePath();
// piCout << "remove from" << ap;
piForeachC(PIString & s, l) {
for (const auto & s: l) {
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
if (fi.isDir()) {
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);
@@ -149,7 +149,7 @@ bool cryptFiles(const PIDir & dir, PIStringList l, const PIByteArray & secret) {
if (secret.size() != PICrypt::sizeKey() || secret.isEmpty()) return false;
l.removeAll("..");
PIString ap = dir.absolutePath();
piForeachC(PIString & s, l) {
for (const auto & s: l) {
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
if (fi.isDir()) {
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);