From 910fe5891e6d8b1adc71f3d96e95ea5d3fd6b02b Mon Sep 17 00:00:00 2001
From: "Thomas G. Lockhart" <lockhart@fourpalms.org>
Date: Sat, 13 Feb 1999 04:22:34 +0000
Subject: [PATCH] Add routines to convert between int8 and text/varchar types.
 Change #if FALSE to #if NOT_USED to avoid port problems. Fix up pg_indent
 weirdness with function argument declarations.

---
 src/backend/utils/adt/int8.c | 133 +++++++++++++++++++++++------------
 1 file changed, 89 insertions(+), 44 deletions(-)

diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index f97b352bf2c..1b020225945 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -70,7 +70,7 @@ int8in(char *str)
 /* int8out()
  */
 char *
-int8out(int64 * val)
+int8out(int64 *val)
 {
 	char	   *result;
 
@@ -99,37 +99,37 @@ int8out(int64 * val)
  * Is val1 relop val2?
  */
 bool
-int8eq(int64 * val1, int64 * val2)
+int8eq(int64 *val1, int64 *val2)
 {
 	return *val1 == *val2;
 }	/* int8eq() */
 
 bool
-int8ne(int64 * val1, int64 * val2)
+int8ne(int64 *val1, int64 *val2)
 {
 	return *val1 != *val2;
 }	/* int8ne() */
 
 bool
-int8lt(int64 * val1, int64 * val2)
+int8lt(int64 *val1, int64 *val2)
 {
 	return *val1 < *val2;
 }	/* int8lt() */
 
 bool
-int8gt(int64 * val1, int64 * val2)
+int8gt(int64 *val1, int64 *val2)
 {
 	return *val1 > *val2;
 }	/* int8gt() */
 
 bool
-int8le(int64 * val1, int64 * val2)
+int8le(int64 *val1, int64 *val2)
 {
 	return *val1 <= *val2;
 }	/* int8le() */
 
 bool
-int8ge(int64 * val1, int64 * val2)
+int8ge(int64 *val1, int64 *val2)
 {
 	return *val1 >= *val2;
 }	/* int8ge() */
@@ -139,37 +139,37 @@ int8ge(int64 * val1, int64 * val2)
  * Is 64-bit val1 relop 32-bit val2?
  */
 bool
-int84eq(int64 * val1, int32 val2)
+int84eq(int64 *val1, int32 val2)
 {
 	return *val1 == val2;
 }	/* int84eq() */
 
 bool
-int84ne(int64 * val1, int32 val2)
+int84ne(int64 *val1, int32 val2)
 {
 	return *val1 != val2;
 }	/* int84ne() */
 
 bool
-int84lt(int64 * val1, int32 val2)
+int84lt(int64 *val1, int32 val2)
 {
 	return *val1 < val2;
 }	/* int84lt() */
 
 bool
-int84gt(int64 * val1, int32 val2)
+int84gt(int64 *val1, int32 val2)
 {
 	return *val1 > val2;
 }	/* int84gt() */
 
 bool
-int84le(int64 * val1, int32 val2)
+int84le(int64 *val1, int32 val2)
 {
 	return *val1 <= val2;
 }	/* int84le() */
 
 bool
-int84ge(int64 * val1, int32 val2)
+int84ge(int64 *val1, int32 val2)
 {
 	return *val1 >= val2;
 }	/* int84ge() */
@@ -179,37 +179,37 @@ int84ge(int64 * val1, int32 val2)
  * Is 32-bit val1 relop 64-bit val2?
  */
 bool
-int48eq(int32 val1, int64 * val2)
+int48eq(int32 val1, int64 *val2)
 {
 	return val1 == *val2;
 }	/* int48eq() */
 
 bool
-int48ne(int32 val1, int64 * val2)
+int48ne(int32 val1, int64 *val2)
 {
 	return val1 != *val2;
 }	/* int48ne() */
 
 bool
-int48lt(int32 val1, int64 * val2)
+int48lt(int32 val1, int64 *val2)
 {
 	return val1 < *val2;
 }	/* int48lt() */
 
 bool
-int48gt(int32 val1, int64 * val2)
+int48gt(int32 val1, int64 *val2)
 {
 	return val1 > *val2;
 }	/* int48gt() */
 
 bool
-int48le(int32 val1, int64 * val2)
+int48le(int32 val1, int64 *val2)
 {
 	return val1 <= *val2;
 }	/* int48le() */
 
 bool
-int48ge(int32 val1, int64 * val2)
+int48ge(int32 val1, int64 *val2)
 {
 	return val1 >= *val2;
 }	/* int48ge() */
@@ -220,7 +220,7 @@ int48ge(int32 val1, int64 * val2)
  *---------------------------------------------------------*/
 
 int64 *
-int8um(int64 * val)
+int8um(int64 *val)
 {
 	int64		temp = 0;
 	int64	   *result = palloc(sizeof(int64));
@@ -228,7 +228,7 @@ int8um(int64 * val)
 	if (!PointerIsValid(val))
 		return NULL;
 
-#if FALSE
+#if NOT_USED
 	*result = temp - (*val);
 #else
 	result = int8mi(&temp, val);
@@ -239,7 +239,7 @@ int8um(int64 * val)
 
 
 int64 *
-int8pl(int64 * val1, int64 * val2)
+int8pl(int64 *val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -252,7 +252,7 @@ int8pl(int64 * val1, int64 * val2)
 }	/* int8pl() */
 
 int64 *
-int8mi(int64 * val1, int64 * val2)
+int8mi(int64 *val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -265,7 +265,7 @@ int8mi(int64 * val1, int64 * val2)
 }	/* int8mi() */
 
 int64 *
-int8mul(int64 * val1, int64 * val2)
+int8mul(int64 *val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -278,7 +278,7 @@ int8mul(int64 * val1, int64 * val2)
 }	/* int8mul() */
 
 int64 *
-int8div(int64 * val1, int64 * val2)
+int8div(int64 *val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -291,9 +291,9 @@ int8div(int64 * val1, int64 * val2)
 }	/* int8div() */
 
 int64 *
-int8larger(int64 * val1, int64 * val2)
+int8larger(int64 *val1, int64 *val2)
 {
-#if FALSE
+#if NOT_USED
 	int64	   *result = palloc(sizeof(int64));
 
 #endif
@@ -301,7 +301,7 @@ int8larger(int64 * val1, int64 * val2)
 	if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
 		return NULL;
 
-#if FALSE
+#if NOT_USED
 	*result = ((*val1 > *val2) ? *val1 : *val2);
 
 	return result;
@@ -310,9 +310,9 @@ int8larger(int64 * val1, int64 * val2)
 }	/* int8larger() */
 
 int64 *
-int8smaller(int64 * val1, int64 * val2)
+int8smaller(int64 *val1, int64 *val2)
 {
-#if FALSE
+#if NOT_USED
 	int64	   *result = palloc(sizeof(int64));
 
 #endif
@@ -320,7 +320,7 @@ int8smaller(int64 * val1, int64 * val2)
 	if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
 		return NULL;
 
-#if FALSE
+#if NOT_USED
 	*result = ((*val1 < *val2) ? *val1 : *val2);
 
 	return result;
@@ -330,7 +330,7 @@ int8smaller(int64 * val1, int64 * val2)
 
 
 int64 *
-int84pl(int64 * val1, int32 val2)
+int84pl(int64 *val1, int32 val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -343,7 +343,7 @@ int84pl(int64 * val1, int32 val2)
 }	/* int84pl() */
 
 int64 *
-int84mi(int64 * val1, int32 val2)
+int84mi(int64 *val1, int32 val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -356,7 +356,7 @@ int84mi(int64 * val1, int32 val2)
 }	/* int84mi() */
 
 int64 *
-int84mul(int64 * val1, int32 val2)
+int84mul(int64 *val1, int32 val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -369,7 +369,7 @@ int84mul(int64 * val1, int32 val2)
 }	/* int84mul() */
 
 int64 *
-int84div(int64 * val1, int32 val2)
+int84div(int64 *val1, int32 val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -383,7 +383,7 @@ int84div(int64 * val1, int32 val2)
 
 
 int64 *
-int48pl(int32 val1, int64 * val2)
+int48pl(int32 val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -396,7 +396,7 @@ int48pl(int32 val1, int64 * val2)
 }	/* int48pl() */
 
 int64 *
-int48mi(int32 val1, int64 * val2)
+int48mi(int32 val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -409,7 +409,7 @@ int48mi(int32 val1, int64 * val2)
 }	/* int48mi() */
 
 int64 *
-int48mul(int32 val1, int64 * val2)
+int48mul(int32 val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -422,7 +422,7 @@ int48mul(int32 val1, int64 * val2)
 }	/* int48mul() */
 
 int64 *
-int48div(int32 val1, int64 * val2)
+int48div(int32 val1, int64 *val2)
 {
 	int64	   *result = palloc(sizeof(int64));
 
@@ -450,14 +450,14 @@ int48(int32 val)
 }	/* int48() */
 
 int32
-int84(int64 * val)
+int84(int64 *val)
 {
 	int32		result;
 
 	if (!PointerIsValid(val))
 		elog(ERROR, "Invalid (null) int64, can't convert int8 to int4", NULL);
 
-#if FALSE
+#if NOT_USED
 
 	/*
 	 * Hmm. This conditional always tests true on my i686/linux box. It's
@@ -474,7 +474,7 @@ int84(int64 * val)
 	return result;
 }	/* int84() */
 
-#if FALSE
+#if NOT_USED
 int64 *
 int28		(int16 val)
 {
@@ -488,7 +488,7 @@ int28		(int16 val)
 }	/* int28() */
 
 int16
-int82(int64 * val)
+int82(int64 *val)
 {
 	int16		result;
 
@@ -506,7 +506,7 @@ int82(int64 * val)
 #endif
 
 float64
-i8tod(int64 * val)
+i8tod(int64 *val)
 {
 	float64		result = palloc(sizeof(float64data));
 
@@ -537,3 +537,48 @@ dtoi8(float64 val)
 
 	return result;
 }	/* dtoi8() */
+
+/* text_int8()
+ */
+int64 *
+text_int8(text *str)
+{
+	int			len;
+	char	   *s;
+
+	if (!PointerIsValid(str))
+		elog(ERROR, "Bad (null) int8 external representation", NULL);
+
+	len = (VARSIZE(str) - VARHDRSZ);
+	s = palloc(len+1);
+	memmove(s, VARDATA(str), len);
+	*(s+len) = '\0';
+
+	return int8in(s);
+}	/* text_int8() */
+
+
+/* int8_text()
+ */
+text *
+int8_text(int64 *val)
+{
+	text	   *result;
+
+	int			len;
+	char	   *s;
+
+	if (!PointerIsValid(val))
+		return NULL;
+
+	s = int8out(val);
+	len = strlen(s);
+
+	result = palloc(VARHDRSZ + len);
+
+	VARSIZE(result) = len + VARHDRSZ;
+	memmove(VARDATA(result), s, len);
+
+	return result;
+}	/* int8out() */
+
-- 
GitLab