|
@@ -622,6 +622,7 @@ void help(void) {
|
|
|
printf("\t-ICONV\tUse ICONV library\n");
|
|
|
printf("\t-NOLOG\tNo logging\n");
|
|
|
printf("\t-NOC\tDon't allow Ctrl-C\n");
|
|
|
+ printf("\t-NOTERM\tDon't Translate Keys\n");
|
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
@@ -881,23 +882,16 @@ int main(int argc, char *argv[]) {
|
|
|
// leia a entrada padrao
|
|
|
char input[BSIZE];
|
|
|
int r = read(STDIN_FILENO, &input, BSIZE);
|
|
|
- input[r] = 0;
|
|
|
+ std::string input_str(input, r);
|
|
|
+ // input[r] = 0;
|
|
|
+
|
|
|
// e escreva no bc
|
|
|
- ZF_LOGI("<< %s", repr(input));
|
|
|
+ ZF_LOGI_MEM(input_str.data(), input_str.size(), "INPUT <<");
|
|
|
|
|
|
if (CATCH_CTRLC) {
|
|
|
- char *cp;
|
|
|
- int found = 0;
|
|
|
- while ((cp = strchr(input, '\x03')) != NULL) {
|
|
|
- memmove(cp, cp + 1, strlen(cp));
|
|
|
- r--;
|
|
|
- found++;
|
|
|
- }
|
|
|
- ZF_LOGI("Removed %d ^Cs", found);
|
|
|
+ remove_all(input_str, '\x03');
|
|
|
}
|
|
|
|
|
|
- std::string input_str = input;
|
|
|
-
|
|
|
if (TERM_XLATE) {
|
|
|
// We're going to try it without any buffer or understanding of ANSI
|
|
|
// codes.
|
|
@@ -905,13 +899,13 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
while (replace(input_str, "\x1b[A", "\x1bOA")) {
|
|
|
c++;
|
|
|
- };
|
|
|
+ }
|
|
|
while (replace(input_str, "\x1b[B", "\x1bOB")) {
|
|
|
c++;
|
|
|
- };
|
|
|
+ }
|
|
|
while (replace(input_str, "\x1b[C", "\x1bOC")) {
|
|
|
c++;
|
|
|
- };
|
|
|
+ }
|
|
|
while (replace(input_str, "\x1b[D", "\x1bOD")) {
|
|
|
c++;
|
|
|
}
|
|
@@ -931,23 +925,105 @@ int main(int argc, char *argv[]) {
|
|
|
while (replace(input_str, "\x1b[@", "\x1b[2\x7e")) {
|
|
|
c++;
|
|
|
}
|
|
|
+
|
|
|
+ /* F1-F5 are "broken". They all map to this.
|
|
|
while (replace(input_str, "\x1b[1", "\x1bOR")) { // F3
|
|
|
c++;
|
|
|
}
|
|
|
-
|
|
|
+ */
|
|
|
while (replace(input_str, "\r\n", "\r")) {
|
|
|
c++;
|
|
|
}
|
|
|
- if (c) {
|
|
|
- ZF_LOGE("Input %d now [%s]", c, repr(input_str.c_str()));
|
|
|
+
|
|
|
+ // DOORWAYS mode:
|
|
|
+ if (input_str.find(char(0)) != std::string::npos) {
|
|
|
+ // We found a null character, TIAS
|
|
|
+ ZF_LOGE("null found. Start doorways replace mode.");
|
|
|
+
|
|
|
+ using namespace std::string_literals;
|
|
|
+
|
|
|
+ // F1-F12
|
|
|
+ while (replace(input_str, std::string("\x00\x3b"s), std::string("\x1bOA") )) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x3c"s), "\x1bOB")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x3d"s), "\x1bOC")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x3e"s), "\x1bOD")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x3f"s), "\x1b[6\x7e")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x40"s), "\x1b[5\x7e")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x41"s), "\x1bOH")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x42"s), "\x1bOF")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x43"s), "\x1b[2\x7e")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x44"s), "F10")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x85"s), "F11")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x86"s), "F12")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Delete = 0x7f (not here)
|
|
|
+ // Left, Right, Up, Down, Insert, Home, End, PgUp, PgDwn
|
|
|
+ while (replace(input_str, std::string("\x00\x4b"s), "L")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x4d"s), "R")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x48"s), "U")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x50"s), "D")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x52"s), "INS")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ // Delete is 0x7f (no null)
|
|
|
+ while (replace(input_str, std::string("\x00\x47"s), "HOME")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x4f"s), "END")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x49"s), "PU")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+ while (replace(input_str, std::string("\x00\x51"s), "PD")) {
|
|
|
+ c++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (c) {
|
|
|
+ ZF_LOGE_MEM(input_str.data(), input_str.size(), "Input (%d changed):", c);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // write(master, &input, r);
|
|
|
- write(master, input_str.data(), input_str.size());
|
|
|
+ ZF_LOGD_MEM(input_str.data(), input_str.size(), "Write Input String:");
|
|
|
+
|
|
|
+ // write(master, &input, r);
|
|
|
+ write(master, input_str.data(), input_str.size());
|
|
|
|
|
|
- // This is INPUT from the USER
|
|
|
- // ZF_LOGI_MEM( input, strlen(input), "<< ");
|
|
|
+ // This is INPUT from the USER
|
|
|
+ // ZF_LOGI_MEM( input, strlen(input), "<< ");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|