template <typename G , typename V> Path(
        const G &graph,
        const V v_source,
        const V v_target,
        const std::vector<V> &predecessors,
        const std::vector<double> &distances,
        bool only_cost,
        bool normal = true) :
    m_start_id(graph.graph[v_source].id),
    m_end_id(graph.graph[v_target].id) {
        if (!only_cost) {
            complete_path(graph,
                    v_source,
                    v_target,
                    predecessors,
                    distances,
                    normal);
            return;
        }
        /*
         * only_cost
         */
        if (v_target != predecessors[v_target]) {
            push_front(
                    {graph.graph[v_target].id,
                    -1,
                    distances[v_target],
                    distances[v_target]});
        }
        return;
    }
Exemple #2
0
void		file_dfs(char *arg, t_vector *stack,
			 t_vector *dirs, char *name)
{
  struct stat	dd;
  struct dirent	*dp;
  char		*path_name;
  char		*dirname;
  DIR		*dir;

  dirname = (vector_size(dirs) ? dir_from_vector(dirs) : my_strdup("./"));
  if ((dir = opendir(dirname)))
    {
      while ((dp = readdir(dir)) != NULL)
	{
	  path_name = complete_path(dirname, dp->d_name);
	  if (lstat(path_name, &dd) == -1)
	    my_fprintf(2, "globbing: can't stat %s\n", path_name);
	  if ((name[0] != '.') && (dp->d_name[0] == '.'));
	  else if ((S_ISDIR(dd.st_mode) || (!my_strstr(arg, "/")))
		   && (match(dp->d_name, name)))
	    matching_file(arg, stack, dirs, dp);
	  xsfree(path_name);
	}
      closedir(dir);
    }
  xsfree(dirname);
}
Exemple #3
0
static int		check_path(t_env *data, int step)
{
	int		i;
	t_room	*ptr;

	i = 0;
	ptr = data->rooms;
	if (step > data->nb_room)
		return (0);
	while (ptr)
	{
		if (ptr->weight == step - 1)
		{
			while (ptr->link && ptr->link[i])
			{
				if (!(ptr->link[i]->weight))
					ptr->link[i]->weight = step;
				i++;
			}
			i = 0;
		}
		ptr = ptr->next;
	}
	if (complete_path(data))
		return (1);
	return (check_path(data, step + 1));
}
Exemple #4
0
SEXP get_tol_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,n;
	void **pdata;
	char pathtofile[PATH];
	AVCTol *reg;
	AVCBinFile *file;
	SEXP *table, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));
	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)), 1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileTOL)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextTol(file)){n++;}

	Rprintf("Number of TOLERANCES:%d\n", n);
	
	table=calloc(3, sizeof(SEXP));
	pdata=calloc(3, sizeof(void *));

	PROTECT(table[0]=NEW_INTEGER(n));
	pdata[0]=INTEGER(table[0]);
	PROTECT(table[1]=NEW_INTEGER(n));
	pdata[1]=INTEGER(table[1]);
	PROTECT(table[2]=NEW_NUMERIC(n));
	pdata[2]=REAL(table[2]);

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		if(!(reg=(AVCTol*)AVCBinReadNextTol(file)))
			error("Error while reading register");

		((int *)pdata[0])[i]=reg->nIndex;

		((int *)pdata[1])[i]=reg->nFlag;

		((double *)pdata[2])[i]=reg->dValue;
	}

	PROTECT(aux=NEW_LIST(3));
	for(i=0;i<3;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	UNPROTECT(4);

	free(table);
	free(pdata);

	return aux;
}
Exemple #5
0
void		matching_file(char *arg, t_vector *stack,
			      t_vector *dirs, struct dirent *dp)
{
  char		*file_name;

  if (my_strstr(arg, "/"))
    {
      vector_push(dirs, (void *)complete_path(dp->d_name, "/"));
      add_matching_files(my_strstr(arg, "/") + 1, stack, dirs);
      xsfree(vector_pop(dirs));
    }
  else
    {
      file_name = dir_from_vector(dirs);
      vector_push(stack, (void *)complete_path(file_name, dp->d_name));
      xsfree(file_name);
    }
}
Exemple #6
0
int FileSystem::create_dir(char *new_dir_)
{
	char new_dir[BCTEXTLEN];
	strcpy(new_dir, new_dir_);
	complete_path(new_dir);

	mkdir(new_dir, S_IREAD | S_IWRITE | S_IEXEC);
	return 0;
}
bool all_paths_enumeratort::next(patht &path)
{
  if(last_path.empty())
  {
    // This is the first time we've been called -- build an initial
    // path.
    last_path.push_back(path_nodet(loop_header));

    // This shouldn't be able to fail.
    complete_path(last_path, 0);

    if(is_looping(last_path))
    {
      // If this was a loop path, we're good.  If it wasn't,
      // we'll keep enumerating paths until we hit a looping one.
      // This case is exactly the same as if someone just called
      // next() on us.
      path.clear();
      path.insert(path.begin(), last_path.begin(), last_path.end());
      return true;
    }
  }

  do
  {
#ifdef DEBUG
    std::cout << "Enumerating next path...\n";
#endif

    int decision=backtrack(last_path);
    complete_path(last_path, decision);

    if(is_looping(last_path))
    {
      path.clear();
      path.insert(path.begin(), last_path.begin(), last_path.end());
      return true;
    }
  }
  while(!last_path.empty());

  // We've enumerated all the paths.
  return false;
}
Exemple #8
0
void run_external(char *path, char *filename)
{
	static char	cmdline[MAX_PATH*2];
	GtkWidget	*w;

	w=GTK_WIDGET(gtk_builder_get_object(builder, "UserListWindow"));
	gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
	complete_path(cmdline,path,filename);
	_beginthread(exec_cmdline, 0, strdup(cmdline));
}
Exemple #9
0
void run_external(char *path, char *filename)
{
	static char	cmdline[MAX_PATH*2];
	GtkWidget	*w;

	w=glade_xml_get_widget(xml, "MainWindow");
	gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
	complete_path(cmdline,path,filename);
	_beginthread(exec_cmdline, 0, strdup(cmdline));
}
Exemple #10
0
void exec_cmdstr(char *cmdstr, char *path, char *filename)
{
	char	p[MAX_PATH+1];
	GtkWidget	*w;

	complete_path(p,path,filename);
	w=glade_xml_get_widget(xml, "MainWindow");
	gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
	_beginthread(exec_cmdline, 0, mycmdstr(cmdstr, p));
}
Exemple #11
0
int FileSystem::is_dir(const char *path)      // return 0 if the text is a directory
{
	if(!strlen(path)) return 0;

	char new_dir[BCTEXTLEN];
	struct stat ostat;    // entire name is a directory

	strcpy(new_dir, path);
	complete_path(new_dir);
	if(!stat(new_dir, &ostat) && S_ISDIR(ostat.st_mode)) 
		return 1;
	else
		return 0;
}
Exemple #12
0
int FileSystem::change_dir(const char *new_dir)
{
	char new_dir_full[BCTEXTLEN];
	
	strcpy(new_dir_full, new_dir);

	complete_path(new_dir_full);
// cut ending slash
	if(strcmp(new_dir_full, "/") && 
		new_dir_full[strlen(new_dir_full) - 1] == '/') 
		new_dir_full[strlen(new_dir_full) - 1] = 0;
	update(new_dir_full);
	return 0;
}
void all_paths_enumeratort::complete_path(patht &path, int succ)
{
  if(path.empty())
    return;

  path_nodet &node=path.back();
  extend_path(path, node.loc, succ);

  goto_programt::targett end=path.back().loc;

  if(end==loop_header || loop.find(end)==loop.end())
    return;

  complete_path(path, 0);
}
Exemple #14
0
int FileSystem::extract_dir(char *out, const char *in)
{
	strcpy(out, in);
	if(!is_dir(in))
	{
// complete string is not directory
		int i;

		complete_path(out);

		for(i = strlen(out); i > 0 && out[i - 1] != '/'; i--)
		{
			;
		}
		if(i >= 0) out[i] = 0;
	}
	return 0;
}
int CondorFileTable::is_file_name_local( const char *incomplete_name, char **local_name )
{
	char *url = NULL;
	char *logical_name = NULL;

	assert( local_name != NULL && *local_name == NULL );

	// Convert the incomplete name into a complete path
	complete_path( incomplete_name, &logical_name );

	// Now look to see if the file is already open.
	// If it is, ask the file if it is local.

	int match = find_logical_name( logical_name );
	if(match!=-1) {
		CondorFile *file;
		resume(match);
		file = pointers[match]->file;
		*local_name = strdup(strrchr(file->get_url(),':')+1); 
		free( logical_name );
		return file->is_file_local();
	}

	// Otherwise, resolve the url by normal methods.
	lookup_url( logical_name, &url );
	free( logical_name );

	// Copy the local path name out
	*local_name = strdup(strrchr(url,':')+1);

	// Create a URL chain and ask it if it is local.
	CondorFile *f = create_url_chain(url);
	free( url );
	if(f) {
		if( f->is_file_local() ) {
			delete f;
			return 1;
		} else {
			delete f;
			return 0;
		}
	}
	return 0;
}
Exemple #16
0
/*It returns the fields of the table (name and type)*/
SEXP get_table_fields(SEXP info_dir, SEXP table_name)
{
	int i, *idata;
	char infodir[PATH];
	SEXP *table, aux;
	AVCBinFile *tablefile;
	AVCTableDef *tabledef;
	AVCFieldInfo *fields;

	strcpy(infodir,CHAR(STRING_ELT(info_dir,0)));
	complete_path(infodir,"",1);

tablefile=_AVCBinReadOpenTable( infodir, CHAR(STRING_ELT(table_name,0)) );

	if(!tablefile)
		error("The path to the info directory is invalid or the table doesn't exist");
	
	tabledef=(tablefile->hdr).psTableDef;
	fields=tabledef->pasFieldDef;


	table=calloc(2, sizeof(SEXP));

	PROTECT(table[0]=NEW_STRING(tabledef->numFields));
	PROTECT(table[1]=NEW_INTEGER(tabledef->numFields));
	idata=INTEGER(table[1]);
	for(i=0;i<tabledef->numFields;i++)
	{
		SET_STRING_ELT(table[0],i,COPY_TO_USER_STRING(fields[i].szName));

		idata[i]=fields[i].nType1;
	}

	PROTECT(aux=NEW_LIST(2));
	SET_VECTOR_ELT(aux,0,table[0]);
	SET_VECTOR_ELT(aux,1,table[1]);

	UNPROTECT(3);

	free(table);

	return aux;
}
Exemple #17
0
/*\
|*| Find a file in the static directory structure
\*/
hfile_t *
find_file_name(u16 *path, int displ)
{
	hfile_t *p, *ret = 0;

	hash_directory(stuni(path));
	path = unist(complete_path(stuni(path)));

	/*\ Check filename (caseless) and then check md5 hash \*/
	for (p = hfile; p; p = p->next) {
		switch (unicode_cmp(p->filename, path)) {
		case 1:
			if (ret) break;
		case 0:
			ret = p;
		}
	}
	if (!ret && displ)
		fprintf(stderr, "  %-40s - NOT FOUND\n", basename(path));
	return ret;
}
int CondorFileTable::open( const char *logical_name, int flags, int mode )
{
	char *full_logical_name = NULL;

	CondorFile *file=0;
	CondorFileInfo *info=0;

	// Convert a relative path into a complete path

	complete_path( logical_name, &full_logical_name );

	// Find a fresh file descriptor

	int fd = find_empty();
	if(fd<0) {
		errno = EMFILE;
		free( full_logical_name );
		return -1;
	}

	file = open_file_unique( full_logical_name, flags, mode );
	if(!file) {
		free( full_logical_name );
		return -1;
	}

	info = make_info( full_logical_name );
	info->open_count++;

	// Flags that should be applied once only are now removed

	flags &= ~(O_TRUNC);
	flags &= ~(O_CREAT);
	
	// Install the pointer and return!

	pointers[fd] = new CondorFilePointer(file,info,flags,full_logical_name);
	free( full_logical_name );
	return fd;
}
Exemple #19
0
void touch_sem(char *path, char *filename)
{
	char	fn[MAX_PATH*2];

	ftouch(complete_path(fn,path,filename));
}
Exemple #20
0
/*It imports the data from an arc file*/
SEXP get_arc_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n, **ptable;
	double *x,*y;
	char pathtofile[PATH];
	AVCArc *reg;
	AVCBinFile *file;
	SEXP *table, points, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));

	complete_path(pathtofile, (char *)CHAR(STRING_ELT(coverage,0)), 1);

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileARC)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextArc(file)){n++;}

	Rprintf("Number of ARCS:%d\n",n);


	table=calloc(7,sizeof(SEXP));
	ptable=(int **)calloc(7, sizeof(int *));
	for(i=0;i<7;i++)
	{
		PROTECT(table[i]=NEW_INTEGER(n));
		ptable[i]=(int *)INTEGER(table[i]);
	}


	PROTECT(points=NEW_LIST(n));

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		
		if(!(reg=(AVCArc*)AVCBinReadNextArc(file)))
			error("Error while reading register");


		ptable[0][i]=reg->nArcId;

		ptable[1][i]=reg->nUserId;

		ptable[2][i]=reg->nFNode;

		ptable[3][i]=reg->nTNode;

		ptable[4][i]=reg->nLPoly;

		ptable[5][i]=reg->nRPoly;

		ptable[6][i]=reg->numVertices;

		SET_VECTOR_ELT(points,i,NEW_LIST(2));

		aux=VECTOR_ELT(points,i);

		SET_VECTOR_ELT(aux,0,NEW_NUMERIC(reg->numVertices));
		SET_VECTOR_ELT(aux,1,NEW_NUMERIC(reg->numVertices));

		x=REAL(VECTOR_ELT(aux,0));
		y=REAL(VECTOR_ELT(aux,1));

		for(j=0;j<reg->numVertices;j++)
		{
			x[j]=reg->pasVertices[j].x;
			y[j]=reg->pasVertices[j].y;
		}

	}

	PROTECT(aux=NEW_LIST(8));

	for(i=0;i<7;i++)
	{
		SET_VECTOR_ELT(aux,i,table[i]);
	}

	SET_VECTOR_ELT(aux,7,points);

	UNPROTECT(9);

	free(table);
	return aux;
}
Exemple #21
0
/*
It returns the table names and something more:
- Arc file
- Number of fields
- Register Size
- Number of registers
- External/Internal Table Identifier
*/
SEXP get_table_names(SEXP directory)
{
	SEXP *table, aux;
	AVCRawBinFile *arcfile;
	AVCTableDef tabledefaux;
	char arcdir[PATH], *dirname;
	int i,n, **idata;

	dirname= (char *) CHAR(STRING_ELT(directory,0));/*FIXME*/
	strcpy(arcdir,dirname);

	complete_path(arcdir,"arc.dir", 0);

	if(!(arcfile=AVCRawBinOpen(arcdir,"r")))
	{
		error("Error opening arc.dir");
	}

	n=0;
	while(!AVCRawBinEOF(arcfile))
	{
		if(!_AVCBinReadNextArcDir(arcfile, &tabledefaux))
			n++;
	}

	AVCRawBinFSeek(arcfile, 0,SEEK_SET);

	table=calloc(6, sizeof(SEXP));

	PROTECT(table[0]=NEW_STRING(n));
	PROTECT(table[1]=NEW_STRING(n));

	idata=calloc(4, sizeof(char *));
	PROTECT(table[2]=NEW_INTEGER(n));
	idata[0]=INTEGER(table[2]);
	PROTECT(table[3]=NEW_INTEGER(n));
	idata[1]=INTEGER(table[3]);
	PROTECT(table[4]=NEW_INTEGER(n));
	idata[2]=INTEGER(table[4]);
	PROTECT(table[5]=NEW_LOGICAL(n));
	idata[3]=LOGICAL(table[5]);


	i=0;
	while(!AVCRawBinEOF(arcfile))
	{
		if(_AVCBinReadNextArcDir(arcfile, &tabledefaux))
			break;


		SET_STRING_ELT(table[0],i,COPY_TO_USER_STRING(tabledefaux.szTableName));
		SET_STRING_ELT(table[1],i,COPY_TO_USER_STRING(tabledefaux.szInfoFile));

		idata[0][i]=tabledefaux.numFields;
		idata[1][i]=tabledefaux.nRecSize;
		idata[2][i]=tabledefaux.numRecords;
		if(!strcmp(tabledefaux.szExternal,"XX"))
			idata[3][i]=1;
		else
			idata[3][i]=0;

		i++;
	}

	PROTECT(aux=NEW_LIST(6));

	for(i=0;i<6;i++)
		SET_VECTOR_ELT(aux,i,table[i]);

	UNPROTECT(7);

	free(table);
	free(idata);

	return aux;
}
Exemple #22
0
int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd)
{
    char b_path[MAX_STR_SIZE];
    char b_name[MAX_STR_SIZE];
    char b_cmd[MAX_STR_SIZE];
    const wchar_t *tmpline = &line[wcslen(cmd) + 1];   /* start after "/command " */

    if (wcs_to_mbs_buf(b_path, tmpline, sizeof(b_path)) == -1) {
        return -1;
    }

    if (wcs_to_mbs_buf(b_cmd, cmd, sizeof(b_cmd)) == -1) {
        return -1;
    }

    if (b_path[0] == '~') {
        complete_home_dir(self, b_path, sizeof(b_path), b_cmd, strlen(b_cmd) + 2);
    }

    int si = char_rfind(b_path, '/', strlen(b_path));

    if (!b_path[0]) {    /* list everything in pwd */
        b_path[0] = '.';
        b_path[1] = '\0';
    } else if (!si && b_path[0] != '/') {    /* look for matches in pwd */
        char tmp[MAX_STR_SIZE];
        snprintf(tmp, sizeof(tmp), ".%s", b_path);
        snprintf(b_path, sizeof(b_path), "%s", tmp);
    }

    snprintf(b_name, sizeof(b_name), "%s", &b_path[si + 1]);
    b_path[si + 1] = '\0';
    int b_name_len = strlen(b_name);
    DIR *dp = opendir(b_path);

    if (dp == NULL) {
        return -1;
    }

    char dirnames[MAX_DIRS][NAME_MAX + 1];
    struct dirent *entry;
    int dircount = 0;

    while ((entry = readdir(dp)) && dircount < MAX_DIRS) {
        if (strncmp(entry->d_name, b_name, b_name_len) == 0
                && strcmp(".", entry->d_name) && strcmp("..", entry->d_name)) {
            snprintf(dirnames[dircount], sizeof(dirnames[dircount]), "%s", entry->d_name);
            ++dircount;
        }
    }

    closedir(dp);

    if (dircount == 0) {
        return -1;
    }

    if (dircount > 1) {
        qsort(dirnames, dircount, NAME_MAX + 1, qsort_strcasecmp_hlpr);
        print_matches(self, m, dirnames, dircount, NAME_MAX + 1);
    }

    return complete_path(self, dirnames, dircount, NAME_MAX + 1);
}
Exemple #23
0
SEXP get_pal_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n;
	int **idata;
	char pathtofile[PATH];
	void **ptable;
	AVCPal *reg;
	AVCBinFile *file;
	SEXP *table, points, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));


	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)), 1);


	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFilePAL)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextPal(file)){n++;}

	Rprintf("Number of POLYGONS:%d\n",n);

	idata=calloc(3,sizeof(int *));

        table=calloc(6,sizeof(SEXP));
        ptable=(void **)calloc(6, sizeof(void *));

        PROTECT(table[0]=NEW_INTEGER(n));  /*Polygon ID*/
        ptable[0]=(int *)INTEGER(table[0]);
        PROTECT(table[1]=NEW_NUMERIC(n));  /*Min X. coordinate*/
        ptable[1]=(double *)REAL(table[1]);
        PROTECT(table[2]=NEW_NUMERIC(n));  /*Min Y. coordinate*/
        ptable[2]=(double *)REAL(table[2]);
        PROTECT(table[3]=NEW_NUMERIC(n));  /*Max X. coordinate*/
        ptable[3]=(double *)REAL(table[3]);
        PROTECT(table[4]=NEW_NUMERIC(n));  /*Max Y. coordinate*/
        ptable[4]=(double *)REAL(table[4]);
        PROTECT(table[5]=NEW_INTEGER(n));  /*Number of arcs*/
        ptable[5]=(int *)INTEGER(table[5]);
 
 
        PROTECT(points=NEW_LIST(n));  


	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		
		if(!(reg=(AVCPal*)AVCBinReadNextPal(file)))
			error("Error while reading register");


		((int *)ptable[0])[i]=reg->nPolyId;

		((double *)ptable[1])[i]=reg->sMin.x;
		((double *)ptable[2])[i]=reg->sMin.y;

		((double *)ptable[3])[i]=reg->sMax.x;
		((double *)ptable[4])[i]=reg->sMax.y;

		((int *)ptable[5])[i]=reg->numArcs;


		SET_VECTOR_ELT(points,i,NEW_LIST(3));
		aux=VECTOR_ELT(points,i);

		SET_VECTOR_ELT(aux,0,NEW_INTEGER(reg->numArcs));
		idata[0]=INTEGER(VECTOR_ELT(aux,0));
		SET_VECTOR_ELT(aux,1,NEW_INTEGER(reg->numArcs));
		idata[1]=INTEGER(VECTOR_ELT(aux,1));
		SET_VECTOR_ELT(aux,2,NEW_INTEGER(reg->numArcs));
		idata[2]=INTEGER(VECTOR_ELT(aux,2));

		for(j=0;j<reg->numArcs;j++)
		{
			idata[0][j]=reg->pasArcs[j].nArcId;
			idata[1][j]=reg->pasArcs[j].nFNode;
			idata[2][j]=reg->pasArcs[j].nAdjPoly;
		}

	}


        PROTECT(aux=NEW_LIST(7));
 
        for(i=0;i<6;i++)
        {
                SET_VECTOR_ELT(aux,i,table[i]);
        }
 
        SET_VECTOR_ELT(aux,6,points);
 
        UNPROTECT(8);  


	free(ptable);
	free(idata);

	return aux;
}
Exemple #24
0
SEXP get_lab_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,n;
	void **pdata;
	char pathtofile[PATH];
	AVCLab *reg;
	AVCBinFile *file;
	SEXP *table,aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));

	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)),1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileLAB)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextLab(file)){n++;}

	Rprintf("Number of LABELS:%d\n",n);


	table=calloc(8, sizeof(SEXP));
	pdata=calloc(8, sizeof(void *));

	PROTECT(table[0]=NEW_INTEGER(n));
	pdata[0]=INTEGER(table[0]);
	PROTECT(table[1]=NEW_INTEGER(n));
	pdata[1]=INTEGER(table[1]);

	for(i=2;i<8;i++)
	{
		PROTECT(table[i]=NEW_NUMERIC(n));
		pdata[i]=REAL(table[i]);

	}

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		if(!(reg=(AVCLab*)AVCBinReadNextLab(file)))
			error("Error while reading register");


		((int *)pdata[0])[i]=reg->nValue;
		((int *)pdata[1])[i]=reg->nPolyId;

		((double*)pdata[2])[i]=reg->sCoord1.x;
		((double*)pdata[3])[i]=reg->sCoord1.y;
		((double*)pdata[4])[i]=reg->sCoord2.x;
		((double*)pdata[5])[i]=reg->sCoord2.y;
		((double*)pdata[6])[i]=reg->sCoord3.x;
		((double*)pdata[7])[i]=reg->sCoord3.y;
		
	}


	PROTECT(aux=NEW_LIST(8));

	for(i=0;i<8;i++)
	{
		SET_VECTOR_ELT(aux,i,table[i]);
	}

	UNPROTECT(9);

	free(table);
	free(pdata);

	return aux;
}
Exemple #25
0
SEXP get_cnt_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n, *ilabel;
	void **pdata;
	char pathtofile[PATH];
	AVCCnt *reg;
	AVCBinFile *file;
	SEXP *table, label, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));
	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)),1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileCNT)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextCnt(file)){n++;}

	Rprintf("Number of CENTROIDS:%d\n",n);

	table=calloc(4, sizeof(SEXP));
	pdata=calloc(4,sizeof(void *));

	PROTECT(table[0]=NEW_INTEGER(n));
	pdata[0]=INTEGER(table[0]);

	PROTECT(table[1]=NEW_NUMERIC(n));
	pdata[1]=REAL(table[1]);

	PROTECT(table[2]=NEW_NUMERIC(n));
	pdata[2]=REAL(table[2]);

	PROTECT(table[3]=NEW_INTEGER(n));
	pdata[3]=INTEGER(table[3]);

	PROTECT(label=NEW_LIST(n));

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		
		if(!(reg=(AVCCnt*)AVCBinReadNextCnt(file)))
			error("Error while reading register");

		((int *)pdata[0])[i]=reg->nPolyId;

		((double *)pdata[1])[i]=reg->sCoord.x;
		((double *)pdata[2])[i]=reg->sCoord.y;

		((int *)pdata[3])[i]=reg->numLabels;

		SET_VECTOR_ELT(label,i,NEW_INTEGER(reg->numLabels));
		ilabel=INTEGER(VECTOR_ELT(label,i));
		if(reg->numLabels >0)
		{
			for(j=0;j<reg->numLabels;j++)
			{
/*				printf("%d\n", reg->panLabelIds[j]);*/
				ilabel[j]=reg->panLabelIds[j];
			}
		}

	}


	PROTECT(aux=NEW_LIST(5));

	for(i=0;i<4;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	SET_VECTOR_ELT(aux, 4, label);

	UNPROTECT(6);

	free(table);
	free(pdata);

	return aux;
}
Exemple #26
0
int pseudo_get_file_info_new( const char *logical_name, char *&actual_url )
{
	MyString remap_list;
	MyString	split_dir;
	MyString	split_file;
	MyString	full_path;
	MyString	remap;
	MyString urlbuf;
	const char	*method = NULL;

	dprintf( D_SYSCALLS, "\tlogical_name = \"%s\"\n", logical_name );

	ASSERT( actual_url == NULL );

	/* The incoming logical name might be a simple, relative, or complete path */
	/* We need to examine both the full path and the simple name. */

	filename_split( logical_name, split_dir, split_file );
	complete_path( logical_name, full_path );

	/* Any name comparisons must check the logical name, the simple name, and the full path */

	if(Shadow->getJobAd()->LookupString(ATTR_FILE_REMAPS,remap_list) &&
	  (filename_remap_find( remap_list.Value(), logical_name, remap ) ||
	   filename_remap_find( remap_list.Value(), split_file.Value(), remap ) ||
	   filename_remap_find( remap_list.Value(), full_path.Value(), remap ))) {

		dprintf(D_SYSCALLS,"\tremapped to: %s\n",remap.Value());

		/* If the remap is a full URL, return right away */
		/* Otherwise, continue processing */

		if(strchr(remap.Value(),':')) {
			dprintf(D_SYSCALLS,"\tremap is complete url\n");
			actual_url = strdup(remap.Value());
			return 0;
		} else {
			dprintf(D_SYSCALLS,"\tremap is simple file\n");
			complete_path( remap.Value(), full_path );
		}
	} else {
		dprintf(D_SYSCALLS,"\tnot remapped\n");
	}

	dprintf( D_SYSCALLS,"\tfull_path = \"%s\"\n", full_path.Value() );

	/* Now, we have a full pathname. */
	/* Figure out what url modifiers to slap on it. */

#ifdef HPUX
	/* I have no idea why this is happening, but I have seen it happen many
	 * times on the HPUX version, so here is a quick hack -Todd 5/19/95 */
	if ( full_path == "/usr/lib/nls////strerror.cat" )
		full_path = "/usr/lib/nls/C/strerror.cat\0";
#endif

	if( use_local_access(full_path.Value()) ) {
		method = "local";
	} else {
		method = "remote";
	}

	if( use_fetch(method,full_path.Value()) ) {
		urlbuf += "fetch:";
	}

	if( use_compress(method,full_path.Value()) ) {
		urlbuf += "compress:";
	}

	append_buffer_info(urlbuf,method,full_path.Value());

	if( use_append(method,full_path.Value()) ) {
		urlbuf += "append:";
	}

	if (method) {
		urlbuf += method;
		urlbuf += ":";
	}
	urlbuf += full_path;
	actual_url = strdup(urlbuf.Value());

	dprintf(D_SYSCALLS,"\tactual_url: %s\n",actual_url);

	return 0;
}
Exemple #27
0
SEXP get_txt_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n;
	int **idata;
	double *x, *y;
	char pathtofile[PATH];
	AVCTxt *reg;
	AVCBinFile *file;
	SEXP *table, points,aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));
	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)), 1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileTXT)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextTxt(file)){n++;}

	Rprintf("Number of TxT ANNOTATIONS:%d\n",n);


	table=calloc(6, sizeof(SEXP));
	idata=calloc(5, sizeof(int *));


	PROTECT(table[0]=NEW_INTEGER(n));/*nTxtId*/
	idata[0]=INTEGER(table[0]);
	PROTECT(table[1]=NEW_INTEGER(n));/*nUserId*/
	idata[1]=INTEGER(table[1]);
	PROTECT(table[2]=NEW_INTEGER(n));/*nLevel*/
	idata[2]=INTEGER(table[2]);
	PROTECT(table[3]=NEW_INTEGER(n));/*numVerticesLine*/
	idata[3]=INTEGER(table[3]);
	PROTECT(table[4]=NEW_INTEGER(n));/*numVerticesArrow*/
	idata[4]=INTEGER(table[4]);

	PROTECT(table[5]=NEW_STRING(n));/*Character strings*/


	PROTECT(points=NEW_LIST(n));

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		if(!(reg=(AVCTxt*)AVCBinReadNextTxt(file)))
			error("Error while reading register");

		((int *)idata[0])[i]=reg->nTxtId;
		((int *)idata[1])[i]=reg->nUserId;
		((int *)idata[2])[i]=reg->nLevel;
		((int *)idata[3])[i]=reg->numVerticesLine;
		((int *)idata[4])[i]=reg->numVerticesArrow;

		SET_STRING_ELT(table[5],i, COPY_TO_USER_STRING(reg->pszText));

		SET_VECTOR_ELT(points, i, NEW_LIST(2));
		aux=VECTOR_ELT(points, i);

/*This can be improved storing only the right numnber of vertices*/
		SET_VECTOR_ELT(aux, 0, NEW_NUMERIC(4));
		x=REAL(VECTOR_ELT(aux,0));
		SET_VECTOR_ELT(aux, 1, NEW_NUMERIC(4));
		y=REAL(VECTOR_ELT(aux,1));

		for(j=0;j<4;j++)
		{
			x[j]=reg->pasVertices[j].x;
			y[j]=reg->pasVertices[j].y;
		}

	}

	PROTECT(aux=NEW_LIST(7));

	for(i=0;i<6;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	SET_VECTOR_ELT(aux, i, points);

	UNPROTECT(8);

	free(table);
	free(idata);

	return aux;
}
Exemple #28
0
SEXP get_table_data(SEXP infodir, SEXP tablename) 
{
	int i,j,n;
	char pathtoinfodir[PATH];
	void **pdata;
	AVCTableDef *tabledef;
	AVCField *reg;
	AVCBinFile *file;
	SEXP *table,aux;

	strcpy(pathtoinfodir, CHAR(STRING_ELT(infodir,0)));
	complete_path(pathtoinfodir, "", 1);

	if(!(file=AVCBinReadOpen(pathtoinfodir,CHAR(STRING_ELT(tablename,0)),AVCFileTABLE)))
	{
		error("Couldn't open table file\n");
	}

	n=0;

	while(AVCBinReadNextTableRec(file)){n++;}

	AVCBinReadRewind(file);


	tabledef=(file->hdr).psTableDef;

	table=calloc(tabledef->numFields, sizeof(SEXP));
	pdata=calloc(tabledef->numFields, sizeof(void *));


	for(i=0;i<tabledef->numFields;i++)
        {
/*printf("%d %d %d\n",i,j,tabledef->pasFieldDef[j].nType1);*/
		switch(tabledef->pasFieldDef[i].nType1)
		{
			case 1:
			case 2: PROTECT(table[i]=NEW_STRING(n));break;

			case 3: PROTECT(table[i]=NEW_INTEGER(n));
				pdata[i]=(int *)INTEGER(table[i]);break;

			case 4: PROTECT(table[i]=NEW_NUMERIC(n));
				pdata[i]=(double *)REAL(table[i]);break;
                                
			case 5: PROTECT(table[i]=NEW_INTEGER(n));
				pdata[i]=(int *)INTEGER(table[i]);break;

			case 6: PROTECT(table[i]=NEW_NUMERIC(n));
				pdata[i]=(double *)REAL(table[i]);break;
		}
	}		


	for(i=0;i<n;i++)
	{
		reg=AVCBinReadNextTableRec(file);

		for(j=0;j<tabledef->numFields;j++)
		{
/*			printf("%d %d %d\n",i,j,tabledef->pasFieldDef[j].nType1);*/
			switch(tabledef->pasFieldDef[j].nType1)
			{
				case 1: 
				case 2:
	SET_STRING_ELT(table[j],i, COPY_TO_USER_STRING(reg[j].pszStr)); 
				break;

				case 3:
				((int *)pdata[j])[i]=atoi(reg[j].pszStr);
				break;

				case 4:
				((double *)pdata[j])[i]=atof(reg[j].pszStr);
				break;

				case 5:
				if(reg[j].nInt16!=0)/*Single precision*/
					((int *)pdata[j])[i]=reg[j].nInt16;
				else/*Default and double precision*/
					((int *)pdata[j])[i]=reg[j].nInt32;
				break;
				
				case 6:
				if(reg[j].fFloat!=0)/*Single precision*/
					((double *)pdata[j])[i]=reg[j].fFloat;
				else/*Default and double precision*/
					((double *)pdata[j])[i]=reg[j].dDouble;
				break;
			}
		}
	}

	PROTECT(aux=NEW_LIST(tabledef->numFields));

	for(i=0;i<tabledef->numFields;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	UNPROTECT(1+tabledef->numFields);

	free(table);
	free(pdata);

	return aux;
}