[comp.sys.atari.st] OOPS; C escape code *syntax* needed...

kuento@kuhub.cc.ukans.edu (01/29/91)

In article <28140.279f603c@kuhub.cc.ukans.edu>, kuento@kuhub.cc.ukans.edu writes:
> As opposed to my usual pleas for help with my drive, my brother in New
> York (who also has an Atari, but no modem), has asked me to request of
> the Net the following:
>     He's doing C programming, and needs to know all the various
> "escape codes" that control the printer from directly within the C
> program. He says he knows *some* of the codes, but that there are
> some he doesn't know, and he's looking for a list of some sort that
> describes them all...or something along those lines. Those of you

I apologize - he wasn't very good at explaining to me what he needed
to know: 
    He has an Epson FX86E printer, and knows one version of the codes,
but he doesn't know which form (hex, octal, etc) should be used in the
C program, and he doesn't know whether straight conversion from one
system to another is possible. He needs examples of source code that
show the proper programming syntax for using the escape codes, and how
exactly to convert codes, if it's needed. He says he can get some of
them to work in hex, others work in octal, some don't work in either,
and he's not sure if it's the codes that are wrong or (more likely)
the syntax he's using works with some codes and not others. Thanks again,
-------(please include "DY" in subj header of mail to this user)--------
Doug "Speaker-To-Insects" Yanega      "UT!"       Bitnet: KUENTO@UKANVAX
My card: 0 The Fool       (Snow Museum, Univ. of KS, Lawrence, KS 66045)
"Bobby, jiggle Grandpa's rat so it looks alive."   "Roota! Voota! ZOOT!"

wolfram@cip-s02.informatik.rwth-aachen.de (Wolfram Roesler) (01/31/91)

kuento@kuhub.cc.ukans.edu writes:

>I apologize - he wasn't very good at explaining to me what he needed
>to know: 
>    He has an Epson FX86E printer, and knows one version of the codes,
>but he doesn't know which form (hex, octal, etc) should be used in the
>C program, and he doesn't know whether straight conversion from one
>system to another is possible. He needs examples of source code that
>show the proper programming syntax for using the escape codes, and how
>exactly to convert codes, if it's needed. He says he can get some of
>them to work in hex, others work in octal, some don't work in either,
>and he's not sure if it's the codes that are wrong or (more likely)
>the syntax he's using works with some codes and not others. Thanks again,

The system in which a number is displayed doesnt change anything about the
number itself, and in C it is possible to use numbers in oct, dec and hex
very easily. For instance, if you wish to send a number to the printer
in binary format (that means send the number 123 and not the string "123"),
use the following form
	fputs("\123",fp);
where 123 is the number in octal and fp is a FILE* opened for the printer.
(you can use any 3-digit octal number after the backslash.)
If you have the number in a different format, no problem:

	printf("%c",(char)123);		sends decimal 123
	printf("%c",(char)0x123);	sends hex 123
	printf("%c",(char)0123);	sends octal 123 as well.

For example, to send a control string like ESC 1, use 
	printf("%c%c",(char)27,(char)1);

But watch out: some printer codes don't require the number in binary but
in ascii, so you would have to send to send the ascii code for the character
'1' (which is 48) instead of the number 1. No problem with C: simply change
1 to '1' to get the ascii code. You could do things more simply then, however:
	printf("%c%c",(char)27,'1')	will do the same as
	printf("%c%d",(char)27,1)	or as
	printf("%c1",(char)27)		or even as
	fputs("\0331",fp)

So find out first if the printer code is binary or ascii. Epson printers
usually understand both.

BTW: the cast to char in the examples above shouldnt be vital but is recommended.

Sayonara

Wolfram