diff -r 000000000000 -r d2ef4b44e95a setup/setup.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup/setup.c Thu Jul 09 08:23:50 2009 +0100 @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2009 J. Ali Harlow + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#ifdef WIN32 +#include +#include +#endif +#include +#include "config.h" +#include "plover/plover.h" +#include "whelk/whelk.h" + +LUALIB_API int luaopen_posix(lua_State *L); + +struct vector { + int len,alloc; + char **strings; +}; + +struct vector *vector_new(void) +{ + struct vector *vector; + vector=malloc(sizeof(*vector)); + vector->len=0; + vector->alloc=16; + vector->strings=calloc(vector->alloc,sizeof(char *)); + return vector; +} + +void vector_append(struct vector *vector,const char *str) +{ + if (++(vector->len)>=vector->alloc) + { + vector->alloc*=2; + vector->strings=realloc(vector->strings,vector->alloc*sizeof(char *)); + } + vector->strings[vector->len-1]=strdup(str); + vector->strings[vector->len]=NULL; +} + +int vector_contains(struct vector *vector,const char *str) +{ + int i; + for(i=0;ilen;i++) + if (!strcmp(vector->strings[i],str)) + return 1; + return 0; +} + +void vector_free(struct vector *vector) +{ + int i; + for(i=0;ilen;i++) + free(vector->strings[i]); + free(vector->strings); + free(vector); +} + +static void *alloc_lua(void *user_data,void *ptr,size_t osize,size_t nsize) +{ + if (!nsize) + { + free(ptr); + return NULL; + } + else + return realloc(ptr,nsize); +} + +void setup() +{ + char path[PATH_MAX],*s,*t,*prefix; + int changed; + struct comps *comps; + struct comps_group *group; + struct comps_requirement *pkg; + struct vector *packages=NULL; +#ifdef WIN32 + SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0, + path); + prefix=strdup(path); + GetModuleFileName(NULL,path,sizeof(path)); + s=strrchr(path,'/'); + if (s) + { + t=strrchr(s,'\\'); + if (t) + s=t; + } + else + s=strrchr(path,'\\'); + if (s) + *s='\0'; +#else + strcpy(path,"/tmp"); + prefix=NULL; +#endif + s=plover_strconcat(path,"/repodata/comps.xml",NULL); + comps=plover_comps_new_from_file(s); + if (!comps) + { + perror(s); + exit(1); + } + free(s); +#ifdef WIN32 + s=plover_strconcat(prefix,"\\",comps->vendor?comps->vendor:"Plover",NULL); + free(prefix); + prefix=s; +#endif + group=plover_comps_lookup_group(comps,"base"); + if (!group) + { + fprintf(stderr,"No base group found in comps.xml\n"); + exit(1); + } + packages=vector_new(); + do + { + changed=0; + for(pkg=group->packages;pkg;pkg=pkg->next) + { + if (vector_contains(packages,pkg->name)) + continue; + if (pkg->type==COMPS_REQUIREMENT_DEFAULT || + pkg->type==COMPS_REQUIREMENT_MANDATORY || + pkg->type==COMPS_REQUIREMENT_CONDITIONAL && + vector_contains(packages,pkg->requires)) + { + changed++; + vector_append(packages,pkg->name); + } + } + } while(changed); + if (!packages->len) + { + fprintf(stderr,"No packages to install\n"); + exit(1); + } + plover_install(path,prefix,packages->strings); + vector_free(packages); + plover_comps_free(comps); +#ifdef WIN32 + free(prefix); +#endif +} + +int main(int argc,char **argv) +{ + razor_set_lua_loader("posix",luaopen_posix); + razor_set_lua_loader("whelk",luaopen_whelk); + if (argc>1 && !strcmp(argv[1],"-u")) + plover_remove(NULL); + else + setup(); +}