Preserving the new-line while reading variable length record



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

Re: Preserving the new-line while reading variable length re

Postby dick scherrer » Tue Jul 24, 2012 7:58 am

Hello,

what would happen if you collect all the input lines in a huge buffer and then print all of them at once
You don't do that in z/OS. Your code needs to adapt to the new environment.

the guy who'd created the package, was converted, compiled and linked in z/OS without any problem
Possibly a different release of z/OS or some routines that are different between the system where it was developed and your system.

There are advantages and disadvantages for both posibilities which I would weigh.
If the existing code does not work and may not for quite a while, i again suggest the COBOL alternative. It should work the first time. . .

I'm not aware of an automated way to convert C to COBOL.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Preserving the new-line while reading variable length re

Postby zatlas1 » Tue Jul 24, 2012 8:40 am

Hi Dick
1. I know that I have to either adapt or rewrite... most probably rewrite.
2. I converted the thing with an automated process, from UNIX based code to z/OS tolerant code and my version compiled and linked, yet it does not work for obvious reasons. See #1 most probable conclusion above :)
3. Agree! I am now in the process of reading and understanding the ILC [Language Environment Writing Interlanguage Communication Applications] manual as related to COBOL/C relations.
4. Well, I will have to either do it by hand or write the automated conversion process, or, most probably, I will have to write the COBOL myself from scratch, oh joy :(
ZA
zatlas1
 
Posts: 61
Joined: Mon Mar 15, 2010 9:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Preserving the new-line while reading variable length re

Postby steve-myers » Tue Jul 24, 2012 3:26 pm

dick scherrer wrote:...
what would happen if you collect all the input lines in a huge buffer and then print all of them at once
You don't do that in z/OS. Your code needs to adapt to the new environment.
From the XL C/C++ Run-Time Library Reference chapter for the fputs function -
For a text file, truncation may occur if the record is too long. Truncation means that excess characters are discarded after the record is full, up to a control character that ends the line (\n). Characters after the \n start at the next record. For more information, see the section on "Truncation" in z/OS XL C/C++ Programming Guide. (my emphasis)
Dick and zatlas: I think what zatlas is describing is supposed to work - I think - as zatlas appears to be thinking it should work. I wrote the following little program -
#include <stdlib.h>
#include <stdio.h>

int main( int argn, char *dataset??( ??) )
 {
  char *astring = "Line 1\n"
                  "Line 2\n"
                  "Line 3\n";
  FILE *f;
  if ( argn < 2 )
   printf( "writevb file\n" );
  else
   if ( ( f = fopen( dataset??( 1 ??), "w" ) ) == NULL )
    printf( "I cannot open %s\n", dataset??( 1 ??) );
   else
    {
     fputs( astring, f );
     fclose( f );
    }
  return 0;
 }
The output dataset (which was defined with DCB=(RECFM=VB,LRECL=255,DSORG=PS)) contained 3 logical records when I ran it in batch. I also ran the load module in TSO with the output dataset directed to the terminal, and it produced 3 lines.

Dick: I'm inclined to agree this is not great programming style for z/OS, but the manual and direct experimentation seem to agree it should work as zatlas thinks it should.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Preserving the new-line while reading variable length re

Postby zatlas1 » Tue Jul 24, 2012 4:08 pm

Hi Steve
In the meantime, I ran a test in which I dumped the buffer and the newline character is NOT there, which means that it was removed while collecting the data into the buffer. I am inclined to give one more serious look at the logic of the existing program and try to understand its strange behavior in z/OS, in parallel to planning for the COBOL solution (that I will need anyway, to test the planned API). The problem is that this is a hefty, 5000 lines program with zillion macro calls.
ZA
zatlas1
 
Posts: 61
Joined: Mon Mar 15, 2010 9:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Preserving the new-line while reading variable length re

Postby zatlas1 » Tue Jul 24, 2012 11:31 pm

Hi all
While I am investing my efforts in converting the C program to COBOL and reducing all the unnecessary options, I have a request to all you, expert C programmers on z/OS:

Would any of you be willing to take a quick look (no run, no test, just a look) at the compiled program and suggest what might be causing my issue. I can produce a compile with or without expanded #include and other needed information. I really do not ask for you to do my work, just suggestions.

As a reminder for what the issue is:
The existing test program was written by the guy who'd created the original Open Source package and was compiled and tested on Unix, Linux and Windows. I conveted it, using some automated tool to be z/OS tolerant. It was converted, compiled and linked in z/OS without any visible problem. Once I try to run it I get strange results. For example, when I let it read from stdin (SYSIN) and write to stdout (SYSPRINT) I get the results only (correct or incorrect), most of them are in new lines as they should, but the image of the input is not printed. When I read an actual phisical file and output to an actual phisical file, the image of the input is printed as a one long line (wrapped around) but no result is printed. Since the program was converted almost verbatim, I assume that it's logic, which was correct in Linux, is still correct and what causes the problem is either some configuration option or conversion mistake.

Please contact me via private messaging

Thanks
ZA
zatlas1
 
Posts: 61
Joined: Mon Mar 15, 2010 9:19 am
Has thanked: 0 time
Been thanked: 0 time

Previous

Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post