Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <libguile.h>
- SCM daemon_wrapper(SCM nochdir, SCM noclose)
- {
- return scm_from_int(daemon(scm_to_int(nochdir), scm_to_int(noclose)));
- }
- static int arg_count;
- static char** arguments;
- SCM get_arguments_wrapper(int argc, char** argv)
- {
- SCM arguments = SCM_EOL;
- for (int i = argc - 1; i >= 0; --i) arguments = scm_cons(scm_from_utf8_string(argv[i]), arguments);
- return arguments;
- }
- int main(int argc, char** argv)
- {
- arg_count = argc;
- arguments = argv;
- scm_init_guile();
- scm_c_define_gsubr("daemon", 2, 0, 0, daemon_wrapper);
- scm_c_define_gsubr("get-arguments", 2, 0, 0, get_arguments_wrapper);
- /* We can do literally nothing without the database. */
- scm_c_eval_string(
- "(define-module (sapod)"
- " #:use-module (ice-9 getopt-long)"
- " #:use-module (ice-9 threads)"
- " #:use-module (sqlite3)"
- " #:use-module (srfi srfi-43)"
- " #:use-module (system repl server))"
- "(get-arguments)"
- "(set-current-module (resolve-module '(sapod)))"
- "(import (except (guile-user) (get-arguments)))"
- "(define database-path)"
- "(let ((options (getopt-long (get-arguments) '((database-path (single-char #\\d) (value #t) (required? #t))))))"
- " (set! database-path (option-ref options 'database-path '())))"
- "(define database (sqlite-open database-path))"
- "(define (sapod-load-modules predicate)"
- " (sqlite-map (lambda (row) (vector-ref row 0)) (sqlite-prepare database (format #f \"SELECT source FROM guile WHERE ~a\" predicate))))"
- "(eval-string (car (sapod-load-modules \"module='__sapod-lib.scm'\")))"
- "(eval-string (car (sapod-load-modules \"module='__boot.scm'\")))"
- "(run-server (make-tcp-server-socket #:port 51281))");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment