int find_path(TreeNode* root, TreeNode*p, vector<TreeNode*>&path)
{
    if (root == NULL)
    {
        return 0;
    }
    
    path.push_back(root);
    if ( root == p)
    {
        return 1;
    }
    
    if ( root->left && 1 == find_path(root->left, p, path))
    {
        return 1;
    }
    if ( root->right && 1 == find_path(root->right, p, path))
    {
        return 1;
    }
    ///////
    path.pop_back();
    return 0;
}
DirectoryEntryPtr
MetaDataStore::rename(const ObjectId& from_parent,
                      const std::string& from,
                      const ObjectId& to_parent,
                      const std::string& to)
{
    LOG_TRACE(from << " -> " << to);

    FrontendPath from_path(find_path(from_parent));
    from_path /= from;

    FrontendPath to_path(find_path(to_parent));
    to_path /= to;

    boost::optional<DirectoryEntryPtr>
        maybe_overwritten(harakoon_.rename<DirectoryEntry>(yt::UUID(from_parent.str()),
                                                           from,
                                                           yt::UUID(to_parent.str()),
                                                           to));
    drop_from_cache(from_path);

    DirectoryEntryPtr dentry;

    if (maybe_overwritten)
    {
        drop_from_cache(to_path);
        dentry = *maybe_overwritten;
    }

    return dentry;
}
int find_path(int maze[N][N], int x, int y, int sol[N][N])
{
	if(x== N-1 && y ==N-1)
	{
	  sol[x][y]=1;
	  return 1;
	}
	
	if(is_valid_path(x,y,maze) == 1)
	{
		sol[x][y]=1;
		//now move forward in x direction ie right
		if(find_path(maze, x+1, y, sol) == 1)
		  return 1;
		
		//moving right did not yield soln ,so move down 
		if(find_path(maze, x, y+1, sol) == 1)
		  return 1;
		  
		//nothing gives soln, mark sol array as 0 and backtrack
		sol[x][y]=0;
		return 0;
	}
	
	return 0;
}
示例#4
0
文件: track.c 项目: blanciq/bq-killer
void char_walk( CHAR_DATA *ch )
{
	int        dir = -1;
	bool close = FALSE;
	bool lock = FALSE;
	ROOM_INDEX_DATA *prev_room;

	if ( !ch || ch->walking == 0 )
	return;

	if ( ch->in_room->vnum == ch->walking || ch->in_room->vnum == -1 * ch->walking )
	{
		ch->walking = 0;
		return;
	}

	if ( ch->walking > 0 )
	dir = find_path( ch->in_room->vnum, ch->walking, ch, 40000, TRUE );
	else if ( ch->walking < 0 )
	dir = find_path( ch->in_room->vnum, -1 * ch->walking, ch, 40000, FALSE );

	if ( dir < 0 || dir >= MAX_DIR )
	{
		ch->walking = 0;
		return;
	}

	if ( IS_SET( ch->in_room->exit[dir]->exit_info, EX_LOCKED ) )
	{
		do_unlock( ch, (char *) eng_dir_name[dir] );
		lock = TRUE;
	}

	if ( IS_SET( ch->in_room->exit[dir]->exit_info, EX_CLOSED ) )
	{
		do_open( ch, (char *) eng_dir_name[dir] );
		close = TRUE;
	}

	if ( IS_SET( sector_table[ch->in_room->exit[dir]->u1.to_room->sector_type].flag, SECT_UNDERWATER ) )
		return;

	prev_room = ch->in_room;
	move_char( ch, dir, FALSE, NULL );

	if ( ch->in_room->vnum == ch->walking || ch->in_room->vnum == -1 * ch->walking )
	ch->walking = 0;

	if ( ch->in_room == prev_room )
	return;

	if ( close )
	do_close( ch, (char *) eng_dir_name[rev_dir[dir]] );

	if ( lock )
	do_lock( ch, (char *) eng_dir_name[rev_dir[dir]] );

	return;
}
示例#5
0
static int
build_appliance (guestfs_h *g,
                 char **kernel,
                 char **initrd,
                 char **appliance)
{
  int r;
  uid_t uid = geteuid ();
  CLEANUP_FREE char *supermin_path = NULL;
  CLEANUP_FREE char *path = NULL;

  /* Step (1). */
  r = find_path (g, contains_supermin_appliance, NULL, &supermin_path);
  if (r == -1)
    return -1;

  if (r == 1)
    /* Step (2): build supermin appliance. */
    return build_supermin_appliance (g, supermin_path, uid,
                                     kernel, initrd, appliance);

  /* Step (3). */
  r = find_path (g, contains_fixed_appliance, NULL, &path);
  if (r == -1)
    return -1;

  if (r == 1) {
    size_t len = strlen (path);
    *kernel = safe_malloc (g, len + 6 /* "kernel" */ + 2);
    *initrd = safe_malloc (g, len + 6 /* "initrd" */ + 2);
    *appliance = safe_malloc (g, len + 4 /* "root" */ + 2);
    sprintf (*kernel, "%s/kernel", path);
    sprintf (*initrd, "%s/initrd", path);
    sprintf (*appliance, "%s/root", path);
    return 0;
  }

  /* Step (4). */
  r = find_path (g, contains_old_style_appliance, NULL, &path);
  if (r == -1)
    return -1;

  if (r == 1) {
    size_t len = strlen (path);
    *kernel = safe_malloc (g, len + strlen (kernel_name) + 2);
    *initrd = safe_malloc (g, len + strlen (initrd_name) + 2);
    sprintf (*kernel, "%s/%s", path, kernel_name);
    sprintf (*initrd, "%s/%s", path, initrd_name);
    *appliance = NULL;
    return 0;
  }

  error (g, _("cannot find any suitable libguestfs supermin, fixed or old-style appliance on LIBGUESTFS_PATH (search path: %s)"),
         g->path);
  return -1;
}
示例#6
0
int decode(FILE* f)
{
	uint64_t node_index;
	int ret;
	
	int unknown_node = 0;
	
	while (1)
	{
		ret = bit_read(my_bitio_d, actual_bits_counter, &node_index);
		if (ret<0)
		{
			fprintf(stderr, "Error in bit_read()\n");
			return -1;
		}
		
		//EOF symbol reached
		if (node_index == 0)
			break;
		
		if (array_elem_counter < dictionary_size-1)
        {
			//there is some space avialable in the tree
            ret = array_add(node_index, -1);
				
            //browse the tree
            ret = find_path(node_index, unknown_node, f);
			if (ret == -1) {
				return -1;
			}
			
			unknown_node = 1;
        }
        else
		{
			//the tree is full
			++array_elem_counter;
			
			//emit the last sequence of char
			ret = find_path(node_index, unknown_node, f);
			if (ret == -1) {
				return -1;
			}
			
			//reset the tree
			array_reset();

			//at the next iteration we have not a node with an unspecified char
            unknown_node = 0;
        }	
	}
	
	return 0;
}
示例#7
0
TEST(CPathFinderTest, oriented_graph)
{
    OrientedGraph::COrientedGraph* graph = new OrientedGraph::COrientedGraph(5);
    graph->add(new OrientedGraph::CEdge(0, 1, 1));
    graph->add(new OrientedGraph::CEdge(1, 2, 1));
    graph->add(new OrientedGraph::CEdge(2, 4, 1));
    graph->add(new OrientedGraph::CEdge(4, 3, 1));
    graph->add(new OrientedGraph::CEdge(0, 3, 1));
    auto pathFinder = init<OrientedGraph::CEdge, OrientedGraph::CPath,
            std::vector<OrientedGraph::CEdge*> (OrientedGraph::COrientedGraph::*)(const int) const>(&OrientedGraph::COrientedGraph::get, graph);
    auto path = pathFinder->find_path(0, 4);
    EXPECT_EQ(path.get_path_length(), 3);
    EXPECT_THROW(pathFinder->find_path(4, 0), CExNoPath);
}
示例#8
0
//*grid or use grid[][[]with malloc?
int find_path(char grid[][8], int i, int k)
{
  if(i < 0 || k > 7 || i > 7 || k < 0 || grid[i][k] == 'X')//if out of bound
      return (FAIL);
  grid[i][k] = 'X';

    
  if(i == 0 && k == 1) //if destination is good, don't call recursions again
    {
      grid[i][k] = 'X';//change current position to X
      printf("(%d, %d)\n", i, k);
      return (SUCCESS);
    }//if

  //----END BASE CASE CHECKING----------//
  
          if((find_path(grid, i-1, k)) == SUCCESS)//check up
	    { 
	      //    grid[i][k] = 'X';            
	      printf("(%d, %d)\n", i, k);
	      return SUCCESS;
	    }
	  else if((find_path(grid, i+1, k)) == SUCCESS)//check down
	    { 
	      //grid[i][k] = 'X';
	      printf("(%d, %d)\n", i, k);
	      return SUCCESS;
	    }
	  else if((find_path(grid, i, k-1)) == SUCCESS)//check left
	    {
	      //grid[i][k] = 'X';
	      printf("(%d, %d)\n", i, k);
	      return SUCCESS;
	    }
	  else if((find_path(grid, i, k+1)) == SUCCESS)//check right
	    {	     
	      // grid[i][k] = 'X';
	      printf("(%d, %d)\n", i, k);
	      return SUCCESS;
	    }
          else
	    return FAIL;
         
	  // return (SUCCESS); //--> is the way i am returning things bad? 
	
  
  return (FAIL); //default cause  
}//find_path
示例#9
0
struct node *find_link (int index, struct node *parent, 
						struct node *child, int firsti, int lasti)
// Find and establish the suffix link for the given child node, 
// working downward from its parent's suffix link.
{
	int e, betalen, r, depth;
	struct node *vp, *branch, *leaf;

	// Capture beta for later consumption
	betalen = lasti - firsti;

	// traverse parent's suffix link.
	vp = parent -> sfxlink;
	branch = get_branch (firsti, vp);  

	if (branch && betalen) {	// Beta not empty
		// Consume Beta and Establish child -> sfxlink
		leaf = consume_beta (index, firsti, betalen, branch, child);
	} else {	
		// Beta was empty or no branch exists for the letter at input[index]
		child -> sfxlink = vp;
		leaf = find_path (index, index, vp);
	}
	return leaf;
}
示例#10
0
void
MetaDataStore::add(const ObjectId& parent,
                   const std::string& name,
                   DirectoryEntryPtr dentry)
{
    LOG_TRACE(parent << ", dentry uuid " << dentry->object_id() << " name " << name);

    const yt::UUID p(parent.str());
    const boost::optional<DirectoryEntry> oldval;

    try
    {
        harakoon_.test_and_set(p,
                               name,
                               *dentry,
                               oldval);
    }
    catch (HierarchicalArakoon::PreconditionFailedException)
    {
        throw FileExistsException("Metadata entry already exists",
                                  name.c_str(),
                                  EEXIST);
    }

    FrontendPath path(find_path(parent));
    path /= name;

    maybe_add_to_cache_(path, dentry);
}
static char* test_find_path_empty_level_horizontal()
{
    Level* level = level_alloc_empty(LEVEL_TEST_WIDTH, LEVEL_TEST_HEIGHT);
    mu_assert(level != NULL);
    Cell* start_cell = &level->cells[2][1];
    Cell* target_cell = &level->cells[2][17];

    Path* path = find_path(level, start_cell, target_cell);

    mu_assert(path != NULL);
    mu_assert(path->distance == 12 * (17 - 1));
    mu_assert(path->step_count == 17);

    mu_assert(path->steps != NULL);
    mu_assert(test_is_path_start_and_end_step_correct(path, start_cell, target_cell));
    mu_assert(test_is_path_walkable(path, level) == 1);

    int i;
    for (i = 1; i < path->step_count; i++)
    {
        mu_assert(path->steps[i].row == start_cell->row);
        mu_assert(path->steps[i].col == start_cell->col + i);
    }

    path_free(path);
    level_free(level);

    return NULL;
}
static char* test_find_path_empty_level_corner_to_corner()
{
    Level* level = level_alloc_empty(LEVEL_TEST_WIDTH, LEVEL_TEST_HEIGHT);
    mu_assert(level != NULL);
    Cell* start_cell = &level->cells[11][0];
    Cell* target_cell = &level->cells[0][24];

    Path* path = find_path(level, start_cell, target_cell);

    mu_assert(path != NULL);
    mu_assert(path->distance == 12 * 13 + 17 * 11);
    mu_assert(path->step_count == 25);

    mu_assert(path->steps != NULL);
    mu_assert(test_is_path_start_and_end_step_correct(path, start_cell, target_cell));
    mu_assert(test_is_path_walkable(path, level) == 1);

    int i;
    for (i = 1; i < path->step_count - 1; i++)
    {
        mu_assert(path->steps[i].row <= start_cell->row);
        mu_assert(path->steps[i].col >= start_cell->col);
        mu_assert(path->steps[i].row >= target_cell->row);
        mu_assert(path->steps[i].col <= target_cell->col);
    }

    path_free(path);
    level_free(level);

    return NULL;
}
示例#13
0
int main(int argc, char *argv[])
{
    for(int i = 1; i < argc; i++)
    {
        if(argv[i] == NULL) continue;
        if(strncmp(argv[i], "-r", 2) == 0 || strncmp(argv[i], "--replace", 9) == 0)
            allow_replace = true;
        else if(strncmp(argv[i], "-l", 2) == 0 || strncmp(argv[i], "--local", 7) == 0)
            local = true;
        else if(strncmp(argv[i], "-f", 2) == 0 || strncmp(argv[i], "--fetch", 7) == 0)
            do_fetch = true;
        else if(strncmp(argv[i], "-s", 2) == 0 || strncmp(argv[i], "--sql", 5) == 0)
            do_sql = true;
        else if(strncmp(argv[i], "--branch=", 9) == 0)
            snprintf(remote_branch, MAX_REMOTE, "%s", argv[i] + 9);
        else if(strncmp(argv[i], "-h", 2) == 0 || strncmp(argv[i], "--help", 6) == 0)
        {
            printf("Usage: git_id [OPTION]\n");
            printf("Generates a new rev number and updates revision_nr.h and the commit message.\n");
            printf("Should be used just before push.\n");
            printf("   -h, --help            show the usage\n");
            printf("   -r, --replace         replace the rev number if it was already applied\n");
            printf("                         to the last commit\n");
            printf("   -l, --local           search for the highest rev number on HEAD\n");
            printf("   -f, --fetch           fetch from origin before searching for the new rev\n");
            printf("   -s, --sql             search for new sql updates and do all of the changes\n");
            printf("                         for the new rev\n");
            printf("       --branch=BRANCH   specify which remote branch to use\n");
            return 0;
        }
    }

    DO( find_path()                     );
    if(!local)
    {
        DO( find_origin()               );
        if(do_fetch)
            DO( fetch_origin()          );
        DO( check_fwd()                 );
    }
    DO( find_rev()                      );
    DO( find_head_msg()                 );
    if(do_sql)
        DO( find_sql_updates()          );
    DO( prepare_new_index()             );
    DO( write_rev_nr()                  );
    if(do_sql)
    {
        DO( convert_sql_updates()       );
        DO( generate_sql_makefile()     );
        //DO( change_sql_database()       );
        DO( write_rev_sql()             );
    }
    DO( amend_commit()                  );
    DO( cleanup_new_index()             );
    //if(do_sql)
    //    DO( change_sql_history()        );

    return 0;
}
示例#14
0
文件: package.c 项目: dleonard0/ponyc
bool package_init(pass_opt_t* opt)
{
  if(!codegen_init(opt))
    return false;

  package_add_paths(getenv("PONYPATH"));
  add_exec_dir();

  // Convert all the safe packages to their full paths.
  strlist_t* full_safe = NULL;

  while(safe != NULL)
  {
    const char* path;
    safe = strlist_pop(safe, &path);

    // Lookup (and hence normalise) path.
    path = find_path(NULL, path);

    if(path == NULL)
    {
      strlist_free(full_safe);
      return false;
    }

    full_safe = strlist_push(full_safe, path);
  }

  safe = full_safe;
  return true;
}
示例#15
0
asmlinkage long our_sys_rename(const char* oldfile, const char* newfile)
{
    struct log_path *p;
    long euid, pid, ppid;
    long audit, paudit, result;
    struct passwd_entry *pe;
    struct task_struct *atask;
    struct task_struct *ptask;

    result = original_sys_rename_call(oldfile, newfile);
    if(result < 0) return result;

    euid = current_uid();
    pe = get_passwd_entry(euid);
    pid = current->pid;
    audit = get_audit_id();
    ptask = find_task_by_vpid(pid);
    ppid = (long)(ptask->real_parent->pid);

    atask = find_task_by_vpid(audit);
    if(atask != NULL && atask->real_parent != NULL) {
        paudit = atask->real_parent->pid;
    }
    else {
        paudit = -1;
    }
    if(euid > 0 && pe != NULL) {
        p = find_path();
        LOG_RENAME(SYSCALL_MOVE, pe->username, pid, ppid, audit, paudit, ptask->comm, oldfile, newfile, p->name);
        kfree(p);
    }
    return result;
}
示例#16
0
int		do_command(t_env *env, char *com)
{
	char	*str;
	char	**arr;
	pid_t	forked;

	str = NULL;
	arr = NULL;
	forked = fork();
	env->pid = forked;
	if (forked == 0)
	{
		arr = ft_strsplit(com, ' ');
		execve(arr[0], arr, E_EN);
		str = find_path(env, arr[0]);
		if (str == NULL)
			ft_putstr(E_MESS02);
		else
			execve(str, arr, E_EN);
		exit(0);
	}
	else
		wait(0);
	return (1);
}
示例#17
0
void	second_pipe_traitement(char *buffer, char **env,
			       t_traite *tr, int pipefd[2])
{
  int	tst;
  int	directory;

  if ((tr->pid = fork()) == -1)
    exit(EXIT_FAILURE);
  if (tr->pid == 0)
    {
      buffer = tr->tmp;
      buffer = cut_buff_pipe(buffer);
      tr->buff = epure_str(buffer);
      tr->tab = strtab(tr->buff);
      tr->path = find_path(env, tr->path);
      directory = current_directory(tr->tab);
      if (directory == 2)
	tr->exec = test(tr->path, tr->tab[0]);
      close(pipefd[1]);
      dup2(pipefd[0], 0);
      execve(tr->exec, tr->tab, env);
      exit(0);
    }
  close(pipefd[1]);
  close(pipefd[0]);
  wait(&tr->statut);
  if (WIFSIGNALED(tr->statut))
    my_putstr("Segmentation fault\n");
}
示例#18
0
int main(int argc, char** argv, char** env)
{
    char buffer[4096];
    int len;
    char** env_path;
    char** cmd;
    int permission;
    int status;

    env_path = find_path(env);
    my_putstr("$>");
    while((len = read(STDIN_FILENO, buffer, 4096)) > 0)
    {
        cmd = my_str_to_wordtab(&buffer[1]);
        if(cmd[0] != 0)
        {
            permission = my_exec(env_path, cmd, env);
            if (permission == 0)
                my_putstr("Permission denied.\n");
            else if (permission == -1)
                my_putstr(my_strcat(buffer, " : command not found.\n"));
            else
                waitpid(permission, &status, 0);
        }
        my_putstr("$>");
    }
    return (0);
}
示例#19
0
// create or open
static int mhdd_internal_open(const char *file,
		mode_t mode, struct fuse_file_info *fi, int what)
{
	mhdd_debug(MHDD_INFO, "mhdd_internal_open: %s, flags = 0x%X\n",
		file, fi->flags);
	int dir_id, fd;

	char *path = find_path(file);

	if (path) {
		if (what == CREATE_FUNCTION)
			fd = open(path, fi->flags, mode);
		else
			fd = open(path, fi->flags);
		if (fd == -1) {
			free(path);
			return -errno;
		}
		struct flist *add = flist_create(file, path, fi->flags, fd);
		fi->fh = add->id;
		flist_unlock();
		free(path);
		return 0;
	}

	mhdd_debug(MHDD_INFO, "mhdd_internal_open: new file %s\n", file);

	if ((dir_id = get_free_dir()) < 0) {
		errno = ENOSPC;
		return -errno;
	}

	create_parent_dirs(dir_id, file);
	path = create_path(mhdd.dirs[dir_id], file);

	if (what == CREATE_FUNCTION)
		fd = open(path, fi->flags, mode);
	else
		fd = open(path, fi->flags);

	if (fd == -1) {
		free(path);
		return -errno;
	}

	if (getuid() == 0) {
		struct stat st;
		gid_t gid = fuse_get_context()->gid;
		if (fstat(fd, &st) == 0) {
			/* parent directory is SGID'ed */
			if (st.st_gid != getgid()) gid = st.st_gid;
		}
		fchown(fd, fuse_get_context()->uid, gid);
	}
	struct flist *add = flist_create(file, path, fi->flags, fd);
	fi->fh = add->id;
	flist_unlock();
	free(path);
	return 0;
}
示例#20
0
int main(int argc, char *argv[])
{
  FILE *fp = fopen(argv[1], "r");
  char grid[8][8]; 
  int col, row;
  int i, k;
  char garbage;
  col = row = 7;
  
  for(i = 0; i <= row; i++)
      {
	for(k = 0; k <= col; k++)
	  {
	    fscanf(fp, "%c", &grid[i][k]);
	  }//inner for
        fscanf(fp, "%c", &garbage);
      }//large for

  if(FAIL == find_path(grid, 7, 7)) //start point
    {
      printf("No path was found\n");
    }//if

  fclose(fp);

  return (0);
}//end main
示例#21
0
asmlinkage long our_sys_link(const char* file, const char* newfile)
{
    long result;
    long uid, gid;
    long audit, pid;
    struct log_path *p;
    struct passwd_entry *pe = NULL;


    if (is_relevant_file(file, &uid, &gid) == 1)
    {
        result = original_sys_link_call(file, newfile);
        if(result >= 0) {
            pid = current->pid;
            uid = current_uid();
            pe = get_passwd_entry(uid);
            audit = get_audit_id();
            p = find_path();
            LOG_LINK(SYSCALL_LINK, pe->username, pid, audit, file, newfile, p->name);
            kfree(p);
        }
    }
    else {
        result = original_sys_link_call(file, newfile);
    }
    return result;
}
示例#22
0
struct node *consume_beta (int index, int firsti, int betalen, 
							struct node *startnode, struct node *u)
// Consume Beta (slice of input string);
// Establish suffix link of u to point to the spot at which Beta was consumed;
// Find leaf insertion location and return a pointer to it.
{
	int e, r, depth;
	struct node *branch, *leaf;

	r = 0;
	branch = startnode;

	while (r < betalen) {
		e = (branch -> endi) - (branch -> starti);
		if (r + e > betalen) {	// Beta is consumed mid-edge.
			// Break edge.  Assign the suffix link to the breakpoint and append leaf.
			u -> sfxlink = break_edge (branch -> starti + (betalen - r), branch); 
			allocate_node (&leaf, index, index + u -> sfxlink -> strdepth, slen, u -> sfxlink);
			push_branch (&(u -> sfxlink), leaf);
			break;
		} else if (r + e == betalen) {	// Beta is consumed at an existing node
			// Establish link and place the leaf by matching characters.
			u -> sfxlink = branch;
			depth = index - 1 + u -> strdepth;
			leaf = find_path (index, depth, branch);
			break;
		} else { 		// Hop to next node by adding its edge length to r.
			r += e;		
			branch = get_branch (firsti + r, branch);
		}
	}
	return leaf;
}
示例#23
0
文件: main.c 项目: GastaldiRemi/Dante
int		main(int ac, char **av)
{
  char		*line;
  char		**maze;
  t_path	*path;
  int           fd;
  struct stat   fileStat;

  if (ac != 2)
    {
      printf("Utilisation : ./solver maze.txt,\n");
      return (0);
    }
  if ((fd = open(av[1], O_RDONLY)) < -1)
    return (0);
  if (fstat(fd, &fileStat) < 0)
    return (0);
  path = NULL;
  line = NULL;
  line = malloc(sizeof(char) * (fileStat.st_size + 1));
  read(fd, line, fileStat.st_size);
  line[fileStat.st_size] = '\0';
  maze = my_str_to_wordtab(line);
  find_path(maze, &path);
  free_fonc(maze, path);
  free(line);
  return 0;
}
示例#24
0
int main()
{
    fin = fopen("stall4.in", "r");
    fout = fopen("stall4.out", "w");

    long i, j, k;
    for (i = 1, fscanf(fin, "%ld %ld", &n, &m); i <= n; i++)
	for (j = 0, fscanf(fin, "%ld", &k); j < k; j++)
	{
	    long l;
	    fscanf(fin, "%ld", &l);
	    cost[i][l] = 1;
	}

    memset(match, -1, sizeof(match));

    for (i = 1; i <= n; i++)
    {
	memset(used, 0, sizeof(used));
	if (find_path(i)) ans++;
    }

    fprintf(fout, "%ld\n", ans);

    fclose(fin); fclose(fout);
    return 0;
}
示例#25
0
void	first_pipe_traitement(char *buffer, char **env,
			      t_traite *tr, int pipefd[2])
{
  int	tst;
  int	directory;
  int	error;

  error = pipe(pipefd);
  if (error == -1)
    exit(EXIT_FAILURE);
  if ((tr->pid = fork()) == -1)
    exit(EXIT_FAILURE);
  if (tr->pid == 0)
    {
      tr->buff = epure_str(buffer);
      tr->tab = strtab(tr->buff);
      tr->path = find_path(env, tr->path);
      directory = current_directory(tr->tab);
      if (directory == 2)
	tr->exec = test(tr->path, tr->tab[0]);
      close(pipefd[0]);
      dup2(pipefd[1], 1);
      execve(tr->exec, tr->tab, env);
      exit(0);
    }
  waitpid(tr->pid, &tst, 0);
}
示例#26
0
int main()
{
    int n;
    int i, j;
    int a, b, c;
    int flow;
    int from[N];
    int sum;

    while(scanf("%d%d", &num, &n) != EOF) {
        memset(map, 0, sizeof(map));
        sum = 0;
        for(i=0; i<n; i++) {
            scanf("%d%d%d", &a, &b, &c);
            a--, b--;
            map[a][b] += c;
            map[b][a] += c;
        }
        scanf("%d%d", &a, &b);
        a--, b--;
        if(a == b) {
            printf("Are you joking?\n");
            printf("I think its max-flow is infinite.\n");
        }
        else {
            while((flow=find_path(a, b, from)) > 0) {
                sum += flow;
                change(flow, from, a, b);
            }
            printf("%d\n", sum);
        }
    }
    return 0;
}
示例#27
0
文件: rcopy.c 项目: brkt/fuse-xfs
int main(int argc, char *argv[]) {
    xfs_mount_t	*mp;
    xfs_inode_t *inode = NULL;
    char *progname;
    char *source_name;
    char *parent;
    int r;

    if (argc != 3) {
        printf("Usage: xfs-rcopy raw_device directory\n");
        printf("Copies the named directory from an XFS file system to the current directory\n");
        return 1;
    }
    progname = argv[0];
    source_name = argv[1];
    parent = argv[2];
    
    mp = mount_xfs(progname, source_name);
    
    if (mp == NULL) 
        return 1;
    
    r = find_path(mp, parent, &inode);
    if (r) {
        printf("Can't find %s\n", parent);
        libxfs_umount(mp);
        return 1;
    }

    copy_tree(mp, parent, last(parent), inode);
    libxfs_iput(inode, 0);
    libxfs_umount(mp);
    return 0;
}
示例#28
0
    vector<pair<int, int> > find_max_matching(vector<vector<int> > &v, int _n, int _k)
    {
        //v[i] is a list of adjacent vertices to vertex i, where i is from left part and v[i][j] is from right part
        n = _n;
        //n is number of vertices in left part of graph
        k = _k;
        //k is number of vertices in right part of graph

        g = vector<vector<int> >(n+k+2, vector<int>(n+k+2));
        //g[i][j] = 1 if there is edge between vertex i from left part
        //            			    and vertex j from right part
        for(int i = 0; i < v.size(); i++)
            for(int j = 0; j < v[i].size(); j++)
                g[i][v[i][j]] = 1;
        int S = n+k;
        int T = n+k+1;
        for(int i = 0; i < n; i++)
            g[S][i] = 1;
        for(int i = 0; i < k; i++)
            g[n+i][T] = 1;

        vector<vector<int> > _g(g);

        used = vector<bool> (n+k+2, false);
        while(find_path(S, T))
            fill(used.begin(), used.end(), false);

        vector<pair<int, int> > res;
        for(int i = 0; i < n; i++)
            for(int j = n; j < n+k; j++)
                if(g[i][j] < _g[i][j])
                    res.push_back(make_pair(i, j));

        return res;
    }
示例#29
0
文件: package.c 项目: lzpfmh/ponyc
bool package_init(pass_opt_t* opt)
{
  if(!codegen_init(opt))
    return false;

  // package_add_paths for command line paths has already been done. Here, we
  // append the paths from an optional environment variable, and then the paths
  // that are relative to the compiler location on disk.
  package_add_paths(getenv("PONYPATH"));
  add_exec_dir();

  // Convert all the safe packages to their full paths.
  strlist_t* full_safe = NULL;

  while(safe != NULL)
  {
    const char* path;
    safe = strlist_pop(safe, &path);

    // Lookup (and hence normalise) path.
    path = find_path(NULL, path, NULL);

    if(path == NULL)
    {
      strlist_free(full_safe);
      return false;
    }

    full_safe = strlist_push(full_safe, path);
  }

  safe = full_safe;
  return true;
}
示例#30
0
struct t_rooms				*find_path(struct t_datas *datas, struct t_rooms *room)
{
	if (room->seen == 0 && find_neighbours(room, datas->tubes))
		return (find_path(datas, find_neighbours(room, datas->tubes)));
	else
		return (room);
}