2013-02-04 16 views
1

這裏是爲「阿達軟件工程師」的例子程序源代碼:這是阿達教科書的例子垃圾嗎?

http://www.springer.com/cda/content/document/cda_downloaddocument/978-1-84882-313-6_programs.zip

提取到C04陣列後/辯解

$ gnatmake justify.adb 

運行證明,並比較輸出與「example.txt」是輸入內容。 我得到的輸出是交織線,與理由無關。 如果我保存的輸出:

$ justify > result.txt 

然後看着那我可以斷定,有些行寫在那裏ontop的其他終端的。 但即使我忽略了這個問題,結果也很難稱之爲理由。

我的問題: 你會得到相同的意外輸出嗎? 你得到的輸出是否類似於正當性?

請注意,輸入也隨源提供!所以我甚至不想打破這個計劃。

輸出我得到的終端上:

 
    The quicke quick brown fox jumped over the lazy dog. 
      brown  fox  jumped  over  the  lazy  dog. 
      ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedov 
The quickThe quick brown fox jumped over the lazy dog. 
    The quick brown foxed over the lazy dog. 
The quick brown fox jumped over dog. 
The quick brown fox jumped over the lazy 
Thee slow gray wolf skipped over the frisky cat. 
The slow grayray wolf skipped over the frisky cat. 
    The slow gray wolfed over the frisky cat. 
The slow gray wolf skippedky cat. 
The slow gray wolf skipped over the 
The slow gray wolf skipped over the frisky 
      cat. 

我重定向後有輸出:

 
      The quick brown fox jumped over the lazy dog. 
    The quick 
      brown  fox  jumped  over  the  lazy  dog. 
      ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedov 
      The quick brown fox jumped over the lazy dog. 
The quick 
      brown fox jumped over the lazy dog. 
    The quick brown fox 
      jumped over the lazy dog. 
The quick brown fox jumped over 
      the lazy dog. 
The quick brown fox jumped over the lazy 
      dog. 
    The slow gray wolf skipped over the frisky cat. 
The 
      slow gray wolf skipped over the frisky cat. 
The slow gray 
      wolf skipped over the frisky cat. 
    The slow gray wolf 
      skipped over the frisky cat. 
The slow gray wolf skipped 
      over the frisky cat. 
The slow gray wolf skipped over the 
      frisky cat. 
The slow gray wolf skipped over the frisky 
      cat. 


難道這應該是理由? 這個問題是否與我的機器/系統/終端/外殼有關,或者是其他地方的問題?

+1

編譯,鏈接,並且與Windows XP上的GNAT GPL 2012完全一樣。 –

回答

3

我得到在Mac OS X相同的輸出

的問題是,example.txt是一個Windows文件,以CR/LF行結束,而你在Unix系統中,剛剛預計LF上運行;並且Ada RTS將在每條輸入行的末尾離開CR。 (我懷疑C RTS可能會做同樣的事情,Python會更好地處理它)。

大量的信息在Wikipedia,包括可以使用cat -v看到控制字符:

 The quick brown fox jumped over the lazy dog.^M The quick 
     brown  fox  jumped  over  the  lazy  dog.^M 
     ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedov 
     The quick brown fox jumped over the lazy dog.^M The quick 
     brown fox jumped over the lazy dog.^M The quick brown fox 
     jumped over the lazy dog.^M The quick brown fox jumped over 
     the lazy dog.^M The quick brown fox jumped over the lazy 
     dog.^M The slow gray wolf skipped over the frisky cat.^M The 
     slow gray wolf skipped over the frisky cat.^M The slow gray 
     wolf skipped over the frisky cat.^M The slow gray wolf 
     skipped over the frisky cat.^M The slow gray wolf skipped 
     over the frisky cat.^M The slow gray wolf skipped over the 
     frisky cat.^M The slow gray wolf skipped over the frisky 
     cat.^M ^M 

我不知道你的系統是否有dos2unix效用,但在任何情況下,你可以使用tr

$ tr -d '\r' <example.txt >example.lf 
$ mv example.lf example.txt 

通常情況下,你可以使用unzip -a到行尾轉換上的所有文件都提取存檔的原始zip鑑定者定爲文字;在這種情況下,它將所有文件標識爲二進制文件,因此您可以使用unzip -aa強制進行轉換(由於這些是教科書示例,因此不會有任何實際的二進制文件存在!)

0

答案可能是您的控制檯正在使標籤看起來像空格,從而給出不同的效果。


你可以測試:

Ada.Text_IO.Put(ASCII.HT & '.'); 
Ada.Text_IO.Put(' ' & '.'); 

,看看兩個時期是在同一列。