pmt: initial 2.7.0 update
This commit is contained in:
53
jni/Makefile
53
jni/Makefile
@@ -31,7 +31,7 @@ PMT_INCDIR := $(INCLUDE_DIR)/pmt
|
||||
|
||||
# the presence of all source files that are on this list will be checked
|
||||
SRCS_REQ := \
|
||||
place-holder/debugging.c \
|
||||
place-holder/debug.c \
|
||||
place-holder/help.c \
|
||||
place-holder/get_stat.c \
|
||||
place-holder/lang_tools.c \
|
||||
@@ -40,34 +40,38 @@ SRCS_REQ := \
|
||||
place-holder/pmt.c \
|
||||
place-holder/root.c \
|
||||
place-holder/tools.c \
|
||||
place-holder/versioning.c
|
||||
place-holder/version.c
|
||||
|
||||
# objects to be used when executable file is created
|
||||
OBJS_EXEC := \
|
||||
$(SOURCE_DIR)/$(TARGET).o \
|
||||
$(SOURCE_DIR)/help.o \
|
||||
$(SOURCE_DIR)/versioning.o \
|
||||
$(SOURCE_DIR)/version.o \
|
||||
$(SOURCE_DIR)/get_stat.o \
|
||||
$(SOURCE_DIR)/tools.o \
|
||||
$(SOURCE_DIR)/lang_tools.o \
|
||||
$(SOURCE_DIR)/languages.o
|
||||
|
||||
HEADERS_REQ := \
|
||||
$(PMT_INCDIR)/pmt/deprecates.h \
|
||||
$(PMT_INCDIR)/pmt/help_msgs.h \
|
||||
$(PMT_INCDIR)/pmt/pmt.h \
|
||||
$(PMT_INCDIR)/pmt/stringkeys.h \
|
||||
$(PMT_INCDIR)/pmt/versioning.h
|
||||
$(PMT_INCDIR)/pmt/ExternC.h \
|
||||
$(PMT_INCDIR)/pmt/Deprecates.h \
|
||||
$(PMT_INCDIR)/pmt/HelpMessages.h \
|
||||
$(PMT_INCDIR)/pmt/PartitionManager.h \
|
||||
$(PMT_INCDIR)/pmt/StringKeys.h \
|
||||
$(PMT_INCDIR)/pmt/VersionVars.h
|
||||
|
||||
PROGRESS_LIST := \
|
||||
welcome \
|
||||
wait \
|
||||
$(SRCS_REQ) \
|
||||
$(HEADERS_REQ) \
|
||||
pr_obj \
|
||||
$(OBJS) \
|
||||
make_outdirs \
|
||||
pr_sts \
|
||||
$(STATIC_LIBS) \
|
||||
make_executable \
|
||||
wait \
|
||||
end_progress
|
||||
|
||||
define check_hf
|
||||
@@ -88,17 +92,22 @@ welcome:
|
||||
&& $(E_NS)
|
||||
$(E) " -------------------------------- " \
|
||||
&& $(E_NS)
|
||||
@ if [ -f $(SOURCE_DIR)/debugging.o ]; then \
|
||||
@ if [ -f $(SOURCE_DIR)/debug.o ]; then \
|
||||
$(E_NS) " - Please clean up before you build it." && echo; \
|
||||
$(E_NS) " ----------------------------------- "; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(E) " - Checking required source files..."
|
||||
@ sleep 1
|
||||
|
||||
pr_obj:
|
||||
$(E) " - Building objects..."
|
||||
|
||||
pr_sts:
|
||||
$(E) " - Making static libraries..."
|
||||
|
||||
wait:
|
||||
@ sleep 2
|
||||
|
||||
make_outdirs:
|
||||
@ rm -rf $(IN_OUT_DIR)
|
||||
@ mkdir $(BINARY_DIR)
|
||||
@@ -122,31 +131,15 @@ $(PMT_INCDIR)/%.h:
|
||||
$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
|
||||
$(E) " CC $(SOURCE_DIRNAME)/`basename $@`"
|
||||
@ $(CC) $(CFLAGS) -c "$<" || exit 1
|
||||
$(eval GEN_OBJS_MSG = )
|
||||
|
||||
lib$(TARGET)_root.a:
|
||||
$(E) " - Making static libraries..."
|
||||
$(E) " AR $@"
|
||||
@ $(AR) rcs "$@" "$(SOURCE_DIR)/root.o" || exit 1
|
||||
|
||||
lib$(TARGET)_debugging.a:
|
||||
$(E) " AR $@"
|
||||
@ $(AR) rcs "$@" "$(SOURCE_DIR)/debugging.o"
|
||||
|
||||
lib$(TARGET)_listpart.a:
|
||||
$(E) " AR $@"
|
||||
@ $(AR) rcs "$@" "$(SOURCE_DIR)/listpart.o"
|
||||
|
||||
lib$(TARGET)_partitiontool.a:
|
||||
$(E) " AR $@"
|
||||
@ $(AR) rcs "$@" "$(SOURCE_DIR)/partitiontool.o"
|
||||
@ sleep 1
|
||||
$(TARGET)_%:
|
||||
$(E) " AR lib$@.a"
|
||||
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/$$(echo "$@" | cut -d'_' -f2).o"
|
||||
|
||||
make_executable:
|
||||
$(E) " - Making executable file..."
|
||||
$(E) " LD $(TARGET)"
|
||||
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) -l$(TARGET)_root -l$(TARGET)_debugging -l$(TARGET)_listpart -l$(TARGET)_partitiontool -o $(TARGET) $(OBJS_EXEC) || exit 1
|
||||
@ sleep 1
|
||||
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1
|
||||
|
||||
end_progress:
|
||||
@ abort_build() { \
|
||||
|
||||
@@ -22,8 +22,8 @@ extern "C" {
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
|
||||
void debug(LogLevel status, const char* _Nullable fmt, ...)
|
||||
{
|
||||
@@ -23,8 +23,8 @@ extern "C" {
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_STAT
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
|
||||
/**
|
||||
* The target file is controlled by the stat function.
|
||||
|
||||
@@ -23,9 +23,9 @@ extern "C" {
|
||||
#define INC_MAIN_LIBS
|
||||
#define HELP
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/help_msgs.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
#include <pmt/HelpMessages.h>
|
||||
|
||||
extern char* bin_name;
|
||||
extern char* curr_lang;
|
||||
|
||||
@@ -24,8 +24,8 @@ extern "C" {
|
||||
#define INC_DEBUGERS
|
||||
#define INC_STAT
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
|
||||
/* pmt's man doc file path on termux */
|
||||
#define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz"
|
||||
|
||||
@@ -22,8 +22,8 @@ extern "C" {
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
|
||||
struct pmt_langdb_general en = {
|
||||
.lang_by_s = "YZBruh & r0manas",
|
||||
|
||||
@@ -24,7 +24,7 @@ extern "C" {
|
||||
#define INC_DEBUGERS
|
||||
#define INC_DIRENT
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
|
||||
/* current /dev context */
|
||||
|
||||
@@ -22,7 +22,7 @@ extern "C" {
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
|
||||
static int
|
||||
accf(const char* _Nonnull target) { return access(target, F_OK); }
|
||||
|
||||
93
jni/pmt.c
93
jni/pmt.c
@@ -26,10 +26,10 @@ extern "C" {
|
||||
#define INC_STAT
|
||||
#define INC_GETOPT
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/deprecates.h>
|
||||
#include <pmt/help_msgs.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
#include <pmt/Deprecates.h>
|
||||
#include <pmt/HelpMessages.h>
|
||||
|
||||
#define opt_symbol "-"
|
||||
|
||||
@@ -55,21 +55,6 @@ bool pmt_inst_on_termux = false;
|
||||
/* variable for use in control of '-' expression */
|
||||
static char common_symbol_rule[350];
|
||||
|
||||
#if !defined(__clang__)
|
||||
|
||||
static char*
|
||||
strdup(const char* s)
|
||||
{
|
||||
size_t len = strlen(s) + 1;
|
||||
char* copy = malloc(len);
|
||||
if (copy) {
|
||||
memcpy(copy, s, len);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* He controls whether the '-' sign at
|
||||
* the beginning of the given word
|
||||
@@ -94,10 +79,32 @@ ctrl_arg(const char* _Nullable argv_holder)
|
||||
}
|
||||
|
||||
/* classic main function (C binary here xd) */
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
bin_name = argv[0];
|
||||
|
||||
int argc_n = argc;
|
||||
char buf[256];
|
||||
char** args = malloc((argc + 1) * sizeof(char *));
|
||||
|
||||
/* copy original arguments */
|
||||
for (int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
|
||||
if (!isatty(fileno(stdin)))
|
||||
{
|
||||
while (fgets(buf, sizeof(buf), stdin) != NULL)
|
||||
{
|
||||
buf[strcspn(buf, "\n")] = 0;
|
||||
|
||||
args = realloc(args, (argc_n + 1) * sizeof(char *));
|
||||
args[argc_n] = strdup(buf);
|
||||
argc_n++;
|
||||
}
|
||||
}
|
||||
|
||||
argc = argc_n;
|
||||
|
||||
/* load language */
|
||||
if (loadlang() != 0)
|
||||
{
|
||||
@@ -117,7 +124,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
/* check argument total */
|
||||
if (argc < 2)
|
||||
LOGE("%s.\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, argv[0], current->for_more);
|
||||
LOGE("%s.\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, args[0], current->for_more);
|
||||
|
||||
/* a structure for long arguments */
|
||||
struct option option_table[] = {
|
||||
@@ -148,27 +155,27 @@ int main(int argc, char* argv[])
|
||||
static int search_result = 3;
|
||||
static int opt;
|
||||
|
||||
if (strcmp(argv[1], "backup") == 0)
|
||||
if (strcmp(args[1], "backup") == 0)
|
||||
{
|
||||
if (argc <= 2)
|
||||
LOGE("%s 0.\n", current->expected_backup_arg);
|
||||
|
||||
if (ctrl_arg(argv[2]))
|
||||
target_partition = argv[2];
|
||||
if (ctrl_arg(args[2]))
|
||||
target_partition = args[2];
|
||||
else
|
||||
LOGE("%s.\n", current->not_spec_opt);
|
||||
|
||||
out = target_partition;
|
||||
|
||||
if (argc > 3 && ctrl_arg(argv[3]))
|
||||
out = argv[3];
|
||||
if (argc > 3 && ctrl_arg(args[3]))
|
||||
out = args[3];
|
||||
|
||||
check_optsym(target_partition);
|
||||
check_optsym(out);
|
||||
|
||||
pmt_backup = true;
|
||||
}
|
||||
else if (strcmp(argv[1], "flash") == 0)
|
||||
else if (strcmp(args[1], "flash") == 0)
|
||||
{
|
||||
if (argc <= 2)
|
||||
LOGE("%s 0.\n", current->expected_flash_arg);
|
||||
@@ -176,13 +183,13 @@ int main(int argc, char* argv[])
|
||||
if (argc <= 3)
|
||||
LOGE("%s 1.\n", current->expected_flash_arg);
|
||||
|
||||
if (ctrl_arg(argv[2]))
|
||||
target_partition = argv[2];
|
||||
if (ctrl_arg(args[2]))
|
||||
target_partition = args[2];
|
||||
else
|
||||
LOGE("%s.\n", current->not_spec_opt);
|
||||
|
||||
if (ctrl_arg(argv[3]))
|
||||
target_flash_file = argv[3];
|
||||
if (ctrl_arg(args[3]))
|
||||
target_flash_file = args[3];
|
||||
else
|
||||
LOGE("%s.\n", current->not_spec_opt);
|
||||
|
||||
@@ -191,7 +198,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
pmt_flash = true;
|
||||
}
|
||||
else if (strcmp(argv[1], "format") == 0)
|
||||
else if (strcmp(args[1], "format") == 0)
|
||||
{
|
||||
|
||||
if (argc <= 2)
|
||||
@@ -200,13 +207,13 @@ int main(int argc, char* argv[])
|
||||
if (argc <= 3)
|
||||
LOGE("%s 1.\n", current->expected_format_arg);
|
||||
|
||||
if (ctrl_arg(argv[2]))
|
||||
target_partition = argv[2];
|
||||
if (ctrl_arg(args[2]))
|
||||
target_partition = args[2];
|
||||
else
|
||||
LOGE("%s.\n", current->not_spec_opt);
|
||||
|
||||
if (ctrl_arg(argv[3]))
|
||||
format_fs = argv[3];
|
||||
if (ctrl_arg(args[3]))
|
||||
format_fs = args[3];
|
||||
else
|
||||
LOGE("%s.\n", current->not_spec_opt);
|
||||
|
||||
@@ -217,7 +224,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
/* control for each argument */
|
||||
while ((opt = getopt_long(argc, argv, "bFrDlc:psfS:vL", option_table, NULL)) != -1)
|
||||
while ((opt = getopt_long(argc, args, "bFrDlc:psfS:vL", option_table, NULL)) != -1)
|
||||
{
|
||||
/* process arguments */
|
||||
switch (opt)
|
||||
@@ -286,11 +293,11 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
/* for invalid options */
|
||||
case '?':
|
||||
LOGD("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more);
|
||||
LOGD("%s `%s --help' %s\n", current->try_h, args[0], current->for_more);
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-s | --silent] [-v | --version] [--help]\n", current->usage_head, argv[0]);
|
||||
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-s | --silent] [-v | --version] [--help]\n", current->usage_head, args[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -318,15 +325,15 @@ int main(int argc, char* argv[])
|
||||
|
||||
if (pmt_setlang)
|
||||
{
|
||||
LOGD("%s: %s\n", argv[0], current->switching_lang);
|
||||
LOGD("%s: %s\n", args[0], current->switching_lang);
|
||||
setlang(langpr, 0);
|
||||
sleep(2);
|
||||
LOGD("%s: %s.\n", argv[0], current->please_rerun);
|
||||
LOGD("%s: %s.\n", args[0], current->please_rerun);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!pmt_backup && !pmt_flash && !pmt_format)
|
||||
LOGE("%s.\n%s `%s --help` %s\n", current->no_target, current->try_h, argv[0], current->for_more);
|
||||
LOGE("%s.\n%s `%s --help` %s\n", current->no_target, current->try_h, args[0], current->for_more);
|
||||
|
||||
if (pmt_format)
|
||||
{
|
||||
@@ -373,7 +380,7 @@ int main(int argc, char* argv[])
|
||||
if (target_partition == NULL)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, argv[0], current->for_more);
|
||||
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, args[0], current->for_more);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,8 +23,8 @@ extern "C" {
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_DEBUGERS
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
|
||||
/* root checker function */
|
||||
void check_root(void)
|
||||
|
||||
@@ -26,8 +26,8 @@ extern "C" {
|
||||
#define INC_DEBUGERS
|
||||
#define INC_TOOLS_REQS
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
|
||||
#define count (1024 * 1024 * 1024)
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ extern "C" {
|
||||
#define INC_MAIN_LIBS
|
||||
#define VERSIONING
|
||||
|
||||
#include <pmt/pmt.h>
|
||||
#include <pmt/stringkeys.h>
|
||||
#include <pmt/versioning.h>
|
||||
#include <pmt/PartitionManager.h>
|
||||
#include <pmt/StringKeys.h>
|
||||
#include <pmt/VersionVars.h>
|
||||
|
||||
void version(void)
|
||||
{
|
||||
Reference in New Issue
Block a user