original files of m241

This commit is contained in:
neelimap
2026-07-30 11:19:44 +05:30
parent 170c2b3f3a
commit afc7070c1f
12254 changed files with 7655111 additions and 0 deletions
@@ -0,0 +1,88 @@
; $Header: /usr/cvsroot/target/h/wrn/wm/util/layout/ldbcomp/dumpit.scm,v 1.1.1.1 2001/11/05 17:47:21 tneale Exp $
; Dump out an excutable for the layout tool.
;****************************************************************************
;
; *** Restricted Rights Legend ***
;
; The programs and information contained herein are licensed only
; pursuant to a license agreement that contains use, reverse
; engineering, disclosure, and other restrictions; accordingly, it
; is "Unpublished--all rights reserved under the applicable
; copyright laws".
;
; Use duplication, or disclosure by the Government is subject to
; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
; in Technical Data and Computer Licensed Programs clause of DFARS
; 52.227 7013.
;
; Copyright 2000-2001 Wind River Systems, Inc.
; Copyright 1997 Epilogue Technology Corporation.
; Copyright 1998 Integrated Systems, Inc.
; All rights reserved.
;
; *** Government Use ***
;
; The Licensed Programs and their documentation were developed at
; private expense and no part of them is in the public domain.
;
; The Licensed Programs are "Restricted Computer Software" as that
; term is defined in Clause 52.227-19 of the Federal Acquisition
; Regulations (FAR) and are "Commercial Computer Software" as that
; term is defined in Subpart 227.401 of the Department of Defense
; Federal Acquisition Regulation Supplement (DFARS).
;
; (i) If the licensed Programs are supplied to the Department of
; Defense (DoD), the Licensed Programs are classified as
; "Commercial Computer Software" and the Government is acquiring
; only "restricted rights" in the Licensed Programs and their
; documentation as that term is defined in Clause 52.227
; 7013(c)(1) of the DFARS, and
;
; (ii) If the Licensed Programs are supplied to any unit or agency
; of the United States Government other than DoD, the
; Government's rights in the Licensed Programs and their
; documentation will be as defined in Clause 52.227-19(c)(2) of
; the FAR.
;****************************************************************************
(let ((target (nth command-line-arguments 0))
(image (nth command-line-arguments 1)))
(let* ((psarg (format #F "ww~A" (pid)))
(scshvm (symbol->string (nth (run/sexps (ps ,psarg)) 11)))
(lscshvm (string-length scshvm)))
(unless (and (char=? #\/ (string-ref scshvm 0))
(string=? "/scshvm"
(substring scshvm (- lscshvm 7) lscshvm)))
(err 'dumpit "Bad scshvm pathname: ~S" scshvm))
(set! user-layouts-package (get-package 'user-layouts))
(call-with-output-file target
(lambda (port)
(display "#!/bin/sh -" port)
(newline port)
(display scshvm port)
(display " -i " port)
(display image port)
(display " \"$@\"" port)
(newline port)
))
(set-file-mode target #o755)
(set-err-should-exit? #T)
(dump-scsh-program do-layout-command-line image)))
; $Log: dumpit.scm,v $
; Revision 1.1.1.1 2001/11/05 17:47:21 tneale
; Tornado shuffle
;
; Revision 1.3 2001/01/19 22:22:35 paul
; Update copyright.
;
; Revision 1.2 1998/02/25 04:54:20 sra
; Update copyrights.
;
; Revision 1.1 1997/09/26 20:14:39 alan
; Initial Revision
;
; Local Variables:
; mode: Scheme
; End:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,228 @@
; $Header: /usr/cvsroot/target/h/wrn/wm/util/layout/ldbcomp/lists.scm,v 1.1.1.1 2001/11/05 17:47:21 tneale Exp $
; List manipulation, mapping, folding, reducing...
;****************************************************************************
;
; *** Restricted Rights Legend ***
;
; The programs and information contained herein are licensed only
; pursuant to a license agreement that contains use, reverse
; engineering, disclosure, and other restrictions; accordingly, it
; is "Unpublished--all rights reserved under the applicable
; copyright laws".
;
; Use duplication, or disclosure by the Government is subject to
; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
; in Technical Data and Computer Licensed Programs clause of DFARS
; 52.227 7013.
;
; Copyright 2000-2001 Wind River Systems, Inc.
; Copyright 1997 Epilogue Technology Corporation.
; Copyright 1998 Integrated Systems, Inc.
; All rights reserved.
;
; *** Government Use ***
;
; The Licensed Programs and their documentation were developed at
; private expense and no part of them is in the public domain.
;
; The Licensed Programs are "Restricted Computer Software" as that
; term is defined in Clause 52.227-19 of the Federal Acquisition
; Regulations (FAR) and are "Commercial Computer Software" as that
; term is defined in Subpart 227.401 of the Department of Defense
; Federal Acquisition Regulation Supplement (DFARS).
;
; (i) If the licensed Programs are supplied to the Department of
; Defense (DoD), the Licensed Programs are classified as
; "Commercial Computer Software" and the Government is acquiring
; only "restricted rights" in the Licensed Programs and their
; documentation as that term is defined in Clause 52.227
; 7013(c)(1) of the DFARS, and
;
; (ii) If the Licensed Programs are supplied to any unit or agency
; of the United States Government other than DoD, the
; Government's rights in the Licensed Programs and their
; documentation will be as defined in Clause 52.227-19(c)(2) of
; the FAR.
;****************************************************************************
(define (last-pair l)
(let loop ((cell l)
(next (cdr l)))
(if (pair? next)
(loop next (cdr next))
cell)))
(define (cons* first . rest)
(cond ((null? rest) first)
((null? (cdr rest)) (cons first (car rest)))
(else (let loop ((a rest)
(b (cdr rest))
(c (cddr rest)))
(if (null? c)
(set-cdr! a (car b))
(loop b c (cdr c))))
(cons first rest))))
(define (reverse! lst)
(reverse*! lst '()))
(define (reverse*! lst tail)
(let loop ((in lst) (out tail))
(cond ((null? in) out)
((pair? in)
(let ((x (cdr in)))
(set-cdr! in out)
(loop x in)))
(else (err 'reverse*! "Not a proper list: ~S" in)))))
(define (reverse* lst tail)
(let loop ((in lst) (out tail))
(cond ((null? in) out)
((pair? in) (loop (cdr in) (cons (car in) out)))
(else (err 'reverse* "Not a proper list: ~S" lst)))))
(define (append! lst tail)
(cond ((pair? lst)
(let loop ((prev lst) (l (cdr lst)))
(if (pair? l)
(loop l (cdr l))
(set-cdr! prev tail)))
lst)
(else tail)))
(define (map* tail proc lst)
(let loop ((l lst))
(cond ((null? l) tail)
((pair? l)
(cons (proc (car l))
(loop (cdr l))))
(else (err 'map* "Not a proper list: ~S" lst)))))
(define (append-map proc lst) (append-map* '() proc lst))
(define (append-map* tail proc lst)
(let loop ((l lst))
(cond ((null? l) tail)
((pair? l)
(append (proc (car l))
(loop (cdr l))))
(else (err 'append-map* "Not a proper list: ~S" lst)))))
(define (append-map! proc lst) (append-map*! '() proc lst))
(define (append-map*! tail proc lst)
(let loop ((l lst))
(cond ((null? l) tail)
((pair? l)
(append! (proc (car l))
(loop (cdr l))))
(else (err 'append-map*! "Not a proper list: ~S" lst)))))
(define (there-exists? list predicate)
(let loop ((list list))
(and (not (null? list))
(or (predicate (car list))
(loop (cdr list))))))
(define (for-all? list predicate)
(let loop ((list list))
(or (null? list)
(and (predicate (car list))
(loop (cdr list))))))
(define (reduce procedure initial list)
(if (null? list)
initial
(let loop ((val (car list))
(l (cdr list)))
(if (null? l)
val
(loop (procedure val (car l))
(cdr l))))))
(define (reduce-right procedure initial list)
(if (null? list)
initial
(let loop ((first (car list))
(rest (cdr list)))
(if (null? rest)
first
(procedure first (loop (car rest) (cdr rest)))))))
(define (reduce-map reduce-proc initial map-proc lst)
(if (null? lst)
initial
(let loop ((val (map-proc (car lst)))
(l (cdr lst)))
(if (null? l)
val
(loop (reduce-proc val (map-proc (car l))) (cdr l))))))
(define (reduce-right-map reduce-proc initial map-proc lst)
(if (null? lst)
initial
(let loop ((val (map-proc (car lst)))
(l (cdr lst)))
(if (null? l)
val
(reduce-proc val (loop (map-proc (car l)) (cdr l)))))))
(define (fold fold-proc lst)
(fold* fold-proc '() lst))
(define (fold* fold-proc tail lst)
(let loop ((l lst))
(cond ((null? l) tail)
((pair? l) (fold-proc (car l) (loop (cdr l))))
(else (err 'fold* "Not a proper list: ~S" lst)))))
(define (fold-map fold-proc map-proc lst)
(fold-map* fold-proc '() map-proc lst))
(define (fold-map* fold-proc tail map-proc lst)
(let loop ((l lst))
(cond ((null? l) tail)
((pair? l)
(fold-proc (map-proc (car l))
(loop (cdr l))))
(else (err 'fold-map* "Not a proper list: ~S" lst)))))
(define (fold-reverse fold-proc lst)
(fold-reverse* fold-proc '() lst))
(define (fold-reverse* fold-proc tail lst)
(let loop ((l lst)
(v tail))
(cond ((null? l) v)
((pair? l) (loop (cdr l) (fold-proc (car l) v)))
(else (err 'fold-reverse* "Not a proper list: ~S" lst)))))
(define (fold-reverse-map fold-proc map-proc lst)
(fold-reverse-map* fold-proc '() map-proc lst))
(define (fold-reverse-map* fold-proc tail map-proc lst)
(let loop ((l lst)
(v tail))
(cond ((null? l) v)
((pair? l) (loop (cdr l) (fold-proc (map-proc (car l)) v)))
(else (err 'fold-reverse-map* "Not a proper list: ~S" lst)))))
; $Log: lists.scm,v $
; Revision 1.1.1.1 2001/11/05 17:47:21 tneale
; Tornado shuffle
;
; Revision 1.3 2001/01/19 22:22:35 paul
; Update copyright.
;
; Revision 1.2 1998/02/25 04:54:27 sra
; Update copyrights.
;
; Revision 1.1 1997/09/26 20:14:40 alan
; Initial Revision
;
; Local Variables:
; mode: Scheme
; eval: (put 'for-all\? 'scheme-indent-hook 1)
; eval: (put 'there-exists\? 'scheme-indent-hook 1)
; End:
@@ -0,0 +1,22 @@
#
# Make the layout compiler
#
$#equate(PRODUCTH)
$#makefile-init()
$#equate(SCMFILES packages.scm dumpit.scm
utils.scm lists.scm strings.scm match.scm layout.scm)
all: ldbcomp $#dummy()
ldbcomp: $(SCMFILES)
$(SCSH) -lm packages.scm -m layout-language -s \
dumpit.scm $@ $#filepath($(SRCDIR) layout ldbcomp ldbcomp.img)
sizes: $#dummy()
clean: $#dummy()
-$(RM) ldbcomp ldbcomp.img
$#clean()
@@ -0,0 +1,137 @@
; $Header: /usr/cvsroot/target/h/wrn/wm/util/layout/ldbcomp/match.scm,v 1.1.1.1 2001/11/05 17:47:21 tneale Exp $
; Simple matcher
;****************************************************************************
;
; *** Restricted Rights Legend ***
;
; The programs and information contained herein are licensed only
; pursuant to a license agreement that contains use, reverse
; engineering, disclosure, and other restrictions; accordingly, it
; is "Unpublished--all rights reserved under the applicable
; copyright laws".
;
; Use duplication, or disclosure by the Government is subject to
; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
; in Technical Data and Computer Licensed Programs clause of DFARS
; 52.227 7013.
;
; Copyright 2000-2001 Wind River Systems, Inc.
; Copyright 1997 Epilogue Technology Corporation.
; Copyright 1998 Integrated Systems, Inc.
; All rights reserved.
;
; *** Government Use ***
;
; The Licensed Programs and their documentation were developed at
; private expense and no part of them is in the public domain.
;
; The Licensed Programs are "Restricted Computer Software" as that
; term is defined in Clause 52.227-19 of the Federal Acquisition
; Regulations (FAR) and are "Commercial Computer Software" as that
; term is defined in Subpart 227.401 of the Department of Defense
; Federal Acquisition Regulation Supplement (DFARS).
;
; (i) If the licensed Programs are supplied to the Department of
; Defense (DoD), the Licensed Programs are classified as
; "Commercial Computer Software" and the Government is acquiring
; only "restricted rights" in the Licensed Programs and their
; documentation as that term is defined in Clause 52.227
; 7013(c)(1) of the DFARS, and
;
; (ii) If the Licensed Programs are supplied to any unit or agency
; of the United States Government other than DoD, the
; Government's rights in the Licensed Programs and their
; documentation will be as defined in Clause 52.227-19(c)(2) of
; the FAR.
;****************************************************************************
(define (match? pat x)
(cond ((pair? pat)
((case (car pat)
((quote) match-quote)
((?) match-?)
((*) match-*)
((+) match-+)
((or) match-or)
((and) match-and)
((not) match-not)
(else match-pair))
pat x))
((symbol? pat)
(case pat
((any anything) #T)
((symbol) (symbol? x))
((string) (string? x))
((symbol/string) (or (symbol? x) (string? x))) ; very common
((number) (number? x))
((integer) (integer? x))
((char) (char? x))
((pair) (pair? x))
((list) (list? x))
((boolean) (boolean? x))
((vector) (vector? x))
;; ((record) (record? x))
(else (err 'match "Bad pattern: ~S" pat))))
((procedure? pat) (pat x))
(else (eqv? pat x))))
(define (match-quote pat x)
(equal? (cadr pat) x))
(define (match-? pat x)
(or (and (pair? x)
(match? (cadr pat) (car x))
(match? (cddr pat) (cdr x)))
(match? (cddr pat) x)))
(define (match-* pat x)
(let ((p1 (cadr pat))
(p2 (cddr pat)))
(let loop ((x x))
(or (match? p2 x)
(and (pair? x)
(match? p1 (car x))
(loop (cdr x)))))))
(define (match-+ pat x)
(and (pair? x)
(match? (cadr pat) (car x))
(match-* pat (cdr x))))
(define (match-pair pat x)
(and (pair? x)
(match? (car pat) (car x))
(match? (cdr pat) (cdr x))))
(define (match-or pat x)
(let loop ((l (cdr pat)))
(and (not (null? l))
(or (match? (car l) x)
(loop (cdr l))))))
(define (match-and pat x)
(let loop ((l (cdr pat)))
(or (null? l)
(and (match? (car l) x)
(loop (cdr l))))))
(define (match-not pat x)
(not (match? (cadr pat) x)))
; $Log: match.scm,v $
; Revision 1.1.1.1 2001/11/05 17:47:21 tneale
; Tornado shuffle
;
; Revision 1.3 2001/01/19 22:22:35 paul
; Update copyright.
;
; Revision 1.2 1998/02/25 04:54:29 sra
; Update copyrights.
;
; Revision 1.1 1997/09/26 20:14:40 alan
; Initial Revision
;
; Local Variables:
; mode: Scheme
; End:
@@ -0,0 +1,167 @@
; $Header: /usr/cvsroot/target/h/wrn/wm/util/layout/ldbcomp/packages.scm,v 1.1.1.1 2001/11/05 17:47:21 tneale Exp $
; Package definitions for the layout tool.
;****************************************************************************
;
; *** Restricted Rights Legend ***
;
; The programs and information contained herein are licensed only
; pursuant to a license agreement that contains use, reverse
; engineering, disclosure, and other restrictions; accordingly, it
; is "Unpublished--all rights reserved under the applicable
; copyright laws".
;
; Use duplication, or disclosure by the Government is subject to
; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
; in Technical Data and Computer Licensed Programs clause of DFARS
; 52.227 7013.
;
; Copyright 2000-2001 Wind River Systems, Inc.
; Copyright 1997 Epilogue Technology Corporation.
; Copyright 1998 Integrated Systems, Inc.
; All rights reserved.
;
; *** Government Use ***
;
; The Licensed Programs and their documentation were developed at
; private expense and no part of them is in the public domain.
;
; The Licensed Programs are "Restricted Computer Software" as that
; term is defined in Clause 52.227-19 of the Federal Acquisition
; Regulations (FAR) and are "Commercial Computer Software" as that
; term is defined in Subpart 227.401 of the Department of Defense
; Federal Acquisition Regulation Supplement (DFARS).
;
; (i) If the licensed Programs are supplied to the Department of
; Defense (DoD), the Licensed Programs are classified as
; "Commercial Computer Software" and the Government is acquiring
; only "restricted rights" in the Licensed Programs and their
; documentation as that term is defined in Clause 52.227
; 7013(c)(1) of the DFARS, and
;
; (ii) If the Licensed Programs are supplied to any unit or agency
; of the United States Government other than DoD, the
; Government's rights in the Licensed Programs and their
; documentation will be as defined in Clause 52.227-19(c)(2) of
; the FAR.
;****************************************************************************
(define-structure utils
(export (defmac :syntax)
(comment :syntax)
(define-constant :syntax)
(define-in-line :syntax)
(define-integrable :syntax)
(when :syntax) (unless :syntax)
set-err-should-exit?
err
make-string-hash-table
make-symbol-hash-table
hash-table/lookup
hash-table/get hash-table/put! hash-table/modify!
hash-table/clear! hash-table/for-each
parse-options
)
;; Eventually weed some of these out...
(open defrec-package
scsh ; order matters
;;signals
;;conditions
;;handle
tables
;;sort
scheme
)
(files utils
))
(define-structure lists
(export last-pair cons*
reverse! reverse*! reverse* append!
map* append-map append-map* append-map! append-map*!
there-exists? for-all?
reduce reduce-right reduce-map reduce-right-map
fold fold* fold-map fold-map*
fold-reverse fold-reverse* fold-reverse-map fold-reverse-map*
)
(open utils
scheme
)
(files lists
))
(define-structure strings
(export string-search-forwards string-ci-search-forwards
string-search-forwards-not string-ci-search-forwards-not
string-search-backwards string-ci-search-backwards
string-search-backwards-not string-ci-search-backwards-not
string-downcase string-downcase!
string-upcase string-upcase!
string-capitalize string-capitalize!
pathname-entry-name pathname-directory-name
pathname-append
pathname-relative?
pathname->list
list->pathname
canonicalize-pathname-list
canonicalize-pathname
symbol-append
encode-integer-in-base
)
(open lists
utils
scheme
)
(files strings
))
(define-structure match (export match?)
(open utils
scheme
)
(files match
))
(define-structure layout-language (export (define-layout :syntax)
(define-layout-macro :syntax)
define-rcs-info
use-layouts
(C-include :syntax)
)
(open match
strings
lists
utils
defrec-package
scsh ; order matters
sort
evaluation ; Ick
environments ; Yuck!
package-commands-internal ; Gag!!
scheme
)
(files layout
))
; This is the package we actually load .ldb files into:
(define-structure user-layouts (export)
(open layout-language
scheme
))
; $Log: packages.scm,v $
; Revision 1.1.1.1 2001/11/05 17:47:21 tneale
; Tornado shuffle
;
; Revision 1.3 2001/01/19 22:22:36 paul
; Update copyright.
;
; Revision 1.2 1998/02/25 04:54:31 sra
; Update copyrights.
;
; Revision 1.1 1997/09/26 20:14:41 alan
; Initial Revision
;
; Local Variables:
; mode: Scheme
; End:
@@ -0,0 +1,302 @@
; $Header: /usr/cvsroot/target/h/wrn/wm/util/layout/ldbcomp/strings.scm,v 1.1.1.1 2001/11/05 17:47:21 tneale Exp $
; Strings and pathnames
;****************************************************************************
;
; *** Restricted Rights Legend ***
;
; The programs and information contained herein are licensed only
; pursuant to a license agreement that contains use, reverse
; engineering, disclosure, and other restrictions; accordingly, it
; is "Unpublished--all rights reserved under the applicable
; copyright laws".
;
; Use duplication, or disclosure by the Government is subject to
; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
; in Technical Data and Computer Licensed Programs clause of DFARS
; 52.227 7013.
;
; Copyright 2000-2001 Wind River Systems, Inc.
; Copyright 1997 Epilogue Technology Corporation.
; Copyright 1998 Integrated Systems, Inc.
; All rights reserved.
;
; *** Government Use ***
;
; The Licensed Programs and their documentation were developed at
; private expense and no part of them is in the public domain.
;
; The Licensed Programs are "Restricted Computer Software" as that
; term is defined in Clause 52.227-19 of the Federal Acquisition
; Regulations (FAR) and are "Commercial Computer Software" as that
; term is defined in Subpart 227.401 of the Department of Defense
; Federal Acquisition Regulation Supplement (DFARS).
;
; (i) If the licensed Programs are supplied to the Department of
; Defense (DoD), the Licensed Programs are classified as
; "Commercial Computer Software" and the Government is acquiring
; only "restricted rights" in the Licensed Programs and their
; documentation as that term is defined in Clause 52.227
; 7013(c)(1) of the DFARS, and
;
; (ii) If the Licensed Programs are supplied to any unit or agency
; of the United States Government other than DoD, the
; Government's rights in the Licensed Programs and their
; documentation will be as defined in Clause 52.227-19(c)(2) of
; the FAR.
;****************************************************************************
;
; Case
;
(define (string-upcase str)
(let* ((len (string-length str))
(new (make-string len)))
(do ((i (- len 1) (- i 1)))
((< i 0))
(string-set! new i (char-upcase (string-ref str i))))
new))
(define (string-downcase str)
(let* ((len (string-length str))
(new (make-string len)))
(do ((i (- len 1) (- i 1)))
((< i 0))
(string-set! new i (char-downcase (string-ref str i))))
new))
(define (string-upcase! str)
(do ((i (- (string-length str) 1) (- i 1)))
((< i 0))
(string-set! str i (char-upcase (string-ref str i))))
str)
(define (string-downcase! str)
(do ((i (- (string-length str) 1) (- i 1)))
((< i 0))
(string-set! str i (char-downcase (string-ref str i))))
str)
(define (string-capitalize str)
(let* ((len (string-length str))
(new (make-string len)))
(let loop ((i 0)
(last-alpha? #F))
(when (< i len)
(let ((c (string-ref str i)))
(string-set! new i (if last-alpha?
(char-downcase c)
(char-upcase c)))
(loop (+ i 1) (char-alphabetic? c)))))
new))
(define (string-capitalize! str)
(let ((len (string-length str)))
(let loop ((i 0)
(last-alpha? #F))
(when (< i len)
(let ((c (string-ref str i)))
(string-set! str i (if last-alpha?
(char-downcase c)
(char-upcase c)))
(loop (+ i 1) (char-alphabetic? c)))))
str))
;
; Searching
;
; These all assume that you won't pass bogus values of `beg' and `end'.
; It is safe to compare characters using `eq?' in Scheme48...
(define (string-search-forwards chr str beg end)
(let loop ((i beg))
(cond ((>= i end) #F)
((eq? chr (string-ref str i)) i)
(else (loop (+ i 1))))))
(define (string-search-forwards-not chr str beg end)
(let loop ((i beg))
(cond ((>= i end) #F)
((not (eq? chr (string-ref str i))) i)
(else (loop (+ i 1))))))
(define (string-search-backwards chr str beg end)
(let loop ((i (- end 1)))
(cond ((< i beg) #F)
((eq? chr (string-ref str i)) i)
(else (loop (- i 1))))))
(define (string-search-backwards-not chr str beg end)
(let loop ((i (- end 1)))
(cond ((< i beg) #F)
((not (eq? chr (string-ref str i))) i)
(else (loop (- i 1))))))
; And the -ci versions:
(define (string-ci-search-forwards chr str beg end)
(let loop ((i beg))
(cond ((>= i end) #F)
((char-ci=? chr (string-ref str i)) i)
(else (loop (+ i 1))))))
(define (string-ci-search-forwards-not chr str beg end)
(let loop ((i beg))
(cond ((>= i end) #F)
((not (char-ci=? chr (string-ref str i))) i)
(else (loop (+ i 1))))))
(define (string-ci-search-backwards chr str beg end)
(let loop ((i (- end 1)))
(cond ((< i beg) #F)
((char-ci=? chr (string-ref str i)) i)
(else (loop (- i 1))))))
(define (string-ci-search-backwards-not chr str beg end)
(let loop ((i (- end 1)))
(cond ((< i beg) #F)
((not (char-ci=? chr (string-ref str i))) i)
(else (loop (- i 1))))))
;
; Pathnames
;
(define (pathname-entry-name pathname)
(let* ((len (string-length pathname))
(j (string-search-backwards-not #\/ pathname 0 len)))
(if (not j)
"."
(let ((i (string-search-backwards #\/ pathname 0 j)))
(if (not i)
(substring pathname 0 (+ 1 j))
(substring pathname (+ 1 i) (+ 1 j)))))))
(define (pathname-directory-name pathname)
;; Always ends with a "/", both for convenience in concatenation, and so
;; that the root directory has a non-empty name.
(let* ((len (string-length pathname))
(j (string-search-backwards-not #\/ pathname 0 len)))
(if (not j)
"/"
(let ((i (string-search-backwards #\/ pathname 0 j)))
(if (not i)
"./"
(let ((h (string-search-backwards-not #\/ pathname 0 i)))
(if (not h)
"/"
(substring pathname 0 (+ h 2)))))))))
(define (pathname-append pn1 pn2)
(let ((len1 (string-length pn1))
(len2 (string-length pn2)))
(cond ((= 0 len1) pn2)
((= 0 len2) pn1)
((eq? #\/ (string-ref pn2 0)) pn2)
((eq? #\/ (string-ref pn1 (- len1 1)))
(string-append pn1 pn2))
(else (string-append pn1 "/" pn2)))))
(define (pathname-relative? pn)
(or (= 0 (string-length pn))
(not (eq? #\/ (string-ref pn 0)))))
(define (pathname->list pathname)
(let ((end (string-length pathname)))
(if (= 0 end)
'(relative)
(cons (if (eq? #\/ (string-ref pathname 0))
'absolute
'relative)
(let loop ((beg 0))
(let ((i (string-search-forwards-not #\/ pathname beg end)))
(if (not i)
'()
(let ((j (string-search-forwards #\/ pathname i end)))
(if (not j)
(list (substring pathname i end))
(cons (substring pathname i j)
(loop j)))))))))))
(define (list->pathname lst)
(define (process lst)
(if (null? lst)
'()
(cons* "/" (car lst) (process (cdr lst)))))
(case (car lst)
((absolute)
(if (null? (cdr lst))
"/"
(apply string-append (process (cdr lst)))))
((relative)
(if (null? (cdr lst))
"."
(apply string-append (cdr (process (cdr lst))))))
(else (err 'list->pathname "Bad pathname list: ~S" lst))))
(define (canonicalize-pathname-list lst)
(let loop ((l (cdr lst))
(p '())
(r '()))
(cond ((null? l)
(cons (car lst) (append! p (reverse! r))))
((string=? "." (car l))
(loop (cdr l) p r))
((string=? ".." (car l))
(if (null? r)
(loop (cdr l) (cons ".." p) r)
(loop (cdr l) p (cdr r))))
(else
(loop (cdr l) p (cons (car l) r))))))
(define (canonicalize-pathname pathname)
(list->pathname (canonicalize-pathname-list (pathname->list pathname))))
;
; Making things into strings
;
(define (symbol-append . args)
(define (->string arg)
(cond ((string? arg) arg)
((symbol? arg) (symbol->string arg))
((char? arg) (string arg))
((and (integer? arg) (exact? arg))
(number->string arg 10))
(else (err 'symbol-append "Don't know how to use: ~S" arg))))
(string->symbol (apply string-append (map ->string args))))
(define (encode-integer-in-base n base digits)
(define (loop n l)
(if (< n base)
(cons (string-ref digits n) l)
(loop (quotient n base)
(cons (string-ref digits (modulo n base)) l))))
(unless (integer? n)
(err 'encode-integer-in-base "Not an integer: ~S" n))
(unless (and (integer? base) (> base 1))
(err 'encode-integer-in-base "Bad base: ~S" base))
(unless (<= base (string-length digits))
(err 'encode-integer-in-base "Not enough digits for base ~S: ~S"
base digits))
(list->string (if (< n 0)
(cons #\- (loop (- n) '()))
(loop n '()))))
; $Log: strings.scm,v $
; Revision 1.1.1.1 2001/11/05 17:47:21 tneale
; Tornado shuffle
;
; Revision 1.3 2001/01/19 22:22:36 paul
; Update copyright.
;
; Revision 1.2 1998/02/25 04:54:33 sra
; Update copyrights.
;
; Revision 1.1 1997/09/26 20:14:41 alan
; Initial Revision
;
; Local Variables:
; mode: Scheme
; End:
@@ -0,0 +1,233 @@
; $Header: /usr/cvsroot/target/h/wrn/wm/util/layout/ldbcomp/utils.scm,v 1.1.1.1 2001/11/05 17:47:21 tneale Exp $
; Utilities for the layout tool.
;****************************************************************************
;
; *** Restricted Rights Legend ***
;
; The programs and information contained herein are licensed only
; pursuant to a license agreement that contains use, reverse
; engineering, disclosure, and other restrictions; accordingly, it
; is "Unpublished--all rights reserved under the applicable
; copyright laws".
;
; Use duplication, or disclosure by the Government is subject to
; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
; in Technical Data and Computer Licensed Programs clause of DFARS
; 52.227 7013.
;
; Copyright 2000-2001 Wind River Systems, Inc.
; Copyright 1997 Epilogue Technology Corporation.
; Copyright 1998 Integrated Systems, Inc.
; All rights reserved.
;
; *** Government Use ***
;
; The Licensed Programs and their documentation were developed at
; private expense and no part of them is in the public domain.
;
; The Licensed Programs are "Restricted Computer Software" as that
; term is defined in Clause 52.227-19 of the Federal Acquisition
; Regulations (FAR) and are "Commercial Computer Software" as that
; term is defined in Subpart 227.401 of the Department of Defense
; Federal Acquisition Regulation Supplement (DFARS).
;
; (i) If the licensed Programs are supplied to the Department of
; Defense (DoD), the Licensed Programs are classified as
; "Commercial Computer Software" and the Government is acquiring
; only "restricted rights" in the Licensed Programs and their
; documentation as that term is defined in Clause 52.227
; 7013(c)(1) of the DFARS, and
;
; (ii) If the Licensed Programs are supplied to any unit or agency
; of the United States Government other than DoD, the
; Government's rights in the Licensed Programs and their
; documentation will be as defined in Clause 52.227-19(c)(2) of
; the FAR.
;****************************************************************************
;
; Macrology
;
(define-syntax defmac
(syntax-rules ()
((defmac (name . bvl) def)
(define-syntax name
(syntax-rules ()
((name . bvl) def))))))
(defmac (comment . stuff)
(quote (comment)))
(defmac (define-constant . stuff)
(define . stuff))
(defmac (define-in-line (name . bvl) expr)
(define-syntax name
(syntax-rules ()
((name . bvl) expr))))
(defmac (define-integrable . stuff)
(define . stuff))
(defmac (when test first . rest)
(if test (begin first . rest)))
(defmac (unless test first . rest)
(if (not test) (begin first . rest)))
;
; Errors
;
(define err-should-exit? #F)
(define (set-err-should-exit? flag)
(set! err-should-exit? flag))
(define (err id format-string . format-args)
(format (error-output-port) "layout: ")
(unless (eq? id 'layout)
(format (error-output-port) "~A: " id))
(apply format (error-output-port) format-string format-args)
(cond (err-should-exit?
(newline (error-output-port))
(exit 1))
(else
(apply error format-string format-args))))
;
; (Hash) Tables
;
(define-record hash-table
table
init
)
(define (make-string-hash-table initial-size)
(make-hash-table (make-string-table) make-string-table))
(define (make-symbol-hash-table initial-size)
(make-hash-table (make-symbol-table) make-symbol-table))
(define (hash-table/clear! table)
(set-hash-table:table table ((hash-table:init table))))
(define (hash-table/get table key default)
(let ((cell (table-ref (hash-table:table table) key)))
(if cell (car cell) default)))
(define (hash-table/put! table key value)
(let* ((table (hash-table:table table))
(cell (table-ref table key)))
(if cell
(set-car! cell value)
(table-set! table key (list value)))))
(define (hash-table/modify! table key default proc)
(let* ((table (hash-table:table table))
(cell (table-ref table key)))
(if cell
(set-car! cell (proc (car cell)))
(table-set! table key (list (proc default))))))
(define (hash-table/lookup table key win lose)
(let ((cell (table-ref (hash-table:table table) key)))
(if cell
(win (car cell))
(lose))))
(define (hash-table/for-each table procedure)
(table-walk (lambda (key cell)
(procedure key (car cell)))
(hash-table:table table)))
;
; Operating system interface
;
(define (parse-options args specs)
;; each spec is of the form: ("-foo" <kind> foo)
;; "--" is understood
;; Possible <kind>s:
;; #F or FLAG boolean flag
;; #T or ARG next argument is the value
;; EXEC arguments up to ";" are values
;; (like "find ... -exec ... \;". Yuck!)
(let ((alist (let loop ((alist '())
(specs specs))
(if (null? specs)
alist
(case (cadr (car specs))
((#F flag)
(loop alist (cdr specs)))
((arg #T exec)
(loop (cons (cons (caddr (car specs)) '()) alist)
(cdr specs)))
(else
(err 'parse-options "bad spec: ~S" (car specs))))))))
(define (add prop vals)
(let ((p (assq prop alist)))
(if p
(set-cdr! p (append (cdr p) vals))
(set! alist (cons (cons prop vals) alist)))))
(let loop ((args args))
(if (null? args)
(add 'args '())
(let ((opt (car args)))
(if (and (<= 2 (string-length opt))
(char=? #\- (string-ref opt 0)))
(let ((spec (assoc opt specs)))
(cond (spec
(case (cadr spec)
((#F flag)
(add (caddr spec) '())
(loop (cdr args)))
((#T arg)
(when (null? (cdr args))
(err 'parse-options
"option requires argument: ~A" opt))
(add (caddr spec) (list (cadr args)))
(loop (cddr args)))
((exec)
(let l ((args (cdr args))
(vals '()))
(cond ((null? args)
(err 'parse-options
"missing `;': ~A" opt))
((string=? ";" (car args))
(add (caddr spec) (list (reverse vals)))
(loop (cdr args)))
(else
(l (cdr args) (cons (car args) vals))))))
(else
(err 'parse-options
"unknown option type: ~A" (cadr spec)))))
((string=? opt "--")
(add 'args (cdr args)))
(else
(err 'parse-options "unknown option: ~A" opt))))
(add 'args args)))))
alist))
; $Log: utils.scm,v $
; Revision 1.1.1.1 2001/11/05 17:47:21 tneale
; Tornado shuffle
;
; Revision 1.3 2001/01/19 22:22:36 paul
; Update copyright.
;
; Revision 1.2 1998/02/25 04:54:36 sra
; Update copyrights.
;
; Revision 1.1 1997/09/26 20:14:41 alan
; Initial Revision
;
; Local Variables:
; mode: Scheme
; eval: (put 'hash-table/modify! 'scheme-indent-hook 3)
; eval: (put 'hash-table/lookup 'scheme-indent-hook 2)
; eval: (put 'hash-table/for-each 'scheme-indent-hook 1)
; End: