|
|
| Line 41: |
Line 41: |
| | // Currently it can't compile, so additional functionality required by nodal-app are pre-declared here | | // Currently it can't compile, so additional functionality required by nodal-app are pre-declared here |
| | // later the script and its functions will be a nodal-state produced by a nodal-build and cache | | // later the script and its functions will be a nodal-state produced by a nodal-build and cache |
| − |
| |
| − | // Process passed "alias1|alias2|alias3..." string (GUID's are just alias's)
| |
| − | // NOTE: GUID-alias is traversed as ASCII not binary - these are external guids
| |
| − | // - this is using list-space as a dictionary
| |
| − | // - the nodal structure of a number can still be binary
| |
| − | // - used by [de]serialise()
| |
| − | // - returns integer index of subject node
| |
| − | int processNodeLink(char *link) {
| |
| − | int subject = atoi(link); // not like this anymore, passed link is external
| |
| − | // - split by pipe and for each,
| |
| − | // - if its a number, convert to a binary-coded-string of \x00's and \x01's
| |
| − | // - traverse from root through name using chr-as-node-index,
| |
| − | // - the first iteration creates the subject,
| |
| − | // - subsequent iterations must link their last jump to the existing subject
| |
| − | return subject;
| |
| − | }
| |
| − |
| |
| − | // Convert a node to text for storage or transport
| |
| − | char* serialise(int subject) {
| |
| − | char *text;
| |
| − | return text;
| |
| − | }
| |
| − |
| |
| − | // Convert textual represntation of one or more nodes and associations to nodal change
| |
| − | int deserialise(char *text) {
| |
| − | printf("\nPARSING THE FOLLOWING TEXT:\n--------------------------------------------\n%s\n--------------------------------------------\n\n", text);
| |
| − | printf("INFORMATION EXTRACTED:\n--------------------------------------------\n");
| |
| − | int node, subject = 0, key, i, j = 0, linkStart, c;
| |
| − | char links[100];
| |
| − | char *link1 = (char*)&links;
| |
| − | char *link2 = link1+50;
| |
| − | for (i = 0; i < strlen(text); i++) {
| |
| − | char *s = text+i;
| |
| − | if ((c = (int)s[0]) < 32) j = 1;
| |
| − | else switch (j) {
| |
| − | case 0: // waiting for next line
| |
| − | break;
| |
| − | case 1: // starting new line
| |
| − | // - if not starting with *[[ then wait for next line
| |
| − | if (strncmp(s, "*[[", 3) == 0) {
| |
| − | j = 2;
| |
| − | linkStart = i;
| |
| − | } else j = 0;
| |
| − | break;
| |
| − | case 2: // processing first link
| |
| − | if (strncmp(s, "]]", 2) == 0) {
| |
| − | if (strncmp(s, "]]:[[", 5) == 0) {
| |
| − | // link1 as an association-key
| |
| − | // key = strtoint(...)
| |
| − | j = 3; // process link2 next
| |
| − | }
| |
| − | else {
| |
| − | // link1 specifies a change of nodal subject
| |
| − | link1 = strncpy(link1, text+linkStart+3, i-linkStart-3);
| |
| − | link1[i-linkStart-3] = '\0';
| |
| − | subject = processNodeLink(link1);
| |
| − | printf("%d:\n", subject);
| |
| − | j = 0; // wait for new line
| |
| − | }
| |
| − | }
| |
| − | break;
| |
| − | case 3: // processing second link
| |
| − | if (strncmp(s, "]]", 2) == 0) {
| |
| − | // process link2
| |
| − | link1 = strncpy(link1, text+linkStart+3, i-linkStart-3);
| |
| − | link2 = strchr(link1, '[')+2;
| |
| − | link1[i-linkStart-3] = '\0';
| |
| − | link1[i-linkStart-strlen(link2)-8] = '\0';
| |
| − | int key = processNodeLink(link1);
| |
| − | int val = processNodeLink(link2);
| |
| − | // store in nodal-space
| |
| − | // - we use list functions because nodal functions cause change
| |
| − | listSetValue(listTraverse(subject,key),val);
| |
| − | printf(" %d => %d\n", key, val);
| |
| − | j = 0;
| |
| − | }
| |
| − | break;
| |
| − | }
| |
| − | //printf("chr:%c,%d\n",s[0],j);
| |
| − | }
| |
| − | printf("--------------------------------------------\n");
| |
| − | return node;
| |
| − | }
| |
| | | | |
| | // box properties | | // box properties |
// prototype of listSpace in c
// Licenced under LGPL: www.gnu.org/copyleft/lesser.html
- include <stdlib.h>
- include <stdio.h>
- include <string.h>
// Globals & constants
- define MAXITEMS 10000
int i,j; // global iterators
int items = 0;
int *space;
// Strucst used to emulate a variant-type
typedef struct types {
char* text;
void (*code)();
int number;
} variant;
int main() {
#include "listSpace.c"
#include "nodeSpace.c"
#include "server.c"
// NODAL CONTENT - default "hardwired" default-nodal-app
// define the serialsed-text version of nodal structure
// - allow shorthand for Next's?
// NodalSpace = deserialise(string);
// if the node is a function (same type-check as reduce() uses),
// then use its value (if any) as local function name,
// change it to a ref with this[functionName] (if pre-declared - see below)
// NODAL FUNCTIONS - later included in content instead of "hardwired" here
// pre-declared functions built by nodal-app
// Currently it can't compile, so additional functionality required by nodal-app are pre-declared here
// later the script and its functions will be a nodal-state produced by a nodal-build and cache
// box properties
// events
// tcc
int test = deserialise( "testing deserialise:\n\r== can do headings for wiki ==\n*Foo\n*bar:hello # my special association\r\r\n*baz:world\n*key:1628\n*key2:[[8928|]]\n*key3:value");
printf("\n%d list-space items have been created.\n", items);
// Count how many nodes have payloads
int p=0;
for (i=0; i<MAXITEMS; i++) if (listGetValue(i)) p++;
printf("%d items in use:\n", p);
for (i=0; i<MAXITEMS; i++) if (j=listGetValue(i)) printf(" %d = %d\n",i,j);
printf("\n\n");
}