*
* Licensed under GPLv2 or later, see file License in this tarball for details.
*
- * example : conspy num shared access to console num
- * or conspy -d num screenshot of console num
- * or conspy -cs num poor man's GNU screen like
+ * example: conspy num shared access to console num
+ * or conspy -d num screenshot of console num
+ * or conspy -cs num poor man's GNU screen like
*/
//applet:IF_CONSPY(APPLET(conspy, _BB_DIR_BIN, _BB_SUID_DROP))
//config: or conspy -cs num poor man's GNU screen like
//usage:#define conspy_trivial_usage
-//usage: "[-vcsndf] [-x ROW] [-y LINE] [CONSOLE_NO]"
+//usage: "[-vcsndf] [-x ROW] [-y LINE] [CONSOLE_NO]"
//usage:#define conspy_full_usage "\n\n"
//usage: "A text-mode VNC like program for Linux virtual consoles."
//usage: "\nTo exit, quickly press ESC 3 times."
unsigned char lines, rows, cursor_x, cursor_y;
};
-#define CHAR(x) ((x)[0])
-#define ATTR(x) ((x)[1])
+#define CHAR(x) ((uint8_t)((x)[0]))
+#define ATTR(x) ((uint8_t)((x)[1]))
#define NEXT(x) ((x)+=2)
-#define DATA(x) (* (short *) (x))
+#define DATA(x) (*(uint16_t*)(x))
struct globals {
char* data;
unsigned y = i - G.y; // if will catch i < G.y too
if (CHAR(data) < ' ')
- CHAR(data) = ' ';
+ *data = ' '; // CHAR(data) = ' ';
if (y >= G.height || x >= G.width)
DATA(data) = 0;
}
putchar(CHAR(data));
}
-#define clrscr() printf("\033[1;1H" "\033[0J")
-#define curoff() printf("\033[?25l")
+static void clrscr(void)
+{
+ printf("\033[1;1H" "\033[0J");
+}
+
+static void curoff(void)
+{
+ printf("\033[?25l");
+}
static void curon(void)
{
if (tty_row >= G.width)
continue;
space_cnt++;
- if (BW && (CHAR(data) | ' ') == ' ')
+ if (BW && CHAR(data) == ' ')
continue;
while (linefeed_cnt != 0) {
- bb_putchar('\r');
+ //bb_putchar('\r'); - tty driver does it for us
bb_putchar('\n');
linefeed_cnt--;
}
static void get_initial_data(const char* vcsa_name)
{
- int size;
G.vcsa_fd = xopen(vcsa_name, O_RDONLY);
xread(G.vcsa_fd, &G.info, 4);
- G.size = size = G.info.rows * G.info.lines * 2;
+ G.size = G.info.rows * G.info.lines * 2;
G.width = G.height = UINT_MAX;
- G.data = xzalloc(2 * size);
+ G.data = xzalloc(2 * G.size);
screen_read_close();
}
}
}
-int conspy_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int conspy_main(int argc UNUSED_PARAM, char **argv)
{
- char vcsa_name[sizeof("/dev/vcsa") + 2];
- char tty_name[sizeof("/dev/tty") + 2];
+ char vcsa_name[sizeof("/dev/vcsaNN")];
+ char tty_name[sizeof("/dev/ttyNN")];
#define keybuf bb_common_bufsiz1
struct termios termbuf;
unsigned opts;
tcgetattr(G.kbd_fd, &G.term_orig);
termbuf = G.term_orig;
termbuf.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL);
- termbuf.c_oflag &= ~(OPOST);
+ //termbuf.c_oflag &= ~(OPOST); - no, we still want \n -> \r\n
termbuf.c_lflag &= ~(ISIG|ICANON|ECHO);
termbuf.c_cc[VMIN] = 1;
termbuf.c_cc[VTIME] = 0;
old = G.data + G.current;
G.current = G.size - G.current;
data = G.data + G.current;
-
+
// Close & re-open vcsa in case they have
// swapped virtual consoles
G.vcsa_fd = xopen(vcsa_name, O_RDONLY);
// Do exit processing
for (i = 0; i < bytes_read; i++) {
- if (k[i] != '\033') G.escape_count = 0;
+ if (k[i] != '\033')
+ G.escape_count = 0;
else if (++G.escape_count >= 3)
cleanup(0);
}