gcc -o channeldb channel.c -db -Wall
# -Wall参数等价于执行lint,即:进行代码的静态分析,它可以指出未初始化的变量,未使用的变量
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <db.h>
#include <sys/types.h>
#include <getopt.h>
//define DATABASE "/work/stat/read/newstat/data/userlist/historydb/channel.db"
#define DATABASE "/mnt/disk1/ucshuqi/touch/userlist/historydb/channel.db"
#define YES 1
#define NO 0
/* ViewData Module */
struct ViewData {
int date;
};
void setDate(struct ViewData *data,char *s)
{
assert(data!=NULL && s!= NULL && strlen(s) == 8);
data->date = atoi(s);
}
// the function return YES when query.date >= stored.date
int isHistoryViewInfo(struct ViewData *query , struct ViewData *stored)
{
assert(query != NULL && stored != NULL);
printf("query date is %d , stored date is %d
",query->date, stored->date);
if(query->date >= stored->date)
{
return YES;
}
else
{
return NO;
}
}
void printViewData(struct ViewData *data)
{
printf("print view date : %d
",data->date);
}
/* string helper module */
char *trim(char *s)
{
int i = strlen(s);
for(;i>0;i--)
{
if(s[i]==' ' || s[i]=='
' || s[i]=='