view system/file.h @ 47:5f548e5957a8

* get rid of the "deprecated conversion from string constant to ‘char*’" warnings
author thib
date Wed, 15 Apr 2009 20:26:32 +0000
parents 2c574c3d50a9
children 15a18fbe6f21
line wrap: on
line source

/*  file.h  : KANON ¤Î°µ½Ì¥Õ¥¡¥¤¥ë¡¦PDT ¥Õ¥¡¥¤¥ë¡Ê²èÁü¥Õ¥¡¥¤¥ë¡Ë¤ÎŸ³«¤Î
 *            ¤¿¤á¤Î¥¯¥é¥¹
 *     class FILESEARCH : ¥Õ¥¡¥¤¥ë¤Î´ÉÍý¤ò¹Ô¤¦
 *     class ARCINFO : ½ñ¸Ë¥Õ¥¡¥¤¥ë¤ÎÃæ¤Î£±¤Ä¤Î¥Õ¥¡¥¤¥ë¤ò°·¤¦¥¯¥é¥¹
 *     class PDTCONV : PDT ¥Õ¥¡¥¤¥ë¤ÎŸ³«¤ò¹Ô¤¦¡£
 */

/*
 *
 *  Copyright (C) 2000-   Kazunori Ueno(JAGARL) <jagarl@creator.club.ne.jp>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
*/

#ifndef __KANON_FILE_H__
#define __KANON_FILE_H__

#ifndef DIR_SPLIT
#define DIR_SPLIT '/'	/* UNIX */
#endif

// read 'KANON' compressed file

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#if defined(__sparc) || defined(sparc)
#  if !defined(WORDS_BIGENDIAN)
#    define WORDS_BIGENDIAN 1
#  endif
#endif

#define INT_SIZE 4

static int read_little_endian_int(const char* buf) {
	const unsigned char *p = (const unsigned char *) buf;
	return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
}

static int read_little_endian_short(const char* buf) {
	const unsigned char *p = (const unsigned char *) buf;
	return (p[1] << 8) | p[0];
}

static int write_little_endian_int(char* buf, int number) {
	int c = read_little_endian_int(buf);
	unsigned char *p = (unsigned char *) buf;
	unsigned int unum = (unsigned int) number;
	p[0] = unum & 255;
	unum >>= 8;
	p[1] = unum & 255;
	unum >>= 8;
	p[2] = unum & 255;
	unum >>= 8;
	p[3] = unum & 255;
	return c;
}

static int write_little_endian_short(char* buf, int number) {
	int c = read_little_endian_short(buf);
	unsigned char *p = (unsigned char *) buf;
	unsigned int unum = (unsigned int) number;
	p[0] = unum & 255;
	unum >>= 8;
	p[1] = unum & 255;
	return c;
}


/*********************************************
**  FILESEARCH:
**	½ñ¸Ë¥Õ¥¡¥¤¥ë¡¿¥Ç¥£¥ì¥¯¥È¥ê¤ò´Þ¤á¡¢
**	Á´¥Õ¥¡¥¤¥ë¤Î´ÉÍý¤ò¹Ô¤¦¡£
**
**	ºÇ½é¤Ë¡¢ÀßÄê¥Õ¥¡¥¤¥ë¤«¤é¥Õ¥¡¥¤¥ë¤Î¼ïÎऴ¤È¤Ë
**	¼ÂºÝ¤ËÆþ¤Ã¤Æ¤¤¤ë¥Ç¥£¥ì¥¯¥È¥ê¡¢½ñ¸Ë¤òÀßÄꤹ¤ë
**
**	°Ê¹ß¤ÏFind() ¥á¥½¥Ã¥É¤Ç¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¤ÎÆâÍƤòÆÀ¤ë
**
*/

/* ARCFILE ¤È DIRFILE ¤Ï¥Õ¥¡¥¤¥ë¼ïÎऴ¤È¤Î¾ðÊó */
class ARCFILE;
class DIRFILE;
class SCN2kFILE;
/* ARCINFO ¤Ï¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤à¤¿¤á¤ËɬÍ× */
class ARCINFO;
class ARCFILE_ATOM;

class KEYHOLDER {
public:
	void SetKey(char[16]);
	void SetKey2(char[33]);
	void GuessKey(char*);
	const char* GetKey(void);
private:
	char key[16];
};

class FILESEARCH {
public:
#define TYPEMAX 14
	enum FILETYPE {
		/* °ì±þ¡¢0 - 15 ¤Þ¤Ç reserved */
		ALL = 1, /* dat/ °Ê²¼¤Î¥Õ¥¡¥¤¥ë(¥Ç¥Õ¥©¥ë¥È¤Î¸¡º÷Àè) */
		ROOT= 2, /* ¥²¡¼¥à¤Î¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê */
		PDT = 3, /* default: PDT/ */
		SCN = 4, /* default: DAT/SEEN.TXT */
		ANM = 5, /* default: DAT/ALLANM.ANL */
		ARD = 6, /* default: DAT/ALLARD.ARD */
		CUR = 7, /* default: DAT/ALLCUR.CUR */
		MID = 8, /* default: ALL */
		WAV = 9, /* default: ALL */
		KOE = 10, /* default: KOE/ */
		BGM = 11, /* default: BGM */
		MOV = 12, /* default : MOV */
		GAN = 13  /* default : MOV */
	};
	enum ARCTYPE {ATYPE_DIR, ATYPE_ARC, ATYPE_SCN2k};
private:
	/* InitRoot() ¤Î»þÅÀ¤Ç½é´ü²½¤µ¤ì¤ëÊÑ¿ô */
	DIRFILE* root_dir;
	DIRFILE* dat_dir;
	ARCFILE* searcher[TYPEMAX];
	/* ¥Õ¥¡¥¤¥ë¤Î¸ºß°ÌÃ֤Πinformation */
	ARCTYPE is_archived[TYPEMAX];
	const char* filenames[TYPEMAX];
	/* ¥Ç¥Õ¥©¥ë¥È¤Î information */
	static ARCTYPE default_is_archived[TYPEMAX];
	static const char* default_dirnames[TYPEMAX];
public:
	FILESEARCH(void);
	~FILESEARCH();
	/* ½é¤á¤Ë¥²¡¼¥à¤Î¥Ç¡¼¥¿¤¬¤¢¤ë¥Ç¥£¥ì¥¯¥È¥ê¤òÀßÄꤹ¤ëɬÍפ¬¤¢¤ë */
	int InitRoot(char* root);
	/* ¥Õ¥¡¥¤¥ë¤Î·¿¤´¤È¤Î¾ðÊó¤ò¥»¥Ã¥È¤¹¤ë */
	void SetFileInformation(FILETYPE type, ARCTYPE is_arc,
		char* filename);
	/* Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤ò°ì¤Ä¤Î·¿¤Ë´ØÏ¢¤Å¤±¤ë */
	void AppendFileInformation(FILETYPE type, ARCTYPE is_arc,
		char* filename);
	ARCFILE* MakeARCFILE(ARCTYPE tp, const char* filename);
	/* fname ¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤ò¸¡º÷ */
	class ARCINFO* Find(FILETYPE type, const char* fname, const char* ext=0);
	/* ¤¢¤ë¼ïÎà¤Î¥Õ¥¡¥¤¥ë¤ò¤¹¤Ù¤Æ¥ê¥¹¥È¥¢¥Ã¥×
	** ËöÈø¤Ï NULL pointer
	*/
	char** ListAll(FILETYPE type);
};

class ARCINFO {
protected:
	/* ¥Õ¥¡¥¤¥ë¤½¤Î¤â¤Î¤Î¾ðÊó */
	ARCFILE_ATOM& info;
	char* arcfile;
	/* mmap ¤·¤Æ¤¤¤ë¾ì¹ç¡¢¤½¤Î¾ðÊó */
	bool use_mmap;
	char* mmapped_memory;
	int fd;
	/* ¥Õ¥¡¥¤¥ëÆâÍƤÎÆþ¤Ã¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡ */
	const char* data;

protected:
	ARCINFO(const char* arcfile, ARCFILE_ATOM& from); // only from ARCFILE
	friend class ARCFILE;
	friend class DIRFILE;

	virtual bool ExecExtract(void);
public:
	/* dest ¤Ï256byte ÄøÅÙ¤Î;͵¤¬¤¢¤ë¤³¤È */
	static void Extract(char*& dest, char*& src, char* destend, char* srcend);
	static void Extract2k(char*& dest, char*& src, char* destend, char* srcend);
	virtual ~ARCINFO();
	/* ɬÍפʤé Read Á°¤Ë¸Æ¤Ö¤³¤È¤Ç½èÍý¤òʬ³ä¤Ç¤­¤ë */
	int Size(void) const;
	char* CopyRead(void); /* Read() ¤·¤ÆÆâÍƤΥ³¥Ô¡¼¤òÊÖ¤¹ */
	const char* Read(void);
	/* ¥Õ¥¡¥¤¥ë¤¬ regular file ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë̾¤òµ¢¤¹ */
	/* ¤½¤¦¤Ç¤Ê¤¤¤Ê¤é 0 ¤òµ¢¤¹ */
	const char* Path(void) const;
	FILE* OpenFile(int* length=0) const; /* ¸ß´¹À­¤Î¤¿¤á¡§raw file ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¤ò³«¤¯ */
};

class GRPCONV {
public:
	int width;
	int height;
	bool is_mask;

	const char* filename;
	const char* data;
	int datalen;

	int Width(void) { return width;}
	int Height(void) { return height;}
	bool IsMask(void) { return is_mask;}

	GRPCONV(void);
	virtual ~GRPCONV();
	void Init(const char* fname, const char* data, int dlen, int width, int height, bool is_mask);

	virtual bool Read(char* image) = 0;
	static GRPCONV* AssignConverter(const char* inbuf, int inlen, const char* fname);
	static GRPCONV* AssignConverter(ARCINFO* info) {
		const char* dat = info->Read();
		if (dat == 0) return 0;
		return AssignConverter(dat, info->Size(), "???");
	}
	void CopyRGBA(char* image, const char* from);
	void CopyRGB(char* image, const char* from);
	void CopyRGBA_rev(char* image, const char* from);
	void CopyRGB_rev(char* image, const char* from);
};

extern FILESEARCH file_searcher;
extern KEYHOLDER key_holder;

#endif // !defined(__KANON_FILE_H__)