2 * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "plover/plover.h"
30 #include "whelk/whelk.h"
32 LUALIB_API int luaopen_posix(lua_State *L);
39 struct vector *vector_new(void)
41 struct vector *vector;
42 vector=malloc(sizeof(*vector));
45 vector->strings=calloc(vector->alloc,sizeof(char *));
49 void vector_append(struct vector *vector,const char *str)
51 if (++(vector->len)>=vector->alloc)
54 vector->strings=realloc(vector->strings,vector->alloc*sizeof(char *));
56 vector->strings[vector->len-1]=strdup(str);
57 vector->strings[vector->len]=NULL;
60 int vector_contains(struct vector *vector,const char *str)
63 for(i=0;i<vector->len;i++)
64 if (!strcmp(vector->strings[i],str))
69 void vector_free(struct vector *vector)
72 for(i=0;i<vector->len;i++)
73 free(vector->strings[i]);
74 free(vector->strings);
78 static void *alloc_lua(void *user_data,void *ptr,size_t osize,size_t nsize)
86 return realloc(ptr,nsize);
91 char path[PATH_MAX],*s,*t,*prefix;
94 struct comps_group *group;
95 struct comps_requirement *pkg;
96 struct vector *packages=NULL;
98 SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0,
101 GetModuleFileName(NULL,path,sizeof(path));
110 s=strrchr(path,'\\');
117 s=plover_strconcat(path,"/repodata/comps.xml",NULL);
118 comps=plover_comps_new_from_file(s);
126 s=plover_strconcat(prefix,"\\",comps->vendor?comps->vendor:"Plover",NULL);
130 group=plover_comps_lookup_group(comps,"base");
133 fprintf(stderr,"No base group found in comps.xml\n");
136 packages=vector_new();
140 for(pkg=group->packages;pkg;pkg=pkg->next)
142 if (vector_contains(packages,pkg->name))
144 if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
145 pkg->type==COMPS_REQUIREMENT_MANDATORY ||
146 pkg->type==COMPS_REQUIREMENT_CONDITIONAL &&
147 vector_contains(packages,pkg->requires))
150 vector_append(packages,pkg->name);
156 fprintf(stderr,"No packages to install\n");
159 plover_install(path,prefix,packages->strings);
160 vector_free(packages);
161 plover_comps_free(comps);
167 int main(int argc,char **argv)
169 razor_set_lua_loader("posix",luaopen_posix);
170 razor_set_lua_loader("whelk",luaopen_whelk);
171 if (argc>1 && !strcmp(argv[1],"-u"))