From bcb832b755b84ef1c95c1dc7e209fd4338f850a0 Mon Sep 17 00:00:00 2001 From: martijn Date: Thu, 14 Dec 2017 10:02:53 +0000 Subject: [PATCH] Enable the awk scripts to generate ex_def.h and options_def.h. These scripts generate the enums required for the ex commands and vi options. Before these lists had to be maintained either by hand or someone had to stumble upon these scripts and figure out how to use them. By enabling them these headers are now always in sync based on the comments in the corresponding source files, which are a lot harder to miss during an update than an extra file. Update the awk scripts to the new enum style introduced by bentley@ with his update on options_def.h r1.7 Feedback Makefile semantics by espie@ Original diff and OK tb@ OK millert@ --- usr.bin/vi/build/Makefile | 15 ++++++- usr.bin/vi/common/options.awk | 13 ++++-- usr.bin/vi/ex/ex.awk | 14 ++++-- usr.bin/vi/include/ex_def.h | 76 -------------------------------- usr.bin/vi/include/options_def.h | 75 ------------------------------- 5 files changed, 33 insertions(+), 160 deletions(-) delete mode 100644 usr.bin/vi/include/ex_def.h delete mode 100644 usr.bin/vi/include/options_def.h diff --git a/usr.bin/vi/build/Makefile b/usr.bin/vi/build/Makefile index d8663107b73..f7e32ba1405 100644 --- a/usr.bin/vi/build/Makefile +++ b/usr.bin/vi/build/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.24 2016/03/30 06:38:46 jmc Exp $ +# $OpenBSD: Makefile,v 1.25 2017/12/14 10:02:53 martijn Exp $ # @(#)Makefile.in 8.75 (Berkeley) 10/23/96 PROG= vi # Modern curses (ncurses) -CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../include +CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../include -I. LDADD+=-lcurses DPADD+= ${LIBCURSES} @@ -38,6 +38,17 @@ SRCS= cl_funcs.c cl_main.c cl_read.c cl_screen.c cl_term.c \ LINKS= ${BINDIR}/vi ${BINDIR}/ex LINKS+= ${BINDIR}/vi ${BINDIR}/view +options_def.h: common/options.awk common/options.c + awk -f ${.CURDIR}/../common/options.awk ${.CURDIR}/../common/options.c \ + > $@.tmp && mv $@.tmp $@ || rm $@.tmp + +ex_def.h: ex/ex.awk ex/ex_cmd.c + awk -f ${.CURDIR}/../ex/ex.awk ${.CURDIR}/../ex/ex_cmd.c > $@.tmp \ + && mv $@.tmp $@ || rm $@.tmp + +BUILDFIRST = options_def.h ex_def.h +CLEANFILES += options_def.h ex_def.h + .PATH: ${.CURDIR}/../vi ${.CURDIR}/../ex ${.CURDIR}/../cl ${.CURDIR}/../common ${.CURDIR}/../docs/USD.doc/vi.man .include "../../Makefile.inc" diff --git a/usr.bin/vi/common/options.awk b/usr.bin/vi/common/options.awk index 261b48f6d42..c23129d727c 100644 --- a/usr.bin/vi/common/options.awk +++ b/usr.bin/vi/common/options.awk @@ -1,11 +1,16 @@ -# $OpenBSD: options.awk,v 1.3 2001/01/29 01:58:31 niklas Exp $ +# $OpenBSD: options.awk,v 1.4 2017/12/14 10:02:53 martijn Exp $ # @(#)options.awk 10.1 (Berkeley) 6/8/95 - + +BEGIN { + printf("enum {\n"); + first = 1; +} /^\/\* O_[0-9A-Z_]*/ { - printf("#define %s %d\n", $2, cnt++); + printf("\t%s%s,\n", $2, first ? " = 0" : ""); + first = 0; next; } END { - printf("#define O_OPTIONCOUNT %d\n", cnt); + printf("\tO_OPTIONCOUNT\n};\n"); } diff --git a/usr.bin/vi/ex/ex.awk b/usr.bin/vi/ex/ex.awk index 709d3468bd1..cfa1a1c44ee 100644 --- a/usr.bin/vi/ex/ex.awk +++ b/usr.bin/vi/ex/ex.awk @@ -1,8 +1,16 @@ -# $OpenBSD: ex.awk,v 1.2 2001/01/29 01:58:40 niklas Exp $ +# $OpenBSD: ex.awk,v 1.3 2017/12/14 10:02:53 martijn Exp $ # @(#)ex.awk 10.1 (Berkeley) 6/8/95 - + +BEGIN { + printf("enum {"); + first = 1; +} /^\/\* C_[0-9A-Z_]* \*\/$/ { - printf("#define %s %d\n", $2, cnt++); + printf("%s\n\t%s%s", first ? "" : ",", $2, first ? " = 0" : ""); + first = 0; next; } +END { + printf("\n};\n"); +} diff --git a/usr.bin/vi/include/ex_def.h b/usr.bin/vi/include/ex_def.h deleted file mode 100644 index 16ab6709620..00000000000 --- a/usr.bin/vi/include/ex_def.h +++ /dev/null @@ -1,76 +0,0 @@ -/* $OpenBSD: ex_def.h,v 1.5 2015/11/19 07:53:31 bentley Exp $ */ - -#define C_SCROLL 0 -#define C_BANG 1 -#define C_HASH 2 -#define C_SUBAGAIN 3 -#define C_STAR 4 -#define C_SHIFTL 5 -#define C_EQUAL 6 -#define C_SHIFTR 7 -#define C_AT 8 -#define C_APPEND 9 -#define C_ABBR 10 -#define C_ARGS 11 -#define C_BG 12 -#define C_CHANGE 13 -#define C_CD 14 -#define C_CHDIR 15 -#define C_COPY 16 -#define C_DELETE 17 -#define C_DISPLAY 18 -#define C_EDIT 19 -#define C_EX 20 -#define C_EXUSAGE 21 -#define C_FILE 22 -#define C_FG 23 -#define C_GLOBAL 24 -#define C_HELP 25 -#define C_INSERT 26 -#define C_JOIN 27 -#define C_K 28 -#define C_LIST 29 -#define C_MOVE 30 -#define C_MARK 31 -#define C_MAP 32 -#define C_MKEXRC 33 -#define C_NEXT 34 -#define C_NUMBER 35 -#define C_OPEN 36 -#define C_PRINT 37 -#define C_PRESERVE 38 -#define C_PREVIOUS 39 -#define C_PUT 40 -#define C_QUIT 41 -#define C_READ 42 -#define C_RECOVER 43 -#define C_RESIZE 44 -#define C_REWIND 45 -#define C_SUBSTITUTE 46 -#define C_SCRIPT 47 -#define C_SET 48 -#define C_SHELL 49 -#define C_SOURCE 50 -#define C_STOP 51 -#define C_SUSPEND 52 -#define C_T 53 -#define C_TAG 54 -#define C_TAGNEXT 55 -#define C_TAGPOP 56 -#define C_TAGPREV 57 -#define C_TAGTOP 58 -#define C_UNDO 59 -#define C_UNABBREVIATE 60 -#define C_UNMAP 61 -#define C_V 62 -#define C_VERSION 63 -#define C_VISUAL_EX 64 -#define C_VISUAL_VI 65 -#define C_VIUSAGE 66 -#define C_WRITE 67 -#define C_WN 68 -#define C_WQ 69 -#define C_XIT 70 -#define C_YANK 71 -#define C_Z 72 -#define C_SUBTILDE 73 diff --git a/usr.bin/vi/include/options_def.h b/usr.bin/vi/include/options_def.h deleted file mode 100644 index f080dfa6a3b..00000000000 --- a/usr.bin/vi/include/options_def.h +++ /dev/null @@ -1,75 +0,0 @@ -/* $OpenBSD: options_def.h,v 1.8 2017/07/03 07:01:14 bentley Exp $ */ - -enum { - O_ALTWERASE = 0, - O_AUTOINDENT, - O_AUTOPRINT, - O_AUTOWRITE, - O_BACKUP, - O_BEAUTIFY, - O_CDPATH, - O_CEDIT, - O_COLUMNS, - O_COMMENT, - O_EDCOMPATIBLE, - O_ESCAPETIME, - O_ERRORBELLS, - O_EXRC, - O_EXTENDED, - O_FILEC, - O_FLASH, - O_HARDTABS, - O_ICLOWER, - O_IGNORECASE, - O_KEYTIME, - O_LEFTRIGHT, - O_LINES, - O_LIST, - O_LOCKFILES, - O_MAGIC, - O_MATCHTIME, - O_MESG, - O_NOPRINT, - O_NUMBER, - O_OCTAL, - O_OPEN, - O_PARAGRAPHS, - O_PATH, - O_PRINT, - O_PROMPT, - O_READONLY, - O_RECDIR, - O_REMAP, - O_REPORT, - O_RULER, - O_SCROLL, - O_SEARCHINCR, - O_SECTIONS, - O_SECURE, - O_SHELL, - O_SHELLMETA, - O_SHIFTWIDTH, - O_SHOWMATCH, - O_SHOWMODE, - O_SIDESCROLL, - O_TABSTOP, - O_TAGLENGTH, - O_TAGS, - O_TERM, - O_TERSE, - O_TILDEOP, - O_TIMEOUT, - O_TTYWERASE, - O_VERBOSE, - O_W1200, - O_W300, - O_W9600, - O_WARN, - O_WINDOW, - O_WINDOWNAME, - O_WRAPLEN, - O_WRAPMARGIN, - O_WRAPSCAN, - O_WRITEANY, - O_OPTIONCOUNT, -}; -- 2.20.1