Guest User

Untitled

a guest
Jul 2nd, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.75 KB | None | 0 0
  1. #include <unistd.h>
  2.  
  3. #include <libguile.h>
  4.  
  5. SCM daemon_wrapper(SCM nochdir, SCM noclose)
  6. {
  7.   return scm_from_int(daemon(scm_to_int(nochdir), scm_to_int(noclose)));
  8. }
  9.  
  10. static int arg_count;
  11. static char** arguments;
  12. SCM get_arguments_wrapper(int argc, char** argv)
  13. {
  14.   SCM arguments = SCM_EOL;
  15.   for (int i = argc - 1; i >= 0; --i) arguments = scm_cons(scm_from_utf8_string(argv[i]), arguments);
  16.   return arguments;
  17. }
  18.  
  19. int main(int argc, char** argv)
  20. {
  21.   arg_count = argc;
  22.   arguments = argv;
  23.  
  24.   scm_init_guile();
  25.  
  26.   scm_c_define_gsubr("daemon", 2, 0, 0, daemon_wrapper);
  27.   scm_c_define_gsubr("get-arguments", 2, 0, 0, get_arguments_wrapper);
  28.  
  29.   /* We can do literally nothing without the database. */
  30.   scm_c_eval_string(
  31.     "(define-module (sapod)"
  32.     " #:use-module (ice-9 getopt-long)"
  33.     " #:use-module (ice-9 threads)"
  34.     " #:use-module (sqlite3)"
  35.     " #:use-module (srfi srfi-43)"
  36.     " #:use-module (system repl server))"
  37.     "(get-arguments)"
  38.     "(set-current-module (resolve-module '(sapod)))"
  39.     "(import (except (guile-user) (get-arguments)))"
  40.     "(define database-path)"
  41.     "(let ((options (getopt-long (get-arguments) '((database-path (single-char #\\d) (value #t) (required? #t))))))"
  42.     "  (set! database-path (option-ref options 'database-path '())))"
  43.     "(define database (sqlite-open database-path))"
  44.     "(define (sapod-load-modules predicate)"
  45.     "    (sqlite-map (lambda (row) (vector-ref row 0)) (sqlite-prepare database (format #f \"SELECT source FROM guile WHERE ~a\" predicate))))"
  46.     "(eval-string (car (sapod-load-modules \"module='__sapod-lib.scm'\")))"
  47.     "(eval-string (car (sapod-load-modules \"module='__boot.scm'\")))"
  48.     "(run-server (make-tcp-server-socket #:port 51281))");
  49.  
  50.   return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment