pmt: initial 2.7.0 update

This commit is contained in:
2024-08-02 17:44:31 +03:00
parent ed745369fa
commit 5d51e44a2c
31 changed files with 223 additions and 191 deletions

View File

@@ -15,8 +15,8 @@
# limitations under the License.
# speficy
VERSION := 2.6.0
VERSION_CODE := 260
VERSION := 2.7.0
VERSION_CODE := 270
TARGET := pmt
# device arch info
@@ -83,10 +83,10 @@ SRCS := $(wildcard $(SOURCE_DIR)/*.c)
OBJS = $(SRCS:.c=.o)
STATIC_LIBS := \
lib$(TARGET)_root.a \
lib$(TARGET)_debugging.a \
lib$(TARGET)_listpart.a \
lib$(TARGET)_partitiontool.a
$(TARGET)_root \
$(TARGET)_debug \
$(TARGET)_listpart \
$(TARGET)_partitiontool
# other directories in the out directory
IN_OUT_DIR := \

View File

@@ -1,6 +0,0 @@
NDK_PROG=false
FORCE_GEN=false
THIS_IS=main
UPDATE_MAKEFILES=false
SOURCE_DIRNAME=src
OUT_DIRNAME=out

View File

@@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
[ ! "${THIS_IS}" = "main" ] \
&& abort "The caller is not the main makefile. Something's wrong."
try_with="Try with force mode (FORCE_GEN=true)."
@@ -24,7 +25,7 @@ else
mfiles=("${OUT_DIR}/Makefile" "${SOURCE_DIR}/Makefile")
fi
for mfile in ${mfiles[0]} ${mfiles[1]}; do
for mfile in ${mfiles[@]}; do
[ -f "${mfile}" ] && \
if [ "${FORCE_GEN}" = "true" ]; then

View File

@@ -17,25 +17,27 @@
. build/bash/vars
. build/bash/functions
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
[ ! "${THIS_IS}" = "main" ] \
&& abort "The caller is not the main makefile. Something's wrong."
if [ "${NDK_PROG}" = "true" ]; then
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Android.mk..."
rm -f ${SOURCE_DIR}/Android.mk
[ "${UPDATE_MAKEFILES}" = "true" ] \
|| print " - Removing Android.mk..." \
&& print " - Removing Application.mk..."
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Application.mk..."
rm -f ${SOURCE_DIR}/Application.mk
rm -f ${SOURCE_DIR}/Application.mk \
${SOURCE_DIR}/Android.mk
else
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Info: Main makefile won't be deleted."
[ "${UPDATE_MAKEFILES}" = "true" ] \
|| print " - Info: Main makefile won't be deleted." \
&& print " - Removing output directory makefile..." \
&& print " - Removing source directory makefile..."
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing output directory makefile..."
rm -f ${OUT_DIR}/Makefile
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing source directory makefile"
rm -f ${SOURCE_DIR}/Makefile
rm -f ${SOURCE_DIR}/Makefile \
${OUT_DIR}/Makefile
fi

View File

@@ -16,22 +16,22 @@
function abort()
{
[ -n "$1" ] && echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} $1"
[ -n "${1}" ] \
&& echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} ${1}"
exit 1
}
function read_file()
{
cat "$1" >> "$2" || abort "failed to read/write $1/$2"
cat "${1}" >> "${2}" \
|| abort "failed to read/write ${1}/${2}"
}
function gen()
{
[ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] && rm -f "$1"
touch "$1" || abort "failed to generate: $1"
[ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] \
&& rm -f "${1}"
touch "${1}" || abort "failed to generate: ${1}"
}
function print()
{
echo -e "$1"
}
function print() { echo -e "${1}"; }

View File

@@ -14,13 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
[ -z ${NDK_ROOT_DIR} ] && \
echo "Please set NDK_ROOT_DIR variable!" && \
exit 1
[ -z ${NDK_ROOT_DIR} ] \
&& echo "Please set NDK_ROOT_DIR variable!" \
&& exit 1
[ -z ${NDK_PROJECT_PATH} ] && \
echo "Please set NDK_PROJECT_PATH variable!" && \
exit 1
[ -z ${NDK_PROJECT_PATH} ] \
&& echo "Please set NDK_PROJECT_PATH variable!" \
&& exit 1
CC_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
CC_VERS=$(${CC_IS} --version | head -n 1)

View File

@@ -17,8 +17,10 @@
. build/bash/vars
. build/bash/functions
[ ! "${UPDATE_MAKEFILES}" = "true" ] && . build/bash/check-makefiles
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
[ ! "${UPDATE_MAKEFILES}" = "true" ] \
&& . build/bash/check-makefiles
[ ! "${THIS_IS}" = "main" ] \
&& abort "The caller is not the main makefile. Something's wrong."
if [ "${UPDATE_MAKEFILES}" = "true" ]; then
GENR="Re-generating"

Binary file not shown.

View File

@@ -15,6 +15,7 @@
# limitations under the License.
UPDATE_MAKEFILES = false
CLS_ADTS := "rm -f $(BUILD)/bash/additional-vars"
all:
$(MAKE_HIDE) $(SILENT) -C $(BUILD)/config || exit 1
@@ -46,7 +47,8 @@ clean:
# helper function
.PHONY: help
help:
$(E) " ------- Partition Manager help ------- " && $(E_NS)
$(E) " ------- Partition Manager help ------- " \
&& $(E_NS)
$(E) " Commands:"
$(E) " $(MAKE) ==> Build Partition Manager."
$(E) " $(MAKE) deb ==> Generate debian package for termux."
@@ -85,13 +87,13 @@ gen-ndk-makefiles:
$(eval NDK_PROG = true)
$(call save-gen-vars)
$(call gen-ndk-mfiles)
@ $(P) ""
@ $(CLS_ADTS)
.PHONY: gen-makefiles
gen-makefiles:
$(call save-gen-vars)
$(call gen-mfiles)
@ $(P) ""
@ $(CLS_ADTS)
.PHONY: update-ndk-makefiles
update-ndk-makefiles:
@@ -101,6 +103,7 @@ update-ndk-makefiles:
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(call gen-ndk-mfiles)
@ $(CLS_ADTS)
.PHONY: update-makefiles
update-makefiles:
@@ -109,18 +112,19 @@ update-makefiles:
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(call gen-mfiles)
@ $(CLS_ADTS)
.PHONY: clean-ndk-makefiles
clean-ndk-makefiles:
$(eval NDK_PROG = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
@ $(P) ""
@ $(CLS_ADTS)
.PHONY: clean-makefiles
clean-makefiles:
$(call save-gen-vars)
$(call clean-mfiles)
@ $(P) ""
@ $(CLS_ADTS)
# end

View File

@@ -15,7 +15,7 @@
# limitations under the License.
########
# 2.6.0
# 2.7.0
########
LOCAL_PATH := $(call my-dir)
@@ -49,8 +49,8 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_debugging
LOCAL_SRC_FILES := debugging.c
LOCAL_MODULE := libpmt_debug
LOCAL_SRC_FILES := debug.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_CFLAGS := $(PMT_CFLAGS)
@@ -79,7 +79,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := pmt
LOCAL_SRC_FILES := \
pmt.c \
versioning.c \
version.c \
get_stat.c \
tools.c \
lang_tools.c \
@@ -88,7 +88,7 @@ LOCAL_SRC_FILES := \
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_STATIC_LIBRARIES := \
libpmt_root \
libpmt_debugging \
libpmt_debug \
libpmt_partitiontool \
libpmt_list
LOCAL_CFLAGS := $(PMT_CFLAGS)

View File

@@ -15,7 +15,7 @@
# limitations under the License.
########
# 2.6.0
# 2.7.0
########
# architecture

View File

@@ -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/ExternC.h \
$(PMT_INCDIR)/pmt/Deprecates.h \
$(PMT_INCDIR)/pmt/HelpMessages.h \
$(PMT_INCDIR)/pmt/pmt.h \
$(PMT_INCDIR)/pmt/stringkeys.h \
$(PMT_INCDIR)/pmt/versioning.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() { \

View File

@@ -1,5 +1,5 @@
export PMT_VERSION="2.6.0"
export PMT_VERSION_CODE=260
export PMT_VERSION="2.7.0"
export PMT_VERSION_CODE=270
export NDK_LINK="https://dl.google.com/android/repository/android-ndk-r27-linux.zip"
export NDK_VERSION="r27"
export NDK_IS="android-ndk"

View File

@@ -19,9 +19,9 @@
#ifndef __PMT_DEPRECATED_H
#define __PMT_DEPRECATED_H
#include <sys/cdefs.h>
#include <pmt/ExternC.h>
__BEGIN_DECLS
PMT_EXTERN_C_BEGIN
#define deprecated_opt 1
#define changed_opt 2
@@ -41,6 +41,8 @@ __BEGIN_DECLS
#define v230 "2.3.0"
#define v240 "2.4.0"
#define v250 "2.5.0"
#define v260 "2.6.0"
#define v270 "2.7.0"
#define vUNK NULL
struct pmt_deprecates {
@@ -92,7 +94,7 @@ __deprecated_opt_handle(int opt, const char* opt_long, const char* depr_msg)
#define DEPR_HANDLE(x, y, z) __deprecated_opt_handle(x, y, z)
__END_DECLS
PMT_EXTERN_C_END
#endif

30
include/pmt/ExternC.h Executable file
View File

@@ -0,0 +1,30 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __PMT_EXTERN_C_H_
#define __PMT_EXTERN_C_H_
#ifdef __cplusplus
#define PMT_EXTERN_C_BEGIN extern "C" {
#define PMT_EXTERN_C_END }
#else
#define PMT_EXTERN_C_BEGIN
#define PMT_EXTERN_C_END
#endif
#endif

View File

@@ -19,11 +19,13 @@
#ifndef __PMT_HELP_MSGS_H
#define __PMT_HELP_MSGS_H
__BEGIN_DECLS
#include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
void help(void);
__END_DECLS
PMT_EXTERN_C_END
#endif

View File

@@ -20,15 +20,13 @@
#error "Your compiler is NOT clang. Please build with LLVM clang."
#endif
#include <sys/cdefs.h>
#include <pmt/ExternC.h>
__BEGIN_DECLS
PMT_EXTERN_C_BEGIN
#ifndef __PMT_H_
#define __PMT_H_
#define PMT_PACKAGE_NAME "Partition Manager"
#ifdef INC_MAIN_LIBS
#include <stdio.h>
#include <stdbool.h>
@@ -118,6 +116,6 @@ void debug(LogLevel status, const char* _Nullable fmt, ...);
#endif
__END_DECLS
PMT_EXTERN_C_END
/* end of code */

View File

@@ -19,7 +19,9 @@
#ifndef __PMT_STRINGKEYS_
#define __PMT_STRINGKEYS_
__BEGIN_DECLS
#include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
/* The struct is a very good option for setting the languages of texts etc. */
struct pmt_langdb_general {
@@ -112,7 +114,7 @@ struct pmt_langdb_langs {
const char* _Nullable lang_pr;
};
__END_DECLS
PMT_EXTERN_C_END
#endif /* __PMT_STRINGKEYS_ */

View File

@@ -19,7 +19,9 @@
#ifndef __PMT_VERSIONING_H
#define __PMT_VERSIONING_H
__BEGIN_DECLS
#include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
#ifdef __NDK_BUILD
#include <android/ndk-version.h>
@@ -28,10 +30,10 @@ __BEGIN_DECLS
/* versioning */
#define PMT_MAJOR 2
#define PMT_MINOR 6
#define PMT_MINOR 7
#define PMT_PATCHLEVEL 0
__END_DECLS
PMT_EXTERN_C_END
#endif

View File

@@ -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() { \

View File

@@ -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, ...)
{

View File

@@ -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.

View File

@@ -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;

View File

@@ -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"

View File

@@ -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",

View File

@@ -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 */

View File

@@ -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); }

View File

@@ -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
{

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
{