mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 22:23:38 -07:00
main_loop() string create refactoring
This commit is contained in:
parent
63e950c5ea
commit
4af40c00d4
3 changed files with 16 additions and 11 deletions
|
@ -117,7 +117,7 @@ void main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
|
|||
if (script_cmds_file) {
|
||||
script_file = fopen(script_cmds_file, "r");
|
||||
if (script_file) {
|
||||
printf("using 'scripting' commands file %s\n", script_cmds_file);
|
||||
printf("executing commands from file: %s\n", script_cmds_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,18 +133,14 @@ void main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
|
|||
} else {
|
||||
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
|
||||
|
||||
if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
|
||||
memset(cmd, 0, strlen(script_cmd_buf) + 1);
|
||||
strcpy(cmd, script_cmd_buf);
|
||||
if ((cmd = strmcopy(script_cmd_buf)) != NULL) {
|
||||
printf(PROXPROMPT"%s\n", cmd);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If there is a script command
|
||||
if (execCommand){
|
||||
if ((cmd = (char*) malloc(strlen(script_cmd) + 1)) != NULL) {
|
||||
memset(cmd, 0, strlen(script_cmd) + 1);
|
||||
strcpy(cmd, script_cmd);
|
||||
if ((cmd = strmcopy(script_cmd)) != NULL) {
|
||||
printf(PROXPROMPT"%s\n", cmd);
|
||||
}
|
||||
|
||||
|
@ -154,6 +150,7 @@ void main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
|
|||
if (script_cmd)
|
||||
break;
|
||||
|
||||
// if there is a pipe from stdin
|
||||
if (stdinOnPipe) {
|
||||
memset(script_cmd_buf, 0, sizeof(script_cmd_buf));
|
||||
if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), stdin)) {
|
||||
|
@ -162,9 +159,7 @@ void main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
|
|||
}
|
||||
strcleanrn(script_cmd_buf, sizeof(script_cmd_buf));
|
||||
|
||||
if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
|
||||
memset(cmd, 0, strlen(script_cmd_buf) + 1);
|
||||
strcpy(cmd, script_cmd_buf);
|
||||
if ((cmd = strmcopy(script_cmd_buf)) != NULL) {
|
||||
printf(PROXPROMPT"%s\n", cmd);
|
||||
}
|
||||
|
||||
|
|
|
@ -637,6 +637,15 @@ void strcreplace(char *buf, size_t len, char from, char to) {
|
|||
}
|
||||
}
|
||||
|
||||
char *strmcopy(char *buf) {
|
||||
char * str = NULL;
|
||||
if ((str = (char*) malloc(strlen(buf) + 1)) != NULL) {
|
||||
memset(str, 0, strlen(buf) + 1);
|
||||
strcpy(str, buf);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// determine number of logical CPU cores (use for multithreaded functions)
|
||||
extern int num_CPUs(void)
|
||||
|
|
|
@ -79,6 +79,7 @@ extern void rol(uint8_t *data, const size_t len);
|
|||
extern void clean_ascii(unsigned char *buf, size_t len);
|
||||
void strcleanrn(char *buf, size_t len);
|
||||
void strcreplace(char *buf, size_t len, char from, char to);
|
||||
char *strmcopy(char *buf);
|
||||
|
||||
extern int num_CPUs(void); // number of logical CPUs
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue