FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2003, 02:10 PM
kumar
Guest
 
Posts: n/a
Default $fgets()-- different results in different simulators?

Hello all,

I have one interesting point to make regarding system task $fgets().

testin = $fopen("test.txt", "r");
str_len = $fgets(l, testin);
$display("%s, %h, %d",l, l, str_len);

I have used Model-Sim, Active Hdl and NC-Sim in PC Environment and did
find that CR- Carriage Return is not displayed by Modelsim and Active
HDL simulators when $display is done .
Is there any reason for that?

But NC-Sim displays both CR and LF ie., its equivalent is 0d and 0a
hex value respectively.
Is it a bug in Model-Sim/ActiveHDL.

If NC-Sim is displaying the character CR+LF, Model-sim/Active-HDL just
reports LF.

But i should be able to display the character "CR" x0d.


Well one more point is that if i do $fseek, In Model-Sim/ActiveHDL it
would result in
p = $fseek(testin, -str_len-1, 1); to go back to the start/Begining of
the line.

but in NC-Sim i need to do just this
p = $fseek(testin, -str_len, 1);

Hence i have to use two different statements for differnet simulators.
Looks like Model-Sim and ActiveHdl is not displaying the character
value of "CR"

Can anybody help me out in this regard

Thanks in advance

Regards
Kumar
Reply With Quote
  #2 (permalink)  
Old 07-31-2003, 06:44 PM
Steven Sharp
Guest
 
Posts: n/a
Default Re: $fgets()-- different results in different simulators?

[email protected] (kumar) wrote in message news:<[email protected] com>...
>
> I have used Model-Sim, Active Hdl and NC-Sim in PC Environment and did
> find that CR- Carriage Return is not displayed by Modelsim and Active
> HDL simulators when $display is done .
> Is there any reason for that?


I am guessing that you are running on a Windows system rather than
Unix. Windows systems use CR+LF to end text lines, while Unix uses
just LF. To try to make text processing applications portable from
Unix to Windows (or originally DOS), the C fopen() on Windows has
both text and binary modes. In text mode, CR+LF gets converted into
just LF when read, and LF gets converted into CR+LF when written.
That allows typical C code that assumes lines end with LF to work
under Windows. Binary mode does not do this translation, so that
you can read raw data without losing some bytes.

This would account for the CR characters disappearing on you, and
for the $fseek counts not matching the number of characters that
you thought you read. If you want to prevent this, you should be
able to force the files to be opened in binary mode. Just change
the file mode from "r" to "rb" in the $fopen call. It appears
that NC is always opening in binary mode.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
System Task $fgets kumar Verilog 2 07-09-2003 12:10 AM


All times are GMT +1. The time now is 11:27 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved