level_list.h

/**
*
*/ #ifndef __zlog_level_list_h
#define __zlog_level_list_h zc_arraylist_t *zlog_level_list_new(void);
void zlog_level_list_del(zc_arraylist_t *levels);
void zlog_level_list_profile(zc_arraylist_t *levels, int flag); /* notice */
int zlog_level_list_set(zc_arraylist_t *levels, char *line); /* notice */
zlog_level_t *zlog_level_list_get(zc_arraylist_t *levels, int l); /* notice */
int zlog_level_init_atoi(zc_arraylist_t *level, char *str); #endif

level_list.c

#include <stdio.h>
#include <ctype.h>
#include <errno.h> #include "zc_defs.h"
#include "level.h"
#include "level_list.h" void zlog_level_list_profile(zc_arraylist_t *levels, int flag){
int i;
zlog_level_t *a_level; zc_assert(levels,);
zc_profile(flag, "---level_list[%p]", levels);
zc_arraylist_foreach(levels, i, a_level){
/*skip empty slots*/
if(a_level){
zlog_level_profile(a_level, flag);
}
}
return ;
} //----------------------------------------------------------------------
void zlog_level_list_del(zc_arraylist_t *levels){
zc_assert(levels,);
zc_arraylist_del(levels);
zc_debug("zc_level_list_del[%p]", levels);
return ;
} int zlog_level_list_set(zc_arraylist_t *levels, char *line){
zlog_level_t *a_level;
a_level = zlog_level_new(line);
if(!a_level){
zc_error("zlog_level_new fail");
return -;
}
if(zc_arraylist_set(levels, a_level->int_level, a_level)){
zc_error("zc_arraylist_set fail");
goto err;
}
return ;
err:
zc_error("line[%s]", line);
zlog_level_del(a_level);
return -;
} static int zlog_level_list_set_default(zc_arraylist_t *levels){
return zlog_level_list_set(levels, "* = 0, LOG_INFO")
|| zlog_level_list_set(levels, "DEBUG = 20, LOG_DEBUG")
|| zlog_level_list_set(levels, "INFO = 40, LOG_INFO")
|| zlog_level_list_set(levels, "WARN = 80, LOG_WARNING")
|| zlog_level_list_set(levels, "ERROR = 100, LOG_ERR")
|| zlog_level_list_set(levels, "FATAL = 120, LOG_ALERT")
|| zlog_level_list_set(levels, "UNKNOWN = 254, LOG_ERR")
|| zlog_level_list_set(levels, "! = 255, LOG_INFO");
} zc_arraylist_t *zlog_level_list_new(void){
zc_arraylist_t *levels;
levels = zc_arraylist_new((zc_arraylist_del_fn) *zlog_level_del);
if(!levels){
zc_error("zc_arraylist_new fail");
return NULL;
}
if(zlog_level_list_set_default(levels)){
zc_error("zlog_level_set_default faile");
goto err;
}
//zlog_level_list_profile(levels, ZC_DEBUG);
return levels;
err:
zc_arraylist_del(levels);
return NULL;
} zlog_level_t *zlog_level_list_get(zc_arraylist_t *levels, int l){
zlog_level_t *a_level;
#if 0 #endif a_level = zc_arraylist_get(levels, l);
if(a_level){
return a_level;
}else{
zc_error("l[%d] not in (0, 254), or has no level defined,"
"see configure file define, set to UNKOWN", l);
return zc_arraylist_get(levels, );
}
} //------------------------------------------------------------------
int zlog_level_list_atoi(zc_arraylist_t *levels, char *str){
int i;
zlog_level_t *a_level; if(str == NULL || *str == '\0'){
zc_error("str is [%s], can't find level", str);
return -;
} zc_arraylist_foreach(levels, i, a_level){
if(a_level && STRICMP(str, ==, a_level->str_uppercase)){
return i;
}
} zc_error("str[%s] can't found in level list", str);
return -;
}

测试 test_level_list.c

#include "zc_defs.h"
#include "level.h"
#include "level_list.h" #include "zc_profile.c"
#include "zc_arraylist.c"
#include "level.c"
#include "level_list.c" int main(){
zc_arraylist_t *levels = zlog_level_list_new(); zlog_level_list_set(levels, "FATAL = 110, LOG_ERR"); zlog_level_list_profile(levels, ZC_DEBUG); zlog_level_t *a_level = zlog_level_list_get(levels, ); zlog_level_list_del(levels);
}

zlog学习笔记(level_list)的更多相关文章

  1. zlog学习笔记(mdc)

    mdc.h #ifndef __zlog_mdc_h #define __zlog_mdc_h #include "zc_defs.h" typedef struct zlog_m ...

  2. zlog学习笔记(level)

    level.h /** * */ #ifndef __zlog_level_h #define __zlog_level_h #include "stdio.h" #include ...

  3. zlog学习笔记(zc_hashtable)

    zc_hashtable.h /** * hashtable */ #ifndef __zc_hashtable_h #define __zc_hashtable_h typedef struct z ...

  4. zlog学习笔记(zc_arraylist)

    zc_arraylist.h /** * 实现类似列表的功能 * */ #ifndef __zc_arraylist_h #define __zc_arraylist_h #define ARRAY_ ...

  5. zlog学习笔记(zc_profile)

    zc_profile.h #ifndef __zlog_profile_h #define __zlog_profile_h #define EMPTY() #define zc_assert(exp ...

  6. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  7. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  8. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  9. 2014年暑假c#学习笔记目录

    2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...

随机推荐

  1. android bitmap和数据流的互转

    Bitmap aa = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); InputStream input ...

  2. c中的关键字、标识符、注释

    一. 学习语法之前的提醒 1) C语言属于一门高级语言,其实,所有高级语言的基本语法组成部分都是一样的,只是表现形式不太一样 2) 就好像亚洲人和非洲人,大家都有人类的结构:2只 手.2只脚.1个头, ...

  3. NSDate 格式化 NSDate to NSString

    NSLog(@"%@",[NSDate stringFromDate:[NSDate date] withFormat:@"yyyyMMdd__HH_mm_ss_zzz& ...

  4. AOP的实现机制

    1 AOP各种的实现 AOP就是面向切面编程,我们可以从几个层面来实现AOP. 在编译器修改源代码,在运行期字节码加载前修改字节码或字节码加载后动态创建代理类的字节码,以下是各种实现机制的比较. 类别 ...

  5. 未能正确加载 ”Microsoft.VisualStudio.Editor.Implementation.EditorPackate“包错误解决方法

    今天新来一个同事,帮他搭建开发环境.发现他的vs2012一打开就报错. 错误提示: 未能正确加载 "Microsoft.VisualStudio.Editor.Implementation. ...

  6. C#复习⑨(附带C#参考答案仅限参考)

    C#复习⑨ 2016年6月22日 14:28 C#考试题&参考答案:http://pan.baidu.com/s/1sld4K13 Main XML Comments & Pointe ...

  7. 详解MySQL的用户密码过期功能

    这篇文章主要为大家详细介绍了MySQL的用户密码过期功能的相关资料,需要的朋友可以参考下   Payment Card Industry,即支付卡行业,PCI行业表示借记卡.信用卡.预付卡.电子钱包. ...

  8. NPOI对Excel的操作(Sheet转DataTable、List<T>)

    通过NPOI对Excel进行操作,这里主要是读取的操作.封装到ExcelHelper操作类中. 1 using System.Collections.Generic; 2 using NPOI.HSS ...

  9. Tomcat:基于Apache+Tomcat的集群搭建

    根据Tomcat的官方文档说明可以知道,使用Tomcat配置集群需要与其它Web Server配合使用才可以完成,典型的有Apache和IIS. 这里就使用Apache+Tomcat方式来完成基于To ...

  10. 使用Source Safe for SQL Server解决数据库版本管理问题(转载)

    简介 在软件开发过程中,版本控制是一个广为人知的概念.因为一个项目可能会需要不同角色人员的参与,通过使用版本控制软件,可以使得项目中不同角色的人并行参与到项目当中.源代码控制使得代码可以存在多个版本, ...