(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.
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.
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);
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;
warning (_f ("expected to read %d characters, got %d", bytes_read,
read_count));
fclose (f);
-
+ *filesize = bytes_read;
return str;
}
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 ());
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))
(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]+)")
-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))
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
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):