38 #include "contiki-conf.h"
40 #include "contiki-net.h"
44 #include "ctk/ctk-textentry-cmdline.h"
49 #define LOG_WIDTH IRC_CONF_WIDTH
54 #ifdef IRC_CONF_HEIGHT
55 #define LOG_HEIGHT IRC_CONF_HEIGHT
60 PROCESS(irc_process,
"IRC client");
62 AUTOSTART_PROCESSES(&irc_process);
65 unsigned char menuitem_setup, menuitem_quit;
68 static char log[LOG_WIDTH * LOG_HEIGHT];
69 static char line[LOG_WIDTH*2];
70 static struct ctk_label loglabel =
71 {
CTK_LABEL(0, 0, LOG_WIDTH, LOG_HEIGHT, log)};
72 static struct ctk_textentry lineedit =
73 {CTK_TEXTENTRY_INPUT(0, LOG_HEIGHT, LOG_WIDTH - 2, 1, line,
sizeof(line) - 1,
74 ctk_textentry_cmdline_input)};
77 #define SETUPWINDOW_WIDTH 18
78 #define SETUPWINDOW_HEIGHT 9
79 #define MAX_SERVERLEN 32
80 #define MAX_NICKLEN 16
81 static uip_ipaddr_t serveraddr;
82 static char server[MAX_SERVERLEN + 1];
83 static char nick[MAX_NICKLEN + 1];
84 static struct ctk_label serverlabel =
86 static struct ctk_textentry serverentry =
89 static struct ctk_label nicklabel =
90 {
CTK_LABEL(1, 4, 13, 1,
"IRC nickname: ")};
91 static struct ctk_textentry nickentry =
94 static struct ctk_button connectbutton =
100 static struct ircc_state s;
114 ircc_text_output(
struct ircc_state *s,
char *text1,
char *text2)
128 memcpy(log, &log[LOG_WIDTH], LOG_WIDTH * (LOG_HEIGHT - 1));
130 ptr = &log[LOG_WIDTH * (LOG_HEIGHT - 1)];
131 len = (int)strlen(text1);
133 memset(ptr, 0, LOG_WIDTH);
134 strncpy(ptr, text1, LOG_WIDTH);
135 if(len < LOG_WIDTH) {
139 if(LOG_WIDTH - len > 0) {
140 strncpy(ptr + 1, text2, LOG_WIDTH - len);
146 if((
int)strlen(text2) > LOG_WIDTH - len) {
147 memcpy(log, &log[LOG_WIDTH], LOG_WIDTH * (LOG_HEIGHT - 1));
148 strncpy(&log[LOG_WIDTH * (LOG_HEIGHT - 1)],
149 text2 + LOG_WIDTH - len, LOG_WIDTH);
159 for(i = 0; i < (int)strlen(line); ++i) {
165 if(strncmp(&line[1],
"join", 4) == 0) {
166 ircc_join(&s, &line[6]);
167 ircc_text_output(&s,
"Join", &line[6]);
168 }
else if(strncmp(&line[1],
"list", 4) == 0) {
170 ircc_text_output(&s,
"Channel list",
"");
171 }
else if(strncmp(&line[1],
"part", 4) == 0) {
173 ircc_text_output(&s,
"Leaving channel",
"");
174 }
else if(strncmp(&line[1],
"quit", 4) == 0) {
176 }
else if(strncmp(&line[1],
"me", 2) == 0) {
177 petsciiconv_toascii(&line[4], strlen(&line[4]));
178 ircc_actionmsg(&s, &line[4]);
179 ircc_text_output(&s,
"*", &line[4]);
181 ircc_text_output(&s, &line[1],
"Not implemented");
185 petsciiconv_toascii(line,
sizeof(line) - 1);
186 ircc_msg(&s, &line[0]);
187 ircc_text_output(&s, nick, line);
192 ircc_sent(
struct ircc_state *s)
202 uip_ipaddr_t *ipaddr;
208 memset(log, 0,
sizeof(log));
215 ctk_window_new(&setupwindow, SETUPWINDOW_WIDTH, SETUPWINDOW_HEIGHT,
236 if(ev == PROCESS_EVENT_EXIT) {
241 if(data == (process_data_t)&lineedit) {
243 }
else if(data == (process_data_t)&connectbutton) {
246 ipaddr = &serveraddr;
250 resolv_query(server);
260 ircc_connect(&s, server, &serveraddr, nick);
267 ircc_text_output(&s, server,
"hostname not found");
270 ircc_connect(&s, server, &serveraddr, nick);
282 if((
struct ctk_menu *)data == &menu) {
283 if(menu.
active == menuitem_setup) {
285 }
else if(menu.
active == menuitem_quit) {
295 ircc_closed(
struct ircc_state *s)
297 ircc_text_output(s, server,
"connection closed");
301 ircc_connected(
struct ircc_state *s)
303 ircc_text_output(s, server,
"connected");
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
char ctk_arch_key_t
The keyboard character type of the system.
#define CTK_TEXTENTRY_CLEAR(e)
Clears a text entry widget and sets the cursor to the start of the text line.
unsigned char ctk_menuitem_add(CC_REGISTER_ARG struct ctk_menu *menu, char *name)
Adds a menu item to a menu.
Hostname is fresh and usable.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
unsigned char active
The currently active menu item.
#define PROCESS_BEGIN()
Define the beginning of a process.
void ctk_menu_add(struct ctk_menu *menu)
Add a menu to the menu bar.
#define CTK_TEXTENTRY(x, y, w, h, text, len)
Instantiating macro for the ctk_textentry widget.
#define NULL
The null pointer.
process_event_t ctk_signal_menu_activate
Emitted when a menu item is activated.
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
process_event_t ctk_signal_keypress
Emitted for every key being pressed.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
CCIF process_event_t resolv_event_found
Event that is broadcasted when a DNS name has been resolved.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
PETSCII/ASCII conversion functions.
#define LOADER_UNLOAD()
Unload a program from memory.
void ctk_menu_new(CC_REGISTER_ARG struct ctk_menu *menu, char *title)
Creates a new menu.
void ctk_menu_remove(struct ctk_menu *menu)
Remove a menu from the menu bar.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
process_event_t ctk_signal_widget_activate
Emitted when a widget is activated (pressed).
process_event_t tcpip_event
The uIP event.
Representation of an individual menu.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Representation of a CTK window.
#define CTK_WIDGET_REDRAW(widg)
Add a widget to the redraw queue.
void process_exit(struct process *p)
Cause a process to exit.