Una aplicación completa

Consiste en un diccionario Inglés - [Otro idioma]. Consta de dos ficheros: Diccio.e y Diccio.ex.
Aquí tenemos el primero, donde se encuentra la función nuclear del programa.
 

include wildcard.e

global constant INGLES = 1, OTROIDIOMA = 2
global constant EXACTO = 1, CONTIENE = 2
global constant SEPARADOR = "="

global function buscar(sequence idioma, sequence texto, integer donde, integer modo)
   sequence resultado, registro
   integer num_fichero, separador
   object linea

   resultado = {}
   registro = {{},{}}

   num_fichero = open(idioma, "r")
   if num_fichero = -1 then
    puts(1, "File open failure / No se puede abrir el diccionario.\n")
   else
    texto = lower(texto)
    while 1 do
       linea = lower(gets(num_fichero))
       if atom(linea) then
          exit
       end if
       linea = linea[1..length(linea)-1]
        separador = match(SEPARADOR, linea)
        registro[INGLES] = linea[1..(separador - 1)]
        registro[OTROIDIOMA] = linea[(separador + 1)..length(linea)]
       if match(texto, registro[donde]) then
          if ((modo = EXACTO) and (length(texto) = length(registro[donde])))
          or(modo = CONTIENE) then
             if donde = OTROIDIOMA then
                registro = reverse(registro)
             end if
             resultado = append(resultado, registro)
          end if
       end if
    end while
    close(num_fichero)
   end if
  return resultado
end function

Y aquí tenemos el segundo fichero, donde se implementa la interfaz de usuario.

include wildcard.e
include graphics.e
include get.e
include diccio.e

constant INGLES = 1, OTROIDIOMA = 2
constant EXACTO = 1, CONTIENE = 2
constant F1 = 315, F2 = 316, F3 = 317, ESC = 27
constant TRUE = 1

constant LENGUAJE = 1, INTRO = 4, PULSAR = 5, ENCUENTRA = 6, TEXTO = 7, SALIDA = 8

constant letreros = {{"ENGLISH", "ESPA¥OL"},
                     {"EXACT", "EXACTO"},
                     {"CONTAIN", "CONTIENE"},
                     {"Enter the word: ", "Introduzca la palabra: "},
                     {"Do you want to continue? (y/n) ", "¨Desea continuar? (s/n) "},
                     {"   %d matchs found", "   Se han encontrado %d coincidencias"},
                     {"Word", "Palabra"},
                     {"Exit", "Salir"}}

sequence idioma
   idioma = "Spanish.txt"

integer destino, modo, code
   destino = INGLES
   modo = EXACTO

object NIL
 

procedure palabra()

   sequence texto, resultado
   integer pagcompleta

   while TRUE do

   puts(1, letreros[INTRO][destino])
   text_color(YELLOW)
   texto = gets(0)
   text_color(WHITE)
   texto = texto[1..length(texto)-1]
   if not(equal(texto, {})) then
     resultado = buscar(idioma, texto, destino, modo)
     puts(1, "\n")

     text_color(YELLOW)
     for n = 1 to length(resultado) do
        puts(1, "\n")
        puts(1, resultado[n][1])
        puts(1, " = ")
        puts(1, resultado[n][2])
        pagcompleta = not remainder(n, 15)
        if pagcompleta then
          puts(1, "\n\n")
           puts(1, letreros[PULSAR][destino])
           puts(1, "\n")
           NIL = wait_key()
           if NIL = ESC then
             exit
          end if
        end if
     end for
     text_color(WHITE)
     puts(1, "\n\n   ")
     printf(1, letreros[ENCUENTRA][destino], length(resultado))
     puts(1, "\n\n\n")
     puts(1, letreros[PULSAR][destino])
     NIL = wait_key()
     if find(lower(NIL), {'y', 's'}) then
        puts(1, "\n\n")
     else
        exit
     end if
  end if

  end while

end procedure

procedure cabecera()
   sequence traduccion
   if destino = INGLES then
     traduccion = letreros[LENGUAJE][INGLES] & "->" & letreros[LENGUAJE][OTROIDIOMA]
   else
     traduccion = letreros[LENGUAJE][OTROIDIOMA] & "->" & letreros[LENGUAJE][INGLES]
   end if
   text_color(YELLOW)
   position(1, 1)
   printf(1, "F1 = %s\tF2 = %s\tF3 = %s\tESC = %s \n\n", {letreros[TEXTO][destino],
      traduccion, letreros[modo + 1][destino], letreros[SALIDA][destino]})
   text_color(WHITE)
end procedure

clear_screen()

while 1 do
   cabecera()
   while 1 do
      code = wait_key()
      if code != -1 then
         if code = F1 then
           palabra()
           clear_screen()
             cabecera()
         elsifcode = F2 then
           if destino = OTROIDIOMA then
              destino = INGLES
           else
              destino = OTROIDIOMA
           end if
           cabecera()
         elsifcode = F3 then
           if modo = CONTIENE then
              modo = EXACTO
           else
              modo = CONTIENE
           end if
           cabecera()
         elsifcode = ESC then
           exit
         end if
      end if
  end while
  if code = ESC then
     exit
  end if
end while
 

Espero que estos ejemplos hayan servido para darse una idea de lo que ofrece Euphoria, un lenguaje de programación que, sospecho (y espero no equivocarme), dará que hablar en un futuro próximo.



(volver)