kpm: show usage and --install-all option

git-svn-id: svn://kolibrios.org@5809 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2015-09-06 10:18:55 +00:00
parent 2d6646029b
commit e9ad07e519
13 changed files with 480 additions and 346 deletions

View File

@ -6,6 +6,7 @@
#include "7zCrc.h"
#include "7zFile.h"
#include "7zVersion.h"
#include "http.h"
#include "package.h"
#define PERIOD_4 (4 * 365 + 1)
@ -323,11 +324,11 @@ static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s)
}
void do_install(list_t *install)
void do_7z_unpack(const char *srcpath)
{
CFileInStream archiveStream;
CLookToRead lookStream;
CSzArEx db;
SRes res;
ISzAlloc allocImp;
@ -335,8 +336,7 @@ void do_install(list_t *install)
UInt16 *temp = NULL;
size_t tempSize = 0;
package_t *pkg, *tmp;
char *cache_path;
memset(&lookStream,0,sizeof(lookStream));
allocImp.Alloc = SzAlloc;
allocImp.Free = SzFree;
@ -344,19 +344,15 @@ void do_install(list_t *install)
allocTempImp.Alloc = SzAllocTemp;
allocTempImp.Free = SzFreeTemp;
list_for_each_entry_safe(pkg, tmp, install, list)
{
cache_path = make_cache_path(pkg->filename);
if (InFile_Open(&archiveStream.file, cache_path))
continue;
if (InFile_Open(&archiveStream.file, srcpath))
return;
FileInStream_CreateVTable(&archiveStream);
LookToRead_CreateVTable(&lookStream, False);
lookStream.realStream = &archiveStream.s;
LookToRead_Init(&lookStream);
CrcGenerateTable();
SzArEx_Init(&db);
res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);
@ -420,16 +416,11 @@ void do_install(list_t *install)
for (j = 0; name[j] != 0; j++)
if (name[j] == '/')
{
if (1)
{
name[j] = 0;
MyCreateDir(name);
name[j] = CHAR_PATH_SEPARATOR;
}
else
destPath = name + j + 1;
}
if (isDir)
{
@ -448,22 +439,41 @@ void do_install(list_t *install)
if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed)
{
PrintError("can not write output file");
PrintError("can not write output file\n");
res = SZ_ERROR_FAIL;
break;
}
if (File_Close(&outFile))
{
PrintError("can not close output file");
PrintError("can not close output file\n");
res = SZ_ERROR_FAIL;
break;
}
};
continue;
};
};
IAlloc_Free(&allocImp, outBuffer);
};
SzArEx_Free(&db, &allocImp);
SzFree(NULL, temp);
File_Close(&archiveStream.file);
};
void do_install(list_t *install)
{
package_t *pkg, *tmp;
char *cache_path;
list_for_each_entry_safe(pkg, tmp, install, list)
{
cache_path = make_cache_path(pkg->filename);
sprintf(conbuf,"install package %s-%s\n", pkg->name, pkg->version);
con_write_asciiz(conbuf);
do_7z_unpack(cache_path);
list_del_pkg(pkg);
};
};

View File

@ -6,6 +6,7 @@
#include "LzmaDec.h"
#include <string.h>
#include <stdio.h>
#define kNumTopBits 24
#define kTopValue ((UInt32)1 << kNumTopBits)
@ -439,13 +440,14 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
{
if (distance >= processedPos)
{
p->dicPos = dicPos;
printf("%s fail line %d distance %d processedPos %d\n",
__FUNCTION__,__LINE__,distance,processedPos );
return SZ_ERROR_DATA;
}
}
else if (distance >= checkDicSize)
{
p->dicPos = dicPos;
printf("%s fail line %d\n", __FUNCTION__,__LINE__);
return SZ_ERROR_DATA;
}
state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;

View File

@ -8,7 +8,7 @@ LD = kos32-ld
CPP= kos32-g++
STRIP = kos32-strip
CFLAGS = -U_Win32 -U_WIN32 -U__MINGW32__ -c -Os -fno-ident -fomit-frame-pointer -mno-ms-bitfields
CFLAGS = -U_Win32 -U_WIN32 -U__MINGW32__ -c -Os -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-ident -fomit-frame-pointer -mno-ms-bitfields
ARFLAG = crs
SDK_DIR:= $(abspath ../../sdk)
@ -17,10 +17,11 @@ LIB_DIR:= $(SDK_DIR)/lib
INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include
INCLUDES+=-I$(SDK_DIR)/sources/freetype/include
#DEFINES= -DDEBUG=1
#DEFINES= -DDEBUG=1 -D_7ZIP_PPMD_SUPPPORT
DEFINES= -DNDEBUG
LIBS:= -liberty -lsupc++ -lgcc_eh -lc.dll -lapp -lgcc
LIBS:= -liberty -lsupc++ -lgcc_eh -lc.dll -lapp -lgcc -lc.dll
LIBPATH:= -L$(LIB_DIR) -L/home/autobuild/tools/win32/mingw32/lib
@ -51,7 +52,6 @@ SOURCES = http.asm \
7z/Bra86.c \
7z/BraIA64.c \
7z/7zAlloc.c \
7z/Alloc.c \
$(NULL)
OBJECTS = $(patsubst %.asm, %.o, $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SOURCES))))
@ -68,7 +68,7 @@ $(NAME): $(OBJECTS) Makefile
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
%.o : %.cpp Makefile
$(CPP) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
$(CPP) $(CFLAGS) -fno-rtti -fno-exceptions $(DEFINES) $(INCLUDES) -o $@ $<
%.o : %.asm Makefile
$(FASM) $< $@

129
contrib/other/kpm/app.lds Normal file
View File

@ -0,0 +1,129 @@
/*OUTPUT_FORMAT("binary")*/
ENTRY(__start)
SECTIONS
{
.text 0x000000:
{
LONG(0x554e454D);
LONG(0x32305445);
LONG(1);
LONG(__start);
LONG(___iend);
LONG(___memsize);
LONG(___stacktop);
LONG(___cmdline);
LONG(___pgmname); /* full path */
LONG(0); /*FIXME tls data */
LONG(__idata_start)
LONG(__idata_end)
LONG(_main)
*(.init)
*(.text)
*(SORT(.text$*))
*(.text.*)
*(.glue_7t)
*(.glue_7)
___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0);
___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0);
*(.fini)
/* ??? Why is .gcc_exc here? */
*(.gcc_exc)
PROVIDE (etext = .);
*(.gcc_except_table)
}
.rdata ALIGN(32) :
{
*(.rdata)
*(SORT(.rdata$*))
___RUNTIME_PSEUDO_RELOC_LIST__ = .;
__RUNTIME_PSEUDO_RELOC_LIST__ = .;
*(.rdata_runtime_pseudo_reloc)
___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
}
.CRT ALIGN(32) :
{
___crt_xc_start__ = . ;
*(SORT(.CRT$XC*)) /* C initialization */
___crt_xc_end__ = . ;
___crt_xi_start__ = . ;
*(SORT(.CRT$XI*)) /* C++ initialization */
___crt_xi_end__ = . ;
___crt_xl_start__ = . ;
*(SORT(.CRT$XL*)) /* TLS callbacks */
/* ___crt_xl_end__ is defined in the TLS Directory support code */
___crt_xp_start__ = . ;
*(SORT(.CRT$XP*)) /* Pre-termination */
___crt_xp_end__ = . ;
___crt_xt_start__ = . ;
*(SORT(.CRT$XT*)) /* Termination */
___crt_xt_end__ = . ;
}
.data ALIGN(32) :
{
PROVIDE ( __data_start__ = .) ;
*(.data)
*(.data2)
*(SORT(.data$*))
*(.jcr)
__CRT_MT = .;
LONG(0);
PROVIDE ( __data_end__ = .) ;
*(.data_cygwin_nocopy)
___iend = . ;
}
.idata ALIGN(32):
{
__idata_start = .;
SORT(*)(.idata$2)
SORT(*)(.idata$3)
/* These zeroes mark the end of the import list. */
LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
SORT(*)(.idata$4)
SORT(*)(.idata$5)
SORT(*)(.idata$6)
SORT(*)(.idata$7)
__idata_end = . ;
}
bss ALIGN(32):
{
*(.bss)
*(COMMON)
. = ALIGN(16);
___cmdline = .;
. = . + 256;
___pgmname = .;
. = . + 1024 + 16;
___stacktop = .;
___memsize = . ;
}
/DISCARD/ :
{
*(.debug$S)
*(.debug$T)
*(.debug$F)
*(.drectve)
*(.note.GNU-stack)
*(.eh_frame)
*(.comment)
*(.debug_abbrev)
*(.debug_info)
*(.debug_line)
*(.debug_frame)
*(.debug_loc)
*(.debug_pubnames)
*(.debug_aranges)
*(.debug_ranges)
}
}

View File

@ -1,47 +1,22 @@
#include "tinyxml/tinyxml.h"
#include "package.h"
// *INDENT-OFF*
const char *key_collection = "collection";
const char *key_package = "package";
const char *key_name = "name";
const char *key_version = "version";
const char *key_group = "group";
const char *key_description = "description";
const char *key_title = "title";
const char *key_release = "release";
const char *key_file = "file";
// *INDENT-ON*
int package_id;
void parse_group(pkg_group_t* gr, TiXmlElement *xmlgroup)
{
TiXmlElement *xmlpkg;
TiXmlElement *xmle;
xmlpkg = xmlgroup->FirstChildElement(key_package);
while (xmlpkg)
{
package_t *pkg;
pkg = (package_t*)malloc(sizeof(package_t));
INIT_LIST_HEAD(&pkg->file_list);
pkg->id = package_id++;
pkg->name = strdup(xmlpkg->Attribute(key_name));
pkg->version = strdup(xmlpkg->Attribute(key_version));
xmle = xmlpkg->FirstChildElement(key_description);
pkg->description = strdup(xmle->Attribute(key_title));
xmle = xmlpkg->FirstChildElement(key_release);
pkg->filename = strdup(xmle->Attribute(key_file));
list_add_tail(&pkg->list, &gr->packages);
xmlpkg = xmlpkg->NextSiblingElement();
};
};
collection_t* load_collection_file(const char *name)
collection_t *
load_collection_file(const char *name)
{
TiXmlDocument doc;
TiXmlElement *col;
@ -51,25 +26,37 @@ collection_t* load_collection_file(const char *name)
col = doc.FirstChildElement(key_collection);
if (col)
{
collection = (collection_t*)malloc(sizeof(collection_t));
INIT_LIST_HEAD(&collection->groups);
TiXmlElement *xmlpkg;
TiXmlElement *xmle;
TiXmlElement* xmlgroup = col->FirstChildElement();
if (xmlgroup)
collection = (collection_t *) malloc(sizeof(collection_t));
INIT_LIST_HEAD(&collection->packages);
xmlpkg = col->FirstChildElement(key_package);
while (xmlpkg)
{
pkg_group_t *gr;
package_t *pkg;
gr = (pkg_group_t*)malloc(sizeof(pkg_group_t));
INIT_LIST_HEAD(&gr->list);
INIT_LIST_HEAD(&gr->packages);
pkg = (package_t *) malloc(sizeof(package_t));
gr->name = strdup(xmlgroup->Value());
list_add_tail(&gr->list, &collection->groups);
parse_group(gr, xmlgroup);
INIT_LIST_HEAD(&pkg->file_list);
pkg->id = package_id++;
pkg->name = strdup(xmlpkg->Attribute(key_name));
pkg->version = strdup(xmlpkg->Attribute(key_version));
pkg->group = strdup(xmlpkg->Attribute(key_group));
xmle = xmlpkg->FirstChildElement(key_description);
pkg->description = strdup(xmle->Attribute(key_title));
xmle = xmlpkg->FirstChildElement(key_release);
pkg->filename = strdup(xmle->Attribute(key_file));
list_add_tail(&pkg->list, &collection->packages);
xmlpkg = xmlpkg->NextSiblingElement();
};
};
return collection;
}
};

View File

@ -8,9 +8,9 @@
#include "package.h"
#include "http.h"
#define BUFFSIZE (64*1024)
void process_task(list_t *task);
extern char conbuf[256];
#define BUFFSIZE (64*1024)
#define OPTION_STD_BASE 150
@ -18,16 +18,40 @@ enum option_values
{
OPTION_HELP = OPTION_STD_BASE,
OPTION_LIST_PACKAGES,
OPTION_LIST_INSTALLED
OPTION_LIST_INSTALLED,
OPTION_INSTALL_ALL
};
static const struct option longopts[] =
{
{"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES},
{"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED},
{"install-all",no_argument, NULL, OPTION_INSTALL_ALL},
{NULL,0,NULL,0}
};
static void show_usage ()
{
sprintf (conbuf, "Usage: kpm [option...]\n");
con_write_asciiz(conbuf);
sprintf (conbuf, ("\
Options:\n\
--list-packages\n\
show available packages\n"));
con_write_asciiz(conbuf);
sprintf (conbuf, ("\
--list-installed\n\
show available packages\n"));
con_write_asciiz(conbuf);
sprintf (conbuf, ("\
--install all\n\
install all packages\n"));
con_write_asciiz(conbuf);
};
int main(int argc, char *argv[])
{
LIST_HEAD(server_list);
@ -39,6 +63,7 @@ int main(int argc, char *argv[])
int count;
char *cache_path;
char *tmp_path;
int act = 1;
if(http_init())
goto err_init;
@ -54,62 +79,41 @@ int main(int argc, char *argv[])
if(count)
build_server_list(&server_list, tmp_path);
while(1)
while(act)
{
int val;
int index;
val = getopt_long_only(argc, argv,"",longopts, &index);
if(val == -1)
break;
switch(val)
{
case OPTION_LIST_PACKAGES:
sprintf(conbuf,"available packages:\n\n");
con_write_asciiz(conbuf);
print_pkg_list(&server_list);
con_exit(0);
return 0;
act = 0;
break;
case OPTION_LIST_INSTALLED:
sprintf(conbuf,"installed packages:\n\n");
con_write_asciiz(conbuf);
print_pkg_list(&local_list);
con_exit(0);
return 0;
act = 0;
break;
case OPTION_INSTALL_ALL:
copy_list(&task_list, &server_list);
process_task(&task_list);
act = 0;
break;
default:
break;
show_usage();
act = 0;
}
};
#if 0
{
package_t *pkg;
LIST_HEAD(install_list);
LIST_HEAD(download_list);
if(collection && build_install_list(&install_list, collection))
{
if(build_download_list(&download_list, &install_list))
do_download(&download_list);
if(!list_empty(&download_list))
remove_missing_packages(&install_list, &download_list);
list_for_each_entry(pkg, &install_list, list)
{
sprintf(conbuf,"install package %s-%s\n", pkg->name, pkg->version);
con_write_asciiz(conbuf);
};
do_install(&install_list);
};
}
#endif
con_exit(0);
return 0;
@ -119,6 +123,3 @@ err_init:
return -1;
}

View File

@ -8,17 +8,10 @@ extern "C" {
typedef struct
{
list_t groups;
list_t packages;
char *issue;
}collection_t;
typedef struct
{
list_t list;
list_t packages;
char *name;
}pkg_group_t;
typedef struct package
{
list_t list;
@ -26,6 +19,7 @@ typedef struct package
int id;
char *name;
char *version;
char *group;
char *filename;
char *description;
}package_t;
@ -35,6 +29,7 @@ static inline void list_del_pkg(package_t *pkg)
list_del(&pkg->list);
free(pkg->description);
free(pkg->filename);
free(pkg->group);
free(pkg->version);
free(pkg->name);
free(pkg);
@ -43,8 +38,9 @@ static inline void list_del_pkg(package_t *pkg)
collection_t* load_collection_file(const char *name);
collection_t* load_collection_buffer(const char *buffer);
int copy_list(list_t *list, list_t *src);
int build_server_list(list_t *slist, const char *path);
int build_install_list(list_t *list, collection_t *collection);
int build_download_list(list_t *download, list_t *src);
void remove_missing_packages(list_t *install, list_t *missed);
char *make_cache_path(const char *path);
@ -53,6 +49,8 @@ void print_pkg_list(list_t *list);
void do_download(list_t *download);
void do_install(list_t *install);
extern char conbuf[256];
#ifdef __cplusplus
}
#endif

View File

@ -143,6 +143,7 @@ int build_download_list(list_t *download, list_t *src)
pkg->id = tmp->id;
pkg->name = strdup(tmp->name);
pkg->version = strdup(tmp->version);
pkg->group = strdup(tmp->group);
pkg->filename = strdup(tmp->filename);
pkg->description = strdup(tmp->description);
list_add_tail(&pkg->list, download);
@ -166,6 +167,7 @@ void do_download(list_t *download_list)
count = http_load_file(cache_path, make_url(pkg->filename));
sprintf(conbuf,"%s %d bytes loaded\n",cache_path, count);
con_write_asciiz(conbuf);
if( !test_archive(cache_path))
list_del_pkg(pkg);
else
@ -192,16 +194,12 @@ void remove_missing_packages(list_t *install, list_t *missed)
};
};
int build_install_list(list_t *list, collection_t *collection)
int copy_list(list_t *list, list_t *src)
{
pkg_group_t *gr;
package_t *pkg, *tmp;
int count = 0;
list_for_each_entry(gr, &collection->groups, list)
{
package_t *pkg, *tmp;
list_for_each_entry(tmp, &gr->packages, list)
list_for_each_entry(tmp, src, list)
{
pkg = (package_t*)malloc(sizeof(package_t));
@ -209,11 +207,11 @@ int build_install_list(list_t *list, collection_t *collection)
pkg->id = tmp->id;
pkg->name = strdup(tmp->name);
pkg->version = strdup(tmp->version);
pkg->group = strdup(tmp->group);
pkg->filename = strdup(tmp->filename);
pkg->description = strdup(tmp->description);
list_add_tail(&pkg->list, list);
count++;
}
};
return count;
}
@ -229,14 +227,10 @@ int build_server_list(list_t *slist, const char *path)
collection = load_collection_file(path);
if(collection)
{
pkg_group_t *gr;
list_for_each_entry(gr, &collection->groups, list)
{
package_t *pkg, *tmp;
list_for_each_entry(tmp, &gr->packages, list)
list_for_each_entry(tmp, &collection->packages, list)
{
pkg = (package_t*)malloc(sizeof(package_t));
@ -244,11 +238,11 @@ int build_server_list(list_t *slist, const char *path)
pkg->id = tmp->id;
pkg->name = strdup(tmp->name);
pkg->version = strdup(tmp->version);
pkg->group = strdup(tmp->group);
pkg->filename = strdup(tmp->filename);
pkg->description = strdup(tmp->description);
list_add_tail(&pkg->list, slist);
count++;
}
};
};
return count;
@ -260,7 +254,20 @@ void print_pkg_list(list_t *list)
list_for_each_entry(pkg, list, list)
{
sprintf(conbuf,"%s-%s\n", pkg->name, pkg->version);
sprintf(conbuf,"%s-%s-%s\n", pkg->name, pkg->version, pkg->group);
con_write_asciiz(conbuf);
}
}
void process_task(list_t *task)
{
LIST_HEAD(download_list);
if(build_download_list(&download_list, task))
do_download(&download_list);
if(!list_empty(&download_list))
remove_missing_packages(task, &download_list);
do_install(task);
}