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绘制view的过程

    1 android绘制view的过程简单描述  简单描述可以解释为:计算大小(measure),布局坐标计算(layout),绘制到屏幕(draw):            下面看看每一步的动作到底是 ...

  2. iOS-保存照片或者视频到自定义相薄中以及读取数据

    声明:本文为本人原创作品~转载请注明出处~谢谢配合! 让TableView支持横屏的代码如下: //支持横屏 myTableView.autoresizingMask = UIViewAutoresi ...

  3. 虚拟机安装 Centos6

    1 虚拟机安装 Centos6 1.1 前期配置 New Virtual Machine———Typical(典型安装) 选择镜像文件. 设置文件名,用户名和密码. 设置系统在虚拟机软件的名称, 设置 ...

  4. php中的curl

    /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [ ...

  5. [整理]PHP/HTML混写的四种方式

    PHP作为一款后端语言,为了输出给浏览器让浏览器呈现出来,无可避免的要输出HTML代码,下文介绍下我用过的三种PHP/HTML混编方法 1.单/双引号包围法 这是最初级的方法了,用法就像下面这样 &l ...

  6. MVC数据验证原理及自定义ModelValidatorProvider实现无编译修改验证规则和错误信息

    Asp.net MVC中的提供非常简单易用的数据验证解决方案. 通过System.ComponentModel.DataAnnotations提供的很多的验证规则(Required, StringLe ...

  7. java多线程学习

    在java中要想实现多线程,有两种手段,一种是继续Thread类,另外一种是实现Runable接口. 一.扩展java.lang.Thread类 package com.multithread.lea ...

  8. 模块module

    python中的Module相当于C++中头文件和命名空间的组合体,便于代码的组织,任何一个python代码的文件都是一个Module,都可以被其他模块import import,from...imp ...

  9. IE6-9不支持Textarea的maxlength属性

    给textarea标签添加一个maxlength=200,测试工程师提bug说IE9没起作用.后一测试,发现IE10一下的浏览器均不支持 <textarea maxlength="20 ...

  10. JavaScript获取元素CSS属性

    function getDefaultStyle(obj,attribute){ return obj.currentStyle?obj.currentStyle[attribute]:documen ...