|
@@ -762,7 +762,6 @@ int send_file(int fd, char *filename) {
|
|
|
|
|
|
void send_goto(int fd, int x, int y) {
|
|
|
char gbuffer[16];
|
|
|
- char * cp;
|
|
|
|
|
|
sprintf(gbuffer, "\x1b[%d;%dH", y, x);
|
|
|
write(fd, gbuffer, strlen(gbuffer));
|
|
@@ -772,24 +771,25 @@ int send_file(int fd, int x, int y, char *filename) {
|
|
|
FILE *fp;
|
|
|
char buffer[100];
|
|
|
int read;
|
|
|
- int pos;
|
|
|
+
|
|
|
fp = fopen(filename, "rb");
|
|
|
if (fp == NULL) {
|
|
|
ZF_LOGD("Failed to open %s", filename);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- send_goto(fd, x,y);
|
|
|
+ send_goto(fd, x, y);
|
|
|
y++;
|
|
|
- char *cp, * last_cp;
|
|
|
|
|
|
while ((read = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
|
|
|
+ char *cp, *last_cp;
|
|
|
+
|
|
|
buffer[read] = 0;
|
|
|
last_cp = buffer;
|
|
|
- while ( ( cp = strchr(last_cp, '\n')) != NULL) {
|
|
|
+ while ((cp = strchr(last_cp, '\n')) != NULL) {
|
|
|
*cp = 0;
|
|
|
- write(fd, last_cp, strlen(last_cp));
|
|
|
- send_goto(fd, x,y);
|
|
|
+ write(fd, last_cp, strlen(last_cp));
|
|
|
+ send_goto(fd, x, y);
|
|
|
y++;
|
|
|
last_cp = cp + 1;
|
|
|
};
|
|
@@ -858,7 +858,7 @@ const char *process_trigger(int fd, const char *cp) {
|
|
|
|
|
|
case 'F':
|
|
|
case 'f': {
|
|
|
- int x, y, pos = 0;
|
|
|
+ int pos = 0;
|
|
|
if (ch == 'f') {
|
|
|
pos = 1;
|
|
|
x = (*cp) - '0';
|
|
@@ -871,7 +871,7 @@ const char *process_trigger(int fd, const char *cp) {
|
|
|
y *= 10;
|
|
|
y += (*cp) - '0';
|
|
|
cp++;
|
|
|
- ZF_LOGI( "file at (%d, %d)", x, y);
|
|
|
+ ZF_LOGI("file at (%d, %d)", x, y);
|
|
|
}
|
|
|
// Ok, look for filename
|
|
|
char ansifile[32] = "./hh/";
|
|
@@ -1225,10 +1225,9 @@ int regmatch(regex_t *preg, const char *string, size_t nmatch,
|
|
|
// returns number of matches found. (Max nmatch)
|
|
|
int matches = 0;
|
|
|
int offset = 0;
|
|
|
- int ret;
|
|
|
|
|
|
while (matches < nmatch) {
|
|
|
- ret = regexec(preg, string + offset, nmatch - matches, pmatch + matches,
|
|
|
+ int ret = regexec(preg, string + offset, nmatch - matches, pmatch + matches,
|
|
|
eflags);
|
|
|
if (!ret) {
|
|
|
int current = offset;
|
|
@@ -1495,8 +1494,8 @@ int mangle(int fd, char *buffer) {
|
|
|
// I tried a ^P2 before doing this .. but I'd rather have the picture up
|
|
|
// right away I think.
|
|
|
|
|
|
- sprintf(display, "%s%s%s.^P3%s", needs_cls ? "\x1b[2J" : "",
|
|
|
- fgoto, possibles[r].filename, restore_color);
|
|
|
+ sprintf(display, "%s%s%s.^P3%s", needs_cls ? "\x1b[2J" : "", fgoto,
|
|
|
+ possibles[r].filename, restore_color);
|
|
|
|
|
|
ZF_LOGI("mangle(ANSI_CLS): %d file inserted %s", r, repr(display));
|
|
|
|
|
@@ -1639,26 +1638,6 @@ int mangle(int fd, char *buffer) {
|
|
|
mangled_chars += c;
|
|
|
}
|
|
|
}
|
|
|
- // Do things here.
|
|
|
-
|
|
|
- /*
|
|
|
- // NO! This is predictable
|
|
|
- if (i % 3 == 0) {
|
|
|
- mangled++;
|
|
|
- for (int p = rxmatch[i].rm_so; p < rxmatch[i].rm_eo; p++) {
|
|
|
- buffer[p] = tolower(buffer[p]);
|
|
|
- mangled_chars++;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (i % 3 == 1) {
|
|
|
- mangled++;
|
|
|
- for (int p = rxmatch[i].rm_so; p < rxmatch[i].rm_eo; p++) {
|
|
|
- buffer[p] = toupper(buffer[p]);
|
|
|
- mangled_chars++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1701,6 +1680,56 @@ int harry_happens(time_t *last_event, int wakeup) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+
|
|
|
+TO FIX: Stop using c strings, must use char * buffer + int length.
|
|
|
+MAY CONTAIN NULL VALUES.
|
|
|
+
|
|
|
+Rework some things here.
|
|
|
+
|
|
|
+Here's the "plan":
|
|
|
+
|
|
|
+ if buffer is EMPTY:
|
|
|
+ time_idle = 1;
|
|
|
+ // setup for "random timeout value mess"
|
|
|
+ // we're in luck! The last parameter is time interval/timeout. :D
|
|
|
+ timeout.tv_sec = 10; // randrange(10-25)
|
|
|
+ timeout.tv_usec = 0;
|
|
|
+
|
|
|
+ NOT EMPTY:
|
|
|
+ // we're in luck! The last parameter is time interval/timeout. :D
|
|
|
+ timeout.tv_sec = 0;
|
|
|
+ timeout.tv_usec = 10; // Wild Guess Here? Maybe higher, maybe lower?
|
|
|
+ time_idle = 0;
|
|
|
+
|
|
|
+ ON READ:
|
|
|
+ read/append to current buffer.
|
|
|
+ We can't use nulls -- what if they are using ZModem, there's nulls in the file!
|
|
|
+ Look for trailing / the very last "\r\n".
|
|
|
+
|
|
|
+ (I could mangle/chunk it line by line. But I'm not sure I'd need to do that.)
|
|
|
+
|
|
|
+ Optional "mangle" buffer up to that very point -- and send up to that point.
|
|
|
+
|
|
|
+ Option #2: Maybe we send everything if program has been running for under
|
|
|
+ 20 seconds. This would allow the ANSI detect to not get screwed up by this
|
|
|
+ new idea.
|
|
|
+
|
|
|
+ ON TIMEOUT:
|
|
|
+ if time_idle:
|
|
|
+ Activate funny harry timeout events.
|
|
|
+ else:
|
|
|
+ Ok, we *STILL* haven't received any more characters into the buffer --
|
|
|
+ even after waiting. (Maybe we haven't waited long enough?)
|
|
|
+ send the pending information in the buffer and clear it out.
|
|
|
+ Maybe this is a prompt, and there won't be a \r\n.
|
|
|
+
|
|
|
+This allows for cleaner process of "lines" of buffer. We shouldn't break
|
|
|
+in the midDLE OF A WORD. Downside is that we sit on buffer contents a little
|
|
|
+while / some amount of time -- which will add some lag to prompts showing up.
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
int main(int argc, char *argv[]) {
|
|
|
int master;
|
|
|
pid_t pid;
|