A
Antonio Maschio
Hi,
I've got the following problem:
I wrote a program A that uses fprintf to stdout to output some strings
or numbers as result of some commands.
Now I want to improve this program A, and I want to write a debugger B
that prints information on a new line, for each command of A, and this
output is interspersed with the program A output, of course.
I'd want to know, for any debugger line, if the program A (not the
debugger) is in the middle of the terminal, or has just printed a "\n".
On Mac OS X, using ftell(stdout) in two different moments (at the end of
line n and at beginning of line n+1), subtracting the long values I get,
I obtain a zero if program A didn't print anything, or a positive value
if it printed something; in the first case I simply print the debugging
information, in the second case I print a "\n" before the debugging
information to go to a new line
The problem is that this work on the Mac OS X terminal (which is
emulated), but not a real 80-columns terminal under Linux (in this case,
the long value returned is always -1).
Any idea? I'd like something portable and ANSI C, to work on any
environment.
Thanks in advance to anyone answering.
-- Antonio
Tried on:
Mac OS X Tiger 4.11 (gcc 4.X)
Linux RedHat 9A (gcc 3.X)
Linux Fedora Core 4 (gcc 3.2)
(old linux system, uhu?)
I've got the following problem:
I wrote a program A that uses fprintf to stdout to output some strings
or numbers as result of some commands.
Now I want to improve this program A, and I want to write a debugger B
that prints information on a new line, for each command of A, and this
output is interspersed with the program A output, of course.
I'd want to know, for any debugger line, if the program A (not the
debugger) is in the middle of the terminal, or has just printed a "\n".
On Mac OS X, using ftell(stdout) in two different moments (at the end of
line n and at beginning of line n+1), subtracting the long values I get,
I obtain a zero if program A didn't print anything, or a positive value
if it printed something; in the first case I simply print the debugging
information, in the second case I print a "\n" before the debugging
information to go to a new line
The problem is that this work on the Mac OS X terminal (which is
emulated), but not a real 80-columns terminal under Linux (in this case,
the long value returned is always -1).
Any idea? I'd like something portable and ANSI C, to work on any
environment.
Thanks in advance to anyone answering.
-- Antonio
Tried on:
Mac OS X Tiger 4.11 (gcc 4.X)
Linux RedHat 9A (gcc 3.X)
Linux Fedora Core 4 (gcc 3.2)
(old linux system, uhu?)