Adapted to tell the user what language they were written in (because they're too similar!). Modified the Pascal implementation to work with our new syscall model.

This commit is contained in:
dtrg 2007-04-21 23:19:32 +00:00
parent 1c83baa702
commit 921c55968c
5 changed files with 11 additions and 9 deletions

View file

@ -2,7 +2,7 @@
2 ' $State$ 2 ' $State$
3 ' $Revision$ 3 ' $Revision$
10 print "Hi there! Before we start, what is your name?" 10 print "Hi there! I'm written in Basic. Before we start, what is your name?"
20 input "> ", PlayerName$ 20 input "> ", PlayerName$
30 print 30 print
40 print "Hello, "; PlayerName$; "!" 40 print "Hello, "; PlayerName$; "!"

View file

@ -59,7 +59,7 @@ void game(void)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
printf("\nHi there! Before we start, what is your name?\n"); printf("\nHi there! I'm written in C. Before we start, what is your name?\n");
reads(); reads();
strcpy(PlayerName, buffer); strcpy(PlayerName, buffer);
printf("\nHello, %s! ", PlayerName); printf("\nHello, %s! ", PlayerName);

View file

@ -66,7 +66,7 @@ VAR
finished : BOOLEAN; finished : BOOLEAN;
BEGIN BEGIN
WriteLn; WriteLn;
WriteString("Hi there! Before we start, what is your name?"); WriteString("Hi there! I'm written in Modula-2. Before we start, what is your name?");
WriteLn; WriteLn;
reads; reads;
WriteLn; WriteLn;

View file

@ -56,7 +56,7 @@ proc random(value range, var result) =
proc getname = proc getname =
var seed, buffer[128]: var seed, buffer[128]:
seq seq
puts("*nHi there! Before we start, what is your name?*n") puts("*nHi there! I'm written in Occam. Before we start, what is your name?*n")
puts("> ") puts("> ")
gets(buffer) gets(buffer)

View file

@ -29,10 +29,12 @@ function random(range : integer) : integer;
random := seed mod range; random := seed mod range;
end; end;
{ Pascal doesn't provide string input, so we interface to the _read() syscall { Pascal doesn't provide string input, so we interface to the read() syscall
and do it manually. } and do it manually. But... we can't interface to read() directly because
that conflicts with a Pascal keyword. Luckily there's a private function
uread() in the ACK Pascal library that we can use instead. }
function _read(fd : integer; var buffer : char; count : integer) : integer; function uread(fd : integer; var buffer : char; count : integer) : integer;
extern; extern;
function readchar : char; function readchar : char;
@ -42,7 +44,7 @@ function readchar : char;
begin begin
c := chr(0); c := chr(0);
dummy := _read(0, c, 1); dummy := uread(0, c, 1);
readchar := c; readchar := c;
end; end;
@ -79,7 +81,7 @@ procedure getname;
begin begin
writeln; writeln;
writeln('Hi there! Before we start, what is your name?'); writeln('Hi there! I''m written in Pascal. Before we start, what is your name?');
writeln; writeln;
readstring(name, namelen); readstring(name, namelen);
writeln; writeln;