mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 02:27:26 -07:00
Add pm3line API to hide readline, allowing easier implementation of alternatives
This commit is contained in:
parent
4e78034a6e
commit
fc13b6b20c
12 changed files with 265 additions and 227 deletions
|
@ -12,7 +12,7 @@ This version
|
|||
- Iceman
|
||||
|
||||
Note:
|
||||
This script is used as a helper script to generate the rl_vocabulory.h file.
|
||||
This script is used as a helper script to generate the pm3line_vocabulory.h file.
|
||||
It need a working proxmark3 client to extract the help text.
|
||||
|
||||
Ie: this script can't be used inside the normal build sequence.
|
||||
|
@ -65,22 +65,14 @@ def main():
|
|||
// readline auto complete utilities
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef RL_VOCABULORY_H__
|
||||
#define RL_VOCABULORY_H__
|
||||
#ifndef PM3LINE_VOCABULORY_H__
|
||||
#define PM3LINE_VOCABULORY_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_READLINE)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <readline/readline.h>
|
||||
#include "ui.h" // g_session
|
||||
#include "util.h" // str_ndup
|
||||
|
||||
char* rl_command_generator(const char *text, int state);
|
||||
char **rl_command_completion(const char *text, int start, int end);
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct vocabulory_s {
|
||||
bool offline;
|
||||
|
@ -100,50 +92,6 @@ const static vocabulory_t vocabulory[] = {\n""")
|
|||
|
||||
args.output_file.write(""" {0, NULL}\n};
|
||||
|
||||
|
||||
char **rl_command_completion(const char *text, int start, int end) {
|
||||
rl_attempted_completion_over = 0;
|
||||
return rl_completion_matches (text, rl_command_generator);
|
||||
}
|
||||
|
||||
char* rl_command_generator(const char *text, int state) {
|
||||
static int index;
|
||||
static size_t len;
|
||||
size_t rlen = strlen(rl_line_buffer);
|
||||
const char *command;
|
||||
|
||||
if (!state) {
|
||||
index = 0;
|
||||
len = strlen(text);
|
||||
}
|
||||
|
||||
while ((command = vocabulory[index].name)) {
|
||||
|
||||
// When no pm3 device present
|
||||
// and the command is not available offline,
|
||||
// we skip it.
|
||||
if ((g_session.pm3_present == false) && (vocabulory[index].offline == false )) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
if (strncmp (command, rl_line_buffer, rlen) == 0) {
|
||||
const char *next = command + (rlen - len);
|
||||
const char *space = strstr(next, " ");
|
||||
if (space != NULL) {
|
||||
return str_ndup(next, space - next);
|
||||
}
|
||||
return str_dup(next);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue