1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <stdio.h>
#ifdef MEMDBG
#include "memdbg.h"
#endif
#include "treestruct.h"
#define INIT register char *sp = instring;
#define GETC() (*sp++)
#define PEEKC() (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return(c)
#define ERROR(c) {regerr(c);return(c);}
#include <regexp.h>
int reg_error;
char expbuf[1000];
regerr(c)
int c;
{
reg_error=c;
}
int findnodebyname(t, str, n)
tree t;
char *str; /* regular expression to search for */
treenode *n; /* node found, passes in last node that was found */
/* returns: 0=ok, 1=not found, 2=bad search pattern, 3=bad parameters */
{
list old;
treenode c, start, found;
if(str==NULL)
return(3);
if(nottree(t))
return(3);
compile(str, expbuf, &expbuf[1000+1], '\0');
/* circf=1; */
if(reg_error!=0)
return(2);
old=listnode(t->nodes);
if(*n==NULL || findnode(t->nodes, *n)==NULL)
{
startlist(t->nodes);
start=listnext(t->nodes);
}
else
start=*n;
found=NULL;
while((c=listnext(t->nodes))!=start)
{
if(c==NULL)
startlist(t->nodes);
else
if(c->name!=NULL)
if(step(c->name, expbuf))
{
found=c;
break;
}
}
*n=found;
if(found==NULL)
return(1);
else
return(0);
}
|