Cleanup: Avoid ifdefs in multiple places
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 16 Jan 2018 16:14:57 +0000 (17:14 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 16 Jan 2018 16:14:57 +0000 (17:14 +0100)
Define a helper macro. Makes code read easier.

source/blender/blenloader/intern/readfile.c

index bc51f0fe96bcd4c29b73c4140fd37f5e63a4da20..40b53d4c684b2b02da04e55a264936df3545bc26 100644 (file)
 /* Use GHash for restoring pointers by name */
 #define USE_GHASH_RESTORE_POINTER
 
+/* Define this to have verbose debug prints. */
+#define USE_DEBUG_PRINT
+
+#ifdef USE_DEBUG_PRINT
+#  define DEBUG_PRINTF(...) printf(__VA_ARGS__)
+#else
+#  define DEBUG_PRINTF(...)
+#endif
+
 /***/
 
 typedef struct OldNew {
@@ -8124,22 +8133,16 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
        if (fd->memfile && ELEM(bhead->code, ID_LI, ID_ID)) {
                const char *idname = bhead_id_name(fd, bhead);
 
-#ifdef PRINT_DEBUG
-               printf("Checking %s...\n", idname);
-#endif
+               DEBUG_PRINTF("Checking %s...\n", idname);
 
                if (bhead->code == ID_LI) {
                        Main *libmain = fd->old_mainlist->first;
                        /* Skip oldmain itself... */
                        for (libmain = libmain->next; libmain; libmain = libmain->next) {
-#ifdef PRINT_DEBUG
-                               printf("... against %s: ", libmain->curlib ? libmain->curlib->id.name : "<NULL>");
-#endif
+                               DEBUG_PRINTF("... against %s: ", libmain->curlib ? libmain->curlib->id.name : "<NULL>");
                                if (libmain->curlib && STREQ(idname, libmain->curlib->id.name)) {
                                        Main *oldmain = fd->old_mainlist->first;
-#ifdef PRINT_DEBUG
-                                       printf("FOUND!\n");
-#endif
+                                       DEBUG_PRINTF("FOUND!\n");
                                        /* In case of a library, we need to re-add its main to fd->mainlist, because if we have later
                                         * a missing ID_ID, we need to get the correct lib it is linked to!
                                         * Order is crucial, we cannot bulk-add it in BLO_read_from_memfile() like it used to be... */
@@ -8153,19 +8156,13 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
                                        }
                                        return blo_nextbhead(fd, bhead);
                                }
-#ifdef PRINT_DEBUG
-                               printf("nothing...\n");
-#endif
+                               DEBUG_PRINTF("nothing...\n");
                        }
                }
                else {
-#ifdef PRINT_DEBUG
-                       printf("... in %s (%s): ", main->curlib ? main->curlib->id.name : "<NULL>", main->curlib ? main->curlib->name : "<NULL>");
-#endif
+                       DEBUG_PRINTF("... in %s (%s): ", main->curlib ? main->curlib->id.name : "<NULL>", main->curlib ? main->curlib->name : "<NULL>");
                        if ((id = BKE_libblock_find_name_ex(main, GS(idname), idname + 2))) {
-#ifdef PRINT_DEBUG
-                               printf("FOUND!\n");
-#endif
+                               DEBUG_PRINTF("FOUND!\n");
                                /* Even though we found our linked ID, there is no guarantee its address is still the same... */
                                if (id != bhead->old) {
                                        oldnewmap_insert(fd->libmap, bhead->old, id, GS(id->name));
@@ -8177,9 +8174,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
                                }
                                return blo_nextbhead(fd, bhead);
                        }
-#ifdef PRINT_DEBUG
-                       printf("nothing...\n");
-#endif
+                       DEBUG_PRINTF("nothing...\n");
                }
        }