;;;
;;; c-aide.el: Insert heading comment depend on file type.
;;;
;;; Mar.11,'95. Naoki Oshiro.
;;; First version.
;;; Aug.11,'95. Naoki Oshiro.
;;; ".el", ".c", ".h", ".sh", ".tex" added.
;;; Mar.28,'96. Naoki Oshiro.
;;; Add comment and ".html".
;;;
(require 'get-date)
;;;
;;; Wrapper depend on file type.
;;;
(defun c-prologue ()
(interactive)
(let (filename)
(setq filename (file-name-nondirectory (buffer-file-name)))
(insert
(cond
((string-match "\\.h$" filename)
(concat
(c-prologue:get-c-headcomment filename)
(c-prologue:get-h-firstproc filename)))
((string-match "\\.c$" filename)
(concat
(c-prologue:get-c-headcomment filename)
(c-prologue:get-c-firstproc filename)))
((string-match "\\.el$" filename)
(c-prologue:get-el-headcomment filename))
((or (string-match "\\.tex$" filename)
(string-match "\\.sty$" filename))
(c-prologue:get-tex-headcomment filename))
((or (string-match "\\.html$" filename))
(c-prologue:get-html-headcomment filename))
(t
(c-prologue:get-sh-headcomment filename)
)
))))
(defun c-prologue:get-c-headcomment (filename)
(concat
"/* \n"
" * " filename ": \n"
" * \n"
" * " (c-prologue:get-date) " " (user-full-name) ".\n"
" * \n"
" * $Log:$\n"
" */\n"
"\n"))
;;; for Elisp
(defun c-prologue:get-el-headcomment (filename)
(concat
";;; \n"
";;; " filename ": \n"
";;; \n"
";;; " (c-prologue:get-date) " " (user-full-name) ".\n"
";;; \n"
";;; $Log:$\n"
";;;\n"
"\n"))
;;; for HTML
(defun c-prologue:get-html-headcomment (filename)
(concat
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"
\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"))
;;; for Shell or others
(defun c-prologue:get-sh-headcomment (filename)
(concat
"# \n"
"# " filename ": \n"
"# \n"
"# " (c-prologue:get-date) " " (user-full-name) ".\n"
"# \n"
"# $Log:$\n"
"#\n"
"\n"))
;;; for TeX
(defun c-prologue:get-tex-headcomment (filename)
(concat
"% \n"
"% " filename ": \n"
"% \n"
"% " (c-prologue:get-date) " " (user-full-name) ".\n"
"% \n"
"% $Log:$\n"
"%\n"
"\n"))
;;;
;;; utilities for C
;;;
;;; for C source
(defun c-prologue:get-c-firstproc (filename)
(concat
"static char rcsid[]=\"$Id:$\";\n"
"\n"
"#include \n"
"#include \n"
"\n"))
;;; for C header
(defun c-prologue:get-h-firstproc (filename)
(let ((id filename))
(setq id (upcase id))
(string-match "\\." id)
(setq id
(concat
"_"
(substring id 0 (match-beginning 0))
"_"
(substring id (match-end 0))))
(concat
"#ifndef " id "\n"
"#define " id "\n"
"\n"
"\n"
"#endif /* " id " */\n")))
;;;
;;; utilities
;;;
(defun c-prologue:get-date ()
(get-date))
; (let ((date (current-time-string)))
; (concat (substring date 4 7) "."
; (substring date 8 10) ","
; "'" (substring date 22 24) ".")))
;(defun get-date ()
; (interactive)
; (let ((date (current-time-string)))
; (insert
; (concat "[" (substring date 20 24) "/"
; (c-prologue:month-to-strnum (substring date 4 7)) "/"
; (c-prologue:num-to-strnum (substring date 8 10)) "]"
; ))))
;
;(defun get-dtime ()
; (interactive)
; (let ((date (current-time-string)))
; (insert
; (concat "[" (substring date 20 24) "/"
; (c-prologue:month-to-strnum (substring date 4 7)) "/"
; (c-prologue:num-to-strnum (substring date 8 10)) " "
; (substring date 11 16) "]"
; ))))
;
;(defun get-time ()
; (interactive)
; (let ((date (current-time-string)))
; (insert
; (concat "["
; (substring date 11 16) "]"
; ))))
;
;(defun c-prologue:month-to-strnum (str)
; "月を示す文字列から数字文字列に変換(当てはまらない場合は00)"
; (let (mm)
; (if (setq mm (assoc str
; '(("Jan" . "01")("Feb" . "02")("Mar" . "03")("Apr" . "04")
; ("May" . "05")("Jun" . "06")("Jul" . "07")("Aug" . "08")
; ("Sep" . "09")("Oct" . "10")("Nov" . "11")("Dec" . "12"))))
; (cdr mm)
; "00")))
;
;(defun c-prologue:num-to-strnum (str)
; "月を示す文字列から数字文字列に変換(当てはまらない場合はそのまま)"
; (let (mm)
; (if (setq mm (assoc str
; '((" 1" . "01")(" 2" . "02")(" 3" . "03")(" 4" . "04")
; (" 5" . "05")(" 6" . "06")(" 7" . "07")(" 8" . "08")
; (" 9" . "09"))))
; (cdr mm)
; str)))