int main () { int ret; ret = xz_decompress (stdin, stdout); return ret; }
int crPlayerLoadFile(void *context, const char *filename, unsigned char *data, int size) { gmeContext *gme = (gmeContext*)context; int i; /* check if the data is compressed with XZ */ if ((data[0] == 0xFD) && (data[1] == '7') && (data[2] == 'z') && (data[3] == 'X') && (data[4] == 'Z')) { /* compressed with XZ-embedded; decompress */ if (!xz_decompress(data, size, &gme->dataBuffer, &gme->dataBufferSize)) { free(gme->dataBuffer); return 0; } } else { /* not compressed; move to internal buffer */ gme->dataBufferSize = size; gme->dataBuffer = (uint8_t*)malloc(gme->dataBufferSize); if (!gme->dataBuffer) return 0; memcpy(gme->dataBuffer, data, gme->dataBufferSize); } /* check if this is a .gamemusic file */ if (strncmp((char *)gme->dataBuffer, "Game Music Files", 16) == 0) { /* it's a .gamemusic file; parse out a table of offsets and sizes */ gme->isGameMusicArchive = 1; gme->trackCount = (gme->dataBuffer[16] << 24) | (gme->dataBuffer[17] << 16) | (gme->dataBuffer[18] << 8) | (gme->dataBuffer[19] << 0); gme->entries = (fileEntry*)malloc(gme->trackCount * sizeof(fileEntry)); if (!gme->entries) { return 0; } /* gather up the offsets */ for (i = 0; i < gme->trackCount; i++) { gme->entries[i].offset = (gme->dataBuffer[20 + i * 4 + 0] << 24) | (gme->dataBuffer[20 + i * 4 + 1] << 16) | (gme->dataBuffer[20 + i * 4 + 2] << 8) | (gme->dataBuffer[20 + i * 4 + 3] << 0); } /* derive the sizes based on the offsets */ for (i = 0; i < gme->trackCount - 1; i++) { gme->entries[i].size = gme->entries[i + 1].offset - gme->entries[i].offset; } /* last size takes data size into account */ gme->entries[gme->trackCount - 1].size = gme->dataBufferSize - gme->entries[gme->trackCount - 1].offset; } return 1; }