mirror of
https://github.com/NikitaIvanovV/ctpv.git
synced 2025-02-19 20:10:47 +01:00
Add -h option
This commit is contained in:
parent
0c882097f6
commit
a8d064c43c
8
Makefile
8
Makefile
@ -6,7 +6,7 @@ SRC := $(wildcard src/*.c)
|
||||
OBJ := $(SRC:.c=.o)
|
||||
DEP := $(OBJ:.o=.d)
|
||||
PRE := $(wildcard sh/prev/*)
|
||||
GEN := gen/previews.h gen/server.h gen/helpers.h
|
||||
GEN := gen/help.h gen/previews.h gen/server.h gen/helpers.h
|
||||
|
||||
LIBS := magic crypto
|
||||
|
||||
@ -47,6 +47,7 @@ clean:
|
||||
docs: README.md doc/ctpv.1
|
||||
deptable/list.awk $(PRE) | deptable/markdown.sed | deptable/insert.awk README.md
|
||||
deptable/list.awk $(PRE) | deptable/roff.sed | deptable/insert.awk doc/ctpv.1
|
||||
./genhelp.sh doc/ctpv.1 > help.txt
|
||||
|
||||
ctpv: $(OBJ)
|
||||
$(CC) -o $@ $+ $(ALL_LDFLAGS)
|
||||
@ -55,10 +56,13 @@ ctpv: $(OBJ)
|
||||
$(CC) -o $@ $< -c $(ALL_CFLAGS)
|
||||
|
||||
# Exclicit rules for generated header files
|
||||
src/ctpv.o: gen/previews.h
|
||||
src/ctpv.o: gen/previews.h gen/help.h
|
||||
src/shell.o: gen/helpers.h
|
||||
src/server.o: gen/server.h
|
||||
|
||||
gen/help.h: help.txt embed/embed
|
||||
embed/embed help.txt > $@
|
||||
|
||||
gen/previews.h: $(PRE) embed/embed
|
||||
embed/embed -p prev_scr_ $(PRE) > $@
|
||||
|
||||
|
@ -18,6 +18,10 @@ ctpv \- terminal previewer
|
||||
.YS
|
||||
.
|
||||
.SY ctpv
|
||||
.B \-h
|
||||
.YS
|
||||
.
|
||||
.SY ctpv
|
||||
.B \-l
|
||||
.YS
|
||||
.
|
||||
@ -244,6 +248,10 @@ and standard error are printed.
|
||||
.SH OPTIONS
|
||||
.
|
||||
.TP
|
||||
.B \-h
|
||||
Print help message.
|
||||
.
|
||||
.TP
|
||||
.B \-l
|
||||
List all previews.
|
||||
.
|
||||
|
7
genhelp.sh
Executable file
7
genhelp.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
export GROFF_NO_SGR=1
|
||||
|
||||
groff -t -man -mtty-char "$1" -Tascii |
|
||||
col -bx |
|
||||
sed '/OPTIONS/,/^[A-Z]/!d; /^[A-Z]/d'
|
14
help.txt
Normal file
14
help.txt
Normal file
@ -0,0 +1,14 @@
|
||||
-h Print help message.
|
||||
|
||||
-l List all previews.
|
||||
|
||||
-m file ...
|
||||
Print extension and MIME type of file.
|
||||
|
||||
-s id Start server with ID id.
|
||||
|
||||
-c id Send clear command to server with ID id (usually, it removes im-
|
||||
age from terminal).
|
||||
|
||||
-e id Kill server with ID id.
|
||||
|
16
src/ctpv.c
16
src/ctpv.c
@ -16,6 +16,7 @@
|
||||
#include "preview.h"
|
||||
#include "../version.h"
|
||||
#include "../previews.h"
|
||||
#include "../gen/help.h"
|
||||
|
||||
struct InputFile {
|
||||
char link[PATH_MAX], path[PATH_MAX];
|
||||
@ -392,6 +393,13 @@ static RESULT mime(int argc, char *argv[])
|
||||
return OK;
|
||||
}
|
||||
|
||||
static RESULT help(void)
|
||||
{
|
||||
printf("Usage: %s [OPTION]... FILE\n\n", program);
|
||||
printf("Options:\n%s", help_txt);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static RESULT version(void)
|
||||
{
|
||||
printf("%s version %s\n", program, VERSION);
|
||||
@ -405,8 +413,11 @@ int main(int argc, char *argv[])
|
||||
ctpv.opts.shell = "/bin/sh";
|
||||
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "s:c:e:lmv")) != -1) {
|
||||
while ((c = getopt(argc, argv, "hs:c:e:lmv")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
ctpv.mode = MODE_HELP;
|
||||
break;
|
||||
case 's':
|
||||
ctpv.mode = MODE_SERVER;
|
||||
ctpv.server_id_s = optarg;
|
||||
@ -441,6 +452,9 @@ int main(int argc, char *argv[])
|
||||
case MODE_PREVIEW:
|
||||
ret = preview(argc, argv);
|
||||
break;
|
||||
case MODE_HELP:
|
||||
ret = help();
|
||||
break;
|
||||
case MODE_SERVER:
|
||||
ret = server();
|
||||
break;
|
||||
|
@ -6,6 +6,7 @@
|
||||
struct CTPV {
|
||||
enum {
|
||||
MODE_PREVIEW = 0, /* default mode */
|
||||
MODE_HELP,
|
||||
MODE_SERVER,
|
||||
MODE_CLEAR,
|
||||
MODE_END,
|
||||
|
Loading…
Reference in New Issue
Block a user