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

📄 oid.c

📁 harvest是一个下载html网页得机器人
💻 C
📖 第 1 页 / 共 2 页
字号:
    {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF16,   {1,0,10646,1,0,5,-1},     "UTF-16"},    {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF8,    {1,0,10646,1,0,8,-1},     "UTF-8"},    {PROTO_Z3950,   CLASS_USERINFO,VAL_OCLCUI,  {10, 1000, 17, 1, -1},     "OCLC-userInfo"},    {PROTO_NOP,     CLASS_NOP,     VAL_NOP,       {-1},        0          }};/* OID utilities */void oid_oidcpy(int *t, int *s){    while ((*(t++) = *(s++)) > -1);}void oid_oidcat(int *t, int *s){    while (*t > -1)        t++;    while ((*(t++) = *(s++)) > -1);}int oid_oidcmp(int *o1, int *o2){    while (*o1 == *o2 && *o1 > -1)    {        o1++;        o2++;    }    if (*o1 == *o2)        return 0;    else if (*o1 > *o2)        return 1;    else        return -1;}int oid_oidlen(int *o){    int len = 0;    while (*(o++) >= 0)        len++;    return len;}static int match_prefix(int *look, int *prefix){    int len;    for (len = 0; *look == *prefix; look++, prefix++, len++);    if (*prefix < 0) /* did we reach the end of the prefix? */        return len;    return 0;}void oid_transfer (struct oident *oidentp){    while (*oidentp->oidsuffix >= 0)    {	oid_addent (oidentp->oidsuffix, oidentp->proto,		    oidentp->oclass,		    oidentp->desc, oidentp->value);	oidentp++;    }}void oid_init (void){    if (oid_init_flag == 0)    {	/* oid_transfer is thread safe, so there's nothing wrong in having	   two threads calling it simultaniously. On the other hand	   no thread may exit oid_init before all OID's bave been	   transferred - which is why checked is set after oid_transfer... 	*/	nmem_mutex_create (&oid_mutex);	nmem_mutex_enter (oid_mutex);	if (!oid_nmem)	    oid_nmem = nmem_create ();	nmem_mutex_leave (oid_mutex);	oid_transfer (standard_oids);	oid_init_flag = 1;    }}void oid_exit (void){    if (oid_init_flag)    {        oid_init_flag = 0;        nmem_mutex_destroy (&oid_mutex);        nmem_destroy (oid_nmem);        oid_nmem = 0;    }}static struct oident *oid_getentbyoid_x(int *o){    enum oid_proto proto;    int prelen;    struct oident_list *ol;        /* determine protocol type */    if ((prelen = match_prefix(o, z3950_prefix)) != 0)        proto = PROTO_Z3950;    else if ((prelen = match_prefix(o, sr_prefix)) != 0)        proto = PROTO_SR;    else        proto = PROTO_GENERAL;    for (ol = oident_table; ol; ol = ol->next)    {	struct oident *p = &ol->oident;        if (p->proto == proto && !oid_oidcmp(o + prelen, p->oidsuffix))            return p;	if (p->proto == PROTO_GENERAL && !oid_oidcmp (o, p->oidsuffix))	    return p;    }    return 0;}/* * To query, fill out proto, class, and value of the ent parameter. */int *oid_ent_to_oid(struct oident *ent, int *ret){    struct oident_list *ol;        oid_init ();    for (ol = oident_table; ol; ol = ol->next)    {	struct oident *p = &ol->oident;        if (ent->value == p->value &&            (p->proto == PROTO_GENERAL || (ent->proto == p->proto &&  	    (ent->oclass == p->oclass || ent->oclass == CLASS_GENERAL))))	{	    if (p->proto == PROTO_Z3950)		oid_oidcpy(ret, z3950_prefix);	    else if (p->proto == PROTO_SR)		oid_oidcpy(ret, sr_prefix);	    else		ret[0] = -1;	    oid_oidcat(ret, p->oidsuffix);	    ent->desc = p->desc;	    return ret;	}    }    ret[0] = -1;    return 0;}/* * To query, fill out proto, class, and value of the ent parameter. */int *oid_getoidbyent(struct oident *ent){    static int ret[OID_SIZE];    return oid_ent_to_oid (ent, ret);}struct oident *oid_addent (int *oid, enum oid_proto proto,			   enum oid_class oclass,			   const char *desc, int value){    struct oident *oident = 0;    nmem_mutex_enter (oid_mutex);    if (!oident)    {	char desc_str[200];	struct oident_list *oident_list;	oident_list = (struct oident_list *)	    nmem_malloc (oid_nmem, sizeof(*oident_list));	oident = &oident_list->oident;	oident->proto = proto;	oident->oclass = oclass;	if (!desc)	{	    int i;	    sprintf (desc_str, "%d", *oid);	    for (i = 1; i < 12 && oid[i] >= 0; i++)		sprintf (desc_str+strlen(desc_str), ".%d", oid[i]);	    desc = desc_str;	}	oident->desc = nmem_strdup (oid_nmem, desc);	if (value == VAL_DYNAMIC)	    oident->value = (enum oid_value) (++oid_value_dynamic);	else	    oident->value = (enum oid_value) value;	oid_oidcpy (oident->oidsuffix, oid);	oident_list->next = oident_table;	oident_table = oident_list;    }    nmem_mutex_leave (oid_mutex);    return oident;}struct oident *oid_getentbyoid(int *oid){    struct oident *oident;    if (!oid)	return 0;    oid_init ();    oident = oid_getentbyoid_x (oid);    if (!oident)	oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL,			     NULL, VAL_DYNAMIC);    return oident;}static oid_value oid_getval_raw(const char *name){    int val = 0, i = 0, oid[OID_SIZE];    struct oident *oident;        while (isdigit (*name))    {        val = val*10 + (*name - '0');        name++;        if (*name == '.')        {            if (i < OID_SIZE-1)                oid[i++] = val;	    val = 0;            name++;        }    }    oid[i] = val;    oid[i+1] = -1;    oident = oid_getentbyoid_x (oid);    if (!oident)        oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL, NULL,			 VAL_DYNAMIC);    return oident->value;}oid_value oid_getvalbyname(const char *name){    struct oident_list *ol;    oid_init ();    if (isdigit (*name))        return oid_getval_raw (name);    for (ol = oident_table; ol; ol = ol->next)	if (!yaz_matchstr(ol->oident.desc, name))	{	    return ol->oident.value;	}    return VAL_NONE;}void oid_setprivateoids(oident *list){    oid_transfer (list);}void oid_trav (void (*func)(struct oident *oidinfo, void *vp), void *vp){    struct oident_list *ol;    oid_init ();    for (ol = oident_table; ol; ol = ol->next)        (*func)(&ol->oident, vp);}int *oid_name_to_oid(oid_class oclass, const char *name, int *oid) {    struct oident ent;    /* Translate syntax to oid_val */    oid_value value = oid_getvalbyname(name);    /* Build it into an oident */    ent.proto = PROTO_Z3950;    ent.oclass = oclass;    ent.value = value;    /* Translate to an array of int */    return oid_ent_to_oid(&ent, oid);}char *oid_to_dotstring(const int *oid, char *oidbuf) {    char tmpbuf[20];    int i;    oidbuf[0] = '\0';    for (i = 0; oid[i] != -1; i++) {	sprintf(tmpbuf, "%d", oid[i]);	if (i > 0) strcat(oidbuf, ".");	strcat(oidbuf, tmpbuf);    }    return oidbuf;}char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oidbuf) {    int oid[OID_SIZE];    (void) oid_name_to_oid(oclass, name, oid);    return oid_to_dotstring(oid, oidbuf);}

⌨️ 快捷键说明

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