www.delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2011/12/04/04:22:24

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
X-Mailer: exmh version 2.7.2 01/07/2005 (debian 1:2.7.2-18) with nmh-1.3
X-Exmh-Isig-CompType: comp
X-Exmh-Isig-Folder: inbox
To: geda-user AT delorie DOT com
Subject: [geda-user] Scheme help, component-library-add-tree
Mime-Version: 1.0
Message-Id: <20111204092153.DBD7781D5429@turkos.aspodata.se>
Date: Sun, 4 Dec 2011 10:21:53 +0100 (CET)
From: karl AT aspodata DOT se (Karl Hammar)
X-Virus-Scanned: ClamAV using ClamSMTP
Reply-To: geda-user AT delorie DOT com

 Hello there,
I'm not fluent in scheme, so maybe someone out there can tell me how
to make this script a good scheme citizen:

/////////////
(use-modules (ice-9 ftw))

; get a sorted list of all keys in (hash) table
(define (keys table)
  (let ((lst 0))
    (set! lst (hash-map->list (lambda (key val) (symbol->string key)) table))
    (set! lst (sort-list! lst string<?))
    lst
    )
  )

;;;----------

(define cb_table (make-hash-table 31))

; for given filename's directory,
;  add it to the hash table (so we only count it once),
;  but only if the file is a regular file and its name ends with ".sym"
; (note, we only adds guile symbols to the table so it will be uniqe)
(define (cb filename statinfo flags)
  (if (and
       (eq? 'regular (stat:type statinfo))
       (string=? ".sym" (string-take-right filename 4))
       )
      (hashq-set! cb_table (string->symbol (dirname filename)) 1)
      )
  #t
  )

; get a sorted list of all directories where thare are file names ending with ".sym"
(define (find_gschem_symbol_directories arg)
  (let ((lst 0))
    (ftw arg cb)
    (set! lst (keys cb_table))
    (hash-clear! cb_table)
    lst
    )
  )

;;;----------

; do (component-library path-to-directory prefix+path_below_dir)
; for all directories below dir that contain .sym files
(define (component-library-add-tree prefix dir)
  (let ((lst 0) (len 0))
    (set! len (string-length dir))
    (set! lst (reverse (find_gschem_symbol_directories dir)))
    (for-each
     (lambda (a) (component-library a (string-append prefix (substring a len))))
     lst
     )
    )
  )
/////////////

You use it like (in your gafrc):

 (component-library-add-tree "cvs" "/home/karl/Net/cvs/cvs.gedasymbols.org/www/user")

to add all directories (with .sym files) below the second argument to
the library browser, shown with the first arg. as prefix.

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019