(import (scheme base)
        (scm fs)
        (scm io)
        (scm module))

(define script-dir (directory-name (absolute-path script-name)))
(define base-dir (directory-name script-dir))
(module-search-path! (list (join-path base-dir "scm")))

(import (splg utils)
        (splg options)
        (splg analyzer))

(define (parse-options args)
  (let loop ((args args)
             (options `((cfg-dir ,(join-path base-dir "cfg"))
                        (input ,(join-path "data" "input")))))
    (if (null? args)
        options
        (let ((arg (car args)))
          (cond ((equal? arg "--cfg-dir")
                 (loop (cddr args)
                       (set-option options 'cfg-dir (cadr args))))
                ((equal? arg "--analyze-input")
                 (loop (cddr args)
                       (set-option options 'input (cadr args))))
                ((equal? arg "--help")
                 (display-help)
                 #f)
                (else
                 (format #t "Unknown option ~a~%" arg)
                 #f))))))

(define (display-help)
  (format #t "--cfg-dir <path>~%")
  (format #t "--analyze-input <dir>~%")
  (format #t "--help~%"))

(let ((options (parse-options script-arguments)))
  (if options
      (run-analyzer options)))
