]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/lily-guile.cc (gulp_file_to_string): take size argument.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 22 Aug 2005 14:49:23 +0000 (14:49 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 22 Aug 2005 14:49:23 +0000 (14:49 +0000)
* lily/general-scheme.cc (LY_DEFINE): take optional size argument.

ChangeLog
lily/general-scheme.cc
lily/lily-guile.cc
lily/lily-parser.cc
lily/pfb.cc
lily/source-file.cc
scm/backend-library.scm
scm/ps-to-png.scm

index 47b4c746fd9cd796121d2889a988037ac6721922..7f3e001c05b04339e5bd180a6e3031922980f2a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 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.
index d0804297916f6921ac7c6b4dbc34183795a430d3..6541ab8eaedeecd2bbc47e845309f682b9f00f96 100644 (file)
@@ -52,12 +52,19 @@ LY_DEFINE (ly_find_file, "ly:find-file",
   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 ());
 }
 
index f0f90afa65fbb698989fa382c52fd322d78e478d..1ef5370e8e9d5f951870aca348c9d937ea59d925 100644 (file)
@@ -84,7 +84,7 @@ ly_symbol2string (SCM s)
 }
 
 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 == "")
@@ -103,7 +103,7 @@ gulp_file_to_string (String fn, bool must_exist)
   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;
index 6987c052e85f6b5adeb588f90397712013132eb0..feae02f6455845b05d98a31118aee80d953b0ee9 100644 (file)
@@ -103,7 +103,7 @@ Lily_parser::parse_file (String init, String name, String out_name)
 
   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
index d5961f12f5464e1c3bc728a3aa0aaf901425be05..f255cb846e30eeb93aa0f68d2cdb0d6c0bed9196 100644 (file)
@@ -77,11 +77,11 @@ LY_DEFINE (ly_pfb_to_pfa, "ly:pfb->pfa",
                   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);
 
index af9005e9e7aafb915d22015a68795cee6e3317f4..fdd628fbfbe4791512864097911f4dfe0cfb1fcf 100644 (file)
@@ -57,16 +57,21 @@ gulp_file (String filename, int *filesize)
     }
 
   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;
@@ -95,8 +100,11 @@ Source_file::Source_file (String filename_string)
   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 ();
index 6943b976105958171199746da36c3b6fcd4677a3..18c9c0d2bcd49239b0b594e3026fd56d7be97fc2 100644 (file)
@@ -94,6 +94,7 @@
   (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))
index dfcb9551b08bb942e2b170ee03f6edf705cd2dd9..ddaa3bc18acda6eccd00230c548a9a93af49b784 100644 (file)
@@ -42,8 +42,8 @@
 
 (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)))