From a57be65f1003c57c2e39c651b2d6e97e6d853a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 3 Oct 2023 19:00:12 -0300 Subject: Add a default name transformer --- cmamut.lisp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmamut.lisp b/cmamut.lisp index 7017a93..e608c25 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -294,15 +294,23 @@ (string/= (gethash "tag" x) "const"))) raw-spec)) -(defun run (path-to-header-file &key package-name shared-object additional-directories name-transformer) - (unless (probe-file path-to-header-file) - (error (format t "The header file ~a doesn't exist!" path-to-header-file))) +(defun default-name-transformer (name type) + (cond ((eq type :const) + (concatenate 'string "+" (string-upcase (str:underscore->hyphen name)) "+")) + (t (string-upcase + (str:pascal->kebab + (str:upcase->pascal + (str:underscore->hyphen name))))))) + +(defun run (header-file &key package-name shared-object additional-directories name-transformer) + (unless (probe-file header-file) + (error (format t "The header file ~a doesn't exist!" header-file))) (when (not (find-package +target-package+)) (make-package +target-package+)) - (setf path-to-header-file (parse-namestring path-to-header-file)) - (push (directory-namestring path-to-header-file) additional-directories) - (let* ((raw-spec (get-raw-spec (namestring path-to-header-file) additional-directories)) + (setf header-file (parse-namestring header-file)) + (push (directory-namestring header-file) additional-directories) + (let* ((raw-spec (get-raw-spec (namestring header-file) additional-directories)) (spec (classify-definitions (filter-directories additional-directories raw-spec))) - (code (codegen spec (or name-transformer (lambda (name kind) name))))) - (to-file code (concatenate 'string (pathname-name path-to-header-file) ".lisp") package-name shared-object)) + (code (codegen spec (or name-transformer #'default-name-transformer)))) + (to-file code (concatenate 'string (pathname-name header-file) ".lisp") package-name shared-object)) (delete-package (find-package +target-package+))) -- cgit v1.2.3