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

📄 vobject.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************//***************************************************************************(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International             Business Machines Corporation and Siemens Rolm Communications Inc.                                                                                            For purposes of this license notice, the term Licensors shall mean,            collectively, Apple Computer, Inc., AT&T Corp., International                  Business Machines Corporation and Siemens Rolm Communications Inc.             The term Licensor shall mean any of the Licensors.                                                                                                            Subject to acceptance of the following conditions, permission is hereby        granted by Licensors without the need for written agreement and without        license or royalty fees, to use, copy, modify and distribute this              software for any purpose.                                                                                                                                     The above copyright notice and the following four paragraphs must be           reproduced in all copies of this software and any software including           this software.                                                                                                                                                THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE       ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR       MODIFICATIONS.                                                                                                                                                IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,              INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT         OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH         DAMAGE.                                                                                                                                                       EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,       INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE            IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR             PURPOSE.                                                                       The software is provided with RESTRICTED RIGHTS.  Use, duplication, or         disclosure by the government are subject to restrictions set forth in          DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.                         ***************************************************************************//* * src: vobject.c * doc: vobject and APIs to construct vobject, APIs pretty print  * vobject, and convert a vobject into its textual representation. */#include <stdlib.h>#include <qtopia/config.h>#include "vobject_p.h"#include "qfiledirect_p.h"#include <string.h>#include <stdio.h>#include <fcntl.h>//#include <io.h>#define NAME_OF(o)				o->id#define VALUE_TYPE(o)			o->valType#define STRINGZ_VALUE_OF(o)		o->val.strs#define INTEGER_VALUE_OF(o)		o->val.i#define LONG_VALUE_OF(o)		o->val.l#define ANY_VALUE_OF(o)			o->val.any#define VOBJECT_VALUE_OF(o)		o->val.vobjstatic char vobj_cs[10];static enum { EightBit, QuotedPrintable, Base64 } vobj_enc=EightBit;static const char *vobj_enc_s=0;typedef union ValueItem {    const char *strs;    unsigned int i;    unsigned long l;    void *any;    VObject *vobj;    } ValueItem;struct VObject {    VObject *next;    const char *id;    VObject *prop;    unsigned short valType;    ValueItem val;    };typedef struct StrItem StrItem;struct StrItem {    StrItem *next;    const char *s;    unsigned int refCnt;    };DLLEXPORT(const char**) fieldedProp;/*----------------------------------------------------------------------   The following functions involve with memory allocation:	newVObject	deleteVObject	dupStr	deleteStr	newStrItem	deleteStrItem   ----------------------------------------------------------------------*/DLLEXPORT(VObject*) newVObject_(const char *id){    VObject *p = (VObject*)malloc(sizeof(VObject));    p->next = 0;    p->id = id;    p->prop = 0;    VALUE_TYPE(p) = 0;    ANY_VALUE_OF(p) = 0;    return p;}DLLEXPORT(VObject*) newVObject(const char *id){    return newVObject_(lookupStr(id));}DLLEXPORT(void) deleteVObject(VObject *p){    unUseStr(p->id);    free(p);}DLLEXPORT(char*) dupStr(const char *s, unsigned int size){    char *t;    if  (size == 0) {	size = strlen(s);	}    t = (char*)malloc(size+1);    if (t) {	memcpy(t,s,size);	t[size] = 0;	return t;	}    else {	return (char*)0;	}}DLLEXPORT(void) deleteStr(const char *p){    if (p) free((void*)p);}static StrItem* newStrItem(const char *s, StrItem *next){    StrItem *p = (StrItem*)malloc(sizeof(StrItem));    p->next = next;    p->s = s;    p->refCnt = 1;    return p;}static void deleteStrItem(StrItem *p){    free((void*)p);}/*----------------------------------------------------------------------  The following function provide accesses to VObject's value.  ----------------------------------------------------------------------*/DLLEXPORT(const char*) vObjectName(VObject *o){    return NAME_OF(o);}DLLEXPORT(void) setVObjectName(VObject *o, const char* id){    NAME_OF(o) = id;}DLLEXPORT(const char*) vObjectStringZValue(VObject *o){    return STRINGZ_VALUE_OF(o);}DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s){    STRINGZ_VALUE_OF(o) = dupStr(s,0);    VALUE_TYPE(o) = VCVT_STRINGZ;}DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s){    STRINGZ_VALUE_OF(o) = s;    VALUE_TYPE(o) = VCVT_STRINGZ;}DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o){    return INTEGER_VALUE_OF(o);}DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i){    INTEGER_VALUE_OF(o) = i;    VALUE_TYPE(o) = VCVT_UINT;}DLLEXPORT(unsigned long) vObjectLongValue(VObject *o){    return LONG_VALUE_OF(o);}DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l){    LONG_VALUE_OF(o) = l;    VALUE_TYPE(o) = VCVT_ULONG;}DLLEXPORT(void*) vObjectAnyValue(VObject *o){    return ANY_VALUE_OF(o);}DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t){    ANY_VALUE_OF(o) = t;    VALUE_TYPE(o) = VCVT_RAW;}DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o){    return VOBJECT_VALUE_OF(o);}DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p){    VOBJECT_VALUE_OF(o) = p;    VALUE_TYPE(o) = VCVT_VOBJECT;}DLLEXPORT(int) vObjectValueType(VObject *o){    return VALUE_TYPE(o);}/*----------------------------------------------------------------------  The following functions can be used to build VObject.  ----------------------------------------------------------------------*/DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p){    /* circular link list pointed to tail */    /*    o {next,id,prop,val}                V	pn {next,id,prop,val}             V	    ...	p1 {next,id,prop,val}             V	     pn    -->    o {next,id,prop,val}                V	pn {next,id,prop,val}             V	p {next,id,prop,val}	    ...	p1 {next,id,prop,val}             V	     pn    */    VObject *tail = o->prop;    if (tail) {	p->next = tail->next;	o->prop = tail->next = p;	}    else {	o->prop = p->next = p;	}    return p;}DLLEXPORT(VObject*) addProp(VObject *o, const char *id){    return addVObjectProp(o,newVObject(id));}DLLEXPORT(VObject*) addProp_(VObject *o, const char *id){    return addVObjectProp(o,newVObject_(id));}DLLEXPORT(void) addList(VObject **o, VObject *p){    p->next = 0;    if (*o == 0) {	*o = p;	}    else {	VObject *t = *o;	while (t->next) {	   t = t->next;	   }	t->next = p;	}}DLLEXPORT(VObject*) nextVObjectInList(VObject *o){    return o->next;}DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size){    VObject *sizeProp;    setVObjectAnyValue(prop, val);    sizeProp = addProp(prop,VCDataSizeProp);    setVObjectLongValue(sizeProp, size);    return prop;}DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size){    void *p = dupStr((const char *)val,size);    return setValueWithSize_(prop,p,p?size:0);}DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o){    i->start = o->prop;     i->next = 0;}DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o){    i->start = o->next;     i->next = 0;}DLLEXPORT(int) moreIteration(VObjectIterator *i){     return (i->start && (i->next==0 || i->next!=i->start));}DLLEXPORT(VObject*) nextVObject(VObjectIterator *i){    if (i->start && i->next != i->start) {	if (i->next == 0) {	    i->next = i->start->next;	    return i->next;	    }	else {	    i->next = i->next->next;	    return i->next;	    }	}    else return (VObject*)0;}DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id){    VObjectIterator i;    initPropIterator(&i,o);    while (moreIteration(&i)) {	VObject *each = nextVObject(&i);	if (!qstricmp(id,each->id))	    return each;	}    return (VObject*)0;}DLLEXPORT(VObject*) addGroup(VObject *o, const char *g){    /*	a.b.c	-->	prop(c)	    prop(VCGrouping=b)		prop(VCGrouping=a)     */    char *dot = strrchr(g,'.');    if (dot) {	VObject *p, *t;	char *gs, *n = dot+1;	gs = dupStr(g,0);	/* so we can write to it. */	/* used to be	* t = p = addProp_(o,lookupProp_(n));	*/	t = p = addProp_(o,lookupProp(n));	dot = strrchr(gs,'.');	*dot = 0;	do {	    dot = strrchr(gs,'.');	    if (dot) {		n = dot+1;		*dot=0;		}	    else		n = gs;	    /* property(VCGroupingProp=n);	     *	and the value may have VCGrouping property	     */	    t = addProp(t,VCGroupingProp);	    setVObjectStringZValue(t,lookupProp_(n));	    } while (n != gs);	deleteStr(gs);		return p;	}    else	return addProp_(o,lookupProp(g));}DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v){    VObject *prop;    prop = addProp(o,p);    setVObjectStringZValue_(prop, strdup( v ) );    return prop;}DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v,	unsigned int size){    VObject *prop;    prop = addProp(o,p);    setValueWithSize_(prop, (void*)v, size);    return prop;}DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v,	unsigned int size){    return addPropSizedValue_(o,p,dupStr(v,size),size);}

⌨️ 快捷键说明

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