diff system/file.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 35ce1a30f3f9
children ddbcbd000206
line wrap: on
line diff
--- a/system/file.cc
+++ b/system/file.cc
@@ -47,7 +47,7 @@ bool init_end=false;
 #include <vector>
 #include <algorithm>
 #if HAVE_MMAP
-#include<sys/mman.h>
+#include <sys/mman.h>
 #endif /* HAVE_MMAP */
 #if HAVE_DIRENT_H
 # include <dirent.h>
@@ -67,14 +67,14 @@ bool init_end=false;
 #endif
 
 #if HAVE_LIBZ
-#include<zlib.h>
+#include <zlib.h>
 #endif
 #if HAVE_LIBPNG
-#include<png.h>
+#include <png.h>
 #endif
 #if HAVE_LIBJPEG
 extern "C" {
-#include<jpeglib.h>
+#include <jpeglib.h>
 }
 #endif
 
@@ -111,10 +111,10 @@ const char* FILESEARCH::default_dirnames
 ARCFILE::ARCFILE(const char* aname) {
 	struct stat sb;
 	/* 変数初期化 */
-	arcname = 0;
+	arcname = NULL;
 	list_point = 0;
-	filenames_orig = 0;
-	next = 0;
+	filenames_orig = NULL;
+	next = NULL;
 	if (aname[0] == '\0') {arcname=new char[1]; arcname[0]='\0';return;} // NULFILE
 	/* ディレクトリか否かのチェック */
 	if (stat(aname,&sb) == -1) { /* error */
@@ -133,12 +133,11 @@ ARCFILE::ARCFILE(const char* aname) {
 		if (arcname[strlen(arcname)-1] == DIR_SPLIT)
 			arcname[strlen(arcname)-1] = '\0';
 	}
-	return;
 }
 
 void ARCFILE::Init(void) {
 	if (! arc_atom.empty()) return;
-	if (arcname == 0) return;
+	if (arcname == NULL) return;
 	/* ファイル数を得る */
 	int slen = CheckFileDeal();
 	/* ファイル名のセット */
@@ -156,7 +155,7 @@ ARCFILE::iterator ARCFILE::SearchName(co
 	char buf[1024]; char buf_ext[1024];
 	iterator it;
 	Init();
-	if (f == 0) return arc_atom.end();
+	if (f == NULL) return arc_atom.end();
 	if (arc_atom.empty()) return arc_atom.end();
 	/* エラーチェック */
 	if (strlen(f)>500) return arc_atom.end();
@@ -171,7 +170,7 @@ ARCFILE::iterator ARCFILE::SearchName(co
 	if (ext) {
 		strcpy(buf_ext, buf);
 		char* ext_pt = strrchr(buf_ext, '.');
-		if (ext_pt == 0 || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext);
+		if (ext_pt == NULL || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext);
 		*ext_pt++ = '.';
 		while(*ext=='.') ext++;
 		strcat(buf_ext, ext);
@@ -189,10 +188,10 @@ ARCFILE::iterator ARCFILE::SearchName(co
 	if (it != arc_atom.end() && strcmp(it->filename_lower, buf) == 0) return it;
 
 	// 拡張子をつけて検索
-	if (ext == 0) return arc_atom.end();
+	if (ext == NULL) return arc_atom.end();
 	strcpy(buf_ext, buf);
 	char* ext_pt = strrchr(buf_ext, '.');
-	if (ext_pt == 0 || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext);
+	if (ext_pt == NULL || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext);
 	*ext_pt++ = '.';
 	/* 拡張子の長さを得る */
 	l = strlen(ext);
@@ -209,7 +208,7 @@ ARCINFO* ARCFILE::Find(const char* fname
 	iterator atom = SearchName(fname,ext);
 	if (atom == arc_atom.end()) {
 		if (next) return next->Find(fname, ext);
-		else return 0;
+		else return NULL;
 	}
 	return MakeARCINFO(*atom);
 }
@@ -243,7 +242,7 @@ FILE* DIRFILE::Open(const char* fname) {
 	char* new_path = new char[strlen(arcname)+strlen(name)+1];
 	strcpy(new_path,arcname); strcat(new_path, name);
 	FILE* ret = fopen(new_path, "rb+");
-	fseek(ret, 0, 0);
+	fseek(ret, 0, SEEK_SET);
 	delete[] new_path;
 	return ret;
 }
@@ -283,10 +282,10 @@ void ARCFILE::InitList(void) {
 	list_point = 0;
 }
 char* ARCFILE::ListItem(void) {
-	if (list_point < 0) return 0;
-	if (list_point >= arc_atom.size()) return 0;
+	if (list_point < 0) return NULL;
+	if (list_point >= arc_atom.size()) return NULL;
 	char* fname = arc_atom[list_point].filename;
-	if (fname == 0) return 0;
+	if (fname == NULL) return NULL;
 	char* ret = new char[strlen(fname)+1];
 	strcpy(ret, fname);
 	list_point++;
@@ -297,12 +296,13 @@ int ARCFILE::CheckFileDeal(void) {
 	char buf[0x20];
 	/* ヘッダのチェック */
 	FILE* stream = fopen(arcname, "rb");
-	if (stream == 0) {
+	if (stream == NULL) {
 		fprintf(stderr, "Cannot open archive file : %s\n",arcname);
 		return 0;
 	}
-	fseek(stream, 0, 2); size_t arc_size = ftell(stream);
-	fseek(stream, 0, 0);
+	fseek(stream, 0, SEEK_END);
+	size_t arc_size = ftell(stream);
+	fseek(stream, 0, SEEK_SET);
 	if (arc_size < 0x20) {
 		fclose(stream);
 		return 0;
@@ -330,7 +330,7 @@ void ARCFILE::ListupFiles(int fname_len)
 	fname_len *= 2;
 	char* buf = new char[fname_len];
 	FILE* stream = fopen(arcname, "rb");
-	if (stream == 0) {
+	if (stream == NULL) {
 		fprintf(stderr, "Cannot open archive file : %s\n",arcname);
 		return;
 	}
@@ -363,7 +363,7 @@ int DIRFILE::CheckFileDeal(void) {
 	DIR* dir; struct dirent* ent;
 	int flen = 0;
 	dir = opendir(arcname);
-	if (dir == 0) {
+	if (dir == NULL) {
 		fprintf(stderr, "Cannot open dir file : %s\n",arcname);
 		return 0;
 	}
@@ -379,7 +379,7 @@ void DIRFILE::ListupFiles(int fname_len)
 	DIR* dir;
 	fname_len *= 2;
 	dir = opendir(arcname);
-	if (dir == 0) { 
+	if (dir == NULL) { 
 		fprintf(stderr, "Cannot open dir file : %s\n",arcname);
 		return;
 	}
@@ -394,8 +394,8 @@ void DIRFILE::ListupFiles(int fname_len)
 		closedir(dir);
 		close(old_dir_fd);
 		return;
-	};
-	
+	}
+
 	char* buf = new char[fname_len];
 	ARCFILE_ATOM atom;
 	struct stat sb;
@@ -427,11 +427,12 @@ void DIRFILE::ListupFiles(int fname_len)
 	/* chdir() したのを元に戻る */
 	closedir(dir);
 	fchdir(old_dir_fd); close(old_dir_fd);
-	return;
 }
+
 int NULFILE::CheckFileDeal(void) {
 	return 20;
 }
+
 void NULFILE::ListupFiles(int fname_len) {
 	char* s = new char[40];
 	ARCFILE_ATOM atom;
@@ -441,15 +442,17 @@ void NULFILE::ListupFiles(int fname_len)
 	atom.filename_lower = s;
 	arc_atom.push_back(atom);
 }
+
 int SCN2kFILE::CheckFileDeal(void) {
 	/* ヘッダのチェック */
 	FILE* stream = fopen(arcname, "rb");
-	if (stream == 0) {
+	if (stream == NULL) {
 		fprintf(stderr, "Cannot open archive file : %s\n",arcname);
 		return 0;
 	}
-	fseek(stream, 0, 2); size_t arc_size = ftell(stream);
-	fseek(stream, 0, 0);
+	fseek(stream, 0, SEEK_END);
+	size_t arc_size = ftell(stream);
+	fseek(stream, 0, SEEK_SET);
 	if (arc_size < 10000*8) {
 		fclose(stream);
 		return 0;
@@ -468,16 +471,18 @@ int SCN2kFILE::CheckFileDeal(void) {
 	delete[] buf;
 	return count*13; /* ファイル名は seenXXXX.txt だから、一つ12文字+null */
 }
+
 void SCN2kFILE::ListupFiles(int fname_len) {
 	FILE* stream = fopen(arcname, "rb");
-	if (stream == 0) {
+	if (stream == NULL) {
 		fprintf(stderr, "Cannot open archive file : %s\n",arcname);
 		return;
 	}
 	char* sbuf = new char[fname_len];
 	char* buf = new char[10000*8];
 	fread(buf, 10000, 8, stream);
-	fseek(stream, 0, 2); size_t arc_size = ftell(stream);
+	fseek(stream, 0, SEEK_END);
+	size_t arc_size = ftell(stream);
 	ARCFILE_ATOM atom;
 	int i; for (i=0; i<10000; i++) {
 		char header[0x200];
@@ -485,7 +490,7 @@ void SCN2kFILE::ListupFiles(int fname_le
 		int tmp_size = read_little_endian_int(buf+i*8+4);
 		if (tmp_size <= 0 || tmp_offset < 0 || tmp_offset+tmp_size > int(arc_size) ) continue;
 		/* header を得て圧縮形式などを調べる */
-		fseek(stream, tmp_offset, 0);
+		fseek(stream, tmp_offset, SEEK_SET);
 		fread(header, 0x200, 1, stream);
 		int header_top = read_little_endian_int(header+0);
 		int file_version = read_little_endian_int(header+4);
@@ -528,7 +533,6 @@ void SCN2kFILE::ListupFiles(int fname_le
 	}
 	delete[] buf;
 	fclose(stream);
-	return;
 }
 
 /********************************************************
@@ -589,9 +593,10 @@ const char * KEYHOLDER::GetKey(void)
 
 FILESEARCH::FILESEARCH(void) {
 	int i;
-	root_dir = 0; dat_dir = 0;
+	root_dir = NULL;
+	dat_dir = NULL;
 	for (i=0; i<TYPEMAX; i++) {
-		searcher[i] = 0;
+		searcher[i] = NULL;
 		filenames[i] = default_dirnames[i];
 		is_archived[i] = default_is_archived[i];
 	}
@@ -599,7 +604,7 @@ FILESEARCH::FILESEARCH(void) {
 FILESEARCH::~FILESEARCH(void) {
 	int i;
 	for (i=0; i<TYPEMAX; i++) {
-		if (filenames[i] != 0 && filenames[i] != default_dirnames[i]) delete[] filenames[i];
+		if (filenames[i] != NULL && filenames[i] != default_dirnames[i]) delete[] filenames[i];
 		if (searcher[i] && searcher[i] != dat_dir && searcher[i] != root_dir) {
 			delete searcher[i];
 		}
@@ -612,7 +617,7 @@ int FILESEARCH::InitRoot(char* root) {
 	/* 必要に応じて ~/ を展開 */
 	if (root[0] == '~' && root[1] == '/') {
 		char* home = getenv("HOME");
-		if (home != 0) {
+		if (home != NULL) {
 			char* new_root = new char[strlen(home)+strlen(root)];
 			strcpy(new_root, home);
 			strcat(new_root, root+1);
@@ -622,23 +627,23 @@ int FILESEARCH::InitRoot(char* root) {
 	/* 古いデータを消す */
 	int i;
 	for (i=0; i<TYPEMAX; i++) {
-		if (searcher[i] != 0 &&
+		if (searcher[i] != NULL &&
 			searcher[i] != root_dir &&
 			searcher[i] != dat_dir) {
 				delete searcher[i];
 		}
-		searcher[i] = 0;
+		searcher[i] = NULL;
 	}
 	if (dat_dir && root_dir != dat_dir) delete dat_dir;
 	if (root_dir) delete root_dir;
-	dat_dir = 0;
+	dat_dir = NULL;
 
 	/* 新しいディレクトリのもとで初期化 */
 	root_dir = new DIRFILE(root);
 	root_dir->Init();
 	/* dat/ を検索 */
 	char* dat_path = root_dir->SearchFile("dat");
-	if (dat_path == 0) {
+	if (dat_path == NULL) {
 		/* 見つからなかったら root を dat の代わりにつかう */
 		dat_dir = root_dir;
 	} else {
@@ -654,34 +659,34 @@ int FILESEARCH::InitRoot(char* root) {
 void FILESEARCH::SetFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) {
 	int type = tp;
 	if (type < 0 || type >= TYPEMAX) return;
-	ARCFILE* next_arc = 0;
+	ARCFILE* next_arc = NULL;
 	/* すでに searcher が存在すれば解放 */
-	if (searcher[type] != 0 &&
+	if (searcher[type] != NULL &&
 	  searcher[type] != root_dir &&
 	  searcher[type] != dat_dir) {
 		next_arc = searcher[type]->Next();
 		delete searcher[type];
 	}
-	searcher[type] = 0;
+	searcher[type] = NULL;
 	/* 適当に初期化 */
-	if (filenames[type] != 0 &&
+	if (filenames[type] != NULL &&
 		filenames[type] != default_dirnames[type]) delete[] filenames[type];
 	filenames[type] = filename;
 	is_archived[type] = is_arc;
 	searcher[type] = MakeARCFILE(is_arc, filename);
-	if (searcher[type] && next_arc)
+	if (searcher[type] != NULL && next_arc)
 		searcher[type]->SetNext(next_arc);
-	return;
 }
+
 void FILESEARCH::AppendFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) {
 	int type = tp;
 	if (type < 0 || type >= TYPEMAX) return;
 	/* searcher がまだ割り当てられてない場合 */
-	if (searcher[type] == 0 ||
+	if (searcher[type] == NULL ||
 	  searcher[type] == root_dir ||
 	  searcher[type] == dat_dir) {
 		searcher[type] = MakeARCFILE(is_archived[type], filenames[type]);
-		if (searcher[type] == 0) { /* 作成できなかった場合 */
+		if (searcher[type] == NULL) { /* 作成できなかった場合 */
 			/* この型情報を FileInformation とする */
 			SetFileInformation(tp, is_arc, filename);
 			return;
@@ -691,29 +696,28 @@ void FILESEARCH::AppendFileInformation(F
 	ARCFILE* arc = MakeARCFILE(is_arc, filename);
 	/* append */
 	ARCFILE* cur;
-	for (cur=searcher[type]; cur->Next() != 0; cur = cur->Next()) ;
+	for (cur=searcher[type]; cur->Next() != NULL; cur = cur->Next()) ;
 	cur->SetNext(arc);
-	return;
 }
 
 ARCFILE* FILESEARCH::MakeARCFILE(ARCTYPE tp, const char* filename) {
-	ARCFILE* arc = 0;
+	ARCFILE* arc = NULL;
 	char* file;
-	if (filename == 0) goto err;
+	if (filename == NULL) goto err;
 	if (tp == ATYPE_DIR) {
 		file = root_dir->SearchFile(filename);
 	} else {
 		file = dat_dir->SearchFile(filename);
-		if (file == 0)
+		if (file == NULL)
 			file = root_dir->SearchFile(filename);
 	}
-	if (file == 0) goto err;
+	if (file == NULL) goto err;
 	switch(tp) {
 		case ATYPE_DIR: arc = new DIRFILE(file); break;
 		case ATYPE_SCN2k:
 		case ATYPE_ARC: {
 			FILE* f = fopen(file, "rb");
-			if (f == 0) goto err;
+			if (f == NULL) goto err;
 			char header[32];
 			memset(header, 0, 32);
 			fread(header, 32, 1, f);
@@ -732,19 +736,18 @@ ARCFILE* FILESEARCH::MakeARCFILE(ARCTYPE
 err:
 	arc = new NULFILE;
 	return arc;
-	
 }
 
 ARCINFO* FILESEARCH::Find(FILETYPE type, const char* fname, const char* ext) {
-	if (searcher[type] == 0) {
+	if (searcher[type] == NULL) {
 		/* searcher 作成 */
-		if (filenames[type] == 0) {
+		if (filenames[type] == NULL) {
 			searcher[type] = dat_dir;
 		} else {
 			searcher[type] = MakeARCFILE(is_archived[type], filenames[type]);
-			if (searcher[type] == 0) {
+			if (searcher[type] == NULL) {
 				fprintf(stderr,"FILESEARCH::Find : invalid archive type; type %d name %s\n",type,fname);
-				return 0;
+				return NULL;
 			}
 		}
 	}
@@ -754,16 +757,16 @@ ARCINFO* FILESEARCH::Find(FILETYPE type,
 char** FILESEARCH::ListAll(FILETYPE type) {
 	/* とりあえず searcher を初期化 */
 	Find(type, "THIS FILENAME MAY NOT EXIST IN THE FILE SYSTEM !!!");
-	if (searcher[type] == 0) return 0;
+	if (searcher[type] == NULL) return NULL;
 	/* 全ファイルのリストアップ */
 	int deal = 0;
 	ARCFILE* file;
-	for (file = searcher[type]; file != 0; file = file->Next())
+	for (file = searcher[type]; file != NULL; file = file->Next())
 		deal += file->Deal();
-	if (deal <= 0) return 0;
+	if (deal <= 0) return NULL;
 	char** ret_list = new char*[deal+1];
 	int count = 0;
-	for (file = searcher[type]; file != 0; file = file->Next()) {
+	for (file = searcher[type]; file != NULL; file = file->Next()) {
 		file->InitList();
 		char* f;
 		while( (f = file->ListItem() ) != 0) {
@@ -772,7 +775,7 @@ char** FILESEARCH::ListAll(FILETYPE type
 			count++;
 		}
 	}
-	ret_list[count] = 0;
+	ret_list[count] = NULL;
 	return ret_list;
 }
 
@@ -780,8 +783,8 @@ ARCINFO::ARCINFO(const char* __arcname, 
 	arcfile = new char[strlen(__arcname)+1];
 	strcpy(arcfile, __arcname);
 	use_mmap = false;
-	mmapped_memory = 0;
-	data = 0;
+	mmapped_memory = NULL;
+	data = NULL;
 	fd = -1;
 }
 
@@ -801,19 +804,20 @@ int ARCINFO::Size(void) const {
 /* コピーを返す */
 char* ARCINFO::CopyRead(void) {
 	const char* d = Read();
-	if (d == 0) return 0;
+	if (d == NULL) return NULL;
 	int s = Size();
-	if (s <= 0) return 0;
+	if (s <= 0) return NULL;
 	char* ret = new char[s]; memcpy(ret, d, s);
 	return ret;
 }
 
 const char* ARCINFO::Path(void) const {
-	if (info.offset != 0) return 0; /* archive file なのでパスを帰せない */
+	if (info.offset != 0) return NULL; /* archive file なのでパスを帰せない */
 	char* ret = new char[strlen(arcfile)+1];
 	strcpy(ret, arcfile);
 	return ret;
 }
+
 /* 互換性専用 */
 FILE* ARCINFO::OpenFile(int* length) const {
 	FILE* f = fopen(arcfile, "rb");
@@ -826,25 +830,28 @@ FILE* ARCINFO::OpenFile(int* length) con
 bool ARCINFO::ExecExtract(void) {
 	return true;
 }
+
 /* 読み込みを開始する */
 const char* ARCINFO::Read(void) {
 	// すでにデータを読み込み済みなら何もしない
-	if (data) return data;
+	if (data != NULL) return data;
 
 	if (info.offset < 0 || info.arcsize <= 0) {
-		return 0;
+		return NULL;
 	}
 	/* ファイルを開く */
 	fd = open(arcfile, O_RDONLY);
 	if (fd < 0) {
-		return 0;
+		return NULL;
 	}
-	if (lseek(fd, info.offset, 0) != info.offset) {
-		close(fd); fd = -1; return 0;
+	if (lseek(fd, info.offset, SEEK_SET) != info.offset) {
+		close(fd);
+		fd = -1;
+		return NULL;
 	}
 	/* mmap を試みる */
 #ifdef HAVE_MMAP
-	mmapped_memory = (char*)mmap(0, info.arcsize, PROT_READ, MAP_SHARED, fd, info.offset);
+	mmapped_memory = (char*)mmap(NULL, info.arcsize, PROT_READ, MAP_SHARED, fd, info.offset);
 	if (mmapped_memory != MAP_FAILED) {
 		use_mmap = true;
 		data = (const char*)mmapped_memory;
@@ -865,13 +872,13 @@ const char* ARCINFO::Read(void) {
 #ifdef HAVE_MMAP
 		if (use_mmap) {
 			munmap(mmapped_memory, info.arcsize);
-			if (data == (const char*)mmapped_memory) data = 0;
+			if (data == (const char*)mmapped_memory) data = NULL;
 		}
 #endif /* HAVE_MMAP */
 		delete[] (char*)data;
 		close(fd);
-		fd = -1; data = 0;
-		return 0;
+		fd = -1; data = NULL;
+		return NULL;
 	}
 #ifdef HAVE_MMAP
 	if (use_mmap && data != (const char*)mmapped_memory) {
@@ -892,15 +899,17 @@ const char* ARCINFO::Read(void) {
 ***********************************************
 */
 GRPCONV::GRPCONV(void) {
-	filename = 0;
-	data = 0;
+	filename = NULL;
+	data = NULL;
 }
+
 GRPCONV::~GRPCONV() {
 	if (filename) delete[] filename;
 }
+
 void GRPCONV::Init(const char* f, const char* d, int dlen, int w, int h, bool is_m) {
 	if (filename) delete[] filename;
-	if (f == 0) {
+	if (f == NULL) {
 		char* fn = new char[1];
 		fn[0] = 0;
 		filename = fn;
@@ -916,107 +925,127 @@ void GRPCONV::Init(const char* f, const 
 	height = h;
 	is_mask = is_m;
 }
+
 class PDTCONV : public GRPCONV {
-	bool Read_PDT10(char* image);
-	bool Read_PDT11(char* image);
-public:
-	PDTCONV(const char* _inbuf, int inlen, const char* fname);
-	~PDTCONV() {}
-	bool Read(char* image);
+	private:
+		bool Read_PDT10(char* image);
+		bool Read_PDT11(char* image);
+	public:
+		PDTCONV(const char* _inbuf, int inlen, const char* fname);
+		~PDTCONV() {}
+		bool Read(char* image);
 };
+
 class G00CONV : public GRPCONV {
-	struct REGION {
-		int x1, y1, x2, y2;
-		int Width() { return x2-x1+1;}
-		int Height() { return y2-y1+1;}
-		void FixVar(int& v, int& w) {
-			if (v < 0) v = 0;
-			if (v >= w) v = w-1;
-		}
-		void Fix(int w, int h) {
-			FixVar(x1,w);
-			FixVar(x2,w);
-			FixVar(y1,h);
-			FixVar(y2,h);
-			if (x1 > x2) x2 = x1;
-			if (y1 > y2) y2 = y1;
-		}
-	};
+	private:
+		struct REGION {
+			int x1, y1, x2, y2;
+			int Width() { return x2-x1+1;}
+			int Height() { return y2-y1+1;}
+			void FixVar(int& v, int& w) {
+				if (v < 0) v = 0;
+				if (v >= w) v = w-1;
+			}
+			void Fix(int w, int h) {
+				FixVar(x1,w);
+				FixVar(x2,w);
+				FixVar(y1,h);
+				FixVar(y2,h);
+				if (x1 > x2) x2 = x1;
+				if (y1 > y2) y2 = y1;
+			}
+		};
 
-	void Copy_16bpp(char* image, int x, int y, const char* src, int bpl, int h);
-	void Copy_32bpp(char* image, int x, int y, const char* src, int bpl, int h);
-	bool Read_Type0(char* image);
-	bool Read_Type1(char* image);
-	bool Read_Type2(char* image);
-public:
-	G00CONV(const char* _inbuf, int _inlen, const char* fname);
-	~G00CONV() { }
-	bool Read(char* image);
+		void Copy_16bpp(char* image, int x, int y, const char* src, int bpl, int h);
+		void Copy_32bpp(char* image, int x, int y, const char* src, int bpl, int h);
+		bool Read_Type0(char* image);
+		bool Read_Type1(char* image);
+		bool Read_Type2(char* image);
+	public:
+		G00CONV(const char* _inbuf, int _inlen, const char* fname);
+		~G00CONV() { }
+		bool Read(char* image);
 };
 
 class BMPCONV : public GRPCONV {
-public:
-	BMPCONV(const char* _inbuf, int _inlen, const char* fname);
-	~BMPCONV() {};
-	bool Read(char* image);
+	public:
+		BMPCONV(const char* _inbuf, int _inlen, const char* fname);
+		~BMPCONV() {};
+		bool Read(char* image);
 };
+
 #if HAVE_LIBPNG
 class PNGCONV : public GRPCONV {
-	const char* png_data;
-	static void png_read(png_structp, png_bytep, png_size_t);
+	private:
+		const char* png_data;
+		static void png_read(png_structp, png_bytep, png_size_t);
 
-public:
-	PNGCONV(const char* _inbuf, int _inlen, const char* fname);
-	~PNGCONV() {};
-	bool Read(char* image);
+	public:
+		PNGCONV(const char* _inbuf, int _inlen, const char* fname);
+		~PNGCONV() {};
+		bool Read(char* image);
 };
 #endif
 
 #if HAVE_LIBJPEG
 class JPEGCONV : public GRPCONV {
-
-public:
-	JPEGCONV(const char* _inbuf, int _inlen, const char* fname);
-	~JPEGCONV() {};
-	bool Read(char* image);
-	void SetupSrc(struct jpeg_decompress_struct* cinfo, const char* data, int size);
-	static void init_source(j_decompress_ptr cinfo);
-	static boolean fill_input_buffer(j_decompress_ptr cinfo);
-	static void skip_input_data(j_decompress_ptr cinfo, long num_bytes);
-	static boolean resync_to_restart(j_decompress_ptr cinfo, int desired);
-	static void term_source(j_decompress_ptr cinf);
+	public:
+		JPEGCONV(const char* _inbuf, int _inlen, const char* fname);
+		~JPEGCONV() {};
+		bool Read(char* image);
+		void SetupSrc(struct jpeg_decompress_struct* cinfo, const char* data, int size);
+		static void init_source(j_decompress_ptr cinfo);
+		static boolean fill_input_buffer(j_decompress_ptr cinfo);
+		static void skip_input_data(j_decompress_ptr cinfo, long num_bytes);
+		static boolean resync_to_restart(j_decompress_ptr cinfo, int desired);
+		static void term_source(j_decompress_ptr cinf);
 };
 #endif
 
 GRPCONV* GRPCONV::AssignConverter(const char* inbuf, int inlen, const char* fname) {
 	/* ファイルの内容に応じたコンバーターを割り当てる */
-	GRPCONV* conv = 0;
-	if (inlen < 10) return 0; /* invalid file */
+	GRPCONV* conv = NULL;
+	if (inlen < 10) return NULL; /* invalid file */
 	if (strncmp(inbuf, "PDT10", 5) == 0 || strncmp(inbuf, "PDT11", 5) == 0) { /* PDT10 or PDT11 */
 		conv = new PDTCONV(inbuf, inlen, fname);
-		if (conv->data == 0) { delete conv; conv = 0;}
+		if (conv->data == NULL) {
+			delete conv;
+			conv = NULL;
+		}
 	}
 #if HAVE_LIBPNG
 	unsigned char png_magic[4] = {0x89, 'P', 'N', 'G'};
-	if (conv == 0 && memcmp(inbuf, png_magic,4) == 0) {
+	if (conv == NULL && memcmp(inbuf, png_magic,4) == 0) {
 		conv = new PNGCONV(inbuf, inlen, fname);
-		if (conv->data == 0) { delete conv; conv = 0;}
+		if (conv->data == NULL) {
+			delete conv;
+			conv = NULL;
+		}
 	}
 #endif
 #if HAVE_LIBJPEG
-	if ( conv == 0 && *(unsigned char*)inbuf == 0xff && *(unsigned char*)(inbuf+1) == 0xd8 &&
+	if ( conv == NULL && *(unsigned char*)inbuf == 0xff && *(unsigned char*)(inbuf+1) == 0xd8 &&
 		(strncmp(inbuf+6, "JFIF",4) == 0 || strncmp(inbuf+6,"Exif",4) == 0)) {
 		conv = new JPEGCONV(inbuf, inlen, fname);
-		if (conv->data == 0) { delete conv; conv = 0;}
+		if (conv->data == NULL) {
+			delete conv;
+			conv = NULL;
+		}
 	}
 #endif
-	if (conv == 0 && inbuf[0]=='B' && inbuf[1]=='M' && read_little_endian_int(inbuf+10)==0x36 && read_little_endian_int(inbuf+14) == 0x28) { // Windows BMP
+	if (conv == NULL && inbuf[0]=='B' && inbuf[1]=='M' && read_little_endian_int(inbuf+10)==0x36 && read_little_endian_int(inbuf+14) == 0x28) { // Windows BMP
 		conv = new BMPCONV(inbuf, inlen, fname);
-		if (conv->data == 0) { delete conv; conv = 0;}
+		if (conv->data == NULL) {
+			delete conv;
+			conv = NULL;
+		}
 	}
-	if (conv == 0 && (inbuf[0] == 0 || inbuf[0] == 1 || inbuf[0] == 2)) { /* G00 */
+	if (conv == NULL && (inbuf[0] == 0 || inbuf[0] == 1 || inbuf[0] == 2)) { /* G00 */
 		conv = new G00CONV(inbuf, inlen, fname);
-		if (conv->data == 0) { delete conv; conv = 0;}
+		if (conv->data == NULL) {
+			delete conv;
+			conv = NULL;
+		}
 	}
 	return conv;
 }
@@ -1050,8 +1079,6 @@ PDTCONV::PDTCONV(const char* _inbuf, int
 	int h = read_little_endian_int(_inbuf+0x10);
 	int mask_pt = read_little_endian_int(_inbuf + 0x1c);
 	Init(filename, _inbuf, _inlen, w, h, mask_pt ? true : false);
-
-	return;
 }
 
 
@@ -1111,7 +1138,7 @@ G00CONV::G00CONV(const char* _inbuf, int
 }
 
 bool G00CONV::Read(char* image) {
-	if (data == 0) return false;
+	if (data == NULL) return false;
 	/* header 識別 */
 	int type = *data;
 	if (type == 0) return Read_Type0(image);
@@ -1140,6 +1167,7 @@ static int bitrev_table[256] = {
 	0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
 	0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
 	0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff};
+
 template<class DataType, class DataSize> inline int lzExtract(DataType& datatype,const char*& src, char*& dest, const char* srcend, char* destend) {
 	int count = 0;
 	const char* lsrcend = srcend; char* ldestend = destend;
@@ -1196,6 +1224,7 @@ template<class DataType, class DataSize>
 	dest=ldest; src=lsrc;
 	return 0;
 }
+
 /* 引数を減らすためのwrapper */
 template<class DataType, class DataSize> inline int lzExtract(DataType datatype, DataSize datasize ,const char*& src, char*& dest, const char* srcend, char* destend) {
 	return lzExtract<DataType, DataSize>(datatype,src,dest,srcend,destend);
@@ -1203,114 +1232,119 @@ template<class DataType, class DataSize>
 
 /* 普通の PDT */
 class Extract_DataType {
-public:
-	static void ExtractData(const char*& lsrc, int& data, int& size) {
-		data = read_little_endian_short(lsrc) & 0xffff;
-		size = (data & 0x0f) + 1;
-		data = (data>>4)+1;
-		lsrc += 2;
-	}
-	static void Copy1Pixel(const char*& lsrc, char*& ldest) {
+	public:
+		static void ExtractData(const char*& lsrc, int& data, int& size) {
+			data = read_little_endian_short(lsrc) & 0xffff;
+			size = (data & 0x0f) + 1;
+			data = (data>>4)+1;
+			lsrc += 2;
+		}
+		static void Copy1Pixel(const char*& lsrc, char*& ldest) {
 #ifdef WORDS_BIGENDIAN
-		ldest[3] = lsrc[0];
-		ldest[2] = lsrc[1];
-		ldest[1] = lsrc[2];
-		ldest[0] = 0;
+			ldest[3] = lsrc[0];
+			ldest[2] = lsrc[1];
+			ldest[1] = lsrc[2];
+			ldest[0] = 0;
 #else
-		*(int*)ldest = read_little_endian_int(lsrc); ldest[3]=0;
+			*(int*)ldest = read_little_endian_int(lsrc); ldest[3]=0;
 #endif
-		lsrc += 3; ldest += 4;
-	}
-	static int IsRev(void) { return 0; }
+			lsrc += 3; ldest += 4;
+		}
+		static int IsRev(void) { return 0; }
 };
 
 /* PDT11 の第一段階変換 */
 class Extract_DataType_PDT11 {
-	int* index_table;
-public:
-	Extract_DataType_PDT11(int* it) { index_table = it; }
-	void ExtractData(const char*& lsrc, int& data, int& size) {
-		data = int(*(const unsigned char*)lsrc);
-		size = (data>>4) + 2;
-		data = index_table[data&0x0f];
-		lsrc++;
-	}
-	static void Copy1Pixel(const char*& lsrc, char*& ldest) {
-		*ldest = *lsrc;
-		ldest++; lsrc++;
-	}
-	static int IsRev(void) { return 0; }
+	private:
+		int* index_table;
+	public:
+		Extract_DataType_PDT11(int* it) { index_table = it; }
+		void ExtractData(const char*& lsrc, int& data, int& size) {
+			data = int(*(const unsigned char*)lsrc);
+			size = (data>>4) + 2;
+			data = index_table[data&0x0f];
+			lsrc++;
+		}
+		static void Copy1Pixel(const char*& lsrc, char*& ldest) {
+			*ldest = *lsrc;
+			ldest++; lsrc++;
+		}
+		static int IsRev(void) { return 0; }
 };
+
 /* マスク用 */
 class Extract_DataType_Mask {
-public:
-	void ExtractData(const char*& lsrc, int& data, int& size) {
-		int d = read_little_endian_short(lsrc) & 0xffff;
-		size = (d & 0xff) + 2;
-		data = (d>>8)+1;
-		lsrc += 2;
-	}
-	static void Copy1Pixel(const char*& lsrc, char*& ldest) {
-		*ldest = *lsrc;
-		ldest++; lsrc++;
-	}
-	static int IsRev(void) { return 0; }
+	public:
+		void ExtractData(const char*& lsrc, int& data, int& size) {
+			int d = read_little_endian_short(lsrc) & 0xffff;
+			size = (d & 0xff) + 2;
+			data = (d>>8)+1;
+			lsrc += 2;
+		}
+		static void Copy1Pixel(const char*& lsrc, char*& ldest) {
+			*ldest = *lsrc;
+			ldest++; lsrc++;
+		}
+		static int IsRev(void) { return 0; }
 };
+
 /* 書庫用 */
 class Extract_DataType_ARC {
-public:
-	void ExtractData(const char*& lsrc, int& data, int& size) {
-		data = read_little_endian_short(lsrc) & 0xffff;
-		size = (data&0x0f) + 2;
-		data = (data>>4) + 1;
-		lsrc+= 2;
-	}
-	static void Copy1Pixel(const char*& lsrc, char*& ldest) {
-		*ldest = *lsrc;
-		ldest++; lsrc++;
-	}
-	static int IsRev(void) { return 0; }
+	public:
+		void ExtractData(const char*& lsrc, int& data, int& size) {
+			data = read_little_endian_short(lsrc) & 0xffff;
+			size = (data&0x0f) + 2;
+			data = (data>>4) + 1;
+			lsrc+= 2;
+		}
+		static void Copy1Pixel(const char*& lsrc, char*& ldest) {
+			*ldest = *lsrc;
+			ldest++; lsrc++;
+		}
+		static int IsRev(void) { return 0; }
 };
+
 /* avg2000 のシナリオ用 */
 class Extract_DataType_SCN2k {
-public:
-	void ExtractData(const char*& lsrc, int& data, int& size) {
-		data = read_little_endian_short(lsrc) & 0xffff;
-		size = (data&0x0f) + 2;
-		data = (data>>4);
-		lsrc+= 2;
-	}
-	static void Copy1Pixel(const char*& lsrc, char*& ldest) {
-		*ldest = *lsrc;
-		ldest++; lsrc++;
-	}
-	static int IsRev(void) { return 1; }
+	public:
+		void ExtractData(const char*& lsrc, int& data, int& size) {
+			data = read_little_endian_short(lsrc) & 0xffff;
+			size = (data&0x0f) + 2;
+			data = (data>>4);
+			lsrc+= 2;
+		}
+		static void Copy1Pixel(const char*& lsrc, char*& ldest) {
+			*ldest = *lsrc;
+			ldest++; lsrc++;
+		}
+		static int IsRev(void) { return 1; }
 };
+
 /* ReadLive の type0 */
 class Extract_DataType_G00Type0 {
-public:
-	static void ExtractData(const char*& lsrc, int& data, int& size) {
-		data = read_little_endian_short(lsrc) & 0xffff;
-		size = ((data & 0x0f)+ 1) * 3;
-		data = (data>>4) * 3;
-		lsrc += 2;
-	}
-	static void Copy1Pixel(const char*& lsrc, char*& ldest) {
+	public:
+		static void ExtractData(const char*& lsrc, int& data, int& size) {
+			data = read_little_endian_short(lsrc) & 0xffff;
+			size = ((data & 0x0f)+ 1) * 3;
+			data = (data>>4) * 3;
+			lsrc += 2;
+		}
+		static void Copy1Pixel(const char*& lsrc, char*& ldest) {
 #ifdef WORDS_BIGENDIAN
-		ldest[0] = lsrc[0];
-		ldest[1] = lsrc[1];
-		ldest[2] = lsrc[2];
+			ldest[0] = lsrc[0];
+			ldest[1] = lsrc[1];
+			ldest[2] = lsrc[2];
 #else /* LITTLE ENDIAN / intel architecture */
-		*(int*)ldest = *(int*)lsrc;
+			*(int*)ldest = *(int*)lsrc;
 #endif
-		lsrc += 3; ldest += 3;
-	}
-	static int IsRev(void) { return 1; }
+			lsrc += 3; ldest += 3;
+		}
+		static int IsRev(void) { return 1; }
 };
 
 
 bool PDTCONV::Read(char* image) {
-	if (data == 0) return false;
+	if (data == NULL) return false;
 
 	if (strncmp(data, "PDT10", 5) == 0) {
 		if (! Read_PDT10(image)) return false;
@@ -1353,6 +1387,7 @@ bool PDTCONV::Read_PDT10(char* image) {
 	while(lzExtract(Extract_DataType(), int(), src, dest, srcend, destend)) ;
 	return true;
 }
+
 bool PDTCONV::Read_PDT11(char* image) {
 	int index_table[16];
 	int color_table[256];
@@ -1391,13 +1426,12 @@ void ARCINFO::Extract(char*& dest_start,
 	const char* src = src_start;
 	while (lzExtract(Extract_DataType_ARC(), char(), src, dest_start, src_end, dest_end)) ;
 	src_start = (char*)src;
-	return;
 }
+
 void ARCINFO::Extract2k(char*& dest_start, char*& src_start, char* dest_end, char* src_end) {
 	const char* src = src_start;
 	while (lzExtract(Extract_DataType_SCN2k(), char(), src, dest_start, src_end, dest_end)) ;
 	src_start = (char*)src;
-	return;
 }
 
 bool ARCINFO_AVG32::ExecExtract(void) {
@@ -1496,6 +1530,7 @@ bool G00CONV::Read_Type0(char* image) {
 	delete[] uncompress_data;
 	return true;
 }
+
 bool G00CONV::Read_Type1(char* image) {
 	int i;
 	int uncompress_size = read_little_endian_int(data+9) + 1;
@@ -1611,7 +1646,6 @@ void GRPCONV::CopyRGBA_rev(char* image, 
 		*d = (int(s[2])) | (int(s[1])<<8) | (int(s[0])<<16) | (int(s[3])<<24) | mask;
 		d++; s += 4;
 	}
-	return;
 }
 
 void GRPCONV::CopyRGBA(char* image, const char* buf) {
@@ -1627,8 +1661,8 @@ void GRPCONV::CopyRGBA(char* image, cons
 		*outbuf++ =  read_little_endian_int(buf);
 		buf += 4;
 	}
-	return;
 }
+
 void GRPCONV::CopyRGB(char* image, const char* buf) {
 	/* 色変換を行う */
 	int len = width * height;
@@ -1639,15 +1673,14 @@ void GRPCONV::CopyRGB(char* image, const
 		*d = (int(s[0])) | (int(s[1])<<8) | (int(s[2])<<16) | 0xff000000;
 		d++; s+=3;
 	}
-	return;
 }
 
 #if HAVE_LIBPNG
 PNGCONV::PNGCONV(const char* _inbuf, int _inlen, const char* _filename) {
 	int w,h,type;
-	png_structp png_ptr = 0;
-	png_infop info_ptr = 0;
-	png_infop end_info = 0;
+	png_structp png_ptr = NULL;
+	png_infop info_ptr = NULL;
+	png_infop end_info = NULL;
 
 	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
 	if (!png_ptr) return;
@@ -1686,20 +1719,19 @@ err:
 		else
 			png_destroy_read_struct(&png_ptr, (png_infopp) 0,(png_infopp)0);
 	}
-	return;
 }
 
 bool PNGCONV::Read(char* image) {
-	if (data == 0) return false;
+	if (data == NULL) return false;
 	bool retcode = false;
 	int bpp = is_mask ? 4 : 3;
 	int i;
 	char* buf;
-	png_bytepp row_pointers = 0;
+	png_bytepp row_pointers = NULL;
 
-	png_structp png_ptr = 0;
-	png_infop info_ptr = 0;
-	png_infop end_info = 0;
+	png_structp png_ptr = NULL;
+	png_infop info_ptr = NULL;
+	png_infop end_info = NULL;
 
 	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
 	if (!png_ptr) goto err;
@@ -1748,7 +1780,6 @@ void PNGCONV::png_read(png_structp png_p
 	PNGCONV* orig = (PNGCONV*)png_get_io_ptr(png_ptr);
 	memcpy(d, orig->png_data, sz);
 	orig->png_data += sz;
-	return;
 }
 #endif /* HAVE_LIBPNG */
 
@@ -1765,16 +1796,16 @@ JPEGCONV::JPEGCONV(const char* _inbuf, i
 		Init(filename, _inbuf, _inlen, cinfo.image_width, cinfo.image_height, false);
 	}
 	delete cinfo.src;
-	cinfo.src = 0;
+	cinfo.src = NULL;
 	jpeg_destroy_decompress(&cinfo);
-	return;
 }
 		
 bool JPEGCONV::Read(char* image) {
-	if (data == 0) return false;
+	if (data == NULL) return false;
 	bool retcode = false;
-	JSAMPARRAY rows, rows_orig; int i;
-	char* buf = 0;
+	JSAMPARRAY rows, rows_orig;
+	int i;
+	char* buf = NULL;
 
 	struct jpeg_decompress_struct cinfo;
 	struct jpeg_error_mgr jerr;
@@ -1807,13 +1838,14 @@ bool JPEGCONV::Read(char* image) {
 	retcode = true;
 err:
 	delete cinfo.src;
-	cinfo.src = 0;
+	cinfo.src = NULL;
 	jpeg_destroy_decompress(&cinfo);
 	return retcode;
 }
 
 void JPEGCONV::init_source(j_decompress_ptr cinfo) {
 }
+
 boolean JPEGCONV::fill_input_buffer(j_decompress_ptr cinfo) {
 	static char dummy[1024];
 	memset(dummy, 0, 1024);
@@ -1822,15 +1854,18 @@ boolean JPEGCONV::fill_input_buffer(j_de
 	fprintf(stderr,"JPEGCONV::fill_input_buffer: warning corrupted jpeg stream\n");
 	return TRUE;
 }
+
 void JPEGCONV::skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
 	if (cinfo->src->bytes_in_buffer > num_bytes) {
 		cinfo->src->next_input_byte += num_bytes;
 		cinfo->src->bytes_in_buffer -= num_bytes;
 	}
 }
+
 boolean JPEGCONV::resync_to_restart(j_decompress_ptr cinfo, int desired) {
 	return jpeg_resync_to_restart(cinfo, desired);
 }
+
 void JPEGCONV::term_source(j_decompress_ptr cinf) {
 }
 
@@ -1843,6 +1878,7 @@ void JPEGCONV::SetupSrc(struct jpeg_deco
 	cinfo->src->resync_to_restart = resync_to_restart;
 	cinfo->src->term_source = term_source;
 }
+
 #endif /* HAVE_LIBJPEG */
 BMPCONV::BMPCONV(const char* _inbuf, int _inlen, const char* _filename) {
 	/* データから情報読み込み */
@@ -1852,11 +1888,10 @@ BMPCONV::BMPCONV(const char* _inbuf, int
 	int bpp = read_little_endian_short(_inbuf + 0x1c);
 	int comp = read_little_endian_int(_inbuf + 0x1e);
 	Init(filename, _inbuf, _inlen, w, h, bpp==32 ? true : false);
-	return;
 }
 
 bool BMPCONV::Read(char* image) {
-	if (data == 0) return false;
+	if (data == NULL) return false;
 
 	/* マスクのチェック */
 	int bpp = read_little_endian_short(data+0x1c);