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:
Franck STAUFFER 2020-09-02 20:19:04 +02:00
parent a53f1fdd0a
commit 311a9054ee
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261
4 changed files with 62 additions and 8 deletions

View File

@ -4,10 +4,11 @@ LDFLAGS = -Wl,-z,now,-z,relro,-s,-pie
OBJS = obj/main.o
BIN = bin/stc
MAN = man1/stc.1.gz
PREFIX = /usr
default: obj bin $(BIN)
default: obj bin $(BIN) $(MAN)
obj:
@mkdir obj
@ -21,17 +22,25 @@ $(BIN): $(OBJS)
obj/%.o: src/%.c
$(CC) -c -o $@ $^ $(CFLAGS)
man1/%.1.gz: man1/%.1
gzip --keep --best -c $^ > $@
clean:
@[ -d obj ] && rm -rf obj
@[ -d bin ] && rm -rf bin
@[ -f $(MAN) ] && rm -f $(MAN)
format:
@clang-format -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.c
install: default
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:
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

View File

@ -25,5 +25,5 @@ sudo make uninstall
## Usage
```
stc address|hostname [port]
stc address|domainname [port]
```

45
man1/stc.1 Normal file
View 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>

View File

@ -135,7 +135,7 @@ int
main(int argc, char** argv)
{
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;
}
@ -176,7 +176,7 @@ main(int argc, char** argv)
ev[1].data.fd = sock;
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev[1])) {
perror("epoll_ctl");
return 7;
return 6;
}
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);
if (count == -1) {
perror("epoll_wait");
return 8;
return 7;
}
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);
if (ret == -1) {
perror("recv");
return 9;
return 8;
}
if (!ret)
@ -206,7 +206,7 @@ main(int argc, char** argv)
ret = recv(sock, buf + 1, 2, 0);
if (ret < 0) {
perror("recv");
return 10;
return 8;
}
if (!ret)
@ -226,7 +226,7 @@ main(int argc, char** argv)
if (send(sock, &chr, 1, 0) != 1) {
perror("send");
return 11;
return 9;
}
if (chr == '\n')