8000 CLI and feedback enhancements by stevebroshar · Pull Request #461 · nxp-imx/mfgtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CLI and feedback enhancements #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 91 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
ecae36e
CLI and feedback enhancements
Feb 19, 2025
8be2c0c
refactoring
Feb 21, 2025
76b3658
Enhance script classes
Feb 22, 2025
5dfe40d
simplify script
Feb 22, 2025
2278318
fix bugs
Feb 22, 2025
084d9c6
organize
Feb 22, 2025 8000
ca0bd59
support doxygen
Feb 22, 2025
95c50a8
code format
Feb 22, 2025
e0b6c2a
define func instead of macro
Feb 22, 2025
a177e4f
fix linux build issues
Feb 22, 2025
0d1cb02
use windows setenv func
Feb 22, 2025
7e74061
implement setenv for linux
Feb 22, 2025
1274c94
Updates for gcc
Feb 23, 2025
6a952e3
update linux code for general changes
Feb 23, 2025
a3497a3
fix compiler warnings
Feb 23, 2025
5263452
feedback
Feb 23, 2025
ac94a69
error if no operation
Feb 23, 2025
f5c13b3
protocol command help
Feb 23, 2025
5ca8c1d
disable autocomplete for windows
Feb 23, 2025
fed38ca
disable auto-complete for linux
Feb 23, 2025
f141786
comments
Feb 23, 2025
8f25328
logging
Feb 23, 2025
59b35cc
simplify CLI handling by writing app title to stderr
Feb 23, 2025
ddc5711
simplify cli parsing
Feb 23, 2025
a09392a
feedback
Feb 23, 2025
14fc152
remove 'v'
Feb 23, 2025
3814eb7
make build work even without appveryer or git tags
Feb 23, 2025
72a2d64
Comments/feedback
Feb 23, 2025
86333a1
Remove 'using std'
Feb 23, 2025
8f3c267
new cli
Mar 5, 2025
13be3fd
fix of linux
Mar 5, 2025
4b5ee62
new CLI
Mar 7, 2025
475094a
include static funcs; exclude non uuu code
Mar 8, 2025
01b4cc5
feedback
Mar 8, 2025
0ce28db
remove new line
Mar 8, 2025
5a896d8
add include to fix linux build
Mar 8, 2025
92f36e0
feedback
Mar 8, 2025
c28b210
revert changes that break linux build
Mar 8, 2025
02adbde
feedback
Mar 8, 2025
1a625af
examples
Mar 8, 2025
d204d3e
feedback
Mar 9, 2025
66ca610
data hiding
Mar 9, 2025
41b5a0f
feedback
Mar 9, 2025
b3d8e49
code cleanup
Mar 9, 2025
09ebe46
simplify
Mar 10, 2025
365245d
fix horizontal scrolling
Mar 10, 2025
07be979
comments
Mar 10, 2025
6e20cd0
feedback
Mar 10, 2025
351a7d4
code format
Mar 10, 2025
ea55180
remove blank line in status area
8000 Mar 10, 2025
ff06c06
shrink function
Mar 10, 2025
d13ff30
comments
Mar 10, 2025
768fe14
Leave curser below the status area instead of all the nonsense trying…
Mar 10, 2025
7677f1c
move horizontal_scroll_index into a class
Mar 10, 2025
79b71a9
Remove more new lines on exit; not needed
Mar 10, 2025
abf7afe
back to new CLI
Mar 10, 2025
6b96848
comments
Mar 10, 2025
f2c7665
code cleanup
Mar 10, 2025
6301a02
factor out formatter
Mar 10, 2025
e3bb107
factor out to new file
Mar 10, 2025
7c2267a
error message
Mar 10, 2025
b33cb3a
message text
Mar 10, 2025
ce842bd
comments and feedback
Mar 10, 2025
d927efd
feedback
Mar 10, 2025
cf923d2
comments
Mar 10, 2025
1873091
show waiting in a way that can cleanly be overwritten
Mar 10, 2025
93455d6
fix bug when no filter
Mar 10, 2025
e995657
cleanup
Mar 10, 2025
94dc3db
comments
Mar 10, 2025
942a688
help text
Mar 10, 2025
b37e464
comments
Mar 11, 2025
6787ab1
move main logic to cli.h
Mar 11, 2025
793d446
Merge remote-tracking branch 'nxp/master' into CLI-and-feedback-enhan…
Mar 11, 2025
6189051
fixes for last merge to nxp/master
Mar 11, 2025
366f82e
Manually apply change for commit c031b2a to new CLI
Mar 11, 2025
843ab5c
Manually apply change for commit 09fe178 to new CLI
Mar 11, 2025
f5bada6
Manually apply change for commit f764c01 to new CLI
Mar 11, 2025
5e96528
rename script arg to script param
Mar 11, 2025
5bf8d75
fix quoting of params
Mar 11, 2025
23d40e8
str should be const so change it; move new line to output; not in con…
Mar 11, 2025
36829cb
remove unused function
Mar 11, 2025
27aca3b
remove first CLI rework attempt
Mar 11, 2025
3fab0be
help text
Mar 11, 2025
d2ee494
remove unused declaration
Mar 11, 2025
647c156
help info
Mar 11, 2025
615fb62
help info
Mar 17, 2025
2a47358
Show message instead of empty table for no devices found
Mar 17, 2025
3047e6a
cleanup interactive mode feedback and code
Mar 18, 2025
7323702
help/feedback info
Mar 18, 2025
0f5c691
warn for empty input file
Apr 2, 2025
7af2439
rename/shorten command to list devices
Apr 22, 2025
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ CMakeCache.txt
*.clst
*.snap
node_modules
build
build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create sperate patch for .gitignore file

bin/
Docs/
.vscode
2,863 changes: 2,863 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

203 changes: 150 additions & 53 deletions libuuu/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,31 @@
*
*/

#include <map>
#include "buffer.h"
#include <sys/stat.h>
#include "liberror.h"
#include <iostream>
#include <fstream>

#include "libcomm.h"
#include "libuuu.h"
#include "zip.h"
#include "fat.h"
#include "tar.h"
#include <string.h>

#include "bzlib.h"
#include "stdio.h"
#include <limits>
#include "fat.h"
#include "http.h"
#include "string_man.h"
#include "tar.h"
#include "zip.h"
#include "zstd.h"

#include "libusb.h"
#include <chrono>

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>

#include <fstream>
#include <iostream>
#include <limits>
#include <map>

#ifdef WIN32
#define stat_os _stat64
#elif defined(__APPLE__)
Expand All @@ -63,10 +68,51 @@ static map<string, shared_ptr<FileBuffer>> g_filebuffer_map;
static mutex g_mutex_map;
static bool g_small_memory = true;

// [what is the point/value of this value?]
#define MAGIC_PATH '>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark avoid dead loop when search parent path


string g_current_dir = ">";

static map<string, bool> warned_empty_files;

/**
* @brief Logs a warning if the specified file is empty
* @details
* This situation (opening an empty file) is somewhat common on Windows since builds typically
* are run on Linux and such builds typically create link files which are convenient on Linux,
* but when transferred to Windows are useless empty files, and processing an empty file at least
* sometimes results in a hang at install time. This warning can be very helpful to a user
* confused by the hang.
*
* Would be nice to use the logging facility, but it's at the app level; not accessible here.
* Maybe should move the logging facility to the lib level.
*/
static void warn_if_empty_file(string filename)
{
// don't know what the > prefix means, but it's problematic here; remove it
if (filename[0] == MAGIC_PATH)
{
filename = filename.substr(1);
}

// only warn once per file since annoying to warn for the same file multiple times
if (warned_empty_files.find(filename) != warned_empty_files.end()) return;
warned_empty_files[filename] = true;

// opening here shouldn't fail since should have been tested for existence already
ifstream file(filename);
if (!file.is_open()) {
cerr << "INTERNAL ERROR: Could not open file to validate for empty: " << filename << std::endl;
return;
}

bool is_empty = file.peek() == std::ifstream::traits_type::eof();
if (is_empty)
{
cerr << "Warning: Empty input file: " << filename << "; maybe it's a link file accessed in Windows" << endl;
}
}

void set_current_dir(const string &dir)
{
g_current_dir = MAGIC_PATH;
Expand Down Expand Up @@ -128,6 +174,9 @@ int DataBuffer::ref_other_buffer(std::shared_ptr<FileBuffer> p, size_t offset, s
return 0;
};

/**
* @brie Base class for FS things [whatever 'FS' means/is].
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove [...]

class FSBasic
{
public:
Expand All @@ -143,55 +192,86 @@ class FSBasic
virtual std::shared_ptr<FragmentBlock> ScanCompressblock(const string& /*backfile*/, size_t& /*input_offset*/, size_t& /*output_offset*/) { return NULL; };
virtual int PreloadWorkThread(shared_ptr<FileBuffer>outp);

virtual int split(const string &filename, string *outbackfile, string *outfilename, bool dir=false)
{
string path = str_to_upper(filename);
/**
* @brief Splits a file system path into directory and final name parts
* @param path Input path
* @param[out] dir_part Directory path info from input path
* @param[out] name_part Final name part from input path
* @param dir [what does this mean/imply?]
* @return 0 for success; -1 for error
* @details
* If no/blank m_ext:
* If dir:
* Load dir_part with directory path part of path; >./ if none
* Load name_part with file name part of path; blank if none
* Else:
* Load dir_part with input path
* Else:
* ext = m_ext
* Append slash to ext if !dir
* Find last ext in path
* If not found: fail
* Load dir_part with path up to and including ext
* Load name_part with path after found ext
* @example
* path:"f", m_ext:"", !dir ==> ">./", "f"
* path:"d/f", m_ext:"", !dir ==> "d", "f"
* path:"d/", m_ext:"", !dir ==> "d", ""
* path:"f", m_ext:"z", !dir ==> error
* path:"d/z/f", m_ext:"z", !dir ==> "d/z", "f"
* path:"d/z/", m_ext:"z", !dir ==> "d/z", ""
* @note
* Passing a bool like dir is bad style since it only controls flow.
*/
virtual int split(const string &path, string *dir_part, string *name_part, bool dir=false)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use seperate patch to change outbackfile-> dir_part, outfilename -> filename_part

string upper_path = str_to_upper(path);
if (m_ext == nullptr || strlen(m_ext) == 0)
{
if(dir)
{
size_t pos = path.rfind("/");
size_t pos = upper_path.rfind("/");
if(pos == string::npos)
{
*outbackfile = MAGIC_PATH;
*outbackfile += "./";
*outfilename = filename;
*dir_part = MAGIC_PATH;
*dir_part += "./";
*name_part = path;
} else {
*outbackfile = filename.substr(0, pos);
if(filename.size() >= pos + 1)
*outfilename = filename.substr(pos + 1);
*dir_part = path.substr(0, pos);
if(path.size() >= pos + 1)
*name_part = path.substr(pos + 1);
else
outfilename->clear();
name_part->clear();
}
}else
{
*outbackfile = filename;
*dir_part = path;
}
return 0;
}

string ext = m_ext;
if(!dir)
ext += "/";
size_t pos = path.rfind(ext);
size_t pos = upper_path.rfind(ext);
if (pos == string::npos)
{
string err = "can't find ext name in path: ";
err += filename;
string err = "Expected '" + ext + "' in path '" + path + "'";
set_last_err_string(err);
return -1;
}

*outbackfile = filename.substr(0, pos + strlen(m_ext));
*dir_part = path.substr(0, pos + strlen(m_ext));

if(filename.size() >= pos + strlen(m_ext) + 1)
*outfilename = filename.substr(pos + strlen(m_ext) + 1);
if(path.size() >= pos + strlen(m_ext) + 1)
*name_part = path.substr(pos + strlen(m_ext) + 1);
else
outfilename->clear();
name_part->clear();
return 0;
}

protected:
FSBasic() {} // enforce that this class is abstract base; only creatable via a superclass
const char * m_ext = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be sperate patch

const char * m_Prefix = nullptr;
public:
Expand Down Expand Up @@ -718,20 +798,16 @@ static class FS_DATA
}
int load(const string &filename, shared_ptr<FileBuffer> p)
{
for (size_t i = 0; i < m_pFs.size(); i++)
for (auto& fs : m_pFs)
{
string back, fn;
if (m_pFs[i]->split(filename, &back, &fn) == 0) {
if (m_pFs[i]->load(back, fn, p) == 0)
if (fs->split(filename, &back, &fn) == 0) {
if (fs->load(back, fn, p) == 0)
return 0;
}
}

string err;
err = "fail open file: ";
err += filename;
set_last_err_string(err);
return -1;
return set_last_err_string("Unable to open file: " + filename);
}
}g_fs_data;

Expand Down Expand Up @@ -914,7 +990,10 @@ bool FSCompressStream::exist(const string &backfile, const string &filename)
return false;

if (filename == "*")
{
warn_if_empty_file(backfile);
return true;
}

return false;
}
Expand Down Expand Up @@ -1175,32 +1254,35 @@ uint64_t get_file_timesample(string filename)
return time;
}

/**
* [what does this do?]
* @param filename File system path
* @param async TBD
* @details
* As a side-effect, this conforms filename by stripping quotes and if doesn't start with
* MAGIC_PATH prepending g_current_dir and then replacing backslashes with forward.
* @note
* The side-effect should be eliminated since it adds to cognative load.
*/
shared_ptr<FileBuffer> get 3D11 _file_buffer(string filename, bool async)
{
filename = remove_quota(filename);

filename = strip_quotes(filename);
if (!filename.empty() && filename[0] != MAGIC_PATH)
{
if (filename == "..")
filename = g_current_dir.substr(0, g_current_dir.size() - 1);
else
filename = g_current_dir + filename;
}
string_man::replace(filename, "\\", "/");

string_ex path;
path += filename;

path.replace('\\', '/');

filename = path;

bool find;
bool found;
{
std::lock_guard<mutex> lock(g_mutex_map);
find = (g_filebuffer_map.find(filename) == g_filebuffer_map.end());
found = (g_filebuffer_map.find(filename) == g_filebuffer_map.end());
}

if (find)
if (found)
{
shared_ptr<FileBuffer> p(new FileBuffer);

Expand Down Expand Up @@ -1383,6 +1465,9 @@ int FileBuffer::ref_other_buffer(shared_ptr<FileBuffer> p, size_t offset, size_t
return 0;
}

/**
* [what does this do?]
*/
int FileBuffer::reload(string filename, bool async)
{
if(async) {
Expand Down Expand Up @@ -1803,10 +1888,16 @@ int FileBuffer::unmapfile()
return 0;
}

bool check_file_exist(string filename, bool /*start_async_load*/)
bool path_exists(const string& path)
{
struct stat_os st;
return stat_os(path.c_str(), &st) == 0;
}

int verify_file_exist(string filename)
{
string_ex fn;
fn += remove_quota(filename);
fn += strip_quotes(filename);
string_ex path;
if (!fn.empty() && fn[0] != MAGIC_PATH)
{
Expand All @@ -1823,7 +1914,13 @@ bool check_file_exist(string filename, bool /*start_async_load*/)

if (path.empty())
path += "./";
return g_fs_data.exist(path);

bool exists = g_fs_data.exist(path);
if (!exists)
{
return set_last_err_string("File not found: " + filename);
}
return 0;
}

#ifdef WIN32
Expand Down
3 changes: 2 additions & 1 deletion libuuu/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ class FileBuffer: public std::enable_shared_from_this<FileBuffer>
};

std::shared_ptr<FileBuffer> get_file_buffer(std::string filename, bool async=false);
bool check_file_exist(std::string filename, bool start_async_load=true);
int verify_file_exist(std::string filename);
bool path_exists(const std::string& path);

void set_current_dir(const std::string &dir);

Expand Down
Loading
0