| 1 | ;;; -*-emacs-lisp-*- |
| 2 | |
| 3 | (skel-include "skelrc.c") |
| 4 | |
| 5 | (defun skelrc-c-sanitize-guard (s) |
| 6 | (setq s (copy-sequence s)) |
| 7 | (let ((i 0) (l (length s))) |
| 8 | (while (< i l) |
| 9 | (let ((c (aref s i))) |
| 10 | (aset s i (if (eq (char-syntax c) ?w) (upcase c) ?_))) |
| 11 | (setq i (1+ i)))) |
| 12 | s) |
| 13 | |
| 14 | (defun skelrc-c-guard-name () |
| 15 | (if buffer-file-name |
| 16 | (skelrc-c-sanitize-guard |
| 17 | (concat |
| 18 | (let ((pre (or (skelrc-assq 'guard-prefix skel-alist) |
| 19 | (skelrc-assq 'library skel-alist) |
| 20 | (skelrc-assq 'Library skel-alist)))) |
| 21 | (if pre (concat pre "/"))) |
| 22 | (file-name-nondirectory buffer-file-name))) |
| 23 | (skel-lookup 'include-guard-name))) |
| 24 | |
| 25 | (setq skel-alist |
| 26 | (append |
| 27 | '((preamble . "[[guard]][[c++-guard]][[includes]][[structures]][[functions]]") |
| 28 | (guard . "#ifndef [[guard-name]]\n#define [[guard-name]]\n\n") |
| 29 | (guard-name . (skelrc-c-guard-name)) |
| 30 | (c++-guard . "#ifdef __cplusplus\n extern \"C\" {\n#endif\n\n") |
| 31 | (includes . "[[includes-banner]]\n\n[[headers]]") |
| 32 | (includes-banner . (skelrc-banner "Header files")) |
| 33 | (headers . "") |
| 34 | (structures . "[[struct-banner]]\n\n") |
| 35 | (struct-banner . (skelrc-banner "Data structures")) |
| 36 | (functions . "[[func-banner]]\n\n") |
| 37 | (func-banner . (skelrc-banner "Functions provided")) |
| 38 | (postamble . "\n[[c++-unguard]]#endif\n") |
| 39 | (c++-unguard . "#ifdef __cplusplus\n }\n#endif\n\n")) |
| 40 | skel-alist)) |