From 0c5b70952e7f290e901bf1434ebcb8bc092eb3a4 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期五, 24 七月 2020 14:55:28 +0800
Subject: [PATCH] commit

---
 test_queue/test       |    0 
 test/protocle_parse.c |   85 ++++++++++++++++++++++++++++
 /dev/null             |   35 -----------
 test/Makefile         |   26 ++++++++
 test_queue/Makefile   |    2 
 test/protocle_parse   |    0 
 6 files changed, 112 insertions(+), 36 deletions(-)

diff --git a/test/Makefile b/test/Makefile
new file mode 100755
index 0000000..d6fa6d8
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,26 @@
+#
+# Makefile for common library.
+#
+ROOT=..
+LDLIBS+=-Wl,-rpath=$(ROOT)/lib:$(ROOT)/build/lib
+# 寮�婧愬伐鍏峰寘璺緞
+LDDIR +=  -L$(ROOT)/lib -L$(ROOT)/build/lib
+# 寮�婧愬伐鍏峰寘
+LDLIBS += -lshm_queue -lusgcommon -lpthread
+
+INCLUDE += -I$(ROOT)/build/include
+
+PLATFORM=$(shell $(ROOT)/systype.sh)
+include $(ROOT)/Make.defines.$(PLATFORM)
+
+ 
+PROGS = protocle_parse
+
+build: $(PROGS)
+
+# test1: $(LIBCOMMON)
+
+# 濡傛灉鍖匒 寮曠敤鍖匓锛� B 瑕佹斁鍦� A 鍚庨潰
+
+clean:
+	rm -f $(TEMPFILES) $(PROGS)
diff --git a/test/protocle_parse b/test/protocle_parse
new file mode 100755
index 0000000..6b06605
--- /dev/null
+++ b/test/protocle_parse
Binary files differ
diff --git a/test/protocle_parse.c b/test/protocle_parse.c
new file mode 100644
index 0000000..a64a4b6
--- /dev/null
+++ b/test/protocle_parse.c
@@ -0,0 +1,85 @@
+#include "usg_common.h"
+#include "usg_typedef.h"
+
+#define ACTION_LIDENTIFIER "<**"
+#define ACTION_RIDENTIFIER "**>"
+#define TOPIC_LIDENTIFIER '{'
+#define TOPIC_RIDENTIFIER '}'
+
+int parse_pubsub_topic(char *str, char **_action, size_t *_action_len,  char **_topic, size_t *_topic_len) {
+ char *ptr = str;
+ char *str_end_ptr = str + strlen(str);
+ char *action_start_ptr;
+ char *action_end_ptr;
+ size_t action_len = 0;
+
+ char *topic_start_ptr;
+ char *topic_end_ptr;
+ size_t topic_len = 0;
+
+ // if (strlen(identifier) > strlen(str)) {
+ //  return 0;
+ // }
+
+ if (strncmp(ptr, ACTION_LIDENTIFIER, strlen(ACTION_LIDENTIFIER)) == 0) {
+  ptr += strlen(ACTION_LIDENTIFIER);
+  action_start_ptr = ptr;
+  while(strncmp(++ptr, ACTION_RIDENTIFIER, strlen(ACTION_RIDENTIFIER)) != 0) {
+    if(ptr >= str_end_ptr) {
+      return 0;
+    }
+  }
+// printf("%s\n", ptr);
+  action_end_ptr = ptr;
+  action_len = action_end_ptr - action_start_ptr;
+  ptr += strlen(ACTION_RIDENTIFIER);
+// printf("%s\n", ptr);
+// printf("%s\n", str_end_ptr-1);
+  if( (*ptr == TOPIC_LIDENTIFIER) && (*(str_end_ptr-1) == TOPIC_RIDENTIFIER) ) {
+    topic_start_ptr = ptr;
+    topic_end_ptr = str_end_ptr;
+    topic_len = topic_end_ptr - topic_start_ptr + 1;
+    ptr++;
+    // while(*(++ptr) != '}') {
+    //   length++;
+    // }
+  } else {
+    return 0;
+  }
+ } else {
+  return 0;
+ }
+
+ char *topic = (char *)calloc(1, topic_len+1);
+ strncpy(topic, topic_start_ptr, topic_len);
+ *_topic = topic;
+ *_topic_len = topic_len;
+
+ char *action = (char *)calloc(1, action_len+1);
+ strncpy(action, action_start_ptr, action_len);
+ *_action = action;
+ *_action_len = action_len;
+
+
+ return 1;
+}
+
+int main() {
+ char *action;
+ size_t action_len;
+ char *topic;
+ size_t topic_len;
+  
+ char *str = "<**subsdf**>{缁忔祹}";
+ if(parse_pubsub_topic(str, &action, &action_len, &topic, &topic_len)) {
+  printf("action:%s\n", action);
+  printf("topic:%s\n", topic);
+  free(action);
+  free(topic);
+ } else {
+  printf("===========error==============\n");
+ }
+
+
+ 
+}
\ No newline at end of file
diff --git a/test_queue/Makefile b/test_queue/Makefile
index 643b72d..1a3a201 100755
--- a/test_queue/Makefile
+++ b/test_queue/Makefile
@@ -14,7 +14,7 @@
 include $(ROOT)/Make.defines.$(PLATFORM)
 
  
-PROGS = dgram_socket_test
+PROGS = test
 
 build: $(PROGS)
 
diff --git a/test_queue/test b/test_queue/test
index 5e82a18..bdad69e 100755
--- a/test_queue/test
+++ b/test_queue/test
Binary files differ
diff --git a/test_queue/test.c b/test_queue/test.c
deleted file mode 100644
index 99e3289..0000000
--- a/test_queue/test.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "test.h"
-#define MKEY 0x2222
-int testmatshm() {
-
-  int shmid = -1;
-  void *shmp;
-  shmid = shmget(MKEY, 1024, IPC_CREAT | IPC_EXCL | OBJ_PERMS);
-  if (shmid == -1 && errno == EEXIST) {
-    printf("first create\n");
-    shmid = shmget(MKEY, 0, 0);
-  }
-
-  if (shmid == -1)
-    err_exit(errno, "testmatshm shmget");
-
-  shmp = shmat(shmid, NULL, 0);
-}
-
-typedef struct buf_t { char buf[7]; } buf_t;
-
-void test(int size) {
-  char buf[size];
-  printf("size = %d\n", sizeof(buf));
-}
-
-char msg[10];
-int main() {
-  // testmatshm();
-  // testmatshm();
-
-  // sleep(60);
-
-  // printf("size = %d, msg = %d\n", sizeof(buf_t), sizeof(msg));
-  test(12);
-}
\ No newline at end of file

--
Gitblit v1.8.0