intirain пре 4 година
родитељ
комит
8c3c7f0796
4 измењених фајлова са 21 додато и 30 уклоњено
  1. 3 3
      Makefile
  2. 5 5
      include/vcc/vcc.h
  3. 1 1
      include/vcc/version.h
  4. 12 21
      main.c

+ 3 - 3
Makefile

@@ -1,11 +1,11 @@
 VCCD_MAJOR 		= 0
-VCCD_MINOR 		= 2
+VCCD_MINOR 		= 3
 VCCD_PATCH 		= 0
 VCCD_COMPILE_TIME 	= $(shell date)
 VCCD_COMPILE_BY 	= $(shell whoami)
 
-srcs 			= main.c 
-objs 			= main.o 
+srcs 			= main.c vcc.c pretty.c 
+objs 			= main.o vcc.o pretty.o 
 target 			= vcc 
 CFLAGS 			= -Wall -Werror -Iinclude -g 
 MAKEFLAGS 		= --no-print-directory

+ 5 - 5
include/vcc/vcc.h

@@ -1,19 +1,19 @@
-/* vccd/include/vcc/vcc.h 
+/* vcc/include/vcc/vcc.h 
  * 
- * This file is part of vccd. 
+ * This file is part of vcc. 
  * 
- * vccd is free software: you can redistribute it and/or modify 
+ * vcc is free software: you can redistribute it and/or modify 
  * it under the terms of the GNU General Public License as published by 
  * the Free Software Foundation, either version 3 of the License, or 
  * (at your option) any later version. 
  * 
- * vccd is distributed in the hope that it will be useful, 
+ * vcc is distributed in the hope that it will be useful, 
  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  * GNU General Public License for more details. 
  * 
  * You should have received a copy of the GNU General Public License 
- * along with vccd. If not, see <https://www.gnu.org/licenses/>
+ * along with vcc. If not, see <https://www.gnu.org/licenses/>
  */ 
 
 

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.2.0 Sun Mar  6 08:14:22 CST 2022 root"
+#define VCCD_VERSION "vccd 0.3.0 Sun Mar  6 12:54:48 CST 2022 root"

+ 12 - 21
main.c

@@ -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);