This commit is contained in:
guha%netscape.com 1998-12-14 20:51:53 +00:00
Родитель b2888d6f9d
Коммит 8a88af0089
8 изменённых файлов: 169 добавлений и 7 удалений

128
rdf/opendir/gs.c Normal file
Просмотреть файл

@ -0,0 +1,128 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// 39204897
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "rdf-int.h"
#include "gs.h"
typedef struct _TrieNodeStruct {
char c;
struct _TrieNodeStruct* next;
struct _TrieTargetStruct* targets;
} TrieNodeStruct;
typedef TrieNodeStruct* TNS;
typedef struct _TrieTargetStruct {
RDF_Resource label;
RDF_Resource target;
struct _TrieTargetStruct* next;
RDFT db;
} TrieTargetStruct;
typedef TrieTargetStruct* TTS;
static TNS gRootNode = 0;
void addTarget (RDFT db, TNS node, RDF_Resource label, RDF_Resource targetNode) {
TTS target = (TTS) fgetMem(sizeof(TrieTargetStruct));
target->next = node->targets;
node->targets = target;
target->label = label;
target->target = targetNode;
target->db = db;
}
void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resource target) {
size_t size = strlen(string);
size_t n = 0;
TNS prev, next;
if (!gRootNode) gRootNode = (TNS) getMem(sizeof(TrieNodeStruct));
prev = gRootNode;
next = 0;
while (n < size) {
char c = string[n];
if (!wsCharp(c)) {
next = (TNS) fgetMem(sizeof(TrieNodeStruct));
next->next = gRootNode->next;
gRootNode->next = next;
gRootNode->c = c;
} else if (next) {
addTarget(db, next, label, target);
next = 0;
}
}
if (next) addTarget(db, next, label, target);
}
RDF_Cursor RDFGS_Search (RDFT db, char* searchString, RDF_Resource label) {
RDF_Cursor c = (RDF_Cursor) getMem(sizeof(RDF_CursorStruct));
c->searchString = searchString;
c->s = label;
c->db = db;
c->pdata = gRootNode;
return c;
}
void RDFGS_DisposeCursor (RDF_Cursor c) {
freeMem(c);
}
RDF_Resource RDFGS_NextValue (RDF_Cursor c) {
TNS currentTNS = (TNS) c->pdata;
TTS currentTTS = (TTS) c->pdata1;
if (!currentTNS && !currentTTS) {
return 0;
} else if (currentTTS) {
while (currentTTS) {
if ((!c->s) || (c->s == currentTTS->label)) {
RDF_Resource ans =currentTTS->target;
currentTTS = c->pdata1 = currentTTS->next;
return ans;
}
c->pdata1 = currentTTS = currentTTS->next;
}
}
while (!currentTTS) {
c->pdata = currentTNS = currentTNS->next;
if (currentTNS) c->pdata1 = currentTTS = currentTNS->targets;
}
return RDFGS_NextValue(c);
}

26
rdf/opendir/gs.h Normal file
Просмотреть файл

@ -0,0 +1,26 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* This is the header file for the RDF related search functions */
void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resource target) ;
RDF_Cursor RDFGS_Search (RDFT db, char* searchString, RDF_Resource label);
RDF_Resource RDFGS_NextValue (RDF_Cursor c) ;
void RDFGS_DisposeCursor (RDF_Cursor c);

Просмотреть файл

@ -2,7 +2,7 @@
# Microsoft Visual C makefile for WAI sample
INCLUDES = -I..\..\..\include -I..\..\include
INCLUDES = -I..\..\..\include -I..\..\include -IC:\Netscape\Suitespot\include -IC:\Netscape\Suitespot\wai\include
NSLIB = ..\..\..\lib
WAILIB= c:\netscape\suitespot\wai\lib
LIBS = $(WAILIB)\ONEiiop10.lib WSOCK32.lib
@ -16,12 +16,13 @@ OBJS = opendir.o \
remstore.o \
hash.o \
genopendir.o \
gs.o \
$(NULL)
all: opendir
opendir: opendir.c rdf.c rdfparse.c remstore.c hash.c genopendir.c
opendir: opendir.c rdf.c rdfparse.c remstore.c hash.c genopendir.c gs.c
$(CC) $(CPPFLAGS) $(LIBS) $? -o $@
clean:

Просмотреть файл

@ -116,7 +116,7 @@ int main(int argc, char **argv)
WAIregisterService(obj, host);
RDF_Initialize();
printf("RDF Initialized!\n");
RDF_ReadFile("excite.rdf");
RDF_ReadFile("opendir.rdf");
printf("done");

Просмотреть файл

@ -50,7 +50,8 @@ typedef struct _RDF_ResourceStruct {
typedef enum {
GET_SLOT_VALUES,
ARC_LABELS_IN,
ARC_LABELS_OUT
ARC_LABELS_OUT,
SEARCH
} QueryType;
@ -75,12 +76,14 @@ typedef struct _RDF_CursorStruct {
RDF_Resource u;
RDF_Resource s;
void *value;
struct _RDF_AssertionStruct* pdata;
void* pdata;
void* pdata1;
int inversep;
RDF_ValueType type;
int count;
RDFT db;
QueryType queryType;
char* searchString;
} RDF_CursorStruct;

Просмотреть файл

@ -43,7 +43,8 @@ char* RDF_ResourceID(RDF_Resource u);
int RDF_Assert(RDFT db, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
int RDF_Unassert (RDFT db, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
int RDF_HasAssertion (RDFT db, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
int RDF_HasAssertion (RDFT db, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type);
void* RDF_OnePropValue (RDFT db, RDF_Resource u, RDF_Resource s, RDF_ValueType type);
RDF_Cursor RDF_GetTargets (RDFT db, RDF_Resource u, RDF_Resource s, RDF_ValueType type);
RDF_Cursor RDF_GetSourcess (RDFT db, RDF_Resource u, RDF_Resource s);

Просмотреть файл

@ -20,6 +20,7 @@
#include "rdf-int.h"
#include <stdio.h>
char* error_string = NULL;
int lineNumber = 0;

Просмотреть файл

@ -16,7 +16,7 @@
* Reserved.
*/
#include "rdf-int.h"
#include "gs.h"
int
asEqual(RDFT r, Assertion as, RDF_Resource u, RDF_Resource s, void* v,
@ -81,6 +81,8 @@ remoteStoreAdd (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
newAs->invNext = iu->rarg2;
iu->rarg2 = newAs;
}
if (type == RDF_STRING_TYPE) RDFGS_AddSearchIndex(mcf, (char*) v, s, u);
return newAs;
}