Sign in Join

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

Mailing lists / fpc-pascal / 2009-11

sysutils.beep doesn't beep under Linux?

38 messages · 12 people · –

Reply by email Subscribe to this list Your subscription

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

Bruce Bauman

I'm porting some code which "beeps" the console. When I use sysutils.beep() it doesn't work under Linux.

What's the easiest way to accomplish this?

Thanks.

-- Bruce
CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

David Butler
to Bruce Bauman

Try writing Ctrl-G (#7) out to the terminal.

2009/11/18 Bruce Bauman :

Show quoted text 18 lines
I'm porting some code which "beeps" the console. When I use sysutils.beep() it doesn't work under Linux. What's the easiest way to accomplish this? Thanks. -- Bruce CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed.  If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender. _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Graeme Geldenhuys
to Bruce Bauman: I'm porting some code which "beeps" the console. When I use sysutils.beep() it doesn't…
Bruce Bauman wrote
I'm porting some code which "beeps" the console. When I use sysutils.beep() it doesn't work under Linux.

Looking at it's implementation in FPC 2.4.0-rc1 (Linux) I can indeed see why it doesn't beep. :-)

--------------------------
procedure Beep;
begin
end;
--------------------------

As David suggested, simply write #7 character to the console and it will beep. I wonder if we can't use that for the Linux sysutils.beep implementation.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 17 lines
Bruce Bauman wrote: > I'm porting some code which "beeps" the console. When I use > sysutils.beep() it doesn't work under Linux. Looking at it's implementation in FPC 2.4.0-rc1 (Linux) I can indeed see why it doesn't beep. :-) -------------------------- procedure Beep; begin end; -------------------------- As David suggested, simply write #7 character to the console and it will beep. I wonder if we can't use that for the Linux sysutils.beep implementation.

No, because you don't know if a terminal is available or whether standard output is writable.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: No, because you don't know if a terminal is available or whether standard output is…
Michael Van Canneyt wrote
No, because you don't know if a terminal is available or whether standard output is writable.

As far as I know stdout is always available for Linux. Even if I compile applications for X11 and launch them from a desktop icon, I can do writeln() calls without problems (unlike under Windows which will throw an error).

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

Show quoted text 7 lines
> No, because you don't know if a terminal is available or whether > standard output is writable. As far as I know stdout is always available for Linux. Even if I compile applications for X11 and launch them from a desktop icon, I can do writeln() calls without problems (unlike under Windows which will throw an error).

And did you test daemons?

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: As far as I know stdout is always available for Linux. Even if I compile applications for…
Graeme Geldenhuys wrote 9 lines
Michael Van Canneyt wrote: > > No, because you don't know if a terminal is available or whether > standard output is writable. As far as I know stdout is always available for Linux. Even if I compile applications for X11 and launch them from a desktop icon, I can do writeln() calls without problems (unlike under Windows which will throw an error).

No, the application can (for instance almost all daemons do) close stdout. Programs that use ncurses will also be messed-up.

For CGI programs, stdout is also reserved for the HTML output. Imagine someone else's code doing a beep, and it ends up in your HTML output.

Before you think that these are far-fetched:

If you'll remember, tiOPF had some very common (but nasty) windows-only constructs like showing message boxes deeply buried in core functionality. Works fine. Till I come along and want to run the thing on Linux. Bummer...

By that rationale: no beep() on linux.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
No, the application can (for instance almost all daemons do) close stdout. Programs that use ncurses will also be messed-up.

Ah, ok.

For CGI programs, stdout is also reserved for the HTML output. Imagine someone else's code doing a beep, and it ends up in your HTML

I can't say I have ever seen a HTML page that beeps, but then again you never know. ;-)

If you'll remember, tiOPF had some very common (but nasty) windows-only constructs like showing message boxes deeply buried in core functionality. Works fine. Till I come along and want to run the thing on Linux. Bummer...

Please let me know if this is still the case, so those + translations can be resolved. It took me considerable time to fix tiOPF Core to run on a headless Linux box. So if any strange "gui" message boxes appear in tiOPF Core, I would be very surprised. Hard-coded English text is a different issue.

By that rationale: no beep() on linux.

Funny you say that. When I started working on fpGUI's DocView (help viewer) and viewed various OS/2 INF files, I couldn't get the damn program to stop beeping at me! It took me a good two weeks before I found the problem - it was #7 characters used in the IBM INF documents!

So I can honestly say my Linux system CAN beep. ;-)

Possible alternatives:
Maybe under Linux the system.beep() can make a sound if stdout is available, otherwise write the word "beep" to the console (like the old silent movies did on screen), or flash the Scroll Lock keyboard light. :-)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 25 lines
Michael Van Canneyt wrote: > > No, the application can (for instance almost all daemons do) close > stdout. Programs that use ncurses will also be messed-up. Ah, ok. > For CGI programs, stdout is also reserved for the HTML output. > Imagine someone else's code doing a beep, and it ends up in your HTML I can't say I have ever seen a HTML page that beeps, but then again you never know. ;-) > If you'll remember, tiOPF had some very common (but nasty) > windows-only constructs like showing message boxes deeply buried in > core functionality. Works fine. Till I come along and want to run the > thing on Linux. Bummer... Please let me know if this is still the case, so those + translations can be resolved. It took me considerable time to fix tiOPF Core to run on a headless Linux box. So if any strange "gui" message boxes appear in tiOPF Core, I would be very surprised. Hard-coded English text is a different issue.

As far as I know, they were removed at the first "complaint" from my side, but I just wanted to make a point, namely: you don't know what system your code will end up on.

Show quoted text 10 lines
> By that rationale: no beep() on linux. Funny you say that. When I started working on fpGUI's DocView (help viewer) and viewed various OS/2 INF files, I couldn't get the damn program to stop beeping at me! It took me a good two weeks before I found the problem - it was #7 characters used in the IBM INF documents! So I can honestly say my Linux system CAN beep. ;-)

It can, of course...

Show quoted text 5 lines
Possible alternatives: Maybe under Linux the system.beep() can make a sound if stdout is available, otherwise write the word "beep" to the console (like the old silent movies did on screen), or flash the Scroll Lock keyboard light. :-)

No, see the ncurses/cgi use cases.

Michael.

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Ah, ok. I can't say I have ever seen a HTML page that beeps, but then again you never…

In our previous episode, Graeme Geldenhuys said:

Possible alternatives: Maybe under Linux the system.beep() can make a sound if stdout is available, otherwise write the word "beep" to the console (like the old silent movies did on screen), or flash the Scroll Lock keyboard light. :-)

Sure. How to detect this? What stdout exactly points to, if I can toggle scroll lock etc?

If you are really good at this kind of stuff, please have a look at the video, keyboard and mouse unit. They can also use sb who is good at this kind of stuff. (which is hell under *nix)

Reply by email

Bruce Bauman
to Bruce Bauman: I'm porting some code which "beeps" the console. When I use sysutils.beep() it doesn't…

I'm porting some code which called "system". Is there an equivalent under FPC, or do I need to use FpFork/FpExecV?

-- Bruce
CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Marco van de Voort
to Bruce Bauman

In our previous episode, Bruce Bauman said:

I'm porting some code which called "system". Is there an equivalent under FPC, or do I need to use FpFork/FpExecV?

unix.fpsystem both with short annd ansistring arguments.

Reply by email

Bruce Bauman
to Bruce Bauman: I'm porting some code which called "system". Is there an equivalent under FPC, or do I…

I need to convert the st_time field of the record returned by BaseUnix.FpStat to the year, month, day, hour, minute and second and need to compensate for the local timezone.

I've read over the RTL documentation and am thoroughly confused. Some of the documentation of the interfaces say that they are unimplemented and will raise an exception. Others just appear to be missing.

How can I accompilish this? Any example code?

-- Bruce

CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Jonas Maebe
to Bruce Bauman
Bruce Bauman wrote
I need to convert the st_time field of the record returned by BaseUnix.FpStat to the year, month, day, hour, minute and second and need to compensate for the local timezone.

The dateutils unit contains the following functions that you can use:

Function DateTimeToUnix(const AValue: TDateTime): Int64;
Function UnixToDateTime(const AValue: Int64): TDateTime;

Once you have a TDateTime, you can use DecodeDateTime() to extract the various components.

I've read over the RTL documentation and am thoroughly confused. Some of the documentation of the interfaces say that they are unimplemented and will raise an exception.

Which ones?

Others just appear to be missing.

Which ones?

Jonas

Reply by email

Graeme Geldenhuys
to Unknown author

The joys of Linux. I have neither /dev/pcspkr or xbell available on my Ubuntu 9.08.2 system. :-(

Graeme.

Show quoted text 20 lines
On Saturday 21 November 2009 08:56:53 Martin Schreiber wrote: > On Friday 20 November 2009 21:24:17 Jorge Aldo G. de F. Junior wrote: > > arent there a /dev/something device for pcspeaker ? /dev/pcspkr > > With X11 one can use xbell(). > > Martin > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Andrew Haines
Andrew Haines wrote 6 lines
Michael Van Canneyt wrote: > > By that rationale: no beep() on linux. > Can beep be made a procvar?

I have been thinking along similar lines, and made an implementation for beep that works with a handler. It's not yet committed, as I was trying to make an LCL plugin which would work on Linux/X11.

Michael.

Reply by email

Jonas Maebe
to Michael Van Canneyt
Michael Van Canneyt wrote
I have been thinking along similar lines, and made an implementation for beep that works with a handler. It's not yet committed, as I was trying to make an LCL plugin which would work on Linux/X11.

Wouldn't it be better to do nothing by default under *nix? There are so many situations where writing #7 won't work or can even break things (redirection, daemons), that making beep perform this action by default seems like a bad idea to me. Especially since if it does nothing, then programs expecting to beep won't fail (while programs not expecting random #7 characters in their output can suddenly start failing with the new behaviour). Unless users are familiar with the inner workings of Unix terminals, they won't expect that beeping can corrupt their program's output.

Jonas

Reply by email

Jonas Maebe
Bruce Bauman wrote 15 lines
If you look at the HTML documentation: http://www.freepascal.org/docs-html/rtl/dateutils/datetimetounix.html under Description it says: Not yet implemented under "Errors" it says: Currently, trying to use this function will raise an exception ditto for http://www.freepascal.org/docs-html/rtl/dateutils/unixtodatetime.html Is the HTML documentation out-of-date/incorrect?

It seems that it's out-of-date. The 2.4.0rc1 pdf documentation correctly describes these functions.

Jonas

Reply by email

Bruce Bauman
to Jonas Maebe

Thanks. I am now using them and they are working for me.

Upon further investigation I was that a bug was opened for the documentation.

Thanks again.

-- Bruce

________________________________

Earlier message 31 lines
From: on behalf of Jonas Maebe Sent: Mon 11/23/2009 5:19 AM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] convert st_mtime from BaseUnix.FpStat to year, month,day, hour, minute, sec On 23 Nov 2009, at 00:42, Bruce Bauman wrote: > If you look at the HTML documentation: > > http://www.freepascal.org/docs-html/rtl/dateutils/datetimetounix.html > > under Description it says: > > Not yet implemented > > under "Errors" it says: > > Currently, trying to use this function will raise an exception > > ditto for http://www.freepascal.org/docs-html/rtl/dateutils/unixtodatetime.html > > Is the HTML documentation out-of-date/incorrect? It seems that it's out-of-date. The 2.4.0rc1 pdf documentation correctly describes these functions. Jonas

Reply by email

Jonas Maebe
to Jonas Maebe: Wouldn't it be better to do nothing by default under *nix? There are so many situations…
Jonas Maebe wrote 18 lines
On 21 Nov 2009, at 14:20, Michael Van Canneyt wrote: > I have been thinking along similar lines, and made an > implementation for beep > that works with a handler. It's not yet committed, as I was trying > to make an > LCL plugin which would work on Linux/X11. Wouldn't it be better to do nothing by default under *nix? There are so many situations where writing #7 won't work or can even break things (redirection, daemons), that making beep perform this action by default seems like a bad idea to me. Especially since if it does nothing, then programs expecting to beep won't fail (while programs not expecting random #7 characters in their output can suddenly start failing with the new behaviour). Unless users are familiar with the inner workings of Unix terminals, they won't expect that beeping can corrupt their program's output.

Or maybe at least a check could be added whether stdout is a tty. It will probably still break when crt is used, but at least redirected output won't be corrupted anymore.

Jonas

Reply by email

Michael Van Canneyt
to Jonas Maebe
Jonas Maebe wrote 25 lines
On 22 Nov 2009, at 19:02, Jonas Maebe wrote: > > On 21 Nov 2009, at 14:20, Michael Van Canneyt wrote: > >> I have been thinking along similar lines, and made an implementation for >> beep >> that works with a handler. It's not yet committed, as I was trying to make >> an >> LCL plugin which would work on Linux/X11. > > Wouldn't it be better to do nothing by default under *nix? There are so > many situations where writing #7 won't work or can even break things > (redirection, daemons), that making beep perform this action by default > seems like a bad idea to me. Especially since if it does nothing, then > programs expecting to beep won't fail (while programs not expecting random > #7 characters in their output can suddenly start failing with the new > behaviour). Unless users are familiar with the inner workings of Unix > terminals, they won't expect that beeping can corrupt their program's > output. Or maybe at least a check could be added whether stdout is a tty. It will probably still break when crt is used, but at least redirected output won't be corrupted anymore.

Correct. I'll add a check.

Michael.

Reply by email

Bruce Bauman
to Bruce Bauman: I'm porting some code which called "system". Is there an equivalent under FPC, or do I…

I'm trying to port/debug some ugly Pascal code.

Is there a way I can tell if an arbitrary address is within the heap or stack?

I want to do something like:

Assert(ValidHeapAddress(a))

Assert(ValidStackAddress(a))

to catch potential errors in the code.

I'm guessing any address between "end" and the current brk is a valid heap address.

Thanks.

-- Bruce

CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Jonas Maebe
to Bruce Bauman
Bruce Bauman wrote 6 lines
Is there a way I can tell if an arbitrary address is within the heap or stack? I want to do something like: Assert(ValidHeapAddress(a))

That is not possible without installing your own memory manager that tracks all allocations. Also keep in mind that this will never work for memory allocated by code outside your application (in some external library).

heaptrc has a function with similar functionality called checkpointer(), but a) it's not exported
b) it checks for more than just heap allocations (it also checks for global data and stack) c) it only works on some targets (the ones supported by -gc in 2.4.0 -- earlier FPC versions did not contain any checks regarding supported targets for this feature, so it just caused crashes on some platforms) and has not been maintained for ages (so I have no idea as to what its status is).

Assert(ValidStackAddress(a))

This can be done by checking whether the address is <= sptr and >= stackbottom.

to catch potential errors in the code.

If you are working on an Intel Linux or Mac OS X/i386 10.5.x platform, I would strongly recommend Valgrind.

I'm guessing any address between "end" and the current brk is a valid heap address.

That is only true on some old systems (such as go32v2, and possibly some very old Linux FPC versions). In most systems, the heap is no longer a contiguous region.

Jonas

Reply by email

Anthony Walter
to Bruce Bauman: I'm trying to port/debug some ugly Pascal code. Is there a way I can tell if an arbitrary…
Bruce Bauman wrote
I’m trying to port/debug some ugly Pascal code. Is there a way I can tell if an arbitrary address is within the heap or stack?

Without hooking/replacing the memory manager, I don't believe you can handle memory tracking this information. And even if you did hook replace the memory manager it would still fail in places where you interface with shared libraries that handle their own memory management.

If don't mind using OS specific functions, Windows provides ways to query process memory base address range and memory querying (which returns the number of consecutive pages available for writing). For that look at GetSystemInfo for memory page information, OpenProcess with memory query flags (if you don't have the rights use AdjustTokenPrivileges), and VirtualQueryEx to find consecutive valid memory pages. I believe VirtualQueryEx works upon all process system memory (code/stack/heap).

Reply by email

Anthony Walter
to Anthony Walter

Oh and for querying stack pointers, there should be an OS function somewhere to give you the base stack pointer address and available stack size, though I don't know the names of functions off the top of my head.

Reply by email

Bruce Bauman
to Bruce Bauman: I need to convert the st_time field of the record returned by BaseUnix.FpStat to the…

If I am compiling a file bar.pas, but I want the resulting .o filename to be something different, is there a way to do this?

For example, I want the object filename to be foo__bar.o, but the source file is just bar.pas.

Right now we can get this to work by creating a symlink from foo__bar.pas to bar.pas, running the compiler, then deleting the symlink, but it seems like there should be a better way.

Thanks.

-- Bruce

CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Jonas Maebe
to Bruce Bauman
Bruce Bauman wrote
If I am compiling a file bar.pas, but I want the resulting .o filename to be something different, is there a way to do this?

No, there is not. The unit searching logic in the compiler requires the .ppu files and .o files to be named the same, and .ppu files are named the same as the units they were compiled from (so the compiler can find them when you use a unit).

Jonas

PS: please do not reply to existing messages when starting a new thread, but create a new message instead. Replying messes up threading in the web archive and in many mail clients.

Reply by email

Bruce Bauman
to Jonas Maebe

Will it cause problems if the unit name (e.g. unit foo__bar;) doesn't match the source filename?

I want to source filename to remain unchanged (e.g. bar.pas), but the unit name (and .ppu and .o filenames) to be different (e.g. foo__bar.o, foo__bar.ppu, unit foo__bar). Thus, the .ppu files are named the same as the object file and unit, but different from the source filename.

We are porting a large body of existing code and don't want to rename all of the source files if we can avoid it.

-- Bruce

CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Jonas Maebe
to Bruce Bauman
Bruce Bauman wrote 11 lines
Will it cause problems if the unit name (e.g. unit foo__bar;) doesn't match the source filename? I want to source filename to remain unchanged (e.g. bar.pas), but the unit name (and .ppu and .o filenames) to be different (e.g. foo__bar.o, foo__bar.ppu, unit foo__bar). Thus, the .ppu files are named the same as the object file and unit, but different from the source filename. We are porting a large body of existing code and don't want to rename all of the source files if we can avoid it.

You can use the -Un command line option, in which case the compiler will not check that the unit name matches the source file name. In this case, you have to explicitly mention the source file name every time you use this unit though, since otherwise the compiler won't be able to find it. See e.g. http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/tw1279.pp and http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/uw1279.pp

Jonas

Reply by email

DONALD PEDDER
to Bruce Bauman: If I am compiling a file bar.pas, but I want the resulting .o filename to be something…

Just write a script to call the program and do the re-name.

e.g. create call_bar.pas_with_rename in a directory that's in your path with following code...
set homedir=(where-ever this stuff lives)
cd $homedir
bar.pas
mv bar.o ${1}.o

Then you can just run "call_bar.pas_with_rename foo_bar"

I do this with heaps of stuff in DOS (but with batch-files obviously :-) ).

Bruce Bauman wrote 29 lines
If I am compiling a file bar.pas, but I want the resulting .o filename to be something different, is there a way to do this? For example, I want the object filename to be foo__bar.o, but the source file is just bar.pas. Right now we can get this to work by creating a symlink from foo__bar.pas to bar.pas, running the compiler, then deleting the symlink, but it seems like there should be a better way. Thanks. -- Bruce CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Bruce Bauman
to Bruce Bauman: I'm porting some code which called "system". Is there an equivalent under FPC, or do I…

I've read through the documentation several times and cannot figure this out. The documentation is pretty unclear on this.

I want a command line equivalent to {$PACKRECORDS 1}. Is there a way to do this via the command line?

Thanks.

-- Bruce

CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email