소스 검색

libgis: Enable the C99 bool type (#1567)

Enables globally the C99 'bool' type with its values 'true' and 'false'.

The old boolean constants 'TRUE' and 'FALSE' are still valid but
redefined to 'true' and 'false' to emphasize their equivalence.

(Re-)definitions of TRUE/FALSE in modules are removed.

This change was originally triggered by a conflict of v.hull -- defining
a local bool type -- with GDAL 3.3 which introduced the inclusion of
stdbool.h (#1563).
nilason 3 년 전
부모
커밋
1e0c11f526
7개의 변경된 파일14개의 추가작업 그리고 27개의 파일을 삭제
  1. 6 3
      include/grass/gis.h
  2. 0 3
      lib/lidar/lidar.h
  3. 0 2
      raster/r.param.scale/param.h
  4. 0 2
      raster/r.surf.idw/main.h
  5. 0 2
      raster3d/r3.showdspf/Ball.c
  6. 0 3
      raster3d/r3.showdspf/togif.c
  7. 8 12
      vector/v.hull/chull.c

+ 6 - 3
include/grass/gis.h

@@ -23,6 +23,8 @@
 /* System include files */
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdbool.h>
+
 
 /* Grass and local include files */
 #include <grass/config.h>
@@ -51,13 +53,14 @@ static const char *GRASS_copyright __attribute__ ((unused))
 #define G_gisinit(pgm) G__gisinit(GIS_H_VERSION, (pgm))
 #define G_no_gisinit() G__no_gisinit(GIS_H_VERSION)
 
-/* Define TRUE and FALSE for boolean comparisons */
+/* For boolean values and comparisons use the C99 type 'bool' with values 'true' */
+/* and 'false' For historical reasons 'TRUE' and 'FALSE' are still valid.        */
 #ifndef TRUE
-#define TRUE 1
+#define TRUE true
 #endif
 
 #ifndef FALSE
-#define FALSE 0
+#define FALSE false
 #endif
 
 #if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || (__APPLE__ && __LP64__)

+ 0 - 3
lib/lidar/lidar.h

@@ -62,9 +62,6 @@
     /* INTERPOLATOR */
 #define P_BILINEAR 		1
 #define P_BICUBIC 		0
-    /* Boolean definitions */
-#define TRUE 			1
-#define FALSE 			0
 
 /*----------------------------------------------------------------------------------------------------------*/
     /*STRUCTS DECLARATION */

+ 0 - 2
raster/r.param.scale/param.h

@@ -18,8 +18,6 @@
 				/* 'blank' edge around raster.          */
 #define MAX_WSIZE 499		/* Maximum dimensions of window.        */
 				/* Some useful labels.                  */
-#define TRUE 1
-#define FALSE 0
 
 #define RAD2DEG M_R2D
 #define DEG2RAD M_D2R

+ 0 - 2
raster/r.surf.idw/main.h

@@ -1,8 +1,6 @@
 #include <grass/raster.h>
 
 #define         SHORT           short
-#define         TRUE    1
-#define         FALSE   0
 
 #define MELEMENT        struct Melement
 MELEMENT {

+ 0 - 2
raster3d/r3.showdspf/Ball.c

@@ -7,8 +7,6 @@
 #include "Ball.h"
 #include "BallMath.h"
 #include <stdio.h>
-#define TRUE 1
-#define FALSE 0
 
 HMatrix mId = { {1, 0, 0, 0}
 , {0, 1, 0, 0}

+ 0 - 3
raster3d/r3.showdspf/togif.c

@@ -324,9 +324,6 @@ static int ditherrow(unsigned short *r, unsigned short *g, unsigned short *b,
  *
  *****************************************************************************/
 
-#define TRUE 1
-#define FALSE 0
-
 
 /************************** BumpPixel() ********************************/
 /*

+ 8 - 12
vector/v.hull/chull.c

@@ -29,10 +29,6 @@
 
 #include "globals.h"
 
-/*Define Boolean type */
-typedef enum
-{ BFALSE, BTRUE } bool;
-
 /* Define vertex indices. */
 #define X   0
 #define Y   1
@@ -76,10 +72,10 @@ struct tFaceStructure
 };
 
 /* Define flags */
-#define ONHULL   	BTRUE
-#define REMOVED  	BTRUE
-#define VISIBLE  	BTRUE
-#define PROCESSED	BTRUE
+#define ONHULL   	true
+#define REMOVED  	true
+#define VISIBLE  	true
+#define PROCESSED	true
 
 /* Global variable definitions */
 tVertex vertices = NULL;
@@ -436,7 +432,7 @@ bool AddOne(tVertex p)
     tFace f;
     tEdge e, temp;
     long int vol;
-    bool vis = BFALSE;
+    bool vis = false;
 
 
     /* Mark faces visible from p. */
@@ -446,7 +442,7 @@ bool AddOne(tVertex p)
 
 	if (vol < 0) {
 	    f->visible = VISIBLE;
-	    vis = BTRUE;
+	    vis = true;
 	}
 	f = f->next;
     } while (f != faces);
@@ -454,7 +450,7 @@ bool AddOne(tVertex p)
     /* If no faces are visible from p, then p is inside the hull. */
     if (!vis) {
 	p->onhull = !ONHULL;
-	return BFALSE;
+	return false;
     }
 
     /* Mark edges in interior of visible region for deletion.
@@ -470,7 +466,7 @@ bool AddOne(tVertex p)
 	    e->newface = MakeConeFace(e, p);
 	e = temp;
     } while (e != edges);
-    return BTRUE;
+    return true;
 }
 
 /*---------------------------------------------------------------------