3

I'm trying to get a portion of bytes from stdin using ACUCOBOL-GT. Because the data could be of any length, specifying a variable PIC X(n) and then using ACCEPT variable won't work, since the whole line is read, and the input line is truncated to the length of variable.

For example, if the stdin contains this:

Some line exceeding 10 caracters↵
and then another line↵
and at last a third line.

and I have this code:

working-storage division.

 77 someLine pic X(10).

procedure division.

    perform 3 times
        accept someLine;
        display someLine;
    end-perform;

then the result is only

Some line ↵
and then a↵
and at las

Apparently, each ACCEPT reads until a newline is found, and then moves the line into the specified variable, possibly truncating a part of the line.

Now I want to read only a portion of stdin, so no bytes get discarded. I tried to assign a file descriptor to the stdin using SYSIN, as recommended in this post:

    select sysin
        assign to keyboard
        organization binary sequential.

data division.
file section.

fd sysin.
01 inputByte pic X.

procedure division.

    open input sysin
    perform 3 times
        accept inputByte from sysin
        display inputByte
    end-perform
    close sysin.

But it somehow gives an File error 35 (file not found). Seems like ACUCOBOL-GT

does not support the direct assignment to the user's screen or keyboard.

Can I somehow force ACCEPT to read a specified number of bytes instead of scanning for a newline? Or can I somehow use READ SYSIN NEXT?

Community
  • 1
  • 1
MC Emperor
  • 22,334
  • 15
  • 80
  • 130
  • Can you provide some data which reflects what you want to do? Generally, a plain ACCEPT will consume an input record and you will not see data that does not "fit" into what you have ACCEPTed into. There are often Extensions to ACCEPT and DISPLAY, and I think there are many in AcuCOBOL. Do you want keyboard input, or "sysin" input that happens to have been typed at some point in the past (by the time the program runs) – Bill Woodger Jan 20 '17 at 15:51
  • @BillWoodger For example, POST data passed in through CGI or a program that pipes its output to the COBOL program. I do no require keystrokes per se, but bytes from the standard input. – MC Emperor Jan 20 '17 at 15:57
  • So you are dealing with potentially different inputs which you want to deal with in different ways depending on the first part of the text? The "easy" way is to define something that is the maximum size that you could possibly receive, so you get all the data, and then define for the first portion to test. Someone with AcuCOBOL experience my have other ideas. – Bill Woodger Jan 20 '17 at 16:17
  • @BillWoodger The contents of the stdin don't have a predefined structure. In contrast, it could have **any length**, and it's possibly larger than the maximum `PICTURE` size, if any. – MC Emperor Jan 20 '17 at 16:23
  • 3
    I'd suggest to check out `C$GETCGI`[1] or try to get the pointer to stdin, assign its address to a `PIC X(1)` in `LINKAGE ITEM` to it and use a perform to get the data until EOF. [1]:http://documentation.microfocus.com/help/topic/com.microfocus.eclipse.infocenter.extendACUSuite/BKPPPPLIBRS055.html?cp=5_0_1_4_8_0_20 [2]:http://documentation.microfocus.com/help/topic/com.microfocus.eclipse.infocenter.extendACUSuite/BKPPPPLIBRS071.html?cp=5_0_1_4_8_0_36 – Simon Sobisch Jan 20 '17 at 17:23
  • 1
    Using `C$GETCGI` won't work, unfortunately, because it only allows to copy its value to a fixed-size working-storage variable. Using `C$MEMCPY` could be an option, if I only knew how to retrieve that pointer... – MC Emperor Jan 21 '17 at 10:39

0 Answers0