head     1.5;
branch   ;
access   ;
symbols  Version_2_1:1.5 C_Demo_1:1.2;
locks    ; strict;
comment  @ * @;


1.5
date     91.02.28.20.55.14;  author mao;  state Exp;
branches ;
next     1.4;

1.4
date     90.09.25.16.16.23;  author kemnitz;  state Exp;
branches ;
next     1.3;

1.3
date     89.09.21.18.45.53;  author hirohama;  state Exp;
branches ;
next     1.2;

1.2
date     89.09.05.16.58.29;  author mao;  state C_Demo_1;
branches ;
next     1.1;

1.1
date     89.01.19.22.24.27;  author aoki;  state Stab;
branches ;
next     ;


desc
@base keyword functions
@


1.5
log
@typecast calls to palloc
@
text
@/*
 * kw.c --
 *	Primitive Keyword operations.
 */

#include <strings.h>

#include "tmp/c.h"

RcsId("$Header: RCS/kw.c,v 1.4 90/09/25 16:16:23 kemnitz Exp Locker: mao $");

#include "access/kwlist.h"
#include "utils/palloc.h"

Keyword
keyword_in(s)
        char	*s;
{
        Keyword	result;

        if (s == NULL)
                return(NULL);
        result = (Keyword) palloc(sizeof(KeywordData));
	bzero((char *) result, sizeof(KeywordData));
	strncpy((char *) result, s, sizeof(KeywordData));
        return(result);
}

KeywordList
kw_in(s)
        char	*s;
{
        KeywordList	result;

        if (s == NULL)
                return(NULL);
        result = (KeywordList) palloc(KeywordListSize(1));
	bzero((char *) result, KeywordListSize(1));
	KeywordListSetKeywordCount(result, 1);
	KeywordListSetKeyword(result, 0, s);
        return(result);
}

char *
keyword_out(kw)
        Keyword	kw;
{
        char	*result = (char *) palloc(sizeof(KeywordData) + 1);

	bzero(result, sizeof(KeywordData) + 1);
        if (kw == NULL) {
                result[0] = '-';
                result[1] = '\0';
        } else {
                strncpy(result, (char *) kw, sizeof(KeywordData));
                result[sizeof(KeywordData)] = '\0';
        }
        return(result);
}

char *
kw_out(kw)
        KeywordList	kw;
{
        char	*result = (char *) palloc(sizeof(KeywordData) + 1);

	bzero(result, sizeof(KeywordData) + 1);
        if (kw == NULL) {
                result[0] = '-';
                result[1] = '\0';
        } else {
                strncpy(result,
			(char *) KeywordListGetKeyword(kw, 0),
			sizeof(KeywordData));
                result[sizeof(KeywordData)] = '\0';
        }
        return(result);
}


int32
kw_cmp(keyword1, keyword2)
	Keyword	keyword1, keyword2;
{
	return(strncmp(KeywordGetData(keyword1),
		       KeywordGetData(keyword2),
		       sizeof(KeywordData)));
}


int32
kw_eq(keyword1, keyword2)
	KeywordList	keyword1, keyword2;
{
	register int	i;
	int		count = KeywordListGetKeywordCount(keyword1);
	Keyword		test = KeywordListGetKeyword(keyword2, 0);

	for (i = 0; i < count; ++i)
		if (kw_cmp(KeywordListGetKeyword(keyword1, i), test) == 0)
			return(1);
	return(0);
}

int32
kw_ne(keyword1, keyword2)
	KeywordList	keyword1, keyword2;
{
	register int	i;
	int		count = KeywordListGetKeywordCount(keyword1);
	Keyword		test = KeywordListGetKeyword(keyword2, 0);

	for (i = 0; i < count; ++i)
		if (kw_cmp(KeywordListGetKeyword(keyword1, i), test) != 0)
			return(1);
	return(0);
}

int32
kw_lt(keyword1, keyword2)
	KeywordList	keyword1, keyword2;
{
	register int	i;
	int		count = KeywordListGetKeywordCount(keyword1);
	Keyword		test = KeywordListGetKeyword(keyword2, 0);

	for (i = 0; i < count; ++i)
		if (kw_cmp(KeywordListGetKeyword(keyword1, i), test) < 0)
			return(1);
	return(0);
}

int32
kw_le(keyword1, keyword2)
	KeywordList	keyword1, keyword2;
{
	register int	i;
	int		count = KeywordListGetKeywordCount(keyword1);
	Keyword		test = KeywordListGetKeyword(keyword2, 0);

	for (i = 0; i < count; ++i)
		if (kw_cmp(KeywordListGetKeyword(keyword1, i), test) <= 0)
			return(1);
	return(0);
}

int32
kw_gt(keyword1, keyword2)
	KeywordList	keyword1, keyword2;
{
	register int	i;
	int		count = KeywordListGetKeywordCount(keyword1);
	Keyword		test = KeywordListGetKeyword(keyword2, 0);

	for (i = 0; i < count; ++i)
		if (kw_cmp(KeywordListGetKeyword(keyword1, i), test) > 0)
			return(1);
	return(0);
}

int32
kw_ge(keyword1, keyword2)
	KeywordList	keyword1, keyword2;
{
	register int	i;
	int		count = KeywordListGetKeywordCount(keyword1);
	Keyword		test = KeywordListGetKeyword(keyword2, 0);

	for (i = 0; i < count; ++i)
		if (kw_cmp(KeywordListGetKeyword(keyword1, i), test) >= 0)
			return(1);
	return(0);
}
@


1.4
log
@Updating from revision 1.3 to revision 1.4
@
text
@d10 1
a10 1
RcsId("$Header: RCS/kw.c,v 1.4 90/08/15 09:27:33 cimarron Exp $");
d48 1
a48 1
        char	*result = palloc(sizeof(KeywordData) + 1);
d65 1
a65 1
        char	*result = palloc(sizeof(KeywordData) + 1);
@


1.3
log
@palloc now defined in "palloc.h" not "postgres.h"
@
text
@d6 1
a6 1
#include "c.h"
d8 1
a8 1
RcsId("$Header: RCS/kw.c,v 1.2 89/09/05 16:58:29 mao C_Demo_1 Locker: hirohama $");
d10 1
a10 1
#include <strings.h>
d12 2
a13 3
#include "palloc.h"

#include "kwlist.h"
@


1.2
log
@Working version of C-only demo
@
text
@a5 1
#include <strings.h>
a6 1
#include "postgres.h"
d8 5
a12 1
RcsId("$Header: /usr6/postgres/mao/postgres/src/access/index-ftree/RCS/kw.c,v 1.1 89/01/19 22:24:27 aoki Stab $");
@


1.1
log
@Initial revision
@
text
@d10 1
a10 1
RcsId("$Header$");
@
