pmt: solve serious working problem

This commit is contained in:
2024-07-13 21:55:51 +03:00
parent 57403a0196
commit da15903881
3 changed files with 56 additions and 65 deletions

View File

@@ -6,9 +6,9 @@ It offers a lot of options. I will place these below. But first let me talk abou
#### Presented arguments (options)
```
Usage: pmt [OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...
or: pmt [OPTIONS] flash FILE PARTITION [OPTIONS]...
or: pmt [OPTIONS] format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...
Usage: pmt backup PARTITION [OUTPUT] [OPTIONS]...
or: pmt flash FILE PARTITION [OPTIONS]...
or: pmt format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...
Options:
-l, --logical It is meant to determine whether the target partition is logical.

View File

@@ -135,9 +135,9 @@ struct pmt_langdb_general tr = {
};
struct pmt_langdb_docs en_docs = {
.docs_strs_l1 = "[OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...",
.docs_strs_l2 = "[OPTIONS] flash FILE PARTITION [OPTIONS]...",
.docs_strs_l3 = "[OPTIONS] format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...",
.docs_strs_l1 = "backup PARTITION [OUTPUT] [OPTIONS]...",
.docs_strs_l2 = "flash FILE PARTITION [OPTIONS]...",
.docs_strs_l3 = "format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...",
.docs_strs_l4 = "Options",
.docs_strs_l5 = "It is meant to determine whether the target partition is logical.",
.docs_strs_l6 = "It is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name).",

77
jni/pmt.c Executable file → Normal file
View File

@@ -1,4 +1,4 @@
/* By YZBruh | ShawkTeam */
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
@@ -59,6 +59,21 @@ extern int pmt_langdb_total;
static const char* opt_symbol = "-";
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
@@ -101,7 +116,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, argv[0], current->for_more);
/* a structure for long arguments */
struct option long_options[] = {
@@ -126,8 +141,6 @@ int main(int argc, char* argv[])
static bool pmt_setlang = false;
static char* langpr;
static int search_result = 3;
static int getvar_temp;
static int check_getvar_temp;
static int opt;
/* control for each argument */
@@ -194,7 +207,7 @@ int main(int argc, char* argv[])
return 1;
break;
default:
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", current->usage_head, argv[0]);
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-v | --version] [--help] [-L | --license]\n", current->usage_head, argv[0]);
return 1;
}
}
@@ -238,79 +251,57 @@ int main(int argc, char* argv[])
static char arg1[20];
sprintf(arg1, "%s", argv[1]);
for (int argtest = 2; argtest == argc; argtest++)
if (strcmp(argv[1], "backup") == 0)
{
getvar_temp = argtest;
check_getvar_temp = getvar_temp;
getvar_temp++;
if (strcmp(argv[argtest], "backup") == 0)
{
check_getvar_temp++;
if (argc < check_getvar_temp)
if (argc == 2)
LOGE("%s 0.\n", current->expected_backup_arg);
target_partition = argv[getvar_temp];
target_partition = argv[2];
if (argc == check_getvar_temp) out = target_partition;
if (argc == 3)
out = target_partition;
else
{
getvar_temp++;
out = argv[getvar_temp];
}
out = argv[3];
check_optsym(target_partition);
check_optsym(out);
pmt_backup = true;
break;
}
else if (strcmp(argv[argtest], "flash") == 0)
else if (strcmp(argv[1], "flash") == 0)
{
check_getvar_temp++;
if (argc < check_getvar_temp)
if (argc == 2)
LOGE("%s 0.\n", current->expected_flash_arg);
if (argc == check_getvar_temp)
if (argc == 2)
LOGE("%s 1.\n", current->expected_flash_arg);
target_flash_file = argv[getvar_temp];
target_flash_file = argv[2];
getvar_temp++;
target_partition = argv[getvar_temp];
target_partition = argv[3];
check_optsym(target_flash_file);
check_optsym(target_partition);
pmt_flash = true;
break;
}
else if (strcmp(argv[argtest], "format") == 0)
else if (strcmp(argv[1], "format") == 0)
{
check_getvar_temp++;
if (argc < check_getvar_temp)
if (argc == 2)
LOGE("%s 0.\n", current->expected_format_arg);
if (argc == check_getvar_temp)
if (argc == 3)
LOGE("%s 1.\n", current->expected_format_arg);
format_fs = argv[getvar_temp];
format_fs = argv[2];
getvar_temp++;
target_partition = argv[getvar_temp];
target_partition = argv[3];
check_optsym(format_fs);
check_optsym(target_partition);
pmt_format = true;
break;
}
}
/* target control is done */