Changeset 13949 in project


Ignore:
Timestamp:
03/26/09 19:17:28 (11 years ago)
Author:
Kon Lovett
Message:

Start of timezone/locale file support.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/locale/trunk/locale-posix.scm

    r13893 r13949  
    1616  (export
    1717    ;
    18     seconds->hms-string
     18    seconds->h:m:s-string
    1919    ;
    2020    make-posix-timezone
     
    2828    gnu-load-locale) )
    2929
    30 (require-extension srfi-1 srfi-13 regex data-structures locale-categories locale-components)
     30(require-extension srfi-1 srfi-13 regex data-structures files locale-categories locale-components)
    3131
    3232;;;
     
    3939                     str ) ) )
    4040
    41 ;;
     41;;;
    4242
    4343(define-constant SEC/HR   3600)
    4444(define-constant SEC/MIN  60)
    4545
    46 (define (seconds->hms-string secs)
     46(define (seconds->h:m:s-string secs)
    4747  (let* ((asecs (abs secs))
    4848         (rsecs (remainder asecs SEC/HR)) )
     
    5252
    5353(define (make-posix-timezone dst-tzn dst-off std-tzn std-off)
    54   (string-append dst-tzn (seconds->hms-string dst-off) std-tzn (seconds->hms-string std-off)) )
     54  (string-append dst-tzn (seconds->h:m:s-string dst-off) std-tzn (seconds->h:m:s-string std-off)) )
     55
     56;;;
    5557
    5658;; Splits an IEEEÊStdÊ1003.1-2001 TZ specifier string into components.
     
    6365;; timezone specifier
    6466
    65 (define parse-posix-standard-timezone-value
     67(define parse-posix-literal-timezone
    6668        (let ((name-re (regexp "([A-Za-z]+)|<([^>]+)>"))
    6769                                (offset-re (regexp "(\\+|-)?([0-9]+)(:[0-9]+)?(:[0-9]+)?"))
     
    143145               tz ) ) ) ) ) )
    144146
    145 (define (parse-posix-implementation-defined-timezone-value tz str)
    146   (warning "cannot understand Posix implementation-defined timezone values" str)
     147;;
     148
     149(cond-expand
     150  (macosx
     151    (define *system-timezone-directory* "/usr/share/zoneinfo") )
     152  (else
     153    (define *system-timezone-directory* #f) ) )
     154
     155(define (parse-posix-tzfile tz pn)
     156  (warning "cannot understand Posix pathname timezone" pn)
    147157  #f )
    148158
    149 (define (parse-posix-pathname-timezone-value tz str)
    150   (warning "cannot understand Posix pathname timezone values" str)
    151   #f )
     159(define (parse-posix-pathname-timezone tz str)
     160  (let ((pn (if (string-prefix? "/" str) str (make-pathname *system-timezone-directory* str))))
     161    (if (file-exists? pn) (parse-posix-tzfile tz pn)
     162        #f ) ) )
     163
     164(define (parse-posix-implementation-defined-timezone tz str)
     165  (or (parse-posix-pathname-timezone tz (substring str 1))
     166      (begin
     167        (warning "cannot understand Posix implementation-defined timezone" str)
     168        #f ) ) )
     169
     170;;
    152171
    153172(define (posix-timezone-string->timezone-components str . src)
    154173  (let ((tz (make-timezone-components str (optional src "POSIX"))))
    155174    (cond ((string-prefix? ":" str)
    156             (parse-posix-implementation-defined-timezone-value tz str) )
    157           ((string-prefix? "/" str)
    158             (parse-posix-pathname-timezone-value tz str) )
     175            (parse-posix-implementation-defined-timezone tz str) )
    159176          (else
    160             (parse-posix-standard-timezone-value tz str) ) ) ) )
     177            (or (parse-posix-pathname-timezone tz str)
     178                (parse-posix-literal-timezone tz str) ) ) ) ) )
     179
     180;;;
    161181
    162182;; Splits an IEEEÊStdÊ1003.1-2001 locale specifier string into
     
    173193;; modifier:
    174194
    175 (define parse-posix-standard-locale
     195(define parse-posix-literal-locale
    176196        (let ((locale-re (regexp "([a-zA-Z]+)(-[a-zA-Z]+)?(_[a-zA-Z]+)?(\\.[^@]+)?(@.+)?")))
    177197                (lambda (lc str)
     
    204224                 lc ) ) ) ) ) ) )
    205225
     226;;
     227
     228(cond-expand
     229  (macosx
     230    (define *system-locale-directory* "/usr/share/locale") )
     231  (else
     232    (define *system-locale-directory* #f) ) )
     233
     234(define (parse-posix-localefile lc pn)
     235  (warning "cannot understand Posix pathname locale" pn)
     236  #f )
     237
    206238(define (parse-posix-pathname-locale lc str)
    207   (warning "cannot understand Posix pathname locale values" str)
    208   #f )
     239  (let ((pn (if (string-prefix? "/" str) str (make-pathname *system-locale-directory* str))))
     240    (if (file-exists? pn) (parse-posix-localefile lc pn)
     241        #f ) ) )
     242
     243;;
    209244
    210245(define (posix-locale-string->locale-components str . args)
     
    212247    (let ((lc (make-locale-components str src tag)))
    213248      (cond ((or (string=? str "C") (string=? str "POSIX"))
     249              ;FIXME - #f so BUILTIN source used but ...
    214250              #f )
    215             ((string-prefix? "/" str)
    216               (parse-posix-pathname-locale lc str) )
    217251            (else
    218               (parse-posix-standard-locale lc str) ) ) ) ) )
     252              (or (parse-posix-pathname-locale lc str)
     253                  (parse-posix-literal-locale lc str) ) ) ) ) ) )
    219254
    220255;; The POSIX/GNU locale categories
Note: See TracChangeset for help on using the changeset viewer.