CVSROOT:        /cvsroot/lilypond
Module name:    lilypond
Branch:         
Changes by:     Han-Wen Nienhuys <[EMAIL PROTECTED]>    05/08/22 15:50:37

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

Log message:
        * 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.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.4060&tr2=1.4061&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/lily-guile.cc.diff?tr1=1.221&tr2=1.222&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/source-file.cc.diff?tr1=1.34&tr2=1.35&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/text-metrics.cc.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/lily-guile.hh.diff?tr1=1.164&tr2=1.165&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/python/lilylib.py.diff?tr1=1.67&tr2=1.68&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/ps-to-png.scm.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scripts/lilypond-book.py.diff?tr1=1.270&tr2=1.271&r1=text&r2=text

Patches:
Index: lilypond/ChangeLog
diff -u lilypond/ChangeLog:1.4060 lilypond/ChangeLog:1.4061
--- lilypond/ChangeLog:1.4060   Mon Aug 22 14:49:23 2005
+++ lilypond/ChangeLog  Mon Aug 22 15:50:36 2005
@@ -1,5 +1,14 @@
 2005-08-22  Han-Wen Nienhuys  <[EMAIL PROTECTED]>
 
+       * 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: lilypond/lily/include/lily-guile.hh
diff -u lilypond/lily/include/lily-guile.hh:1.164 
lilypond/lily/include/lily-guile.hh:1.165
--- lilypond/lily/include/lily-guile.hh:1.164   Sat Aug 13 21:35:22 2005
+++ lilypond/lily/include/lily-guile.hh Mon Aug 22 15:50:37 2005
@@ -33,7 +33,7 @@
 
 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: lilypond/lily/lily-guile.cc
diff -u lilypond/lily/lily-guile.cc:1.221 lilypond/lily/lily-guile.cc:1.222
--- lilypond/lily/lily-guile.cc:1.221   Mon Aug 22 14:49:23 2005
+++ lilypond/lily/lily-guile.cc Mon Aug 22 15:50:37 2005
@@ -103,7 +103,7 @@
   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: lilypond/lily/source-file.cc
diff -u lilypond/lily/source-file.cc:1.34 lilypond/lily/source-file.cc:1.35
--- lilypond/lily/source-file.cc:1.34   Mon Aug 22 14:49:23 2005
+++ lilypond/lily/source-file.cc        Mon Aug 22 15:50:37 2005
@@ -73,7 +73,7 @@
     warning (_f ("expected to read %d characters, got %d", bytes_read,
                 read_count));
   fclose (f);
-
+  *filesize = bytes_read;
   return str;
 }
 
Index: lilypond/lily/text-metrics.cc
diff -u lilypond/lily/text-metrics.cc:1.7 lilypond/lily/text-metrics.cc:1.8
--- lilypond/lily/text-metrics.cc:1.7   Fri Aug 12 00:04:45 2005
+++ lilypond/lily/text-metrics.cc       Mon Aug 22 15:50:37 2005
@@ -75,7 +75,7 @@
   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: lilypond/python/lilylib.py
diff -u lilypond/python/lilylib.py:1.67 lilypond/python/lilylib.py:1.68
--- lilypond/python/lilylib.py:1.67     Sun Jul 10 11:25:24 2005
+++ lilypond/python/lilylib.py  Mon Aug 22 15:50:37 2005
@@ -348,6 +348,13 @@
                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: lilypond/scm/ps-to-png.scm
diff -u lilypond/scm/ps-to-png.scm:1.13 lilypond/scm/ps-to-png.scm:1.14
--- lilypond/scm/ps-to-png.scm:1.13     Mon Aug 22 14:49:23 2005
+++ lilypond/scm/ps-to-png.scm  Mon Aug 22 15:50:37 2005
@@ -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)
@@ -45,14 +46,10 @@
     (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)
@@ -111,6 +108,16 @@
   (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)
@@ -121,13 +128,12 @@
         )
    
    (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.
@@ -154,10 +160,6 @@
          (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)
@@ -167,20 +169,26 @@
 
      (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: lilypond/scripts/lilypond-book.py
diff -u lilypond/scripts/lilypond-book.py:1.270 
lilypond/scripts/lilypond-book.py:1.271
--- lilypond/scripts/lilypond-book.py:1.270     Tue Aug 16 11:22:40 2005
+++ lilypond/scripts/lilypond-book.py   Mon Aug 22 15:50:37 2005
@@ -954,9 +954,20 @@
                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 @@
                   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):


_______________________________________________
Lilypond-cvs mailing list
Lilypond-cvs@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-cvs

Reply via email to