From f64467af21efab70b8cfab46f3f7f9d36c5b6e5f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 11 Sep 2020 01:54:26 -0700 Subject: Updated makefile, added manpage --- Makefile | 33 ++++++++++++++++++++++++++++----- bpeg.1 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bpeg.c | 2 +- 3 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 bpeg.1 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\fR=\fI\fR] +[\fI-r\fR|\fI--replace\fR \fI\fR] +[\fI-g\fR|\fI--grammar\fR \fI\fR] +\fI\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 = +Define a grammar rule. + +.B \--replace +Replace all occurrences of the main pattern with the given string. + +.B \--grammar +Load the grammar from the given file. + +.B \--help +Print the usage and exit. + +.B +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 +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 = Define a grammar rule\n" " -r --replace replace the input pattern with the given replacement\n" " -g --grammar use the specified file as a grammar\n"); -- cgit v1.2.3