Example #1
0
int mtnfile_console_cd(int argc, ARG args)
{
  STR path;
  int r = 1;
  MTNSTAT *rst;
  MTNSTAT *kst;
  if(argc == 1){
    ctx->remote_path = modstr(ctx->remote_path, "/");
    return(0);
  }
  path = mtnfile_console_path(args[1]);
  rst = mtn_stat(mtn, path);
  for(kst=rst;kst;kst=kst->next){
    if(S_ISDIR(kst->stat.st_mode)){
      ctx->remote_path = modstr(ctx->remote_path, path);
      r = 0;      
      break;
    }
  }
  if(r){
    mtnlogger(mtn, 0, "error: %s: not directory.\n", args[1]);
  }
  path = clrstr(path);
  rst  = clrstat(rst);
  return(r);
}
Example #2
0
STR convarg(STR a, MTNJOB *j)
{
  int i;
  STR p;
  STR q;
  if(!a){
    return(NULL);
  }
  if(!j){
    return(a);
  }
  i = 0;
  p = newstr(a);
  while(*(p + i)){
    if(*(p + i) == '{'){
      *(p + i) = 0;
      i++;
      q = newstr(p + i);
      q = convarg2(q, j);
      a = modstr(a, p);
      a = catstr(a, q);
      p = modstr(p, a);
      q = clrstr(q);
      continue;
    }
    i++;
  }
  clrstr(p);
  return(a);
}
Example #3
0
STR convarg3(STR a, MTNJOB *j)
{
  int m;
  int n;
  STR s;
  char *b;

  if(!strcmp(a, "H")){
    if(j->svr){
      a = modstr(a, j->svr->host);
    }else{
      a = modstr(a, "local");
    }
    return(a);
  }

  b = malloc(ctx->arg_max);
  a = strnum(a, b);
  if(!strlen(b)){
    s = joinarg(j->argl, ctx->delim);
  }else{
    n = atoi(b);
    m = cntarg(j->argl);
    s = newstr((n < m) ? j->argl[n] : "");
  }
  free(b);
  b = NULL;
  a = convarg4(a, s);
  clrstr(s);
  return(a);
}
Example #4
0
STR convarg2(STR a, MTNJOB *j)
{
  int i;
  STR p;
  STR q;
  STR r;
  i = 0;
  p = newstr(a);
  while(*(p + i)){
    if(*(p + i) == '}'){
      *(p + i) = 0;
      i++;
      q = newstr(p);
      r = newstr(p + i);
      q = convarg3(q, j);
      a = modstr(a, q);
      a = catstr(a, r);
      clrstr(q);
      clrstr(r);
      break;
    }
    i++;
  }
  clrstr(p);
  return(a);
}
Example #5
0
STR mtnfile_console_path(STR opt)
{
  int i;
  STR path;
  ARG dirs;
  path = newstr(ctx->remote_path);
  dirs = splitstr(opt, "/");
  for(i=0;dirs[i];i++){
    if(!strcmp(dirs[i], "..")){
      path = modstr(path, dirname(path));
    }else if(!strcmp(dirs[i], ".")){
    }else{
      if(lastchar(path) != '/'){
        path = catstr(path, "/");
      }
      path = catstr(path, dirs[i]);
    }
  }
  dirs = clrarg(dirs);
  return(path);
}
Example #6
0
int mtnfile_console()
{
  int   argc;
  ARG   args;
  char *line;
  STR prompt = newstr("mtn:/> ");
  ctx->remote_path = newstr("/");
  rl_attempted_completion_function = mtnfile_console_readline_callback;
  while((line = readline(prompt))){
    if(!strlen(line)){
      free(line); 
      continue;
    }
    args = splitstr(line, " ");
    argc = cntarg(args);
    if(!argc){
      free(line);
      continue;
    }else if(!strcmp(args[0], "exit")){ break;
    }else if(!strcmp(args[0], "quit")){ break;
    }else if(!strcmp(args[0], "help")){ mtnfile_console_help(args[1]);
    }else if(!strcmp(args[0], "ls"  )){ mtnfile_console_ls(argc,  args);
    }else if(!strcmp(args[0], "cd"  )){ mtnfile_console_cd(argc,  args);
    }else if(!strcmp(args[0], "lcd" )){ mtnfile_console_lcd(argc, args);
    }else if(!strcmp(args[0], "cat" )){ mtnfile_console_cat(argc, args);
    }else if(!strcmp(args[0], "get" )){ mtnfile_console_get(argc, args);
    }else if(!strcmp(args[0], "put" )){ mtnfile_console_put(argc, args);
    }else if(!strcmp(args[0], "del" )){ mtnfile_console_del(argc, args);
    }else{ mtnlogger(mtn, 0, "%s: no such command.\n", args[0]); }
    add_history(line);
    free(line);
    line = NULL;
    args = clrarg(args);
    prompt = modstr(prompt, "mtn:");
    prompt = catstr(prompt, ctx->remote_path);
    prompt = catstr(prompt, "> ");
  }
  return(0);
}
Example #7
0
SEXP makedf_xlink(struct iobtd *iop){
	SEXP df, df_names, idvec, peakidvec, errvec, covvec, modsv;
	yamldom_node_t *xlseq, *tmp, *seq, *prottmp, *peptmp;
	int i, count, modstrlen;
	const int ncols=5;
	char *mods;

	if(!(xlseq=yamldom_find_map_val(iop->root,"xlink"))){
		goto err;
	}

	count = count_seq_elem(xlseq);

	hidefromGC(idvec = allocVector(INTSXP,count));
	hidefromGC(peakidvec = allocVector(INTSXP,count));
	hidefromGC(errvec = allocVector(REALSXP,count));
	hidefromGC(covvec = allocVector(REALSXP,count));
	hidefromGC(modsv = allocVector(STRSXP,count));

	i=0;
	for(seq=YAMLDOM_SEQ_NODES(xlseq);seq;seq=seq->next){
		if(!(peptmp=yamldom_find_map_val(seq,"peps")))
			goto err;
		peptmp = YAMLDOM_SEQ_NODES(peptmp);

		push_elem(INTEGER(idvec),i,seq,"id",strtoint);
		push_elem(REAL(errvec),i,seq,"error",strtodouble);
		push_elem(REAL(covvec),i,seq,"fragcov",strtodouble);

		/* peaklist id (via prot -> param) */
		if(!(prottmp=yamldom_find_map_val(peptmp,"prot")))
			goto err;
		tmp = YAMLDOM_DEREF(prottmp);
		if(!(tmp=yamldom_find_map_val(tmp,"peaks")))
			goto err;
		tmp = YAMLDOM_DEREF(tmp);
		push_elem(INTEGER(peakidvec),i,tmp,"id",strtoint);
		if(!(tmp=yamldom_find_map_val(tmp,"param")))
			goto err;
		tmp = YAMLDOM_DEREF(tmp);
		modstrlen = getmodstrlen(yamldom_find_map_val(tmp,"vmod"));

		if(!(mods=malloc(modstrlen)))
			goto err;

		modstr(yamldom_find_map_val(seq,"mods"),mods);
		if(mods && *mods)
			SET_STRING_ELT(modsv, i, mkChar(mods));
		else
			SET_STRING_ELT(modsv, i, mkChar(""));

		free(mods);

		i++;
	}

	make_list_names(df_names, ncols, "xlid", "peakid", "error", "frag.cov", "mods");
	make_dataframe(df, RNULL, df_names, ncols, idvec, peakidvec, errvec, covvec, modsv);

	unhideGC();

	return df;

err:
	unhideGC();
	return RNULL;
}
Example #8
0
ARG parse(int argc, char *argv[])
{
  int r;
  char *p;
  STR buff;
  ARG args;
  if(argc < 2){
    usage();
    exit(0);
  }
  optind = 0;
  while((r = getopt_long(argc, argv, "+hVvnBbig:j:e:I:RALT:P:N:m:p:d:f:D:", get_optlist(), NULL)) != -1){
    switch(r){
      case 'h':
        usage();
        exit(0);

      case 'V':
        version();
        exit(0);

      case 'F':
        ctx->info = 1;
        break;

      case 'f':
        ctx->arg_num = ctx->arg_num ? ctx->arg_num : 1;
        if(!strcmp("-", optarg)){
          ctx->afd = 0;
        }else{
          ctx->afd = open(optarg, O_RDONLY);
          if(ctx->afd == -1){
            mtnlogger(mtn, 0, "[error] %s: %s %s\n", __func__, optarg, strerror(errno));
            exit(1);
          }
        }
        break;

      case 't':
        test();
        exit(0);

      case 'v':
        ctx->verbose = 1;
        break;

      case 'n':
        ctx->dryrun  = 1;
        break;

      case 'i':
        ctx->conv = 1;
        break;

      case 'g':
        mtn->groupstr = newstr(optarg);
        mtn->grouparg = splitstr(optarg, ",");
        break;

      case 'j':
        ctx->cpu_lim = atoi(optarg) * 10;
        break;

      case 'e':
        ctx->echo = newstr(optarg);
        setbuf(stdout, NULL);
        break;

      case 'I':
        ctx->stdin = newstr(optarg);
        break;

      case 'O':
        ctx->stdout = newstr(optarg);
        break;

      case 'E':
        ctx->stderr = newstr(optarg);
        break;

      case 'S':
        ctx->putarg = splitstr(optarg, ",");
        break;

      case 'G':
        ctx->getarg = splitstr(optarg, ",");
        break;

      case 'B':
        ctx->text = 0;
        break;

      case 'b':
        ctx->nobuf = 0;
        break;

      case 'R':
        ctx->opt_R = 1;
        break;

      case 'A':
        ctx->opt_A = 1;
        break;

      case 'L':
        ctx->opt_L = 1;
        break;

      case 'P':
        ctx->job_max = atoi(optarg);
        break;

      case 'N':
        ctx->arg_num = atoi(optarg);
        break;

      case 'm':
        strcpy(mtn->mcast_addr, optarg);
        break;

      case 'p':
        mtn->mcast_port = atoi(optarg);
        break;

      case 'd':
        ctx->delim = modstr(ctx->delim, optarg);
        break;

      case 'D':
        mtn->loglevel = atoi(optarg);
        break;

      case 'T':
        buff = newstr(optarg);
        p = strtok(buff, ",");
        while(p){
          ctx->targets = addarg(ctx->targets, p);
          p = strtok(NULL, ",");
        }
        break;

      case '?':
        usage();
        exit(1);
    }
  }

  if(ctx->opt_R && ctx->opt_A){
    usage();
    exit(1);
  }
  if(ctx->opt_R && ctx->targets[0]){
    usage();
    exit(1);
  }
  if(ctx->opt_A && ctx->targets[0]){
    usage();
    exit(1);
  }
  if(ctx->opt_R){
    ctx->mode = ctx->opt_L ? MTNEXECMODE_HYBRID : MTNEXECMODE_REMOTE;
  }else if(ctx->opt_A){
    ctx->mode = ctx->opt_L ? MTNEXECMODE_ALL1 : MTNEXECMODE_ALL0;
  }else{
    ctx->mode = ctx->targets[0] ? MTNEXECMODE_TARGET : MTNEXECMODE_LOCAL;
  }
  if(ctx->info){
    info();
    exit(0);
  }
  ctx->verbose = ctx->dryrun ? 0 : ctx->verbose;

  args = newarg(0);
  while(optind < argc){
    if(strcmp(argv[optind], ":::") == 0){
      optind++;
      ctx->linearg = newarg(0);
      break;
    }
    args = addarg(args, argv[optind++]);
  }

  if(ctx->linearg){
    while(optind < argc){
      ctx->linearg = addarg(ctx->linearg, argv[optind++]);
    }
    ctx->arg_num = ctx->arg_num ? ctx->arg_num : 1;
  }

  if((args[0] == NULL) && (ctx->arg_num == 0)){
    ctx->arg_num = 1;
  }
  return(args);
}