Back to index

courier  0.68.2
rfc2045find.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 /*
00007 */
00008 #include      "rfc2045.h"
00009 #include      <ctype.h>
00010 
00011 struct rfc2045findstruct {
00012 
00013        const char *partnum;
00014        struct rfc2045 *ptr;
00015        } ;
00016 
00017 static void do_decode(struct rfc2045 *p, struct rfc2045id *id, void *ptr)
00018 {
00019 struct rfc2045findstruct *fs=(struct rfc2045findstruct *)ptr;
00020 const char *partnum=fs->partnum;
00021 unsigned n;
00022 
00023        while (id)
00024        {
00025               if (!isdigit((int)(unsigned char)*partnum))      return;
00026               n=0;
00027               while (isdigit((int)(unsigned char)*partnum))
00028                      n=n*10 + *partnum++ - '0';
00029               if (*partnum)
00030               {
00031                      if (*partnum != '.') return;
00032                      ++partnum;
00033               }
00034               if (n != (unsigned)id->idnum)      return;
00035               id=id->next;
00036        }
00037        if ( *partnum == '\0')      fs->ptr=p;
00038 }
00039 
00040 
00041 struct rfc2045 *rfc2045_find(struct rfc2045 *p, const char *str)
00042 {
00043 struct rfc2045findstruct fs;
00044 
00045        fs.partnum=str;
00046        fs.ptr=0;
00047        rfc2045_decode(p, &do_decode, &fs);
00048        return (fs.ptr);
00049 }