diff scn2k/scn2k_text.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/scn2k/scn2k_text.cc
+++ b/scn2k/scn2k_text.cc
@@ -55,14 +55,14 @@ DONE:
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include"window/event.h"
-#include"window/picture.h"
-#include"window/widget.h"
-#include"system/file.h"
-#include"system/system_config.h"
-#include"scn2k.h"
+#include "window/event.h"
+#include "window/picture.h"
+#include "window/widget.h"
+#include "system/file.h"
+#include "system/system_config.h"
+#include "scn2k.h"
 
-#include<string>
+#include <string>
 using namespace std;
 
 // kanji conv : デバッグ表示用
@@ -95,11 +95,21 @@ struct TextWindow {
 	PicBase* face_pics[8];
 	TextWindow(PicContainer& parent, Event::Container& event, int window_no, const AyuSysConfig& config, void* callback);
 	~TextWindow() {
-		if (name_container) delete name_container;
-		int i; for (i=0; i<8; i++) {
-			if (face_pics[i]) delete face_pics[i];
+		if (name_container != NULL) {
+			delete name_container;
+			name_container = NULL;
 		}
-		if (wid) delete wid;
+		int i;
+		for (i=0; i<8; i++) {
+			if (face_pics[i] != NULL) {
+				delete face_pics[i];
+				face_pics[i] = NULL;
+			}
+		}
+		if (wid != NULL) {
+			delete wid;
+			wid = NULL;
+		}
 	}
 	Rect WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config);
 	void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, const AyuSysConfig& config, void* callback);
@@ -154,86 +164,88 @@ struct TextWindow {
 };
 
 class TextImpl {
-private:
-public:
-	TextWindow* text;
-	typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2, WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5, WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
-		WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
-		WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
-		CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
-		SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15), BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
-		ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK)
-	} Status;
-	Status status, status_saved, status_mask;
-private:
-	std::string ruby_text;
-	bool ruby_text_flag;
-	unsigned int wait_time;
-	unsigned int old_time;
-	unsigned int base_time;
-	int text_window_number;
-	bool text_parsing;
-	TextStream text_stream;
-	SkipMode skip_mode;
-	int save_selectcount;
+	public:
+		TextWindow* text;
+		typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2,
+			WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5,
+			WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
+			WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
+			WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
+			CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
+			SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
+			BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
+			ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK)
+		} Status;
+		Status status, status_saved, status_mask;
+	private:
+		std::string ruby_text;
+		bool ruby_text_flag;
+		unsigned int wait_time;
+		unsigned int old_time;
+		unsigned int base_time;
+		int text_window_number;
+		bool text_parsing;
+		TextStream text_stream;
+		SkipMode skip_mode;
+		int save_selectcount;
 
-	std::map<int, TimerAtom> timer_var;
-	std::vector<WidTextButton*> selects;
-	std::vector<int> sel_backlog_pos;
-	string replace_name[26];
-	string replace_name2[26];
-	PicContainer* sel_widget;
-	PicWidget* backlog_widget;
+		std::map<int, TimerAtom> timer_var;
+		std::vector<WidTextButton*> selects;
+		std::vector<int> sel_backlog_pos;
+		string replace_name[26];
+		string replace_name2[26];
+		PicContainer* sel_widget;
+		PicWidget* backlog_widget;
 
-	vector<BacklogItem>& backlog;
-	BacklogItem& backlog_item;
-	BacklogItem cur_backlog_item;
-	BacklogItem drawn_backlog_item;
+		vector<BacklogItem>& backlog;
+		BacklogItem& backlog_item;
+		BacklogItem cur_backlog_item;
+		BacklogItem drawn_backlog_item;
 
-public:
-	PicContainer& parent;
-	Event::Container& event;
-	AyuSysConfig& config;
-private:
-	TextWindow* widgets[32];
-	WidTimeCursor* kcursor;
-	Surface* sel_bg1;
-	Surface* sel_bg2;
-	Rect sel_bg_rect;
+	public:
+		PicContainer& parent;
+		Event::Container& event;
+		AyuSysConfig& config;
+	private:
+		TextWindow* widgets[32];
+		WidTimeCursor* kcursor;
+		Surface* sel_bg1;
+		Surface* sel_bg2;
+		Rect sel_bg_rect;
 
-	void SetCursor(int num);
-	VarInfo wait_savedvar[2];
+		void SetCursor(int num);
+		VarInfo wait_savedvar[2];
 
-public:
-	void AddText(const char* str);
+	public:
+		void AddText(const char* str);
 
-	static void PressFuncSkip(void* pointer, WidButton* from);
-	static void PressFuncLoad(void* pointer, WidButton* from);
-	static void PressFuncSave(void* pointer, WidButton* from);
-	static void PressFuncBacklog(void* pointer, WidButton* from);
-	static void PressFuncBacklogFwd(void* pointer, WidButton* from);
-private:
-	static void PressFuncButton(void* pointer, WidButton* from);
-	static bool PressFunc(int x, int y, void* pointer);
+		static void PressFuncSkip(void* pointer, WidButton* from);
+		static void PressFuncLoad(void* pointer, WidButton* from);
+		static void PressFuncSave(void* pointer, WidButton* from);
+		static void PressFuncBacklog(void* pointer, WidButton* from);
+		static void PressFuncBacklogFwd(void* pointer, WidButton* from);
+	private:
+		static void PressFuncButton(void* pointer, WidButton* from);
+		static bool PressFunc(int x, int y, void* pointer);
 
-public:
-	TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item);
-	~TextImpl();
-	void InitWindow(void);
-	void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
-	void SetTextSpeed(int new_speed);
-	void SetTextWait(int new_wait);
-	void CreateSelect(Cmd& cmd);
-	void Exec(Cmd& cmd);
-	bool Wait(unsigned int current_time, Cmd& cmd);
-	void hide(void);
-	void show(void) { show(text_window_number); }
-	void show(int num);
-	void DrawBacklog(BacklogItem& item, Cmd& cmd);
-	void Save(std::string& str, bool select_save);
-	void Load(const char* str);
-	void SetSkipMode(SkipMode _mode);
-	void CreateSelBG(void);
+	public:
+		TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item);
+		~TextImpl();
+		void InitWindow(void);
+		void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
+		void SetTextSpeed(int new_speed);
+		void SetTextWait(int new_wait);
+		void CreateSelect(Cmd& cmd);
+		void Exec(Cmd& cmd);
+		bool Wait(unsigned int current_time, Cmd& cmd);
+		void hide(void);
+		void show(void) { show(text_window_number); }
+		void show(int num);
+		void DrawBacklog(BacklogItem& item, Cmd& cmd);
+		void Save(std::string& str, bool select_save);
+		void Load(const char* str);
+		void SetSkipMode(SkipMode _mode);
+		void CreateSelBG(void);
 };
 
 /**************************************************************::
@@ -310,7 +322,7 @@ void TextImpl::SetSkipMode(SkipMode _mod
 		if (status_mask & BACKLOG_WAIT_MASK) { // backlog mode から復帰
 			status_mask = Status(status_mask & (~(BACKLOG_MASK|BACKLOG_MASK_FWD|BACKLOG_MASK_KOE|BACKLOG_WAIT_MASK)));
 			text->wid->Clear();
-			if (status == WAIT_TEXT && text != 0) {
+			if (status == WAIT_TEXT && text != NULL) {
 				text->StartText(text_stream);
 				text->ShowFace(backlog_item.face.c_str());
 				text->wid->Flush();
@@ -337,8 +349,8 @@ void TextImpl::SetSkipMode(SkipMode _mod
 }
 
 /* hash_map が欲しい……*/
-#include<map>
-#include<list>
+#include <map>
+#include <list>
 struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う
 	map<string, int> facetonum;
 	typedef pair<string,int> Node;
@@ -389,6 +401,7 @@ struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う
 		return "";
 	}
 };
+
 int SaveFaceHash::size_max = 20;
 
 void TextImpl::Save(string& str, bool rollback_save) {
@@ -463,20 +476,21 @@ void TextImpl::Save(string& str, bool ro
 	}
 	return;
 }
+
 void TextImpl::Load(const char* str) {
 	if (text) text->wid->Clear();
 	hide();
 	text_window_number = 0;
 	save_selectcount = 0;
-	if (sel_widget) {
+	if (sel_widget != NULL) {
 		selects.clear();
 		sel_backlog_pos.clear();
 		delete sel_widget;
-		sel_widget = 0;
+		sel_widget = NULL;
 	}
-	if (backlog_widget) {
+	if (backlog_widget != NULL) {
 		delete backlog_widget;
-		backlog_widget = 0;
+		backlog_widget = NULL;
 	}
 	status = NORMAL;
 	status_mask = NORMAL;
@@ -499,7 +513,7 @@ void TextImpl::Load(const char* str) {
 			str = strend;
 
 			strend = strchr(str, '\n');
-			if (strend == 0) strend = str + strlen(str);
+			if (strend == NULL) strend = str + strlen(str);
 			else strend++;
 
 			if (str[0] == '[') break; // next section
@@ -524,15 +538,15 @@ void TextImpl::Load(const char* str) {
 				int n = -1;
 				sscanf(str+8, "%d", &n); /* not used */
 				const char* next_str = strchr(str, ';');
-				while(next_str != 0 && next_str < strend) {
+				while(next_str != NULL && next_str < strend) {
 					str = next_str + 1;
 					next_str = strchr(str, ';');
-					if (next_str == 0) next_str = strend;
+					if (next_str == NULL) next_str = strend;
 
 					BacklogItem item;
 					if (str[0] == '"') {
 						const char* send = strchr(str+1, '"');
-						if (send == 0 || send > next_str) continue;
+						if (send == NULL || send > next_str) continue;
 						string tmp_str; tmp_str.assign(str+1, send-str-1);
 						item.DeleteTextPos();
 						item.text.Load(tmp_str);
@@ -550,14 +564,14 @@ void TextImpl::Load(const char* str) {
 						sscanf(str, "%d", &item.pos);
 					}
 					str = strchr(str, ',');
-					if (str == 0 || str > next_str) goto backlog_store;
+					if (str == NULL || str > next_str) goto backlog_store;
 					str++;
 					if (str[0] == ';' || str[0] == ',')
 						item.koe = -1;
 					else
 						sscanf(str, "%d", &item.koe);
 					str = strchr(str, ',');
-					if (str == 0 || str > next_str) goto backlog_store;
+					if (str == NULL || str > next_str) goto backlog_store;
 					str++;
 					if (*str == '"') {
 						const char* send = strchr(str+1, '"');
@@ -589,13 +603,12 @@ void TextImpl::Load(const char* str) {
 		backlog.swap(new_backlog);
 	}
 	// backlog.clear();
-	return;
 }
 
 void TextImpl::hide(void) {
 	if (text) text->hide();
 	if (kcursor) kcursor->hide();
-	text = 0;
+	text = NULL;
 }
 void TextImpl::show(int num) {
 	if (num != text_window_number) {
@@ -619,6 +632,7 @@ void TextImpl::show(int num) {
 		kcursor->Pic()->Move(kx, ky);
 	}
 }
+
 void TextImpl::DrawBacklog(BacklogItem& item, Cmd& cmd) {
 	show();
 	text->wid->deactivate();
@@ -641,27 +655,26 @@ void TextImpl::DrawBacklog(BacklogItem& 
 }
 
 void TextImpl::CreateSelBG(void) {
-	if (sel_bg1 != 0 || sel_bg2 != 0) return;
+	if (sel_bg1 != NULL || sel_bg2 != NULL) return;
 
 	const char* btnfile1 = config.GetParaStr("#SELBTN.000.NAME");
 	const char* btnfile2 = config.GetParaStr("#SELBTN.000.BACK");
 	char path[1024];
 	strcpy(path, btnfile1);
 	sel_bg1 = parent.Root().NewSurface(path);
-	if (sel_bg1 == 0) {
+	if (sel_bg1 == NULL) {
 		sprintf(path,"%s.g00",btnfile1);
 		sel_bg1 = parent.Root().NewSurface(path);
 	}
 	strcpy(path, btnfile2);
 	sel_bg2 = parent.Root().NewSurface(path);
-	if (sel_bg2 == 0) {
+	if (sel_bg2 == NULL) {
 		sprintf(path,"%s.g00",btnfile2);
 		sel_bg2 = parent.Root().NewSurface(path);
 	}
 	sel_bg_rect = Rect(0,0,0,0);
 	if (sel_bg1) sel_bg_rect.join(Rect(*sel_bg1));
 	if (sel_bg2) sel_bg_rect.join(Rect(*sel_bg2));
-	return;
 }
 
 void TextImpl::CreateSelect(Cmd& cmd) {
@@ -755,7 +768,7 @@ External_select:
 		Color seled(0xff,0xff,0xff);
 
 		show();
-		if (text == 0) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする
+		if (text == NULL) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする
 		text->wid->Clear();
 		if (kcursor) kcursor->hide();
 		/* ウィジット作成  : テキスト表示範囲と同じ*/
@@ -787,7 +800,7 @@ External_select:
 
 void TextImpl::AddText(const char* str_o) {
 	char str[10001];
-	if (text == 0) return;
+	if (text == NULL) return;
 	/* まず、replace string を変換 */
 	int i;
 	int cnt = 0;
@@ -848,12 +861,11 @@ void TextImpl::AddText(const char* str_o
 		} else if (*s < 0 && s[1] != 0) s++;
 	}
 	text_stream.Add(str_top);
-	return;
 }
 
 void TextImpl::Exec(Cmd& cmd) {
 	if (cmd.cmd_type == CMD_TEXT) {
-		if (text == 0) {
+		if (text == NULL) {
 			show();
 		}
 		if (cmd.args.size() != 1) return;
@@ -920,7 +932,7 @@ void TextImpl::Exec(Cmd& cmd) {
 			cur_backlog_item.DeleteTextPos();
 			cmd.clear();
 		} else if (cmd.cmd3 == 0x3e8 || cmd.cmd3 == 0x3e9) { // 顔グラフィック変更
-			if (text == 0) {
+			if (text == NULL) {
 				show();
 			}
 			if (cmd.cmd3 == 0x3e8) {
@@ -935,7 +947,7 @@ void TextImpl::Exec(Cmd& cmd) {
 				cmd.cmd_type = CMD_SAVECMD_ONCE;
 			}
 		} else if (cmd.cmd3 == 0x78) { // ルビ関連
-			if (text == 0) {
+			if (text == NULL) {
 				show();
 			}
 			if (cmd.cmd4 == 1) {
@@ -1325,12 +1337,11 @@ else fprintf(stderr,"AUTO %d,%d <- wait 
 			}
 		}
 	}
+}
 
-	return;
-}
 extern int print_blit;
 bool TextImpl::Wait(unsigned int current_time, Cmd& cmd) {
-	if (current_time != 0xffffffffUL) old_time = current_time;
+	if (current_time != Event::Time::NEVER_WAKE) old_time = current_time;
 /*
 if (event.presscount(MOUSE_UP)) {
 if (text) text->Pic()->ReBlit();
@@ -1341,16 +1352,16 @@ print_blit^=1;
 */
 
 	if (status == NORMAL && status_mask == NORMAL) return false;
-	
+
 	if (status_mask & WAIT_EXTRN_MASK) return true;
 	if (status_mask & (BACKLOG_MASK|BACKLOG_MASK_FWD) ) {
 		if (status_mask & BACKLOG_WAIT_MASK) ;
 		else {
-			if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
+			if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
 				if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
 					text->wid->Flush(); // 表示を最後の状態にする
 				}
-				if (status == WAIT_TEXT && text != 0 && kcursor) kcursor->show();
+				if (status == WAIT_TEXT && text != NULL && kcursor != NULL) kcursor->show();
 			}
 		}
 		if (status_mask & BACKLOG_MASK) {
@@ -1409,7 +1420,7 @@ print_blit^=1;
 		return false;
 	}
 	if (event.presscount(MOUSE_RIGHT)) {
-		if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
+		if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
 			if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
 				text->wid->Flush(); // 表示を最後の状態にする
 			}
@@ -1424,7 +1435,7 @@ print_blit^=1;
 		}
 	}
 	if (event.presscount(MOUSE_UP)) {
-		if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
+		if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
 			if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
 				text->wid->Flush(); // 表示を最後の状態にする
 			}
@@ -1437,17 +1448,17 @@ print_blit^=1;
 		}
 	}
 	if (status_mask & CLEARSCR_MASK) {
-		if ( (status == WAIT_TEXT && text != 0 ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
+		if ( (status == WAIT_TEXT && text != NULL ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
 			if (skip_mode) skip_mode = SKIP_NO;
 			if (text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
 				text->wid->Flush(); // 表示を最後の状態にする
 				return true;
 			}
 			status_mask = Status(status_mask & (~CLEARSCR_MASK) | CLEARSCR_WAIT_MASK);
-			if (text) text->hide();
-			if (kcursor) kcursor->hide();
-			if (sel_widget) sel_widget->hide();
-			if (backlog_widget) backlog_widget->hide();
+			if (text != NULL) text->hide();
+			if (kcursor != NULL) kcursor->hide();
+			if (sel_widget != NULL) sel_widget->hide();
+			if (backlog_widget != NULL) backlog_widget->hide();
 			return true;
 		}
 		status_mask = Status(status_mask & (~CLEARSCR_MASK));
@@ -1457,12 +1468,15 @@ print_blit^=1;
 		return true;
 	}
 	if (status == WAIT_TEXT) {
-		if (text == 0) { status = NORMAL; return false;}
+		if (text == NULL) {
+			status = NORMAL;
+			return false;
+		}
 		if (skip_mode & SKIP_TEXT) {
 		} else if (text->wid->status != WidText::PREPARE) {
 			return true;
 		}
-		if (kcursor) kcursor->hide();
+		if (kcursor != NULL) kcursor->hide();
 		text_stream.Clear();
 		status = NORMAL;
 		cmd.cmd_type = CMD_TEXTEND;
@@ -1500,7 +1514,7 @@ print_blit^=1;
 		cmd.SetSysvar(sel_val);
 		selects.clear();
 		delete sel_widget;
-		sel_widget = 0;
+		sel_widget = NULL;
 		status = NORMAL;
 		// CreateSelect() で作成された cur_backlog_item を backlog_item へ反映させる
 		cur_backlog_item.text.InsertColor(sel_backlog_pos[sel_val], sel_backlog_pos[sel_val+1], 0xff, 0, 0);
@@ -1511,45 +1525,46 @@ print_blit^=1;
 }
 
 void clearbtn_press(void* pointer, WidButton* button) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	TextImpl* t = (TextImpl*)pointer;
 	t->status_mask = TextImpl::Status(t->status_mask | TextImpl::CLEARSCR_MASK);
 	return;
 }
 void TextImpl::PressFuncSkip(void* pointer, WidButton* from) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	TextImpl* t = (TextImpl*)pointer;
 	t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SKIPMASK);
 	return;
 }
 void TextImpl::PressFuncLoad(void* pointer, WidButton* from) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	TextImpl* t = (TextImpl*)pointer;
 	t->status_mask = TextImpl::Status(t->status_mask | TextImpl::LOADMASK);
 	return;
 }
 void TextImpl::PressFuncSave(void* pointer, WidButton* from) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	TextImpl* t = (TextImpl*)pointer;
 	t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SAVEMASK);
 	return;
 }
 void TextImpl::PressFuncBacklog(void* pointer, WidButton* from) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	TextImpl* t = (TextImpl*)pointer;
 	t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK);
 	return;
 }
 void TextImpl::PressFuncBacklogFwd(void* pointer, WidButton* from) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	TextImpl* t = (TextImpl*)pointer;
 	t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK_FWD);
 	return;
 }
 void movebtn_drag(int from_x, int from_y, int x, int y, void* pointer, WidButton* button) {
-	if (pointer == 0) return;
+	if (pointer == NULL) return;
 	fprintf(stderr,"drag.\n");
 }
+
 #define BTNCNT 10
 static const char* btnname[BTNCNT] = {
 	"MOVE",
@@ -1563,13 +1578,16 @@ static const char* btnname[BTNCNT] = {
 	"EXBTN_001",
 	"EXBTN_002"
 };
+
 static int btnpos[BTNCNT] = { // g00 ファイル内のボタン情報の位置
 //	0, 1, 13, 12, 2, 3, 4, 5, 6, 7 // princess bride?
 	0, 1, 13, 14, 2, 3, 4, 5, 6, 7 // tomoyo after?
 };
+
 static WidButton::PressFunc btnpress[BTNCNT] = {
 	0, clearbtn_press, &TextImpl::PressFuncSkip,0,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncBacklog,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncSave,&TextImpl::PressFuncLoad,0
 };
+
 static WidButton::DragFunc btndrag[BTNCNT] = {
 	movebtn_drag, 0,0,0,0, 0,0,0,0, 0
 };
@@ -1585,6 +1603,7 @@ void TextImpl::SetTextSpeed(int speed) {
 	for (i=0; i<32; i++)
 		if (widgets[i]) widgets[i]->wid->SetSpeed(speed);
 }
+
 void TextImpl::SetTextWait(int wait) {
 	int i;
 	for (i=0; i<32; i++)
@@ -1596,13 +1615,13 @@ void TextImpl::SetWindowColor(int r, int
 	int w;
 
 	for (w=0; w<32; w++) {
-		if (widgets[w] == 0) continue;
+		if (widgets[w] == NULL) continue;
 		sprintf(key, "#WAKU.%03d.000.BACK", w);
 		const char* back = config.GetParaStr(key);
-		if (back == 0 || back[0] == 0) continue;
+		if (back == NULL || back[0] == 0) continue;
 		sprintf(key, "%s.g00", back);
 		Surface* back_s = parent.Root().NewSurface(key);
-		if (back_s == 0) continue;
+		if (back_s == NULL) continue;
 		Rect rect(*back_s);
 		Surface* new_s = parent.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK);
 		DSurfaceMove(back_s, rect, new_s, rect);
@@ -1613,7 +1632,6 @@ void TextImpl::SetWindowColor(int r, int
 			widgets[w]->wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY);
 		parent.Root().DeleteSurface(back_s);
 	}
-	return;
 }
 
 void TextImpl::SetCursor(int cursor_no) {
@@ -1631,7 +1649,7 @@ void TextImpl::SetCursor(int cursor_no) 
 	config.GetParam(key, 1, &speed);
 
 	// speed で1周、cont 回変化
-	if (kcursor) delete kcursor;
+	if (kcursor != NULL) delete kcursor;
 
 	kcursor = new WidTimeCursor(event, speed/cont, &parent, path.c_str(), 0, 0, w, 0, cont, Rect(0,0,w,h));
 	int i;
@@ -1640,7 +1658,7 @@ void TextImpl::SetCursor(int cursor_no) 
 	}
 }
 
-void kconv(const unsigned char* src, unsigned char* dest) {
+void kconv(const unsigned char* src, unsigned char* dest) { //FIXME: code duplication?
 	/* input : sjis output: euc */
 	while(*src) {
 		unsigned int high = *src++;
@@ -1673,7 +1691,8 @@ void kconv(const unsigned char* src, uns
 	}
 	*dest = 0;
 }
-void kconv_rev(const unsigned char* src, unsigned char* dest) {
+
+void kconv_rev(const unsigned char* src, unsigned char* dest) { //FIXME: code duplication?
 	/* input : euc output: sjis */
 	while(*src) {
 		unsigned int high = *src++;
@@ -1701,6 +1720,7 @@ void kconv_rev(const unsigned char* src,
 	}
 	*dest = 0;
 }
+
 string kconv(const string& s) {
 	char* out = new char[s.length()*2+100];
 	kconv((const unsigned char*)s.c_str(), (unsigned char*)out);
@@ -1708,6 +1728,7 @@ string kconv(const string& s) {
 	delete[] out;
 	return ret;
 }
+
 string kconv_rev(const string& s) {
 	char* out = new char[s.length()*2+100];
 	kconv_rev((const unsigned char*)s.c_str(), (unsigned char*)out);
@@ -1723,24 +1744,32 @@ string kconv_rev(const string& s) {
 Text::Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config) {
 	pimpl = new TextImpl(_event, _parent, config, backlog, backlog_item);
 }
+
 Text::~Text() {
 	delete pimpl;
+	pimpl = NULL;
 }
+
 void Text::InitWindow(void) {
 	pimpl->InitWindow();
 }
+
 void Text::Exec(Cmd& cmd) {
 	pimpl->Exec(cmd);
 }
+
 bool Text::Wait(unsigned int current_time, Cmd& cmd) {
 	return pimpl->Wait(current_time, cmd);
 }
+
 void Text::SetSkipMode(SkipMode mode) {
 	pimpl->SetSkipMode(mode);
 }
+
 void Text::Save(std::string& str, bool select_save) {
 	pimpl->Save(str, select_save);
 }
+
 void Text::Load(const char* str) {
 	pimpl->Load(str);
 }
@@ -1748,15 +1777,19 @@ void Text::Load(const char* str) {
 void Text::hide(void) {
 	pimpl->hide();
 }
+
 void Text::show(void) {
 	pimpl->show();
 }
+
 void Text::show(int num) {
 	pimpl->show(num);
 }
+
 void Text::DrawBacklog(BacklogItem& item, Cmd& cmd) {
 	pimpl->DrawBacklog(item, cmd);
 }
+
 /**************************************************************::
 **
 **	BacklogItem
@@ -1769,12 +1802,14 @@ BacklogItem::BacklogItem(void) {
 	face = "";
 	text.kanji_type = TextStream::sjis;
 }
+
 void BacklogItem::Clear(void) {
 	scn = -1;
 	pos = -1;
 	koe = -1;
 	text.Clear();
 }
+
 void BacklogItem::AddTextPos(Cmd& cmd) {
 	if (scn == -1 && pos == -1) {
 		scn = cmd.scn;
@@ -1783,10 +1818,12 @@ void BacklogItem::AddTextPos(Cmd& cmd) {
 	}
 	DeleteTextPos();
 }
+
 void BacklogItem::DeleteTextPos(void) {
 	scn = 0;
 	pos = -1;
 }
+
 BacklogItem& BacklogItem::operator =(const BacklogItem& p) {
 	scn = p.scn;
 	pos = p.pos;
@@ -1794,6 +1831,7 @@ BacklogItem& BacklogItem::operator =(con
 	face = p.face;
 	text = p.text;
 }
+
 void BacklogItem::SetSavepos(int p) {
 	Clear();
 	scn = SaveSelect;
@@ -1804,41 +1842,42 @@ Rect TextWindow::WakuSize(PicContainer& 
 	char key[1024];
 	sprintf(key, "#WAKU.%03d.000.NAME", waku_no);
 	const char* name = config.GetParaStr(key);
-	if (!name) return Rect(0,0,0,0);
+	if (name == NULL) return Rect(0,0,0,0);
 	std::string str = name; str += ".g00";
 	Surface* s = pic.Root().NewSurface(str.c_str());
-	if (!s) return Rect(0,0,0,0);
+	if (s == NULL) return Rect(0,0,0,0);
 	Rect r(*s);
 	pic.Root().DeleteSurface(s);
 	return r;
 }
+
 void TextWindow::MakeWaku(PicContainer& pic, Event::Container& event, int waku_no, int window_no, bool* use_btn, const AyuSysConfig& config, void* callback) {
 	char key[1024];
 	std::string str;
 	/* 枠を作成 */
 	sprintf(key, "#WAKU.%03d.000.NAME", waku_no);
 	const char* name = config.GetParaStr(key);
-	if (name && name[0] == 0) name = 0;
+	if (name != NULL && name[0] == 0) name = NULL;
 	sprintf(key, "#WAKU.%03d.000.BACK", waku_no);
 	const char* back = config.GetParaStr(key);
-	if (back && back[0] == 0) back = 0;
+	if (back != NULL && back[0] == 0) back = NULL;
 	sprintf(key, "#WAKU.%03d.000.BTN", waku_no);
 	const char* btn = config.GetParaStr(key);
-	if (btn && btn[0] == 0) btn = 0;
+	if (btn != NULL && btn[0] == 0) btn = NULL;
 
-	if (name == 0 && back == 0 && btn == 0) return;
+	if (name == NULL && back == NULL && btn == NULL) return;
 
 	/* まず、テキスト背景を設定 */
-	if (back) {
+	if (back != NULL) {
 		str = back; str += ".g00";
-		int rc,gc,bc,ac, flag;
+		int rc, gc, bc, ac, flag;
 		char key[1024];
 		sprintf(key, "#WINDOW.%03d.ATTR", window_no);
 		if (config.GetParam(key, 5, &rc, &gc, &bc, &ac, &flag) == -1) {
 			config.GetParam("#WINDOW_ATTR", 5, &rc, &gc, &bc, &ac, &flag);
 		}
 		Surface* back_s = pic.Root().NewSurface(str.c_str());
-		if (back_s) {
+		if (back_s != NULL) {
 			Rect rect(*back_s);
 			Surface* s = pic.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK);
 			DSurfaceMove(back_s, rect, s, rect);
@@ -1850,7 +1889,7 @@ void TextWindow::MakeWaku(PicContainer& 
 		}
 	}
 	/* その前に枠飾りを設定 */
-	if (name) {
+	if (name != NULL) {
 		str = name; str += ".g00";
 		Surface* s = pic.Root().NewSurface(str.c_str());
 		if (s) {
@@ -1862,19 +1901,19 @@ void TextWindow::MakeWaku(PicContainer& 
 			p->show();
 		}
 	}
-	if (btn == 0) return;
-	if (use_btn == 0) return;
+	if (btn == NULL) return;
+	if (use_btn == NULL) return;
 	// ボタンの作成
 	// 使用するボタンについては、必要に応じて show() すること
 
 	/* ボタンの位置情報を求める */
 	str = btn; str += ".g00";
 	ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, str.c_str(), "g00");
-	if (info == 0) return; // cannot find file
+	if (info == NULL) return; // cannot find file
 	const char* data = info->Read();
 	/* g00 ファイルのヘッダ部分に位置情報は入っている */
 	/* 存在しなければボタン画像ではない */
-	if (data == 0 || *data != 2) {
+	if (data == NULL || *data != 2) {
 		delete info;
 		return;
 	}
@@ -1901,7 +1940,6 @@ void TextWindow::MakeWaku(PicContainer& 
 		if (btndrag[i]) { wid->drag_func = btndrag[i]; wid->drag_pointer = callback;}
 	}
 	delete info;
-	return;
 }
 
 TextWindow::TextWindow(PicContainer& parent, Event::Container& event, int win_no, const AyuSysConfig& config, void* callback) :
@@ -1987,16 +2025,17 @@ TextWindow::TextWindow(PicContainer& par
 				name_r.rmove(r.lx, r.ty);
 				name_r.rmove(name_posx, name_posy-name_size);
 				name_container = parent.create_node(name_r, 0);
-				name = new WidLabel(name_container, Rect(0,0,w,h), true, 0, name_size);
+				name = new WidLabel(name_container, Rect(0, 0, w, h), true, 0, name_size);
 				name->show();
 				name_container->show();
 			}
 		} else { // name_mod == 2 or 3
-			name_container = parent.create_node( Rect(0,0,1,1), 0);
+			name_container = parent.create_node( Rect(0, 0, 1, 1), 0);
 		}
 	}
 	MakeWaku(*wid->PicNode(), event,waku_no, win_no, use_btn, config, callback);
 }
+
 void TextImpl::InitWindow(void) {
 	int i;
 	int w;
@@ -2006,7 +2045,7 @@ void TextImpl::InitWindow(void) {
 		widgets[w] = new TextWindow(parent, event, w, config, (void*)this);
 		if (widgets[w]->wid == 0) {
 			delete widgets[w];
-			widgets[w] = 0;
+			widgets[w] = NULL;
 		}
 	}
 	SetCursor(0);
@@ -2014,16 +2053,16 @@ void TextImpl::InitWindow(void) {
 		char buf[1024];
 		sprintf(buf, "#NAME.%c", i+'A');
 		const char* s = config.GetParaStr(buf);
-		if (s) replace_name[i] = s;
+		if (s != NULL) replace_name[i] = s;
 	}
 	// replace_name2 : 初期設定
 	// 渚、秋生、渚 (CLANNAD)
-	char name_nagisa[3] = {0x8f,0x8d,0};
-	char name_akio[5] = {0x8f, 0x48, 0x90, 0xb6, 0};
+	char name_nagisa[3] = {'\x8f', '\x8d', '\0'};
+	char name_akio[5] = {'\x8f', '\x48', '\x90', '\xb6', '\0'};
 	replace_name2[0] = name_nagisa;
 	replace_name2[1] = name_akio;
 	replace_name2[2] = name_nagisa;
-	text = 0;
+	text = NULL;
 	/* テキスト速度の設定 */
 	int speed, mod, wait, auto_mod;
 	config.GetParam("#INIT_MESSAGE_SPEED", 1, &speed);