summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--call/call.c889
1 files changed, 475 insertions, 414 deletions
diff --git a/call/call.c b/call/call.c
index f9fe6eb..1d18bdc 100644
--- a/call/call.c
+++ b/call/call.c
@@ -86,10 +86,10 @@ static char *port;
static char *mycall;
static int stdin_is_tty = 1;
-static iconv_t ibm850toutf8 = 0, wcharttoibm850 = 0, wcharttoutf8 = 0, utf8towchart = 0;
+static iconv_t ibm850toutf8, wcharttoibm850, wcharttoutf8, utf8towchart;
volatile int interrupted = FALSE;
-static int sigwinchsignal = FALSE;
+static int sigwinchsignal;
int paclen;
int fd;
int curson = 1;
@@ -121,7 +121,7 @@ typedef struct {
#define TALKMODE 001 /* two windows (outgoing and incoming) with menu */
#define SLAVEMODE 002 /* Menu mode */
-#define RAWMODE 004 /* mode used by earlier versions */
+#define RAWMODE 004 /* mode used by earlier versions */
#define ORIGINALENCODING 0
#define UTF8ENCODING 1
@@ -129,98 +129,112 @@ typedef struct {
#define SCROLLBACKSIZE 5000
typedef struct {
- char *str;int len;
-}scrollbackstruct;
-
+ char *str;
+ int len;
+}scrollbackstruct;
static scrollbackstruct scrollback[SCROLLBACKSIZE];
-static int topscroll=0, lastscroll = 0, scrolledup=0, eatchar = 0;
-static char inbuf[MAX_BUFLEN];static int inbuflen = 0, inbufwid = 0;
-static char incharbuf[6];static int incharbuflen = 0;
-void statline(int mode, char *s);
+static int topscroll, lastscroll, scrolledup, eatchar;
+static char inbuf[MAX_BUFLEN];
+static int inbuflen, inbufwid;
+static char incharbuf[6];
+static int incharbuflen;
-void addscrollline(char *s, int len)
+static void addscrollline(char *s, int len)
{
scrollback[lastscroll].str = malloc(len);
memcpy(scrollback[lastscroll].str, s, len);
scrollback[lastscroll].len = len;
- if (++lastscroll >= SCROLLBACKSIZE)lastscroll = 0;
- if (lastscroll == topscroll){
- free(scrollback[topscroll].str);
- if (++topscroll >= SCROLLBACKSIZE)topscroll = 0;
+ if (++lastscroll >= SCROLLBACKSIZE)
+ lastscroll = 0;
+ if (lastscroll == topscroll) {
+ free(scrollback[topscroll].str);
+ if (++topscroll >= SCROLLBACKSIZE)
+ topscroll = 0;
}
}
-// Notes: Japanese, Chinese and Korean characters mostly take up two
-// characters in width. These characters return 2 via
-// wcwidth to let the code know that they require two
-// spaces. Mono-space fonts/ncurses seems to work correctly with
-// East Asian characters.
-//
-// There are also some characters that return a wcwidth of 0. I'm
-// not sure about all of them, but some of the 0 width characters
-// add a mark above or below a character. In order for these marks
-// to appear correctly, the previous character and the overstrike
-// must be drawn together. using wmove and drawing the accent doesn't
-// work.
-//
-// There are some other characters that have functions, and these
-// are not supported using a print to the screen. South Asian
-// fonts are complicated. I don't believe south asian fonts work
-// correctly from the Linux command line (as of late 2009). They
-// print but don't combine. The result is distorted.
-//
-// Many characters, as of 12/09, are too wide for a single space
-// in the font, although they return a wcwidth of 1. I suspect
-// this is due to these characters not being part of the mono-spaced
-// font and are instead pulled from an alternate font. These
-// characters also glitch in xterm, vim and other ncurses
-// software. I suspect this is actually a font bug, and any character
-// that returns wcwidth=1 in a monospaced font should be
-// monospaced.
-//
-
-
-int widthchar(char *s, size_t bytes, int xpos)
+/*
+ * Notes: Japanese, Chinese and Korean characters mostly take up two characters
+ * in width. These characters return 2 via wcwidth to let the code know that
+ * they require two spaces. Mono-space fonts/ncurses seems to work correctly
+ * with East Asian characters.
+ *
+ * There are also some characters that return a wcwidth of 0. I'm not sure
+ * about all of them, but some of the 0 width characters add a mark above or
+ * below a character. In order for these marks to appear correctly, the
+ * previous character and the overstrike must be drawn together. using wmove
+ * and drawing the accent doesn't work.
+ *
+ * There are some other characters that have functions, and these are not
+ * supported using a print to the screen. South Asian fonts are complicated. I
+ * don't believe south asian fonts work correctly from the Linux command line
+ * (as of late 2009). They print but don't combine. The result is distorted.
+ *
+ * Many characters, as of 12/09, are too wide for a single space in the font,
+ * although they return a wcwidth of 1. I suspect this is due to these
+ * characters not being part of the mono-spaced font and are instead pulled
+ * from an alternate font. These characters also glitch in xterm, vim and
+ * other ncurses software. I suspect this is actually a font bug, and any
+ * character that returns wcwidth=1 in a monospaced font should be monospaced.
+ */
+
+static int widthchar(char *s, size_t bytes, int xpos)
{
- wchar_t c;int width;
+ wchar_t c;
+ int width;
char *outbuf=(char *) &c;
- size_t outsize = sizeof(wchar_t);
- // Note: Actually need to check if bad UTF8 characters show as ?
- if (iconv(utf8towchart, &s, &bytes, &outbuf, &outsize)< 0)return 0;
- if (c == 9){
+ size_t outsize = sizeof(wchar_t);
+
+ /*
+ * Note: Actually need to check if bad UTF8 characters show as ?
+ */
+ if (iconv(utf8towchart, &s, &bytes, &outbuf, &outsize)< 0)
+ return 0;
+ if (c == 9) {
return 8 - (xpos & 7);
}
width = wcwidth(c);
- if (width < 0)return 0;
+ if (width < 0)
+ return 0;
return width;
}
-
-int completecharlen(char *s)
+static int completecharlen(char *s)
{
- unsigned ut = (unsigned char)s[0];int clen;
- if (ut <= 0x80)clen = 1;
- else if ((ut >= 192) && (ut < 192+32))clen = 2;
- else if ((ut >= 224) && (ut < 224+16))clen = 3;
- else if ((ut >= 240) && (ut < 240+8))clen = 4;
- else if ((ut >= 248) && (ut < 248+4))clen = 5;
- else if ((ut >= 252) && (ut < 252+2))clen = 6;
- else clen = 1; // bad
+ unsigned ut = (unsigned char)s[0];
+ int clen;
+ if (ut <= 0x80)
+ clen = 1;
+ else if ((ut >= 192) && (ut < 192+32))
+ clen = 2;
+ else if ((ut >= 224) && (ut < 224+16))
+ clen = 3;
+ else if ((ut >= 240) && (ut < 240+8))
+ clen = 4;
+ else if ((ut >= 248) && (ut < 248+4))
+ clen = 5;
+ else if ((ut >= 252) && (ut < 252+2))
+ clen = 6;
+ else
+ clen = 1; /* bad */
return clen;
}
-
-// Must check for COLS while redrawing from history. Or otherwise the text
-// wraps around and does strange things.
-int waddnstrcolcheck(WINDOW *win, char *s, int len, int twidth)
+/*
+ * Must check for COLS while redrawing from history. Or otherwise the text
+ * wraps around and does strange things.
+ */
+static int waddnstrcolcheck(WINDOW *win, char *s, int len, int twidth)
{
int n;
- for (twidth = 0,n=0;n<len;){
+ for (twidth = 0,n=0;n<len;) {
int cwidth = completecharlen(&s[n]), width;
- if (n + cwidth > len)return twidth; // Error condition
+ if (n + cwidth > len) /* Error condition */
+ return twidth;
width = widthchar(&s[n], cwidth, twidth);
- if (twidth+width > COLS)return twidth; //
+ if (twidth+width > COLS)
+ return twidth;
waddnstr(win, &s[n], cwidth);
n += cwidth;
twidth += width;
@@ -228,18 +242,20 @@ int waddnstrcolcheck(WINDOW *win, char *s, int len, int twidth)
return twidth;
}
-// Update a line on the screen from the backscroll buffer.
-void updateline(int screeny, int yfrom, t_win *win_in, int mode, t_win *win_out)
+/*
+ * Update a line on the screen from the backscroll buffer.
+ */
+static void updateline(int screeny, int yfrom, t_win *win_in, int mode, t_win *win_out)
{
wmove(win_in->ptr, screeny, 0);
- if (yfrom == lastscroll){
+ if (yfrom == lastscroll) {
int twidth = 0;
if (inbuflen > 0)
twidth = waddnstrcolcheck(win_in->ptr, inbuf, inbuflen, 0);
- if (mode == SLAVEMODE){
+ if (mode == SLAVEMODE) {
char obuf[MAX_BUFLEN];
char *inbuf = (char *)win_out->string, *outbuf = obuf;
- size_t insize = win_out->bytes * sizeof(wchar_t), outsize = MAX_BUFLEN;
+ size_t insize = win_out->bytes * sizeof(wchar_t), outsize = MAX_BUFLEN;
iconv(wcharttoutf8, &inbuf, &insize, &outbuf, &outsize);
waddnstrcolcheck(win_in->ptr, obuf, MAX_BUFLEN - outsize, twidth);
win_out->curs_pos = win_out->bytes;
@@ -250,14 +266,17 @@ void updateline(int screeny, int yfrom, t_win *win_in, int mode, t_win *win_out)
}
}
-// Cursor in SLAVE mode while scrolling looks broken.
-// Cursor in TALK mode is always good, because it's on the bottom window
-void checkcursor(int mode)
+/*
+ * Cursor in SLAVE mode while scrolling looks broken.
+ * Cursor in TALK mode is always good, because it's on the bottom window
+ */
+static void checkcursor(int mode)
{
int newcursor;
- if ((mode == SLAVEMODE) && scrolledup)newcursor = 0;
+ if ((mode == SLAVEMODE) && scrolledup)
+ newcursor = 0;
else newcursor = 1;
- if (curson != newcursor){
+ if (curson != newcursor) {
curs_set(newcursor);
curson = newcursor;
}
@@ -267,86 +286,147 @@ void checkcursor(int mode)
* window. Otherwise the display is confused */
static void restorecursor(int mode, t_win *win_out)
{
- checkcursor(mode);
- if (mode != RAWMODE){
+ checkcursor(mode);
+ if (mode != RAWMODE) {
int x,y;
- getyx(win_out->ptr, y, x);// Must restore input cursor location.
- wmove(win_out->ptr,y, x);
+ getyx(win_out->ptr, y, x); /* Must restore input cursor */
+ wmove(win_out->ptr,y, x); /* location. */
wrefresh(win_out->ptr);
- }
+ }
}
-void redrawscreen(t_win *win_in, int mode, t_win *win_out)
+static void redrawscreen(t_win *win_in, int mode, t_win *win_out)
{
- int y, storedlines;
- if (lastscroll >= topscroll) storedlines = lastscroll - topscroll;
+ int y, storedlines;
+ if (lastscroll >= topscroll)
+ storedlines = lastscroll - topscroll;
else storedlines = lastscroll + SCROLLBACKSIZE - topscroll;
- // Note it's stored lines + 1 extra line for text input.
- for (y=0;(y<=win_in->max_y) && (y <= storedlines);y++){
+ /*
+ * Note it's stored lines + 1 extra line for text input.
+ */
+ for (y=0;(y<=win_in->max_y) && (y <= storedlines);y++) {
int linefrom;
- if (storedlines <= win_in->max_y){// This is a little confusing.
- linefrom = topscroll + y;// The screen scrolls top down at start
+ if (storedlines <= win_in->max_y) {
+ /*
+ * This is a little confusing.
+ * The screen scrolls top down at start
+ */
+ linefrom = topscroll + y;
}
else linefrom = lastscroll -scrolledup - (win_in->max_y) + y;
- while (linefrom < 0)linefrom += SCROLLBACKSIZE;
- while (linefrom >= SCROLLBACKSIZE)linefrom -= SCROLLBACKSIZE;
+ while (linefrom < 0)
+ linefrom += SCROLLBACKSIZE;
+ while (linefrom >= SCROLLBACKSIZE)
+ linefrom -= SCROLLBACKSIZE;
updateline(y,linefrom , win_in, mode, win_out);
}
checkcursor(mode);
}
-void scrolltext(t_win *win_in, int lines, int mode, t_win *win_out)
+static void statline(int mode, char *s)
+{
+ static int oldlen = 0;
+ int l, cnt;
+
+ if (*s == '\0') {
+ if (mode == RAWMODE)
+ return;
+ if (oldlen > 0) {
+ move(0, STATW_STAT);
+ attron(A_REVERSE);
+ for (cnt = STATW_STAT; cnt < COLS; cnt++)
+ addch(' ');
+ oldlen = 0;
+ attroff(A_REVERSE);
+ refresh();
+ }
+ return;
+ }
+ if (mode == RAWMODE) {
+ printf(">>%s\n", s);
+ fflush(stdout);
+ return;
+ }
+ if (COLS <= STATW_STAT)
+ return;
+ l = strlen(s);
+ if (l > COLS - STATW_STAT)
+ l = COLS-STATW_STAT;
+
+ move(0, STATW_STAT);
+
+ attron(A_REVERSE);
+ addnstr(s, l);
+ for (cnt = STATW_STAT+l;cnt < COLS;cnt++)
+ addch(' ');
+ attroff(A_REVERSE);
+ oldlen = l;
+ refresh();
+}
+
+static void scrolltext(t_win *win_in, int lines, int mode, t_win *win_out)
{
int topline, storedlines;
int y;
int wasscrolledup;
- if (scrolledup + lines < 0){
+ if (scrolledup + lines < 0) {
lines = -scrolledup;
}
- // storedlines = Lines stored in buffer.
- if (lastscroll >= topscroll) storedlines = lastscroll - topscroll;
+ /*
+ * storedlines = Lines stored in buffer.
+ */
+ if (lastscroll >= topscroll)
+ storedlines = lastscroll - topscroll;
else storedlines = lastscroll + SCROLLBACKSIZE - topscroll;
- // The max scrolling we can do is the # of lines stored - the
- // screen size.
+ /*
+ * The max scrolling we can do is the # of lines stored - the
+ * screen size.
+ */
topline = storedlines - win_in->max_y;
- if (topline < 0)topline = 0;
- if (scrolledup + lines > topline){
+ if (topline < 0)
+ topline = 0;
+ if (scrolledup + lines > topline) {
lines = topline - scrolledup;
}
- if (!lines)return;
+ if (!lines)
+ return;
wasscrolledup = scrolledup;
scrolledup += lines;
wscrl(win_in->ptr, -lines);
scrollok(win_in->ptr, FALSE);
- if (lines > 0){
- for (y=0;y<lines;y++){
+ if (lines > 0) {
+ for (y=0;y<lines;y++) {
int linefrom = lastscroll -scrolledup - (win_in->max_y) + y;
- while (linefrom < 0)linefrom += SCROLLBACKSIZE;
- while (linefrom >= SCROLLBACKSIZE)linefrom -= SCROLLBACKSIZE;
+ while (linefrom < 0)
+ linefrom += SCROLLBACKSIZE;
+ while (linefrom >= SCROLLBACKSIZE)
+ linefrom -= SCROLLBACKSIZE;
updateline(y,linefrom , win_in, mode, win_out);
}
}
else {
- for (y=-lines-1;y>=0;y--){
+ for (y=-lines-1;y>=0;y--) {
int linefrom = lastscroll -scrolledup - y;
- while (linefrom < 0)linefrom += SCROLLBACKSIZE;
- while (linefrom >= SCROLLBACKSIZE)linefrom -= SCROLLBACKSIZE;
+ while (linefrom < 0)
+ linefrom += SCROLLBACKSIZE;
+ while (linefrom >= SCROLLBACKSIZE)
+ linefrom -= SCROLLBACKSIZE;
updateline(win_in->max_y - y,linefrom , win_in, mode, win_out);
}
-
+
}
scrollok(win_in->ptr, TRUE);
checkcursor(mode);
wrefresh(win_in->ptr);
- if (wasscrolledup && !scrolledup){
+ if (wasscrolledup && !scrolledup) {
statline(mode, "");
}
- else if (!wasscrolledup && scrolledup){
+ else if (!wasscrolledup && scrolledup) {
statline(mode, "Viewing Scrollback");
}
}
-
-void usage(void)
+
+static void usage(void)
{
fprintf(stderr, "usage: call [-8] [-b l|e] [-d] [-h] [-i] [-m s|e] [-p paclen] [-r] [-R]\n");
fprintf(stderr, " [-s mycall] [-S] [-t] [-T timeout] [-v] [-w window] [-W]\n");
@@ -354,20 +434,22 @@ void usage(void)
exit(1);
}
-WINDOW *win;
-const char *key_words[] = { "//",
+static WINDOW *win;
+static const char *key_words[] = { "//",
"#BIN#",
" go_7+. ",
" stop_7+. ",
"\0"
};
-const char *rkey_words[] = {
- // actually restricted keywords are very restrictive
+
+static const char *rkey_words[] = {
+ /*
+ * actually restricted keywords are very restrictive
+ */
"\0"
};
-#define MAXCMDLEN 10
-void convert_cr_lf(char *buf, int len)
+static void convert_cr_lf(char *buf, int len)
{
while (len--) {
if (*buf == '\r')
@@ -376,7 +458,7 @@ void convert_cr_lf(char *buf, int len)
}
}
-void convert_lf_cr(char *buf, int len)
+static void convert_lf_cr(char *buf, int len)
{
while (len--) {
if (*buf == '\n')
@@ -385,7 +467,7 @@ void convert_lf_cr(char *buf, int len)
}
}
-void convert_upper_lower(char *buf, int len)
+static void convert_upper_lower(char *buf, int len)
{
while (len--) {
*buf = tolower(*buf);
@@ -393,9 +475,7 @@ void convert_upper_lower(char *buf, int len)
}
}
-
-
-/* Return the with of this character in character blocks. (Normal = 1, CJK=2)
+/* Return the with of this character in character blocks. (Normal = 1, CJK=2)
* Also for control chracters, return the width of the replacement string.
* */
static int wcwidthcontrol(wchar_t c)
@@ -405,7 +485,8 @@ static int wcwidthcontrol(wchar_t c)
wchar_t *str;
cc.chars[0] = c;
str = wunctrl(&cc);
- if (!str)return 0;
+ if (!str)
+ return 0;
width = wcswidth(str, wcslen(str));
return width;
}
@@ -419,48 +500,61 @@ static wchar_t *wunctrlwchar(wchar_t c)
cc.chars[0] = c;
str = wunctrl(&cc);
return str;
-}
+}
-// For some reason wins_nwstr fails on fedora 12 on some characters
-// but waddnstr works.
-// Draw the entire input buffer when adding text.
-// The fonts that do overstrike fail when written one char at a time.
-void drawinbuf(WINDOW *w, wchar_t *string, int bytes, int cur_pos)
+/*
+ * For some reason wins_nwstr fails on fedora 12 on some characters but
+ * waddnstr works. Draw the entire input buffer when adding text.
+ * The fonts that do overstrike fail when written one char at a time.
+ */
+static void drawinbuf(WINDOW *w, wchar_t *string, int bytes, int cur_pos)
{
int n, x, cursorx, xpos, ypos, width;
- getyx(w, ypos, xpos);// Assume cursor to be at position of current char to draw.
- x = xpos;cursorx = xpos;
+
+ /*
+ * Assume cursor to be at position of current char to draw.
+ */
+ getyx(w, ypos, xpos);
+ x = xpos;
+
+ cursorx = xpos;
// cur_pos-1 = the chracter that was just added.
- for (n=cur_pos-2;n>=0;n--){// Move x position to start of string or 0
+ for (n=cur_pos-2;n>=0;n--) {
+ /*
+ * Move x position to start of string or 0
+ */
width = wcwidthcontrol(string[n]);
- if (x >= width)x -= width;
+ if (x >= width)
+ x -= width;
else x = 0;
}
wmove(w, ypos, x);
- for (n=0;n<bytes;n++){
+ for (n=0;n<bytes;n++) {
char obuf[MAX_BUFLEN];
char *inbuf, *outbuf = obuf;
- size_t insize, outsize = MAX_BUFLEN;
- wchar_t *str;int len, width;
- if (n == cur_pos){
+ size_t insize, outsize = MAX_BUFLEN;
+ int len, width;
+ wchar_t *str;
+
+ if (n == cur_pos) {
cursorx = x;
}
str = wunctrlwchar(string[n]);
- if (!str)continue;
+ if (!str)
+ continue;
inbuf = (char *) str;
len = wcslen(str);
- insize = len * sizeof(wchar_t);
+ insize = len * sizeof(wchar_t);
width = wcswidth(str, len);
iconv(wcharttoutf8, &inbuf, &insize, &outbuf, &outsize);
- waddnstr(w, obuf, MAX_BUFLEN-outsize);
+ waddnstr(w, obuf, MAX_BUFLEN-outsize);
x += width;
}
- if (cur_pos < bytes){
- wmove(w,ypos, cursorx);
+ if (cur_pos < bytes) {
+ wmove(w,ypos, cursorx);
}
}
-
/* Convert linear UNIX date to a MS-DOS time/date pair. */
static char * unix_to_sfbin_date_string(time_t gmt)
@@ -712,57 +806,17 @@ static int connect_to(char *address[])
return fd;
}
-
static void cmd_sigwinch(int sig)
{
signal(SIGWINCH, cmd_sigwinch);
sigwinchsignal = TRUE;
}
-void cmd_intr(int sig)
+static void cmd_intr(int sig)
{
interrupted = TRUE;
}
-void statline(int mode, char *s)
-{
- static int oldlen = 0;
- int l, cnt;
-
- if (*s == '\0') {
- if (mode == RAWMODE)
- return;
- if (oldlen > 0) {
- move(0, STATW_STAT);
- attron(A_REVERSE);
- for (cnt = STATW_STAT; cnt < COLS; cnt++)
- addch(' ');
- oldlen = 0;
- attroff(A_REVERSE);
- refresh();
- }
- return;
- }
- if (mode == RAWMODE) {
- printf(">>%s\n", s);
- fflush(stdout);
- return;
- }
- if (COLS <= STATW_STAT)return;
- l = strlen(s);
- if (l > COLS - STATW_STAT)
- l = COLS-STATW_STAT;
-
- move(0, STATW_STAT);
-
- attron(A_REVERSE);
- addnstr(s, l);
- for (cnt = STATW_STAT+l;cnt < COLS;cnt++)addch(' ');
- attroff(A_REVERSE);
- oldlen = l;
- refresh();
-}
-
WINDOW *opnstatw(int mode, wint * wintab, char *s, int lines, int cols)
{
WINDOW *win;
@@ -905,7 +959,6 @@ int start_ab_download(int mode, WINDOW ** swin, wint * wintab,
strncpy(gp->file_name, STD_DWN_DIR, GP_FILENAME_SIZE-1);
gp->file_name[GP_FILENAME_SIZE-1] = 0;
-
if (crcst == parmsbytes - 1 || datest - crcst > 7
|| namest - datest > 10) {
*swin =
@@ -1150,7 +1203,7 @@ int start_slave_mode(wint * wintab, t_win * win_in, t_win * win_out)
win_out->curs_pos = 0;
win_in->bytes = 0;
win_in->curs_pos = 0;
- redrawscreen(win_in, SLAVEMODE, win_out);
+ redrawscreen(win_in, SLAVEMODE, win_out);
wrefresh(win_in->ptr);
return 0;
}
@@ -1188,7 +1241,7 @@ int start_talk_mode(wint * wintab, t_win * win_in, t_win * win_out)
win_out->curs_pos = 0;
win_in->bytes = 0;
win_out->curs_pos = 0;
- redrawscreen(win_in, TALKMODE, win_out);
+ redrawscreen(win_in, TALKMODE, win_out);
restorecursor(TALKMODE, win_out);
wrefresh(win_in->ptr);
wrefresh(win_out->ptr);
@@ -1251,20 +1304,20 @@ static void reinit_mode(int mode, wint * wintab, t_win * win_in, t_win * win_out
switch (mode) {
case RAWMODE:
break;
- case TALKMODE:// Clear the screen and re-init. Which looks awful.
+ case TALKMODE: /* Clear the screen and re-init. Which looks awful. */
wclear(win_out->ptr);
wrefresh(win_out->ptr);
wclear(win_in->ptr);
- //wrefresh(win_in->ptr);
+ /* wrefresh(win_in->ptr); */
wintab->next = 0;
endwin();
start_screen(call);
start_talk_mode(wintab, win_in, win_out);
restorecursor(mode, win_out);
break;
- case SLAVEMODE:// Also fix me.
+ case SLAVEMODE: /* Also fix me. */
wclear(win_out->ptr);
- //wrefresh(win_out->ptr);
+ /* wrefresh(win_out->ptr); */
wintab->next = 0;
endwin();
start_screen(call);
@@ -1274,156 +1327,168 @@ static void reinit_mode(int mode, wint * wintab, t_win * win_in, t_win * win_out
}
}
-void waddnstrcrcheck(t_win *win_in, char *buf, int bytes, int draw, int mode, t_win *win_out)
+static void waddnstrcrcheck(t_win *win_in, char *buf, int bytes, int draw, int mode, t_win *win_out)
{
- int n;
- for (n=0;n<bytes;n++){
- int width;
- incharbuf[incharbuflen++] = buf[n];
- if (completecharlen(incharbuf) > incharbuflen)continue;
- if (eatchar && (incharbuf[0] == '\n')){
- eatchar = 0;
- incharbuflen = 0;
- continue;
- }
- width = widthchar(incharbuf, incharbuflen, inbufwid);
- eatchar = 0;
- if (draw) {
- if (win_in) waddnstr(win_in->ptr, incharbuf, incharbuflen);
- else write(STDOUT_FILENO, incharbuf, incharbuflen);
- }
- if (incharbuf[0] == '\n')incharbuflen = 0;
- else if (width + inbufwid <= COLS){
- if (inbuflen + incharbuflen <= MAX_BUFLEN){
- memcpy(&inbuf[inbuflen], incharbuf, incharbuflen);
- inbuflen += incharbuflen;
- }
- incharbuflen = 0;
- inbufwid += width;
- if (inbufwid >= COLS)eatchar = 1;
- continue;// Skip to next line when width goes over.
- }
- addscrollline(inbuf, inbuflen);
- if (incharbuflen){
- memcpy(&inbuf[0], incharbuf, incharbuflen);
- inbuflen = incharbuflen;
- incharbuflen = 0;
- inbufwid = width;
- }
- else {
- inbuflen = 0;
- inbufwid = 0;
- }
- if (scrolledup && win_in && win_out){
- scrolledup++; // scrolledup is relative to bottom line
- scrolltext(win_in, 0, mode, win_out);
- }
- }
- if (draw && win_in) wrefresh(win_in->ptr);
-
+ int n;
+ for (n=0;n<bytes;n++) {
+ int width;
+ incharbuf[incharbuflen++] = buf[n];
+ if (completecharlen(incharbuf) > incharbuflen)
+ continue;
+ if (eatchar && (incharbuf[0] == '\n')) {
+ eatchar = 0;
+ incharbuflen = 0;
+ continue;
+ }
+ width = widthchar(incharbuf, incharbuflen, inbufwid);
+ eatchar = 0;
+ if (draw) {
+ if (win_in)
+ waddnstr(win_in->ptr, incharbuf, incharbuflen);
+ else write(STDOUT_FILENO, incharbuf, incharbuflen);
+ }
+ if (incharbuf[0] == '\n')
+ incharbuflen = 0;
+ else if (width + inbufwid <= COLS) {
+ if (inbuflen + incharbuflen <= MAX_BUFLEN) {
+ memcpy(&inbuf[inbuflen], incharbuf, incharbuflen);
+ inbuflen += incharbuflen;
+ }
+ incharbuflen = 0;
+ inbufwid += width;
+ if (inbufwid >= COLS)
+ eatchar = 1;
+ continue; /* Skip to next line when width goes over. */
+ }
+ addscrollline(inbuf, inbuflen);
+ if (incharbuflen) {
+ memcpy(&inbuf[0], incharbuf, incharbuflen);
+ inbuflen = incharbuflen;
+ incharbuflen = 0;
+ inbufwid = width;
+ }
+ else {
+ inbuflen = 0;
+ inbufwid = 0;
+ }
+ if (scrolledup && win_in && win_out) {
+ /*
+ * scrolledup is relative to bottom line
+ */
+ scrolledup++;
+ scrolltext(win_in, 0, mode, win_out);
+ }
+ }
+ if (draw && win_in)
+ wrefresh(win_in->ptr);
}
-
-void writeincom(int mode, int encoding, t_win * win_in, unsigned char buf[], int bytes, t_win *win_out)
+static void writeincom(int mode, int encoding, t_win * win_in, unsigned char buf[], int bytes, t_win *win_out)
{
- if (mode & RAWMODE) {
- while (write(STDOUT_FILENO, buf, bytes) == -1) {
- if (errno == EWOULDBLOCK || errno == EAGAIN) {
- usleep(100000);
- continue;
- }
- exit(1);
- }
- return;
- } else if (encoding == UTF8ENCODING)
- waddnstrcrcheck(win_in, (char *)buf, bytes,scrolledup == 0, mode, win_out);
- else {
- char *inbuf = (char *) buf, out[MAX_BUFLEN], *outbuf=out;
- size_t insize = bytes, outsize = MAX_BUFLEN;
- iconv(ibm850toutf8, &inbuf, &insize, &outbuf, &outsize);
- waddnstrcrcheck(win_in, out, MAX_BUFLEN-outsize,scrolledup == 0, mode, win_out);
- }
- return;
+ if (mode & RAWMODE) {
+ while (write(STDOUT_FILENO, buf, bytes) == -1) {
+ if (errno == EWOULDBLOCK || errno == EAGAIN) {
+ usleep(100000);
+ continue;
+ }
+ exit(1);
+ }
+ return;
+ } else if (encoding == UTF8ENCODING)
+ waddnstrcrcheck(win_in, (char *)buf, bytes,scrolledup == 0, mode, win_out);
+ else {
+ char *inbuf = (char *) buf, out[MAX_BUFLEN], *outbuf=out;
+ size_t insize = bytes, outsize = MAX_BUFLEN;
+ iconv(ibm850toutf8, &inbuf, &insize, &outbuf, &outsize);
+ waddnstrcrcheck(win_in, out, MAX_BUFLEN-outsize,scrolledup == 0, mode, win_out);
+ }
+ return;
}
+
static void writeincomstr(int mode, int encoding, t_win * win_in, char buf[], t_win *win_out)
{
- int len;
- len = strlen(buf);
- writeincom(mode, encoding, win_in, (unsigned char *)buf, len, win_out);
+ int len;
+ len = strlen(buf);
+ writeincom(mode, encoding, win_in, (unsigned char *)buf, len, win_out);
}
-int outstring(char *buf, wchar_t *string, int bytes, int encoding)
+static int outstring(char *buf, wchar_t *string, int bytes, int encoding)
{
- char *inbuf = (char *) string, *outbuf = buf;
- size_t insize = bytes * sizeof(wchar_t), outsize = MAX_BUFLEN-1;
- if (encoding == UTF8ENCODING){
- iconv(wcharttoutf8, &inbuf, &insize, &outbuf, &outsize);
- }
- else {
- iconv(wcharttoibm850, &inbuf, &insize, &outbuf, &outsize);
-
- }
- buf[(MAX_BUFLEN-1)-outsize] = '\0';
- return (MAX_BUFLEN-1)-outsize;
+ char *inbuf = (char *) string, *outbuf = buf;
+ size_t insize = bytes * sizeof(wchar_t), outsize = MAX_BUFLEN-1;
+ if (encoding == UTF8ENCODING) {
+ iconv(wcharttoutf8, &inbuf, &insize, &outbuf, &outsize);
+ }
+ else {
+ iconv(wcharttoibm850, &inbuf, &insize, &outbuf, &outsize);
+
+ }
+ buf[(MAX_BUFLEN-1)-outsize] = '\0';
+ return (MAX_BUFLEN-1)-outsize;
}
-int getstring(wint * wintab, char text[], char buf[])
+static int getstring(wint * wintab, char text[], char buf[])
{
- wchar_t c;
- int ypos = 0, xpos = 0;
- int bytes = 0;
- wchar_t wbuf[MAX_BUFLEN];
- WINDOW *win = winopen(wintab, 3, COLS, 10, 0, TRUE);
- int done = 0;
-
- wmove(win, 1, 2);
- waddstr(win, text);
- wrefresh(win);
-
- do {
- int r;
- wint_t ci;
- r = get_wch(&ci);
- if (r != ERR) {
- c = (wchar_t) ci;
- if (((r == KEY_CODE_YES) && (c == KEY_BACKSPACE))||
- ((r == OK) && ((c==127)|| (c==8)))){
- getyx(win, ypos, xpos);
- if (bytes > 0) {
- int width, j;
- width = wcwidthcontrol(wbuf[bytes-1]);
- for (j=0;j<width;j++) mvwdelch(win, ypos, xpos-width);
- xpos -= width;
- wmove(win, ypos, xpos);
- bytes--;
- }
- }
- else if (( (r==KEY_CODE_YES) && (c == KEY_ENTER))||
- ( (r == OK) && ((c=='\n') || (c=='\r')))){
- wbuf[bytes++] = (wchar_t) '\n';
- outstring(buf, wbuf, bytes, UTF8ENCODING);
- done = 1;
- }
- else if (r == KEY_CODE_YES); // Put in code for other KEYCODES here
- else if (bytes+2 < MAX_BUFLEN){
- //int width;
- //width = wins_nwchrmy(win, c);
- //getyx(win, ypos, xpos);
- //wmove(win, ypos, xpos+width);
- wbuf[bytes++] = c;
- drawinbuf(win, wbuf, bytes, bytes);
- }
- wrefresh(win);
- }
- }
- while (!done);
- delwin(win);
- winclose(wintab);
- return 0;
-}
+ wchar_t c;
+ int ypos = 0, xpos = 0;
+ int bytes = 0;
+ wchar_t wbuf[MAX_BUFLEN];
+ WINDOW *win = winopen(wintab, 3, COLS, 10, 0, TRUE);
+ int done = 0;
+ wmove(win, 1, 2);
+ waddstr(win, text);
+ wrefresh(win);
-int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
+ do {
+ int r;
+ wint_t ci;
+ r = get_wch(&ci);
+ if (r != ERR) {
+ c = (wchar_t) ci;
+ if (((r == KEY_CODE_YES) && (c == KEY_BACKSPACE))||
+ ((r == OK) && ((c==127)|| (c==8)))) {
+ getyx(win, ypos, xpos);
+ if (bytes > 0) {
+ int width, j;
+ width = wcwidthcontrol(wbuf[bytes-1]);
+ for (j=0;j<width;j++)
+ mvwdelch(win, ypos, xpos-width);
+ xpos -= width;
+ wmove(win, ypos, xpos);
+ bytes--;
+ }
+ }
+ else if (( (r==KEY_CODE_YES) && (c == KEY_ENTER))||
+ ( (r == OK) && ((c=='\n') || (c=='\r')))) {
+ wbuf[bytes++] = (wchar_t) '\n';
+ outstring(buf, wbuf, bytes, UTF8ENCODING);
+ done = 1;
+ }
+ else if (r == KEY_CODE_YES);
+ /*
+ * Put in code for other KEYCODES here
+ */
+ else if (bytes+2 < MAX_BUFLEN) {
+#if 0
+ int width;
+ width = wins_nwchrmy(win, c);
+ getyx(win, ypos, xpos);
+ wmove(win, ypos, xpos+width);
+#endif
+ wbuf[bytes++] = c;
+ drawinbuf(win, wbuf, bytes, bytes);
+ }
+ wrefresh(win);
+ }
+ } while (!done);
+ delwin(win);
+ winclose(wintab);
+
+ return 0;
+}
+
+static int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
int keyesc, int mode, int encoding, t_win *win_in)
{
int out_cnt;
@@ -1512,13 +1577,16 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
return 2;
}
if (((r == KEY_CODE_YES) && (c == KEY_BACKSPACE))||
- ((r == OK) && ((c==127)|| (c==8)))){
- if ((mode == SLAVEMODE) && scrolledup) return 0;
- while(win_out->curs_pos > 0){
- int width;int j;
+ ((r == OK) && ((c==127)|| (c==8)))) {
+ if ((mode == SLAVEMODE) && scrolledup)
+ return 0;
+ while(win_out->curs_pos > 0) {
+ int width;
+ int j;
getyx(win_out->ptr, ypos, xpos);
width = wcwidthcontrol(win_out->string[win_out->curs_pos-1]);
- for (j=0;j<width;j++) mvwdelch(win_out->ptr, ypos, xpos-width);
+ for (j=0;j<width;j++)
+ mvwdelch(win_out->ptr, ypos, xpos-width);
xpos -= width;
wmove(win_out->ptr, ypos, xpos);
if (win_out->curs_pos < win_out->bytes) {
@@ -1527,16 +1595,19 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
&win_out->string[win_out-> curs_pos],
(win_out->bytes -
win_out->curs_pos) * sizeof(wchar_t));
- }
+ }
win_out->bytes--;
win_out->curs_pos--;
- if (width)break;
+ if (width)
+ break;
}
}
else if (( (r==KEY_CODE_YES) && (c == KEY_ENTER))||
- ( (r == OK) && ((c=='\n') || (c=='\r')))){
- if ((mode == SLAVEMODE) && scrolledup) return 0;
- while (win_out->curs_pos < win_out->bytes) { // Move to end of the line
+ ( (r == OK) && ((c=='\n') || (c=='\r')))) {
+ if ((mode == SLAVEMODE) && scrolledup)
+ return 0;
+ while (win_out->curs_pos < win_out->bytes) {
+ /* Move to end of the line */
int width;
width = wcwidthcontrol(win_out->string[win_out->curs_pos]);
win_out->curs_pos++;
@@ -1547,37 +1618,40 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
win_out->string[win_out->bytes++] = (wchar_t) '\n';
wrefresh(win_out->ptr);
out_cnt = outstring(buf, win_out->string, win_out->bytes, encoding);
- if (mode == SLAVEMODE){
+ if (mode == SLAVEMODE) {
char obuf[MAX_BUFLEN];
char *inbuf = (char *)win_out->string, *outbuf = obuf;
- size_t insize = win_out->bytes * sizeof(wchar_t), outsize = MAX_BUFLEN;
+ size_t insize = win_out->bytes * sizeof(wchar_t), outsize = MAX_BUFLEN;
iconv(wcharttoutf8, &inbuf, &insize, &outbuf, &outsize);
- waddnstrcrcheck(win_in, obuf, MAX_BUFLEN-outsize, 0, mode, win_out);
+ waddnstrcrcheck(win_in, obuf, MAX_BUFLEN-outsize, 0, mode, win_out);
}
win_out->bytes = 0;
win_out->curs_pos = 0;
return out_cnt;
}
- else if (r == KEY_CODE_YES){
- switch(c){
- case KEY_LEFT:// Character of 0 width
+ else if (r == KEY_CODE_YES) {
+ switch(c) {
+ case KEY_LEFT: /* Character of 0 width */
while (win_out->curs_pos > 0) {
int width;
win_out->curs_pos--;
width = wcwidthcontrol(win_out->string[win_out->curs_pos]);
getyx(win_out->ptr, ypos, xpos);
wmove(win_out->ptr, ypos, xpos - width);
- if (width)break; // Skip to non-width
+ if (width)
+ break; /* Skip to non-width */
}
break;
case KEY_RIGHT:
{
- int skipped = 0;// Skip over 0 length characters
+ /* Skip over 0 length characters */
+ int skipped = 0;
while (win_out->curs_pos < win_out->bytes) {
int width;
width = wcwidthcontrol(win_out->string[win_out->curs_pos]);
- if (width){
- if (skipped)break;
+ if (width) {
+ if (skipped)
+ break;
skipped = 1;
}
win_out->curs_pos++;
@@ -1608,7 +1682,10 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
}
break;
case KEY_END:
- while (win_out->curs_pos < win_out->bytes) { // Move to end of the line
+ while (win_out->curs_pos < win_out->bytes) {
+ /*
+ * Move to end of the line
+ */
int width;
width = wcwidthcontrol(win_out->string[win_out->curs_pos]);
win_out->curs_pos++;
@@ -1618,21 +1695,25 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
break;
case KEY_DC:{
int skipped = 0;
- if ((mode == SLAVEMODE) && scrolledup) return 0;
- while (win_out->curs_pos < win_out->bytes){
- int width;int j;
+ if ((mode == SLAVEMODE) && scrolledup)
+ return 0;
+ while (win_out->curs_pos < win_out->bytes) {
+ int width;
+ int j;
getyx(win_out->ptr, ypos, xpos);
width = wcwidthcontrol(win_out->string[win_out->curs_pos]);
- if (width){
- if (skipped)break;
+ if (width) {
+ if (skipped)
+ break;
skipped = 1;
}
- for (j=0;j<width;j++) mvwdelch(win_out->ptr, ypos, xpos);
+ for (j=0;j<width;j++)
+ mvwdelch(win_out->ptr, ypos, xpos);
if (win_out->curs_pos + 1 < win_out->bytes) {
memmove(&win_out-> string[win_out->curs_pos],
&win_out->string[win_out-> curs_pos+1],
(win_out->bytes - (win_out->curs_pos+1)) * sizeof(wchar_t));
- }
+ }
win_out->bytes--;
}
break;
@@ -1654,15 +1735,21 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
case '\n':
break;
default:
- if ((mode == SLAVEMODE) && scrolledup) return 0; // Don't try to edit while scrolled up in SLAVEmode.
- // It's just not possible because the cursor is off screen
+ /*
+ * Don't try to edit while scrolled up in SLAVEmode.
+ */
+ if ((mode == SLAVEMODE) && scrolledup)
+ return 0;
+ /*
+ * It's just not possible because the cursor is off screen
+ */
if (win_out->bytes < MAX_BUFLEN ) {
if (win_out->curs_pos < win_out->bytes) {
memmove(&win_out->
string[win_out->curs_pos + 1],
&win_out->string[win_out-> curs_pos],
(win_out->bytes -
- win_out->curs_pos) * sizeof(wchar_t));
+ win_out->curs_pos) * sizeof(wchar_t));
}
win_out->string[win_out->curs_pos] = c;
win_out->bytes++;
@@ -1674,36 +1761,6 @@ int readoutg(t_win * win_out, wint * wintab, menuitem * top, char buf[],
wrefresh(win_out->ptr);
return 0;
}
-void writemsg(char fname[], char caller[])
-{
- char text_row[255];
- char *text_ptr;
- char buf[255];
- FILE *f = fopen(fname, "r");
-
- if (f == NULL) {
- perror(fname);
- return;
- }
- do {
- if (fgets(text_row, 255, f) != 0) {
- text_row[strlen(text_row) - 1] = '\r';
- text_ptr = strchr(text_row, '$');
- if (text_ptr != NULL) {
- strcpy(buf, text_ptr + 2);
- switch (*(text_ptr + 1)) {
- case 'c':
- {
- strcpy(text_ptr, caller);
- strcat(text_ptr, buf);
- }
- }
- }
- write(fd, text_row, strlen(text_row));
- }
- }
- while (!feof(f));
-}
void remotecommand(char buf[], int bytes)
{
@@ -1729,7 +1786,7 @@ void remotecommand(char buf[], int bytes)
}
}
-int compstr(const char st1[], char st2[], int maxbytes)
+static int compstr(const char st1[], char st2[], int maxbytes)
{
int cnt;
for (cnt = 0;
@@ -1746,7 +1803,7 @@ int compstr(const char st1[], char st2[], int maxbytes)
return -1;
}
-int eol(char c)
+static int eol(char c)
{
if (c == '\r' || c == '\n' || c == 0x1A)
@@ -1755,7 +1812,7 @@ int eol(char c)
return FALSE;
}
-int searche_key_words(char buf[], int *bytes, char *parms, int *parmsbytes,
+static int searche_key_words(char buf[], int *bytes, char *parms, int *parmsbytes,
char restbuf[], int *restbytes)
{
static char cmpstr[MAX_CMPSTRLEN];
@@ -1767,7 +1824,6 @@ int searche_key_words(char buf[], int *bytes, char *parms, int *parmsbytes,
int cnt = 0;
int t = 0;
-
if (cmpstrbyte != 0) {
memmove(buf + cmpstrbyte, buf, *bytes);
*bytes += cmpstrbyte;
@@ -1837,7 +1893,7 @@ int searche_key_words(char buf[], int *bytes, char *parms, int *parmsbytes,
return t;
}
-int sevenplname(int mode, WINDOW ** swin, wint * wintab, int *f,
+static int sevenplname(int mode, WINDOW ** swin, wint * wintab, int *f,
int *logfile, char parms[], int parmsbytes, char buf[],
int bytes)
{
@@ -1930,7 +1986,8 @@ int sevenplname(int mode, WINDOW ** swin, wint * wintab, int *f,
return lines;
}
-void statbits(int mode, char stat, int m)
+
+static void statbits(int mode, char stat, int m)
{
if (mode == RAWMODE)
return;
@@ -1941,8 +1998,7 @@ void statbits(int mode, char stat, int m)
refresh();
}
-
-int cmd_call(char *call[], int mode, int encoding)
+static int cmd_call(char *call[], int mode, int encoding)
{
menuitem con[] = {
{"~Reconnect", 'R', M_ITEM, (void *) 0x01},
@@ -2091,7 +2147,9 @@ int cmd_call(char *call[], int mode, int encoding)
continue;
}
if ((errno == EINTR) && sigwinchsignal) {
- // Just process screen resize here.
+ /*
+ * Just process screen resize here.
+ */
reinit_mode(mode, &wintab, &win_in, &win_out, call);
sigwinchsignal = 0;
continue;
@@ -2176,17 +2234,19 @@ int cmd_call(char *call[], int mode, int encoding)
}
switch (com_num) {
case 0:
- {
#if 0
- /*
- FIXME! We should, no: WE MUST be able to turn off
- all remote commands to avoid mail bombs generating
- offensive mails with //e while sucking the BBS
- */
+ /*
+ * FIXME! We should, no: WE MUST be
+ * able to turn off all remote commands
+ * to avoid mail bombs generating
+ * offensive mails with //e while
+ *sucking the BBS
+ */
+ {
remotecommand(parms,
parmsbytes);
-#endif
}
+#endif
break;
case 1:
{
@@ -2248,8 +2308,7 @@ int cmd_call(char *call[], int mode, int encoding)
memcpy(buf, restbuf, restbytes);
bytes = restbytes;
- }
- while (restbytes != 0);
+ } while (restbytes != 0);
}
if (FD_ISSET(STDIN_FILENO, &sock_read)) {
if ((mode & RAWMODE) == RAWMODE) {
@@ -2447,7 +2506,6 @@ int cmd_call(char *call[], int mode, int encoding)
else
file_time = time(0);
-
do {
upllen =
read
@@ -2711,7 +2769,7 @@ int cmd_call(char *call[], int mode, int encoding)
{ */ /* printf("\r%ld bytes sent ", uplpos + bytes); */
sprintf(s, "%ld", uplpos + bytes);
dupdstatw(swin, s, FALSE);
-/* } */
+/* } */
uplpos += bytes;
upldp += bytes;
@@ -2759,7 +2817,7 @@ int cmd_call(char *call[], int mode, int encoding)
}
}
-void iconvclose(void)
+static void iconvclose(void)
{
iconv_close(ibm850toutf8);
iconv_close(wcharttoibm850);
@@ -2771,7 +2829,7 @@ int main(int argc, char **argv)
{
int p;
int mode = TALKMODE;
- int encoding = UTF8ENCODING;// Maybe controversial?
+ int encoding = UTF8ENCODING; /* Maybe controversial? */
setlocale(LC_ALL, "");
if (!isatty(STDIN_FILENO))
@@ -2816,7 +2874,11 @@ int main(int argc, char **argv)
}
break;
case 'r':
- COLS = 80; // This is used to format the scrollback buffer, which is stored in raw
+ /*
+ * This is used to format the scrollback buffer,
+ * which is stored in raw
+ */
+ COLS = 80;
mode = RAWMODE;
break;
case 's':
@@ -2934,7 +2996,6 @@ int main(int argc, char **argv)
break;
}
-
if (!be_silent) {
printf("GW4PTS AX.25 Connect v1.11\n");
fflush(stdout);