----- Original Message ----- From: Masaharu Goto <MXJ02154@nifty.ne.jp> To: <fine@bnl.gov> Cc: <stephan.heising@cern.ch>; <ROOTTALK@pcroot.cern.ch> Subject: RE:Re: end of line handling under NT Bottom line: To avoid mess try to avoid "MS DOS" text mode at all !!! -------------------------------------------------------- > Hello Stephan and Valery, > > I think this depends on whether you open the file with > > FILE* fp = fopen("fname","rb"); > > or > > FILE* fp = fopen("fname","r"); > > The first case opens the file with binary mode and second text mode. Yes, it is true but for Windows only. For example the "man fopen" on SunOS says: "The character "b" has no effect, but is allowed for ISO C" and NO say about "t" mode at all ! MS Visual Studio says: " . . . "t Open in text (translated) mode. In this mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing with "a+", fopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z, may cause fseek to behave improperly near the end of the file. Also, in text mode, carriage return-linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return-linefeed combinations on output. . . . b Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed. . . . " > If you open the file by yourself, it is under your control to choose > between binary and text mode. As long as you use fopen(), Cint simply > behaves the same as the compiled code. > If the file is opened by ROOT or CINT utility, it is likely the mode > is binary. I think this is unlikely, but this case, Here is a problem. FILE* fp = fopen("fname","r"); opens the file - on UNIX as "binary" - on NT as " text" To open the file as "binary" on NT one MUST do FILE* fp = fopen("fname","rb"); There is no way to open "Ms Dos" text file properly under UNIX. > we may need to modify things in ROOT or CINT. and the second problem is the format of "text" file on UNIX and NT "end-of-line" on UNIX is one byte: <CR> "end-of-line" on MSDOS (Windows) is either two bytes long: <CR><LF> or single <CR>. This means if the file was created as "text" under Windows it CAN NOT be read back properly by UNIX !!! In my mind this had been discussed 2 or 3 years ago. As far as I know there is no good solution for that (there was very long discussion on this issue on cygnus-gnuwin32 list). Anyway it is not CINT problem but the poor user sitting between two platforms. Valery > > Thank you > Masaharu Goto > > > > > > >> Hello, > >> > >> I'm using ROOT v 2.23/09 on a PC with NT v4 (sp5). > >> fgets is not acting as expected. I recognized this behaviour some time > >> ago. > >> This function should read >1< line or MAX-1 characters from a file. > >> Instead > >> it reads always MAX-1 characters including newlines (0x0d 0x0a). > >> > > > > This sounds like CINT "defaults" are "UNIX" defaults. Namely, > > CINT opens files in "binary" mode. > > UNIX opens the file as "binary" "by default, "native" NT does > > the "text" default. > > > > This means to make code portable the user should always specify > > whether he wants the file to be open as "binary" or "text" > > It is true for the "plain" C/C++ environment as well (with no ROOT/CINT > > involved). > > > > From another hand one has to choose which text format he is going > > to play with "UNIX" / "NT". > > > > Do you want to share the text files between UNIX and NT? It is question too > . > > The ROOT assumption the files should be shared and by this reason they are > > UNIX text files. > > > > Keep in mind: > > > > - Usually few UNIX utilities can manage NT text files > > - Usually any NT utility can "understand" the UNIX text format as well. > > > > if decide to stick UNIX formsat then you have to make sure your favorite > editor > > > > can save the file in UNIX format (almost all of them can read > > UNIX text > > but many of them write out NT text format only (for example > MS DevStudio > > > > > >> Do I have to switch to C++ streams? > > > > Very likely there you face the same problem ? > > > > May be Masa Goto can comment how the default mode to open files > > is chosen. > > > > Valery > > >
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET