aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-11 01:54:26 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-11 01:54:26 -0700
commitf64467af21efab70b8cfab46f3f7f9d36c5b6e5f (patch)
tree9ecb841dc536a14a9bb418f8886b94632e14f541
parent2baadd9ba00a84b3daa5c7028e7129223fbd5b1d (diff)
Updated makefile, added manpage
-rw-r--r--Makefile33
-rw-r--r--bpeg.160
-rw-r--r--bpeg.c2
3 files changed, 89 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index a6ce457..7636bce 100644
--- a/Makefile
+++ b/Makefile
@@ -1,23 +1,46 @@
+NAME=bpeg
PREFIX=/usr/local
CFLAGS=-std=c99 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CWARN=-Wall -Wpedantic -Wextra -Wno-unknown-pragmas -Wno-missing-field-initializers\
-Wno-padded -Wsign-conversion -Wno-missing-noreturn -Wno-cast-qual -Wtype-limits
-LDFLAGS=
G ?=
O ?= -O3
CFILES=compiler.c grammar.c utils.c vm.c
OBJFILES=$(CFILES:.c=.o)
-all: bpeg
+all: $(NAME)
.c.o:
cc -c $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $<
-bpeg: $(OBJFILES) bpeg.c
+$(NAME): $(OBJFILES) $(NAME).c
cc $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $^
clean:
- rm -f bpeg $(OBJFILES)
+ rm -f $(NAME) $(OBJFILES)
-.PHONY: all clean
+install: $(NAME)
+ @prefix="$(PREFIX)"; \
+ if [ ! "$$prefix" ]; then \
+ printf '\033[1mWhere do you want to install? (default: /usr/local) \033[0m'; \
+ read prefix; \
+ fi; \
+ [ ! "$$prefix" ] && prefix="/usr/local"; \
+ mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" \
+ && cp -v $(NAME).1 "$$prefix/share/man/man1/" \
+ && rm -f "$$prefix/bin/$(NAME)" \
+ && cp -v $(NAME) "$$prefix/bin/"
+
+uninstall:
+ @prefix="$(PREFIX)"; \
+ if [ ! "$$prefix" ]; then \
+ printf '\033[1mWhere do you want to uninstall from? (default: /usr/local) \033[0m'; \
+ read prefix; \
+ fi; \
+ [ ! "$$prefix" ] && prefix="/usr/local"; \
+ echo "Deleting..."; \
+ rm -rvf "$$prefix/bin/$(NAME)" "$$prefix/share/man/man1/$(NAME).1" ; \
+ printf "\033[1mIf you created any config files in ~/.config/$(NAME), you may want to delete them manually.\033[0m\n"
+
+.PHONY: all, clean, install, uninstall
diff --git a/bpeg.1 b/bpeg.1
new file mode 100644
index 0000000..3dfb806
--- /dev/null
+++ b/bpeg.1
@@ -0,0 +1,60 @@
+.\" Manpage for bpeg.
+.\" Contact bruce@bruce-hill.com to correct errors or typos.
+.TH man 1 "Sep 12, 2020" "0.1" "bpeg manual page"
+.SH NAME
+bpeg \- Bruce's Parsing Expression Grammar tool
+.SH SYNOPSIS
+.B bpeg
+[\fI-h\fR|\fI--help\fR]
+[\fI-v\fR|\fI--verbose\fR]
+[\fI-d\fR|\fI--define\fR \fI<name>\fR=\fI<pattern>\fR]
+[\fI-r\fR|\fI--replace\fR \fI<replacement>\fR]
+[\fI-g\fR|\fI--grammar\fR \fI<grammar file>\fR]
+\fI<pattern\fR
+[[--] \fI<input file>\fR]
+.SH DESCRIPTION
+\fBbpeg\fR is a tool that matches parsing expression grammars using a custom syntax.
+.SH OPTIONS
+.B \--verbose
+Print debugging information.
+
+.B \--define <name>=<pattern>
+Define a grammar rule.
+
+.B \--replace <replacement>
+Replace all occurrences of the main pattern with the given string.
+
+.B \--grammar <grammar file>
+Load the grammar from the given file.
+
+.B \--help
+Print the usage and exit.
+
+.B <pattern>
+The main pattern for bpeg to match. By default, this pattern
+is in "string literal" mode (i.e. a backslash is requres for
+non-literal patterns). The default mode is to find \fBall\fR
+occurrences of the pattern and highlight them.
+
+.B <input file>
+The input file to search (default: stdin).
+
+.SH EXAMPLES
+.TP
+.B
+ls | bpeg foo
+Find files containing the string "foo"
+
+.TP
+.B
+ls | bpeg '.c\\$' -r '.h'
+Find files ending with ".c" and replace the extension with ".h"
+
+.TP
+.B
+bpeg -g grammar.bpeg '\\myThing' my_file.txt
+Find ocurrences of the grammar rule "myThing" in the file \fBmy_file.txt\fR
+using the grammar rules defined in \fBgrammar.bpeg\fR
+
+.SH AUTHOR
+Bruce Hill (bruce@bruce-hill.com)
diff --git a/bpeg.c b/bpeg.c
index 01073a0..2515d8b 100644
--- a/bpeg.c
+++ b/bpeg.c
@@ -48,7 +48,7 @@ static const char *usage = (
"Flags:\n"
" -h --help\t print the usage and quit\n"
" -v --verbose\t print verbose debugging info\n"
- " -s --slow\t run in slow mode for debugging\n"
+ " -d --define <name>=<def> Define a grammar rule\n"
" -r --replace <replacement> replace the input pattern with the given replacement\n"
" -g --grammar <grammar file> use the specified file as a grammar\n");