| 1 |
;;;-*- Mode:LISP; Package:CHAOS; Base:10; Syntax:Common-lisp -*- |
| 2 |
;;; |
| 3 |
;;; Copyright (c) 2000-2015, Toshimi Sawada. All rights reserved. |
| 4 |
;;; |
| 5 |
;;; Redistribution and use in source and binary forms, with or without |
| 6 |
;;; modification, are permitted provided that the following conditions |
| 7 |
;;; are met: |
| 8 |
;;; |
| 9 |
;;; * Redistributions of source code must retain the above copyright |
| 10 |
;;; notice, this list of conditions and the following disclaimer. |
| 11 |
;;; |
| 12 |
;;; * Redistributions in binary form must reproduce the above |
| 13 |
;;; copyright notice, this list of conditions and the following |
| 14 |
;;; disclaimer in the documentation and/or other materials |
| 15 |
;;; provided with the distribution. |
| 16 |
;;; |
| 17 |
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED |
| 18 |
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 |
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 21 |
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 23 |
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 |
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 |
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 |
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
;;; |
| 29 |
;;; (in-package :chaos) |
| 30 |
#|============================================================================== |
| 31 |
System: CHAOS |
| 32 |
Module: comlib |
| 33 |
File: message.lisp |
| 34 |
==============================================================================|# |
| 35 |
#-:chaos-debug |
| 36 |
(declaim (optimize (speed 3) (safety 0) #-GCL (debug 0))) |
| 37 |
#+:chaos-debug |
| 38 |
(declaim (optimize (speed 1) (safety 3) #-GCL (debug 3))) |
| 39 |
|
| 40 |
(defvar *Panic-messages* (make-hash-table)) |
| 41 |
(defvar *Error-messages* (make-hash-table)) |
| 42 |
(defvar *Warning-messages* (make-hash-table)) |
| 43 |
(defvar *Simple-messages* (make-hash-table)) |
| 44 |
(defvar *Messages* (make-hash-table)) |
| 45 |
|
| 46 |
(defun flush-all () |
| 47 |
(finish-output *standard-output*) |
| 48 |
(finish-output *error-output*) |
| 49 |
) |
| 50 |
|
| 51 |
(defun fresh-all () |
| 52 |
(fresh-line *standard-output*) |
| 53 |
(fresh-line *error-output*)) |
| 54 |
|
| 55 |
(defun get-msg-fmt (type id) |
| 56 |
(case type |
| 57 |
(:panic (gethash id *Panic-messages*)) |
| 58 |
(:error (gethash id *Error-messages*)) |
| 59 |
(:warning (gethash id *Warning-messages*)) |
| 60 |
(:smessage (gethash id *Simple-messages*)) |
| 61 |
(:message (gethash id *Messages*)) |
| 62 |
(otherwise (error "Internal error: unknown message type ~a" type)) |
| 63 |
)) |
| 64 |
|
| 65 |
(defun output-msg (type id prefix &rest args) |
| 66 |
(apply #'format t (concatenate 'string prefix |
| 67 |
(get-msg-fmt type id)) |
| 68 |
args)) |
| 69 |
|
| 70 |
(defmacro with-output-chaos-error-n ((msg-id args &optional (tag 'to-top tag-p)) &body body) |
| 71 |
` (progn |
| 72 |
(let ((*standard-output* *error-output*) |
| 73 |
(*print-indent* 4)) |
| 74 |
(output-msg :error ',msg-id "~%[Error]:" ,args) |
| 75 |
,@body) |
| 76 |
,(if (and tag-p (eq tag 'to-top)) |
| 77 |
`(chaos-to-top) |
| 78 |
`(chaos-error ,tag) |
| 79 |
))) |
| 80 |
|
| 81 |
(defmacro with-output-chaos-warning-n ((msg-id args) &body body) |
| 82 |
` (unless *chaos-quiet* |
| 83 |
(let ((*standard-output* *error-output*) |
| 84 |
(*print-indent* 4)) |
| 85 |
(output-msg :warning ',msg-id "~&[Warning]: " ,args) |
| 86 |
,@body) |
| 87 |
(flush-all))) |
| 88 |
|
| 89 |
(defmacro with-output-panic-message-n ((msg-id args) &body body) |
| 90 |
` (progn |
| 91 |
(let ((*standard-output* *error-output*)) |
| 92 |
(output-msg :panic ',msg-id "~&!! PANIC !!: " ,args) |
| 93 |
,@body) |
| 94 |
(chaos-to-top))) |
| 95 |
;;; |
| 96 |
(defmacro with-output-msg-n ((msg-id args &optional (stream '*error-output*)) &body body) |
| 97 |
` (unless *chaos-quiet* |
| 98 |
(let ((*standard-output* ,stream) |
| 99 |
(*print-indent* 3)) |
| 100 |
(output-msg :message ',msg-id "~&-- " ,args) |
| 101 |
,@body) |
| 102 |
(flush-all))) |
| 103 |
|
| 104 |
(defmacro with-output-simple-msg-n ((msg-id args &optional (stream '*error-output*)) &body body) |
| 105 |
` (unless *chaos-quiet* |
| 106 |
(let ((*standard-output* ,stream) |
| 107 |
(*print-indent* 2)) |
| 108 |
(output-msg :smessage "~&" ',msg-id ,args) |
| 109 |
,@body) |
| 110 |
(flush-all))) |
| 111 |
|
| 112 |
;;; |
| 113 |
(defun print-in-progress (str) |
| 114 |
(unless *chaos-quiet* |
| 115 |
(princ str *error-output*) |
| 116 |
(finish-output *error-output*))) |
| 117 |
|
| 118 |
;;; I-miss-current-module me |
| 119 |
;;; Checks if the *current-module* is bound, returns nil with an error mesage if |
| 120 |
;;; *current-mdoule* is not bound to non-nil value. |
| 121 |
;;; - me must a name (symbol) of a block. |
| 122 |
;;; |
| 123 |
(defmacro I-miss-current-module (me) |
| 124 |
` (unless *current-module* |
| 125 |
(fresh-all) |
| 126 |
(flush-all) |
| 127 |
(with-output-panic-message (:p-no-module '(,me)) |
| 128 |
;; (format t "in ~a : no current module is specified!" ',me) |
| 129 |
(force-output) |
| 130 |
(finish-output) |
| 131 |
(return-from ,me nil)))) |
| 132 |
|
| 133 |
;;; EOF |