Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-11

How to find out, if TInputPipeStream empty?

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

Hi all,

Reading from a TInputPipeStream waits till input arrives. I don't want to wait.
How can I find out if there is input?
Is there an OS independent solution?

thx in advance,
Mattias Gaertner

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 6 lines
Hi all, Reading from a TInputPipeStream waits till input arrives. I don't want to wait. How can I find out if there is input? Is there an OS independent solution?

No. That is, not yet. We're working on a OS-independent solution for asynchroneous I/O, but currently it only works for Linux.

Michael.

Eduardo Morras
to Michael Van Canneyt

Hello everyone:

I'm new to fpc and i'm trying to port some mac pascal code to win32 console. I have this code to read 64 bytes of data from a file, work with them and save a double and 64 bytes of data. Of course if blockread reads f.e. 32 bytes it saves the double and 32 bytes. But when i want to check the output file size is different from the expected. So i have an input file of 4369 bytes, with 68 blocks of 64 bytes plus a block of 17 bytes (4369-64*68), the output file size must be 68 * 8 + 68 * 64 + 1 * 8 + 1 * 17 = 4921 bytes. But i get 4896, which are 25 bytes less (25 bytes = 8(from double)+17(the last block size)). So, the program don't treat the last data block. The debugger says error 100 (FileIO problem), but what can i do make it work for?

     cuant : Pointer to array[0..63] of byte;
     Repeat
           BytesLeidos := 64;
           blockread(FileIn,Entrada^,BytesLeidos);
           if BytesLeidos>0 then begin
              AjustarBloque(BytesLeidos-1);                     //Substrac
1 for 0-based array bounds
              CuantificarBloque(BytesLeidos-1);                //Substrac 1
for 0-based array bounds
              blockwrite(FileOut,factor,sizeof(double));
              blockwrite(FileOut,cuant^,BytesLeidos*sizeof(byte));
           end;
     Until (EOF(FileIn)) OR (BytesLeidos=0);

TIA

La diferencia entre la teoria y la practica es que en teoria no hay, pero en la practica si

Anton Tichawa
to Eduardo Morras

Hi, Eduardo!

The blockread function has the declaration:

Procedure Blockread (Var F : File; Var Buffer; Var Count : Longint [; var
Result : Longint]);

If the "Result" parameter is not specified, as is the case in your program, an error is generated when there are less than Count bytes available in the input file.

With the "Result" parameter, no error is generated, and "Result" returns the number of bytes actually read from the file.

Try to change your code to:

      bla bla
      var
          BytesRead: Longint;
      Repeat
            BytesLeidos := 64;
            blockread(FileIn,Entrada^,BytesLeidos, BytesRead);
            if BytesRead > 0 then begin
                  bla bla
HTH.

Anton.

Eduardo Morras wrote 39 lines
Hello everyone: I'm new to fpc and i'm trying to port some mac pascal code to win32 console. I have this code to read 64 bytes of data from a file, work with them and save a double and 64 bytes of data. Of course if blockread reads f.e. 32 bytes it saves the double and 32 bytes. But when i want to check the output file size is different from the expected. So i have an input file of 4369 bytes, with 68 blocks of 64 bytes plus a block of 17 bytes (4369-64*68), the output file size must be 68 * 8 + 68 * 64 + 1 * 8 + 1 * 17 = 4921 bytes. But i get 4896, which are 25 bytes less (25 bytes = 8(from double)+17(the last block size)). So, the program don't treat the last data block. The debugger says error 100 (FileIO problem), but what can i do make it work for? cuant : Pointer to array[0..63] of byte; Repeat BytesLeidos := 64; blockread(FileIn,Entrada^,BytesLeidos); if BytesLeidos>0 then begin AjustarBloque(BytesLeidos-1); //Substrac 1 for 0-based array bounds CuantificarBloque(BytesLeidos-1); //Substrac 1 for 0-based array bounds blockwrite(FileOut,factor,sizeof(double)); blockwrite(FileOut,cuant^,BytesLeidos*sizeof(byte)); end; Until (EOF(FileIn)) OR (BytesLeidos=0); TIA La diferencia entre la teoria y la practica es que en teoria no hay, pero en la practica si _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Eduardo Morras
to Anton Tichawa

Thanks for your reply, but the runtime error 100 still appear, and i don't get the hoped output filesize, it must be 4921 bytes (68*64+68*8+1*8+17*1) i get 4968 bytes (69*64+69*8); so the last blockwrite

blockwrite(FileOut,Entrada^,BytesLeidos*sizeof(byte));

writes the entire Entrada^ array (64 bytes) and not BytesLeidos bytes (17 in this case)... so perhaps BlockRead doesn´t change the Result value... don´t know. More clues:?

Also, adding Result to BlockWrite makes no change, run error 100 is there.

I can make public all my code (near 170 lines) if needed.

TIA

Show quoted text 34 lines
The blockread function has the declaration: Procedure Blockread (Var F : File; Var Buffer; Var Count : Longint [; var Result : Longint]); If the "Result" parameter is not specified, as is the case in your program, an error is generated when there are less than Count bytes available in the input file. With the "Result" parameter, no error is generated, and "Result" returns the number of bytes actually read from the file. Try to change your code to: bla bla var BytesRead: Longint; Repeat BytesLeidos := 64; blockread(FileIn,Entrada^,BytesLeidos, BytesRead); if BytesRead > 0 then begin bla bla > I'm new to fpc and i'm trying to port some mac pascal code to > win32 console. I have this code to read 64 bytes of data from a file, work > with them and save a double and 64 bytes of data. Of course if blockread > reads f.e. 32 bytes it saves the double and 32 bytes. But when i want to > check the output file size is different from the expected. So i have an > input file of 4369 bytes, with 68 blocks of 64 bytes plus a block of 17 > bytes (4369-64*68), the output file size must be 68 * 8 + 68 * 64 + 1 * 8 + > 1 * 17 = 4921 bytes. But i get 4896, which are 25 bytes less (25 bytes = > 8(from double)+17(the last block size)). So, the program don't treat the > last data block. The debugger says error 100 (FileIO problem), but what can > i do make it work for?

#The Unix Guru's View of Sex unzip ; strip ; touch ; grep ; finger ; mount ; fsck ; more ; yes ; umount ; sleep

Anton Tichawa
to Eduardo Morras

hi, eduardo!

yes, please send your source code.

bye, anton.

Eduardo Morras wrote 58 lines
Thanks for your reply, but the runtime error 100 still appear, and i don't get the hoped output filesize, it must be 4921 bytes (68*64+68*8+1*8+17*1) i get 4968 bytes (69*64+69*8); so the last blockwrite blockwrite(FileOut,Entrada^,BytesLeidos*sizeof(byte)); writes the entire Entrada^ array (64 bytes) and not BytesLeidos bytes (17 in this case)... so perhaps BlockRead doesn´t change the Result value... don´t know. More clues:? Also, adding Result to BlockWrite makes no change, run error 100 is there. I can make public all my code (near 170 lines) if needed. TIA >The blockread function has the declaration: > >Procedure Blockread (Var F : File; Var Buffer; Var Count : Longint [; var >Result : Longint]); > >If the "Result" parameter is not specified, as is the case in your > program, an error is generated when there are less than Count bytes > available in the input file. > >With the "Result" parameter, no error is generated, and "Result" returns > the number of bytes actually read from the file. > >Try to change your code to: > > bla bla > var > BytesRead: Longint; > Repeat > BytesLeidos := 64; > blockread(FileIn,Entrada^,BytesLeidos, BytesRead); > if BytesRead > 0 then begin > bla bla > > > I'm new to fpc and i'm trying to port some mac pascal code to > > win32 console. I have this code to read 64 bytes of data from a file, > > work with them and save a double and 64 bytes of data. Of course if > > blockread reads f.e. 32 bytes it saves the double and 32 bytes. But > > when i want to check the output file size is different from the > > expected. So i have an input file of 4369 bytes, with 68 blocks of 64 > > bytes plus a block of 17 bytes (4369-64*68), the output file size must > > be 68 * 8 + 68 * 64 + 1 * 8 + 1 * 17 = 4921 bytes. But i get 4896, > > which are 25 bytes less (25 bytes = 8(from double)+17(the last block > > size)). So, the program don't treat the last data block. The debugger > > says error 100 (FileIO problem), but what can i do make it work for? #The Unix Guru's View of Sex unzip ; strip ; touch ; grep ; finger ; mount ; fsck ; more ; yes ; umount ; sleep _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Unknown author
to Eduardo Morras: Hello everyone: I'm new to fpc and i'm trying to port some mac pascal code to win32…

In , on 11/06/02
at 12:46 AM, Eduardo Morras said:

Show quoted text 13 lines
Hello everyone: I'm new to fpc and i'm trying to port some mac pascal code to win32 console. I have this code to read 64 bytes of data from a file, work with them and save a double and 64 bytes of data. Of course if blockread reads f.e. 32 bytes it saves the double and 32 bytes. But when i want to check the output file size is different from the expected. So i have an input file of 4369 bytes, with 68 blocks of 64 bytes plus a block of 17 bytes (4369-64*68), the output file size must be 68 * 8 + 68 * 64 + 1 * 8 + 1 * 17 = 4921 bytes. But i get 4896, which are 25 bytes less (25 bytes = 8(from double)+17(the last block size)). So, the program don't treat the last data block. The debugger says error 100 (FileIO problem), but what can i do make it work for?
Show quoted text 16 lines
cuant : Pointer to array[0..63] of byte; Repeat BytesLeidos := 64; blockread(FileIn,Entrada^,BytesLeidos); if BytesLeidos>0 then begin AjustarBloque(BytesLeidos-1); //Substrac 1 for 0-based array bounds CuantificarBloque(BytesLeidos-1); //Substrac 1 for 0-based array bounds blockwrite(FileOut,factor,sizeof(double)); blockwrite(FileOut,cuant^,BytesLeidos*sizeof(byte)); end; Until (EOF(FileIn)) OR (BytesLeidos=0);

What size have you set the block size? By default, Blockread/write does I/O in 128 byte blocks. You can change this in the reset, rewrite statement. The count value refers to the number of blocks to read or write. Setting count to 64 would result in a transfer of 128 * 64 bytes or 8192 bytes.

A common mistake (at least common for me) is to forget that the count parameter refers to the number of blocks and not the number of bytes and that only full blocks are read or written. If you have read and write variable numbers of bytes, then set the block size to one and then the count parameter will always be the number of bytes.

Hope this helps

Rolf Grunsky

----------------------------------------------------------------- Truth in her dress finds facts too tight In fiction she moves with ease. Rabinranath Tagore -----------------------------------------------------------------