The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Literal character escapes in v7
@ 2017-11-07  4:21 Will Senn
  2017-11-07  4:34 ` arnold
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Will Senn @ 2017-11-07  4:21 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

I wrote a snippet from my K&R C studies to convert tabs and backspaces 
to \t \b to display them, the code looks like this:

/* ex 1-8 */

main()
{
     int c, sf;

     while((c = getchar()) != EOF) {
         if(c == '\t')
             printf("\\t");
          if(c == '\b')
             printf("\\b");
         else
             putchar(c);
     }
}

I'm not looking for code review, but the code is intended to replace the 
tabs and backspaces with \t and \b respectively, but I haven't been able 
to test it because I can't seem to make a backspace character appear in 
input. In later unices, ^V followed by the backspace would work, but 
that's not part of v7. Backspace itself is my erase character, so 
anytime I just type it, it backspaces :).

Thanks,

Will

-- 
GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:21 [TUHS] Literal character escapes in v7 Will Senn
@ 2017-11-07  4:34 ` arnold
  2017-11-07  4:49   ` Will Senn
  2017-11-07  9:07 ` Dennis Boone
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: arnold @ 2017-11-07  4:34 UTC (permalink / raw)


Will Senn <will.senn at gmail.com> wrote:

> I'm not looking for code review, but the code is intended to replace the 
> tabs and backspaces with \t and \b respectively, but I haven't been able 
> to test it because I can't seem to make a backspace character appear in 
> input. In later unices, ^V followed by the backspace would work, but 
> that's not part of v7. Backspace itself is my erase character, so 
> anytime I just type it, it backspaces :).

	awk 'BEGIN { print "a\bc\td" ; exit }' | your-program

Enjoy,

Arnold

P.S. The exit is needed for V7 awk, IIRC, not modern ones.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:34 ` arnold
@ 2017-11-07  4:49   ` Will Senn
  2017-11-07  5:00     ` Will Senn
  0 siblings, 1 reply; 11+ messages in thread
From: Will Senn @ 2017-11-07  4:49 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]

On 11/6/17 10:34 PM, arnold at skeeve.com wrote:
> Will Senn <will.senn at gmail.com> wrote:
>
>> I'm not looking for code review, but the code is intended to replace the
>> tabs and backspaces with \t and \b respectively, but I haven't been able
>> to test it because I can't seem to make a backspace character appear in
>> input. In later unices, ^V followed by the backspace would work, but
>> that's not part of v7. Backspace itself is my erase character, so
>> anytime I just type it, it backspaces :).
> 	awk 'BEGIN { print "a\bc\td" ; exit }' | your-program
>
> Enjoy,
>
> Arnold
>
> P.S. The exit is needed for V7 awk, IIRC, not modern ones.

This is a good idea, but... Here's my results from just running awk for 
\t, \n, and \b:

$ awk 'BEGIN { print "a\tb" ; exit }';
a       b
$ awk 'BEGIN { print "a\nb" ; exit }'
anb
$ awk 'BEGIN { print "a\bb" ; exit }'
abb
$

Strange. It looks like it's just ignoring the backslash in the case of 
\n and \b.

Will

-- 
GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:49   ` Will Senn
@ 2017-11-07  5:00     ` Will Senn
  2017-11-07  8:08       ` arnold
  0 siblings, 1 reply; 11+ messages in thread
From: Will Senn @ 2017-11-07  5:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1300 bytes --]

On 11/6/17 10:49 PM, Will Senn wrote:
> On 11/6/17 10:34 PM, arnold at skeeve.com wrote:
>> Will Senn <will.senn at gmail.com> wrote:
>>
>>> I'm not looking for code review, but the code is intended to replace 
>>> the
>>> tabs and backspaces with \t and \b respectively, but I haven't been 
>>> able
>>> to test it because I can't seem to make a backspace character appear in
>>> input. In later unices, ^V followed by the backspace would work, but
>>> that's not part of v7. Backspace itself is my erase character, so
>>> anytime I just type it, it backspaces :).
>>     awk 'BEGIN { print "a\bc\td" ; exit }' | your-program
>>
>> Enjoy,
>>
>> Arnold
>>
>> P.S. The exit is needed for V7 awk, IIRC, not modern ones.
>
> This is a good idea, but... Here's my results from just running awk 
> for \t, \n, and \b:
>
> $ awk 'BEGIN { print "a\tb" ; exit }';
> a       b
> $ awk 'BEGIN { print "a\nb" ; exit }'
> anb
> $ awk 'BEGIN { print "a\bb" ; exit }'
> abb
> $
>
> Strange. It looks like it's just ignoring the backslash in the case of 
> \n and \b.
>
> Will
>
I wrote a c program to print a string in line with the suggestion to use 
awk and my code worked, but it's still odd that the above didn't work.

Will

-- 
GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  5:00     ` Will Senn
@ 2017-11-07  8:08       ` arnold
  0 siblings, 0 replies; 11+ messages in thread
From: arnold @ 2017-11-07  8:08 UTC (permalink / raw)


Will Senn <will.senn at gmail.com> wrote:

> I wrote a c program to print a string in line with the suggestion to use 
> awk and my code worked, but it's still odd that the above didn't work.

The V7 awk was really primitive. Another idea that occurred to me:

	stty erase #

and then you can enter a literal backspace on the command line.

HTH,

Arnold


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:21 [TUHS] Literal character escapes in v7 Will Senn
  2017-11-07  4:34 ` arnold
@ 2017-11-07  9:07 ` Dennis Boone
  2017-11-07 13:55   ` Will Senn
  2017-11-07 11:21 ` Dan Cross
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Dennis Boone @ 2017-11-07  9:07 UTC (permalink / raw)


 > I'm not looking for code review, but the code is intended to replace
 > the tabs and backspaces with \t and \b respectively, but I haven't
 > been able to test it because I can't seem to make a backspace
 > character appear in input. In later unices, ^V followed by the
 > backspace would work, but that's not part of v7. Backspace itself is
 > my erase character, so anytime I just type it, it backspaces :).

This bit from the middle of sys/dev/tty.c seems to indicate that you
escape it with \:

	} else {
		mc = maptab[c];
		if (c==tp->t_erase || c==tp->t_kill)
			mc = c;
		if (mc && (mc==c || (tp->t_flags&LCASE))) {
			if (bp[-2] != '\\')
			c = mc;
			bp--;
		}
	}

On my test v7 system if I type backslash control-h:

	# stty
	speed 0 baud
	erase = '^H'; kill = '^U'
	even -nl echo -tabs
	# echo \^H | od -c
	0000000  \b  \n
	0000002
	#

De


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:21 [TUHS] Literal character escapes in v7 Will Senn
  2017-11-07  4:34 ` arnold
  2017-11-07  9:07 ` Dennis Boone
@ 2017-11-07 11:21 ` Dan Cross
  2017-11-07 14:59   ` Will Senn
  2017-11-07 15:33 ` Don Hopkins
  2017-11-08 16:48 ` Ralph Corderoy
  4 siblings, 1 reply; 11+ messages in thread
From: Dan Cross @ 2017-11-07 11:21 UTC (permalink / raw)


On Mon, Nov 6, 2017, 11:21 PM Will Senn <will.senn at gmail.com> wrote:

> I wrote a snippet from my K&R C studies to convert tabs and backspaces
> to \t \b to display them, the code looks like this:
>
> /* ex 1-8 */
>
> main()
> {
>      int c, sf;
>
>      while((c = getchar()) != EOF) {
>          if(c == '\t')
>              printf("\\t");
>           if(c == '\b')
>

Shouldn't this be 'else if'? Otherwise, if you encounter a tab, you will
print '\t' and then call into the 'else' below after the test for '\b' and
print c, which is a tab literal.

        - Dan C.

             printf("\\b");
>          else
>              putchar(c);
>      }
> }
>
> I'm not looking for code review, but the code is intended to replace the
> tabs and backspaces with \t and \b respectively, but I haven't been able
> to test it because I can't seem to make a backspace character appear in
> input. In later unices, ^V followed by the backspace would work, but
> that's not part of v7. Backspace itself is my erase character, so
> anytime I just type it, it backspaces :).
>
> Thanks,
>
> Will
>
> --
> GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20171107/530b2ff6/attachment-0001.html>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  9:07 ` Dennis Boone
@ 2017-11-07 13:55   ` Will Senn
  0 siblings, 0 replies; 11+ messages in thread
From: Will Senn @ 2017-11-07 13:55 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1534 bytes --]

On 11/7/17 3:07 AM, Dennis Boone wrote:
>   > I'm not looking for code review, but the code is intended to replace
>   > the tabs and backspaces with \t and \b respectively, but I haven't
>   > been able to test it because I can't seem to make a backspace
>   > character appear in input. In later unices, ^V followed by the
>   > backspace would work, but that's not part of v7. Backspace itself is
>   > my erase character, so anytime I just type it, it backspaces :).
>
> This bit from the middle of sys/dev/tty.c seems to indicate that you
> escape it with \:
>
> 	} else {
> 		mc = maptab[c];
> 		if (c==tp->t_erase || c==tp->t_kill)
> 			mc = c;
> 		if (mc && (mc==c || (tp->t_flags&LCASE))) {
> 			if (bp[-2] != '\\')
> 			c = mc;
> 			bp--;
> 		}
> 	}
>
> On my test v7 system if I type backslash control-h:
>
> 	# stty
> 	speed 0 baud
> 	erase = '^H'; kill = '^U'
> 	even -nl echo -tabs
> 	# echo \^H | od -c
> 	0000000  \b  \n
> 	0000002
> 	#
>
> De

Thanks for the note. I thought about it and tried it out even though I 
don't see the ^H (my cursor backs up a space).

After typing echo "\^H" | od -c, here's what it looks like:

$ echo "" | od -c
0000000  \b  \n
0000002

So, sure enough there's a backspace in there and my code "sees" it too:

$ echo "" | 1-8
<<BACKSPACE>>
$


-- 
GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20171107/34432d5e/attachment.html>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07 11:21 ` Dan Cross
@ 2017-11-07 14:59   ` Will Senn
  0 siblings, 0 replies; 11+ messages in thread
From: Will Senn @ 2017-11-07 14:59 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]


>
>          while((c = getchar()) != EOF) {
>              if(c == '\t')
>                  printf("\\t");
>               if(c == '\b')
>
>
> Shouldn't this be 'else if'? Otherwise, if you encounter a tab, you 
> will print '\t' and then call into the 'else' below after the test for 
> '\b' and print c, which is a tab literal.
>
>         - Dan C.
>
>
Yes it should - I was concentrating on the backspace thing and not being 
careful enough about the code.

        if(c== '\t')
            printf("\\t");
        else if(c == '\b')
            printf("\\b");
        else
            putchar(c);

Thanks,
Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20171107/b700f995/attachment.html>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:21 [TUHS] Literal character escapes in v7 Will Senn
                   ` (2 preceding siblings ...)
  2017-11-07 11:21 ` Dan Cross
@ 2017-11-07 15:33 ` Don Hopkins
  2017-11-08 16:48 ` Ralph Corderoy
  4 siblings, 0 replies; 11+ messages in thread
From: Don Hopkins @ 2017-11-07 15:33 UTC (permalink / raw)


I have always been a proponent of generalizing /dev/zero such that it supports both block and character mode, and the minor node number specifies the byte you get mapped into memory or read from a file.

So then you could just make a character device /dev/backspace whose minor node number was 8, and /dev/beep whose minor node number was 7! 

-Don

> On 7 Nov 2017, at 05:21, Will Senn <will.senn at gmail.com> wrote:
> 
> I wrote a snippet from my K&R C studies to convert tabs and backspaces to \t \b to display them, the code looks like this:
> 
> /* ex 1-8 */
> 
> main()
> {
>     int c, sf;
> 
>     while((c = getchar()) != EOF) {
>         if(c == '\t')
>             printf("\\t");
>          if(c == '\b')
>             printf("\\b");
>         else
>             putchar(c);
>     }
> }
> 
> I'm not looking for code review, but the code is intended to replace the tabs and backspaces with \t and \b respectively, but I haven't been able to test it because I can't seem to make a backspace character appear in input. In later unices, ^V followed by the backspace would work, but that's not part of v7. Backspace itself is my erase character, so anytime I just type it, it backspaces :).
> 
> Thanks,
> 
> Will
> 
> -- 
> GPG Fingerprint: 68F4 B3BD 1730 555A 4462  7D45 3EAA 5B6D A982 BAAF
> 



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [TUHS] Literal character escapes in v7
  2017-11-07  4:21 [TUHS] Literal character escapes in v7 Will Senn
                   ` (3 preceding siblings ...)
  2017-11-07 15:33 ` Don Hopkins
@ 2017-11-08 16:48 ` Ralph Corderoy
  4 siblings, 0 replies; 11+ messages in thread
From: Ralph Corderoy @ 2017-11-08 16:48 UTC (permalink / raw)


Hi Will,

> I can't seem to make a backspace character

dc(1) is handy for unhexdump.

    $ echo 16i4108666F6F0AP | dc | sed -n l
    A\bfoo$
    $

-- 
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-11-08 16:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07  4:21 [TUHS] Literal character escapes in v7 Will Senn
2017-11-07  4:34 ` arnold
2017-11-07  4:49   ` Will Senn
2017-11-07  5:00     ` Will Senn
2017-11-07  8:08       ` arnold
2017-11-07  9:07 ` Dennis Boone
2017-11-07 13:55   ` Will Senn
2017-11-07 11:21 ` Dan Cross
2017-11-07 14:59   ` Will Senn
2017-11-07 15:33 ` Don Hopkins
2017-11-08 16:48 ` Ralph Corderoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).