⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-record.c

📁 linux下的电话本的最底层
💻 C
字号:
/*	librecord2 - Record Object manipulation and storage library 2 * *	Authors: YE Nan <nan.ye@orange-ftgroup.com>  *	 *	This software and associated documentation files (the "Software")  *	are copyright (C) 2005 LiPS Linux Phone Standards Forum [FranceTelecom]  *	All Rights Reserved.  * *	A copyright license is hereby granted for redistribution and use of  *	the Software in source and binary forms, with or without modification,  *	provided that the following conditions are met:  *	- Redistributions of source code must retain the above copyright notice,  *	this copyright license and the following disclaimer.  *  - Redistributions in binary form must reproduce the above copyright  * 	notice, this copyright license and the following disclaimer in the  *	documentation and/or other materials provided with the distribution.  *	- Neither the name of LiPS  nor the names of its Members may be used  *	to endorse or promote products derived from the Software without  *	specific prior written permission.  * *	A patent license for any Necessary Claims owned by Members of LiPS Forum  *	to make, have made, use, import, offer to sell, lease and sell or otherwise  *	distribute any implementation compliant with the any specification adopted  *	by the LiPS Forumcan be obtained from the respective Members on reasonable  *	and non-discriminatory terms and conditions and under reciprocity, as  *	regulated in more detail in the Internal Policy of the LiPS Forum.  * *	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER, ITS MEMBERS AND CONTRIBUTORS  *	"AS IS", AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  *	THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE  *	AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER,  *	ITS MEMBERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  *	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  *	OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  *	WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  *	POSSIBILITY OF SUCH DAMAGE.  */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <glib.h>#include <record.h>#define TEMPL_FNAME	"./sample.templ"typedef enum {	REC_FIELD_UID					= 1,	REC_FIELD_NAME				= 3,	REC_FIELD_MOBILE			= 6,	REC_FIELD_NUM_HOME		= 7,	REC_FIELD_NUM_OFFICE	= 8,	REC_FIELD_FAX					= 9,	REC_FIELD_COMPANY			= 10,	REC_FIELD_DEPART			= 11,	REC_FIELD_WEBSITE			= 12,	REC_FIELD_EMAIL				= 13,	REC_FIELD_PICTURE			= 14,	REC_FIELD_RINGTONE		= 15,	REC_FIELD_ADDRESS			= 16,} RecordFields;int main (int argc, char *argv[]){	FieldTemplate * templ = NULL;	Record * record = NULL;		templ = field_template_new_from_file(TEMPL_FNAME);		record = record_new(templ);		/*	 * record_set_field_default() routine. 	 */	if (TRUE)	{		record_set_field_default(record,														 REC_FIELD_MOBILE,														 "13911087820",														 FIELD_SIZE_AUTO);		record_set_field_default(record,														 REC_FIELD_NAME,														 "Nan.Ye",														 FIELD_SIZE_AUTO);		record_set_field_default(record,														 REC_FIELD_NAME,														 NULL,														 FIELD_SIZE_AUTO);	}		/*	 * test record_add_field() routines	 */	if (TRUE)	{		gint i;				for (i = 0; i < 3; i++)		{			guint32 fid = FIELD_ID_INVALID;			gchar * str = NULL;						fid = record_add_field(record, REC_FIELD_COMPANY);						str = g_strdup_printf("company%d", i);			record_set_field(record,											 fid,											 str,											 FIELD_SIZE_AUTO);			g_free(str);						str = g_strdup_printf("Company Label%d", i);			record_set_label(record,											 fid,											 str);			g_free(str);			str = g_strdup_printf("Company Desc%d", i);			record_set_desc(record,											fid,											str);			g_free(str);		}		//		record_add_field(record, REC_FIELD_RINGTONE);	}		/*	 * test record_get_fids() routines.	 */	if (TRUE)	{		Iterator * iter = NULL;				record_add_field(record, REC_FIELD_ADDRESS);		iter = record_get_fids(record,													 REC_FIELD_ADDRESS,													 FID_ALL);		g_print("%s(): fids of REC_FIELD_ADDRESS: ",						__FUNCTION__);		for (iterator_to_first(iter);				 !iterator_at_last(iter);				 iterator_next(iter))		{			g_print("%d ",							*(guint32 *)iterator_current(iter)); 		}		g_print("\n");		iterator_free(iter, TRUE);	}		/*	 * test record_get_fids() routines. special case:	 * FIELD_TEMPLATE_ID_INVALID to retrieve all fids.	 */	if (TRUE)	{		Iterator * iter = NULL;				iter = record_get_fids(record,													 FIELD_TEMPLATE_ID_INVALID,													 FID_ALL);		g_print("%s(): fids of ALL: ",						__FUNCTION__);		for (iterator_to_first(iter);				 !iterator_at_last(iter);				 iterator_next(iter))		{			g_print("%d ",							*(guint32 *)iterator_current(iter)); 		}		g_print("\n");		iterator_free(iter, TRUE);	}			/*	 * test set record_remove_field() routines.	 */	if (TRUE)	{		gboolean ret = FALSE;		Iterator * iter = NULL;				iter = record_get_fids(record,													 REC_FIELD_ADDRESS,													 FALSE);		for (iterator_to_first(iter);				 !iterator_at_last(iter);				 iterator_next(iter))		{			guint32 fid = *(guint32 *)iterator_current(iter);						ret = record_remove_field(record, 																fid);			g_print("%s(): remove field %d ---> %s\n",							__FUNCTION__,							fid,							(ret ? "TRUE" : "FALSE"));		}		iterator_free(iter, TRUE);		ret = record_remove_field(record,															REC_FIELD_COMPANY * 1000 + 1);		g_print("%s(): remove field %d ---> %s\n",						__FUNCTION__,						REC_FIELD_COMPANY * 1000 + 1,						(ret ? "TRUE" : "FALSE"));			ret = record_remove_field(record,															REC_FIELD_COMPANY * 1000 + 4);		g_print("%s(): remove field %d ---> %s\n",						__FUNCTION__,						REC_FIELD_COMPANY * 1000 + 4,						(ret ? "TRUE" : "FALSE"));	}		/*	 * test set record_set_default_fid() and 	 * record_get_field_default() routines.	 */	if (TRUE)	{		const gchar * value = NULL;		record_set_default_fid(record,													 REC_FIELD_ADDRESS,													 REC_FIELD_ADDRESS * 1000 + 2);						value = record_get_field_default(record, 																		 REC_FIELD_ADDRESS,																		 NULL);		g_print("%s(): %s\n",						__FUNCTION__,						(value ? value : "(null)"));	}	if (TRUE)	{		guint32 fid = FIELD_ID_INVALID;				record_set_field_default(record,														 REC_FIELD_EMAIL,														 "emaildefault@domain.com",														 FIELD_SIZE_AUTO);		record_set_label_default(record,														 REC_FIELD_EMAIL,														 "Email Primary");				fid = record_add_field(record, REC_FIELD_EMAIL);		record_set_field(record,										 fid,										 "email1@domain.com",										 FIELD_SIZE_AUTO);		fid = record_add_field(record, REC_FIELD_EMAIL);		record_set_field(record,										 fid,										 "email2@domain.com",										 FIELD_SIZE_AUTO);				record_remove_field(record,												fid);														fid = record_add_field(record, REC_FIELD_EMAIL);		record_set_field(record,										 fid,										 "email3@domain.com",										 FIELD_SIZE_AUTO);		record_set_default_fid(record,													 REC_FIELD_EMAIL,													 fid);				record_set_field_default(record,														 REC_FIELD_EMAIL,														 "email3todef@domain.com",														 FIELD_SIZE_AUTO);			record_set_default_fid(record,													 REC_FIELD_EMAIL,													 FID_GENERATE(REC_FIELD_EMAIL, 1));	}		record_print(record);	record_free(record);		field_template_free(templ);		return EXIT_SUCCESS;}/*vi:ts=2:nowrap:ai:expandtab */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -