예제 #1
0
파일: sm-reader.c 프로젝트: cosmo-ray/yirl
void *load_map(int nb, void **args)
{
  const char *file_name = yeGetString(args[0]);
  int fd = open(file_name, O_RDONLY);
  int width = 0;
  Entity *mod_description = nb > 1 ? args[1] : NULL;
  char *name = nb > 3 ? args[3] : NULL;
  Entity *father = nb > 2 ? args[2] : yeCreateArray(NULL, name);
  Entity *map = yeCreateArray(father, "map");

  if (fd < 0) {
    DPRINT_ERR("error when opening '%s'\n", file_name);
    goto error;
  }

  if (!read_map(fd, map, mod_description, file_name, &width, NULL, NULL)) {
    yeReCreateInt(width, father, "width");
    return father;
  }

 error:
  if (nb > 2)
    YE_DESTROY(father);
  YE_DESTROY(map);
  return NULL;
}
예제 #2
0
map_t *init_map(char *fp) {
    map_t *map = malloc(sizeof(map_t));

    /* Read raw map */
    char **raw_map = read_map(fp, &(map->height), &(map->width));

    if(raw_map != NULL) {
        map->block = malloc(sizeof(block_t*)*map->height);
        map->redraw_block = NULL;
        map->animate_unit = NULL;
        map->unit = NULL;
        map->player = NULL;
        map->num_players = 0;
        map->num_units = 0;
        map->camera = 0;
        map->block = malloc(sizeof(block_t*)*map->height);
        int i;
        int j;
        for(i = 0; i < map->height; i++) {
            map->block[i] = malloc(sizeof(block_t)*map->width);
            for(j = 0; j < map->width; j++) {
                map->block[i][j].status = UNASSIGNED;
            }
        }
        parse_map(map, raw_map);
        free(raw_map);
        return map;
    } else {
        free(map);
        return NULL;
    }
}
예제 #3
0
파일: quering.cpp 프로젝트: hieuhoang/proj4
QueryEngine::QueryEngine(const char * filepath){
	
	//Create filepaths
	std::string basepath(filepath);
	std::string path_to_hashtable = basepath + "/probing_hash.dat";
	std::string path_to_data_bin = basepath + "/binfile.dat";
	std::string path_to_vocabid = basepath + "/vocabid.dat";

	//Read config file
	std::string line;
	std::ifstream config ((basepath + "/config").c_str());
	getline(config, line);
	int tablesize = atoi(line.c_str()); //Get tablesize.

	getline(config, line);
	largest_entry = atoi(line.c_str()); //Set largest_entry.
	config.close();

	//Mmap binary table
	struct stat filestatus;
	stat(path_to_data_bin.c_str(), &filestatus);
	binary_filesize = filestatus.st_size;
	binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize);

	//Read hashtable
	size_t table_filesize = Table::Size(tablesize, 1.2);
	mem = readTable(path_to_hashtable.c_str(), table_filesize);
	Table table_init(mem, table_filesize);
	table = table_init;

	//Read vocabid
	read_map(&vocabids, path_to_vocabid.c_str());

	std::cout << "Initialized successfully! " << std::endl;
}
예제 #4
0
/**
 * Looks for entry 'file' in the given directory contents. The inode is 
 * assumed to be of directory type.
 *
 * If the file is found it's inode number is returned, otherwise NO_INODE is
 * returned.
 */
inode_nr dir_search(struct minix_inode *inode, const char *file)
{
	struct minix_block *blk;	/* block belonging to inode */
	zone_nr z;			
	int c_pos = 0;		/* current position in scan of directory */
	int i;			/* current position in directory block */
	inode_nr retval;

	debug("dir_search(%d, \"%s\"): searching...", inode->i_num,
		file);
	while((z = read_map(inode, c_pos)) != NO_ZONE) {
		blk = get_block(z, TRUE);
		/* TODO: fix bug. shouldn't use BLOCK_SIZE */
		for(i = 0; i < BLOCK_SIZE; i+= DENTRY_SIZE) {
			if(strcmp((char *)(blk->blk_data + i + 2), file) == 0) {
				retval = *((inode_nr *)(blk->blk_data + i));
				put_block(blk, DIR_BLOCK);
				debug("dir_search(): found \"%s\" at ix=%d", 
					file, i);
				return retval;
			}
		}
		put_block(blk, DIR_BLOCK);
		c_pos += BLOCK_SIZE;
	}

	/* couldn't find directory entry */
	debug("dir_search(%d, \"%s\"): couldn't find entry", inode->i_num, 
		file);
	return NO_INODE;
}
예제 #5
0
void init_maps(void)
{
	uint32 i = 0;
	uint32 n = 0;
	char *path;

	map_array = (map_t *)calloc(MAX_MAPS, sizeof(map_t));
	map_array_cache = (buffer_t *)calloc(MAX_MAPS, sizeof(buffer_t));

	for( i = 0; i < MAX_MAPS; i++){
		map_array[i].name = (char *)calloc(MAX_NAME_LENGTH, sizeof(char));
		map_array[i].npc = (map_npc_t *)calloc(MAX_MAP_NPCS, sizeof(map_npc_t));
		map_array[i].tile = (tile_t *)calloc(MAX_MAPX * MAX_MAPY, sizeof(tile_t));
		map_array[i].items = (map_item_t *)calloc(MAX_MAP_ITEMS, sizeof(map_item_t));

		for( n = 0; n < MAX_MAP_NPCS; n++)
			map_array[i].npc[n].vitals = (uint16 *)calloc(VITAL_COUNT, sizeof(uint16));

		path = get_path(MAP_PATH, i, FILE_ENDING);

		check_dir(MAP_PATH);

		if(file_readable(path))
			read_map(path,i);
		else
			write_map(path,i);

		mapcache_create(i);
	}
}
예제 #6
0
QueryEngine::QueryEngine(const char * filepath) : decoder(filepath){
    
    //Create filepaths
    std::string basepath(filepath);
    std::string path_to_hashtable = basepath + "/probing_hash.dat";
    std::string path_to_data_bin = basepath + "/binfile.dat";
    std::string path_to_source_vocabid = basepath + "/source_vocabids";

    ///Source phrase vocabids
    read_map(&source_vocabids, path_to_source_vocabid.c_str());

    //Target phrase vocabIDs
    vocabids = decoder.get_target_lookup_map();

    //Read config file
    std::string line;
    std::ifstream config ((basepath + "/config").c_str());
    getline(config, line);
    int tablesize = atoi(line.c_str()); //Get tablesize.
    config.close();

    //Mmap binary table
    struct stat filestatus;
    stat(path_to_data_bin.c_str(), &filestatus);
    binary_filesize = filestatus.st_size;
    binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize);

    //Read hashtable
    size_t table_filesize = Table::Size(tablesize, 1.2);
    mem = readTable(path_to_hashtable.c_str(), table_filesize);
    Table table_init(mem, table_filesize);
    table = table_init;

    std::cerr << "Initialized successfully! " << std::endl;
}
예제 #7
0
파일: maze.cpp 프로젝트: NEWPLAN/Sources
int main()
{
	int nrow_map = 0, ncol_map = 0;
	const char *filename = "D:\\data\\map.txt";
	int **maze;
	int **mark;
	TCellPtr pstack;

	if(!verify_mat(filename, &nrow_map, &ncol_map)){
		printf("请检查迷宫地图文件:文件读取失败,或地图每行的元素数目不相容\n");
		exit(0);
	}

	// 读入地图文件
	maze = read_map(filename, nrow_map, ncol_map);
	// 生成迷宫访问标记矩阵
	mark = setup_mat(nrow_map, ncol_map);
	// 初始化路径探测堆栈
	pstack = setup_stack(nrow_map, ncol_map);

	search_maze( maze, mark, pstack, nrow_map, ncol_map );


	// 销毁为存储迷宫地图而动态分配的内存
	destroy_map(maze, nrow_map);
	// 销毁为存储迷宫访问标记而动态分配的内存
	destroy_map(mark, nrow_map);
	// 销毁路径探测堆栈
	free(pstack);

	system("pause");
	return 0;
}
예제 #8
0
/*===========================================================================*
 *                             fs_rdlink                                     *
 *===========================================================================*/
int fs_rdlink()
{
  block_t b;                   /* block containing link text */
  struct buf *bp;              /* buffer containing link text */
  register struct inode *rip;  /* target inode */
  register int r;              /* return value */
  size_t copylen;
  
  copylen = min( (size_t) fs_m_in.REQ_MEM_SIZE, UMAX_FILE_POS);

  /* Temporarily open the file. */
  if( (rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);

  if(!S_ISLNK(rip->i_mode))
	  r = EACCES;
  else if ((b = read_map(rip, (off_t) 0)) == NO_BLOCK)
	r = EIO;
  else {
	/* Passed all checks */
	/* We can safely cast to unsigned, because copylen is guaranteed to be
	   below max file size */
	copylen = min( copylen, (unsigned) rip->i_size);
	bp = get_block(rip->i_dev, b, NORMAL);
	r = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
			   (vir_bytes) 0, (vir_bytes) b_data(bp),
	  		   (size_t) copylen);
	put_block(bp, DIRECTORY_BLOCK);
	if (r == OK)
		fs_m_out.RES_NBYTES = copylen;
  }
  
  put_inode(rip);
  return(r);
}
예제 #9
0
파일: rename.c 프로젝트: gatoravi/MFAST
int main(int argc, char *argv[])
{
	struct rooted_tree *tree;	
	struct hash *rename_map;
	struct parameters params;
	
	params = get_params(argc, argv);

	rename_map = read_map(params.map_filename);

	while (NULL != (tree = parse_tree())) {
		process_tree(tree, rename_map, params);
		destroy_tree(tree, DONT_FREE_NODE_DATA);
	}

	struct llist *keys = hash_keys(rename_map);
	if (NULL == keys) { perror(NULL); exit(EXIT_FAILURE); }
	struct list_elem *e;
	for (e = keys->head; NULL != e; e = e->next) {
		char *key = (char *) e->data;
		char *val = hash_get(rename_map, key);
		free(val);
	}
	destroy_llist(keys);
	destroy_hash(rename_map);

	return 0;
}
예제 #10
0
파일: main.c 프로젝트: mde-la-t/Projets
void			option_case(char *name, int opt)
{
	t_data		e;
	char		**buf;

	if (opt != 2 && opt != 1)
		put_usage_error("./fdf");
	open_check(name);
	buf = get_data(name);
	e.opt = opt;
	if (opt == 1)
	{
		e.para = 0;
		e.iso = 1;
	}
	if (opt == 2)
	{
		e.para = 1;
		e.iso = 0;
	}
	e.y_max = nb_lines(buf);
	e.x_max = nb_points(buf, e.y_max);
	e.data = read_map(buf, e.x_max, e.y_max);
	e.cal_data = NULL;
	init_t_m(&e);
	create_img(&e);
	free_tab(&e);
}
static int
osf_open_symbol_file_object (void *from_ttyp)
{
  struct read_map_ctxt ctxt;
  struct so_list so;
  int found;

  if (symfile_objfile)
    if (!query ("Attempt to reload symbols from process? "))
      return 0;

  /* The first module after /sbin/loader is the main program.  */
  if (!open_map (&ctxt))
    return 0;
  for (found = 0; !found;)
    {
      if (!read_map (&ctxt, &so))
	break;
      found = !so.lm_info->isloader;
      osf_free_so (&so);
    }
  close_map (&ctxt);

  if (found)
    symbol_file_add_main (so.so_name, *(int *) from_ttyp);
  return found;
}
예제 #12
0
int va_server_init(char *crash_file, u_long *start, u_long *end, u_long *stride)
{
	Page_Size = getpagesize();  /* temporary setting until disk header is read */

	if(read_map(crash_file)) {
		if(va_server_init_v1(crash_file, start, end, stride))
			return -1;
		vas_version = 1;
		return 0;
	}
	
	vas_version = 2;
	zero_page = (char *)malloc(Page_Size);
	bzero((void *)zero_page, Page_Size);

	vas_base_va = vas_start_va = vas_map_base->map[0].start_va;

	if(start)
		*start = vas_start_va;
	if(end) {
		*end = vas_find_end();
	}
	if(stride)
		*stride = Page_Size;
	return 0;
}
예제 #13
0
파일: fs.c 프로젝트: jpbottaro/minios
/* read/write (flag) to 'buf' 'n' bytes from position 'pos' of the file 'ino' */
int copy_file(char *buf, unsigned int n, unsigned int pos, struct inode_s *ino,
                                                                          int flag)
{
    unsigned int size, off;
    block_t blocknr;
    struct buf_s *block;

    while (n > 0) {
        if ( (blocknr = read_map(ino, pos, flag)) == NO_BLOCK)
            return ERROR;
        block = get_block(blocknr);

        off = pos % BLOCK_SIZE;
        size = MIN(n, BLOCK_SIZE - off);

        if (flag == FS_WRITE) {
            mymemcpy(block->b_buffer + off, buf, size);
            block->b_dirty = 1;
        } else {
            mymemcpy(buf, block->b_buffer + off, size);
        }

        n -= size;
        pos += size;
        buf += size;
        release_block(block);
    }

    return pos;
}
int main(int argc, char const *argv[])
{
	if(argc<2)
		return 1;
	struct Graph *map=read_map(argv[1]);
	display_debug(map);

	return 0;
}
int main(int argc, char const *argv[])
{
	if(argc<2)
		return 1;
	int nodesize;
	int **map=read_map(argv[1],&nodesize);
	//display_debug(map,nodesize);
	basemethod(map,nodesize);
	return 0;
}
예제 #16
0
static void	read_file(t_env *e)
{
	int		fd;

	if ((fd = open("src/maps/map01.txt", O_RDONLY)) == -1)
		exit(EXIT_FAILURE);
	read_size(e, fd);
	read_map(e, fd);
	close(fd);
}
int main(int argc, char const *argv[])
{
	if(argc==1){
		printf("argv NULL!\n");
		return (1);
	}
	struct Graph *map=read_map(argv[1]);
	display_debug(map);
	depth_first_search(map);
	return 0;
}
예제 #18
0
/*This function read perform the fucll check, read map into vector, check if the map is valid. If it is, it returns true*/
bool MapHandler::map_is_valid(std::string filename){
  if(!read_map(filename)){
    return false;
  }else{
    if(check_regex(filename)){
      return true;
    }else{
      return false;
    }
  }
}
예제 #19
0
파일: ldi.c 프로젝트: clcreuso/Corewar
void		ft_ldi(t_process **proc)
{
	int		fparam;
	int		sparam;

	fparam = 0;
	sparam = 0;
	if (PROC->params[0][0] == REG_CODE)
		fparam = PROC->reg[PROC->params[0][1]];
	if (PROC->params[0][0] == DIR_CODE)
		fparam = PROC->params[0][1];
	if (PROC->params[0][0] == IND_CODE)
		fparam = read_map((PROC->begin + PROC->params[0][1] % IDX_MOD));
	if (PROC->params[1][0] == DIR_CODE)
		sparam = PROC->params[1][1];
	if (PROC->params[1][0] == REG_CODE)
		sparam = PROC->reg[PROC->params[1][1]];
	PROC->reg[PROC->params[2][1]] = read_map((fparam + sparam)
			% IDX_MOD + PROC->begin);
}
int main(int argc, char const *argv[])
{
	if(argc==1){
		printf("argv NULL!\n");
		return (1);
	}
	int nodesize;
	int **map=read_map(argv[1],&nodesize);
	display_debug(map,nodesize);
	depth_first_search(map,nodesize);
	return 0;
}
예제 #21
0
파일: parser.c 프로젝트: iscaswcm/darknet
layer parse_region(list *options, size_params params)
{
    int coords = option_find_int(options, "coords", 4);
    int classes = option_find_int(options, "classes", 20);
    int num = option_find_int(options, "num", 1);

    layer l = make_region_layer(params.batch, params.w, params.h, num, classes, coords);
    assert(l.outputs == params.inputs);

    l.log = option_find_int_quiet(options, "log", 0);
    l.sqrt = option_find_int_quiet(options, "sqrt", 0);

    l.softmax = option_find_int(options, "softmax", 0);
    l.background = option_find_int_quiet(options, "background", 0);
    l.max_boxes = option_find_int_quiet(options, "max",30);
    l.jitter = option_find_float(options, "jitter", .2);
    l.rescore = option_find_int_quiet(options, "rescore",0);

    l.thresh = option_find_float(options, "thresh", .5);
    l.classfix = option_find_int_quiet(options, "classfix", 0);
    l.absolute = option_find_int_quiet(options, "absolute", 0);
    l.random = option_find_int_quiet(options, "random", 0);

    l.coord_scale = option_find_float(options, "coord_scale", 1);
    l.object_scale = option_find_float(options, "object_scale", 1);
    l.noobject_scale = option_find_float(options, "noobject_scale", 1);
    l.mask_scale = option_find_float(options, "mask_scale", 1);
    l.class_scale = option_find_float(options, "class_scale", 1);
    l.bias_match = option_find_int_quiet(options, "bias_match",0);

    char *tree_file = option_find_str(options, "tree", 0);
    if (tree_file) l.softmax_tree = read_tree(tree_file);
    char *map_file = option_find_str(options, "map", 0);
    if (map_file) l.map = read_map(map_file);

    char *a = option_find_str(options, "anchors", 0);
    if(a){
        int len = strlen(a);
        int n = 1;
        int i;
        for(i = 0; i < len; ++i){
            if (a[i] == ',') ++n;
        }
        for(i = 0; i < n; ++i){
            float bias = atof(a);
            l.biases[i] = bias;
            a = strchr(a, ',')+1;
        }
    }
    return l;
}
예제 #22
0
파일: spawn.c 프로젝트: ichaos/jos
static int
map_segment(envid_t child, uintptr_t va, size_t memsz,
	int fd, size_t filesz, off_t fileoffset, int perm)
{
	int i, r;
	void *blk;

	//cprintf("map_segment %x+%x\n", va, memsz);

	if ((i = PGOFF(va))) {
		va -= i;
		memsz += i;
		filesz += i;
		fileoffset -= i;
	}

	for (i = 0; i < memsz; i += PGSIZE) {
		if (i >= filesz) {
			// allocate a blank page
			if ((r = sys_page_alloc(0, UTEMP, perm)) < 0) {
				return r;
			}
                        memset(UTEMP, 0, PGSIZE);
			sys_page_map(0, UTEMP, child, (void *)(va+i), perm);
			return r;
		} else {
			// from file
			if (perm & PTE_W) {
				// must make a copy so it can be writable
				if ((r = sys_page_alloc(0, UTEMP, PTE_P|PTE_U|PTE_W)) < 0)
					return r;
				if ((r = seek(fd, fileoffset + i)) < 0)
					return r;
				if ((r = read(fd, UTEMP, MIN(PGSIZE, filesz-i))) < 0)
					return r;
                                memset(UTEMP+MIN(PGSIZE, filesz-i), 0, PGSIZE-MIN(PGSIZE, filesz-i));
				if ((r = sys_page_map(0, UTEMP, child, (void*) (va + i), perm)) < 0)
					panic("spawn: sys_page_map data: %e", r);
				sys_page_unmap(0, UTEMP);
			} else {
				// can map buffer cache read only
				if ((r = read_map(fd, fileoffset + i, &blk)) < 0)
					return r;
				if ((r = sys_page_map(0, blk, child, (void*) (va + i), perm)) < 0)
					panic("spawn: sys_page_map text: %e", r);
			}
		}
	}
	return 0;
}
예제 #23
0
파일: tiled.c 프로젝트: rlofc/cage
/* We use libtmx to load our game's Tiled file and
 * then call read_map to store our required tilemap
 * layers.
 */
static int build_tilemap(struct game* game)
{
    tmx_map* m;
    m = tmx_load("res/game.tmx");
    if (m == NULL) {
        printf("Error reading tmx file.");
        goto error;
    } else {
        if (read_map(game, m) == -1) goto error;
    }
    return 0;
error:
    return -1;
}
예제 #24
0
struct hash *set_map(struct parameters params)
{
	if (NULL != params.map_filename)
		return read_map(params.map_filename);

	struct hash *map = create_hash(1);
	if (NULL == map) { perror(NULL); exit(EXIT_FAILURE); }

	char *val = strdup(params.new_label);
	if (! hash_set(map, params.old_label, val)) {
		perror(NULL); exit(EXIT_FAILURE);
	}

	return map;
}
예제 #25
0
파일: link.c 프로젝트: ssinghi/minix
/*===========================================================================*
 *                             fs_rdlink                                     *
 *===========================================================================*/
int fs_rdlink()
{
  block_t b;                   /* block containing link text */
  struct buf *bp = NULL;       /* buffer containing link text */
  char* link_text;             /* either bp->b_data or rip->i_block */
  register struct inode *rip;  /* target inode */
  register int r;              /* return value */
  size_t copylen;

  copylen = min( (size_t) fs_m_in.REQ_MEM_SIZE, UMAX_FILE_POS);

  /* Temporarily open the file. */
  if( (rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);

  if (rip->i_size >= MAX_FAST_SYMLINK_LENGTH) {
  /* normal symlink */
	if ((b = read_map(rip, (off_t) 0)) == NO_BLOCK) {
		r = EIO;
	} else {
		bp = get_block(rip->i_dev, b, NORMAL);
		link_text = bp->b_data;
		if (bp)
			r = OK;
		else
			r = EIO;
	}
  } else {
        /* fast symlink, stored in inode */
        link_text = (char*) rip->i_block;
	r = OK;
  }
  if (r == OK) {
  /* Passed all checks */
  /* We can safely cast to unsigned, because copylen is guaranteed to be
     below max file size */
	copylen = min( copylen, (unsigned) rip->i_size);
	r = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
	                   (vir_bytes) 0, (vir_bytes) link_text,
			   (size_t) copylen);
	put_block(bp, DIRECTORY_BLOCK);
	if (r == OK)
		fs_m_out.RES_NBYTES = copylen;
  }

  put_inode(rip);
  return(r);
}
예제 #26
0
파일: rich_json.c 프로젝트: vaughan0/vlib
static void read_value(void* _self, rich_Sink* to) {
  JSONSource* self = _self;
  Input* in = self->in;
  int ch = skip_whitespace(in);
  bool bval;
  switch (ch) {
    case -1:
      RAISE(EOF);

    case 'n':
      read_primitive(in, "ull");
      call(to, sink, RICH_NIL, NULL);
      break;
    case 't':
      read_primitive(in, "rue");
      bval = true;
      call(to, sink, RICH_BOOL, &bval);
      break;
    case 'f':
      read_primitive(in, "alse");
      bval = false;
      call(to, sink, RICH_BOOL, &bval);
      break;

    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
    case '+': case '-':
      read_number(in, ch, to);
      break;

    case '"':
      read_string(self);
      call(to, sink, RICH_STRING, &self->sval);
      break;

    case '[':
      read_array(self, to);
      break;
    case '{':
      read_map(self, to);
      break;

    default:
      RAISE(MALFORMED);
  }
}
예제 #27
0
파일: count_island.c 프로젝트: Strade288/42
int			count_island(char *path)
{
	int		fd;
	int		nb_line;
	int		size_line;

	nb_line = 0;
	size_line = 0;
	if (!(fd = open(path, O_RDONLY)))
		return (0);
	if (!read_map(fd, &nb_line, &size_line))
		return (0);
	if (!(fd = open(path, O_RDONLY)))
		return (0);
	draw_map(fd, nb_line, size_line);
	return (1);
}
예제 #28
0
파일: nif.c 프로젝트: valekhz/aliter
void read_all_maps(const char *file) {
    struct map_cache_header header;

    FILE *fp;
    int i;

    if ((fp = fopen(file, "rb")) == NULL) {
        debug("Could not open map cache file.\n");
        exit(EXIT_FAILURE);
    }

    fseek(fp, 0, SEEK_SET);
    fread(&header, sizeof(struct map_cache_header), 1, fp);

    for (i = 0; i < header.map_count; i++) {
        debug("Reading map %d\n", i);
        read_map(&maps[i], fp);
    }
}
예제 #29
0
/**
 * Reads 'size' bytes starting at 'offset' from the data of the given inode.
 * 
 * If successful buf[0] -> buf[size-1] will contain bytes read.
 *
 * Returns the number of bytes successfully read.
 */
int minix_read(struct minix_inode *inode, char *buf, size_t size, off_t offset)
{
	int sbytes = 0;		/* bytes read so far */
	int nbytes = size;	/* bytes remaining to be read */
	int c_pos = offset;	/* current position in file data */

	zone_nr z = 0;		/* the zone c_pos is located in */
	zone_nr z_data = 0;	/* the zone # on disk that holds c_pos */
	int z_offset = 0;	/* c_pos's offset in this zone */
	int chunk = 0;		/* # bytes we're reading from this zone */

	struct minix_block *blk;	/* current block we're reading */

	/* can't possibly read more than the file has to offer */
	if(nbytes > inode->i_size)
		nbytes = inode->i_size;

	while(nbytes > 0) {
		z = c_pos / BLOCK_SIZE;
		z_offset = c_pos % BLOCK_SIZE;
		chunk = MIN(nbytes, (BLOCK_SIZE - z_offset));

		/* if we try to read past file end then stop and just return
		 * bytes read so far. */
		if((z_data = read_map(inode, z * BLOCK_SIZE)) == NO_ZONE)
			return sbytes;

		blk = get_block(z_data, TRUE);

		/* copy the required contents (chunk bytes) of the block to 
 		 * correct position in user buffer. */
		memcpy(buf + sbytes, blk->blk_data + z_offset, chunk);

		put_block(blk, DATA_BLOCK);

		sbytes += chunk;	/* ++ bytes read so far */
		nbytes -= chunk;	/* -- bytes left to read */
		c_pos += chunk;		/* ++ current position in file data */
	}

	/* return the number of bytes we managed to read */
	return sbytes;
}
int main(int argc, char const *argv[])
{
	if(argc==1){
		printf("argv NULL!\n");
		return (1);
	}
	struct Graph *map=read_map(argv[1]);
	//display_debug(map);
	int startnode,endnode;
	int answer[EDGE];
	startnode=0,endnode=7;
	//recursive
	answer[0]=startnode;
	allpath(map,answer,endnode,1);
	printf("*************\n");
	//no recursive
	allpath_nor(map,startnode,endnode);
	return 0;
}