[Bf-blender-cvs] [0d7817d] master: Cleanup: use bool for writefile

Campbell Barton noreply at git.blender.org
Tue Jun 28 13:00:14 CEST 2016


Commit: 0d7817d1a46adebdad4cb68ea54169720e86068d
Author: Campbell Barton
Date:   Tue Jun 28 21:00:00 2016 +1000
Branches: master
https://developer.blender.org/rB0d7817d1a46adebdad4cb68ea54169720e86068d

Cleanup: use bool for writefile

===================================================================

M	source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 9cf32e1..2c8bb92 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -308,7 +308,8 @@ typedef struct {
 	unsigned char *buf;
 	MemFile *compare, *current;
 
-	int tot, count, error;
+	int tot, count;
+	bool error;
 
 	/* Wrap writing, so we can use zlib or
 	 * other compression types later, see: G_FILE_COMPRESS
@@ -316,7 +317,7 @@ typedef struct {
 	WriteWrap *ww;
 
 #ifdef USE_BMESH_SAVE_AS_COMPAT
-	char use_mesh_compat; /* option to save with older mesh format */
+	bool use_mesh_compat; /* option to save with older mesh format */
 #endif
 } WriteData;
 
@@ -349,7 +350,7 @@ static void writedata_do_write(WriteData *wd, const void *mem, int memlen)
 	}
 	else {
 		if (wd->ww->write(wd->ww, mem, memlen) != memlen) {
-			wd->error = 1;
+			wd->error = true;
 		}
 	}
 }
@@ -448,16 +449,14 @@ static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current)
  * \return unknown global variable otherwise
  * \warning Talks to other functions with global parameters
  */
-static int endwrite(WriteData *wd)
+static bool endwrite(WriteData *wd)
 {
-	int err;
-
 	if (wd->count) {
 		writedata_do_write(wd, wd->buf, wd->count);
 		wd->count = 0;
 	}
 
-	err = wd->error;
+	const bool err = wd->error;
 	writedata_free(wd);
 
 	return err;
@@ -2179,7 +2178,7 @@ static void write_customdata(
 static void write_meshes(WriteData *wd, ListBase *idbase)
 {
 	Mesh *mesh;
-	int save_for_old_blender = 0;
+	bool save_for_old_blender = false;
 
 #ifdef USE_BMESH_SAVE_AS_COMPAT
 	save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */
@@ -3979,11 +3978,11 @@ static void write_thumb(WriteData *wd, const BlendThumbnail *thumb)
 }
 
 /* if MemFile * there's filesave to memory */
-static int write_file_handle(
+static bool write_file_handle(
         Main *mainvar,
         WriteWrap *ww,
         MemFile *compare, MemFile *current,
-        int write_user_block, int write_flags, const BlendThumbnail *thumb)
+        int write_flags, const BlendThumbnail *thumb)
 {
 	BHead bhead;
 	ListBase mainlist;
@@ -4050,7 +4049,7 @@ static int write_file_handle(
 	write_linestyles(wd, &mainvar->linestyle);
 	write_libraries(wd,  mainvar->next);
 
-	if (write_user_block) {
+	if (write_flags & G_FILE_USERPREFS) {
 		write_userdef(wd);
 	}
 
@@ -4128,7 +4127,6 @@ bool BLO_write_file(
         ReportList *reports, const BlendThumbnail *thumb)
 {
 	char tempname[FILE_MAX + 1];
-	int err, write_user_block;
 	eWriteWrapType ww_type;
 	WriteWrap ww;
 
@@ -4183,15 +4181,13 @@ bool BLO_write_file(
 		}
 	}
 
-	write_user_block = write_flags & G_FILE_USERPREFS;
-
 	if (write_flags & G_FILE_RELATIVE_REMAP) {
 		/* note, making relative to something OTHER then G.main->name */
 		BKE_bpath_relative_convert(mainvar, filepath, NULL);
 	}
 
 	/* actual file writing */
-	err = write_file_handle(mainvar, &ww, NULL, NULL, write_user_block, write_flags, thumb);
+	const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, thumb);
 
 	ww.close(&ww);
 
@@ -4230,9 +4226,9 @@ bool BLO_write_file(
  */
 bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int write_flags)
 {
-	int err;
+	write_flags &= ~G_FILE_USERPREFS;
 
-	err = write_file_handle(mainvar, NULL, compare, current, 0, write_flags, NULL);
+	const bool err = write_file_handle(mainvar, NULL, compare, current, write_flags, NULL);
 
 	return (err == 0);
 }




More information about the Bf-blender-cvs mailing list