]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/ps-to-png.scm: remove dir-re function.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 22 Aug 2005 15:50:37 +0000 (15:50 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 22 Aug 2005 15:50:37 +0000 (15:50 +0000)
(make-ps-images): generate page names, instead of globbing them.
This brings down LilyPond memory usage for make web by a factor
10.

* scripts/lilypond-book.py (Lilypond_snippet.png_is_outdated):
don't use glob. With 3000 files, globbing
Documentation/user/out-www/ can take too much time.

* lily/lily-guile.cc (gulp_file_to_string): take size argument.

ChangeLog
lily/include/lily-guile.hh
lily/lily-guile.cc
lily/source-file.cc
lily/text-metrics.cc
python/lilylib.py
scm/ps-to-png.scm
scripts/lilypond-book.py

index 7f3e001c05b04339e5bd180a6e3031922980f2a4..02960840588b095de95e88f0c0becca49f8ede62 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2005-08-22  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * scm/ps-to-png.scm: remove dir-re function.
+       (make-ps-images): generate page names, instead of globbing them.
+       This brings down LilyPond memory usage for make web by a factor
+       10.
+
+       * scripts/lilypond-book.py (Lilypond_snippet.png_is_outdated):
+       don't use glob. With 3000 files, globbing
+       Documentation/user/out-www/ can take too much time.
+
        * lily/lily-guile.cc (gulp_file_to_string): take size argument.
 
        * lily/general-scheme.cc (LY_DEFINE): take optional size argument.
index eaa638ee00aa1c5dbad34051245cb3e9540a3fba..672a0df804fdd7197d8b2a0154e2fa014ba011f9 100644 (file)
@@ -33,7 +33,7 @@ SCM ly_to_symbol (SCM scm);
 
 extern SCM global_lily_module;
 
-String gulp_file_to_string (String fn, bool must_exist);
+String gulp_file_to_string (String fn, bool must_exist, int size);
 
 String ly_scm2string (SCM s);
 String ly_symbol2string (SCM);
index 1ef5370e8e9d5f951870aca348c9d937ea59d925..856c9d30cd3afa8567e35caec43507affa7c9ee0 100644 (file)
@@ -103,7 +103,7 @@ gulp_file_to_string (String fn, bool must_exist, int size)
   if (be_verbose_global)
     progress_indication ("[" + s);
 
-  int n = sz;
+  int n = size;
   char *str = gulp_file (s, &n);
   String result ((Byte *) str, n);
   delete[] str;
index fdd628fbfbe4791512864097911f4dfe0cfb1fcf..74bb5c3b40ac75c7954fd7db20c8048b0b9124e9 100644 (file)
@@ -73,7 +73,7 @@ gulp_file (String filename, int *filesize)
     warning (_f ("expected to read %d characters, got %d", bytes_read,
                 read_count));
   fclose (f);
-
+  *filesize = bytes_read;
   return str;
 }
 
index d69b59d3b4858d5937ccc4847960f07a5b15aaf5..93495258538838c5f5abf8bf44bde6f06db6eb2c 100644 (file)
@@ -75,7 +75,7 @@ try_load_text_metrics (String basename)
   String path = global_path.find (basename + ".textmetrics");
   if (path != "")
     {
-      String contents (gulp_file_to_string (path, true));
+      String contents (gulp_file_to_string (path, true, -1));
       contents = "(quote (" + contents + "))";
 
       SCM lst = scm_c_eval_string (contents.to_str0 ());
index 82b3818966254231690838fe3d9d2911a1b5470a..c50ab48e10902660fbdc42adf73d120daf1db651 100644 (file)
@@ -348,6 +348,13 @@ def print_environment ():
                sys.stderr.write ("%s=\"%s\"\n" % (k, v)) 
 
 
+def ps_page_count (ps_name):
+       header = open (ps_name).read (1024)
+       m = re.search ('\n%%Pages: ([0-9]+)', header)
+       if m:
+               return string.atoi (m.group (1))
+       return 0
+
 def make_ps_images (ps_name, resolution = 90, papersize = "a4",
                    rename_page1_p = 0):
        base = os.path.basename (re.sub (r'\.e?ps', '', ps_name))
index ddaa3bc18acda6eccd00230c548a9a93af49b784..ee16349a83cd8673979d58c06b934d824d7b3585 100644 (file)
@@ -12,7 +12,8 @@
  (ice-9 rw)
  (srfi srfi-1)
  (srfi srfi-13)
- (srfi srfi-14))
+ (srfi srfi-14)
+ )
 
 ;; gettext wrapper for guile < 1.7.2
 (if (defined? 'gettext)
     (read-string!/partial str port 0 max-length)
    str))
 
-(define (dir-listing dir-name)
-  (define (dir-helper dir lst)
-    (let ((e (readdir dir)))
-      (if (eof-object? e) lst (dir-helper dir (cons e lst)))))
-  (reverse (dir-helper (opendir dir-name) '())))
+(define (gulp-file nm len)
+  (gulp-port (open-file nm "r") len))
 
-(define (dir-re dir re)
-  (filter (lambda (x) (string-match re x)) (dir-listing dir)))
+;;; ARGH - cuases memory usage to explode with GUILE cvs.  
 
 (define BOUNDING-BOX-RE
   "^%%BoundingBox: (-?[0-9]+) (-?[0-9]+) (-?[0-9]+) (-?[0-9]+)")
@@ -69,7 +66,7 @@
  -c quit 2>~S"
                          file-name bbox))
         (status (system cmd))
-        (s (gulp-port (open-file bbox "r") 10240))
+        (s (gulp-file d bbox 10240))
         (m (string-match BOUNDING_BOX_RE s)))
     (display m)
     (newline)
   (delete-file old)
   ))
 
+
+(define-public (ps-page-count ps-name)
+  (let*
+      ((header (gulp-file ps-name 10240))
+       (match (string-match "%%Pages: ([0-9]+)" header))
+       (count (if match
+                 (string->number (match:substring match 1))
+                 0)))
+    count))
+
 (define-public (make-ps-images ps-name . rest)
   (let-optional
    rest ((resolution 90)
         )
    
    (let* ((base (basename (re-sub "[.]e?ps" "" ps-name)))
-         (header (ly:gulp-file ps-name))
-;        (header (gulp-port (open-file ps-name "r") 10240))
+         (header (gulp-file ps-name 10240))
          (png1 (string-append base ".png"))
          (pngn (string-append base "-page%d.png"))
-         (pngn-re (re-sub "%d" "[0-9]*" pngn))
-         (multi-page? (and (string-match "\n%%Pages: " header)
-                           (not (string-match "\n%%Pages: 1\n" header))))
+         (page-count (ps-page-count ps-name))
+         
+         (multi-page? (> page-count 1))
          (output-file (if multi-page? pngn png1))
 
          ;;png16m is because Lily produces color nowadays.
          (status 0)
          (files '()))
 
-     
-     (for-each delete-file (append (dir-re "." png1)
-                                  (dir-re "." pngn-re)))
-     
      ;; The wrapper on windows cannot handle `=' signs,
      ;; gs has a workaround with #.
      (if (eq? PLATFORM 'windows)
 
      (set! status (my-system verbose? #f cmd))
 
-     (set! files
-          (append (dir-re "." png1) (dir-re "." pngn-re)))
-
+     (if multi-page?
+        (set! files
+              (map
+               (lambda (n)
+                 (format "~a-page~a.png" base n))
+               (iota page-count)))
+        (list (format "~a.png" base)))
+     
      (if (not (= 0 status))
         (begin
           (map delete-file files)
           (exit 1)))
      
      (if (and rename-page-1? multi-page?)
-        (rename-file (re-sub "%d" "1" pngn) png1))
-     
-     (set! files
-          (append (dir-re "." png1) (dir-re "." pngn-re)))
-
+        (begin
+          (rename-file (re-sub "%d" "1" pngn) png1)
+          (set! files
+                (cons png1
+                      (cdr files)))
+          ))
      
      (if (not (= 1 aa-factor))
         (for-each  (lambda (f) (scale-down-image verbose? aa-factor f))
index 116d5a07ca1e5346754f38f4e26002fe57aad2fb..acb6f81dd01f54628885dba4e6f39483a409ad30 100644 (file)
@@ -954,9 +954,20 @@ class Lilypond_snippet (Snippet):
                base = self.basename ()
                ok = self.ly_is_outdated ()
                if format == HTML or format == TEXINFO:
-                       ok = ok and (os.path.exists (base + '.png')
-                                    or glob.glob (base + '-page*.png'))
+                       ok = ok and os.path.exists (base + '.eps')
+
+                       page_count = 0
+                       if ok:
+                               page_count = ly.ps_page_count (base + '.eps')
+                       
+                       if page_count == 1:
+                               ok = ok and os.path.exists (base + '.png')
+                       elif page_count > 1:
+                               for a in range (1, page_count + 1):
+                                               ok = ok and os.path.exists (base + '-page%d.png' % a)
+                               
                return not ok
+       
        def texstr_is_outdated (self):
                if backend == 'ps':
                        return 0
@@ -990,7 +1001,9 @@ class Lilypond_snippet (Snippet):
                   and (not os.path.exists (single) \
                        or (os.stat (multiple)[stat.ST_MTIME] \
                            > os.stat (single)[stat.ST_MTIME])):
-                       images = glob.glob ('%(base)s-page*.png' % vars ())
+                       count = ly.ps_page_count ('%(base)s.eps' % vars ())
+                       images = ['%s-page%d.png' % (base, a) for a in range (1, count+1)]
+                       images = tuple (images)
                return images
 
        def output_html (self):