Date: Thu, 12 Oct 1995 15:02:36 +0200 (UKR) From: Sergey Shkonda <serg@bcs1.bcs.zaporizhzhe.ua> To: hackers@freebsd.org Cc: eugen@zgik.zaporizhzhe.ua (Eugen Polovnikow) Subject: Patch to talk client Message-ID: <199510121302.AA07744@bcs1.bcs.zaporizhzhe.ua>
next in thread | raw e-mail | index | archive | help
There are patch to talk client for support 8-bit
talking (for example in russian language)
--
Sergey Shkonda serg@bcs1.bcs.zaporizhzhe.ua
****************************************************
****************************************************
Sample.tbl:
# Syntax:
#
# from:
# [ table from remote to local ]
#
# to:
# [ table from local to remote ]
from:
0x7e 0x5e # "~" -> "^"
0x60 0x27 # "`" -> "'"
to:
0x5e 0x7e # "^" -> "~"
0x27 0x60 # "'" -> "`"
****************************************************
****************************************************
Only in talk.n: Sample.tbl
diff -c -r talk.o/display.c talk.n/display.c
*** talk.o/display.c Thu Oct 12 14:43:51 1995
--- talk.n/display.c Thu Oct 12 14:43:42 1995
***************
*** 144,150 ****
text++;
continue;
}
! if (!isprint(*text) && *text != '\t') {
waddch(win->x_win, '^');
getyx(win->x_win, win->x_line, win->x_col);
cch = (*text & 63) + 64;
--- 144,151 ----
text++;
continue;
}
! /* if (!isprint(*text) && *text != '\t') { */
! if ((*text<' ') && *text != '\t') {
waddch(win->x_win, '^');
getyx(win->x_win, win->x_line, win->x_col);
cch = (*text & 63) + 64;
diff -c -r talk.o/get_names.c talk.n/get_names.c
*** talk.o/get_names.c Thu Oct 12 14:43:51 1995
--- talk.n/get_names.c Thu Oct 12 14:43:42 1995
***************
*** 60,66 ****
register char *cp;
if (argc < 2 ) {
! printf("Usage: talk user [ttyname]\n");
exit(-1);
}
if (!isatty(0)) {
--- 60,66 ----
register char *cp;
if (argc < 2 ) {
! printf("Usage: talk [-t table] user [ttyname]\n");
exit(-1);
}
if (!isatty(0)) {
diff -c -r talk.o/io.c talk.n/io.c
*** talk.o/io.c Thu Oct 12 14:43:51 1995
--- talk.n/io.c Thu Oct 12 14:43:42 1995
***************
*** 44,51 ****
--- 44,53 ----
#include <sys/ioctl.h>
#include <sys/time.h>
#include <stdio.h>
+ #include <limits.h>
#include <errno.h>
#include <string.h>
+ #include <ctype.h>
#include "talk.h"
#define A_LONG_TIME 10000000
***************
*** 53,64 ****
input */
/*
* The routine to do the actual talking
*/
talk()
{
register int read_template, sockt_mask;
! int read_set, nb;
char buf[BUFSIZ];
struct timeval wait;
--- 55,170 ----
input */
/*
+ * the tables for input/oupput mapping
+ */
+ unsigned char to_his_table[256];
+ unsigned char from_his_table[256];
+
+ /*
+ * The routine for init tables
+ */
+ init_tables()
+ {
+ int k;
+ for ( k=0; k<256; k++)
+ to_his_table[k]=from_his_table[k]=k;
+ }
+
+ #define xdigtonum(a) ((toupper(a)>='A')?((toupper(a))-'7'):(a)-'0')
+
+ int
+ _txt_to_char(s)
+ char* s;
+ {
+ int k;
+ if(!isdigit(*s))
+ return -1;
+ if((s[0]=='0') && (s[1]=='x')) /* hex notation */
+ {
+ if(!isxdigit(s[2]) || !isxdigit(s[3]))
+ return 0;
+ k=xdigtonum(s[2])*16+xdigtonum(s[3]);
+ return k;
+ }
+ k=0;
+ while(isdigit(*s))
+ k=k*10+(*(s++))-'0';
+ return k;
+ }
+
+ /*
+ * The routine for load tables from file
+ */
+
+ load_tables(table)
+ char* table;
+ {
+ FILE* f;
+ int stat;
+ char s[200]; /* no more 200 chars in line */
+ f=fopen(table,"r");
+ if (!f)
+ {
+ char fname[PATH_MAX];
+ strcpy(fname,"/usr/share/misc/");
+ strcat(fname,table);
+ f=fopen(fname,"r");
+ }
+ if (!f)
+ return 0;
+ stat=0; /* begin read table */
+ while (!feof(f))
+ {
+ int ich,och,k;
+ if (!fgets(s,200,f))
+ s[0]=0;
+ if(!s[0])
+ continue;
+ if(s[strlen(s)-1]=='\n')
+ s[strlen(s)-1]=0;
+ if((s[0]=='#')||(!s[0])) /* comment or void line */
+ continue;
+ if(!strncmp(s,"from:",5))
+ {
+ stat=1;
+ continue;
+ }
+ if(!strncmp(s,"to:",3))
+ {
+ stat=2;
+ continue;
+ }
+ ich=_txt_to_char(s);
+ /* search second parameter */
+ for( k=1; s[k] && !( isdigit(s[k]) &&
+ ((s[k-1]==' ') || (s[k-1]=='\t'))
+ ); k++) { }
+ if (!stat||(ich>=0x100)||(ich<0)||(!s[k]) ) /* error */
+ {
+ init_tables();
+ break;
+ }
+ och=_txt_to_char(s+k);
+ if((och>=0x100) || (och<0))
+ {
+ init_tables();
+ break;
+ }
+ if (stat==1) /* _from_ mapping */
+ from_his_table[ich]=och;
+ else /* _to_ mapping */
+ to_his_table[ich]=och;
+ }
+ fclose(f);
+ }
+
+ /*
* The routine to do the actual talking
*/
talk()
{
register int read_template, sockt_mask;
! int read_set, nb, k;
char buf[BUFSIZ];
struct timeval wait;
***************
*** 92,97 ****
--- 198,206 ----
message("Connection closed. Exiting");
quit();
}
+ /* translate using from_his_table[] */
+ for (k=0; k<nb; k++)
+ buf[k]=from_his_table[((unsigned char)buf[k])];
display(&his_win, buf, nb);
}
if (read_set & STDIN_MASK) {
***************
*** 103,108 ****
--- 212,220 ----
nb = read(0, buf, nb);
display(&my_win, buf, nb);
/* might lose data here because sockt is non-blocking */
+ /* translate using to_his_table[] */
+ for (k=0; k<nb; k++)
+ buf[k]=to_his_table[((unsigned char)buf[k])];
write(sockt, buf, nb);
}
}
diff -c -r talk.o/talk.1 talk.n/talk.1
*** talk.o/talk.1 Thu Oct 12 14:43:51 1995
--- talk.n/talk.1 Thu Oct 12 14:43:41 1995
***************
*** 31,36 ****
--- 31,40 ----
.\"
.\" @(#)talk.1 8.1 (Berkeley) 6/6/93
.\"
+ .\"
+ .\" (C) Russian mapping apply by Sergey Shkonda
+ .\" Zaporozhye, 1995
+ .\"
.Dd June 6, 1993
.Dt TALK 1
.Os BSD 4.2
***************
*** 39,44 ****
--- 43,49 ----
.Nd talk to another user
.Sh SYNOPSIS
.Nm talk
+ .Op Ar -t table
.Ar person
.Op Ar ttyname
.Sh DESCRIPTION
***************
*** 68,73 ****
--- 73,86 ----
.Ar ttyname
is of the form
.Ql ttyXX .
+ .It Ar -t table
+ If you wish to talk to a user on host with another character coding
+ you can define translation table. (For example you have
+ .Ar Code Page 866
+ character coding and his have
+ .Ar KOI8
+ characters coding). This file can be found in current directory or in
+ .Ar /usr/share/misc .
.El
.Pp
When first called,
diff -c -r talk.o/talk.c talk.n/talk.c
*** talk.o/talk.c Thu Oct 12 14:43:51 1995
--- talk.n/talk.c Thu Oct 12 14:43:42 1995
***************
*** 63,68 ****
--- 63,76 ----
int argc;
char *argv[];
{
+ init_tables();
+ if (argc > 2)
+ if (!strcmp(argv[1],"-t"))
+ {
+ load_tables(argv[2]);
+ argv+=2;
+ argc-=2;
+ }
get_names(argc, argv);
check_writeable();
init_display();
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510121302.AA07744>
