Пример #1
0
int mincore_one(char *filename)
{
    int fd, npg;
    struct stat st;
    char *outname;
    unsigned char *vec;
    void *map = 0;
    int retval = 1;

    if((fd = open(filename, O_RDONLY)) == -1) {
	fprintf(stderr, "%s: %s\n", filename, strerror(errno));
	retval = 0;
	goto out;
    }

    if(fstat(fd, &st) == -1) {
	fprintf(stderr, "fstat: %s\n", strerror(errno));
	retval = 0;
	goto out_close;
    }

    npg = st.st_size / pagesize + ((st.st_size % pagesize) != 0);
    vec = malloc(npg);
    if(!vec) {
	fprintf(stderr, "malloc(%d): %s\n", npg, strerror(errno));
	retval = 0;
	goto out_close;
    }
    if(st.st_size) {
	map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
	if(map == MAP_FAILED) {
	    fprintf(stderr, "mmap(%s): %s\n", filename, strerror(errno));
	    retval = 0;
	    goto out_free;
	}
	if(mincore(map, st.st_size, vec) == -1) {
	    fprintf(stderr, "mincore: %s\n", strerror(errno));
	    retval = 0;
	    goto out_munmap;
	}
    }
    if(o_fullname)
	outname = filename;
    else {
	outname = strrchr(filename, '/');
	outname = outname ? outname + 1 : filename;
    }
    info_func(outname, vec, npg);

out_munmap:
    if(map && munmap(map, st.st_size) == -1)
	fprintf(stderr, "munmap(%p, %ld): %s\n", map, st.st_size,
		strerror(errno));
out_free:
    free(vec);
out_close:
    close(fd);
out:
    return retval;
}
Пример #2
0
/**
 * load a specified plugin.
 *
 * @param pe pointer to error string returned (if error)
 * @param plugin path to plugin to load
 *
 * return PLUGIN_E_SUCCESS, or not, with pe set
 */
int plugin_load(char **pe, char *path) {
    PLUGIN_ENTRY *ppi;
    void *phandle;
    PLUGIN_INFO *(*info_func)(void);
    PLUGIN_INFO *pinfo;

    DPRINTF(E_DBG,L_PLUG,"Attempting to load plugin %s\n",path);

    phandle = os_loadlib(pe, path);
    if(!phandle) {
        DPRINTF(E_INF,L_PLUG,"Couldn't get lib handle for %s\n",path);
        return PLUGIN_E_NOLOAD;
    }

    ppi = (PLUGIN_ENTRY*)malloc(sizeof(PLUGIN_ENTRY));
    memset(ppi,0x00,sizeof(PLUGIN_ENTRY));

    ppi->phandle = phandle;

    info_func = (PLUGIN_INFO*(*)(void)) os_libfunc(pe, phandle,"plugin_info");
    if(info_func == NULL) {
        DPRINTF(E_INF,L_PLUG,"Couldn't get info_func for %s\n",path);
        os_unload(phandle);
        free(ppi);
        return PLUGIN_E_BADFUNCS;
    }

    pinfo = info_func();
    ppi->pinfo = pinfo;

    if(!pinfo) {
        if(pe) *pe = strdup("plugin declined to load");
        os_unload(phandle);
        free(ppi);
        return PLUGIN_E_NOLOAD;
    }

    if(pinfo->version != PLUGIN_VERSION) {
        DPRINTF(E_INF,L_PLUG,"Plugin is too old: version %d, expecting %d\n",
                pinfo->version, PLUGIN_VERSION);
        os_unload(phandle);
        free(ppi);
        return PLUGIN_E_NOLOAD;
    }

    DPRINTF(E_INF,L_PLUG,"Loaded plugin %s (%s)\n",path,pinfo->server);

    if(!_plugin_initialized) {
        _plugin_initialized = 1;
        memset((void*)&_plugin_list,0,sizeof(_plugin_list));
    }

    ppi->next = _plugin_list.next;
    _plugin_list.next = ppi;

    _plugin_recalc_codecs();
    return PLUGIN_E_SUCCESS;
}
Пример #3
0
static int l_sqlite3_column_info(lua_State * L, const char * (*info_func)(sqlite3_stmt*,int) )
{
    const char * info = info_func(checkstmt_stmt(L, 1), checkint(L, 2));

    if (info)
        lua_pushstring(L, info);
    else
        lua_pushstring(L, "");

    return 1;
}
Пример #4
0
/*
 * find_fragments()
 *
 * This breaks down the assembly between start and end (inclusive, starting
 * from 1) into small fragments where each fragment consists of a set of
 * sequences which all span the entire fragment size.
 *
 * Or to put it another way:
 *
 * Seq1  ----------------------------------
 * Seq2      ------------------------
 * Seq3           --------------------------------
 *
 * Gives:
 *
 * Seq1  |----|-----|-------------------|------|       |
 * Seq2  |    |-----|-------------------|      |       |
 * Seq3  |    |     |-------------------|------|-------|
 *
 * This greatly simplifies the process of certain types of depth analysis.
 *
 * Arguments:
 *	io		The Gap IO handle
 *	contig		The contig number (1..NumContigs)
 *	start		The first base to include (1..ContigLen)
 *	end		The last base to include (start..ContigLen)
 *	info_func	A function to call when querying contig and seq info
 *	info_data	Client specific data passed into info_func
 *	clientfunc	A function to call with each fragment set
 *	clientdata	Client specific data passed into clientfunc
 *
 * Returns:
 *	 0 for success
 *	-1 for failure
 */
int find_fragments(GapIO *io,
		   int contig,
		   int start,
		   int end,
		   int (*info_func)(int         job,
				    void       *mydata,
				    info_arg_t *theirdata),
		   void *info_data,
		   void (*clientfunc)(GapIO *io,
				      int contig,
				      int start,
				      int end,
				      seq_frag *frag,
				      int num_frags,
				      void *clientdata),
		   void *clientdata) {
    seq_frag *frag;
    int max_frags, num_frags;
    int last_pos = start;
    int next_end = INT_MAX;
    info_arg_t info;

    /*
     * Firstly, find the left most gel in our region.
     * This leaves the first GReadings spanning this region in "r".
     */
    info.contig_info.contig = contig;
    info_func(GET_CONTIG_INFO, info_data, &info);
    info.gel_info.gel = info.contig_info.leftgel;
    do {
	info_func(GET_GEL_INFO, info_data, &info);
    } while (info.gel_info.position + info.gel_info.length < start &&
	     (info.gel_info.gel = info.gel_info.next_right));

    /*
     * Initialise our "frag" array.
     * See qual.c:calc_contig_info_phred() for similar code structuring.
     */
    max_frags = 10;
    num_frags = 0;
    if (NULL == (frag = (seq_frag *)xmalloc(max_frags * sizeof(*frag))))
	return -1;

    /*
     * Now we scan through sequences finding regions of identical depth.
     * We produce a series of sequence fragments within this region.
     * This makes non-trivial depth-based analysis (such as depth of
     * templates) much easier.
     */
    do {
	int frag_start, frag_end;

	if (info.gel_info.gel == 0)
	    break;

	/* Keep track of the nearest sequence end point */
	if (next_end > info.gel_info.position + info.gel_info.length - 1) {
	    next_end = info.gel_info.position + info.gel_info.length - 1;
	}

	/* Add gel to fragment list */
	if (num_frags >= max_frags) {
	    max_frags *= 2;
	    frag = (seq_frag *)xrealloc(frag, max_frags * sizeof(*frag));
	    if (frag == NULL)
		return -1;
	}
	
	frag[num_frags].num = info.gel_info.gel;
	frag[num_frags].abs_start = info.gel_info.position;
	frag[num_frags].abs_end =
	    info.gel_info.position + info.gel_info.length - 1;
	frag[num_frags].cutoff_len = info.gel_info.start;
	num_frags++;


	/*
	 * Candidate end position - where the next sequence starts.
	 */
	last_pos = info.gel_info.position;
	info.gel_info.gel = info.gel_info.next_right;
	if (info.gel_info.gel) {
	    info_func(GET_GEL_INFO, info_data, &info);
	    frag_end = MIN(info.gel_info.position-1, end);
	} else {
	    frag_end = end;
	}

	frag_start = MAX(last_pos, start);

	if (frag_end >= frag_start) {
	    int i;
	    int tmp_end;

	    /*
	     * We have a fragment, but we may need to break it up further.
	     * Specifically, our frag_start to frag_end at this point will
	     * indicate the region between two sequence start points, but
	     * one or more sequences could end within this range. We keep
	     * track of the next end position and break this fragment into
	     * sub fragments.
	     */
	    do {
		tmp_end = MIN(frag_end, next_end);

		if (tmp_end >= frag_start) {
		    /*
		     * At long last, we now have our fragment information.
		     * Compute the start and end points within the individual
		     * sequences and call our callback function.
		     */
		    for (i = 0; i < num_frags; i++) {
			frag[i].seq_start =frag_start - frag[i].abs_start +
			    frag[i].cutoff_len;
			frag[i].seq_end   = tmp_end - frag[i].abs_start +
			    frag[i].cutoff_len;
		    }

		    clientfunc(io, contig, frag_start, tmp_end,
			       frag, num_frags, clientdata);
		}
		
		/*
		 * Check if a sequence ends - if so, remove it from our frag
		 * array.
		 * This also recomputes the new next_end value.
		 */
		frag_start = MAX(start, next_end+1);
		next_end = INT_MAX-1;
		for (i = 0; i < num_frags; i++) {
		    if (frag[i].abs_end <= tmp_end) {
			memmove(&frag[i], &frag[i+1],
				(num_frags-i-1) * sizeof(*frag));
			num_frags--; i--;
		    } else if (next_end > frag[i].abs_end) {
			next_end = frag[i].abs_end;
		    }
		}
	    } while (frag_start <= frag_end);
	}

    } while (info.gel_info.position <= end);

    xfree(frag);
    return 0;
}
Пример #5
0
void open_plugin_tex(PluginTex *pit)
{
	int (*version)(void);
	
	/* init all the happy variables */
	pit->doit= NULL;
	pit->pname= NULL;
	pit->stnames= NULL;
	pit->varstr= NULL;
	pit->result= NULL;
	pit->cfra= NULL;
	pit->version= 0;
	pit->instance_init= NULL;
	
	/* clear the error list */
	BLI_dynlib_get_error_as_string(NULL);

	/* no BLI_dynlib_close! multiple opened plugins... */
	/* if(pit->handle) BLI_dynlib_close(pit->handle); */
	/* pit->handle= 0; */

	/* open the needed object */
	pit->handle= BLI_dynlib_open(pit->name);
	if(test_dlerr(pit->name, pit->name)) return;

	if (pit->handle != NULL) {
		/* find the address of the version function */
		version= (int (*)(void)) BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion");
		if (test_dlerr(pit->name, "plugin_tex_getversion")) return;
		
		if (version != NULL) {
			pit->version= version();
			if( pit->version >= 2 && pit->version <=6) {
				int (*info_func)(PluginInfo *);
				PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); 

				info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo");
				if (!test_dlerr(pit->name, "plugin_getinfo")) {
					info->instance_init = NULL;

					info_func(info);

					pit->doit= (int(*)(void)) info->tex_doit;
					pit->callback= (void(*)(unsigned short)) info->callback;
					pit->stypes= info->stypes;
					pit->vars= info->nvars;
					pit->pname= info->name;
					pit->stnames= info->snames;
					pit->varstr= info->varstr;
					pit->result= info->result;
					pit->cfra= info->cfra;
					pit->instance_init = info->instance_init;
					if (info->init) info->init();
				}
				MEM_freeN(info);
			} else {
				printf ("Plugin returned unrecognized version number\n");
				return;
			}
		}
	}
}