Add man page:
- Add man1/stc.1 - Add target in Makefile - install target installs man page - uninstall target uninstalls man page - Reduce number of exit code
This commit is contained in:
parent
a53f1fdd0a
commit
311a9054ee
11
Makefile
11
Makefile
@ -4,10 +4,11 @@ LDFLAGS = -Wl,-z,now,-z,relro,-s,-pie
|
|||||||
|
|
||||||
OBJS = obj/main.o
|
OBJS = obj/main.o
|
||||||
BIN = bin/stc
|
BIN = bin/stc
|
||||||
|
MAN = man1/stc.1.gz
|
||||||
|
|
||||||
PREFIX = /usr
|
PREFIX = /usr
|
||||||
|
|
||||||
default: obj bin $(BIN)
|
default: obj bin $(BIN) $(MAN)
|
||||||
|
|
||||||
obj:
|
obj:
|
||||||
@mkdir obj
|
@mkdir obj
|
||||||
@ -21,17 +22,25 @@ $(BIN): $(OBJS)
|
|||||||
obj/%.o: src/%.c
|
obj/%.o: src/%.c
|
||||||
$(CC) -c -o $@ $^ $(CFLAGS)
|
$(CC) -c -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
|
man1/%.1.gz: man1/%.1
|
||||||
|
gzip --keep --best -c $^ > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@[ -d obj ] && rm -rf obj
|
@[ -d obj ] && rm -rf obj
|
||||||
@[ -d bin ] && rm -rf bin
|
@[ -d bin ] && rm -rf bin
|
||||||
|
@[ -f $(MAN) ] && rm -f $(MAN)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
@clang-format -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.c
|
@clang-format -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.c
|
||||||
|
|
||||||
install: default
|
install: default
|
||||||
install -Dm755 $(BIN) $(PREFIX)/bin/stc
|
install -Dm755 $(BIN) $(PREFIX)/bin/stc
|
||||||
|
install -Dm644 LICENSE $(PREFIX)/share/licenses/stc/LICENSE
|
||||||
|
install -Dm644 man1/stc.1.gz $(PREFIX)/share//man/man1/stc.1.gz
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(PREFIX)/bin/stc
|
rm -f $(PREFIX)/bin/stc
|
||||||
|
rm -f $(PREFIX)/share/licenses/stc/LICENSE
|
||||||
|
rm -f $(PREFIX)/share/man/man1/stc.1.gz
|
||||||
|
|
||||||
.PHONY: default clean format install uninstall
|
.PHONY: default clean format install uninstall
|
||||||
|
@ -25,5 +25,5 @@ sudo make uninstall
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
stc address|hostname [port]
|
stc address|domainname [port]
|
||||||
```
|
```
|
||||||
|
45
man1/stc.1
Normal file
45
man1/stc.1
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
.TH STC 1 "2020-09-02" 1.0
|
||||||
|
.SH NAME
|
||||||
|
stc \- Simple Telnet Client
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B stc
|
||||||
|
address|hostname [port]
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.B stc
|
||||||
|
is a Simple Telnet Client that take at least an IP address or a domain name as a first argument. If a domain name is provided, it will try to resolve it.
|
||||||
|
Optionnaly it can take a port number as a second argument. In this case it will be used instead of the default (which is 23).
|
||||||
|
.SH EXIT STATUS
|
||||||
|
.TP
|
||||||
|
0
|
||||||
|
if no error uncountered
|
||||||
|
.TP
|
||||||
|
1
|
||||||
|
if the wrong amount of arguments has been given
|
||||||
|
.TP
|
||||||
|
2
|
||||||
|
if it failed to initialize network connection (socket, NS resolution, ...)
|
||||||
|
.TP
|
||||||
|
3
|
||||||
|
if it failed to setup terminal
|
||||||
|
.TP
|
||||||
|
4
|
||||||
|
if it failed to create epoll instance
|
||||||
|
.TP
|
||||||
|
5
|
||||||
|
if it failed to set signal handler (for SIGINT or SIGTERM)
|
||||||
|
.TP
|
||||||
|
6
|
||||||
|
if it failed to add a file descriptor to the epoll instance (for stdin or the socket)
|
||||||
|
.TP
|
||||||
|
7
|
||||||
|
if error happened during epoll_wait
|
||||||
|
.TP
|
||||||
|
8
|
||||||
|
if it failed to receive data
|
||||||
|
.TP
|
||||||
|
9
|
||||||
|
if it failed to send data
|
||||||
|
.SH AUTHOR
|
||||||
|
Franck STAUFFER
|
||||||
|
.I <franck.stauffer@monaco.mc>
|
||||||
|
|
12
src/main.c
12
src/main.c
@ -135,7 +135,7 @@ int
|
|||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 2 || argc > 3) {
|
if (argc < 2 || argc > 3) {
|
||||||
printf("USAGE: %s, address|hostname [port]\n", argv[0]);
|
printf("USAGE: %s, address|domainname [port]\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ main(int argc, char** argv)
|
|||||||
ev[1].data.fd = sock;
|
ev[1].data.fd = sock;
|
||||||
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev[1])) {
|
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev[1])) {
|
||||||
perror("epoll_ctl");
|
perror("epoll_ctl");
|
||||||
return 7;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint_fast8_t run = 1;
|
uint_fast8_t run = 1;
|
||||||
@ -186,7 +186,7 @@ main(int argc, char** argv)
|
|||||||
int_fast8_t count = epoll_wait(epoll_fd, events, 2, -1);
|
int_fast8_t count = epoll_wait(epoll_fd, events, 2, -1);
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
perror("epoll_wait");
|
perror("epoll_wait");
|
||||||
return 8;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int_fast8_t i = 0; i < count; ++i) {
|
for (int_fast8_t i = 0; i < count; ++i) {
|
||||||
@ -196,7 +196,7 @@ main(int argc, char** argv)
|
|||||||
int_fast8_t ret = recv(sock, buf, 1, 0);
|
int_fast8_t ret = recv(sock, buf, 1, 0);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
perror("recv");
|
perror("recv");
|
||||||
return 9;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
@ -206,7 +206,7 @@ main(int argc, char** argv)
|
|||||||
ret = recv(sock, buf + 1, 2, 0);
|
ret = recv(sock, buf + 1, 2, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("recv");
|
perror("recv");
|
||||||
return 10;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
@ -226,7 +226,7 @@ main(int argc, char** argv)
|
|||||||
|
|
||||||
if (send(sock, &chr, 1, 0) != 1) {
|
if (send(sock, &chr, 1, 0) != 1) {
|
||||||
perror("send");
|
perror("send");
|
||||||
return 11;
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chr == '\n')
|
if (chr == '\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user