├── .gitattributes ├── .gitignore ├── BSDmakefile ├── ChangeLog ├── ChangeLog.license ├── GNUmakefile ├── LICENSE.md ├── LICENSES ├── BSD-2-Clause.txt ├── BSD-3-Clause.txt └── ISC.txt ├── README.md ├── README_pt_BR.md ├── REUSE.toml ├── cl ├── cl.h ├── cl_extern.h ├── cl_funcs.c ├── cl_main.c ├── cl_read.c ├── cl_screen.c ├── cl_term.c └── extern.h ├── common ├── args.h ├── common.h ├── cut.c ├── cut.h ├── delete.c ├── exf.c ├── exf.h ├── gs.h ├── key.c ├── key.h ├── line.c ├── log.c ├── log.h ├── main.c ├── mark.c ├── mark.h ├── mem.h ├── msg.c ├── msg.h ├── options.awk ├── options.c ├── options.h ├── options_f.c ├── put.c ├── recover.c ├── screen.c ├── screen.h ├── search.c ├── seq.c ├── seq.h └── util.c ├── db ├── btree │ ├── bt_close.c │ ├── bt_conv.c │ ├── bt_debug.c │ ├── bt_delete.c │ ├── bt_get.c │ ├── bt_open.c │ ├── bt_overflow.c │ ├── bt_page.c │ ├── bt_put.c │ ├── bt_search.c │ ├── bt_seq.c │ ├── bt_split.c │ ├── bt_utils.c │ ├── btree.h │ └── extern.h ├── db │ └── db.c ├── hash │ ├── bsd_ndbm.h │ ├── extern.h │ ├── hash.c │ ├── hash.h │ ├── hash_bigkey.c │ ├── hash_buf.c │ ├── hash_func.c │ ├── hash_log2.c │ ├── hash_page.c │ ├── ndbm.c │ └── page.h ├── mpool │ └── mpool.c └── recno │ ├── extern.h │ ├── rec_close.c │ ├── rec_delete.c │ ├── rec_get.c │ ├── rec_open.c │ ├── rec_put.c │ ├── rec_search.c │ ├── rec_seq.c │ ├── rec_utils.c │ └── recno.h ├── docs ├── USD.doc │ ├── edit │ │ ├── edit.vindex │ │ └── edittut.ms │ ├── exref │ │ ├── ex.rm │ │ └── ex.summary │ ├── re_format │ │ └── vi_regex.7 │ ├── vi.man │ │ └── vi.1 │ └── vitut │ │ ├── vi.apwh.ms │ │ ├── vi.chars │ │ ├── vi.in │ │ └── vi.summary ├── ev ├── ev.license ├── help ├── help.license ├── internals │ ├── autowrite │ ├── autowrite.license │ ├── context │ ├── context.license │ ├── gdb.script │ ├── input │ ├── input.license │ ├── openmode │ ├── openmode.license │ ├── quoting │ ├── quoting.license │ ├── structures │ └── structures.license └── tutorial │ ├── vi.advanced │ ├── vi.advanced.license │ ├── vi.beginner │ ├── vi.beginner.license │ └── vi.tut.csh ├── ex ├── ex.awk ├── ex.c ├── ex.h ├── ex_abbrev.c ├── ex_append.c ├── ex_args.c ├── ex_argv.c ├── ex_at.c ├── ex_bang.c ├── ex_cd.c ├── ex_cmd.c ├── ex_delete.c ├── ex_display.c ├── ex_edit.c ├── ex_equal.c ├── ex_file.c ├── ex_filter.c ├── ex_global.c ├── ex_init.c ├── ex_join.c ├── ex_map.c ├── ex_mark.c ├── ex_mkexrc.c ├── ex_move.c ├── ex_open.c ├── ex_preserve.c ├── ex_print.c ├── ex_put.c ├── ex_quit.c ├── ex_read.c ├── ex_screen.c ├── ex_script.c ├── ex_set.c ├── ex_shell.c ├── ex_shift.c ├── ex_source.c ├── ex_stop.c ├── ex_subst.c ├── ex_tag.c ├── ex_txt.c ├── ex_undo.c ├── ex_usage.c ├── ex_util.c ├── ex_version.c ├── ex_visual.c ├── ex_write.c ├── ex_yank.c ├── ex_z.c ├── script.h ├── tag.h └── version.h ├── include ├── bitstring.h ├── bsd_db.h ├── bsd_err.h ├── bsd_fcntl.h ├── bsd_regex.h ├── bsd_stdlib.h ├── bsd_string.h ├── bsd_termios.h ├── bsd_unistd.h ├── com_extern.h ├── compat.h ├── compat_bsd_db.h ├── ex_extern.h ├── libgen.h ├── mpool.h ├── pathnames.h ├── poll.h ├── sys │ ├── proc.h │ ├── queue.h │ ├── stat.h │ ├── time.h │ ├── tree.h │ └── types.h ├── util.h └── vi_extern.h ├── openbsd ├── basename.c ├── dirname.c ├── err.c ├── errc.c ├── errc.h ├── errx.c ├── getopt_long.c ├── getopt_long.h ├── getprogname.c ├── issetugid.c ├── minpwcache.c ├── minpwcache.h ├── open.c ├── pledge.c ├── reallocarray.c ├── setmode.c ├── setmode.h ├── strlcat.c ├── strlcpy.c ├── strtonum.c ├── verr.c ├── verrc.c ├── verrx.c ├── vwarn.c ├── vwarnc.c ├── vwarnx.c ├── warn.c ├── warnc.c └── warnx.c ├── regex ├── bsd_regex2.h ├── cclass.h ├── cname.h ├── engine.c ├── regcomp.c ├── regerror.c ├── regexec.c ├── regfree.c └── utils.h ├── scripts ├── virecover └── virecover.8 ├── vi ├── getc.c ├── v_at.c ├── v_ch.c ├── v_cmd.c ├── v_delete.c ├── v_ex.c ├── v_increment.c ├── v_init.c ├── v_itxt.c ├── v_left.c ├── v_mark.c ├── v_match.c ├── v_paragraph.c ├── v_put.c ├── v_redraw.c ├── v_replace.c ├── v_right.c ├── v_screen.c ├── v_scroll.c ├── v_search.c ├── v_section.c ├── v_sentence.c ├── v_status.c ├── v_txt.c ├── v_ulcase.c ├── v_undo.c ├── v_util.c ├── v_word.c ├── v_xchar.c ├── v_yank.c ├── v_z.c ├── v_zexit.c ├── vi.c ├── vi.h ├── vs_line.c ├── vs_msg.c ├── vs_refresh.c ├── vs_relative.c ├── vs_smap.c └── vs_split.c └── xinstall ├── xinstall.1 └── xinstall.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 3 | *.txt linguist-documentation 4 | *.ms linguist-documentation 5 | *.1 linguist-documentation 6 | *.8 linguist-documentation 7 | *.md linguist-documentation 8 | *.rm linguist-documentation 9 | *.advanced linguist-documentation 10 | *.beginner linguist-documentation 11 | *.summary linguist-documentation 12 | *.vindex linguist-documentation 13 | *.chars linguist-documentation 14 | *.refs linguist-documentation 15 | *.roff linguist-documentation 16 | ./docs/* linguist-documentation 17 | *.in linguist-vendored 18 | *.csh linguist-vendored 19 | *.script linguist-vendored 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 3 | 4 | # Prerequisites 5 | *.d 6 | 7 | # Timing 8 | *.t 9 | 10 | # Object files 11 | *.o 12 | *.ko 13 | *.obj 14 | *.elf 15 | *.dll 16 | *.exe 17 | 18 | # Linker output 19 | *.ilk 20 | *.map 21 | *.exp 22 | 23 | # Precompiled Headers 24 | *.gch 25 | *.pch 26 | 27 | # Libraries 28 | *.lib 29 | *.a 30 | *.la 31 | *.lo 32 | 33 | # Shared objects (inc. Windows DLLs) 34 | *.dll 35 | *.so 36 | *.so.* 37 | *.dylib 38 | 39 | # Executables 40 | *.exe 41 | *.out 42 | *.app 43 | *.i*86 44 | *.x86_64 45 | *.hex 46 | 47 | # Debug files 48 | *.dSYM/ 49 | *.su 50 | *.idb 51 | *.pdb 52 | 53 | # Kernel Module Compile Results 54 | *.mod* 55 | *.cmd 56 | .tmp_versions/ 57 | modules.order 58 | Module.symvers 59 | Mkfile.old 60 | dkms.conf 61 | 62 | # Output 63 | common/options_def.h 64 | ex/ex_def.h 65 | bin/* 66 | 67 | # Patch 68 | *.rej 69 | *.orig 70 | *.diff 71 | 72 | # Junk 73 | typescript 74 | .DS_Store 75 | .cproject 76 | .project 77 | .settings/ 78 | .vscode/ 79 | .nvimlog 80 | .vimlog 81 | *.*.swp 82 | test.txt 83 | 84 | # Tags 85 | tags 86 | .tags 87 | ctags 88 | .ctags 89 | etags 90 | .etags 91 | .TAGS 92 | TAGS 93 | GRTAGS 94 | GTAGS 95 | GPATH 96 | 97 | # Cores 98 | core 99 | *.core 100 | 101 | # Local 102 | .autoenv 103 | .envrc 104 | 105 | # Bad Targets 106 | all 107 | clean 108 | install 109 | distclean 110 | 111 | # Profiling 112 | *.gcda 113 | *.gcov 114 | *.gcno 115 | *.profdata 116 | *.profout 117 | 118 | # Tidy 119 | compile_commands.json 120 | -------------------------------------------------------------------------------- /BSDmakefile: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # - O p e n V i - # 3 | ############################################################################### 4 | # vim: filetype=make:tabstop=8:tw=79:noexpandtab:colorcolumn=79 5 | # SPDX-License-Identifier: BSD-3-Clause 6 | ############################################################################### 7 | 8 | ############################################################################### 9 | # 10 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 11 | # 12 | # Copying and distribution of this file, with or without modification, 13 | # are permitted in any medium without royalty provided the copyright 14 | # notice and this notice are preserved. This file is offered "AS-IS", 15 | # without any warranty. 16 | # 17 | ############################################################################### 18 | 19 | ############################################################################### 20 | # Configuration 21 | 22 | .SHELL: name=sh 23 | .MAIN: all 24 | .MAKE.JOBS ?= 1 25 | .NOTPARALLEL: _FAIL all _GMAKE $(.TARGETS) 26 | .PHONY: _FAIL all _GMAKE $(.TARGETS) 27 | $(.TARGETS): _GMAKE 28 | 29 | ############################################################################### 30 | # Wrapper 31 | 32 | _GMAKE: 33 | @command -v gmake > /dev/null 2>&1 || \ 34 | { \ 35 | printf '\rError: %s\n' "GNU Make is required." 1>&2; \ 36 | exit 1; \ 37 | } && \ 38 | command gmake \ 39 | $$(printf '%s' "$(MAKEFLAGS)" 2> /dev/null | \ 40 | sed -e 's/-J .* //' \ 41 | -e 's/-J.* //' 2> /dev/null) \ 42 | $(.TARGETS) 43 | 44 | ############################################################################### 45 | -------------------------------------------------------------------------------- /ChangeLog.license: -------------------------------------------------------------------------------- 1 | SPDX-License-Identifier: BSD-3-Clause 2 | Copyright (c) 2021-2024 Jeffrey H. Johnson and contributors 3 | -------------------------------------------------------------------------------- /LICENSES/BSD-2-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2000, 2006, 2013, 2020 The NetBSD Foundation, Inc. 2 | Copyright (c) 2002 Niels Provos 3 | Copyright (c) 2022-2024 Jeffrey H. Johnson 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /LICENSES/ISC.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 1997, 1998, 2002, 2004, 2015 2 | Todd C. Miller 3 | Copyright (c) 2004 Ted Unangst and Todd Miller 4 | Copyright (c) 2008 Otto Moerbeek 5 | Copyright (c) 2013 Antoine Jacoutot 6 | Copyright (c) 2015 Philip Guenther 7 | Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | 9 | Permission to use, copy, modify, and distribute this software for any 10 | purpose with or without fee is hereby granted, provided that the above 11 | copyright notice and this permission notice appear in all copies. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 3 | version = 1 4 | SPDX-PackageName = "OpenVi" 5 | SPDX-PackageSupplier = "Jeffrey H. Johnson " 6 | SPDX-PackageDownloadLocation = "https://github.com/johnsonjh/OpenVi" 7 | annotations = [] 8 | -------------------------------------------------------------------------------- /cl/cl.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: cl.h,v 1.12 2021/09/02 11:19:02 schwarze Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)cl.h 10.19 (Berkeley) 9/24/96 15 | */ 16 | 17 | extern volatile sig_atomic_t cl_sigint; 18 | extern volatile sig_atomic_t cl_sigterm; 19 | extern volatile sig_atomic_t cl_sigwinch; 20 | 21 | typedef struct _cl_private { 22 | CHAR_T ibuf[512]; /* Input keys. */ 23 | 24 | int eof_count; /* EOF count. */ 25 | 26 | struct termios orig; /* Original terminal values. */ 27 | struct termios ex_enter;/* Terminal values to enter ex. */ 28 | struct termios vi_enter;/* Terminal values to enter vi. */ 29 | 30 | char *el; /* Clear to EOL terminal string. */ 31 | char *cup; /* Cursor movement terminal string. */ 32 | char *cuu1; /* Cursor up terminal string. */ 33 | char *rmso, *smso; /* Inverse video terminal strings. */ 34 | char *smcup, *rmcup; /* Terminal start/stop strings. */ 35 | 36 | #define INDX_HUP 0 37 | #define INDX_INT 1 38 | #define INDX_TERM 2 39 | #define INDX_WINCH 3 40 | #define INDX_MAX 4 /* Original signal information. */ 41 | struct sigaction oact[INDX_MAX]; 42 | 43 | enum { /* Tty group write mode. */ 44 | TGW_UNKNOWN=0, TGW_SET, TGW_UNSET } tgw; 45 | 46 | enum { /* Terminal initialization strings. */ 47 | TE_SENT=0, TI_SENT } ti_te; 48 | 49 | #define CL_IN_EX 0x0001 /* Currently running ex. */ 50 | #define CL_RENAME 0x0002 /* X11 xterm icon/window renamed. */ 51 | #define CL_RENAME_OK 0x0004 /* User wants the windows renamed. */ 52 | #define CL_SCR_EX_INIT 0x0008 /* Ex screen initialized. */ 53 | #define CL_SCR_VI_INIT 0x0010 /* Vi screen initialized. */ 54 | #define CL_STDIN_TTY 0x0020 /* Talking to a terminal. */ 55 | u_int32_t flags; 56 | } CL_PRIVATE; 57 | 58 | #define CLP(sp) ((CL_PRIVATE *)((sp)->gp->cl_private)) 59 | #define GCLP(gp) ((CL_PRIVATE *)(gp)->cl_private) 60 | 61 | /* Return possibilities from the keyboard read routine. */ 62 | typedef enum { INP_OK=0, INP_EOF, INP_ERR, INP_INTR, INP_TIMEOUT } input_t; 63 | 64 | /* The screen line relative to a specific window. */ 65 | #define RLNO(sp, lno) (sp)->woff + (lno) 66 | 67 | /* X11 xterm escape sequence to rename the icon/window. */ 68 | #define XTERM_RENAME "\033]0;%s\007" 69 | 70 | #include "cl_extern.h" 71 | -------------------------------------------------------------------------------- /cl/cl_extern.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | int cl_addstr(SCR *, const char *, size_t); 37 | int cl_attr(SCR *, scr_attr_t, int); 38 | int cl_baud(SCR *, unsigned long *); 39 | int cl_bell(SCR *); 40 | int cl_clrtoeol(SCR *); 41 | int cl_cursor(SCR *, size_t *, size_t *); 42 | int cl_deleteln(SCR *); 43 | int cl_ex_adjust(SCR *, exadj_t); 44 | int cl_insertln(SCR *); 45 | int cl_keyval(SCR *, scr_keyval_t, CHAR_T *, int *); 46 | int cl_move(SCR *, size_t, size_t); 47 | int cl_refresh(SCR *, int); 48 | int cl_rename(SCR *, char *, int); 49 | int cl_suspend(SCR *, int *); 50 | void cl_usage(void); 51 | int sig_init(GS *, SCR *); 52 | int cl_event(SCR *, EVENT *, u_int32_t, int); 53 | int cl_screen(SCR *, u_int32_t); 54 | int cl_quit(GS *); 55 | int cl_getcap(SCR *, char *, char **); 56 | int cl_term_init(SCR *); 57 | int cl_term_end(GS *); 58 | int cl_fmap(SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t); 59 | int cl_optchange(SCR *, int, char *, unsigned long *); 60 | int cl_omesg(SCR *, CL_PRIVATE *, int); 61 | int cl_ssize(SCR *, int, size_t *, size_t *, int *); 62 | int cl_putchar(int); 63 | -------------------------------------------------------------------------------- /common/args.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: args.h,v 1.5 2016/05/27 09:18:11 martijn Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)args.h 10.2 (Berkeley) 3/6/96 15 | */ 16 | 17 | /* 18 | * Structure for building "argc/argv" vector of arguments. 19 | * 20 | * !!! 21 | * All arguments are NULL terminated as well as having an associated length. 22 | * The argument vector is NOT necessarily NULL terminated. The proper way 23 | * to check the number of arguments is to use the argc value in the EXCMDARG 24 | * structure or to walk the array until an ARGS structure with a length of 0 25 | * is found. 26 | */ 27 | typedef struct _args { 28 | CHAR_T *bp; /* Argument. */ 29 | size_t blen; /* Buffer length. */ 30 | size_t len; /* Argument length. */ 31 | 32 | #define A_ALLOCATED 0x01 /* If allocated space. */ 33 | u_int8_t flags; 34 | } ARGS; 35 | -------------------------------------------------------------------------------- /common/log.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: log.h,v 1.3 2001/01/29 01:58:30 niklas Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)log.h 10.2 (Berkeley) 3/6/96 15 | */ 16 | 17 | #define LOG_NOTYPE 0 18 | #define LOG_CURSOR_INIT 1 19 | #define LOG_CURSOR_END 2 20 | #define LOG_LINE_APPEND 3 21 | #define LOG_LINE_DELETE 4 22 | #define LOG_LINE_INSERT 5 23 | #define LOG_LINE_RESET_F 6 24 | #define LOG_LINE_RESET_B 7 25 | #define LOG_MARK 8 26 | -------------------------------------------------------------------------------- /common/mark.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: mark.h,v 1.5 2016/05/27 09:18:11 martijn Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)mark.h 10.3 (Berkeley) 3/6/96 15 | */ 16 | 17 | /* 18 | * The MARK and LMARK structures define positions in the file. There are 19 | * two structures because the mark subroutines are the only places where 20 | * anything cares about something other than line and column. 21 | * 22 | * Because of the different interfaces used by the db(3) package, curses, 23 | * and users, the line number is 1 based and the column number is 0 based. 24 | * Additionally, it is known that the out-of-band line number is less than 25 | * any legal line number. The line number is of type recno_t, as that's 26 | * the underlying type of the database. The column number is of type size_t, 27 | * guaranteeing that we can malloc a line. 28 | */ 29 | 30 | struct _mark { 31 | #define OOBLNO 0 /* Out-of-band line number. */ 32 | recno_t lno; /* Line number. */ 33 | size_t cno; /* Column number. */ 34 | }; 35 | 36 | struct _lmark { 37 | LIST_ENTRY(_lmark) q; /* Linked list of marks. */ 38 | recno_t lno; /* Line number. */ 39 | size_t cno; /* Column number. */ 40 | CHAR_T name; /* Mark name. */ 41 | 42 | #define MARK_DELETED 0x01 /* Mark was deleted. */ 43 | #define MARK_USERSET 0x02 /* User set this mark. */ 44 | u_int8_t flags; 45 | }; 46 | 47 | #define ABSMARK1 '\'' /* Absolute mark name. */ 48 | #define ABSMARK2 '`' /* Absolute mark name. */ 49 | -------------------------------------------------------------------------------- /common/msg.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: msg.h,v 1.3 2001/01/29 01:58:31 niklas Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)msg.h 10.10 (Berkeley) 5/10/96 15 | */ 16 | 17 | /* 18 | * Common messages (continuation or confirmation). 19 | */ 20 | 21 | typedef enum { 22 | CMSG_CONF, CMSG_CONT, CMSG_CONT_EX, 23 | CMSG_CONT_R, CMSG_CONT_S, CMSG_CONT_Q } cmsg_t; 24 | 25 | /* 26 | * Message types. 27 | * 28 | * !!! 29 | * In historical vi, O_VERBOSE didn't exist, and O_TERSE made the error 30 | * messages shorter. In this implementation, O_TERSE has no effect and 31 | * O_VERBOSE results in informational displays about common errors, for 32 | * naive users. 33 | * 34 | * M_NONE Display to the user, no reformatting, no nothing. 35 | * 36 | * M_BERR Error: M_ERR if O_VERBOSE, else bell. 37 | * M_ERR Error: Display in inverse video. 38 | * M_INFO Info: Display in normal video, except in silent mode. 39 | * M_SYSERR Error: M_ERR, using strerror(3) message. 40 | * M_VINFO Info: M_INFO if O_VERBOSE, else ignore. 41 | * M_XINFO Info: Like M_INFO, but ignoring silent mode setting. 42 | * 43 | * The underlying message display routines only need to know about M_NONE, 44 | * M_ERR and M_INFO -- all the other message types are converted into one 45 | * of them by the message routines. 46 | */ 47 | 48 | typedef enum { 49 | M_NONE = 1, M_BERR, M_ERR, M_INFO, 50 | M_SYSERR, M_VINFO, M_XINFO } mtype_t; 51 | 52 | /* 53 | * There are major problems with error messages being generated by routines 54 | * preparing the screen to display error messages. It's possible for the 55 | * editor to generate messages before we have a screen in which to display 56 | * them, or during the transition between ex (and vi startup) and a true vi. 57 | * There's a queue in the global area to hold them. 58 | * 59 | * If SC_EX/SC_VI is set, that's the mode that the editor is in. If the flag 60 | * S_SCREEN_READY is set, that means that the screen is prepared to display 61 | * messages. 62 | */ 63 | 64 | typedef struct _msgh MSGH; /* MSGS list head structure. */ 65 | LIST_HEAD(_msgh, _msg); 66 | struct _msg { 67 | LIST_ENTRY(_msg) q; /* Linked list of messages. */ 68 | mtype_t mtype; /* Message type: M_NONE, M_ERR, M_INFO. */ 69 | char *buf; /* Message buffer. */ 70 | size_t len; /* Message length. */ 71 | }; 72 | 73 | /* Flags to msgq_status(). */ 74 | #define MSTAT_SHOWLAST 0x01 /* Show the line number of the last line. */ 75 | #define MSTAT_TRUNCATE 0x02 /* Truncate the file name if it's too long. */ 76 | -------------------------------------------------------------------------------- /common/options.awk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 | # The Regents of the University of California 4 | # Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 5 | # Keith Bostic 6 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 7 | 8 | BEGIN { 9 | printf("enum {\n"); 10 | first = 1; 11 | } 12 | /^\/\* O_[0-9A-Z_]*/ { 13 | printf("\t%s%s,\n", $2, first ? " = 0" : ""); 14 | first = 0; 15 | next; 16 | } 17 | END { 18 | printf("\tO_OPTIONCOUNT\n};\n"); 19 | } 20 | -------------------------------------------------------------------------------- /common/seq.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: seq.h,v 1.5 2016/05/27 09:18:11 martijn Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)seq.h 10.3 (Berkeley) 3/6/96 15 | */ 16 | 17 | /* 18 | * Map and abbreviation structures. 19 | * 20 | * The map structure is doubly linked list, sorted by input string and by 21 | * input length within the string. (The latter is necessary so that short 22 | * matches will happen before long matches when the list is searched.) 23 | * Additionally, there is a bitmap which has bits set if there are entries 24 | * starting with the corresponding character. This keeps us from walking 25 | * the list unless it's necessary. 26 | * 27 | * The name and the output fields of a SEQ can be empty, i.e. NULL. 28 | * Only the input field is required. 29 | * 30 | * XXX 31 | * The fast-lookup bits are never turned off -- users don't usually unmap 32 | * things, though, so it's probably not a big deal. 33 | */ 34 | 35 | struct _seq { 36 | LIST_ENTRY(_seq) q; /* Linked list of all sequences. */ 37 | seq_t stype; /* Sequence type. */ 38 | CHAR_T *name; /* Sequence name (if any). */ 39 | size_t nlen; /* Name length. */ 40 | CHAR_T *input; /* Sequence input keys. */ 41 | size_t ilen; /* Input keys length. */ 42 | CHAR_T *output; /* Sequence output keys. */ 43 | size_t olen; /* Output keys length. */ 44 | 45 | #define SEQ_FUNCMAP 0x01 /* If unresolved function key. */ 46 | #define SEQ_NOOVERWRITE 0x02 /* Don't replace existing entry. */ 47 | #define SEQ_SCREEN 0x04 /* If screen specific. */ 48 | #define SEQ_USERDEF 0x08 /* If user defined. */ 49 | u_int8_t flags; 50 | }; 51 | -------------------------------------------------------------------------------- /db/btree/bt_page.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: bt_page.c,v 1.9 2005/08/05 13:02:59 espie Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1990, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | */ 39 | 40 | #include "../../include/compat.h" 41 | 42 | #include 43 | 44 | #include 45 | 46 | #include 47 | #include 48 | #include "btree.h" 49 | 50 | /* 51 | * __bt_free -- 52 | * Put a page on the freelist. 53 | * 54 | * Parameters: 55 | * t: tree 56 | * h: page to free 57 | * 58 | * Returns: 59 | * RET_ERROR, RET_SUCCESS 60 | * 61 | * Side-effect: 62 | * mpool_put's the page. 63 | */ 64 | 65 | int 66 | __bt_free(BTREE *t, PAGE *h) 67 | { 68 | /* Insert the page at the head of the free list. */ 69 | h->prevpg = P_INVALID; 70 | h->nextpg = t->bt_free; 71 | t->bt_free = h->pgno; 72 | F_SET(t, B_METADIRTY); 73 | 74 | /* Make sure the page gets written back. */ 75 | return (mpool_put(t->bt_mp, h, MPOOL_DIRTY)); 76 | } 77 | 78 | /* 79 | * __bt_new -- 80 | * Get a new page, preferably from the freelist. 81 | * 82 | * Parameters: 83 | * t: tree 84 | * npg: storage for page number. 85 | * 86 | * Returns: 87 | * Pointer to a page, NULL on error. 88 | */ 89 | 90 | PAGE * 91 | __bt_new(BTREE *t, pgno_t *npg) 92 | { 93 | PAGE *h; 94 | 95 | if (t->bt_free != P_INVALID && 96 | (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) { 97 | *npg = t->bt_free; 98 | t->bt_free = h->nextpg; 99 | F_SET(t, B_METADIRTY); 100 | return (h); 101 | } 102 | return (mpool_new(t->bt_mp, npg, MPOOL_PAGE_NEXT)); 103 | } 104 | -------------------------------------------------------------------------------- /db/btree/extern.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: extern.h,v 1.8 2015/08/27 04:37:09 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1991, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)extern.h 8.10 (Berkeley) 7/20/94 40 | */ 41 | 42 | __BEGIN_HIDDEN_DECLS 43 | int __bt_close(DB *); 44 | int __bt_cmp(BTREE *, const DBT *, EPG *); 45 | int __bt_defcmp(const DBT *, const DBT *); 46 | size_t __bt_defpfx(const DBT *, const DBT *); 47 | int __bt_delete(const DB *, const DBT *, unsigned int); 48 | int __bt_dleaf(BTREE *, const DBT *, PAGE *, unsigned int); 49 | int __bt_fd(const DB *); 50 | int __bt_free(BTREE *, PAGE *); 51 | int __bt_get(const DB *, const DBT *, DBT *, unsigned int); 52 | PAGE *__bt_new(BTREE *, pgno_t *); 53 | void __bt_pgin(void *, pgno_t, void *); 54 | void __bt_pgout(void *, pgno_t, void *); 55 | int __bt_put(const DB *dbp, DBT *, const DBT *, unsigned int); 56 | int __bt_ret(BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int); 57 | EPG *__bt_search(BTREE *, const DBT *, int *); 58 | int __bt_seq(const DB *, DBT *, DBT *, unsigned int); 59 | void __bt_setcur(BTREE *, pgno_t, unsigned int); 60 | int __bt_split(BTREE *, PAGE *, 61 | const DBT *, const DBT *, int, size_t, u_int32_t); 62 | int __bt_sync(const DB *, unsigned int); 63 | 64 | int __ovfl_delete(BTREE *, void *); 65 | int __ovfl_get(BTREE *, void *, size_t *, void **, size_t *); 66 | int __ovfl_put(BTREE *, const DBT *, pgno_t *); 67 | 68 | #ifdef DEBUG 69 | void __bt_dnpage(DB *, pgno_t); 70 | void __bt_dpage(PAGE *); 71 | void __bt_dump(DB *); 72 | #endif /* ifdef DEBUG */ 73 | #ifdef STATISTICS 74 | void __bt_stat(DB *); 75 | #endif /* ifdef STATISTICS */ 76 | __END_HIDDEN_DECLS 77 | -------------------------------------------------------------------------------- /db/hash/bsd_ndbm.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ndbm.h,v 1.6 2004/05/03 17:27:50 millert Exp $ */ 2 | /* $NetBSD: ndbm.h,v 1.6 1995/07/20 23:31:11 jtc Exp $ */ 3 | 4 | /* SPDX-License-Identifier: BSD-3-Clause */ 5 | 6 | /* 7 | * Copyright (c) 1990, 1993 8 | * The Regents of the University of California. All rights reserved. 9 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 10 | * 11 | * All rights reserved. 12 | * 13 | * This code is derived from software contributed to Berkeley by 14 | * Margo Seltzer. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 23 | * 2. Redistributions in binary form must reproduce the above copyright 24 | * notice, this list of conditions and the following disclaimer in the 25 | * documentation and/or other materials provided with the distribution. 26 | * 27 | * 3. Neither the name of the University nor the names of its contributors 28 | * may be used to endorse or promote products derived from this software 29 | * without specific prior written permission. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41 | * SUCH DAMAGE. 42 | * 43 | * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 44 | */ 45 | 46 | #ifndef _NDBM_H_ 47 | # define _NDBM_H_ 48 | 49 | # include "../../include/compat.h" 50 | 51 | # include 52 | # include 53 | 54 | # undef open 55 | 56 | /* Map dbm interface onto db(3). */ 57 | # define DBM_RDONLY O_RDONLY 58 | 59 | /* Flags to dbm_store(). */ 60 | # define DBM_INSERT 0 61 | # define DBM_REPLACE 1 62 | 63 | /* 64 | * The db(3) support for ndbm(3) always appends this suffix to the 65 | * file name to avoid overwriting the user's original database. 66 | */ 67 | 68 | # define DBM_SUFFIX ".db" 69 | 70 | typedef struct { 71 | void *dptr; 72 | size_t dsize; 73 | } datum; 74 | 75 | typedef DB DBM; 76 | # define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE 77 | 78 | __BEGIN_DECLS 79 | int dbm_clearerr(DBM *); 80 | void dbm_close(DBM *); 81 | int dbm_delete(DBM *, datum); 82 | int dbm_error(DBM *); 83 | datum dbm_fetch(DBM *, datum); 84 | datum dbm_firstkey(DBM *); 85 | datum dbm_nextkey(DBM *); 86 | DBM *dbm_open(const char *, int, mode_t); 87 | int dbm_store(DBM *, datum, datum, int); 88 | int dbm_dirfno(DBM *); 89 | int dbm_rdonly(DBM *); 90 | __END_DECLS 91 | 92 | #endif /* !_NDBM_H_ */ 93 | -------------------------------------------------------------------------------- /db/hash/extern.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: extern.h,v 1.9 2016/05/29 20:47:49 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1991, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)extern.h 8.4 (Berkeley) 6/16/94 40 | */ 41 | 42 | __BEGIN_HIDDEN_DECLS 43 | BUFHEAD *__add_ovflpage(HTAB *, BUFHEAD *); 44 | int __addel(HTAB *, BUFHEAD *, const DBT *, const DBT *); 45 | int __big_delete(HTAB *, BUFHEAD *); 46 | int __big_insert(HTAB *, BUFHEAD *, const DBT *, const DBT *); 47 | int __big_keydata(HTAB *, BUFHEAD *, DBT *, DBT *, int); 48 | int __big_return(HTAB *, BUFHEAD *, int, DBT *, int); 49 | int __big_split(HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, 50 | int, u_int32_t, SPLIT_RETURN *); 51 | int __buf_free(HTAB *, int, int); 52 | void __buf_init(HTAB *, int); 53 | u_int32_t __call_hash(HTAB *, char *, int); 54 | int __delpair(HTAB *, BUFHEAD *, int); 55 | int __expand_table(HTAB *); 56 | int __find_bigpair(HTAB *, BUFHEAD *, int, char *, int); 57 | u_int16_t __find_last_page(HTAB *, BUFHEAD **); 58 | void __free_ovflpage(HTAB *, BUFHEAD *); 59 | BUFHEAD *__get_buf(HTAB *, u_int32_t, BUFHEAD *, int); 60 | int __get_page(HTAB *, char *, u_int32_t, int, int, int); 61 | int __ibitmap(HTAB *, int, int, int); 62 | u_int32_t __log2(u_int32_t); 63 | int __put_page(HTAB *, char *, u_int32_t, int, int); 64 | void __reclaim_buf(HTAB *, BUFHEAD *); 65 | int __split_page(HTAB *, u_int32_t, u_int32_t); 66 | 67 | #ifdef HASH_STATISTICS 68 | extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows; 69 | #endif /* ifdef HASH_STATISTICS */ 70 | __END_HIDDEN_DECLS 71 | -------------------------------------------------------------------------------- /db/hash/hash_log2.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: hash_log2.c,v 1.8 2005/08/05 13:03:00 espie Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1990, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * This code is derived from software contributed to Berkeley by 13 | * Margo Seltzer. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * 3. Neither the name of the University nor the names of its contributors 27 | * may be used to endorse or promote products derived from this software 28 | * without specific prior written permission. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 | * SUCH DAMAGE. 41 | */ 42 | 43 | #include "../../include/compat.h" 44 | 45 | #include 46 | #include 47 | #include "hash.h" 48 | #include "page.h" 49 | #include "extern.h" 50 | 51 | u_int32_t 52 | __log2(u_int32_t num) 53 | { 54 | u_int32_t i, limit; 55 | 56 | limit = 1; 57 | for (i = 0; limit < num; limit = limit << 1, i++); 58 | return (i); 59 | } 60 | -------------------------------------------------------------------------------- /db/recno/extern.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: extern.h,v 1.7 2015/08/27 04:37:09 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1991, 1993 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)extern.h 8.3 (Berkeley) 6/4/94 40 | */ 41 | 42 | #include "../btree/extern.h" 43 | 44 | __BEGIN_HIDDEN_DECLS 45 | int __rec_close(DB *); 46 | int __rec_delete(const DB *, const DBT *, unsigned int); 47 | int __rec_dleaf(BTREE *, PAGE *, u_int32_t); 48 | int __rec_fd(const DB *); 49 | int __rec_fmap(BTREE *, recno_t); 50 | int __rec_fout(BTREE *); 51 | int __rec_fpipe(BTREE *, recno_t); 52 | int __rec_get(const DB *, const DBT *, DBT *, unsigned int); 53 | int __rec_iput(BTREE *, recno_t, const DBT *, unsigned int); 54 | int __rec_put(const DB *dbp, DBT *, const DBT *, unsigned int); 55 | int __rec_ret(BTREE *, EPG *, recno_t, DBT *, DBT *); 56 | EPG *__rec_search(BTREE *, recno_t, enum SRCHOP); 57 | int __rec_seq(const DB *, DBT *, DBT *, unsigned int); 58 | int __rec_sync(const DB *, unsigned int); 59 | int __rec_vmap(BTREE *, recno_t); 60 | int __rec_vout(BTREE *); 61 | int __rec_vpipe(BTREE *, recno_t); 62 | __END_HIDDEN_DECLS 63 | -------------------------------------------------------------------------------- /db/recno/recno.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: recno.h,v 1.5 2003/06/02 20:18:34 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1991, 1993 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)recno.h 8.1 (Berkeley) 6/4/93 40 | */ 41 | 42 | enum SRCHOP { SDELETE, SINSERT, SEARCH}; /* Rec_search operation. */ 43 | 44 | #include "../btree/btree.h" 45 | #include "extern.h" 46 | -------------------------------------------------------------------------------- /docs/ev: -------------------------------------------------------------------------------- 1 | Ev: Vi: Result: 2 | (Cursor keys). Move around the file. 3 | 4 | Meta key commands: 5 | ^A<#> <#>G Goto line #. 6 | ^A$ G Goto the end of the file. 7 | ^A/ / Prompt and execute a forward search. 8 | ^A: : Prompt and execute an ex command. 9 | ^A? ? Prompt and execute a backward search. 10 | ^Ac y' Copy to mark in line mode (or copy the current line). 11 | ^AC y` Copy to mark in character mode. 12 | ^Ad d' Delete to mark in line mode (or delete the current line). 13 | ^AD d` Delete to mark in character mode. 14 | ^Aj J Join lines. 15 | ^Am m Mark the current cursor position. 16 | ^AN N Repeat search in the reverse direction. 17 | ^An ^A Search for the word under the cursor. 18 | ^Ar u Redo a command. 19 | ^Au u Undo a command. 20 | 21 | Single key commands: 22 | ^B ^B Page up a screen. 23 | ^C ^C Interrupt long-running commands. 24 | ^D ^D Page down a half-screen. 25 | ^E $ End of line. 26 | ^F ^F Page down a screen. 27 | ^G ^G File status/information. 28 | ^H X Delete the character to the left of the cursor. 29 | ^I (TAB) 30 | ^J j Cursor down one line. 31 | ^K k Cursor up one line. 32 | ^L ^L Redraw the screen. 33 | ^M (CR) ^M In insert mode, split the line at the current cursor, 34 | creating a new line. 35 | In overwrite mode, cursor down one line. 36 | ^N n Repeat previous search, in previous direction. 37 | ^O (UNUSED) 38 | ^P p Paste the cut text at the cursor position. 39 | ^Q (XON/XOFF) 40 | ^R (UNUSED) 41 | ^S (XON/XOFF) 42 | ^T D Truncate the line at the cursor position. 43 | ^U ^U Page up a half-screen. 44 | ^V ^V Insert/overwrite with a literal next character. 45 | ^W w Move forward one whitespace separated word. 46 | ^X x Delete the current character. 47 | ^Y (UNUSED) 48 | ^Z ^Z Suspend. 49 | 50 | New ex mode commands: 51 | 52 | ^A:set ov[erwrite] Toggle "insert" mode, so that input keys overwrite 53 | the existing characters. 54 | -------------------------------------------------------------------------------- /docs/ev.license: -------------------------------------------------------------------------------- 1 | SPDX-License-Identifier: BSD-3-Clause 2 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 | The Regents of the University of California 4 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 5 | Keith Bostic 6 | Copyright (c) 2021-2024 Jeffrey H. Johnson 7 | -------------------------------------------------------------------------------- /docs/help.license: -------------------------------------------------------------------------------- 1 | SPDX-License-Identifier: BSD-3-Clause 2 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 | The Regents of the University of California 4 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 5 | Keith Bostic 6 | Copyright (c) 2021-2024 Jeffrey H. Johnson 7 | -------------------------------------------------------------------------------- /docs/internals/autowrite.license: -------------------------------------------------------------------------------- 1 | # $OpenBSD: autowrite,v 1.3 2001/01/29 01:58:37 niklas Exp $ 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | # @(#)autowrite 8.3 (Berkeley) 2/17/95 4 | 5 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 6 | The Regents of the University of California 7 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 8 | Keith Bostic 9 | Copyright (c) 2021-2024 Jeffrey H. Johnson 10 | -------------------------------------------------------------------------------- /docs/internals/context: -------------------------------------------------------------------------------- 1 | In historic vi, the previous context mark was always set: 2 | 3 | ex address: 4 | any number, , , , 5 | , 6 | 7 | ex commands: undo, "z.", global, v 8 | 9 | vi commands: (, ), {, }, %, [[, ]], ^] 10 | 11 | nvi adds the vi command ^T to this list. 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | In historic vi, the previous context mark was set if the 16 | line changed: 17 | 18 | vi commands: ', G, H, L, M, z 19 | 20 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 21 | 22 | In historic vi, the previous context mark was set if the 23 | line or column changed: 24 | 25 | vi commands: `, /, ?, N, n 26 | 27 | nvi adds the vi command ^A to this list. 28 | 29 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 30 | 31 | In historic vi, the previous context mark was set in non-visual 32 | mode for ^R and ^L if the line changed, but I have yet to figure 33 | out how the line could change. 34 | -------------------------------------------------------------------------------- /docs/internals/context.license: -------------------------------------------------------------------------------- 1 | # $OpenBSD: context,v 1.3 2001/01/29 01:58:37 niklas Exp $ 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | # @(#)context 8.6 (Berkeley) 10/14/94 4 | 5 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 6 | The Regents of the University of California 7 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 8 | Keith Bostic 9 | Copyright (c) 2021-2024 Jeffrey H. Johnson 10 | -------------------------------------------------------------------------------- /docs/internals/gdb.script: -------------------------------------------------------------------------------- 1 | # $OpenBSD: gdb.script,v 1.3 2001/01/29 01:58:38 niklas Exp $ 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | # Copyright (c) 1996, 1997, 1998, 1999, 2000 Keith Bostic 4 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 5 | # @(#)gdb.script 8.5 (Berkeley) 5/4/96 6 | 7 | # display the VI screen map 8 | # usage dmap(sp) 9 | define dmap 10 | set $h = ((VI_PRIVATE *)$arg0->vi_private)->h_smap 11 | set $t = ((VI_PRIVATE *)$arg0->vi_private)->t_smap 12 | while ($h <= $t) 13 | printf "lno: %2d; soff %d coff %d ", \ 14 | (int)$h->lno, (int)$h->soff, (int)$h->coff 15 | if ($h->c_ecsize == 0) 16 | printf "flushed\n" 17 | else 18 | printf "\n\tsboff %d; scoff %d\n", \ 19 | (int)$h->c_sboff, (int)$h->c_scoff 20 | printf "\teboff %d; eclen %d; ecsize %d\n", \ 21 | (int)$h->c_eboff, (int)$h->c_eclen, \ 22 | (int)$h->c_ecsize 23 | end 24 | set $h = $h + 1 25 | end 26 | end 27 | 28 | # display the tail of the VI screen map 29 | define tmap 30 | set $h = ((VI_PRIVATE *)$arg0->vi_private)->h_smap 31 | set $t = ((VI_PRIVATE *)$arg0->vi_private)->t_smap 32 | while ($t >= $h) 33 | printf "lno: %2d; soff %d coff %d ", \ 34 | (int)$t->lno, (int)$t->soff, (int)$t->coff 35 | if ($t->c_ecsize == 0) 36 | printf "flushed\n" 37 | else 38 | printf "\n\tsboff %d; scoff %d\n", \ 39 | (int)$t->c_sboff, (int)$t->c_scoff 40 | printf "\teboff %d; eclen %d; ecsize %d\n", \ 41 | (int)$t->c_eboff, (int)$t->c_eclen, \ 42 | (int)$t->c_ecsize 43 | end 44 | set $t = $t - 1 45 | end 46 | end 47 | 48 | # display the private structures 49 | define clp 50 | print *((CL_PRIVATE *)sp->gp->cl_private) 51 | end 52 | define vip 53 | print *((VI_PRIVATE *)sp->vi_private) 54 | end 55 | define exp 56 | print *((EX_PRIVATE *)sp->ex_private) 57 | end 58 | 59 | # display the marks 60 | define markp 61 | set $h = sp->ep->marks.next 62 | set $t = &sp->ep->marks 63 | while ($h != 0 && $h != $t) 64 | printf "key %c lno: %d cno: %d flags: %x\n", \ 65 | ((MARK *)$h)->name, ((MARK *)$h)->lno, \ 66 | ((MARK *)$h)->cno, ((MARK *)$h)->flags 67 | set $h = ((MARK *)$h)->next 68 | end 69 | end 70 | 71 | # display the tags 72 | define tagp 73 | set $h = sp->taghdr.next 74 | set $t = &sp->taghdr 75 | while ($h != 0 && $h != $t) 76 | printf "tag: %s lno %d cno %d\n", ((TAG *)$h)->frp->fname, \ 77 | ((TAG *)$h)->lno, ((TAG *)$h)->cno 78 | set $h= ((TAG *)$h)->next 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /docs/internals/input.license: -------------------------------------------------------------------------------- 1 | # $OpenBSD: input,v 1.2 2001/01/29 01:58:38 niklas Exp $ 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | # @(#)input 5.5 (Berkeley) 7/2/94 4 | 5 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 6 | The Regents of the University of California 7 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 8 | Keith Bostic 9 | Copyright (c) 2021-2024 Jeffrey H. Johnson 10 | -------------------------------------------------------------------------------- /docs/internals/openmode: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # @(#)openmode 8.1 (Berkeley) 10/29/94 3 | 4 | Open mode has the following special behaviors: 5 | 6 | z, ^F, ^B: 7 | If count is not specified, it shall default to the window 8 | edit option - 2. 9 | 10 | Write lines from the edit buffer starting at: 11 | 12 | (the current line) - ((count - 2) / 2) 13 | 14 | until: 15 | 16 | (((count + 1) / 2) * 2) - 1 17 | 18 | lines, or the last line in the edit buffer has been written. A 19 | line consisting of the smaller of the number of columns in the 20 | display divided by two or 40 ``-'' characters shall be written 21 | immediately before and after the specified is written. These two 22 | lines shall count against the total number of lines to be written. 23 | A blank line shall be written after the last line is written. 24 | 25 | z, ^F and ^B all behave identically. 26 | 27 | ^D: Display the next scroll value lines, change the current line. 28 | 29 | ^U: Change the current line, do nothing else. 30 | 31 | ^E, ^Y: Do nothing. 32 | 33 | ^L: Clear the screen and re-display the current line. 34 | 35 | H, L, M: 36 | Move to the first nonblank of the current line and do nothing 37 | else. 38 | -------------------------------------------------------------------------------- /docs/internals/openmode.license: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # @(#)openmode 8.1 (Berkeley) 10/29/94 3 | 4 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 5 | The Regents of the University of California 6 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 7 | Keith Bostic 8 | Copyright (c) 2021-2024 Jeffrey H. Johnson 9 | -------------------------------------------------------------------------------- /docs/internals/quoting.license: -------------------------------------------------------------------------------- 1 | # $OpenBSD: quoting,v 1.3 2001/01/29 01:58:39 niklas Exp $ 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | # @(#)quoting 5.5 (Berkeley) 11/12/94 4 | 5 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 6 | The Regents of the University of California 7 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 8 | Keith Bostic 9 | Copyright (c) 2021-2024 Jeffrey H. Johnson 10 | -------------------------------------------------------------------------------- /docs/internals/structures: -------------------------------------------------------------------------------- 1 | There are three major data structures in this package, plus a single data 2 | structure per screen type. The first is a single global structure (GS) 3 | which contains information common to all files and screens. It hold 4 | global things like the input key queues, and functions as a single place 5 | to hang things. For example, interrupt routines have to be able to find 6 | screen structures, and they can only do this if they have a starting 7 | point. The number of globals in nvi is dependent on the screen type, but 8 | every screen type will have at least one global, __global_list, which 9 | references the GS structure. 10 | 11 | The GS structure contains linked lists of screen (SCR) structures. 12 | Each SCR structure normally references a file (EXF) structure. 13 | 14 | The GS structure has a set of functions which update the screen and/or 15 | return information about the screen from the underlying screen package. 16 | The GS structure never goes away. The SCR structure persists over 17 | instances of screens, and the EXF structure persists over references to 18 | files. 19 | 20 | File names have different properties than files themselves, so the name 21 | information for a file is held in an FREF structure which is chained from 22 | the SCR structure. 23 | 24 | In general, functions are always passed an SCR structure, which usually 25 | references an underlying EXF structure. The SCR structure is necessary 26 | for any routine that wishes to talk to the screen, the EXF structure is 27 | necessary for any routine that wants to modify the file. The relationship 28 | between an SCR structure and its underlying EXF structure is not fixed, 29 | and various ex commands will substitute a new EXF in place of the current 30 | one, and there's no way to detect this. 31 | 32 | The naming of the structures is consistent across the program. (Macros 33 | even depend on it, so don't try and change it!) The global structure is 34 | "gp", the screen structure is "sp", and the file structure is "ep". 35 | 36 | A few other data structures: 37 | 38 | TEXT In nvi/cut.h. This structure describes a portion of a line, 39 | and is used by the input routines and as the "line" part of a 40 | cut buffer. 41 | 42 | CB In nvi/cut.h. A cut buffer. A cut buffer is a place to 43 | hang a list of TEXT structures. 44 | 45 | CL The curses screen private data structure. Everything to 46 | do standalone curses screens. 47 | 48 | MARK In nvi/mark.h. A cursor position, consisting of a line number 49 | and a column number. 50 | 51 | MSG In nvi/msg.h. A chain of messages for the user. 52 | 53 | SEQ In nvi/seq.h. An abbreviation or a map entry. 54 | 55 | EXCMD In nvi/ex/ex.h. The structure that gets passed around to the 56 | functions that implement the ex commands. (The main ex command 57 | loop (see nvi/ex/ex.c) builds this up and then passes it to the 58 | ex functions.) 59 | 60 | VICMD In nvi/vi/vi.h. The structure that gets passed around to the 61 | functions that implement the vi commands. (The main vi command 62 | loop (see nvi/vi/vi.c) builds this up and then passes it to the 63 | vi functions.) 64 | -------------------------------------------------------------------------------- /docs/internals/structures.license: -------------------------------------------------------------------------------- 1 | # $OpenBSD: structures,v 1.3 2001/01/29 01:58:39 niklas Exp $ 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | # @(#)structures 5.4 (Berkeley) 10/4/95 4 | 5 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 6 | The Regents of the University of California 7 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 8 | Keith Bostic 9 | Copyright (c) 2021-2024 Jeffrey H. Johnson 10 | -------------------------------------------------------------------------------- /docs/tutorial/vi.advanced.license: -------------------------------------------------------------------------------- 1 | SPDX-License-Identifier: BSD-3-Clause 2 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 | The Regents of the University of California 4 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 5 | Keith Bostic 6 | Copyright (c) 2021-2024 Jeffrey H. Johnson 7 | -------------------------------------------------------------------------------- /docs/tutorial/vi.beginner.license: -------------------------------------------------------------------------------- 1 | SPDX-License-Identifier: BSD-3-Clause 2 | Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 | The Regents of the University of California 4 | Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 5 | Keith Bostic 6 | Copyright (c) 2021-2024 Jeffrey H. Johnson 7 | -------------------------------------------------------------------------------- /docs/tutorial/vi.tut.csh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env csh 2 | # $OpenBSD: vi.tut.csh,v 1.2 2001/01/29 01:58:40 niklas Exp $ 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | # Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 5 | # The Regents of the University of California 6 | # Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 7 | # Keith Bostic 8 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 9 | 10 | # XXX I don't know what happens if there is .exrc file! 11 | # XXX Make sure that user is using a 24 line window!!! 12 | 13 | if ($1 != "beginner" && $1 != "advanced") then 14 | echo Usage: $0 beginner or $0 advanced 15 | exit 16 | endif # ($1 != "beginner" && $1 != "advanced") 17 | 18 | if ($?EXINIT) then 19 | set oexinit="$EXINIT" 20 | setenv EXINIT 'se ts=4 wm=8 sw=4' 21 | endif # $?EXINIT 22 | 23 | vi vi.{$1} 24 | 25 | onintr: 26 | 27 | if ($?oexinit) then 28 | setenv EXINIT "$oexinit" 29 | endif # $?oexinit 30 | -------------------------------------------------------------------------------- /ex/ex.awk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # Copyright (c) 1980, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 3 | # The Regents of the University of California 4 | # Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 5 | # Keith Bostic 6 | # Copyright (c) 2021-2024 Jeffrey H. Johnson 7 | 8 | BEGIN { 9 | printf("enum {"); 10 | first = 1; 11 | } 12 | /^\/\* C_[0-9A-Z_]* \*\// { 13 | printf("%s\n\t%s%s", first ? "" : ",", $2, first ? " = 0" : ""); 14 | first = 0; 15 | next; 16 | } 17 | END { 18 | printf("\n};\n"); 19 | } 20 | -------------------------------------------------------------------------------- /ex/ex_delete.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_delete.c,v 1.7 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | 24 | /* 25 | * ex_delete: [line [,line]] d[elete] [buffer] [count] [flags] 26 | * 27 | * Delete lines from the file. 28 | * 29 | * PUBLIC: int ex_delete(SCR *, EXCMD *); 30 | */ 31 | int 32 | ex_delete(SCR *sp, EXCMD *cmdp) 33 | { 34 | recno_t lno; 35 | 36 | NEEDFILE(sp, cmdp); 37 | 38 | /* 39 | * !!! 40 | * Historically, lines deleted in ex were not placed in the numeric 41 | * buffers. We follow historic practice so that we don't overwrite 42 | * vi buffers accidentally. 43 | */ 44 | if (cut(sp, 45 | FL_ISSET(cmdp->iflags, E_C_BUFFER) ? &cmdp->buffer : NULL, 46 | &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE)) 47 | return (1); 48 | 49 | /* Delete the lines. */ 50 | if (del(sp, &cmdp->addr1, &cmdp->addr2, 1)) 51 | return (1); 52 | 53 | /* Set the cursor to the line after the last line deleted. */ 54 | sp->lno = cmdp->addr1.lno; 55 | 56 | /* Or the last line in the file if deleted to the end of the file. */ 57 | if (db_last(sp, &lno)) 58 | return (1); 59 | if (sp->lno > lno) 60 | sp->lno = lno; 61 | return (0); 62 | } 63 | -------------------------------------------------------------------------------- /ex/ex_equal.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_equal.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | 24 | /* 25 | * ex_equal -- :address = 26 | * 27 | * PUBLIC: int ex_equal(SCR *, EXCMD *); 28 | */ 29 | int 30 | ex_equal(SCR *sp, EXCMD *cmdp) 31 | { 32 | recno_t lno; 33 | 34 | NEEDFILE(sp, cmdp); 35 | 36 | /* 37 | * Print out the line number matching the specified address, 38 | * or the number of the last line in the file if no address 39 | * specified. 40 | * 41 | * !!! 42 | * Historically, ":0=" displayed 0, and ":=" or ":1=" in an 43 | * empty file displayed 1. Until somebody complains loudly, 44 | * we're going to do it right. The tables in excmd.c permit 45 | * lno to get away with any address from 0 to the end of the 46 | * file, which, in an empty file, is 0. 47 | */ 48 | if (F_ISSET(cmdp, E_ADDR_DEF)) { 49 | if (db_last(sp, &lno)) 50 | return (1); 51 | } else 52 | lno = cmdp->addr1.lno; 53 | 54 | (void)ex_printf(sp, "%ld\n", lno); 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /ex/ex_file.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_file.c,v 1.9 2016/05/27 09:18:12 martijn Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "../common/common.h" 26 | 27 | /* 28 | * ex_file -- :f[ile] [name] 29 | * Change the file's name and display the status line. 30 | * 31 | * PUBLIC: int ex_file(SCR *, EXCMD *); 32 | */ 33 | int 34 | ex_file(SCR *sp, EXCMD *cmdp) 35 | { 36 | CHAR_T *p; 37 | FREF *frp; 38 | 39 | NEEDFILE(sp, cmdp); 40 | 41 | switch (cmdp->argc) { 42 | case 0: 43 | break; 44 | case 1: 45 | frp = sp->frp; 46 | 47 | /* Make sure can allocate enough space. */ 48 | if ((p = v_strdup(sp, 49 | cmdp->argv[0]->bp, cmdp->argv[0]->len)) == NULL) 50 | return (1); 51 | 52 | /* If already have a file name, it becomes the alternate. */ 53 | if (!F_ISSET(frp, FR_TMPFILE)) 54 | set_alt_name(sp, frp->name); 55 | 56 | /* Free the previous name. */ 57 | free(frp->name); 58 | frp->name = p; 59 | 60 | /* 61 | * The file has a real name, it's no longer a temporary, 62 | * clear the temporary file flags. 63 | */ 64 | F_CLR(frp, FR_TMPEXIT | FR_TMPFILE); 65 | 66 | /* Have to force a write if the file exists, next time. */ 67 | F_SET(frp, FR_NAMECHANGE); 68 | 69 | /* Notify the screen. */ 70 | (void)sp->gp->scr_rename(sp, sp->frp->name, 1); 71 | break; 72 | default: 73 | abort(); 74 | } 75 | msgq_status(sp, sp->lno, MSTAT_SHOWLAST); 76 | return (0); 77 | } 78 | -------------------------------------------------------------------------------- /ex/ex_mark.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_mark.c,v 1.7 2016/01/06 22:28:52 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | 24 | /* 25 | * ex_mark -- :mark char 26 | * :k char 27 | * Mark lines. 28 | * 29 | * 30 | * PUBLIC: int ex_mark(SCR *, EXCMD *); 31 | */ 32 | int 33 | ex_mark(SCR *sp, EXCMD *cmdp) 34 | { 35 | NEEDFILE(sp, cmdp); 36 | 37 | if (cmdp->argv[0]->len != 1) { 38 | msgq(sp, M_ERR, "Mark names must be a single character"); 39 | return (1); 40 | } 41 | return (mark_set(sp, cmdp->argv[0]->bp[0], &cmdp->addr1, 1)); 42 | } 43 | -------------------------------------------------------------------------------- /ex/ex_mkexrc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_mkexrc.c,v 1.7 2016/01/06 22:28:52 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include "../include/compat.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "../common/common.h" 31 | #include "pathnames.h" 32 | 33 | #undef open 34 | 35 | /* 36 | * ex_mkexrc -- :mkexrc[!] [file] 37 | * 38 | * Create (or overwrite) a .exrc file with the current info. 39 | * 40 | * PUBLIC: int ex_mkexrc(SCR *, EXCMD *); 41 | */ 42 | int 43 | ex_mkexrc(SCR *sp, EXCMD *cmdp) 44 | { 45 | struct stat sb; 46 | FILE *fp; 47 | int fd, sverrno; 48 | char *fname; 49 | 50 | switch (cmdp->argc) { 51 | case 0: 52 | fname = _PATH_EXRC; 53 | break; 54 | case 1: 55 | fname = cmdp->argv[0]->bp; 56 | set_alt_name(sp, fname); 57 | break; 58 | default: 59 | abort(); 60 | } 61 | 62 | if (!FL_ISSET(cmdp->iflags, E_C_FORCE) && !stat(fname, &sb)) { 63 | msgq_str(sp, M_ERR, fname, 64 | "%s exists, not written; use ! to override"); 65 | return (1); 66 | } 67 | 68 | /* Create with max permissions of rw-r--r--. */ 69 | if ((fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 70 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) { 71 | msgq_str(sp, M_SYSERR, fname, "%s"); 72 | return (1); 73 | } 74 | 75 | if ((fp = fdopen(fd, "w")) == NULL) { 76 | sverrno = errno; 77 | (void)close(fd); 78 | goto e2; 79 | } 80 | 81 | if (seq_save(sp, fp, "abbreviate ", SEQ_ABBREV) || ferror(fp)) 82 | goto e1; 83 | if (seq_save(sp, fp, "map ", SEQ_COMMAND) || ferror(fp)) 84 | goto e1; 85 | if (seq_save(sp, fp, "map! ", SEQ_INPUT) || ferror(fp)) 86 | goto e1; 87 | if (opts_save(sp, fp) || ferror(fp)) 88 | goto e1; 89 | if (fclose(fp)) { 90 | sverrno = errno; 91 | goto e2; 92 | } 93 | 94 | msgq_str(sp, M_INFO, fname, "New exrc file: %s"); 95 | return (0); 96 | 97 | e1: sverrno = errno; 98 | (void)fclose(fp); 99 | e2: errno = sverrno; 100 | msgq_str(sp, M_SYSERR, fname, "%s"); 101 | return (1); 102 | } 103 | -------------------------------------------------------------------------------- /ex/ex_open.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_open.c,v 1.7 2016/01/06 22:28:52 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include "../include/compat.h" 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../common/common.h" 25 | 26 | #undef open 27 | 28 | /* 29 | * ex_open -- :[line] o[pen] [/pattern/] [flags] 30 | * 31 | * Switch to single line "open" mode. 32 | * 33 | * PUBLIC: int ex_open(SCR *, EXCMD *); 34 | */ 35 | int 36 | ex_open(SCR *sp, EXCMD *cmdp) 37 | { 38 | /* If open option off, disallow open command. */ 39 | if (!O_ISSET(sp, O_OPEN)) { 40 | msgq(sp, M_ERR, 41 | "The open command requires that the open option be set"); 42 | return (1); 43 | } 44 | 45 | msgq(sp, M_ERR, "The open command is not yet implemented"); 46 | return (1); 47 | } 48 | -------------------------------------------------------------------------------- /ex/ex_preserve.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_preserve.c,v 1.7 2016/01/06 22:28:52 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../common/common.h" 25 | 26 | /* 27 | * ex_preserve -- :pre[serve] 28 | * Push the file to recovery. 29 | * 30 | * PUBLIC: int ex_preserve(SCR *, EXCMD *); 31 | */ 32 | int 33 | ex_preserve(SCR *sp, EXCMD *cmdp) 34 | { 35 | recno_t lno; 36 | 37 | NEEDFILE(sp, cmdp); 38 | 39 | if (!F_ISSET(sp->ep, F_RCV_ON)) { 40 | msgq(sp, M_ERR, "Preservation of this file not possible"); 41 | return (1); 42 | } 43 | 44 | /* If recovery not initialized, do so. */ 45 | if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp)) 46 | return (1); 47 | 48 | /* Force the file to be read in, in case it hasn't yet. */ 49 | if (db_last(sp, &lno)) 50 | return (1); 51 | 52 | /* Sync to disk. */ 53 | if (rcv_sync(sp, RCV_SNAPSHOT)) 54 | return (1); 55 | 56 | msgq(sp, M_INFO, "File preserved"); 57 | return (0); 58 | } 59 | 60 | /* 61 | * ex_recover -- :rec[over][!] file 62 | * Recover the file. 63 | * 64 | * PUBLIC: int ex_recover(SCR *, EXCMD *); 65 | */ 66 | int 67 | ex_recover(SCR *sp, EXCMD *cmdp) 68 | { 69 | ARGS *ap; 70 | FREF *frp; 71 | 72 | ap = cmdp->argv[0]; 73 | 74 | /* Set the alternate file name. */ 75 | set_alt_name(sp, ap->bp); 76 | 77 | /* 78 | * Check for modifications. Autowrite did not historically 79 | * affect :recover. 80 | */ 81 | if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE))) 82 | return (1); 83 | 84 | /* Get a file structure for the file. */ 85 | if ((frp = file_add(sp, ap->bp)) == NULL) 86 | return (1); 87 | 88 | /* Set the recover bit. */ 89 | F_SET(frp, FR_RECOVER); 90 | 91 | /* Switch files. */ 92 | if (file_init(sp, frp, NULL, FS_SETALT | 93 | (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0))) 94 | return (1); 95 | 96 | F_SET(sp, SC_FSWITCH); 97 | return (0); 98 | } 99 | -------------------------------------------------------------------------------- /ex/ex_put.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_put.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../common/common.h" 25 | 26 | /* 27 | * ex_put -- [line] pu[t] [buffer] 28 | * Append a cut buffer into the file. 29 | * 30 | * PUBLIC: int ex_put(SCR *, EXCMD *); 31 | */ 32 | int 33 | ex_put(SCR *sp, EXCMD *cmdp) 34 | { 35 | MARK m; 36 | 37 | NEEDFILE(sp, cmdp); 38 | 39 | m.lno = sp->lno; 40 | m.cno = sp->cno; 41 | if (put(sp, NULL, 42 | FL_ISSET(cmdp->iflags, E_C_BUFFER) ? &cmdp->buffer : NULL, 43 | &cmdp->addr1, &m, 1)) 44 | return (1); 45 | sp->lno = m.lno; 46 | sp->cno = m.cno; 47 | return (0); 48 | } 49 | -------------------------------------------------------------------------------- /ex/ex_quit.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_quit.c,v 1.5 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | 24 | /* 25 | * ex_quit -- :quit[!] 26 | * Quit. 27 | * 28 | * PUBLIC: int ex_quit(SCR *, EXCMD *); 29 | */ 30 | int 31 | ex_quit(SCR *sp, EXCMD *cmdp) 32 | { 33 | int force; 34 | 35 | force = FL_ISSET(cmdp->iflags, E_C_FORCE); 36 | 37 | /* Check for file modifications, or more files to edit. */ 38 | if (file_m2(sp, force) || ex_ncheck(sp, force)) 39 | return (1); 40 | 41 | F_SET(sp, force ? SC_EXIT_FORCE : SC_EXIT); 42 | return (0); 43 | } 44 | -------------------------------------------------------------------------------- /ex/ex_set.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_set.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | 24 | /* 25 | * ex_set -- :set 26 | * Ex set option. 27 | * 28 | * PUBLIC: int ex_set(SCR *, EXCMD *); 29 | */ 30 | int 31 | ex_set(SCR *sp, EXCMD *cmdp) 32 | { 33 | switch(cmdp->argc) { 34 | case 0: 35 | opts_dump(sp, CHANGED_DISPLAY); 36 | break; 37 | default: 38 | if (opts_set(sp, cmdp->argv, cmdp->cmd->usage)) 39 | return (1); 40 | break; 41 | } 42 | return (0); 43 | } 44 | -------------------------------------------------------------------------------- /ex/ex_source.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_source.c,v 1.11 2021/10/24 21:24:17 deraadt Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include "../include/compat.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "../common/common.h" 31 | 32 | #undef open 33 | 34 | /* 35 | * ex_sourcefd -- :source already opened file 36 | * Execute ex commands from the given file descriptor 37 | * 38 | * PUBLIC: int ex_sourcefd(SCR *, EXCMD *, int); 39 | */ 40 | int 41 | ex_sourcefd(SCR *sp, EXCMD *cmdp, int fd) 42 | { 43 | struct stat sb; 44 | int len; 45 | char *bp, *name; 46 | 47 | name = cmdp->argv[0]->bp; 48 | if (fstat(fd, &sb)) 49 | goto err; 50 | 51 | /* 52 | * XXX 53 | * I'd like to test to see if the file is too large to malloc. Since 54 | * we don't know what size or type off_t's or size_t's are, what the 55 | * largest unsigned integral type is, or what random insanity the local 56 | * C compiler will perpetrate, doing the comparison in a portable way 57 | * is flatly impossible. So, put an fairly unreasonable limit on it, 58 | * I don't want to be dropping core here. 59 | */ 60 | #define MEGABYTE 1048576 61 | if (sb.st_size > (8 * MEGABYTE)) { 62 | errno = ENOMEM; 63 | goto err; 64 | } 65 | 66 | MALLOC(sp, bp, (size_t)sb.st_size + 1); 67 | if (bp == NULL) { 68 | (void)close(fd); 69 | return (1); 70 | } 71 | bp[sb.st_size] = '\0'; 72 | 73 | /* Read the file into memory. */ 74 | len = read(fd, bp, (int)sb.st_size); 75 | (void)close(fd); 76 | if (len == -1 || len != sb.st_size) { 77 | if (len != sb.st_size) 78 | errno = EIO; 79 | free(bp); 80 | err: msgq_str(sp, M_SYSERR, name, "%s"); 81 | return (1); 82 | } 83 | 84 | /* Put it on the ex queue. */ 85 | return (ex_run_str(sp, name, bp, (size_t)sb.st_size, 1, 1)); 86 | } 87 | 88 | /* 89 | * ex_source -- :source file 90 | * Execute ex commands from a file. 91 | * 92 | * PUBLIC: int ex_source(SCR *, EXCMD *); 93 | */ 94 | int 95 | ex_source(SCR *sp, EXCMD *cmdp) 96 | { 97 | char *name; 98 | int fd; 99 | 100 | name = cmdp->argv[0]->bp; 101 | if ((fd = open(name, O_RDONLY)) >= 0) 102 | return (ex_sourcefd(sp, cmdp, fd)); 103 | 104 | msgq_str(sp, M_SYSERR, name, "%s"); 105 | return (1); 106 | } 107 | -------------------------------------------------------------------------------- /ex/ex_stop.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_stop.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "../common/common.h" 26 | 27 | /* 28 | * ex_stop -- :stop[!] 29 | * :suspend[!] 30 | * Suspend execution. 31 | * 32 | * PUBLIC: int ex_stop(SCR *, EXCMD *); 33 | */ 34 | int 35 | ex_stop(SCR *sp, EXCMD *cmdp) 36 | { 37 | int allowed; 38 | 39 | /* For some strange reason, the force flag turns off autowrite. */ 40 | if (!FL_ISSET(cmdp->iflags, E_C_FORCE) && file_aw(sp, FS_ALL)) 41 | return (1); 42 | 43 | if (sp->gp->scr_suspend(sp, &allowed)) 44 | return (1); 45 | if (!allowed) 46 | ex_emsg(sp, NULL, EXM_NOSUSPEND); 47 | return (0); 48 | } 49 | -------------------------------------------------------------------------------- /ex/ex_undo.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_undo.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | 25 | /* 26 | * ex_undo -- u 27 | * Undo the last change. 28 | * 29 | * PUBLIC: int ex_undo(SCR *, EXCMD *); 30 | */ 31 | int 32 | ex_undo(SCR *sp, EXCMD *cmdp) 33 | { 34 | EXF *ep; 35 | MARK m; 36 | 37 | /* 38 | * !!! 39 | * Historic undo always set the previous context mark. 40 | */ 41 | m.lno = sp->lno; 42 | m.cno = sp->cno; 43 | if (mark_set(sp, ABSMARK1, &m, 1)) 44 | return (1); 45 | 46 | /* 47 | * !!! 48 | * Multiple undo isn't available in ex, as there's no '.' command. 49 | * Whether 'u' is undo or redo is toggled each time, unless there 50 | * was a change since the last undo, in which case it's an undo. 51 | */ 52 | ep = sp->ep; 53 | if (!F_ISSET(ep, F_UNDO)) { 54 | F_SET(ep, F_UNDO); 55 | ep->lundo = FORWARD; 56 | } 57 | switch (ep->lundo) { 58 | case BACKWARD: 59 | if (log_forward(sp, &m)) 60 | return (1); 61 | ep->lundo = FORWARD; 62 | break; 63 | case FORWARD: 64 | if (log_backward(sp, &m)) 65 | return (1); 66 | ep->lundo = BACKWARD; 67 | break; 68 | case NOTSET: 69 | abort(); 70 | } 71 | sp->lno = m.lno; 72 | sp->cno = m.cno; 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /ex/ex_version.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_version.c,v 1.10 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1991, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1991, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | #include "version.h" 24 | 25 | /* 26 | * ex_version -- :version 27 | * Display the program version. 28 | * 29 | * PUBLIC: int ex_version(SCR *, EXCMD *); 30 | */ 31 | 32 | int 33 | ex_version(SCR *sp, EXCMD *cmdp) 34 | { 35 | msgq(sp, M_XINFO, VI_VERSION); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /ex/ex_yank.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ex_yank.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../common/common.h" 23 | 24 | /* 25 | * ex_yank -- :[line [,line]] ya[nk] [buffer] [count] 26 | * Yank the lines into a buffer. 27 | * 28 | * PUBLIC: int ex_yank(SCR *, EXCMD *); 29 | */ 30 | int 31 | ex_yank(SCR *sp, EXCMD *cmdp) 32 | { 33 | NEEDFILE(sp, cmdp); 34 | 35 | /* 36 | * !!! 37 | * Historically, yanking lines in ex didn't count toward the 38 | * number-of-lines-yanked report. 39 | */ 40 | return (cut(sp, 41 | FL_ISSET(cmdp->iflags, E_C_BUFFER) ? &cmdp->buffer : NULL, 42 | &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE)); 43 | } 44 | -------------------------------------------------------------------------------- /ex/script.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: script.h,v 1.4 2014/11/12 16:29:04 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)script.h 10.2 (Berkeley) 3/6/96 15 | */ 16 | 17 | struct _script { 18 | pid_t sh_pid; /* Shell pid. */ 19 | int sh_master; /* Master pty fd. */ 20 | int sh_slave; /* Slave pty fd. */ 21 | char *sh_prompt; /* Prompt. */ 22 | size_t sh_prompt_len; /* Prompt length. */ 23 | char sh_name[64]; /* Pty name */ 24 | struct winsize sh_win; /* Window size. */ 25 | struct termios sh_term; /* Terminal information. */ 26 | }; 27 | -------------------------------------------------------------------------------- /ex/tag.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: tag.h,v 1.7 2015/11/19 07:53:31 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 1994, 1996 11 | * Rob Mayoff. All rights reserved. 12 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 13 | * 14 | * See the LICENSE.md file for redistribution information. 15 | * 16 | * @(#)tag.h 10.5 (Berkeley) 5/15/96 17 | */ 18 | 19 | /* 20 | * Tag file information. One of these is maintained per tag file, linked 21 | * from the EXPRIVATE structure. 22 | */ 23 | struct _tagf { /* Tag files. */ 24 | TAILQ_ENTRY(_tagf) q; /* Linked list of tag files. */ 25 | char *name; /* Tag file name. */ 26 | int errnum; /* Errno. */ 27 | 28 | #define TAGF_ERR 0x01 /* Error occurred. */ 29 | #define TAGF_ERR_WARN 0x02 /* Error reported. */ 30 | u_int8_t flags; 31 | }; 32 | 33 | /* 34 | * Tags are structured internally as follows: 35 | * 36 | * +----+ +----+ +----+ +----+ 37 | * | EP | -> | Q1 | <-- | T1 | <-- | T2 | 38 | * +----+ +----+ --> +----+ --> +----+ 39 | * | 40 | * +----+ +----+ 41 | * | Q2 | <-- | T1 | 42 | * +----+ --> +----+ 43 | * | 44 | * +----+ +----+ 45 | * | Q3 | <-- | T1 | 46 | * +----+ --> +----+ 47 | * 48 | * Each Q is a TAGQ, or tag "query", which is the result of one tag. 49 | * Each Q references one or more TAG's, or tagged file locations. 50 | * 51 | * tag: put a new Q at the head (^]) 52 | * tagnext: T1 -> T2 inside Q (^N) 53 | * tagprev: T2 -> T1 inside Q (^P) 54 | * tagpop: discard Q (^T) 55 | * tagtop: discard all Q 56 | */ 57 | struct _tag { /* Tag list. */ 58 | TAILQ_ENTRY(_tag) q; /* Linked list of tags. */ 59 | 60 | /* Tag pop/return information. */ 61 | FREF *frp; /* Saved file. */ 62 | recno_t lno; /* Saved line number. */ 63 | size_t cno; /* Saved column number. */ 64 | 65 | char *fname; /* Filename. */ 66 | size_t fnlen; /* Filename length. */ 67 | recno_t slno; /* Search line number. */ 68 | char *search; /* Search string. */ 69 | size_t slen; /* Search string length. */ 70 | 71 | char buf[1]; /* Variable length buffer. */ 72 | }; 73 | 74 | struct _tagq { /* Tag queue. */ 75 | TAILQ_ENTRY(_tagq) q; /* Linked list of tag queues. */ 76 | /* This queue's tag list. */ 77 | TAILQ_HEAD(_tagqh, _tag) tagq; 78 | 79 | TAG *current; /* Current TAG within the queue. */ 80 | 81 | char *tag; /* Tag string. */ 82 | size_t tlen; /* Tag string length. */ 83 | 84 | u_int8_t flags; 85 | 86 | char buf[1]; /* Variable length buffer. */ 87 | }; 88 | -------------------------------------------------------------------------------- /ex/version.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _VERSION_H 37 | # define _VERSION_H 38 | 39 | # define VI_VERSION \ 40 | "Version 7.6.31 (OpenVi) 10/08/2024" 41 | 42 | #endif /* ifndef _VERSION_H */ 43 | -------------------------------------------------------------------------------- /include/bsd_err.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: err.h,v 1.13 2015/08/31 02:53:56 guenther Exp $ */ 2 | /* $NetBSD: err.h,v 1.11 1994/10/26 00:55:52 cgd Exp $ */ 3 | 4 | /* SPDX-License-Identifier: BSD-3-Clause */ 5 | 6 | /* 7 | * Copyright (c) 1993 8 | * The Regents of the University of California. All rights reserved. 9 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 20 | * 2. Redistributions in binary form must reproduce the above copyright 21 | * notice, this list of conditions and the following disclaimer in the 22 | * documentation and/or other materials provided with the distribution. 23 | * 24 | * 3. Neither the name of the University nor the names of its contributors 25 | * may be used to endorse or promote products derived from this software 26 | * without specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 | * SUCH DAMAGE. 39 | * 40 | * @(#)err.h 8.1 (Berkeley) 6/2/93 41 | */ 42 | 43 | #ifndef _COMPAT_ERR_H_ 44 | # define _COMPAT_ERR_H_ 45 | 46 | # include /* for va_list */ 47 | 48 | void openbsd_errc(int, int, const char *, ...) 49 | __attribute__((__format__ (printf, 3, 4))); 50 | void openbsd_verrc(int, int, const char *, va_list) 51 | __attribute__((__format__ (printf, 3, 0))); 52 | void openbsd_warnc(int, const char *, ...) 53 | __attribute__((__format__ (printf, 2, 3))); 54 | void openbsd_vwarnc(int, const char *, va_list) 55 | __attribute__((__format__ (printf, 2, 0))); 56 | #endif /* !_COMPAT_ERR_H_ */ 57 | -------------------------------------------------------------------------------- /include/bsd_fcntl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include_next 37 | 38 | #ifndef _COMPAT_FCNTL_H_ 39 | # define _COMPAT_FCNTL_H_ 40 | 41 | # define open openbsd_open 42 | 43 | # ifdef O_EXLOCK 44 | # undef O_EXLOCK 45 | # endif /* ifdef O_EXLOCK */ 46 | # define O_EXLOCK 10000000 47 | 48 | # ifdef O_SHLOCK 49 | # undef O_SHLOCK 50 | # endif /* ifdef O_SHLOCK */ 51 | # define O_SHLOCK 20000000 52 | 53 | int openbsd_open(const char *, int, ...); 54 | 55 | #endif /* !_COMPAT_FCNTL_H_ */ 56 | -------------------------------------------------------------------------------- /include/bsd_stdlib.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: stdlib.h,v 1.67 2016/09/20 21:10:22 fcambus Exp $ */ 2 | /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ 3 | 4 | /* SPDX-License-Identifier: BSD-3-Clause */ 5 | 6 | /* 7 | * Copyright (c) 1990 The Regents of the University of California. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)stdlib.h 5.13 (Berkeley) 6/4/91 40 | */ 41 | 42 | #ifndef _COMPAT_STDLIB_H_ 43 | # define _COMPAT_STDLIB_H_ 44 | 45 | # ifdef __solaris__ 46 | # undef _TIMESPEC_UTIL_H 47 | # define _TIMESPEC_UTIL_H 1 48 | # endif /* ifdef __solaris__ */ 49 | 50 | # include 51 | # include 52 | 53 | extern char *__progname; 54 | const char *bsd_getprogname(void); 55 | 56 | void *openbsd_reallocarray(void *, size_t, size_t); 57 | void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 58 | long long strtonum(const char *, long long, long long, const char **); 59 | 60 | #endif /* _COMPAT_STDLIB_H_ */ 61 | 62 | #include_next 63 | -------------------------------------------------------------------------------- /include/bsd_string.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: string.h,v 1.31 2016/09/09 18:12:37 millert Exp $ */ 2 | /* $NetBSD: string.h,v 1.6 1994/10/26 00:56:30 cgd Exp $ */ 3 | 4 | /* SPDX-License-Identifier: BSD-3-Clause */ 5 | 6 | /* 7 | * Copyright (c) 1990 The Regents of the University of California. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)string.h 5.10 (Berkeley) 3/9/91 40 | */ 41 | 42 | #ifndef _COMPAT_STRING_H_ 43 | # define _COMPAT_STRING_H_ 44 | 45 | size_t openbsd_strlcpy(char *, const char *, size_t); 46 | size_t openbsd_strlcat(char *dst, const char *src, size_t dsize); 47 | 48 | # ifndef __OpenBSD__ 49 | 50 | # include 51 | 52 | # endif /* ifndef __OpenBSD__ */ 53 | 54 | #endif /* _COMPAT_STRING_H_ */ 55 | 56 | #include_next 57 | -------------------------------------------------------------------------------- /include/bsd_termios.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 1988, 1989, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 21 | * 3. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | * 37 | * @(#)termios.h 8.3 (Berkeley) 3/28/94 38 | */ 39 | 40 | #include_next 41 | 42 | #ifndef _COMPAT_TERMIOS_H 43 | # define _COMPAT_TERMIOS_H 44 | 45 | # ifndef TCSASOFT 46 | # define TCSASOFT 0 47 | # endif /* ifndef TCSASOFT */ 48 | 49 | # ifndef CCEQ 50 | # define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0) 51 | # endif /* ifndef CCEQ */ 52 | 53 | #endif /* _COMPAT_TERMIOS_H */ 54 | -------------------------------------------------------------------------------- /include/bsd_unistd.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: unistd.h,v 1.103 2016/09/12 19:36:26 guenther Exp $ */ 2 | /* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */ 3 | 4 | /* SPDX-License-Identifier: BSD-3-Clause */ 5 | 6 | /* 7 | * Copyright (c) 1991 The Regents of the University of California. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)unistd.h 5.13 (Berkeley) 6/17/91 40 | */ 41 | 42 | #ifndef _COMPAT_UNISTD_H_ 43 | # define _COMPAT_UNISTD_H_ 44 | 45 | int openbsd_pledge(const char *, const char *); 46 | int openbsd_getopt(int, char * const *, const char *); 47 | int openbsd_getopt(int, char * const *, const char *); 48 | extern char *openbsd_optarg; 49 | extern int openbsd_opterr, openbsd_optind, \ 50 | openbsd_optopt, openbsd_optreset; 51 | 52 | # ifdef __OpenBSD__ 53 | # include 54 | # else 55 | 56 | # include 57 | 58 | # define STDIN_FILENO 0 /* standard input file descriptor */ 59 | # define STDOUT_FILENO 1 /* standard output file descriptor */ 60 | # define STDERR_FILENO 2 /* standard error file descriptor */ 61 | 62 | # endif /* _COMPAT_UNISTD_H_ */ 63 | 64 | #endif /* ifdef __OpenBSD__ */ 65 | 66 | #define _COMPAT_GETOPT_H_ /* glibc includes getopt.h */ 67 | #include_next 68 | #undef _COMPAT_GETOPT_H_ 69 | -------------------------------------------------------------------------------- /include/libgen.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | /* Workarounds for header buglets */ 37 | #ifdef __solaris__ 38 | # undef _TIMESPEC_UTIL_H 39 | # define _TIMESPEC_UTIL_H 1 40 | #endif /* ifdef __solaris__ */ 41 | 42 | #ifndef _COMPAT_LIBGEN_H_ 43 | # define _COMPAT_LIBGEN_H_ 44 | 45 | char *openbsd_basename(char *); 46 | char *openbsd_dirname(char *); 47 | 48 | # include_next 49 | 50 | #endif /* _COMPAT_LIBGEN_H_ */ 51 | -------------------------------------------------------------------------------- /include/pathnames.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _PATHNAMES_H 37 | # define _PATHNAMES_H 38 | 39 | # ifdef _PATH_EXRC 40 | # undef _PATH_EXRC 41 | # endif /* ifdef _PATH_EXRC */ 42 | 43 | # define _PATH_EXRC ".exrc" 44 | 45 | # ifdef _PATH_NEXRC 46 | # undef _PATH_NEXRC 47 | # endif /* ifdef _PATH_NEXRC */ 48 | 49 | # define _PATH_NEXRC ".nexrc" 50 | 51 | # ifdef _PATH_PRESERVE 52 | # undef _PATH_PRESERVE 53 | # endif /* ifdef _PATH_PRESERVE */ 54 | 55 | # define _PATH_PRESERVE "/var/tmp/vi.recover" 56 | 57 | # ifdef _PATH_SYSEXRC 58 | # undef _PATH_TAGS 59 | # endif /* ifdef _PATH_SYSEXRC */ 60 | 61 | # define _PATH_SYSEXRC "/etc/vi.exrc" 62 | 63 | # ifdef _PATH_TAGS 64 | # undef _PATH_TAGS 65 | # endif /* ifdef _PATH_TAGS */ 66 | 67 | # define _PATH_TAGS "tags" 68 | 69 | # ifndef _PATH_SENDMAIL 70 | # define _PATH_SENDMAIL "/usr/sbin/sendmail" 71 | # endif /* ifndef _PATH_SENDMAIL */ 72 | 73 | # ifndef _PATH_STRIP 74 | # define _PATH_STRIP "/usr/bin/strip" 75 | # endif /* ifndef _PATH_STRIP */ 76 | 77 | # ifndef _PATH_SYSV_PTY 78 | # define _PATH_SYSV_PTY "/dev/ptmx" 79 | # endif /* ifndef _PATH_SYSV_PTY */ 80 | 81 | #endif /* ifndef _PATHNAMES_H */ 82 | -------------------------------------------------------------------------------- /include/poll.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include_next 37 | 38 | #ifndef _COMPAT_POLL_H_ 39 | # define _COMPAT_POLL_H_ 40 | 41 | # ifndef INFTIM 42 | # define INFTIM (-1) 43 | # endif /* ifndef INFTIM */ 44 | 45 | #endif /* ifndef _COMPAT_POLL_H */ 46 | -------------------------------------------------------------------------------- /include/sys/stat.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _COMPAT_SYS_STAT_H_ 37 | # define _COMPAT_SYS_STAT_H_ 38 | 39 | # ifndef S_ISTXT 40 | # define S_ISTXT S_ISVTX /* sticky bit */ 41 | # endif /* ifndef S_ISTXT */ 42 | 43 | # ifndef st_atimespec 44 | # define st_atimespec st_atim 45 | # endif /* ifndef st_atimespec */ 46 | 47 | # ifndef st_atimensec 48 | # define st_atimensec st_atim.tv_nsec 49 | # endif /* ifndef st_atimensec */ 50 | 51 | # ifndef st_mtimespec 52 | # define st_mtimespec st_mtim 53 | # endif /* ifndef st_mtimespec */ 54 | 55 | # ifndef st_mtimensec 56 | # define st_mtimensec st_mtim.tv_nsec 57 | # endif /* ifndef st_mtimensec */ 58 | 59 | # ifndef st_ctimespec 60 | # define st_ctimespec st_ctim 61 | # endif /* ifndef st_ctimespec */ 62 | 63 | # ifndef st_ctimensec 64 | # define st_ctimensec st_ctim.tv_nsec 65 | # endif /* ifndef st_ctimensec */ 66 | 67 | #endif /* !_COMPAT_SYS_STAT_H_ */ 68 | 69 | #include_next 70 | -------------------------------------------------------------------------------- /include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _COMPAT_SYS_TYPES_H_ 37 | # define _COMPAT_SYS_TYPES_H_ 38 | /* 39 | * for major() / minor() macros with glibc, needs to be included 40 | * before 41 | */ 42 | # if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ) 43 | # include 44 | # endif /* if defined(__GNU_LIBRARY__) && defined(__GLIBC_PREREQ) */ 45 | #endif /* _COMPAT_SYS_TYPES_H_ */ 46 | 47 | #include_next 48 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: util.h,v 1.5 2022/12/26 19:16:03 jmc Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | * 14 | * @(#)util.h 10.5 (Berkeley) 3/16/96 15 | */ 16 | 17 | #ifndef _UTIL_H 18 | # define _UTIL_H 19 | 20 | /* Macros to init/set/clear/test flags. */ 21 | # define FL_INIT(l, f) (l) = (f) /* Specific flags location. */ 22 | # define FL_SET(l, f) ((l) |= (f)) 23 | # define FL_CLR(l, f) ((l) &= ~(f)) 24 | # define FL_ISSET(l, f) ((l) & (f)) 25 | 26 | # define LF_INIT(f) FL_INIT(flags, (f)) /* Local variable flags. */ 27 | # define LF_SET(f) FL_SET(flags, (f)) 28 | # define LF_CLR(f) FL_CLR(flags, (f)) 29 | # define LF_ISSET(f) FL_ISSET(flags, (f)) 30 | 31 | # define F_INIT(p, f) FL_INIT((p)->flags, (f)) /* Structure element flags. */ 32 | # define F_SET(p, f) FL_SET((p)->flags, (f)) 33 | # define F_CLR(p, f) FL_CLR((p)->flags, (f)) 34 | # define F_ISSET(p, f) FL_ISSET((p)->flags, (f)) 35 | 36 | /* Offset to next column of stop size, e.g. tab offsets. */ 37 | # define COL_OFF(c, stop) ((stop) - ((c) % (stop))) 38 | 39 | /* Busy message types. */ 40 | typedef enum { B_NONE, B_OFF, B_READ, B_RECOVER, B_SEARCH, B_WRITE } bmsg_t; 41 | 42 | /* 43 | * Number handling defines and prototypes. 44 | * 45 | * NNFITS: test for addition of two negative numbers under a limit 46 | * NPFITS: test for addition of two positive numbers under a limit 47 | * NADD_SLONG: test for addition of two signed longs 48 | * NADD_USLONG: test for addition of two unsigned longs 49 | */ 50 | enum nresult { NUM_ERR, NUM_OK, NUM_OVER, NUM_UNDER }; 51 | 52 | # define NNFITS(min, cur, add) \ 53 | (((long)(min)) - (cur) <= (add)) 54 | 55 | # define NPFITS(max, cur, add) \ 56 | (((unsigned long)(max)) - (cur) >= (add)) 57 | 58 | # define NADD_SLONG(v1, v2) \ 59 | ((v1) < 0 ? \ 60 | ((v2) < 0 && \ 61 | NNFITS(LONG_MIN, (v1), (v2))) ? NUM_UNDER : NUM_OK : \ 62 | (v1) > 0 ? \ 63 | (v2) > 0 && \ 64 | NPFITS(LONG_MAX, (v1), (v2)) ? NUM_OK : NUM_OVER : \ 65 | NUM_OK) 66 | 67 | #endif /* ifndef _UTIL_H */ 68 | -------------------------------------------------------------------------------- /openbsd/basename.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: basename.c,v 1.17 2020/10/20 19:30:14 naddy Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 1997, 2004 Todd C. Miller 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #undef open 29 | 30 | char * 31 | openbsd_basename(char *path) 32 | { 33 | static char bname[PATH_MAX]; 34 | size_t len; 35 | const char *endp, *startp; 36 | 37 | /* Empty or NULL string gets treated as "." */ 38 | if (path == NULL || *path == '\0') 39 | { 40 | bname[0] = '.'; 41 | bname[1] = '\0'; 42 | return bname; 43 | } 44 | 45 | /* Strip any trailing slashes */ 46 | endp = path + strlen(path) - 1; 47 | while (endp > path && *endp == '/') 48 | { 49 | endp--; 50 | } 51 | 52 | /* All slashes becomes "/" */ 53 | if (endp == path && *endp == '/') 54 | { 55 | bname[0] = '/'; 56 | bname[1] = '\0'; 57 | return bname; 58 | } 59 | 60 | /* Find the start of the base */ 61 | startp = endp; 62 | while (startp > path && *( startp - 1 ) != '/') 63 | { 64 | startp--; 65 | } 66 | 67 | len = endp - startp + 1; 68 | if (len >= sizeof ( bname )) 69 | { 70 | errno = ENAMETOOLONG; 71 | return NULL; 72 | } 73 | 74 | memcpy(bname, startp, len); 75 | bname[len] = '\0'; 76 | return bname; 77 | } 78 | -------------------------------------------------------------------------------- /openbsd/dirname.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: dirname.c,v 1.17 2020/10/20 19:30:14 naddy Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 1997, 2004 Todd C. Miller 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #undef open 29 | 30 | char * 31 | openbsd_dirname(char *path) 32 | { 33 | static char dname[PATH_MAX]; 34 | size_t len; 35 | const char *endp; 36 | 37 | /* Empty or NULL string gets treated as "." */ 38 | if (path == NULL || *path == '\0') 39 | { 40 | dname[0] = '.'; 41 | dname[1] = '\0'; 42 | return dname; 43 | } 44 | 45 | /* Strip any trailing slashes */ 46 | endp = path + strlen(path) - 1; 47 | while (endp > path && *endp == '/') 48 | { 49 | endp--; 50 | } 51 | 52 | /* Find the start of the dir */ 53 | while (endp > path && *endp != '/') 54 | { 55 | endp--; 56 | } 57 | 58 | /* Either the dir is "/" or there are no slashes */ 59 | if (endp == path) 60 | { 61 | dname[0] = *endp == '/' ? '/' : '.'; 62 | dname[1] = '\0'; 63 | return dname; 64 | } 65 | else 66 | { 67 | /* Move forward past the separating slashes */ 68 | do 69 | { 70 | endp--; 71 | } 72 | while ( endp > path && *endp == '/' ); 73 | } 74 | 75 | len = endp - path + 1; 76 | if (len >= sizeof ( dname )) 77 | { 78 | errno = ENAMETOOLONG; 79 | return NULL; 80 | } 81 | 82 | memcpy(dname, path, len); 83 | dname[len] = '\0'; 84 | return dname; 85 | } 86 | -------------------------------------------------------------------------------- /openbsd/err.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: err.c,v 1.12 2015/08/31 02:53:57 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | 46 | #undef open 47 | 48 | void 49 | openbsd_err(int eval, const char *fmt, ...) 50 | { 51 | va_list ap; 52 | 53 | va_start(ap, fmt); 54 | openbsd_verr(eval, fmt, ap); 55 | va_end(ap); 56 | } 57 | -------------------------------------------------------------------------------- /openbsd/errc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: errc.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include 42 | #include 43 | 44 | #include "errc.h" 45 | 46 | #undef open 47 | 48 | void 49 | openbsd_errc(int eval, int code, const char *fmt, ...) 50 | { 51 | va_list ap; 52 | 53 | va_start(ap, fmt); 54 | openbsd_verrc(eval, code, fmt, ap); 55 | va_end(ap); 56 | } 57 | -------------------------------------------------------------------------------- /openbsd/errc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _ERRC_H 37 | # define _ERRC_H 38 | 39 | # include "../include/compat.h" 40 | 41 | # ifndef __solaris__ 42 | # include 43 | # include 44 | # else 45 | # undef _TIMESPEC_UTIL_H 46 | # define _TIMESPEC_UTIL_H 1 47 | # endif /* ifndef __solaris__ */ 48 | 49 | # include 50 | # include 51 | # include 52 | 53 | # undef open 54 | 55 | void openbsd_errc(int eval, int code, const char *fmt, ...); 56 | void openbsd_err(int eval, const char *fmt, ...); 57 | void openbsd_errx(int eval, const char *fmt, ...); 58 | void openbsd_verrc(int eval, int code, const char *fmt, va_list ap); 59 | void openbsd_verr(int eval, const char *fmt, va_list ap); 60 | void openbsd_verrx(int eval, const char *fmt, va_list ap); 61 | void openbsd_vwarnc(int code, const char *fmt, va_list ap); 62 | void openbsd_vwarn(const char *fmt, va_list ap); 63 | void openbsd_vwarnx(const char *fmt, va_list ap); 64 | void openbsd_warnc(int code, const char *fmt, ...); 65 | void openbsd_warn(const char *fmt, ...); 66 | void openbsd_warnx(const char *fmt, ...); 67 | 68 | #endif /* ifndef _ERRC_H */ 69 | -------------------------------------------------------------------------------- /openbsd/errx.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: errx.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | 46 | #undef open 47 | 48 | void 49 | openbsd_errx(int eval, const char *fmt, ...) 50 | { 51 | va_list ap; 52 | 53 | va_start(ap, fmt); 54 | openbsd_verrx(eval, fmt, ap); 55 | va_end(ap); 56 | } 57 | -------------------------------------------------------------------------------- /openbsd/getopt_long.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: getopt.h,v 1.3 2013/11/22 21:32:49 millert Exp $ */ 2 | /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 3 | 4 | /* SPDX-License-Identifier: BSD-2-Clause */ 5 | 6 | /* 7 | * Copyright (c) 2000 The NetBSD Foundation, Inc. 8 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 9 | * 10 | * All rights reserved. 11 | * 12 | * This code is derived from software contributed to The NetBSD Foundation 13 | * by Dieter Baron and Thomas Klausner. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef _OBSD_GETOPT_H_ 40 | # define _OBSD_GETOPT_H_ 41 | 42 | /* 43 | * GNU-like getopt_long() 44 | */ 45 | # define no_argument 0 46 | # define required_argument 1 47 | # define optional_argument 2 48 | 49 | struct option 50 | { 51 | /* name of long option */ 52 | const char *name; 53 | /* 54 | * one of no_argument, required_argument, and optional_argument: 55 | * whether option takes an argument 56 | */ 57 | int has_arg; 58 | /* if not NULL, set *flag to val when option found */ 59 | int *flag; 60 | /* if flag not NULL, value to set *flag to; else return value */ 61 | int val; 62 | }; 63 | 64 | int openbsd_getopt_long (int, char *const *, const char *, const struct option *, 65 | int *); 66 | int openbsd_getopt_long_only (int, char *const *, const char *, const struct option *, 67 | int *); 68 | # ifndef _GETOPT_DEFINED_ 69 | # define _GETOPT_DEFINED_ 70 | int openbsd_getopt (int, char *const *, const char *); 71 | 72 | extern char *openbsd_optarg; /* getopt(3) external variables */ 73 | extern int openbsd_opterr; 74 | extern int openbsd_optind; 75 | extern int openbsd_optopt; 76 | extern int openbsd_optreset; 77 | # endif /* _GETOPT_DEFINED_ */ 78 | 79 | #endif /* !_OBSD_GETOPT_H_ */ 80 | -------------------------------------------------------------------------------- /openbsd/getprogname.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: getprogname.c,v 1.4 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 2013 Antoine Jacoutot 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include 23 | 24 | #ifdef _AIX 25 | # include 26 | # include 27 | # include 28 | #else 29 | extern char *__progname; 30 | #endif /* ifdef _AIX */ 31 | 32 | const char * 33 | bsd_getprogname(void) 34 | { 35 | #ifdef _AIX 36 | static char *p; 37 | static int first = 1; 38 | if (first) 39 | { 40 | first = 0; 41 | pid_t pid = getpid(); 42 | struct procentry64 procs; 43 | p = (0 < getprocs64 (&procs, sizeof procs, NULL, 0, &pid, 1) 44 | ? strdup (procs.pi_comm) : NULL); 45 | if (!p) 46 | p = "?"; 47 | } 48 | return p; 49 | #else 50 | return (__progname); 51 | #endif /* ifdef _AIX */ 52 | } 53 | -------------------------------------------------------------------------------- /openbsd/issetugid.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022 Ørjan Malde 5 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 6 | * 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * 3. Neither the names of the copyright holders nor the names of any 21 | * contributors may be used to endorse or promote products derived from 22 | * this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 28 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 34 | * THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #include "../include/compat.h" 38 | 39 | #include 40 | 41 | #undef open 42 | 43 | #if ( defined(__GLIBC__) && defined(__GLIBC_MINOR__) ) \ 44 | || defined(__linux__) || defined(__midipix__) \ 45 | || defined(__illumos__) 46 | # include 47 | #else 48 | # include 49 | #endif /* if ( defined(__GLIBC__) && defined(__GLIBC_MINOR__) ) 50 | || defined(__linux__) || defined(__midipix__) 51 | || defined(__illumos__) */ 52 | 53 | #if defined(__FreeBSD__) || defined(__OpenBSD__) \ 54 | || ( defined(__APPLE__ ) && defined(__MACH__) ) \ 55 | || defined(__CYGWIN__) || defined(__NetBSD__) 56 | # include 57 | #else 58 | 59 | # if defined(__linux__) || defined(__illumos__) 60 | # include 61 | # endif /* if defined(__linux__) || defined(__illumos__) */ 62 | 63 | int 64 | issetugid(void) 65 | { 66 | int rv = 0; 67 | 68 | errno = 0; 69 | # if !defined(_AIX) \ 70 | && !defined(__illumos__) && !defined(__solaris__) \ 71 | && !defined(__managarm__) 72 | rv = getauxval(AT_SECURE) != 0; 73 | # endif /* if !defined(_AIX) 74 | && !defined(__illumos__) && !defined(__solaris__) */ 75 | if (errno) 76 | { 77 | errno = 0; 78 | rv = 1; 79 | } 80 | 81 | return rv; 82 | } 83 | #endif /* if defined(__FreeBSD__) || defined(__OpenBSD__) 84 | || ( defined(__APPLE__) && defined(__MACH__) ) 85 | || defined(__CYGWIN__) || defined(__NetBSD__) */ 86 | -------------------------------------------------------------------------------- /openbsd/minpwcache.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _MINPWCAC_H 37 | # define _MINPWCAC_H 38 | 39 | # include "../include/compat.h" 40 | 41 | # include 42 | # include 43 | 44 | # include 45 | # include 46 | # include 47 | 48 | # undef open 49 | 50 | int openbsd_gid_from_group(const char *name, gid_t *gid); 51 | int openbsd_uid_from_user(const char *name, uid_t *uid); 52 | 53 | #endif /* ifndef _MINPWCAC_H */ 54 | -------------------------------------------------------------------------------- /openbsd/open.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "../include/compat.h" 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #undef open 46 | 47 | int 48 | openbsd_open(const char *path, int flags, ...) 49 | { 50 | va_list ap; 51 | int fd, lock; 52 | 53 | lock = flags & ( O_EXLOCK | O_SHLOCK ); 54 | flags &= ~lock; 55 | 56 | va_start(ap, flags); 57 | if (( fd = open(path, flags, ap)) == -1) 58 | { 59 | return -1; 60 | } 61 | 62 | va_end(ap); 63 | 64 | if (lock == 0) 65 | { 66 | return fd; 67 | } 68 | 69 | #ifndef __solaris__ 70 | if (flock(fd, lock & O_EXLOCK ? LOCK_EX : LOCK_SH) == -1) 71 | { 72 | close(fd); 73 | return -1; 74 | } 75 | #endif /* ifndef __solaris__ */ 76 | 77 | return fd; 78 | } 79 | -------------------------------------------------------------------------------- /openbsd/pledge.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2021-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "../include/compat.h" 37 | 38 | #include 39 | 40 | #undef open 41 | 42 | #ifdef __OpenBSD__ 43 | # include 44 | #endif /* ifdef __OpenBSD__ */ 45 | 46 | int 47 | openbsd_pledge(const char *promises, const char *execpromises) 48 | { 49 | #if defined(__OpenBSD__) || defined(__serenity__) 50 | # if ( defined(OpenBSD) && OpenBSD >= 201605 ) \ 51 | || defined(OpenBSD5_9) || defined(__serenity__) 52 | return(pledge(promises, execpromises)); 53 | # else 54 | return 0; 55 | # endif /* if ( defined(OpenBSD) && OpenBSD >= 201605 ) 56 | || defined(OpenBSD5_9) || defined(__serenity__) */ 57 | #else 58 | return 0; 59 | #endif /* if defined(__OpenBSD__) || defined(__serenity__) */ 60 | } 61 | -------------------------------------------------------------------------------- /openbsd/reallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 2008 Otto Moerbeek 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include "../include/compat.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #undef open 30 | 31 | /* 32 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 33 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 34 | */ 35 | 36 | #ifdef MUL_NO_OVERFLOW 37 | # undef MUL_NO_OVERFLOW 38 | #endif /* ifdef MUL_NO_OVERFLOW */ 39 | #define MUL_NO_OVERFLOW ((size_t)1 << ( sizeof ( size_t ) * 4 )) 40 | 41 | void * 42 | openbsd_reallocarray(void *optr, size_t nmemb, size_t size) 43 | { 44 | if (( nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW ) && nmemb > 0 45 | && SIZE_MAX / nmemb < size) 46 | { 47 | errno = ENOMEM; 48 | return NULL; 49 | } 50 | 51 | return realloc(optr, size * nmemb); 52 | } 53 | -------------------------------------------------------------------------------- /openbsd/setmode.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause */ 2 | 3 | /* 4 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the names of the copyright holders nor the names of any 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 | * THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _SETMODE_H 37 | # define _SETMODE_H 38 | 39 | # include "../include/compat.h" 40 | 41 | # include 42 | # include 43 | 44 | # include 45 | # include 46 | # include 47 | 48 | # undef open 49 | 50 | void *openbsd_setmode(const char *p); 51 | mode_t openbsd_getmode(const void *bbox, mode_t omode); 52 | 53 | #endif /* ifndef _SETMODE_H */ 54 | -------------------------------------------------------------------------------- /openbsd/strlcat.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 1998, 2015 Todd C. Miller 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include "../include/compat.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #undef open 30 | 31 | /* 32 | * Appends src to string dst of size dsize (unlike strncat, dsize is the 33 | * full size of dst, not space left). At most dsize-1 characters 34 | * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). 35 | * Returns strlen(src) + MIN(dsize, strlen(initial dst)). 36 | * If retval >= dsize, truncation occurred. 37 | */ 38 | size_t 39 | openbsd_strlcat(char *dst, const char *src, size_t dsize) 40 | { 41 | const char *odst = dst; 42 | const char *osrc = src; 43 | size_t n = dsize; 44 | size_t dlen; 45 | 46 | /* Find the end of dst and adjust bytes left but don't go past end. */ 47 | while (n-- != 0 && *dst != '\0') 48 | { 49 | dst++; 50 | } 51 | dlen = dst - odst; 52 | n = dsize - dlen; 53 | 54 | if (n-- == 0) 55 | { 56 | return dlen + strlen(src); 57 | } 58 | 59 | while (*src != '\0') 60 | { 61 | if (n != 0) 62 | { 63 | *dst++ = *src; 64 | n--; 65 | } 66 | 67 | src++; 68 | } 69 | *dst = '\0'; 70 | 71 | return dlen + ( src - osrc ); /* count does not include NUL */ 72 | } 73 | -------------------------------------------------------------------------------- /openbsd/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 1998, 2015 Todd C. Miller 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * Permission to use, copy, modify, and distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice appear in all copies. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 | */ 21 | 22 | #include "../include/compat.h" 23 | 24 | #include 25 | #include 26 | 27 | #undef open 28 | 29 | /* 30 | * Copy string src to buffer dst of size dsize. At most dsize-1 31 | * chars will be copied. Always NUL terminates (unless dsize == 0). 32 | * Returns strlen(src); if retval >= dsize, truncation occurred. 33 | */ 34 | size_t 35 | openbsd_strlcpy(char *dst, const char *src, size_t dsize) 36 | { 37 | const char *osrc = src; 38 | size_t nleft = dsize; 39 | 40 | /* Copy as many bytes as will fit. */ 41 | if (nleft != 0) 42 | { 43 | while (--nleft != 0) 44 | { 45 | if (( *dst++ = *src++ ) == '\0') 46 | { 47 | break; 48 | } 49 | } 50 | } 51 | 52 | /* Not enough room in dst, add NUL and traverse rest of src. */ 53 | if (nleft == 0) 54 | { 55 | if (dsize != 0) 56 | { 57 | *dst = '\0'; /* NUL-terminate dst */ 58 | } 59 | 60 | while (*src++) 61 | { 62 | ; 63 | } 64 | } 65 | 66 | return src - osrc - 1; /* count does not include NUL */ 67 | } 68 | -------------------------------------------------------------------------------- /openbsd/strtonum.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: ISC */ 4 | 5 | /* 6 | * Copyright (c) 2004 Ted Unangst and Todd Miller 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Permission to use, copy, modify, and distribute this software for any 12 | * purpose with or without fee is hereby granted, provided that the above 13 | * copyright notice and this permission notice appear in all copies. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 16 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 17 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 18 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 20 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 21 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #define INVALID 1 29 | #define TOOSMALL 2 30 | #define TOOLARGE 3 31 | 32 | long long 33 | strtonum(const char *numstr, long long minval, long long maxval, 34 | const char **errstrp) 35 | { 36 | long long ll = 0; 37 | int error = 0; 38 | char *ep; 39 | struct errval { 40 | const char *errstr; 41 | int err; 42 | } ev[4] = { 43 | { NULL, 0 }, 44 | { "invalid", EINVAL }, 45 | { "too small", ERANGE }, 46 | { "too large", ERANGE }, 47 | }; 48 | 49 | ev[0].err = errno; 50 | errno = 0; 51 | if (minval > maxval) { 52 | error = INVALID; 53 | } else { 54 | ll = strtoll(numstr, &ep, 10); 55 | if (numstr == ep || *ep != '\0') 56 | error = INVALID; 57 | else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) 58 | error = TOOSMALL; 59 | else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) 60 | error = TOOLARGE; 61 | } 62 | if (errstrp != NULL) 63 | *errstrp = ev[error].errstr; 64 | errno = ev[error].err; 65 | if (error) 66 | ll = 0; 67 | 68 | return (ll); 69 | } 70 | -------------------------------------------------------------------------------- /openbsd/verr.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: verr.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #undef open 51 | 52 | void 53 | openbsd_verr(int eval, const char *fmt, va_list ap) 54 | { 55 | int sverrno; 56 | 57 | sverrno = errno; 58 | (void)fprintf(stderr, "%s: ", bsd_getprogname()); 59 | if (fmt != NULL) { 60 | (void)vfprintf(stderr, fmt, ap); 61 | (void)fprintf(stderr, ": "); 62 | } 63 | (void)fprintf(stderr, "%s\n", strerror(sverrno)); 64 | exit(eval); 65 | } 66 | -------------------------------------------------------------------------------- /openbsd/verrc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: verrc.c,v 1.3 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | #include "bsd_err.h" 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #undef open 48 | 49 | void 50 | openbsd_verrc(int eval, int code, const char *fmt, va_list ap) 51 | { 52 | (void)fprintf(stderr, "%s: ", bsd_getprogname()); 53 | if (fmt != NULL) 54 | { 55 | (void)vfprintf(stderr, fmt, ap); 56 | (void)fprintf(stderr, ": "); 57 | } 58 | 59 | (void)fprintf(stderr, "%s\n", strerror(code)); 60 | exit(eval); 61 | } 62 | -------------------------------------------------------------------------------- /openbsd/verrx.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: verrx.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #undef open 49 | 50 | void 51 | openbsd_verrx(int eval, const char *fmt, va_list ap) 52 | { 53 | (void)fprintf(stderr, "%s: ", bsd_getprogname()); 54 | if (fmt != NULL) 55 | (void)vfprintf(stderr, fmt, ap); 56 | (void)fprintf(stderr, "\n"); 57 | exit(eval); 58 | } 59 | -------------------------------------------------------------------------------- /openbsd/vwarn.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: vwarn.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #undef open 51 | 52 | void 53 | openbsd_vwarn(const char *fmt, va_list ap) 54 | { 55 | int sverrno; 56 | 57 | sverrno = errno; 58 | (void)fprintf(stderr, "%s: ", bsd_getprogname()); 59 | if (fmt != NULL) { 60 | (void)vfprintf(stderr, fmt, ap); 61 | (void)fprintf(stderr, ": "); 62 | } 63 | (void)fprintf(stderr, "%s\n", strerror(sverrno)); 64 | } 65 | -------------------------------------------------------------------------------- /openbsd/vwarnc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: vwarnc.c,v 1.3 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #undef open 48 | 49 | void 50 | openbsd_vwarnc(int code, const char *fmt, va_list ap) 51 | { 52 | (void)fprintf(stderr, "%s: ", bsd_getprogname()); 53 | if (fmt != NULL) 54 | { 55 | (void)vfprintf(stderr, fmt, ap); 56 | (void)fprintf(stderr, ": "); 57 | } 58 | 59 | (void)fprintf(stderr, "%s\n", strerror(code)); 60 | } 61 | -------------------------------------------------------------------------------- /openbsd/vwarnx.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: vwarnx.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #undef open 49 | 50 | void 51 | openbsd_vwarnx(const char *fmt, va_list ap) 52 | { 53 | (void)fprintf(stderr, "%s: ", bsd_getprogname()); 54 | if (fmt != NULL) 55 | (void)vfprintf(stderr, fmt, ap); 56 | (void)fprintf(stderr, "\n"); 57 | } 58 | -------------------------------------------------------------------------------- /openbsd/warn.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: warn.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | 46 | #undef open 47 | 48 | void 49 | openbsd_warn(const char *fmt, ...) 50 | { 51 | va_list ap; 52 | 53 | va_start(ap, fmt); 54 | openbsd_vwarn(fmt, ap); 55 | va_end(ap); 56 | } 57 | -------------------------------------------------------------------------------- /openbsd/warnc.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: warnc.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | 46 | #undef open 47 | 48 | void 49 | openbsd_warnc(int code, const char *fmt, ...) 50 | { 51 | va_list ap; 52 | 53 | va_start(ap, fmt); 54 | openbsd_vwarnc(code, fmt, ap); 55 | va_end(ap); 56 | } 57 | -------------------------------------------------------------------------------- /openbsd/warnx.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: warnx.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993 The Regents of the University of California. 7 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | */ 38 | 39 | #include "../include/compat.h" 40 | 41 | #include "errc.h" 42 | 43 | #include 44 | #include 45 | 46 | #undef open 47 | 48 | void 49 | openbsd_warnx(const char *fmt, ...) 50 | { 51 | va_list ap; 52 | 53 | va_start(ap, fmt); 54 | openbsd_vwarnx(fmt, ap); 55 | va_end(ap); 56 | } 57 | -------------------------------------------------------------------------------- /regex/cclass.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: cclass.h,v 1.7 2020/12/30 08:54:42 tb Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 Henry Spencer. 7 | * Copyright (c) 1992, 1993, 1994 8 | * The Regents of the University of California. 9 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 10 | * 11 | * All rights reserved. 12 | * 13 | * This code is derived from software contributed to Berkeley by 14 | * Henry Spencer. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 23 | * 2. Redistributions in binary form must reproduce the above copyright 24 | * notice, this list of conditions and the following disclaimer in the 25 | * documentation and/or other materials provided with the distribution. 26 | * 27 | * 3. Neither the name of the University nor the names of its contributors 28 | * may be used to endorse or promote products derived from this software 29 | * without specific prior written permission. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41 | * SUCH DAMAGE. 42 | * 43 | * @(#)cclass.h 8.3 (Berkeley) 3/20/94 44 | */ 45 | 46 | /* character-class table */ 47 | static const struct cclass 48 | { 49 | const char *name; 50 | const char *chars; 51 | } cclasses[] 52 | = { { "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 53 | 0123456789" }, 54 | { "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" }, 55 | { "blank", " \t" }, 56 | { "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ 57 | \25\26\27\30\31\32\33\34\35\36\37\177" }, 58 | { "digit", "0123456789" }, 59 | { "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 60 | 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" }, 61 | { "lower", "abcdefghijklmnopqrstuvwxyz" }, 62 | { "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 63 | 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ " }, 64 | { "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" }, 65 | { "space", "\t\n\v\f\r " }, 66 | { "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, 67 | { "xdigit", "0123456789ABCDEFabcdef" }, 68 | { NULL, 0 } }; 69 | -------------------------------------------------------------------------------- /regex/regfree.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: regfree.c,v 1.11 2015/12/28 22:27:03 mmcc Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 Henry Spencer. 7 | * Copyright (c) 1992, 1993, 1994 8 | * The Regents of the University of California. All rights reserved. 9 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 10 | * 11 | * All rights reserved. 12 | * 13 | * This code is derived from software contributed to Berkeley by 14 | * Henry Spencer. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 23 | * 2. Redistributions in binary form must reproduce the above copyright 24 | * notice, this list of conditions and the following disclaimer in the 25 | * documentation and/or other materials provided with the distribution. 26 | * 27 | * 3. Neither the name of the University nor the names of its contributors 28 | * may be used to endorse or promote products derived from this software 29 | * without specific prior written permission. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41 | * SUCH DAMAGE. 42 | * 43 | * @(#)regfree.c 8.3 (Berkeley) 3/20/94 44 | */ 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #include "utils.h" 53 | #include "bsd_regex2.h" 54 | 55 | /* 56 | - regfree - free everything 57 | */ 58 | void 59 | regfree(regex_t *preg) 60 | { 61 | struct re_guts *g; 62 | 63 | if (preg->re_magic != MAGIC1) /* oops */ 64 | return; /* nice to complain, but hard */ 65 | 66 | g = preg->re_g; 67 | if (g == NULL || g->magic != MAGIC2) /* oops again */ 68 | return; 69 | preg->re_magic = 0; /* mark it invalid */ 70 | g->magic = 0; /* mark it invalid */ 71 | 72 | free(g->strip); 73 | free(g->sets); 74 | free(g->setbits); 75 | free(g->must); 76 | free(g); 77 | } 78 | -------------------------------------------------------------------------------- /regex/utils.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: utils.h,v 1.4 2003/06/02 20:18:36 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 Henry Spencer. 7 | * Copyright (c) 1992, 1993, 1994 8 | * The Regents of the University of California. All rights reserved. 9 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 10 | * 11 | * All rights reserved. 12 | * 13 | * This code is derived from software contributed to Berkeley by 14 | * Henry Spencer. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 23 | * 2. Redistributions in binary form must reproduce the above copyright 24 | * notice, this list of conditions and the following disclaimer in the 25 | * documentation and/or other materials provided with the distribution. 26 | * 27 | * 3. Neither the name of the University nor the names of its contributors 28 | * may be used to endorse or promote products derived from this software 29 | * without specific prior written permission. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41 | * SUCH DAMAGE. 42 | * 43 | * @(#)utils.h 8.3 (Berkeley) 3/20/94 44 | */ 45 | 46 | /* utility definitions */ 47 | 48 | #if defined(__managarm__) 49 | # if !defined(_POSIX2_RE_DUP_MAX) 50 | # define _POSIX2_RE_DUP_MAX 255 51 | # endif 52 | #endif 53 | 54 | #define DUPMAX _POSIX2_RE_DUP_MAX 55 | #define INFINITY (DUPMAX + 1) 56 | #define NC (CHAR_MAX - CHAR_MIN + 1) 57 | typedef unsigned char uch; 58 | 59 | /* switch off assertions (if not already off) if no REDEBUG */ 60 | #ifndef REDEBUG 61 | # ifndef NDEBUG 62 | # define NDEBUG /* no assertions please */ 63 | # endif /* ifndef NDEBUG */ 64 | #endif /* ifndef REDEBUG */ 65 | #include 66 | -------------------------------------------------------------------------------- /scripts/virecover.8: -------------------------------------------------------------------------------- 1 | .\" $NetBSD: virecover.8,v 1.1 2013/11/22 16:00:45 christos Exp $ 2 | .\" 3 | .\" SPDX-License-Identifier: BSD-2-Clause 4 | .\" 5 | .\" Copyright (c) 2006 The NetBSD Foundation, Inc. 6 | .\" Copyright (c) 2022-2024 Jeffrey H. Johnson 7 | .\" 8 | .\" All rights reserved. 9 | .\" 10 | .\" This code is derived from software contributed to The NetBSD Foundation 11 | .\" by Jeremy C. Reed. 12 | .\" 13 | .\" Redistribution and use in source and binary forms, with or without 14 | .\" modification, are permitted provided that the following conditions 15 | .\" are met: 16 | .\" 17 | .\" 1. Redistributions of source code must retain the above copyright 18 | .\" notice, this list of conditions and the following disclaimer. 19 | .\" 20 | .\" 2. Redistributions in binary form must reproduce the above copyright 21 | .\" notice, this list of conditions and the following disclaimer in the 22 | .\" documentation and/or other materials provided with the distribution. 23 | .\" 24 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 25 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | .\" POSSIBILITY OF SUCH DAMAGE. 35 | .\" 36 | .Dd October 9, 2006 37 | .Dt VIRECOVER 8 38 | .Os 39 | .Sh NAME 40 | .Nm vi.recover 41 | .Nd report recovered nvi edit sessions 42 | .Sh SYNOPSIS 43 | .Pa /usr/libexec/vi.recover 44 | .Sh DESCRIPTION 45 | The 46 | .Nm 47 | utility sends emails to users who have 48 | .Xr nvi 1 49 | recovery files. 50 | .Pp 51 | This email gives the name of the file that was 52 | saved for recovery and instructions for recovering 53 | most, if not all, of the changes to the file. 54 | This is done by using the 55 | .Fl r 56 | option with 57 | .Xr nvi 1 . 58 | See the 59 | .Fl r 60 | option in 61 | .Xr nvi 1 62 | for details. 63 | .Pp 64 | If the backup files have the execute bit set or are zero length, 65 | then they have not been modified, so 66 | .Nm 67 | deletes them to clean up. 68 | .Nm 69 | also removes recovery files that are corrupted, zero length, 70 | or do not have a corresponding backup file. 71 | .Pp 72 | .Nm 73 | is normally run automatically at boot time. 74 | .Sh FILES 75 | .Bl -tag -width "/var/tmp/vi.recover/recover.*" -compact 76 | .It Pa /var/tmp/vi.recover/recover.* 77 | .Xr nvi 1 78 | recovery files 79 | .It Pa /var/tmp/vi.recover/vi.* 80 | .Xr nvi 1 81 | editor backup files 82 | .El 83 | .Sh SEE ALSO 84 | .Xr nvi 1 85 | .Sh AUTHORS 86 | This man page was originally written by 87 | .An Jeremy C. Reed Aq Mt reed@reedmedia.net . 88 | -------------------------------------------------------------------------------- /vi/v_delete.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_delete.c,v 1.8 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | #include "vi.h" 25 | 26 | /* 27 | * v_delete -- [buffer][count]d[count]motion 28 | * [buffer][count]D 29 | * Delete a range of text. 30 | * 31 | * PUBLIC: int v_delete(SCR *, VICMD *); 32 | */ 33 | int 34 | v_delete(SCR *sp, VICMD *vp) 35 | { 36 | recno_t nlines = 0; 37 | size_t len; 38 | int lmode; 39 | 40 | lmode = F_ISSET(vp, VM_LMODE) ? CUT_LINEMODE : 0; 41 | 42 | /* Yank the lines. */ 43 | if (cut(sp, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, 44 | &vp->m_start, &vp->m_stop, 45 | lmode | (F_ISSET(vp, VM_CUTREQ) ? CUT_NUMREQ : CUT_NUMOPT))) 46 | return (1); 47 | 48 | /* Delete the lines. */ 49 | if (del(sp, &vp->m_start, &vp->m_stop, lmode)) 50 | return (1); 51 | 52 | /* 53 | * Check for deletion of the entire file. Try to check a close 54 | * by line so we don't go to the end of the file unnecessarily. 55 | */ 56 | if (!db_exist(sp, vp->m_final.lno + 1)) { 57 | if (db_last(sp, &nlines)) 58 | return (1); 59 | if (nlines == 0) { 60 | vp->m_final.lno = 1; 61 | vp->m_final.cno = 0; 62 | return (0); 63 | } 64 | } 65 | 66 | /* 67 | * One special correction, in case we've deleted the current line or 68 | * character. We check it here instead of checking in every command 69 | * that can be a motion component. 70 | */ 71 | if (db_get(sp, vp->m_final.lno, 0, NULL, &len)) { 72 | if (db_get(sp, nlines, DBG_FATAL, NULL, &len)) 73 | return (1); 74 | vp->m_final.lno = nlines; 75 | } 76 | 77 | /* 78 | * !!! 79 | * Cursor movements, other than those caused by a line mode command 80 | * moving to another line, historically reset the relative position. 81 | * 82 | * This currently matches the check made in v_yank(), I'm hoping that 83 | * they should be consistent... 84 | */ 85 | if (!F_ISSET(vp, VM_LMODE)) { 86 | F_CLR(vp, VM_RCM_MASK); 87 | F_SET(vp, VM_RCM_SET); 88 | 89 | /* Make sure the set cursor position exists. */ 90 | if (vp->m_final.cno >= len) 91 | vp->m_final.cno = len ? len - 1 : 0; 92 | } 93 | 94 | /* 95 | * !!! 96 | * The "dd" command moved to the first non-blank; "d" 97 | * didn't. 98 | */ 99 | if (F_ISSET(vp, VM_LDOUBLE)) { 100 | F_CLR(vp, VM_RCM_MASK); 101 | F_SET(vp, VM_RCM_SETFNB); 102 | } 103 | return (0); 104 | } 105 | -------------------------------------------------------------------------------- /vi/v_init.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_init.c,v 1.8 2017/04/18 01:45:35 deraadt Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "../common/common.h" 27 | #include "vi.h" 28 | 29 | /* 30 | * v_screen_copy -- 31 | * Copy vi screen. 32 | * 33 | * PUBLIC: int v_screen_copy(SCR *, SCR *); 34 | */ 35 | int 36 | v_screen_copy(SCR *orig, SCR *sp) 37 | { 38 | VI_PRIVATE *ovip, *nvip; 39 | 40 | /* Create the private vi structure. */ 41 | CALLOC_RET(orig, nvip, 1, sizeof(VI_PRIVATE)); 42 | sp->vi_private = nvip; 43 | 44 | /* Invalidate the line size cache. */ 45 | VI_SCR_CFLUSH(nvip); 46 | 47 | if (orig == NULL) { 48 | nvip->csearchdir = CNOTSET; 49 | } else { 50 | ovip = VIP(orig); 51 | 52 | /* User can replay the last input, but nothing else. */ 53 | if (ovip->rep_len != 0) { 54 | MALLOC_RET(orig, nvip->rep, ovip->rep_len); 55 | memmove(nvip->rep, ovip->rep, ovip->rep_len); 56 | nvip->rep_len = ovip->rep_len; 57 | } 58 | 59 | /* Copy the paragraph/section information. */ 60 | if (ovip->ps != NULL && (nvip->ps = 61 | v_strdup(sp, ovip->ps, strlen(ovip->ps))) == NULL) 62 | return (1); 63 | 64 | nvip->lastckey = ovip->lastckey; 65 | nvip->csearchdir = ovip->csearchdir; 66 | 67 | nvip->srows = ovip->srows; 68 | } 69 | return (0); 70 | } 71 | 72 | /* 73 | * v_screen_end -- 74 | * End a vi screen. 75 | * 76 | * PUBLIC: int v_screen_end(SCR *); 77 | */ 78 | int 79 | v_screen_end(SCR *sp) 80 | { 81 | VI_PRIVATE *vip; 82 | 83 | if ((vip = VIP(sp)) == NULL) 84 | return (0); 85 | free(vip->keyw); 86 | free(vip->rep); 87 | free(vip->ps); 88 | free(HMAP); 89 | free(vip); 90 | sp->vi_private = NULL; 91 | 92 | return (0); 93 | } 94 | 95 | /* 96 | * v_optchange -- 97 | * Handle change of options for vi. 98 | * 99 | * PUBLIC: int v_optchange(SCR *, int, char *, unsigned long *); 100 | */ 101 | int 102 | v_optchange(SCR *sp, int offset, char *str, unsigned long *valp) 103 | { 104 | switch (offset) { 105 | case O_PARAGRAPHS: 106 | return (v_buildps(sp, str, O_STR(sp, O_SECTIONS))); 107 | case O_SECTIONS: 108 | return (v_buildps(sp, O_STR(sp, O_PARAGRAPHS), str)); 109 | case O_WINDOW: 110 | return (vs_crel(sp, *valp)); 111 | } 112 | return (0); 113 | } 114 | -------------------------------------------------------------------------------- /vi/v_redraw.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_redraw.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | #include "vi.h" 25 | 26 | /* 27 | * v_redraw -- ^L, ^R 28 | * Redraw the screen. 29 | * 30 | * PUBLIC: int v_redraw(SCR *, VICMD *); 31 | */ 32 | 33 | int 34 | v_redraw(SCR *sp, VICMD *vp) 35 | { 36 | F_SET(sp, SC_SCR_REFORMAT); 37 | return (sp->gp->scr_refresh(sp, 1)); 38 | } 39 | -------------------------------------------------------------------------------- /vi/v_screen.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_screen.c,v 1.9 2016/01/06 22:28:52 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | #include "vi.h" 25 | 26 | /* 27 | * v_screen -- ^W 28 | * Switch screens. 29 | * 30 | * PUBLIC: int v_screen(SCR *, VICMD *); 31 | */ 32 | int 33 | v_screen(SCR *sp, VICMD *vp) 34 | { 35 | /* 36 | * You can't leave a colon command-line edit window -- it's not that 37 | * it won't work, but it gets real weird, real fast when you execute 38 | * a colon command out of a window that was forked from a window that's 39 | * now backgrounded... You get the idea. 40 | */ 41 | if (F_ISSET(sp, SC_COMEDIT)) { 42 | msgq(sp, M_ERR, 43 | "Enter to execute a command, :q to exit"); 44 | return (1); 45 | } 46 | 47 | /* 48 | * Try for the next lower screen, or, go back to the first 49 | * screen on the stack. 50 | */ 51 | if (TAILQ_NEXT(sp, q)) 52 | sp->nextdisp = TAILQ_NEXT(sp, q); 53 | else if (TAILQ_FIRST(&sp->gp->dq) == sp) { 54 | msgq(sp, M_ERR, "No other screen to switch to"); 55 | return (1); 56 | } else 57 | sp->nextdisp = TAILQ_FIRST(&sp->gp->dq); 58 | 59 | F_SET(sp->nextdisp, SC_STATUS); 60 | F_SET(sp, SC_SSWITCH | SC_STATUS); 61 | return (0); 62 | } 63 | -------------------------------------------------------------------------------- /vi/v_status.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_status.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../common/common.h" 25 | #include "vi.h" 26 | 27 | /* 28 | * v_status -- ^G 29 | * Show the file status. 30 | * 31 | * PUBLIC: int v_status(SCR *, VICMD *); 32 | */ 33 | int 34 | v_status(SCR *sp, VICMD *vp) 35 | { 36 | (void)msgq_status(sp, vp->m_start.lno, MSTAT_SHOWLAST); 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /vi/v_xchar.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_xchar.c,v 1.8 2016/01/06 22:28:52 millert Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | #include "vi.h" 25 | 26 | /* 27 | * v_xchar -- [buffer] [count]x 28 | * Deletes the character(s) on which the cursor sits. 29 | * 30 | * PUBLIC: int v_xchar(SCR *, VICMD *); 31 | */ 32 | int 33 | v_xchar(SCR *sp, VICMD *vp) 34 | { 35 | size_t len; 36 | int isempty; 37 | 38 | if (db_eget(sp, vp->m_start.lno, NULL, &len, &isempty)) { 39 | if (isempty) 40 | goto nodel; 41 | return (1); 42 | } 43 | if (len == 0) { 44 | nodel: msgq(sp, M_BERR, "No characters to delete"); 45 | return (1); 46 | } 47 | 48 | /* 49 | * Delete from the cursor toward the end of line, w/o moving the 50 | * cursor. 51 | * 52 | * !!! 53 | * Note, "2x" at EOL isn't the same as "xx" because the left movement 54 | * of the cursor as part of the 'x' command isn't taken into account. 55 | * Historically correct. 56 | */ 57 | if (F_ISSET(vp, VC_C1SET)) 58 | vp->m_stop.cno += vp->count - 1; 59 | if (vp->m_stop.cno >= len - 1) { 60 | vp->m_stop.cno = len - 1; 61 | vp->m_final.cno = vp->m_start.cno ? vp->m_start.cno - 1 : 0; 62 | } else 63 | vp->m_final.cno = vp->m_start.cno; 64 | 65 | if (cut(sp, 66 | F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, 67 | &vp->m_start, &vp->m_stop, 0)) 68 | return (1); 69 | return (del(sp, &vp->m_start, &vp->m_stop, 0)); 70 | } 71 | 72 | /* 73 | * v_Xchar -- [buffer] [count]X 74 | * Deletes the character(s) immediately before the current cursor 75 | * position. 76 | * 77 | * PUBLIC: int v_Xchar(SCR *, VICMD *); 78 | */ 79 | int 80 | v_Xchar(SCR *sp, VICMD *vp) 81 | { 82 | unsigned long cnt; 83 | 84 | if (vp->m_start.cno == 0) { 85 | v_sol(sp); 86 | return (1); 87 | } 88 | 89 | cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; 90 | if (cnt >= vp->m_start.cno) 91 | vp->m_start.cno = 0; 92 | else 93 | vp->m_start.cno -= cnt; 94 | --vp->m_stop.cno; 95 | vp->m_final.cno = vp->m_start.cno; 96 | 97 | if (cut(sp, 98 | F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, 99 | &vp->m_start, &vp->m_stop, 0)) 100 | return (1); 101 | return (del(sp, &vp->m_start, &vp->m_stop, 0)); 102 | } 103 | -------------------------------------------------------------------------------- /vi/v_yank.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_yank.c,v 1.7 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | #include "vi.h" 25 | 26 | /* 27 | * v_yank -- [buffer][count]y[count][motion] 28 | * [buffer][count]Y 29 | * Yank text (or lines of text) into a cut buffer. 30 | * 31 | * !!! 32 | * Historic vi moved the cursor to the from MARK if it was before the current 33 | * cursor and on a different line, e.g., "yk" moves the cursor but "yj" and 34 | * "yl" do not. Unfortunately, it's too late to change this now. Matching 35 | * the historic semantics isn't easy. The line number was always changed and 36 | * column movement was usually relative. However, "y'a" moved the cursor to 37 | * the first non-blank of the line marked by a, while "y`a" moved the cursor 38 | * to the line and column marked by a. Hopefully, the motion component code 39 | * got it right... Unlike delete, we make no adjustments here. 40 | * 41 | * PUBLIC: int v_yank(SCR *, VICMD *); 42 | */ 43 | int 44 | v_yank(SCR *sp, VICMD *vp) 45 | { 46 | size_t len; 47 | 48 | if (cut(sp, 49 | F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, &vp->m_start, 50 | &vp->m_stop, F_ISSET(vp, VM_LMODE) ? CUT_LINEMODE : 0)) 51 | return (1); 52 | sp->rptlines[L_YANKED] += (vp->m_stop.lno - vp->m_start.lno) + 1; 53 | 54 | /* 55 | * One special correction, in case we've deleted the current line or 56 | * character. We check it here instead of checking in every command 57 | * that can be a motion component. 58 | */ 59 | if (db_get(sp, vp->m_final.lno, DBG_FATAL, NULL, &len)) 60 | return (1); 61 | 62 | /* 63 | * !!! 64 | * Cursor movements, other than those caused by a line mode command 65 | * moving to another line, historically reset the relative position. 66 | * 67 | * This currently matches the check made in v_delete(), I'm hoping 68 | * that they should be consistent... 69 | */ 70 | if (!F_ISSET(vp, VM_LMODE)) { 71 | F_CLR(vp, VM_RCM_MASK); 72 | F_SET(vp, VM_RCM_SET); 73 | 74 | /* Make sure the set cursor position exists. */ 75 | if (vp->m_final.cno >= len) 76 | vp->m_final.cno = len ? len - 1 : 0; 77 | } 78 | return (0); 79 | } 80 | -------------------------------------------------------------------------------- /vi/v_zexit.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: v_zexit.c,v 1.6 2014/11/12 04:28:41 bentley Exp $ */ 2 | 3 | /* SPDX-License-Identifier: BSD-3-Clause */ 4 | 5 | /* 6 | * Copyright (c) 1992, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 9 | * Keith Bostic. All rights reserved. 10 | * Copyright (c) 2022-2024 Jeffrey H. Johnson 11 | * 12 | * See the LICENSE.md file for redistribution information. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../common/common.h" 25 | #include "vi.h" 26 | 27 | /* 28 | * v_zexit -- ZZ 29 | * Save the file and exit. 30 | * 31 | * PUBLIC: int v_zexit(SCR *, VICMD *); 32 | */ 33 | int 34 | v_zexit(SCR *sp, VICMD *vp) 35 | { 36 | (void)sp; 37 | (void)vp; 38 | 39 | /* Write back any modifications. */ 40 | if (F_ISSET(sp->ep, F_MODIFIED) && 41 | file_write(sp, NULL, NULL, NULL, FS_ALL)) 42 | return (1); 43 | 44 | /* Check to make sure it's not a temporary file. */ 45 | if (file_m3(sp, 0)) 46 | return (1); 47 | 48 | /* Check for more files to edit. */ 49 | if (ex_ncheck(sp, 0)) 50 | return (1); 51 | 52 | F_SET(sp, SC_EXIT); 53 | return (0); 54 | } 55 | --------------------------------------------------------------------------------