Exemple #1
0
void free_package_data(pkgdata* data) {
	stringptrlist_freeall(data->buildscript);
	stringptrlist_freeall(data->deps);
	stringptrlist_freeall(data->mirrors);
	stringptr_free(data->name);
	stringptr_free(data->tardir);
	stringptr_free(data->sha512);
}
Exemple #2
0
int main(int argc, char** argv) {
	RSScript ss, *s = &ss;
	rss_init(s, argc, argv);
	
	rss_http_request* req = rss_get_request(s);
	if(!req) return 1;
	
	if(!rss_is_cookie_authed(s)) {
		rss_redirect_hard(s, SPLITERAL("/login.html"));
		rss_free(s);
		exit(0);
	}
	
	rss_set_cookie_authed(s, NULL);
	
	stringptr *x, *y;
	
	if((kv_find(req->formdata, SPLITERAL("list"), (void**) &x))) {
		y = stringptr_replace(x, SPLITERAL("\r"), SPLITERAL(""));
		stringptr_tofile("/tmp/testfile", y);
		stringptr_free(y);
		rss_redirect_soft(s, SPLITERAL("main.cgi"));
	} else
		rss_respond500(s);
	
	rss_free(s);
	return 0;
}
/** reads FASTA formatted sequence file, and saves the sequences to
  the array seq[]; any comment line preceded by a hash-mark will be saved
  to comment */
int read_fasta(FILE *seq_file,Sequence_T **seq,
	       int do_switch_case,char **comment)
{
  int c,nseq=0,length=0;
  char seq_name[FASTA_NAME_MAX]="",
  line[SEQ_LENGTH_MAX],seq_title[FASTA_NAME_MAX]="";
  char *p;
  stringptr tmp_seq=STRINGPTR_EMPTY_INIT;

 /* read in sequences */
  while (fgets(line,sizeof(line)-1,seq_file)) {
    if ((p=strrchr(line,'\n'))) /* REMOVE NEWLINE FROM END OF LINE */
      *p= '\0'; /* TRUNCATE THE STRING */
    switch (line[0]) {
    case '#':  /* SEQUENCE COMMENT, SAVE IT */
      if (comment) /* SAVE COMMENT FOR CALLER TO USE */
	*comment = strdup(line+1);
      break;

    case '>':  /* SEQUENCE HEADER LINE */
      if (seq_name[0] && tmp_seq.p && tmp_seq.p[0]) { /* WE HAVE A SEQUENCE, SO SAVE IT! */
	if (create_seq(nseq,seq,seq_name,seq_title,tmp_seq.p,do_switch_case))
	  nseq++;
      }
      seq_name[0]='\0';
      if (sscanf(line+1,"%s %[^\n]",  /* SKIP PAST > TO READ SEQ NAME*/
	     seq_name,seq_title)<2)
	strcpy(seq_title,"untitled"); /* PROTECT AGAINST MISSING NAME */
      if (tmp_seq.p)
	tmp_seq.p[0]='\0'; /* RESET TO EMPTY SEQUENCE */
      length=0;
      break;

    case '*': /* IGNORE LINES STARTING WITH *... DON'T TREAT AS SEQUENCE! */
      break;

    default:  /* READ AS ACTUAL SEQUENCE DATA, ADD TO OUR SEQUENCE */
      if (seq_name[0]) /* IF WE'RE CURRENTLY READING A SEQUENCE, SAVE IT */
	stringptr_cat_pos(&tmp_seq,line,&length);
    }

    c=getc(seq_file); /* ?FIRST CHARACTER IS UNIGENE CLUSTER TERMINATOR? */
    if (c==EOF)
      break;
    else {
      ungetc(c,seq_file); /* PUT THE CHARACTER BACK */
      if (c=='#' && nseq>0) /* UNIGENE CLUSTER TERMINATOR, SO DONE!*/
	break;
    }
  }
  if (seq_name[0] && tmp_seq.p && tmp_seq.p[0]) { /* WE HAVE A SEQUENCE, SO SAVE IT! */
    if (create_seq(nseq,seq,seq_name,seq_title,tmp_seq.p,do_switch_case))
      nseq++;
  }
  stringptr_free(&tmp_seq);
  return nseq; /* TOTAL NUMBER OF SEQUENCES CREATED */
}
Exemple #4
0
int main(void) {
	ini_section sec;
	stringptr result;
	stringptr* ini = stringptr_copy(SPLITERAL("[main]\nfoo=bar\nbar=baz\n[section1]\nbaz=blah\nblah=foo\n"));
	// we need stringptr_copy since stringptr_linesplit modifies the buffer. which would segfault using a literal.
	stringptrlist* lines = stringptr_linesplit(ini);
	
	sec = iniparser_get_section(lines, SPLITERAL("main"));
	iniparser_getvalue(lines, &sec, SPLITERAL("bar"), &result);
	
	printf("[main] bar=%s, size=%d\n", result.ptr, (int) result.size);
	
	
	sec = iniparser_get_section(lines, SPLITERAL("section1"));
	iniparser_getvalue(lines, &sec, SPLITERAL("blah"), &result);
	
	printf("blah=%s, size=%d\n", result.ptr, (int) result.size);
	
	stringptr_free(ini);
	free(lines);
	
	return 0;
}
Exemple #5
0
int create_script(jobtype ptype, pkgstate* state, pkg_exec* item, pkgdata* data) {
	stringptr* temp, *config, tb;
	stringptr* set_cc = SPL("if [ -z \"$CC\" ] ; then\n\tCC=cc\nfi\n");
	
	char* prefix;
	char buf[256];
	int hastarball;
	if(ptype == JT_DOWNLOAD) {
		prefix = "dl";
	} else if (ptype == JT_BUILD) {
		prefix = "build";
	} else
		abort();
	
	item->scripts.filename = stringptr_format("%s/%s_%s.sh", state->cfg.builddir.ptr, prefix, item->name->ptr);
	item->scripts.stdoutfn = stringptr_format("%s/%s_%s.log", state->cfg.logdir.ptr, prefix, item->name->ptr); 
	
	config = make_config(&state->cfg);
	hastarball = get_tarball_filename(data, buf, sizeof(buf));
	
	if(ptype == JT_DOWNLOAD) {
		if(!hastarball) abort(); //bug
		temp = stringptr_concat(SPL("#!/bin/sh\n"),
			config,
			SPL("wget -O $C/"),
			stringptr_fromchar(buf, &tb),
			SPL(" "),
			stringptrlist_get(data->mirrors, rand() % stringptrlist_getsize(data->mirrors)),
			//SPL(" --no-check-certificate"),
			NULL);
		
	} else if (ptype == JT_BUILD) {
		stringptr* buildscr = stringptrlist_tostring(data->buildscript);
		
		if(!hastarball) {
			temp = stringptr_concat(SPL("#!/bin/sh\n"), 
				config,
				set_cc,
				buildscr,
				NULL);
		} else {
			if(data->tardir->size && data->tardir->ptr[0] == '/') 
				// prevent erroneus scripts from trash our fs
				abort();
			
			temp = stringptr_concat(SPL("#!/bin/sh\n"), 
				config,
				set_cc,
				SPL("cd $S/build\n"), 
				SPL("[ -e "),
				data->tardir,
				SPL(" ] && rm -rf "),
				data->tardir,
				SPL("\ntar xf $C/"), 
				stringptr_fromchar(buf, &tb),
				SPL(" || (echo tarball error; exit 1)\ncd $S/build/"),
				data->tardir,
				SPL("\n"),
				buildscr,
				NULL);
		}
		
		stringptr_free(buildscr);
		
	} else abort();

	stringptr_tofile(item->scripts.filename->ptr, temp);
	if(chmod(item->scripts.filename->ptr, 0777) == -1) die(SPL("error setting permission"));
	stringptr_free(config);
	stringptr_free(temp);
	return 1;
}
Exemple #6
0
// contract: out is already zeroed and contains only name
void get_package_contents(pkgconfig* cfg, stringptr* packagename, pkgdata* out) {
	ini_section sec;
	char buf[256];
	ulz_snprintf(buf, sizeof(buf), "%s/pkg/%s", cfg->pkgroot.ptr, packagename->ptr);
	
	stringptr* fc = stringptr_fromfile(buf);
	stringptr val;
	
	if(!fc) goto err;
	stringptrlist* ini = stringptr_linesplit(fc);
	size_t start = 0;
	
	stringptr* tmp;
	
	sec = iniparser_get_section(ini, SPL("mirrors"));
	out->mirrors = stringptrlist_new(sec.linecount);
	
	for(start = sec.startline; start < sec.startline + sec.linecount; start++) {
		tmp = stringptrlist_get(ini, start);
		if(tmp->size) stringptrlist_add(out->mirrors, stringptr_strdup(tmp), tmp->size);
	}
	
	
	sec = iniparser_get_section(ini, SPL("main"));
	
	iniparser_getvalue(ini, &sec, SPL("tardir"), &val);
	if(val.size)
		out->tardir = stringptr_copy(&val);
	else {
		// must run after mirrors!
		stringptr fe;
		if(get_tarball_filename(out, buf, sizeof(buf))) {
			stringptr_fromchar(buf, &fe);
			strip_fileext(&fe);
		} else {
			fe.size = 0;
			fe.ptr = NULL;
		}
		out->tardir = stringptr_copy(&fe);
	}
	
	iniparser_getvalue(ini, &sec, SPL("sha512"), &val);
	if(val.size)
		out->sha512 = stringptr_copy(&val);
	else
		out->sha512 = NULL;
	
	iniparser_getvalue(ini, &sec, SPL("filesize"), &val);
	if(val.size)
		out->filesize = strtoint64(val.ptr, val.size);
	else
		out->filesize = 0;
	
	sec = iniparser_get_section(ini, SPL("deps"));
	out->deps = stringptrlist_new(sec.linecount);
	
	for(start = sec.startline; start < sec.startline + sec.linecount; start++) {
		tmp = stringptrlist_get(ini, start);
		if(tmp->size) stringptrlist_add(out->deps, stringptr_strdup(tmp), tmp->size);
	}
	
	sec = iniparser_get_section(ini, SPL("build")); // the build section has always to come last
	if(sec.startline || sec.linecount) {
		start = sec.startline;
		sec = iniparser_file_as_section(ini); // iniparser may disinterpret lines starting with [
		// so be sure to use the entire rest of the file
		sec.startline = start;
		sec.linecount -= start;
		
		out->buildscript = stringptrlist_new(sec.linecount);
		
		for(start = sec.startline; start < sec.startline + sec.linecount; start++) {
			tmp = stringptrlist_get(ini, start);
			stringptrlist_add(out->buildscript, stringptr_strdup(tmp), tmp->size);
		}
	} else 
		out->buildscript = stringptrlist_new(1);
	
	stringptrlist_free(ini);
	stringptr_free(fc);
	return;
	err:
	log_perror(packagename->ptr);
	die(SPL("package not existing"));
}