Example #1
0
int sbcl_bin_install(struct install_options* param) {
  int ret;
  char* home=configdir();
  char* impl=param->impl;
  char* version=param->version;
  char* impl_path= cat(home,impldir(param->arch,param->os,impl,version),NULL);
  char* src=param->expand_path;
  char* sbcl_home=cat(impl_path,"/lib/sbcl",NULL);
  char* install_root=q(impl_path);
  char* log_path=cat(home,"impls/log/",impl,"-",version,"/install.log",NULL);
  cond_printf(0,"Building %s/%s...",impl,version);
  ensure_directories_exist(impl_path);
  ensure_directories_exist(log_path);
  change_directory(src);
  setenv("SBCL_HOME",sbcl_home,1);
  setenv("INSTALL_ROOT",install_root,1);
  ret=System("(cat find-gnumake.sh; echo find_gnumake)|sh");
  if(ret!=0) {
    fprintf(stderr,"'make' command not available.\n");
    return 0;
  }
  ret=1;
  if(system_redirect("sh install.sh",log_path)==-1)
    ret=0;
  s(home),s(impl_path),s(sbcl_home),s(install_root),s(log_path);
  printf(" Done.\n");
  return ret;
}
Example #2
0
int sbcl_version_bin(struct install_options* param) {
  char* home=configdir();
  char* platforms_html=cat(home,"tmp",SLASH,"sbcl-bin.html",NULL);
  cond_printf(1,"sbcl_version_bin\n");
  ensure_directories_exist(platforms_html);
  param->version_not_specified=param->version?0:1;
  if(param->version_not_specified) {
    int ret;
    printf("No SBCL version specified. Downloading platform-table.html to see the available versions...\n");
    char* uri=get_opt("sbcl-bin-version-uri",0);
    ret=download_simple(uri?uri:PLATFORM_HTML_URI,platforms_html,0);
    if(ret!=0) {
      printf("Something wrong! Check the connection or sbcl.org is down. Download failed (Code=%d), tring the backup URL.\n",ret);
      ret=download_simple(PLATFORM_HTML_BACKUP_URI,platforms_html,0);
    }
    if(ret!=0) {
      printf("Download failed (Code=%d)\n",ret);
      return 0;
    }
    sbcl_bin_check_file(platforms_html);
    param->version=sbcl_bin(platforms_html,param->version_not_specified++);
  }else
    param->version=q(param->version);
  printf("Installing sbcl-bin/%s...\n",param->version);
  param->arch_in_archive_name=1;

  s(platforms_html),s(home);
  return 1;
}
Example #3
0
int sbcl_bin_download(struct install_options* param) {
  int result;
  char* home=configdir();
  char* arch=arch_(param);
  char* uri=get_opt("sbcl-bin-uri",0);
  cond_printf(1,"sbcl_bin_download\n");
  int retry=10;
  do {
    param->expand_path=cat(home,"src",SLASH,"sbcl","-",param->version,"-",arch,SLASH,NULL);
    impls_sbcl_bin.uri=cat(uri?uri:SBCL_BIN_URI ,param->version,"/sbcl-",param->version,
                           "-",arch,"-binary",sbcl_bin_extention(param),NULL);
    result = download(param);
    if(!result && param->version_not_specified) {
      int len = strlen(param->version)-1;
      if('1'<= param->version[len] && param->version[len] <= '9') {
        param->version[len]--;
        s(param->expand_path),s(impls_sbcl_bin.uri);
      }else if('2' <= param->version[len-1] && param->version[len-1] <= '9') {
        param->version[len-1]--;
        param->version[len] = '9';
        s(param->expand_path),s(impls_sbcl_bin.uri);
      }else if('1' == param->version[len-1]) {
        param->version[len-1] = '9';
        param->version[len] = '\0';
        s(param->expand_path),s(impls_sbcl_bin.uri);
      }else{
        s(arch),s(home);
        return 0;
      }
    }
  }while (!result && retry--);
  s(arch),s(home);
  return !!result;
}
Example #4
0
int config_help(int argc,char **argv,struct sub_command* cmd) {
  if(argc==1) {
    cond_printf(0,
                "Usage: %s config              show all variables and it's value.\n"
                "Usage: %s config set var val  set variable.\n"
                "Usage: %s config show var     show a variable value.\n\n"
                ,argv_orig[0],argv_orig[0],argv_orig[0]);
  }
  return 0;
}
Example #5
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
}
Example #6
0
char* which(char* cmd) {
#ifndef HAVE_WINDOWS_H
  char* which_cmd=cat("command -v \"",cmd,"\"",NULL);
#else
  if((cmd[0]=='.' && cmd[1]=='/')|| /* relative path */
     position_char("/:",cmd)!=-1) { /* have no path element */
    cmd=substitute_char('\\','/',q(cmd));
    return truename(cmd);
  }
  char* which_cmd=cat("cmd /c where ",cmd,"",NULL);
#endif
  cond_printf(1,"which cmd:%s\n",which_cmd);
  char* p=system_(which_cmd);
  cond_printf(1,"which result:%s\n",p);
  p=substitute_char('\0','\r',substitute_char('\0','\n',p));
  char* p2=p?remove_char("\r\n",p):q("");
  s(p),s(which_cmd);
  return p2;
}
Example #7
0
char* determin_impl(char* impl) {
  char* version=NULL;
  int pos;
  cond_printf(1,"determin_impl:%s\n",impl);
  if(impl && (pos=position_char("/",impl))!=-1) {
    version=subseq(impl,pos+1,0);
    impl=subseq(impl,0,pos);
  }else {
    if(!impl)
      impl=get_opt("default.lisp",1);
    if(impl) {
      char* opt=s_cat(q(impl),q("."),q("version"),NULL);
      version=get_opt(opt,1);
      s(opt);
    }
    if(!impl)
      impl=DEFAULT_IMPL;
    impl=q(impl);
    if(version)
      version=q(version);
  }
  if(!version&&strcmp(impl,DEFAULT_IMPL)!=0) {
    cond_printf(1,"once!%s,%s\n",impl,version);
    if(!version)
      s(version);
    version=q("system");
  }

  if(!(impl && version)) {
    char* cmd=cat(which(argv_orig[0]),verbose>0?(verbose>1?" -v -v":" -v"):""," setup",NULL);
    char* ret;
    if(impl) s(impl);
    impl=q(DEFAULT_IMPL);
    cond_printf(1,"cmd:%s\n",cmd);
    ret=system_(cmd);
    cond_printf(1,"ret:%s\n",ret);
    s(ret);
    char* path=s_cat(configdir(),q("config"),NULL);
    global_opt=load_opts(path),s(path);;
    version=get_opt(DEFAULT_IMPL".version",0);
  }
  return s_cat(impl,q("/"),version,NULL);
}
Example #8
0
int cmd_script_frontend(int argc,char **argv,struct sub_command* cmd) {
  FILE* in;
  char buf[800];
  int i=0,j,c;
  int argc_;
  char** argv_;
  char** argv_gen;
  struct opts* opt;
  if(script_frontend_sentinel)
    return cmd_script(argc,argv,cmd);
  script_frontend_sentinel=1;
  if(strcmp(argv[0],"--")==0)
    ++argv,--argc;
  cond_printf(1,"frontend:script_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]);

  for(opt=local_opt;opt;opt=opt->next)
    if(strcmp(opt->name,"lisp")==0)
      opt->name=s_cat(q("*"),opt->name,NULL);
  if((in=fopen(argv[0],"rb"))!=NULL) {
    if(fgetc(in)!='#'||fgetc(in)!='!') {
      fclose(in);
      cmd_script(argc,argv,cmd);
    }
    for(i=0;i<3;++i)
      while((c=fgetc(in))!=EOF && c!='\n');
    for(i=0;(c=fgetc(in))!=EOF;buf[i++]=c)
      if(c=='\r'||c=='\n'||i==799)
        break;
    fclose(in);
  }
  buf[i]='\0';
  cond_printf(1,"ros_script_cmd=%s\n",buf);
  argv_=parse_cmdline(buf,&argc_);
  argv_gen=alloc(sizeof(char**)*(argc+argc_));
  for(i=0;i<argc_-2&&strcmp(argv_[i+2],"$0")!=0;++i)
    argv_gen[i]=argv_[i+2];
  for(j=i;i<j+argc;++i)
    argv_gen[i]=argv[i-j];
  j=i;
  for(i=0;i<j;i+=proccmd(j-i,&argv_gen[i],top_options,top_commands));
  return 0;
}
Example #9
0
int cmd_run(int argc,char **argv,struct sub_command* cmd) {
  char* current=get_opt("program",0);
  cond_printf(1,"cmd_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]);
  if(argc==1 && !current) {
    char* tmp[]={(char*)cmd->name,"--"};
    return proccmd(2,tmp,top_options,top_commands);
  }else {
    int i;
    for(i=1;i<argc;i+=proccmd(argc-i,&argv[i],run_options,run_commands));
    if(strcmp((char*)cmd->name,ROS_RUN_REPL)!=0) {
      char* tmp[]={"--"};
      proccmd(1,tmp,run_options,run_commands);
    }else {
      char* tmp[]={"--",ROS_RUN_REPL};
      proccmd(1,tmp,run_options,run_commands);
    }
    cond_printf(1,"cmd_%s ends here %d\n",cmd->name,i);
    return i;
  }
}
Example #10
0
void sbcl_bin_check_file(char* file) {
  FILE* fp=fopen(file,"r");
  int found=0,i,j;
  char line[2000],*str="sbcl";
  if(fp!=NULL)
    while(fgets(line,2000,fp) != NULL)
      for(i=0,j=0;i<2000 && line[i]!='\0';++i)
        if(str[j]==line[i]) {
          ++j;
          if(str[j]=='\0') {
            found=1;break;
          }
        }else j=0;
  else {
    cond_printf(0,"File Open Error\n");
    exit(1);
  }
  if(!found) {
    cond_printf(0,"Invalid html(man in the middle attack?)\n");
    exit(1);
  }
}
Example #11
0
int sbcl_bin_expand(struct install_options* param) {
  cond_printf(1,"sbcl_bin_expand\n");
  char* argv[6]={"","-xf",NULL,"-C",NULL,NULL};
  char* archive=download_archive_name(param);
  char* dist_path=param->expand_path;
  char* home=configdir();
  printf("Extracting %s to %s\n",archive,dist_path);
  delete_directory(dist_path,1);
  ensure_directories_exist(dist_path);
  argv[2]=cat(home,"archives",SLASH,archive,NULL);
  argv[4]=cat(home,"src",SLASH,NULL);
  return !cmd_tar(array_stringlist(5,argv),NULL);
}
Example #12
0
int installed_p(struct install_options* param) {
  int ret;
  char *i,*impl;

  impl=q(param->impl);
  //TBD for util.
  i=s_cat(configdir(),q("impls"),q(SLASH),q(param->arch),q(SLASH),q(param->os),q(SLASH),
          q(impl),q(param->version?SLASH:""),q(param->version?param->version:""),q(SLASH),NULL);
  ret=directory_exist_p(i);
  cond_printf(1,"directory_exist_p(%s)=%d\n",i,ret);
  s(i),s(impl);
  return ret;
}
Example #13
0
int cmd_script(int argc,char **argv,struct sub_command* cmd) {
  char* current=get_opt("program",0);
  cond_printf(1,"script_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]);
  cond_printf(1,"current=%s\n",current);
  if(argc==1 && !current &&
     strcmp(argv[0],"--")==0) {
    char* tmp[]={"help","--"};
    return proccmd(2,tmp,top_options,top_commands);
  }else {
    char* result=q("");
    char* tmp[]={"script"};
    int i=strcmp(argv[0],"--")==0?1:0;
    for (;i<argc;++i) {
      char* val=escape_string(argv[i]);
      result=cat(result,"\"",val,"\"",NULL);
      s(val);
    }
    set_opt(&local_opt,"script",result,0);
    s(result);
    cmd_run_star(1,tmp,cmd);
  }
  return 0;
}
Example #14
0
LVal atag_list(char* filename) {
  FILE* fp;
  LVal ret=(LVal)NULL;
  cond_printf(1,"open %s\n",filename);
  fp=fopen(filename,"r");
  if(fp!=NULL) {
    LVal tags=parse_tags(fp,(LVal)NULL,0);
    tags=delete_not_tags("a",delete_not_open_tags(tags));
    ret=nreverse(filter_href(tags));
    tagsfree(tags);
    fclose (fp);
  }
  return ret;
}
Example #15
0
char* sbcl_bin(char* file) {
  char* str;
  LVal ret3,ret2,ret;
  cond_printf(1,"uname=%s uname-m=%s\n",uname(),uname_m());
  ret=atag_list(file);
  ret2=remove_if_not1(filter_sbcl_uri,ret);
  if(ret2==(LVal)NULL) {
    fprintf(stderr,"this architecture is not supported.stop\n");
    exit(1);
  }
  if(verbose&2)
    print_list(ret2);
  ret3= split_string(firsts(ret2),"-");
  str=q(firsts(nthcdr(1,ret3)));
  sL(ret),sL(ret2),sL(ret3);
  return str;
}
int sbcl_bin_expand(struct install_options* param) {
  char* impl=param->impl;
  char* version=q(param->version);
  int ret;
  char* home=configdir();
  char* arch= arch_(param);
  char* archive=cat(impl,"-",version,"-",arch,".msi",NULL);
  char* log_path=cat(home,"impls",SLASH,"log",SLASH,impl,"-",version,"-",arch,SLASH,"install.log",NULL);
  char* dist_path;
  int pos=position_char("-",impl);
  if(pos!=-1) {
    impl=subseq(impl,0,pos);
  }else
    impl=q(impl);
  dist_path=cat(home,"src",SLASH,impl,"-",version,"-",arch,SLASH,NULL);
  printf("Extracting the msi archive. %s to %s\n",archive,dist_path);
  archive=s_cat(q(home),q("archives"),q(SLASH),archive,NULL);
  delete_directory(dist_path,1);
  ensure_directories_exist(dist_path);
  ensure_directories_exist(log_path);
  if(dist_path[strlen(dist_path)-1]=='\\')
    dist_path[strlen(dist_path)-1]='\0';

  char* cmd=cat("msiexec.exe /a \"",
                archive,
                "\" targetdir=\"",
                dist_path,
                "\" /qn /lv ",
                "\"",
                log_path,
                "\"",
                NULL);
  cmd=cat("cmd /c \"",cmd,"\"",NULL);
  cond_printf(1,"msiexeccmd:%s\n",cmd);
  ret=System(cmd);
  s(impl);
  s(dist_path);
  s(log_path);
  s(archive);
  s(cmd),s(home),s(version),s(arch);
  return !ret;
}
Example #17
0
int System(const char* command) {
#ifndef HAVE_WINDOWS_H
  return system(command);
#else
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  DWORD ExitCode;
  cond_printf(1,"System:'%s'\n",command);
  ZeroMemory(&si,sizeof(STARTUPINFO));
  si.cb = sizeof(STARTUPINFO);
  if(!CreateProcess(NULL,(char*)command,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
    DisplayError("CreateProcess");
  if(!CloseHandle(pi.hThread)) DisplayError("CloseHandle");
  DWORD r=WaitForSingleObject(pi.hProcess, INFINITE);
  if(WAIT_OBJECT_0!=r)
    return 1;
  if(!GetExitCodeProcess(pi.hProcess,&ExitCode)||ExitCode)
    return ExitCode||1;
  return 0;
#endif
}
Example #18
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;
}
Example #19
0
void s_internal(char* f,char* name,char* file,int line) {
  cond_printf(2,"%s %d s(%s) %lu \n",file,line,name,(intptr_t)f);
  dealloc(f);
}
Example #20
0
int System(const char* command) {
  cond_printf(1,"System:%s\n",command);
  return system(command);
}
Example #21
0
char* q_internal(const char* orig,char* file,int line) {
  cond_printf(2,"%s %d q(%s) %lu \n",file,line,orig,(intptr_t)orig);
  char* ret= (char*)alloc(strlen(orig)+1);
  strcpy(ret,orig);
  return ret;
}
Example #22
0
int download_simple (char* uri,char* path,int opt) {
  FILE *bodyfile;
  char* path_partial=cat(path,".partial",NULL);
  bodyfile = fopen(path_partial,"wb");
  if (bodyfile == NULL) {
    s(path_partial);
    return 1;
  }
  download_out=0==(download_opt=opt)?stderr:stdout;

  CURL *curl;
  CURLcode res=!CURLE_OK;
  curl = curl_easy_init();
  if(curl) {
    char* current=get_opt("ros.proxy",1);
    int lenuri=strlen(uri);
    int https=(lenuri>5 && strncmp("https",uri,5)==0);
    int httponly= get_opt("proxy.http.only",0) && strcmp(get_opt("proxy.http.only",0),"1")==0;
    if(current&& ((https && !httponly) || !https)) {
      /*<[protocol://][user:password@]proxyhost[:port]>*/
      char *reserve,*protocol=NULL,*userpwd=NULL,*port=NULL,*uri=NULL;
      int pos=position_char("/",current);
      reserve=current=q_(current);
      if(pos>0 && current[pos-1]==':' && current[pos+1]=='/')
        protocol=current,current[pos-1]='\0',current=current+pos+2;
      pos=position_char("@",current);
      if(pos!=-1)
        userpwd=current,current[pos]='\0',current=current+pos+1;
      pos=position_char(":",current);
      if(pos!=-1)
        current[pos]='\0',port=current+pos+1,uri=current;
      cond_printf(1,"proxy uri=%s",uri);
      curl_easy_setopt(curl, CURLOPT_PROXY, uri);
      if(port) {
        cond_printf(1," port=%s",port);
        curl_easy_setopt(curl, CURLOPT_PROXYPORT,atoi(port));
      }
      if(userpwd)
        curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, userpwd);
      cond_printf(1,"\n");
      s(reserve);
    }
    download_count=0,content_length=0;
    curl_easy_setopt(curl, CURLOPT_URL, uri);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, PACKAGE_STRING);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
    curl_easy_setopt(curl,CURLOPT_WRITEDATA,bodyfile);
    res = curl_easy_perform(curl);
    if(res != CURLE_OK && verbose) {
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
    }
    curl_easy_cleanup(curl);
    fclose(bodyfile);
  }
  if(res != CURLE_OK)
    return 2;
  fprintf(download_out, "\n");
  int ret=rename_file(path_partial,path);
  s(path_partial);
  return ret?0:7;
}