Skip to content

Commit 024a11a

Browse files
committed
Various fix/improvement to samples:
- 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
1 parent a3743bc commit 024a11a

File tree

5 files changed

+135
-9
lines changed

5 files changed

+135
-9
lines changed

samples/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.d.htm
2+
*.exe
3+
chello
4+
dclient
5+
dserver
6+
d2html
7+
dhry
8+
hello
9+
htmlget
10+
listener
11+
pi
12+
sieve
13+
wc
14+
wc2
15+
winsamp
16+

samples/Makefile

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
##
2+
# Example Makefile for the D programming language
3+
##
4+
TARGETS= \
5+
d2html \
6+
dhry \
7+
hello \
8+
htmlget \
9+
listener \
10+
pi \
11+
sieve \
12+
wc \
13+
wc2
14+
15+
## Those examples are Windows specific:
16+
# chello
17+
# dserver
18+
# dclient
19+
# winsamp
20+
21+
SRC = \
22+
chello.d \
23+
d2html.d \
24+
dclient.d \
25+
dhry.d \
26+
dserver.d \
27+
hello.d \
28+
htmlget.d \
29+
listener.d \
30+
pi.d \
31+
sieve.d \
32+
wc.d \
33+
wc2.d \
34+
winsamp.d
35+
DFLAGS =
36+
LFLAGS =
37+
38+
39+
##
40+
## Those values are immutables
41+
## For languages such as C and C++, builtin rules are provided.
42+
## But for D, you had to had to do everything by hand.
43+
## Basically, if you had some Makefile knowledge, this is all you need.
44+
##
45+
## For explanation / more advanced use, see:
46+
## http://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html
47+
.SUFFIXES: .d
48+
.d.o:
49+
$(DMD) $(DFLAGS) -c $< -of$@
50+
##
51+
52+
LINK = dmd
53+
DMD = dmd
54+
RM = rm -rf
55+
OBJS = $(SRC:.d=.o)
56+
57+
all: $(TARGETS)
58+
59+
clean:
60+
$(RM) $(OBJS)
61+
62+
fclean: clean
63+
$(RM) $(TARGETS)
64+
$(RM) *.d.htm
65+
66+
re: fclean all
67+
68+
chello: $(OBJS)
69+
$(LINK) $(LFLAGS) $(OBJS) -of$@
70+
71+
.PHONY: all clean fclean re
72+
.NOTPARALLEL: clean
73+
74+
d2html: d2html.o
75+
$(LINK) $(LFLAGS) $< -of$@
76+
77+
dclient: dclient.o
78+
$(LINK) $(LFLAGS) $< -of$@
79+
80+
dhry: dhry.o
81+
$(LINK) $(LFLAGS) $< -of$@
82+
83+
dserver: dserver.o
84+
$(LINK) $(LFLAGS) $< -of$@
85+
86+
hello: hello.o
87+
$(LINK) $(LFLAGS) $< -of$@
88+
89+
htmlget: htmlget.o
90+
$(LINK) $(LFLAGS) $< -of$@
91+
92+
listener: listener.o
93+
$(LINK) $(LFLAGS) $< -of$@
94+
95+
pi: pi.o
96+
$(LINK) $(LFLAGS) $< -of$@
97+
98+
sieve: sieve.o
99+
$(LINK) $(LFLAGS) $< -of$@
100+
101+
wc2: wc2.o
102+
$(LINK) $(LFLAGS) $< -of$@
103+
104+
wc: wc.o
105+
$(LINK) $(LFLAGS) $< -of$@
106+
107+
winsamp: winsamp.o
108+
$(LINK) $(LFLAGS) $< -of$@

samples/d2html.d

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ int main(string[] args)
176176
dst.write(c);
177177
src.read(c);
178178

179-
while (ishexdigit(c))
180-
dst.write(c);
179+
while (ishexdigit(c)) {
180+
dst.write(c);
181+
src.read(c);
182+
}
181183

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

189-
while (c == '0' || c == '1')
190-
dst.write(c);
191+
while (c == '0' || c == '1') {
192+
dst.write(c);
193+
src.read(c);
194+
}
191195
}
192196
else // octal
193197
{
@@ -384,7 +388,7 @@ int main(string[] args)
384388
}
385389
else
386390
// whatever it is, it's not a valid D token
387-
throw new Error("unrecognized token");
391+
throw new Error("unrecognized token " ~ c);
388392
//~ break;
389393
}
390394
}

samples/htmlget.d

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ int main(string[] args)
2121
}
2222

2323
string url = args[1];
24-
int i;
25-
26-
i = indexOf(url, "://");
24+
auto i = indexOf(url, "://");
2725

2826
if (i != -1)
2927
{

samples/listener.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ next:
5050
if (sset.isSet(reads[i]))
5151
{
5252
char[1024] buf;
53-
int read = reads[i].receive(buf);
53+
auto read = reads[i].receive(buf);
5454

5555
if (Socket.ERROR == read)
5656
{

0 commit comments

Comments
 (0)