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 ... 21 22 [23] 24 25 26
331
Rexx / Get first and last line in text file
« on: 2008.03.31, 11:45:22 »
Marked as: Advanced
Hello,

here's an example on how to parse the first row of a file and then the last one without looping through the whole file.

If the file is large, then it has to load the entire file into memory, but if you modify the code to read the file from a position (har coded as 1) such as "max( 1, f_size - 1000 )" then you'll be able to handle only the last few rows which is more efficient.

The first function is just a wrapper to allow named return variables but not expose the internal data of the actual function.

Code: [Select]
/* Params: FileName, get_data_from_first_row_into_variable, get_data_from_last_row_into_variable */
rxGetErrBoundaries:
    if ARG() < 1 then Return ''
   
    retval = rxGetErrBoundaries_( ARG(1), 'start_val', 'stop_val' )
   
    if length( ARG(2) ) > 0 then
        interpret ARG(2)||' = start_val'
    if length( ARG(3) ) > 0 then
        interpret ARG(3)||' = stop_val'
Return retval

rxGetErrBoundaries_: procedure expose start_val stop_val
    fileName = ARG(1)
    if FileExist( fileName ) then
    do
        f_size = stream( fileName, "c", "QUERY SIZE" )
        call stream fileName, "c", "OPEN READ"
       
        fileContents = charin( fileName, 1, f_size )
   
        call stream fileName, "c", "CLOSE"

        interpret "parse value fileContents with "||ARG(2)||"','."

        linePos = lastpos( d2c(13)||d2c(10), fileContents )
        if linePos > 0 then
        do
/* Modify to meet your need, this one get the value present before "," */
            interpret "parse var fileContents 1 fileContents +"||linePos||" input','."
            input = changestr( d2c(13), changestr( d2c(10), input, '' ), '' )
               
            if length( input ) > 0 then
            do
                interpret ARG(3)||' = input'
                Return input.i
            end
        end
    end
Return ''

332
Rexx / DataType
« on: 2008.03.31, 09:49:03 »
Marked as: Advanced
Hello,

here's my example on how to check if a value is a date, time or timestamp. It's not that very well tested yet so use with care.

Can you improve it? tell me what to do!

Note: It's possible to modify it to overload the builtin function DATATYPE, just check Rexx Tips & Tricks if you want to create your own datatype and test it.


Code: [Select]
datatypes: procedure
    if ARG() = 2 then
    do
        if length( strip( ARG(1) ) ) = 0 then
            if pos( 'EMPTY', translate( ARG(2) ) ) > 0 then Return 1
            else Return 0
        if pos( 'TIMESTAMP', translate( ARG(2) ) ) > 0 then
        do
            parse value ARG(1) with date_stamp' 'time_stamp','.
            if rxDateType( date_stamp, 'I', rxNot ) then
                if rxTimeType( time_stamp, 'L', rxNot ) then Return 1
        end
        else if pos( 'DATE', translate( ARG(2) ) ) > 0 then
        do
            if pos( 'E', translate( ARG(2) ) ) = 1 then
                if rxDateType( ARG(1), 'E', rxNotEuropeanDate ) then Return 1
            if pos( 'I', translate( ARG(2) ) ) = 1 then
                if rxDateType( ARG(1), 'I', rxNotISODate ) then Return 1
            if pos( 'N', translate( ARG(2) ) ) = 1 then
                if rxDateType( ARG(1), 'N', rxNotNormalDate ) then Return 1
            if pos( 'O', translate( ARG(2) ) ) = 1 then
                if rxDateType( ARG(1), 'O', rxNotOrderedDate ) then Return 1
            if pos( 'S', translate( ARG(2) ) ) = 1 then
                if rxDateType( ARG(1), 'S', rxNotStandardDate ) then Return 1
            if pos( 'U', translate( ARG(2) ) ) = 1 then
                if rxDateType( ARG(1), 'U', rxNot ) then Return 1
            Return datatypes( ARG(1), 'EDATE' )
        end
        else if pos( 'TIME', translate( ARG(2) ) ) > 0 then
        do
            if pos( 'C', translate( ARG(2) ) ) = 1 then
                if rxTimeType( ARG(1), 'E', rxNotCivilTime ) then Return 1
            if pos( 'L', translate( ARG(2) ) ) = 1 then
                if rxTimeType( ARG(1), 'L', rxNotLongTime ) then Return 1
            if pos( 'N', translate( ARG(2) ) ) = 1 then
                if rxTimeType( ARG(1), 'N', rxNot ) then Return 1
            Return datatypes( ARG(1), 'ETIME' )
        end
        else Return Datatype( ARG(1), ARG(2) )
        Return 0
    end
    else if datatypes( ARG(1), 'TIMESTAMP' ) then Return 'TIMESTAMP'
    else if datatypes( ARG(1), 'DATE' ) then Return 'DATE'
    else if datatypes( ARG(1), 'TIME' ) then Return 'TIME'
Return Datatype( ARG(1) )

rxDateType: procedure
    interpret 'SIGNAL ON SYNTAX NAME '||ARG(3)
    SIGNAL OFF NOVALUE
    SIGNAL OFF FAILURE
    SIGNAL OFF ERROR
    SIGNAL OFF NOTREADY
    if datatype( date( 'B', ARG(1), ARG(2) ), 'W' ) then Return 1
Return 0
   
rxTimeType: procedure
    interpret 'SIGNAL ON SYNTAX NAME '||ARG(3)
    SIGNAL OFF NOVALUE
    SIGNAL OFF FAILURE
    SIGNAL OFF ERROR
    SIGNAL OFF NOTREADY
    if datatype( time( 'S', ARG(1), ARG(2) ), 'W' ) then Return 1
Return 0

rxNotDateTime:
Return datatypes( ARG(1) )
   
rxNotEuropeanDate:
Return datatypes( ARG(1), 'IDATE' )
   
rxNotISODate:
Return datatypes( ARG(1), 'NDATE' )
   
rxNotNormalDate:
Return datatypes( ARG(1), 'ODATE' )

rxNotOrderedDate:
Return datatypes( ARG(1), 'SDATE' )
   
rxNotStandardDate:
Return datatypes( ARG(1), 'UDATE' )
   
rxNot:
Return 0
   
rxNotCivilTime:
Return datatypes( ARG(1), 'LTIME' )
   
rxNotLongTime:
Return datatypes( ARG(1), 'NTIME' )

333
Rexx / Re: Parse XML
« on: 2008.03.31, 09:30:37 »
Here is another question: Can the "REXX Tool" that you have created ((or a similarly created one) be used to extract embedded data in the context of "Spread Sheet" scenarios.? Also, to what extent have historical considerations been given to the fact that "REXX became part of the base operating system. It (having ) previously been included in the IBM OS/2 Extended Edition 1.2 only.

Re: http://www-306.ibm.com/software/awdtools/rexx/library/rexxos2.html

If you use OS/2 or eCs, then you've got rexx installed as it's integrated into the OS.

The rexx tool is just rexx code that solve a specific task. You don't compile the code, it's a text-file that instruct the interpreter to perform certain things. If you want higher performance decoding into binary data then you may want to use dll's that can do the job faster.

It should work on any OS as it doesn't rely on external functions (dll's) but may require that the interpreter can handle certain functions.


It's possible that it can help you out decoding spread sheet data, but what do you have in mind?

Rexx is a scripting language, you'd rather use C/C++ or some other traditional language and compile and use rexx on top. I'd rather think of it as the ease-of-use language to improve the every day chores in OS/2-eCS instead of VisualBasic/LotusScript that other use. REXX would certainly be a great choise to have as e.g. the scription language and functions (ERR, LEFT etc.) in some spread sheet application.


There are some obsticles you need to take into consideration if you want to handle files.
1) I haven't used rexx for OS/2 EE 1.2, so some features may not be there as in the Warp 3/4, eCS version that I usually write for.
2) Don't think that older spread sheets (1-2-3 and/or Excel files) got a form similar to xml, they're more like binary data only. So you need to know the binary sequence that precede the data you want to extract.
3) You need to know the format of the data to decode as I did (or found out on the net). ClipArt come as base64 (see other post) and someone had already written and included some code in Rexx Tips & Tricks that i modified.
4) ooxml may contain encryptions and require special software, but it's possible if you have inside knowledge to extract something there as well.

334
Rexx / Re: Parse XML
« on: 2008.03.30, 20:17:04 »
Hello,

the example doesn't handle ODF nor OOXML files, but you can probably use the code as a base to do something like that. Just unzip the ODF-file and parse "contents.xml" for example and you'll get the text in plain format.
Hmm, you may want to reverse the procedure as you may not know all the tag names in advance as I did.

The example does however handle images and files in another format, ClipArt files (plu.) contained in 1 file (extension mpf).

Just get rxClipArt from hobbes and the files from ... somewhere ... test the tool and you have a bunch of .wmf-files to add to OO.org 2.x Theme Gallery.

Note: You're not allowed to fetch mpf-files if you don't have a valid license for "the other" Office suite, but who ca...

//jep

335
Rexx / Decode base64
« on: 2008.03.30, 18:19:36 »
Marked as: Advanced
Hello,

It's possible to encode applications in base64 format so that they appear as characters. That feature make it possible to include the code in rexx and create a self extracting installers or just extract binary code from external files.

Example of  where it's used:
PMMail and other mail software use base64 to encode attached files
ClipArt packages
etc.

If you look in rexx Tips & Tricks you'll notice code that describe how to decode base64 encoded data, though I think it may contain some missing pieces that I've adjusted somewhat.

Here's an example you may want to try ( based on code from Rexx Tips & Tricks ).

Code: [Select]
DeCodeB64: procedure expose x_range. clp.
    input_data = translate( ARG(1), '0000'x, '0d0a'x )
    l64 = length( input_data )
    if l64 = 0 then
        Return -1 /* Nothing to extract */
    retval = x2b( c2x( translate( input_data, x_range.d_code, x_range.s_code ) ) )
    t64 = length( retval )
    drop f_data
    f_data = ''
    do while retval \= ''
        parse var retval +2 bin.0 +6 +2 bin.1 +6 +2 bin.2 +6 +2 bin.3 +6 +2 bin.4 +6 +2 bin.5 +6  +2 bin.6 +6 +2 bin.7 +6 +2 bin.8 +6 +2 bin.9 +6 +2 bin.10 +6 +2 bin.11 +6 retval
        f_data = f_data || bin.0 || bin.1 || bin.2 || bin.3 || bin.4 || bin.5 || bin.6 || bin.7 || bin.8 || bin.9 || bin.10 || bin.11
    end
    input_data = x2c( b2x( left( f_data, length( f_data ) % 8 * 8 ) ) )
Return input_data

336
Rexx / Parse XML
« on: 2008.03.30, 18:04:38 »
Marked as: Advanced
Hello,

I've created a tool in rexx to extract data embedded into a special kind of XML-files.
You can see the functions below that you can use as guides for further discussions
You can also give us examples of the xml parser .dll's for OS/2 and rexx that's available and where and how to use them in various situations.

Some tags in some implementations may look a bit different than the usual ones, the company I work for use empty tags at times that may look something like:
<option430 />
where the ending /> indicate that there's no end tag related to this one. ( compare to <option>bla bla bla</option> )
Please note that the code below doesn't handle such situations.


Code: [Select]
xml_dispose_tag: procedure
    retval = ARG(1)
    interpret 'parse value retval with ."<'||ARG(2)||'>"."</'||ARG(2)||'>"retval'
Return retval
   
xml_no_tag_parser: procedure
    retval = ARG(1)
    interpret 'parse value retval with ."<'||ARG(2)||' />"retval'
Return retval
   
xml_tags_parser: procedure
    retval = ARG(1)
    do i = 2 to ARG()
        interpret 'parse value retval with ."<'||ARG(i)||'>"retval"</'||ARG(i)||'>".'
    end
Return retval

xml_tag_parser: procedure
    retval = ARG(1)
    interpret 'parse value retval with ."<'||ARG(2)||'"jmf_1">"retval"</'||ARG(2)||'"jmf_2">".'
    if pos( translate( ARG(3) ), translate( jmf_1 ) ) = 0 & pos( translate( ARG(3) ), translate( jmf_2 ) ) = 0 then
        Return ''
Return retval

337
Applications / Re: Need New Database
« on: 2008.03.25, 10:43:23 »
Dennis,

Copy and paste the rexx code here and we'll have a look at it, we may figure something out.

You may also tell us what columns are there and if they're connected in some special way.

You're problably using dbf, format version 4.

db2 is the ibm database, big and bulky and not as easy as dbf-files DBExpert default to. :-)

//Jan-Erik

338
dnh cTorrent 221 still have problems though... but not related to large files >2Gb but rather many files in the package.

It'll complain that there aint enough space left to download the hundred of files in the package and then stop download "temporarly" forever :-(

wrote eros2 about it and also asked if he can create a media download center, that is:

SOM folder class for various downloaders as plugins (dll's instead of executables) such as
CTorrent
WGet
Limewire
Live Multimedia Streams ( MMS, MP3/Shoutcast )
etc.

( should also be available as rexx extensions as well )

something like the link below should illustrate, but of course with more colours and fields etc.
but you'll get the idea.
http://www.xn--lrka-loa.com/Progress.html

//Jan-Erik

339
General Discussion / Re: Sundial Systems
« on: 2008.03.06, 08:57:21 »
I've asked the same question to Dennsi in another thread...
He has been in contact with her, but the last mail has been unanswered so far as to what I know.

Hope that someone else can approach her and ask the right questions.

mvh / MfG / Wkr
//Jan-Erik

340
Applications / Re: Need New Database
« on: 2008.03.04, 09:41:47 »
Sad to hear that she didn't reply.

dbExpert and MyPHPAdmin + MySQL can't be compared though.

dbExpert can be used to design each database, produce a runnable GUI with forms for input and reports for output of data, printouts etc. while MyPHPAdmin is mearly an advanced database design tool.

The same goes if you use Postgres and PgPHPAdmin, though there's no official package at the moment. I consider Postgres (8.1.14) the more powerful alternative, but you need the gui components.
The problem you'll encounter with Postgres is that you'll have to assemble the installation yourself. I've got a self configuring script though, that'll do it automagically for you ;-)

You may want to learn and use development tools such as VX-REXX, WDSybil or GpfREXX etc. to get the gui input/output equvivalence to reports and forms and tie it to one of those database engines.

Note: Both database engines can import dbf-databases, either directly or as comma separated text. There's often 2 - 5 possible formats to choose from.

//Jan-Erik

341
Marketplace / Re: WANTED: VisPro/REXX and Watcom VX/REXX
« on: 2008.02.19, 14:29:16 »
Hmmm, I guess we need to approach Sybase the official way, anyone here that can begin to write a proposal that we can discuss before we send it to Sybase?
Ok, I've recieved the reply from Sybase...

MikeG, please do check you mailbox, we're getting closer as it seem...  ;D

mvh / MfG / Wkr
//Jan-Erik

342
Hardware / Re: Where can I download ps30822en.zip?
« on: 2008.02.13, 09:11:42 »
While you mention it...are there any replacement for ls30827en.zip anytime soon?
It doesn't really work as the radio buttons for paper orientation among other things can't be set.
I have to install ls30822en.zip to be able to use it with my Brother HL-1240 and HP 2550Ln.

//Jan-Erik


Yes, I know, HP 2550Ln work better with the PS driver.

343
Marketplace / Re: WANTED: VisPro/REXX and Watcom VX/REXX
« on: 2008.01.22, 10:16:31 »
Glad you noticed the subtle hint MikeG! ;D

Would be nice if FTE could work as the editor for a new version of VX-REXX.

Hmmm, I guess we need to approach Sybase the official way, anyone here that can begin to write a prposal that we can discuss before we send it to Sybase?

//Jan-Erik

344
Marketplace / Re: WANTED: VisPro/REXX and Watcom VX/REXX
« on: 2008.01.21, 10:27:43 »
HI,

would you (MikeG) refresh VX/REXX if they do?

I'd like to see a new version of VX/REXX though I've never used it, but got a hunch that it'll be a success, especially if we'd get NOM (Netlabs SOM) or IBM togheter with Netlabs would create versions of SOM for as many OSes as possible.

Am working for a company that use Sybase products SQL Anywhere... at least for a while longer.  :-\
Wonder if one could use that to pull some strings. People has mentioned that Sybase would open it up, but OpenWatcom cost them a bit more in terms of man hours than they had anticipated. ( Removing patented code etc. I guess )

//Jan-Erik

/* */
if MikeG.promise = UPDATE.VX_REXX then
do
   MikeG = jan-erik.bounty.donation
   end /* Notice the indented text from FTE  ;) */

345
Gimp 2.28 should be sufficient for many people, take a look at Alex Taylors homepage.
Even I could install it  ;D

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