示例#1
0
void findedge(node* start,char A,char B,listnode** edgeloc)
{
    if(start==NULL)
    {
        printf("\nNo nodes in the graph");
        return;
    }
    node* locA=NULL;
    findnode(start,A,&locA);
    node* locB=NULL;
    findnode(start,B,&locB);
    if(locA==NULL || locB==NULL)
    {
        printf("\nEdge not found!!!");
        *edgeloc=NULL;
        return;
    }
    listnode* ptr=locA->adj;
    while(ptr!=NULL)
    {
        if(ptr->link==locB)
        {
            *edgeloc=ptr;
            return;
        }
        else
        {
            ptr=ptr->next;
        }
    }
    printf("\nEdge not found!!!");
}
示例#2
0
int findtree(int order,PCB *pcb,node *node,int memsize){
    int f;
  if(node->order==order){//find the right order
    if(!((node->left==NULL)&&(node->right==NULL))){ //not leaf but chunk could only be allocated at leaf
       return(-1);
    }
    else{   //the leaf node
       if(node->free_status==0){  //not free
          return(-1);
       }
       else{   //find one heap chunk!
           node->free_status=0;
           printf("Allocated the block: order = %d, addr= %d , requested mem size = %d, block size = %d\n",node->order,node->address,memsize,node->size); 
           return(node->address);
           }
    }
  }
  else{ //fail to locate correct order,keep searching
    if((node->left==NULL)&&(node->right==NULL)){     //leaf with higher order, should create new node
      if(node->free_status==0){ //not free
         return(-1);
      }
      else{ //insert children
        node->left=&pcb->heapnode[findnode(pcb)];
        node->left->order=node->order-1;
        node->left->address=node->address;
        node->left->size=node->size/2;
        node->left->left=NULL;
        node->left->right=NULL;
        node->left->free_status=1;  //initiate as free
        printf("Created a left child node(order= %d, addr= %d, size= %d) of parent (order= %d, addr= %d, size= %d)\n",node->left->order,node->left->address,node->left->size,node->order,node->address,node->size);
        node->right=&pcb->heapnode[findnode(pcb)];
        node->right->order=node->order-1;
        node->right->address=node->address+(32*(1<<node->right->order));
        node->right->size=node->size/2;
        node->right->left=NULL;
        node->right->right=NULL;
        node->right->free_status=1; //initiate as free
        printf("Created a right child node(order= %d, addr= %d, size= %d) of parent (order= %d, addr= %d, size= %d)\n",node->right->order,node->right->address,node->right->size,node->order,node->address,node->size);
        if(((f=findtree(order,currentPCB,node->left,memsize))==-1)){
          //  printf("f= %d\n",f);
            return(findtree(order,currentPCB,node->right,memsize));
        }
        else{
          //  printf("f= %d\n",f);
            return (f);
        }
      }
    }
    else{ //not a leaf, search in left child first, then right child
      if(((f=findtree(order,currentPCB,node->left,memsize))==-1)){
          return(findtree(order,currentPCB,node->right,memsize));
      }
      else{
          return (f);
      }
    }
  }
}   
示例#3
0
avlnode * Tree::insertion(avlnode * temp, int value, int value1)
{
    avlnode * temp1 = findnode(value);
    if (temp1!=NULL)
    {
        ((temp1->head2)->head)=(temp1->head2)->add(value1);
        return temp;
    }
    if (temp==NULL)
    {
        temp = new avlnode;
        temp->data=value;
        temp->left=NULL;
        temp->right=NULL;
        temp->head2=new Connection;
        ((temp->head2)->head)=(temp->head2)->add(value1);
    }
    else if (value>temp->data)
    {
        temp->left=insertion(temp->left, value, value1);
        temp=balance (temp);
    }
    else if (value<temp->data)
    {
        temp->right=insertion(temp->right, value, value1);
        temp=balance (temp);
    }
    return temp;
}
示例#4
0
文件: myndbm.c 项目: rdebath/cvs
datum
mydbm_fetch (DBM *db, datum key)
{
    Node *p;
    char *s;
    datum val;

    /* make sure it's null-terminated */
    s = xmalloc (key.dsize + 1);
    (void) strncpy (s, key.dptr, key.dsize);
    s[key.dsize] = '\0';

    p = findnode (db->dbm_list, s);
    if (p)
    {
	val.dptr = p->data;
	val.dsize = strlen (p->data);
    }
    else
    {
	val.dptr = NULL;
	val.dsize = 0;
    }
    free (s);
    return val;
}
示例#5
0
char* list::getstrdata(char *str)
{
    node *temp;
    temp = (node *)findnode(str);
    if (temp==NULL)
        return NULL;
    return temp->strdata;
}
示例#6
0
listitemtype list::getdata(char *str)
{
    node *temp;
    temp = (node *)findnode(str);
    if (temp==NULL)
        return -1;
    return temp->data;
}
示例#7
0
void delete_node(node **start, char A)
{
    if(*start==NULL)
    {
        printf("\nNo nodes in the graph!!\n");
        return ;
    }
    node *ptr1=*start;
    //checking if the node is in the graoh or not
    node* locA=NULL;
    findnode(*start,A,&locA);
    if(locA==NULL)
    {
        printf("\nThe entered node is not in the graph\n");
        return ;
    }
    listnode *ptr2=ptr1->adj;
    listnode* save2=ptr2;
    //deleting all the incoming edges
    while(ptr1!=NULL)
    {
        if(ptr1->data!=A)
        {
            while(ptr2!=NULL)
            {
                if(ptr2->link->data==A)
                {
                    if(ptr2==ptr1->adj)
                        ptr1->adj=ptr2->next;
                    else
                        save2->next=ptr2->next;
                }
                save2=ptr2;
                ptr2=ptr2->next;
            }
        }

        ptr1=ptr1->next;
    }
    //deleting all outgoing edges


    listnode* ptr=locA->adj;
    listnode* save=ptr;
    while(ptr!=NULL)
    {
        save=ptr;
        ptr=ptr->next;
        free(save);
    }
    //if starting node is to be deleted
    if((*start)->data==A)
    {
        *start=(*start)->next;
    }
    //delete the node
    free(locA);
}
示例#8
0
int main(void)
{
      int i;
      node **L;

      if (sizeof(int) < 4)
      {
            puts("This code must be compiled with 32-bit ints!");
            return EXIT_FAILURE;
      }

      L=newlist();

      puts(" DOWN");

      for(i = 100; i >= 0; i -=2)
            insertnode(L, i, i);

      puts(" UP");
      for(i = 1; i < 100; i += 2)
            insertnode(L, i, i);

      deletenode(L, 40);

      puts(" FIND");
      for(i = -2; i <= 100; ++i)
            findnode(L, i);

      puts(" FAST");
      findall(L);

      puts("SAMPLES");
      printf(" %d", findnode(L, -10));

      printf(" %d,", findnode(L, 0));
      printf(" %d", findnode(L, 1));
      printf(" %d", findnode(L, 2));
      printf(" %d", findnode(L, 39));
      printf(" %d", findnode(L, 40));
      printf(" %d", findnode(L, 41));
      printf(" %d", findnode(L, 42));

      puts(" DONE");

      return EXIT_SUCCESS;
}
示例#9
0
int list::setdata(char *str, char *strdata,listitemtype data)
{
    node *temp;
    temp = (node *)findnode(str);
    if (temp==NULL)
        return -1;
    temp->data = data;
    //temp->strdata = strdup(strdata);
    temp->strdata = new char[strlen(strdata)];
    strcpy(temp->strdata, strdata);
    return 0;
}
示例#10
0
void insertedge(node* start,char A,char B)
{
    if(start==NULL)
    {
        printf("\nNo nodes in the graph");
        return;
    }
    node* locA=NULL;
    findnode(start,A,&locA);
    node* locB=NULL;
    findnode(start,B,&locB);
    if(locA==NULL || locB==NULL)
    {
        printf("\nNodes not present in graph!!!");
        return;
    }
    listnode* temp=NULL;
    getlistnode(locB,&temp);
    temp->next=locA->adj;
    locA->adj=temp;
}
示例#11
0
void delete_edge(node* start,char A, char B)
{
    if(start==NULL)
    {
        printf("\nNo nodes in the graph!!\n");
        return ;
    }
    if(start==NULL)
    {
        printf("\nNo nodes in the graph");
        return;
    }
    node* locA=NULL;
    findnode(start,A,&locA);
    node* locB=NULL;
    findnode(start,B,&locB);
    if(locA==NULL || locB==NULL)
    {
        printf("\nNodes not present in graph!!!");
        return;
    }
    listnode* ptr=locA->adj;
    listnode* save=ptr;

    while(ptr!=NULL)
    {
        if(ptr->link==locB)
        {
            if(ptr==locA->adj)
                locA->adj=ptr->next;
            else
                save->next=ptr->next;
            free(ptr);
            return;
        }
        save=ptr;
        ptr=ptr->next;
    }
}
示例#12
0
void Tree::removelink(int x, int y)
{
    avlnode * temp1=findnode(x);
    conn * temp2=(temp1->head2)->head;
    while ((temp2)!=NULL)
    {
        if (temp2->data==y)
        {
            (temp1->head2)->removal(y);
            return;
        }
        temp2=temp2->next;
    }
}
示例#13
0
文件: input2.c 项目: sdteffen/epanetl
int   addnodeID(int n, char *id)
/*
**-------------------------------------------------------------
**  Input:   n = node index
**           id = ID label
**  Output:  returns 0 if ID already in use, 1 if not
**  Purpose: adds a node ID to the Node Hash Table
**--------------------------------------------------------------
*/
{
    if (findnode(id)) return(0);         /* see EPANET.C */
    strncpy(Node[n].ID, id, MAXID);
    HTinsert(Nht, Node[n].ID, n);        /* see HASH.C */
    return(1);
}
示例#14
0
Tnode*
findnode(Tnode *t, Point p)
{
    int i;
    Tnode *tt;

    if(ptinrect(p, rectaddpt(Rect(0,0,Nubwidth, Nubheight), t->offset)))
        return t;
    if(!t->expanded)
        return nil;
    for(i=0; i<t->nkid; i++)
        if(tt = findnode(t->kid[i], p))
            return tt;
    return nil;
}
示例#15
0
int list::remove(char *str)
{
    node *temp,*prev;
    temp = (node *)findnode(str);
    if (temp == NULL)
        return -1;
    prev = (node *)findprev(temp);
    if (prev == NULL)
        return -1;
    prev->next = temp->next;
//  delete[] temp->str;
//  delete[] temp->strdata;
    delete temp;
    return 0;
}
示例#16
0
struct filenode *findnode(struct filenode *node, dev_t dev, ino_t ino)
{
	struct filenode *found, *p;

	/* scan the whole tree */
	if (node->ondev == dev && node->onino == ino)
		return node;
	p = node->dirlist.head;
	while (p->next) {
		found = findnode(p, dev, ino);
		if (found)
			return found;
		p = p->next;
	}
	return NULL;
}
示例#17
0
void
variable_set (char *nameval)
{
    char *p;
    char *name;
    Node *node;

    p = nameval;
    while (isalnum ((unsigned char) *p) || *p == '_')
	++p;
    if (*p != '=')
	error (1, 0, "invalid character in user variable name in %s", nameval);
    if (p == nameval)
	error (1, 0, "empty user variable name in %s", nameval);
    name = xmalloc (p - nameval + 1);
    strncpy (name, nameval, p - nameval);
    name[p - nameval] = '\0';
    /* Make p point to the value.  */
    ++p;
    if (strchr (p, '\012'))
	error (1, 0, "linefeed in user variable value in %s", nameval);

    if (!variable_list)
	variable_list = getlist ();

    node = findnode (variable_list, name);
    if (!node)
    {
	node = getnode ();
	node->type = VARIABLE;
	node->delproc = variable_delproc;
	node->key = name;
	node->data = xstrdup (p);
	(void) addnode (variable_list, node);
    }
    else
    {
	/* Replace the old value.  For example, this means that -s
	   options on the command line override ones from .cvsrc.  */
	free (node->data);
	node->data = xstrdup (p);
	free (name);
    }
}
示例#18
0
文件: symtab.c 项目: samjeba/cstuff
/* lookup with optional insertion
 * See: The practice of programming, page 56
 */
void *
lookup(Symtab *table, int insert, char *key, void *value){
	unsigned long h = hash(key, table->size);
	Node *np = findnode(table->buckets[h], key);

	if(np)
		return np->value;
	if(insert){
		np        = xmalloc(sizeof(*np));
		np->key   = clonekey(key);
		np->value = value;
		np->next  = table->buckets[h];
		table->buckets[h] = np;
		table->entries++;
		if(mustexpand(table))
			expandtable(table);
	}
	return np;
}
示例#19
0
文件: 58.c 项目: wj32/Judge
void split(int x)
{
    int index;
    node *d;
    
    findnode(x, &index);
    d = list[index];
    
    if (d->start < x && x < d->start + d->length)
    {
        node *right;
        
        right = makenode();
        right->start = x;
        right->length = d->length - (x - d->start);
        right->count = d->count;
        insert(index + 1, right);
        
        d->length = x - d->start;
    }
}
示例#20
0
int list::insert(char *str,char *strdata,listitemtype data)
{
    node *next, *prev;
    if (findnode(str) != NULL)
        return -1;
    prev = (node *)findprev(tail);
    next = new node;
    if (next == NULL)
        return -1;
    prev->next = next;
    next->next = tail;
    next->str = new char[strlen(str)+1];
    if (next->str == NULL)
        return -1;
    //clearstr(next->str,strlen(str)+1);
    strcpy(next->str,str);
    next->data = data;
    next->strdata = new char[strlen(strdata)+1];//strdup(strdata);
    strcpy(next->strdata, strdata);
    return 0;
}
示例#21
0
文件: 58.c 项目: wj32/Judge
void increment(int a, int b)
{
    int index;
    node *d;
    
    split(a);
    split(b + 1);
    
    if (!findnode(a, &index))
        assert(0);
    
    while (index < count)
    {
        d = list[index];
        
        if (d->start > b)
            break;
        
        d->count++;
        index++;
    }
}
示例#22
0
/*  Routine to slid one branch of a node along the a branch
 *  The moving node is assumed to be simple!*/
void greasebranch(struct treenode *node_p,FILE *file_p,unsigned int e){
#include "variables.h"
  int steps,a,b,c;
  int slippe,to,from,to_root,to_false_root;
  int sp_case;

  double f_min,f_max,f,l;

  extern int root;
  struct treenode *movingnode,*node_c;
  struct treenode *tree;

  /*  Make two copies of the tree*/
  tree2=treecopy(node_p,0);
  tree=treecopy(node_p,0);
  filltree(node_p,tree,0);

  /*  Print out the tree branches and respective numbers*/
  printf("\n");
  for(a=0;a<branches;a++)
    printf("Branch %d goes from %s to %s\n",a
           ,(branch[a]->node[0])->name,branch[a]->name);

  /*  Get the necessary parameters from the user*/
  do{
    printf("\nWhich branch would you like to move?");
    scanf("%d",&slippe);
  }while(slippe<0 || slippe>branches);

  do{
    printf("\nWhich branch would you like to move branch %d along(towards)?"
                                                                    ,slippe);
    scanf("%d",&to);
    printf("\nWhich branch would you like to move branch %d along(away)?"
                                                                 ,slippe);
    scanf("%d",&from);
  }while(to<0 || to>branches || from<0 || from>branches);

/*  Out of the three parameters given, two of them must point
 * the common node.*/
  movingnode=(branch[to]->node[0]==branch[from]->node[0])
             ?branch[to]->node[0]:branch[slippe]->node[0];

/*  Find which branch in the common node points to each of the
 * parameter branches.*/
  from=findnode(movingnode,branch[from]);
  to=findnode(movingnode,branch[to]);
  slippe=findnode(movingnode,branch[slippe]);

/*  Get the amount of variation from the user*/
  printf("Sliding branch leading to %s\n\n",branch[slippe]->name);
  printf("Please enter min. & max. distance to move and number of points:\n");
  do{
    printf("\tmin. distance:");
    scanf("%lf",&f_min);
  }while(f_min<=-movingnode->length[from] || f_min>=movingnode->length[to]);
  do{
    printf("\tmax. distance:");
    scanf("%lf",&f_max);
  }while(f_min>=f_max || f_max>=movingnode->length[to]);
  do{
    printf("\tnumber of points:");
    scanf("%d",&steps);
  }while(steps<=0);

/*  Are we moving the branch towards the (code) root?*/
  to_false_root=(to==0)?0:1;

/*  Work out where root node is relative to movingnode.
 * Needed to work out whether to increase or decrease branch
 * lengths when moving node*/
  to_root=to_false_root; /*  Correct unless we are between the
                          * two roots in the tree */
  /*  If we have a genetic root...*/
  if(ISMODE(ROOTED)){
    /*  Decide depending on whether the root is floating or not,
     * which node it refers to*/
    node_c=(ISMODE(NODEASROOT))?branch[root]->node[0]:branch[root];

    /*  Iterate from the genetic root to the code root and set
     * "to_root" as appropriate. to_root only differs from to_false_root
     * if we are moving a branch between the two roots*/
    while(node_c!=tree){

      /*  If we reach movingnode without passing either the to or from
       * node first, then we must have come down on of the other branches
       * or our root is the movingnode itself. In either case, we can't 
       * keep evolutionary times fixed - problem*/
      if(node_c==movingnode){
        printf("Moving branch containing root - can't keep evolutionary times fixed\n");
        exit(0);
      }

      /*  We encounter the "to" node first and so must be moving 
       * towards the genetic root*/
      if(node_c==movingnode->node[to]){
        to_root=0;
        break;
      }

      /*  We encounter the from root first and so must be moving
       * away from the genetic node*/
      if(node_c==movingnode->node[from]){
        to_root=1;
        break;
      }

      /*  Iterate up one step*/
      node_c=node_c->node[0];
    }

  /*  If the root is on the branch we are moving, bad things
   * happen (TM) Moving the branch can't be done if evolutionary
   * times are fixed.
   *  We have deal with the case when root is on the moving bit of
   * tree but not the false root.*/
    if(slippe==0){
      /*  Decide where the root is depending on whether it is fixed
       * or floating*/
      node_c=(ISMODE(NODEASROOT))?branch[root]->node[0]:branch[root];
      a=0;

      /*  We may assume that the code root is on the moving branch of
       * the tree. If we have to pass through movingnode to get from
       * the genetic root to the code root then we are fine*/
      while(node_c!=tree){
	if(node_c==movingnode){
          a=1;
          break;
        }
        node_c=node_c->node[0];
      }

      /*  One special case if the movingnode is the fixed root*/
      if(ISMODE(NODEASROOT) && branch[root]->node[0]==movingnode)
        a=0;

      /*  If both the code and genetic roots are on the moving section
       * of tree, complain*/
      if(a==0){
        printf("Moving branch containing root - can't keep evolutionary"
               " times fixed\n");
        exit(0);
      }
    }

/*   If the root of the tree is on the same branch as we are moving across
 * then we'll have trouble when we cross it - give warning*/
    if(NOTMODE(NODEASROOT)) /*  genetic root is floating*/
      if(to_root==0) /*  we are heading towards it*/

        /*  Depending on whether we are going away or towards the
         * code root, see if the genetic root is on the branch we are
         * moving along*/
        if((to_false_root==0 && branch[root]==movingnode)
         ||(to_false_root==1 && branch[root]->node[0]==movingnode))
          fprintf(file_p,"# *** Root in branch moving across. Beware, here be dragons ***\n");
  }

  /*  Dump some information to file informing user what we are about
   * to do*/
  fprintf(file_p,"#Results from sliding branch from %s to"
	  " %s along branch from %s to %s\n"
	  ,movingnode->name,(movingnode->node[slippe])->name
	  ,(movingnode->node[from])->name,(movingnode->node[to])->name);
  fprintf(file_p,"#Distance moved towards %s\t%s\n",(movingnode->node[to])->name,outstring);
  if(ISMODE(MATRICES))
    fprintf(matrix_file_p,"#Matrices from sliding branch from %s to"
	    " %s along branch from %s to %s\n"
	    ,movingnode->name,(movingnode->node[slippe])->name
	    ,(movingnode->node[from])->name,(movingnode->node[to])->name);
  if(sample_file_p!=NULL){
    fprintf(sample_file_p,"#Points %d\n",steps);
    fprintf(sample_file_p,"#Samples from sliding branch from %s to"
	    " %s along branch from %s to %s\n"
	    ,movingnode->name,(movingnode->node[slippe])->name
	    ,(movingnode->node[from])->name,(movingnode->node[to])->name);
  }
  if(ISMODE(PROBS))
    fprintf(prob_file_p,"#Probabilities from sliding branch from %s to"
	    " %s along branch from %s to %s\n"
	    ,movingnode->name,(movingnode->node[slippe])->name
	    ,(movingnode->node[from])->name,(movingnode->node[to])->name);
  
  /*  l is the total length of the "branch" we are moving across*/
  l=movingnode->length[to]+movingnode->length[from];
  
  if(steps==1)
    f=f_min;
  else
    f=(f_max-f_min)/(steps-1);

  /* We aren't changing any rates, so we don't need to apply the
   * factor to any information (so factor=1)*/
  factor=1.0;
  factor_flag=0;
  
  /* Initialise the tree...*/
  movingnode->length[to]-=f_min;
  if(to==0){
    b=findnode(movingnode->node[0],movingnode);
    (movingnode->node[to])->length[b]=movingnode->length[to];
  }
  else
    (movingnode->node[to])->length[0]=movingnode->length[to];

  movingnode->length[from]+=f_min;
  if(from==0){
    b=findnode(movingnode->node[0],movingnode);
    (movingnode->node[from])->length[b]=movingnode->length[from];
  }
  else
    (movingnode->node[from])->length[0]=movingnode->length[from];
  /*  If the tree is rooted, then we must preserve evolutionary 
   * times. This requires adding bits onto any other branches
   * connected to the moving node, bar the to and from branches.*/
  if(ISMODE(ROOTED)){
    /*  Case moving towards the evolutionary root - all branches
     * connected to the moving node, bar from and to need to have 
     * the distance added onto them*/
    sp_case=(movingnode==tree)?1:0;
    if(to_root==0){
      if(sp_case==1 && to!=0 && from!=0){
	b=findnode(movingnode->node[0],movingnode);
	movingnode->length[0]+=f_min;
	(movingnode->node[0])->length[b]=movingnode->length[0];
      }
      for(a=sp_case;a<DOODAH && movingnode->node[a]!=NULL;a++)
	if(a!=to && a!=from){
	  (movingnode->node[a])->length[0]+=f_min;
	  movingnode->length[a]=(movingnode->node[a])->length[0];
        }
    }
    /*  Else we are moving away from it and all branches connected to
     * the moving node need the distance subtracted from them. Same
     * special case as above*/
    else{
      if(sp_case==1 && to!=0 && from!=0){
	b=findnode(movingnode->node[0],movingnode);
	movingnode->length[0]-=f_min;
	(movingnode->node[0])->length[b]=movingnode->length[0];
      }
      for(a=sp_case;a<DOODAH && movingnode->node[a]!=NULL;a++)
	if(a!=to && a!=from){
	(movingnode->node[a])->length[0]-=f_min;
	movingnode->length[a]=(movingnode->node[a])->length[0];
      }
    }
  }  

  
  for(c=0;c<steps;c++){

/*  Adding new lengths - if any of the markers are zero then
 * we have to search for the correct pointer in the parent node*/

    movingnode->length[to]-=(c!=0)*f;
    /*  Also need to update length of branch that leads to this
     * one. If to=0 then we must look up the tree*/
    if(to==0){
      b=findnode(movingnode->node[0],movingnode);
      (movingnode->node[to])->length[b]=movingnode->length[to];
    }
    else
      (movingnode->node[to])->length[0]=movingnode->length[to];

    movingnode->length[from]+=(c!=0)*f;
    /*  Also need to update length of branch that leads to this                 
     * one. If from=0 then we must look up the tree*/
    if(from==0){
      b=findnode(movingnode->node[0],movingnode);
      (movingnode->node[from])->length[b]=movingnode->length[from];
    }
    else
      (movingnode->node[from])->length[0]=movingnode->length[from];

    /*  If the tree is rooted, then we must preserve evolutionary 
     * times. This requires adding bits onto any other branches
     * connected to the moving node, bar the to and from branches.*/
    if(ISMODE(ROOTED)){
      /*  Case moving towards the evolutionary root - all branches
       * connected to the moving node, bar from and to need to have 
       * the distance added onto them*/
      sp_case=(movingnode==tree)?1:0; /*  Is the movingnode the code root?*/

      if(to_root==0){
        if(sp_case==1 && to!=0 && from!=0){
          b=findnode(movingnode->node[0],movingnode);
          movingnode->length[0]+=(c!=0)*f;
          (movingnode->node[0])->length[b]=movingnode->length[0];
        }
	for(a=sp_case;a<DOODAH && movingnode->node[a]!=NULL;a++)
	  if(a!=to && a!=from){
 	    (movingnode->node[a])->length[0]+=(c!=0)*f;
	    movingnode->length[a]=(movingnode->node[a])->length[0];
	  }
      }
      /*  Else we are moving away from it and all branches connected to
       * the moving node need the distance subtracted from them. Same
       * special case as above*/
      else{
        if(sp_case==1 && to!=0 && from!=0){
          b=findnode(movingnode->node[0],movingnode);
          movingnode->length[0]-=(c!=0)*f;
          (movingnode->node[0])->length[b]=movingnode->length[0];
        }
	for(a=sp_case;a<DOODAH && movingnode->node[a]!=NULL;a++)
	  if(a!=to && a!=from){
	    (movingnode->node[a])->length[0]-=(c!=0)*f;
	    movingnode->length[a]=(movingnode->node[a])->length[0];
	  }
      }
    }

    /*  Fill in second copy of tree from first and update the leaf
     * array to point to tree*/
    filltree(tree,tree2,0);
    leaves=0;
    doleaf(tree,0);

    /*  Print a bit of information to all open files*/
    printf("Doing distance %E\n",c*f+f_min);
    if(ISMODE(TREES))
      print_tree(tree,file_p,0);
    fprintf(file_p,"%E\n",c*f+f_min);
    if(ISMODE(MATRICES)){
      fprintf(matrix_file_p,"\n#Distance %E\n",c*f+f_min);
      if(ISMODE(TREES))
        print_tree(tree,matrix_file_p,0);
    }
    if(ISMODE(VARIANCE)){
      fprintf(variance_file_p,"\n#Distance %E\n",c*f+f_min);
      if(ISMODE(TREES))
        print_tree(tree,variance_file_p,0);
    }
    if(sample_file_p!=NULL){
      fprintf(sample_file_p,"\n#Distance %E\n",c*f+f_min);
      if(ISMODE(TREES))
	print_tree(tree,sample_file_p,0);
    }
    if(ISMODE(PROBS)){
      fprintf(prob_file_p,"\n#Distance %E\n",c*f+f_min);
      if(ISMODE(TREES))
	print_tree(tree,prob_file_p,0);
    }
    
    det=find_information(tree,tree2,e,factor_flag,factor);

    /*  Possible may want to print out more than one result*/
    b=1;
    if(ISMODE(INDIVIDUAL))
      b=individual;
    
    if(ISMODE(INDIVIDUAL)){
      if(ISMODE(DETINDIV)){
	fprintf(file_p,"\t\t\t%E\tD(",det[0]);
	for(a=0;a<b-1;a++)
	  fprintf(file_p,"%d,",interesting_branches[a]);
	fprintf(file_p,"%d)\n",interesting_branches[a]);
      }else
	for(a=0;a<b;a++)
	  fprintf(file_p,"\t\t\t%E\t%d\n",det[a],interesting_branches[a]);
    }else
      fprintf(file_p,"\t\t\t%E\tD\n",det[0]);
    
    if(ISMODE(HKY) && NOTMODE(NOKAPPA) && NOTMODE(PERCENTILE))
      fprintf(file_p,"\t\t\t%E\tKappa\n",det[b]);
    free(det);
  }
}
示例#23
0
/*  Routine to vary the length of one branch though several
 * multipliers. This has little meaning when considering a clock-like
 * (rooted) tree*/
void growbranch(struct treenode *node_p,FILE *file_p,unsigned int e){
#include "variables.h"
  int steps,a,b,c;
  int elastic;

  double f_min,f_max,f;

  struct treenode *tree;

/*  Test to see whether tree is rooted - changing branch 
 * length in unrooted trees doesn't have much experimental
 * meaning                                                  */
  if(((mode&4)|(mode&32))!=0)
    printf("\a\n**Changing branch length in a rooted tree doesn't"
           " have meaning\n**in an experimental design problem!\n\n\a");

  /*  Make two copies of the tree*/
  tree2=treecopy(node_p,0);
  tree=treecopy(node_p,0);
  /*  Fill in the first*/
  filltree(node_p,tree,0);

  /*  Choose branch to stretch - better be elastic*/
  printf("\n");
  for(a=0;a<branches;a++)
    printf("Branch %d goes from %s to %s\n",a
           ,(branch[a]->node[0])->name,branch[a]->name);
  do{
    printf("\nWhich branch would you like to alter?");
    scanf("%d",&elastic);
  }while(elastic<0 || elastic>branches);

  /*  Get length scaling factors from user*/
  printf("Altering length of a branch leading to"
                    " %s by a varying factor\n\n",branch[elastic]->name);
  printf("Please enter min. factor, max factor and number of points:\n");
  do{
    printf("\tmin. factor:");
    scanf("%lf",&f_min);
  }while(f_min<=0);
  do{
    printf("\tmax. factor:");
    scanf("%lf",&f_max);
  }while(f_min>=f_max);
  do{
    printf("\tnumber of points:");
    scanf("%d",&steps);
  }while(steps<=0);

  /*  Dump the necessary information to file*/
  fprintf(file_p,"#Results from varying length of branch"
	  " between %s and %s by factor\n"
	  ,(branch[elastic]->node[0])->name,branch[elastic]->name);
  fprintf(file_p,"#Factor\t\t\t%s\n",outstring);
  if(ISMODE(MATRICES))
    fprintf(matrix_file_p,"#Matrices from varying length of branch"
	    " between %s and %s by factor\n"
	    ,(branch[elastic]->node[0])->name,branch[elastic]->name);
  if(sample_file_p!=NULL){
    fprintf(sample_file_p,"#Points %d\n",steps);
    fprintf(sample_file_p,"#Samples from varying length of branch"
	    " between %s and %s by factor\n"
	    ,(branch[elastic]->node[0])->name,branch[elastic]->name);
  }
  if(ISMODE(PROBS))
    fprintf(prob_file_p,"#Probabilities from varying length of branch"
	    " between %s and %s by factor\n"
	    ,(branch[elastic]->node[0])->name,branch[elastic]->name);
  
  /*  Main loop to stretch the branch*/
  for(c=0;c<steps;c++){
    /*  Calculate the factor wanted and set the flag - we only
     * want to apply the factor to one of the informations this
     * time*/
    if(steps==1)
      f=f_min;
    else
      f=f_min+c*(f_max-f_min)/(steps-1);

    factor=f;
    factor_flag=elastic;

    /*  Fill in first copy from the original*/
    filltree(node_p,tree,0);

   /*  Branch[] points to those of 'tree'
    * Change length of the branch by factor - need to find the node
    * that points from the other side of the branch.*/
    branch[elastic]->length[0]=branch[elastic]->length[0]*f;
    a=findnode(branch[elastic]->node[0],branch[elastic]);
    (branch[elastic]->node[0])->length[a]=branch[elastic]->length[0];

    /*  Fill in the second copy from the first (with the new branch 
     * length and set all the leaves to point to "tree"*/
    filltree(tree,tree2,0);
    leaves=0;
    doleaf(tree,0);

    printf("Doing Factor %E\n",f);
    /*  If we are printing out the intermediate trees, then dump them
     * to every file*/
    if(ISMODE(TREES))
      print_tree(tree,file_p,0);
    fprintf(file_p,"%E\n",f);
    if(ISMODE(MATRICES)){
      fprintf(matrix_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
        print_tree(tree,matrix_file_p,0);
    }
    if(ISMODE(VARIANCE)){
      fprintf(variance_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
        print_tree(tree,variance_file_p,0);
    }
    if(sample_file_p!=NULL){
      fprintf(sample_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
	print_tree(tree,sample_file_p,0);
    }
    if(ISMODE(PROBS)){
      fprintf(prob_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
	print_tree(tree,prob_file_p,0);
    }
    
    det=find_information(tree,tree2,e,factor_flag,factor);

    /*  Possible may want to print out more than one result*/
    b=1;
    if(ISMODE(INDIVIDUAL))
      b=individual;
    
    if(ISMODE(INDIVIDUAL)){
      if(ISMODE(DETINDIV)){
	fprintf(file_p,"\t\t\t%E\tD(",det[0]);
	for(a=0;a<b-1;a++)
	  fprintf(file_p,"%d,",interesting_branches[a]);
	fprintf(file_p,"%d)\n",interesting_branches[a]);
      }else
	for(a=0;a<b;a++)
	  fprintf(file_p,"\t\t\t%E\t%d\n",det[a],interesting_branches[a]);
    }else
      fprintf(file_p,"\t\t\t%E\tD\n",det[0]);
    
    if(ISMODE(HKY) && NOTMODE(NOKAPPA) && NOTMODE(PERCENTILE))
      fprintf(file_p,"\t\t\t%E\tKappa\n",det[b]);
    free(det);
  }
}
示例#24
0
int
No_Difference (struct file_info *finfo, Vers_TS *vers)
{
    Node *p;
    int ret;
    char *ts, *options;
    int retcode = 0;
    char *tocvsPath;

    /* If ts_user is "Is-modified", we can only conclude the files are
       different (since we don't have the file's contents).  */
    if (vers->ts_user != NULL
	&& strcmp (vers->ts_user, "Is-modified") == 0)
	return -1;

    if (!vers->srcfile || !vers->srcfile->path)
	return (-1);			/* different since we couldn't tell */

#ifdef PRESERVE_PERMISSIONS_SUPPORT
    /* If special files are in use, then any mismatch of file metadata
       information also means that the files should be considered different. */
    if (preserve_perms && special_file_mismatch (finfo, vers->vn_user, NULL))
	return 1;
#endif

    if (vers->entdata && vers->entdata->options)
	options = xstrdup (vers->entdata->options);
    else
	options = xstrdup ("");

    tocvsPath = wrap_tocvs_process_file (finfo->file);
    retcode = RCS_cmp_file (vers->srcfile, vers->vn_user, NULL, NULL, options,
			    tocvsPath == NULL ? finfo->file : tocvsPath);
    if (retcode == 0)
    {
	/* no difference was found, so fix the entries file */
	ts = time_stamp (finfo->file);
	Register (finfo->entries, finfo->file,
		  vers->vn_user ? vers->vn_user : vers->vn_rcs, ts,
		  options, vers->tag, vers->date, NULL);
#ifdef SERVER_SUPPORT
	if (server_active)
	{
	    /* We need to update the entries line on the client side.  */
	    server_update_entries (finfo->file, finfo->update_dir,
				   finfo->repository, SERVER_UPDATED);
	}
#endif
	free (ts);

	/* update the entdata pointer in the vers_ts structure */
	p = findnode (finfo->entries, finfo->file);
	assert (p);
	vers->entdata = p->data;

	ret = 0;
    }
    else
	ret = 1;			/* files were really different */

    if (tocvsPath)
    {
	/* Need to call unlink myself because the noexec variable
	 * has been set to 1.  */
	TRACE (TRACE_FUNCTION, "unlink (%s)", tocvsPath);
	if ( CVS_UNLINK (tocvsPath) < 0)
	    error (0, errno, "could not remove %s", tocvsPath);
    }

    free (options);
    return ret;
}
示例#25
0
/*  Routine to vary the length of all branches by the same factor
 * and dump the expected information to disk. Since we are altering 
 * the rate of change, we need to include a factor in all the information
 * calculations*/
void growtree(struct treenode *node_p,FILE *file_p,unsigned int e){
#include "variables.h"
  int steps,a,b,c;
  
  double f_min,f_max,f;

  struct treenode *tree;


/*  Code to get the factors from the users*/
  printf("Altering length of all branches by same factor\n\n");
  printf("Please enter min. factor, max factor and number of points:\n");
  do{
    printf("\tmin. factor:");
    scanf("%lf",&f_min);
  }while(f_min<=0);
  do{
    printf("\tmax. factor:");
    scanf("%lf",&f_max);
  }while(f_min>=f_max);
  do{
    printf("\tnumber of points:");
    scanf("%d",&steps);
  }while(steps<=0);

  /*  Dump text to file explaining what we are about to do*/
  fprintf(file_p,"#Results from Varying length of all branches by factor\n");
  fprintf(file_p,"#Factor\t\t\t%s\n",outstring);
  if(ISMODE(MATRICES))
    fprintf(matrix_file_p,"#Matrices from Varying length of all branches by factor\n");
  if(sample_file_p!=NULL){
    fprintf(sample_file_p,"#Points %d\n",steps);
    fprintf(sample_file_p,"#Samples from varying length of all branches by factor\n");
  }
  if(ISMODE(PROBS))
    fprintf(prob_file_p,"#Probabilities from varying length of all branches by factor\n");
  
/*  Start main loop*/

  /*  Make two copies of the tree*/
  tree2=treecopy(node_p,0);
  tree=treecopy(node_p,0);

  /*  Calculate what factor we need to include in the calculations*/
  for(c=0;c<(steps);c++){
    if(steps==1)  /* Prevent divide by zero if only one step*/
      f=f_min;
    else
      f=f_min+c*(f_max-f_min)/(steps-1);
    factor=f;
    factor_flag=-1; /*  Flag = -1 means that we want to include the
                     * factor on all branches*/

    /*  Add all the information to one copy from the original tree*/
    filltree(node_p,tree,0);

/*  Change all the length in the tree to the scaled version
 * The array branch[] currently points to those of 'tree'*/
    for(b=0;b<branches;b++){
      branch[b]->length[0]=branch[b]->length[0]*f;
      a=findnode(branch[b]->node[0],branch[b]);
      (branch[b]->node[0])->length[a]=branch[b]->length[0];
    }
    /*  Make copy of the tree with scaled branches*/
    filltree(tree,tree2,0);

    /*  Branch[] now points to those in tree2
     * Make leaves point to those on tree*/
    leaves=0;
    doleaf(tree,0);

    printf("Doing factor %E\n",f);

    /*  If we've been asked to print out the intermediate trees, then
     * dump them to all the open files*/
    if(ISMODE(TREES))
      print_tree(tree,file_p,0);
    fprintf(file_p,"%E\n",f);
    if(ISMODE(MATRICES)){
      fprintf(matrix_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
        print_tree(tree,matrix_file_p,0);
    }
    if(ISMODE(VARIANCE)){
      fprintf(variance_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
        print_tree(tree,variance_file_p,0);
    }
    if(sample_file_p!=NULL){
      fprintf(sample_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
	print_tree(tree,sample_file_p,0);
    }
    if(ISMODE(PROBS)){
      fprintf(prob_file_p,"\n#Factor %E\n",f);
      if(ISMODE(TREES))
	print_tree(tree,prob_file_p,0);
    }
    det=find_information(tree,tree2,e,factor_flag,factor);

    /*  Possible may want to print out more than one result*/
    b=1;
    if(ISMODE(INDIVIDUAL))
      b=individual;
    
    if(ISMODE(INDIVIDUAL)){
      if(ISMODE(DETINDIV)){
	fprintf(file_p,"\t\t\t%E\tD(",det[0]);
	for(a=0;a<b-1;a++)
	  fprintf(file_p,"%d,",interesting_branches[a]);
	fprintf(file_p,"%d)\n",interesting_branches[a]);
      }else
	for(a=0;a<b;a++)
	  fprintf(file_p,"\t\t\t%E\t%d\n",det[a],interesting_branches[a]);
    }else
      fprintf(file_p,"\t\t\t%E\tD\n",det[0]);
    
    if(ISMODE(HKY) && NOTMODE(NOKAPPA) && NOTMODE(PERCENTILE))
      fprintf(file_p,"\t\t\t%E\tKappa\n",det[b]);
    free(det);
  }
}
示例#26
0
int processdir(int level, const char *base, const char *dirname, struct stat *sb,
               struct filenode *dir, struct filenode *root, int curroffset) {
    DIR *dirfd;
    struct dirent *dp;
    struct filenode *n, *link;
    struct excludes *pe;

    if(level <= 1) {
        /* Ok, to make sure . and .. are handled correctly
         * we add them first.  Note also that we alloc them
         * first to get to know the real name
         */
        link = newnode(base, ".", curroffset);

        if(!lstat(link->realname, sb)) {
            setnode(link, sb->st_dev, sb->st_ino, sb->st_mode);
            append(&dir->dirlist, link);

            /* special case for root node - '..'s in subdirs should link to
             *   '.' of root node, not root node itself.
             */
            dir->dirlist.owner = link;

            curroffset = alignnode(link, curroffset, 0) + spaceneeded(link);
            n = newnode(base, "..", curroffset);

            if(!lstat(n->realname, sb)) {
                setnode(n, sb->st_dev, sb->st_ino, sb->st_mode);
                append(&dir->dirlist, n);
                n->orig_link = link;
                curroffset = alignnode(n, curroffset, 0) + spaceneeded(n);
            }
        }
    }

    dirfd = opendir(dir->realname);

    while((dp = readdir(dirfd))) {
        /* don't process main . and .. twice */
        if(level <= 1 &&
                (strcmp(dp->d_name, ".") == 0
                 || strcmp(dp->d_name, "..") == 0))
            continue;

        n = newnode(base, dp->d_name, curroffset);

        /* Process exclude list. */
        for(pe = excludelist; pe; pe = pe->next) {
            if(!nodematch(pe->pattern, n)) {
                freenode(n);
                break;
            }
        }

        if(pe) continue;

        if(lstat(n->realname, sb)) {
            fprintf(stderr, "ignoring '%s' (lstat failed)\n", n->realname);
            freenode(n);
            continue;
        }

        /* Handle special names */
        if(n->name[0] == '@') {
            if(S_ISLNK(sb->st_mode)) {
                /* this is a link to follow at build time */
                n->name = n->name + 1; /* strip off the leading @ */
                memset(bigbuf, 0, sizeof(bigbuf));
                if(readlink(n->realname, bigbuf, sizeof(bigbuf))) {
                    return -1;
                }
                n->realname = strdup(bigbuf);

                if(lstat(n->realname, sb)) {
                    fprintf(stderr, "ignoring '%s' (lstat failed)\n",
                            n->realname);
                    freenode(n);
                    continue;
                }
            }
            else if(S_ISREG(sb->st_mode) && sb->st_size == 0) {
                /*
                 *        special file @name,[bcp..],major,minor
                 */
                char      devname[32];
                char      type;
                int       major;
                int       minor;

                if(sscanf(n->name, "@%[a-zA-Z0-9],%c,%d,%d",
                          devname, &type, &major, &minor) == 4) {
                    strcpy(n->name, devname);
                    sb->st_rdev = makedev(major, minor);
                    sb->st_mode &= ~S_IFMT;

                    switch(type) {
                        case 'c':
                        case 'u':
                            sb->st_mode |= S_IFCHR;
                            break;
                        case 'b':
                            sb->st_mode |= S_IFBLK;
                            break;
                        case 'p':
                            sb->st_mode |= S_IFIFO;
                            break;
                        default:
                            fprintf(stderr, "Invalid special device type '%c' "
                                    "for file %s\n", type, n->realname);
                            freenode(n);
                            continue;
                    }
                }
            }
        }

        setnode(n, sb->st_dev, sb->st_ino, sb->st_mode);

        /* Skip unreadable files/dirs */
        if(!S_ISLNK(n->modes) && access(n->realname, R_OK)) {
            fprintf(stderr, "ignoring '%s' (access failed)\n", n->realname);
            freenode(n);
            continue;
        }

        /* Look up old links */
        if(strcmp(n->name, ".") == 0) {
            append(&dir->dirlist, n);
            link = n->parent;
        }
        else if(strcmp(n->name, "..") == 0) {
            append(&dir->dirlist, n);
            link = n->parent->parent;
        }
        else {
            link = findnode(root, n->ondev, n->onino);
            append(&dir->dirlist, n);
        }

        if(link) {
            n->orig_link = link;
            curroffset = alignnode(n, curroffset, 0) + spaceneeded(n);
            continue;
        }

        if(S_ISREG(sb->st_mode)) {
            curroffset = alignnode(n, curroffset, spaceneeded(n));
            n->size = sb->st_size;
        }
        else
            curroffset = alignnode(n, curroffset, 0);

        if(S_ISLNK(sb->st_mode)) {
            n->size = sb->st_size;
        }

        curroffset += spaceneeded(n);

        if(S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) {
            n->devnode = sb->st_rdev;
        }

        if(S_ISDIR(sb->st_mode)) {
            if(!strcmp(n->name, "..")) {
                curroffset = processdir(level + 1, dir->realname, dp->d_name,
                                        sb, dir, root, curroffset);
            }
            else {
                curroffset = processdir(level + 1, n->realname, dp->d_name,
                                        sb, n, root, curroffset);
            }

            if(curroffset < 0)
                return -1;
        }
    }

    closedir(dirfd);
    return curroffset;
}
示例#27
0
文件: rules.c 项目: CitiLogics/EPANET
int  newpremise(int logop)
/*
**--------------------------------------------------------------------
**   Adds new premise to current rule.
**   Formats are:
**     IF/AND/OR <object> <id> <variable> <operator> <value>
**     IF/AND/OR  SYSTEM <variable> <operator> <value> (units)
**
**   Calls findmatch() and hour() in INPUT2.C.
**   Calls findnode() and findlink() in EPANET.C.
**---------------------------------------------------------------------
*/
{
   int   i,j,k,m,r,s,v;
   double x;
   struct Premise *p;

   /* Check for correct number of tokens */
   if (Ntokens != 5 && Ntokens != 6) return(201);

   /* Find network object & id if present */
   i = findmatch(Tok[1],Object);
   if (i == r_SYSTEM)
   { 
      j = 0;
      v = findmatch(Tok[2],Varword);
      if (v != r_DEMAND && v != r_TIME && v != r_CLOCKTIME) return(201);
   }
   else
   {
      v = findmatch(Tok[3],Varword);
      if (v < 0) return(201);
      switch (i) 
      {
         case r_NODE:
         case r_JUNC:
         case r_RESERV:
         case r_TANK:   k = r_NODE; break;
         case r_LINK:
         case r_PIPE:
         case r_PUMP:
         case r_VALVE:  k = r_LINK; break;
         default: return(201);
      }
      i = k;
      if (i == r_NODE)
      {
         j = findnode(Tok[2]);
         if (j == 0) return(203);
         switch (v)
         {
            case r_DEMAND:
            case r_HEAD:
            case r_GRADE:
            case r_LEVEL:
            case r_PRESSURE: break;

/*** Updated 9/7/00 ***/
            case r_FILLTIME:
            case r_DRAINTIME: if (j <= Njuncs) return(201); break;

            default: return(201);
         }
      }
      else
      {
         j = findlink(Tok[2]);
         if (j == 0) return(204);
         switch (v)
         {
            case r_FLOW:
            case r_STATUS:
            case r_SETTING: break;
            default: return(201);
         }
      }
   }

   /* Parse relational operator (r) and check for synonyms */
   if (i == r_SYSTEM) m = 3;
   else m = 4;
   k = findmatch(Tok[m],Operator);
   if (k < 0) return(201);
   switch(k)
   {
      case IS:    r = EQ; break;
      case NOT:   r = NE; break;
      case BELOW: r = LT; break;
      case ABOVE: r = GT; break;
      default:    r = k;
   }

   /* Parse for status (s) or numerical value (x) */
   s = 0;
   x = MISSING;
   if (v == r_TIME || v == r_CLOCKTIME)
   {
      if (Ntokens == 6)
         x = hour(Tok[4],Tok[5])*3600.;
      else
         x = hour(Tok[4],"")*3600.;
      if (x < 0.0) return(202);
   }
   else if ((k = findmatch(Tok[Ntokens-1],Value)) > IS_NUMBER) s = k;
   else
   {
      if (!getfloat(Tok[Ntokens-1],&x)) return(202);
      if (v == r_FILLTIME || v == r_DRAINTIME) x = x*3600.0;                   //(2.00.11 - LR)
   }

   
         
   /* Create new premise structure */
   p = (struct Premise *) malloc(sizeof(struct Premise));
   if (p == NULL) return(101);
   p->object = i;
   p->index =  j;
   p->variable = v;
   p->relop = r;
   p->logop = logop;
   p->status   = s;
   p->value    = x;

   /* Add premise to current rule's premise list */
   p->next = NULL;
   if (Plast == NULL) Rule[Nrules].Pchain = p;
   else Plast->next = p;
   Plast = p;
   return(0);
}
示例#28
0
文件: ls.c 项目: gosudream/netbsd-src
/* ARGSUSED */
static int
ls_fileproc (void *callerdat, struct file_info *finfo)
{
    Vers_TS *vers;
    char *regex_err;
    Node *p, *n;
    bool isdead;
    const char *filename;

    if (regexp_match)
    {
#ifdef FILENAMES_CASE_INSENSITIVE
	  re_set_syntax (REG_ICASE|RE_SYNTAX_EGREP);
#else
	  re_set_syntax (RE_SYNTAX_EGREP);
#endif
	  if ((regex_err = re_comp (regexp_match)) != NULL)
	  {
	      error (1, 0, "bad regular expression passed to 'ls': %s",
                     regex_err);
	  }
	  if (re_exec (finfo->file) == 0)
	      return 0;				/* no match */
    }

    vers = Version_TS (finfo, NULL, show_tag, show_date, 1, 0);
    /* Skip dead revisions unless specifically requested to do otherwise.
     * We also bother to check for long_format so we can print the state.
     */
    if (vers->vn_rcs && (!show_dead_revs || long_format))
	isdead = RCS_isdead (finfo->rcs, vers->vn_rcs);
    else
	isdead = false;
    if (!vers->vn_rcs || (!show_dead_revs && isdead))
    {
        freevers_ts (&vers);
	return 0;
    }

    p = findnode (callerdat, finfo->update_dir);
    if (!p)
    {
	/* This only occurs when a complete path to a file is specified on the
	 * command line.  Put the file in the root list.
	 */
	filename = finfo->fullname;

	/* Add update_dir node.  */
	p = findnode (callerdat, ".");
	if (!p)
	{
	    p = getnode ();
	    p->key = xstrdup (".");
	    p->data = getlist ();
	    p->delproc = ls_delproc;
	    addnode (callerdat, p);
	}
    }
    else
	filename = finfo->file;

    n = getnode();
    if (entries_format)
    {
	char *outdate = entries_time (RCS_getrevtime (finfo->rcs, vers->vn_rcs,
                                                      0, 0));
	n->data = Xasprintf ("/%s/%s/%s/%s/%s%s\n",
                             filename, vers->vn_rcs,
                             outdate, vers->options,
                             show_tag ? "T" : "", show_tag ? show_tag : "");
	free (outdate);
    }
    else if (long_format)
    {
	struct long_format_data *out =
		xmalloc (sizeof (struct long_format_data));
	out->header = Xasprintf ("%-5.5s",
                                 vers->options[0] != '\0' ? vers->options
                                                          : "----");
	/* FIXME: Do we want to mimc the real `ls' command's date format?  */
	out->time = gmformat_time_t (RCS_getrevtime (finfo->rcs, vers->vn_rcs,
                                                     0, 0));
	out->footer = Xasprintf (" %-9.9s%s %s%s", vers->vn_rcs,
                                 strlen (vers->vn_rcs) > 9 ? "+" : " ",
                                 show_dead_revs ? (isdead ? "dead " : "     ")
                                                : "",
                                 filename);
	n->data = out;
	n->delproc = long_format_data_delproc;
    }
    else
	n->data = Xasprintf ("%s\n", filename);

    addnode (p->data, n);

    freevers_ts (&vers);
    return 0;
}
示例#29
0
文件: wsp.c 项目: andreas-wilm/stral
/* Function:		
 * 
 * Purpose:		calculates the path from root to leaf		
 *           
 * Args:			p,q:
 *				wtree:
 *
 * Returns:		void
 */
float leaf2leaf(node *q,tree wtree, node *p,int k , int l){
	int i=0;
	int m;
	node **nodearray;

	float *branchorder;
	float lengthtoleaf =0;
	int odd=1;
	
	struct node *n;
	n = (struct node *)malloc(sizeof(struct node));
	n->tip=1;
	nodearray = (struct node **)malloc(sizeof(struct node *));
	*(nodearray+i) = (struct node *)malloc(sizeof(struct node));
	
	

	
	
	nodearray[i] = q;
	branchorder = (float *)calloc(1,sizeof(float));
	branchorder[i]=0;
	while(q!=p){
		
		if (q->back == NULL)
			q->back=n;
		if (odd && !(q->back->tip)) {
			int j;
			nodearray = (struct node **)realloc(nodearray,(i+2)*sizeof(struct node *));
			branchorder = (float *)realloc(branchorder,(i+2)*(sizeof (float)));
			*(nodearray+(i+1)) = (struct node *)malloc(sizeof(struct node));
			nodearray[i+1] = q->back;
			branchorder[i+1]=q->v;
			++i;
/*			printf("nodearray[%d]->next: %p\n",i, nodearray[i]);
			printf("i: %d\n",i);
			fflush(stdout);*/
			odd = !odd;
			q = q->back;
			j = findnode(nodearray, q, i);
/*			printf("j: %d\n",j);*/
			fflush(stdout);	
			if (j < i){
				nodearray = (struct node **)realloc(nodearray,(j+2)*sizeof(struct node *));
				branchorder = (float *)realloc(branchorder,(j+2)*(sizeof (float)));
				nodearray[j+1]=q->next;

				branchorder[j+1]=0;
				j++;
/*				printf("nodearray[%d]: %p\n",j, nodearray[j]);				*/
				i=j;

/*				printf("i: %d, j: %d\n",i,j);*/
				fflush(stdout);
			} 
		} 
		
		
		else if (odd && (q->back->tip) && (q->back!=p)){
			int j;
			nodearray = (struct node **)realloc(nodearray,(i+2)*sizeof(struct node *));
			branchorder = (float *)realloc(branchorder,(i+2)*(sizeof(float)));
			*(nodearray+(i+1)) = (struct node *)malloc(sizeof(struct node));
			nodearray[i+1] = nodearray[i]->next;
			branchorder[i+1] = 0;
			
			++i;
			q = q->next;
			j = findnode(nodearray, q, i);
/*			printf("nodearray[%d]->next: %p\n",i, nodearray[i]);
			printf("odd,tip: i: %d, j: %d\n",i,j);
			fflush(stdout);*/
			if (j < i){
				nodearray = (struct node **)realloc(nodearray,(j)*sizeof(struct node *));
				branchorder = (float *)realloc(branchorder,(j)*(sizeof (float)));
				i = j;
/*				printf("i: %d, j: %d\n",i,j);
				fflush(stdout);*/
			} 
		} 
		
		
		else if (odd && (q->back->tip) && (q->back==p)){
/*			int j = 0;
			printf("odd,q=p: i: %d, j: %d\n",i,j);*/
			nodearray = (struct node **)realloc(nodearray,(i+2)*sizeof(struct node *));
			branchorder = (float *)realloc(branchorder,(i+2)*(sizeof(float)));
			*(nodearray+(i+1)) = (struct node *)malloc(sizeof(struct node));
			nodearray[i+1] = nodearray[i]->back;
			branchorder[i+1] = q->v;
			++i;
/*			printf("nodearray[%d]->next: %p\n",i, nodearray[i]);
			printf("odd,q=p: i: %d, j: %d\n",i,j);
			fflush(stdout);*/
			q = q->back;
		} 
		
		
		else if (!odd){
			int j;
			nodearray = (struct node **)realloc(nodearray,(i+2)*sizeof(struct node *));
			branchorder = (float *)realloc(branchorder,(i+2)*(sizeof(float)));
			*(nodearray+(i+1)) = (struct node *)malloc(sizeof(struct node));
			nodearray[i+1] = nodearray[i]->next;
			branchorder[i+1] = 0;
			++i;
/*			printf("nodearray[%d]->next: %p\n",i, nodearray[i]);
			fflush(stdout);*/
			odd = !odd;
			q = q->next;
			j = findnode(nodearray, q, i);
/*			printf("!odd: i: %d, j: %d\n",i,j);
			fflush(stdout);*/
			if (j < i){
				nodearray = (struct node **)realloc(nodearray,(j+2)*sizeof(struct node *));
				branchorder = (float *)realloc(branchorder,(j+2)*(sizeof (float)));
				nodearray[j] = q;
				i = j;
/*				printf("i: %d, j: %d\n",i,j);
				fflush(stdout);*/
			}
		}
	}
	
/*	printf("i: %d\n",i);*/
	brancharray[k][l] = (struct node **)malloc((i+1)*sizeof(struct node *));
	blgth[k][l] = (float *)calloc((i+1),sizeof(float));
	for (m=0; m <= i; ++m){
		lengthtoleaf = lengthtoleaf + branchorder[m];
		arraysize[k][l]=i+1; 
		brancharray[k][l][m]=nodearray[m];
		blgth[k][l][m]=branchorder[m];
		/*printf("nodearray[%d]->v: %f; p: %p\n",k,branchorder[m], nodearray[m]);*/
	}
	
	
	free(nodearray);
	free(branchorder);
	return lengthtoleaf;
}
示例#30
0
文件: ls.c 项目: gosudream/netbsd-src
/*
 * Add this directory to the list of data to be printed for a directory and
 * decide whether to tell the recursion processor whether to continue
 * recursing or not.
 */
static Dtype
ls_direntproc (void *callerdat, const char *dir, const char *repos,
               const char *update_dir, List *entries)
{
    Dtype retval;
    Node *p;

    /* Due to the way we called start_recursion() from ls_proc() with a single
     * argument at a time, we can assume that if we don't yet have a parent
     * directory in DIRS then this directory should be processed.
     */

    if (strcmp (dir, "."))
    {
        /* Search for our parent directory.  */
	char *parent;
        parent = xmalloc (strlen (update_dir) - strlen (dir) + 1);
        strncpy (parent, update_dir, strlen (update_dir) - strlen (dir));
        parent[strlen (update_dir) - strlen (dir)] = '\0';
        strip_trailing_slashes (parent);
        p = findnode (callerdat, parent);
    }
    else
        p = NULL;

    if (p)
    {
	/* Push this dir onto our parent directory's listing.  */
	Node *n = getnode();

	if (entries_format)
	    n->data = Xasprintf ("D/%s////\n", dir);
	else if (long_format)
	{
	    struct long_format_data *out =
		    xmalloc (sizeof (struct long_format_data));
	    out->header = xstrdup ("d--- ");
	    out->time = gmformat_time_t (unix_time_stamp (repos));
	    out->footer = Xasprintf ("%12s%s%s", "",
                                     show_dead_revs ? "     " : "", dir);
	    n->data = out;
	    n->delproc = long_format_data_delproc;
	}
	else
	    n->data = Xasprintf ("%s\n", dir);

	addnode (p->data, n);
    }

    if (!p || recurse)
    {
	/* Create a new list for this directory.  */
	p = getnode ();
	p->key = xstrdup (strcmp (update_dir, ".") ? update_dir : "");
	p->data = getlist ();
        p->delproc = ls_delproc;
	addnode (callerdat, p);

	/* Create a local directory and mark it as needing deletion.  This is
         * the behavior the recursion processor relies upon, a la update &
         * checkout.
         */
	if (!isdir (dir))
        {
	    int nonbranch;
	    if (show_tag == NULL && show_date == NULL)
	    {
		ParseTag (&show_tag, &show_date, &nonbranch);
		set_tag = true;
	    }

	    if (!created_dir)
		created_dir = xstrdup (update_dir);

	    make_directory (dir);
	    Create_Admin (dir, update_dir, repos, show_tag, show_date,
			  nonbranch, 0, 0);
	    Subdir_Register (entries, NULL, dir);
	}

	/* Tell do_recursion to keep going.  */
	retval = R_PROCESS;
    }
    else
        retval = R_SKIP_ALL;

    return retval;
}