Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
269 user(s) are online (156 user(s) are browsing Forums)

Members: 0
Guests: 269

more...

Headlines

 
  Register To Post  

minor AREXX programming question
Home away from home
Home away from home


See User information
let's say i have 2 buffers:

test1 = '"RAM:aaaa/aaaa"'
test2 = 'bbbb'

say test1
say test2

and i have:

"RAM:aaaa/aaaa"
bbbb

now i need to combine it to one string, with " " around, to have in end "RAM:aaaa/aaaabbbb"

so i try:

test1 = '"RAM:aaaa/aaaa"'
test2 = 'bbbb'
test3 = insert(test1,test2)

and as result test3 of course look like this:

"RAM:aaaa/aaaa"bbbb

but i need "RAM:aaaa/aaaabbbb"

Should i manually remove " " from first buffer, then combine them, and then again add " at begining and " at end of final buffer ? Is there any better way ? Ready to use example preffered of course. Thanks.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Amigans Defender
Amigans Defender


See User information
test3 = strip(test1, 'B', '"')
test4 = test3 || test2

or something like that.

Go to top
Re: minor AREXX programming question
Home away from home
Home away from home


See User information
@Chris
Yep, that mean removing manually " characters, then contain, and need to add them back to full string. Is there arexx function which mean "add character at begining and at end of string" ? I currently do it like this:

test3 = strip(test1, 'B', '"')
test4 = test3 || test2
test4 = '"'test4'"'

seems works, but dunno if it right way

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Just popping in
Just popping in


See User information
@kas1e

You can do it in one step:

test1 '"RAM:aaaa/aaaa"'
test2 'bbbb'

test3 '"' || strip(test1'B''"') || strip(test2'B''"') || '"'


I stripped both vars to make it more general.

Go to top
Re: minor AREXX programming question
Home away from home
Home away from home


See User information
@Gazelle
Yep thanks, that one works and looks better :)

@all
Its in general about arexx script for sketchblock to save in os4 native icon format: It use netpbm and pngicon2amiga for conversion, checking the size of image (if it bigger than 256x256 it says that 256x256 max and need to rescale), as well as if you typed anything for save without ending it with ".info", then ".info" adds automatically to the filename (and if .info was added, then it skips).

There is script.

I add it to sketchmenu by adding to sketchprefs.xml that:

<menu label="Advanced Save As">
 <
item label="Save As AOS4 icon">
 <
command>work:sketchblock/my_rexxscripts/saveasos4icon.rexx</command>
 </
item>
</
menu>

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Not too shy to talk
Not too shy to talk


See User information

You aren't programmer, are you?

Not only that it seems like you never heard of the logical or operator | nor of the keyword else, you obviously don't even consider reading (or understanding?) the docs about the functions you use.

I only read your script up to the part with .info, then I could not stop laughing.

verify(a,b) checks if the string a contains only letters also contained in the string b. If not, it returns the position of the character in a which is not contained in b.

So what your verify(".info",filename) does is, it verifies that ".info" only consists of characters also contained in filename. For example verify(".info","mainpart.four") will return 0 because all letters of .info are also contained in mainpart.four, but verify(".info","mainpart.six") will return 4 because f is the first letter in .info which is not contained in mainpart.six. In neither case your program will add ".info" to the file name because the result of verify is not 1.


Go to top
Re: minor AREXX programming question
Home away from home
Home away from home


See User information
@Thomas
After i read your answer, i even happy that i am not programmer :) But thanks for info about verify().

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Just can't stay away
Just can't stay away


See User information
@Thomas:
After you finished laughing, perhaps it would have been useful to suggest an alternative solution.

@kas1e:
As far as I can see, the main problem (about the .info suffix) is the misunderstanding about verify.

So if simply this line:

if verify('.info',outfile) = 1 then do

was changed to e.g.:

if lastpos('.info'outfile) < length(outfile) - 4 then do

- then that part should be working as intended, I believe. The new line checks that there is the string ".info" at the very end of the filename; lastpos makes sure it won't bother about an earlier ".info" (if anyone should be so weird as to suggest the filename "abc.infodef.info" ), and length minus 4 is where we would expect the .info to start for a correct icon filename. If it is not found at all, lastpos returns 0, which wil also be less than the length - 4, so that's covered too.

One missing check would be to ensure the filename is longer than 4 characters in the first place; if not, we will have a problem. But that is left as an exercise .

BTW, I can recommend having ARexxGuide available when coding ARexx. Although it's old, it is really useful and easy to find your way around, and it's not like ARexx has changed since then. It is/was originally shareware; does anyone know if the original author is still around somewhere?

Best regards,

Niels

Go to top
Re: minor AREXX programming question
Not too shy to talk
Not too shy to talk


See User information
Quote:
if lastpos('.info', outfile) < length(outfile) - 4 then do


This will not work, either. It also applies to "something.information" and similar.

This one will work correctly:

if right(outfile,5) = ".info" then do
...


or if you want it to accept both upper and lower case file names:

if upper(right(outfile,5)) = ".INFO" then do
...



Go to top
Re: minor AREXX programming question
Home away from home
Home away from home


See User information
@thomas
Are you programmer ? I could not stop laughing when i tryed your suggestions, as they didn't works, while NBache's one works at least (through add .info all the time because of -4, but with -5 is ok)

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Not too shy to talk
Not too shy to talk


See User information
Here is a revised version (not tested, though):

/* save as AmigaOS4 icon */

/* requires:
NetPBM  http://os4depot.net/share/graphics/convert/netpbm.lha
pngicon2amiga http://os4depot.net/share/graphics/convert/pngicon2amiga.lha
*/

ADDRESS COMMAND
options results

time 
date('s') || space(translate(time(),' ',':',0))
tempexportfile "T:" || pragma('ID') || '_' || time || '_exp'
tempfnamefile "T:" || pragma('ID') || '_' || time || '_fn'

signal on error

/* get size of image to save (for os4icon 256x256 is max) */
ADDRESS SKETCHBLOCK GETPROJECTINFO STEM prj

WIDTH 
prj.width
HEIGHT 
prj.height

if WIDTH 256 HEIGHT 256 then do
    
say "AmigaOS4 icons can't be more than 256x256 pixels, plz scale"
    
exit
end

/* ok, size of image fine, continue */

'EXPORT FILE=' || tempexportfile


"REQUESTFILE SAVEMODE PATTERN #?.info TO " tempfnamefile

outfile 
""
if open('FILENAME',tempfnamefile,'R'then do
    
outfile strip(readln('FILENAME'),'B','"')
    
call close('FILENAME')
end

if outfile "" right(outfile,1) = ':' right(outfile,1) = '/' then do
    
say "requester cancelled or no file name given"
    
exit
end

/* check , if filename have .info at end (necessary for png2icon). and if not, add it automatically*/

if upper(right(outfile,5)) ~= '.INFO' then do
    
say ".info is NOT here!, so add"
    
outfile '"' || outfile || ".info" || '"'
end


conversion1 
"work:NetPBM/bin/ilbmtoppm -maskfile ram:mask " || tempexportfile ||  " >ram:tmpfile"
conversion2 "work:NetPBM/bin/pnmtopng -force -alpha ram:mask ram:tmpfile >" || outfile
conversion3 
"work:PNGIcon2Amiga/PNGIcon2Amiga " || outfile

/* 'address command' has been set above */

say conversion1
conversion1

say conversion2
conversion2

say conversion3
conversion3

error
:

"delete >NIL: *>NIL: quiet " || tempexportfile
"delete >NIL: *>NIL: quiet " || tempfnamefile
"delete >NIL: *>NIL: quiet ram:tmpfile"
"delete >NIL: *>NIL: quiet ram:mask"

exit



One thing left, though: in the beginning you make big effort to create unique file names and in the end you just use ram:tmpfile and ram:mask.

Go to top
Re: minor AREXX programming question
Home away from home
Home away from home


See User information
@Thomas
When i tryed to use your version, i have:

EXPORT: Unknown command


Also after reading a script briefly, i see that if .info was here initially, then " " symbols are strips, and so, output will be not "RAM DISK:aaa.info", but without " ", and conversion will not works because of space. So i add some stuff here:

if upper(right(outfile,5)) ~= '.INFO' then do 
    
say ".info is NOT here!, so add" 
    
outfile '"' || outfile || ".info" || '"' 
end 
else do
    
outfile '"' || outfile || '"'
end



Also seems that part:
if outfile "" right(outfile,1) = ':' right(outfile,1) = '/' then do 
    
say "requester cancelled or no file name given" 
    
exit 
end


Works only when no file name was given, but it didn't triggers when i press "chancel" in asl requester.


Quote:

One thing left, though: in the beginning you make big effort to create unique file names and in the end you just use ram:tmpfile and ram:mask.


It is need it (to save mask separately from file, and to have in end normal png with transparency, which in end can be normally converted to icon)


Edited by kas1e on 2013/1/3 11:26:42
Edited by kas1e on 2013/1/3 11:31:10
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Not too shy to talk
Not too shy to talk


See User information
Quote:

When i tryed to use your version, i have:

EXPORT: Unknown command


An ADDRESS SKETCHBLOCK is missing in front of it. I changed the global address to COMMAND because there are many commands sent to COMMAND but only two commands sent to SKETCHBLOCK. Forgot to change the second one.

Quote:

Also after reading a script briefly, i see that if .info was here initially, then " " symbols are strips, and so, output will be not "RAM DISK:aaa.info", but without " ", and conversion will not works because of space. So i add some stuff here:


That's right. I forgot this because usually I don't put quotation marks into the variable which holds the file name but into the command line. This script is different.

Quote:

Also seems that part:

Works only when no file name was given, but it didn't triggers when i press "chancel" in asl requester.


What does outfile contain if cancel is pressed?


Quote:

It is need it (to save mask separately from file, and to have in end normal png with transparency, which in end can be normally converted to icon)


I know how the process works. My criticism was about using fixed global file names in one place but trying to use process-dependent unique file names in another place. If you use hard-coded ram:xyz in one place you can skip the effort to create unique names in the other places, too.


Go to top
Re: minor AREXX programming question
Just can't stay away
Just can't stay away


See User information
Quote:

thomas wrote:
Quote:
if lastpos('.info', outfile) < length(outfile) - 4 then do
This will not work, either. It also applies to "something.information" and similar.
Huh? Not in my tests (and prior analysis). Did you test it yourself?

9.WB-B0 0 [0,001.997Fredag 04/01-2013 00:30:21 
rx "outfile = 'something.information'; if lastpos('.info', outfile) < length(outfile) - 4 then say 'No info'; else say 'OK'"
No info
9.WB
-B0 0 [0,002.042Fredag 04/01-2013 00:32:54 
rx "outfile = 'something.info'; if lastpos('.info', outfile) < length(outfile) - 4 then say 'No info'; else say 'OK'"
OK
9.WB
-B0 0 [0,003.102Fredag 04/01-2013 00:33:05 
>


Best regards,

Niels

Go to top
Re: minor AREXX programming question
Home away from home
Home away from home


See User information
@Thomas
Modified script with all your suggestions, there is

Only that i can't detect when "chancel" is pressed in asl-requester (i put before error: label, "say outfile" and when i press chancel in asl req it says OUTFILE), like its empty or kind.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: minor AREXX programming question
Just can't stay away
Just can't stay away


See User information
Maybe the following snippet can give you inspiration?

/* TestSavereq.rexx */
options results
address command 
'requestfile savemode pattern #?.info to RAM:xyz'
if RC 0 then say 'Cancelled'
else do
   if 
open('tmpf''RAM:xyz''r'then do
      
ofn strip(readln('tmpf'), 'B''"')
      
call close('tmpf')
      
say ofn
   end
end


Best regards,

Niels

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project