Sign in Join

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

Mailing lists / fpc-pascal / 2001-07

Problems with "Write" and/or ANSI-Emulation from fpc

12 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

Martin

hello...

i have problems with "Write" and/or ANSI-Emulation from fpc. as first please take a look at my testing source:

----CUT------------CUT------------CUT------------CUT------------CUT------------CUT------
uses crt;
var
  line  : ansistring;
  i     : byte;
begin
  writeln(#027,'[2J');		// ansi-sequence - clear screen
  line := '1234567890abcdef';
  for i:= 1 to length(line) do begin
    write (#027, '[s');         // ansi-sequence - position save
    write ('',ord(line[i]),''); // ansi-sequence - write data
    write (#027, '[u');         // ansi-sequence - position restore
    write (#027, '[4C');        // ansi-sequence - move cursor 4 tokens to the right
  end;
end.
----CUT------------CUT------------CUT------------CUT------------CUT------------CUT------

the output of the program is exactly:
--------------------------------------------------------------------------- 49 50 51 52 53 54 55 56 57 48 97
98 99 100 101 102
---------------------------------------------------------------------------

but why ? normaly the output must be:
--------------------------------------------------------------------------- 49 50 51 52 53 54 55 56 57 48 97 98 99 100 101 102 ---------------------------------------------------------------------------

has fpc an own ansi emulation in write/writlen procedures ? if so, there is an bug in the ansi-code sequence/s "ESC[s" and/or "ESC[u".

on the standard linux console with the shell-command echo the output is 100% ok.

can you help me to fix this problem ?

jc
to Martin
Show quoted text 18 lines
the output of the program is exactly: --------------------------------------------------------------------------- 49 50 51 52 53 54 55 56 57 48 97 98 99 100 101 102 --------------------------------------------------------------------------- but why ? normaly the output must be: --------------------------------------------------------------------------- 49 50 51 52 53 54 55 56 57 48 97 98 99 100 101 102 --------------------------------------------------------------------------- has fpc an own ansi emulation in write/writlen procedures ? if so, there is an bug in the ansi-code sequence/s "ESC[s" and/or "ESC[u". on the standard linux console with the shell-command echo the output is 100% ok. can you help me to fix this problem ?

I've had some similar strange results with ANSI and FPC's write function under Linux. I've never narrowed it down to a specific problem though, so it could be FPC or my code itself...

Gene Buckle
to jc

Is there a known method for processing signals such as SIGTERM and SIGQUIT? I need to be able to execute some code when either one of those signals are sent to my application.

thanks!

g.

Adam Naumowicz
to Gene Buckle
Gene Buckle wrote
Is there a known method for processing signals such as SIGTERM and SIGQUIT? I need to be able to execute some code when either one of those signals are sent to my application.

To install your own signal handler use the Signal function in 'linux' unit like that:

var NewSignal, OldSigInt : SignalHandler;
procedure CatchSignal(aSig : Integer);cdecl;
begin
  case aSig of
    SIGQUIT : do_something1;
    SIGTERM : do_something2;
  end;
end;

...

NewSignal:=SignalHandler(CatchSignal);
OldSigInt:=Signal(SIDQUIT,NewSignal);
OldSigInt:=Signal(SIGTERM,NewSignal);

Regards,
Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Gene Buckle
to Adam Naumowicz: To install your own signal handler use the Signal function in 'linux' unit like that: var…

Thanks Adam! This is perfect.

g.

Adam Naumowicz wrote 38 lines
On Fri, 27 Jul 2001, Gene Buckle wrote: > Is there a known method for processing signals such as SIGTERM and > SIGQUIT? I need to be able to execute some code when either one of those > signals are sent to my application. To install your own signal handler use the Signal function in 'linux' unit like that: var NewSignal, OldSigInt : SignalHandler; procedure CatchSignal(aSig : Integer);cdecl; begin case aSig of SIGQUIT : do_something1; SIGTERM : do_something2; end; end; .... NewSignal:=SignalHandler(CatchSignal); OldSigInt:=Signal(SIDQUIT,NewSignal); OldSigInt:=Signal(SIGTERM,NewSignal); Regards, Adam Naumowicz -------------------------------------- WWW: http://math.uwb.edu.pl/~adamn/ -------------------------------------- _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marco van de Voort
to Michael Van Canneyt: See the signal or sigaction calls in the linux unit documentation. They contain example…
Show quoted text 8 lines
On Fri, 27 Jul 2001, Gene Buckle wrote: > Is there a known method for processing signals such as SIGTERM and > SIGQUIT? I need to be able to execute some code when either one of those > signals are sent to my application. See the signal or sigaction calls in the linux unit documentation. They contain example programs.

BTW: I implemented Signal() for FreeBSD too (based on SigAction)

Adam Naumowicz
to Gene Buckle: Adam, here the compiler is telling me that the incorrect number of parameters have been…
Gene Buckle wrote
> NewSignal:=SignalHandler(CatchSignal); Adam, here the compiler is telling me that the incorrect number of parameters have been specified. Ideas?

Sorry, I often use the Delphi syntax compatibility switch and that accepts the code. But in your case you have to add the address operator like: NewSignal:=SignalHandler(@CatchSignal);
I think the typecast is also not neccesary when you change the type of CatchSignal formal parameter to Longint.
Regards,
Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Peter Vreman
to jc: I've had some similar strange results with ANSI and FPC's write function under Linux. …
you wrote 22 lines
>the output of the program is exactly: >--------------------------------------------------------------------------- >49 50 51 52 53 54 55 56 57 48 97 >98 99 100 101 102 >--------------------------------------------------------------------------- > >but why ? normaly the output must be: >--------------------------------------------------------------------------- >49 50 51 52 53 54 55 56 57 48 97 98 99 100 101 102 >--------------------------------------------------------------------------- > >has fpc an own ansi emulation in write/writlen procedures ? >if so, there is an bug in the ansi-code sequence/s "ESC[s" and/or "ESC[u". > >on the standard linux console with the shell-command echo the output is >100% ok. > >can you help me to fix this problem ? I've had some similar strange results with ANSI and FPC's write function under Linux. I've never narrowed it down to a specific problem though, so it could be FPC or my code itself...

Don't use the crt unit if you want to write the ansi codes yourself.

Peter

Gene Buckle
to Adam Naumowicz: Sorry, I often use the Delphi syntax compatibility switch and that accepts the code. But…
Adam Naumowicz wrote 10 lines
On Fri, 27 Jul 2001, Gene Buckle wrote: > > NewSignal:=SignalHandler(CatchSignal); > > Adam, here the compiler is telling me that the incorrect number of > parameters have been specified. Ideas? Sorry, I often use the Delphi syntax compatibility switch and that accepts the code. But in your case you have to add the address operator

like:

Show quoted text 6 lines
NewSignal:=SignalHandler(@CatchSignal); I think the typecast is also not neccesary when you change the type of CatchSignal formal parameter to Longint. Regards, Adam Naumowicz

Thanks. I figured that out about an hour after I sent the message. Doh! :)

g.

http://www.f15sim.com - The only one of its kind.