예제 #1
0
파일: download.c 프로젝트: dtpeters/roswell
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) {
  int written = fwrite(ptr, size, nmemb, (FILE *)stream);
  static char* last_showd=NULL;
  char* w=q("\r");
  last_showd=last_showd?last_showd:q("");
  count+=written*size;
  if(download_opt&&content_length) {
    int i,len=width*count/content_length-width*(count-written*size)/content_length;
    s(w);
    for(i=0;i<len;++i)
      fprintf(c_out,"#"),fflush(c_out);
    return written;
  }
  if(content_length) {
    int i;
    for(i=0;i<width;++i)
      w=s_cat2(w,q((i>=(count/(content_length/(width)))?" ":"#")));
    w=s_cat2(w,qsprintf(8," %3d%%",(100*(count/100))/(content_length/100)));
  }else {
    int current,aux;
    aux=1024>count?' ':1024*1024>count?(current=count/1024,'K'):
      1024*1024*1024>count?(current=count/(1024*1024),'M'):(current=count/(1024*1024*1024),'G');
    w=s_cat2(w,qsprintf(20,"%4d%c downloaded.",current,aux));
  }
  if(strcmp(w,last_showd)){
    if(!(download_opt&1))
      fprintf(c_out, "%s", w),fflush(c_out);
    s(last_showd),last_showd=q(w);
  }
  s(w);return written;
}
예제 #2
0
LVal directory(char* path) {
  LVal ret=0;
#ifndef HAVE_WINDOWS_H
  DIR* dir=opendir(path);
  struct dirent *dirent;

  if(dir==NULL)
    return 0;
  while((dirent=readdir(dir))!=0) {
    char* str=q(dirent->d_name);
    if(dirent->d_type&DT_DIR)
      str=s_cat2(str,q("/"));
    ret=conss(str,ret);
  }
  closedir(dir);
#else
  WIN32_FIND_DATA fd;
  char *p=cat(path,"*.*",NULL);
  HANDLE dir=FindFirstFile(p,&fd);
  if(dir==INVALID_HANDLE_VALUE)
    return 0;
  do {
    if(!(strcmp(fd.cFileName,".")==0 ||
         strcmp(fd.cFileName,"..")==0)) {
      char* str=q(fd.cFileName);
      if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
        str=s_cat2(str,q(SLASH));
      ret=conss(str,ret);
    }
  }while(FindNextFile(dir,&fd)!=0);
  s(p);
  FindClose(dir);
#endif
  return ret;
}
예제 #3
0
void touch(char* path) {
  int ret;
  cond_printf(1,"%s\n",path);
#ifndef HAVE_WINDOWS_H
  char* cmd=s_cat2(q("touch "),q(path));
  ret=System(cmd);
  s(cmd);
#else
#endif
}
예제 #4
0
char* cat(char* first,...) {
  char* ret=q_(first);
  char* i;
  va_list list;
  va_start(list,first);

  for(i=va_arg( list , char*);i!=NULL;i=va_arg( list , char*)) {
    ret=s_cat2(ret,q_(i));
  }
  va_end(list);
  return ret;
}
예제 #5
0
int delete_file(char* pathspec) {
#ifndef HAVE_WINDOWS_H
  char* cmd;
  int ret;
  cmd=s_cat2(q("rm -f "),q(pathspec));
  ret=System(cmd);
  s(cmd);
  return ret==0;
#else
//  #error not implemented delete_file
#endif  
}
예제 #6
0
char* system_(char* cmd) {
  FILE *fp;
  char buf[256];
  char* s=q("");
  if((fp=popen(cmd,"r")) ==NULL) {
    printf("Error:%s\n",cmd);
    exit(EXIT_FAILURE);
  }
  while(fgets(buf,256,fp) !=NULL) {
    s=s_cat2(s,q(buf));
  }
  (void)pclose(fp);
  return s;
}
예제 #7
0
int install_help(int argc,char **argv,struct sub_command* cmd) {
  if(argc==1) {
    cond_printf(0,"Usage: %s install impl [OPTIONS]\n\nFor more details on impl specific options, type:\n %s help install impl\n\n"
                "Candidates impls for installation are:\n",argv_orig[0],argv_orig[0]);
    char* install=lispdir();
    LVal d=directory(install),v=d;
    for(;v;v=Next(v)) {
      char* str=firsts(v);
      if(str[strlen(str)-1]!='/') {
        int p=position_char(".",str);
        if(p!=-1) {
          char *sub=subseq(str,0,p);
          if(p>=8/*strlen("install-")*/ && strncmp(str,"install-",8)==0)
            printf("%s\n",sub+8);
          s(sub);
        }
      }
    }
    sL(d);
  }else if(argc==2) {
    int i,j,argc_;
    char** tmp;
    char* install_ros=s_cat2(lispdir(),q("install.ros"));
    tmp=(char**)alloc(sizeof(char*)*(argc+9));
    i=0;
    tmp[i++]=q("--");
    tmp[i++]=install_ros;
    tmp[i++]=q("help");
    tmp[i++]=q(argv[1]);
    for(j=2;j<argc;tmp[i++]=q(argv[j++]));
    argc_=i;
    for(i=0;i<argc_;i+=proccmd(argc_-i,&tmp[i],top_options,top_commands));
    for(j=0;j<argc_;s(tmp[j++]));
    dealloc(tmp);
  }
  return 0;
}
예제 #8
0
int cmd_install(int argc,char **argv,struct sub_command* cmd) {
  install_cmds *cmds=NULL;
  struct install_options param;
  quicklisp=1;
  param.os=uname();
  param.arch=uname_m();
  param.arch_in_archive_name=0;
  param.expand_path=NULL;
  if(argc!=1) {
    int ret=1,k;
    for(k=1;k<argc;++k) {
      int i,pos;
      param.impl=argv[k];
      pos=position_char("/",param.impl);
      if(pos!=-1) {
        param.version=subseq(param.impl,pos+1,0);
        param.impl=subseq(param.impl,0,pos);
      }else {
        param.version=NULL;
        param.impl=q(param.impl);
      }

      for(install_impl=NULL,i=0;i<sizeof(impls_to_install)/sizeof(struct install_impls*);++i) {
        struct install_impls* j=impls_to_install[i];
        if(strcmp(param.impl,j->name)==0) {
          install_impl=j;
        }
      }
      if(install_impl) {
        for(cmds=install_impl->call;*cmds&&ret;++cmds)
          ret=(*cmds)(&param);
        if(ret) { // after install latest installed impl/version should be default for 'run'
          struct opts* opt=global_opt;
          struct opts** opts=&opt;
          char* home=configdir();
          char* path=cat(home,"config",NULL);
          char* v=cat(param.impl,".version",NULL);
          char* version=param.version;
          if(!install_impl->util) {
            int i;
            for(i=0;version[i]!='\0';++i)
              if(version[i]=='-')
                version[i]='\0';
            set_opt(opts,"default.lisp",param.impl,0);
            set_opt(opts,v,version,0);
            save_opts(path,opt);
          }
          s(home),s(path),s(v);
        }
      }else {
        char* lisp_path=lispdir();
        int i,j,argc_;
        char** tmp;
        char* install_ros=s_cat2(lisp_path,q("install.ros"));
        if(verbose&1) {
          fprintf(stderr,"%s is not implemented internal. %s argc:%d\n",param.impl,install_ros,argc);
          for(i=0;i<argc;++i)
            fprintf(stderr,"%s:",argv[i]);
          fprintf(stderr,"\n");
        }
        tmp=(char**)alloc(sizeof(char*)*(argc+9));
        i=0;
        tmp[i++]=q("--");
        tmp[i++]=install_ros;
        tmp[i++]=q("install");
        tmp[i++]=q(argv[1]);
        for(j=2;j<argc;tmp[i++]=q(argv[j++]));
        argc_=i;
        if(verbose&1) {
          int j;
          fprintf(stderr,"argc_=%d",argc_);
          for(j=0;j<argc_;++j)
            fprintf(stderr,"argv[%d]=%s,",j,tmp[j]);
        }
        for(i=0;i<argc_;i+=proccmd(argc_-i,&tmp[i],top_options,top_commands));
        for(j=0;j<argc_;s(tmp[j++]));
        dealloc(tmp);
        return 0;
      }
      if(param.version)s(param.version);
      s(param.impl),s(param.arch),s(param.os);
      s(param.expand_path);
      if(!ret)
        exit(EXIT_FAILURE);
    }
  }else {
    char* tmp[]={"help","install"};
    proccmd(2,tmp,top_options,top_commands);
    exit(EXIT_SUCCESS);
  }
  return 0;
}
예제 #9
0
LVal parse_tags(FILE* fp,LVal before,int mode) {
  LVal current=tagalloc();
  char str[2]={'\0','\0'};
  int c,i=0;
  char* buf=q("");
  switch(mode) {
  case 0: /* wait for '<' */
    ((struct tag*)firstp(current))->type=0;
    while((c=fgetc(fp))!=EOF) {
      if(c=='<') {
        if(strlen(buf)==0) {
          tagfree(current);
          s(buf);
          return parse_tags(fp,before,1);
        }else {
          ((struct Cons*)current)->next=parse_tags(fp,current,1);
          s(buf);
          return current;
        }
      }else
        str[0]=c,buf=s_cat2(buf,q(str));
    }
    break;
  case 1: /* wait for '>' */
    ((struct tag*)firstp(current))->type=0;
    while((c=fgetc(fp))!=EOF) {
      if(i==0) {
        if(c=='/')
          ((struct tag*)firstp(current))->type=2;
        else {
          ((struct tag*)firstp(current))->type=1;
          str[0]=c;
          buf=s_cat2(buf,q(str));
        }
        ++i;
        continue;
      }
      if(c=='>') {
        char *buf2;
        if(((struct tag*)firstp(current))->type==2) {
          int pos=position_char(" \t\r\n",buf);
          if(pos!=-1) {
            buf2=subseq(buf,0,pos);
            s(buf);
            buf=buf2;
            ((struct tag*)firstp(current))->name=q(buf);
          }else {
            ((struct tag*)firstp(current))->name=buf;
            buf=q("");
          }
        }else if(((struct tag*)firstp(current))->type==1) {
          int pos=position_char(" \t\r\n",buf);
          if(pos!=-1) {
            ((struct tag*)firstp(current))->name=subseq(buf,0,pos);
            buf2=subseq(buf,pos,0);
            ((struct tag*)firstp(current))->attr=(struct Cons*)parse_attr(buf2);
            s(buf);
            buf=buf2;
          }else {
            ((struct tag*)firstp(current))->name=buf;
            buf=q("");
          }
        }
        if(strcmp(((struct tag*)firstp(current))->name,"script")==0) {
          ((struct Cons*)current)->next=parse_tags(fp,current,2);
        }else{
          ((struct Cons*)current)->next=parse_tags(fp,current,0);
        }
        s(buf);
        return current;
      }else {
        str[0]=c;
        buf=s_cat2(buf,q(str));
      }
      ++i;
    }
    break;
  case 2: /* wait for '</' */
    ((struct tag*)firstp(current))->type=0;
    while((c=fgetc(fp))!=EOF) {
      if(c=='<') {
        if((c=fgetc(fp))!=EOF && c=='/') {
          ungetc('/',fp);
          if(strlen(buf)==0) {
            tagfree(current);
            s(buf);
            return parse_tags(fp,current,1);
          }else {
            ((struct Cons*)current)->next=parse_tags(fp,current,1);
            s(buf);
            return current;
          }
        }
        ungetc('/',fp);
      }else {
        str[0]=c;
        buf=s_cat2(buf,q(str));
      }
    }
    break;
  }
  s(buf);
  return current;
}