[comp.unix.questions] ASCII question

andrew@cs.arizona.edu (Andrei V. Zaitsev) (03/28/91)

I have a question about ASCII code. Can I be sure that character
with code 13 will return cursor to the beginning of the line
independently of the terminal type ?
I need this ability for my C program but I do not want to use
curses package because it results in the huge size of the
executable file.

barmar@think.com (Barry Margolin) (03/28/91)

In article <1270@caslon.cs.arizona.edu> andrew@cs.arizona.edu (Andrei V. Zaitsev) writes:
>I have a question about ASCII code. Can I be sure that character
>with code 13 will return cursor to the beginning of the line
>independently of the terminal type ?

If you're willing to assume that you're talking to an ASCII terminal you
should be pretty safe.  Then again, any ASCII system that supports
non-ASCII terminals probably also has a tty driver that automatically
converts from ASCII; however, if your program writes in raw mode this
conversion would be bypassed.

You're also probably safer using '\r' rather than '\015', since the former
will work properly on a system that uses something other than ASCII
internally.

Some terminals can be configured to perform a line feed automatically after
receiving carriage return.  However, since most Unix software doesn't
expect this, it's safe to assume that the terminal is not in this mode.

--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

gwyn@smoke.brl.mil (Doug Gwyn) (03/28/91)

In article <1270@caslon.cs.arizona.edu> andrew@cs.arizona.edu (Andrei V. Zaitsev) writes:
>I have a question about ASCII code. Can I be sure that character
>with code 13 will return cursor to the beginning of the line
>independently of the terminal type ?
>I need this ability for my C program but I do not want to use
>curses package because it results in the huge size of the
>executable file.

If you're sure that USASCII is used, then the answer is "Yes, if ANYthing
simple will return the cursor this is the one."

In C, try using the escape sequence \r in character constants and string
literals.  That should port to non-ASCII environments also.