Skip to content

Commit

Permalink
Various fix/improvement to samples:
Browse files Browse the repository at this point in the history
- Adding gitignore
- Added a sample GNU Makefile for linux compilation
- Fixed infinite loop on hexa/octal numbers in d2html.d
- Fixed 64 bits issues (int used) on listener.d and htmlget.d
TODO: Fix d2html.d to support the '$' token
  • Loading branch information
Geod24 committed Oct 7, 2013
1 parent a3743bc commit 024a11a
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
16 changes: 16 additions & 0 deletions samples/.gitignore
@@ -0,0 +1,16 @@
*.d.htm
*.exe
chello
dclient
dserver
d2html
dhry
hello
htmlget
listener
pi
sieve
wc
wc2
winsamp

108 changes: 108 additions & 0 deletions samples/Makefile
@@ -0,0 +1,108 @@
##
# Example Makefile for the D programming language
##
TARGETS= \
d2html \
dhry \
hello \
htmlget \
listener \
pi \
sieve \
wc \
wc2

## Those examples are Windows specific:
# chello
# dserver
# dclient
# winsamp

SRC = \
chello.d \
d2html.d \
dclient.d \
dhry.d \
dserver.d \
hello.d \
htmlget.d \
listener.d \
pi.d \
sieve.d \
wc.d \
wc2.d \
winsamp.d
DFLAGS =
LFLAGS =


##
## Those values are immutables
## For languages such as C and C++, builtin rules are provided.
## But for D, you had to had to do everything by hand.
## Basically, if you had some Makefile knowledge, this is all you need.
##
## For explanation / more advanced use, see:
## http://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html
.SUFFIXES: .d
.d.o:
$(DMD) $(DFLAGS) -c $< -of$@
##

LINK = dmd
DMD = dmd
RM = rm -rf
OBJS = $(SRC:.d=.o)

all: $(TARGETS)

clean:
$(RM) $(OBJS)

fclean: clean
$(RM) $(TARGETS)
$(RM) *.d.htm

re: fclean all

chello: $(OBJS)
$(LINK) $(LFLAGS) $(OBJS) -of$@

.PHONY: all clean fclean re
.NOTPARALLEL: clean

d2html: d2html.o
$(LINK) $(LFLAGS) $< -of$@

dclient: dclient.o
$(LINK) $(LFLAGS) $< -of$@

dhry: dhry.o
$(LINK) $(LFLAGS) $< -of$@

dserver: dserver.o
$(LINK) $(LFLAGS) $< -of$@

hello: hello.o
$(LINK) $(LFLAGS) $< -of$@

htmlget: htmlget.o
$(LINK) $(LFLAGS) $< -of$@

listener: listener.o
$(LINK) $(LFLAGS) $< -of$@

pi: pi.o
$(LINK) $(LFLAGS) $< -of$@

sieve: sieve.o
$(LINK) $(LFLAGS) $< -of$@

wc2: wc2.o
$(LINK) $(LFLAGS) $< -of$@

wc: wc.o
$(LINK) $(LFLAGS) $< -of$@

winsamp: winsamp.o
$(LINK) $(LFLAGS) $< -of$@
14 changes: 9 additions & 5 deletions samples/d2html.d
Expand Up @@ -176,8 +176,10 @@ int main(string[] args)
dst.write(c);
src.read(c);

while (ishexdigit(c))
dst.write(c);
while (ishexdigit(c)) {
dst.write(c);
src.read(c);
}

// TODO: add support for hexadecimal floats
}
Expand All @@ -186,8 +188,10 @@ int main(string[] args)
dst.write(c);
src.read(c);

while (c == '0' || c == '1')
dst.write(c);
while (c == '0' || c == '1') {
dst.write(c);
src.read(c);
}
}
else // octal
{
Expand Down Expand Up @@ -384,7 +388,7 @@ int main(string[] args)
}
else
// whatever it is, it's not a valid D token
throw new Error("unrecognized token");
throw new Error("unrecognized token " ~ c);
//~ break;
}
}
Expand Down
4 changes: 1 addition & 3 deletions samples/htmlget.d
Expand Up @@ -21,9 +21,7 @@ int main(string[] args)
}

string url = args[1];
int i;

i = indexOf(url, "://");
auto i = indexOf(url, "://");

if (i != -1)
{
Expand Down
2 changes: 1 addition & 1 deletion samples/listener.d
Expand Up @@ -50,7 +50,7 @@ next:
if (sset.isSet(reads[i]))
{
char[1024] buf;
int read = reads[i].receive(buf);
auto read = reads[i].receive(buf);

if (Socket.ERROR == read)
{
Expand Down

0 comments on commit 024a11a

Please sign in to comment.