A very basic blog about D

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jul 7 09:06:41 PDT 2013


On 7/7/13 8:55 AM, Andrei Alexandrescu wrote:
> Here's a conformant implementation for reference:
> http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c

Hmm, that's actually not so good, it doesn't ensure that I/O was 
successful. Anyhow, here's a possibility:

import std.stdout;
void main(string[] args)
{
     const appendNewline = args.length > 1 && args[1] == "-n";
     foreach (i, arg; args[appendNewline + 1 .. $])
     {
         if (i) write(' ');
         write(arg);
     }
     if (nl) writeln();
}

But then I figured echo must do escape character processing, see e.g. 
http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. 
With that the blog entry would become quite interesting.


Andrei


More information about the Digitalmars-d-announce mailing list