* Ada.Text_IO.Get_Line issue in windows @ 2015-06-01 5:07 tornenvi 2015-06-02 2:44 ` AdaMagica ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: tornenvi @ 2015-06-01 5:07 UTC (permalink / raw) Hello, I have found some unexpected behavior for calls to Ada.Text_IO.Get_Line on windows when reading from a text that has only one line in it. The program below simply reads the first line of a text file into a 6 character buffer, and outputs the length of the line read, the line and the line again as hex. I use windows notepad to create the test file Test.txt. When using Test.txt with the one line of text ABCD with no blank line at the end of the file I get output 1 below -- Output 1 ------------------------------------------------------ Length= 4 Line=[ABCDXX] Line as hex=[414243445858] ------------------------------------------------------------------ as expected. However if Test.txt is the one line of text ABCDE with no blank line at the end of the file then I get output 2 below -- Output 2 ----------------------------------------------------- Length= 6 Line=[ABCDE ] Line as hex=[4142434445ff] ----------------------------------------------------------------- I receive an unexpected length of 6, expected 5. The fact that the last two characters are not 'XX' is acceptable since ARM A.10.7 19 says "The values of characters not assigned are not specified." I get the same output 2 if I compile the program with GNAT GPL 2014, 2013,2012 or 2011 or with mingw FSF GNAT 4.7.0-1 or 4.8.1-4. However if I compile with mingw FSF GNAT 4.5.2-1 , 4.5.0-1, 4.4.0 or 3.4.5 then I get the expected output 3 below -- Output 3 ----------------------------------------------------- Length= 5 Line=[ABCDEX] Line as hex=[414243444558] ----------------------------------------------------------------- Under windows the one line text file does not have an end of line character (usually CRLF) which means it is not a canonical text file as described here http://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/the_implementation_of_standard_i_o.html#text-io however that section also states that text_io can be use to read non canonical text files and the very last line of that section says "Every LF character is considered to end a line, and there is an implied LF character at the end of the file." this indicates to me that there should be an implied LF at the end of the file and I should be getting the expected output 3 result for all the compilers. Is this a bug in the windows builds of GNAT? ---- Program ----------------------------------------------------- with Ada.Text_IO; procedure FileRead is TestFileName : constant string := "Test.txt"; TestFile : Ada.Text_IO.File_Type; Line : string(1..6) := "XXXXXX"; Length : natural; function ToHex(Msg : string) return string is Hex : constant array (0..15) of character := "0123456789abcdef"; Str : String(1..Msg'length*2) := (others => ' '); -- 2 hex digits per byte Index : Integer :=1; ByteValue : Integer; begin for i in Msg'Range loop ByteValue := character'Pos(Msg(i)); Str(Index) := Hex(ByteValue / 16); Index := Index + 1; Str(Index) := Hex(ByteValue mod 16); Index := Index + 1; end loop; return Str; end; begin Ada.Text_IO.Open( TestFile, Ada.Text_IO.IN_FILE, TestFileName ); if not Ada.Text_IO.End_Of_File(TestFile) then Ada.Text_IO.Get_Line( TestFile, Line, Length ); Ada.Text_IO.Put_Line("Length= " & integer'image(Length)); Ada.Text_IO.Put_Line("Line=[" & Line & "]"); Ada.Text_IO.Put_Line("Line as hex=[" & ToHex(Line) & "]"); end if; exception when E: others => Ada.Text_IO.Put_Line("Exception"); end; ------------------------------------------------------------- ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-01 5:07 Ada.Text_IO.Get_Line issue in windows tornenvi @ 2015-06-02 2:44 ` AdaMagica 2015-06-03 5:54 ` tornenvi 2015-06-03 7:02 ` Simon Wright 2015-06-08 22:47 ` wowwomenonwheels205 2 siblings, 1 reply; 9+ messages in thread From: AdaMagica @ 2015-06-02 2:44 UTC (permalink / raw) As you say, it's a nonregular file. Are you sure the documentation you cite is up to date with your GNAT implementation? Obviously it isn't. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-02 2:44 ` AdaMagica @ 2015-06-03 5:54 ` tornenvi 2015-06-03 6:32 ` Jeffrey R. Carter 0 siblings, 1 reply; 9+ messages in thread From: tornenvi @ 2015-06-03 5:54 UTC (permalink / raw) On 6/2/2015 12:14 PM, AdaMagica wrote: > As you say, it's a nonregular file. Are you sure the documentation you cite is up to date with your GNAT implementation? Obviously it isn't. > I know by the definition it is a nonregular file however it is a "standard" windows text file. Earlier versions of the compiler did handle it correctly. I just checked the gnat reference manual for gcc 5.1 direct from gnu.org and the documentation is still the same. I also found in a-textio.ads ... ----------------------------------- -- Handling of Format Characters -- ----------------------------------- -- Line marks are represented by the single character ASCII.LF (16#0A#). -- In DOS and similar systems, underlying file translation takes care -- of translating this to and from the standard CR/LF sequences used in -- these operating systems to mark the end of a line. On output there is -- always a line mark at the end of the last line, but on input, this -- line mark can be omitted, and is implied by the end of file. So I believe the intent of the compiler code is as described in the documentation. I did some more digging and it seems that the Get_line function was modified and separated out into its own package (a-tigeli.adb) and the code in this file is different from what it used to be. I believe I have found the problem in that file (a-tigeli.adb) I believe line 193 which is elsif ch /= LM then should read elsif ch /= LM and ch /=EOF then There is even a comment already there saying -- If we get EOF after already reading data, this is an incomplete -- last line, in which case no End_Error should be raised. it just looks like the EOF was not checked for before adding the last character. I will post a bug report to gcc.gnu.org/bugzilla for the FSF compiler. I could not find any way to report a bug to Adacores libre site, is there some where I should report it to? Is there any point? I assume Adacore will be the ones processing the FSF gcc ada bugs anyway. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-03 5:54 ` tornenvi @ 2015-06-03 6:32 ` Jeffrey R. Carter 2015-06-05 4:10 ` tornenvi 0 siblings, 1 reply; 9+ messages in thread From: Jeffrey R. Carter @ 2015-06-03 6:32 UTC (permalink / raw) On 06/02/2015 10:54 PM, tornenvi wrote: > > I believe I have found the problem in that file (a-tigeli.adb) > > I believe line 193 which is > > elsif ch /= LM then > > should read > > elsif ch /= LM and ch /=EOF then In context, this is ch := Getc (File); -- If we get EOF after already reading data, this is an incomplete -- last line, in which case no End_Error should be raised. if ch = EOF and then Last < Item'First then raise End_Error; elsif ch /= LM then -- Buffer really is full without having seen LM, update col Last := Last + 1; Item (Last) := Character'Val (ch); File.Col := File.Col + Count (Last - Item'First + 1); return; end if; We can see that if EOF is encountered after reading characters into Item then the EOF is incorrectly stored in Item, so you have found an error in Get_Line. While your change will work, it might be better to rewrite the "if" as if ch = EOF then if Last < Item'First then raise End_Error; end if; elsif ch = LM then null; else -- ch /= EOF and ch /= LM ... end if; to divide the code into the 3 cases of interest: EOF, in which case we either raise End_Error or do nothing, depending on Last; LM, do nothing; and anything else, store the character in Item. It's disturbing that EOF can be converted into a valid Character. -- Jeff Carter "Frankie Wolf, wanted by Federal authorities for dancing with a mailman." Take the Money and Run 143 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-03 6:32 ` Jeffrey R. Carter @ 2015-06-05 4:10 ` tornenvi 0 siblings, 0 replies; 9+ messages in thread From: tornenvi @ 2015-06-05 4:10 UTC (permalink / raw) On 6/3/2015 4:02 PM, Jeffrey R. Carter wrote: > On 06/02/2015 10:54 PM, tornenvi wrote: >> >> I believe I have found the problem in that file (a-tigeli.adb) >> >> I believe line 193 which is >> >> elsif ch /= LM then >> >> should read >> >> elsif ch /= LM and ch /=EOF then > > In context, this is > > ch := Getc (File); > > -- If we get EOF after already reading data, this is an incomplete > -- last line, in which case no End_Error should be raised. > > if ch = EOF and then Last < Item'First then > raise End_Error; > > elsif ch /= LM then > > -- Buffer really is full without having seen LM, update col > > Last := Last + 1; > Item (Last) := Character'Val (ch); > File.Col := File.Col + Count (Last - Item'First + 1); > return; > end if; > > We can see that if EOF is encountered after reading characters into Item then > the EOF is incorrectly stored in Item, so you have found an error in Get_Line. > > While your change will work, it might be better to rewrite the "if" as > > if ch = EOF then > if Last < Item'First then > raise End_Error; > end if; > elsif ch = LM then > null; > else -- ch /= EOF and ch /= LM > ... > end if; > > to divide the code into the 3 cases of interest: EOF, in which case we either > raise End_Error or do nothing, depending on Last; LM, do nothing; and anything > else, store the character in Item. > > It's disturbing that EOF can be converted into a valid Character. > I have already reported the bug on bugzilla, the link to it is below. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66390 You can add your suggested change to the bug report, or I can update it if you like. However I'm not set up to report patch files (tested) so I am only adding the changes as comments to the bug report. Also note that line 84 of \gcc\ada\a-tigeli.adb reads memset (S, 10, size_t (N)); I believe the hardcoded '10' here should be 'LM'. I have added it as a comment to the bug report. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-01 5:07 Ada.Text_IO.Get_Line issue in windows tornenvi 2015-06-02 2:44 ` AdaMagica @ 2015-06-03 7:02 ` Simon Wright 2015-06-03 10:08 ` Simon Clubley 2015-06-08 22:47 ` wowwomenonwheels205 2 siblings, 1 reply; 9+ messages in thread From: Simon Wright @ 2015-06-03 7:02 UTC (permalink / raw) tornenvi <tornenvi@gmail.com> writes: > Is this a bug in the windows builds of GNAT? It took me some time to realise that Emacs was automatically adding a linefeed to the end of the example file. Now I see that the behaviour you report is present in all the Mac OS X compilers I have from GNAT GPL 2011 to 2014 and GCC 4.6 to 5.1. For reference, $ echo -n "abcde" >Test.txt does the trick. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-03 7:02 ` Simon Wright @ 2015-06-03 10:08 ` Simon Clubley 2015-06-03 11:14 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: Simon Clubley @ 2015-06-03 10:08 UTC (permalink / raw) On 2015-06-03, Simon Wright <simon@pushface.org> wrote: > tornenvi <tornenvi@gmail.com> writes: > >> Is this a bug in the windows builds of GNAT? > > It took me some time to realise that Emacs was automatically adding a > linefeed to the end of the example file. That behaviour is adjustable in Emacs and the default with early versions of Emacs was _not_ to add the line terminator to the final record in the file. I have had the following line in my .emacs since the 1990s: (setq require-final-newline t) However, your comment above implies that the default has changed so I don't know if that's now obsolete in the very latest Emacs versions. Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-03 10:08 ` Simon Clubley @ 2015-06-03 11:14 ` Simon Wright 0 siblings, 0 replies; 9+ messages in thread From: Simon Wright @ 2015-06-03 11:14 UTC (permalink / raw) Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> writes: > On 2015-06-03, Simon Wright <simon@pushface.org> wrote: >> It took me some time to realise that Emacs was automatically adding a >> linefeed to the end of the example file. > > That behaviour is adjustable in Emacs and the default with early > versions of Emacs was _not_ to add the line terminator to the final > record in the file. > > I have had the following line in my .emacs since the 1990s: > > (setq require-final-newline t) > > However, your comment above implies that the default has changed so I > don't know if that's now obsolete in the very latest Emacs versions. Looks as though text-mode (& message-mode?) set it to t (my global default is nil). C-h v: require-final-newline is a variable defined in `files.el'. Its value is t Original value was nil Local in buffer *unsent followup to Simon Clubley on comp.lang.ada*; global value is nil This variable is safe as a file local variable if its value satisfies the predicate `symbolp'. Documentation: Whether to add a newline automatically at the end of the file. A value of t means do this only when the file is about to be saved. A value of `visit' means do this right after the file is visited. A value of `visit-save' means do it at both of those times. Any other non-nil value means ask user whether to add a newline, when saving. A value of nil means don't add newlines. Certain major modes set this locally to the value obtained from `mode-require-final-newline'. You can customize this variable. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ada.Text_IO.Get_Line issue in windows 2015-06-01 5:07 Ada.Text_IO.Get_Line issue in windows tornenvi 2015-06-02 2:44 ` AdaMagica 2015-06-03 7:02 ` Simon Wright @ 2015-06-08 22:47 ` wowwomenonwheels205 2 siblings, 0 replies; 9+ messages in thread From: wowwomenonwheels205 @ 2015-06-08 22:47 UTC (permalink / raw) Postal Lottery: Turn $6 into $60,000 in 90 days, GUARANTEED I found this in a news group and decided to try it. A little while back, I was browsing through newsgroups, just like you are now and came across a message just like this that said you could make thousands of dollars within weeks with only an initial investment of $6.00!!! So I thought yeah right, this must be a scam!!! But like most of us, I was curious, so I kept reading. Anyway, it said that you send $1.00 to each of the 6 names and addresses stated in the message. You then place your own name and address at the bottom of the list at #6 and post the message in at least 200 news groups. (There are thousands to choose from). No catch, that was it. So after thinking it over, and talking to a few people first. I thought about trying it. I figured, what have I got to lose except 6 stamps and $6.00, right? So I invested the measly $6.00!!! Guess what? Within 7 days I started getting money in the mail!!! I was shocked!!! I figured it would end soon, but the money just kept coming in!!! In my first week, I had made about $25.00. By the end of the second week, I had made a total of over $1,000.00!!! In the third week, I had over $10,000.00 and it is still growing!!! This is now my fourth week and I have made a total of just over $42,000.00 and it is still coming in rapidly!!! It's certainly worth $6.00 and 6 stamps!!! I have spent more than that on the lottery!!! Let me tell you how this works and most importantly, why it works!!! Also, make sure you print a copy of this message now. So you can get the information off of it as you need it. I promise you that if you follow the directions exactly, that you will start making more money than you thought possible by doing something so easy!!! Suggestion: Read this entire message carefully!!! (Print it out or download it.) Follow the simple directions and watch the money come in!!! It's easy!!! It's legal!!! Your investment is only $6.00 (plus postage). IMPORTANT: This is not a rip-off!!! It is not illegal!!! ? It is almost entirely risk free and it really works!!! If all of the following instructions are adhered to, you will receive extraordinary dividends!!! Please note: Follow these directions EXACTLY, and $60,000.00 or more can be yours in 20 to 90 days!!! This program remains successful because of the honesty and the integrity of the participants!!! Please continue its success by carefully adhering to the instructions. You will now become part of the mail order business. In this business your product is not solid or tangible, it is a service. You are in the business of developing mailing lists. Many large corporations are happy to pay big bucks for quality lists. However, the money made from a mailing list is secondary to the income which is made from people like you and me asking to be included on your mailing list!!! Here are the 4 easy steps to success:- Step 1:- Get 6 separate pieces of paper and write the following on each piece of paper. PLEASE PUT ME ON YOUR MAILING LIST Now get 6 U.S. dollar bills and place ONE inside each of the 6 pieces of paper so the bills will not be seen through the envelopes (to prevent mail theft). Next, place one paper in each of the 6 envelopes and seal them, you should now have 6 sealed envelopes. Each with a piece of paper stating the above phrase, your name and address, and a $1.00 bill. THIS IS ABSOLUTELY LEGAL!!! YOU ARE REQUESTING A LEGITIMATE SERVICE AND YOU ARE PAYING FOR IT!!! Like most of us, I was a little skeptical and a little worried about the legal aspect of it all. So I checked it out with the U.S. Postal Service and they confirmed that it is indeed legal!!! Mail the 6 envelopes to the following addresses:- D. Kumar Room 2.36 Burkhardt House Oxford Place, Victoria Park M14 5RR Manchester ENGLAND T. Perce 11505 Headley Avenue Cleveland, Oh 44111 T. Beckers Rijksweg 46 6267AH Cadier en Keer The Netherlands J. Eddolls 144 Pursey Drive Bradley Stoke Bristol BS32 8DP United Kingdom Louis Joseph 1933 Highway 35, #104 Wall, NJ 07719 Jesse Quiroz 2845 Franklin #1001 Mesquite, Texas 75150 Step 2:- Now take the #1 name off the list that you see above, move the other names up (6 becomes 5, 5 becomes 4, etc.) and add your name as number 6 on the list. Step 3:- Change anything you need to, but try to keep this message as close to what you see as possible. Now, post your amended message to at least 200 news groups. I think there are close to 24,000 groups!!! All you need is 200, but remember, the more you post, the more money you make!!! This is perfectly legal!! If you have any doubts, refer to Title18 Sec. 1302 & 1341 of the postal lottery laws. Keep a copy of these steps for yourself and whenever you need money, you can use it again. Please remember that this program remains successful because of the honesty and the integrity of the participants and by their carefully adhering to the directions!!! Look at it this way. If you are of integrity, the program will continue and the money that so many others have received will come your way!!! Note: - You may want to retain every name and address sent to you, either on your computer or hard copy and keep the notes people send you. This verifies that you are truly providing a service. Also, it might be a good Idea to wrap the $1 bills in dark paper to reduce the risk of mail theft. So, as each post is downloaded and the directions carefully followed, six members will be reimbursed for their participation as a list developer with one dollar each. Your name will move up the list geometrically so that when your name reaches the #1 position, you will be receiving thousands of dollars in cash!!! What an opportunity for only $6.00!!! ($1.00 for each of the first six people listed above). Send it now, add your own name to the list and your in business!!! DIRECTIONS FOR HOW TO POST TO A NEWS GROUP!!! Step 1:- You do not need to re-type this entire message to do your own posting. Simply put your cursor at the beginning of this message and drag your cursor to the bottom of this message and select copy from the edit menu. This will copy the entire message into the computer memory. Step 2:- Open a blank note pad file and place your cursor at the top of the blank page. From the edit menu select paste. This will paste a copy of the message into notepad so that you can add your name to the list. Step 3:- Save your new notepad file as a txt file. If you want to do your posting in a different setting, you'll always have this file to go back to. Step 4:- Use Netscape or Internet Explorer and try searching for various news groups (on-line forums, message boards, chat sites, discussions, etc.) Step 5:- Visit these message boards and post this message as a new message by highlighting the text of this message from your notepad and selecting paste from the edit menu. Fill in the subject, this will be the header that everybody sees as they scroll through the list of postings in a particular group. Click the post message button. You've done your first one! Congratulations!!! All you have to do is jump to different news groups and post away, after you get the hang of it, it will take about 30 seconds for each news group! REMEMBER, THE MORE NEWS GROUPS YOU POST IN, THE MORE MONEY YOU WILL MAKE!!! (But you have to post a minimum of 200). That's it!!! You will begin receiving money from around the world within days!!! You may eventually want to rent a P.O. Box due to the large amount of mail you will receive. If you wish to stay anonymous, you can invent a name to use, as long as the postman will deliver it. JUST MAKE SURE ALL THE ADDRESSES ARE CORRECT!!! Now the why part. Out of 200 postings, say you receive only 5 replies (a very low example). So then you made $5.00 with your name at #6 on the letter. Now, each of the 5 persons who sent you $1.00 make the minimum 200 postings, each with your name at #5 and only 5 persons respond to each of the original 5, that is another $25.00 for you. Now those 25 each make 200 MINIMUM posts with your name at #4 and only 5 replies each, you will bring in an additional $125.00!!! Now, those 125 persons turn around and post the minimum 200 with your name at #3 and only receive 5 replies each, you will make an additional $625.00!!! OK, now here is the fun part, each of those 625 persons post a minimum 200 messages with your name at #2 and they each only receive 5 replies, that just made you $3,125.00!!! Those 3,125 persons will all deliver this message to 200 news groups. If just 5 more reply you will receive $15,625.00!!! All with an original investment of only $6.00!!! Amazing isn't it!!!! When your name is no longer on the list, you just take the latest posting in the news groups and send out another $6.00 to the names on the list, putting your name at number 6 again. You must realize that thousands of people all over the world are joining the internet and reading these messages every day!!! Just like you are now!!! So, can you afford $6.00 and see if it really works? I'm glad I did!!! People have said, "what if the plan is played out and no one sends you the money?" So what!!! What are the chances of that happening, when there are tons of new honest users and new honest people who are joining the internet and news groups everyday and are willing to give it a try? Estimates are at 20,000 to 50,000 new users, every day!!! REMEMBER PLAY HONESTLY AND FAIRLY AND THIS WILL REALLY WORK!!! -- Comments/Feedback (please post your feedback/experiences here) -- Not bad for 1 hr's work....made me around $5320 in roughly 35 days Anthony M - TX Hello, I rcvd 269 bucks in the post in 2 weeks. Dan Miami - FL I had to wait around 10 days before I had any results - $13,450 as of 3rd Jan 2003 to date (14th Feb 2003).Am gonna re-post it again for more money!! Del from Alberta - Canada Only received around 588 in the post the last 2 months since I started the program but I'd posted to approx. 100 newsgroups. James P - Manchester, UK Cool....didn't expect much out of this "scam" initially but I have pay my credit card bill Mustafa - Jordan For $6,I made $246 in 2 weeks ROMEO2326 - Little Rock, AR -US of A Hey, just droppin a line to say that after posting to well over 820 newsgroups on google and my ISP newsgroup server over a period of 4 1/2 months ,Ive raked in $54280 . Mucho dinero baby!!!! Peace Drew Dallas - TX ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-06-08 22:47 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-06-01 5:07 Ada.Text_IO.Get_Line issue in windows tornenvi 2015-06-02 2:44 ` AdaMagica 2015-06-03 5:54 ` tornenvi 2015-06-03 6:32 ` Jeffrey R. Carter 2015-06-05 4:10 ` tornenvi 2015-06-03 7:02 ` Simon Wright 2015-06-03 10:08 ` Simon Clubley 2015-06-03 11:14 ` Simon Wright 2015-06-08 22:47 ` wowwomenonwheels205
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox