guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

very obscure problem, help needed


From: David Pirotte
Subject: very obscure problem, help needed
Date: Thu, 02 Nov 2000 11:52:00 +0100

Hello guilers,

Some time ago, I sent a 'help requested' message, the content of which
is further below.

Now I have a better idea on what the problem is, not knowing how I can
solve it. Here is the problem:

        whenever - from a guile script used to querying postgres and
                   generating html code -
        I call 'system-date' (code follows)
        ==> I have a complete mess in my generated html pages

        system-date:

        (define (system-date . rest)
          (let ((p (open-input-pipe (if (null? rest)
                                        "date '+%d-%m-%Y'"
                                        (format #f "date ~A" (car rest))))))
            (let ((line (read-line p)))
              (close-pipe p)
              line)))

please help ...
thanks,
david


;; previous message content
;; ------------------------

I apologies in advance: due to multiple technologies involved, it is
not possible for me to build an example that people on this list can
just launch and see what happens to help me.

I just hope that some folks will take few minutes to see if they woud
have encounterred the same problem in the past and help me.

Here is my problem, involving the following S/W:

        postgres 7.0
        apache:         Server version: Apache/1.3.12 (Unix)
                        Server built:   Apr  6 2000 08:56:04
        an html browser (netscape)
        
        guile:  analyses its arguments,
                queries postgres,
                generates html code that it sends to netscape

Guile script summary:

        #!/usr/local/bin/guile -s
        !#

        ;; html/apache protocol request this
        (display "Content-Type: text/html\n\n")

        (use-modules (oop goops))
        ...
        (use-modules (alto date))
        (use-modules (alto strings))
        ...

        (setenv "PGDATESTYLE" "German")

        (define  (getenv "QUERY_STRING"))
        (define args-tokens (get-tokens call-args #\,))
        (define cha-ref (list-ref args-tokens 0))
        (define proj-name (list-ref args-tokens 1))

        (define html-input
          (let ((hi (read-line)))
            (if (eof-object? hi)
                '()
                (get-tokens hi #\&))))

        ... some class definition and so on

        (define pg-con
         (pg-connectdb (format #f "~A ~A ~A"
                                "dbname=tactus"
                                "tty=/usr/www/logs/pg-error.log"
                                "user=david"
                                )))

        ... all postgres queries I need, based on call-args and html-input
==>     ... calling my date engine (see below)

==>     ... html page generation

        ;; closing connection and result pointers
        (define pg-result '())
        (define pg-con '())

        ;; end of guile script

PROBLEM:

        whithin my guile code, I call a 'date engine' which, among other
        things, computes dates in future and dates in the passed, given a swivel
        date, week-end days in a week and bank-holidays

        for some totaly obscure reasons to me so far (2 days of investigations)
        if, whithin a loop, I call (date-in-future ...),

        ===> I get several "Content-Type: text/html" written as the beginning
             of my html pages, just as if the guile script was called several
             times:

                exactly 1 "Content-Type: text/html"     
                per call to date-in-future              

NOW:    if I momentaraly define date-in-future to always reply the same integer,
        just to try to understand what is going on, everything is fine!

        example
                
                (define (date-in-future-1 res-dte w-dn nb-days we bh)
                   ;; this represents "18/09/2000", european dd/mm/yyyy
                   11231)

SO:

        so far, I can only deduce that the code, both date-in-future and 
        date-in-the-passed, which are just 'symetric' are the culprits!

        here is date-in-future code: 

                its too complicated to pass the all date engine software,
                but I checked that the function 'open-day?' itself refering
                to a 'binary-search' function are not involved (forcing them
                to temporarily always return #t)

        (define (date-in-future-1 res-dte w-dn nb-days we bh)
          (do ()
              ((= nb-days 0)
               (if (open-day? res-dte we bh w-dn)
                   res-dte
                   (do ((res-dte (+ res-dte 1)
                                 (+ res-dte 1))
                        (w-dn (remainder (+ w-dn 1) 7)
                              (remainder (+ w-dn 1) 7)))
                       ((open-day? res-dte we bh w-dn)
                        res-dte)
                     '())))
            (if (open-day? res-dte we bh w-dn)
                (set! nb-days (- nb-days 1)))
           (set! res-dte (+ res-dte 1))
            (set! w-dn (remainder (+ w-dn 1) 7))
           ))

        (define (date-in-future sw-dte nb-days we bh . inc-sw-dte?)
          ;; CAUTION: the are 2 ways of computing this:
          ;;          - in x days, we will be ...
          ;;            (if monday, in 5 days ==> saturday
          ;;          - in terms of duration: what will be the day name in 
'nb-days',
          ;;                                  counting from swivel-dte (and not 
1+ swivel-dte)
          (if (= nb-days 0)
             sw-dte
             (if (null? inc-sw-dte?)
                  (date-in-future-1 sw-dte
                                    (day-nb-in-week sw-dte)
                                    nb-days
                                    we 
                                    bh)
                  (date-in-future-1 sw-dte (day-nb-in-week sw-dte)
                                    (- nb-days 1)
                                    we
                                    bh))))

I am lost, any idea??
Many thanks for those who will get to the end of the message and try
to help me,

David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]