X-Git-Url: http://git.shiar.net/perl/schtarr.git/blobdiff_plain/66615c316074968c4c39fd3962ba2e7eacedd44c..da2d5c0b14bfbd8550f4d77a471c7212c17a1898:/Archive-MoPaQ/MoPaQ.xs diff --git a/Archive-MoPaQ/MoPaQ.xs b/Archive-MoPaQ/MoPaQ.xs new file mode 100644 index 0000000..4ec9358 --- /dev/null +++ b/Archive-MoPaQ/MoPaQ.xs @@ -0,0 +1,91 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include "ppport.h" + +#include "libmpq/mpq.h" + +typedef PerlIO * OutputStream; +typedef mpq_archive * Archive__MoPaQ; + + +MODULE = Archive::MoPaQ PACKAGE = Archive::MoPaQ + +Archive::MoPaQ init(package) + char *package; + CODE: + RETVAL = malloc(sizeof(mpq_archive)); + memset(RETVAL, 0, sizeof(mpq_archive)); + OUTPUT: + RETVAL + +int open(mpqa,filename) + Archive::MoPaQ mpqa; + char *filename; + CODE: + RETVAL = libmpq_archive_open(mpqa, filename); + OUTPUT: + RETVAL + +int get_size(mpqa) + Archive::MoPaQ mpqa; + CODE: + RETVAL = libmpq_archive_info(mpqa, LIBMPQ_MPQ_ARCHIVE_SIZE); + OUTPUT: + RETVAL + +int get_numfiles(mpqa) + Archive::MoPaQ mpqa; + CODE: + RETVAL = libmpq_archive_info(mpqa, LIBMPQ_MPQ_NUMFILES); + OUTPUT: + RETVAL + +int listopen(mpqa,listfile) + Archive::MoPaQ mpqa; + char* listfile; + CODE: + RETVAL = 0; + switch (libmpq_listfile_open(mpqa, listfile)) { + case LIBMPQ_CONF_EFILE_OPEN: + warn("found filelist, but could not open, so disabling listfile\n"); + break; + case LIBMPQ_CONF_EFILE_CORRUPT: + warn("found filelist with errors, so disabling listfile\n"); + break; + case LIBMPQ_CONF_EFILE_LIST_CORRUPT: + warn("found filelist, header matches %s, but filelist is corrupt.\n", mpqa->mpq_l->mpq_name); + break; + case LIBMPQ_CONF_EFILE_VERSION: + warn("found filelist, but libmpq %s is required.\n", mpqa->mpq_l->mpq_version); + break; + case LIBMPQ_CONF_EFILE_NOT_FOUND: + warn("Filelist not found"); + break; + default: +// printf("game: %s, file: %s, version: %s\n", mpqa->mpq_l->mpq_game, mpqa->mpq_l->mpq_name, mpqa->mpq_l->mpq_game_version); + RETVAL = 1; + } + OUTPUT: + RETVAL + +int extract(mpqa,nr) + Archive::MoPaQ mpqa; + int nr; + CODE: + if (libmpq_file_check(mpqa, &nr, LIBMPQ_FILE_TYPE_INT)) { + warn("file %i not found\n", nr); + } else { + RETVAL = libmpq_file_extract(mpqa, nr); + } + OUTPUT: + RETVAL + +void DESTROY(mpqa) + Archive::MoPaQ mpqa; + CODE: + libmpq_listfile_close(mpqa); + libmpq_archive_close(mpqa); + free(mpqa); +