예제 #1
0
int main_searchvariants(int argc, char* argv[],char *server_url)
{
	int cmd;
	int i;
	search_variant_request *request=(search_variant_request*)malloc(1*sizeof(search_variant_request));	
	int size_variants = 0;
	int size_calls = 0;
	request->name = "null";
	request->pageToken ="null";
	char debug = 0;
	
	static struct option long_options[]={
		{"variantSetIds",required_argument,0,'v'},
		{"referenceName",required_argument,0,'r'},
		{"start",required_argument,0,'s'},
		{"end",required_argument,0,'e'},
		{"callSetIds",required_argument,0,'c'},
		{"variantName",required_argument,0,'n'},
		{"debug",no_argument,0,'d'},
		{0,0,0,0}
	};
	//if(argc < 2)
	while((cmd=getopt_long(argc,argv,"v:r:s:e:c:n:d",long_options,NULL))!=-1)
	{
		switch(cmd)
		{
			case 'v':
					if(optarg==NULL||(strcmp(optarg,"")==0))
						{
							error("--variantSetIds string can't be empty.\n");	
						}
					  else
						{
							size_variants = count_ids(optarg);
						 	request->variantSetIds = (char**)malloc(size_variants*sizeof(char*));
							set_ids(optarg,request->variantSetIds,size_variants);
						}
						break;
			case 'r':
					if(optarg==NULL||(strcmp(optarg,"")==0))
						{
							error("--referenceName string can't be empty.\n");				
						}
					  else
						{
							request->referenceName = optarg; 
						  	
						}
						break;
			case 's': request->start = atol(optarg);
					if(request->start < 0)
					{
					  	error("--start integer must be no negative.");
					}
					break;
			case 'e': request->end = atol(optarg); 
					if(request->end < 0)
					{
						perror("--end integer must be no negative.");
					}
					break;
			case 'c': if(optarg==NULL||(strcmp(optarg,"")==0))
						{
							size_calls = 0;
						}
					  else
					  	{
					  		size_calls = count_ids(optarg);
						  	request->callSetIds = (char**)malloc(size_calls*sizeof(char*));
						  	set_ids(optarg,request->callSetIds,size_calls);
					  	}
					break;
			case 'n': request->name = optarg; break;
			case 'd': debug = 1; break;
			case '?': usage();
			default: error("Unknown argument %s\n",optarg);
		}
	}
	
	if(size_variants==0)
	{
		usage();
	}
	
	start_user(server_url);
	char* vcf_file_name;
	//process each variantSet
	for(i=0; i<size_variants; i++)
	{
		
		vcf_file_name = get_variantSetId_vcf_name(request,i);
		create_vcf_file(vcf_file_name);	
		
		while(strcmp(request->pageToken,"NULL")!=0)
		{
			user->post_fields = create_request_string(request,i,size_calls);
			//printf("post field string: %s \n",user->post_fields);
			client_search_request(user,"variants");
			//printf("%s\n",user->response);
			write_vcf_file(user->response,vcf_file_name);
			request->pageToken = get_pageToken();
			//printf("%s \n",request->pageToken);
			if(debug)
			{
				printf("%s\n",user->response);
			}
		}
	}
	end_user();
	return 0;
}
예제 #2
0
파일: pk.c 프로젝트: freebsd-riscv/riscv-pk
static void run_loaded_program(size_t argc, char** argv, uintptr_t kstack_top)
{
  // copy phdrs to user stack
  size_t stack_top = current.stack_top - current.phdr_size;
  memcpy((void*)stack_top, (void*)current.phdr, current.phdr_size);
  current.phdr = stack_top;

  // copy argv to user stack
  for (size_t i = 0; i < argc; i++) {
    size_t len = strlen((char*)(uintptr_t)argv[i])+1;
    stack_top -= len;
    memcpy((void*)stack_top, (void*)(uintptr_t)argv[i], len);
    argv[i] = (void*)stack_top;
  }

  // copy envp to user stack
  const char* envp[] = {
    // environment goes here
  };
  size_t envc = sizeof(envp) / sizeof(envp[0]);
  for (size_t i = 0; i < envc; i++) {
    size_t len = strlen(envp[i]) + 1;
    stack_top -= len;
    memcpy((void*)stack_top, envp[i], len);
    envp[i] = (void*)stack_top;
  }

  // align stack
  stack_top &= -sizeof(void*);

  struct {
    long key;
    long value;
  } aux[] = {
    {AT_ENTRY, current.entry},
    {AT_PHNUM, current.phnum},
    {AT_PHENT, current.phent},
    {AT_PHDR, current.phdr},
    {AT_PAGESZ, RISCV_PGSIZE},
    {AT_SECURE, 0},
    {AT_RANDOM, stack_top},
    {AT_NULL, 0}
  };

  // place argc, argv, envp, auxp on stack
  #define PUSH_ARG(type, value) do { \
    *((type*)sp) = (type)value; \
    sp += sizeof(type); \
  } while (0)

  #define STACK_INIT(type) do { \
    unsigned naux = sizeof(aux)/sizeof(aux[0]); \
    stack_top -= (1 + argc + 1 + envc + 1 + 2*naux) * sizeof(type); \
    stack_top &= -16; \
    long sp = stack_top; \
    PUSH_ARG(type, argc); \
    for (unsigned i = 0; i < argc; i++) \
      PUSH_ARG(type, argv[i]); \
    PUSH_ARG(type, 0); /* argv[argc] = NULL */ \
    for (unsigned i = 0; i < envc; i++) \
      PUSH_ARG(type, envp[i]); \
    PUSH_ARG(type, 0); /* envp[envc] = NULL */ \
    for (unsigned i = 0; i < naux; i++) { \
      PUSH_ARG(type, aux[i].key); \
      PUSH_ARG(type, aux[i].value); \
    } \
  } while (0)

  STACK_INIT(uintptr_t);

  if (current.cycle0) { // start timer if so requested
    current.time0 = rdtime();
    current.cycle0 = rdcycle();
    current.instret0 = rdinstret();
  }

  trapframe_t tf;
  init_tf(&tf, current.entry, stack_top);
  __clear_cache(0, 0);
  write_csr(sscratch, kstack_top);
  start_user(&tf);
}