summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/cash.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-08-03 16:35:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-08-03 16:35:08 +0000
commitc298d74d4957845bb03a67092c30b53e5e0d01c2 (patch)
tree4dca901e87c14a249de21374da867db1059b8462 /src/backend/utils/adt/cash.c
parent1bd3a8f58bb8147628a85643b0246051a6e4e5ee (diff)
More functions updated to new fmgr style --- money, name, tid datatypes.
We're reaching the mopup stage here (good thing too, this is getting tedious).
Diffstat (limited to 'src/backend/utils/adt/cash.c')
-rw-r--r--src/backend/utils/adt/cash.c184
1 files changed, 82 insertions, 102 deletions
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c
index e1a68940a84..d924bf3fe09 100644
--- a/src/backend/utils/adt/cash.c
+++ b/src/backend/utils/adt/cash.c
@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.44 2000/08/01 18:29:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.45 2000/08/03 16:34:22 tgl Exp $
*/
#include <limits.h>
@@ -66,11 +66,11 @@ CashGetDatum(Cash value)
* XXX UNHACK Allow the currency symbol to be multi-byte.
* - thomas 1998-03-01
*/
-Cash *
-cash_in(const char *str)
+Datum
+cash_in(PG_FUNCTION_ARGS)
{
- Cash *result;
-
+ char *str = PG_GETARG_CSTRING(0);
+ Cash result;
Cash value = 0;
Cash dec = 0;
Cash sgn = 1;
@@ -200,17 +200,14 @@ cash_in(const char *str)
if (*s != '\0')
elog(ERROR, "Bad money external representation %s", str);
- if (!PointerIsValid(result = palloc(sizeof(Cash))))
- elog(ERROR, "Memory allocation failed, can't input cash '%s'", str);
-
- *result = (value * sgn);
+ result = (value * sgn);
#ifdef CASHDEBUG
- printf("cashin- result is %d\n", *result);
+ printf("cashin- result is %d\n", result);
#endif
- return result;
-} /* cash_in() */
+ PG_RETURN_CASH(result);
+}
/* cash_out()
@@ -218,10 +215,10 @@ cash_in(const char *str)
* XXX HACK This code appears to assume US conventions for
* positive-valued amounts. - tgl 97/04/14
*/
-const char *
-cash_out(Cash *in_value)
+Datum
+cash_out(PG_FUNCTION_ARGS)
{
- Cash value = *in_value;
+ Cash value = PG_GETARG_CASH(0);
char *result;
char buf[CASH_BUFSZ];
int minus = 0;
@@ -323,103 +320,95 @@ cash_out(Cash *in_value)
strcpy(result, buf + count);
}
- return result;
-} /* cash_out() */
+ PG_RETURN_CSTRING(result);
+}
-bool
-cash_eq(Cash *c1, Cash *c2)
+Datum
+cash_eq(PG_FUNCTION_ARGS)
{
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return FALSE;
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
- return *c1 == *c2;
-} /* cash_eq() */
+ PG_RETURN_BOOL(c1 == c2);
+}
-bool
-cash_ne(Cash *c1, Cash *c2)
+Datum
+cash_ne(PG_FUNCTION_ARGS)
{
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return FALSE;
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
- return *c1 != *c2;
-} /* cash_ne() */
+ PG_RETURN_BOOL(c1 != c2);
+}
-bool
-cash_lt(Cash *c1, Cash *c2)
+Datum
+cash_lt(PG_FUNCTION_ARGS)
{
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return FALSE;
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
- return *c1 < *c2;
-} /* cash_lt() */
+ PG_RETURN_BOOL(c1 < c2);
+}
-bool
-cash_le(Cash *c1, Cash *c2)
+Datum
+cash_le(PG_FUNCTION_ARGS)
{
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return FALSE;
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
- return *c1 <= *c2;
-} /* cash_le() */
+ PG_RETURN_BOOL(c1 <= c2);
+}
-bool
-cash_gt(Cash *c1, Cash *c2)
+Datum
+cash_gt(PG_FUNCTION_ARGS)
{
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return FALSE;
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
- return *c1 > *c2;
-} /* cash_gt() */
+ PG_RETURN_BOOL(c1 > c2);
+}
-bool
-cash_ge(Cash *c1, Cash *c2)
+Datum
+cash_ge(PG_FUNCTION_ARGS)
{
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return FALSE;
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
- return *c1 >= *c2;
-} /* cash_ge() */
+ PG_RETURN_BOOL(c1 >= c2);
+}
/* cash_pl()
* Add two cash values.
*/
-Cash *
-cash_pl(Cash *c1, Cash *c2)
+Datum
+cash_pl(PG_FUNCTION_ARGS)
{
- Cash *result;
-
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return NULL;
-
- if (!PointerIsValid(result = palloc(sizeof(Cash))))
- elog(ERROR, "Memory allocation failed, can't add cash");
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
+ Cash result;
- *result = (*c1 + *c2);
+ result = c1 + c2;
- return result;
-} /* cash_pl() */
+ PG_RETURN_CASH(result);
+}
/* cash_mi()
* Subtract two cash values.
*/
-Cash *
-cash_mi(Cash *c1, Cash *c2)
+Datum
+cash_mi(PG_FUNCTION_ARGS)
{
- Cash *result;
-
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return NULL;
-
- if (!PointerIsValid(result = palloc(sizeof(Cash))))
- elog(ERROR, "Memory allocation failed, can't subtract cash");
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
+ Cash result;
- *result = (*c1 - *c2);
+ result = c1 - c2;
- return result;
-} /* cash_mi() */
+ PG_RETURN_CASH(result);
+}
/* cash_mul_flt8()
@@ -626,41 +615,32 @@ cash_div_int2(PG_FUNCTION_ARGS)
/* cashlarger()
* Return larger of two cash values.
*/
-Cash *
-cashlarger(Cash *c1, Cash *c2)
+Datum
+cashlarger(PG_FUNCTION_ARGS)
{
- Cash *result;
-
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return NULL;
-
- if (!PointerIsValid(result = palloc(sizeof(Cash))))
- elog(ERROR, "Memory allocation failed, can't return larger cash");
-
- *result = ((*c1 > *c2) ? *c1 : *c2);
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
+ Cash result;
- return result;
-} /* cashlarger() */
+ result = (c1 > c2) ? c1 : c2;
+ PG_RETURN_CASH(result);
+}
/* cashsmaller()
* Return smaller of two cash values.
*/
-Cash *
-cashsmaller(Cash *c1, Cash *c2)
+Datum
+cashsmaller(PG_FUNCTION_ARGS)
{
- Cash *result;
-
- if (!PointerIsValid(c1) || !PointerIsValid(c2))
- return NULL;
-
- if (!PointerIsValid(result = palloc(sizeof(Cash))))
- elog(ERROR, "Memory allocation failed, can't return smaller cash");
+ Cash c1 = PG_GETARG_CASH(0);
+ Cash c2 = PG_GETARG_CASH(1);
+ Cash result;
- *result = ((*c1 < *c2) ? *c1 : *c2);
+ result = (c1 < c2) ? c1 : c2;
- return result;
-} /* cashsmaller() */
+ PG_RETURN_CASH(result);
+}
/* cash_words()