https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109779

            Bug ID: 109779
           Summary: isolib SkipLine skips the first character of the
                    successive line
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: modula2
          Assignee: gaius at gcc dot gnu.org
          Reporter: gaius at gcc dot gnu.org
  Target Milestone: ---

This bug report is copied from the gm2 mailing list.

It appears that the first character is consumed from the subsequent line when
using SkipLine (as seen when using ReadString after SkipLine).


MODULE port_test6_gm2;

FROM ChanConsts IMPORT
  OpenResults, old, read, write;
FROM IOChan IMPORT
  ChanId;
FROM StdChans IMPORT
  StdOutChan;
IMPORT StreamFile;
FROM TextIO IMPORT
  ReadString, SkipLine, WriteLn, WriteString;


PROCEDURE SkipReadTest();
  CONST
    arr_len=                    128;

  TYPE
    arr_type=                   ARRAY[0..arr_len-1] OF CHAR;

  VAR
    cid_file:                   ChanId;
    cid_out:                    ChanId;
    file_name:                  arr_type;
    a_str:                      arr_type;
    res:                        OpenResults;

  BEGIN                         (* PROCEDURE SkipReadTest *)
    cid_out:=StdOutChan();

    file_name:='test_data';

    (* create file and write 2 lines to it *)
    StreamFile.Open(cid_file, file_name, write+old, res);
    IF res=opened THEN
      WriteString(cid_file, '# line1');
      WriteLn(cid_file);
      WriteString(cid_file, '# line2');
      WriteLn(cid_file);
      StreamFile.Close(cid_file);
    END;                        (* IF res=opened *)

    (* (re-)open file and read from it *)
    StreamFile.Open(cid_file, file_name, read, res);
    IF res=opened THEN
      SkipLine(cid_file);
      ReadString(cid_file, a_str);
      WriteString(cid_out, a_str);
      WriteLn(cid_out);
      StreamFile.Close(cid_file);
    END;                        (* IF res=opened *)
  END SkipReadTest;


BEGIN                           (* MODULE port_test6_gm2 *)
  SkipReadTest();
END port_test6_gm2.

Reply via email to