Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jep

Pages: 1 ... 20 21 [22] 23 24 ... 26
316
Applications / Re: dbExpert/REXX help needed
« on: 2008.04.08, 16:27:06 »
Hello Dennis,

yes, can you at least cut and paste code here for us to look at? Then we may be able to help you out.
I have a copy of DBE 2.09 running at home to try out if needed.


WarpCafé is right... the rexx implementation i DBE doesn't handle things outside the macro itself, so no shared variables or system calls. All macros behave as they've got "procedure" set, a bit annoying to be tied down like that.

//Jan-Erik

317
Rexx / Difference between changestr and translate
« on: 2008.04.07, 13:26:20 »
Marked as: Easy
Object Rexx
Hello,

Many have the opinion that one should stick with Classic Rexx because it's not that picky and object raxx xan't handle those scripts. A drawbac though is that those who know how Object Rexx was develop can state that the compiler used didn't produce the perfect script engine we'd like.

I've found that Object Rexx contain alot of interesting functions that Classic rexx lack and that almost all classic rexx scripts work without any modifications. Object rexx check the code before execution and is probably stricter, so sloppy code may have to be rewritten a bit though.


Code: [Select]
f_size = stream( fileName, "c", "QUERY SIZE" )
        call stream fileName, "c", "OPEN READ"
       
        fileContents = charin( fileName, 1, f_size )
   
        call stream fileName, "c", "CLOSE"


say CHANGESTR( '%**P', fileContents, 'C:\Path_to_file' )
say TRANSLATE( fileContents, '/', '\~' )

changestr search and replace the whole string ( '%**P in the example above ) with the other ( 'C:\Path_to_file' ) while translate replace every occurance of a character ( '\' ) with the character at the corresponding position in the other string ( '/' ). Additional characters to search for that doesn't have a replacement char in the other string ( '/' ) are removed.

Translate is also very useful when one want to preform a caseless string match.
Code: [Select]
  text = TRANSLATE( text ) /* Convert all text to UPPER CASE */
  if text = 'THIS IS A MATCH' then Return 1

the opposite is a bit trickier, but then you may want to use:
Code: [Select]
  text = TRANSLATE( text, XRANGE( 'a', 'z' ), XRANGE( 'A', 'Z' ) ) /* Convert all text to lower case */
  if text = 'this is a match' then Return 1
but you may not that you may want to add some more characters such as ( üåäö vs. üÅÄÖ ) to support more languages, the problem with those characters are that they're scattered out in the ascii table and that different codepages may have position them somewhere else than you expect. If you use the first method you can be sure that it convert all characters to upper case and that your comparison will work better.

318
Rexx / Fading "progressbar"
« on: 2008.04.04, 20:05:09 »
Marked as: Easy
Hello,

This example show you how one can create a progress bar that travels back and forth to show that the script is busy processing something. Quite neat when one can't calculate the time left nor have any other measurement on how far away the finish may be.

Description:
The first call to the function configure it and draw the initial characters, consecutive calls move the characters one step forward for each call. 3 global variables ( count_ width_ pos_y_ ) store information between each call. The usage of the character "_" in the end was chosen to not interfere with normal naming of variables.

In this example you'll learn how calculations with % work (divide and keeps the whole number part ), as well as //  (keep the remainder).

NOTE: Changed % 2 to // 2... Now it should behave better. 2008-04-07 //Jan-Erik

Code: [Select]
/* Fading away */

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

call SysCls
call rxFade 2, 23

do i = 1 to 100
    call SysSleep 1
    call rxFade
end
Return 0

Code: [Select]
rxFade: procedure expose count_ width_ pos_y_
    if datatype( count_, "W" ) = 0 then count_ = 1
   
    if datatype( width_, "W" ) = 0 then
        if datatype( ARG(2), "W" ) = 0 then width_ = ARG(2)
        else width_ = 20
   
    if datatype( pos_y_, "W" ) = 0 then
        if datatype( ARG(1), "W" ) = 0 then pos_y_ = 0
        else pos_y_ = ARG(1)
   
    do i = min( 4, count_ ) to 0 by -1
        pos_x = ( count_ - i ) // width_
        if ( count_ - i ) % width_ // 2 = 1 then
            pos_x = width_ - pos_x
        parse value SysCurPos( pos_y_, pos_x ) with prev_row prev_col
        select
            when i = 4 then
                say ' '
            when i = 3 then
                say '░'
            when i = 2 then
                say '▒'
            when i = 1 then
                say '▓'
            otherwise
            say '█'
        end
        call SysCurPos prev_row, prev_col
    end
    count_ = count_ + 1
Return 0

319
Rexx / Rotating statusindicator
« on: 2008.04.04, 11:16:06 »
Marked as: Easy
Hello,

The code below describe a way to show and update a message every second indicating that the script is busy processing infromation. It changes the character "\", "|", "/" or "-" in front of the message to give the impression of a rotating motion.

Code: [Select]
start_time = TIME( 'R' )
...
curr_time = TIME( 'E' )
...
do while ...
    if curr_time + 1 < TIME( 'E' ) then
    do
        call rxWorking 'Processing... Please Wait'
        curr_time = TIME( 'E' )
    end
end
Code: [Select]
rxWorking: Procedure Expose cfg.
    if datatype( ARG(1), 'W' ) then
        parse value SysCurPos( ARG(1), 0 ) with prev_row prev_col
    SELECT
        WHEN cfg.counter = 1 THEN
            say left( '/ '||ARG(2), 80 )
        WHEN cfg.counter = 2  THEN
            say left( '- '||ARG(2), 80 )
        WHEN cfg.counter = 3 THEN
            say left( '\ '||ARG(2), 80 )
        OTHERWISE
        cfg.counter = 0
        say left( '| '||ARG(2), 80 )
    END
    cfg.counter = cfg.counter + 1
    if datatype( ARG(1), 'W' ) then
        call SysCurPos prev_row, prev_col
Return 0

320
Rexx / Re: ReSize and convert Images
« on: 2008.04.04, 08:13:25 »
Hello,

I've read all your discussions about gbmrx (thread Determine Image Size) and to me it looks like having a special dll for operations that could be directly coded in REXX is overkill  ::). It took me about half an hour to hack a function in REXX that does almost the same as your dll. The benefit of having it coded in REXX is that no additional dll is required.

Quite true and your code is quite complete too, very good.
One may want to add the function "GBM_PaletteDataTo24bpp" so it can operate on many more images and filters?

You need the rexx dll ( gbmrx.dll ) on top of gbm.dll just as rxImgSze.dll would then be the replacement for lazy people. ;)

If the resize function is intended only for a one step operation on the same images, it might be OK. But if you plan to run another operation on the resized images afterwards it might be a rather bad idea. Not all output formats are lossless. If you scale a bitmap and write it as JPG image, then read it again for another operation and save it as JPG a second time, the image quality will suffer because JPG is a lossy format, also if quality is set to 100% when saving it!

I have attached the pure REXX version. Maybe some special features are missing but hey, it is REXX, so just add them.

eville
Yes, the greatness of GBM is that it can provide both flexiblity (trough usage of a rexx function) and full freedom to allow sophisticated operations over and over again, something that should be very useful to many users.

The example you provided should be included in the GBM package as it's easy to use and allow flexible operation as well as it's written as a function that make it ideal to cut and paste for other people.

Please do add it!!!
//Jan-Erik

321
Rexx / ReSize and convert Images
« on: 2008.04.03, 23:11:31 »
Markes as: Easy
Hello,

here's the updated rexx dll to resize and convert Images.

  • Ensure that you have gbm.dll installed on your computer
    Unpack to a folder
    Add another folder into it and call it "images"
    Open the script and modify it (Important) or you'll end up with one of the images that is 90Mb in size.
    add two images to the folder "images" you just created, one gif and one bmp, both should have the name example before the dot and the extension.
    Run the script and see the result(s)

If you don't modify the script you'll notice that gbm will use all your RAM to do the scaling for the fifth image... it takes a while but should give you the image at the end.

This dll has been written and compiled by me using OpenWatcom 1.7, adjusted to the latest changes Heiko put into gbm and gbmsize.
The dll is based entierly on the code for gbmsize with the exception of a function for conversion to 24 bit pixel depth that has been taken from his rexx dll.
I've also provided string handling through a class to ease comparisons and conversions back and forth.

322
Rexx / Re: Retrieve information with rexxsql
« on: 2008.04.03, 14:44:08 »

Good to know because I've read it several times and never dared to try that one!  :)

//Jan-Erik

323
Rexx / Re: Determine Image Size ( Bitmap and GIF )
« on: 2008.04.03, 14:30:59 »
...agree. However, I feel it's still better than nothing. At some point (and with limited skills and/or time) you just want to get something done and then it's OK. ;-)
Yes, I totally agree, but when it's a pain to use then you begin to investigate how things can be done differently as I did. Reusing already written code by Heiko (for gbmsize.exe) was very easy to do, let's see if more people can do that (copy & paste basically)!

WAIT!
Did I understand correctly that you are able to create DLLs in C which are callable from rexx?
If so - har-har, can I post my wishlist here? :-)
Duh!!! ::)
Hahaha, shouldn't have told you about that one I guess.

Go on, post all your wishes, maybe Santa will hear you! (If no one else can help out before that)

Ehh... I don't know what you exactly mean by "accept the position"... Kim wrote me some time ago that I'll be given moderator status, and I said "thanks". As from the options in the forum, I seem to have moderator status now... if that is what you ask. ;-)
Still, it doesn't mean that I might be the right person for the job. What I can think of is some kind of CVS with web interface. That would enable multiple people to submit and work with snippets simultaneously (can't tell about available search functionality however).
Then again, "CVS at OS2World" this is the same topic as in http://www.os2world.com/component/option,com_smf/Itemid,63/topic,830.0/ where Christian admitted that it might be better to have such things at Netlabs. On the other hand - why not have a choice and put "live projects" sources to Netlabs CVS while "code snippets" are stored here?
It's settled then, WarpCafe will be the moderator for the rexx area! The OS2WF board discussed your suggestions and my personal opinion is that the additions mentioned above should be added asap. ( except the part about Netlabs... to much "techno geek"/"assembler freak" about it ).

Who told you that?? :-) Rumors, rumors... I will ask that guy when I next meet him. Sometimes he's just too busy with other things but I agree that some code samples might be useful for others too.

Regards,
Thomas
You can ask him that the next time you look in the mirror!  ;D

Thank you WarpCafe for the excellent arrangement at Warpstock in Köln 2006.
//Jan-Erik

324
Rexx / Re: Progressbar
« on: 2008.04.03, 10:52:41 »
Fixed :-)

Thanks

325
Rexx / Installation script for Apache, PHP5 and PHPPgAdmin
« on: 2008.04.02, 13:08:16 »
Marked as: Normal
Hello,

Here's my script to automatically configure PHP5, Apache and PHPPGAdmin so you can use you web browser to add tables and configure Postgres databases.

The installation script for Postgres should be used first, but I may have anticipated that someone would try the opposite.

Download PHPPgAdmin ( http://phppgadmin.sourceforge.net/, the Beta is OK to use as well ), PHP5 ( http://www.smedley.info/os2ports/index.php?page=php-5 ) and Apache ( http://www.smedley.info/os2ports/index.php?page=apache2 ) and unzip them to some folders.

You can then run the following script that will create/update a folder on you desktop with some icons.
Note that you may want to change the entry "Europe/Berlin" in the code below if you live in another time zone. Also ensure that you start Postgres (see other post on how to install it) before you run Apache/PHP.

You can then point your web browser to phppgadmin by specifying the local ip address... http://127.0.0.1 and log on with the name you specified during creation of the database (see other post).

The user PHPPgAdmin interface is available in many languages and is quite easy to use. You can export and import data there as well.

Code: [Select]
/* REXX Script to configure PHP5 and PhpPGAdmin */
Call Time 'R'
CALL RxFuncAdd 'SysCls', 'RexxUtil', 'SysCls'
call SysCls
say ''
call Meter 0, 1

CALL RxFuncAdd 'SysDriveMap', 'RexxUtil', 'SysDriveMap'
drives = SysDriveMap();
drives.0 = WORDS( drives );

CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
DO i = 1 TO drives.0
  say 'Searching drive '||subword( drives, i, 1 )||' for PHP...one moment please.'
  call Meter i / drives.0, drives.0 * 3
  call SysFileTree subword( drives, i, 1 )||'\*php.exe', 'php_path', 'SFO'
  stpath = strip( filespec( 'D', php_path.1 )||filespec( 'P', php_path.1 ), 'T', '\' )
  if php_path.0 > 0 then
    leave i
END
if php_path.0 = 0 then do
  say "Couldn't find PHP..."
  Return -1
end

DO i = 1 TO drives.0
  say 'Searching drive '||subword( drives, i, 1 )||' for phpPGAdmin...one moment please.'
  call Meter i / drives.0 + drives.0, drives.0 * 3
  call SysFileTree subword( drives, i, 1 )||'\*sqledit.php', 'phppgadmin_path', 'SFO'
  phpgconf = phppgadmin_path.1
  a_len = LASTPOS( '\', phpgconf ) - 1
  if a_len < 1 then iterate i
  phppgadmin_path = LEFT( phpgconf, a_len )
  if phppgadmin_path.0 > 0 then
    leave i
END
if phppgadmin_path.0 = 0 then do
  say "Couldn't find phpPGAdmin..."
  Return -2
end

DO i = 1 TO drives.0
  say 'Searching drive '||subword( drives, i, 1 )||' for Apache...one moment please.'
  call Meter i / drives.0 + 2 * drives.0, drives.0 * 3
  call SysFileTree subword( drives, i, 1 )||'\*httpd.conf', 'apache_path', 'SFO'
  aconf = apache_path.1
  a_len = LENGTH( aconf ) - 16
  if a_len < 1 then iterate i
  apache_path = LEFT( aconf, a_len )
  if apache_path.0 > 0 then
    leave i
END
if apache_path.0 = 0 then do
  say "Couldn't find Apache..."
  Return -3
end

etcpath = value( 'etc', , 'OS2ENVIRONMENT')
filedef = stpath||'\php.ini-recommended'
fileconf = etcpath||'\php.ini'


crlf= '0d0a'x
lf = '0a'x
replace_from.1 = 'memory_limit = 8M'
replace_tgt.1 = 'memory_limit = 32M      ; Maximum amount of memory a script may consume (8MB)'

replace_from.2 = 'extension_dir = "./"'
replace_tgt.2 = 'extension_dir = "'||stpath||'\modules"'

replace_from.3 = 'upload_max_filesize = 2M'
replace_tgt.3 = 'upload_max_filesize = 10M'

replace_from.4 = ';extension=php_xsl.dll'
replace_tgt.4 = ';extension=php_xsl.dll'||lf,
'extension=bz2.dll'||lf,
'extension=curl.dll'||lf,
'extension=dbase.dll'||lf,
'extension=exif.dll'||lf,
'extension=filepro.dll'||lf,
'extension=gd.dll'||lf,
'extension=gettext.dll'||lf,
'extension=mbstring.dll'||lf,
'extension=mysql.dll'||lf,
'extension=mysqli.dll'||lf,
'extension=openssl.dll'||lf,
'extension=pdo_mysq.dll'||lf,
'extension=pdo_sqli.dll'||lf,
'extension=pgsql.dll'||lf,
'extension=sqlite.dll00'

replace_from.5 = 'date.timezone ='
replace_tgt.5 = 'date.timezone = Europe/Berlin' /* can you determine this at runtime please?! */

replace.0 = 5

apache_startup = apache_path||'\startup.cmd'
apache_startup.conf = '@echo off'||lf,
'SET LIBPATHSTRICT=T'||lf,
'SET BEGINLIBPATH='||strip( apache_path, 'T', '\' )||'\bin;'||strip( apache_path, 'T', '\' )||'\modules;'||lf,
strip( filespec( 'D', apache_path ), 'T', '\' )||lf,
'cd '||strip( filespec( 'P', apache_path )||filespec( 'N', apache_path ), 'T', '\' )||lf,
'bin\httpd -d . 2>&1'

apache_shutdown = apache_path||'\shutdown.cmd'
apache_shutdown.conf = '/* Rexx script to shut down Apache */'||lf,
'pid = linein("logs\httpd.pid")'||lf||"'kill.exe -TERM '||pid"

say ""
say "PHP:"
say "Reading from:   "||filedef
say "Configures:     "||fileconf
say ""
say "Apache:"
say "Reading from:   "||aconf||'.sample'
say "Configures:     "||aconf
say "Startup Apache: "||apache_startup
say "Shutdown Apache:"||apache_shutdown

apache_path = translate( apache_path, '/', '\' )

CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
CALL RxFuncAdd 'SysCurPos', 'RexxUtil', 'SysCurPos'

/* update php.ini */
f_size.0 = Stream( filedef, 'C', 'QUERY SIZE' ) + Stream( aconf, 'C', 'QUERY SIZE' )
f_size = 0
outlines = ""
i = 1
do while( lines( filedef ) )
  rec = linein( filedef )
  f_size = f_size + length( rec )
  if time( 'E' ) > 0.5 then
    call Meter f_size, f_size.0

  /* substitute data */
  if POS( replace_from.i, rec ) > 0 then do
    rec = replace_tgt.i
    i = i + 1
  end
  outlines = outlines||rec||crlf
end
rc = Stream( filedef, 'C', 'Close' )
rc = SysFileDelete( fileconf )
call lineout fileconf,, 1
call lineout fileconf, outlines
rc = Stream( fileconf, 'C', 'Close')


replace_from.1 = 'ServerRoot "/apache2"'
replace_tgt.1 = 'ServerRoot "'||filespec( 'P', apache_path )||filespec( 'N', apache_path )||'"'

replace_from.2 = '# LoadModule vhost_alias_module modules/vhost_al.dll'
replace_tgt.2 = '# LoadModule vhost_alias_module modules/vhost_al.dll'||lf,
'Loadmodule php5_module modules/modphp5.dll'

replace_from.3 = 'DocumentRoot "/apache2/htdocs"'
replace_tgt.3 = 'DocumentRoot "'||phppgadmin_path||'"'

replace_from.4 = '<Directory "/apache2/htdocs">'
replace_tgt.4 = '<Directory "'||phppgadmin_path||'">'

replace_from.5 = '    DirectoryIndex index.html'
replace_tgt.5 = '    DirectoryIndex index.html index.htm index.html.var index.php'

replace_from.6 = '    ScriptAlias /cgi-bin/ "/apache2/cgi-bin/"'
replace_tgt.6 = '   ScriptAlias /cgi-bin/ "'||filespec( 'P', apache.path )||filespec( 'N', apache_path )||'/cgi-bin/"'

replace_from.7 = '<Directory "/apache2/cgi-bin">'
replace_tgt.7 = '<Directory "'||filespec( 'P', apache.path )||filespec( 'N', apache_path )||'/cgi-bin/">'

replace_from.8 = '#AddOutputFilter INCLUDES .shtml'
replace_tgt.8 = '   #AddOutputFilter INCLUDES .shtml'||lf||lf,
'   # For PHP Scripts'||crlf,
'   AddType application/x-httpd-php .php'||lf,
'   AddType application/x-httpd-php-source .sphp'||lf||lf

replace.0 = 8

rc = SysFileDelete( apache_startup )
call lineout apache_startup,, 1
call lineout apache_startup, apache_startup.conf
rc = Stream( apache_startup, 'C', 'Close')

rc = SysFileDelete( apache_shutdown )
call lineout apache_shutdown,, 1
call lineout apache_shutdown, apache_shutdown.conf
rc = Stream( apache_shutdown, 'C', 'Close')


outlines = ""
i = 1
do while( lines( aconf||'.sample' ) )
  rec = linein( aconf||'.sample' )
  f_size = f_size + length( rec )
  if time( 'E' ) > 0.5 then
    call Meter f_size, f_size.0
  /* substitute data */
  if POS( replace_from.i, rec ) > 0 then do
    rec = replace_tgt.i
    i = i + 1
  end
  outlines = outlines||rec||crlf
end
call Meter f_size.0, f_size.0
rc = Stream( aconf||'.sample', 'C', 'Close' )
rc = SysFileDelete( aconf )
call lineout aconf,, 1
call lineout aconf, outlines
rc = Stream( aconf, 'C', 'Close')

If  SysCreateObject( 'WPFolder', 'Postgres 8.x', '<WP_DESKTOP>', 'OBJECTID=<PGSQL8>', 'u' ) Then
  If SysCreateObject( 'WPProgram', 'Start Apache', '<PGSQL8>', 'EXENAME='||apache_startup, 'u' ) Then
    If SysCreateObject( 'WPProgram', 'Stop Apache', '<PGSQL8>', 'EXENAME='||apache_shutdown, 'u' ) Then
      say 'Installation done!'
Return 0

Meter:
  parse value SysCurPos( 18, 0 ) with row col
  SAY left( COPIES( '█', ( ARG(1) * 80 ) % ARG(2) ), 80, '░' )
  call SysCurPos row, col
RETURN;

326
Rexx / Install Postgres 8.1.14
« on: 2008.04.02, 12:45:09 »
Marked as: Normal
Hello,

Get a copy of Postgres 8.1.14 from Paul Smedley's site ( http://www.smedley.info/os2ports/index.php?page=postgresql ) and unzip it to a folder on you computer.

Save the code below to a file called Install_Postgres.cmd and type the following in the command prompt ( adjust to your liking ):

Install_Postgres UTF8 John TestDB D:\db

where
UTF8 = Use the UTF 8 encoding inside the batabase
John = The adminitrator user over the database
TestDB = Name of the database
D:\db = drive and path where to place the database files

The default password is postgres if I remember correctly

Code: [Select]
/* Installation of PostGres Database 8.1.14 */

if arg() = 0 then Return Usage()

parse source . . path
pg_path = ''
path = filespec( 'D', path )||filespec( 'P', path )

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

drives = SysDriveMap()
retval = ''
i = 1
do while length( retval ) = 0 & i <= words( drives )
  say 'Searching drive '||subword( drives, i, 1 )||' for Postgres...one moment please.'
  if SysFileTree( subword( drives, i, 1 )||'\*initdb.exe', 'pg_path', 'SFO' ) <> 0 then Return -1
  do j = 1 to pg_path.0
    if stream( filespec( 'D', pg_path.j )||filespec( 'P', pg_path.j )||'pg_ctl.exe' ) <> '' then do
      pg_path = filespec( 'D', pg_path.j )||filespec( 'P', pg_path.j )
      i = words( drives )
    end
  end
  i = i + 1
end
if pg_path = '' then Return -2
pg_lib_path = filespec( 'D', pg_path )||filespec( 'P', strip( pg_path, 'T', '\' ) )||'bin'
say 'Initializing database...one moment please.'
call value 'PATH', pg_lib_path||';.;'||value( 'PATH',, 'OS2ENVIRONMENT' ), 'OS2ENVIRONMENT'
parse value ARG(1) with encoding userName dbName path_to_create
db = strip( translate( path_to_create, '/', '\' ), 'T', '/' )||'/'||dbName
if Directory( path_to_create||'\'||dbName ) = '' then
  if SysMkDir( path_to_create||'\'||dbName ) = 3 then
    if SysMkDir( path_to_create ) = 0 then
      call SysMkDir path_to_create||'\'||dbName
    else do
      say "Couldn't create database in "||path_to_create||'\'||dbName
      Return -3
    end
call directory strip( pg_path, 'T', '\' )
'@'||pg_path||'initdb --encoding='||encoding||' -D '||db
if rc = 0 then do
   '@'||pg_path||'pg_ctl -D '||db||' -l logfile start'
   if rc = 0 then do
      Call SysSleep 5
      say 'Adding the user '||userName||'...'
      '@'||pg_path||'createuser -q -U postgres -s -r -l '||userName
      if rc = 0 then do
         say 'Creating the database '||dbName||'...'
         '@'||pg_path||'createdb -q -O '||userName||' -U '||userName||' '||dbName
         if rc = 0 then do
            say 'Creating Postgres Icons...'
            If  SysCreateObject( 'WPFolder', 'PostGres 8.x', '<WP_DESKTOP>', 'OBJECTID=<PGSQL8>', 'u' ) Then
               If SysCreateObject( 'WPProgram', 'Start Postgres ('||dbName||')', '<PGSQL8>', 'EXENAME='||pg_path||'PG_CTL.EXE;PARAMETERS=-D '||path_to_create||' start;', 'u' ) Then
                            If SysCreateObject( 'WPProgram', 'Stop Postgres ('||dbName||')', '<PGSQL8>', 'EXENAME='||pg_path||'PG_CTL.EXE;PARAMETERS=-D '||path_to_create||' stop;', 'u' ) Then
                  say 'Installation done!'
         end
         else say 'Unable to create database in the directory '||path_to_create||'\'||dbName
      end
      else say 'Unable to grant '||userName||' rights.'
   end
   else say 'The server failed to start...'
end
else say "Couldn't initialize database"
Return 0

Usage:
say 'Usage: Install_Postgres encoding userName dbName drive:\path_to_create'
say ''
say 'where encoding can be e.g. BIG5, EUC_CN, EUC_JP, EUC_KR, EUC_TW, GB18030, GBK,'
say '                           ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8,'
say '                           JOHAB, KOI8, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5,'
say '                           LATIN6, LATIN7, LATIN8, LATIN9, LATIN10, SJIS,'
say '                           SQL_ASCII, UHC, UTF8, WIN866, WIN874, WIN1250,'
say '                           WIN1251, WIN1252, WIN1256 or WIN1258'
say ''
say 'where userName should be your name that you want to use'
say ''
say 'where dbName should be the name to give the DataBase'
say ''
say 'where the last parameter point to the physical drive and directory to place the database.'
say ''
say 'Example: Install_Postgres UTF8 John MyTestDB D:\db'
Return 0

327
Rexx / Retrieve information with rexxsql
« on: 2008.04.02, 11:54:55 »
Marked as: Normal
Hello,

Here's a small example on how to query a database and retrieve information.

When you've managed to install and configure the database and ODBC drivers, then you'll find this part easy.  ;)

There are a few things you need to do to use a database:
Connect to the database (SQLConnect)
if it was sucessful (= 0),
    create the SQL statement you want to use and send the SQL statement to the database engine ( INSERT, UPDATE, SELECT, UNOAD, READ etc. )
    if it was sucessful (= 0),
        close the connection /* If we don't want to use it in the near future */
        loop through the values returned

Code: [Select]
/* Params: Table_name, Password */
rxGetPKey4Table: procedure
    search_4_table = ARG(1) /* Name of table to search for Primary keys within */
    pwd = ARG(2) /* Password for this conenction to the database */
    if SQLConnect( "s1", "dba", pwd, "TESTDB" ) = 0 then
    do
        sqlstr = "SELECT column_name FROM sys.syscolumn KEY INNER JOIN sys.systable WHERE table_name = '"||search_4_table||"' AND pkey = 'Y'"
        if SQLCOmmand( "s1", sqlstr ) = 0 then
        do
            call SQLDisconnect /* We close the connection as there's nothing more we want to retrieve */
            say "Table "||search_4_table
            do j = 1 to s1.column_name.0
                say "Column name for primry key is "||s1.column_name.j
            end
        end
    end
Return rc /* rc = automatic return value from functions to indicate if something is wrong or not */

Note 1: You can retrieve the information by using the first parameter to SQLCommand ( s1 in the example ) paired with column_name form "SELECT column_name FROM..." followed by the order number, that is s1.column_name.0 to get the number of found entries, s1.column_name.1, s1.column_name.2 etc. to get the actual data.

Note 2: You can open several connections, even to other databases at the same time, by specifying different connection placeholders ( First parameter to SQLConnect and SQLCommand ).

328
Rexx / Re: Determine Image Size ( Bitmap and GIF )
« on: 2008.04.01, 16:58:20 »
Hello Thomas,

Nope, but since you brought it up... ;D
There's a rexx dll for it that can do most everything and it's very good. Visit Heiko Nitches homepage http://heikon.home.tlink.de/.

One drawback with the rexx version though is that it's a bit picky about what params you have to enter and you have to provide everythig even though you may only be interested in a fraction of the functions.

I used the included source code of the GBMScale executable to create a dll that may be easier for some to use as it can do most of the fancy stuff using only one function and it doesn't complain if you don't want to provide/add/use all params.

Regarding searchable snippets... well I hope you (Thomas) have accepted the position as the Moderator for this section? Be my guest/moderator :P and arrange searchable code snippets, I'll try to provide a couple every day (If I can come up with some).

Nope, not only command line... as this is in preparation for some heavier stuff, let's flood the market with knowledge! B.t.w. a little bird wispered in my ear that a "small" person has got some projects that he'd like to show as well. Let's hope he does!!!

//Jan-Erik

Hi jep,

wondering about the "code you found" that was too bulky... are you talking about gbmrx?
If not, check out gbmrx (from the gbm package). I found it to be very comfortable and reliable... OK, one has to use more dlls, but it's worth it I think and provides lots of features.

P.S.: Thanks for all your code snippets... I really like that idea.
How about putting this together into a -let's say- searchable snippets / knowledge base? :-)
One more question while we#re at it: Do we focus on "pure REXX" here (VIO rexx only so to say) or do we include the different GUI flavors (DrDialog, vx-rexx, etc.) too?

Regards,
Thomas

329
Rexx / Progressbar
« on: 2008.04.01, 09:24:14 »
Marked as: Easy
Hello,

here's an example on how to create a function that display a progressbar.

call rxProgress 23, 214, 2 /* row 0 is the topmost row */

Code: [Select]
/* part, of_total, display_on_row */
rxProgress: Procedure
    if datatype( ARG(1), 'N' ) & datatype( ARG(2), 'N' ) then
    do
        if datatype( ARG(3), 'W' ) then
            parse value SysCurPos( ARG(3), 0 ) with prev_row prev_col
    progress = 76 * ARG(1) % ARG(2)
    say left( copies( '█', progress )||copies( '░', 76 - progress ), 76 )||right( ( ( 100 * ARG(1) ) % ARG(2) )||'%', 4 )
        if datatype( ARG(3), 'W' ) then
            call SysCurPos prev_row, prev_col
    end
Return 0

330
Rexx / Determine Image Size ( Bitmap and GIF )
« on: 2008.04.01, 08:39:47 »
Marked as: Easy
Hello,

found rexx code on the net how to determine the size of a bitmap image , but it was to bulky for me so I rewrote it.
Searched some more and found information in wikipedia http://en.wikipedia.org/wiki/BMP_file_format   
that contain alot of useful data about the bitmap format. There's a table that describe each part of the image format that tell you what to look for http://en.wikipedia.org/wiki/BMP_file_format#Bitmap_information_.28DIB_header.29 ( see table "Purpose" ).

That should be useful for other formats as well, so I used that to test gif images too http://en.wikipedia.org/wiki/Graphics_Interchange_Format.

Try yourself and write versions for other image formats!
Do also add tests to determine the real image format http://en.wikipedia.org/wiki/BMP_file_format#BMP_file_header first!
( Some people just rename the extension and think that's the difference between them ).



Code: [Select]
/* Determine size of images */

say rxGIFSize( 'Background.gif' )
say rxBMPSize( 'BlueBar.bmp' )
Return 0

rxGIFSize: PROCEDURE
    d = c2d( reverse( charin( ARG(1), 7, 2 ) ) )||';'||c2d( reverse( charin( ARG(1),, 2 ) ) ) /* In case bytes > 1 */
Return d

rxBMPSize: PROCEDURE
    d = c2d( reverse( charin( ARG(1), 19, 2 ) ) )||';'||c2d( reverse( charin( ARG(1), 23, 2 ) ) ) /* In case bytes > 1 */
Return d

Pages: 1 ... 20 21 [22] 23 24 ... 26