;;; frsh-forb.el --- Helper functions for editing FRSH/FORB sources ;; Copyright (C) 2010 Michal Sojka ;; Author: Michal Sojka ;; Keywords: c, files, convenience ;; This program 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. ;; This program 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 this program. If not, see . ;;; Commentary: ;; ;;; Code: (defun update-fres-error-c () "When called from fres_error.h it updates fres_error.c to match the list if defined errors" (save-excursion (beginning-of-buffer) (let* ((beg (progn (re-search-forward "^enum fres_error \{") (beginning-of-line 2) (point))) (end (progn (search-forward "}") (beginning-of-line) (point)))) (let ((errors)) (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (while (re-search-forward "^[[:space:]]*FRES_ERR_" nil t) (push (current-word) errors))) (save-current-buffer (set-buffer (find-file-noselect "fres_error.c")) (beginning-of-buffer) (search-forward "switch (e) {") (kill-region (point) (save-excursion (search-forward "}") (backward-char) (point))) (insert "\n") (dolist (e errors) (insert "\n") (indent-according-to-mode) (previous-line) (insert (concat "MSG(" (replace-regexp-in-string "^FRES_ERR_" "" e) ");")) (indent-according-to-mode) (beginning-of-line))))) (message "fres_error.c updated"))) (provide 'frsh-forb) ;;; frsh-forb.el ends here