* lily/general-scheme.cc (LY_DEFINE): take optional size argument.
2005-08-22 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/lily-guile.cc (gulp_file_to_string): take size argument.
+
+ * lily/general-scheme.cc (LY_DEFINE): take optional size argument.
+
* input/regression/tie-manual.ly: new file
* input/regression/tie-chord.ly: update.
buffering.)
*/
LY_DEFINE (ly_gulp_file, "ly:gulp-file",
- 1, 0, 0, (SCM name),
+ 1, 1, 0, (SCM name, SCM size),
"Read the file @var{name}, and return its contents in a string. "
- "The file is looked up using the search path.")
+ "The file is looked up using the search path. ")
{
SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
- String contents = gulp_file_to_string (ly_scm2string (name), true);
+ int sz = -1;
+ if (size != SCM_UNDEFINED)
+ {
+ SCM_ASSERT_TYPE (scm_is_number (size), size, SCM_ARG2, __FUNCTION__, "number");
+ sz = scm_to_int (size);
+ }
+
+ String contents = gulp_file_to_string (ly_scm2string (name), true, sz);
return scm_from_locale_stringn (contents.get_str0 (), contents.length ());
}
}
String
-gulp_file_to_string (String fn, bool must_exist)
+gulp_file_to_string (String fn, bool must_exist, int size)
{
String s = global_path.find (fn);
if (s == "")
if (be_verbose_global)
progress_indication ("[" + s);
- int n;
+ int n = sz;
char *str = gulp_file (s, &n);
String result ((Byte *) str, n);
delete[] str;
File_name f (name);
String s = global_path.find (f.base_ + ".twy");
- s = gulp_file_to_string (s, false);
+ s = gulp_file_to_string (s, false, -1);
scm_eval_string (scm_makfrom0str (s.to_str0 ()));
/* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
SCM_ARG1, __FUNCTION__, "string");
String file_name = ly_scm2string (pfb_file_name);
- int len;
+ int len = -1;
if (be_verbose_global)
progress_indication ("[" + file_name);
-
+
char *str = gulp_file (file_name, &len);
char *pfa = pfb2pfa ((Byte *)str, len);
}
fseek (f, 0, SEEK_END);
- *filesize = ftell (f);
+ int real_size = ftell (f);
+ int read_count = real_size;
+
+ if (*filesize >= 0)
+ read_count = min (read_count, *filesize);
+
rewind (f);
- char *str = new char[*filesize + 1];
- str[*filesize] = 0;
+ char *str = new char[read_count + 1];
+ str[read_count] = 0;
- int bytes_read = fread (str, sizeof (char), *filesize, f);
- if (bytes_read != *filesize)
+ int bytes_read = fread (str, sizeof (char), read_count, f);
+ if (bytes_read != read_count)
warning (_f ("expected to read %d characters, got %d", bytes_read,
- *filesize));
+ read_count));
fclose (f);
return str;
if (filename_string == "-")
load_stdin ();
else
- contents_str0_ = gulp_file (filename_string, &length_);
-
+ {
+ length_ = -1;
+ contents_str0_ = gulp_file (filename_string, &length_);
+ }
+
pos_str0_ = to_str0 ();
init_port ();
(let ((paper-size (sanitize-command-option paper-size-name))
(verbose (ly:get-option 'verbose))
(rename-page-1 #f))
+
(ly:message (_ "Converting to ~a...") "PNG")
(make-ps-images name resolution paper-size rename-page-1 verbose
(ly:get-option 'anti-alias-factor))
(define (gulp-port port max-length)
(let ((str (make-string max-length)))
- (read-string!/partial str port)
- str))
+ (read-string!/partial str port 0 max-length)
+ str))
(define (dir-listing dir-name)
(define (dir-helper dir lst)
)
(let* ((base (basename (re-sub "[.]e?ps" "" ps-name)))
- (header (gulp-port (open-file ps-name "r") 10240))
+ (header (ly:gulp-file ps-name))
+; (header (gulp-port (open-file ps-name "r") 10240))
(png1 (string-append base ".png"))
(pngn (string-append base "-page%d.png"))
(pngn-re (re-sub "%d" "[0-9]*" pngn))
(* aa-factor resolution) ps-name))
(status 0)
(files '()))
+
(for-each delete-file (append (dir-re "." png1)
(dir-re "." pngn-re)))