Fix contrib/cube and contrib/seg to compile on Windows.

Andreas Pflug
This commit is contained in:
Tom Lane 2004-09-14 04:21:38 +00:00
parent 92244e8e54
commit db64df4b1c
6 changed files with 59 additions and 63 deletions

View File

@ -15,8 +15,6 @@
#include "cubedata.h" #include "cubedata.h"
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define abs(a) ((a) < (0) ? (-a) : (a)) #define abs(a) ((a) < (0) ? (-a) : (a))
extern int cube_yyparse(); extern int cube_yyparse();
@ -590,8 +588,8 @@ cube_union(NDBOX * a, NDBOX * b)
*/ */
for (i = 0; i < b->dim; i++) for (i = 0; i < b->dim; i++)
{ {
result->x[i] = min(b->x[i], b->x[i + b->dim]); result->x[i] = Min(b->x[i], b->x[i + b->dim]);
result->x[i + a->dim] = max(b->x[i], b->x[i + b->dim]); result->x[i + a->dim] = Max(b->x[i], b->x[i + b->dim]);
} }
for (i = b->dim; i < a->dim; i++) for (i = b->dim; i < a->dim; i++)
{ {
@ -603,8 +601,8 @@ cube_union(NDBOX * a, NDBOX * b)
for (i = 0; i < a->dim; i++) for (i = 0; i < a->dim; i++)
{ {
result->x[i] = result->x[i] =
min(min(a->x[i], a->x[i + a->dim]), result->x[i]); Min(Min(a->x[i], a->x[i + a->dim]), result->x[i]);
result->x[i + a->dim] = max(max(a->x[i], result->x[i + a->dim] = Max(Max(a->x[i],
a->x[i + a->dim]), result->x[i + a->dim]); a->x[i + a->dim]), result->x[i + a->dim]);
} }
@ -648,8 +646,8 @@ cube_inter(NDBOX * a, NDBOX * b)
*/ */
for (i = 0; i < b->dim; i++) for (i = 0; i < b->dim; i++)
{ {
result->x[i] = min(b->x[i], b->x[i + b->dim]); result->x[i] = Min(b->x[i], b->x[i + b->dim]);
result->x[i + a->dim] = max(b->x[i], b->x[i + b->dim]); result->x[i + a->dim] = Max(b->x[i], b->x[i + b->dim]);
} }
for (i = b->dim; i < a->dim; i++) for (i = b->dim; i < a->dim; i++)
{ {
@ -661,8 +659,8 @@ cube_inter(NDBOX * a, NDBOX * b)
for (i = 0; i < a->dim; i++) for (i = 0; i < a->dim; i++)
{ {
result->x[i] = result->x[i] =
max(min(a->x[i], a->x[i + a->dim]), result->x[i]); Max(Min(a->x[i], a->x[i + a->dim]), result->x[i]);
result->x[i + a->dim] = min(max(a->x[i], result->x[i + a->dim] = Min(Max(a->x[i],
a->x[i + a->dim]), result->x[i + a->dim]); a->x[i + a->dim]), result->x[i + a->dim]);
} }
@ -720,8 +718,8 @@ cube_over_left(NDBOX * a, NDBOX * b)
if ((a == NULL) || (b == NULL)) if ((a == NULL) || (b == NULL))
return (FALSE); return (FALSE);
return (min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) <= return (Min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) <=
min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) && Min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) &&
!cube_left(a, b) && !cube_right(a, b)); !cube_left(a, b) && !cube_right(a, b));
} }
@ -733,8 +731,8 @@ cube_over_right(NDBOX * a, NDBOX * b)
if ((a == NULL) || (b == NULL)) if ((a == NULL) || (b == NULL))
return (FALSE); return (FALSE);
return (min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) >= return (Min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) >=
min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) && Min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) &&
!cube_left(a, b) && !cube_right(a, b)); !cube_left(a, b) && !cube_right(a, b));
} }
@ -747,8 +745,8 @@ cube_left(NDBOX * a, NDBOX * b)
if ((a == NULL) || (b == NULL)) if ((a == NULL) || (b == NULL))
return (FALSE); return (FALSE);
return (min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) < return (Min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) <
min(b->x[0], b->x[b->dim])); Min(b->x[0], b->x[b->dim]));
} }
/* return 'true' if the projection of 'a' is /* return 'true' if the projection of 'a' is
@ -759,8 +757,8 @@ cube_right(NDBOX * a, NDBOX * b)
if ((a == NULL) || (b == NULL)) if ((a == NULL) || (b == NULL))
return (FALSE); return (FALSE);
return (min(a->x[0], a->x[a->dim]) > return (Min(a->x[0], a->x[a->dim]) >
min(b->x[b->dim - 1], b->x[2 * b->dim - 1])); Min(b->x[b->dim - 1], b->x[2 * b->dim - 1]));
} }
/* make up a metric in which one box will be 'lower' than the other /* make up a metric in which one box will be 'lower' than the other
@ -771,25 +769,25 @@ cube_cmp(NDBOX * a, NDBOX * b)
int i; int i;
int dim; int dim;
dim = min(a->dim, b->dim); dim = Min(a->dim, b->dim);
/* compare the common dimensions */ /* compare the common dimensions */
for (i = 0; i < dim; i++) for (i = 0; i < dim; i++)
{ {
if (min(a->x[i], a->x[a->dim + i]) > if (Min(a->x[i], a->x[a->dim + i]) >
min(b->x[i], b->x[b->dim + i])) Min(b->x[i], b->x[b->dim + i]))
return 1; return 1;
if (min(a->x[i], a->x[a->dim + i]) < if (Min(a->x[i], a->x[a->dim + i]) <
min(b->x[i], b->x[b->dim + i])) Min(b->x[i], b->x[b->dim + i]))
return -1; return -1;
} }
for (i = 0; i < dim; i++) for (i = 0; i < dim; i++)
{ {
if (max(a->x[i], a->x[a->dim + i]) > if (Max(a->x[i], a->x[a->dim + i]) >
max(b->x[i], b->x[b->dim + i])) Max(b->x[i], b->x[b->dim + i]))
return 1; return 1;
if (max(a->x[i], a->x[a->dim + i]) < if (Max(a->x[i], a->x[a->dim + i]) <
max(b->x[i], b->x[b->dim + i])) Max(b->x[i], b->x[b->dim + i]))
return -1; return -1;
} }
@ -798,16 +796,16 @@ cube_cmp(NDBOX * a, NDBOX * b)
{ {
for (i = dim; i < a->dim; i++) for (i = dim; i < a->dim; i++)
{ {
if (min(a->x[i], a->x[a->dim + i]) > 0) if (Min(a->x[i], a->x[a->dim + i]) > 0)
return 1; return 1;
if (min(a->x[i], a->x[a->dim + i]) < 0) if (Min(a->x[i], a->x[a->dim + i]) < 0)
return -1; return -1;
} }
for (i = dim; i < a->dim; i++) for (i = dim; i < a->dim; i++)
{ {
if (max(a->x[i], a->x[a->dim + i]) > 0) if (Max(a->x[i], a->x[a->dim + i]) > 0)
return 1; return 1;
if (max(a->x[i], a->x[a->dim + i]) < 0) if (Max(a->x[i], a->x[a->dim + i]) < 0)
return -1; return -1;
} }
@ -821,16 +819,16 @@ cube_cmp(NDBOX * a, NDBOX * b)
{ {
for (i = dim; i < b->dim; i++) for (i = dim; i < b->dim; i++)
{ {
if (min(b->x[i], b->x[b->dim + i]) > 0) if (Min(b->x[i], b->x[b->dim + i]) > 0)
return -1; return -1;
if (min(b->x[i], b->x[b->dim + i]) < 0) if (Min(b->x[i], b->x[b->dim + i]) < 0)
return 1; return 1;
} }
for (i = dim; i < b->dim; i++) for (i = dim; i < b->dim; i++)
{ {
if (max(b->x[i], b->x[b->dim + i]) > 0) if (Max(b->x[i], b->x[b->dim + i]) > 0)
return -1; return -1;
if (max(b->x[i], b->x[b->dim + i]) < 0) if (Max(b->x[i], b->x[b->dim + i]) < 0)
return 1; return 1;
} }
@ -911,13 +909,13 @@ cube_contains(NDBOX * a, NDBOX * b)
} }
/* Can't care less about the excess dimensions of (a), if any */ /* Can't care less about the excess dimensions of (a), if any */
for (i = 0; i < min(a->dim, b->dim); i++) for (i = 0; i < Min(a->dim, b->dim); i++)
{ {
if (min(a->x[i], a->x[a->dim + i]) > if (Min(a->x[i], a->x[a->dim + i]) >
min(b->x[i], b->x[b->dim + i])) Min(b->x[i], b->x[b->dim + i]))
return (FALSE); return (FALSE);
if (max(a->x[i], a->x[a->dim + i]) < if (Max(a->x[i], a->x[a->dim + i]) <
max(b->x[i], b->x[b->dim + i])) Max(b->x[i], b->x[b->dim + i]))
return (FALSE); return (FALSE);
} }
@ -961,20 +959,20 @@ cube_overlap(NDBOX * a, NDBOX * b)
/* compare within the dimensions of (b) */ /* compare within the dimensions of (b) */
for (i = 0; i < b->dim; i++) for (i = 0; i < b->dim; i++)
{ {
if (min(a->x[i], a->x[a->dim + i]) > if (Min(a->x[i], a->x[a->dim + i]) >
max(b->x[i], b->x[b->dim + i])) Max(b->x[i], b->x[b->dim + i]))
return (FALSE); return (FALSE);
if (max(a->x[i], a->x[a->dim + i]) < if (Max(a->x[i], a->x[a->dim + i]) <
min(b->x[i], b->x[b->dim + i])) Min(b->x[i], b->x[b->dim + i]))
return (FALSE); return (FALSE);
} }
/* compare to zero those dimensions in (a) absent in (b) */ /* compare to zero those dimensions in (a) absent in (b) */
for (i = b->dim; i < a->dim; i++) for (i = b->dim; i < a->dim; i++)
{ {
if (min(a->x[i], a->x[a->dim + i]) > 0) if (Min(a->x[i], a->x[a->dim + i]) > 0)
return (FALSE); return (FALSE);
if (max(a->x[i], a->x[a->dim + i]) < 0) if (Max(a->x[i], a->x[a->dim + i]) < 0)
return (FALSE); return (FALSE);
} }
@ -1031,11 +1029,11 @@ distance_1D(double a1, double a2, double b1, double b2)
{ {
/* interval (a) is entirely on the left of (b) */ /* interval (a) is entirely on the left of (b) */
if ((a1 <= b1) && (a2 <= b1) && (a1 <= b2) && (a2 <= b2)) if ((a1 <= b1) && (a2 <= b1) && (a1 <= b2) && (a2 <= b2))
return (min(b1, b2) - max(a1, a2)); return (Min(b1, b2) - Max(a1, a2));
/* interval (a) is entirely on the right of (b) */ /* interval (a) is entirely on the right of (b) */
if ((a1 > b1) && (a2 > b1) && (a1 > b2) && (a2 > b2)) if ((a1 > b1) && (a2 > b1) && (a1 > b2) && (a2 > b2))
return (min(a1, a2) - max(b1, b2)); return (Min(a1, a2) - Max(b1, b2));
/* the rest are all sorts of intersections */ /* the rest are all sorts of intersections */
return (0.0); return (0.0);
@ -1074,7 +1072,7 @@ cube_ll_coord(NDBOX * a, int4 n)
result = (double *) palloc(sizeof(double)); result = (double *) palloc(sizeof(double));
*result = 0; *result = 0;
if (a->dim >= n && n > 0) if (a->dim >= n && n > 0)
*result = min(a->x[n - 1], a->x[a->dim + n - 1]); *result = Min(a->x[n - 1], a->x[a->dim + n - 1]);
return result; return result;
} }
@ -1087,7 +1085,7 @@ cube_ur_coord(NDBOX * a, int4 n)
result = (double *) palloc(sizeof(double)); result = (double *) palloc(sizeof(double));
*result = 0; *result = 0;
if (a->dim >= n && n > 0) if (a->dim >= n && n > 0)
*result = max(a->x[n - 1], a->x[a->dim + n - 1]); *result = Max(a->x[n - 1], a->x[a->dim + n - 1]);
return result; return result;
} }

View File

@ -28,7 +28,7 @@ static NDBOX * write_point_as_box(char *s, int dim);
%} %}
/* BISON Declarations */ /* BISON Declarations */
%token FLOAT O_PAREN C_PAREN O_BRACKET C_BRACKET COMMA %token CUBEFLOAT O_PAREN C_PAREN O_BRACKET C_BRACKET COMMA
%start box %start box
/* Grammar follows */ /* Grammar follows */
@ -128,13 +128,13 @@ paren_list:
; ;
list: list:
FLOAT { CUBEFLOAT {
/* alloc enough space to be sure whole list will fit */ /* alloc enough space to be sure whole list will fit */
$$ = palloc(scanbuflen + 1); $$ = palloc(scanbuflen + 1);
strcpy($$, $1); strcpy($$, $1);
} }
| |
list COMMA FLOAT { list COMMA CUBEFLOAT {
$$ = $1; $$ = $1;
strcat($$, ","); strcat($$, ",");
strcat($$, $3); strcat($$, $3);

View File

@ -39,7 +39,7 @@ float ({integer}|{real})([eE]{integer})?
%% %%
{float} yylval = yytext; return FLOAT; {float} yylval = yytext; return CUBEFLOAT;
\[ yylval = "("; return O_BRACKET; \[ yylval = "("; return O_BRACKET;
\] yylval = ")"; return C_BRACKET; \] yylval = ")"; return C_BRACKET;
\( yylval = "("; return O_PAREN; \( yylval = "("; return O_PAREN;

View File

@ -14,8 +14,6 @@
#include "segdata.h" #include "segdata.h"
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define abs(a) ((a) < (0) ? (-a) : (a)) #define abs(a) ((a) < (0) ? (-a) : (a))
/* /*
@ -924,7 +922,7 @@ restore(char *result, float val, int n)
* put a cap on the number of siugnificant digits to avoid nonsense in * put a cap on the number of siugnificant digits to avoid nonsense in
* the output * the output
*/ */
n = min(n, FLT_DIG); n = Min(n, FLT_DIG);
/* remember the sign */ /* remember the sign */
sign = (val < 0 ? 1 : 0); sign = (val < 0 ? 1 : 0);
@ -946,7 +944,7 @@ restore(char *result, float val, int n)
if (exp == 0) if (exp == 0)
{ {
/* use the supplied mantyssa with sign */ /* use the supplied mantyssa with sign */
strcpy((char *) index(result, 'e'), ""); strcpy((char *) strchr(result, 'e'), "");
} }
else else
{ {

View File

@ -38,7 +38,7 @@
} bnd; } bnd;
char * text; char * text;
} }
%token <text> FLOAT %token <text> SEGFLOAT
%token <text> RANGE %token <text> RANGE
%token <text> PLUMIN %token <text> PLUMIN
%token <text> EXTENSION %token <text> EXTENSION
@ -105,13 +105,13 @@ range:
; ;
boundary: boundary:
FLOAT { SEGFLOAT {
$$.ext = '\0'; $$.ext = '\0';
$$.sigd = significant_digits($1); $$.sigd = significant_digits($1);
$$.val = seg_atof($1); $$.val = seg_atof($1);
} }
| |
EXTENSION FLOAT { EXTENSION SEGFLOAT {
$$.ext = $1[0]; $$.ext = $1[0];
$$.sigd = significant_digits($2); $$.sigd = significant_digits($2);
$$.val = seg_atof($2); $$.val = seg_atof($2);
@ -119,7 +119,7 @@ boundary:
; ;
deviation: deviation:
FLOAT { SEGFLOAT {
$$.ext = '\0'; $$.ext = '\0';
$$.sigd = significant_digits($1); $$.sigd = significant_digits($1);
$$.val = seg_atof($1); $$.val = seg_atof($1);

View File

@ -41,7 +41,7 @@ float ({integer}|{real})([eE]{integer})?
{range} yylval.text = yytext; return RANGE; {range} yylval.text = yytext; return RANGE;
{plumin} yylval.text = yytext; return PLUMIN; {plumin} yylval.text = yytext; return PLUMIN;
{float} yylval.text = yytext; return FLOAT; {float} yylval.text = yytext; return SEGFLOAT;
\< yylval.text = "<"; return EXTENSION; \< yylval.text = "<"; return EXTENSION;
\> yylval.text = ">"; return EXTENSION; \> yylval.text = ">"; return EXTENSION;
\~ yylval.text = "~"; return EXTENSION; \~ yylval.text = "~"; return EXTENSION;