File: xchat-autob5.c

package info (click to toggle)
zh-autoconvert 0.3.16-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,612 kB
  • sloc: ansic: 28,053; perl: 264; makefile: 84; python: 9
file content (133 lines) | stat: -rwxr-xr-x 2,883 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#define USE_PLUGIN

#include <stdio.h>
#include <string.h>
#include "xchat.h"
#include "text.h"
#include "plugin.h"
#include "../../include/hz.h"

extern	struct module *module_find (char *name);

struct	xp_signal	chanmsg_sig;
int	(*chanmsg_next)	(void *, void *, void *, void *, void *, char);
int autob5_chanmsg (struct server *serv, char * channel, char *from, char *text, void *a, char c);

struct	xp_signal	privmsg_sig;
int	(*privmsg_next)	(void *, void *, void *, void *, void *, char);
int autob5_privmsg (struct server *serv, char * channel, char *from, char *text, void *a, char c);

char	*name = "xchat-autob5";
char	*desc = "This is a gb->big5 code convert module for Xchat!";


int	module_init (int ver, struct module *mod, struct session *sess)
{
	/* This check *MUST* be done first */
	if (ver != MODULE_IFACE_VER)
		return 1;
	
	if (module_find (name) != NULL) {
		/* We are already loaded */
		PrintText(sess, "Module xchat-autob5 already loaded\n");
		return 1;
	}
	PrintText(sess, "Loaded module xchat-autob5\n");
	mod->name = name;
	mod->desc = desc;
		
	chanmsg_sig.signal = XP_CHANMSG;
	chanmsg_sig.callback = XP_CALLBACK(autob5_chanmsg);
	chanmsg_sig.naddr = &chanmsg_next;
	chanmsg_sig.mod = mod;

	privmsg_sig.signal = XP_PRIVMSG;
	privmsg_sig.callback = XP_CALLBACK(autob5_privmsg);
	privmsg_sig.naddr = &privmsg_next;
	privmsg_sig.mod = mod;
	
	hook_signal(&chanmsg_sig);
	hook_signal(&privmsg_sig);
	gb2big_init();
	
	return 0;
}

void	module_cleanup (struct module *mod, struct session *sess)
{
	PrintText(sess, "xchat-autob5 module unloading\n");
}

int	autob5_chanmsg (struct server *serv, char *channel, char *from, char *text, void *a, char c)
{
	int len;
	int msg_code;

	char * ps;
#ifdef DEBUG
	struct session *sess;
	char msg[512];

	sess= serv->front_session;
#endif
	len=strlen(text);

#ifdef DEBUG
	snprintf(msg,510, "String: %s, Len: %d",text,len);
	PrintText(sess, msg);
#endif
	msg_code=j_code(text,len);
	switch(msg_code){
		case BIG5_CODE:
#ifdef DEBUG
			PrintText(sess," GB\n");
#endif
			break;
		case GB_CODE:
			ps=gb2big(text,&len,0);
			strncpy(text,ps,len);
#ifdef DEBUG
			PrintText(sess," Big\n");
#endif
			break;
	}

	XP_CALLNEXT(chanmsg_next, serv, channel, from, text, a, c);
}

int	autob5_privmsg (struct server *serv, char *from, char *ip, char *text, void *a, char c)
{
	int len;
	int msg_code;

	char * ps;
#ifdef DEBUG
	struct session *sess;
	char msg[512];

	sess= serv->front_session;
#endif
	len=strlen(text);

#ifdef DEBUG
	snprintf(msg,510, "String: %s, Len: %d",text,len);
	PrintText(sess, msg);
#endif
	msg_code=j_code(text,len);
	switch(msg_code){
		case BIG5_CODE:
#ifdef DEBUG
			PrintText(sess," GB\n");
#endif
			break;
		case GB_CODE:
			ps=gb2big(text,&len,0);
			strncpy(text,ps,len);
#ifdef DEBUG
			PrintText(sess," Big\n");
#endif
			break;
	}

	XP_CALLNEXT(privmsg_next, serv, from, ip, text, a, c);
}