#66 2.x: SORT blanks files containing 2+ newlines

GC 2.2
closed
None
6
2017-04-10
2014-02-21
Edward Hart
No

Suppose I have a text file like this:

world
hello

which contains two or more newlines, and this program to sort its contents:

       >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. sort-test.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT in-text ASSIGN "text.txt"
        ORGANIZATION LINE SEQUENTIAL.

    SELECT text-sort.
DATA DIVISION.
FILE SECTION.
FD  in-text.
01  text-entry                          PIC X(40).

SD  text-sort.
01  sort-entry                          PIC X(40).

PROCEDURE DIVISION.
    PERFORM display-file

    SORT text-sort ASCENDING sort-entry USING in-text GIVING in-text

    PERFORM display-file

    GOBACK
    .
display-file.
    OPEN INPUT in-text
    PERFORM UNTIL EXIT
        READ in-text
            AT END
                EXIT PERFORM

            NOT AT END
                DISPLAY FUNCTION TRIM(text-entry) " " NO ADVANCING END-DISPLAY
        END-READ
    END-PERFORM
    DISPLAY SPACE END-DISPLAY
    CLOSE in-text
    .
END PROGRAM sort-test.

I would expect the output to be:

world hello
hello world

but instead it is just:

world hello

and the file is blank except for some newlines.

cobc -info:

    cobc (GNU Cobol) 2.0.0
    Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
    Copyright (C) 2006-2012 Roger While
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    Built     Jan 03 2014 15:06:26
    Packaged  Feb 11 2012 12:36:31 UTC
    C version "4.8.1"
    Build information
    Build environment        : x86_64-unknown-linux-gnu
    CC                       : gcc -std=gnu99
    CPPFLAGS                 : 
    CFLAGS                   : -O2 -pipe -finline-functions -fsigned-char
                               -Wall -Wwrite-strings -Wmissing-prototypes
                               -Wno-format-y2k -U_FORTIFY_SOURCE
    LD                       : /usr/bin/ld -m elf_x86_64
    LDFLAGS                  : -Wl,-z,relro,-z,now,-O1

    GNU Cobol information
    COB_CC                   : gcc -std=gnu99
    COB_CFLAGS               : -I/usr/local/include -pipe
    COB_LDFLAGS              : 
    COB_LIBS                 : -L/usr/local/lib -lcob -lm -lgmp -lncursesw
                               -ldb -ldl
    COB_CONFIG_DIR           : /usr/local/share/gnu-cobol/config
    COB_COPY_DIR             : /usr/local/share/gnu-cobol/copy
    COB_LIBRARY_PATH         : /usr/local/lib/gnu-cobol
    COB_MODULE_EXT           : so
    COB_EXEEXT               : 
    Dynamic loading          : System
    "CBL_" param check       : Disabled
    Variable format          : 0
    BINARY-C-LONG            : 8 bytes
    Sequential handler       : Internal
    ISAM handler             : BDB

Discussion

  • Edward Hart

    Edward Hart - 2014-02-21

    I should clarify that this occurs when there are two or more consecutive newlines.

     
    • Brian Tiffin

      Brian Tiffin - 2014-02-21

      Thanks for the report Edward. Verified as a bug.

       
  • Brian Tiffin

    Brian Tiffin - 2014-02-21
    • status: open --> accepted
    • assigned_to: Brian Tiffin
     
  • Simon Sobisch

    Simon Sobisch - 2014-02-25
    • summary: SORT blanks files containing 2+ newlines --> 2.x: SORT blanks files containing 2+ newlines
    • Priority: 1 --> 6
     
  • Simon Sobisch

    Simon Sobisch - 2014-02-25

    Just rechecked this.
    Problem occurs in 2.x (both C and CPP version) but not in 1.x

    Simon

     
  • Philipp Böhme

    Philipp Böhme - 2014-07-09
    • status: accepted --> closed
    • assigned_to: Brian Tiffin --> Philipp Böhme
     
  • Simon Sobisch

    Simon Sobisch - 2014-11-24
    • Group: unclassified --> GC 2.0
     

Log in to post a comment.