[*correction*][writing to files] Error: set-output-port: needs 1 argument(s)
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s) | Paul Langevin | 23 Mar 04:29 |
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s) | Kevin Cozens | 23 Mar 05:42 |
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s) | Bill Skaggs | 23 Mar 06:22 |
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s) | Kevin Cozens | 23 Mar 15:50 |
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s)
Hi,
I've asked "script-fu" yahoo group where no-one seems to know the trouble. Can someone here tell me, please, why this script works perfectly well with Windows:MIT/GNU-Scheme and fails on Windows:Gimp2.4.4/TinyScheme ?
It should create a file (whose name is given as an argument) which looks like this :
____________ beginning of the file having 4096 lines______
0 0
0 0.8
0 1.6
0 2.4
0 3.2
0 4
0 4.8
0 5.6
0 6.4
.
.
.
0 44.8
0 45.6
0 46.4
0 47.2
0 48
0 48.8
0 49.6
0 50.4
0.8 0
0.8 0.8
0.8 1.6
0.8 2.4
0.8 3.2
0.8 4
.
.
.
...
.
.
.
50.4 42.4
50.4 43.2
50.4 44.
50.4 44.8
50.4 45.6
50.4 46.4
50.4 47.2
50.4 48.
50.4 48.8
50.4 49.6
50.4 50.4
______________end of the file_________
for the argument inPas given equal to 8.
Instead, with Gimp2.4.4, there always is an error and my file ends too soon :
_______beginning of the file having far less than 4096 lines______
0 0
0 0.8
0 1.6
0 2.4
0 3.2
0 4
0 4.8
0 5.6
0 6.4
.
.
.
11.2 32.8
11.2 33.6
11.2 34.4
11.2 35.2
11.2 36
11.2 36.8
11.2 37.6
11.2 Error: set-output-port: needs 1 argument(s)
______________end of the file_________
My script uses 4 procedures (the same ones on Gimp as on MIT) : 1 main and 3 auxiliary procedures :
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; the construct-list procedure which increments the first number : ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (construct-list row height width pas port)
(cond
((< row height)
(construct-list (+ row pas) height width pas (construct-list-col (/ row 10.0) 0 width pas port)))
(else port)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; the construct-list-col procedure which increments the second number : ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (construct-list-col x col width pas port)
(cond
((< col width)
(element->port x port)
(element->port (/ col 10.0) port)
(newline port)
(construct-list-col x (+ col pas) width pas port))
(else port)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;the element->port procedure which actually writes to the file ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (element->port x port)
(if (number? x)
(begin
(write x port)
(write-char #\space port))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the main procedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (script-fu-exp-medit inFileName inPas)
(define (subscript tour p)
(cond
((= tour 0)
(subscript
1
(construct-list
0 ; row
512 ;heigt
512 ;width
inPas
p)))
(else (close-output-port p))))
(subscript 0 (open-output-file inFileName)))
- On windows:Gimp2.4.4, those 4 procedures together with the call
(script-fu-exp-medit "the-name-of-a-file" 8)
produce, on the Console Script-fu TiinyScheme, the wrong file (and the set-output-port error message written inside the file) without any message neither from the console nor from Gimp.
- On Gimp2.4.4, the use of this registration :
(script-fu-register
"script-fu-exp-medit" ;func name
"Export Medit" ;menu label
"Exports the current image layer as a Medit file.";description
"My Name" ;author
"copyright 2008, My Name" ;copyright notice
"Mars 6, 2008" ;date created
"RGB*" ;image type that the script works on
SF-FILENAME "Fichier en sortie "
"C:\\gimp-2.4\\production\\remplir_Ici" ;a string variable
SF-ADJUSTMENT "taille du pas" '(8 1 256 1 10 0 1)
)
(script-fu-menu-register "script-fu-exp-medit"
"Somewhere"
)
produces the wrong file (and the set-output-port error message written inside the file) with an error message from Gimp :
"Message Export Medit
Erreur à l'exécution de (script-fu-exp-medit "the-name-of-a-file" 8) "
- On MIT/GNU Scheme, I call :
(script-fu-exp-medit "the-name-of-a-file" 8)
and everything works fine.
Any ideas?
Thank you for reading and sorry for the long post. __________________
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s)
Paul Langevin wrote:
I've asked "script-fu" yahoo group where no-one seems to know the trouble. Can someone here tell me, please, why this script works perfectly well with Windows:MIT/GNU-Scheme and fails on Windows:Gimp2.4.4/TinyScheme ?
I had asked you for a more readable version of your script and was waiting for your reply. Now that you have provided it (to the gimp-devel list), I tried to run the script. It runs perfectly fine using TinyScheme directly. Since it doesn't work under GIMP using Script-Fu, it would seem there is a bug in the version of TinyScheme used in Script-Fu.
I would suggest you open a bug report about this problem. However, when you are creating the bug report, it would be better if you attach the expected and actual output from the script as an attachment instead of in the bug report itself. It will make the report easier to read. Also, add the readable version of the script (the one with the extra white-space) as an attachment. Don't forget to include the Script-Fu register blocks.
BTW, the menu register block isn't right. It should read something like: (script-fu-menu-register "script-fu-exp-medit" "/Xtns/Somewhere")
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s)
The script can be made to work in Gimp by adding one line:
...
(define (script-fu-exp-medit inFileName inPas)
(define (subscript tour p)
(set-output-port p) ;;; THIS IS THE ADDED LINE
(cond
((= tour 0)
...
I came up with this by looking at the tinyscheme source code. In the code, if you call
(write x port)
or
(write-char #\space port)
as you do, and if "port" is not the current output port, then scheme saves the value of the current port, sets the output port to "port", performs the write, and then resets the output port back to the old value. Your code never sets the output port, so this set-reset sequence happens for every write and write-char command. Furthermore, the "old value" is undefined.
I don't know enough about scheme to say whether this is a bug in your code or in tinyscheme.
-- Bill
[*correction*][writing to files] Error: set-output-port: needs 1 argument(s)
Bill Skaggs wrote:
The script can be made to work in Gimp by adding one line:
[snip]
(write-char #\space port)
as you do, and if "port" is not the current output port, then scheme saves the value of the current port, sets the output port to "port", performs the write, and then resets the output port back to the old value. Your code never sets the output port, so this set-reset sequence happens for every write and write-char command. Furthermore, the "old value" is undefined.
I don't know enough about scheme to say whether this is a bug in your code or in tinyscheme.
Thanks, Bill. Please add the comments to bug #523974. Since the script generates the correct output when run with TinyScheme I am considering this a bug in Script-Fu.