[comp.lang.c] C I/O in VMS

EDSTROM%UNCAEDU.BITNET@wiscvm.wisc.EDU (06/02/87)

In message #<79@decvax.UUCP> Martin Minow <minow@decvax.uucp> replies to
article <7614@brl-adm.ARPA> from ADLER1%BRANDEIS.BITNET@wiscvm.wisc.EDU
regarding a problem with I/O in VMS C.

In general I agree with Marin Minow's reply about the quality of the
documentation. If anything it is too complete and requires time and
effort to track things down. On the other hand I also agree with ADLER1
that there is nothing describing the situation leading to his problem(s).
The manual is unambiguous about how to set different RMS attributes on
opening a file but they don't explain which attributes you need for a given
task or why. This can be easily discovered by an experienced VMS user
but is not immediately available to the beginner programer or person who
does not want to get into system-dependent programing.

ADLER1's description of the I/O problem does not sound complete. I have had
no problem with character I/O in VMS C. The only time I have any problems
is if I try to use the EDT editor on a file created with default C I/O
attributes. Then I get a warning from the editor that the file is not in
standard format. This is a warning only and the editor has no problem with
the text file. I no longer use EDT but the TPU editors instead. THese editors
don't even detect a situation needing a warning. I have never had a problem
the utility TYPE. Its so dumb it will happily type out an executable image.

The DEC-supplied editors create files with variable length records while
C creates LF-terminated records. The conversion is done implicitly by the
RMS interface and the attributes modifications suggested by Minow are not
needed. I am including a tested test program that does UNIX- and
standard-style I/O. There are no errors or warnings unless the output file
is edited by EDT and then only a single warning is issued.

_____________________ test.c ________________________________________
#include stdio
#include file

main()
{       std_alt('.', "..........", "test.in", "test.out_s");
                                /*      standard alternative    */
        unix_alt('.', "..........", "test.in", "test.out_u");
                                /*      unix alternative        */
}


std_alt (S_CHAR, REPLACE_STR, FILE_IN, FILE_OUT)
char    S_CHAR, *REPLACE_STR, *FILE_IN, *FILE_OUT;
{       FILE *i = fopen (FILE_IN, "r");
        FILE *o = fopen (FILE_OUT, "w");
        char    c;

        while ( (c = fgetc (i)) > NULL)
        {       if (c != S_CHAR)
                        fwrite (&c, 1, 1, o);
                        /* fprintf (o, "%c", c); */
                        /* fputc (c, o);  */
                else
                        fwrite (REPLACE_STR, 10, 1, o);
                        /* fprintf (o, "%s", REPLACE_STR); */
                        /* fputs (REPLACE_STR, o); */
        }
        fclose (o);
        fclose (i);
}

unix_alt (S_CHAR, REPLACE_STR, FILE_IN, FILE_OUT)
char    S_CHAR, *REPLACE_STR, *FILE_IN, *FILE_OUT;
{       FILE *i = fopen (FILE_IN, "r");
        FILE *o = fopen (FILE_OUT, "w");
        char    c;

        while (read (i, &c, 1) > 0)
        {       if (c == '.')
                        write (o, REPLACE_STR, 10);
                else
                        write (o, &c, 1);
        }
        close (i);
        close (o);
}
___________________________________

 +-- In the Real World ----------+--- Elsewhere ---------+
 |Dr. John P. Edstrom            |EDSTROM@UNCAEDU Bitnet |
 |Div. Medical Physiology        |7641,21         CIS    |
 |3330 Hospital Drive NW         |JPEDstrom       BIX    |
 |Calgary, ALberta       T2N 4N1 |                       |
 |CANADA          (403) 220 4493 |                       |
 +-------------------------------+-----------------------+