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. 终极指南:如何为iOS8应用制作预览视频

    最近一两个月里,苹果的世界里出现了很多新东西,比如屏幕更大的iPhone 6,可穿戴设备Apple Watch,iOS8,以及旨在帮助用户更好的发现应用的App Store改版等等. 说到App St ...

  2. 面试题:“你能不能谈谈,java GC是在什么时候,对什么东西,做了什么事情?”

    面试题目:地球人都知道,Java有个东西叫垃圾收集器,它让创建的对象不需要像c/cpp那样delete.free掉,你能不能谈谈: GC是在什么时候,对什么东西,做了什么事情? 以上算是三个问题,下面 ...

  3. Zend Studio 12 安装及破解

    安装: 1.下载最新版本Zend Studio:http://downloads.zend.com/studio-eclipse/12.0.0/ZendStudio-12.0.0-win32.win3 ...

  4. PHP中设置时区方法小结

    找到原因后,在网上搜索到了一些关于PHP的时区设置方法: 1.修改php.ini,在php.ini中找到data.timezone =去掉它前面的;号,然后设置data.timezone = “Asi ...

  5. mvc 开发razor模式注意事项

    1 情景为:mvc模式开发的.cshtml画面,里面有@if语句,if语句里面还有其他的代码,画面总是报错:if模块中没有对应的"}",什么问题 跟踪了之后,判定cs语句没问题,那 ...

  6. Windows下好用到必须开机自启的小工具

    折腾过linux,黑苹果,最后还是回到了盖茨大叔的windows.得出的结论是,日常使用的话,折腾Linux还不如把精力去拿去折腾windows.分享下折腾的成果,介绍下一些很不错的小工具.     ...

  7. Java 设计模式(示例代码)

    Java 设计模式 项目实例:https://github.com/windwant/java-design-pattern

  8. column 'id' in field list is ambiguous

    column 'id' in field list is ambiguous  这个错误,是因为你查询语句里面有id字段的时候,没有说明是哪个表的id字段,应该加上表名(或者别名)来区分.

  9. ubuntu14.04下的NVIDIA Tesla K80显卡驱动的安装教程

    搞深度学习如何能够不与浑身是“核”的显卡打交道呢? 人工智能的兴起除了数据量的大量提升,算法的不断改进,计算能力的逐步提高,还离不开软件基础设施的逐步完善.当下的主流的深度学习工具软件无论是Caffe ...

  10. 成为 Linux 终端高手的七种武器 之七 条件执行&&

    7.条件执行 Bash 也可以连续执行两条命令。 第二条命令仅在第一条命令成功执行后才会开始执行。如要如此,你可以通过键入“&&”,也就是两个“&”字符进行分隔,在同一行输入两 ...