wangzhengquan
2020-07-24 0c5b70952e7f290e901bf1434ebcb8bc092eb3a4
commit
1个文件已删除
3个文件已添加
2个文件已修改
148 ■■■■ 已修改文件
test/Makefile 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/protocle_parse 补丁 | 查看 | 原始文档 | blame | 历史
test/protocle_parse.c 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_queue/Makefile 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_queue/test 补丁 | 查看 | 原始文档 | blame | 历史
test_queue/test.c 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/Makefile
New file
@@ -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)
# 如果包A 引用包B, B 要放在 A 后面
clean:
    rm -f $(TEMPFILES) $(PROGS)
test/protocle_parse
Binary files differ
test/protocle_parse.c
New file
@@ -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");
 }
}
test_queue/Makefile
@@ -14,7 +14,7 @@
include $(ROOT)/Make.defines.$(PLATFORM)
 
PROGS = dgram_socket_test
PROGS = test
build: $(PROGS)
test_queue/test
Binary files differ
test_queue/test.c
File was deleted