HEADERS.LSP



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;						;;
;;	EDITOR VISUAL DEL LENGUAJE C		;;
;;	Modulo: headers.lsp			;;
;;						;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;						;;
;;	Autor: J. Rafael R. Ochoa		;;
;;	e-mail: rochoa@zeus.umich.mx	        ;;
;;	Universidad Michoacana de 		;;
;;	Morelia, Mich. MEXICO			;;
;;						;;
;;	Marzo 1998				;;
;;						;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq lista nil)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 	de headers

;;;;;;;;;;;;;;;
;; Macro utilizada para cargar el contenido del archivo
;; headers.txt en la variable global "lista"
;;;;;;;
;(with-open-file (ver-headers "c:\\maestria\\compil~1\\editor~1\\headers.txt"
;	:direction :input)
;	(do ((elemento (read ver-headers nil)
;		(read ver-headers nil)))
;		((not elemento))
;  	(push elemento lista)))



;;;;; (crea-headers lista 20 5) <<====

;;;;;;;;;;;;;;;;;;;
;; Funcion empleada para la creacion de los headers
;; en la *ventana-secundaria* A cada header se le 
;; asocia un hotspot
;;;;;;;
(defun crea-headers (lista-de-headers pos_x pos_y)
  (cond ((null lista-de-headers) nil)
	(T (progn
	       (ghw:draw-rectangle *ventana-secundaria* pos_x pos_y 80 30
		        :pen *lapiz-azul* :brush *relleno-amarillo*)
	       (ghw:draw-text *ventana-secundaria* (+ pos_x 5) (+ pos_y 5) 
				(string (car lista-de-headers)))
	       (let ((hotspot
       			(ghw:make-hotspot *ventana-secundaria* :x pos_x :y pos_y
               			:width 80 :height 30
               			:status :active)))
       			(ghw:add-to-object-method hotspot :mouse-left-down
                                        '(:after (entro)))
       			(ghw:add-to-object-method hotspot :mouse-out
                                        '(:after (salio))))                           
	       (crea-headers (cdr lista-de-headers) pos_x (+ pos_y 40))))))

(defun header-stdio ()
  (ghw:draw-rectangle *ventana-secundaria* 20 5 80 30
		        :pen *lapiz-azul* :brush *relleno-amarillo*)
	       (ghw:draw-text *ventana-secundaria* 25 10 
				"stdio.h")
	       (let ((hotspot
       			(ghw:make-hotspot *ventana-secundaria* :x 20 :y 5
               			:width 80 :height 30
               			:status :active)))
       			(ghw:add-to-object-method hotspot :mouse-left-down
                                        '(:after (entro-stdio)))))

(defun header-stdlib ()
  (ghw:draw-rectangle *ventana-secundaria* 20 45 80 30
		        :pen *lapiz-azul* :brush *relleno-amarillo*)
	       (ghw:draw-text *ventana-secundaria* 25 50 
				"stdlib.h")
	       (let ((hotspot
       			(ghw:make-hotspot *ventana-secundaria* :x 20 :y 45
               			:width 80 :height 30
               			:status :active)))
       			(ghw:add-to-object-method hotspot :mouse-left-down
                                        '(:after (entro-stdlib)))))
 
(defun header-string ()
  (ghw:draw-rectangle *ventana-secundaria* 20 85 80 30
		        :pen *lapiz-azul* :brush *relleno-amarillo*)
	       (ghw:draw-text *ventana-secundaria* 25 90 
				"string.h")
	       (let ((hotspot
       			(ghw:make-hotspot *ventana-secundaria* :x 20 :y 85
               			:width 80 :height 30
               			:status :active)))
       			(ghw:add-to-object-method hotspot :mouse-left-down
                                        '(:after (entro-string)))))



(defun entro-stdio (hotspot &rest ignore)
  	(if (agrega-header 'stdio.h)
	(escribe-encabezado "#include <stdio.h>")))

(defun entro-stdlib (hotspot &rest ignore)
  	(if (agrega-header 'stdlib.h)
	(escribe-encabezado "#include <stdlib.h>")))

(defun entro-string (hotspot &rest ignore)
  	(if (agrega-header 'string.h)
	      (escribe-encabezado "#include <string.h>")))


(defun escribe-encabezado (encabezado)
  (ghw:draw-text *ventana-principal* 20 posicion-renglon encabezado)
  (setq posicion-renglon (+ posicion-renglon 20)))


(defun borra-texto (x1 y1 x2 y2)
  	(ghw:draw-rectangle *ventana-secundaria* x1 y1 x2 y2 
		:pen *lapiz-azul*))

(defun entro (hotspot &rest ignore)
  	(borra-texto 10 285 70 40)
  	(ghw:draw-text (ghw:hotspot-window hotspot)
			 30 300 "hola")
	  (ghw:force-window-output))

(defun salio (hotspot &rest ignore)
  	(borra-texto 10 285 70 40)
  	(ghw:draw-text (ghw:hotspot-window hotspot)
			 30 300 "adios")
	  (ghw:force-window-output))

(defun limpia (hotspot &rest ignore)
  	(limpia-ventana-secundaria))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;	Almacenamiento de los headers que se
;;; 	han empleado
(setq *headers-usados* nil)

;;;;;;;;;;;;;;;;
;; Funcion que forma la lista de headers empleados
;;;;
(defun agrega-header (header)
  (let ((header-en-la-lista?
	 (search (list header) *headers-usados*))) 
    (cond
	;; NO se encuentra aun en la lista de headers 
     	((null header-en-la-lista?) (pushnew header *headers-usados*))
	;; si se encuentra
	(T nil))))