mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +08:00
Added example for hiding secret information
This commit is contained in:
parent
4784fe2491
commit
3cd9894747
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "editline.h"
|
#include "editline.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <regex.h>
|
||||||
|
|
||||||
#define HISTORY "/tmp/.cli-history"
|
#define HISTORY "/tmp/.cli-history"
|
||||||
|
|
||||||
@ -116,6 +117,33 @@ el_status_t do_suspend(void)
|
|||||||
return CSstay;
|
return CSstay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int my_rl_check_secret(const char* source)
|
||||||
|
{
|
||||||
|
const char* pattern = (char *)"^unlock\\s";
|
||||||
|
regex_t regex;
|
||||||
|
|
||||||
|
int reti;
|
||||||
|
int rez = 0;
|
||||||
|
|
||||||
|
if (!pattern || !source)
|
||||||
|
return rez;
|
||||||
|
|
||||||
|
/* Compile regular expression */
|
||||||
|
reti = regcomp(®ex, pattern, 0);
|
||||||
|
if (reti) // If couldn't compile regex
|
||||||
|
return rez;
|
||||||
|
|
||||||
|
/* Execute regular expression */
|
||||||
|
reti = regexec(®ex, source, 0, NULL, 0);
|
||||||
|
if (!reti) // If regex match
|
||||||
|
rez = 1;
|
||||||
|
|
||||||
|
/* Free memory allocated to the pattern buffer by regcomp() */
|
||||||
|
regfree(®ex);
|
||||||
|
|
||||||
|
return rez;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
@ -124,6 +152,7 @@ int main(void)
|
|||||||
/* Setup callbacks */
|
/* Setup callbacks */
|
||||||
rl_set_complete_func(&my_rl_complete);
|
rl_set_complete_func(&my_rl_complete);
|
||||||
rl_set_list_possib_func(&my_rl_list_possib);
|
rl_set_list_possib_func(&my_rl_list_possib);
|
||||||
|
rl_set_check_secret_func(&my_rl_check_secret);
|
||||||
el_bind_key('?', list_possible);
|
el_bind_key('?', list_possible);
|
||||||
el_bind_key(CTL('C'), do_break);
|
el_bind_key(CTL('C'), do_break);
|
||||||
el_bind_key(CTL('D'), do_exit);
|
el_bind_key(CTL('D'), do_exit);
|
||||||
|
Loading…
Reference in New Issue
Block a user