Skip to content

Commit eb228f9

Browse files
committed
Added a Makefile to make compilation easy
1 parent 2203864 commit eb228f9

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Contact
3+
==========
4+
Avinash Joshi, Sandeep Shenoy [axj107420,sxs115220]@utdallas.edu

CHECKLIST

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
To be implemented
22
========================
3+
o No client-server concept. peer-peer only tutor.c
34
o Separate files for TCP and UDP code
45
o Can use commands like "JOIN" "STOP" "PATH" etc in client side
56
o Write code for path computation

Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Use this Makefile to compile the code
2+
# Collaborators: Avinash Joshi <[email protected]>
3+
# Sandeep Shenoy <[email protected]>
4+
5+
# Use this if pthread is needed to be
6+
# linked explicit
7+
C_LINK = -pthread
8+
9+
# Comment the following line while not
10+
# using the gnu c compiler
11+
C_ARGS = -Wall
12+
13+
CC = gcc
14+
15+
# No more changes below this line
16+
17+
all: tutor
18+
19+
clean:
20+
@echo Removing object files: rm -f *.o
21+
@rm -f *.o
22+
23+
cleanall: clean
24+
@echo Removing compiled files: rm -f tutor
25+
@rm -f tutor
26+
27+
tutor: tutor.o
28+
$(CC) -o tutor tutor.o $(C_LINK)
29+
30+
tutor.o: tutor.c
31+
$(CC) $(C_ARGS) -c tutor.c

README

+7
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ Collaborators: Avinash Joshi <[email protected]>, Sandeep Shenoy <sxs115220
88
Using the application
99

1010
0) Compiling the code
11+
make all
12+
1) Removing object files
13+
make clean
14+
2) Removing all compiled files
15+
make cleanall
16+
17+
You may want to have a look at the file Makefile

tutor.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ int is_number (char * string) {
5353
return is_num;
5454
}
5555

56+
int atoport (char *port_arg) {
57+
int port;
58+
port = atoi(port_arg);
59+
if (!is_number (port_arg) || port < 0) {
60+
fprintf (stderr, "%s: %s: invalid port number\n", exec_name, port_arg);
61+
exit (EXIT_FAILURE);
62+
}
63+
return port;
64+
}
65+
5666
int main (int argc, char **argv) {
5767

5868
/* strrchr gives the last occurance of PATH_SEPARATOR in argv[0] */
@@ -76,18 +86,11 @@ int main (int argc, char **argv) {
7686
switch (optchar) {
7787
case 'p':
7888
pflag = 1;
79-
tport = atoi (optarg);
80-
if (!is_number (optarg)) {
81-
fprintf (stderr, "%s: %s: argument to -p must be a number\n", exec_name, optarg);
82-
exit (EXIT_FAILURE);
83-
}
84-
if (tport < 0) {
85-
fprintf (stderr, "%s: %d: port number must be positive\n", exec_name, tport);
86-
exit (EXIT_FAILURE);
87-
}
89+
tport = atoport (optarg);
8890
break;
8991
case 'P':
9092
Pflag = 1;
93+
uport = atoport (optarg);
9194
break;
9295
case 'n':
9396
nclients = atoi (optarg);

0 commit comments

Comments
 (0)