head 1.13; access; symbols Version_2_1:1.10 C_Demo_1:1.3; locks; strict; comment @ * @; 1.13 date 92.07.12.23.12.08; author joey; state Exp; branches; next 1.12; 1.12 date 92.05.28.21.15.56; author mer; state Exp; branches; next 1.11; 1.11 date 91.03.16.17.29.20; author sp; state Exp; branches; next 1.10; 1.10 date 91.02.28.20.55.51; author mao; state Exp; branches; next 1.9; 1.9 date 91.02.25.12.09.14; author choi; state Exp; branches; next 1.8; 1.8 date 91.02.19.15.17.29; author cimarron; state Exp; branches; next 1.7; 1.7 date 91.02.19.08.43.01; author kemnitz; state Exp; branches; next 1.6; 1.6 date 90.10.15.23.25.54; author cimarron; state Exp; branches; next 1.5; 1.5 date 90.09.25.16.48.55; author kemnitz; state Exp; branches; next 1.4; 1.4 date 89.09.21.18.59.57; author hirohama; state Exp; branches; next 1.3; 1.3 date 89.09.05.17.25.44; author mao; state C_Demo_1; branches; next 1.2; 1.2 date 89.01.20.06.57.41; author aoki; state Stab; branches; next 1.1; 1.1 date 89.01.17.05.58.29; author cimarron; state Exp; branches; next ; desc @@ 1.13 log @change char16in to null out its extra bytes @ text @/* * char.c -- * Functions for the built-in type "char". * Functions for the built-in type "char16". */ #include #include "tmp/postgres.h" RcsId("$Header: /private/joey/pg/src/utils/adt/RCS/char.c,v 1.12 1992/05/28 21:15:56 mer Exp joey $"); #include "utils/palloc.h" char *PG_username; char * pg_username() { return(PG_username); } /* ========== USER I/O ROUTINES ========== */ /* * charin - converts "x" to 'x' */ int32 charin(ch) char *ch; { if (ch == NULL) return((int32) NULL); return((int32) *ch); } /* * charout - converts 'x' to "x" */ char * charout(ch) int32 ch; { char *result = (char *) palloc(2); result[0] = (char) ch; result[1] = '\0'; return(result); } /* * cidin - converts "..." to internal representation. * * NOTE: we must no use 'charin' because cid might be a non * printable character... */ int32 cidin(s) char *s; { CommandId c; if (s==NULL) c = 0; else c = atoi(s); return((int32)c); } /* * cidout - converts a cid to "..." * * NOTE: we must no use 'charout' because cid might be a non * printable character... */ char * cidout(c) int32 c; { char *result; CommandId c2; /* * cid is a number between 0 .. 2^16-1, therefore we need at most * 4 chars for the string (6 digits + '\0') * NOTE: print it as an UNSIGNED int! */ result = palloc(8); c2 = (CommandId)c; sprintf(result, "%u", (unsigned)(c2)); return(result); } /* * char16in - converts "..." to internal reprsentation * * Note: * Currently if strlen(s) < 14, the extra chars are nulls */ char * char16in(s) char *s; { char *result; int i; if (s == NULL) return(NULL); result = (char *) palloc(16); strncpy(result, s, 16); /* null out the extra chars */ for (i = strlen(s) + 1; i < 16; i++) result[i] = '\0'; return(result); } /* * char16out - converts internal reprsentation to "..." */ char * char16out(s) char *s; { char *result = (char *) palloc(17); if (s == NULL) { result[0] = '-'; result[1] = '\0'; } else { strncpy(result, s, 16); result[16] = '\0'; } return(result); } /* ========== PUBLIC ROUTINES ========== */ int32 chareq(arg1, arg2) int8 arg1, arg2; { return(arg1 == arg2); } int32 charne(arg1, arg2) int8 arg1, arg2; { return(arg1 != arg2); } int32 charlt(arg1, arg2) int8 arg1, arg2; { return(arg1 < arg2); } int32 charle(arg1, arg2) int8 arg1, arg2; { return(arg1 <= arg2); } int32 chargt(arg1, arg2) int8 arg1, arg2; { return(arg1 > arg2); } int32 charge(arg1, arg2) int8 arg1, arg2; { return(arg1 >= arg2); } int32 charpl(arg1, arg2) int8 arg1, arg2; { return(arg1 + arg2); } int32 charmi(arg1, arg2) int8 arg1, arg2; { return(arg1 - arg2); } int32 charmul(arg1, arg2) int8 arg1, arg2; { return(arg1 * arg2); } int32 chardiv(arg1, arg2) int8 arg1, arg2; { return(arg1 / arg2); } /* * char16eq - returns 1 iff arguments are equal * char16ne - returns 1 iff arguments are not equal * * BUGS: * Assumes that "xy\0\0a" should be equal to "xy\0b". * If not, can do the comparison backwards for efficiency. * * char16lt - returns 1 iff a < b * char16le - returns 1 iff a <= b * char16gt - returns 1 iff a < b * char16ge - returns 1 iff a <= b * */ int32 char16eq(arg1, arg2) char *arg1, *arg2; { if (arg1 == NULL || arg2 == NULL) return((int32) NULL); return((int32) (strncmp(arg1, arg2, 16) == 0)); } int32 char16ne(arg1, arg2) char *arg1, *arg2; { return((int32) !char16eq(arg1, arg2)); } int32 char16lt(arg1, arg2) char *arg1, *arg2; { if (arg1 == NULL || arg2 == NULL) return((int32) NULL); return((int32) (strncmp(arg1, arg2, 16) < 0)); } int32 char16le(arg1, arg2) char *arg1, *arg2; { if (arg1 == NULL || arg2 == NULL) return((int32) NULL); return((int32) (strncmp(arg1, arg2, 16) <= 0)); } int32 char16gt(arg1, arg2) char *arg1, *arg2; { if (arg1 == NULL || arg2 == NULL) return((int32) NULL); return((int32) (strncmp(arg1, arg2, 16) > 0)); } int32 char16ge(arg1, arg2) char *arg1, *arg2; { if (arg1 == NULL || arg2 == NULL) return((int32) NULL); return((int32) (strncmp(arg1, arg2, 16) >= 0)); } @ 1.12 log @xids are now shorts, xidin and xidout now reflect this @ text @d11 1 a11 1 RcsId("$Header: /private/mer/pg.latest/src/utils/adt/RCS/char.c,v 1.11 1991/03/16 17:29:20 sp Exp mer $"); d100 1 a100 1 * Currently if strlen(s) < 14, the extra chars are garbage. d107 1 a107 1 d112 3 @ 1.11 log @Added routines : 'cidin' and 'cidout' @ text @d9 1 a9 1 #include "tmp/c.h" d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.10 91/02/28 20:55:51 mao Exp $"); d62 1 a62 1 unsigned char c; d83 1 a83 1 unsigned char c2; d86 2 a87 2 * cid is a number between 0 .. 255, therefore we need at most * 4 chars for the string (3 digits + '\0') d90 3 a92 3 result = palloc(4); c2 = c; sprintf(result, "%d", (int)(c2)); @ 1.10 log @typecast calls to palloc @ text @d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.9 91/02/25 12:09:14 choi Exp Locker: mao $"); d50 44 @ 1.9 log @pg_username no longer takes any dummy argument. @ text @d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.8 91/02/19 15:17:29 cimarron Exp Locker: choi $"); d45 1 a45 1 char *result = palloc(2); d66 1 a66 1 result = palloc(16); d78 1 a78 1 char *result = palloc(17); @ 1.8 log @moved PG_username definition to char.c so that support routines not linking against tcop/postgres.c will compile. @ text @d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.7 91/02/19 08:43:01 kemnitz Exp Locker: cimarron $"); d18 1 a18 2 pg_username(dummy) int dummy; @ 1.7 log @Added pg_username() @ text @d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.6 90/10/15 23:25:54 cimarron Exp Locker: kemnitz $"); d15 9 a174 11 } char * pg_username(dummy) int dummy; { extern char *PG_username; return(PG_username); @ 1.6 log @added new system catalog functions for tuple id printing and char16 compairson @ text @d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.5 90/09/25 16:48:55 kemnitz Exp $"); d166 11 @ 1.5 log @Updating from revision 1.4 to revision 1.5 @ text @d11 1 a11 1 RcsId("$Header: RCS/char.c,v 1.5 90/08/15 08:16:29 cimarron Exp $"); d104 6 d113 1 a113 1 char *arg1, *arg2; d116 3 a118 13 if (arg1 == NULL || arg2 == NULL) return((int32) NULL); return((int32) (strncmp(arg1, arg2, 16) == 0)); /* register char *a1p, *a2p; a1p = arg1 + 15; a2p = arg2 + 15; while (*a1p-- == *a2p--) if (a1p < arg1) return(1L); return(0L); */ d123 1 a123 1 char *arg1, *arg2; d125 1 a125 1 return((int32) !char16eq(arg1, arg2)); d128 6 d135 2 a136 1 /* ========== PRIVATE ROUTINES ========== */ d138 29 a166 1 /* (none) */ @ 1.4 log @palloc defined in "palloc.h" not "postgres.h" @ text @d7 1 a7 1 #include "c.h" d9 1 a9 1 RcsId("$Header: RCS/char.c,v 1.3 89/09/05 17:25:44 mao C_Demo_1 Locker: hirohama $"); d11 3 a13 2 #include #include "palloc.h" @ 1.3 log @Working version of C-only demo @ text @a7 1 #include "postgres.h" d9 2 d12 1 a12 3 RcsId("$Header: /usr6/postgres/mao/postgres/src/utils/adt/RCS/char.c,v 1.2 89/01/20 06:57:41 aoki Stab $"); @ 1.2 log @*** empty log message *** @ text @d12 1 a12 1 RcsId("$Header: char.c,v 1.2 89/01/17 03:15:38 aoki Exp $"); @ 1.1 log @Initial revision @ text @a0 1 a1 26 * * POSTGRES Data Base Management System * * Copyright (c) 1988 Regents of the University of California * * Permission to use, copy, modify, and distribute this software and its * documentation for educational, research, and non-profit purposes and * without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, and that * the name of the University of California not be used in advertising * or publicity pertaining to distribution of the software without * specific, written prior permission. Permission to incorporate this * software into commercial products can be obtained from the Campus * Software Office, 295 Evans Hall, University of California, Berkeley, * Ca., 94720 provided only that the the requestor give the University * of California a free licence to any derived software for educational * and research purposes. The University of California makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ /* d12 1 a12 1 RcsId("$Header: char.c,v 1.1 88/11/11 16:35:41 postgres Exp $"); d84 11 @