Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions planning/src/RS/rsOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ static bool input_file_exists(CStr fn) noexcept {
return sz > 1; // require non-empty file
}

static inline bool ends_with_dot_cmd(CStr z, size_t len) noexcept {
assert(z);
if (len < 5) return false;
return z[len - 1] == 'd' and z[len - 2] == 'm' and z[len - 3] == 'c' and z[len - 4] == '.';
// .cmd
// dmc.
}

static inline bool ends_with_dot_tcl(CStr z, size_t len) noexcept {
assert(z);
if (len < 5) return false;
return z[len - 1] == 'l' and z[len - 2] == 'c' and z[len - 3] == 't' and z[len - 4] == '.';
// .tcl
// lct.
}

static bool op_match(CStr op, CStr* aliases) noexcept {
assert(op and aliases);
if (!op || !aliases) return false;
Expand Down Expand Up @@ -324,6 +340,23 @@ bool rsOpts::is_implicit_check() const noexcept {
return true;
}

bool rsOpts::isTclInput() const noexcept {
assert(argv_);
assert(argv_[0]);
assert(argc_ > 0);
if (!argv_ or !argv_[0])
return false;
if (argc_ > 5 or assignOrder_)
return false;

if (!input_ || !input_[0]) return false;
size_t len = ::strlen(input_);
if (len < 5 || len > UNIX_Path_Max) return false;
if (!ends_with_dot_tcl(input_, len)) return false;

return input_file_exists(input_);
}

void rsOpts::parse(int argc, const char** argv) noexcept {
using namespace ::pln::alias;

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

static inline bool ends_with_dot_cmd(CStr z, size_t len) noexcept {
assert(z);
if (len < 5) return false;
return z[len - 1] == 'd' and z[len - 2] == 'm' and z[len - 3] == 'c' and z[len - 4] == '.';
// .cmd
// dmc.
}

bool rsOpts::isCmdInput() const noexcept {
if (!input_ || !input_[0]) return false;
size_t len = ::strlen(input_);
Expand Down
1 change: 1 addition & 0 deletions planning/src/RS/rsOpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct rsOpts {
bool hasInputFile() const noexcept;
bool hasCsvFile() const noexcept;
bool isCmdInput() const noexcept;
bool isTclInput() const noexcept;

private:
bool set_VPR_TC_args(CStr raw_tc) noexcept;
Expand Down
82 changes: 64 additions & 18 deletions planning/src/file_io/pln_Fio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ void Info::init() noexcept {
}
}

void Info::inval() noexcept {
absName_.clear();
type_.clear();
size_ = 0;
exists_ = false;
accessible_ = false;
absolute_ = false;
numLines_ = -1;
numWords_ = -1;
maxLlen_ = -1;
numTextChars_ = -1;
}

string Info::get_abs_name(const string& nm) noexcept {
namespace fs = std::filesystem;
if (nm.empty()) return {};
Expand Down Expand Up @@ -549,14 +562,20 @@ int64_t MMapReader::countWC(int64_t& numWords) const noexcept {
}

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

int64_t numLines, numWords = 0;
numLines = countWC(numWords);

os << numLines << ' ' << numWords << ' ' << sz_ << ' ' << fnm_ << endl;
if (infRet) {
infRet->numLines_ = numLines;
infRet->numWords_ = numWords;
}

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

bool MMapReader::is_text_file(string& label) const noexcept {
label.clear();
bool MMapReader::is_text_file(Info& typeRet, bool scan) const noexcept {
typeRet.inval();
typeRet.size_ = sz_;
if (!buf_ or sz_ < 4)
return false;

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

if (sig == 0x464c457f) {
label = "ELF";
typeRet.type_ = "ELF";
return false;
}
if (sig == 0x21726152) {
label = "RAR";
typeRet.type_ = "RAR";
return false;
}
if (sig == 0x587a37fd) {
label = "XZ";
typeRet.type_ = "XZ";
return false;
}
if (sig == 0xfd2fb528) {
label = "ZST";
typeRet.type_ = "ZST";
return false;
}
if (sig == 0x425a6839) {
label = "BZ2";
typeRet.type_ = "BZ2";
return false;
}
if (sig == 0x1f8b0808) {
label = "GZ";
typeRet.type_ = "GZ";
return false;
}
if (sig == 0x46445025) {
label = "PDF";
typeRet.type_ = "PDF";
return false;
}
if (sig == 0x213c6172) {
label = "AR";
typeRet.type_ = "AR";
return false;
}

return true;
size_t numLines = 0, numText = 0;
if (scan) {
for (size_t i = 0; i < sz_; i++) {
char c = buf_[i];
if (!c) {
numText++;
continue;
}
if (c == '\n') {
numLines++;
numText++;
continue;
}
numText += int(str::c_is_text(c));
}
}
else {
return true;
}

if (sz_ - numText < 3) {
typeRet.type_ = "TXT";
return true;
}

typeRet.type_ = "BIN";
return false;
}

bool MMapReader::printMagic(std::ostream& os) const noexcept {
Expand Down Expand Up @@ -645,12 +691,12 @@ bool MMapReader::printMagic(std::ostream& os) const noexcept {
if (i > 8)
break;
}
string label;
bool is_txt = is_text_file(label);
Info inf;
bool is_txt = is_text_file(inf, true);
if (is_txt) {
os << "(guessed TEXT)" << endl;
} else if (!label.empty()) {
os << "(guessed BINARY) : " << label << endl;
} else if (!inf.type_.empty()) {
os << "(guessed BINARY) : " << inf.type_ << endl;
}
os.flush();
return true;
Expand All @@ -668,8 +714,8 @@ bool MMapReader::isGoodForParsing() const noexcept {
return false;

if (sz_ < UINT_MAX) {
string label;
bool is_txt = is_text_file(label);
Info inf;
bool is_txt = is_text_file(inf);
return is_txt;
}

Expand Down
36 changes: 20 additions & 16 deletions planning/src/file_io/pln_Fio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,24 @@ inline char* p_strdup(CStr p) noexcept {

struct Info {
string name_, absName_;
string type_;
size_t size_ = 0;
int64_t numLines_ = 0;
int64_t numWords_ = 0;
int64_t maxLlen_ = 0;
int64_t numTextChars_ = 0;

bool exists_ = false;
bool accessible_ = false;
bool absolute_ = false;

public:
Info() noexcept = default;
explicit Info(CStr nm) noexcept;
explicit Info(const string& nm) noexcept;

Info(CStr nm) noexcept;
Info(const string& nm) noexcept;
void init() noexcept;
void inval() noexcept;

static string get_abs_name(const string& nm) noexcept;
static string get_realpath(const string& nm) noexcept;
Expand Down Expand Up @@ -215,9 +222,9 @@ class MMapReader : public Fio
public:
MMapReader() noexcept = default;

MMapReader(CStr nm) noexcept : Fio(nm) {}
explicit MMapReader(CStr nm) noexcept : Fio(nm) {}

MMapReader(const string& nm) noexcept : Fio(nm) {}
explicit MMapReader(const string& nm) noexcept : Fio(nm) {}

virtual ~MMapReader();

Expand All @@ -242,7 +249,7 @@ class MMapReader : public Fio
}

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

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

private:
bool is_text_file(string& label) const noexcept;
bool is_text_file(Info& typeRet, bool scan = false) const noexcept;

private:
vector<char*> get_backslashed_block(size_t fromLine) noexcept;

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

public:
LineReader(size_t iniCap = 0) noexcept;
LineReader(CStr nm, size_t iniCap = 0) noexcept;
LineReader(const string& nm, size_t iniCap = 0) noexcept;
explicit LineReader(size_t iniCap = 0) noexcept;
explicit LineReader(CStr nm, size_t iniCap = 0) noexcept;
explicit LineReader(const string& nm, size_t iniCap = 0) noexcept;

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

Expand Down Expand Up @@ -349,7 +356,7 @@ class CSV_Reader : public MMapReader

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

CSV_Reader(const string& nm) noexcept : MMapReader(nm) {}
explicit CSV_Reader(const string& nm) noexcept : MMapReader(nm) {}

virtual ~CSV_Reader();

Expand Down Expand Up @@ -437,8 +444,8 @@ class XML_Reader : public MMapReader

public:
XML_Reader() noexcept;
XML_Reader(CStr nm) noexcept;
XML_Reader(const string& nm) noexcept;
explicit XML_Reader(CStr nm) noexcept;
explicit XML_Reader(const string& nm) noexcept;

virtual ~XML_Reader();

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

bool addIncludeGuards(LineReader& lr) noexcept;

inline bool c_is_digit(char c) noexcept { return uint32_t(c) - '0' < 10u; }
inline bool c_is_dot_digit(char c) noexcept { return uint32_t(c) - '0' < 10u or c == '.'; }

inline bool has_digit(CStr z) noexcept {
if (!z || !z[0]) return false;

Expand Down
2 changes: 1 addition & 1 deletion planning/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const char* _pln_VERSION_STR = "pln0367";
static const char* _pln_VERSION_STR = "pln0368";

#include "RS/rsEnv.h"
#include "RS/rsDeal.h"
Expand Down
31 changes: 9 additions & 22 deletions planning/src/util/geo/iv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@
#ifndef _PLN_util_geo_IV_h_b6e76e5fa705cfb_
#define _PLN_util_geo_IV_h_b6e76e5fa705cfb_

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>

#include "util/pln_log.h"

namespace pln {
Expand Down Expand Up @@ -102,6 +81,7 @@ struct Iv {

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

void set(Iv i) noexcept { *this = i; }
void set(int a, int b) noexcept {
Expand Down Expand Up @@ -147,11 +127,18 @@ struct Iv {
a_ = t;
b_ = t + l;
}
void moveRel(int dt) noexcept {
void translate(int dt) noexcept {
assert(valid() and normal());
a_ += dt;
b_ += dt;
}
Iv translated(int dt) const noexcept {
assert(valid() and normal());
Iv ret(*this);
ret.a_ += dt;
ret.b_ += dt;
return ret;
}

inline void unite(Iv i) noexcept;
inline void unite(int t) noexcept;
Expand Down
Loading
Loading