示例#1
0
/* add download paths --------------------------------------------------------*/
static int add_path(paths_t *paths, const char *remot, const char *dir)
{
    path_t *paths_path;
    char local[1024];
    
    if (paths->n>=paths->nmax) {
        paths->nmax=paths->nmax<=0?1024:paths->nmax*2;
        paths_path=(path_t *)realloc(paths->path,sizeof(path_t)*paths->nmax);
        if (!paths_path) {
            free_path(paths);
            return 0;
        }
        paths->path=paths_path;
    }
    remot2local(remot,dir,local);
    
    paths->path[paths->n].remot=paths->path[paths->n].local=NULL;
    
    if (!(paths->path[paths->n].remot=(char *)malloc(strlen(remot)+1))||
        !(paths->path[paths->n].local=(char *)malloc(strlen(local)+1))) {
        free_path(paths);
        return 0;
    }
    strcpy(paths->path[paths->n].remot,remot);
    strcpy(paths->path[paths->n].local,local);
    paths->n++;
    return 1;
}
示例#2
0
/* execute download ------------------------------------------------------------
* execute download
* args   : gtime_t ts,te    I   time start and end
*          double tint      I   time interval (s)
*          int    seqnos    I   sequence number start
*          int    seqnoe    I   sequence number end
*          url_t  *urls     I   url address list
*          int    nurl      I   number of urls
*          char   **stas    I   station list
*          int    nsta      I   number of stations
*          char   *dir      I   local directory
*          char   *remote_p I   previous remote file path
*          char   *usr      I   login user for ftp
*          char   *pwd      I   login password for ftp
*          char   *proxy    I   proxy server address
*          int    opts      I   download options (or of the followings)
*                                 DLOPT_FORCE = force download existing file
*                                 DLOPT_KEEPCMP=keep compressed file
*                                 DLOPT_HOLDERR=hold on error file
*                                 DLOPT_HOLDLST=hold on listing file
*          char   *msg      O   output messages
*          FILE   *fp       IO  log file pointer (NULL: no output log)
* return : status (1:ok,0:error,-1:aborted)
* notes  : urls should be read by using dl_readurl()
*-----------------------------------------------------------------------------*/
extern int dl_exec(gtime_t ts, gtime_t te, double ti, int seqnos, int seqnoe,
                   const url_t *urls, int nurl, char **stas, int nsta,
                   const char *dir, const char *usr, const char *pwd,
                   const char *proxy, int opts, char *msg, FILE *fp)
{
    paths_t paths={0};
    gtime_t ts_p={0};
    char str[2048],remot_p[1024]="";
    int i,n[4]={0};
    unsigned int tick=tickget();
    
    showmsg("STAT=_");
    
    /* generate download paths  */
    while (timediff(ts,te)<1E-3) {
        
        for (i=0;i<nurl;i++) {
            if (!gen_paths(ts,ts_p,seqnos,seqnoe,urls+i,stas,nsta,dir,&paths)) {
                free_path(&paths);
                return 0;
            }
        }
        ts_p=ts; ts=timeadd(ts,ti);
    }
    /* compact download paths */
    compact_paths(&paths);
    
    if (paths.n<=0) {
        sprintf(msg,"no download data");
        return 0;
    }
    for (i=0;i<paths.n;i++) {
        
        sprintf(str,"%s->%s (%d/%d)",paths.path[i].remot,paths.path[i].local,i+1,
                paths.n);
        if (showmsg(str)) break;
        
        /* execute download */
        if (exec_down(paths.path+i,remot_p,usr,pwd,proxy,opts,n,fp)) {
            break;
        }
    }
    if (!(opts&DLOPT_HOLDLST)) {
        remove(FTP_LISTING);
    }
    sprintf(msg,"OK=%d No_File=%d Skip=%d Error=%d (Time=%.1f s)",n[0],n[1],n[2],
            n[3],(tickget()-tick)*0.001);
    
    free_path(&paths);
    
    return 1;
}
示例#3
0
int
cha_parse_bos(cha_lat_t *lat)
{
    static int path0 = -1;

    lat->offset = lat->cursor = 0;
    lat->anno = lat->last_anno = -1;
    lat->head_path = 1;

    cha_block_clear(Cha_mrph_block);

    free_chars();
    free_path();

    Cha_path[0].start = Cha_path[0].end = 0;
    Cha_path[0].path = &path0;
    Cha_path[0].cost = 0;
    Cha_path[0].mrph_p = 0;
    Cha_path[0].state = 0;

    Cha_path_num = 1;
    register_bos_eos();

    return 0;
}
示例#4
0
/* gets the lowest free inode, or 0 if errno.
 * (inode 0 is the root dir, which is never free)
 * not concerned with optimizations at this point in the project.
 */
PUBLIC uint32_t find_free_inode(struct fs_info *fsi) {
	struct key first;
	struct key *key;
	struct path p;
	uint32_t prev_inode;
	int ret;

	set_inode_key(0, &first);
	ret = search_slot(&fsi->fs_root, &first, &p, 0);
	if (ret < 0) {
		errno = -ret;
		return 0;
	}
	key = key_for(p.nodes[0], p.slots[0]);
	while (TRUE) {
		prev_inode = key->objectid;
		ret = step_to_next_slot(&p);
		if (ret < 0) {
			errno = -ret;
			return 0;
		}
		if (ret == KEY_NOT_FOUND) {	/* no more items, and no path to free */
			return prev_inode + 1;
		}
		assert(ret == SUCCESS);
		key = key_for(p.nodes[0], p.slots[0]);
		if (key->objectid - prev_inode > 1) {
			free_path(&p);
			return prev_inode + 1;
		}
	}
}
示例#5
0
void		free_path(t_path *path)
{
	if (path)
	{
		if (path->next)
			free_path(path->next);
		free(path);
	}
}
示例#6
0
void		free_paths(t_paths *paths)
{
	if (paths)
	{
		free_path(paths->path);
		if (paths->next)
			free_paths(paths->next);
		free(paths);
	}
}
示例#7
0
文件: free_env.c 项目: elhmn/Vog42sh
static void free_path(t_path *path)
{
	if (path)
	{
		free(path->dir);
		if (path->nxt)
			free_path(path->nxt);
		free(path);
	}
}
示例#8
0
/* inserts an empty item into the tree at the given key.
 * (This function's signature is modeled after the one in Btrfs.)
 * r - the root of the tree to insert into
 * key - the key to insert
 * p - path result prepared
 * ins_len - number of bytes needed for the item and its metadata in leaf.
 * returns 0 if inserted, or a negative errno.
 */
PUBLIC int insert_empty_item(struct root *r, struct key *key, struct path *p,
						int ins_len) {
	int ret;
	ret = search_slot(r, key, p, ins_len);
	if (ret == KEY_FOUND) {
		free_path(p);
		return -EEXIST;
	}
	if (ret != KEY_NOT_FOUND) return ret;
	return insert_item_in_leaf(r, p, key, ins_len);
}
示例#9
0
文件: free_env.c 项目: elhmn/Vog42sh
void		free_env(t_env *env)
{
	if (env)
	{
		if (env->path)
			free_path(env->path);
		if (env->var)
			free_var(env->var);
		free(env);
	}
}
示例#10
0
static int
sysctl_nodecount(SYSCTL_HANDLER_ARGS)
{
    int             error, i;
    int             newcount = nodecount;


    error = sysctl_handle_int(oidp, &newcount, 0, req);
    if (error || !req->newptr)
        return (error);

    mtx_lock(mn_mtx);

    if (newcount != nodecount) {
        free_path();            /* free_path requires the old nodecount */
        nodecount = newcount;

        pathtable = malloc(nodecount * sizeof(struct hop **),
                           M_MN_ROUTE, M_WAITOK | M_ZERO);
        if (!pathtable) {
            free_path();
	    mtx_unlock(mn_mtx);
            return ENOMEM;
        }
        for (i = 0; i < nodecount; ++i) {
            pathtable[i] = malloc(nodecount * sizeof(struct hop *),
                                  M_MN_ROUTE, M_WAITOK | M_ZERO);
            if (!pathtable[i]) {
		nodecount=i-1;
                free_path();
		mtx_unlock(mn_mtx);
                return ENOMEM;
            }
        }
    }

    mtx_unlock(mn_mtx);
    
    return 0;
}
示例#11
0
t_path			*free_path(t_path *path)
{
	t_path			*tmp;

	if (path == NULL)
		return (NULL);
	else
	{
		tmp = path->next;
		free(path);
		return (free_path(tmp));
	}
}
示例#12
0
void
free_pathvec (vector vec, int free_paths)
{
	int i;
	struct path * pp;

	if (!vec)
		return;

	if (free_paths)
		vector_foreach_slot(vec, pp, i)
			free_path(pp);

	vector_free(vec);
}
示例#13
0
/* gets the inode of a directory entry, or 0 if errno.
 * (inode 0 is the root dir, which is not an entry in any dir)
 */
PUBLIC uint32_t get_dir_ent_inode(struct fs_info *fsi, uint32_t dir_inode,
									char *name) {
	struct path p;
	struct key key;
	struct dir_ent_metadata *demd;
	int ret;

	set_dir_ent_key(dir_inode, name, &key);
	ret = search_slot(&fsi->fs_root, &key, &p, 0);
	if (ret == KEY_NOT_FOUND) {
		free_path(&p);	/* only for search_slot(), not step_to_next_slot() */
	}
	while (TRUE) {
		if (ret == KEY_NOT_FOUND) {
			errno = ENOENT;
		}
		if (ret < 0) {
			errno = -ret;
		}
		if (ret != KEY_FOUND) {
			return 0;	/* failure, with errno */
		}
		demd = (struct dir_ent_metadata *) metadata_for(&p);
		if (!strcmp(name, demd->name)) {	/* name matches */
			ret = demd->inode;
			free_path(&p);
			return ret;
		}
		ret = step_to_next_slot(&p);
		if (ret == KEY_FOUND && compare_keys(&key, item_key(&p))) {
			errno = ENOENT;
			free_path(&p);
			return 0;	/* failure, with errno */
		}
	}
}
示例#14
0
int
main (int argc, char **argv)
{
  if (argc != 2)
    usage (argv[0], 1);

  split_path (argv[1]);
  init_inotify ();

  if (! exists (watch_path))
    loop_inotify ();

  deinit_inotify ();
  free_path ();

  return 0;
}
示例#15
0
void			print_solve(t_path *begin, t_env *data)
{
	t_path	*end_room;
	int		round;

	end_room = begin;
	round = 0;
	while (end_room->next)
		end_room = end_room->next;
	while (end_room->gone_ant < data->ants)
	{
		play_round(begin, end_room, data, round);
		round++;
		ft_putchar('\n');
	}
	free_path(begin);
}
示例#16
0
void clip_rgn_mix(drawingStates *states, PATH *path, uint32_t mode) {
    // FIXME need to handle clip region definition properly.
    // Need to calculate new clipping form.
    // it's not trivial, use a lib like polyclip (cpp) which in turn
    // needs to convert Bezier/ARC curves in segment.
    switch (mode) {
    case U_RGN_NONE:
    case U_RGN_AND:
    case U_RGN_OR:
    case U_RGN_XOR:
    case U_RGN_DIFF:
    case U_RGN_COPY:
    default:
        free_path(&(states->currentDeviceContext.clipRGN));
        copy_path(path, &(states->currentDeviceContext.clipRGN));
        break;
    }
}
示例#17
0
PUBLIC int get_inode_metadata(struct fs_info *fsi, uint32_t inode,
								struct inode_metadata *imd) {
	struct path p;
	struct key key;
	int ret;

	set_inode_key(inode, &key);
	ret = search_slot(&fsi->fs_root, &key, &p, 0);
	if (ret == KEY_NOT_FOUND) ret = -ENOENT;
	if (ret == KEY_FOUND) {
		memmove(imd, metadata_for(&p), sizeof(*imd));
	}
	if (ret == KEY_FOUND || ret == KEY_NOT_FOUND) {
		free_path(&p);
	}
	assert(KEY_FOUND == SUCCESS);
	return ret;
}
示例#18
0
/* inserts a directory entry.
 * dir_inode - inode of the directory in which to insert
 * name - of the inserted file or directory
 * ent_inode - inode of the inserted file or directory
 * returns 0 for success, or negative errno.
 */
PUBLIC int insert_dir_ent(struct fs_info *fsi, uint32_t dir_inode,
								char *name, uint32_t ent_inode) {
	struct path p;
	struct key key;
	struct dir_ent_metadata *demd;
	int len = strlen(name), ret;

	if (len > MAX_FILE_NAME_LENGTH) {
		return -ENAMETOOLONG;
	}
	set_dir_ent_key(dir_inode, name, &key);
	ret = insert_empty_item_allowing_duplicates(&fsi->fs_root, &key, &p,
							sizeof(struct item) + sizeof(*demd) + len);
	if (ret) return ret;
	demd = (struct dir_ent_metadata *) metadata_for(&p);
	demd->inode = ent_inode;
	memmove(&demd->name, name, len);
	free_path(&p);
	return 0;	/* failure, with errno */
}
示例#19
0
PUBLIC int insert_inode(struct fs_info *fsi, uint32_t inode,
						uint16_t inode_type) {
	struct path p;
	struct key key;
	struct inode_metadata *imd; 
	int ins_len = sizeof(struct item) + sizeof(*imd); 
	int ret;

	set_inode_key(inode, &key);
	ret = insert_empty_item(&fsi->fs_root, &key, &p, ins_len);
	if (ret) return ret;

	imd = (struct inode_metadata *) metadata_for(&p);
	imd->inode_type = inode_type;
	imd->ctime = get_time();
	imd->mtime = get_time();

	free_path(&p);
	return SUCCESS;
}
示例#20
0
/* uninit_paths[]
 *
 * remove paths, but also remove each hop 
 */
void
uninit_paths(void)
{
    int             i;

    mtx_lock(mn_mtx);
    
    free_path();
    if (hoptable) {
	    for (i = 0; i < hopcount; ++i){
		    xtq_uninstall(&(hoptable[i]),-1);
		    free(hoptable[i].exittick, M_MN_CONF);
		    free(hoptable[i].slotlen, M_MN_CONF);
	    }
	    free(hoptable, M_MN_CONF);
    }
    hoptable = NULL;
    hopcount = 0;

    mtx_unlock(mn_mtx);
}
示例#21
0
static struct cpp_dir *
remove_duplicates (cpp_reader *pfile, struct cpp_dir *head,
		   struct cpp_dir *system, struct cpp_dir *join,
		   int verbose)
{
  struct cpp_dir **pcur, *tmp, *cur;
  struct stat st;

  for (pcur = &head; *pcur; )
    {
      int reason = REASON_QUIET;

      cur = *pcur;

      if (stat (cur->name, &st))
	{
	  /* Dirs that don't exist are silently ignored, unless verbose.  */
	  if (errno != ENOENT)
	    cpp_errno (pfile, CPP_DL_ERROR, cur->name);
	  else
	    {
	      /* If -Wmissing-include-dirs is given, warn.  */
	      cpp_options *opts = cpp_get_options (pfile);
	      if (opts->warn_missing_include_dirs && cur->user_supplied_p)
		cpp_errno (pfile, CPP_DL_WARNING, cur->name);
	      reason = REASON_NOENT;
	    }
	}
      else if (!S_ISDIR (st.st_mode))
	/* APPLE LOCAL begin headermaps 3871393 */
	{
	  /* Only check for headermap if this is a regular file and if there
	     is no path-constructor function in CUR. */
	  if (S_ISREG (st.st_mode) && !cur->construct)
	    {
	      /* Try to load the file as a headermap.  We will get back NULL
	         if this fails, and there won't be any warnings/errors emitted
	         unless the load function is fairly sure it's dealing with a
	         headermap file that is malformed.  */
	      struct hmap_header_map *header_map;

	      header_map = hmap_load_header_map (cur->name);
	      if (header_map)
		{
		  /* Successfully loaded a headermap.  Store a pointer to it
		     and set up the construct function pointer in cur.  */
		  cur->header_map = header_map;
		  cur->construct = hmap_construct_pathname;
		  pcur = &cur->next;
		  continue;
		}
	    }

	    /* If we fall through to here, it's some other kind of file.  */
	    cpp_error_with_line (pfile, CPP_DL_ERROR, 0, 0,
				 "%s: not a directory", cur->name);
	}
        /* APPLE LOCAL end headermaps 3871393 */
      else
	{
	  INO_T_COPY (cur->ino, st.st_ino);
	  cur->dev  = st.st_dev;

	  /* Remove this one if it is in the system chain.  */
	  reason = REASON_DUP_SYS;
	  for (tmp = system; tmp; tmp = tmp->next)
           if (INO_T_EQ (tmp->ino, cur->ino) && tmp->dev == cur->dev
               && cur->construct == tmp->construct)
	      break;

	  if (!tmp)
	    {
	      /* Duplicate of something earlier in the same chain?  */
	      reason = REASON_DUP;
	      for (tmp = head; tmp != cur; tmp = tmp->next)
               if (INO_T_EQ (cur->ino, tmp->ino) && cur->dev == tmp->dev
                   && cur->construct == tmp->construct)
		  break;

	      if (tmp == cur
		  /* Last in the chain and duplicate of JOIN?  */
		  && !(cur->next == NULL && join
		       && INO_T_EQ (cur->ino, join->ino)
                      && cur->dev == join->dev
                      && cur->construct == join->construct))
		{
		  /* Unique, so keep this directory.  */
		  pcur = &cur->next;
		  continue;
		}
	    }
	}

      /* Remove this entry from the chain.  */
      *pcur = cur->next;
      free_path (cur, verbose ? reason: REASON_QUIET);
    }

  *pcur = join;
  return head;
}
示例#22
0
void DSU::ComputeTBD(TBD &pqueue, int maxkeep, int num_threshold, bool outer, bool noLP, bool shifts, bool debug, vector<RNAsaddle> *output_saddles, int conn_neighs, bool no_new)
{
  int cnt = 0;

  clock_t time_tbd = clock();

  // go through all pairs in queue
  while (pqueue.size()>0) {
    // check time:
    double time_secs = ((clock()  - time)/(double)CLOCKS_PER_SEC);
    if (stop_after && (time_secs > stop_after)) {
      fprintf(stderr, "Time threshold reached (%d secs.), processed %d/%d\n", stop_after, cnt, pqueue.size()+cnt);
      break;
    }

    // just visualisation
    if (!output_saddles && cnt%100==0) {
      double tim = (clock()  - time_tbd)/(double)CLOCKS_PER_SEC;
      std::pair<int, int> mem = getValue();
      //double one = ((sizeof(char)*strlen(seq) + sizeof(short)*strlen(seq)) + sizeof(RNAsaddle)) / 1024.0;
      fprintf(stderr, "Finding path: %7d/%7d; Time: %6.2f; Est.:%6.2f Mem.:%6.1fMB VM %6.1fMB PM\n", cnt, pqueue.size()+cnt, tim, tim/(double)cnt*pqueue.size(), mem.first/1024.0, mem.second/1024.0);
    }

    // apply threshold
    if (cnt>num_threshold) {
      fprintf(stderr, "Number threshold reached, processed %d/%d\n", cnt, pqueue.size()+cnt);
      break;
    } else {
      cnt++;
    }

    // get next
    TBDentry tbd = pqueue.get_first();
    if (tbd.i==-1) {
      fprintf(stderr, "Ending the path-finding -- i = %5d ; j = %5d ; fiber = %c ; type = %s \n", tbd.i, tbd.j, tbd.fiber?'Y':'N', type1_str[tbd.type_clust]);
      break;
    }

    // check no-conn
    if (conectivity.size() > 0 && !tbd.fiber && conectivity.joint(tbd.i, tbd.j)) continue;


    // get path
    if (debug) fprintf(stderr, "path between (%3d, %3d) type=%s fiber=%d:\n", tbd.i, tbd.j, type1_str[tbd.type_clust], tbd.fiber);
    //2fprintf(stderr, "depth: %d\n%s\n%s\n%s\n", maxkeep, seq, LM[tbd.i].str_ch, LM[tbd.j].str_ch);
    if (pknots) {
      path_pk *path = get_path_light_pk(seq, LM[tbd.i].structure, LM[tbd.j].structure, maxkeep);

      // variables for outer insertion
      double max_energy= -1e8;
      path_pk *max_path = path;

      // variables for inner loops and insertions

      // get the length of path for speed up
      int length = 0;
      for (path_pk *tmp = path; tmp && tmp->structure; tmp++) {
        if (max_path->en < tmp->en) max_path = tmp;
        length ++;
      }

      // create vector of known LM numbers on path (where 0 and length-1 are known)
      vector<int> lm_numbers(length, -1);
      lm_numbers[0] = tbd.i;
      lm_numbers[length-1] = tbd.j;

      // debug
      if (debug) {
        for (int i=0; i<length; i++) {
          fprintf(stderr, "path[%3d] %s %6.2f\n", i, pt_to_str_pk(path[i].structure).c_str(), path[i].en/100.0);
        }
      }

      // bisect the path and find new LMs:
      unsigned int old_size = LM.size();
      FindNumbers(0, length-1, path, lm_numbers, shifts, noLP, debug, no_new);

      // if we have found new minima and we want to do more than simple reevaluation of path (--conn-neighs>0)
      if (LM.size() - old_size > 0 && conn_neighs > 0 && !no_new) {
        for (unsigned int j=old_size; j<LM.size(); j++) {

          // sort 'em according to Hamming D. and take first "conn_neighs"
          multimap<int, int> distances;
          for (unsigned int i=0; i<old_size; i++) {
            distances.insert(make_pair(HammingDist(LM[i].structure, LM[j].structure), i));
          }
          int cnt = 0;
          int last_hd = -1;
          for (auto it=distances.begin(); it!=distances.end(); it++) {
            if (cnt > conn_neighs && last_hd != it->first) {
              break;
            }

            pqueue.insert(it->second, j, EXPERIM, false);

            cnt++;
            last_hd = it->first;
          }
        }

      }

      // debug
      if (debug) {
        int diff = 1;
        int last_num = lm_numbers[0];
        for (int i=0; i<length; i++) {
          fprintf(stderr, "path[%3d]= %4d (%s %6.2f)\n", i, lm_numbers[i], pt_to_str_pk(path[i].structure).c_str(), path[i].en/100.0);
          if (lm_numbers[i]!=last_num && lm_numbers[i]!=-1) {
            diff++;
            last_num=lm_numbers[i];
          }
        }
        histo[length][diff]++;
        histo[length][0]++;
      }

      // now process the array of found numbers:
      int last_num = lm_numbers[0];
      for (int i=1; i<length; i++) {
        if (lm_numbers[i]!=-1 && lm_numbers[i]!=last_num) {

          // get the highest saddle in case we traveled through many "-1" saddles:
          int j=i-1;
          int highest_num = i;
          while (j>0) {
            // check if not higher saddle:
            if (path[highest_num].en < path[j].en) highest_num = j;

            // we found first that is not -1
            if (lm_numbers[j]!=-1) break;
            j--;
          }

          // save saddle
          SDtype typ = (j==i-1?DIRECT:REDUCED);
          RNAsaddle saddle(last_num, lm_numbers[i], typ);
          saddle.energy = path[highest_num].en;
          saddle.str_ch = NULL;
          saddle.structure = allocopy(path[highest_num].structure);
          bool inserted = InsertUB(saddle, debug);

          // ???
          if (output_saddles && inserted) {
            output_saddles->push_back(saddle);
          }

          // try to insert new things into TBD:
          if ((lm_numbers[i]!=lm_numbers[length-1] || lm_numbers[i-1]!=lm_numbers[0]) && !no_new) {
            // check no-conn
            if (conectivity.size() > 0) conectivity.union_set(tbd.i, tbd.j);
            pqueue.insert(lm_numbers[i-1], lm_numbers[i], NEW_FOUND, true);


          }
          last_num = lm_numbers[i];
        }
      }

      // insert saddle between outer structures
      if (outer) {
        RNAsaddle tmp(tbd.i, tbd.j, NOT_SURE);
        tmp.energy = en_fltoi(max_energy);
        tmp.str_ch = NULL;
        tmp.structure = allocopy(max_path->structure);

        bool inserted = InsertUB(tmp, debug);

        if (output_saddles && inserted) {
          output_saddles->push_back(tmp);
        }
      }

      free_path_pk(path);
    } else {
      //fprintf(stderr, "%s\n%s\n%s\n", seq, LM[tbd.i].str_ch, LM[tbd.j].str_ch);
      path_t *path = get_path(seq, LM[tbd.i].str_ch, LM[tbd.j].str_ch, maxkeep);

      // variables for outer insertion
      double max_energy= -1e8;
      path_t *max_path = path;

      // variables for inner loops and insertions

      // get the length of path for speed up
      int length = 0;
      for (path_t *tmp = path; tmp && tmp->s; tmp++) {
        if (max_path->en < tmp->en) max_path = tmp;
        length ++;
      }

      // create vector of known LM numbers on path (where 0 and length-1 are known)
      vector<int> lm_numbers(length, -1);
      lm_numbers[0] = tbd.i;
      lm_numbers[length-1] = tbd.j;

      // bisect the path and find new LMs:
      unsigned int old_size = LM.size();
      FindNumbers(0, length-1, path, lm_numbers, shifts, noLP, debug, no_new);

      // if we have found new minima and we want to do more than simple reevaluation of path (--conn-neighs>0)
      if (LM.size() - old_size > 0 && conn_neighs > 0 && !no_new) {
        for (unsigned int j=old_size; j<LM.size(); j++) {

          // sort 'em according to Hamming D. and take first "conn_neighs"
          multimap<int, int> distances;
          for (unsigned int i=0; i<old_size; i++) {
            distances.insert(make_pair(HammingDist(LM[i].structure, LM[j].structure), i));
          }
          int cnt = 0;
          int last_hd = -1;
          for (auto it=distances.begin(); it!=distances.end(); it++) {
            if (cnt > conn_neighs && last_hd != it->first) {
              break;
            }

            pqueue.insert(it->second, j, EXPERIM, false);

            cnt++;
            last_hd = it->first;
          }
        }

      }

      // debug
      if (debug) {
        int diff = 1;
        int last_num = lm_numbers[0];
        for (int i=0; i<length; i++) {
          fprintf(stderr, "path[%3d]= %4d (%s %6.2f)\n", i, lm_numbers[i], path[i].s, path[i].en);
          if (lm_numbers[i]!=last_num && lm_numbers[i]!=-1) {
            diff++;
            last_num=lm_numbers[i];
          }
        }
        histo[length][diff]++;
        histo[length][0]++;
      }

      // now process the array of found numbers:
      int last_num = lm_numbers[0];
      for (int i=1; i<length; i++) {
        if (lm_numbers[i]!=-1 && lm_numbers[i]!=last_num) {

          // get the highest saddle in case we traveled through many "-1" saddles:
          int j=i-1;
          int highest_num = i;
          while (j>0) {
            // check if not higher saddle:
            if (path[highest_num].en < path[j].en) highest_num = j;

            // we found first that is not -1
            if (lm_numbers[j]!=-1) break;
            j--;
          }

          // save saddle
          SDtype typ = (j==i-1?DIRECT:REDUCED);
          RNAsaddle saddle(last_num, lm_numbers[i], typ);
          saddle.energy = en_fltoi(path[highest_num].en);
          saddle.str_ch = NULL;
          saddle.structure = make_pair_table(path[highest_num].s);
          bool inserted = InsertUB(saddle, debug);

          // ???
          if (output_saddles && inserted) {
            output_saddles->push_back(saddle);
          }

          // try to insert new things into TBD:
          if ((lm_numbers[i]!=lm_numbers[length-1] || lm_numbers[i-1]!=lm_numbers[0]) && !no_new) {
            // check no-conn
            if (conectivity.size() > 0) conectivity.union_set(tbd.i, tbd.j);
            pqueue.insert(lm_numbers[i-1], lm_numbers[i], NEW_FOUND, true);
          }
          last_num = lm_numbers[i];
        }
      }

      // insert saddle between outer structures
      if (outer) {
        RNAsaddle tmp(tbd.i, tbd.j, NOT_SURE);
        tmp.energy = en_fltoi(max_energy);
        tmp.str_ch = NULL;
        tmp.structure = make_pair_table(max_path->s);

        bool inserted = InsertUB(tmp, debug);

        if (output_saddles && inserted) {
          output_saddles->push_back(tmp);
        }
      }

      free_path(path);
    }

    // free stuff
    //if (last_str) free(last_str);

  } // all doing while
  fprintf(stderr, "The end of finding paths(%d). Size of pqueue = %d\n", cnt, (int)pqueue.size());
}
示例#23
0
/* calculate a curve-deform path for a curve 
 * 	- only called from displist.c -> do_makeDispListCurveTypes
 */
void calc_curvepath(Object *ob)
{
	BevList *bl;
	BevPoint *bevp, *bevpn, *bevpfirst, *bevplast;
	PathPoint *pp;
	Curve *cu;
	Nurb *nu;
	Path *path;
	float *fp, *dist, *maxdist, xyz[3];
	float fac, d=0, fac1, fac2;
	int a, tot, cycl=0;
	ListBase *nurbs;
	
	/* in a path vertices are with equal differences: path->len = number of verts */
	/* NOW WITH BEVELCURVE!!! */
	
	if (ob==NULL || ob->type != OB_CURVE) return;
	cu= ob->data;

	nurbs= BKE_curve_nurbs(cu);
	nu= nurbs->first;

	if (cu->path) free_path(cu->path);
	cu->path= NULL;
	
	bl= cu->bev.first;
	if (bl==NULL || !bl->nr) return;

	cu->path=path= MEM_callocN(sizeof(Path), "calc_curvepath");
	
	/* if POLY: last vertice != first vertice */
	cycl= (bl->poly!= -1);
	
	if (cycl) tot= bl->nr;
	else tot= bl->nr-1;
	
	path->len= tot+1;
	/* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */
	if (path->len<nu->resolu*SEGMENTSU(nu)) path->len= nu->resolu*SEGMENTSU(nu);
	
	dist= (float *)MEM_mallocN((tot+1)*4, "calcpathdist");

		/* all lengths in *dist */
	bevp= bevpfirst= (BevPoint *)(bl+1);
	fp= dist;
	*fp= 0;
	for (a=0; a<tot; a++) {
		fp++;
		if (cycl && a==tot-1)
			sub_v3_v3v3(xyz, bevpfirst->vec, bevp->vec);
		else
			sub_v3_v3v3(xyz, (bevp+1)->vec, bevp->vec);
		
		*fp= *(fp-1)+len_v3(xyz);
		bevp++;
	}
	
	path->totdist= *fp;
	
		/* the path verts  in path->data */
		/* now also with TILT value */
	pp= path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint)*path->len, "pathdata");
	
	bevp= bevpfirst;
	bevpn= bevp+1;
	bevplast= bevpfirst + (bl->nr-1);
	fp= dist+1;
	maxdist= dist+tot;
	fac= 1.0f/((float)path->len-1.0f);
		fac = fac * path->totdist;
	
	for (a=0; a<path->len; a++) {
		
		d= ((float)a)*fac;
		
		/* we're looking for location (distance) 'd' in the array */
		while ((d>= *fp) && fp<maxdist) {
			fp++;
			if (bevp<bevplast) bevp++;
			bevpn= bevp+1;
			if (bevpn>bevplast) {
				if (cycl) bevpn= bevpfirst;
				else bevpn= bevplast;
			}
		}
		
		fac1= *(fp)- *(fp-1);
		fac2= *(fp)-d;
		fac1= fac2/fac1;
		fac2= 1.0f-fac1;
		
		interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2);
		pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa;
		pp->radius= fac1*bevp->radius + fac2*bevpn->radius;
		pp->weight= fac1*bevp->weight + fac2*bevpn->weight;
		interp_qt_qtqt(pp->quat, bevp->quat, bevpn->quat, fac2);
		normalize_qt(pp->quat);
		
		pp++;
	}
	
	MEM_freeN(dist);
}
示例#24
0
文件: astar.c 项目: arvidfm/fiend
//finds the x,y of the pathnode that is best to walk at if you want to get to goal.
//returns -1 if you can't get to the goal.
int find_best_xy(int start_x,int  start_y, int goal_x,int goal_y,int w, int h, int *best_x, int *best_y,int check_player)
{
	int i;

	NODE *n;

	//init...
	global_x = start_x;
	global_y = start_y;
	global_goal_x = goal_x;
	global_goal_y = goal_y;

	for(i=0;i<map->num_of_path_nodes;i++)
		h_list[i] = 99999;

	//Check if you can walk straight to the goal
	if(free_path(start_x, start_y,goal_x,goal_y,w,h,check_player))
	{
		*best_x = goal_x;
		*best_y = goal_y;
		return 1;
	}

	//check what nodes you can see and put em in node[]
	for(i=0;i<map->num_of_path_nodes;i++)
	{
		if(check_collision(start_x-240, start_y-240,480,480, map->path_node[i].x,map->path_node[i].y,2,2))
			if(free_path(start_x, start_y,map->path_node[i].x,map->path_node[i].y,w,h,check_player))
			{
				new_node(node_num, i, NULL);
				node_num++;
			}
	}

	//if we have no nodes in list exit...
	if(node_num==0)return 0;

	//Sort the nodes...
	sort_node_list();

	while(1)
	{
		//if we have no nodes in list exit...
		if(node_num==0)return 0;
		
		//set active node..
		n = node[node_num-1];
		node_num--;

		//check if you can get from the current node to the goal, if so quit.
		if(free_path(map->path_node[n->num].x,map->path_node[n->num].y,goal_x, goal_y,w,h,check_player))
		{
			//if the node has any parents then the parent node is the one we want!
			if(n->parent==NULL)
			{
				*best_x = map->path_node[n->num].x;		
				*best_y = map->path_node[n->num].y;
			}
			else
			{
				*best_x = map->path_node[n->parent->num].x;		
				*best_y = map->path_node[n->parent->num].y;
			}
			
			delete_node(n);
			break;
		}

		
		//check wich nodes that you can get to from the current node.
		for(i=0;i<map->num_of_path_nodes;i++)
		{
			if(i != n->num)
				if(check_collision(map->path_node[n->num].x-240, map->path_node[n->num].y-240,480,480, map->path_node[i].x,map->path_node[i].y,2,2))
					if(free_path(map->path_node[n->num].x, map->path_node[n->num].y,map->path_node[i].x,map->path_node[i].y,w,h,check_player))
					{
						if(new_node(node_num, i, n))
							node_num++;
					}
		}

		delete_node(n);

		//Sort the nodes...
		sort_node_list();
		
	}
	
	//delete the nodes left
	for(i=0;i<node_num;i++)
		delete_node(node[i]);

	node_num=0;


	return 1;
}
示例#25
0
/* searches a tree for a key, or the slot where it should be inserted.
 * (This function's signature is modeled after the one in Btrfs.)
 * r - the root of the tree to search
 * key - the key to search for
 * p - path result found/prepared for modification (shadowed at least)
 * ins_len - number of bytes needed for the item and its metadata in leaf
 *	(if inserting), or negative if deleting.  When inserting,
 *	index nodes on the path and the leaf node are proactively split
 *	if at the upper bounds, or to provide the required space in the leaf.
 *	When deleting, index nodes (below root) at the lower bounds
 *	on the path are proactively fixed.  When 0, the nodes on the path
 *	are not modified or shadowed.
 * returns 0 if the key is found, 1 if not, or a negative errno with no path.
 */
PUBLIC int search_slot(struct root *r, struct key *key, struct path *p,
						int ins_len) {
	int ret, level = -1;
	blocknr_t blocknr = r->blocknr;		/* start at root blocknr */
	memset(p, 0, sizeof(*p));		/* make NULL after the root level */

	/* traverse from root to leaf */
	while (TRUE) {				
		int i, j, least_key, comparison;
		struct header *hdr;
		struct cache *node = get_block(blocknr);
		if (!node) {
			if (level != -1) {
				free_path_from(p, level);
			}
			return -errno;
		}
		hdr = &node->u.node.header;
		assert(hdr->header_magic == HEADER_MAGIC);
		if (level >= 0) {
			assert(level == hdr->level + 1);	/* level counts down to 0 */
		}
		level = hdr->level;
		p->nodes[level] = node;

		/* check for special case: empty root node during mkfs */
		if (!hdr->nritems) {
			struct cache *leaf;
			blocknr_t leafnr;
			uint16_t type = LEAF_TYPE_FOR(hdr->type);
			assert(level == 1);
			assert(!p->nodes[2]);
			assert(ins_len > 0);

			p->slots[level] = 0;
			/* init first leaf and add to path, but leave empty */
			leafnr = alloc_block(r->fs_info, node, type);
			if (!leafnr) {
				free_path_from(p, level);
				return -ENOSPC;
			}
			leaf = init_node(leafnr, type, 0);
			if (!leaf) {
				free_path_from(p, level);
				return -errno;
			}
			/* a new node gets a new ptr to it */
			insert_key_ptr(r, p, level, key, leafnr);
			p->nodes[0] = leaf;
			p->slots[0] = 0;
			/* the caller will insert the first item in the new leaf */
			return KEY_NOT_FOUND;
		}

		/* go one slot past the search key */
		for (i = 0; i < hdr->nritems; i++) {
			comparison = compare_keys(key_for(node, i), key);
			if (comparison > 0) break;	/* one slot past the key */
		}
		if (i) {		/* the slot to the left is equal or less */
			p->slots[level] = i - 1;
			least_key = FALSE;
		} else { 	/* the key is less than everything else in the tree */
			least_key = TRUE;
			p->slots[level] = 0;	/* it would be inserted here */
			j = level;
			while (TRUE) {
				assert(p->slots[j] == 0);
				if (is_root_level(j++, p))	break;
			}
		}

		/* if going to modify, shadow now (on tree descent) */
		if (ins_len) {
			ret = ensure_will_write(r, p, level);
			if (ret) {
				free_path_from(p, level);
				return ret;
			}
		}

		/* leaf node */
		if (level == 0) {
			if (ins_len > 0) {
				ret = ensure_leaf_space(r, p, ins_len);
				if (ret) {
					free_path(p);
					return ret;
				}
			}
			assert(hdr->nritems);	/* an empty leaf would not be preserved */
			/* so there is an item to compare with */
			comparison = compare_keys(key_for(node, p->slots[0]), key);
			if (comparison < 0) {
				p->slots[0]++;	/* would insert at next slot in leaf */
			}
			ret = insert_extents_for_reserves(&r->fs_info->extent_root);
			return ret ? ret : (comparison ? KEY_NOT_FOUND : KEY_FOUND);

		/* index node */
		} else {
			if (ins_len > 0) {		/* inserting */
				if (least_key) {	/* will make leftmost key less */
					update_index_key(r, p, level, key);
				}
				if (hdr->nritems >= UPPER_BOUNDS(r->fs_info->lower_bounds)) {
					ret = split_index_node(r, p, level);
					if (ret) {
						free_path_from(p, level);
						return ret;
					}
				}
			}
			if (ins_len < 0) {		/* deleting */
				if (!is_root_level(level, p)
				&& hdr->nritems <= r->fs_info->lower_bounds) {
					ret = fix_index_node(r, p, level);
					if (ret) {
						free_path_from(p, level);
						return ret;
					}
				}
			}
			blocknr = ptr_for(node, p->slots[level]);
		}
	}
}
示例#26
0
static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispbase,
	DerivedMesh **derivedFinal, int forRender, int forOrco)
{
	Curve *cu = ob->data;

	/* we do allow duplis... this is only displist on curve level */
	if(!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return;

	if(ob->type==OB_SURF) {
		makeDispListSurf(scene, ob, dispbase, derivedFinal, forRender, forOrco);
	}
	else if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
		ListBase dlbev;
		ListBase *nubase;
		float (*originalVerts)[3];
		float (*deformedVerts)[3];
		int numVerts;

		nubase= BKE_curve_nurbs(cu);

		BLI_freelistN(&(cu->bev));

		if(cu->path) free_path(cu->path);
		cu->path= NULL;

		if(ob->type==OB_FONT) BKE_text_to_curve(scene, ob, 0);

		if(!forOrco) curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts);

		makeBevelList(ob);

		/* If curve has no bevel will return nothing */
		makebevelcurve(scene, ob, &dlbev, forRender);

		/* no bevel or extrude, and no width correction? */
		if (!dlbev.first && cu->width==1.0f) {
			curve_to_displist(cu, nubase, dispbase, forRender);
		} else {
			float widfac= cu->width - 1.0f;
			BevList *bl= cu->bev.first;
			Nurb *nu= nubase->first;

			for (; bl && nu; bl=bl->next,nu=nu->next) {
				DispList *dl;
				float *fp1, *data;
				BevPoint *bevp;
				int a,b;

				if (bl->nr) { /* blank bevel lists can happen */

					/* exception handling; curve without bevel or extrude, with width correction */
					if(dlbev.first==NULL) {
						dl= MEM_callocN(sizeof(DispList), "makeDispListbev");
						dl->verts= MEM_callocN(3*sizeof(float)*bl->nr, "dlverts");
						BLI_addtail(dispbase, dl);

						if(bl->poly!= -1) dl->type= DL_POLY;
						else dl->type= DL_SEGM;

						if(dl->type==DL_SEGM) dl->flag = (DL_FRONT_CURVE|DL_BACK_CURVE);

						dl->parts= 1;
						dl->nr= bl->nr;
						dl->col= nu->mat_nr;
						dl->charidx= nu->charidx;

						/* dl->rt will be used as flag for render face and */
						/* CU_2D conflicts with R_NOPUNOFLIP */
						dl->rt= nu->flag & ~CU_2D;

						a= dl->nr;
						bevp= (BevPoint *)(bl+1);
						data= dl->verts;
						while(a--) {
							data[0]= bevp->vec[0]+widfac*bevp->sina;
							data[1]= bevp->vec[1]+widfac*bevp->cosa;
							data[2]= bevp->vec[2];
							bevp++;
							data+=3;
						}
					}
					else {
						DispList *dlb;

						for (dlb=dlbev.first; dlb; dlb=dlb->next) {
	
							/* for each part of the bevel use a separate displblock */
							dl= MEM_callocN(sizeof(DispList), "makeDispListbev1");
							dl->verts= data= MEM_callocN(3*sizeof(float)*dlb->nr*bl->nr, "dlverts");
							BLI_addtail(dispbase, dl);
	
							dl->type= DL_SURF;
							
							dl->flag= dlb->flag & (DL_FRONT_CURVE|DL_BACK_CURVE);
							if(dlb->type==DL_POLY) dl->flag |= DL_CYCL_U;
							if(bl->poly>=0) dl->flag |= DL_CYCL_V;
							
							dl->parts= bl->nr;
							dl->nr= dlb->nr;
							dl->col= nu->mat_nr;
							dl->charidx= nu->charidx;

							/* dl->rt will be used as flag for render face and */
							/* CU_2D conflicts with R_NOPUNOFLIP */
							dl->rt= nu->flag & ~CU_2D;

							dl->bevelSplitFlag= MEM_callocN(sizeof(*dl->col2)*((bl->nr+0x1F)>>5), "bevelSplitFlag");
	
							/* for each point of poly make a bevel piece */
							bevp= (BevPoint *)(bl+1);
							for(a=0; a<bl->nr; a++,bevp++) {
								float fac=1.0;
								if (cu->taperobj==NULL) {
									if ( (cu->bevobj!=NULL) || !((cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) )
										fac = bevp->radius;
								} else {
									fac = calc_taper(scene, cu->taperobj, a, bl->nr);
								}

								if (bevp->split_tag) {
									dl->bevelSplitFlag[a>>5] |= 1<<(a&0x1F);
								}
	
									/* rotate bevel piece and write in data */
								fp1= dlb->verts;
								for (b=0; b<dlb->nr; b++,fp1+=3,data+=3) {
									if(cu->flag & CU_3D) {
										float vec[3];
	
										vec[0]= fp1[1]+widfac;
										vec[1]= fp1[2];
										vec[2]= 0.0;

										mul_qt_v3(bevp->quat, vec);

										data[0]= bevp->vec[0] + fac*vec[0];
										data[1]= bevp->vec[1] + fac*vec[1];
										data[2]= bevp->vec[2] + fac*vec[2];
									}
									else {
										data[0]= bevp->vec[0] + fac*(widfac+fp1[1])*bevp->sina;
										data[1]= bevp->vec[1] + fac*(widfac+fp1[1])*bevp->cosa;
										data[2]= bevp->vec[2] + fac*fp1[2];
									}
								}
							}
							
							/* gl array drawing: using indices */
							displist_surf_indices(dl);
						}
					}
				}

			}
			freedisplist(&dlbev);
		}