;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; EDITOR VISUAL DEL LENGUAJE C ;;
;; Modulo: global.lsp ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Autor: J. Rafael R. Ochoa ;;
;; e-mail: rochoa@zeus.umich.mx ;;
;; Universidad Michoacana de ;;
;; Morelia, Mich. MEXICO ;;
;; ;;
;; Marzo 1998 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; VARIABLES GLOBALES
(setq tipos-de-variables nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; de las variables-globales
;(with-open-file (ver-tipos "c:\\maestria\\compil~1\\editor~1\\tipos.txt"
; :direction :input)
; (do ((elemento (read ver-tipos nil)
; (read ver-tipos nil)))
; ((not elemento))
; (push elemento tipos-de-variables)))
(defun muestra-tipos (lista-de-tipos pos_x pos_y)
(cond ((null lista-de-tipos) 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-tipos)))
(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))))
(muestra-tipos (cdr lista-de-tipos) pos_x (+ pos_y 40))))))
(defun global-int ()
(ghw:draw-rectangle *ventana-secundaria* 20 5 80 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 25 10
"int")
(let ((hotspot
(ghw:make-hotspot *ventana-secundaria* :x 20 :y 5
:width 80 :height 30
:status :active)))
(ghw:add-to-object-method hotspot :mouse-out
'(:after (borra-hotspot)))
(ghw:add-to-object-method hotspot :mouse-left-down
'(:after (pide-int)))))
(defun pide-int (hotspot &rest ignore)
(obten-valor-global 'int))
(defun global-float ()
(ghw:draw-rectangle *ventana-secundaria* 20 45 80 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 25 50
"float")
(let ((hotspot
(ghw:make-hotspot *ventana-secundaria* :x 20 :y 45
:width 80 :height 30
:status :active)))
(ghw:add-to-object-method hotspot :mouse-out
'(:after (borra-hotspot)))
(ghw:add-to-object-method hotspot :mouse-left-down
'(:after (pide-float)))))
(defun pide-float (hotspot &rest ignore)
(obten-valor-global 'float))
(defun global-double ()
(ghw:draw-rectangle *ventana-secundaria* 20 85 80 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 25 90
"double")
(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 (pide-double)))))
(defun pide-double (hotspot &rest ignore)
(obten-valor-global 'double))
(defun global-char ()
(ghw:draw-rectangle *ventana-secundaria* 20 125 80 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 25 130
"char")
(let ((hotspot
(ghw:make-hotspot *ventana-secundaria* :x 20 :y 125
:width 80 :height 30
:status :active)))
(ghw:add-to-object-method hotspot :mouse-left-down
'(:after (pide-char)))))
(defun pide-char (hotspot &rest ignore)
(obten-valor-global 'char))
(defun global-apuntador-a-caracter ()
(ghw:draw-rectangle *ventana-secundaria* 20 165 80 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 25 170
"char *")
(let ((hotspot
(ghw:make-hotspot *ventana-secundaria* :x 20 :y 165
:width 80 :height 30
:status :active)))
(ghw:add-to-object-method hotspot :mouse-left-down
'(:after (pide-apuntador)))))
(defun pide-apuntador (hotspot &rest ignore)
(obten-valor-global 'char*))
(defun global-arreglo-de-caracteres ()
(ghw:draw-rectangle *ventana-secundaria* 20 205 80 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 25 210
"char []")
(let ((hotspot
(ghw:make-hotspot *ventana-secundaria* :x 20 :y 205
:width 80 :height 30
:status :active)))
(ghw:add-to-object-method hotspot :mouse-left-down
'(:after (entro-string)))))
(defun arreglo-de-caracteres ()
(ghw:draw-rectangle *ventana-secundaria* 20 240 185 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 30 245
"Arreglo de caracteres"))
(defun variable-tipo-char ()
(apuntador-a-caracter)
(arreglo-de-caracteres))
(defun apuntador-a-caracter ()
(ghw:draw-rectangle *ventana-secundaria* 20 200 180 30
:pen *lapiz-azul* :brush *relleno-amarillo*)
(ghw:draw-text *ventana-secundaria* 30 205
"Apuntador a Caracter")
(let ((hotspot
(ghw:make-hotspot *ventana-secundaria* :x 20 :y 300
:width 120 :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)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Almacenamiento de las variables
;;; globales
;;;;;;;;;;;;;;;;
;; *variables-globales* contiene una lista de
;; de cada variable global y su tipo
;;;;
(setq *variables-globales* nil)
;;;;;;;;;;;;;;;;
;; Funcion que forma la lista de variables globales
;;;;
(defun agrega-variable-global (variable tipo)
(if (null (encuentra-variable variable *variables-globales*))
(progn
(if (null *variables-globales*)
(progn
(ghw:draw-text *ventana-principal* 40 posicion-renglon
"/* Variables Globales */")
(setq posicion-renglon (+ posicion-renglon 20))))
(push (variable-con-tipo variable tipo) *variables-globales*)
(imprime-variable-global tipo variable))))
;;;;;;;;;;;;;;;;
;; Impresion de la variable global
;;;;
(defun imprime-variable-global (tipo variable)
(let ((tipo-en-minusculas
(nstring-downcase (string tipo))))
(let ((tipo-y-variable
(concatenate 'string tipo-en-minusculas " " variable "\;")))
(ghw:draw-text *ventana-principal* 20 posicion-renglon tipo-y-variable)
(setq posicion-renglon (+ posicion-renglon 20)))))
;;;;;;;;;;;;;;;;
;; Forma un par que contiene la variable y su tipo
;;;;
(defun variable-con-tipo (variable tipo)
(list variable tipo))
;;;;;;;;;;;;;;;;
;; Funcion que busca si existe una variable en la lista de
;; variables. Si existe regresa una lista que contiene
;; la variable junto con su tipo. Si no existe regresa nil
;;;;
(defun encuentra-variable (variable lista-de-variables)
(let ((par
(car lista-de-variables)))
(cond ((null par) nil)
((string= variable (car par)) par)
(t (encuentra-variable variable (cdr lista-de-variables))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Peticion del nombre de la variable global
;;;;;;
(defun obten-valor-global (tipo)
(let ((nombre-global
(ghw:make-window :title "Variable global"
:x-scrollbar-p nil
:y-scrollbar-p nil
:height 70 :width 250
:system-menu-p nil
:reshapeable-p nil
:status :active)))
(let ((stream (ws::make-window-stream nombre-global)))
(let ((input (read-line stream)))
(agrega-variable-global input tipo)
(setf (ghw:window-caret-p nombre-global) t)
(ghw:flush-window nombre-global)))))