× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Thu, 2005-10-20 at 16:40 -0500, albartell wrote:
>  >Hmm, it seems there is a bug. 
> Yep you are right.  Haven't had time to finesse the code yet, but thanks for
> the reminder. I actually had code that did this in the past (made sure the
> value I was search for didn't get stuck between two reads) but I can't seem
> to find it now.  So if someone has it and wants to share that would be
> great, otherwise I will just write it.
> 
> >I haven't had to build or locate a very speedy search and replace, but I
> would investigate pulling the entire file into memory (assuming it will
> always fit inside 16Mb), then write it out, translating by brute force. 
> 
> Hadn't thought of this!  So are you thinking I should read it into something
> that can hold it (i.e. User space) or do some pointer arithmetic on a string
> that has a base pointer?  I am thinking it would probably be faster to do
> the pointer arithmetic.
Just a pointer.  If you can get the file size, then you can %alloc the
whole buffer at once.  Otherwise, you can use %realloc to extend it as
needed.  Then read from the ifs file right to a pointer that is pointing
to the next open space in the block, or read the whole durned thing in
in one fell swoop. I can't recall the maximum size for a read().
Surely, it will take a 10i?  Otherwise, read it in chunks.

Now brute force: Loop over every character.  If it's not one of the
starting characters of your search, write it to the IFS.  If it is, now
check to see if it matches your search targets.  If so, translate it and
write the translated bits to the IFS, else write the untranslated
characters.  Go until you have no more characters.


> >You might be able to whip up a nice search and replace function using
> memcpy and memcmp.
> How does memcmp fit into the mix for a solution? Are you thinking it would
> work similar to a %scan? I haven't use this before so I am not challenging
> you, I just don't know how you are applying it to the situation.
Yes, they work similarly to %scan, but memcmp and memcmp work with
pointers.  So, you could use memcmp to find the next chunk of text that
has to change.  Anything that doesn't have to change can be written
directly to the output file.  Then, write the change.  Skip over the bit
that needed changing, and start memcmp'ing looking for the next change.
If you run out of changes, but still have data to write, then write the
last block(s) out to the output file.

I don't know if this is going to be a great idea or not.  I suppose you
have to write it and then benchmark it to find out.  I'd probably try
the RPG route first before I resort to C or MI.

Lastly, I think there is a regular expression implementation on the
iSeries.  I've not used it, but in perl, I would generally do something
like:

$string =~ /\&quot\;/\"/g;      // replace      
$string =~ /\&lt\;/\</g;        // replace 
$string =~ /\&gt\;/\>/g;        // replace 
  .
  .
  .

And the regular expression parser would do all the changing for me.  I
wonder if it would be suitable?


> 
> Aaron Bartell
> 


Regards,
Rich


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.