Skip to content

Commit bdaabdb

Browse files
authored
Merge pull request #925 from os-fpga/planner_infrastructure_development
planner: infrastructure development
2 parents b40cf16 + cc1d058 commit bdaabdb

File tree

8 files changed

+160
-69
lines changed

8 files changed

+160
-69
lines changed

planning/src/RS/rsOpts.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ static bool input_file_exists(CStr fn) noexcept {
8282
return sz > 1; // require non-empty file
8383
}
8484

85+
static inline bool ends_with_dot_cmd(CStr z, size_t len) noexcept {
86+
assert(z);
87+
if (len < 5) return false;
88+
return z[len - 1] == 'd' and z[len - 2] == 'm' and z[len - 3] == 'c' and z[len - 4] == '.';
89+
// .cmd
90+
// dmc.
91+
}
92+
93+
static inline bool ends_with_dot_tcl(CStr z, size_t len) noexcept {
94+
assert(z);
95+
if (len < 5) return false;
96+
return z[len - 1] == 'l' and z[len - 2] == 'c' and z[len - 3] == 't' and z[len - 4] == '.';
97+
// .tcl
98+
// lct.
99+
}
100+
85101
static bool op_match(CStr op, CStr* aliases) noexcept {
86102
assert(op and aliases);
87103
if (!op || !aliases) return false;
@@ -324,6 +340,23 @@ bool rsOpts::is_implicit_check() const noexcept {
324340
return true;
325341
}
326342

343+
bool rsOpts::isTclInput() const noexcept {
344+
assert(argv_);
345+
assert(argv_[0]);
346+
assert(argc_ > 0);
347+
if (!argv_ or !argv_[0])
348+
return false;
349+
if (argc_ > 5 or assignOrder_)
350+
return false;
351+
352+
if (!input_ || !input_[0]) return false;
353+
size_t len = ::strlen(input_);
354+
if (len < 5 || len > UNIX_Path_Max) return false;
355+
if (!ends_with_dot_tcl(input_, len)) return false;
356+
357+
return input_file_exists(input_);
358+
}
359+
327360
void rsOpts::parse(int argc, const char** argv) noexcept {
328361
using namespace ::pln::alias;
329362

@@ -568,14 +601,6 @@ bool rsOpts::createVprArgv(vector<string>& W) noexcept {
568601
return true;
569602
}
570603

571-
static inline bool ends_with_dot_cmd(CStr z, size_t len) noexcept {
572-
assert(z);
573-
if (len < 5) return false;
574-
return z[len - 1] == 'd' and z[len - 2] == 'm' and z[len - 3] == 'c' and z[len - 4] == '.';
575-
// .cmd
576-
// dmc.
577-
}
578-
579604
bool rsOpts::isCmdInput() const noexcept {
580605
if (!input_ || !input_[0]) return false;
581606
size_t len = ::strlen(input_);

planning/src/RS/rsOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct rsOpts {
115115
bool hasInputFile() const noexcept;
116116
bool hasCsvFile() const noexcept;
117117
bool isCmdInput() const noexcept;
118+
bool isTclInput() const noexcept;
118119

119120
private:
120121
bool set_VPR_TC_args(CStr raw_tc) noexcept;

planning/src/file_io/pln_Fio.cpp

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ void Info::init() noexcept {
6060
}
6161
}
6262

63+
void Info::inval() noexcept {
64+
absName_.clear();
65+
type_.clear();
66+
size_ = 0;
67+
exists_ = false;
68+
accessible_ = false;
69+
absolute_ = false;
70+
numLines_ = -1;
71+
numWords_ = -1;
72+
maxLlen_ = -1;
73+
numTextChars_ = -1;
74+
}
75+
6376
string Info::get_abs_name(const string& nm) noexcept {
6477
namespace fs = std::filesystem;
6578
if (nm.empty()) return {};
@@ -549,14 +562,20 @@ int64_t MMapReader::countWC(int64_t& numWords) const noexcept {
549562
}
550563

551564
// unix command 'wc'
552-
int64_t MMapReader::printWC(std::ostream& os) const noexcept {
565+
int64_t MMapReader::printWC(std::ostream& os, Info* infRet) const noexcept {
566+
if (infRet)
567+
infRet->inval();
553568
assert(fsz_ == sz_);
554569
if (!fsz_ || !sz_ || !buf_ || fnm_.empty()) return -1;
555570

556571
int64_t numLines, numWords = 0;
557572
numLines = countWC(numWords);
558573

559574
os << numLines << ' ' << numWords << ' ' << sz_ << ' ' << fnm_ << endl;
575+
if (infRet) {
576+
infRet->numLines_ = numLines;
577+
infRet->numWords_ = numWords;
578+
}
560579

561580
return numLines;
562581
}
@@ -571,8 +590,9 @@ static void print_byte(std::ostream& os, CStr prefix, int b) noexcept {
571590
os.flush();
572591
}
573592

574-
bool MMapReader::is_text_file(string& label) const noexcept {
575-
label.clear();
593+
bool MMapReader::is_text_file(Info& typeRet, bool scan) const noexcept {
594+
typeRet.inval();
595+
typeRet.size_ = sz_;
576596
if (!buf_ or sz_ < 4)
577597
return false;
578598

@@ -582,39 +602,65 @@ bool MMapReader::is_text_file(string& label) const noexcept {
582602
// lprintf("\t ....... sig= %u hex %x\n", sig, sig);
583603

584604
if (sig == 0x464c457f) {
585-
label = "ELF";
605+
typeRet.type_ = "ELF";
586606
return false;
587607
}
588608
if (sig == 0x21726152) {
589-
label = "RAR";
609+
typeRet.type_ = "RAR";
590610
return false;
591611
}
592612
if (sig == 0x587a37fd) {
593-
label = "XZ";
613+
typeRet.type_ = "XZ";
594614
return false;
595615
}
596616
if (sig == 0xfd2fb528) {
597-
label = "ZST";
617+
typeRet.type_ = "ZST";
598618
return false;
599619
}
600620
if (sig == 0x425a6839) {
601-
label = "BZ2";
621+
typeRet.type_ = "BZ2";
602622
return false;
603623
}
604624
if (sig == 0x1f8b0808) {
605-
label = "GZ";
625+
typeRet.type_ = "GZ";
606626
return false;
607627
}
608628
if (sig == 0x46445025) {
609-
label = "PDF";
629+
typeRet.type_ = "PDF";
610630
return false;
611631
}
612632
if (sig == 0x213c6172) {
613-
label = "AR";
633+
typeRet.type_ = "AR";
614634
return false;
615635
}
616636

617-
return true;
637+
size_t numLines = 0, numText = 0;
638+
if (scan) {
639+
for (size_t i = 0; i < sz_; i++) {
640+
char c = buf_[i];
641+
if (!c) {
642+
numText++;
643+
continue;
644+
}
645+
if (c == '\n') {
646+
numLines++;
647+
numText++;
648+
continue;
649+
}
650+
numText += int(str::c_is_text(c));
651+
}
652+
}
653+
else {
654+
return true;
655+
}
656+
657+
if (sz_ - numText < 3) {
658+
typeRet.type_ = "TXT";
659+
return true;
660+
}
661+
662+
typeRet.type_ = "BIN";
663+
return false;
618664
}
619665

620666
bool MMapReader::printMagic(std::ostream& os) const noexcept {
@@ -645,12 +691,12 @@ bool MMapReader::printMagic(std::ostream& os) const noexcept {
645691
if (i > 8)
646692
break;
647693
}
648-
string label;
649-
bool is_txt = is_text_file(label);
694+
Info inf;
695+
bool is_txt = is_text_file(inf, true);
650696
if (is_txt) {
651697
os << "(guessed TEXT)" << endl;
652-
} else if (!label.empty()) {
653-
os << "(guessed BINARY) : " << label << endl;
698+
} else if (!inf.type_.empty()) {
699+
os << "(guessed BINARY) : " << inf.type_ << endl;
654700
}
655701
os.flush();
656702
return true;
@@ -668,8 +714,8 @@ bool MMapReader::isGoodForParsing() const noexcept {
668714
return false;
669715

670716
if (sz_ < UINT_MAX) {
671-
string label;
672-
bool is_txt = is_text_file(label);
717+
Info inf;
718+
bool is_txt = is_text_file(inf);
673719
return is_txt;
674720
}
675721

planning/src/file_io/pln_Fio.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,24 @@ inline char* p_strdup(CStr p) noexcept {
4040

4141
struct Info {
4242
string name_, absName_;
43+
string type_;
4344
size_t size_ = 0;
45+
int64_t numLines_ = 0;
46+
int64_t numWords_ = 0;
47+
int64_t maxLlen_ = 0;
48+
int64_t numTextChars_ = 0;
49+
4450
bool exists_ = false;
4551
bool accessible_ = false;
4652
bool absolute_ = false;
4753

4854
public:
4955
Info() noexcept = default;
56+
explicit Info(CStr nm) noexcept;
57+
explicit Info(const string& nm) noexcept;
5058

51-
Info(CStr nm) noexcept;
52-
Info(const string& nm) noexcept;
5359
void init() noexcept;
60+
void inval() noexcept;
5461

5562
static string get_abs_name(const string& nm) noexcept;
5663
static string get_realpath(const string& nm) noexcept;
@@ -215,9 +222,9 @@ class MMapReader : public Fio
215222
public:
216223
MMapReader() noexcept = default;
217224

218-
MMapReader(CStr nm) noexcept : Fio(nm) {}
225+
explicit MMapReader(CStr nm) noexcept : Fio(nm) {}
219226

220-
MMapReader(const string& nm) noexcept : Fio(nm) {}
227+
explicit MMapReader(const string& nm) noexcept : Fio(nm) {}
221228

222229
virtual ~MMapReader();
223230

@@ -242,7 +249,7 @@ class MMapReader : public Fio
242249
}
243250

244251
int64_t countWC(int64_t& numWords) const noexcept; // ~ wc command
245-
int64_t printWC(std::ostream& os) const noexcept; // ~ wc command
252+
int64_t printWC(std::ostream& os, Info* inf = nullptr) const noexcept;
246253

247254
size_t printLines(std::ostream& os) noexcept;
248255
int64_t writeFile(const string& nm) noexcept;
@@ -257,9 +264,9 @@ class MMapReader : public Fio
257264
int dprint1() const noexcept;
258265
int dprint2() const noexcept;
259266

260-
private:
261-
bool is_text_file(string& label) const noexcept;
267+
bool is_text_file(Info& typeRet, bool scan = false) const noexcept;
262268

269+
private:
263270
vector<char*> get_backslashed_block(size_t fromLine) noexcept;
264271

265272
}; // MMapReader
@@ -276,9 +283,9 @@ struct LineReader : public Fio
276283
size_t cap_ = lr_DEFAULT_CAP;
277284

278285
public:
279-
LineReader(size_t iniCap = 0) noexcept;
280-
LineReader(CStr nm, size_t iniCap = 0) noexcept;
281-
LineReader(const string& nm, size_t iniCap = 0) noexcept;
286+
explicit LineReader(size_t iniCap = 0) noexcept;
287+
explicit LineReader(CStr nm, size_t iniCap = 0) noexcept;
288+
explicit LineReader(const string& nm, size_t iniCap = 0) noexcept;
282289

283290
virtual ~LineReader() { p_free(buf_); }
284291

@@ -349,7 +356,7 @@ class CSV_Reader : public MMapReader
349356

350357
CSV_Reader(CStr nm) noexcept : MMapReader(nm) {}
351358

352-
CSV_Reader(const string& nm) noexcept : MMapReader(nm) {}
359+
explicit CSV_Reader(const string& nm) noexcept : MMapReader(nm) {}
353360

354361
virtual ~CSV_Reader();
355362

@@ -437,8 +444,8 @@ class XML_Reader : public MMapReader
437444

438445
public:
439446
XML_Reader() noexcept;
440-
XML_Reader(CStr nm) noexcept;
441-
XML_Reader(const string& nm) noexcept;
447+
explicit XML_Reader(CStr nm) noexcept;
448+
explicit XML_Reader(const string& nm) noexcept;
442449

443450
virtual ~XML_Reader();
444451

@@ -463,9 +470,6 @@ class XML_Reader : public MMapReader
463470

464471
bool addIncludeGuards(LineReader& lr) noexcept;
465472

466-
inline bool c_is_digit(char c) noexcept { return uint32_t(c) - '0' < 10u; }
467-
inline bool c_is_dot_digit(char c) noexcept { return uint32_t(c) - '0' < 10u or c == '.'; }
468-
469473
inline bool has_digit(CStr z) noexcept {
470474
if (!z || !z[0]) return false;
471475

planning/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const char* _pln_VERSION_STR = "pln0367";
1+
static const char* _pln_VERSION_STR = "pln0368";
22

33
#include "RS/rsEnv.h"
44
#include "RS/rsDeal.h"

planning/src/util/geo/iv.h

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@
33
#ifndef _PLN_util_geo_IV_h_b6e76e5fa705cfb_
44
#define _PLN_util_geo_IV_h_b6e76e5fa705cfb_
55

6-
#include <algorithm>
7-
#include <cassert>
8-
#include <cctype>
9-
#include <cfloat>
10-
#include <climits>
11-
#include <cmath>
12-
#include <cstdint>
13-
#include <cstdio>
14-
#include <cstdlib>
15-
#include <cstring>
16-
#include <iomanip>
17-
#include <iostream>
18-
#include <limits>
19-
#include <memory>
20-
#include <numeric>
21-
#include <string>
22-
#include <string_view>
23-
#include <type_traits>
24-
#include <utility>
25-
#include <vector>
26-
276
#include "util/pln_log.h"
287

298
namespace pln {
@@ -102,6 +81,7 @@ struct Iv {
10281

10382
Iv() noexcept = default;
10483
Iv(int a, int b) noexcept : a_(a), b_(b) {}
84+
explicit Iv(ipair p) noexcept : a_(p.first), b_(p.second) {}
10585

10686
void set(Iv i) noexcept { *this = i; }
10787
void set(int a, int b) noexcept {
@@ -147,11 +127,18 @@ struct Iv {
147127
a_ = t;
148128
b_ = t + l;
149129
}
150-
void moveRel(int dt) noexcept {
130+
void translate(int dt) noexcept {
151131
assert(valid() and normal());
152132
a_ += dt;
153133
b_ += dt;
154134
}
135+
Iv translated(int dt) const noexcept {
136+
assert(valid() and normal());
137+
Iv ret(*this);
138+
ret.a_ += dt;
139+
ret.b_ += dt;
140+
return ret;
141+
}
155142

156143
inline void unite(Iv i) noexcept;
157144
inline void unite(int t) noexcept;

0 commit comments

Comments
 (0)