Difference between revisions of "Peerd.c"

From Organic Design wiki
m
(ok got that bullshit sorted I think)
Line 19: Line 19:
  
 
#include "listSpace.c"  // listSpace and some C-specific extras: hash, trie, linked-list
 
#include "listSpace.c"  // listSpace and some C-specific extras: hash, trie, linked-list
 
+
#include "args.c"      // Handle command-line args and globals like peer and port
// Store the command-line args in the listSpace hash, eg char *name = *hash("name")
 
printf("argc=%d\n",argc);
 
int l;
 
while (argc-->2) {
 
char **arg = split('=',argv[argc]);
 
*hash(*arg) = strncpy(malloc(l=strlen(arg[1])+1),arg[1],l);
 
printf("\t*hash(\"%s\")=\"%s\"\n",arg[0],arg[1]);
 
free(arg);
 
}
 
 
 
// Make a global peer name and port number
 
char *peer = strncpy(malloc(l=strlen(argv[1])+1),argv[1],l);
 
int port = atoi(*hash("port"));
 
 
 
// Set name as seen in ps list
 
char *tmp = *argv;
 
for (l=40;l--;) *tmp++ = '\0';
 
sprintf(*argv,"peerd: %s (http%d)",peer,port);
 
printf("argv[0] = \"%s\"\n",*argv);
 
 
 
printf("postargs\n");
 
 
#include "nodeSpace.c"  // NodeSpace function declarations and initialisation
 
#include "nodeSpace.c"  // NodeSpace function declarations and initialisation
 
#include "serialise.c"  // Nodal-to-text and visa-versa
 
#include "serialise.c"  // Nodal-to-text and visa-versa
Line 47: Line 26:
 
#include "server.c"    // Set up listening socket and declare serverIterate
 
#include "server.c"    // Set up listening socket and declare serverIterate
  
printf("port=%s\n",*hash("port"));
 
printf("fredie=%s\n",*hash("fred"));
 
 
logAdd("\nEntering nodal reduction...\n");
 
logAdd("\nEntering nodal reduction...\n");
 
while(nodeReduce(this=ROOT));
 
while(nodeReduce(this=ROOT));

Revision as of 07:46, 22 July 2006

// This article and all its includes are licenced under LGPL // GPL: http://www.gnu.org/copyleft/lesser.html // SRC: http://www.organicdesign.co.nz/husk.c

  1. include <unistd.h>
  2. include <stdlib.h>
  3. include <stdio.h>
  4. include <string.h>

int main(int argc, char **argv) {

#include "util.c" // General utils, file,log,string etc

#ifdef WINDOWS // Set up as a daemon or service #include "servicate.c" #else #include "daemonise.c" #endif

#include "listSpace.c" // listSpace and some C-specific extras: hash, trie, linked-list #include "args.c" // Handle command-line args and globals like peer and port #include "nodeSpace.c" // NodeSpace function declarations and initialisation #include "serialise.c" // Nodal-to-text and visa-versa #include "interface.c" // Layer model (currently bitmap/imagemap-based) #include "nodalHusk.c" // Build initial nodal environment #include "server.c" // Set up listening socket and declare serverIterate

logAdd("\nEntering nodal reduction...\n"); while(nodeReduce(this=ROOT));

free(space);

}