davidgiven / ack

The Amsterdam Compiler Kit
http://tack.sf.net
Other
420 stars 59 forks source link

About \r and \n confused I am. #198

Closed drawkula closed 5 years ago

drawkula commented 5 years ago
(yeti@kumari:6)/opt/ack/src/ack$ git describe --always 
585e035c1

Outside of CP/M:

(yeti@kumari:6)/home/wrk/runcpm/run/H/1$ cat hchs.c
#include <stdio.h>

main()
{
        puts("Hello, CP/M!");
        puts("Hello, StdIO!");
        puts("-------------");
        puts("Hello, CP/M!\r");
        puts("Hello, StdIO!\r");
        puts("-------------\r");
        puts("Hello, CP/M!\n");
        puts("Hello, StdIO!\n");
        puts("-------------\n");
}
(yeti@kumari:6)/home/wrk/runcpm/run/H/1$ /opt/ack/bin/ack -mcpm hchs.c -o HCHS.COM
"hchs.c", line 4: (warning) 'main' old-fashioned function definition

In RunCPM:

H1>hchs
Hello, CP/M!

Hello, StdIO!

-------------

Hello, CP/M!

Hello, StdIO!

-------------

Hello, CP/M!

Hello, StdIO!

-------------

H1>█

This are more linefeeds than I expected.

davidgiven commented 5 years ago

The CP/M plat translates \n into \r\n, because that's what most CP/M systems need. It looks like runcpm is treating the \r as a carriage return, so you're seeing two newlines per \n. Also remember that puts() itself appends a newline.

drawkula commented 5 years ago

HiTech-C behaves differently in the same emulator on the same terminal:

C1>type hchs.c
#include <stdio.h>

main()
{
        puts("Hello, CP/M!");
        puts("Hello, StdIO!");
}

C1>c hchs.c
HI-TECH C COMPILER (CP/M-80) V3.09
Copyright (C) 1984-87 HI-TECH SOFTWARE

C1>hchs
Hello, CP/M!
Hello, StdIO!

C1>█

So I'm still too confused to close this issue... ;-)

davidgiven commented 5 years ago

Hmm, interesting. Could you attach your hchs.com file? (I want to see what it does in my emulator.)

drawkula commented 5 years ago

Sure!

HCHS_ACK.COM.gz HCHS_HTC.COM.gz

davidgiven commented 5 years ago

Er, oops. Apparently it was translating \n into \n\n rather than \r\n. Will fix. Thanks for the report!

drawkula commented 5 years ago

\o/ Thanks!

I was just trying to go back some commits because I was sure it behaved differently not too far ago... you were faster...