|
|
@@ -36,6 +36,11 @@
|
|
|
|
|
|
#include <vcc/vcc.h>
|
|
|
#include <vcc/version.h>
|
|
|
+#include <vcc/pretty.h>
|
|
|
+
|
|
|
+
|
|
|
+int send_msg(const char *msg, const char *usrname);
|
|
|
+int read_msg(struct vcc_request *buf);
|
|
|
|
|
|
|
|
|
int fd;
|
|
|
@@ -91,23 +96,6 @@ static int init_socket(const char *server_addr) {
|
|
|
return fd;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-static int send_msg(const char *msg, const char *usrname) {
|
|
|
- struct vcc_request req;
|
|
|
-
|
|
|
- strcpy(req.usrname, usrname);
|
|
|
- strcpy(req.msg, msg);
|
|
|
- write(fd, &req, REQ_SIZE);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int read_msg(struct vcc_request *buf) {
|
|
|
- return read(fd, buf, REQ_SIZE);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
void alarm_handler(int nr) {
|
|
|
alarm(1);
|
|
|
|
|
|
@@ -165,8 +153,8 @@ int main(int argc, const char **argv) {
|
|
|
if (!*buf || *(unsigned char *) buf == 0xffu)
|
|
|
continue;
|
|
|
|
|
|
- printf("\n@%s: %s", req.usrname, buf);
|
|
|
- fprintf(stderr, "%s$ ", usrname);
|
|
|
+ pretty_new_msg(req.usrname, buf);
|
|
|
+ pretty_prompt(usrname);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -180,7 +168,7 @@ int main(int argc, const char **argv) {
|
|
|
for (;;) {
|
|
|
memset(buf, 0, MSG_SIZE);
|
|
|
|
|
|
- fprintf(stderr, "%s$ ", usrname);
|
|
|
+ pretty_prompt(usrname);
|
|
|
|
|
|
if (read(0, buf, MSG_SIZE) <= 0) {
|
|
|
fprintf(stderr, "--- read() failed. \n");
|
|
|
@@ -188,7 +176,10 @@ int main(int argc, const char **argv) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (!strcmp(buf, "quit"))
|
|
|
+ if (*buf == '\n')
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (!strcmp(buf, "quit\n"))
|
|
|
break;
|
|
|
|
|
|
send_msg(buf, usrname);
|