소스 검색

!2 change the time
Merge pull request !2 from 3swordman/master

rain 4 년 전
부모
커밋
e2cb5ef170
6개의 변경된 파일과 34개의 추가작업 그리고 23개의 파일을 삭제
  1. 14 14
      Makefile
  2. 6 1
      include/vcc/pretty.h
  3. 2 2
      include/vcc/version.h
  4. 1 1
      main.c
  5. 7 1
      pretty.c
  6. 4 4
      vcc.c

+ 14 - 14
Makefile

@@ -1,26 +1,26 @@
-VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 3
-VCCD_PATCH 		= 0
-VCCD_STR 		= -rc 
+VCC_MAJOR 		= 1
+VCC_MINOR 		= 3
+VCC_PATCH 		= 0
+VCC_STR 		= -rc 
 
-VCCD_COMPILE_TIME 	= $(shell date)
-VCCD_COMPILE_BY 	= $(shell whoami)
-VCCD_SYMVER 		= vcc $(VCCD_MAJOR).$(VCCD_MINOR).$(VCCD_PATCH)$(VCCD_STR)
+VCC_COMPILE_TIME 	= $(shell date)
+VCC_COMPILE_BY 	= $(shell whoami)
+VCC_SYMVER 		= vcc $(VCC_MAJOR).$(VCC_MINOR).$(VCC_PATCH)$(VCC_STR)
 
 srcs 			= main.c vcc.c pretty.c cmd.c 
 objs 			= main.o vcc.o pretty.o cmd.o 
 target 			= vcc 
-CFLAGS 			= -Wall -Werror -Iinclude -g 
+CFLAGS 			= -std=gnu11 -Wall -Wextra -Wno-unused-parameter -Werror -Iinclude -g 
 MAKEFLAGS 		= --no-print-directory
 
-VCCD_VERSION 		= vccd $(VCCD_MAJOR).$(VCCD_MINOR).$(VCCD_PATCH) \
-		  $(VCCD_COMPILE_TIME) $(VCCD_COMPILE_BY)
+VCC_VERSION 		= VCC $(VCC_MAJOR).$(VCC_MINOR).$(VCC_PATCH) \
+		  $(VCC_COMPILE_TIME) $(VCC_COMPILE_BY)
 
 all : 
-	@echo "$(VCCD_VERSION)"
-	@echo "$(VCCD_SYMVER)"
-	@echo "#define VCCD_VERSION \"$(VCCD_VERSION)\"" > include/vcc/version.h 
-	@echo "#define VCCD_SYMVER \"$(VCCD_SYMVER)\"" >> include/vcc/version.h 
+	@echo "$(VCC_VERSION)"
+	@echo "$(VCC_SYMVER)"
+	@echo "#define VCC_VERSION \"$(VCC_VERSION)\"" > include/vcc/version.h 
+	@echo "#define VCC_SYMVER \"$(VCC_SYMVER)\"" >> include/vcc/version.h 
 	@$(MAKE) $(target) $(MAKEFLAGS)
 
 $(target) : 	$(objs) $(srcs)

+ 6 - 1
include/vcc/pretty.h

@@ -29,15 +29,20 @@
 #define FG_GREEN 		32
 #define FG_YELLOW 		33
 #define FG_BLUE 		34
-#define FG_WHITE 		35
+#define FG_MAGENTA 		35
 #define FG_LIGHTBLUE 		36
+#define FG_WHITE 		37
+#define FG_GRAY 		90
 
 #define BG_BLACK 		40
 #define BG_RED 			41
 #define BG_GREEN 		42
 #define BG_YELLOW 		43
 #define BG_BLUE 		44
+#define BG_MAGENTA 		45
+#define BG_LIGHTBLUE 		46
 #define BG_WHITE 		47
+#define BG_GRAY 		100
 
 #define MODE_DEFAULT 		0
 #define MODE_HIGHLIGHT 		1

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.3.0 2022年 03月 20日 星期日 17:05:54 CST root"
-#define VCCD_SYMVER "vcc 1.3.0-rc "
+#define VCC_VERSION "VCC 1.3.0 Sun 20 Mar 2022 09:20:53 PM CST ubuntu"
+#define VCC_SYMVER "vcc 1.3.0-rc "

+ 1 - 1
main.c

@@ -134,7 +134,7 @@ int main(int argc, const char **argv) {
 	if (unlikely(argc != 1 && argc != 2)) 
 		return usage();
 
-	printf(VCCD_VERSION "\n");
+	printf(VCC_VERSION "\n");
 
 	init_socket(argv[1] ? argv[1] : "124.223.105.230");
 

+ 7 - 1
pretty.c

@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <time.h>
 #include <sys/times.h>
 
 #include <vcc/vcc.h>
@@ -91,10 +92,15 @@ struct theme *current_theme = &theme_def;
 
 
 int pretty_new_msg(char *usrname, char *buf) {
+	time_t time_now;
+	struct tm *tm_now;
+
 	ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
 
 	setcolor(stdout, curr_time);
-	printf("\r[%ld] ", times(NULL));
+	time_now = time(NULL);
+	tm_now = localtime(&time_now);
+	printf("\r[%02d:%02d] ", tm_now->tm_hour, tm_now->tm_min);
 
 	if (unlikely(!strcmp(usrname, "system"))) {
 		setcolor(stdout, curr_sysusername);

+ 4 - 4
vcc.c

@@ -55,8 +55,8 @@ int send_msg(const char *msg, const char *usrname) {
 	req.reqtype = htonl(REQ_MSG_SEND);
 	req.uid = 0;
        
-	strcpy(req.usrname, usrname);
-	strcpy(req.msg, msg);
+	strncpy(req.usrname, usrname, USRNAME_SIZE);
+	strncpy(req.msg, msg, MSG_SIZE);
 	write(fd, &req, REQ_SIZE);
 
 	return 0;
@@ -128,8 +128,8 @@ int vcc_login(char *usrname, char *passwd) {
 	req.magic = htonl(VCC_MAGIC);
 	req.reqtype = htonl(REQ_CTL_LOGIN);
 
-	strcpy(req.usrname, usrname);
-	strcpy(req.msg, passwd);
+	strncpy(req.usrname, usrname, USRNAME_SIZE);
+	strncpy(req.msg, passwd, MSG_SIZE);
 
 	write(fd, &req, REQ_SIZE);