On Mon, Dec 11, 2017 at 10:11:44AM +0100, Martijn van Duren wrote: > ping > > On 11/11/17 10:59, Martijn van Duren wrote: > > Hello tech@, > > > > I've gotten confused by the awk scripts a few times now. > > They seem to unused and I had to really look where they were originally > > intended. For the curious: > > awk -f common/options.awk common/options.c > include/options_def.h > > awk -f ex/ex.awk ex/ex_cmd.c > include/ex_def.h > > > > The options_def.h file has moved from define to enum by bentley earlier > > this year, so there seems to be no motivation to move back to the awk > > scripts. > > > > This does however mean that we have to keep a close eye on the options > > and commands we expose and keep them in sync manually. > > > > Another option would be to keep the scripts and hook them into the > > makefile and cvs rm include/{options,ex}_def.h, but that would require > > some black magic I haven't mastered yet.
I'm not 100% sure it's a good idea to generate these files from the source files, but one could consider doing something like this instead: Generate options_def.h and ex_def.h in build/obj/ using the awk files if needed and remove them from includes/ and thus the need to maintain them manually. I changed options.awk to emit an enum instead of the #defines (but this is not really needed). This way, the only difference between the files in build and includes is in the options comment. Index: usr.bin/vi/build/Makefile =================================================================== RCS file: /var/cvs/src/usr.bin/vi/build/Makefile,v retrieving revision 1.24 diff -u -p -r1.24 Makefile --- usr.bin/vi/build/Makefile 30 Mar 2016 06:38:46 -0000 1.24 +++ usr.bin/vi/build/Makefile 11 Dec 2017 10:12:10 -0000 @@ -4,7 +4,7 @@ PROG= vi # Modern curses (ncurses) -CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../include +CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../include -I. LDADD+=-lcurses DPADD+= ${LIBCURSES} @@ -37,6 +37,16 @@ SRCS= cl_funcs.c cl_main.c cl_read.c cl_ 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 \ + > options_def.h + +ex_def.h: ex/ex.awk ex/ex_cmd.c + awk -f ${.CURDIR}/../ex/ex.awk ${.CURDIR}/../ex/ex_cmd.c > ex_def.h + +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 Index: usr.bin/vi/common/options.awk =================================================================== RCS file: /var/cvs/src/usr.bin/vi/common/options.awk,v retrieving revision 1.3 diff -u -p -r1.3 options.awk --- usr.bin/vi/common/options.awk 29 Jan 2001 01:58:31 -0000 1.3 +++ usr.bin/vi/common/options.awk 11 Dec 2017 10:20:39 -0000 @@ -1,11 +1,16 @@ # $OpenBSD: options.awk,v 1.3 2001/01/29 01:58:31 niklas 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"); } Index: usr.bin/vi/include/ex_def.h =================================================================== RCS file: usr.bin/vi/include/ex_def.h diff -N usr.bin/vi/include/ex_def.h --- usr.bin/vi/include/ex_def.h 19 Nov 2015 07:53:31 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -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 Index: usr.bin/vi/include/options_def.h =================================================================== RCS file: usr.bin/vi/include/options_def.h diff -N usr.bin/vi/include/options_def.h --- usr.bin/vi/include/options_def.h 3 Jul 2017 07:01:14 -0000 1.8 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -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, -};