* instead of html parse sbcl-bin version is managed by tsv file.
This commit is contained in:
SANO,Masatoshi 2020-01-28 01:25:50 +08:00 committed by GitHub
parent d803f4e5b5
commit 5950fbc531
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 92 additions and 373 deletions

View file

@ -93,15 +93,10 @@ AC_ARG_WITH([sbcl_bin_base],
[SBCL_BIN_URI=$withval],[SBCL_BIN_URI="https://github.com/roswell/sbcl_bin/releases/download/"])
AC_DEFINE_UNQUOTED([SBCL_BIN_URI],["${SBCL_BIN_URI}"],[uri for sbcl master])
AC_ARG_WITH([platformhtml_base],
[AC_HELP_STRING([--with-platformhtml-base=URI],[set URI for platform.html [default=https://github.com/roswell/sbcl_bin/releases/download/files/build.html]])],
[PLATFORM_HTML_URI=$withval],[PLATFORM_HTML_URI=https://github.com/roswell/sbcl_bin/releases/download/files/build.html])
AC_DEFINE_UNQUOTED([PLATFORM_HTML_URI],["${PLATFORM_HTML_URI}"],[uri for platform.html])
AC_ARG_WITH([platformhtml_backup_base],
[AC_HELP_STRING([--with-platformhtml-backup-base=URI],[set backup URI for platform.html [default=http://www.sbcl.org/]])],
[PLATFORM_HTML_BACKUP_URI=$withval],[PLATFORM_HTML_BACKUP_URI="http://www.sbcl.org/platform-table.html"])
AC_DEFINE_UNQUOTED([PLATFORM_HTML_BACKUP_URI],["${PLATFORM_HTML_BACKUP_URI}"],[backup uri for platform.html])
AC_ARG_WITH([platformtsvl_base],
[AC_HELP_STRING([--with-platformtsv-base=URI],[set URI for sbcl-bin_uri.tsv [default=https://github.com/roswell/sbcl_bin/releases/download/files/sbcl-bin_uri.tsv]])],
[PLATFORM_TSV_URI=$withval],[PLATFORM_TSV_URI=https://github.com/roswell/sbcl_bin/releases/download/files/sbcl-bin_uri.tsv])
AC_DEFINE_UNQUOTED([PLATFORM_TSV_URI],["${PLATFORM_TSV_URI}"],[uri for sbcl-bin_uri.tsv])
# man file (ros.1) generation switch
AC_ARG_ENABLE([manual_generation],

View file

@ -7,7 +7,7 @@ ROSWELL_DIR=$HOME/.roswell
ROSWELL_REPO=${ROSWELL_REPO:-https://github.com/roswell/roswell}
ROSWELL_BRANCH=${ROSWELL_BRANCH:-release}
ROSWELL_INSTALL_DIR=${ROSWELL_INSTALL_DIR:-/usr/local}
ROSWELL_PLATFORMHTML_BASE=${ROSWELL_PLATFORMHTML_BASE:-https://github.com/roswell/sbcl_bin/releases/download/files/build.html}
ROSWELL_PLATFORMHTML_BASE=${ROSWELL_PLATFORMHTML_BASE:-https://github.com/roswell/sbcl_bin/releases/download/files/sbcl-bin_uri.tsv}
ROSWELL_SBCL_BIN_URI=${ROSWELL_SBCL_BIN_URI:-https://github.com/roswell/sbcl_bin/releases/download/}
ROSWELL_QUICKLISP_DIST_URI=${ROSWELL_QUICKLISP_DIST_URI:-http://beta.quicklisp.org/dist/quicklisp.txt}

View file

@ -2,9 +2,9 @@ ros_utils= util.c util_windows.c util-list.c util-string.c util-dir.c util-dir_w
util-file.c util-file_windows.c util-system.c util-system_windows.c util-cmdline.c proc-opt.c \
manual.c manual_windows.c
check_PROGRAMS = html_sbcl
html_sbcl_SOURCES = html.c html-sbcl-bin.c main.c opt.c $(ros_utils)
html_sbcl_CFLAGS = "-D ROSWELL_HTML_TEST"
check_PROGRAMS = tsv_sbcl
tsv_sbcl_SOURCES = tsv-sbcl-bin.c main.c opt.c $(ros_utils)
tsv_sbcl_CFLAGS = "-D ROSWELL_TSV_TEST"
gend.h: FORCE
printf '#define ROS_COMPILE_ENVIRONMENT "%s"\n' "`$(CC) --version|head -n 1`" > $@.tmp
@ -23,7 +23,7 @@ cmd-internal.o: gend.h
bin_PROGRAMS = ros
ros_SOURCES = main.c opt.c download.c download_windows.c archive.c archive_windows.c \
register-commands.c html.c html-sbcl-bin.c \
register-commands.c tsv-sbcl-bin.c \
$(ros_utils) \
cmd-internal.c cmd-script.c \
cmd-run.c cmd-run-sbcl.c cmd-run-ccl.c cmd-run-clasp.c cmd-run-clisp.c cmd-run-ecl.c \

View file

@ -101,7 +101,7 @@ DEF_SUBCMD(cmd_internal_version) {
}else if(strcmp(arg1,"revision")==0) {
printf("%s\n",ROS_REVISION);
}else if(strcmp(arg1,"sbcl-bin-version-uri")==0) {
printf("%s\n",PLATFORM_HTML_URI);
printf("%s\n",PLATFORM_TSV_URI);
}else if(strcmp(arg1,"sbcl-bin-uri")==0) {
printf("%s\n",SBCL_BIN_URI);
}else if(strcmp(arg1,"glibc")==0) {

View file

@ -1,62 +0,0 @@
#include "opt.h"
LVal atag_list(char* filename);
LVal filter_sbcl_uri(LVal v) {
char* str=subseq(firsts(v),-3,0);
if(strcmp(str,"bz2")==0 ||
strcmp(str,"msi")==0) {
char* u=uname_s();
char* m=uname_m();
char *third,*fourth;
char *m2;
int i;
char* tmp=file_namestring(q(firsts(v)));
LVal ret= split_string(tmp,"-");
s(tmp);
third=firsts(nthcdr(2,ret));
fourth=firsts(nthcdr(3,ret));
if(strcmp(third,"x86")==0 &&
strcmp(fourth,"64")==0) {
m2=q("x86-64");
i=4;
}else {
m2=q(third);
i=3;
}
i=(strcmp(m2,m)==0 && strncmp(firsts(nthcdr(i,ret)),u,strlen(u))==0);
s(m2),s(str),s(m),s(u),sL(ret);
return i?toNumber(1):0;
}
s(str);
return 0;
}
char* sbcl_bin(char* file,int nth) {
char* str;
LVal ret3,ret2,ret;
cond_printf(1,"uname=%s uname-m=%s\n",uname_s(),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(nth,ret3)));
sL(ret),sL(ret2),sL(ret3);
return str;
}
#ifdef ROSWELL_HTML_TEST
char* lispdir(void) {
return NULL;
}
char** argv_orig;
int verbose=1;
int main(int argc,char** argv) {
printf("version is %s\n",sbcl_bin(argv[1],1));
}
#endif

View file

@ -1,284 +0,0 @@
#include "opt.h"
struct tag {
int type; /* 0 for not tag
1 for open tag
2 for close tag*/
char* name;
struct Cons* attr;
};
struct Cons* attralloc(void) {
struct opts* ret=alloc(sizeof(struct opts));
ret->name=NULL;
ret->value=NULL;
return toPointer(cons(ret,(LVal)NULL));
}
void attrsfree(struct Cons* a) {
struct Cons* next;
for(;a;) {
struct opts* p=(struct opts*)firstp((LVal)a);
s((char*)p->name),s((char*)p->value);
next=(struct Cons*)a->next;
dealloc(a);
a=next;
}
}
LVal parse_attr(char* str) {
int i,j;
char *name,*val;
struct Cons tmp,*ret=&tmp,*cur=ret;
struct opts* p;
tmp.next=(LVal)NULL;
for(i=0;str[i]!='\0';++i) {
name=NULL,val=NULL;
/*skip space*/
int pos=position_char_not(" \t\r\n",&str[i]);
if(pos!=-1) {
i+=pos;
}else continue;
/*attr name */
pos=position_char("\"'>/= \t\r\n",&str[i]);
if(pos!=-1)
name=subseq(&str[i],0,pos),i+=pos;
/*skip space*/
pos=position_char_not(" \t\r\n",&str[i]);
if(pos!=-1)
i+=pos;
if(!(name && str[i]=='='))
continue;
cur->next=(LVal)attralloc();;
p=(struct opts*)firstp((LVal)cur->next);
p->name=name;
/*skip space*/
pos=position_char_not(" \t\r\n",&str[++i]);
if(pos!=-1) {
i+=pos;
switch(str[i]) {
case '\'':
j=position_char("'",&str[i+1]);
if(j!=-1) {
val=subseq(&str[i+1],0,j);
i+=j+1;
}
break;
case '"':
for(j=1;str[i+j]!='"';++j)
if(str[i+j]=='\\')
++j;
val=subseq(&str[i],1,j);
i+=j;
break;
default:
pos=position_char(" \t\r\n",&str[i]);
val=subseq(&str[i],0,pos);
break;
}
p->value=val;
}
cur=(struct Cons *)cur->next;
}
return (LVal)ret->next;
}
LVal tagalloc(void) {
struct tag* t=alloc(sizeof(struct tag));
t->type=0;
t->name=NULL;
t->attr=NULL;
return (LVal)toPointer(cons(t,(LVal)NULL));
}
void tagfree(LVal l) {
struct tag* t=firstp(l);
s(t->name);
attrsfree(t->attr);
dealloc(t);
dealloc((void*)l);
}
void tagsfree(LVal tags) {
struct Cons* t=(struct Cons*)tags;
struct Cons* next;
for(;t;t=next) {
next=(struct Cons*)t->next;
tagfree((LVal)t);
}
}
LVal delete_not_open_tags(LVal t) {
LVal tag=t;
LVal ret=tag;
LVal next;
for(;((struct Cons*)tag)->next!=(LVal)NULL&&((struct tag*)firstp(tag))->type!=1;tag=next) { /* find first*/
next=Next(tag);
tagfree(tag);
}
while(Next(tag)) {
if(((struct tag*)firstp(Next(tag)))->type!=1) {
next=Next(Next(tag));
tagfree(Next(tag));
((struct Cons*)tag)->next=next;
}else
tag=Next(tag);
}
return ret;
}
LVal delete_not_tags(char* tags,LVal tag) {
LVal ret;
LVal next;
for(;Next((LVal)tag)!=(LVal)NULL&&((struct tag*)firstp(tag))->name&&strcmp(((struct tag*)firstp(tag))->name,tags)!=0;tag=Next(tag)); /* find first*/
ret=tag;
while(Next(tag)) {
if(((struct tag*)firstp(Next((LVal)tag)))->name&&
strcmp(((struct tag*)firstp(Next((LVal)tag)))->name,tags)!=0) {
next=Next(Next(tag));
tagfree(Next(tag));
((struct Cons*)tag)->next=next;
}else
tag=Next(tag);
}
return (LVal)ret;
}
LVal filter_href(LVal t) {
LVal tags=t;
LVal ret=(LVal)NULL;
for(;tags!=(LVal)NULL;tags=Next(tags)) {
char* href=NULL;
LVal a=(LVal)((struct tag*)firstp(tags))->attr;
for(;a;a=Next(a)) {
struct opts* v=(struct opts*)firstp(a);
if(strcmp(v->name,"href")==0) {
href=q(v->value);
break;
}
}
if(href)
ret=(LVal)toPointer(conss(href,ret));
}
return ret;
}
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;
}
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;
}

View file

@ -34,26 +34,22 @@ void sbcl_bin_check_file(char* file) {
int sbcl_version_bin(struct install_options* param) {
char* home=configdir();
char* platforms_html=cat(home,"tmp",SLASH,"sbcl-bin.html",NULL);
char* platforms_tsv=cat(home,"tmp",SLASH,"sbcl-bin_uri.tsv",NULL);
char* uri=get_opt("uri",0);
cond_printf(1,"sbcl_version_bin\n");
ensure_directories_exist(platforms_html);
ensure_directories_exist(platforms_tsv);
param->version_not_specified=param->version||uri?0:1;
if(param->version_not_specified) {
int ret;
printf("No SBCL version specified. Downloading platform-table.html to see the available versions...\n");
printf("No SBCL version specified. Downloading sbcl-bin_uri.tsv 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);
}
ret=download_simple(uri?uri:PLATFORM_TSV_URI,platforms_tsv,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++);
sbcl_bin_check_file(platforms_tsv);
param->version=sbcl_bin(platforms_tsv,param->version_not_specified++);
}else {
if(param->version)
param->version=q(param->version);
@ -74,7 +70,7 @@ int sbcl_version_bin(struct install_options* param) {
printf("Installing sbcl-bin/%s...\n",param->version);
param->arch_in_archive_name=1;
s(platforms_html),s(home);
s(platforms_tsv),s(home);
return 1;
}

View file

@ -7,7 +7,7 @@ struct opts* local_opt=NULL;
struct proc_opt top;
#ifndef ROSWELL_HTML_TEST
#ifndef ROSWELL_TSV_TEST
int main(int argc,char **argv) {
int i;
char* path=s_cat(configdir(),q("config"),NULL);

64
src/tsv-sbcl-bin.c Normal file
View file

@ -0,0 +1,64 @@
#include "opt.h"
LVal read_tsvline(FILE* fp) {
char buf[2000];
if(fgets(buf,2000,fp)==NULL)
return 0;
return split_string(buf,"\t\n");
}
LVal tsv_eq(LVal v1,LVal v2) {
return strcmp((char*)v1,toString(v2))==0;
}
char* sbcl_bin(char* filename,int nth) {
FILE* fp;
char buf[2000];
int os=-1,arch=-1,version=-1,variant=-1,uri=-1;
char* uname=uname_s();
char* unamem=uname_m();
cond_printf(1,"uname=%s uname-m=%s\n",uname,unamem);
cond_printf(1,"open %s\n",filename);
if((fp=fp=fopen(filename,"r"))==NULL)
return NULL;
LVal l=read_tsvline(fp);
int l_count=0;
os=position((LVal)"os",l,tsv_eq);
arch=position((LVal)"arch",l,tsv_eq);
version=position((LVal)"version",l,tsv_eq);
variant=position((LVal)"variant",l,tsv_eq);
uri=position((LVal)"uri",l,tsv_eq);
cond_printf(1,"header os=%d,arch=%d,version=%d,variant=%d,uri=%d\n",
os,arch,version,variant,uri);
sL(l);
while(l=read_tsvline(fp)) {
++l_count;
cond_printf(1,"%d os:%s ",l_count,firsts(nthcdr(os,l)));
cond_printf(1,"arch:%s ",firsts(nthcdr(arch,l)));
cond_printf(1,"variant:%s ",firsts(nthcdr(variant,l)));
cond_printf(1,"version:%s\n",firsts(nthcdr(version,l)));
if(strcmp(unamem,firsts(nthcdr(arch,l)))==0 &&
strcmp(uname,firsts(nthcdr(os,l)))==0) {
if(--nth==0) {
char* ret=q(firsts(nthcdr(version,l)));
sL(l);
fclose(fp);
return ret;
}
}
sL(l);
}
fclose(fp);
return NULL;
}
#ifdef ROSWELL_TSV_TEST
char* lispdir(void) {
return NULL;
}
char** argv_orig;
int verbose=1;
int main(int argc,char** argv) {
printf("version is %s\n",sbcl_bin(argv[1],1));
}
#endif

View file

@ -59,6 +59,15 @@ LVal find(LVal v,LVal l,Compare2 c) {
return 0;
}
int position(LVal v,LVal l,Compare2 c) {
int pos = 0;
for(;l;l=Next(l),++pos) {
if(c(v,first(l)))
return pos;
}
return -1;
}
int firsti(LVal v) {
struct Cons* l=(struct Cons*)v;
return (l->val>>2);

View file

@ -89,6 +89,7 @@ LVal mapcar1(Function1 f,LVal v);
LVal string_equal(LVal v1,LVal v2);
LVal find(LVal v,LVal l,Compare2 c);
int position(LVal v,LVal l,Compare2 c);
int firsti(LVal l);
char* firsts(LVal l);