зеркало из https://github.com/mozilla/pjs.git
bunch of fixes to make it run properly under Solaris
This commit is contained in:
Родитель
36188f0b5c
Коммит
439d8f2706
|
@ -16,6 +16,9 @@
|
||||||
* Reserved.
|
* Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "rdf.h"
|
#include "rdf.h"
|
||||||
|
|
||||||
RDF_Resource
|
RDF_Resource
|
||||||
|
@ -30,7 +33,7 @@ getNodeFromQuery (char* query) {
|
||||||
|
|
||||||
void
|
void
|
||||||
AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) {
|
AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) {
|
||||||
char *buff = malloc(10000);
|
char *buff = (char*) malloc(10000);
|
||||||
RDF_Resource items[300];
|
RDF_Resource items[300];
|
||||||
RDF_Resource topics[100];
|
RDF_Resource topics[100];
|
||||||
RDF_Resource child = RDF_GetResource("child", 1);
|
RDF_Resource child = RDF_GetResource("child", 1);
|
||||||
|
@ -44,8 +47,8 @@ AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) {
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
RDF_Cursor c = RDF_GetTargets(0, node, child, RDF_RESOURCE_TYPE);
|
RDF_Cursor c = RDF_GetTargets(0, node, child, RDF_RESOURCE_TYPE);
|
||||||
RDF_Resource ans = 0;
|
RDF_Resource ans ;
|
||||||
while (c && (ans = RDF_NextValue(c))) {
|
while (c && (ans = (RDF_Resource) RDF_NextValue(c))) {
|
||||||
int subjectp = RDF_HasAssertion(0, ans, type, topic, RDF_RESOURCE_TYPE);
|
int subjectp = RDF_HasAssertion(0, ans, type, topic, RDF_RESOURCE_TYPE);
|
||||||
if (subjectp) {
|
if (subjectp) {
|
||||||
topics[topicCount++] = ans;
|
topics[topicCount++] = ans;
|
||||||
|
@ -63,7 +66,7 @@ AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) {
|
||||||
(*callBack)(obj, "<tr>");
|
(*callBack)(obj, "<tr>");
|
||||||
while ((w < ROW_WIDTH) && (n < topicCount)) {
|
while ((w < ROW_WIDTH) && (n < topicCount)) {
|
||||||
RDF_Resource u = topics[n];
|
RDF_Resource u = topics[n];
|
||||||
char* nm = RDF_OnePropValue(0, u, name, RDF_STRING_TYPE);
|
char* nm = (char*) RDF_OnePropValue(0, u, name, RDF_STRING_TYPE);
|
||||||
char* id = RDF_ResourceID(u);
|
char* id = RDF_ResourceID(u);
|
||||||
sprintf(buff, "<td><li><a href=\"OpenDir?%s\">%s</a></td>", id, (nm ? nm : id));
|
sprintf(buff, "<td><li><a href=\"OpenDir?%s\">%s</a></td>", id, (nm ? nm : id));
|
||||||
(*callBack)(obj, buff);
|
(*callBack)(obj, buff);
|
||||||
|
@ -82,7 +85,7 @@ AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) {
|
||||||
int w = 0;
|
int w = 0;
|
||||||
|
|
||||||
RDF_Resource u = items[n];
|
RDF_Resource u = items[n];
|
||||||
char* nm = RDF_OnePropValue(0, u, name, RDF_STRING_TYPE);
|
char* nm = (char*) RDF_OnePropValue(0, u, name, RDF_STRING_TYPE);
|
||||||
char* id = RDF_ResourceID(u);
|
char* id = RDF_ResourceID(u);
|
||||||
sprintf(buff, "<li><a href=\"%s\">%s</a>", id, (nm ? nm : id));
|
sprintf(buff, "<li><a href=\"%s\">%s</a>", id, (nm ? nm : id));
|
||||||
(*callBack)(obj, buff);
|
(*callBack)(obj, buff);
|
||||||
|
|
|
@ -35,7 +35,7 @@ typedef struct _HashTableStruct {
|
||||||
HashEntry* buckets; /* vector of hash buckets */
|
HashEntry* buckets; /* vector of hash buckets */
|
||||||
} HashTableStruct;
|
} HashTableStruct;
|
||||||
|
|
||||||
typedef HashTableStruct* HashTable;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
hashKey (HashTable ht, char* key) {
|
hashKey (HashTable ht, char* key) {
|
||||||
|
@ -89,9 +89,9 @@ HashAdd (HashTable ht, char* key, void* value) {
|
||||||
he->value = value;
|
he->value = value;
|
||||||
he->key = key;
|
he->key = key;
|
||||||
if (prev) {
|
if (prev) {
|
||||||
prev->next = he;
|
prev->next = he;
|
||||||
} else {
|
} else {
|
||||||
ht->buckets[offset] = he;
|
ht->buckets[offset] = he;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "ONEiiop.h"
|
#include "ONEiiop.h"
|
||||||
#include "rdf.h"
|
#include "rdf.h"
|
||||||
|
|
||||||
#if !defined(WIN32) && !defined(HPUX) && !defined(OSF1)
|
#if !defined(WIN32)
|
||||||
extern "C" int gethostname(char *name, int namelen);
|
extern "C" int gethostname(char *name, int namelen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -37,7 +37,7 @@ void AnswerOpenDirQuery(WriteClientProc callBack, void* obj, char* query);
|
||||||
long
|
long
|
||||||
Run(ServerSession_t obj)
|
Run(ServerSession_t obj)
|
||||||
{
|
{
|
||||||
char* query = malloc(300);
|
char* query = (char*) malloc(300);
|
||||||
WAIgetRequestInfo(obj, "QUERY", &query);
|
WAIgetRequestInfo(obj, "QUERY", &query);
|
||||||
|
|
||||||
//WAIsetResponseContentLength(obj, 10000);
|
//WAIsetResponseContentLength(obj, 10000);
|
||||||
|
@ -115,6 +115,7 @@ int main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
WAIregisterService(obj, host);
|
WAIregisterService(obj, host);
|
||||||
RDF_Initialize();
|
RDF_Initialize();
|
||||||
|
printf("RDF Initialized!\n");
|
||||||
RDF_ReadFile("excite.rdf");
|
RDF_ReadFile("excite.rdf");
|
||||||
|
|
||||||
printf("done");
|
printf("done");
|
||||||
|
|
|
@ -44,7 +44,7 @@ typedef struct _RDF_ResourceStruct {
|
||||||
struct _RDF_AssertionStruct* rarg2;
|
struct _RDF_AssertionStruct* rarg2;
|
||||||
} RDF_ResourceStruct ;
|
} RDF_ResourceStruct ;
|
||||||
|
|
||||||
typedef RDF_ResourceStruct* RDF_Resource;
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -69,7 +69,7 @@ typedef struct _RDF_FileStruct {
|
||||||
struct _RDF_AssertionStruct** assertionList;
|
struct _RDF_AssertionStruct** assertionList;
|
||||||
} RDF_FileStruct;
|
} RDF_FileStruct;
|
||||||
|
|
||||||
typedef RDF_FileStruct* RDFT;
|
|
||||||
|
|
||||||
typedef struct _RDF_CursorStruct {
|
typedef struct _RDF_CursorStruct {
|
||||||
RDF_Resource u;
|
RDF_Resource u;
|
||||||
|
@ -83,7 +83,7 @@ typedef struct _RDF_CursorStruct {
|
||||||
QueryType queryType;
|
QueryType queryType;
|
||||||
} RDF_CursorStruct;
|
} RDF_CursorStruct;
|
||||||
|
|
||||||
typedef RDF_CursorStruct* RDF_Cursor;
|
|
||||||
|
|
||||||
typedef struct _RDF_AssertionStruct {
|
typedef struct _RDF_AssertionStruct {
|
||||||
RDF_Resource u;
|
RDF_Resource u;
|
||||||
|
@ -103,7 +103,7 @@ HashTable NewHashTable(int size) ;
|
||||||
void* HashLookup(HashTable ht, char* key) ;
|
void* HashLookup(HashTable ht, char* key) ;
|
||||||
void HashAdd (HashTable ht, char* key, void* value) ;
|
void HashAdd (HashTable ht, char* key, void* value) ;
|
||||||
|
|
||||||
|
void readRDFFile (char* file) ;
|
||||||
RDF_Resource getResource(char* url, int createp);
|
RDF_Resource getResource(char* url, int createp);
|
||||||
char* getMem(size_t n);
|
char* getMem(size_t n);
|
||||||
char* fgetMem (size_t size) ;
|
char* fgetMem (size_t size) ;
|
||||||
|
|
|
@ -81,6 +81,7 @@ void RDF_DisposeCursor (RDF_Cursor c) {
|
||||||
|
|
||||||
char** RDF_processPathQuery(char* query) {
|
char** RDF_processPathQuery(char* query) {
|
||||||
// return processRDFQuery (query) ;
|
// return processRDFQuery (query) ;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "rdf-int.h"
|
#include "rdf-int.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
char* error_string = NULL;
|
char* error_string = NULL;
|
||||||
int lineNumber = 0;
|
int lineNumber = 0;
|
||||||
|
@ -26,7 +27,7 @@ static HashTable resourceHash = NULL;
|
||||||
|
|
||||||
RDF_Resource
|
RDF_Resource
|
||||||
getResource (char* key, int createp) {
|
getResource (char* key, int createp) {
|
||||||
RDF_Resource existing = HashLookup(resourceHash, key);
|
RDF_Resource existing = (RDF_Resource) HashLookup(resourceHash, key);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
return existing;
|
return existing;
|
||||||
} else if (createp){
|
} else if (createp){
|
||||||
|
@ -47,8 +48,9 @@ size_t allocated = 0;
|
||||||
#define MEM_BLOCK_SIZE 10000
|
#define MEM_BLOCK_SIZE 10000
|
||||||
|
|
||||||
char*
|
char*
|
||||||
fgetMem (size_t size) {
|
fgetMem (size_t rsize) {
|
||||||
char* ans = 0;
|
char* ans = 0;
|
||||||
|
size_t size = rsize + (4 - ldiv(rsize, 4).rem);
|
||||||
if (!MemBlock || (size >= (MEM_BLOCK_SIZE - allocated))) {
|
if (!MemBlock || (size >= (MEM_BLOCK_SIZE - allocated))) {
|
||||||
MemBlock = getMem(MEM_BLOCK_SIZE);
|
MemBlock = getMem(MEM_BLOCK_SIZE);
|
||||||
allocated = 0;
|
allocated = 0;
|
||||||
|
@ -62,20 +64,22 @@ fgetMem (size_t size) {
|
||||||
void readRDFFile (char* file) {
|
void readRDFFile (char* file) {
|
||||||
FILE* f = fopen(file, "r");
|
FILE* f = fopen(file, "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
RDFT rf = (RDFT)getRDFT(file, 1) ;
|
RDFT rf = (RDFT)getRDFT(file, 1) ;
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
char* buff = malloc(100 * 1024);
|
char* buff = (char*) malloc(100 * 1024);
|
||||||
int len ;
|
int len ;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
memset(buff, '\0', (100 * 1024));
|
memset(buff, '\0', (100 * 1024));
|
||||||
memset(rf, '\0', sizeof(RDF_FileStruct));
|
memset(rf, '\0', sizeof(RDF_FileStruct));
|
||||||
|
|
||||||
rf->line = (char*)getMem(RDF_BUF_SIZE);
|
rf->line = (char*)getMem(RDF_BUF_SIZE);
|
||||||
rf->holdOver = (char*)getMem(RDF_BUF_SIZE);
|
rf->holdOver = (char*)getMem(RDF_BUF_SIZE);
|
||||||
rf->depth = 1;
|
rf->depth = 1;
|
||||||
rf->lastItem = rf->stack[0] ;
|
rf->lastItem = rf->stack[0] ;
|
||||||
while ((len = fread(buff, 1, (100 * 1024) -1, f)) > 0) {
|
while ((len = fread(buff, 1, (100 * 1024) -1, f)) > 0) {
|
||||||
buff[len] = '\0';
|
buff[len] = '\0';
|
||||||
printf("[%i] ", i++);
|
printf("[%i] ", i++);
|
||||||
|
fflush(0);
|
||||||
if (!(ok = parseNextRDFXMLBlobInt(rf, buff, len))) {
|
if (!(ok = parseNextRDFXMLBlobInt(rf, buff, len))) {
|
||||||
printf("Error in RDF File\n");
|
printf("Error in RDF File\n");
|
||||||
}
|
}
|
||||||
|
@ -93,7 +97,7 @@ static HashTable rdftHash = NULL;
|
||||||
|
|
||||||
RDFT
|
RDFT
|
||||||
getRDFT (char* key, int createp) {
|
getRDFT (char* key, int createp) {
|
||||||
RDFT existing = HashLookup(rdftHash, key);
|
RDFT existing = (RDFT) HashLookup(rdftHash, key);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
return existing;
|
return existing;
|
||||||
} else if (createp){
|
} else if (createp){
|
||||||
|
@ -259,8 +263,8 @@ parseNextRDFXMLBlobInt(RDFT f, char* blob, int size) {
|
||||||
if (c == '<') f->holdOver[0] = '<';
|
if (c == '<') f->holdOver[0] = '<';
|
||||||
if (somethingseenp == 1) {
|
if (somethingseenp == 1) {
|
||||||
int ok = parseNextRDFToken(f, f->line);
|
int ok = parseNextRDFToken(f, f->line);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (size > last) {
|
} else if (size > last) {
|
||||||
memcpy(f->holdOver, f->line, m);
|
memcpy(f->holdOver, f->line, m);
|
||||||
|
@ -327,6 +331,8 @@ parseNextRDFToken (RDFT f, char* token)
|
||||||
{
|
{
|
||||||
char* attlist[2*MAX_ATTRIBUTES+1];
|
char* attlist[2*MAX_ATTRIBUTES+1];
|
||||||
char* elementName;
|
char* elementName;
|
||||||
|
|
||||||
|
fflush(0);
|
||||||
|
|
||||||
|
|
||||||
if (token[0] != '<') {
|
if (token[0] != '<') {
|
||||||
|
@ -337,7 +343,7 @@ parseNextRDFToken (RDFT f, char* token)
|
||||||
remoteStoreAdd(f, u, s, val , RDF_STRING_TYPE, 1);
|
remoteStoreAdd(f, u, s, val , RDF_STRING_TYPE, 1);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
sprintf(error_string, "Did not expect \n\"%s\".\n Was expecting a tag.", token);
|
printf(error_string, "Did not expect \n\"%s\".\n Was expecting a tag.", token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (startsWith("<!--", token)) {
|
} else if (startsWith("<!--", token)) {
|
||||||
|
@ -346,7 +352,7 @@ parseNextRDFToken (RDFT f, char* token)
|
||||||
return 1;
|
return 1;
|
||||||
} else if (token[1] == '/') {
|
} else if (token[1] == '/') {
|
||||||
if ((f->status != EXPECTING_OBJECT) && (f->status != EXPECTING_PROPERTY)) {
|
if ((f->status != EXPECTING_OBJECT) && (f->status != EXPECTING_PROPERTY)) {
|
||||||
sprintf(error_string, "Did not expect %s. Something pretty screwed up", token);
|
printf(error_string, "Did not expect %s. Something pretty screwed up", token);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (f->depth > 0) f->depth--;
|
if (f->depth > 0) f->depth--;
|
||||||
|
@ -367,9 +373,9 @@ parseNextRDFToken (RDFT f, char* token)
|
||||||
url = getID(attlist);
|
url = getID(attlist);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
if (f->tagDepth > 2) {
|
if (f->tagDepth > 2) {
|
||||||
sprintf(error_string, "Unbalanced tags ");
|
printf(error_string, "Unbalanced tags ");
|
||||||
} else {
|
} else {
|
||||||
sprintf(error_string, "Require a \"about\" attribute on %s", token);
|
printf(error_string, "Require a \"about\" attribute on %s", token);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -405,6 +411,7 @@ parseNextRDFToken (RDFT f, char* token)
|
||||||
f->status = EXPECTING_OBJECT;
|
f->status = EXPECTING_OBJECT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ asEqual(RDFT r, Assertion as, RDF_Resource u, RDF_Resource s, void* v,
|
||||||
(as->s == s) &&
|
(as->s == s) &&
|
||||||
(as->type == type) &&
|
(as->type == type) &&
|
||||||
((as->value == v) ||
|
((as->value == v) ||
|
||||||
((type == RDF_STRING_TYPE) && (strcmp(v, as->value) == 0))));
|
((type == RDF_STRING_TYPE) && (strcmp((char*)v, (char*)as->value) == 0))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ void
|
||||||
addToAssertionList (RDFT f, Assertion as)
|
addToAssertionList (RDFT f, Assertion as)
|
||||||
{
|
{
|
||||||
if (f->assertionListCount >= f->assertionListSize) {
|
if (f->assertionListCount >= f->assertionListSize) {
|
||||||
f->assertionList = realloc(f->assertionList,
|
f->assertionList = (Assertion*) realloc(f->assertionList,
|
||||||
(sizeof(Assertion*) *
|
(sizeof(Assertion*) *
|
||||||
(f->assertionListSize =
|
(f->assertionListSize =
|
||||||
f->assertionListSize + GROW_LIST_INCR)));
|
f->assertionListSize + GROW_LIST_INCR)));
|
||||||
|
|
Загрузка…
Ссылка в новой задаче