diff system/visarc.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 3a6aaeab7b4e
children 4416cfac86ae
line wrap: on
line diff
--- a/system/visarc.cc
+++ b/system/visarc.cc
@@ -64,7 +64,7 @@ void usage(void) {
 void List(char* path) {
 	ARCFILE* file;
 	FILE* f = fopen(path, "rb");
-	if (f == 0) return;
+	if (f == NULL) return;
 	char header[32];
 	fread(header, 32, 1, f);
 	fclose(f);
@@ -74,17 +74,16 @@ void List(char* path) {
 	file->Init();
 	file->ListFiles(stdout);
 	delete file;
-	return;
 }
 
 void ExtractOne(ARCFILE* arc, char* file) {
 	ARCINFO* info = arc->Find(file,"");
-	if (info == 0) {
+	if (info == NULL) {
 		fprintf(stderr, "Cannot find file %s in archive\n",file);
 		return;
 	}
 	FILE* out = fopen(file, "w");
-	if (out == 0) {
+	if (out == NULL) {
 		delete info;
 		fprintf(stderr, "Cannot open output file %s\n",file);
 		return;
@@ -97,13 +96,12 @@ void ExtractOne(ARCFILE* arc, char* file
 	fclose(out);
 	fprintf(stdout, "done\n");
 	delete info;
-	return;
 }
 
 void Extract(char* path, char** files, int fnum) {
 	ARCFILE* file;
 	FILE* f = fopen(path, "rb");
-	if (f == 0) return;
+	if (f == NULL) return;
 	char header[32];
 	fread(header, 32, 1, f);
 	fclose(f);
@@ -111,23 +109,23 @@ void Extract(char* path, char** files, i
 	if (strncmp(header, "PACL", 4) == 0) file = new ARCFILE(path);
 	else file = new SCN2kFILE(path);
 	file->Init();
-	if (files != 0 && fnum != 0) {
+	if (files != NULL && fnum != 0) {
 		int i; for (i=0; i<fnum; i++) {
 			ExtractOne(file, files[i]);
 		}
 	} else {
 		file->InitList();
-		char* path; while( (path=file->ListItem()) != 0) {
+		char* path;
+		while( (path=file->ListItem()) != 0) {
 			ExtractOne(file, path);
 		}
 	}
 	delete file;
-	return;
 }
 
 void ChangeExt(char* path, char* new_ext, char* buf) {
 	char* name = strrchr(path, DIR_SPLIT);
-	if (name == 0) name = path;
+	if (name == NULL) name = path;
 	else name++;
 	int path_len = name - path;
 
@@ -142,8 +140,10 @@ void ChangeExt(char* path, char* new_ext
 
 char* ReadFile(char* fname, int* len) {
 	FILE* in = fopen(fname, "rb");
-	if (in == 0) return 0;
-	fseek(in,0,2); size_t s = ftell(in); fseek(in,0,0);
+	if (in == NULL) return 0;
+	fseek(in, 0, SEEK_END);
+	size_t s = ftell(in);
+	fseek(in, 0, SEEK_SET);
 	char* buf = new char[s];
 	fread(buf,s,1,in);
 	fclose(in);
@@ -215,19 +215,18 @@ void create_png(FILE* stream, char* path
 	}
 	png_write_end(png_ptr, info_ptr);
 	png_destroy_write_struct(&png_ptr, &info_ptr);
-	return;
 }
 
 void ExtractPngRgbaGraphic(char* path,char* outpath = 0) {
 	char buf[1024]; char* fname = buf;
 	int len;
 	char* dat = ReadFile(path, &len);
-	if (dat == 0) {
+	if (dat == NULL) {
 		fprintf(stderr, "Cannot open PDT file : %s\n",path);
 		return;
 	}
 	GRPCONV* conv = GRPCONV::AssignConverter(dat, len, path);
-	if (conv == 0) {
+	if (conv == NULL) {
 		fprintf(stderr, "Invalid format\n");
 		return;
 	}
@@ -243,10 +242,10 @@ void ExtractPngRgbaGraphic(char* path,ch
 			data[4*i+3] = 0xff;	// 不透明度を最大にする
 		}
 	}
-	if (outpath == 0) ChangeExt(path,".png", buf); // path をつくる
+	if (outpath == NULL) ChangeExt(path,".png", buf); // path をつくる
 	else fname = outpath;
 	FILE* out = fopen(fname, "wb"); // ファイルを開く
-	if (out == 0) {
+	if (out == NULL) {
 		fprintf(stderr, "Cannot open raw file : %s\n",buf);
 		delete conv;
 		return;