;;; Gash --- Guile As SHell
;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of Gash.
;;;
;;; Gash is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; Gash is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Gash.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gash core-utils)
  #:use-module (ice-9 match)
  #:use-module (gash core-utils config)
  #:export (register-core-utils))

(define *core-utils*
  `(("[" . ,(@@ (gash core-utils test) test/bracket))
    ("awk" . ,(@@ (gash core-utils awk) main))
    ("basename" . ,(@@ (gash core-utils basename) main))
    ("cat" . ,(@@ (gash core-utils cat) main))
    ("chmod" . ,(@@ (gash core-utils chmod) main))
    ("cmp" . ,(@@ (gash core-utils cmp) main))
    ("compress" . ,(@@ (gash core-utils compress) main))
    ("cp" . ,(@@ (gash core-utils cp) main))
    ("cut" . ,(@@ (gash core-utils cut) main))
    ("diff" . ,(@@ (gash core-utils diff) main))
    ("dirname" . ,(@@ (gash core-utils dirname) main))
    ("expr" . ,(@@ (gash core-utils expr) main))
    ("false" . ,(@@ (gash core-utils false) main))
    ("find" . ,(@@ (gash core-utils find) main))
    ("grep" . ,(@@ (gash core-utils grep) main))
    ("head" . ,(@@ (gash core-utils head) main))
    ("ln" . ,(@@ (gash core-utils ln) main))
    ("ls" . ,(@@ (gash core-utils ls) main))
    ("mkdir" . ,(@@ (gash core-utils mkdir) main))
    ("mv" . ,(@@ (gash core-utils mv) main))
    ("pwd" . ,(@@ (gash core-utils pwd) main))
    ("reboot" . ,(@@ (gash core-utils reboot) main))
    ("rm" . ,(@@ (gash core-utils rm) main))
    ("rmdir" . ,(@@ (gash core-utils rmdir) main))
    ("sed" . ,(@@ (gash core-utils sed) main))
    ("sleep" . ,(@@ (gash core-utils sleep) main))
    ("sort" . ,(@@ (gash core-utils sort) main))
    ("tar" . ,(@@ (gash core-utils tar) main))
    ("test" . ,(@@ (gash core-utils test) main))
    ("touch" . ,(@@ (gash core-utils touch) main))
    ("tr" . ,(@@ (gash core-utils tr) main))
    ("true" . ,(@@ (gash core-utils true) main))
    ("uname" . ,(@@ (gash core-utils uname) main))
    ("uniq" . ,(@@ (gash core-utils uniq) main))
    ("wc" . ,(@@ (gash core-utils wc) main))
    ("which" . ,(@@ (gash core-utils which) main))))

(define (register-core-utils)
  (let ((*built-ins* (@@ (gash built-ins) *built-ins*))
        (module (resolve-module '(gash built-ins)))
        (*core-utils* (map (match-lambda
                             ((name . proc)
                              `(name . ,(lambda args
                                          (apply proc (cons name args))))))
                           *core-utils*)))
    (module-define! module '*built-ins* (append *built-ins* *core-utils*))))
