/
aiko_server.c
95 lines (73 loc) · 2.44 KB
/
aiko_server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Please do not remove the following notices.
*
* \file aiko_server.c
* \author Andy Gelme <andyg@geekscape.org>
* \copyright (c) 2015 by Geekscape Pty. Ltd.
* \license AGPLv3 http://geekscape.org/static/aiko_license.html
*
* Description
* ~~~~~~~~~~~
* Aiko (Lisp) server: Unix implementation
*
* Usage
* ~~~~~
* ./aiko_server [ source_file ]
*
* nc -u localhost 4149
* (3:car(1:a1:b)) // Lisp 1.5 with canonical S-expressions :)
* (5:debug) // toggle lispDebug flag
* (8:addTimer) // add timer every 1 second for a single count
* (8:addTimer4:2000) // add timer every 2 seconds for a single count
* (8:addTimer4:20001:4) // add timer every 2 seconds for 4 counts
* (4:load) // load "aikoStore" from persistant storage
* (4:save) // save "aikoStore" to persistent storage
* (4:wifi(4:ssid8:password)) // set Wi-Fi station SSID and password
*
* To Do
* ~~~~~
* - None, yet.
*/
#include <stdio.h>
#include <string.h>
#include "aiko_engine.h"
#include "lisp.h"
#include "../common/aiko_server/lisp_extend.h"
aiko_store_t aiko_server_store;
/* ------------------------------------------------------------------------- */
FILE *initialize(
int argc,
char *argv[]) {
tExpression *lisp_environment = lisp_initialize(LISP_DEBUG);
if (lispError) {
printf("lisp_initialize(): %s\n", lispErrorMessage);
exit(-1);
}
memset(& aiko_server_store, 0x00, sizeof(aiko_server_store));
aiko_server_store.size = sizeof(aiko_server_store);
aiko_server_store.magic = AIKO_STORE_MAGIC;
aiko_server_store.version = AIKO_STORE_VERSION;
lisp_extend(lisp_environment, & aiko_server_store);
if (lispError) {
printf("lisp_extend(): %s\n", lispErrorMessage);
exit(-1);
}
FILE *inputFile = stdin;
if (argc > 1) inputFile = fopen(argv[1], "r");
return(inputFile);
}
/* ------------------------------------------------------------------------- */
int main(
int argc,
char *argv[]) {
FILE *input_file = initialize(argc, argv);
printf("[%s %s]\n", argv[0], AIKO_VERSION);
aiko_add_handler(aiko_create_file_stream(input_file), lisp_message_handler);
aiko_add_handler(
aiko_create_socket_stream(AIKO_STREAM_SOCKET_UDP4, TRUE, 0, AIKO_PORT),
lisp_message_handler
);
aiko_loop(AIKO_LOOP_FOREVER);
return(0);
}
/* ------------------------------------------------------------------------- */