;;;; Greek Dictionary Web Engine
;;;; Copyright (C) 2004, 2005, 2006, 2007, 2010 Sergey Poznyakoff
;;;;
;;;; 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 .
;;;;
;;; Tailor this statement to your needs if necessary.
(set! %load-path (cons "GUILE_SITE" %load-path))
(use-modules ifelse(IFACE,[CGI],(www cgi),(guile-user))
(ice-9 rdelim)
(gamma sql)
(xmltools dict)
(ellinika i18n)
(ellinika xlat)
(ellinika cgi))
ifelse(IFACE,[CGI],(cgi:init))
(ellinika-cgi-init dict-template-file-name)
;; Τα μέρη του λόγου
(define part-of-speech '())
(define (sql-error-handler key func fmt fmtargs data)
(format #t "
~A
\n"
(_ "ΣΦΆΛΜΑ: σύνδεση με το λέξικο απέτυχε."))
(apply format (current-error-port) fmt fmtargs))
(define (mk-dict-connect)
(let ((db-connection #f))
(lambda (. rest)
(cond
((null? rest)
(if (not db-connection)
(begin
(set! db-connection
(sql-open-connection
ellinika-sql-connection))
(sql-query db-connection "SET NAMES utf8")
)))
(else
(if db-connection
(sql-close-connection db-connection))
(set! db-connection #f)))
db-connection)))
(define dict-connect (mk-dict-connect))
(define (load-pos)
(sql-ignore-failure
(let ((conn (dict-connect)))
(let ((plist (my-sql-query
conn
"SELECT name,id FROM pos WHERE canonical='Y' order by id")))
(set! part-of-speech
(cons
(cons "κανένα μέρος του λόγου" #f)
(map
(lambda (x)
(cons (car x) (cadr x)))
plist)))))))
;; Protect occurences of " in a string.
;; Usual backslash escapes do not work in INPUT widgets, so I
;; change all quotation marks to "
;; Possibly not the better solution, though...
(define (protect string)
(list->string
(apply append
(map
(lambda (x)
(if (eq? x #\")
(list #\& #\# #\3 #\4 #\;)
(list x)))
(string->list string)))))
(define (get-topic-list)
(let ((categories #f))
(letrec ((getcat
(lambda ()
(sql-ignore-failure
(let ((conn (dict-connect)))
(let ((ctg (my-sql-query
conn
(string-append
"SELECT t.category, c.title, c.description "
"FROM category c,topic t "
"WHERE c.lang='" (language-code target-language) "' "
"AND c.category=t.category GROUP BY 1 ORDER BY 1"))))
(if (null? ctg)
'()
(map
(lambda (category)
(let ((topics (my-sql-query
conn
(string-append
"SELECT ident,title FROM topic WHERE category="
(car category)
" ORDER BY title"))))
(append category (if (null? topics)
'()
(list topics)))))
ctg))))))))
(if (not categories)
(set! categories (or (getcat) '())))
categories)))
(define (join-widget widget-id tabindex)
(let* ((name (string-append "join" widget-id))
(selected-choice (or (let ((s (cgi:value name)))
(if s
(string->number s)
#f))
0)))
(display (string-append "")))
(define (main-form)
(load-pos)
(display "
")))
;;
(define (replace-tilde word sentence)
(apply
string-append
(let loop ((lst '())
(str sentence))
(cond
((string-index str #\~) =>
(lambda (x)
(loop
(append lst (list (substring str 0 x) word))
(substring str (1+ x)))))
((string-null? str)
lst)
(else
(append lst (list str)))))))
;;
(define (display-results rlist)
(let ((x (car rlist)))
(display "
")
(display "
")
(display (car x))
(display "
")
(cond
((list-ref x 3)
(display "
")
(let ((href (assoc (list-ref x 2) word-forms-reference)))
(cond
(href
(display "")
(display (list-ref x 3))
(display ""))
(else
(display (list-ref x 3)))))
(display "
")))
(display "
")
(display (list-ref x 2))
(display "
"))
(for-each
(lambda (x)
(display "
")
(display (1+ (string->number (list-ref x 4))))
(display "
")
(display (replace-tilde (car x) (list-ref x 5)))
(display ";