× 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.




I'm trying create a .RTF file via a stream file. I'm running into
problems that I suspect are caused by the codepage I'm using. For
starters I opened the stream file with a codepage of 819 and populated
it. When I opened the .RTF file all of RTF formatting syntax showed up.
Obviously that is because all of the data was translated as text. I then
tried codepages 427 and 850, but that didn't work either.

I assume you mean 437? (I'm not familiar with 427). I tried creating an RTF file using codepage 437, 819, 850 and 1252. All worked for me.

I don't think codepage is your problem, but I suspect the CCSID 1252 is correct for an RTF file, since it's a Windows text file, and 1252 is the appropriate CCSID for Windows in the USA.


Can anyone tell me if all I need to do is find the correct codepage, or
is there something else I should be looking into? I suppose it's also
possible that I'm not opening the stream file correctly. I'll post the
code that I have.

I don't see anything wrong with the code that you posted, aside from the fact that you're setting the permissions to "write only" which would prevent anyone from reading the file!

You say that the problem is that all of the formatting syntax shows up? Does it show up with the wrong characters? Or are the formatting characters the correct ones? If they're the correct ones, it's definitely not a CCSID/codepage issue.

What are you viewing the file with? Are you viewing it with something that understands the format of an RTF document? If not, you'll see the RTF codes.

I tested mine with both Wordpad and Microsoft Word 2000. Both worked fine.

Here's the code I was using for my tests:

     H DFTACTGRP(*NO)

      /copy IFSIO_H

     D CRLF            c                   x'0d25'
     D stmFile         s            500A   varying
     D fd              s             10I 0
     D data            s            500A   varying

      /free
        *inlr = *on;

        // -----------------------------------
        //   Create new file with CCSID 1252
        //  (tried using 437, 819, and 850 as well
        //   also tried using O_CODEPAGE instead of
        //   O_CCSID... all of them worked for me.)
        // -----------------------------------
        stmFile = '/home/klemscot/test.rtf';

        unlink( stmFile );

        callp close( open( stmFile
                         : O_WRONLY + O_TRUNC + O_CREAT + O_CCSID
                         : S_IWUSR + S_IRUSR
                         : 1252 )
                   );

        // -----------------------------------
        //  Open file in text mode (to get it
        //   to do translations)
        // -----------------------------------

        fd = open( stmFile : O_WRONLY + O_TEXTDATA );
        if fd < 0;
           // ... handle error....
           return;
        endif;

        // -----------------------------------
        //  sample RTF data taken from
        //     http://www.wikipedia.org
        // -----------------------------------
        data = '{\rtf' + CRLF
             + 'Hello!\par' + CRLF
             + 'This is some {\b bold} text.\par' + CRLF
             + '}';

        callp write(fd: %addr(data)+2: %len(data));

        // -----------------------------------
        //  close stream file.
        // -----------------------------------
        callp close(fd);

      /end-free


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.