diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Makefile | 4 | ||||
-rw-r--r-- | lib/cdabstract.cpp | 144 | ||||
-rw-r--r-- | lib/cdreader.cpp | 107 | ||||
-rw-r--r-- | lib/cdutils.cpp | 4 | ||||
-rw-r--r-- | lib/isobuilder.cpp | 1560 | ||||
-rw-r--r-- | lib/luacd.cpp | 3210 |
6 files changed, 2517 insertions, 2512 deletions
diff --git a/lib/Makefile b/lib/Makefile index a7d7fe5..750b4c1 100755 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,9 +1,9 @@ #!/usr/bin/make -f -CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -I../includes -DHAVE_ZLIB -DUSE_CDREADER -DDEBUG `baltisot-config --cflags` +CPPFLAGS=-Wall -g -O3 -mcpu=i686 -I../includes -DHAVE_ZLIB -DUSE_CDREADER -DDEBUG `baltisot-config --cflags` `lua-config --include` CXX=g++ -OBJECTS = cdutils.o lzss.o yazedc.o cdreader.o cdabstract.o mips.o +OBJECTS = cdutils.o lzss.o yazedc.o cdreader.o cdabstract.o isobuilder.o luacd.o TARGET = lib.a all: ${TARGET} diff --git a/lib/cdabstract.cpp b/lib/cdabstract.cpp index 103be1a..ff438c4 100644 --- a/lib/cdabstract.cpp +++ b/lib/cdabstract.cpp @@ -17,17 +17,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdabstract.cpp,v 1.6 2003-12-04 01:55:15 pixel Exp $ */ +/* $Id: cdabstract.cpp,v 1.7 2003-12-11 16:53:43 pixel Exp $ */ #include "cdabstract.h" #include "Input.h" #include "cdreader.h" #ifdef __linux__ -#include <unistd.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <linux/cdrom.h>
+#include <unistd.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <linux/cdrom.h> #endif #if defined (_MSC_VER) || defined (__MINGW32__) @@ -47,13 +47,13 @@ bool cdabstract::canprobe() { return true; #endif #ifdef _WIN32 - OSVERSIONINFO ov;
- memset(&ov, 0, sizeof(OSVERSIONINFO));
- ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- GetVersionEx(&ov);
-
- return ((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4));
+ OSVERSIONINFO ov; + memset(&ov, 0, sizeof(OSVERSIONINFO)); + ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + GetVersionEx(&ov); + + return ((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)); #endif return false; } @@ -94,66 +94,66 @@ std::vector<String> cdabstract::probe() throw (GeneralException) { } #ifdef _WIN32 -HANDLE cdabstract::OpenIOCTLFile(char cLetter) {
- HANDLE hF;
- char szFName[16];
- OSVERSIONINFO ov;
- DWORD dwFlags;
- DWORD dwIOCTLAttr = 0;
-
- memset(&ov, 0, sizeof(OSVERSIONINFO));
- ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&ov);
-
- if((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4))
- dwFlags = GENERIC_READ | GENERIC_WRITE; // add gen write on W2k/XP
- else dwFlags = GENERIC_READ;
-
- sprintf(szFName, "\\\\.\\%c:", cLetter);
-
- hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // open drive
- NULL, OPEN_EXISTING, dwIOCTLAttr, NULL);
-
- if (hF == INVALID_HANDLE_VALUE) { // mmm... no success?
- dwFlags ^= GENERIC_WRITE; // -> try write toggle
- hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // -> open drive again
- NULL, OPEN_EXISTING, dwIOCTLAttr, NULL);
- if (hF == INVALID_HANDLE_VALUE)
- return NULL;
- }
- return hF;
-}
-
-typedef struct {
- ULONG Length;
- UCHAR PortNumber;
- UCHAR PathId;
- UCHAR TargetId;
- UCHAR Lun;
-} SCSI_ADDRESS, *PSCSI_ADDRESS;
-
-void cdabstract::GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL) {
- char szBuf[1024];
- PSCSI_ADDRESS pSA;
- DWORD dwRet;
-
- *iDA = *iDT = *iDL = -1;
-
- if (hF == NULL)
- return;
-
- memset(szBuf,0,1024);
-
- pSA = (PSCSI_ADDRESS)szBuf;
- pSA->Length = sizeof(SCSI_ADDRESS);
-
- if (!DeviceIoControl(hF, IOCTL_SCSI_GET_ADDRESS, NULL, 0, pSA,
- sizeof(SCSI_ADDRESS), &dwRet, NULL))
- return;
-
- *iDA = pSA->PortNumber;
- *iDT = pSA->TargetId;
- *iDL = pSA->Lun;
+HANDLE cdabstract::OpenIOCTLFile(char cLetter) { + HANDLE hF; + char szFName[16]; + OSVERSIONINFO ov; + DWORD dwFlags; + DWORD dwIOCTLAttr = 0; + + memset(&ov, 0, sizeof(OSVERSIONINFO)); + ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&ov); + + if((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)) + dwFlags = GENERIC_READ | GENERIC_WRITE; // add gen write on W2k/XP + else dwFlags = GENERIC_READ; + + sprintf(szFName, "\\\\.\\%c:", cLetter); + + hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // open drive + NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); + + if (hF == INVALID_HANDLE_VALUE) { // mmm... no success? + dwFlags ^= GENERIC_WRITE; // -> try write toggle + hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // -> open drive again + NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); + if (hF == INVALID_HANDLE_VALUE) + return NULL; + } + return hF; +} + +typedef struct { + ULONG Length; + UCHAR PortNumber; + UCHAR PathId; + UCHAR TargetId; + UCHAR Lun; +} SCSI_ADDRESS, *PSCSI_ADDRESS; + +void cdabstract::GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL) { + char szBuf[1024]; + PSCSI_ADDRESS pSA; + DWORD dwRet; + + *iDA = *iDT = *iDL = -1; + + if (hF == NULL) + return; + + memset(szBuf,0,1024); + + pSA = (PSCSI_ADDRESS)szBuf; + pSA->Length = sizeof(SCSI_ADDRESS); + + if (!DeviceIoControl(hF, IOCTL_SCSI_GET_ADDRESS, NULL, 0, pSA, + sizeof(SCSI_ADDRESS), &dwRet, NULL)) + return; + + *iDA = pSA->PortNumber; + *iDT = pSA->TargetId; + *iDL = pSA->Lun; } #endif diff --git a/lib/cdreader.cpp b/lib/cdreader.cpp index cfe91b3..058dddc 100644 --- a/lib/cdreader.cpp +++ b/lib/cdreader.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdreader.cpp,v 1.16 2003-12-04 01:47:37 pixel Exp $ */ +/* $Id: cdreader.cpp,v 1.17 2003-12-11 16:53:43 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -191,6 +191,7 @@ void cdreader::introduce(Byte * datas, int n) { cdreader::cdreader(const String & no) throw (GeneralException) : Handle(open(no.to_charp(), O_RDONLY)), n(no), sector(0) { + int i; #ifdef DEBUG printm(M_ERROR, "Opening cdrom device " + no + "\n"); @@ -214,7 +215,9 @@ cdreader::cdreader(const String & no) throw (GeneralException) : nsectors = 0; } -cdreader::cdreader(const cdreader & i) : Handle(i), n(i.n) { +cdreader::cdreader(const cdreader & inp) : Handle(inp), n(inp.n) { + int i; + for (i = 0; i < 400000; i++) { sectors[i] = 0; } @@ -271,62 +274,62 @@ void cdreader::close() throw (GeneralException) { CloseHandle(hFile); } -typedef enum _TRACK_MODE_TYPE {
- YellowMode2,
- XAForm2,
- CDDA
-} TRACK_MODE_TYPE, *PTRACK_MODE_TYPE;
+typedef enum _TRACK_MODE_TYPE { + YellowMode2, + XAForm2, + CDDA +} TRACK_MODE_TYPE, *PTRACK_MODE_TYPE; -typedef struct _RAW_READ_INFO {
- LARGE_INTEGER DiskOffset;
- ULONG SectorCount;
- TRACK_MODE_TYPE TrackMode;
+typedef struct _RAW_READ_INFO { + LARGE_INTEGER DiskOffset; + ULONG SectorCount; + TRACK_MODE_TYPE TrackMode; } RAW_READ_INFO, *PRAW_READ_INFO; void cdreader::getsector(void *buf, int sec, int nb) throw (GeneralException) { - RAW_READ_INFO rawIOCTL;
- DWORD dwRet;
- BOOL bStat;
- bool done = false;
+ RAW_READ_INFO rawIOCTL; + DWORD dwRet; + BOOL bStat; + bool done = false; if (sec >= 0) sector = sec; -
- rawIOCTL.DiskOffset.QuadPart = sector * 2048;
- rawIOCTL.SectorCount = nb;
- rawIOCTL.TrackMode = YellowMode2;
-
- while (!done) {
- SetLastError(0);
- bStat = DeviceIoControl(hFile, IOCTL_CDROM_RAW_READ,
- &rawIOCTL, sizeof(RAW_READ_INFO),
- buf, 2352 * nb, &dwRet, NULL);
- if (!bStat) {
- DWORD dwErrCode = GetLastError();
- if (dwErrCode == ERROR_INVALID_FUNCTION) {
- if (rawIOCTL.TrackMode == YellowMode2) {
- rawIOCTL.TrackMode = XAForm2;
- continue;
- }
- }
- if (dwErrCode != ERROR_IO_PENDING) {
- LPVOID lpMsgBuf;
- if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf, 0, NULL ))
- throw GeneralException("Gave up on reading CD: unknown error");
- String errmsg = (LPCTSTR) lpMsgBuf;
- LocalFree(lpMsgBuf);
- throw GeneralException("Gave up on reading CD: " + errmsg);
- }
- } else {
- done = true;
- }
- }
-
- sector += nb;
+ + rawIOCTL.DiskOffset.QuadPart = sector * 2048; + rawIOCTL.SectorCount = nb; + rawIOCTL.TrackMode = YellowMode2; + + while (!done) { + SetLastError(0); + bStat = DeviceIoControl(hFile, IOCTL_CDROM_RAW_READ, + &rawIOCTL, sizeof(RAW_READ_INFO), + buf, 2352 * nb, &dwRet, NULL); + if (!bStat) { + DWORD dwErrCode = GetLastError(); + if (dwErrCode == ERROR_INVALID_FUNCTION) { + if (rawIOCTL.TrackMode == YellowMode2) { + rawIOCTL.TrackMode = XAForm2; + continue; + } + } + if (dwErrCode != ERROR_IO_PENDING) { + LPVOID lpMsgBuf; + if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, 0, NULL )) + throw GeneralException("Gave up on reading CD: unknown error"); + String errmsg = (LPCTSTR) lpMsgBuf; + LocalFree(lpMsgBuf); + throw GeneralException("Gave up on reading CD: " + errmsg); + } + } else { + done = true; + } + } + + sector += nb; } #endif diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 685d0f1..82e460a 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdutils.cpp,v 1.18 2003-12-10 02:59:31 pixel Exp $ */ +/* $Id: cdutils.cpp,v 1.19 2003-12-11 16:53:43 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -834,7 +834,7 @@ cdfile::~cdfile() { ssize_t cdfile::read(void *buf, size_t count) throw (GeneralException) { Byte buffer[2352]; - size_t startsec, nsec, startbyte, nstartbytes; + size_t startsec, startbyte, nstartbytes; count = MIN(count, (size_t) (size - itell)); diff --git a/lib/isobuilder.cpp b/lib/isobuilder.cpp index d267063..f8d8bfa 100644 --- a/lib/isobuilder.cpp +++ b/lib/isobuilder.cpp @@ -17,320 +17,320 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: isobuilder.cpp,v 1.8 2003-12-10 02:59:32 pixel Exp $ */ - -#include "isobuilder.h"
-
-void isobuilder::Date::dump(Byte * datas) {
- char pbuf[256];
-
- sprintf(pbuf, "%04i", year);
- memcpy(datas + 0, pbuf, 4);
- sprintf(pbuf, "%02i", month);
- memcpy(datas + 4, pbuf, 2);
- sprintf(pbuf, "%02i", day);
- memcpy(datas + 6, pbuf, 2);
- sprintf(pbuf, "%02i", hour);
- memcpy(datas + 8, pbuf, 2);
- sprintf(pbuf, "%02i", minute);
- memcpy(datas + 10, pbuf, 2);
- sprintf(pbuf, "%02i", second);
- memcpy(datas + 12, pbuf, 2);
- sprintf(pbuf, "%02i", hundredths);
- memcpy(datas + 14, pbuf, 2);
-
- *((char *) (datas + 16)) = offset;
-}
-
-isobuilder::Date::Date(int) {
- year = month = day = hour = minute = second = hundredths = offset = 0;
-}
-
-isobuilder::Date::Date(Byte * datas) {
- char pbuf[256];
- char * cdatas = (char *) datas;
-
- memcpy(pbuf, cdatas + 0, 4);
- pbuf[4] = 0;
- sscanf(pbuf, "%d", &year);
-
- memcpy(pbuf, cdatas + 4, 2);
- pbuf[2] = 0;
- sscanf(pbuf, "%d", &month);
-
- memcpy(pbuf, cdatas + 6, 2);
- pbuf[2] = 0;
- sscanf(pbuf, "%d", &day);
-
- memcpy(pbuf, cdatas + 8, 2);
- pbuf[2] = 0;
- sscanf(pbuf, "%d", &hour);
-
- memcpy(pbuf, cdatas + 10, 2);
- pbuf[2] = 0;
- sscanf(pbuf, "%d", &minute);
-
- memcpy(pbuf, cdatas + 12, 2);
- pbuf[2] = 0;
- sscanf(pbuf, "%d", &second);
-
- memcpy(pbuf, cdatas + 14, 2);
- pbuf[2] = 0;
- sscanf(pbuf, "%d", &hundredths);
-
- offset = *(cdatas + 16);
-}
-
-isobuilder::DirTree::DirTree(isobuilder::DirTree * _father, bool _dir) : father(_father), mode(-1), dir(_dir) {
- DirTree * p;
-
- child = brother = 0;
-
- if (!father)
- return;
-
- creation = father->creation;
-
- if (father->child) {
- for (p = father->child; p->brother; p = p->brother);
- p->brother = this;
- } else {
- father->child = this;
- }
-}
-
-isobuilder::DirTree::~DirTree() {
- while (child) {
- delete child;
- }
-
- if (!father)
- return;
-
- if (father->child == this) {
- father->child = brother;
- } else {
- // Dirty, should not happen.
- DirTree * p;
- for (p = father->child; p->brother != this; p = p->brother);
- p->brother = brother;
- }
-}
-
-void isobuilder::DirTree::dumpdirs(isobuilder * builder) throw (GeneralException) {
- Byte * dir, * odir;
- int cursiz, cursectsize, R;
- String oldname;
- DirTree * p;
-
- odir = dir = (Byte *) malloc(cursiz = size);
- cursectsize = 2048;
-
- oldname = name;
- name = ".";
- R = buildentry(dir, cursectsize);
- name = oldname;
- cursectsize -= R;
- dir += R;
-
- if (father) {
- oldname = father->name;
- father->name = "..";
- R = father->buildentry(dir, cursectsize);
- father->name = oldname;
- } else {
- name = "..";
- R = buildentry(dir, cursectsize);
- name = ".";
- }
-
- cursectsize -= R;
- dir += R;
-
- for (p = child; p; p = p->brother) {
- if (p->dir) {
- p->dumpdirs(builder);
- }
- if (p->hardhide)
- continue;
- while (!(R = p->buildentry(dir, cursectsize))) {
- cursiz -= 2048;
- dir += cursectsize;
- cursectsize = 2048;
- if (!cursiz)
- throw GeneralException("Directory is too small! Entries don't fit.");
- }
- cursectsize -= R;
- dir += R;
- }
-
- builder->putdatas(odir, size, mode, sector);
-
- free(odir);
-}
-
-int isobuilder::DirTree::buildpath(Byte * datas, int size, bool bigendian) throw (GeneralException) {
- int N, r, tr;
- Uint16 pn;
- char pbuf[256], pad;
-
- if (!dir) {
- if (brother) {
- return brother->buildpath(datas, size, bigendian);
- } else {
- return 0;
- }
- }
-
- if (!father) {
- numerate(1);
- N = 1;
- pbuf[0] = 0;
- pn = 1;
- } else {
- N = name.strlen();
- strcpy(pbuf, name.to_charp());
- pn = father->node;
- }
-
- pad = N & 1;
- size -= (r = N + pad + 8);
-
- if (size < 0)
- throw GeneralException("Path table too small.");
-
- datas[0] = N;
- datas[1] = 0;
- *((Uint32 *) (datas + 2)) = bigendian ? cdutils::swap_dword(sector) : sector;
- *((Uint16 *) (datas + 6)) = bigendian ? cdutils::swap_word(pn) : pn;
- memcpy(datas + 8, pbuf, N);
- if (pad)
- datas[8 + N] = 0;
-
- datas += r;
-
- if (brother) {
- tr = brother->buildpath(datas, size, bigendian);
- r += tr;
- size -= tr;
- datas += tr;
- }
-
- if (child) {
- tr = child->buildpath(datas, size, bigendian);
- r += tr;
- size -= tr;
- datas += tr;
- }
-
- return r;
-}
-
-int isobuilder::DirTree::buildentry(Byte * buffer, int spaceleft, bool put_xa) {
- int N, R;
- char pbuf[256], pad;
- Byte * p;
- cdutils::DirEntry * d = (cdutils::DirEntry *) buffer;
-
- put_xa = put_xa && have_xa;
-
- memset(pbuf, 0, 256);
-
- if (name == ".") {
- N = 1;
- pbuf[0] = 0;
- } else if (name == "..") {
- N = 1;
- pbuf[0] = 1;
- } else {
- strcpy(pbuf, name.to_charp());
- N = name.strlen();
- if (!dir) {
- N += 2;
- strcat(pbuf, ";1");
- }
- }
-
- R = N + 33;
-
- if (R & 1) {
- R++;
- pad = 1;
- } else {
- pad = 0;
- }
-
- if (put_xa) {
- R += 14;
- p = (Byte *) pbuf + N + pad;
- p[4] = 0x05;
- p[5] = 0x55;
- p[6] = 'X';
- p[7] = 'A';
-
- p[4] |= xa_dir ? 0x80 : 0;
- p[4] |= xa_audio ? 0x40 : 0;
- p[4] |= xa_str ? 0x20 : 0;
- p[4] |= xa_xa ? 0x10 : 0;
- p[4] |= xa_form1 ? 0x08 : 0;
- }
-
- if (R > spaceleft) {
- return 0;
- }
-
- memset(d, 0, R);
-
- d->R = R;
- d->N = N;
- memcpy(d->id, pbuf, N + pad + (put_xa ? 14 : 0));
-
- d->Sector = sector;
- d->BESector = cdutils::swap_dword(sector);
- d->Size = size;
- d->BESize = cdutils::swap_dword(size);
- d->Year = creation.year - 1900;
- d->Month = creation.month;
- d->Day = creation.day;
- d->Hour = creation.hour;
- d->Minute = creation.minute;
- d->Second = creation.second;
- d->Offset = creation.offset;
- d->Flags |= hidden ? 1 : 0;
- d->Flags |= dir ? 2 : 0;
-
- return R;
-}
-
-void isobuilder::DirTree::fromdir(cdutils::DirEntry * d) {
- Date t;
+/* $Id: isobuilder.cpp,v 1.9 2003-12-11 16:53:43 pixel Exp $ */ + +#include "isobuilder.h" + +void isobuilder::Date::dump(Byte * datas) { + char pbuf[256]; + + sprintf(pbuf, "%04i", year); + memcpy(datas + 0, pbuf, 4); + sprintf(pbuf, "%02i", month); + memcpy(datas + 4, pbuf, 2); + sprintf(pbuf, "%02i", day); + memcpy(datas + 6, pbuf, 2); + sprintf(pbuf, "%02i", hour); + memcpy(datas + 8, pbuf, 2); + sprintf(pbuf, "%02i", minute); + memcpy(datas + 10, pbuf, 2); + sprintf(pbuf, "%02i", second); + memcpy(datas + 12, pbuf, 2); + sprintf(pbuf, "%02i", hundredths); + memcpy(datas + 14, pbuf, 2); + + *((char *) (datas + 16)) = offset; +} + +isobuilder::Date::Date(int) { + year = month = day = hour = minute = second = hundredths = offset = 0; +} + +isobuilder::Date::Date(Byte * datas) { + char pbuf[256]; + char * cdatas = (char *) datas; + + memcpy(pbuf, cdatas + 0, 4); + pbuf[4] = 0; + sscanf(pbuf, "%d", &year); + + memcpy(pbuf, cdatas + 4, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &month); + + memcpy(pbuf, cdatas + 6, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &day); + + memcpy(pbuf, cdatas + 8, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &hour); + + memcpy(pbuf, cdatas + 10, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &minute); + + memcpy(pbuf, cdatas + 12, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &second); + + memcpy(pbuf, cdatas + 14, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &hundredths); + + offset = *(cdatas + 16); +} + +isobuilder::DirTree::DirTree(isobuilder::DirTree * _father, bool _dir) : mode(-1), father(_father), dir(_dir) { + DirTree * p; + + child = brother = 0; + + if (!father) + return; + + creation = father->creation; + + if (father->child) { + for (p = father->child; p->brother; p = p->brother); + p->brother = this; + } else { + father->child = this; + } +} + +isobuilder::DirTree::~DirTree() { + while (child) { + delete child; + } + + if (!father) + return; + + if (father->child == this) { + father->child = brother; + } else { + // Dirty, should not happen. + DirTree * p; + for (p = father->child; p->brother != this; p = p->brother); + p->brother = brother; + } +} + +void isobuilder::DirTree::dumpdirs(isobuilder * builder) throw (GeneralException) { + Byte * dir, * odir; + int cursiz, cursectsize, R; + String oldname; + DirTree * p; + + odir = dir = (Byte *) malloc(cursiz = size); + cursectsize = 2048; + + oldname = name; + name = "."; + R = buildentry(dir, cursectsize); + name = oldname; + cursectsize -= R; + dir += R; + + if (father) { + oldname = father->name; + father->name = ".."; + R = father->buildentry(dir, cursectsize); + father->name = oldname; + } else { + name = ".."; + R = buildentry(dir, cursectsize); + name = "."; + } + + cursectsize -= R; + dir += R; + + for (p = child; p; p = p->brother) { + if (p->dir) { + p->dumpdirs(builder); + } + if (p->hardhide) + continue; + while (!(R = p->buildentry(dir, cursectsize))) { + cursiz -= 2048; + dir += cursectsize; + cursectsize = 2048; + if (!cursiz) + throw GeneralException("Directory is too small! Entries don't fit."); + } + cursectsize -= R; + dir += R; + } + + builder->putdatas(odir, size, mode, sector); + + free(odir); +} + +int isobuilder::DirTree::buildpath(Byte * datas, int size, bool bigendian) throw (GeneralException) { + int N, r, tr; + Uint16 pn; + char pbuf[256], pad; + + if (!dir) { + if (brother) { + return brother->buildpath(datas, size, bigendian); + } else { + return 0; + } + } + + if (!father) { + numerate(1); + N = 1; + pbuf[0] = 0; + pn = 1; + } else { + N = name.strlen(); + strcpy(pbuf, name.to_charp()); + pn = father->node; + } + + pad = N & 1; + size -= (r = N + pad + 8); + + if (size < 0) + throw GeneralException("Path table too small."); + + datas[0] = N; + datas[1] = 0; + *((Uint32 *) (datas + 2)) = bigendian ? cdutils::swap_dword(sector) : sector; + *((Uint16 *) (datas + 6)) = bigendian ? cdutils::swap_word(pn) : pn; + memcpy(datas + 8, pbuf, N); + if (pad) + datas[8 + N] = 0; + + datas += r; + + if (brother) { + tr = brother->buildpath(datas, size, bigendian); + r += tr; + size -= tr; + datas += tr; + } + + if (child) { + tr = child->buildpath(datas, size, bigendian); + r += tr; + size -= tr; + datas += tr; + } + + return r; +} + +int isobuilder::DirTree::buildentry(Byte * buffer, int spaceleft, bool put_xa) { + int N, R; + char pbuf[256], pad; + Byte * p; + cdutils::DirEntry * d = (cdutils::DirEntry *) buffer; + + put_xa = put_xa && have_xa; + + memset(pbuf, 0, 256); + + if (name == ".") { + N = 1; + pbuf[0] = 0; + } else if (name == "..") { + N = 1; + pbuf[0] = 1; + } else { + strcpy(pbuf, name.to_charp()); + N = name.strlen(); + if (!dir) { + N += 2; + strcat(pbuf, ";1"); + } + } + + R = N + 33; + + if (R & 1) { + R++; + pad = 1; + } else { + pad = 0; + } + + if (put_xa) { + R += 14; + p = (Byte *) pbuf + N + pad; + p[4] = 0x05; + p[5] = 0x55; + p[6] = 'X'; + p[7] = 'A'; + + p[4] |= xa_dir ? 0x80 : 0; + p[4] |= xa_audio ? 0x40 : 0; + p[4] |= xa_str ? 0x20 : 0; + p[4] |= xa_xa ? 0x10 : 0; + p[4] |= xa_form1 ? 0x08 : 0; + } + + if (R > spaceleft) { + return 0; + } + + memset(d, 0, R); + + d->R = R; + d->N = N; + memcpy(d->id, pbuf, N + pad + (put_xa ? 14 : 0)); + + d->Sector = sector; + d->BESector = cdutils::swap_dword(sector); + d->Size = size; + d->BESize = cdutils::swap_dword(size); + d->Year = creation.year - 1900; + d->Month = creation.month; + d->Day = creation.day; + d->Hour = creation.hour; + d->Minute = creation.minute; + d->Second = creation.second; + d->Offset = creation.offset; + d->Flags |= hidden ? 1 : 0; + d->Flags |= dir ? 2 : 0; + + return R; +} + +void isobuilder::DirTree::fromdir(cdutils::DirEntry * d) { + Date t; char pbuf[200], pad; int s; if ((!d) || (!d->R)) { return; } -
- if ((d->N == 1) && (d->id[0] == 0)) {
- name = ".";
- } else if ((d->N == 1) && (d->id[0] == 1)) {
- name = "..";
- } else {
- memcpy(pbuf, d->id, s = (d->N - ((d->Flags & 2) ? 0 : 2)));
- pbuf[s] = 0;
- name = pbuf;
- }
- hidden = d->Flags & 1;
+ + if ((d->N == 1) && (d->id[0] == 0)) { + name = "."; + } else if ((d->N == 1) && (d->id[0] == 1)) { + name = ".."; + } else { + memcpy(pbuf, d->id, s = (d->N - ((d->Flags & 2) ? 0 : 2))); + pbuf[s] = 0; + name = pbuf; + } + hidden = d->Flags & 1; if (d->Year < 70) - d->Year += 100;
- t.year = d->Year;
- t.month = d->Month;
- t.day = d->Day;
- t.hour = d->Hour;
- t.second = d->Second;
- t.hundredths = 0;
- t.offset = d->Offset;
- creation = t;
-
+ d->Year += 100; + t.year = d->Year; + t.month = d->Month; + t.day = d->Day; + t.hour = d->Hour; + t.second = d->Second; + t.hundredths = 0; + t.offset = d->Offset; + creation = t; + s = 33 + d->N; if (s & 1) { s++; @@ -351,386 +351,388 @@ void isobuilder::DirTree::fromdir(cdutils::DirEntry * d) { xa_form1 = p[4] & 0x08; } } - }
-}
-
-bool isobuilder::DirTree::isdir() {
- return dir;
-}
-
-void isobuilder::DirTree::setbasicsxa() {
- have_xa = true;
- if (dir)
- xa_dir = true;
- xa_form1 = true;
-}
-
-int isobuilder::DirTree::numerate(int n) {
- DirTree * p;
-
- if (!dir) {
- if (brother) {
- return brother->numerate(n);
- } else {
- return n;
- }
- }
-
- node = n++;
-
- if (brother)
- n = brother->numerate(n);
-
- if (child)
- n = child->numerate(n);
-
- return n;
-}
-
-isobuilder::DirTree * isobuilder::DirTree::Father() {
- return father;
-}
-
-isobuilder::DirTree * isobuilder::DirTree::Brother() {
- return brother;
-}
-
-isobuilder::DirTree * isobuilder::DirTree::Child() {
- return child;
-}
-
-isobuilder::DirTree * isobuilder::DirTree::Find(const String & _name) {
- DirTree * p = 0;
-
- if (name == _name)
- return this;
-
- if (brother)
- p = brother->Find(_name);
-
- if (!p && child)
- return child->Find(_name);
-
- return p;
-}
-
-isobuilder::isobuilder(Handle * _w, int _mode) : w(_w), sector(0), nsectors(0), basics(false), dmode(_mode) {
- Byte sect[2352];
- memset(sect, 0, 2352);
-
- for (int i = 0; i < 16; i++) {
- createsector(sect, MODE2, i);
- }
-}
-
-isobuilder::~isobuilder() {
- if (!closed)
- close();
- if (root)
- delete root;
-}
-
-void isobuilder::foreword(cdutils * cd) {
- Byte sect[2352];
- for (int i = 0; i < 16; i++) {
- cd->read_sector(sect, MODE_RAW, i);
- createsector(sect, MODE_RAW, i);
- }
-}
-
-void isobuilder::foreword(Handle * forewords, int mode) {
- Byte sect[2352];
- for (int i = 0; i < 16; i++) {
- forewords->read(sect, sec_sizes[mode]);
- createsector(sect, mode, i);
- }
-}
-
-void isobuilder::foreword(Byte * forewords, int mode) {
- for (int i = 0; i < 16; i++) {
- createsector(forewords + i * sec_sizes[mode], mode, i);
- }
-}
-
-int isobuilder::getdispsect() {
- return lastdispsect;
-}
-
-int isobuilder::putfile(Handle * file, int mode, int n) {
- Byte datas[2352];
- size_t filesize;
- int fsect;
-
- if (mode < 0)
- mode = dmode;
-
- if (n >= 0) {
- sector = n;
- } else {
- sector = lastdispsect;
- }
-
- fsect = sector;
-
- filesize = file->GetSize();
-
- while (filesize > 0) {
- memset(datas, 0, 2352);
- filesize -= file->read(datas, sec_sizes[mode]);
- if ((mode == MODE2_FORM1) || (mode == MODE2_FORM2)) {
- if (filesize) {
- clearEOF();
- } else {
- setEOF();
- }
- }
- createsector(datas, mode);
- }
-
- return fsect;
-}
-
-int isobuilder::putdatas(Byte * _datas, size_t size, int smode, int n) {
- Byte datas[2352];
- size_t eating;
- int dsect;
- if (n >= 0) {
- sector = n;
- } else {
- sector = lastdispsect;
- }
-
- dsect = sector;
-
- if (smode < 0)
- smode = dmode;
-
- while (size > 0) {
- memset(datas, 0, 2352);
- eating = MIN(size, (size_t) sec_sizes[smode]);
- memcpy(datas, _datas, eating);
- size -= eating;
- _datas += eating;
- if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) {
- if (size) {
- clearEOF();
- } else {
- setEOF();
- }
- }
- createsector(datas, smode);
- }
-
- return dsect;
-}
-
-int isobuilder::createsector(Byte * datas, int smode, int n) {
- Byte dsector[2352];
- int rsector;
- if (n >= 0)
- sector = n;
-
- if (smode < 0)
- smode = dmode;
-
- rsector = sector;
-
- w->seek(2352 * sector, SEEK_SET);
-
- memcpy(dsector + sec_offsts[smode], datas, sec_sizes[smode]);
-
- if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) {
- // Mode 2 Form 2 would be odd, but well....
- dsector[16] = dsector[20] = 0; // File Number
- dsector[17] = dsector[21] = 0; // Channel Number
- dsector[18] = dsector[22] = sub_EOR | sub_EOF | 8 |
- (smode == MODE2_FORM2 ? 32 : 0);
- dsector[19] = dsector[23] = 0;
- }
-
- if (smode != MODE_RAW) {
- sector += 150;
- yazedc_o.minute = cdutils::to_BCD(sector / 60 / 75);
- yazedc_o.second = cdutils::to_BCD((sector / 75) % 60);
- yazedc_o.frame = cdutils::to_BCD(sector % 75);
- sector -= 150;
- yazedc_o.do_encode_L2(dsector, smode, 0);
- }
-
- w->write(dsector, 2352);
-
- sector++;
-
- nsectors = MAX(nsectors, sector);
- lastdispsect = MAX(lastdispsect, sector);
-
- return rsector;
-}
-
-void isobuilder::setEOF() {
- sub_EOF = 128;
- sub_EOR = 1;
-}
-
-void isobuilder::clearEOF() {
- sub_EOF = sub_EOR = 0;
-}
-
-isobuilder::DirTree * isobuilder::setbasics(PVD _pvd, int _rootsize, int _ptsize, int _nvd, int _rootsect) throw (GeneralException) {
- if (basics) {
- throw GeneralException("Basic ISO structures already set");
- }
- basics = true;
-
- pvd = _pvd;
- rootsize = _rootsize;
- ptsize = _ptsize;
- nvd = _nvd;
-
- ptsect = 17 + nvd;
- rootsect = ptsect + ptsize * 4;
- if (_rootsect >= 0)
- rootsect = _rootsect;
- lastdispsect = rootsect + rootsize;
-
- root = new DirTree(0);
- root->name = ".";
- root->creation = pvd.volcreat;
- root->sector = rootsect;
- root->size = rootsize * 2048;
- return root;
-}
-
-isobuilder::DirTree * isobuilder::createdir(DirTree * p, const String & _name, int size, cdutils::DirEntry * d, int mode) throw (GeneralException) {
- DirTree * r;
-
- if (!p)
- throw GeneralException("Empty father");
-
- if (closed)
- throw GeneralException("ISO is closed");
-
- if (!basics)
- throw GeneralException("ISO basis not created (no root!)");
-
- r = new DirTree(p);
-
- r->creation = p->creation;
- if (d)
- r->fromdir(d);
- if (_name != "")
- r->name = _name;
- r->size = size * 2048;
- if (!r->size)
- r->size = d->Size;
- r->sector = lastdispsect;
- if (mode >= 0)
- r->mode = mode;
- else
- r->mode = dmode;
-
- lastdispsect += size;
-
- return r;
-}
-
-isobuilder::DirTree * isobuilder::createfile(DirTree * p, Handle * file, const String & _name, cdutils::DirEntry * d, int mode) throw (GeneralException) {
- DirTree * r;
-
- if (!p)
- throw GeneralException("Empty father");
-
- if (closed)
- throw GeneralException("ISO is closed");
-
- if (!basics)
- throw GeneralException("ISO basis not created (no root!)");
-
- r = new DirTree(p, false);
-
- r->name = _name;
- r->creation = p->creation;
- r->fromdir(d);
- if (_name != "")
- r->name = _name;
- r->size = file->GetSize();
- r->sector = putfile(file, mode);
- if (mode >= 0)
- r->mode = mode;
- else
- r->mode = dmode;
-}
-
-void isobuilder::copydir(isobuilder::DirTree * r, cdutils * cd, cdutils::DirEntry * d, int mode) {
- Byte datas[2048];
- cdutils::DirEntry * p;
- int nsectors = d->Size / 2048, ssize, c = 0;
- int fsize, osize;
-
- if (mode < 0)
- mode = dmode;
-
- while (nsectors) {
- cd->read_sector(datas, mode, d->Sector + c++);
- nsectors--;
- p = (cdutils::DirEntry *) datas;
- ssize = 2048;
- while ((ssize) && (p->R)) {
- ssize -= p->R;
- char pbuf[256];
- memcpy(pbuf, p->id, p->N);
- pbuf[p->N] = 0;
- if (p->Flags & 2) {
- if (!((p->N == 1) && ((p->id[0] == 0) || (p->id[0] == 1))))
- copydir(createdir(r, "", p->Size / 2048, p, mode), cd, p, mode);
- } else {
- printm(M_INFO, "Dupping %s\n", pbuf);
- int fmode;
- if (mode == MODE1) {
- fmode = mode;
- } else {
- fmode = MODE2_FORM1;
- osize = fsize = p->Size;
- int s, pad;
- s = 33 + p->N;
- if (s & 1) {
- s++;
- pad = 1;
- } else {
- pad = 0;
- }
- if ((s != p->R) && ((s + 14) == p->R)) {
- if (!(p->id[p->N + pad + 4] & 8)) {
- fmode = MODE2;
- fsize = (p->Size / 2048) * 2336;
- }
- }
- }
- p->Size = fsize;
- createfile(r, &cdfile(cd, p, fmode), "", p, fmode)->size = osize;
- p->Size = osize;
- }
- p = (cdutils::DirEntry *) (((Byte *) p) + p->R);
- }
- }
-}
-
-isobuilder::PVD isobuilder::createpvd(Handle * f) {
- Byte datas[2048];
- f->read(datas, 2048);
- return createpvd(datas);
-}
-
-isobuilder::PVD isobuilder::createpvd(cdutils * cd) {
- Byte datas[2048];
- cd->read_sector(datas, GUESS, 16);
- return createpvd(datas);
-}
-
-isobuilder::PVD isobuilder::createpvd(Byte * buffer) {
- PVD r;
- char pbuff[256];
-
+ } +} + +bool isobuilder::DirTree::isdir() { + return dir; +} + +void isobuilder::DirTree::setbasicsxa() { + have_xa = true; + if (dir) + xa_dir = true; + xa_form1 = true; +} + +int isobuilder::DirTree::numerate(int n) { + if (!dir) { + if (brother) { + return brother->numerate(n); + } else { + return n; + } + } + + node = n++; + + if (brother) + n = brother->numerate(n); + + if (child) + n = child->numerate(n); + + return n; +} + +isobuilder::DirTree * isobuilder::DirTree::Father() { + return father; +} + +isobuilder::DirTree * isobuilder::DirTree::Brother() { + return brother; +} + +isobuilder::DirTree * isobuilder::DirTree::Child() { + return child; +} + +isobuilder::DirTree * isobuilder::DirTree::Find(const String & _name) { + DirTree * p = 0; + + if (name == _name) + return this; + + if (brother) + p = brother->Find(_name); + + if (!p && child) + return child->Find(_name); + + return p; +} + +isobuilder::isobuilder(Handle * _w, int _mode) : w(_w), sector(0), nsectors(0), basics(false), dmode(_mode) { + Byte sect[2352]; + memset(sect, 0, 2352); + + for (int i = 0; i < 16; i++) { + createsector(sect, MODE2, i); + } +} + +isobuilder::~isobuilder() { + if (!closed) + close(); + if (root) + delete root; +} + +void isobuilder::foreword(cdutils * cd) { + Byte sect[2352]; + for (int i = 0; i < 16; i++) { + cd->read_sector(sect, MODE_RAW, i); + createsector(sect, MODE_RAW, i); + } +} + +void isobuilder::foreword(Handle * forewords, int mode) { + Byte sect[2352]; + for (int i = 0; i < 16; i++) { + forewords->read(sect, sec_sizes[mode]); + createsector(sect, mode, i); + } +} + +void isobuilder::foreword(Byte * forewords, int mode) { + for (int i = 0; i < 16; i++) { + createsector(forewords + i * sec_sizes[mode], mode, i); + } +} + +int isobuilder::getdispsect() { + return lastdispsect; +} + +int isobuilder::putfile(Handle * file, int mode, int n) { + Byte datas[2352]; + size_t filesize; + int fsect; + + if (mode < 0) + mode = dmode; + + if (n >= 0) { + sector = n; + } else { + sector = lastdispsect; + } + + fsect = sector; + + filesize = file->GetSize(); + + while (filesize > 0) { + memset(datas, 0, 2352); + filesize -= file->read(datas, sec_sizes[mode]); + if ((mode == MODE2_FORM1) || (mode == MODE2_FORM2)) { + if (filesize) { + clearEOF(); + } else { + setEOF(); + } + } + createsector(datas, mode); + } + + return fsect; +} + +int isobuilder::putdatas(Byte * _datas, size_t size, int smode, int n) { + Byte datas[2352]; + size_t eating; + int dsect; + if (n >= 0) { + sector = n; + } else { + sector = lastdispsect; + } + + dsect = sector; + + if (smode < 0) + smode = dmode; + + while (size > 0) { + memset(datas, 0, 2352); + eating = MIN(size, (size_t) sec_sizes[smode]); + memcpy(datas, _datas, eating); + size -= eating; + _datas += eating; + if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) { + if (size) { + clearEOF(); + } else { + setEOF(); + } + } + createsector(datas, smode); + } + + return dsect; +} + +int isobuilder::createsector(Byte * datas, int smode, int n) { + Byte dsector[2352]; + int rsector; + if (n >= 0) + sector = n; + + if (smode < 0) + smode = dmode; + + rsector = sector; + + w->seek(2352 * sector, SEEK_SET); + + memcpy(dsector + sec_offsts[smode], datas, sec_sizes[smode]); + + if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) { + // Mode 2 Form 2 would be odd, but well.... + dsector[16] = dsector[20] = 0; // File Number + dsector[17] = dsector[21] = 0; // Channel Number + dsector[18] = dsector[22] = sub_EOR | sub_EOF | 8 | + (smode == MODE2_FORM2 ? 32 : 0); + dsector[19] = dsector[23] = 0; + } + + if (smode != MODE_RAW) { + sector += 150; + yazedc_o.minute = cdutils::to_BCD(sector / 60 / 75); + yazedc_o.second = cdutils::to_BCD((sector / 75) % 60); + yazedc_o.frame = cdutils::to_BCD(sector % 75); + sector -= 150; + yazedc_o.do_encode_L2(dsector, smode, 0); + } + + w->write(dsector, 2352); + + sector++; + + nsectors = MAX(nsectors, sector); + lastdispsect = MAX(lastdispsect, sector); + + return rsector; +} + +void isobuilder::setEOF() { + sub_EOF = 128; + sub_EOR = 1; +} + +void isobuilder::clearEOF() { + sub_EOF = sub_EOR = 0; +} + +isobuilder::DirTree * isobuilder::setbasics(PVD _pvd, int _rootsize, int _ptsize, int _nvd, int _rootsect) throw (GeneralException) { + if (basics) { + throw GeneralException("Basic ISO structures already set"); + } + basics = true; + + pvd = _pvd; + rootsize = _rootsize; + ptsize = _ptsize; + nvd = _nvd; + + ptsect = 17 + nvd; + rootsect = ptsect + ptsize * 4; + if (_rootsect >= 0) + rootsect = _rootsect; + lastdispsect = rootsect + rootsize; + + root = new DirTree(0); + root->name = "."; + root->creation = pvd.volcreat; + root->sector = rootsect; + root->size = rootsize * 2048; + return root; +} + +isobuilder::DirTree * isobuilder::createdir(DirTree * p, const String & _name, int size, cdutils::DirEntry * d, int mode) throw (GeneralException) { + DirTree * r; + + if (!p) + throw GeneralException("Empty father"); + + if (closed) + throw GeneralException("ISO is closed"); + + if (!basics) + throw GeneralException("ISO basis not created (no root!)"); + + r = new DirTree(p); + + r->creation = p->creation; + if (d) + r->fromdir(d); + if (_name != "") + r->name = _name; + r->size = size * 2048; + if (!r->size) + r->size = d->Size; + r->sector = lastdispsect; + if (mode >= 0) + r->mode = mode; + else + r->mode = dmode; + + lastdispsect += size; + + return r; +} + +isobuilder::DirTree * isobuilder::createfile(DirTree * p, Handle * file, const String & _name, cdutils::DirEntry * d, int mode) throw (GeneralException) { + DirTree * r; + + if (!p) + throw GeneralException("Empty father"); + + if (closed) + throw GeneralException("ISO is closed"); + + if (!basics) + throw GeneralException("ISO basis not created (no root!)"); + + r = new DirTree(p, false); + + r->name = _name; + r->creation = p->creation; + r->fromdir(d); + if (_name != "") + r->name = _name; + r->size = file->GetSize(); + r->sector = putfile(file, mode); + if (mode >= 0) + r->mode = mode; + else + r->mode = dmode; + + return r; +} + +void isobuilder::copydir(isobuilder::DirTree * r, cdutils * cd, cdutils::DirEntry * d, int mode) { + Byte datas[2048]; + cdutils::DirEntry * p; + int nsectors = d->Size / 2048, ssize, c = 0; + int fsize, osize; + + if (mode < 0) + mode = dmode; + + while (nsectors) { + cd->read_sector(datas, mode, d->Sector + c++); + nsectors--; + p = (cdutils::DirEntry *) datas; + ssize = 2048; + while ((ssize) && (p->R)) { + ssize -= p->R; + char pbuf[256]; + memcpy(pbuf, p->id, p->N); + pbuf[p->N] = 0; + if (p->Flags & 2) { + if (!((p->N == 1) && ((p->id[0] == 0) || (p->id[0] == 1)))) + copydir(createdir(r, "", p->Size / 2048, p, mode), cd, p, mode); + } else { + printm(M_INFO, "Dupping %s\n", pbuf); + int fmode; + osize = fsize = p->Size; + if (mode == MODE1) { + fmode = mode; + } else { + fmode = MODE2_FORM1; + int s, pad; + s = 33 + p->N; + if (s & 1) { + s++; + pad = 1; + } else { + pad = 0; + } + if ((s != p->R) && ((s + 14) == p->R)) { + if (!(p->id[p->N + pad + 4] & 8)) { + fmode = MODE2; + fsize = (p->Size / 2048) * 2336; + } + } + } + p->Size = fsize; + cdfile * tmp = new cdfile(cd, p, fmode); + createfile(r, tmp, "", p, fmode)->size = osize; + delete tmp; + p->Size = osize; + } + p = (cdutils::DirEntry *) (((Byte *) p) + p->R); + } + } +} + +isobuilder::PVD isobuilder::createpvd(Handle * f) { + Byte datas[2048]; + f->read(datas, 2048); + return createpvd(datas); +} + +isobuilder::PVD isobuilder::createpvd(cdutils * cd) { + Byte datas[2048]; + cd->read_sector(datas, GUESS, 16); + return createpvd(datas); +} + +isobuilder::PVD isobuilder::createpvd(Byte * buffer) { + PVD r; + char pbuff[256]; + memcpy(pbuff, buffer + 8, 32); pbuff[32] = 0; r.sysid = pbuff; @@ -774,94 +776,94 @@ isobuilder::PVD isobuilder::createpvd(Byte * buffer) { r.voleff = Date(buffer + 864); memcpy(r.appdata, buffer + 883, 512); -
- return r;
-}
-
-void isobuilder::close(Handle * cue, int mode) throw (GeneralException) {
- Byte datas[2048];
- Byte * pdatas;
- char * cdatas = (char *) datas;
- int psize;
-
- memset(datas, 0, 2048);
-
- pdatas = (Byte *) malloc(ptsize * 2048);
- psize = root->buildpath(pdatas, ptsize * 2048);
- putdatas(pdatas, ptsize * 2048, mode, ptsect);
- putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize);
- root->buildpath(pdatas, ptsize * 2048, true);
- putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 2);
- putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 3);
- free(pdatas);
-
- datas[0] = 1;
- datas[1] = 67;
- datas[2] = 68;
- datas[3] = 48;
- datas[4] = 48;
- datas[5] = 49;
- datas[6] = 1;
- datas[7] = 0;
-
- sprintf(cdatas + 8, "%-32s", pvd.sysid.to_charp());
- sprintf(cdatas + 40, "%-32s", pvd.volid.to_charp());
- *((Uint32 *) (datas + 80)) = nsectors;
- *((Uint32 *) (datas + 84)) = cdutils::swap_dword(nsectors);
-
- datas[120] = 1;
- datas[121] = 0;
- datas[122] = 0;
- datas[123] = 1;
- datas[124] = 1;
- datas[125] = 0;
- datas[126] = 0;
- datas[127] = 1;
- datas[128] = 0;
- datas[129] = 8;
- datas[130] = 8;
- datas[131] = 0;
- *((Uint32 *) (datas + 132)) = psize;
- *((Uint32 *) (datas + 136)) = cdutils::swap_dword(psize);
- *((Uint32 *) (datas + 140)) = ptsect;
- *((Uint32 *) (datas + 144)) = ptsect + ptsize;
- *((Uint32 *) (datas + 148)) = cdutils::swap_dword(ptsect + ptsize * 2);
- *((Uint32 *) (datas + 152)) = cdutils::swap_dword(ptsect + ptsize * 2);
-
- root->buildentry(datas + 156, 34, false);
-
- sprintf(cdatas + 190, "%-128s", pvd.volsetid.to_charp());
- sprintf(cdatas + 318, "%-128s", pvd.pubid.to_charp());
- sprintf(cdatas + 446, "%-128s", pvd.prepid.to_charp());
- sprintf(cdatas + 574, "%-128s", pvd.appid.to_charp());
- sprintf(cdatas + 702, "%-37s", pvd.copyright.to_charp());
- sprintf(cdatas + 739, "%-37s", pvd.appid.to_charp());
- sprintf(cdatas + 776, "%-37s", pvd.biblio.to_charp());
-
- pvd.volcreat.dump(datas + 813);
- pvd.modif.dump(datas + 830);
- pvd.volexp.dump(datas + 847);
- pvd.voleff.dump(datas + 864);
-
- memcpy(datas + 883, pvd.appdata, 512);
-
- clearEOF();
- sub_EOR = 1;
- createsector(datas, mode, 16);
-
- memset(datas, 0, 2048);
- datas[0] =255;
- datas[1] = 67;
- datas[2] = 68;
- datas[3] = 48;
- datas[4] = 48;
- datas[5] = 49;
- datas[6] = 1;
-
- setEOF();
- createsector(datas, mode);
-
- root->dumpdirs(this);
-
- closed = true;
-}
+ + return r; +} + +void isobuilder::close(Handle * cue, int mode) throw (GeneralException) { + Byte datas[2048]; + Byte * pdatas; + char * cdatas = (char *) datas; + int psize; + + memset(datas, 0, 2048); + + pdatas = (Byte *) malloc(ptsize * 2048); + psize = root->buildpath(pdatas, ptsize * 2048); + putdatas(pdatas, ptsize * 2048, mode, ptsect); + putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize); + root->buildpath(pdatas, ptsize * 2048, true); + putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 2); + putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 3); + free(pdatas); + + datas[0] = 1; + datas[1] = 67; + datas[2] = 68; + datas[3] = 48; + datas[4] = 48; + datas[5] = 49; + datas[6] = 1; + datas[7] = 0; + + sprintf(cdatas + 8, "%-32s", pvd.sysid.to_charp()); + sprintf(cdatas + 40, "%-32s", pvd.volid.to_charp()); + *((Uint32 *) (datas + 80)) = nsectors; + *((Uint32 *) (datas + 84)) = cdutils::swap_dword(nsectors); + + datas[120] = 1; + datas[121] = 0; + datas[122] = 0; + datas[123] = 1; + datas[124] = 1; + datas[125] = 0; + datas[126] = 0; + datas[127] = 1; + datas[128] = 0; + datas[129] = 8; + datas[130] = 8; + datas[131] = 0; + *((Uint32 *) (datas + 132)) = psize; + *((Uint32 *) (datas + 136)) = cdutils::swap_dword(psize); + *((Uint32 *) (datas + 140)) = ptsect; + *((Uint32 *) (datas + 144)) = ptsect + ptsize; + *((Uint32 *) (datas + 148)) = cdutils::swap_dword(ptsect + ptsize * 2); + *((Uint32 *) (datas + 152)) = cdutils::swap_dword(ptsect + ptsize * 2); + + root->buildentry(datas + 156, 34, false); + + sprintf(cdatas + 190, "%-128s", pvd.volsetid.to_charp()); + sprintf(cdatas + 318, "%-128s", pvd.pubid.to_charp()); + sprintf(cdatas + 446, "%-128s", pvd.prepid.to_charp()); + sprintf(cdatas + 574, "%-128s", pvd.appid.to_charp()); + sprintf(cdatas + 702, "%-37s", pvd.copyright.to_charp()); + sprintf(cdatas + 739, "%-37s", pvd.appid.to_charp()); + sprintf(cdatas + 776, "%-37s", pvd.biblio.to_charp()); + + pvd.volcreat.dump(datas + 813); + pvd.modif.dump(datas + 830); + pvd.volexp.dump(datas + 847); + pvd.voleff.dump(datas + 864); + + memcpy(datas + 883, pvd.appdata, 512); + + clearEOF(); + sub_EOR = 1; + createsector(datas, mode, 16); + + memset(datas, 0, 2048); + datas[0] =255; + datas[1] = 67; + datas[2] = 68; + datas[3] = 48; + datas[4] = 48; + datas[5] = 49; + datas[6] = 1; + + setEOF(); + createsector(datas, mode); + + root->dumpdirs(this); + + closed = true; +} diff --git a/lib/luacd.cpp b/lib/luacd.cpp index 68b3028..cab50b2 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -17,574 +17,574 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luacd.cpp,v 1.4 2003-12-10 02:59:32 pixel Exp $ */ +/* $Id: luacd.cpp,v 1.5 2003-12-11 16:53:43 pixel Exp $ */ #include "luacd.h" -
-
- /**************************\
-|** class cdutils exports **|
- \**************************/
-
-Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { }
-
-enum cdutils_methods_t {
- CDUTILS_SETISOW = 0,
- CDUTILS_GUESSTYPE,
- CDUTILS_SECTORSEEK,
- CDUTILS_READSECTOR,
- CDUTILS_READDATAS,
- CDUTILS_READFILE,
- CDUTILS_WRITESECTOR,
- CDUTILS_WRITEDATAS,
- CDUTILS_WRITEFILE,
- CDUTILS_GETISOINFOS,
- CDUTILS_GETPTINFOS,
- CDUTILS_FINDPATH,
- CDUTILS_FINDPARENT,
- CDUTILS_FINDDIRENTRY,
-};
-
-enum cdutils_functions_t {
- CDUTILS_NEWCDUTILS = 0,
- CDUTILS_SWAPWORD,
- CDUTILS_SWAPDWORD,
- CDUTILS_FROM_BCD,
- CDUTILS_TO_BCD,
- CDUTILS_IS_VALID_BCD,
- CDUTILS_FROM_MSF,
-};
-
-struct lua_functypes_t cdutils_methods[] = {
- { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} },
- { CDUTILS_GUESSTYPE, "guessmode", 0, 1, {LUA_NUMBER} },
- { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} },
- { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_READDATAS, "readdatas", 1, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_READFILE, "readfile", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 },
- { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 },
- { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} },
- { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} },
- { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} },
- { -1, 0, 0, 0, 0 }
-};
-
-struct lua_functypes_t cdutils_functions[] = {
- { CDUTILS_NEWCDUTILS, "cdutils" , 1, 2, {LUA_OBJECT, LUA_OBJECT} },
- { CDUTILS_SWAPWORD, "swapword", 1, 1, {LUA_NUMBER} },
- { CDUTILS_SWAPDWORD, "swapdword", 1, 1, {LUA_NUMBER} },
- { CDUTILS_FROM_BCD, "from_BCD", 1, 1, {LUA_NUMBER} },
- { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} },
- { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} },
- { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_cdutils : public Base {
- public:
- DECLARE_METHOD(cdutils, CDUTILS_SETISOW);
- DECLARE_METHOD(cdutils, CDUTILS_GUESSTYPE);
- DECLARE_METHOD(cdutils, CDUTILS_SECTORSEEK);
- DECLARE_METHOD(cdutils, CDUTILS_READSECTOR);
- DECLARE_METHOD(cdutils, CDUTILS_READDATAS);
- DECLARE_METHOD(cdutils, CDUTILS_READFILE);
- DECLARE_METHOD(cdutils, CDUTILS_WRITESECTOR);
- DECLARE_METHOD(cdutils, CDUTILS_WRITEDATAS);
- DECLARE_METHOD(cdutils, CDUTILS_WRITEFILE);
- DECLARE_METHOD(cdutils, CDUTILS_GETISOINFOS);
- DECLARE_METHOD(cdutils, CDUTILS_GETPTINFOS);
- DECLARE_METHOD(cdutils, CDUTILS_FINDPATH);
- DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT);
- DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY);
-
- DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS);
- DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD);
- DECLARE_FUNCTION(cdutils, CDUTILS_SWAPDWORD);
- DECLARE_FUNCTION(cdutils, CDUTILS_FROM_BCD);
- DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD);
- DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD);
- DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF);
-
- private:
- static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller);
- static int cdutils_proceed_statics(Lua * L, int n, int caller);
-};
-
-void Luacdutils::pushmembers(Lua * L) {
- pushme(L, cd);
-
- PUSH_METHOD(cdutils, CDUTILS_SETISOW);
- PUSH_METHOD(cdutils, CDUTILS_GUESSTYPE);
- PUSH_METHOD(cdutils, CDUTILS_SECTORSEEK);
- PUSH_METHOD(cdutils, CDUTILS_READSECTOR);
- PUSH_METHOD(cdutils, CDUTILS_READDATAS);
- PUSH_METHOD(cdutils, CDUTILS_READFILE);
- PUSH_METHOD(cdutils, CDUTILS_WRITESECTOR);
- PUSH_METHOD(cdutils, CDUTILS_WRITEDATAS);
- PUSH_METHOD(cdutils, CDUTILS_WRITEFILE);
- PUSH_METHOD(cdutils, CDUTILS_GETISOINFOS);
- PUSH_METHOD(cdutils, CDUTILS_GETPTINFOS);
- PUSH_METHOD(cdutils, CDUTILS_FINDPATH);
- PUSH_METHOD(cdutils, CDUTILS_FINDPARENT);
- PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY);
-}
-
-void Luacdutils::pushstatics(Lua * L) throw (GeneralException) {
- CHECK_METHODS(cdutils);
- CHECK_FUNCTIONS(cdutils);
-
- PUSH_FUNCTION(cdutils, CDUTILS_NEWCDUTILS);
- PUSH_FUNCTION(cdutils, CDUTILS_SWAPWORD);
- PUSH_FUNCTION(cdutils, CDUTILS_SWAPDWORD);
- PUSH_FUNCTION(cdutils, CDUTILS_FROM_BCD);
- PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD);
- PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD);
- PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF);
-
- L->push("MODE0");
- L->push((lua_Number) MODE0);
- L->setvar();
-
- L->push("MODE1");
- L->push((lua_Number) MODE1);
- L->setvar();
-
- L->push("MODE2");
- L->push((lua_Number) MODE2);
- L->setvar();
-
- L->push("MODE2_FORM1");
- L->push((lua_Number) MODE2_FORM1);
- L->setvar();
-
- L->push("MODE2_FORM2");
- L->push((lua_Number) MODE2_FORM2);
- L->setvar();
-
- L->push("MORE_RAW");
- L->push((lua_Number) MODE_RAW);
- L->setvar();
-
- L->push("GUESS");
- L->push((lua_Number) GUESS);
- L->setvar();
-
- int i;
-
- L->push("sec_sizes");
- L->newtable();
- for (i = 0; i <= GUESS; i++) {
- L->push((lua_Number) i);
- L->push((lua_Number) sec_sizes[i]);
- L->settable();
- }
- L->setvar();
-
- L->push("sec_offsts");
- L->newtable();
- for (i = 0; i <= GUESS; i++) {
- L->push((lua_Number) i);
- L->push((lua_Number) sec_offsts[i]);
- L->settable();
- }
- L->setvar();
-
- L->push("sec_modes");
- L->newtable();
- for (i = 0; i <= GUESS; i++) {
- L->push((lua_Number) i);
- L->push(sec_modes[i]);
- L->settable();
- }
- L->setvar();
-}
-
-int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) {
- int r = 0, sect = -1, mode = GUESS, size = -1, i;
- Handle * h;
- Byte sdatas[2352], * datas;
- String path;
- cdutils::DirEntry * dir, * bdir, * adir;
-
- switch(caller) {
- case CDUTILS_SETISOW:
- h = (Handle *) LuaObject::getme(L, 2);
- cd->set_iso_w(h);
- break;
- case CDUTILS_GUESSTYPE:
- if (n == 1) {
- sect = L->tonumber();
- }
- L->push((lua_Number) cd->guess_type(sect));
- r = 1;
- break;
- case CDUTILS_SECTORSEEK:
- sect = L->tonumber();
- cd->sector_seek(sect);
- break;
- case CDUTILS_READSECTOR:
- if (n >= 1)
- mode = L->tonumber(2);
- if (n == 2)
- sect = L->tonumber(3);
- size = cd->read_sector(sdatas, mode, sect);
- L->newtable();
- for (i = 0; i < size; i++) {
- L->push((lua_Number) i);
- L->push((lua_Number) sdatas[i]);
- L->settable();
- }
- r = 1;
- break;
- case CDUTILS_READDATAS:
- size = L->tonumber(2);
- if (n >= 2)
- mode = L->tonumber(3);
- if (n == 3)
- sect = L->tonumber(3);
- datas = (Byte *) malloc(size);
- cd->read_datas(datas, size, mode, sect);
- L->newtable();
- for (i = 0; i < size; i++) {
- L->push((lua_Number) i);
- L->push((lua_Number) datas[i]);
- L->settable();
- }
- r = 1;
- free(datas);
- break;
- case CDUTILS_READFILE:
- h = (Handle *) LuaObject::getme(L, 2);
- size = L->tonumber(5);
- if (n >= 3)
- mode = L->tonumber(4);
- if (n == 4)
- sect = L->tonumber(5);
- cd->read_file(h, size, mode, sect);
- break;
- case CDUTILS_WRITESECTOR:
- if (n >= 2)
- mode = L->tonumber(3);
- if (n == 3)
- sect = L->tonumber(4);
- for (i = 0; i < 2352; i++) {
- L->push((lua_Number) i);
- L->gettable(2);
- sdatas[i] = L->tonumber();
- L->pop();
- }
- cd->write_sector(datas, mode, sect);
- break;
- case CDUTILS_WRITEDATAS:
- size = L->tonumber(3);
- if (n >= 3)
- mode = L->tonumber(4);
- if (n == 4)
- sect = L->tonumber(5);
- datas = (Byte *) malloc(size);
-
- for (i = 0; i < size; i++) {
- L->push((lua_Number) i);
- L->gettable(2);
- sdatas[i] = L->tonumber();
- L->pop();
- }
- cd->write_datas(datas, size, mode, sect);
- free(datas);
- break;
- case CDUTILS_WRITEFILE:
- h = (Handle *) LuaObject::getme(L, 2);
- if (n >= 2)
- size = L->tonumber(3);
- if (n >= 3)
- mode = L->tonumber(4);
- if (n == 4)
- sect = L->tonumber(5);
- cd->write_file(h, size, mode, sect);
- break;
- case CDUTILS_GETISOINFOS:
- L->push((lua_Number) cd->get_iso_infos());
- r = 1;
- break;
- case CDUTILS_GETPTINFOS:
- L->push((lua_Number) cd->get_pt_infos());
- r = 1;
- break;
- case CDUTILS_FINDPATH:
- path = L->tostring(2);
- bdir = cd->find_path(&datas, path);
- if ((bdir) && bdir->R) {
- dir = (cdutils::DirEntry *) malloc(bdir->R);
- memcpy(dir, bdir, bdir->R);
- } else {
- dir = 0;
- }
- if (dir) {
- Luadirentry ldir(dir);
- ldir.pushdestruct(L);
- } else {
- L->push();
- }
- r = 1;
- free(datas);
- break;
- case CDUTILS_FINDPARENT:
- path = L->tostring(2);
- bdir = cd->find_parent(&datas, path);
- if ((bdir) && bdir->R) {
- dir = (cdutils::DirEntry *) malloc(bdir->R);
- memcpy(dir, bdir, bdir->R);
- } else {
- dir = 0;
- }
- if (dir) {
- Luadirentry ldir(dir);
- ldir.pushdestruct(L);
- } else {
- L->push();
- }
- r = 1;
- free(datas);
- break;
- case CDUTILS_FINDDIRENTRY:
- adir = (cdutils::DirEntry *) LuaObject::getme(L, 2);
- path = L->tostring(3);
- bdir = cd->find_dir_entry(&datas, adir, path);
- if ((bdir) && bdir->R) {
- dir = (cdutils::DirEntry *) malloc(bdir->R);
- memcpy(dir, bdir, bdir->R);
- } else {
- dir = 0;
- }
- if (dir) {
- Luadirentry ldir(dir);
- ldir.pushdestruct(L);
- } else {
- L->push();
- }
- r = 1;
- free(datas);
- break;
- }
- return r;
-}
-
-int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) {
- int r = 0;
- Uint32 x;
- Handle * isor = 0, * isow = 0;
- Uint32 msf, start = 150;
- Byte m, s, f;
-
- switch(caller) {
- case CDUTILS_NEWCDUTILS:
- isor = (Handle *) LuaObject::getme(L, 1);
- if (n == 2)
- isow = (Handle *) LuaObject::getme(L, 2);
- {
- Luacdutils cd(new cdutils(isor, isow));
- cd.pushdestruct(L);
- }
- break;
- case CDUTILS_SWAPWORD:
- x = L->tonumber();
- L->push((lua_Number) cdutils::swap_word(x));
- r = 1;
- break;
- case CDUTILS_SWAPDWORD:
- x = L->tonumber();
- L->push((lua_Number) cdutils::swap_dword(x));
- r = 1;
- break;
- case CDUTILS_FROM_BCD:
- x = L->tonumber();
- L->push((lua_Number) cdutils::from_BCD(x));
- r = 1;
- break;
- case CDUTILS_TO_BCD:
- x = L->tonumber();
- L->push((lua_Number) cdutils::to_BCD(x));
- r = 1;
- break;
- case CDUTILS_IS_VALID_BCD:
- x = L->tonumber();
- L->push(cdutils::is_valid_BCD(x));
- r = 1;
- break;
- case CDUTILS_FROM_MSF:
- if (n <= 2) {
- msf = L->tonumber(1);
- if (n == 2)
- start = L->tonumber(2);
- L->push((lua_Number) cdutils::from_MSF(msf, start));
- } else {
- m = L->tonumber(1);
- s = L->tonumber(2);
- f = L->tonumber(3);
- if (n == 4)
- start = L->tonumber(4);
- L->push((lua_Number) cdutils::from_MSF(m, s, f, start));
- }
- r = 1;
- break;
- }
-
- return r;
-}
-
-
- /*************************\
-|** class cdfile exports **|
- \*************************/
-
-Luacdfile::Luacdfile(cdfile * h) : LuaHandle(h) { }
-
-enum cdfile_functions_t {
- CDFILE_NEWCDFILE = 0,
-};
-
-struct lua_functypes_t cdfile_functions[] = {
- { CDFILE_NEWCDFILE, "cdfile", 1, 4, {LUA_OBJECT, LUA_ANY, LUA_NUMBER, LUA_NUMBER} },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_cdfile : public Base {
- public:
- DECLARE_FUNCTION(cdfile, CDFILE_NEWCDFILE);
- private:
- static int cdfile_proceed_statics(Lua * L, int n, int caller);
-};
-
-void Luacdfile::pushmembers(Lua * L) {
- LuaHandle::pushmembers(L);
-}
-
-void Luacdfile::pushstatics(Lua * L) throw (GeneralException) {
- CHECK_FUNCTIONS(cdfile);
- PUSH_FUNCTION(cdfile, CDFILE_NEWCDFILE);
-}
-
-int sLua_cdfile::cdfile_proceed_statics(Lua * L, int n, int caller) {
- int r = 0;
- bool invalid = false;
- cdutils * cd;
- cdutils::DirEntry * dir;
- int sector, mode = GUESS;
- ssize_t size = -1;
- cdfile * cdf;
-
- switch(caller) {
- case CDFILE_NEWCDFILE:
- cd = (cdutils *) LuaObject::getme(L, 1);
- if (L->islightuserdata(2)) {
- if (n <= 3) {
- dir = (cdutils::DirEntry *) LuaObject::getme(L, 2);
- if (n == 3)
- mode = L->tonumber(3);
- cdf = new cdfile(cd, dir, mode);
- } else {
- invalid = true;
- }
- } else if (L->isnumber(2)) {
- if (n >= 2) {
- sector = L->tonumber(2);
- if (n >= 3)
- size = L->tonumber(3);
- if (n == 4)
- mode = L->tonumber(4);
- cdf = new cdfile(cd, sector, size, mode);
- } else {
- invalid = true;
- }
- } else {
- invalid = true;
- }
- if (invalid) {
- L->error("Invalid arguments to constructor of cdutils");
- } else {
- Luacdfile luacdf(cdf);
- luacdf.pushdestruct(L);
- r = 1;
- }
- break;
- }
-
- return r;
-}
-
-
- /***************************\
-|** class direntry exports **|
- \***************************/
-
-typedef cdutils::DirEntry direntry;
-
-Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { }
-
-enum direntry_methods_t {
- DIRENTRY_INDEX = 0,
- DIRENTRY_ISHIDDEN,
- DIRENTRY_ISDIR,
- DIRENTRY_HASXA,
- DIRENTRY_ISXADIR,
- DIRENTRY_ISXAAUDIO,
- DIRENTRY_ISXASTR,
- DIRENTRY_ISXAXA,
- DIRENTRY_ISXAFORM1,
-};
-
-struct lua_functypes_t direntry_methods[] = {
- { DIRENTRY_INDEX, "index", 1, 1, {LUA_STRING} },
- { DIRENTRY_ISHIDDEN, "ishidden", 0, 0, 0 },
- { DIRENTRY_ISDIR, "isdir", 0, 0, 0 },
- { DIRENTRY_HASXA, "hasxa", 0, 0, 0 },
- { DIRENTRY_ISXADIR, "isxadir", 0, 0, 0 },
- { DIRENTRY_ISXAAUDIO, "isxaaudio", 0, 0, 0 },
- { DIRENTRY_ISXASTR, "isxastr", 0, 0, 0 },
- { DIRENTRY_ISXAXA, "isxaxa", 0, 0, 0 },
- { DIRENTRY_ISXAFORM1, "isxaform1", 0, 0, 0 },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_direntry : public Base {
- public:
- DECLARE_METHOD(direntry, DIRENTRY_INDEX);
- DECLARE_METHOD(direntry, DIRENTRY_ISHIDDEN);
- DECLARE_METHOD(direntry, DIRENTRY_ISDIR);
- DECLARE_METHOD(direntry, DIRENTRY_HASXA);
- DECLARE_METHOD(direntry, DIRENTRY_ISXADIR);
- DECLARE_METHOD(direntry, DIRENTRY_ISXAAUDIO);
- DECLARE_METHOD(direntry, DIRENTRY_ISXASTR);
- DECLARE_METHOD(direntry, DIRENTRY_ISXAXA);
- DECLARE_METHOD(direntry, DIRENTRY_ISXAFORM1);
- private:
- static int direntry_proceed(Lua * L, int n, direntry * obj, int caller);
-};
-
-void Luadirentry::pushmembers(Lua * L) {
- pushme(L, dir);
-
- PUSH_METAMETHOD(direntry, DIRENTRY_INDEX);
- PUSH_METHOD(direntry, DIRENTRY_ISHIDDEN);
- PUSH_METHOD(direntry, DIRENTRY_ISDIR);
- PUSH_METHOD(direntry, DIRENTRY_HASXA);
- PUSH_METHOD(direntry, DIRENTRY_ISXADIR);
- PUSH_METHOD(direntry, DIRENTRY_ISXAAUDIO);
- PUSH_METHOD(direntry, DIRENTRY_ISXASTR);
- PUSH_METHOD(direntry, DIRENTRY_ISXAXA);
- PUSH_METHOD(direntry, DIRENTRY_ISXAFORM1);
-}
-
-int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) {
- int r = 0, s, pad;
- String index;
- bool has_xa = false;
+ + + /**************************\ +|** class cdutils exports **| + \**************************/ + +Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { } + +enum cdutils_methods_t { + CDUTILS_SETISOW = 0, + CDUTILS_GUESSTYPE, + CDUTILS_SECTORSEEK, + CDUTILS_READSECTOR, + CDUTILS_READDATAS, + CDUTILS_READFILE, + CDUTILS_WRITESECTOR, + CDUTILS_WRITEDATAS, + CDUTILS_WRITEFILE, + CDUTILS_GETISOINFOS, + CDUTILS_GETPTINFOS, + CDUTILS_FINDPATH, + CDUTILS_FINDPARENT, + CDUTILS_FINDDIRENTRY, +}; + +enum cdutils_functions_t { + CDUTILS_NEWCDUTILS = 0, + CDUTILS_SWAPWORD, + CDUTILS_SWAPDWORD, + CDUTILS_FROM_BCD, + CDUTILS_TO_BCD, + CDUTILS_IS_VALID_BCD, + CDUTILS_FROM_MSF, +}; + +struct lua_functypes_t cdutils_methods[] = { + { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} }, + { CDUTILS_GUESSTYPE, "guessmode", 0, 1, {LUA_NUMBER} }, + { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} }, + { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_READDATAS, "readdatas", 1, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_READFILE, "readfile", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 }, + { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 }, + { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} }, + { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} }, + { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t cdutils_functions[] = { + { CDUTILS_NEWCDUTILS, "cdutils" , 1, 2, {LUA_OBJECT, LUA_OBJECT} }, + { CDUTILS_SWAPWORD, "swapword", 1, 1, {LUA_NUMBER} }, + { CDUTILS_SWAPDWORD, "swapdword", 1, 1, {LUA_NUMBER} }, + { CDUTILS_FROM_BCD, "from_BCD", 1, 1, {LUA_NUMBER} }, + { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} }, + { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} }, + { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_cdutils : public Base { + public: + DECLARE_METHOD(cdutils, CDUTILS_SETISOW); + DECLARE_METHOD(cdutils, CDUTILS_GUESSTYPE); + DECLARE_METHOD(cdutils, CDUTILS_SECTORSEEK); + DECLARE_METHOD(cdutils, CDUTILS_READSECTOR); + DECLARE_METHOD(cdutils, CDUTILS_READDATAS); + DECLARE_METHOD(cdutils, CDUTILS_READFILE); + DECLARE_METHOD(cdutils, CDUTILS_WRITESECTOR); + DECLARE_METHOD(cdutils, CDUTILS_WRITEDATAS); + DECLARE_METHOD(cdutils, CDUTILS_WRITEFILE); + DECLARE_METHOD(cdutils, CDUTILS_GETISOINFOS); + DECLARE_METHOD(cdutils, CDUTILS_GETPTINFOS); + DECLARE_METHOD(cdutils, CDUTILS_FINDPATH); + DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT); + DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY); + + DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); + DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD); + DECLARE_FUNCTION(cdutils, CDUTILS_SWAPDWORD); + DECLARE_FUNCTION(cdutils, CDUTILS_FROM_BCD); + DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD); + DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); + DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF); + + private: + static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller); + static int cdutils_proceed_statics(Lua * L, int n, int caller); +}; + +void Luacdutils::pushmembers(Lua * L) { + pushme(L, cd); + + PUSH_METHOD(cdutils, CDUTILS_SETISOW); + PUSH_METHOD(cdutils, CDUTILS_GUESSTYPE); + PUSH_METHOD(cdutils, CDUTILS_SECTORSEEK); + PUSH_METHOD(cdutils, CDUTILS_READSECTOR); + PUSH_METHOD(cdutils, CDUTILS_READDATAS); + PUSH_METHOD(cdutils, CDUTILS_READFILE); + PUSH_METHOD(cdutils, CDUTILS_WRITESECTOR); + PUSH_METHOD(cdutils, CDUTILS_WRITEDATAS); + PUSH_METHOD(cdutils, CDUTILS_WRITEFILE); + PUSH_METHOD(cdutils, CDUTILS_GETISOINFOS); + PUSH_METHOD(cdutils, CDUTILS_GETPTINFOS); + PUSH_METHOD(cdutils, CDUTILS_FINDPATH); + PUSH_METHOD(cdutils, CDUTILS_FINDPARENT); + PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY); +} + +void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(cdutils); + CHECK_FUNCTIONS(cdutils); + + PUSH_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); + PUSH_FUNCTION(cdutils, CDUTILS_SWAPWORD); + PUSH_FUNCTION(cdutils, CDUTILS_SWAPDWORD); + PUSH_FUNCTION(cdutils, CDUTILS_FROM_BCD); + PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD); + PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); + PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF); + + L->push("MODE0"); + L->push((lua_Number) MODE0); + L->setvar(); + + L->push("MODE1"); + L->push((lua_Number) MODE1); + L->setvar(); + + L->push("MODE2"); + L->push((lua_Number) MODE2); + L->setvar(); + + L->push("MODE2_FORM1"); + L->push((lua_Number) MODE2_FORM1); + L->setvar(); + + L->push("MODE2_FORM2"); + L->push((lua_Number) MODE2_FORM2); + L->setvar(); + + L->push("MORE_RAW"); + L->push((lua_Number) MODE_RAW); + L->setvar(); + + L->push("GUESS"); + L->push((lua_Number) GUESS); + L->setvar(); + + int i; + + L->push("sec_sizes"); + L->newtable(); + for (i = 0; i <= GUESS; i++) { + L->push((lua_Number) i); + L->push((lua_Number) sec_sizes[i]); + L->settable(); + } + L->setvar(); + + L->push("sec_offsts"); + L->newtable(); + for (i = 0; i <= GUESS; i++) { + L->push((lua_Number) i); + L->push((lua_Number) sec_offsts[i]); + L->settable(); + } + L->setvar(); + + L->push("sec_modes"); + L->newtable(); + for (i = 0; i <= GUESS; i++) { + L->push((lua_Number) i); + L->push(sec_modes[i]); + L->settable(); + } + L->setvar(); +} + +int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { + int r = 0, sect = -1, mode = GUESS, size = -1, i; + Handle * h; + Byte sdatas[2352], * datas; + String path; + cdutils::DirEntry * dir, * bdir, * adir; + + switch(caller) { + case CDUTILS_SETISOW: + h = (Handle *) LuaObject::getme(L, 2); + cd->set_iso_w(h); + break; + case CDUTILS_GUESSTYPE: + if (n == 1) { + sect = L->tonumber(); + } + L->push((lua_Number) cd->guess_type(sect)); + r = 1; + break; + case CDUTILS_SECTORSEEK: + sect = L->tonumber(); + cd->sector_seek(sect); + break; + case CDUTILS_READSECTOR: + if (n >= 1) + mode = L->tonumber(2); + if (n == 2) + sect = L->tonumber(3); + size = cd->read_sector(sdatas, mode, sect); + L->newtable(); + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->push((lua_Number) sdatas[i]); + L->settable(); + } + r = 1; + break; + case CDUTILS_READDATAS: + size = L->tonumber(2); + if (n >= 2) + mode = L->tonumber(3); + if (n == 3) + sect = L->tonumber(3); + datas = (Byte *) malloc(size); + cd->read_datas(datas, size, mode, sect); + L->newtable(); + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->push((lua_Number) datas[i]); + L->settable(); + } + r = 1; + free(datas); + break; + case CDUTILS_READFILE: + h = (Handle *) LuaObject::getme(L, 2); + size = L->tonumber(5); + if (n >= 3) + mode = L->tonumber(4); + if (n == 4) + sect = L->tonumber(5); + cd->read_file(h, size, mode, sect); + break; + case CDUTILS_WRITESECTOR: + if (n >= 2) + mode = L->tonumber(3); + if (n == 3) + sect = L->tonumber(4); + for (i = 0; i < 2352; i++) { + L->push((lua_Number) i); + L->gettable(2); + sdatas[i] = L->tonumber(); + L->pop(); + } + cd->write_sector(datas, mode, sect); + break; + case CDUTILS_WRITEDATAS: + size = L->tonumber(3); + if (n >= 3) + mode = L->tonumber(4); + if (n == 4) + sect = L->tonumber(5); + datas = (Byte *) malloc(size); + + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->gettable(2); + sdatas[i] = L->tonumber(); + L->pop(); + } + cd->write_datas(datas, size, mode, sect); + free(datas); + break; + case CDUTILS_WRITEFILE: + h = (Handle *) LuaObject::getme(L, 2); + if (n >= 2) + size = L->tonumber(3); + if (n >= 3) + mode = L->tonumber(4); + if (n == 4) + sect = L->tonumber(5); + cd->write_file(h, size, mode, sect); + break; + case CDUTILS_GETISOINFOS: + L->push((lua_Number) cd->get_iso_infos()); + r = 1; + break; + case CDUTILS_GETPTINFOS: + L->push((lua_Number) cd->get_pt_infos()); + r = 1; + break; + case CDUTILS_FINDPATH: + path = L->tostring(2); + bdir = cd->find_path(&datas, path); + if ((bdir) && bdir->R) { + dir = (cdutils::DirEntry *) malloc(bdir->R); + memcpy(dir, bdir, bdir->R); + } else { + dir = 0; + } + if (dir) { + Luadirentry ldir(dir); + ldir.pushdestruct(L); + } else { + L->push(); + } + r = 1; + free(datas); + break; + case CDUTILS_FINDPARENT: + path = L->tostring(2); + bdir = cd->find_parent(&datas, path); + if ((bdir) && bdir->R) { + dir = (cdutils::DirEntry *) malloc(bdir->R); + memcpy(dir, bdir, bdir->R); + } else { + dir = 0; + } + if (dir) { + Luadirentry ldir(dir); + ldir.pushdestruct(L); + } else { + L->push(); + } + r = 1; + free(datas); + break; + case CDUTILS_FINDDIRENTRY: + adir = (cdutils::DirEntry *) LuaObject::getme(L, 2); + path = L->tostring(3); + bdir = cd->find_dir_entry(&datas, adir, path); + if ((bdir) && bdir->R) { + dir = (cdutils::DirEntry *) malloc(bdir->R); + memcpy(dir, bdir, bdir->R); + } else { + dir = 0; + } + if (dir) { + Luadirentry ldir(dir); + ldir.pushdestruct(L); + } else { + L->push(); + } + r = 1; + free(datas); + break; + } + return r; +} + +int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + Uint32 x; + Handle * isor = 0, * isow = 0; + Uint32 msf, start = 150; + Byte m, s, f; + + switch(caller) { + case CDUTILS_NEWCDUTILS: + isor = (Handle *) LuaObject::getme(L, 1); + if (n == 2) + isow = (Handle *) LuaObject::getme(L, 2); + { + Luacdutils cd(new cdutils(isor, isow)); + cd.pushdestruct(L); + } + break; + case CDUTILS_SWAPWORD: + x = L->tonumber(); + L->push((lua_Number) cdutils::swap_word(x)); + r = 1; + break; + case CDUTILS_SWAPDWORD: + x = L->tonumber(); + L->push((lua_Number) cdutils::swap_dword(x)); + r = 1; + break; + case CDUTILS_FROM_BCD: + x = L->tonumber(); + L->push((lua_Number) cdutils::from_BCD(x)); + r = 1; + break; + case CDUTILS_TO_BCD: + x = L->tonumber(); + L->push((lua_Number) cdutils::to_BCD(x)); + r = 1; + break; + case CDUTILS_IS_VALID_BCD: + x = L->tonumber(); + L->push(cdutils::is_valid_BCD(x)); + r = 1; + break; + case CDUTILS_FROM_MSF: + if (n <= 2) { + msf = L->tonumber(1); + if (n == 2) + start = L->tonumber(2); + L->push((lua_Number) cdutils::from_MSF(msf, start)); + } else { + m = L->tonumber(1); + s = L->tonumber(2); + f = L->tonumber(3); + if (n == 4) + start = L->tonumber(4); + L->push((lua_Number) cdutils::from_MSF(m, s, f, start)); + } + r = 1; + break; + } + + return r; +} + + + /*************************\ +|** class cdfile exports **| + \*************************/ + +Luacdfile::Luacdfile(cdfile * h) : LuaHandle(h) { } + +enum cdfile_functions_t { + CDFILE_NEWCDFILE = 0, +}; + +struct lua_functypes_t cdfile_functions[] = { + { CDFILE_NEWCDFILE, "cdfile", 1, 4, {LUA_OBJECT, LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_cdfile : public Base { + public: + DECLARE_FUNCTION(cdfile, CDFILE_NEWCDFILE); + private: + static int cdfile_proceed_statics(Lua * L, int n, int caller); +}; + +void Luacdfile::pushmembers(Lua * L) { + LuaHandle::pushmembers(L); +} + +void Luacdfile::pushstatics(Lua * L) throw (GeneralException) { + CHECK_FUNCTIONS(cdfile); + PUSH_FUNCTION(cdfile, CDFILE_NEWCDFILE); +} + +int sLua_cdfile::cdfile_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + bool invalid = false; + cdutils * cd; + cdutils::DirEntry * dir; + int sector, mode = GUESS; + ssize_t size = -1; + cdfile * cdf; + + switch(caller) { + case CDFILE_NEWCDFILE: + cd = (cdutils *) LuaObject::getme(L, 1); + if (L->islightuserdata(2)) { + if (n <= 3) { + dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); + if (n == 3) + mode = L->tonumber(3); + cdf = new cdfile(cd, dir, mode); + } else { + invalid = true; + } + } else if (L->isnumber(2)) { + if (n >= 2) { + sector = L->tonumber(2); + if (n >= 3) + size = L->tonumber(3); + if (n == 4) + mode = L->tonumber(4); + cdf = new cdfile(cd, sector, size, mode); + } else { + invalid = true; + } + } else { + invalid = true; + } + if (invalid) { + L->error("Invalid arguments to constructor of cdutils"); + } else { + Luacdfile luacdf(cdf); + luacdf.pushdestruct(L); + r = 1; + } + break; + } + + return r; +} + + + /***************************\ +|** class direntry exports **| + \***************************/ + +typedef cdutils::DirEntry direntry; + +Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { } + +enum direntry_methods_t { + DIRENTRY_INDEX = 0, + DIRENTRY_ISHIDDEN, + DIRENTRY_ISDIR, + DIRENTRY_HASXA, + DIRENTRY_ISXADIR, + DIRENTRY_ISXAAUDIO, + DIRENTRY_ISXASTR, + DIRENTRY_ISXAXA, + DIRENTRY_ISXAFORM1, +}; + +struct lua_functypes_t direntry_methods[] = { + { DIRENTRY_INDEX, "index", 1, 1, {LUA_STRING} }, + { DIRENTRY_ISHIDDEN, "ishidden", 0, 0, 0 }, + { DIRENTRY_ISDIR, "isdir", 0, 0, 0 }, + { DIRENTRY_HASXA, "hasxa", 0, 0, 0 }, + { DIRENTRY_ISXADIR, "isxadir", 0, 0, 0 }, + { DIRENTRY_ISXAAUDIO, "isxaaudio", 0, 0, 0 }, + { DIRENTRY_ISXASTR, "isxastr", 0, 0, 0 }, + { DIRENTRY_ISXAXA, "isxaxa", 0, 0, 0 }, + { DIRENTRY_ISXAFORM1, "isxaform1", 0, 0, 0 }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_direntry : public Base { + public: + DECLARE_METHOD(direntry, DIRENTRY_INDEX); + DECLARE_METHOD(direntry, DIRENTRY_ISHIDDEN); + DECLARE_METHOD(direntry, DIRENTRY_ISDIR); + DECLARE_METHOD(direntry, DIRENTRY_HASXA); + DECLARE_METHOD(direntry, DIRENTRY_ISXADIR); + DECLARE_METHOD(direntry, DIRENTRY_ISXAAUDIO); + DECLARE_METHOD(direntry, DIRENTRY_ISXASTR); + DECLARE_METHOD(direntry, DIRENTRY_ISXAXA); + DECLARE_METHOD(direntry, DIRENTRY_ISXAFORM1); + private: + static int direntry_proceed(Lua * L, int n, direntry * obj, int caller); +}; + +void Luadirentry::pushmembers(Lua * L) { + pushme(L, dir); + + PUSH_METAMETHOD(direntry, DIRENTRY_INDEX); + PUSH_METHOD(direntry, DIRENTRY_ISHIDDEN); + PUSH_METHOD(direntry, DIRENTRY_ISDIR); + PUSH_METHOD(direntry, DIRENTRY_HASXA); + PUSH_METHOD(direntry, DIRENTRY_ISXADIR); + PUSH_METHOD(direntry, DIRENTRY_ISXAAUDIO); + PUSH_METHOD(direntry, DIRENTRY_ISXASTR); + PUSH_METHOD(direntry, DIRENTRY_ISXAXA); + PUSH_METHOD(direntry, DIRENTRY_ISXAFORM1); +} + +int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) { + int r = 0, s, pad; + String index; + bool has_xa = false; Byte * p; -
+ s = 33 + dir->N; if (s & 1) { s++; @@ -595,1043 +595,1043 @@ int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) if (s != dir->R) { if ((s + 14) == dir->R) { p = (Byte *) dir->id + dir->N + pad; - if ((p[6] == 'X') && (p[7] == 'A')) {
- has_xa = true;
- }
- }
- }
-
- switch (caller) {
- case DIRENTRY_HASXA:
- L->push(has_xa);
- r = 1;
- break;
- case DIRENTRY_ISHIDDEN:
- L->push(dir->Flags & 1 ? true : false);
- r = 1;
- break;
- case DIRENTRY_ISDIR:
- L->push(dir->Flags & 2 ? true : false);
- r = 1;
- break;
- case DIRENTRY_ISXADIR:
- L->push(p[4] & 0x80 ? true : false);
- r = 1;
- break;
- case DIRENTRY_ISXAAUDIO:
- L->push(p[4] & 0x40 ? true : false);
- r = 1;
- break;
- case DIRENTRY_ISXASTR:
- L->push(p[4] & 0x20 ? true : false);
- r = 1;
- break;
- case DIRENTRY_ISXAXA:
- L->push(p[4] & 0x10 ? true : false);
- r = 1;
- break;
- case DIRENTRY_ISXAFORM1:
- L->push(p[4] & 0x08 ? true : false);
- r = 1;
- break;
- case DIRENTRY_INDEX:
- index = L->tostring();
- r = 1;
- if (index == "R") {
- L->push((lua_Number) dir->R);
- } else if (index == "NExt") {
- L->push((lua_Number) dir->NExt);
- } else if (index == "Sector") {
- L->push((lua_Number) dir->Sector);
- } else if (index == "Size") {
- L->push((lua_Number) dir->Size);
- } else if (index == "Year") {
- L->push((lua_Number) dir->Year);
- } else if (index == "Month") {
- L->push((lua_Number) dir->Month);
- } else if (index == "Day") {
- L->push((lua_Number) dir->Day);
- } else if (index == "Hour") {
- L->push((lua_Number) dir->Hour);
- } else if (index == "Minute") {
- L->push((lua_Number) dir->Minute);
- } else if (index == "Second") {
- L->push((lua_Number) dir->Second);
- } else if (index == "Offset") {
- L->push((lua_Number) dir->Offset);
- } else if (index == "Flags") {
- L->push((lua_Number) dir->Flags);
- } else if (index == "HandleUnit") {
- L->push((lua_Number) dir->HandleUnit);
- } else if (index == "HandleGap") {
- L->push((lua_Number) dir->HandleGap);
- } else if (index == "VolSeq") {
- L->push((lua_Number) dir->VolSeq);
- } else if (index == "N") {
- L->push((lua_Number) dir->N);
- } else if (index == "id") {
- char pbuf[256];
- memcpy(pbuf, dir->id, dir->N);
- pbuf[dir->N] = 0;
- L->push(pbuf, dir->N);
- } else {
- L->push();
- }
- }
-
- return r;
-}
-
-
- /***************************\
-|** class direntry exports **|
- \***************************/
-
-typedef isobuilder::Date cddate;
-
-Luacddate::Luacddate(isobuilder::Date * _date) : date(_date) { }
-
-enum cddate_methods_t {
- CDDATE_INDEX = 0,
- CDDATE_NEWINDEX,
-};
-
-enum cddate_functions_t {
- CDDATE_NEWCDDATE = 0,
-};
-
-struct lua_functypes_t cddate_methods[] = {
- { CDDATE_INDEX, "index", 1, 1, {LUA_STRING} },
- { CDDATE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_NUMBER} },
- { -1, 0, 0, 0, 0 }
-};
-
-struct lua_functypes_t cddate_functions[] = {
- { CDDATE_NEWCDDATE, "cddate", 0, 0, 0 },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_cddate : public Base {
- public:
- DECLARE_METHOD(cddate, CDDATE_INDEX);
- DECLARE_METHOD(cddate, CDDATE_NEWINDEX);
- DECLARE_FUNCTION(cddate, CDDATE_NEWCDDATE);
- private:
- static int cddate_proceed(Lua * L, int n, cddate * obj, int caller);
- static int cddate_proceed_statics(Lua * L, int n, int caller);
-};
-
-void Luacddate::pushmembers(Lua * L) {
- pushme(L, date);
-
- PUSH_METAMETHOD(cddate, CDDATE_INDEX);
- PUSH_METAMETHOD(cddate, CDDATE_NEWINDEX);
-}
-
-void Luacddate::pushstatics(Lua * L) throw (GeneralException) {
- CHECK_METHODS(cddate);
- CHECK_FUNCTIONS(cddate);
-
- PUSH_FUNCTION(cddate, CDDATE_NEWCDDATE);
-}
-
-int sLua_cddate::cddate_proceed(Lua * L, int n, cddate * date, int caller) {
- int r, value;
- String key;
-
- switch (caller) {
- case CDDATE_INDEX:
- key = L->tostring(2);
- r = 1;
- if (key == "year") {
- L->push((lua_Number) date->year);
- } else if (key == "month") {
- L->push((lua_Number) date->month);
- } else if (key == "day") {
- L->push((lua_Number) date->day);
- } else if (key == "hour") {
- L->push((lua_Number) date->hour);
- } else if (key == "minute") {
- L->push((lua_Number) date->minute);
- } else if (key == "second") {
- L->push((lua_Number) date->second);
- } else if (key == "hundredths") {
- L->push((lua_Number) date->hundredths);
- } else if (key == "offset") {
- L->push((lua_Number) date->offset);
- } else {
- L->error("Key " + key + " not in class Date");
- }
- break;
- case CDDATE_NEWINDEX:
- key = L->tostring(2);
- value = L->tonumber(3);
- if (key == "year") {
- date->year = value;
- } else if (key == "month") {
- date->month = value;
- } else if (key == "day") {
- date->day = value;
- } else if (key == "hour") {
- date->hour = value;
- } else if (key == "minute") {
- date->minute = value;
- } else if (key == "second") {
- date->second = value;
- } else if (key == "hundredths") {
- date->hundredths = value;
- } else if (key == "offset") {
- date->offset = value;
- } else {
- L->error("Key " + key + " not in class Date");
- }
- break;
- }
-
- return r;
-}
-
-int sLua_cddate::cddate_proceed_statics(Lua * L, int n, int caller) {
- int r = 0;
-
- switch (caller) {
- case CDDATE_NEWCDDATE:
- {
- Luacddate t(new cddate());
- t.pushdestruct(L);
- }
- }
-
- return r;
-}
-
- /**********************\
-|** class PVD exports **|
- \**********************/
-
-typedef isobuilder::PVD PVD;
-
-LuaPVD::LuaPVD(struct isobuilder::PVD * _pvd) : pvd(_pvd) { }
-
-enum PVD_methods_t {
- PVD_INDEX = 0,
- PVD_NEWINDEX,
-};
-
-enum PVD_functions_t {
- PVD_NEWPVD = 0,
-};
-
-struct lua_functypes_t PVD_methods[] = {
- { PVD_INDEX, "index", 1, 1, {LUA_ANY} },
- { PVD_NEWINDEX, "newindex", 2, 2, {LUA_ANY, LUA_ANY} },
- { -1, 0, 0, 0, 0 }
-};
-
-struct lua_functypes_t PVD_functions[] = {
- { PVD_NEWPVD, "PVD", 0, 0, 0 },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_PVD : public Base {
- public:
- DECLARE_METHOD(PVD, PVD_INDEX);
- DECLARE_METHOD(PVD, PVD_NEWINDEX);
-
- DECLARE_FUNCTION(PVD, PVD_NEWPVD);
-
- private:
- static int PVD_proceed(Lua * L, int n, PVD * obj, int caller);
- static int PVD_proceed_statics(Lua * L, int n, int caller);
-};
-
-void LuaPVD::pushmembers(Lua * L) {
- pushme(L, pvd);
-
- PUSH_METAMETHOD(PVD, PVD_INDEX);
- PUSH_METAMETHOD(PVD, PVD_NEWINDEX);
-}
-
-void LuaPVD::pushstatics(Lua * L) throw (GeneralException) {
- CHECK_METHODS(PVD);
- CHECK_FUNCTIONS(PVD);
-
- PUSH_FUNCTION(PVD, PVD_NEWPVD);
-}
-
-int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) {
- int r = 0, key_i, value_i;
- String key_s, value_s;
- cddate * value_date;
- bool invalid = false, keyisstring;
-
- if (L->isnumber(2)) {
- keyisstring = false;
- key_i = L->tonumber(2);
- } else {
- keyisstring = true;
- key_s = L->tonumber(2);
- }
-
- switch (caller) {
- case PVD_INDEX:
- r = 1;
- if (keyisstring && (key_s == "sysid")) {
- L->push(pvd->sysid);
- } else if (keyisstring && (key_s == "volid")) {
- L->push(pvd->volid);
- } else if (keyisstring && (key_s == "volsetid")) {
- L->push(pvd->volsetid);
- } else if (keyisstring && (key_s == "pubid")) {
- L->push(pvd->pubid);
- } else if (keyisstring && (key_s == "prepid")) {
- L->push(pvd->prepid);
- } else if (keyisstring && (key_s == "appid")) {
- L->push(pvd->appid);
- } else if (keyisstring && (key_s == "copyright")) {
- L->push(pvd->copyright);
- } else if (keyisstring && (key_s == "abstract")) {
- L->push(pvd->abstract);
- } else if (keyisstring && (key_s == "biblio")) {
- L->push(pvd->biblio);
- } else if (keyisstring && (key_s == "volcreat")) {
- {
- Luacddate date(&pvd->volcreat);
- date.push(L);
- }
- } else if (keyisstring && (key_s == "modif")) {
- {
- Luacddate date(&pvd->modif);
- date.push(L);
- }
- } else if (keyisstring && (key_s == "volexp")) {
- {
- Luacddate date(&pvd->volexp);
- date.push(L);
- }
- } else if (keyisstring && (key_s == "voleff")) {
- {
- Luacddate date(&pvd->voleff);
- date.push(L);
- }
- } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) {
- L->push((lua_Number) pvd->appdata[key_i]);
- } else {
- invalid = true;
- }
- break;
- case PVD_NEWINDEX:
- if (keyisstring && (key_s == "sysid")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->sysid = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "volid")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->volid = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "volsetid")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->volsetid = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "pubid")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->pubid = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "prepid")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->prepid = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "appid")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->appid = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "copyright")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->copyright = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "abstract")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->abstract = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "biblio")) {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- pvd->biblio = value_s;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "volcreat")) {
- if (L->islightuserdata(3)) {
- value_date = (cddate *) LuaObject::getme(L, 3);
- pvd->volcreat = *value_date;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "modif")) {
- if (L->islightuserdata(3)) {
- value_date = (cddate *) LuaObject::getme(L, 3);
- pvd->modif = *value_date;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "volexp")) {
- if (L->islightuserdata(3)) {
- value_date = (cddate *) LuaObject::getme(L, 3);
- pvd->volexp = *value_date;
- } else {
- invalid = true;
- }
- } else if (keyisstring && (key_s == "voleff")) {
- if (L->islightuserdata(3)) {
- value_date = (cddate *) LuaObject::getme(L, 3);
- pvd->voleff = *value_date;
- } else {
- invalid = true;
- }
- } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) {
- if (L->isnumber(3)) {
- pvd->appdata[key_i] = L->tonumber(3);
- } else {
- invalid = true;
- }
- } else {
- invalid = true;
- }
- break;
- }
-
- if (invalid) {
- L->error("Invalid usage of structure PVD");
- }
-
- return r;
-}
-
-int sLua_PVD::PVD_proceed_statics(Lua * L, int n, int caller) {
- int r = 0;
-
- switch (caller) {
- case PVD_NEWPVD:
- r = 1;
- {
- LuaPVD pvd(new PVD);
- pvd.pushdestruct(L);
- }
- break;
- }
-
- return r;
-}
-
-
- /**************************\
-|** class DirTree exports **|
- \**************************/
-
-typedef isobuilder::DirTree DirTree;
-
-LuaDirTree::LuaDirTree(isobuilder::DirTree * _dir) : dir(_dir) { }
-
-enum DirTree_methods_t {
- DIRTREE_INDEX = 0,
- DIRTREE_NEWINDEX,
- DIRTREE_FROMDIR,
- DIRTREE_SETBASICSXA,
- DIRTREE_FIND,
-};
-
-enum DirTree_functions_t {
- DIRTREE_NEWDIRTREE = 0,
-};
-
-struct lua_functypes_t DirTree_methods[] = {
- { DIRTREE_INDEX, "index", 1, 1, {LUA_STRING} },
- { DIRTREE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_ANY} },
- { DIRTREE_FROMDIR, "fromdir", 1, 1, {LUA_OBJECT} },
- { DIRTREE_SETBASICSXA, "setbasicsxa", 0, 0, 0 },
- { DIRTREE_FIND, "find", 1, 1, {LUA_STRING} },
- { -1, 0, 0, 0, 0 }
-};
-
-struct lua_functypes_t DirTree_functions[] = {
- { DIRTREE_NEWDIRTREE, "DirTree", 1, 2, {LUA_OBJECT, LUA_BOOLEAN} },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_DirTree : public Base {
- public:
- DECLARE_METHOD(DirTree, DIRTREE_INDEX);
- DECLARE_METHOD(DirTree, DIRTREE_NEWINDEX);
- DECLARE_METHOD(DirTree, DIRTREE_FROMDIR);
- DECLARE_METHOD(DirTree, DIRTREE_SETBASICSXA);
- DECLARE_METHOD(DirTree, DIRTREE_FIND);
-
- DECLARE_FUNCTION(DirTree, DIRTREE_NEWDIRTREE);
- private:
- static int DirTree_proceed(Lua * L, int n, DirTree * obj, int caller);
- static int DirTree_proceed_statics(Lua * L, int n, int caller);
-};
-
-void LuaDirTree::pushmembers(Lua * L) {
- pushme(L, dir);
-
- PUSH_METAMETHOD(DirTree, DIRTREE_INDEX);
- PUSH_METAMETHOD(DirTree, DIRTREE_NEWINDEX);
-
- PUSH_METHOD(DirTree, DIRTREE_FROMDIR);
- PUSH_METHOD(DirTree, DIRTREE_SETBASICSXA);
- PUSH_METHOD(DirTree, DIRTREE_FIND);
-}
-
-void LuaDirTree::pushstatics(Lua * L) throw (GeneralException) {
- CHECK_METHODS(DirTree);
- CHECK_FUNCTIONS(DirTree);
-
- PUSH_FUNCTION(DirTree, DIRTREE_NEWDIRTREE);
-}
-
-int sLua_DirTree::DirTree_proceed(Lua * L, int n, DirTree * dir, int caller) {
- int r = 0, value_i;
- direntry * dirent;
- DirTree * rdir;
- String f, key, value_s;
- bool invalid = false, value_b;
- cddate * value_date;
-
- switch (caller) {
- case DIRTREE_FROMDIR:
- dirent = (direntry *) LuaObject::getme(L, 2);
- dir->fromdir(dirent);
- break;
- case DIRTREE_SETBASICSXA:
- dir->setbasicsxa();
- break;
- case DIRTREE_FIND:
- f = L->tostring(2);
- rdir = dir->Find(f);
- if (rdir) {
- LuaDirTree dirt(rdir);
- dirt.push(L);
- } else {
- L->push();
- }
- break;
- case DIRTREE_INDEX:
- key = L->tostring(2);
- r = 1;
- if (key == "sector") {
- L->push((lua_Number) dir->sector);
- } else if (key == "size") {
- L->push((lua_Number) dir->size);
- } else if (key == "hidden") {
- L->push(dir->hidden);
- } else if (key == "hardhide") {
- L->push(dir->hardhide);
- } else if (key == "name") {
- L->push(dir->name);
- } else if (key == "creation") {
- Luacddate date(&dir->creation);
- date.push(L);
- } else if (key == "have_xa") {
- L->push(dir->have_xa);
- } else if (key == "xa_dir") {
- L->push(dir->xa_dir);
- } else if (key == "xa_audio") {
- L->push(dir->xa_audio);
- } else if (key == "xa_str") {
- L->push(dir->xa_str);
- } else if (key == "xa_xa") {
- L->push(dir->xa_xa);
- } else if (key == "xa_form1") {
- L->push(dir->xa_form1);
- } else if (key == "mode") {
- L->push((lua_Number) dir->mode);
- } else if (key == "father") {
- LuaDirTree tdir(dir->Father());
- tdir.push(L);
- } else if (key == "child") {
- LuaDirTree tdir(dir->Child());
- tdir.push(L);
- } else if (key == "brother") {
- LuaDirTree tdir(dir->Brother());
- tdir.push(L);
- } else if (key == "isdir") {
- L->push(dir->isdir());
- } else {
- invalid = true;
- }
- break;
- case DIRTREE_NEWINDEX:
- key = L->tostring(2);
- if (key == "sector") {
- if (L->isnumber(3)) {
- value_i = L->tonumber(3);
- dir->sector = value_i;
- } else {
- invalid = true;
- }
- } else if (key == "size") {
- if (L->isnumber(3)) {
- value_i = L->tonumber(3);
- dir->size = value_i;
- } else {
- invalid = true;
- }
- } else if (key == "hidden") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->hidden = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "hardhide") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->hardhide = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "name") {
- if (L->isstring(3)) {
- value_s = L->tostring(3);
- dir->name = value_s;
- } else {
- invalid = true;
- }
- } else if (key == "creation") {
- if (L->islightuserdata(3)) {
- value_date = (cddate *) LuaObject::getme(L, 3);
- dir->creation = *value_date;
- } else {
- invalid = true;
- }
- } else if (key == "have_xa") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->have_xa = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "xa_dir") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->xa_dir = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "xa_audio") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->xa_audio = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "xa_str") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->xa_str = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "xa_xa") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->xa_xa = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "xa_form1") {
- if (L->isboolean(3)) {
- value_b = L->toboolean(3);
- dir->xa_form1 = value_b;
- } else {
- invalid = true;
- }
- } else if (key == "mode") {
- if (L->isnumber(3)) {
- value_i = L->tonumber(3);
- dir->mode = value_i;
- } else {
- invalid = true;
- }
- } else {
- invalid = true;
- }
- break;
- }
-
- if (invalid) {
- L->error("Invalid usage of structure DirTree");
- }
-
- return r;
-}
-
-int sLua_DirTree::DirTree_proceed_statics(Lua * L, int n, int caller) {
- int r;
- DirTree * father;
- bool dir = true;
-
- switch (caller) {
- case DIRTREE_NEWDIRTREE:
- father = (DirTree *) LuaObject::getme(L, 1);
- if (n == 2)
- dir = L->toboolean(2);
- {
- LuaDirTree dirt(new DirTree(father, dir));
- dirt.pushdestruct(L);
- }
- break;
- }
-
- return r;
-}
-
-
- /*****************************\
-|** class isobuilder exports **|
- \*****************************/
-
-Luaisobuilder::Luaisobuilder(isobuilder * _iso) : iso(_iso) { }
-
-enum isobuilder_methods_t {
- ISOBUILDER_FOREWORD = 0,
- ISOBUILDER_FOREWORD_HANDLE,
- ISOBUILDER_FOREWORD_ARRAY,
- ISOBUILDER_GETDISPSECT,
- ISOBUILDER_PUTFILE,
- ISOBUILDER_PUTDATAS,
- ISOBUILDER_CREATESECTOR,
- ISOBUILDER_SETEOF,
- ISOBUILDER_CLEAREOF,
- ISOBUILDER_SETBASICS,
- ISOBUILDER_CREATEDIR,
- ISOBUILDER_CREATEFILE,
- ISOBUILDER_COPYDIR,
- ISOBUILDER_CLOSE,
-};
-
-enum isobuilder_functions_t {
- ISOBUILDER_NEWISOBUILDER = 0,
- ISOBUILDER_CREATEPVD_HANDLE,
- ISOBUILDER_CREATEPVD,
- ISOBUILDER_CREATEPVD_ARRAY,
-};
-
-struct lua_functypes_t isobuilder_methods[] = {
- { ISOBUILDER_FOREWORD, "foreword", 1, 1, {LUA_OBJECT} },
- { ISOBUILDER_FOREWORD_HANDLE, "foreword_handle", 1, 2, {LUA_OBJECT, LUA_NUMBER} },
- { ISOBUILDER_FOREWORD_ARRAY, "foreword_array", 1, 2, {LUA_TABLE, LUA_NUMBER} },
- { ISOBUILDER_GETDISPSECT, "getdispsect", 0, 0, 0},
- { ISOBUILDER_PUTFILE, "putfile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} },
- { ISOBUILDER_PUTDATAS, "putdatas", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { ISOBUILDER_CREATESECTOR, "createsector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} },
- { ISOBUILDER_SETEOF, "setEOF", 0, 0, 0 },
- { ISOBUILDER_CLEAREOF, "clearEOF", 0, 0, 0 },
- { ISOBUILDER_SETBASICS, "setbasics", 1, 5, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { ISOBUILDER_CREATEDIR, "createdir", 2, 5, {LUA_OBJECT, LUA_STRING, LUA_NUMBER, LUA_OBJECT, LUA_NUMBER} },
- { ISOBUILDER_CREATEFILE, "createfile", 3, 5, {LUA_OBJECT, LUA_OBJECT, LUA_STRING, LUA_OBJECT, LUA_NUMBER} },
- { ISOBUILDER_COPYDIR, "copydir", 3, 4, {LUA_OBJECT, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} },
- { ISOBUILDER_CLOSE, "close", 0, 2, {LUA_OBJECT, LUA_NUMBER} },
- { -1, 0, 0, 0, 0 }
-};
-
-struct lua_functypes_t isobuilder_functions[] = {
- { ISOBUILDER_NEWISOBUILDER, "isobuilder", 1, 2, {LUA_OBJECT, LUA_NUMBER} },
- { ISOBUILDER_CREATEPVD_HANDLE, "createpvd_handle", 1, 1, {LUA_OBJECT} },
- { ISOBUILDER_CREATEPVD, "createpvd", 1, 1, {LUA_OBJECT} },
- { ISOBUILDER_CREATEPVD_ARRAY, "createpvd_array", 1, 1, {LUA_TABLE} },
- { -1, 0, 0, 0, 0 }
-};
-
-class sLua_isobuilder : public Base {
- public:
- DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD);
- DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE);
- DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY);
- DECLARE_METHOD(isobuilder, ISOBUILDER_GETDISPSECT);
- DECLARE_METHOD(isobuilder, ISOBUILDER_PUTFILE);
- DECLARE_METHOD(isobuilder, ISOBUILDER_PUTDATAS);
- DECLARE_METHOD(isobuilder, ISOBUILDER_CREATESECTOR);
- DECLARE_METHOD(isobuilder, ISOBUILDER_SETEOF);
- DECLARE_METHOD(isobuilder, ISOBUILDER_CLEAREOF);
- DECLARE_METHOD(isobuilder, ISOBUILDER_SETBASICS);
- DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEDIR);
- DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEFILE);
- DECLARE_METHOD(isobuilder, ISOBUILDER_COPYDIR);
- DECLARE_METHOD(isobuilder, ISOBUILDER_CLOSE);
-
- DECLARE_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER);
- DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE);
- DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD);
- DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY);
-
- private:
- static int isobuilder_proceed(Lua * L, int n, isobuilder * obj, int caller);
- static int isobuilder_proceed_statics(Lua * L, int n, int caller);
-};
-
-void Luaisobuilder::pushmembers(Lua * L) {
- pushme(L, iso);
-
- PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD);
- PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE);
- PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY);
- PUSH_METHOD(isobuilder, ISOBUILDER_GETDISPSECT);
- PUSH_METHOD(isobuilder, ISOBUILDER_PUTFILE);
- PUSH_METHOD(isobuilder, ISOBUILDER_PUTDATAS);
- PUSH_METHOD(isobuilder, ISOBUILDER_CREATESECTOR);
- PUSH_METHOD(isobuilder, ISOBUILDER_SETEOF);
- PUSH_METHOD(isobuilder, ISOBUILDER_CLEAREOF);
- PUSH_METHOD(isobuilder, ISOBUILDER_SETBASICS);
- PUSH_METHOD(isobuilder, ISOBUILDER_CREATEDIR);
- PUSH_METHOD(isobuilder, ISOBUILDER_CREATEFILE);
- PUSH_METHOD(isobuilder, ISOBUILDER_COPYDIR);
- PUSH_METHOD(isobuilder, ISOBUILDER_CLOSE);
-}
-
-void Luaisobuilder::pushstatics(Lua * L) throw (GeneralException) {
- CHECK_METHODS(isobuilder);
- CHECK_FUNCTIONS(isobuilder);
-
- PUSH_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER);
- PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE);
- PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD);
- PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY);
-}
-
-int sLua_isobuilder::isobuilder_proceed(Lua * L, int n, isobuilder * iso, int caller) {
- int r = 0, i;
- Handle * h = 0;
- int mode = -1, sector = -1, rootsize = 1, ptsize = 1, nvd = 1, rootsect = -1;
- size_t size;
- Byte datas[2352 * 16], * p;
- PVD * pvd;
- DirTree * dirt, * rdir;
- direntry * dire = 0;
- String name;
- cdutils * cd;
-
- switch (caller) {
- case ISOBUILDER_FOREWORD:
- cd = (cdutils *) LuaObject::getme(L, 2);
- iso->foreword(cd);
- break;
- case ISOBUILDER_FOREWORD_HANDLE:
- mode = MODE_RAW;
- h = (Handle *) LuaObject::getme(L, 2);
- if (n == 2)
- mode = L->tonumber(3);
- iso->foreword(h, mode);
- break;
- case ISOBUILDER_FOREWORD_ARRAY:
- mode = MODE_RAW;
- if (n == 2)
- mode = L->tonumber(3);
- for (i = 0; i < 16 * 2352; i++) {
- L->push((lua_Number) i);
- L->gettable(2);
- datas[i] = L->tonumber();
- L->pop();
- }
- iso->foreword(datas, mode);
- break;
- case ISOBUILDER_GETDISPSECT:
- L->push((lua_Number) iso->getdispsect());
- r = 1;
- break;
- case ISOBUILDER_PUTFILE:
- h = (Handle *) LuaObject::getme(L, 2);
- if (n >= 2)
- mode = L->tonumber(3);
- if (n >= 3)
- sector = L->tonumber(4);
- L->push((lua_Number) iso->putfile(h, mode, sector));
- r = 1;
- break;
- case ISOBUILDER_PUTDATAS:
- size = L->tonumber(3);
- if (n >= 3)
- mode = L->tonumber(4);
- if (n >= 4)
- sector = L->tonumber(5);
- p = (Byte *) malloc(size);
- for (i = 0; i < size; i++) {
- L->push((lua_Number) i);
- L->gettable(2);
- p[i] = L->tonumber();
- L->pop();
- }
- L->push((lua_Number) iso->putdatas(p, size, mode, sector));
- r = 1;
- free(p);
- break;
- case ISOBUILDER_CREATESECTOR:
- if (n >= 2)
- mode = L->tonumber(3);
- if (n >= 3)
- sector = L->tonumber(4);
- for (i = 0; i < 2352; i++) {
- L->push((lua_Number) i);
- L->gettable(2);
- datas[i] = L->tonumber();
- L->pop();
- }
- L->push((lua_Number) iso->createsector(datas, mode, sector));
- r = 1;
- break;
- case ISOBUILDER_SETEOF:
- iso->setEOF();
- break;
- case ISOBUILDER_CLEAREOF:
- iso->clearEOF();
- break;
- case ISOBUILDER_SETBASICS:
- pvd = (PVD *) LuaObject::getme(L, 2);
- if (n >= 2)
- rootsize = L->tonumber(3);
- if (n >= 3)
- ptsize = L->tonumber(4);
- if (n >= 4)
- nvd = L->tonumber(5);
- if (n >= 5)
- rootsect = L->tonumber(6);
- rdir = iso->setbasics(*pvd, rootsize, ptsize, nvd, rootsect);
- {
- LuaDirTree t(rdir);
- t.push(L);
- }
- r = 1;
- break;
- case ISOBUILDER_CREATEDIR:
- size = 1;
- dirt = 0;
- dirt = (DirTree *) LuaObject::getme(L, 2);
- name = L->tostring(3);
- if (n >= 3)
- size = L->tonumber(4);
- if (n >= 4)
- dire = (direntry *) LuaObject::getme(L, 5);
- if (n >= 5)
- mode = L->tonumber(6);
- rdir = iso->createdir(dirt, name, size, dire, mode);
- {
- LuaDirTree t(rdir);
- t.push(L);
- }
- r = 1;
- break;
- case ISOBUILDER_CREATEFILE:
- dirt = (DirTree *) LuaObject::getme(L, 2);
- h = (Handle *) LuaObject::getme(L, 3);
- name = L->tostring(4);
- if (n >= 4)
- dire = (direntry *) LuaObject::getme(L, 5);
- if (n >= 5)
- mode = L->tonumber(6);
- rdir = iso->createfile(dirt, h, name, dire, mode);
- {
- LuaDirTree t(rdir);
- t.push(L);
- }
- r = 1;
- break;
- case ISOBUILDER_COPYDIR:
- dirt = (DirTree *) LuaObject::getme(L, 2);
- cd = (cdutils *) LuaObject::getme(L, 3);
- dire = (direntry *) LuaObject::getme(L, 4);
- if (n >= 4)
- mode = L->tonumber(5);
- iso->copydir(dirt, cd, dire, mode);
- break;
- case ISOBUILDER_CLOSE:
- if (n >= 1)
- h = (Handle *) LuaObject::getme(L, 2);
- if (n >= 2)
- mode = L->tonumber(3);
- iso->close(h, mode);
- break;
- }
-
- return r;
-}
-
-int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) {
- int r = 0, i;
- Handle * h;
- int mode = MODE2_FORM1;
- cdutils * cd;
- Byte datas[2048];
- PVD * pvd;
-
- switch (caller) {
- case ISOBUILDER_NEWISOBUILDER:
- h = (Handle *) LuaObject::getme(L, 1);
- if (n >= 2)
- mode = L->tonumber();
- {
- Luaisobuilder t(new isobuilder(h, mode));
- t.pushdestruct(L);
- }
- r = 1;
- break;
- case ISOBUILDER_CREATEPVD_HANDLE:
- h = (Handle *) LuaObject::getme(L, 1);
- pvd = new PVD(isobuilder::createpvd(h));
- {
- LuaPVD t(pvd);
- t.pushdestruct(L);
- }
- r = 1;
- break;
- case ISOBUILDER_CREATEPVD:
- cd = (cdutils *) LuaObject::getme(L, 1);
- pvd = new PVD(isobuilder::createpvd(cd));
- {
- LuaPVD t(pvd);
- t.pushdestruct(L);
- }
- r = 1;
- break;
- case ISOBUILDER_CREATEPVD_ARRAY:
- for (i = 0; i < 2048; i++) {
- L->push((lua_Number) i);
- L->gettable(1);
- datas[i] = L->tonumber();
- L->pop();
- }
- pvd = new PVD(isobuilder::createpvd(datas));
- {
- LuaPVD t(pvd);
- t.pushdestruct(L);
- }
- r = 1;
- break;
- }
-
- return r;
-}
+ if ((p[6] == 'X') && (p[7] == 'A')) { + has_xa = true; + } + } + } + + switch (caller) { + case DIRENTRY_HASXA: + L->push(has_xa); + r = 1; + break; + case DIRENTRY_ISHIDDEN: + L->push(dir->Flags & 1 ? true : false); + r = 1; + break; + case DIRENTRY_ISDIR: + L->push(dir->Flags & 2 ? true : false); + r = 1; + break; + case DIRENTRY_ISXADIR: + L->push(p[4] & 0x80 ? true : false); + r = 1; + break; + case DIRENTRY_ISXAAUDIO: + L->push(p[4] & 0x40 ? true : false); + r = 1; + break; + case DIRENTRY_ISXASTR: + L->push(p[4] & 0x20 ? true : false); + r = 1; + break; + case DIRENTRY_ISXAXA: + L->push(p[4] & 0x10 ? true : false); + r = 1; + break; + case DIRENTRY_ISXAFORM1: + L->push(p[4] & 0x08 ? true : false); + r = 1; + break; + case DIRENTRY_INDEX: + index = L->tostring(); + r = 1; + if (index == "R") { + L->push((lua_Number) dir->R); + } else if (index == "NExt") { + L->push((lua_Number) dir->NExt); + } else if (index == "Sector") { + L->push((lua_Number) dir->Sector); + } else if (index == "Size") { + L->push((lua_Number) dir->Size); + } else if (index == "Year") { + L->push((lua_Number) dir->Year); + } else if (index == "Month") { + L->push((lua_Number) dir->Month); + } else if (index == "Day") { + L->push((lua_Number) dir->Day); + } else if (index == "Hour") { + L->push((lua_Number) dir->Hour); + } else if (index == "Minute") { + L->push((lua_Number) dir->Minute); + } else if (index == "Second") { + L->push((lua_Number) dir->Second); + } else if (index == "Offset") { + L->push((lua_Number) dir->Offset); + } else if (index == "Flags") { + L->push((lua_Number) dir->Flags); + } else if (index == "HandleUnit") { + L->push((lua_Number) dir->HandleUnit); + } else if (index == "HandleGap") { + L->push((lua_Number) dir->HandleGap); + } else if (index == "VolSeq") { + L->push((lua_Number) dir->VolSeq); + } else if (index == "N") { + L->push((lua_Number) dir->N); + } else if (index == "id") { + char pbuf[256]; + memcpy(pbuf, dir->id, dir->N); + pbuf[dir->N] = 0; + L->push(pbuf, dir->N); + } else { + L->push(); + } + } + + return r; +} + + + /***************************\ +|** class direntry exports **| + \***************************/ + +typedef isobuilder::Date cddate; + +Luacddate::Luacddate(isobuilder::Date * _date) : date(_date) { } + +enum cddate_methods_t { + CDDATE_INDEX = 0, + CDDATE_NEWINDEX, +}; + +enum cddate_functions_t { + CDDATE_NEWCDDATE = 0, +}; + +struct lua_functypes_t cddate_methods[] = { + { CDDATE_INDEX, "index", 1, 1, {LUA_STRING} }, + { CDDATE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t cddate_functions[] = { + { CDDATE_NEWCDDATE, "cddate", 0, 0, 0 }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_cddate : public Base { + public: + DECLARE_METHOD(cddate, CDDATE_INDEX); + DECLARE_METHOD(cddate, CDDATE_NEWINDEX); + DECLARE_FUNCTION(cddate, CDDATE_NEWCDDATE); + private: + static int cddate_proceed(Lua * L, int n, cddate * obj, int caller); + static int cddate_proceed_statics(Lua * L, int n, int caller); +}; + +void Luacddate::pushmembers(Lua * L) { + pushme(L, date); + + PUSH_METAMETHOD(cddate, CDDATE_INDEX); + PUSH_METAMETHOD(cddate, CDDATE_NEWINDEX); +} + +void Luacddate::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(cddate); + CHECK_FUNCTIONS(cddate); + + PUSH_FUNCTION(cddate, CDDATE_NEWCDDATE); +} + +int sLua_cddate::cddate_proceed(Lua * L, int n, cddate * date, int caller) { + int r, value; + String key; + + switch (caller) { + case CDDATE_INDEX: + key = L->tostring(2); + r = 1; + if (key == "year") { + L->push((lua_Number) date->year); + } else if (key == "month") { + L->push((lua_Number) date->month); + } else if (key == "day") { + L->push((lua_Number) date->day); + } else if (key == "hour") { + L->push((lua_Number) date->hour); + } else if (key == "minute") { + L->push((lua_Number) date->minute); + } else if (key == "second") { + L->push((lua_Number) date->second); + } else if (key == "hundredths") { + L->push((lua_Number) date->hundredths); + } else if (key == "offset") { + L->push((lua_Number) date->offset); + } else { + L->error("Key " + key + " not in class Date"); + } + break; + case CDDATE_NEWINDEX: + key = L->tostring(2); + value = L->tonumber(3); + if (key == "year") { + date->year = value; + } else if (key == "month") { + date->month = value; + } else if (key == "day") { + date->day = value; + } else if (key == "hour") { + date->hour = value; + } else if (key == "minute") { + date->minute = value; + } else if (key == "second") { + date->second = value; + } else if (key == "hundredths") { + date->hundredths = value; + } else if (key == "offset") { + date->offset = value; + } else { + L->error("Key " + key + " not in class Date"); + } + break; + } + + return r; +} + +int sLua_cddate::cddate_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + + switch (caller) { + case CDDATE_NEWCDDATE: + { + Luacddate t(new cddate()); + t.pushdestruct(L); + } + } + + return r; +} + + /**********************\ +|** class PVD exports **| + \**********************/ + +typedef isobuilder::PVD PVD; + +LuaPVD::LuaPVD(struct isobuilder::PVD * _pvd) : pvd(_pvd) { } + +enum PVD_methods_t { + PVD_INDEX = 0, + PVD_NEWINDEX, +}; + +enum PVD_functions_t { + PVD_NEWPVD = 0, +}; + +struct lua_functypes_t PVD_methods[] = { + { PVD_INDEX, "index", 1, 1, {LUA_ANY} }, + { PVD_NEWINDEX, "newindex", 2, 2, {LUA_ANY, LUA_ANY} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t PVD_functions[] = { + { PVD_NEWPVD, "PVD", 0, 0, 0 }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_PVD : public Base { + public: + DECLARE_METHOD(PVD, PVD_INDEX); + DECLARE_METHOD(PVD, PVD_NEWINDEX); + + DECLARE_FUNCTION(PVD, PVD_NEWPVD); + + private: + static int PVD_proceed(Lua * L, int n, PVD * obj, int caller); + static int PVD_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaPVD::pushmembers(Lua * L) { + pushme(L, pvd); + + PUSH_METAMETHOD(PVD, PVD_INDEX); + PUSH_METAMETHOD(PVD, PVD_NEWINDEX); +} + +void LuaPVD::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(PVD); + CHECK_FUNCTIONS(PVD); + + PUSH_FUNCTION(PVD, PVD_NEWPVD); +} + +int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) { + int r = 0, key_i, value_i; + String key_s, value_s; + cddate * value_date; + bool invalid = false, keyisstring; + + if (L->isnumber(2)) { + keyisstring = false; + key_i = L->tonumber(2); + } else { + keyisstring = true; + key_s = L->tonumber(2); + } + + switch (caller) { + case PVD_INDEX: + r = 1; + if (keyisstring && (key_s == "sysid")) { + L->push(pvd->sysid); + } else if (keyisstring && (key_s == "volid")) { + L->push(pvd->volid); + } else if (keyisstring && (key_s == "volsetid")) { + L->push(pvd->volsetid); + } else if (keyisstring && (key_s == "pubid")) { + L->push(pvd->pubid); + } else if (keyisstring && (key_s == "prepid")) { + L->push(pvd->prepid); + } else if (keyisstring && (key_s == "appid")) { + L->push(pvd->appid); + } else if (keyisstring && (key_s == "copyright")) { + L->push(pvd->copyright); + } else if (keyisstring && (key_s == "abstract")) { + L->push(pvd->abstract); + } else if (keyisstring && (key_s == "biblio")) { + L->push(pvd->biblio); + } else if (keyisstring && (key_s == "volcreat")) { + { + Luacddate date(&pvd->volcreat); + date.push(L); + } + } else if (keyisstring && (key_s == "modif")) { + { + Luacddate date(&pvd->modif); + date.push(L); + } + } else if (keyisstring && (key_s == "volexp")) { + { + Luacddate date(&pvd->volexp); + date.push(L); + } + } else if (keyisstring && (key_s == "voleff")) { + { + Luacddate date(&pvd->voleff); + date.push(L); + } + } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { + L->push((lua_Number) pvd->appdata[key_i]); + } else { + invalid = true; + } + break; + case PVD_NEWINDEX: + if (keyisstring && (key_s == "sysid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->sysid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->volid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volsetid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->volsetid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "pubid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->pubid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "prepid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->prepid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "appid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->appid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "copyright")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->copyright = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "abstract")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->abstract = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "biblio")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->biblio = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volcreat")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->volcreat = *value_date; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "modif")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->modif = *value_date; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volexp")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->volexp = *value_date; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "voleff")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->voleff = *value_date; + } else { + invalid = true; + } + } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { + if (L->isnumber(3)) { + pvd->appdata[key_i] = L->tonumber(3); + } else { + invalid = true; + } + } else { + invalid = true; + } + break; + } + + if (invalid) { + L->error("Invalid usage of structure PVD"); + } + + return r; +} + +int sLua_PVD::PVD_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + + switch (caller) { + case PVD_NEWPVD: + r = 1; + { + LuaPVD pvd(new PVD); + pvd.pushdestruct(L); + } + break; + } + + return r; +} + + + /**************************\ +|** class DirTree exports **| + \**************************/ + +typedef isobuilder::DirTree DirTree; + +LuaDirTree::LuaDirTree(isobuilder::DirTree * _dir) : dir(_dir) { } + +enum DirTree_methods_t { + DIRTREE_INDEX = 0, + DIRTREE_NEWINDEX, + DIRTREE_FROMDIR, + DIRTREE_SETBASICSXA, + DIRTREE_FIND, +}; + +enum DirTree_functions_t { + DIRTREE_NEWDIRTREE = 0, +}; + +struct lua_functypes_t DirTree_methods[] = { + { DIRTREE_INDEX, "index", 1, 1, {LUA_STRING} }, + { DIRTREE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_ANY} }, + { DIRTREE_FROMDIR, "fromdir", 1, 1, {LUA_OBJECT} }, + { DIRTREE_SETBASICSXA, "setbasicsxa", 0, 0, 0 }, + { DIRTREE_FIND, "find", 1, 1, {LUA_STRING} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t DirTree_functions[] = { + { DIRTREE_NEWDIRTREE, "DirTree", 1, 2, {LUA_OBJECT, LUA_BOOLEAN} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_DirTree : public Base { + public: + DECLARE_METHOD(DirTree, DIRTREE_INDEX); + DECLARE_METHOD(DirTree, DIRTREE_NEWINDEX); + DECLARE_METHOD(DirTree, DIRTREE_FROMDIR); + DECLARE_METHOD(DirTree, DIRTREE_SETBASICSXA); + DECLARE_METHOD(DirTree, DIRTREE_FIND); + + DECLARE_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); + private: + static int DirTree_proceed(Lua * L, int n, DirTree * obj, int caller); + static int DirTree_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaDirTree::pushmembers(Lua * L) { + pushme(L, dir); + + PUSH_METAMETHOD(DirTree, DIRTREE_INDEX); + PUSH_METAMETHOD(DirTree, DIRTREE_NEWINDEX); + + PUSH_METHOD(DirTree, DIRTREE_FROMDIR); + PUSH_METHOD(DirTree, DIRTREE_SETBASICSXA); + PUSH_METHOD(DirTree, DIRTREE_FIND); +} + +void LuaDirTree::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(DirTree); + CHECK_FUNCTIONS(DirTree); + + PUSH_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); +} + +int sLua_DirTree::DirTree_proceed(Lua * L, int n, DirTree * dir, int caller) { + int r = 0, value_i; + direntry * dirent; + DirTree * rdir; + String f, key, value_s; + bool invalid = false, value_b; + cddate * value_date; + + switch (caller) { + case DIRTREE_FROMDIR: + dirent = (direntry *) LuaObject::getme(L, 2); + dir->fromdir(dirent); + break; + case DIRTREE_SETBASICSXA: + dir->setbasicsxa(); + break; + case DIRTREE_FIND: + f = L->tostring(2); + rdir = dir->Find(f); + if (rdir) { + LuaDirTree dirt(rdir); + dirt.push(L); + } else { + L->push(); + } + break; + case DIRTREE_INDEX: + key = L->tostring(2); + r = 1; + if (key == "sector") { + L->push((lua_Number) dir->sector); + } else if (key == "size") { + L->push((lua_Number) dir->size); + } else if (key == "hidden") { + L->push(dir->hidden); + } else if (key == "hardhide") { + L->push(dir->hardhide); + } else if (key == "name") { + L->push(dir->name); + } else if (key == "creation") { + Luacddate date(&dir->creation); + date.push(L); + } else if (key == "have_xa") { + L->push(dir->have_xa); + } else if (key == "xa_dir") { + L->push(dir->xa_dir); + } else if (key == "xa_audio") { + L->push(dir->xa_audio); + } else if (key == "xa_str") { + L->push(dir->xa_str); + } else if (key == "xa_xa") { + L->push(dir->xa_xa); + } else if (key == "xa_form1") { + L->push(dir->xa_form1); + } else if (key == "mode") { + L->push((lua_Number) dir->mode); + } else if (key == "father") { + LuaDirTree tdir(dir->Father()); + tdir.push(L); + } else if (key == "child") { + LuaDirTree tdir(dir->Child()); + tdir.push(L); + } else if (key == "brother") { + LuaDirTree tdir(dir->Brother()); + tdir.push(L); + } else if (key == "isdir") { + L->push(dir->isdir()); + } else { + invalid = true; + } + break; + case DIRTREE_NEWINDEX: + key = L->tostring(2); + if (key == "sector") { + if (L->isnumber(3)) { + value_i = L->tonumber(3); + dir->sector = value_i; + } else { + invalid = true; + } + } else if (key == "size") { + if (L->isnumber(3)) { + value_i = L->tonumber(3); + dir->size = value_i; + } else { + invalid = true; + } + } else if (key == "hidden") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->hidden = value_b; + } else { + invalid = true; + } + } else if (key == "hardhide") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->hardhide = value_b; + } else { + invalid = true; + } + } else if (key == "name") { + if (L->isstring(3)) { + value_s = L->tostring(3); + dir->name = value_s; + } else { + invalid = true; + } + } else if (key == "creation") { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + dir->creation = *value_date; + } else { + invalid = true; + } + } else if (key == "have_xa") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->have_xa = value_b; + } else { + invalid = true; + } + } else if (key == "xa_dir") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_dir = value_b; + } else { + invalid = true; + } + } else if (key == "xa_audio") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_audio = value_b; + } else { + invalid = true; + } + } else if (key == "xa_str") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_str = value_b; + } else { + invalid = true; + } + } else if (key == "xa_xa") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_xa = value_b; + } else { + invalid = true; + } + } else if (key == "xa_form1") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_form1 = value_b; + } else { + invalid = true; + } + } else if (key == "mode") { + if (L->isnumber(3)) { + value_i = L->tonumber(3); + dir->mode = value_i; + } else { + invalid = true; + } + } else { + invalid = true; + } + break; + } + + if (invalid) { + L->error("Invalid usage of structure DirTree"); + } + + return r; +} + +int sLua_DirTree::DirTree_proceed_statics(Lua * L, int n, int caller) { + int r; + DirTree * father; + bool dir = true; + + switch (caller) { + case DIRTREE_NEWDIRTREE: + father = (DirTree *) LuaObject::getme(L, 1); + if (n == 2) + dir = L->toboolean(2); + { + LuaDirTree dirt(new DirTree(father, dir)); + dirt.pushdestruct(L); + } + break; + } + + return r; +} + + + /*****************************\ +|** class isobuilder exports **| + \*****************************/ + +Luaisobuilder::Luaisobuilder(isobuilder * _iso) : iso(_iso) { } + +enum isobuilder_methods_t { + ISOBUILDER_FOREWORD = 0, + ISOBUILDER_FOREWORD_HANDLE, + ISOBUILDER_FOREWORD_ARRAY, + ISOBUILDER_GETDISPSECT, + ISOBUILDER_PUTFILE, + ISOBUILDER_PUTDATAS, + ISOBUILDER_CREATESECTOR, + ISOBUILDER_SETEOF, + ISOBUILDER_CLEAREOF, + ISOBUILDER_SETBASICS, + ISOBUILDER_CREATEDIR, + ISOBUILDER_CREATEFILE, + ISOBUILDER_COPYDIR, + ISOBUILDER_CLOSE, +}; + +enum isobuilder_functions_t { + ISOBUILDER_NEWISOBUILDER = 0, + ISOBUILDER_CREATEPVD_HANDLE, + ISOBUILDER_CREATEPVD, + ISOBUILDER_CREATEPVD_ARRAY, +}; + +struct lua_functypes_t isobuilder_methods[] = { + { ISOBUILDER_FOREWORD, "foreword", 1, 1, {LUA_OBJECT} }, + { ISOBUILDER_FOREWORD_HANDLE, "foreword_handle", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_FOREWORD_ARRAY, "foreword_array", 1, 2, {LUA_TABLE, LUA_NUMBER} }, + { ISOBUILDER_GETDISPSECT, "getdispsect", 0, 0, 0}, + { ISOBUILDER_PUTFILE, "putfile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_PUTDATAS, "putdatas", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_CREATESECTOR, "createsector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_SETEOF, "setEOF", 0, 0, 0 }, + { ISOBUILDER_CLEAREOF, "clearEOF", 0, 0, 0 }, + { ISOBUILDER_SETBASICS, "setbasics", 1, 5, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_CREATEDIR, "createdir", 2, 5, {LUA_OBJECT, LUA_STRING, LUA_NUMBER, LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_CREATEFILE, "createfile", 3, 5, {LUA_OBJECT, LUA_OBJECT, LUA_STRING, LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_COPYDIR, "copydir", 3, 4, {LUA_OBJECT, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_CLOSE, "close", 0, 2, {LUA_OBJECT, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t isobuilder_functions[] = { + { ISOBUILDER_NEWISOBUILDER, "isobuilder", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_CREATEPVD_HANDLE, "createpvd_handle", 1, 1, {LUA_OBJECT} }, + { ISOBUILDER_CREATEPVD, "createpvd", 1, 1, {LUA_OBJECT} }, + { ISOBUILDER_CREATEPVD_ARRAY, "createpvd_array", 1, 1, {LUA_TABLE} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_isobuilder : public Base { + public: + DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD); + DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); + DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); + DECLARE_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); + DECLARE_METHOD(isobuilder, ISOBUILDER_PUTFILE); + DECLARE_METHOD(isobuilder, ISOBUILDER_PUTDATAS); + DECLARE_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); + DECLARE_METHOD(isobuilder, ISOBUILDER_SETEOF); + DECLARE_METHOD(isobuilder, ISOBUILDER_CLEAREOF); + DECLARE_METHOD(isobuilder, ISOBUILDER_SETBASICS); + DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEDIR); + DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEFILE); + DECLARE_METHOD(isobuilder, ISOBUILDER_COPYDIR); + DECLARE_METHOD(isobuilder, ISOBUILDER_CLOSE); + + DECLARE_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); + DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); + DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); + DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); + + private: + static int isobuilder_proceed(Lua * L, int n, isobuilder * obj, int caller); + static int isobuilder_proceed_statics(Lua * L, int n, int caller); +}; + +void Luaisobuilder::pushmembers(Lua * L) { + pushme(L, iso); + + PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD); + PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); + PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); + PUSH_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); + PUSH_METHOD(isobuilder, ISOBUILDER_PUTFILE); + PUSH_METHOD(isobuilder, ISOBUILDER_PUTDATAS); + PUSH_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); + PUSH_METHOD(isobuilder, ISOBUILDER_SETEOF); + PUSH_METHOD(isobuilder, ISOBUILDER_CLEAREOF); + PUSH_METHOD(isobuilder, ISOBUILDER_SETBASICS); + PUSH_METHOD(isobuilder, ISOBUILDER_CREATEDIR); + PUSH_METHOD(isobuilder, ISOBUILDER_CREATEFILE); + PUSH_METHOD(isobuilder, ISOBUILDER_COPYDIR); + PUSH_METHOD(isobuilder, ISOBUILDER_CLOSE); +} + +void Luaisobuilder::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(isobuilder); + CHECK_FUNCTIONS(isobuilder); + + PUSH_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); + PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); + PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); + PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); +} + +int sLua_isobuilder::isobuilder_proceed(Lua * L, int n, isobuilder * iso, int caller) { + int r = 0, i; + Handle * h = 0; + int mode = -1, sector = -1, rootsize = 1, ptsize = 1, nvd = 1, rootsect = -1; + size_t size; + Byte datas[2352 * 16], * p; + PVD * pvd; + DirTree * dirt, * rdir; + direntry * dire = 0; + String name; + cdutils * cd; + + switch (caller) { + case ISOBUILDER_FOREWORD: + cd = (cdutils *) LuaObject::getme(L, 2); + iso->foreword(cd); + break; + case ISOBUILDER_FOREWORD_HANDLE: + mode = MODE_RAW; + h = (Handle *) LuaObject::getme(L, 2); + if (n == 2) + mode = L->tonumber(3); + iso->foreword(h, mode); + break; + case ISOBUILDER_FOREWORD_ARRAY: + mode = MODE_RAW; + if (n == 2) + mode = L->tonumber(3); + for (i = 0; i < 16 * 2352; i++) { + L->push((lua_Number) i); + L->gettable(2); + datas[i] = L->tonumber(); + L->pop(); + } + iso->foreword(datas, mode); + break; + case ISOBUILDER_GETDISPSECT: + L->push((lua_Number) iso->getdispsect()); + r = 1; + break; + case ISOBUILDER_PUTFILE: + h = (Handle *) LuaObject::getme(L, 2); + if (n >= 2) + mode = L->tonumber(3); + if (n >= 3) + sector = L->tonumber(4); + L->push((lua_Number) iso->putfile(h, mode, sector)); + r = 1; + break; + case ISOBUILDER_PUTDATAS: + size = L->tonumber(3); + if (n >= 3) + mode = L->tonumber(4); + if (n >= 4) + sector = L->tonumber(5); + p = (Byte *) malloc(size); + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->gettable(2); + p[i] = L->tonumber(); + L->pop(); + } + L->push((lua_Number) iso->putdatas(p, size, mode, sector)); + r = 1; + free(p); + break; + case ISOBUILDER_CREATESECTOR: + if (n >= 2) + mode = L->tonumber(3); + if (n >= 3) + sector = L->tonumber(4); + for (i = 0; i < 2352; i++) { + L->push((lua_Number) i); + L->gettable(2); + datas[i] = L->tonumber(); + L->pop(); + } + L->push((lua_Number) iso->createsector(datas, mode, sector)); + r = 1; + break; + case ISOBUILDER_SETEOF: + iso->setEOF(); + break; + case ISOBUILDER_CLEAREOF: + iso->clearEOF(); + break; + case ISOBUILDER_SETBASICS: + pvd = (PVD *) LuaObject::getme(L, 2); + if (n >= 2) + rootsize = L->tonumber(3); + if (n >= 3) + ptsize = L->tonumber(4); + if (n >= 4) + nvd = L->tonumber(5); + if (n >= 5) + rootsect = L->tonumber(6); + rdir = iso->setbasics(*pvd, rootsize, ptsize, nvd, rootsect); + { + LuaDirTree t(rdir); + t.push(L); + } + r = 1; + break; + case ISOBUILDER_CREATEDIR: + size = 1; + dirt = 0; + dirt = (DirTree *) LuaObject::getme(L, 2); + name = L->tostring(3); + if (n >= 3) + size = L->tonumber(4); + if (n >= 4) + dire = (direntry *) LuaObject::getme(L, 5); + if (n >= 5) + mode = L->tonumber(6); + rdir = iso->createdir(dirt, name, size, dire, mode); + { + LuaDirTree t(rdir); + t.push(L); + } + r = 1; + break; + case ISOBUILDER_CREATEFILE: + dirt = (DirTree *) LuaObject::getme(L, 2); + h = (Handle *) LuaObject::getme(L, 3); + name = L->tostring(4); + if (n >= 4) + dire = (direntry *) LuaObject::getme(L, 5); + if (n >= 5) + mode = L->tonumber(6); + rdir = iso->createfile(dirt, h, name, dire, mode); + { + LuaDirTree t(rdir); + t.push(L); + } + r = 1; + break; + case ISOBUILDER_COPYDIR: + dirt = (DirTree *) LuaObject::getme(L, 2); + cd = (cdutils *) LuaObject::getme(L, 3); + dire = (direntry *) LuaObject::getme(L, 4); + if (n >= 4) + mode = L->tonumber(5); + iso->copydir(dirt, cd, dire, mode); + break; + case ISOBUILDER_CLOSE: + if (n >= 1) + h = (Handle *) LuaObject::getme(L, 2); + if (n >= 2) + mode = L->tonumber(3); + iso->close(h, mode); + break; + } + + return r; +} + +int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) { + int r = 0, i; + Handle * h; + int mode = MODE2_FORM1; + cdutils * cd; + Byte datas[2048]; + PVD * pvd; + + switch (caller) { + case ISOBUILDER_NEWISOBUILDER: + h = (Handle *) LuaObject::getme(L, 1); + if (n >= 2) + mode = L->tonumber(); + { + Luaisobuilder t(new isobuilder(h, mode)); + t.pushdestruct(L); + } + r = 1; + break; + case ISOBUILDER_CREATEPVD_HANDLE: + h = (Handle *) LuaObject::getme(L, 1); + pvd = new PVD(isobuilder::createpvd(h)); + { + LuaPVD t(pvd); + t.pushdestruct(L); + } + r = 1; + break; + case ISOBUILDER_CREATEPVD: + cd = (cdutils *) LuaObject::getme(L, 1); + pvd = new PVD(isobuilder::createpvd(cd)); + { + LuaPVD t(pvd); + t.pushdestruct(L); + } + r = 1; + break; + case ISOBUILDER_CREATEPVD_ARRAY: + for (i = 0; i < 2048; i++) { + L->push((lua_Number) i); + L->gettable(1); + datas[i] = L->tonumber(); + L->pop(); + } + pvd = new PVD(isobuilder::createpvd(datas)); + { + LuaPVD t(pvd); + t.pushdestruct(L); + } + r = 1; + break; + } + + return r; +} |