[comp.lang.c] CTRL

ado@elsie.UUCP (Arthur David Olson) (11/12/86)

One possibility for emulating most of the Reiser cpp's handling of
	#define CTRL(x) ('x' & 037)
in proposed draft ANSI C is:
	#define CTRL_A	('A' & 037)
	#define CTRL_B	('B' & 037)
	...
	#define CTRL_Z	('Z' & 037)
	#define CTRL_a	('a' & 037)
	...
	#define CTRL_z	('z' & 037)
	#define CTRL(x)	CTRL_ ## x

A deficiency here is that the handling of constructs such as
	CTRL([)
isn't emulated. . .but the above approach would handle most existing code.

Or, at any rate, it would handle most existing code if the result of catenating
preprocessing tokens with the "##" operator is itself macro expanded.
Whether the Standard currently calls for such rescanning,
whether the Standard will call for such rescanning in the future,
and whether such rescanning is advisable are all open questions.
--
	UUCP: ..decvax!seismo!elsie!ado   ARPA: elsie!ado@seismo.ARPA
	DEC, VAX, Elsie & Ado are Digital, Borden & Ampex trademarks.

jsdy@hadron.UUCP (Joseph S. D. Yao) (11/13/86)

In article <1319@sunybcs.UUCP> colonel@sunybcs.UUCP (Col. G. L. Sicherman) writes:
>) >But. . .is there a way to write an ANSI cpp version of
>) >        #define CTRL(c)
>		   ...  What's wrong with this old trick?
>	#define Q "
>	#define CTRL(z) (Q z "[1]^0100)

The XOR, (x^0100), will not generally work.  Use (x&037).  Also,
there was some concern that "..."[x] will not work where a
constant is required, such as in a case statement.
-- 

	Joe Yao		hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}
			jsdy@hadron.COM (not yet domainised)

karl@haddock.UUCP (Karl Heuer) (11/13/86)

In article <614@hadron.UUCP> jsdy@hadron.UUCP (Joseph S. D. Yao) writes:
>The XOR, (x^0100), will not generally work.  Use (x&037).

True if you want the domain of the function to include lowercase.  I never
do; e.g. I claim that the proper name for EOT is "^D" rather than "^d".  If
you're willing to make this restriction, then the XOR has the advantage of
allowing the use of CTRL('?') for DEL, which is a widely (though by no means
universally) accepted notation.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

jsdy@hadron.UUCP (Joseph S. D. Yao) (11/24/86)

In article <170@haddock.UUCP> karl@haddock.UUCP (Karl Heuer) writes:
>In article <614@hadron.UUCP> jsdy@hadron.UUCP (Joseph S. D. Yao) writes:
>>The XOR, (x^0100), will not generally work.  Use (x&037).
>True if you want the domain of the function to include lowercase.  I never
>do; e.g. I claim that the proper name for EOT is "^D" rather than "^d".

Your privilege.  My definition of control char, umpteen years ago,
just said that no bits not in the lower five were clear.  Said
nothing about "proper" names for them (othere than NUL, EOT, etc.).
Most people make a control-d without hitting the shift key.

Further, Control-ESC is ESC, not '['; and Control-TAB is TAB, not
'I'.  Yes, people are unlikely to do this in C code.  But that's
part of the reason I reacted as I did.

>allowing the use of CTRL('?') for DEL, which is a widely (though by no means
>universally) accepted notation.

My surprise.  I'd thought that Berkeley introduced this notation.
At any rate I'd never heard or seen it before 2BSD.  (My experience
before that had covered a variety of hardware, software, and
documentation.)  If anyone has a VERIFIABLE pre-BSD reference for
use of ^?, I'd appreciate your MAILing to me.  Summary will be
posted.  (I can't remember any non-BSD-derived version of the Unix(R)
operating systems that use this, just to stick my neck out further.)
This cute (x^0100) trick is the first reason I'd ever seen for '^?'
to mean DEL; so I have learned something new today.  (I guess I'd
assumed that with someone's screwy keyboard you could generate DEL
as a Control-?.)
-- 

	Joe Yao		hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}
			jsdy@hadron.COM (not yet domainised)

maart@cs.vu.nl (Maarten Litmaath) (10/24/89)

djones@megatest.UUCP (Dave Jones) writes:
\...
\#define CNTL(c) ((c) & 037)

I prefer:

	#define CTRL(x) ((x) ^ 0100)

...so you can say

	CTRL('?')

to get DEL.
-- 
A symbolic link is a POINTER to a file, | Maarten Litmaath @ VU Amsterdam:
 a hard link is the file system's GOTO. | maart@cs.vu.nl, mcsun!botter!maart

davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (10/25/89)

In article <3786@solo6.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes:
|  
|  	#define CTRL(x) ((x) ^ 0100)
|  
|  ...so you can say
|  
|  	CTRL('?')
|  
|  to get DEL.

  You should use another name, perhaps, since many people assume that
CTRL returns control characters. They are defined as the values from
00-37 octal, from the action of the Control key on the original Teletype
terminals. 
-- 
bill davidsen	(davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon

maart@cs.vu.nl (Maarten Litmaath) (10/25/89)

davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) writes:
\In article <3786@solo6.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes:
\|  
\|  	#define CTRL(x) ((x) ^ 0100)
\|  
\|  ...so you can say
\|  
\|  	CTRL('?')
\|  
\|  to get DEL.
\
\  You should use another name, perhaps, since many people assume that
\CTRL returns control characters. They are defined as the values from
\00-37 octal, from the action of the Control key on the original Teletype
\terminals. 

In BSD the new tty driver as well as vi, cat -v, ... use ^? to denote DEL.
Seems pretty normal to me.  According to iscntrl(3) DEL is a control character
too.  Too bad it isn't a normal control character; it would have simplified
things.
-- 
A symbolic link is a POINTER to a file, | Maarten Litmaath @ VU Amsterdam:
 a hard link is the file system's GOTO. | maart@cs.vu.nl, mcsun!botter!maart

karl@haddock.ima.isc.com (Karl Heuer) (10/25/89)

In article <1422@crdos1.crd.ge.COM> davidsen@crdos1.UUCP (bill davidsen) writes:
>control characters ... are defined as the values from 00-37 octal...

That definition may have been the original one, but as far as C is concerned
the only definition of `control character' is `what iscntrl() tests for' --
and this does include DEL on ASCII systems.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

diamond@csl.sony.co.jp (Norman Diamond) (10/26/89)

In article <3802@solo7.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:

>In BSD the new tty driver as well as vi, cat -v, ... use ^? to denote DEL.
>Seems pretty normal to me.  According to iscntrl(3) DEL is a control character
>too.

It also seems reasonable to me to think of DEL as a control character.
However, it does seem to be ambiguous in the industry.  That is why
some manuals refer to "control characters and DEL" in order to avoid
ambiguity.

>Too bad it isn't a normal control character; it would have simplified
>things.

Well, it couldn't possibly be a normal control character.  To delete a
typographical error from paper tape, you had to backspace the tape and
punch all 1's (holes) in that column.  If someone decided to make DEL
something other than all 1's, then they would have to invent another
delete that would be all 1's, and it would STILL be ambiguous if the
new delete was really a control character or not.

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet@uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".