这是Ada教科书中的垃圾示例吗?

时间:2013-02-04 14:29:40

标签: ada

以下是“Ada for software engineers”示例程序的来源:

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

提取后

转到c04-arrays / justify

$ gnatmake justify.adb

运行justify,并将输出与作为输入的“example.txt”进行比较。 我得到的输出是交织在一起的线,与理由无关。 如果我用以下内容保存输出:

$ justify > result.txt

然后看着我可以得出结论,在终端中写入其他人的某些行。 但即使我忽略了这个问题,结果也很难被称为理由。

我的问题: 你有同样意想不到的输出吗? 你得到的输出是否与理由相似?

请注意,输入也随源提供!所以我甚至都没有试图打破这个计划。

我在终端上获得的输出:

  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.


这应该是理由吗? 这个问题特别与我的机器/系统/终端/外壳有关,还是其他地方的问题?

2 个答案:

答案 0 :(得分: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强制转换(鉴于这些是教科书示例,这是一个相当安全的选择,那里不会有任何实际的二进制文件!)< / p>

答案 1 :(得分:0)

答案可能是您的控制台使标签看起来像空格,从而给出不同的效果。


你可以用以下方法测试:

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

并查看两个句点是否在同一列中。