├── Changes ├── LICENSE ├── Makefile.in ├── README ├── README.md ├── TODO ├── catd └── en_US ├── compat.c ├── config.h ├── configure ├── ex.1 ├── ex.c ├── ex.h ├── ex.spec ├── ex_addr.c ├── ex_argv.h ├── ex_cmds.c ├── ex_cmds2.c ├── ex_cmdsub.c ├── ex_data.c ├── ex_extern.c ├── ex_get.c ├── ex_io.c ├── ex_proto.h ├── ex_put.c ├── ex_re.c ├── ex_re.h ├── ex_set.c ├── ex_subr.c ├── ex_tagio.c ├── ex_temp.c ├── ex_temp.h ├── ex_tty.c ├── ex_tty.h ├── ex_tune.h ├── ex_unix.c ├── ex_v.c ├── ex_vadj.c ├── ex_vars.h ├── ex_version.c ├── ex_vget.c ├── ex_vis.h ├── ex_vmain.c ├── ex_voper.c ├── ex_vops.c ├── ex_vops2.c ├── ex_vops3.c ├── ex_vput.c ├── ex_vwind.c ├── expreserve.c ├── exrecover.c ├── libterm ├── Makefile ├── libterm.h ├── termcap.c ├── tgoto.c └── tputs.c ├── libuxre ├── COPYING.LGPL ├── CVS │ ├── Entries │ ├── Repository │ └── Root ├── Makefile ├── Makefile.mk ├── NOTES ├── _collelem.c ├── _collmult.c ├── bracket.c ├── colldata.h ├── onefile.c ├── re.h ├── regcomp.c ├── regdfa.c ├── regdfa.h ├── regerror.c ├── regex.h ├── regexec.c ├── regfree.c ├── regnfa.c ├── regparse.c ├── stubs.c └── wcharm.h ├── makeoptions ├── malloc.c ├── mapmalloc.c ├── pkginfo ├── printf.c ├── vi.1 ├── wvi └── wvi.1 /LICENSE: -------------------------------------------------------------------------------- 1 | This code contains changes by 2 | Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 3 | 4 | Conditions 1, 2, and 4 and the no-warranty notice below apply 5 | to these changes. 6 | 7 | Copyright (c) 1980, 1993 8 | The Regents of the University of California. 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 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 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 | 3. All advertising materials mentioning features or use of this software 19 | must display the following acknowledgement: 20 | This product includes software developed by the University of 21 | California, Berkeley and its contributors. 22 | 4. 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 | Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 40 | 41 | Redistribution and use in source and binary forms, with or without 42 | modification, are permitted provided that the following conditions 43 | are met: 44 | Redistributions of source code and documentation must retain the 45 | above copyright notice, this list of conditions and the following 46 | disclaimer. 47 | Redistributions in binary form must reproduce the above copyright 48 | notice, this list of conditions and the following disclaimer in the 49 | documentation and/or other materials provided with the distribution. 50 | All advertising materials mentioning features or use of this software 51 | must display the following acknowledgement: 52 | This product includes software developed or owned by Caldera 53 | International, Inc. 54 | Neither the name of Caldera International, Inc. nor the names of 55 | other contributors may be used to endorse or promote products 56 | derived from this software without specific prior written permission. 57 | 58 | USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 59 | INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 60 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 61 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 | ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 63 | LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 64 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 65 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 66 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 67 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 68 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 69 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 70 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome to the ex/vi port! 2 | ========================== 3 | 4 | This implementation is derived from ex/vi 3.7 of 6/7/85 and the BSD 5 | termcap library, originally from the 2.11BSD distribution. All of them 6 | were changed to compile and run on newer POSIX compatible Unix systems. 7 | Support for international character sets was added, including support 8 | for multibyte locales (based on UTF-8 or East Asian encodings), and some 9 | changes were made to get closer to the POSIX.2 guidelines for ex and 10 | vi. Some issues that were clearly bugs and not features have also been 11 | resolved; see the Changes file for details. 12 | 13 | The project homepage is currently at 14 | . 15 | 16 | 17 | How to build 18 | ============ 19 | 20 | First look at the Makefile and change the settings there to match your 21 | build environment. Explanations are provided directly in this file. 22 | 23 | You can tune the sizes of some internal buffers by editing config.h. 24 | 25 | Then type 26 | 27 | $ ./configure 28 | $ make 29 | $ su 30 | # make install 31 | # exit 32 | $ make mrproper 33 | 34 | The following systems have been reported to compile this code: 35 | 36 | Linux Kernel 2.0 and above; libc4, libc5, glibc 2.2 and above, 37 | diet libc, uClibc 38 | Sun Solaris 2.5.1 and above 39 | Caldera Open UNIX 8.0.0 40 | SCO UnixWare 7.1.1, 7.0.1, 2.1.2 41 | HP HP-UX B.11.23, B.11.11, B.11.00, B.10.20 42 | HP Tru64 UNIX 4.0G, 5.1B 43 | IBM AIX 5.1, 4.3 44 | NEC SUPER-UX 10.2 45 | NEC UX/4800 Release11.5 Rev.A 46 | Control Data EP/IX 2.2.1AA 47 | FreeBSD CURRENT (11.0+) 48 | NetBSD CURRENT (7.0+) 49 | DragonFlyBSD 1.3.7-DEVELOPMENT 50 | Mac OS X 10.4.3 51 | OpenBSD CURRENT (5.9+) 52 | 53 | Reports about other Unix systems are welcome, whether successful or not 54 | (in the latter case add a detailed description). This port of vi is only 55 | aimed at Unix, though, so I am not interested about results from running 56 | this software on Windows etc. 57 | 58 | Prerequisites for ports to other systems are: 59 | 60 | - The system must provide an ANSI C-89 compiler and POSIX.1-1990 functions. 61 | 62 | - The system must provide an sbrk() call to increase the memory heap size. 63 | If only a fake sbrk() call is provided that works by pre-allocating 64 | several MB, vi will probably work too. 65 | 66 | - The system library must allow replacement of malloc() and printf() by the 67 | versions provided by vi. For malloc(), it also must make its own internal 68 | memory requests using the vi malloc(). Otherwise, vi will likely die with 69 | a segmentation fault because the storage allocated by sbrk() interferes 70 | with usual Unix library implementations of malloc(). 71 | 72 | The last two requirements could probably be eliminated with some effort, but 73 | it would not result in any real improvements for usual the Unix platforms vi 74 | is targeted at, so it has not be done yet. 75 | 76 | 77 | Terminal capabilities 78 | ===================== 79 | 80 | vi normally uses the termcap library to gather information about the 81 | capabilities of the terminal it is using. A BSD-derived termcap library 82 | is included with the vi distribution, and is usually the preferred choice. 83 | On some platforms, though, either no /etc/termcap file exists, or the file 84 | lacks up-to-date entries. In these cases, two workarounds are possible. 85 | First, vi can be linked against libcurses, libncurses, or libtermcap, if 86 | these provide access to a proper terminal information database. Second, it 87 | is possible to use the included termcap library with a TERMCAP environment 88 | variable that contains a complete termcap entry. Most terminals in current 89 | use provide a superset of DEC VT102 capabilities, so the following will 90 | normally work: 91 | 92 | TERMCAP="vt102|$TERM|dec vt102:"'\ 93 | :do=^J:co#80:li#24:cl=50\E[;H\E[2J:\ 94 | :le=^H:bs:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\ 95 | :ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\ 96 | :md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H:\ 97 | :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\ 98 | :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\ 99 | :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=5\EM:vt#3:\ 100 | :sc=\E7:rc=\E8:cs=\E[%i%d;%dr:vs=\E[?7l:ve=\E[?7h:\ 101 | :mi:al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:' 102 | export TERMCAP 103 | 104 | 105 | Multibyte locale support 106 | ======================== 107 | 108 | Support for multibyte locales has been added to vi. It requires a number of 109 | functions that, while specified in XPG6, are not present on all systems that 110 | provide basic multibyte support. In particular, vi needs wcwidth() to 111 | determine the visual width of a character, and mbrtowc() to detect when a 112 | byte sequence that is entered at the terminal has been completed. 113 | 114 | The multibyte code is known to work on the following systems: 115 | 116 | Linux glibc 2.2.2 and later 117 | Sun Solaris 9 and later 118 | HP HP-UX B.11.11 and later 119 | FreeBSD 5.3 120 | NetBSD 2.0 121 | 122 | It has been tested on xterm patch #192, rxvt-unicode 4.2, mlterm 2.9.1, 123 | xiterm 0.5, and gnome-terminal 2.10.0. 124 | 125 | Successful operation is known for the following encodings: UTF-8, EUC-JP, 126 | EUC-KR, Big5, Big5-HKSCS, GB 2312, GBK. vi does not support locking-shift 127 | encodings like those that use ISO 2022 escape sequences. It also requires 128 | that the first byte of any multibyte character has the highest bit set. 129 | This excludes 7-bit encodings like UTF-7, and encodings whose sequences 130 | start with ASCII characters like TCVN 5712. 131 | 132 | To use UTF-8 locales in ex mode, the terminal should be put in 'stty iutf8' 133 | mode on Linux if it does not perform this automatically. Otherwise, typing 134 | the erase key once after entering a multibyte character will result in an 135 | incomplete byte sequence. 136 | 137 | 138 | Gunnar Ritter 01/12/07 139 | Freiburg i. Br. 140 | Germany 141 | 142 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The traditional Vi 2 | This implementation had been derived by Gunnar Ritter 3 | from ex/vi 3.7 of 6/7/85 and the BSD 4 | termcap library, originally from the 2.11BSD distribution. 5 | He had added some useful enhancements, 6 | most notably UTF-8 support. 7 | 8 | The last release of *heirloom-ex-vi* had been 9 | version 050325 (4.0). 10 | Until 2007 he added new features, e.g. 11 | dynamically allocated screen buffers for resizing the terminal 12 | and support for files with arbitrary line length. 13 | 14 | These changes did introduce an issue to numbered lines mode. 15 | This and other found bugs are fixed now. 16 | A simple `./configure` had been added to set curses 17 | as the terminal capabilities access library 18 | on some systems. 19 | ## How to install 20 | The embedded termcap library may cause problems on systems where 21 | there is no `/etc/termcap` and `$TERMCAP` of the user that runs 22 | `./configure` and other users (e.g. `root`) differs. 23 | Therefore using termcap has lowest priority during auto-configure. 24 | To prefere termcap put the corresponding line before the curses 25 | entries in 26 | [configure](https://github.com/n-t-roff/heirloom-ex-vi/blob/master/configure). 27 | ``` 28 | $ ./configure 29 | $ make 30 | $ su 31 | # make install 32 | # exit 33 | $ make mrproper 34 | ``` 35 | ## Usage information 36 | The traditional `vi` reads the file `~/.exrc` at start-up. 37 | For full screen scrolling `vi` uses the keys `^F` and `^B`. 38 | To make <PAGE-DOWN> and <PAGE-UP> work add the following 39 | lines to `.exrc`: 40 | ``` 41 | map ^[[5~ ^B 42 | map ^[[6~ ^F 43 | ``` 44 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO list for ex 2 | 3 | - Some support for UTF-8 combining characters should probably be added. 4 | 5 | - Since the POSIX standard developers did not include a method to 6 | determine whether something is a valid collation symbol or an 7 | equivalence class, and since there is no access to the basic 8 | collation sequence, LC_COLLATE locales are completely ignored. 9 | 10 | - SVr4 ex probably has some silent features that this one should have too. 11 | 12 | Gunnar Ritter 2/19/05 13 | -------------------------------------------------------------------------------- /catd/en_US: -------------------------------------------------------------------------------- 1 | $ Message catalogue for ex/vi 2 | $ Sccsid @(#)en_US 1.4 (gritter) 3/18/03 3 | $quote " 4 | $set 1 5 | 1 "Usage: %s [- | -s] [-l] [-L] [-R] [-r [file]] [-t tag]\n\ 6 | [-v] [-V] [-w size] [+cmd | -c cmd] file...\n" 7 | 2 "%s: option requires an argument -- %c\n" 8 | 3 "%s: illegal option -- %c\n" 9 | 4 "Trace create error\n" 10 | 5 "Unknown option %s\n" 11 | 6 "Addr1 > addr2|First address exceeds second" 12 | 7 "Bad count|Nonzero count required" 13 | 8 "No address allowed@on this command" 14 | 9 "Badly formed address" 15 | 10 "No match to BOTTOM|Address search hit BOTTOM without matching pattern" 16 | 11 "No match to TOP|Address search hit TOP without matching pattern" 17 | 12 "Fail|Pattern not found" 18 | 13 "Marks are ' and a-z" 19 | 14 "Undefined mark@referenced" 20 | 15 "Negative address@- first buffer line is 1" 21 | 16 "Not that many lines@in buffer" 22 | 17 "Offset out-of-bounds|Offset after command too large" 23 | 18 "Home directory unknown" 24 | 19 "Mark what?|%s requires following letter" 25 | 20 "Bad mark|Mark must specify a letter" 26 | 21 "Preserve failed!" 27 | 22 "File preserved." 28 | 23 "No write@since last change (:rewind! overrides)" 29 | 24 "Old tty driver|Not using new tty driver/shell" 30 | 25 "Bad register" 31 | 26 "At EOF|At end-of-file" 32 | 27 "What?|Unknown command character '%c'" 33 | 28 "Extra chars|Extra characters at end of command" 34 | 29 " [Warning - %s is incomplete]" 35 | 30 "%d files@to edit" 36 | 31 "No more files@to edit" 37 | $quote 38 | 32 Extra chars|Extra characters at end of "%s" command 39 | $quote " 40 | 33 "%d more file" 41 | 34 "%s@to edit" 42 | 35 "No write@since last change (:%s! overrides)" 43 | 36 "What?|%s: No such command from open/visual" 44 | 37 "What?|%s: Not an editor command" 45 | 38 "[Hit return to continue] " 46 | 39 "Out of memory@- too many lines in file" 47 | 40 "Line overflow|Result line of join would be too long" 48 | 41 "That move would do nothing!" 49 | 42 "Move to a moved line" 50 | 43 "%s where?|%s requires a trailing address" 51 | 44 "Cannot put inside global/macro" 52 | 45 "Line too long|Result line after shift would be too long" 53 | 46 "Bad tag|Give one tag per line" 54 | 47 "No previous tag" 55 | 48 "%s: Bad tags file entry" 56 | 49 "No write@since last change (:tag! overrides)" 57 | 50 "No tags file" 58 | 51 "%s: No such tag@in tags file" 59 | 52 "Can't yank inside global/macro" 60 | 53 "\nAt EOF" 61 | 54 "At EOF" 62 | 55 "Hit BOTTOM" 63 | 56 "Hit TOP" 64 | 57 "Nothing to undo" 65 | 58 "Nothing changed|Last undoable command didn't change anything" 66 | 59 "Can't undo in global@commands" 67 | 60 "Missing lhs" 68 | 61 "Missing rhs" 69 | 62 "Missing rhs" 70 | 63 "No tail recursion" 71 | 64 "Too dangerous to map that" 72 | 65 "No tail recursion" 73 | 66 "Missing lhs" 74 | 67 "Not mapped|That macro wasn't mapped" 75 | 68 "Too many macros" 76 | 69 "Too much macro text" 77 | 70 "^H discarded\n" 78 | 71 "Input line too long" 79 | 72 "No file|No current filename" 80 | 73 " [Read only]" 81 | 74 " [Not edited]" 82 | 75 " [Modified]" 83 | 76 "No file " 84 | 77 " line %d of %d --%ld%%--" 85 | 78 "Pattern too long" 86 | 79 "Argument buffer overflow" 87 | 80 "No alternate filename@to substitute for #" 88 | 81 "No current filename@to substitute for %%" 89 | 82 "Can't make pipe to glob" 90 | 83 "Can't fork to do glob" 91 | 84 "Arg list too long" 92 | 85 "Arg list too long" 93 | 86 "No match" 94 | 87 "Missing filename" 95 | 88 "Ambiguous|Too many file names" 96 | 89 "Filename too long" 97 | 90 " [New file]" 98 | 91 " Block special file" 99 | 92 " Teletype" 100 | 93 " Character special file" 101 | 94 " Directory" 102 | 95 " Socket" 103 | 96 " Named pipe" 104 | 97 " Executable" 105 | 98 " Compressed Data" 106 | 99 " ELF object" 107 | 100 " Archive" 108 | 101 " Non-ascii file" 109 | 102 " [Read only]" 110 | 103 " %d/%d" 111 | 104 " %d line%s, %d character%s" 112 | 105 " (" 113 | 106 "%d null" 114 | 107 ", " 115 | 108 "%d non-ASCII" 116 | 109 "Write forms are 'w' and 'w>>'" 117 | 110 "No file|No current filename" 118 | $quote # 119 | 111 # File exists| File exists - use "w! %s" to overwrite# 120 | $quote " 121 | 112 " File is read only" 122 | 113 " File is read only" 123 | $quote # 124 | 114 # Use "w!" to write partial buffer# 125 | $quote " 126 | 115 " [New file]" 127 | 116 " [Existing file]" 128 | 117 " [Incomplete last line]" 129 | 118 " Line too long" 130 | 119 "Too many nested sources" 131 | 120 "Open and visual must be used interactively" 132 | 121 "Global within global@not allowed" 133 | 122 "Global needs re|Missing regular expression for global" 134 | 123 "Global command too long" 135 | 124 "substitution loop" 136 | 125 "Fail|Substitute pattern match failed" 137 | 126 "Substitute needs re|Missing regular expression for substitute" 138 | 127 "No previous re|No previous regular expression" 139 | 128 "No previous substitute re|No previous substitute to repeat" 140 | 129 "Replacement pattern too long@- limit 256 characters" 141 | 130 "Line overflow@in substitute" 142 | 131 "%d subs|%d substitutions" 143 | 132 " on %d lines" 144 | 133 "Regular expressions cannot be delimited by letters or digits" 145 | 134 "No previous scan re|No previous scanning regular expression" 146 | 135 "No previous substitute re|No previous substitute regular expression" 147 | 136 "Badly formed re|Regular expression \\ must be followed by / or ?" 148 | 137 "No previous re|No previous regular expression" 149 | 138 "Missing closing delimiter@for regular expression" 150 | 139 "Re too complex|Regular expression too complicated" 151 | 140 "Unmatched \\(|More \\('s than \\)'s in regular expression" 152 | 141 "Awash in \\('s!|Too many \\('d subexressions in a regular expression" 153 | 142 "Extra \\)|More \\)'s than \\('s in regular expression" 154 | 143 "Bad number|Bad number in regular expression" 155 | 144 "Range endpoint too large|Range endpoint too large in regular expression" 156 | 145 "More than 2 numbers given in \\{~\\}" 157 | 146 "} expected after \\" 158 | 147 "First number exceeds second in \\{~\\}" 159 | $quote 160 | 148 "\\digit" out of range 161 | $quote " 162 | 149 "Replacement pattern contains &@- cannot use in re" 163 | 150 "Replacement pattern contains \\d@- cannot use in re" 164 | 151 "Illegal *|Can't * a \\( ... \\) in regular expression") 165 | 152 "Illegal *|Can't * a \\n in regular expression" 166 | 153 "Bad character class|Empty character class '[]' or '[^]' cannot match" 167 | 154 "Missing ]" 168 | 155 "No newlines in re's|Can't escape newlines into regular expressions" 169 | 156 "Bad \\n|\\n in regular expression with n greater than the number of \\('s" 170 | 157 "Badly formed re|Missing closing delimiter for regular expression" 171 | 158 "Re internal error" 172 | 159 "%s: No such option@- 'set all' gives all option values" 173 | 160 "Option %s is not a toggle" 174 | 161 "Missing =@in assignment to option %s" 175 | 162 "Digits required@after =" 176 | 163 "String too long@in option assignment" 177 | 164 "Can't change type of terminal from within open/visual" 178 | 165 "%s%s" 179 | 166 "" 180 | 167 "no" 181 | 168 "%s=%d" 182 | 169 "%s=%s" 183 | 170 "%d lines" 184 | 171 " %c%s" 185 | 172 "Nonzero address required@on this command" 186 | 173 "No lines@in the buffer" 187 | 174 "more " 188 | 175 "fewer " 189 | 176 "" 190 | 177 "%d %slines@in file after %s" 191 | 178 "" 192 | 179 "s" 193 | 180 "Out of memory@saving lines for undo - try using ed" 194 | 181 "emt trap, _ovno is %d @ - try again" 195 | 182 "\nInterrupt" 196 | 183 " Tmp file too large" 197 | 184 " Tmp file too large" 198 | 185 " Tmp file too large" 199 | 186 "Out of register space (ugh)" 200 | 187 "Nothing in register %c" 201 | 188 "Can't put partial line inside macro" 202 | 189 "Nothing in register %c" 203 | 190 "Register too long@to fit in memory" 204 | 191 "%s: Unknown terminal type" 205 | 192 "Incomplete shell escape command@- use 'shell' to get a shell" 206 | 193 "Command too long" 207 | 194 "No previous command@to substitute for !" 208 | 195 "No alternate filename@to substitute for #" 209 | 196 "No filename@to substitute for %%" 210 | 197 "[No write]|[No write since last change]" 211 | 198 "No previous command@to repeat" 212 | 199 "Can't make pipe for filter" 213 | 200 "No more processes" 214 | 201 "No %s!\n" 215 | 202 "Can't make pipe" 216 | 203 "No more processes" 217 | 204 " Can't make pipe for recovery" 218 | 205 " Can't fork to execute recovery" 219 | 206 " No recovery routine" 220 | 207 "Fail|Pattern not found on addressed line" 221 | 208 "Can't use open/visual unless open option is set" 222 | 209 "Recursive open/visual not allowed" 223 | 210 "[Using open mode]" 224 | 211 "Visual needs addressible cursor or upline capability" 225 | 212 Can't use visual on a terminal which overstrikes" 226 | 213 "Visual requires clear screen capability" 227 | 214 "Visual requires scrolling" 228 | 215 "Screen too large for internal buffer" 229 | 216 "Don't know enough about your terminal to use %s" 230 | 217 "Terminal too wide" 231 | 218 "Screen too large" 232 | 219 "Internal error: vscroll" 233 | 220 "No lines in buffer" 234 | 221 "Internal error: vredraw" 235 | 222 "Input read error" 236 | 223 "%d %sline" 237 | 224 "Macro too long@ - maybe recursive?" 238 | 225 "Infinite macro loop" 239 | 226 "Q gets ex command mode, :q leaves vi" 240 | 227 " " 241 | 228 "AAPPEND MODE" 242 | 229 "CCHANGE MODE" 243 | 230 "OOPEN MODE" 244 | 231 "RREPLACE MODE" 245 | 232 "rREPLACE 1 CHAR" 246 | 233 "IINSERT MODE" 247 | 234 "Infinite macro loop" 248 | 235 "Line too long" 249 | 236 "Line too long" 250 | 237 "Internal error: vclreol" 251 | 238 "Internal error: vgoto" 252 | 239 "Line too long for open" 253 | 240 "Line too long" 254 | 241 "No memory pool" 255 | 242 "Memory pool exhausted" 256 | 243 "failed to memory map anonymous area" 257 | 244 "failed to open /dev/zero" 258 | 245 "failed to memory map /dev/zero" 259 | 246 "chunk of memory already in free list" 260 | 247 "out of memory" 261 | 248 "(null pointer)" 262 | 249 "y" 263 | $ exrecover 264 | $set 2 265 | 1 " Wrong number of arguments to exrecover" 266 | 2 " [Dated: %s" 267 | 3 ", newest of %d saved]" 268 | 4 "]" 269 | 5 " Not enough core for lines" 270 | 6 "No files saved.\n" 271 | 7 "On %s at " 272 | $quote # 273 | 8 # saved %d lines of file "%s"\n# 274 | $quote " 275 | 9 " File not found" 276 | 10 " [Lost line(s):" 277 | 11 " %d" 278 | 12 "-%d" 279 | 13 " [Lost line(s):" 280 | 14 " %d" 281 | 15 "-%d" 282 | 16 "]" 283 | 17 " Tmp file too large" 284 | $ expreserve 285 | $set 3 286 | 1 "NOT super user\n" 287 | 2 "the system went down" 288 | 3 "the editor was killed" 289 | 4 "Subject: editor saved ``LOST''\n" 290 | 5 "You were editing a file without a name\n" 291 | 6 "at <%s> on the machine ``%s'' when %s.\n" 292 | $quote # 293 | 7 #Since the file had no name, it has been named "LOST".\n# 294 | $quote " 295 | 8 "Subject: editor saved ``%s''\n" 296 | $quote # 297 | 9 #You were editing the file "%s"\n# 298 | $quote " 299 | 10 "at <%s> on the machine ``%s''\n" 300 | 11 "when %s.\n" 301 | 12 "\nYou can retrieve most of your changes to this file\n" 302 | $quote # 303 | 13 #using the "recover" command of the editor.\n# 304 | 14 #An easy way to do this is to give the command "vi -r %s".\n# 305 | 15 #This method also works using "ex" and "edit".\n# 306 | $quote " 307 | 16 "Buffer format error\t" 308 | 17 "Buffer read error" 309 | 18 "Can't find a name\t" 310 | -------------------------------------------------------------------------------- /compat.c: -------------------------------------------------------------------------------- 1 | /* Carsten Kunze, 2016 */ 2 | 3 | #include 4 | 5 | #ifndef HAVE_STRLCPY 6 | size_t 7 | strlcpy(char *dst, const char *src, size_t dstsize) { 8 | size_t srcsize; 9 | /* Not conform to strlcpy, but avoids to access illegal memory in case 10 | * of unterminated strings */ 11 | for (srcsize = 0; srcsize < dstsize; srcsize++) 12 | if (!src[srcsize]) 13 | break; 14 | if (dstsize > srcsize) 15 | dstsize = srcsize; 16 | else if (dstsize) 17 | dstsize--; 18 | if (dstsize) 19 | /* assumes non-overlapping buffers */ 20 | memcpy(dst, src, dstsize); 21 | dst[dstsize] = 0; 22 | return srcsize; 23 | } 24 | #endif 25 | 26 | #ifndef HAVE_STRLCAT 27 | size_t 28 | strlcat(char *dst, const char *src, size_t dstsize) { 29 | size_t ld, ls; 30 | for (ld = 0; ld < dstsize - 1; ld++) 31 | if (!dst[ld]) 32 | break; 33 | dst += ld; 34 | dstsize -= ld; 35 | for (ls = 0; ls < dstsize; ls++) 36 | if (!src[ls]) 37 | break; 38 | if (dstsize > ls) 39 | dstsize = ls; 40 | else if (dstsize) 41 | dstsize--; 42 | if (dstsize) 43 | memcpy(dst, src, dstsize); 44 | dst[dstsize] = 0; 45 | return ld + ls; 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | * 73 | * @(#)config.h 1.13 (gritter) 8/4/05 74 | */ 75 | 76 | /* 77 | * Configurable settings for the ex editor. 78 | */ 79 | 80 | /* 81 | * Various buffer sizes. 82 | */ 83 | #ifndef VMUNIX 84 | #define ESIZE 128 /* Regular expression buffer size */ 85 | #define RHSSIZE 256 /* Size of rhs of substitute */ 86 | #define TAGSIZE 128 /* Tag length */ 87 | #define ONMSZ 64 /* Option name size */ 88 | #else /* VMUNIX */ 89 | #define ESIZE 1024 90 | #define RHSSIZE 512 91 | #define TAGSIZE 256 92 | #define ONMSZ 256 93 | #endif /* VMUNIX */ 94 | 95 | /* 96 | * The following types are usually predefined on modern platforms; it 97 | * is only necessary to define them manually if compilation errors occur. 98 | */ 99 | 100 | /* 101 | * The intptr_t type was introduced by SUSv2 and C99. It is a signed 102 | * integer type capable of holding pointers: 103 | * 104 | * sizeof(intptr_t) == sizeof(void *). 105 | * 106 | * Type Environment Typical systems 107 | * int IP16 PDP11, 80286 108 | * int ILP32 Most VAX, M68k, IA32, SPARC 109 | * long LP32 Some IA32 and M68k 110 | * long LP64 64 bit mode of IA64, SPARC v9, and Alpha 111 | * 112 | * The argument to the sbrk() system call has this type. 113 | */ 114 | #ifdef notdef 115 | typedef int intptr_t; 116 | #endif 117 | 118 | /* 119 | * The ssize_t type should be the same as the return type of read() 120 | * and write(). 121 | */ 122 | #ifdef notdef 123 | typedef int ssize_t; 124 | #endif 125 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2016-2018, Carsten Kunze 4 | # 5 | # Permission to use, copy, modify, and/or distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14 | # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | # PERFORMANCE OF THIS SOFTWARE. 16 | 17 | usage () { 18 | echo "Usage: $0 [-s] [-D ...]" 19 | echo " -s Silence output" 20 | echo " -D" 21 | echo " Add define to CFLAGS" 22 | exit $1 23 | } 24 | 25 | SFLAG= 26 | MAKE= 27 | DEFS= 28 | LIB_LEX= 29 | LIB_CURSES= 30 | cat /dev/null > compat.h 31 | 32 | while [ $# -gt 0 ]; do 33 | case $1 in 34 | -s) 35 | SFLAG=1 36 | ;; 37 | -D*) 38 | DEFS="$DEFS $1" 39 | ;; 40 | *) 41 | echo "$0: $1: Unknown option" >&2 42 | usage 1 43 | ;; 44 | esac 45 | shift 46 | done 47 | 48 | check_for () { 49 | [ -e $LOG ] && cat <>$LOG 50 | 51 | ================================================================================ 52 | 53 | EOT 54 | A="Checking for $1 ... " 55 | printf "$A\n\n" >>$LOG 56 | [ -z "$SFLAG" ] && printf "$A" 57 | } 58 | 59 | compile () { 60 | rm -f ${TMPNAM}.o $TMPNAM $OUT $ERR 61 | $MAKE -f $OUTMK $TMPNAM > $OUT 2> $ERR 62 | RESULT=$? 63 | cat $OUT $ERR >> $LOG 64 | if [ $RESULT -eq 0 ]; then true; else false; fi 65 | } 66 | 67 | test_result () { 68 | RESULT=$? 69 | RESULT_TEXT=${1:-0} # 1: omit "no", 2: say nothing 70 | if [ $RESULT -eq 0 ]; then 71 | echo success >>$LOG 72 | [ -z "$SFLAG" -a $RESULT_TEXT -lt 2 ] && \ 73 | echo "yes$PASS_TEXT" 74 | PASS_TEXT= 75 | [ -e $TMPC ] && rm -f $TMPC 76 | true 77 | else 78 | [ -z "$SFLAG" -a $RESULT_TEXT -lt 1 ] && echo no 79 | if [ -e $TMPC ]; then 80 | echo "Failed program:" >>$LOG 81 | pr -n -t $TMPC >>$LOG 82 | rm -f $TMPC 83 | fi 84 | false 85 | fi 86 | } 87 | 88 | gen_mk () { 89 | [ $# -eq 0 ] && rm -f $OUTMK 90 | [ -n "$LEX" ] && echo "LEX=$LEX" >> $OUTMK 91 | [ -n "$FLOAT_STORE" ] && echo "FLOAT_STORE=$FLOAT_STORE" >> $OUTMK 92 | [ -n "$DEFS" ] && echo "DEFINES=$DEFS" >> $OUTMK 93 | [ -n "$INCDIR_CURSES" ] && echo "INCDIR_CURSES=$INCDIR_CURSES" >> $OUTMK 94 | [ -n "$RPATH_CURSES" ] && echo "RPATH_CURSES=$RPATH_CURSES" >> $OUTMK 95 | [ -n "$LIBDIR_CURSES" ] && echo "LIBDIR_CURSES=$LIBDIR_CURSES" \ 96 | >> $OUTMK 97 | [ -n "$LIB_CURSES" ] && echo "LIB_CURSES=$LIB_CURSES" >> $OUTMK 98 | [ -n "$LIB_AVLBST" ] && echo "LIB_AVLBST=$LIB_AVLBST" >> $OUTMK 99 | [ -n "$LIB_LEX" ] && echo "LIB_LEX=$LIB_LEX" >> $OUTMK 100 | [ -n "$__CDBG" ] && echo "__CDBG=$__CDBG" >> $OUTMK 101 | [ -n "$__CXXDBG" ] && echo "__CXXDBG=$__CXXDBG" >> $OUTMK 102 | [ -n "$__CLDBG" ] && echo "__CLDBG=$__CLDBG" >> $OUTMK 103 | [ -n "$__CLXXDBG" ] && echo "__CLXXDBG=$__CLXXDBG" >> $OUTMK 104 | cat $INMK >> $OUTMK || exit 1 105 | } 106 | check_make () { 107 | check_for "make(1)" 108 | 109 | cat <$TMPMK 110 | all: 111 | true 112 | EOT 113 | make -f $TMPMK >> $LOG 2>&1 114 | test_result && { 115 | MAKE=make 116 | return 117 | } 118 | 119 | echo "Failed makefile:" >>$LOG 120 | pr -n -t $TMPMK >>$LOG 121 | 122 | check_for "bmake(1)" 123 | 124 | cat <$TMPMK 125 | all: 126 | true 127 | EOT 128 | bmake -f $TMPMK >> $LOG 2>&1 129 | test_result && MAKE=bmake 130 | } 131 | check_strlcpy () { 132 | check_for "strlcpy(3)" 133 | 134 | cat <$TMPC 135 | #include 136 | int 137 | main(int argc, char **argv) { 138 | char a[10]; 139 | (void)argc; 140 | strlcpy(a, *argv, sizeof a); 141 | return 0; 142 | } 143 | EOT 144 | compile 145 | if test_result; then 146 | DEFS="$DEFS -DHAVE_STRLCPY" 147 | else 148 | H=compat.h 149 | grep -q '' $H 2>/dev/null || cat <>$H 150 | #include 151 | EOT 152 | cat <>$H 153 | size_t strlcpy(char *, const char *, size_t); 154 | EOT 155 | fi 156 | } 157 | check_strlcat () { 158 | check_for "strlcat(3)" 159 | 160 | cat <$TMPC 161 | #include 162 | int 163 | main(int argc, char **argv) { 164 | char a[10]; 165 | (void)argc; 166 | *a = 0; 167 | strlcat(a, *argv, sizeof a); 168 | return 0; 169 | } 170 | EOT 171 | compile 172 | if test_result; then 173 | DEFS="$DEFS -DHAVE_STRLCAT" 174 | else 175 | H=compat.h 176 | grep -q '' $H 2>/dev/null || cat <>$H 177 | #include 178 | EOT 179 | cat <>$H 180 | size_t strlcat(char *, const char *, size_t); 181 | EOT 182 | fi 183 | } 184 | check_Sanitizer () { 185 | check_for "CC Sanitizer" 186 | 187 | # C only 188 | __CDBG= 189 | __CLDBG= 190 | __CCXXDBG= 191 | # C++ only 192 | __CXXDBG= 193 | __CLXXDBG= 194 | __CDBG="$__CDBG -Wmissing-prototypes" 195 | __CDBG="$__CDBG -Wstrict-prototypes" 196 | __CCXXDBG="$__CCXXDBG -g -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls" 197 | __CCXXDBG="$__CCXXDBG -Wall" 198 | __CCXXDBG="$__CCXXDBG -Wextra" 199 | __CCXXDBG="$__CCXXDBG -Wbad-function-cast" 200 | __CCXXDBG="$__CCXXDBG -Wcast-align" 201 | __CCXXDBG="$__CCXXDBG -Wcast-qual" 202 | #__CCXXDBG="$__CCXXDBG -Wconversion" 203 | __CCXXDBG="$__CCXXDBG -Wfloat-equal" 204 | __CCXXDBG="$__CCXXDBG -Wlogical-not-parentheses" 205 | __CCXXDBG="$__CCXXDBG -Wshadow" 206 | __CCXXDBG="$__CCXXDBG -Wsign-compare" 207 | __CCXXDBG="$__CCXXDBG -Wundef" 208 | __CCXXDBG="$__CCXXDBG -Wuninitialized" 209 | __CCXXDBG="$__CCXXDBG -Wunused-parameter" 210 | __CCXXDBG="$__CCXXDBG -Wunused-function" 211 | __CCXXDBG="$__CCXXDBG -Wwrite-strings" 212 | __CLXXDBG="$__CLXXDBG -fno-common -fsanitize=address -fsanitize=undefined" 213 | #__CLXXDBG="$__CLXXDBG -fsanitize-recover=all" 214 | 215 | [ -n "$CC" ] || CC=cc 216 | VER=`$CC --version` 217 | 218 | if echo $VER | grep -iq gcc || echo $VER | \ 219 | grep -iq 'Free Software Foundation'; then 220 | [ -z "$SFLAG" ] && printf "(gcc) " 221 | #__CCXXDBG="$__CCXXDBG -Wduplicated-branches" 222 | __CCXXDBG="$__CCXXDBG -Wduplicated-cond" 223 | __CCXXDBG="$__CCXXDBG -Wjump-misses-init" 224 | __CCXXDBG="$__CCXXDBG -Wlogical-op" 225 | #__CLXXDBG="$__CLXXDBG -fprofile-arcs -ftest-coverage" 226 | __CLXXDBG="$__CLXXDBG -fsanitize=float-divide-by-zero" 227 | __CLXXDBG="$__CLXXDBG -fsanitize=float-cast-overflow" 228 | elif echo $VER | grep -q clang; then 229 | [ -z "$SFLAG" ] && printf "(clang) " 230 | __CCXXDBG="$__CCXXDBG -Wincompatible-pointer-types-discards-qualifiers" 231 | __CCXXDBG="$__CCXXDBG -Wmissing-variable-declarations" 232 | __CXXDBG="$__CXXDBG -Wunused-private-field" 233 | __CLXXDBG="$__CLXXDBG -fsanitize=unsigned-integer-overflow" 234 | else 235 | [ -z "$SFLAG" ] && echo "Unknown compiler" 236 | return 237 | fi 238 | 239 | # Most C++ options can be used for C too 240 | __CDBG="$__CDBG $__CCXXDBG" 241 | __CLDBG="$__CLDBG $__CLXXDBG" 242 | __CXXDBG="$__CXXDBG $__CCXXDBG" 243 | cat <$TMPC 244 | int 245 | main() { 246 | return 0; 247 | } 248 | EOT 249 | gen_mk 250 | cat <>$OUTMK 251 | $TMPNAM: ${TMPNAM}.o 252 | \$(CC) \$(__CDBG) \$(__CLDBG) -o \$@ ${TMPNAM}.o 253 | EOT 254 | compile 255 | test_result || { 256 | __CLDBG= 257 | __CLXXDBG= 258 | } 259 | } 260 | [ ! -s compat.h ] && rm compat.h 261 | OUTMK=Makefile 262 | INMK=${OUTMK}.in 263 | CFG=config 264 | TMPNAM=.$CFG 265 | TMPMK=${TMPNAM}.mk 266 | TMPC=${TMPNAM}.c 267 | TMPL=${TMPNAM}.l # For lex tests only ... 268 | OUT=${TMPNAM}.out 269 | ERR=${TMPNAM}.err 270 | LOG=${CFG}.log 271 | rm -f $LOG 272 | gen_mk 273 | 274 | check_make 275 | check_strlcpy 276 | check_strlcat 277 | #check_Sanitizer 278 | 279 | __CLDBG=`echo $__CLDBG | sed 's/-fsanitize=address//'` 280 | __CLXXDBG=`echo $__CLXXDBG | sed 's/-fsanitize=address//'` 281 | 282 | TermTest () { 283 | check_for "$1" 284 | Term="$1" 285 | echo "TERMLIB=$1" > $OUTMK 286 | gen_mk 1 287 | cat <>$OUTMK 288 | $TMPNAM: ${TMPNAM}.o \$(TLIB) 289 | \$(CC) \$(WARN) \$(DEFINES) -o \$@ ${TMPNAM}.o \$(TERMLIB) 290 | EOT 291 | cat <>$TMPC 292 | #include 293 | int tgetent(char *, const char *); 294 | int main() { 295 | char tcbuf[2048]; 296 | char *terms[] = { "xterm", "screen" }; 297 | unsigned i; 298 | for (i = 0; i < sizeof(terms)/sizeof(*terms); i++) 299 | if (tgetent(tcbuf, terms[i]) != 1) { 300 | fprintf(stderr, "Unknown terminal type \"%s\"\n", 301 | terms[i]); 302 | return i + 1; 303 | } 304 | return 0; 305 | } 306 | EOT 307 | compile 308 | test_result 2 && ./$TMPNAM 2>> $LOG && { 309 | echo yes 310 | return 311 | } 312 | echo no 313 | false 314 | } 315 | 316 | TestLocalTermlib () { 317 | #TermTest "-Llibterm -ltermlib" && return 318 | TermTest "-ltinfo" && return 319 | TermTest "-lncurses" && return 320 | ODEFS=$DEFS 321 | D="-I/usr/pkg/include -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib" 322 | DEFS="$DEFS $D" 323 | TermTest "-lncurses $D" && return 324 | DEFS=$ODEFS 325 | TermTest "-lcurses" && return 326 | TermTest "-Llibterm -ltermlib" && return 327 | } 328 | 329 | TestLocalTermlib 330 | 331 | echo "TERMLIB=$Term" > $OUTMK 332 | gen_mk 1 333 | rm -f $TMPNAM* 334 | -------------------------------------------------------------------------------- /ex.spec: -------------------------------------------------------------------------------- 1 | # 2 | # Sccsid @(#)ex.spec 1.8 (gritter) 7/12/05 3 | # 4 | Summary: A port of the traditional ex/vi editors 5 | Name: ex 6 | Version: 040420 7 | Release: 1 8 | License: BSD 9 | Source: %{name}-%{version}.tar.bz2 10 | Group: System Environment/Base 11 | Vendor: Gunnar Ritter 12 | URL: 13 | BuildRoot: %{_tmppath}/%{name}-root 14 | 15 | Requires: /etc/termcap 16 | 17 | # prefix applies to bindir, libexecdir, and mandir. 18 | %define prefix /usr 19 | %define bindir %{prefix}/5bin 20 | %define libexecdir %{prefix}/5lib 21 | %define mandir %{prefix}/share/man/5man 22 | 23 | %define preservedir /var/preserve 24 | 25 | # install command 26 | %define ucbinstall install 27 | 28 | %define cflags -Os -fomit-frame-pointer 29 | 30 | %define makeflags PREFIX=%{prefix} BINDIR=%{bindir} LIBEXECDIR=%{libexecdir} MANDIR=%{mandir} PRESERVEDIR=%{preservedir} INSTALL=%{ucbinstall} RPMCFLAGS="%{cflags}" 31 | 32 | %description 33 | This is a port of the traditional ex and vi editor implementation as 34 | found on 2BSD and 4BSD. It was enhanced to support most of the additions 35 | in System V and POSIX.2, and international character sets like UTF-8 and 36 | many East Asian encodings. 37 | 38 | %prep 39 | rm -rf %{buildroot} 40 | %setup 41 | 42 | %build 43 | make %{makeflags} 44 | 45 | %install 46 | make DESTDIR=%{buildroot} %{makeflags} install 47 | 48 | %clean 49 | cd ..; rm -rf %{_builddir}/%{name}-%{version} 50 | rm -rf %{buildroot} 51 | 52 | %files 53 | %defattr(-,root,root) 54 | %doc Changes LICENSE README TODO 55 | %{bindir}/* 56 | %{libexecdir}/* 57 | %{mandir}/man1/* 58 | %{preservedir} 59 | -------------------------------------------------------------------------------- /ex_addr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | */ 73 | 74 | #ifndef lint 75 | #ifdef DOSCCS 76 | static char sccsid[] = "@(#)ex_addr.c 1.11 (gritter) 8/4/05"; 77 | #endif 78 | #endif /* not lint */ 79 | 80 | /* from ex_addr.c 7.3 (Berkeley) 6/7/85 */ 81 | 82 | #include "ex.h" 83 | #include "ex_re.h" 84 | 85 | /* 86 | * Routines for address parsing and assignment and checking of address bounds 87 | * in command mode. The routine address is called from ex_cmds.c 88 | * to parse each component of a command (terminated by , ; or the beginning 89 | * of the command itself. It is also called by the scanning routine 90 | * in ex_voperate.c from within open/visual. 91 | * 92 | * Other routines here manipulate the externals addr1 and addr2. 93 | * These are the first and last lines for the current command. 94 | * 95 | * The variable bigmove remembers whether a non-local glitch of . was 96 | * involved in an address expression, so we can set the previous context 97 | * mark '' when such a motion occurs. 98 | */ 99 | 100 | static bool bigmove; 101 | 102 | /* 103 | * Set up addr1 and addr2 for commands whose default address is dot. 104 | */ 105 | void 106 | setdot(void) 107 | { 108 | 109 | setdot1(); 110 | if (bigmove) 111 | markDOT(); 112 | } 113 | 114 | /* 115 | * Call setdot1 to set up default addresses without ever 116 | * setting the previous context mark. 117 | */ 118 | void 119 | setdot1(void) 120 | { 121 | 122 | if (addr2 == 0) 123 | addr1 = addr2 = dot; 124 | if (addr1 > addr2) { 125 | notempty(); 126 | failed = 1; 127 | error(catgets(catd, 1, 6, 128 | "Addr1 > addr2|First address exceeds second")); 129 | } 130 | } 131 | 132 | /* 133 | * Ex allows you to say 134 | * delete 5 135 | * to delete 5 lines, etc. 136 | * Such nonsense is implemented by setcount. 137 | */ 138 | void 139 | setcount(void) 140 | { 141 | register int cnt; 142 | 143 | pastwh(); 144 | if (!isdigit(peekchar())) { 145 | setdot(); 146 | return; 147 | } 148 | addr1 = addr2; 149 | setdot(); 150 | cnt = getnum(); 151 | if (cnt <= 0) 152 | error(catgets(catd, 1, 7, "Bad count|Nonzero count required")); 153 | addr2 += cnt - 1; 154 | if (addr2 > dol) 155 | addr2 = dol; 156 | nonzero(); 157 | } 158 | 159 | /* 160 | * Parse a number out of the command input stream. 161 | */ 162 | int 163 | getnum(void) 164 | { 165 | register int cnt; 166 | 167 | for (cnt = 0; isdigit(peekcd());) 168 | cnt = cnt * 10 + getchar() - '0'; 169 | return (cnt); 170 | } 171 | 172 | /* 173 | * Set the default addresses for commands which use the whole 174 | * buffer as default, notably write. 175 | */ 176 | void 177 | setall(void) 178 | { 179 | 180 | if (addr2 == 0) { 181 | addr1 = one; 182 | addr2 = dol; 183 | if (dol == zero) { 184 | dot = zero; 185 | return; 186 | } 187 | } 188 | /* 189 | * Don't want to set previous context mark so use setdot1(). 190 | */ 191 | setdot1(); 192 | } 193 | 194 | /* 195 | * No address allowed on, e.g. the file command. 196 | */ 197 | void 198 | setnoaddr(void) 199 | { 200 | 201 | if (addr2 != 0) { 202 | failed = 1; 203 | error(catgets(catd, 1, 8, 204 | "No address allowed@on this command")); 205 | } 206 | } 207 | 208 | /* 209 | * Parse an address. 210 | * Just about any sequence of address characters is legal. 211 | * 212 | * If you are tricky you can use this routine and the = command 213 | * to do simple addition and subtraction of cardinals less 214 | * than the number of lines in the file. 215 | */ 216 | line * 217 | address(char *in_line) 218 | { 219 | register line *addr; 220 | register int offset, c; 221 | short lastsign; 222 | 223 | bigmove = 0; 224 | lastsign = 0; 225 | offset = 0; 226 | addr = 0; 227 | for (;;) { 228 | if (isdigit(peekcd())) { 229 | if (addr == 0) { 230 | addr = zero; 231 | bigmove = 1; 232 | } 233 | loc1 = 0; 234 | addr += offset; 235 | offset = getnum(); 236 | if (lastsign >= 0) 237 | addr += offset; 238 | else 239 | addr -= offset; 240 | lastsign = 0; 241 | offset = 0; 242 | } 243 | switch (c = getcd()) { 244 | 245 | case '?': 246 | case '/': 247 | case '$': 248 | case '\'': 249 | case '\\': 250 | bigmove++; 251 | case '.': 252 | if (addr || offset) 253 | error(catgets(catd, 1, 9, 254 | "Badly formed address")); 255 | } 256 | offset += lastsign; 257 | lastsign = 0; 258 | switch (c) { 259 | 260 | case ' ': 261 | case '\t': 262 | continue; 263 | 264 | case '+': 265 | lastsign = 1; 266 | if (addr == 0) 267 | addr = dot; 268 | continue; 269 | 270 | case '^': 271 | case '-': 272 | lastsign = -1; 273 | if (addr == 0) 274 | addr = dot; 275 | continue; 276 | 277 | case '\\': 278 | case '?': 279 | case '/': 280 | c = compile(c, 1); 281 | notempty(); 282 | savere(&scanre); 283 | addr = dot; 284 | if (in_line && execute(0, dot)) { 285 | if (c == '/') { 286 | while (loc1 <= in_line) { 287 | if (loc1 == loc2) 288 | loc2++; 289 | if (!execute(1, NULL)) 290 | goto nope; 291 | } 292 | break; 293 | } else if (loc1 < in_line) { 294 | char *last; 295 | doques: 296 | 297 | do { 298 | last = loc1; 299 | if (loc1 == loc2) 300 | loc2++; 301 | if (!execute(1, NULL)) 302 | break; 303 | } while (loc1 < in_line); 304 | loc1 = last; 305 | break; 306 | } 307 | } 308 | nope: 309 | for (;;) { 310 | if (c == '/') { 311 | addr++; 312 | if (addr > dol) { 313 | if (value(WRAPSCAN) == 0) 314 | error(catgets(catd, 1, 10, "No match to BOTTOM|Address search hit BOTTOM without matching pattern")); 315 | addr = zero; 316 | } 317 | } else { 318 | addr--; 319 | if (addr < zero) { 320 | if (value(WRAPSCAN) == 0) 321 | error(catgets(catd, 1, 11, "No match to TOP|Address search hit TOP without matching pattern")); 322 | addr = dol; 323 | } 324 | } 325 | if (execute(0, addr)) { 326 | if (in_line && c == '?') { 327 | in_line = &linebuf[LBSIZE]; 328 | goto doques; 329 | } 330 | break; 331 | } 332 | if (addr == dot) 333 | error(catgets(catd, 1, 12, 334 | "Fail|Pattern not found")); 335 | } 336 | continue; 337 | 338 | case '$': 339 | addr = dol; 340 | continue; 341 | 342 | case '.': 343 | addr = dot; 344 | continue; 345 | 346 | case '\'': 347 | c = markreg(getchar()); 348 | if (c == 0) 349 | error(catgets(catd, 1, 13, 350 | "Marks are ' and a-z")); 351 | addr = getmark(c); 352 | if (addr == 0) 353 | error(catgets(catd, 1, 14, 354 | "Undefined mark@referenced")); 355 | break; 356 | 357 | default: 358 | ungetchar(c); 359 | if (offset) { 360 | if (addr == 0) 361 | addr = dot; 362 | addr += offset; 363 | loc1 = 0; 364 | } 365 | if (addr == 0) { 366 | bigmove = 0; 367 | return (0); 368 | } 369 | if (addr != zero) 370 | notempty(); 371 | addr += lastsign; 372 | if (addr < zero) { 373 | failed = 1; 374 | error(catgets(catd, 1, 15, 375 | "Negative address@- first buffer line is 1")); 376 | } 377 | if (addr > dol) { 378 | failed = 1; 379 | error(catgets(catd, 1, 16, 380 | "Not that many lines@in buffer")); 381 | } 382 | return (addr); 383 | } 384 | } 385 | } 386 | 387 | /* 388 | * Abbreviations to make code smaller 389 | * Left over from squashing ex version 1.1 into 390 | * 11/34's and 11/40's. 391 | */ 392 | void 393 | setCNL(void) 394 | { 395 | 396 | setcount(); 397 | newline(); 398 | } 399 | 400 | void 401 | setNAEOL(void) 402 | { 403 | 404 | setnoaddr(); 405 | eol(); 406 | } 407 | -------------------------------------------------------------------------------- /ex_argv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | * 73 | * from ex_argv.h 7.3 (Berkeley) 5/31/85 74 | * 75 | * Sccsid @(#)ex_argv.h 1.9 (gritter) 8/4/05 76 | */ 77 | 78 | /* 79 | * The current implementation of the argument list is poor, 80 | * using an argv even for internally done "next" commands. 81 | * It is not hard to see that this is restrictive and a waste of 82 | * space. The statically allocated glob structure could be replaced 83 | * by a dynamically allocated argument area space. 84 | */ 85 | var char **argv; 86 | var char **argv0; 87 | var char *args; 88 | var char *args0; 89 | var short argc; 90 | var short argc0; 91 | var short morargc; /* Used with "More files to edit..." */ 92 | 93 | var int firstln; /* From +lineno */ 94 | var char *firstpat; /* From +/pat */ 95 | 96 | /* Yech... */ 97 | struct glob { 98 | short argc; /* Index of current file in argv */ 99 | short argc0; /* Number of arguments in argv */ 100 | char *argv[NARGS + 1]; /* WHAT A WASTE! */ 101 | char argspac[NCARGS + sizeof (int)]; 102 | }; 103 | var struct glob frob; 104 | 105 | extern void gglob(struct glob *); 106 | -------------------------------------------------------------------------------- /ex_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | */ 73 | 74 | #ifndef lint 75 | #ifdef DOSCCS 76 | static char sccsid[] = "@(#)ex_data.c 1.14 (gritter) 11/23/04"; 77 | #endif 78 | #endif 79 | 80 | /* from ex_data.c 7.5 (Berkeley) 8/29/85 */ 81 | 82 | #include "ex.h" 83 | #include "ex_tty.h" 84 | 85 | /* 86 | * Initialization of option values. 87 | * The option #defines in ex_vars.h are made 88 | * from this file by the script makeoptions. 89 | * 90 | * These initializations are done char by char instead of as strings 91 | * to confuse xstr so it will leave them alone. 92 | */ 93 | #ifdef notdef 94 | char direct[ONMSZ] = 95 | {'/', 't', 'm', 'p'}; 96 | #else 97 | char direct[ONMSZ] = 98 | {'/', 'v', 'a', 'r', '/', 't', 'm', 'p' }; 99 | #endif 100 | char paragraphs[ONMSZ] = { 101 | 'I', 'P', 'L', 'P', 'P', 'P', 'Q', 'P', /* -ms macros */ 102 | 'P', ' ', 'L', 'I', /* -mm macros */ 103 | 'p', 'p', 'l', 'p', 'i', 'p', /* -me macros */ 104 | 'b', 'p' /* bare nroff */ 105 | }; 106 | char sections[ONMSZ] = { 107 | 'N', 'H', 'S', 'H', /* -ms macros */ 108 | 'H', ' ', 'H', 'U', /* -mm macros */ 109 | 'n', 'h', 's', 'h' /* -me macros */ 110 | }; 111 | char shell[ONMSZ] = 112 | { '/', 'b', 'i', 'n', '/', 's', 'h' }; 113 | char tags[ONMSZ] = { 114 | 't', 'a', 'g', 's', ' ', 115 | '/', 'u', 's', 'r', '/', 'l', 'i', 'b', '/', 't', 'a', 'g', 's' 116 | }; 117 | char ttylongname[ONMSZ] = 118 | { 'd', 'u', 'm', 'b' }; 119 | 120 | short TCOLUMNS = 80; 121 | short TLINES = 24; 122 | 123 | struct option options[NOPTS + 1] = { 124 | { "autoindent", "ai", ONOFF, 0, 0, 0 }, 125 | { "autoprint", "ap", ONOFF, 1, 1, 0 }, 126 | { "autowrite", "aw", ONOFF, 0, 0, 0 }, 127 | { "beautify", "bf", ONOFF, 0, 0, 0 }, 128 | { "directory", "dir", STRING, 0, 0, direct }, 129 | { "edcompatible","ed", ONOFF, 0, 0, 0 }, 130 | { "errorbells", "eb", ONOFF, 0, 0, 0 }, 131 | { "exrc", "ex", ONOFF, 0, 0, 0 }, 132 | { "flash", "fl", ONOFF, 1, 1, 0 }, 133 | { "hardtabs", "ht", NUMERIC, 8, 8, 0 }, 134 | { "ignorecase", "ic", ONOFF, 0, 0, 0 }, 135 | { "lisp", 0, ONOFF, 0, 0, 0 }, 136 | { "list", 0, ONOFF, 0, 0, 0 }, 137 | { "magic", 0, ONOFF, 1, 1, 0 }, 138 | { "mesg", 0, ONOFF, 1, 1, 0 }, 139 | { "modelines", "ml", ONOFF, 0, 0, 0 }, 140 | { "number", "nu", ONOFF, 0, 0, 0 }, 141 | { "open", 0, ONOFF, 1, 1, 0 }, 142 | { "optimize", "opt", ONOFF, 0, 0, 0 }, 143 | { "paragraphs", "para", STRING, 0, 0, paragraphs }, 144 | { "prompt", 0, ONOFF, 1, 1, 0 }, 145 | { "readonly", "ro", ONOFF, 0, 0, 0 }, 146 | { "redraw", 0, ONOFF, 0, 0, 0 }, 147 | { "remap", 0, ONOFF, 1, 1, 0 }, 148 | { "report", 0, NUMERIC, 5, 5, 0 }, 149 | { "scroll", "scr", NUMERIC, 12, 12, 0 }, 150 | { "sections", "sect", STRING, 0, 0, sections }, 151 | { "shell", "sh", STRING, 0, 0, shell }, 152 | { "shiftwidth", "sw", NUMERIC, TABS, TABS, 0 }, 153 | { "showmatch", "sm", ONOFF, 0, 0, 0 }, 154 | { "showmode", "smd", ONOFF, 0, 0, 0 }, 155 | { "slowopen", "slow", ONOFF, 0, 0, 0 }, 156 | { "sourceany", 0, ONOFF, 0, 0, 0 }, 157 | { "tabstop", "ts", NUMERIC, TABS, TABS, 0 }, 158 | { "taglength", "tl", NUMERIC, 0, 0, 0 }, 159 | { "tags", "tag", STRING, 0, 0, tags }, 160 | { "term", 0, OTERM, 0, 0, ttylongname }, 161 | { "terse", 0, ONOFF, 0, 0, 0 }, 162 | { "timeout", "to", ONOFF, 1, 1, 0 }, 163 | { "ttytype", "tty", OTERM, 0, 0, ttylongname }, 164 | { "warn", 0, ONOFF, 1, 1, 0 }, 165 | { "window", "wi", NUMERIC, 23, 23, 0 }, 166 | { "wrapscan", "ws", ONOFF, 1, 1, 0 }, 167 | { "wrapmargin", "wm", NUMERIC, 0, 0, 0 }, 168 | { "writeany", "wa", ONOFF, 0, 0, 0 }, 169 | { 0, 0, 0, 0, 0, 0 } 170 | }; 171 | -------------------------------------------------------------------------------- /ex_extern.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | */ 73 | 74 | #ifndef lint 75 | #ifdef DOSCCS 76 | static char sccsid[] = "@(#)ex_extern.c 1.6 (gritter) 11/23/04"; 77 | #endif 78 | #endif 79 | 80 | /* from ex_extern.c 7.4 (Berkeley) 6/7/85 */ 81 | 82 | /* 83 | * Provide defs of the global variables. 84 | * This crock is brought to you by the turkeys 85 | * who broke Unix on the Bell Labs 3B machine, 86 | * all in the name of "but that's what the C 87 | * book says!" 88 | */ 89 | 90 | # define var /* nothing */ 91 | # include "ex.h" 92 | # include "ex_argv.h" 93 | # include "ex_re.h" 94 | # include "ex_temp.h" 95 | # include "ex_tty.h" 96 | /* # include "ex_tune.h" */ 97 | # include "ex_vars.h" 98 | # include "ex_vis.h" 99 | -------------------------------------------------------------------------------- /ex_get.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | */ 73 | 74 | #ifndef lint 75 | #ifdef DOSCCS 76 | static char sccsid[] = "@(#)ex_get.c 1.18 (gritter) 8/4/05"; 77 | #endif 78 | #endif 79 | 80 | /* from ex_get.c 7.6 (Berkeley) 6/7/85 */ 81 | 82 | #include "ex.h" 83 | #include "ex_tty.h" 84 | 85 | /* 86 | * Input routines for command mode. 87 | * Since we translate the end of reads into the implied ^D's 88 | * we have different flavors of routines which do/don't return such. 89 | */ 90 | static bool junkbs; 91 | int lastc = '\n'; 92 | 93 | void 94 | ignchar(void) 95 | { 96 | ignore(getchar()); 97 | } 98 | 99 | int 100 | getach(void) 101 | { 102 | register int c; 103 | static char in_line[BUFSIZ]; 104 | /* struct stat statb; */ 105 | 106 | c = peekc; 107 | if (c != 0) { 108 | peekc = 0; 109 | return (c); 110 | } 111 | if (globp) { 112 | if (*globp) 113 | return (*globp++&0377); 114 | globp = 0; 115 | return (lastc = EOF); 116 | } 117 | top: 118 | if (input) { 119 | if ((c = *input++&0377)) { 120 | if (verbose && !intty) 121 | write(2, &input[-1], 1); 122 | if (c &= TRIM) 123 | return (lastc = c); 124 | goto top; 125 | } 126 | input = 0; 127 | } 128 | flush(); 129 | if (intty) { 130 | c = read(0, in_line, sizeof in_line - 4); 131 | if (c < 0) 132 | return (lastc = EOF); 133 | if (c == 0 || in_line[c-1] != '\n') 134 | in_line[c++] = CTRL('d'); 135 | if (in_line[c-1] == '\n') 136 | noteinp(); 137 | in_line[c] = 0; 138 | for (c--; c >= 0; c--) 139 | if (in_line[c] == 0) 140 | #ifndef BIT8 141 | in_line[c] = QUOTE; 142 | #else 143 | in_line[c] = '\200'; 144 | #endif 145 | input = in_line; 146 | goto top; 147 | } 148 | c = read(0, in_line, sizeof in_line - 1); 149 | if(c <= 0) 150 | return(lastc = EOF); 151 | in_line[c] = '\0'; 152 | input = in_line; 153 | goto top; 154 | } 155 | 156 | int 157 | getchar(void) 158 | { 159 | register int c; 160 | 161 | do 162 | c = getcd(); 163 | while (!globp && c == CTRL('d')); 164 | return (c); 165 | } 166 | 167 | void 168 | checkjunk(int c) 169 | { 170 | 171 | if (junkbs == 0 && c == '\b') { 172 | write(2, cntrlhm, 13); 173 | junkbs = 1; 174 | } 175 | } 176 | 177 | int 178 | getcd(void) 179 | { 180 | register int c; 181 | 182 | again: 183 | c = getach(); 184 | if (c == EOF) 185 | return (c); 186 | c &= TRIM; 187 | if (!inopen) { 188 | if (!globp && c == CTRL('d')) 189 | setlastchar('\n'); 190 | else if (junk(c)) { 191 | checkjunk(c); 192 | goto again; 193 | } 194 | } 195 | return (c); 196 | } 197 | 198 | int 199 | peekchar(void) 200 | { 201 | 202 | if (peekc == 0) 203 | peekc = getchar(); 204 | return (peekc); 205 | } 206 | 207 | int 208 | peekcd(void) 209 | { 210 | if (peekc == 0) 211 | peekc = getcd(); 212 | return (peekc); 213 | } 214 | 215 | /* 216 | * Crunch the indent. 217 | * Hard thing here is that in command mode some of the indent 218 | * is only implicit, so we must seed the column counter. 219 | * This should really be done differently so as to use the whitecnt routine 220 | * and also to hack indenting for LISP. 221 | */ 222 | int 223 | smunch(register int col, char *ocp) 224 | { 225 | register char *cp; 226 | 227 | cp = ocp; 228 | for (;;) 229 | switch (*cp++) { 230 | 231 | case ' ': 232 | col++; 233 | continue; 234 | 235 | case '\t': 236 | col += value(TABSTOP) - (col % value(TABSTOP)); 237 | continue; 238 | 239 | default: 240 | cp--; 241 | CP(ocp, cp); 242 | return (col); 243 | } 244 | } 245 | 246 | /* 247 | * Input routine for insert/append/change in command mode. 248 | * Most work here is in handling autoindent. 249 | */ 250 | static short lastin; 251 | 252 | int 253 | gettty(void) 254 | { 255 | register int c = 0; 256 | register char *cp = genbuf; 257 | char hadup = 0; 258 | int offset = Pline == numbline ? 8 : 0; 259 | int ch; 260 | 261 | if (intty && !inglobal) { 262 | if (offset) { 263 | holdcm = 1; 264 | ex_printf(" %4d ", lineDOT() + 1); 265 | flush(); 266 | holdcm = 0; 267 | } 268 | if (value(AUTOINDENT) ^ aiflag) { 269 | holdcm = 1; 270 | #ifdef LISPCODE 271 | if (value(LISP)) 272 | lastin = lindent(dot + 1); 273 | #endif 274 | tab(lastin + offset); 275 | while ((c = getcd()) == CTRL('d')) { 276 | if (lastin == 0 && isatty(0) == -1) { 277 | holdcm = 0; 278 | return (EOF); 279 | } 280 | lastin = backtab(lastin); 281 | tab(lastin + offset); 282 | } 283 | switch (c) { 284 | 285 | case '^': 286 | case '0': 287 | ch = getcd(); 288 | if (ch == CTRL('d')) { 289 | if (c == '0') 290 | lastin = 0; 291 | if (!OS) { 292 | putchar('\b' | QUOTE); 293 | putchar(' ' | QUOTE); 294 | putchar('\b' | QUOTE); 295 | } 296 | tab(offset); 297 | hadup = 1; 298 | c = getchar(); 299 | } else 300 | ungetchar(ch); 301 | break; 302 | 303 | case '.': 304 | if (peekchar() == '\n') { 305 | ignchar(); 306 | noteinp(); 307 | holdcm = 0; 308 | return (EOF); 309 | } 310 | break; 311 | 312 | case '\n': 313 | hadup = 1; 314 | break; 315 | } 316 | } 317 | flush(); 318 | holdcm = 0; 319 | } 320 | if (c == 0) 321 | c = getchar(); 322 | while (c != EOF && c != '\n') { 323 | if (cp > &genbuf[LBSIZE - 2]) 324 | error(catgets(catd, 1, 71, "Input line too long")); 325 | *cp++ = c; 326 | c = getchar(); 327 | } 328 | if (c == EOF) { 329 | if (inglobal) 330 | ungetchar(EOF); 331 | return (EOF); 332 | } 333 | *cp = 0; 334 | cp = linebuf; 335 | if ((value(AUTOINDENT) ^ aiflag) && hadup == 0 && intty && !inglobal) { 336 | lastin = c = smunch(lastin, genbuf); 337 | for (c = lastin; c >= value(TABSTOP); c -= value(TABSTOP)) 338 | *cp++ = '\t'; 339 | for (; c > 0; c--) 340 | *cp++ = ' '; 341 | } 342 | lcpy(cp, genbuf, LBSIZE - (cp - linebuf)); 343 | if (linebuf[0] == '.' && linebuf[1] == 0) 344 | return (EOF); 345 | return (0); 346 | } 347 | 348 | void 349 | setin(line *addr) 350 | { 351 | 352 | if (addr == zero) 353 | lastin = 0; 354 | else 355 | getline(*addr), lastin = smunch(0, linebuf); 356 | } 357 | -------------------------------------------------------------------------------- /ex_re.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | * 73 | * from ex_re.h 7.3 (Berkeley) 5/31/85 74 | * 75 | * Sccsid @(#)ex_re.h 1.24 (gritter) 8/4/05 76 | */ 77 | 78 | /* 79 | * Regular expression definitions. 80 | * The regular expressions in ex are similar to those in ed, 81 | * with the addition of the word boundaries from Toronto ed 82 | * and allowing character classes to have [a-b] as in the shell. 83 | * The numbers for the nodes below are spaced further apart then 84 | * necessary because I at one time partially put in + and | (one or 85 | * more and alternation.) 86 | */ 87 | struct regexp { 88 | char *Patbuf; 89 | long Re_ident; 90 | void *Expbuf; 91 | bool Circfl; 92 | short Nbra; 93 | int Flags; 94 | int Length; 95 | }; 96 | 97 | /* 98 | * There are three regular expressions here, the previous (in re), 99 | * the previous substitute (in subre) and the previous scanning (in scanre). 100 | * It would be possible to get rid of "re" by making it a stack parameter 101 | * to the appropriate routines. 102 | */ 103 | var struct regexp re; /* Last re */ 104 | var struct regexp scanre; /* Last scanning re */ 105 | var struct regexp subre; /* Last substitute re */ 106 | 107 | extern char *loc1; /* Where re began to match (in linebuf) */ 108 | extern char *loc2; /* First char after re match (") */ 109 | 110 | /* 111 | * Since the phototypesetter v7-epsilon 112 | * C compiler doesn't have structure assignment... 113 | */ 114 | extern struct regexp *savere(struct regexp *); 115 | extern struct regexp *resre(struct regexp *); 116 | 117 | /* 118 | * Definitions for substitute 119 | */ 120 | extern char *braslist[NBRA]; /* Starts of \(\)'ed text in lhs */ 121 | extern char *braelist[NBRA]; /* Ends... */ 122 | var char rhsbuf[RHSSIZE]; /* Rhs of last substitute */ 123 | #ifdef BIT8 124 | var char rhsquo[RHSSIZE]; /* Quote indicator for rhsbuf */ 125 | #endif 126 | -------------------------------------------------------------------------------- /ex_set.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | */ 73 | 74 | #ifndef lint 75 | #ifdef DOSCCS 76 | static char sccsid[] = "@(#)ex_set.c 1.11 (gritter) 11/24/04"; 77 | #endif 78 | #endif 79 | 80 | /* from ex_set.c 7.4 (Berkeley) 6/7/85 */ 81 | 82 | #include "ex.h" 83 | #include "ex_temp.h" 84 | #include "ex_tty.h" 85 | 86 | /* 87 | * Set command. 88 | */ 89 | char optname[ONMSZ]; 90 | 91 | void 92 | set(void) 93 | { 94 | register char *cp; 95 | register struct option *op; 96 | register int c; 97 | bool no; 98 | 99 | setnoaddr(); 100 | if (skipend()) { 101 | if (peekchar() != EOF) 102 | ignchar(); 103 | propts(); 104 | return; 105 | } 106 | do { 107 | cp = optname; 108 | do { 109 | if (cp < &optname[ONMSZ - 2]) 110 | *cp++ = getchar(); 111 | } while (isalnum(peekchar())); 112 | *cp = 0; 113 | cp = optname; 114 | if (eq("all", cp)) { 115 | if (inopen) 116 | pofix(); 117 | prall(); 118 | goto setnext; 119 | } 120 | no = 0; 121 | if (cp[0] == 'n' && cp[1] == 'o') { 122 | cp += 2; 123 | no++; 124 | } 125 | /* Implement w300, w1200, and w9600 specially */ 126 | if (eq(cp, "w300")) { 127 | if (ospeed >= B1200) { 128 | dontset: 129 | ignore(getchar()); /* = */ 130 | ignore(getnum()); /* value */ 131 | continue; 132 | } 133 | cp = "window"; 134 | } else if (eq(cp, "w1200")) { 135 | if (ospeed < B1200 || ospeed >= B2400) 136 | goto dontset; 137 | cp = "window"; 138 | } else if (eq(cp, "w9600")) { 139 | if (ospeed < B2400) 140 | goto dontset; 141 | cp = "window"; 142 | } 143 | for (op = options; op < &options[NOPTS]; op++) 144 | if (eq(op->oname, cp) || (op->oabbrev && eq(op->oabbrev, cp))) 145 | break; 146 | if (op->oname == 0) 147 | serror(catgets(catd, 1, 159, 148 | "%s: No such option@- 'set all' gives all option values"), cp); 149 | c = skipwh(); 150 | if (peekchar() == '?') { 151 | ignchar(); 152 | printone: 153 | propt(op); 154 | noonl(); 155 | goto setnext; 156 | } 157 | if (op->otype == ONOFF) { 158 | op->ovalue = 1 - no; 159 | if (op == &options[PROMPT]) 160 | oprompt = 1 - no; 161 | goto setnext; 162 | } 163 | if (no) 164 | serror(catgets(catd, 1, 160, 165 | "Option %s is not a toggle"), op->oname); 166 | if (c != 0 || setend()) 167 | goto printone; 168 | if (getchar() != '=') 169 | serror(catgets(catd, 1, 161, 170 | "Missing =@in assignment to option %s"), op->oname); 171 | switch (op->otype) { 172 | 173 | case NUMERIC: 174 | if (!isdigit(peekchar())) 175 | error(catgets(catd, 1, 162, 176 | "Digits required@after =")); 177 | op->ovalue = getnum(); 178 | if (value(TABSTOP) <= 0) 179 | value(TABSTOP) = TABS; 180 | if (value(HARDTABS) <= 0) 181 | value(HARDTABS) = TABS; 182 | if (op == &options[WINDOW]) { 183 | if (value(WINDOW) >= TLINES) 184 | value(WINDOW) = TLINES-1; 185 | vsetsiz(value(WINDOW)); 186 | } 187 | break; 188 | 189 | case STRING: 190 | case OTERM: 191 | cp = optname; 192 | while (!setend()) { 193 | if (cp >= &optname[ONMSZ]) 194 | error(catgets(catd, 1, 163, 195 | "String too long@in option assignment")); 196 | /* adb change: allow whitepace in strings */ 197 | if( (*cp = getchar()) == '\\') 198 | if( peekchar() != EOF) 199 | *cp = getchar(); 200 | cp++; 201 | } 202 | *cp = 0; 203 | if (op->otype == OTERM) { 204 | /* 205 | * At first glance it seems like we shouldn't care if the terminal type 206 | * is changed inside visual mode, as long as we assume the screen is 207 | * a mess and redraw it. However, it's a much harder problem than that. 208 | * If you happen to change from 1 crt to another that both have the same 209 | * size screen, it's OK. But if the screen size if different, the stuff 210 | * that gets initialized in vop() will be wrong. This could be overcome 211 | * by redoing the initialization, e.g. making the first 90% of vop into 212 | * a subroutine. However, the most useful case is where you forgot to do 213 | * a setenv before you went into the editor and it thinks you're on a dumb 214 | * terminal. Ex treats this like hardcopy and goes into HARDOPEN mode. 215 | * This loses because the first part of vop calls oop in this case. 216 | * The problem is so hard I gave up. I'm not saying it can't be done, 217 | * but I am saying it probably isn't worth the effort. 218 | */ 219 | if (inopen) 220 | error(catgets(catd, 1, 164, 221 | "Can't change type of terminal from within open/visual")); 222 | setterm(optname); 223 | } else { 224 | CP(op->osvalue, optname); 225 | op->odefault = 1; 226 | } 227 | break; 228 | } 229 | setnext: 230 | flush(); 231 | } while (!skipend()); 232 | eol(); 233 | } 234 | 235 | int 236 | setend(void) 237 | { 238 | 239 | return (is_white(peekchar()) || endcmd(peekchar())); 240 | } 241 | 242 | void 243 | prall(void) 244 | { 245 | register int incr = (NOPTS + 2) / 3; 246 | register int rows = incr; 247 | register struct option *op = options; 248 | 249 | for (; rows; rows--, op++) { 250 | propt(op); 251 | tab(24); 252 | propt(&op[incr]); 253 | if (&op[2*incr] < &options[NOPTS]) { 254 | tab(56); 255 | propt(&op[2 * incr]); 256 | } 257 | putNFL(); 258 | } 259 | } 260 | 261 | void 262 | propts(void) 263 | { 264 | register struct option *op; 265 | 266 | for (op = options; op < &options[NOPTS]; op++) { 267 | if (op == &options[TTYTYPE]) 268 | continue; 269 | switch (op->otype) { 270 | 271 | case ONOFF: 272 | case NUMERIC: 273 | if (op->ovalue == op->odefault) 274 | continue; 275 | break; 276 | 277 | case STRING: 278 | if (op->odefault == 0) 279 | continue; 280 | break; 281 | } 282 | propt(op); 283 | putchar(' '); 284 | } 285 | noonl(); 286 | flush(); 287 | } 288 | 289 | void 290 | propt(register struct option *op) 291 | { 292 | register char *name; 293 | 294 | name = op->oname; 295 | 296 | switch (op->otype) { 297 | 298 | case ONOFF: 299 | ex_printf(catgets(catd, 1, 165, "%s%s"), 300 | op->ovalue ? catgets(catd, 1, 166, "") 301 | : catgets(catd, 1, 167, "no"), name); 302 | break; 303 | 304 | case NUMERIC: 305 | ex_printf(catgets(catd, 1, 168, "%s=%d"), name, op->ovalue); 306 | break; 307 | 308 | case STRING: 309 | case OTERM: 310 | ex_printf(catgets(catd, 1, 169, "%s=%s"), name, op->osvalue); 311 | break; 312 | } 313 | } 314 | -------------------------------------------------------------------------------- /ex_tagio.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1985 Regents of the University of California */ 2 | 3 | /* 4 | * These routines are for faster tag lookup. They support the binary 5 | * search used in tagfind() instead of the linear search. The speedup 6 | * is quite noticable looking for a tag at the end of a long tags 7 | * file. Define FASTTAG in the Makefile to use these routines. 8 | * 9 | * This code contains changes by 10 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 11 | * 12 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 13 | * to these changes. 14 | * 15 | * 16 | * Copyright (c) 1980, 1993 17 | * The Regents of the University of California. All rights reserved. 18 | * 19 | * Redistribution and use in source and binary forms, with or without 20 | * modification, are permitted provided that the following conditions 21 | * are met: 22 | * 1. Redistributions of source code must retain the above copyright 23 | * notice, this list of conditions and the following disclaimer. 24 | * 2. Redistributions in binary form must reproduce the above copyright 25 | * notice, this list of conditions and the following disclaimer in the 26 | * documentation and/or other materials provided with the distribution. 27 | * 3. All advertising materials mentioning features or use of this software 28 | * must display the following acknowledgement: 29 | * This product includes software developed by the University of 30 | * California, Berkeley and its contributors. 31 | * 4. Neither the name of the University nor the names of its contributors 32 | * may be used to endorse or promote products derived from this software 33 | * without specific prior written permission. 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 36 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 38 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 39 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 41 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 43 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 44 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 45 | * SUCH DAMAGE. 46 | * 47 | * 48 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 49 | * 50 | * Redistribution and use in source and binary forms, with or without 51 | * modification, are permitted provided that the following conditions 52 | * are met: 53 | * Redistributions of source code and documentation must retain the 54 | * above copyright notice, this list of conditions and the following 55 | * disclaimer. 56 | * Redistributions in binary form must reproduce the above copyright 57 | * notice, this list of conditions and the following disclaimer in the 58 | * documentation and/or other materials provided with the distribution. 59 | * All advertising materials mentioning features or use of this software 60 | * must display the following acknowledgement: 61 | * This product includes software developed or owned by Caldera 62 | * International, Inc. 63 | * Neither the name of Caldera International, Inc. nor the names of 64 | * other contributors may be used to endorse or promote products 65 | * derived from this software without specific prior written permission. 66 | * 67 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 68 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 69 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 70 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 71 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 72 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 73 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 74 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 75 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 76 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 77 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 78 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 79 | */ 80 | 81 | #ifdef FASTTAG 82 | #ifndef lint 83 | #ifdef DOSCCS 84 | static char sccsid[] = "@(#)ex_tagio.c 1.12 (gritter) 8/4/05"; 85 | #endif 86 | #endif 87 | 88 | /* from ex_tagio.c 7.3 (Berkeley) 1/31/86 */ 89 | 90 | #include "ex.h" 91 | 92 | static long offset = -1; 93 | static long block = -1; 94 | static int bcnt = 0; 95 | static int b_size; 96 | static char *ibuf; 97 | 98 | int 99 | topen(char *file, char *buf) 100 | { 101 | int fd; 102 | struct stat statb; 103 | 104 | b_size = MAXBSIZE; 105 | offset = -1; 106 | block = -1; 107 | if ((fd = open(file, O_RDONLY, 0)) < 0) 108 | return(-1); 109 | if (fstat(fd, &statb) < 0) { 110 | close(fd); 111 | return(-1); 112 | } 113 | ibuf = buf; 114 | if (statb.st_blksize <= MAXBSIZE) 115 | b_size = statb.st_blksize; 116 | return(fd); 117 | } 118 | 119 | int 120 | tseek(int fd, off_t off) 121 | { 122 | off_t nblock; 123 | 124 | nblock = off / b_size * b_size; 125 | offset = off % b_size; 126 | if (nblock == block) 127 | return(0); 128 | block = nblock; 129 | if (lseek(fd, (off_t) nblock, SEEK_SET) < 0) 130 | return(-1); 131 | if ((bcnt = read(fd, ibuf, b_size)) < 0) 132 | return(-1); 133 | return(0); 134 | } 135 | 136 | int 137 | tgets(register char *buf, int cnt, int fd) 138 | { 139 | register char *cp; 140 | register int cc; 141 | 142 | cc = offset; 143 | if (cc == -1) { 144 | if ((bcnt = read(fd, ibuf, b_size)) <= 0) 145 | return 0; 146 | cc = 0; 147 | block = 0; 148 | } 149 | if (bcnt == 0) /* EOF */ 150 | return 0; 151 | cp = ibuf + cc; 152 | while (--cnt > 0) { 153 | if (++cc > bcnt) { 154 | block += b_size; 155 | if ((bcnt = read(fd, ibuf, b_size)) <= 0) { 156 | offset = cc; 157 | return 0; 158 | } 159 | cp = ibuf; 160 | cc = 1; 161 | } 162 | if ((*buf++ = *cp++) == '\n') 163 | break; 164 | } 165 | *--buf = 0; 166 | offset = cc; 167 | return(1); 168 | } 169 | 170 | void 171 | tclose(int fd) 172 | { 173 | close(fd); 174 | offset = -1; 175 | block = -1; 176 | bcnt = 0; 177 | } 178 | #endif 179 | -------------------------------------------------------------------------------- /ex_temp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | * 73 | * from ex_temp.h 7.4 (Berkeley) 5/31/85 74 | * 75 | * Sccsid @(#)ex_temp.h 1.10 (gritter) 8/4/05 76 | */ 77 | 78 | /* 79 | * The editor uses a temporary file for files being edited, in a structure 80 | * similar to that of ed. The first block of the file is used for a header 81 | * block which guides recovery after editor/system crashes. 82 | * Lines are represented in core by a pointer into the temporary file which 83 | * is packed into 16 bits (32 on VMUNIX). All but the low bit index the temp 84 | * file; the last is used by global commands. The parameters below control 85 | * how much the other bits are shifted left before they index the temp file. 86 | * Larger shifts give more slop in the temp file but allow larger files 87 | * to be edited. 88 | * 89 | * The editor does not garbage collect the temporary file. When a new 90 | * file is edited, the temporary file is rather discarded and a new one 91 | * created for the new file. Garbage collection would be rather complicated 92 | * in ex because of the general undo, and in any case would require more 93 | * work when throwing lines away because marks would have be carefully 94 | * checked before reallocating temporary file space. Said another way, 95 | * each time you create a new line in the temporary file you get a unique 96 | * number back, and this is a property used by marks. 97 | * 98 | * The following temp file parameters allow 256k bytes in the temporary 99 | * file. By changing to the numbers in comments you can get 512k. 100 | * For VMUNIX you get more than you could ever want. 101 | * VMUNIX uses long (32 bit) integers giving much more 102 | * space in the temp file and no waste. This doubles core 103 | * requirements but allows files of essentially unlimited size to be edited. 104 | */ 105 | #ifndef VMUNIX 106 | #define BLKMSK 0777 /* 01777 */ 107 | #define BNDRY 8 /* 16 */ 108 | #define INCRMT 0200 /* 0100 */ 109 | #define LBTMSK 0770 /* 0760 */ 110 | #define NMBLKS 506 /* 1018 */ 111 | #define OFFBTS 7 /* 6 */ 112 | #define OFFMSK 0177 /* 077 */ 113 | #define SHFT 2 /* 3 */ 114 | #define TLNMSK 077776 115 | #else /* VMUNIX */ 116 | #ifdef LARGEF 117 | #define BLKMSK 017777777777 118 | #else 119 | #define BLKMSK 077777 120 | #endif 121 | #define BNDRY 2 122 | #define INCRMT 02000 123 | #define LBTMSK 01776 124 | #ifdef LARGEF 125 | #define NMBLKS 017777777770 126 | #else 127 | #define NMBLKS 077770 128 | #endif 129 | #define OFFBTS 10 130 | #define OFFMSK 01777 131 | #define SHFT 0 132 | #define TLNMSK 017777777776 133 | #endif /* VMUNIX */ 134 | 135 | /* 136 | * The editor uses three buffers into the temporary file (ed uses two 137 | * and is very similar). These are two read buffers and one write buffer. 138 | * Basically, the editor deals with the file as a sequence of BUFSIZ character 139 | * blocks. Each block contains some number of lines (and lines 140 | * can run across block boundaries. 141 | * 142 | * New lines are written into the last block in the temporary file 143 | * which is in core as obuf. When a line is needed which isn't in obuf, 144 | * then it is brought into an input buffer. As there are two, the choice 145 | * is to take the buffer into which the last read (of the two) didn't go. 146 | * Thus this is a 2 buffer LRU replacement strategy. Measurement 147 | * shows that this saves roughly 25% of the buffer reads over a one 148 | * input buffer strategy. Since the editor (on our VAX over 1 week) 149 | * spends (spent) roughly 30% of its time in the system read routine, 150 | * this can be a big help. 151 | */ 152 | var bool hitin2; /* Last read hit was ibuff2 not ibuff */ 153 | var bool ichang2; /* Have actually changed ibuff2 */ 154 | var bool ichanged; /* Have actually changed ibuff */ 155 | var bloc iblock; /* Temp file block number of ibuff (or -1) */ 156 | var bloc iblock2; /* Temp file block number of ibuff2 (or -1) */ 157 | var bloc ninbuf; /* Number useful chars left in input buffer */ 158 | var bloc nleft; /* Number usable chars left in output buffer */ 159 | var bloc oblock; /* Temp file block number of obuff (or -1) */ 160 | var bbloc tline; /* Current temp file ptr */ 161 | 162 | var char ibuff[BUFSIZ]; 163 | var char ibuff2[BUFSIZ]; 164 | var char obuff[BUFSIZ]; 165 | 166 | /* 167 | * Structure of the descriptor block which resides 168 | * in the first block of the temporary file and is 169 | * the guiding light for crash recovery. 170 | * 171 | * As the Blocks field below implies, there are temporary file blocks 172 | * devoted to (some) image of the incore array of pointers into the temp 173 | * file. Thus, to recover from a crash we use these indices to get the 174 | * line pointers back, and then use the line pointers to get the text back. 175 | * Except for possible lost lines due to sandbagged I/O, the entire 176 | * file (at the time of the last editor "sync") can be recovered from 177 | * the temp file. 178 | */ 179 | 180 | /* This definition also appears in expreserve.c... beware */ 181 | struct header { 182 | time_t Time; /* Time temp file last updated */ 183 | uid_t Uid; 184 | bbloc Flines; /* Number of lines in file */ 185 | char Savedfile[FNSIZE]; /* The current file name */ 186 | bloc Blocks[LBLKS]; /* Blocks where line pointers stashed */ 187 | }; 188 | var struct header H; 189 | 190 | #define uid H.Uid 191 | #define flines H.Flines 192 | #define savedfile H.Savedfile 193 | #define blocks H.Blocks 194 | -------------------------------------------------------------------------------- /ex_tune.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | * 73 | * from ex_tune.h 7.8.1 (2.11BSD) 1996/10/23 74 | * 75 | * Sccsid @(#)ex_tune.h 1.14 (gritter) 8/4/05 76 | */ 77 | 78 | /* 79 | * Note: the parameters that are actually tuneable have been moved to 80 | * config.h. Do not make changes here unless you know what you are 81 | * doing! GR 82 | */ 83 | 84 | /* 85 | * Definitions of editor parameters and limits 86 | */ 87 | 88 | /* 89 | * Pathnames (will be predefined in Makefile). 90 | */ 91 | #ifndef EXRECOVER 92 | #define EXRECOVER "/usr/sbin/exrecover" 93 | #endif 94 | #ifndef EXPRESERVE 95 | #define EXPRESERVE "/usr/sbin/expreserve" 96 | #endif 97 | #ifndef VMUNIX 98 | #ifndef EXSTRINGS 99 | #define EXSTRINGS "/usr/share/misc/exstrings" 100 | #endif 101 | #endif 102 | 103 | /* 104 | * If your system believes that tabs expand to a width other than 105 | * 8 then your makefile should cc with -DTABS=whatever, otherwise we use 8. 106 | */ 107 | #ifndef TABS 108 | #define TABS 8 109 | #endif 110 | 111 | /* 112 | * Maximums 113 | * 114 | * Most definitions are quite generous. 115 | */ 116 | /* FNSIZE is also defined in expreserve.c */ 117 | #ifdef _POSIX_PATH_MAX 118 | #define FNSIZE _POSIX_PATH_MAX 119 | #else 120 | #define FNSIZE 128 /* File name size */ 121 | #endif 122 | #ifdef VMUNIX 123 | #ifndef ESIZE /* see config.h */ 124 | #define ESIZE 512 /* Regular expression buffer size */ 125 | #endif 126 | #define CRSIZE BUFSIZ /* Crypt buffer size */ 127 | #else /* !VMUNIX */ 128 | #ifdef u370 129 | #ifndef ESIZE /* see config.h */ 130 | #define ESIZE 512 131 | #endif 132 | #define CRSIZE 4096 133 | #else 134 | #ifndef ESIZE /* see config.h */ 135 | #define ESIZE 128 /* Size of compiled re */ 136 | #endif 137 | #define CRSIZE 512 138 | #endif 139 | #endif 140 | #define NBRA 9 /* Number of re \( \) pairs */ 141 | #define GBSIZE 256 /* Buffer size */ 142 | #define UXBSIZE 128 /* Unix command buffer size */ 143 | #define VBSIZE 128 /* Partial line max size in visual */ 144 | /* LBLKS is also defined in expreserve.c */ 145 | #ifndef VMUNIX 146 | #define LBLKS 125 /* Line pointer blocks in temp file */ 147 | #define HBLKS 1 /* struct header fits in BUFSIZ*HBLKS */ 148 | #else /* VMUNIX */ 149 | #ifdef LARGEF 150 | #define LBLKS 20000 151 | #else /* !LARGEF */ 152 | #define LBLKS 900 153 | #endif /* !LARGEF */ 154 | #define HBLKS (1 + (FNSIZE + LBLKS * sizeof(bloc)) / BUFSIZ) 155 | #endif /* VMUNIX */ 156 | #define MAXDIRT 12 /* Max dirtcnt before sync tfile */ 157 | 158 | /* 159 | * Size of in-core buffers for temporary file. Since this is 160 | * sizeof (char) * (INCORB + 1) * BUFSIZ, it should not be too 161 | * large. 162 | * 163 | * If not defined, no in-core buffers are used. 164 | */ 165 | #ifdef VMUNIX 166 | #if (BUFSIZ - 0) <= 16384 167 | #define INCORB (65536/BUFSIZ) 168 | #else /* Huge-memory systems. */ 169 | #define INCORB 4 170 | #endif /* Huge-memory systems. */ 171 | #endif /* VMUNIX */ 172 | 173 | /* 174 | * Except on VMUNIX, these are a ridiculously small due to the 175 | * lousy arglist processing implementation which fixes core 176 | * proportional to them. Argv (and hence NARGS) is really unnecessary, 177 | * and argument character space not needed except when 178 | * arguments exist. Argument lists should be saved before the "zero" 179 | * of the incore line information and could then 180 | * be reasonably large. 181 | */ 182 | #undef NCARGS 183 | #ifndef VMUNIX 184 | #define NARGS 100 /* Maximum number of names in "next" */ 185 | #define NCARGS 512 /* Maximum arglist chars in "next" */ 186 | #else 187 | #define NCARGS 5120 188 | #define NARGS (NCARGS/6) 189 | #endif 190 | 191 | /* 192 | * Output column (and line) are set to this value on cursor addressible 193 | * terminals when we lose track of the cursor to force cursor 194 | * addressing to occur. 195 | */ 196 | #define UKCOL -20 /* Prototype unknown column */ 197 | 198 | /* 199 | * Attention is the interrupt character (normally 0177 -- delete). 200 | * Quit is the quit signal (normally FS -- control-\) and quits open/visual. 201 | */ 202 | extern int ATTN; 203 | #define QUIT ('\\' & 037) 204 | 205 | #define LRGINT INT_MAX /* largest normal length positive integer */ 206 | 207 | #ifdef LONG_BIT 208 | #if (LONG_BIT > 32) 209 | #define MAXOCT 22 /* Maximum octal digits in a long */ 210 | #define BIG 10000000000000000000UL /* largest power of 10 < uns. long */ 211 | #define MAXDIGS 20 /* number of digits in BIG */ 212 | #else /* LONG_BIT <= 32 */ 213 | #define MAXOCT 11 /* Maximum octal digits in a long */ 214 | #define BIG 1000000000UL /* largest power of 10 < unsigned long */ 215 | #define MAXDIGS 10 /* number of digits in BIG */ 216 | #endif /* LONG_BIT <= 32 */ 217 | #else /* !LONG_BIT */ 218 | #define MAXOCT 11 /* Maximum octal digits in a long */ 219 | #define BIG 1000000000 /* largest power of 10 < unsigned long */ 220 | #define MAXDIGS 10 /* number of digits in BIG */ 221 | #endif /* !LONG_BIT */ 222 | -------------------------------------------------------------------------------- /ex_vars.h: -------------------------------------------------------------------------------- 1 | /* sccs id @(#)ex_vars.h makeoptions 1.8 (gritter) 7/1/02 */ 2 | #define AUTOINDENT 0 3 | #define AUTOPRINT 1 4 | #define AUTOWRITE 2 5 | #define BEAUTIFY 3 6 | #define DIRECTORY 4 7 | #define EDCOMPATIBLE 5 8 | #define ERRORBELLS 6 9 | #define EXRC 7 10 | #define FLASH 8 11 | #define HARDTABS 9 12 | #define IGNORECASE 10 13 | #define LISP 11 14 | #define LIST 12 15 | #define MAGIC 13 16 | #define MESG 14 17 | #define MODELINES 15 18 | #define NUMBER 16 19 | #define OPEN 17 20 | #define OPTIMIZE 18 21 | #define PARAGRAPHS 19 22 | #define PROMPT 20 23 | #define READONLY 21 24 | #define REDRAW 22 25 | #define REMAP 23 26 | #define REPORT 24 27 | #define SCROLL 25 28 | #define SECTIONS 26 29 | #define SHELL 27 30 | #define SHIFTWIDTH 28 31 | #define SHOWMATCH 29 32 | #define SHOWMODE 30 33 | #define SLOWOPEN 31 34 | #define SOURCEANY 32 35 | #define TABSTOP 33 36 | #define TAGLENGTH 34 37 | #define TAGS 35 38 | #define TERM 36 39 | #define TERSE 37 40 | #define TIMEOUT 38 41 | #define TTYTYPE 39 42 | #define WARN 40 43 | #define WINDOW 41 44 | #define WRAPSCAN 42 45 | #define WRAPMARGIN 43 46 | #define WRITEANY 44 47 | 48 | #define NOPTS 45 49 | -------------------------------------------------------------------------------- /ex_version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 42 | * 43 | * Redistribution and use in source and binary forms, with or without 44 | * modification, are permitted provided that the following conditions 45 | * are met: 46 | * Redistributions of source code and documentation must retain the 47 | * above copyright notice, this list of conditions and the following 48 | * disclaimer. 49 | * Redistributions in binary form must reproduce the above copyright 50 | * notice, this list of conditions and the following disclaimer in the 51 | * documentation and/or other materials provided with the distribution. 52 | * All advertising materials mentioning features or use of this software 53 | * must display the following acknowledgement: 54 | * This product includes software developed or owned by Caldera 55 | * International, Inc. 56 | * Neither the name of Caldera International, Inc. nor the names of 57 | * other contributors may be used to endorse or promote products 58 | * derived from this software without specific prior written permission. 59 | * 60 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 61 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 62 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 64 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 65 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 68 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 69 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 70 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 71 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | * 73 | * Sccsid @(#)ex_version.c 1.146 (gritter) 12/25/06 74 | */ 75 | 76 | #include "ex.h" 77 | 78 | static char *versionstring = "@(#)Version 4.1.3 (gritter) 11/14/16"; 79 | 80 | void 81 | printver(void) 82 | { 83 | ex_printf("%s%s%s", versionstring + 4, 84 | #ifdef BIT8 85 | "", "" 86 | #else 87 | ",", "@(#) 7bit" + 4 88 | #endif 89 | ); 90 | } 91 | /* SLIST */ 92 | /* 93 | ex.c:static char sccsid[] = "@(#)ex.c 1.37 (gritter) 8/4/05"; 94 | ex.h: * Sccsid @(#)ex.h 1.57 (gritter) 8/6/05 95 | ex_addr.c:static char sccsid[] = "@(#)ex_addr.c 1.11 (gritter) 8/4/05"; 96 | ex_argv.h: * Sccsid @(#)ex_argv.h 1.9 (gritter) 8/4/05 97 | ex_cmds.c:static char sccsid[] = "@(#)ex_cmds.c 1.22 (gritter) 2/18/05"; 98 | ex_cmds2.c:static char sccsid[] = "@(#)ex_cmds2.c 1.18 (gritter) 2/17/05"; 99 | ex_cmdsub.c:static char sccsid[] = "@(#)ex_cmdsub.c 1.32 (gritter) 8/6/05"; 100 | ex_data.c:static char sccsid[] = "@(#)ex_data.c 1.14 (gritter) 11/23/04"; 101 | ex_extern.c:static char sccsid[] = "@(#)ex_extern.c 1.6 (gritter) 11/23/04"; 102 | ex_get.c:static char sccsid[] = "@(#)ex_get.c 1.18 (gritter) 8/4/05"; 103 | ex_io.c:static char sccsid[] = "@(#)ex_io.c 1.42 (gritter) 8/4/05"; 104 | ex_proto.h: * Sccsid @(#)ex_proto.h 1.33 (gritter) 8/6/05 105 | ex_put.c:static char sccsid[] = "@(#)ex_put.c 1.35 (gritter) 12/25/06"; 106 | ex_re.c:static char sccsid[] = "@(#)ex_re.c 1.60 (gritter) 8/6/05"; 107 | ex_re.h: * Sccsid @(#)ex_re.h 1.24 (gritter) 8/4/05 108 | ex_set.c:static char sccsid[] = "@(#)ex_set.c 1.11 (gritter) 11/24/04"; 109 | ex_subr.c:static char sccsid[] = "@(#)ex_subr.c 1.41 (gritter) 12/25/06"; 110 | ex_tagio.c:static char sccsid[] = "@(#)ex_tagio.c 1.12 (gritter) 8/4/05"; 111 | ex_temp.c:static char sccsid[] = "@(#)ex_temp.c 1.27 (gritter) 12/25/06"; 112 | ex_temp.h: * Sccsid @(#)ex_temp.h 1.10 (gritter) 8/4/05 113 | ex_tty.c:static char sccsid[] = "@(#)ex_tty.c 1.30 (gritter) 8/4/05"; 114 | ex_tty.h: * Sccsid @(#)ex_tty.h 1.14 (gritter) 8/4/05 115 | ex_tune.h: * Sccsid @(#)ex_tune.h 1.14 (gritter) 8/4/05 116 | ex_unix.c:static char sccsid[] = "@(#)ex_unix.c 1.17 (gritter) 8/4/05"; 117 | ex_v.c:static char sccsid[] = "@(#)ex_v.c 1.19 (gritter) 8/4/05"; 118 | ex_vadj.c:static char sccsid[] = "@(#)ex_vadj.c 1.16 (gritter) 8/6/05"; 119 | ex_vget.c:static char sccsid[] = "@(#)ex_vget.c 1.31 (gritter) 8/6/05"; 120 | ex_vis.h: * Sccsid @(#)ex_vis.h 1.22 (gritter) 8/6/05 121 | ex_vmain.c:static char sccsid[] = "@(#)ex_vmain.c 1.34 (gritter) 8/6/05"; 122 | ex_voper.c:static char sccsid[] = "@(#)ex_voper.c 1.28 (gritter) 8/6/05"; 123 | ex_vops.c:static char sccsid[] = "@(#)ex_vops.c 1.28 (gritter) 8/4/05"; 124 | ex_vops2.c:static char sccsid[] = "@(#)ex_vops2.c 1.36 (gritter) 12/25/06"; 125 | ex_vops3.c:static char sccsid[] = "@(#)ex_vops3.c 1.21 (gritter) 8/4/05"; 126 | ex_vput.c:static char sccsid[] = "@(#)ex_vput.c 1.52 (gritter) 12/25/06"; 127 | ex_vwind.c:static char sccsid[] = "@(#)ex_vwind.c 1.9 (gritter) 11/23/04"; 128 | expreserve.c:static char sccsid[] UNUSED = "@(#)expreserve.c 1.23 (gritter) 11/27/04"; 129 | exrecover.c:static char sccsid[] UNUSED = "@(#)exrecover.c 1.23 (gritter) 12/25/06"; 130 | mapmalloc.c: * Sccsid @(#)mapmalloc.c 1.7 (gritter) 8/18/05 131 | printf.c:static char sccsid[] = "@(#)printf.c 1.15 (gritter) 12/1/04"; 132 | */ 133 | -------------------------------------------------------------------------------- /libterm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This code contains changes by 3 | # Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | # 5 | # Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | # to these changes. 7 | # 8 | # 9 | # Copyright (c) 1980, 1993 10 | # The Regents of the University of California. 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 | # 1. Redistributions of source code must retain the above copyright 16 | # notice, this list of conditions and the following disclaimer. 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 | # 3. All advertising materials mentioning features or use of this software 21 | # must display the following acknowledgement: 22 | # This product includes software developed by the University of 23 | # California, Berkeley and its contributors. 24 | # 4. 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 | # from Makefile 5.1 (Berkeley) 6/5/85 41 | # 42 | # Sccsid @(#)Makefile 1.2 (gritter) 2/4/02 43 | # 44 | 45 | LIB = libtermlib.a 46 | DEFS = -DCM_N -DCM_GT -DCM_B -DCM_D 47 | SRCS = termcap.c tgoto.c tputs.c 48 | OBJS = $(SRCS:.c=.o) 49 | 50 | .c.o: 51 | # COPT comes from ex 52 | $(CC) $(CFLAGS) $(DEFS) $(COPT) -c $< 53 | 54 | all: $(LIB) 55 | 56 | $(LIB): $(OBJS) 57 | $(AR) crs $@ $(OBJS) 58 | 59 | clean: 60 | rm -f $(LIB) $(OBJS) core 61 | 62 | # DO NOT DELETE 63 | 64 | termcap.o: libterm.h 65 | tgoto.o: libterm.h 66 | tputs.o: libterm.h 67 | -------------------------------------------------------------------------------- /libterm/libterm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | * 41 | * Header for termcap routines derived from 2.11 BSD. 42 | * 43 | * Sccsid @(#)libterm.h 1.4 (gritter) 11/23/04 44 | */ 45 | 46 | /* 47 | * Size of the capability buffer string. 48 | */ 49 | #define TCBUFSIZE 2048 50 | 51 | int tgetent(char *, const char *); 52 | int tgetnum(char *); 53 | int tgetflag(char *); 54 | char *tgetstr(char *, char **); 55 | char *tgoto(char *, int, int); 56 | int tputs(const char *, int, int (*)(int)); 57 | -------------------------------------------------------------------------------- /libterm/termcap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | 41 | #ifndef lint 42 | #ifdef DOSCCS 43 | static char *sccsid = "@(#)termcap.c 1.7 (gritter) 11/23/04"; 44 | #endif 45 | #endif 46 | 47 | /* from termcap.c 5.1 (Berkeley) 6/5/85 */ 48 | 49 | #if 0 /* GR */ 50 | #define TCBUFSIZE 1024 51 | #else 52 | #include "libterm.h" 53 | #endif 54 | #define E_TERMCAP "/etc/termcap" 55 | #define MAXHOP 32 /* max number of tc= indirections */ 56 | 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | /* 66 | * termcap - routines for dealing with the terminal capability data base 67 | * 68 | * BUG: Should use a "last" pointer in tbuf, so that searching 69 | * for capabilities alphabetically would not be a n**2/2 70 | * process when large numbers of capabilities are given. 71 | * Note: If we add a last pointer now we will screw up the 72 | * tc capability. We really should compile termcap. 73 | * 74 | * Essentially all the work here is scanning and decoding escapes 75 | * in string capabilities. We don't use stdio because the editor 76 | * doesn't, and because living w/o it is not hard. 77 | */ 78 | 79 | static char *tbuf; 80 | static int hopcount; /* detect infinite loops in termcap, init 0 */ 81 | 82 | static int tnamatch(const char *); 83 | static int tnchktc(void); 84 | static char *tskip(register const char *); 85 | static char *tdecode(register char *, char **); 86 | 87 | /* 88 | * Tnamatch deals with name matching. The first field of the termcap 89 | * entry is a sequence of names separated by |'s, so we compare 90 | * against each such name. The normal : terminator after the last 91 | * name (before the first field) stops us. 92 | */ 93 | static int 94 | tnamatch(const char *np) 95 | { 96 | register const char *Np; 97 | register char *Bp; 98 | 99 | Bp = tbuf; 100 | if (*Bp == '#') 101 | return(0); 102 | for (;;) { 103 | for (Np = np; *Np && *Bp == *Np; Bp++, Np++) 104 | continue; 105 | if (*Np == 0 && (*Bp == '|' || *Bp == ':' || *Bp == 0)) 106 | return (1); 107 | while (*Bp && *Bp != ':' && *Bp != '|') 108 | Bp++; 109 | if (*Bp == 0 || *Bp == ':') 110 | return (0); 111 | Bp++; 112 | } 113 | } 114 | 115 | /* 116 | * tnchktc: check the last entry, see if it's tc=xxx. If so, 117 | * recursively find xxx and append that entry (minus the names) 118 | * to take the place of the tc=xxx entry. This allows termcap 119 | * entries to say "like an HP2621 but doesn't turn on the labels". 120 | * Note that this works because of the left to right scan. 121 | */ 122 | static int 123 | tnchktc(void) 124 | { 125 | register char *p, *q; 126 | char tcname[16]; /* name of similar terminal */ 127 | char tcbuf[TCBUFSIZE]; 128 | char rmbuf[TCBUFSIZE]; 129 | char *holdtbuf = tbuf, *holdtc; 130 | int l; 131 | 132 | p = tbuf; 133 | while (*p) { 134 | holdtc = p = tskip(p); 135 | if (!*p) 136 | break; 137 | if (*p++ != 't' || *p == 0 || *p++ != 'c') 138 | continue; 139 | if (*p++ != '=') { 140 | bad: write(2, "Bad termcap entry\n", 18); 141 | return (0); 142 | } 143 | for (q = tcname; *p && *p != ':'; p++) { 144 | if (q >= &tcname[sizeof tcname - 1]) 145 | goto bad; 146 | *q++ = *p; 147 | } 148 | *q = '\0'; 149 | if (++hopcount > MAXHOP) { 150 | write(2, "Infinite tc= loop\n", 18); 151 | return (0); 152 | } 153 | if (tgetent(tcbuf, tcname) != 1) { 154 | hopcount = 0; /* unwind recursion */ 155 | return(0); 156 | } 157 | hopcount--; 158 | tbuf = holdtbuf; 159 | strcpy(rmbuf, &p[1]); 160 | for (q=tcbuf; *q != ':'; q++) 161 | ; 162 | l = holdtc - holdtbuf + strlen(rmbuf) + strlen(q); 163 | if (l > TCBUFSIZE) { 164 | write(2, "Termcap entry too long\n", 23); 165 | break; 166 | } 167 | q++; 168 | for (p = holdtc; *q; q++) 169 | *p++ = *q; 170 | strcpy(p, rmbuf); 171 | p = holdtc; 172 | } 173 | return(1); 174 | } 175 | 176 | /* 177 | * Get an entry for terminal name in buffer bp, 178 | * from the termcap file. Parse is very rudimentary; 179 | * we just notice escaped newlines. 180 | */ 181 | int 182 | tgetent(char *bp, const char *name) 183 | { 184 | register char *cp; 185 | register int c; 186 | register int i = 0, cnt = 0; 187 | char ibuf[TCBUFSIZE]; 188 | int tf; 189 | 190 | tbuf = bp; 191 | tf = -1; 192 | #ifndef V6 193 | cp = getenv("TERMCAP"); 194 | /* 195 | * TERMCAP can have one of two things in it. It can be the 196 | * name of a file to use instead of /etc/termcap. In this 197 | * case it better start with a "/". Or it can be an entry to 198 | * use so we don't have to read the file. In this case it 199 | * has to already have the newlines crunched out. 200 | */ 201 | if (cp && *cp) { 202 | if (*cp == '/') { 203 | tf = open(cp, 0); 204 | } else { 205 | tbuf = cp; 206 | c = tnamatch(name); 207 | tbuf = bp; 208 | if (c) { 209 | strcpy(bp,cp); 210 | return(tnchktc()); 211 | } 212 | } 213 | } 214 | if (tf < 0) 215 | tf = open(E_TERMCAP, 0); 216 | #else 217 | tf = open(E_TERMCAP, 0); 218 | #endif 219 | if (tf < 0) 220 | return (-1); 221 | for (;;) { 222 | cp = bp; 223 | for (;;) { 224 | if (i == cnt) { 225 | cnt = read(tf, ibuf, TCBUFSIZE); 226 | if (cnt <= 0) { 227 | close(tf); 228 | return (0); 229 | } 230 | i = 0; 231 | } 232 | c = ibuf[i++]; 233 | if (c == '\n') { 234 | if (cp > bp && cp[-1] == '\\'){ 235 | cp--; 236 | continue; 237 | } 238 | break; 239 | } 240 | if (cp >= bp+TCBUFSIZE) { 241 | write(2,"Termcap entry too long\n", 23); 242 | break; 243 | } else 244 | *cp++ = c; 245 | } 246 | *cp = 0; 247 | 248 | /* 249 | * The real work for the match. 250 | */ 251 | if (tnamatch(name)) { 252 | close(tf); 253 | return(tnchktc()); 254 | } 255 | } 256 | } 257 | 258 | /* 259 | * Skip to the next field. Notice that this is very dumb, not 260 | * knowing about \: escapes or any such. If necessary, :'s can be put 261 | * into the termcap file in octal. 262 | */ 263 | static char * 264 | tskip(register const char *bp) 265 | { 266 | 267 | while (*bp && *bp != ':') 268 | bp++; 269 | if (*bp == ':') 270 | bp++; 271 | return (char *)bp; 272 | } 273 | 274 | /* 275 | * Return the (numeric) option id. 276 | * Numeric options look like 277 | * li#80 278 | * i.e. the option string is separated from the numeric value by 279 | * a # character. If the option is not found we return -1. 280 | * Note that we handle octal numbers beginning with 0. 281 | */ 282 | int 283 | tgetnum(char *id) 284 | { 285 | register int i, base; 286 | register char *bp = tbuf; 287 | 288 | for (;;) { 289 | bp = tskip(bp); 290 | if (*bp == 0) 291 | return (-1); 292 | if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1]) 293 | continue; 294 | if (*bp == '@') 295 | return(-1); 296 | if (*bp != '#') 297 | continue; 298 | bp++; 299 | base = 10; 300 | if (*bp == '0') 301 | base = 8; 302 | i = 0; 303 | while (isdigit((*bp & 0377))) 304 | i *= base, i += *bp++ - '0'; 305 | return (i); 306 | } 307 | } 308 | 309 | /* 310 | * Handle a flag option. 311 | * Flag options are given "naked", i.e. followed by a : or the end 312 | * of the buffer. Return 1 if we find the option, or 0 if it is 313 | * not given. 314 | */ 315 | int 316 | tgetflag(char *id) 317 | { 318 | register char *bp = tbuf; 319 | 320 | for (;;) { 321 | bp = tskip(bp); 322 | if (!*bp) 323 | return (0); 324 | if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) { 325 | if (!*bp || *bp == ':') 326 | return (1); 327 | else if (*bp == '@') 328 | return(0); 329 | } 330 | } 331 | } 332 | 333 | /* 334 | * Get a string valued option. 335 | * These are given as 336 | * cl=^Z 337 | * Much decoding is done on the strings, and the strings are 338 | * placed in area, which is a ref parameter which is updated. 339 | * No checking on area overflow. 340 | */ 341 | char * 342 | tgetstr(char *id, char **area) 343 | { 344 | register char *bp = tbuf; 345 | 346 | for (;;) { 347 | bp = tskip(bp); 348 | if (!*bp) 349 | return (0); 350 | if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1]) 351 | continue; 352 | if (*bp == '@') 353 | return(0); 354 | if (*bp != '=') 355 | continue; 356 | bp++; 357 | return (tdecode(bp, area)); 358 | } 359 | } 360 | 361 | /* 362 | * Tdecode does the grung work to decode the 363 | * string capability escapes. 364 | */ 365 | static char * 366 | tdecode(register char *str, char **area) 367 | { 368 | register char *cp; 369 | register int c; 370 | register char *dp; 371 | int i; 372 | 373 | cp = *area; 374 | while ((c = *str++) && c != ':') { 375 | switch (c) { 376 | 377 | case '^': 378 | c = *str++ & 037; 379 | break; 380 | 381 | case '\\': 382 | dp = "E\033^^\\\\::n\nr\rt\tb\bf\f"; 383 | c = *str++; 384 | nextc: 385 | if (*dp++ == c) { 386 | c = *dp++; 387 | break; 388 | } 389 | dp++; 390 | if (*dp) 391 | goto nextc; 392 | if (isdigit(c)) { 393 | c -= '0', i = 2; 394 | do 395 | c <<= 3, c |= *str++ - '0'; 396 | while (--i && isdigit(*str & 0377)); 397 | } 398 | break; 399 | } 400 | *cp++ = c; 401 | } 402 | *cp++ = 0; 403 | str = *area; 404 | *area = cp; 405 | return (str); 406 | } 407 | 408 | /* 409 | static const char sccssl[] = "@(#)libterm.sl 1.7 (gritter) 11/23/04"; 410 | */ 411 | -------------------------------------------------------------------------------- /libterm/tgoto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | 41 | #ifndef lint 42 | #ifdef DOSCCS 43 | static char *sccsid = "@(#)tgoto.c 1.3 (gritter) 11/23/04"; 44 | #endif 45 | #endif 46 | 47 | /* from tgoto.c 5.1 (Berkeley) 6/5/85 */ 48 | 49 | #include "libterm.h" 50 | 51 | #define CTRL(c) (c & 037) 52 | 53 | #define MAXRETURNSIZE 64 54 | 55 | #ifdef __STDC__ 56 | #include 57 | #endif 58 | 59 | char *UP; 60 | char *BC; 61 | 62 | /* 63 | * Routine to perform cursor addressing. 64 | * CM is a string containing printf type escapes to allow 65 | * cursor addressing. We start out ready to print the destination 66 | * line, and switch each time we print row or column. 67 | * The following escapes are defined for substituting row/column: 68 | * 69 | * %d as in printf 70 | * %2 like %2d 71 | * %3 like %3d 72 | * %. gives %c hacking special case characters 73 | * %+x like %c but adding x first 74 | * 75 | * The codes below affect the state but don't use up a value. 76 | * 77 | * %>xy if value > x add y 78 | * %r reverses row/column 79 | * %i increments row/column (for one origin indexing) 80 | * %% gives % 81 | * %B BCD (2 decimal digits encoded in one byte) 82 | * %D Delta Data (backwards bcd) 83 | * 84 | * all other characters are ``self-inserting''. 85 | */ 86 | char * 87 | tgoto(char *CM, int destcol, int destline) 88 | { 89 | static char result[MAXRETURNSIZE]; 90 | static char added[10]; 91 | char *cp = CM; 92 | register char *dp = result; 93 | register int c; 94 | int oncol = 0; 95 | register int which = destline; 96 | 97 | if (cp == 0) { 98 | toohard: 99 | /* 100 | * ``We don't do that under BOZO's big top'' 101 | */ 102 | return ("OOPS"); 103 | } 104 | added[0] = 0; 105 | while ((c = *cp++)) { 106 | if (c != '%') { 107 | *dp++ = c; 108 | continue; 109 | } 110 | switch (c = *cp++) { 111 | 112 | #ifdef CM_N 113 | case 'n': 114 | destcol ^= 0140; 115 | destline ^= 0140; 116 | goto setwhich; 117 | #endif 118 | 119 | case 'd': 120 | if (which < 10) 121 | goto one; 122 | if (which < 100) 123 | goto two; 124 | /* fall into... */ 125 | 126 | case '3': 127 | *dp++ = (which / 100) | '0'; 128 | which %= 100; 129 | /* fall into... */ 130 | 131 | case '2': 132 | two: 133 | *dp++ = which / 10 | '0'; 134 | one: 135 | *dp++ = which % 10 | '0'; 136 | swap: 137 | oncol = 1 - oncol; 138 | setwhich: 139 | which = oncol ? destcol : destline; 140 | continue; 141 | 142 | #ifdef CM_GT 143 | case '>': 144 | if (which > *cp++) 145 | which += *cp++; 146 | else 147 | cp++; 148 | continue; 149 | #endif 150 | 151 | case '+': 152 | which += *cp++; 153 | /* fall into... */ 154 | 155 | case '.': 156 | /* casedot: */ 157 | /* 158 | * This code is worth scratching your head at for a 159 | * while. The idea is that various weird things can 160 | * happen to nulls, EOT's, tabs, and newlines by the 161 | * tty driver, arpanet, and so on, so we don't send 162 | * them if we can help it. 163 | * 164 | * Tab is taken out to get Ann Arbors to work, otherwise 165 | * when they go to column 9 we increment which is wrong 166 | * because bcd isn't continuous. We should take out 167 | * the rest too, or run the thing through more than 168 | * once until it doesn't make any of these, but that 169 | * would make termlib (and hence pdp-11 ex) bigger, 170 | * and also somewhat slower. This requires all 171 | * programs which use termlib to stty tabs so they 172 | * don't get expanded. They should do this anyway 173 | * because some terminals use ^I for other things, 174 | * like nondestructive space. 175 | */ 176 | if (which == 0 || which == CTRL('d') || /* which == '\t' || */ which == '\n') { 177 | if (oncol || UP) /* Assumption: backspace works */ 178 | /* 179 | * Loop needed because newline happens 180 | * to be the successor of tab. 181 | */ 182 | do { 183 | strcat(added, oncol ? (BC ? BC : "\b") : UP); 184 | which++; 185 | } while (which == '\n'); 186 | } 187 | *dp++ = which; 188 | goto swap; 189 | 190 | case 'r': 191 | oncol = 1; 192 | goto setwhich; 193 | 194 | case 'i': 195 | destcol++; 196 | destline++; 197 | which++; 198 | continue; 199 | 200 | case '%': 201 | *dp++ = c; 202 | continue; 203 | 204 | #ifdef CM_B 205 | case 'B': 206 | which = (which/10 << 4) + which%10; 207 | continue; 208 | #endif 209 | 210 | #ifdef CM_D 211 | case 'D': 212 | which = which - 2 * (which%16); 213 | continue; 214 | #endif 215 | 216 | default: 217 | goto toohard; 218 | } 219 | } 220 | strcpy(dp, added); 221 | return (result); 222 | } 223 | -------------------------------------------------------------------------------- /libterm/tputs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code contains changes by 3 | * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 4 | * 5 | * Conditions 1, 2, and 4 and the no-warranty notice below apply 6 | * to these changes. 7 | * 8 | * 9 | * Copyright (c) 1980, 1993 10 | * The Regents of the University of California. 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 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 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 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the University of 23 | * California, Berkeley and its contributors. 24 | * 4. 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 | 41 | #ifndef lint 42 | #ifdef DOSCCS 43 | static char *sccsid = "@(#)tputs.c 1.4 (gritter) 11/23/04"; 44 | #endif 45 | #endif 46 | 47 | /* from tputs.c 5.1 (Berkeley) 6/5/85 */ 48 | 49 | #include 50 | 51 | #include "libterm.h" 52 | 53 | /* 54 | * The following array gives the number of tens of milliseconds per 55 | * character for each speed as returned by gtty. Thus since 300 56 | * baud returns a 7, there are 33.3 milliseconds per char at 300 baud. 57 | */ 58 | static 59 | short tmspc10[] = { 60 | 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5 61 | }; 62 | 63 | short ospeed; 64 | char PC; 65 | 66 | /* 67 | * Put the character string cp out, with padding. 68 | * The number of affected lines is affcnt, and the routine 69 | * used to output one character is outc. 70 | */ 71 | int 72 | tputs(const char *cp, int affcnt, int (*outc)(int)) 73 | { 74 | register int i = 0; 75 | register int mspc10; 76 | 77 | if (cp == 0) 78 | return 1; 79 | 80 | /* 81 | * Convert the number representing the delay. 82 | */ 83 | if (isdigit(*cp & 0377)) { 84 | do 85 | i = i * 10 + *cp++ - '0'; 86 | while (isdigit(*cp & 0377)); 87 | } 88 | i *= 10; 89 | if (*cp == '.') { 90 | cp++; 91 | if (isdigit(*cp & 0377)) 92 | i += *cp - '0'; 93 | /* 94 | * Only one digit to the right of the decimal point. 95 | */ 96 | while (isdigit(*cp & 0377)) 97 | cp++; 98 | } 99 | 100 | /* 101 | * If the delay is followed by a `*', then 102 | * multiply by the affected lines count. 103 | */ 104 | if (*cp == '*') 105 | cp++, i *= affcnt; 106 | 107 | /* 108 | * The guts of the string. 109 | */ 110 | while (*cp) 111 | (*outc)(*cp++); 112 | 113 | /* 114 | * If no delay needed, or output speed is 115 | * not comprehensible, then don't try to delay. 116 | */ 117 | if (i == 0) 118 | return 1; 119 | if (ospeed <= 0 || ospeed >= (int)(sizeof tmspc10 / sizeof tmspc10[0])) 120 | return 1; 121 | 122 | /* 123 | * Round up by a half a character frame, 124 | * and then do the delay. 125 | * Too bad there are no user program accessible programmed delays. 126 | * Transmitting pad characters slows many 127 | * terminals down and also loads the system. 128 | */ 129 | mspc10 = tmspc10[ospeed]; 130 | i += mspc10 / 2; 131 | for (i /= mspc10; i > 0; i--) 132 | (*outc)(PC); 133 | return 1; 134 | } 135 | -------------------------------------------------------------------------------- /libuxre/CVS/Entries: -------------------------------------------------------------------------------- 1 | /COPYING.LGPL/1.1.1.1/Sat Dec 4 13:51:20 2004// 2 | /Makefile.mk/1.2/Sun Jan 22 21:47:27 2006// 3 | /NOTES/1.1.1.1/Sat Dec 4 13:51:18 2004// 4 | /_collelem.c/1.1.1.1/Sat Dec 4 13:51:19 2004// 5 | /_collmult.c/1.1.1.1/Sat Dec 4 13:51:19 2004// 6 | /bracket.c/1.1.1.1/Sat Dec 4 13:51:19 2004// 7 | /colldata.h/1.1.1.1/Sat Dec 4 13:51:18 2004// 8 | /onefile.c/1.1.1.1/Sat Dec 4 13:51:19 2004// 9 | /re.h/1.2/Sun Feb 6 14:58:27 2005// 10 | /regcomp.c/1.1.1.1/Sat Dec 4 13:51:20 2004// 11 | /regdfa.c/1.1.1.1/Sat Dec 4 13:51:20 2004// 12 | /regdfa.h/1.1.1.1/Sat Dec 4 13:51:20 2004// 13 | /regerror.c/1.1.1.1/Sat Dec 4 13:51:19 2004// 14 | /regex.h/1.2/Sun Feb 6 14:58:27 2005// 15 | /regexec.c/1.2/Sun Feb 6 16:14:00 2005// 16 | /regfree.c/1.1.1.1/Sat Dec 4 13:51:20 2004// 17 | /regnfa.c/1.2/Sun Feb 6 14:58:27 2005// 18 | /regparse.c/1.1.1.1/Sat Dec 4 13:51:19 2004// 19 | /stubs.c/1.3/Sun Jun 26 18:52:43 2005// 20 | /wcharm.h/1.1.1.1/Sat Dec 4 13:51:19 2004// 21 | D 22 | -------------------------------------------------------------------------------- /libuxre/CVS/Repository: -------------------------------------------------------------------------------- 1 | heirloom/libuxre 2 | -------------------------------------------------------------------------------- /libuxre/CVS/Root: -------------------------------------------------------------------------------- 1 | :pserver:anonymous@heirloom.cvs.sourceforge.net:/cvsroot/heirloom 2 | -------------------------------------------------------------------------------- /libuxre/Makefile: -------------------------------------------------------------------------------- 1 | Makefile.mk -------------------------------------------------------------------------------- /libuxre/Makefile.mk: -------------------------------------------------------------------------------- 1 | all: libuxre.a 2 | 3 | #OBJ = bracket.o _collelem.o _collmult.o regcomp.o regdfa.o regerror.o \ 4 | # regexec.o regfree.o regnfa.o regparse.o stubs.o 5 | 6 | OBJ = onefile.o regfree.o regerror.o 7 | 8 | libuxre.a: $(OBJ) 9 | $(AR) crs $@ $(OBJ) 10 | 11 | .c.o: 12 | $(CC) $(CFLAGS2) $(CPPFLAGS) $(XO5FL) $(IWCHAR) $(COPT) -I. -c $< 13 | 14 | install: 15 | 16 | clean: 17 | rm -f libuxre.a $(OBJ) core log *~ 18 | 19 | _collelem.o: colldata.h re.h regex.h wcharm.h 20 | _collmult.o: colldata.h re.h regex.h wcharm.h 21 | bracket.o: colldata.h re.h regex.h wcharm.h 22 | regcomp.o: colldata.h re.h regex.h wcharm.h 23 | regdfa.o: colldata.h regdfa.h re.h regex.h wcharm.h 24 | regerror.o: colldata.h re.h regex.h wcharm.h 25 | regexec.o: colldata.h re.h regex.h wcharm.h 26 | regfree.o: colldata.h re.h regex.h wcharm.h 27 | regnfa.o: colldata.h re.h regex.h wcharm.h 28 | regparse.o: colldata.h re.h regex.h wcharm.h 29 | stubs.o: colldata.h wcharm.h 30 | onefile.o: _collelem.c _collmult.c bracket.c regcomp.c regdfa.c regexec.c 31 | onefile.o: regfree.c regnfa.c regparse.c stubs.c 32 | MRPROPER = libuxre.a 33 | -------------------------------------------------------------------------------- /libuxre/NOTES: -------------------------------------------------------------------------------- 1 | Notes for the modified 'UNIX(R) Regular Expression Library' 2 | ============================================================ 3 | 4 | The code this is based on was released by Caldera as 'osutils-0.1a' 5 | and is available at . Notable 6 | changes include: 7 | 8 | - Support for multibyte characters was enabled again. 9 | - Support for traditional extended regular expression syntax was added. 10 | - Fix: With REG_ICASE, [B-z] matches 'A', 'a', and '[' according to 11 | POSIX.2. 12 | - Some speed improvements. 13 | 14 | Gunnar Ritter 9/22/03 15 | -------------------------------------------------------------------------------- /libuxre/_collelem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)_collelem.c 1.4 (gritter) 10/18/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | #include "colldata.h" 30 | #include 31 | 32 | #define CCE(p) ((const CollElem *)(p)) 33 | #define CCM(p) ((const CollMult *)(p)) 34 | 35 | LIBUXRE_STATIC const CollElem * 36 | libuxre_collelem(struct lc_collate *col, CollElem *spare, wchar_t wc) 37 | { 38 | const char *tbl; 39 | size_t hi, lo, cur; 40 | const CollMult *cmp; 41 | const CollElem *cep; 42 | long diff; 43 | int sz; 44 | 45 | /* 46 | * ELEM_ENCODED is returned when the collation is entirely 47 | * based on the encoded value of the character. 48 | */ 49 | if (col == 0 || col->flags & CHF_ENCODED 50 | || (tbl = (const char *)col->maintbl) == 0) 51 | { 52 | return ELEM_ENCODED; 53 | } 54 | if ((wuchar_type)wc <= UCHAR_MAX) 55 | { 56 | indexed:; 57 | cep = CCE(&tbl[(wuchar_type)wc * col->elemsize]); 58 | if (cep->weight[0] == WGHT_SPECIAL) 59 | return ELEM_BADCHAR; 60 | return cep; 61 | } 62 | if (col->flags & CHF_INDEXED) 63 | { 64 | if ((wuchar_type)wc >= col->nmain) 65 | return ELEM_BADCHAR; 66 | goto indexed; 67 | } 68 | /* 69 | * Binary search for a match. Could speed up the search if 70 | * some interpolation was used, but keep it simple for now. 71 | * Note that this is actually a table of CollMult's. 72 | * 73 | * To save space in the file, sequences of similar elements 74 | * are sometimes compressed into a single CollMult that 75 | * describes many entries. This is denoted by a subnbeg 76 | * with the SUBN_SPECIAL bit set. The rest of the bits give 77 | * the range covered by this entry. 78 | */ 79 | sz = col->elemsize + (sizeof(CollMult) - sizeof(CollElem)); 80 | tbl += (1 + UCHAR_MAX) * col->elemsize; 81 | lo = 0; 82 | hi = col->nmain - UCHAR_MAX; 83 | while (lo < hi) 84 | { 85 | if ((cur = (hi + lo) >> 1) < lo) /* hi+lo overflowed */ 86 | cur |= ~(~(size_t)0 >> 1); /* lost high order bit */ 87 | cmp = CCM(&tbl[cur * sz]); 88 | if ((diff = wc - cmp->ch) < 0) 89 | hi = cur; 90 | else if (cmp->elem.subnbeg & SUBN_SPECIAL) 91 | { 92 | if (diff > (long)(cmp->elem.subnbeg & ~SUBN_SPECIAL)) 93 | lo = cur + 1; 94 | else /* create an entry from the sequence in spare */ 95 | { 96 | spare->multbeg = cmp->elem.multbeg; 97 | spare->subnbeg = 0; 98 | spare->weight[0] = cmp->elem.weight[0] + diff; 99 | for (lo = 1; lo < col->nweight; lo++) 100 | { 101 | wuchar_type w; 102 | 103 | if ((w = cmp->elem.weight[lo]) 104 | == WGHT_SPECIAL) 105 | { 106 | w = spare->weight[0]; 107 | } 108 | spare->weight[lo] = w; 109 | } 110 | return spare; 111 | } 112 | } 113 | else if (diff == 0) 114 | return &cmp->elem; 115 | else 116 | lo = cur + 1; 117 | } 118 | return ELEM_BADCHAR; 119 | } 120 | -------------------------------------------------------------------------------- /libuxre/_collmult.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)_collmult.c 1.4 (gritter) 9/22/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | #include "colldata.h" 30 | #include 31 | 32 | #define CCM(p) ((const CollMult *)(p)) 33 | 34 | LIBUXRE_STATIC const CollElem * 35 | libuxre_collmult(struct lc_collate *col, const CollElem *cep, wchar_t wc) 36 | { 37 | const char *tbl; 38 | size_t sz; 39 | w_type ch; 40 | 41 | if (col == 0 || cep->multbeg == 0 42 | || (tbl = (const char *)col->multtbl) == 0) 43 | { 44 | return ELEM_BADCHAR; 45 | } 46 | sz = col->elemsize + (sizeof(CollMult) - sizeof(CollElem)); 47 | tbl += sz * cep->multbeg; 48 | while ((ch = CCM(tbl)->ch) != wc) 49 | { 50 | if (ch == 0) 51 | return ELEM_BADCHAR; /* end of list */ 52 | tbl += sz; 53 | } 54 | return &CCM(tbl)->elem; 55 | } 56 | -------------------------------------------------------------------------------- /libuxre/colldata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)colldata.h 1.5 (gritter) 5/1/04 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | #ifndef LIBUXRE_COLLDATA_H 29 | #define LIBUXRE_COLLDATA_H 30 | 31 | typedef struct 32 | { 33 | long coll_offst; /* offset to xnd table */ 34 | long sub_cnt; /* length of subnd table */ 35 | long sub_offst; /* offset to subnd table */ 36 | long str_offst; /* offset to strings for subnd table */ 37 | long flags; /* nonzero if reg.exp. used */ 38 | } hd; 39 | 40 | typedef struct 41 | { 42 | unsigned char ch; /* character or number of followers */ 43 | unsigned char pwt; /* primary weight */ 44 | unsigned char swt; /* secondary weight */ 45 | unsigned char ns; /* index of follower state list */ 46 | } xnd; 47 | 48 | typedef struct 49 | { 50 | char *exp; /* expression to be replaced */ 51 | long explen; /* length of expression */ 52 | char *repl; /* replacement string */ 53 | } subnd; 54 | 55 | /*----------------------------------*/ 56 | 57 | #include 58 | #include 59 | /* #include */ 60 | 61 | /* 62 | * Structure of a collation file: 63 | * 1. CollHead (maintbl is 0 if CHF_ENCODED) 64 | * if !CHF_ENCODED then 65 | * 2. CollElem[bytes] (256 for 8 bit bytes) 66 | * 3. if CHF_INDEXED then 67 | * CollElem[wides] (nmain-256 for 8 bit bytes) 68 | * else 69 | * CollMult[wides] 70 | * 4. CollMult[*] (none if multtbl is 0) 71 | * 5. wuchar_type[*] (none if repltbl is 0) 72 | * 6. CollSubn[*] (none if subntbl is 0) 73 | * 7. strings (first is pathname for .so if CHF_DYNAMIC) 74 | * 75 | * The actual location of parts 2 through 7 is not important. 76 | * 77 | * The main table is in encoded value order. 78 | * 79 | * All indeces/offsets must be nonzero to be effective; zero is reserved 80 | * to indicate no-such-entry. This implies either that an unused initial 81 | * entry is placed in each of (4) through (7), or that the "start offset" 82 | * given by the header is artificially pushed back by an entry size. 83 | * 84 | * Note that if CHF_ENCODED is not set, then nweight must be positive. 85 | * 86 | * If an element can begin a multiple character element, it contains a 87 | * nonzero multbeg which is the initial index into (4) for its list; 88 | * the list is terminated by a CollMult with a ch of zero. 89 | * 90 | * If there are elements with the same primary weight (weight[1]), then 91 | * for each such element, it must have a CollMult list. The CollMult 92 | * that terminates the list (ch==0) notes the lowest and highest basic 93 | * weights for those elements with that same primary weight value 94 | * respectively in weight[0] and weight[1]. If there are some basic 95 | * weights between these values that do not have the same primary 96 | * weight--are not in the equivalence class--then the terminator also 97 | * has a SUBN_SPECIAL mark. Note that this list terminator should be 98 | * shared when the elements are not multiple character collating 99 | * elements because they wouldn't otherwise have a CollMult list. 100 | * 101 | * WGHT_IGNORE is used to denote ignored collating elements for a 102 | * particular collation ordering pass. All main table entries other 103 | * than for '\0' will have a non-WGHT_IGNORE weight[0]. However, it is 104 | * possible for a CollMult entries from (4) to have a WGHT_IGNORE 105 | * weight[0]: If, for example, "xyz" is a multiple character collating 106 | * element, but "xy" is not, then the CollMult for "y" will have a 107 | * WGHT_IGNORE weight[0]. Also, WGHT_IGNORE is used to terminate each 108 | * list of replacement weights. 109 | * 110 | * Within (3), it is possible to describe a sequence of unremarkable 111 | * collating elements with a single CollMult entry. If the SUBN_SPECIAL 112 | * bit is set, the rest of subnbeg represents the number of collating 113 | * elements covered by this entry. The weight[0] values are determined 114 | * by adding the difference between the encoded value and the entry's ch 115 | * value to the entry's weight[0]. This value is then substituted for 116 | * any weight[n], n>0 that has only the WGHT_SPECIAL bit set. libuxre_collelem() 117 | * hides any match to such an entry by filling in a "spare" CollElem. 118 | * 119 | * If there are substitution strings, then for each character that begins 120 | * a string, it has a nonzero subnbeg which is similarly the initial 121 | * index into (6). The indeces in (6) refer to offsets within (7). 122 | */ 123 | 124 | #define TOPBIT(t) (((t)1) << (sizeof(t) * CHAR_BIT - 1)) 125 | 126 | #define CHF_ENCODED 0x1 /* collation by encoded values only */ 127 | #define CHF_INDEXED 0x2 /* main table indexed by encoded values */ 128 | #define CHF_MULTICH 0x4 /* a multiple char. coll. elem. exists */ 129 | #define CHF_DYNAMIC 0x8 /* shared object has collation functions */ 130 | 131 | #define CWF_BACKWARD 0x1 /* reversed ordering for this weight */ 132 | #define CWF_POSITION 0x2 /* weight takes position into account */ 133 | 134 | #define CLVERS 1 /* most recent version */ 135 | 136 | #define WGHT_IGNORE 0 /* ignore this collating element */ 137 | #define WGHT_SPECIAL TOPBIT(wuchar_type) 138 | #define SUBN_SPECIAL TOPBIT(unsigned short) 139 | 140 | #ifndef COLL_WEIGHTS_MAX 141 | #define COLL_WEIGHTS_MAX 1 142 | #endif 143 | 144 | typedef struct 145 | { 146 | unsigned long maintbl; /* start of main table */ 147 | unsigned long multtbl; /* start of multi-char table */ 148 | unsigned long repltbl; /* start of replacement weights */ 149 | unsigned long subntbl; /* start of substitutions */ 150 | unsigned long strstbl; /* start of sub. strings */ 151 | unsigned long nmain; /* # entries in main table */ 152 | unsigned short flags; /* CHF_* bits */ 153 | unsigned short version; /* handle future changes */ 154 | unsigned char elemsize; /* # bytes/element (w/padding) */ 155 | unsigned char nweight; /* # weights/element */ 156 | unsigned char order[COLL_WEIGHTS_MAX]; /* CWF_* bits/weight */ 157 | } CollHead; 158 | 159 | typedef struct 160 | { 161 | unsigned short multbeg; /* start of multi-chars */ 162 | unsigned short subnbeg; /* start of substitutions */ 163 | wuchar_type weight[COLL_WEIGHTS_MAX]; 164 | } CollElem; 165 | 166 | typedef struct 167 | { 168 | wchar_t ch; /* "this" character (of sequence) */ 169 | CollElem elem; /* its full information */ 170 | } CollMult; 171 | 172 | typedef struct 173 | { 174 | unsigned short strbeg; /* start of match string */ 175 | unsigned short length; /* length of match string */ 176 | unsigned short repbeg; /* start of replacement */ 177 | } CollSubn; 178 | 179 | struct lc_collate 180 | { 181 | const unsigned char *strstbl; 182 | const wuchar_type *repltbl; 183 | const CollElem *maintbl; 184 | const CollMult *multtbl; 185 | const CollSubn *subntbl; 186 | #ifdef DSHLIB 187 | void *handle; 188 | void (*done)(struct lc_collate *); 189 | int (*strc)(struct lc_collate *, const char *, const char *); 190 | int (*wcsc)(struct lc_collate *, const wchar_t *, const wchar_t *); 191 | size_t (*strx)(struct lc_collate *, char *, const char *, size_t); 192 | size_t (*wcsx)(struct lc_collate *, wchar_t *, const wchar_t *, size_t); 193 | #endif 194 | const char *mapobj; 195 | size_t mapsize; 196 | unsigned long nmain; 197 | short nuse; 198 | unsigned short flags; 199 | unsigned char elemsize; 200 | unsigned char nweight; 201 | unsigned char order[COLL_WEIGHTS_MAX]; 202 | }; 203 | 204 | #define ELEM_BADCHAR ((CollElem *)0) 205 | #define ELEM_ENCODED ((CollElem *)-1) 206 | 207 | /* 208 | LIBUXRE_STATIC int libuxre_old_collate(struct lc_collate *); 209 | LIBUXRE_STATIC int libuxre_strqcoll(struct lc_collate *, const char *, 210 | const char *); 211 | LIBUXRE_STATIC int libuxre_wcsqcoll(struct lc_collate *, const wchar_t *, 212 | const wchar_t *); 213 | */ 214 | extern struct lc_collate *libuxre_lc_collate(struct lc_collate *); 215 | LIBUXRE_STATIC const CollElem *libuxre_collelem(struct lc_collate *, 216 | CollElem *, wchar_t); 217 | LIBUXRE_STATIC const CollElem *libuxre_collmult(struct lc_collate *, 218 | const CollElem *, wchar_t); 219 | /* 220 | LIBUXRE_STATIC const CollElem *libuxre_collmbs(struct lc_collate *, 221 | CollElem *, const unsigned char **); 222 | LIBUXRE_STATIC const CollElem *libuxre_collwcs(struct lc_collate *, 223 | CollElem *, const wchar_t **); 224 | */ 225 | 226 | #endif /* !LIBUXRE_COLLDATA_H */ 227 | -------------------------------------------------------------------------------- /libuxre/onefile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)onefile.c 1.1 (gritter) 9/22/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | #define LIBUXRE_STATIC static 29 | 30 | #include "_collelem.c" 31 | #include "_collmult.c" 32 | #include "stubs.c" 33 | #include "bracket.c" 34 | #include "regdfa.c" 35 | #include "regnfa.c" 36 | #include "regparse.c" 37 | #include "regcomp.c" 38 | #include "regexec.c" 39 | -------------------------------------------------------------------------------- /libuxre/re.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)re.h 1.15 (gritter) 2/6/05 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | #ifndef LIBUXRE_RE_H 29 | #define LIBUXRE_RE_H 30 | 31 | /* 32 | * Maps safe external tag to internal one 33 | */ 34 | #define re_coll_ lc_collate /* */ 35 | /* #define __fnm_collate lc_collate */ /* */ 36 | 37 | #include 38 | #include 39 | /* #include */ 40 | #include 41 | 42 | #define NBSHT (sizeof(unsigned short) * CHAR_BIT) 43 | #define NBYTE (((1 << CHAR_BIT) + NBSHT - 1) / NBSHT) 44 | #define NTYPE 4 45 | #define NWIDE 32 46 | #define NQUIV 4 47 | 48 | typedef struct 49 | { 50 | struct lc_collate *col; /* only member set by caller */ 51 | wctype_t *extype; 52 | wuchar_type *exquiv; 53 | wchar_t *exwide; 54 | wctype_t type[NTYPE]; 55 | wuchar_type quiv[NQUIV]; 56 | wchar_t wide[NWIDE]; 57 | unsigned short byte[NBYTE]; 58 | unsigned short ntype; 59 | unsigned short nquiv; 60 | unsigned short nwide; 61 | unsigned int flags; 62 | } Bracket; 63 | 64 | #define BKT_NEGATED 0x001 /* complemented set */ 65 | #define BKT_ONECASE 0x002 /* uppercase same as lowercase */ 66 | #define BKT_NOTNL 0x004 /* do not match newline when BKT_NEGATED */ 67 | #define BKT_BADRANGE 0x008 /* accept [m-a] ranges as [ma] */ 68 | #define BKT_SEPRANGE 0x010 /* disallow [a-m-z] style ranges */ 69 | #define BKT_NLBAD 0x020 /* newline disallowed */ 70 | #define BKT_SLASHBAD 0x040 /* slash disallowed (for pathnames) */ 71 | #define BKT_EMPTY 0x080 /* take leading ] is end (empty set) */ 72 | #define BKT_ESCAPE 0x100 /* allow \ as quote for next anything */ 73 | #define BKT_QUOTE 0x200 /* allow \ as quote for \\, \^, \- or \] */ 74 | #define BKT_ESCNL 0x400 /* take \n as the newline character */ 75 | #define BKT_ESCSEQ 0x800 /* otherwise, take \ as in C escapes */ 76 | #define BKT_ODDRANGE 0x1000 /* oawk oddity: [m-a] means [m] */ 77 | #define BKT_NOI18N 0x2000 /* disable [::] [==] [..] */ 78 | #define BKT_OLDESC 0x4000 /* enable \b \f \n \r \t only */ 79 | 80 | /* 81 | * These error returns for libuxre_bktmbcomp() are directly tied to 82 | * the error returns for regcomp() for convenience. 83 | */ 84 | #define BKT_BADPAT (-REG_BADPAT) 85 | #define BKT_ECOLLATE (-REG_ECOLLATE) 86 | #define BKT_ECTYPE (-REG_ECTYPE) 87 | #define BKT_EEQUIV (-REG_EEQUIV) 88 | #define BKT_BADCHAR (-REG_EBKTCHAR) 89 | #define BKT_EBRACK (-REG_EBRACK) 90 | #define BKT_EMPTYSUBBKT (-REG_EMPTYSUBBKT) 91 | #define BKT_ERANGE (-REG_ERANGE) 92 | #define BKT_ESPACE (-REG_ESPACE) 93 | #define BKT_BADESC (-REG_BADESC) 94 | #define BKT_ILLSEQ (-REG_ILLSEQ) 95 | 96 | /* 97 | * These must be distinct from the flags in . 98 | */ 99 | #define FNM_COLLATE 0x2000 /* have collation information */ 100 | #define FNM_CURRENT 0x4000 /* have full-sized fnm_t structure */ 101 | 102 | /* 103 | * These must be distinct from the flags in . 104 | */ 105 | #define REG_NFA 0x20000000 106 | #define REG_DFA 0x40000000 107 | #define REG_GOTBKT 0x80000000 108 | 109 | #define BRACE_INF USHRT_MAX 110 | #define BRACE_MAX 5100 /* arbitrary number < SHRT_MAX */ 111 | #define BRACE_DFAMAX 255 /* max amount for r.e. duplication */ 112 | 113 | typedef union /* extra info always kept for some tokens/nodes */ 114 | { 115 | Bracket *bkt; /* ROP_BKT */ 116 | size_t sub; /* ROP_LP (ROP_RP), ROP_REF */ 117 | unsigned short num[2]; /* ROP_BRACE: num[0]=low, num[1]=high */ 118 | } Info; 119 | 120 | typedef struct /* lexical context while parsing */ 121 | { 122 | Info info; 123 | const unsigned char *pat; 124 | unsigned char *clist; 125 | struct lc_collate *col; 126 | unsigned long flags; 127 | w_type tok; 128 | size_t maxref; 129 | size_t nleft; 130 | size_t nright; 131 | size_t nclist; 132 | int bktflags; 133 | int err; 134 | int mb_cur_max; 135 | } Lex; 136 | 137 | typedef struct t_tree Tree; /* RE parse tree node */ 138 | struct t_tree 139 | { 140 | union 141 | { 142 | Tree *ptr; /* unary & binary nodes */ 143 | size_t pos; /* position for DFA leaves */ 144 | } left; 145 | union 146 | { 147 | Tree *ptr; /* binary nodes */ 148 | Info info; 149 | } right; 150 | Tree *parent; 151 | w_type op; /* positive => char. to match */ 152 | }; 153 | 154 | typedef struct re_dfa_ Dfa; /* DFA engine description */ 155 | typedef struct re_nfa_ Nfa; /* NFA engine description */ 156 | 157 | typedef struct 158 | { 159 | const unsigned char *str; 160 | regmatch_t *match; 161 | size_t nmatch; 162 | unsigned long flags; 163 | int mb_cur_max; 164 | } Exec; 165 | 166 | /* 167 | * Regular expression operators. Some only used internally. 168 | * All are negative, to distinguish them from the regular 169 | * "match this particular wide character" operation. 170 | */ 171 | #define BINARY_ROP 0x02 172 | #define UNARY_ROP 0x01 173 | #define LEAF_ROP 0x00 174 | 175 | #define MAKE_ROP(k, v) (-((v) | ((k) << 4))) 176 | #define KIND_ROP(v) ((-(v)) >> 4) 177 | 178 | #define ROP_OR MAKE_ROP(BINARY_ROP, 1) 179 | #define ROP_CAT MAKE_ROP(BINARY_ROP, 2) 180 | 181 | #define ROP_STAR MAKE_ROP(UNARY_ROP, 1) 182 | #define ROP_PLUS MAKE_ROP(UNARY_ROP, 2) 183 | #define ROP_QUEST MAKE_ROP(UNARY_ROP, 3) 184 | #define ROP_BRACE MAKE_ROP(UNARY_ROP, 4) 185 | #define ROP_LP MAKE_ROP(UNARY_ROP, 5) 186 | #define ROP_RP MAKE_ROP(UNARY_ROP, 6) 187 | 188 | #define ROP_NOP MAKE_ROP(LEAF_ROP, 1) /* temporary */ 189 | #define ROP_BOL MAKE_ROP(LEAF_ROP, 2) /* ^ anchor */ 190 | #define ROP_EOL MAKE_ROP(LEAF_ROP, 3) /* $ anchor */ 191 | #define ROP_ALL MAKE_ROP(LEAF_ROP, 4) /* anything (added) */ 192 | #define ROP_ANYCH MAKE_ROP(LEAF_ROP, 5) /* . w/\n */ 193 | #define ROP_NOTNL MAKE_ROP(LEAF_ROP, 6) /* . w/out \n */ 194 | #define ROP_EMPTY MAKE_ROP(LEAF_ROP, 7) /* empty string */ 195 | #define ROP_NONE MAKE_ROP(LEAF_ROP, 8) /* match failure */ 196 | #define ROP_BKT MAKE_ROP(LEAF_ROP, 9) /* [...] */ 197 | #define ROP_BKTCOPY MAKE_ROP(LEAF_ROP, 10) /* [...] (duplicated) */ 198 | #define ROP_LT MAKE_ROP(LEAF_ROP, 11) /* \< word begin */ 199 | #define ROP_GT MAKE_ROP(LEAF_ROP, 12) /* \> word end */ 200 | #define ROP_REF MAKE_ROP(LEAF_ROP, 13) /* \digit */ 201 | #define ROP_END MAKE_ROP(LEAF_ROP, 14) /* final (added) */ 202 | 203 | /* 204 | * Return values: 205 | * libuxre_bktmbcomp() 206 | * <0 error (see BKT_* above); >0 #bytes scanned 207 | * libuxre_bktmbexec() 208 | * <0 doesn't match; >=0 matches, #extra bytes scanned 209 | */ 210 | LIBUXRE_STATIC void libuxre_bktfree(Bracket *); 211 | LIBUXRE_STATIC int libuxre_bktmbcomp(Bracket *, const unsigned char *, 212 | int, int); 213 | LIBUXRE_STATIC int libuxre_bktmbexec(Bracket *, wchar_t, 214 | const unsigned char *, int); 215 | 216 | LIBUXRE_STATIC void libuxre_regdeltree(Tree *, int); 217 | LIBUXRE_STATIC Tree *libuxre_reg1tree(w_type, Tree *); 218 | LIBUXRE_STATIC Tree *libuxre_reg2tree(w_type, Tree *, Tree *); 219 | LIBUXRE_STATIC Tree *libuxre_regparse(Lex *, const unsigned char *, int); 220 | 221 | extern void libuxre_regdeldfa(Dfa *); 222 | LIBUXRE_STATIC int libuxre_regdfacomp(regex_t *, Tree *, Lex *); 223 | LIBUXRE_STATIC int libuxre_regdfaexec(Dfa *, Exec *); 224 | 225 | extern void libuxre_regdelnfa(Nfa *); 226 | LIBUXRE_STATIC int libuxre_regnfacomp(regex_t *, Tree *, Lex *); 227 | LIBUXRE_STATIC int libuxre_regnfaexec(Nfa *, Exec *); 228 | #endif /* !LIBUXRE_RE_H */ 229 | -------------------------------------------------------------------------------- /libuxre/regcomp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)regcomp.c 1.6 (gritter) 9/22/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | #include "re.h" 30 | 31 | /* #pragma weak regcomp = _regcomp */ 32 | 33 | int 34 | regcomp(regex_t *ep, const char *pat, int flags) 35 | { 36 | Tree *tp; 37 | Lex lex; 38 | 39 | if ((tp=libuxre_regparse(&lex, (const unsigned char *)pat, flags)) == 0) 40 | goto out; 41 | ep->re_nsub = lex.nleft; 42 | ep->re_flags = lex.flags & ~(REG_NOTBOL | REG_NOTEOL | REG_NONEMPTY); 43 | ep->re_col = lex.col; 44 | ep->re_mb_cur_max = lex.mb_cur_max; 45 | /* 46 | * Build the engine(s). The factors determining which are built: 47 | * 1. If the pattern built insists on an NFA, then only build NFA. 48 | * 2. If flags include REG_NOSUB or REG_ONESUB and not (1), 49 | * then only build DFA. 50 | * 3. Otherwise, build both. 51 | * Since libuxre_regdfacomp() modifies the tree and libuxre_regnfacomp() 52 | * doesn't, libuxre_regnfacomp() must be called first, if both are to 53 | * be called. 54 | */ 55 | if ((ep->re_nsub != 0 && (flags & (REG_NOSUB | REG_ONESUB)) == 0) 56 | || lex.flags & REG_NFA) 57 | { 58 | ep->re_flags |= REG_NFA; 59 | if ((lex.err = libuxre_regnfacomp(ep, tp, &lex)) != 0) 60 | goto out; 61 | } 62 | if ((lex.flags & REG_NFA) == 0) 63 | { 64 | ep->re_flags |= REG_DFA; 65 | if ((lex.err = libuxre_regdfacomp(ep, tp, &lex)) != 0) 66 | { 67 | if (ep->re_flags & REG_NFA) 68 | libuxre_regdelnfa(ep->re_nfa); 69 | } 70 | } 71 | out:; 72 | if (lex.err != 0 && lex.col != 0) 73 | (void)libuxre_lc_collate(lex.col); 74 | if (tp != 0) 75 | libuxre_regdeltree(tp, lex.err); 76 | return lex.err; 77 | } 78 | -------------------------------------------------------------------------------- /libuxre/regdfa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)regdfa.h 1.3 (gritter) 9/22/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | 30 | /* 31 | * Deterministic Finite Automata. 32 | */ 33 | 34 | #ifndef LIBUXRE_REGDFA_H 35 | #define LIBUXRE_REGDFA_H 36 | 37 | #include 38 | 39 | typedef struct 40 | { 41 | Bracket *bkt; /* extra info for ROP_BKT */ 42 | size_t nset; /* number of items in the follow set */ 43 | size_t seti; /* index into the follow set strip */ 44 | w_type op; /* the leaf match operation */ 45 | } Posn; 46 | 47 | #define CACHESZ 32 /* max. states to remember (must fit in uchar) */ 48 | #define NCHAR (1 << CHAR_BIT) 49 | 50 | struct re_dfa_ /*Dfa*/ 51 | { 52 | unsigned char *posset; /* signatures built here */ 53 | size_t *posfoll; /* follow strip for posn[] */ 54 | size_t *sigfoll; /* follow strip for sigi[] */ 55 | size_t *cursig; /* current state's signature */ 56 | Posn *posn; /* important positions */ 57 | size_t nposn; /* length of posn,cursig,posset */ 58 | size_t used; /* used portion of follow strip */ 59 | size_t avail; /* unused part of follow strip */ 60 | size_t nset; /* # items nonzero in posset[] */ 61 | size_t nsig[CACHESZ]; /* number of items in signature */ 62 | size_t sigi[CACHESZ]; /* index into sigfoll[] */ 63 | unsigned char acc[CACHESZ]; /* nonzero for accepting states */ 64 | unsigned char leftmost; /* leftmost() start, not BOL */ 65 | unsigned char leftbol; /* leftmost() start, w/BOL */ 66 | unsigned char anybol; /* any match start, w/BOL */ 67 | unsigned char nfix; /* number of invariant states */ 68 | unsigned char top; /* next state index available */ 69 | unsigned char flags; /* interesting flags */ 70 | unsigned char trans[CACHESZ][NCHAR]; /* goto table */ 71 | }; 72 | 73 | extern int regtrans(Dfa *, int, w_type, int); 74 | 75 | #endif /* !LIBUXRE_REGDFA_H */ 76 | -------------------------------------------------------------------------------- /libuxre/regerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)regerror.c 1.4 (gritter) 3/29/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | #include 30 | #include "re.h" 31 | /* include "_locale.h" */ 32 | 33 | /* #pragma weak regerror = _regerror */ 34 | 35 | size_t 36 | regerror(int err, const regex_t *ep, char *str, size_t max) 37 | { 38 | const struct 39 | { 40 | int index; 41 | const char *str; 42 | } unk = 43 | { 44 | 88, "unknown regular expression error" 45 | }, msgs[] = 46 | { 47 | /*ENOSYS*/ { 89, "feature not implemented" }, 48 | /*0*/ { 0, "" }, 49 | /*NOMATCH*/ { 90, "regular expression failed to match" }, 50 | /*BADPAT*/ { 91, "invalid regular expression" }, 51 | /*ECOLLATE*/ { 92, "invalid collating element construct" }, 52 | /*ECTYPE*/ { 93, "invalid character class construct" }, 53 | /*EEQUIV*/ { 94, "invalid equivalence class construct" }, 54 | /*EBKTCHAR*/ { 95, "invalid character in '[ ]' construct" }, 55 | /*EESCAPE*/ { 96, "trailing \\ in pattern" }, 56 | /*ESUBREG*/ { 97, "'\\digit' out of range" }, 57 | /*EBRACK*/ { 98, "'[ ]' imbalance" }, 58 | /*EMPTYSUBBKT*/ { 99, "empty nested '[ ]' construct" }, 59 | /*EMPTYPAREN*/ { 100, "empty '\\( \\)' or '( )'" }, 60 | /*NOPAT*/ { 101, "empty pattern" }, 61 | /*EPAREN*/ { 102, "'\\( \\)' or '( )' imbalance" }, 62 | /*EBRACE*/ { 103, "'\\{ \\} or '{ }' imbalance" }, 63 | /*BADBR*/ { 104, "invalid '\\{ \\}' or '{ }'" }, 64 | /*ERANGE*/ { 105, "invalid endpoint in range" }, 65 | /*ESPACE*/ { 106, "out of regular expression memory" }, 66 | /*BADRPT*/ { 107, "invalid *, +, ?, \\{\\} or {} operator" }, 67 | /*BADESC*/ { 108, "invalid escape sequence (e.g. \\0)" }, 68 | /*ILLSEQ*/ { 109, "illegal byte sequence"} 69 | }; 70 | const char *p; 71 | size_t len; 72 | 73 | (void)ep; 74 | if (err < REG_ENOSYS || REG_ILLSEQ < err) 75 | { 76 | p = unk.str; 77 | } 78 | else 79 | { 80 | p = msgs[err - REG_ENOSYS].str; 81 | } 82 | len = strlen(p) + 1; 83 | if (max != 0) 84 | { 85 | if (max > len) 86 | max = len; 87 | else if (max < len) 88 | str[--max] = '\0'; 89 | memcpy(str, p, max); 90 | } 91 | return len; 92 | } 93 | -------------------------------------------------------------------------------- /libuxre/regex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)regex.h 1.13 (gritter) 2/6/05 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | #ifndef LIBUXRE_REGEX_H 29 | #define LIBUXRE_REGEX_H 30 | /* from unixsrc:usr/src/common/head/regex.h /main/uw7_nj/1 */ 31 | 32 | #include /* really only want [s]size_t */ 33 | 34 | /* 35 | * Official regexec() flags. 36 | */ 37 | #define REG_NOTBOL 0x000001 /* start of string does not match ^ */ 38 | #define REG_NOTEOL 0x000002 /* end of string does not match $ */ 39 | 40 | /* 41 | * Additional regexec() flags. 42 | */ 43 | #define REG_NONEMPTY 0x000004 /* do not match empty at start of string */ 44 | 45 | /* 46 | * Extensions to provide individual control over each 47 | * of the differences between basic and extended REs. 48 | */ 49 | #define REG_OR 0x0000001 /* enable | operator */ 50 | #define REG_PLUS 0x0000002 /* enable + operator */ 51 | #define REG_QUEST 0x0000004 /* enable ? operator */ 52 | #define REG_BRACES 0x0000008 /* use {m,n} (instead of \{m,n\}) */ 53 | #define REG_PARENS 0x0000010 /* use (...) [instead of \(...\)] */ 54 | #define REG_ANCHORS 0x0000020 /* ^ and $ are anchors anywhere */ 55 | #define REG_NOBACKREF 0x0000040 /* disable \digit */ 56 | #define REG_NOAUTOQUOTE 0x0000080 /* no automatic quoting of REG_BADRPTs */ 57 | 58 | /* 59 | * Official regcomp() flags. 60 | */ 61 | #define REG_EXTENDED (REG_OR | REG_PLUS | REG_QUEST | REG_BRACES | \ 62 | REG_PARENS | REG_ANCHORS | \ 63 | REG_NOBACKREF | REG_NOAUTOQUOTE) 64 | #define REG_ICASE 0x0000100 /* ignore case */ 65 | #define REG_NOSUB 0x0000200 /* only success/fail for regexec() */ 66 | #define REG_NEWLINE 0x0000400 /* take \n as line separator for ^ and $ */ 67 | 68 | /* 69 | * Additional regcomp() flags. 70 | * Some of these assume that int is >16 bits! 71 | * Beware: 0x20000000 and above are used in re.h. 72 | */ 73 | #define REG_ONESUB 0x0000800 /* regexec() only needs pmatch[0] */ 74 | #define REG_MTPARENFAIL 0x0001000 /* take empty \(\) or () as match failure */ 75 | #define REG_MTPARENBAD 0x0002000 /* disallow empty \(\) or () */ 76 | #define REG_BADRANGE 0x0004000 /* accept [m-a] ranges as [ma] */ 77 | #define REG_ODDRANGE 0x0008000 /* oawk oddity: [m-a] means [m] */ 78 | #define REG_SEPRANGE 0x0010000 /* disallow [a-m-z] style ranges */ 79 | #define REG_BKTQUOTE 0x0020000 /* allow \ in []s to quote \, -, ^ or ] */ 80 | #define REG_BKTEMPTY 0x0040000 /* allow empty []s (w/BKTQUOTE, BKTESCAPE) */ 81 | #define REG_ANGLES 0x0080000 /* enable \<, \> operators */ 82 | #define REG_ESCNL 0x0100000 /* take \n as newline character */ 83 | #define REG_NLALT 0x0200000 /* take newline as alternation */ 84 | #define REG_ESCSEQ 0x0400000 /* otherwise, take \ as start of C escapes */ 85 | #define REG_BKTESCAPE 0x0800000 /* allow \ in []s to quote next anything */ 86 | #define REG_NOBRACES 0x1000000 /* disable {n,m} */ 87 | #define REG_ADDITIVE 0x2000000 /* a+*b means + and * additive, ^+ is valid */ 88 | #define REG_NOI18N 0x4000000 /* disable I18N features ([::] etc.) */ 89 | #define REG_OLDESC 0x8000000 /* recognize \b \f \n \r \t \123 only */ 90 | #define REG_AVOIDNULL 0x10000000/* avoid null subexpression matches */ 91 | #define REG_OLDBRE (REG_BADRANGE | REG_ANGLES | REG_ESCNL) 92 | #define REG_OLDERE (REG_OR | REG_PLUS | REG_QUEST | REG_NOBRACES | \ 93 | REG_PARENS | REG_ANCHORS | REG_ODDRANGE | \ 94 | REG_NOBACKREF | REG_ADDITIVE | REG_NOAUTOQUOTE) 95 | 96 | /* 97 | * Error return values. 98 | */ 99 | #define REG_ENOSYS (-1) /* unsupported */ 100 | #define REG_NOMATCH 1 /* regexec() failed to match */ 101 | #define REG_BADPAT 2 /* invalid regular expression */ 102 | #define REG_ECOLLATE 3 /* invalid collating element construct */ 103 | #define REG_ECTYPE 4 /* invalid character class construct */ 104 | #define REG_EEQUIV 5 /* invalid equivalence class construct */ 105 | #define REG_EBKTCHAR 6 /* invalid character in [] construct */ 106 | #define REG_EESCAPE 7 /* trailing \ in pattern */ 107 | #define REG_ESUBREG 8 /* number in \digit invalid or in error */ 108 | #define REG_EBRACK 9 /* [] imbalance */ 109 | #define REG_EMPTYSUBBKT 10 /* empty sub-bracket construct */ 110 | #define REG_EMPTYPAREN 11 /* empty \(\) or () [REG_MTPARENBAD] */ 111 | #define REG_NOPAT 12 /* no (empty) pattern */ 112 | #define REG_EPAREN 13 /* \(\) or () imbalance */ 113 | #define REG_EBRACE 14 /* \{\} or {} imbalance */ 114 | #define REG_BADBR 15 /* contents of \{\} or {} invalid */ 115 | #define REG_ERANGE 16 /* invalid endpoint in expression */ 116 | #define REG_ESPACE 17 /* out of memory */ 117 | #define REG_BADRPT 18 /* *,+,?,\{\} or {} not after r.e. */ 118 | #define REG_BADESC 19 /* invalid escape sequence (e.g. \0) */ 119 | #define REG_ILLSEQ 20 /* illegal byte sequence */ 120 | 121 | typedef struct 122 | { 123 | size_t re_nsub; /* only advertised member */ 124 | unsigned long re_flags; /* augmented regcomp() flags */ 125 | struct re_dfa_ *re_dfa; /* DFA engine */ 126 | struct re_nfa_ *re_nfa; /* NFA engine */ 127 | struct re_coll_ *re_col; /* current collation info */ 128 | int re_mb_cur_max; /* MB_CUR_MAX acceleration */ 129 | void *re_more; /* just in case... */ 130 | } regex_t; 131 | 132 | typedef ssize_t regoff_t; 133 | 134 | typedef struct 135 | { 136 | regoff_t rm_so; 137 | regoff_t rm_eo; 138 | } regmatch_t; 139 | 140 | #ifdef __cplusplus 141 | extern "C" { 142 | #endif 143 | 144 | int regcomp(regex_t *, const char *, int); 145 | int regexec(const regex_t *, const char *, size_t, regmatch_t *, int); 146 | size_t regerror(int, const regex_t *, char *, size_t); 147 | void regfree(regex_t *); 148 | 149 | #ifdef __cplusplus 150 | } 151 | #endif 152 | 153 | #endif /* !LIBUXRE_REGEX_H */ 154 | -------------------------------------------------------------------------------- /libuxre/regexec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)regexec.c 1.7 (gritter) 2/6/05 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | #include "re.h" 30 | 31 | /* #pragma weak regexec = _regexec */ 32 | 33 | int 34 | regexec(const regex_t *ep, const char *s, size_t n, regmatch_t *mp, int flg) 35 | { 36 | Exec ex; 37 | int ret; 38 | 39 | ex.flags = flg | (ep->re_flags & (REG_NEWLINE|REG_ICASE|REG_AVOIDNULL)); 40 | ex.str = (const unsigned char *)s; 41 | ex.match = mp; 42 | ex.mb_cur_max = ep->re_mb_cur_max; 43 | if ((ex.nmatch = n) != 0) /* impose limits from compile flags */ 44 | { 45 | if (ep->re_flags & REG_NOSUB) 46 | n = ex.nmatch = 0; 47 | else if (ep->re_flags & REG_ONESUB) 48 | ex.nmatch = 1; 49 | else if (n > ep->re_nsub + 1) 50 | ex.nmatch = ep->re_nsub + 1; 51 | } 52 | if (ep->re_flags & REG_DFA && ex.nmatch <= 1) 53 | ret = libuxre_regdfaexec(ep->re_dfa, &ex); 54 | else 55 | ret = libuxre_regnfaexec(ep->re_nfa, &ex); 56 | /* 57 | * Fill unused part of mp[]. 58 | */ 59 | if (ret != 0) 60 | ex.nmatch = 0; 61 | while (n > ex.nmatch) 62 | { 63 | n--; 64 | mp[n].rm_so = -1; 65 | mp[n].rm_eo = -1; 66 | } 67 | return ret; 68 | } 69 | -------------------------------------------------------------------------------- /libuxre/regfree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)regfree.c 1.3 (gritter) 9/22/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | 28 | /* #include "synonyms.h" */ 29 | #include "re.h" 30 | 31 | /* #pragma weak regfree = _regfree */ 32 | 33 | void 34 | regfree(regex_t *ep) 35 | { 36 | if (ep->re_flags & REG_DFA) 37 | libuxre_regdeldfa(ep->re_dfa); 38 | if (ep->re_flags & REG_NFA) 39 | libuxre_regdelnfa(ep->re_nfa); 40 | if (ep->re_col != 0) 41 | (void)libuxre_lc_collate(ep->re_col); 42 | } 43 | -------------------------------------------------------------------------------- /libuxre/stubs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)stubs.c 1.27 (gritter) 6/26/05 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | /* stubbed-out routines needed to complete the RE libc code */ 28 | 29 | #include "colldata.h" 30 | 31 | struct lc_collate * 32 | libuxre_lc_collate(struct lc_collate *cp) 33 | { 34 | static struct lc_collate curinfo; /* means CHF_ENCODED */ 35 | 36 | (void)cp; 37 | return &curinfo; 38 | } 39 | 40 | #include "wcharm.h" 41 | 42 | LIBUXRE_STATIC int 43 | libuxre_mb2wc(w_type *wt, const unsigned char *s) 44 | { 45 | wchar_t wc; 46 | int len; 47 | 48 | if ((len = mbtowc(&wc, (const char *)&s[-1], MB_LEN_MAX)) > 0) 49 | *wt = wc; 50 | else if (len == 0) 51 | *wt = '\0'; 52 | else /*if (len < 0)*/ 53 | *wt = (w_type)WEOF; 54 | return len > 0 ? len - 1 : len; 55 | } 56 | 57 | #if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4 58 | #define USED __attribute__ ((used)) 59 | #elif defined __GNUC__ 60 | #define USED __attribute__ ((unused)) 61 | #else 62 | #define USED 63 | #endif 64 | static const char sccsid[] USED = "@(#)libuxre.sl 1.27 (gritter) 6/26/05"; 65 | /* SLIST */ 66 | /* 67 | _collelem.c: * Sccsid @(#)_collelem.c 1.4 (gritter) 10/18/03 68 | _collmult.c: * Sccsid @(#)_collmult.c 1.4 (gritter) 9/22/03 69 | bracket.c: * Sccsid @(#)bracket.c 1.14 (gritter) 10/18/03 70 | colldata.h: * Sccsid @(#)colldata.h 1.5 (gritter) 5/1/04 71 | onefile.c: * Sccsid @(#)onefile.c 1.1 (gritter) 9/22/03 72 | re.h: * Sccsid @(#)re.h 1.15 (gritter) 2/6/05 73 | regcomp.c: * Sccsid @(#)regcomp.c 1.6 (gritter) 9/22/03 74 | regdfa.c: * Sccsid @(#)regdfa.c 1.9 (gritter) 9/22/03 75 | regdfa.h: * Sccsid @(#)regdfa.h 1.3 (gritter) 9/22/03 76 | regerror.c: * Sccsid @(#)regerror.c 1.4 (gritter) 3/29/03 77 | regex.h: * Sccsid @(#)regex.h 1.13 (gritter) 2/6/05 78 | regexec.c: * Sccsid @(#)regexec.c 1.7 (gritter) 2/6/05 79 | regfree.c: * Sccsid @(#)regfree.c 1.3 (gritter) 9/22/03 80 | regnfa.c: * Sccsid @(#)regnfa.c 1.8 (gritter) 2/6/05 81 | regparse.c: * Sccsid @(#)regparse.c 1.12 (gritter) 9/22/03 82 | wcharm.h: * Sccsid @(#)wcharm.h 1.12 (gritter) 10/18/03 83 | */ 84 | -------------------------------------------------------------------------------- /libuxre/wcharm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. 3 | * 4 | * Sccsid @(#)wcharm.h 1.12 (gritter) 10/18/03 5 | */ 6 | /* UNIX(R) Regular Expresssion Library 7 | * 8 | * Note: Code is released under the GNU LGPL 9 | * 10 | * Copyright (C) 2001 Caldera International, Inc. 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to: 24 | * Free Software Foundation, Inc. 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | */ 27 | /* Stubbed-out wide character locale information */ 28 | 29 | #ifndef LIBUXRE_WCHARM_H 30 | #define LIBUXRE_WCHARM_H 31 | 32 | #ifndef LIBUXRE_STATIC 33 | #define LIBUXRE_STATIC 34 | #endif 35 | 36 | #ifndef LIBUXRE_WUCHAR_T 37 | #define LIBUXRE_WUCHAR_T 38 | typedef unsigned int wuchar_type; 39 | #endif 40 | 41 | #ifndef LIBUXRE_W_TYPE 42 | #define LIBUXRE_W_TYPE 43 | typedef int w_type; 44 | #endif 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | #ifdef notdef 51 | #define ISONEBYTE(ch) ((ch), 1) 52 | 53 | #define libuxre_mb2wc(wp, cp) ((wp), (cp), 0) 54 | #endif /* notdef */ 55 | 56 | #define ISONEBYTE(ch) (((ch) & 0200) == 0 || mb_cur_max == 1) 57 | 58 | #define to_lower(ch) (mb_cur_max > 1 ? towlower(ch) : (wint_t)tolower(ch)) 59 | #define to_upper(ch) (mb_cur_max > 1 ? towupper(ch) : (wint_t)toupper(ch)) 60 | 61 | LIBUXRE_STATIC int libuxre_mb2wc(w_type *, const unsigned char *); 62 | 63 | #endif /* !LIBUXRE_WCHARM_H */ 64 | -------------------------------------------------------------------------------- /makeoptions: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This code contains changes by 4 | # Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. 5 | # 6 | # Conditions 1, 2, and 4 and the no-warranty notice below apply 7 | # to these changes. 8 | # 9 | # 10 | # Copyright (c) 1980, 1993 11 | # The Regents of the University of California. 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 | # 1. Redistributions of source code must retain the above copyright 17 | # notice, this list of conditions and the following disclaimer. 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 | # 3. All advertising materials mentioning features or use of this software 22 | # must display the following acknowledgement: 23 | # This product includes software developed by the University of 24 | # California, Berkeley and its contributors. 25 | # 4. Neither the name of the University nor the names of its contributors 26 | # may be used to endorse or promote products derived from this software 27 | # without specific prior written permission. 28 | # 29 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 | # SUCH DAMAGE. 40 | # 41 | # 42 | # Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 43 | # 44 | # Redistribution and use in source and binary forms, with or without 45 | # modification, are permitted provided that the following conditions 46 | # are met: 47 | # Redistributions of source code and documentation must retain the 48 | # above copyright notice, this list of conditions and the following 49 | # disclaimer. 50 | # Redistributions in binary form must reproduce the above copyright 51 | # notice, this list of conditions and the following disclaimer in the 52 | # documentation and/or other materials provided with the distribution. 53 | # All advertising materials mentioning features or use of this software 54 | # must display the following acknowledgement: 55 | # This product includes software developed or owned by Caldera 56 | # International, Inc. 57 | # Neither the name of Caldera International, Inc. nor the names of 58 | # other contributors may be used to endorse or promote products 59 | # derived from this software without specific prior written permission. 60 | # 61 | # USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 62 | # INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 63 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 64 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 65 | # ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 66 | # LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 67 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 68 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 69 | # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 70 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 71 | # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 72 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 | # 74 | # from makeoptions 6.4 (Berkeley) 5/31/85 75 | # 76 | # @(#)makeoptions 1.8 (gritter) 7/1/02 77 | # 78 | 79 | # 80 | # remake options -- this isn't necessary unless you add/delete options 81 | # 82 | trap "rm -f /tmp/ex_foo$$.c /tmp/ex_bar$$.c" 0 83 | trap '' 2 84 | cat < ex_data.c > /tmp/ex_bar$$.c 85 | ex -s /tmp/ex_bar$$.c <<\! 86 | g/^#include/d 87 | w 88 | q 89 | ! 90 | cc -E ${@+"$@"} /tmp/ex_bar$$.c >/tmp/ex_foo$$.c 91 | ex -s /tmp/ex_foo$$.c <<\! 92 | " delete all preprocessor output (# line, etc) 93 | g/^# /d 94 | set sh=/bin/sh 95 | " delete junk (all but data lines) 96 | g/^[ ]*$/d 97 | 1,/option options/d 98 | /};/-1,$d 99 | " get rid of all of line but option name 100 | 1,$s/[ ]*{[ ]*"// 101 | 1,$s/".*// 102 | " begin kludge since options start at 0 but nl starts at 1 103 | " move first to end and later move it back and renumber 104 | 1m$ 105 | %!nl 106 | $t0 107 | 1s/[0-9][0-9]*/0/ 108 | " end kludge 109 | " make #define lines 110 | 1,$s/[ ]*\([0-9][0-9]*\)[ ]*\(.*\)/#define \U\2\L \1/ 111 | " filter through expand to make it line up nice 112 | %!expand -8\,24 113 | " blank line and number of options. 114 | $i 115 | 116 | . 117 | $s/e[ ].*[ ]/e NOPTS / 118 | 0a 119 | /* sccs id @(#)ex_vars.h makeoptions 1.8 (gritter) 7/1/02 */ 120 | . 121 | w! ex_vars.h 122 | q 123 | ! 124 | -------------------------------------------------------------------------------- /malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * AT&T Unix 7th Edition memory allocation routines. 3 | * 4 | * Modified for ex by Gunnar Ritter, Freiburg i. Br., Germany, 5 | * July 2000. 6 | * 7 | * Copyright(C) Caldera International Inc. 2001-2002. 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 | * Redistributions of source code and documentation must retain the 13 | * above copyright notice, this list of conditions and the following 14 | * disclaimer. 15 | * 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 | * All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed or owned by Caldera 21 | * International, Inc. 22 | * Neither the name of Caldera International, Inc. nor the names of 23 | * other contributors may be used to endorse or promote products 24 | * derived from this software without specific prior written permission. 25 | * 26 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 27 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 28 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 31 | * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 34 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 36 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 37 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | * @(#)malloc.c 1.19 (gritter) 2/20/05 40 | */ 41 | 42 | #ifdef VMUNIX 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #include "config.h" 49 | 50 | #ifdef LANGMSG 51 | #include 52 | extern nl_catd catd; 53 | #else 54 | #define catgets(a, b, c, d) (d) 55 | #endif 56 | 57 | /* 58 | * Since ex makes use of sbrk(), the C library's version of malloc() 59 | * must be avoided. 60 | * 61 | * In ex, malloc() calls sbrk() only one time with an argument of 62 | * POOL. Ex itselves never uses malloc() internally, so POOL 63 | * must be sufficient for library calls like setlocale() only. 64 | * 65 | * Known problem: If linking against ncurses, changing the terminal 66 | * type repeatedly outruns the pool. Even that is not really a 67 | * problem since the work continues with the old terminal type, so 68 | * there is no need for a large pool here. 69 | */ 70 | #define POOL 32768 71 | 72 | #ifdef debug 73 | #define ASSERT(p) if(!(p))botch("p");else 74 | #include 75 | #include 76 | #include 77 | int 78 | botch(char *s) 79 | { 80 | const char msg[] = "assertion botched\n"; 81 | write(2, msg, sizeof msg - 1); 82 | /*printf("assertion botched: %s\n",s);*/ 83 | abort(); 84 | } 85 | static int allock(void); 86 | #else 87 | #define ASSERT(p) 88 | #endif 89 | 90 | /* avoid break bug */ 91 | #ifdef pdp11 92 | #define GRANULE 64 93 | #else 94 | #define GRANULE 0 95 | #endif 96 | /* C storage allocator 97 | * circular first-fit strategy 98 | * works with noncontiguous, but monotonically linked, arena 99 | * each block is preceded by a ptr to the (pointer of) 100 | * the next following block 101 | * blocks are exact number of words long 102 | * aligned to the data type requirements of ALIGN 103 | * pointers to blocks must have BUSY bit 0 104 | * bit in ptr is 1 for busy, 0 for idle 105 | * gaps in arena are merely noted as busy blocks 106 | * last block of arena (pointed to by alloct) is empty and 107 | * has a pointer to first 108 | * idle blocks are coalesced during space search 109 | * 110 | * a different implementation may need to redefine 111 | * ALIGN, NALIGN, BLOCK, BUSY, INT 112 | * where INT is integer type to which a pointer can be cast 113 | */ 114 | #define INT intptr_t 115 | #define ALIGN intptr_t 116 | #define NALIGN 1 117 | #define WORD sizeof (union store) 118 | #define BLOCK 1024 /* a multiple of WORD*/ 119 | #define BUSY ((intptr_t)1) 120 | #ifdef NULL 121 | #undef NULL 122 | #endif 123 | #define NULL 0 124 | #define testbusy(p) ((INT)(p)&BUSY) 125 | #define setbusy(p) (union store *)((INT)(p)|BUSY) 126 | #define clearbusy(p) (union store *)((INT)(p)&~BUSY) 127 | 128 | union store { union store *ptr; 129 | ALIGN dummy[NALIGN]; 130 | INT callocsp; /*calloc clears an array of integers*/ 131 | }; 132 | 133 | static union store allocs[2]; /*initial arena*/ 134 | static union store *allocp; /*search ptr*/ 135 | static union store *alloct; /*arena top*/ 136 | static union store *allocx; /*for benefit of realloc*/ 137 | extern int error(char *, ...); 138 | 139 | char * 140 | poolsbrk(intptr_t inc) 141 | { 142 | static char *pool; 143 | static intptr_t ps; 144 | intptr_t os, ns; 145 | 146 | if (pool == NULL) 147 | if ((pool = sbrk(POOL)) == (char *)-1) 148 | error(catgets(catd, 1, 241, 149 | "No memory pool")); 150 | if (inc == 0) 151 | return pool + ps; 152 | os = ps; 153 | ns = ps + inc; 154 | if (ns >= POOL) 155 | error(catgets(catd, 1, 242, 156 | "Memory pool exhausted")); 157 | ps = ns; 158 | return pool + os; 159 | } 160 | 161 | void * 162 | malloc(size_t nbytes) 163 | { 164 | register union store *p, *q; 165 | register int nw; 166 | static int temp; /*coroutines assume no auto*/ 167 | 168 | if(allocs[0].ptr==0) { /*first time*/ 169 | allocs[0].ptr = setbusy(&allocs[1]); 170 | allocs[1].ptr = setbusy(&allocs[0]); 171 | alloct = &allocs[1]; 172 | allocp = &allocs[0]; 173 | } 174 | nw = (nbytes+WORD+WORD-1)/WORD; 175 | ASSERT(allocp>=allocs && allocp<=alloct); 176 | ASSERT(allock()); 177 | for(p=allocp; ; ) { 178 | for(temp=0; ; ) { 179 | if(!testbusy(p->ptr)) { 180 | while(!testbusy((q=p->ptr)->ptr)) { 181 | int ua = p->ptr==allocp; 182 | ASSERT(q>p&&qptr = q->ptr; 184 | if (ua) 185 | allocp = p->ptr; 186 | } 187 | if(q>=p+nw && p+nw>=p) 188 | goto found; 189 | } 190 | q = p; 191 | p = clearbusy(p->ptr); 192 | if(p>q) 193 | ASSERT(p<=alloct); 194 | else if(q!=alloct || p!=allocs) { 195 | ASSERT(q==alloct&&p==allocs); 196 | errno = ENOMEM; 197 | return(NULL); 198 | } else if(++temp>1) 199 | break; 200 | } 201 | temp = ((nw+BLOCK/WORD)/(BLOCK/WORD))*(BLOCK/WORD); 202 | q = (union store *)poolsbrk(0); 203 | if(q+temp+GRANULE < q) { 204 | errno = ENOMEM; 205 | return(NULL); 206 | } 207 | q = (union store *)poolsbrk(temp*WORD); 208 | if((INT)q == -1) { 209 | errno = ENOMEM; 210 | return(NULL); 211 | } 212 | ASSERT(q>alloct); 213 | alloct->ptr = q; 214 | if(q!=alloct+1) 215 | alloct->ptr = setbusy(alloct->ptr); 216 | alloct = q->ptr = q+temp-1; 217 | alloct->ptr = setbusy(allocs); 218 | } 219 | found: 220 | allocp = p + nw; 221 | ASSERT(allocp<=alloct); 222 | if(q>allocp) { 223 | allocx = allocp->ptr; 224 | allocp->ptr = p->ptr; 225 | } 226 | p->ptr = setbusy(allocp); 227 | return((char *)(p+1)); 228 | } 229 | 230 | /* freeing strategy tuned for LIFO allocation 231 | */ 232 | void 233 | free(register void *ap) 234 | { 235 | register union store *p = ap; 236 | 237 | if (ap == NULL) 238 | return; 239 | ASSERT(p>clearbusy(allocs[1].ptr)&&p<=alloct); 240 | ASSERT(allock()); 241 | allocp = --p; 242 | ASSERT(testbusy(p->ptr)); 243 | p->ptr = clearbusy(p->ptr); 244 | ASSERT(p->ptr > allocp && p->ptr <= alloct); 245 | } 246 | 247 | /* realloc(p, nbytes) reallocates a block obtained from malloc() 248 | * and freed since last call of malloc() 249 | * to have new size nbytes, and old content 250 | * returns new location, or 0 on failure 251 | */ 252 | 253 | void * 254 | realloc(void *ap, size_t nbytes) 255 | { 256 | register union store *p = ap; 257 | register union store *q; 258 | union store *s, *t; 259 | register size_t nw; 260 | size_t onw; 261 | 262 | if (p == NULL) 263 | return malloc(nbytes); 264 | if (nbytes == 0) { 265 | free(p); 266 | return NULL; 267 | } 268 | if(testbusy(p[-1].ptr)) 269 | free(p); 270 | onw = p[-1].ptr - p; 271 | q = malloc(nbytes); 272 | if(q==NULL || q==p) 273 | return(q); 274 | s = p; 275 | t = q; 276 | nw = (nbytes+WORD-1)/WORD; 277 | if(nw=p) 282 | (q+(q+nw-p))->ptr = allocx; 283 | return(q); 284 | } 285 | 286 | #ifdef debug 287 | int 288 | allock(void) 289 | { 290 | #ifdef longdebug 291 | register union store *p; 292 | int x; 293 | x = 0; 294 | for(p= &allocs[0]; clearbusy(p->ptr) > p; p=clearbusy(p->ptr)) { 295 | if(p==allocp) 296 | x++; 297 | } 298 | ASSERT(p==alloct); 299 | return(x==1|p==allocp); 300 | #else 301 | return(1); 302 | #endif 303 | } 304 | #endif 305 | 306 | /* calloc - allocate and clear memory block 307 | */ 308 | #define CHARPERINT (sizeof(INT)/sizeof(char)) 309 | 310 | void * 311 | calloc(size_t num, size_t size) 312 | { 313 | register char *mp; 314 | register INT *q; 315 | register int m; 316 | 317 | num *= size; 318 | mp = malloc(num); 319 | if(mp == NULL) 320 | return(NULL); 321 | q = (INT *) mp; 322 | m = (num+CHARPERINT-1)/CHARPERINT; 323 | while(--m >= 0) 324 | *q++ = 0; 325 | return(mp); 326 | } 327 | 328 | #ifdef notdef 329 | /*ARGSUSED*/ 330 | void 331 | cfree(char *p, size_t num, size_t size) 332 | { 333 | free(p); 334 | } 335 | 336 | /* 337 | * Just in case ... 338 | */ 339 | char * 340 | memalign(size_t alignment, size_t size) 341 | { 342 | return NULL; 343 | } 344 | 345 | char * 346 | valloc(size_t size) 347 | { 348 | return NULL; 349 | } 350 | 351 | char * 352 | mallinfo(void) 353 | { 354 | return NULL; 355 | } 356 | 357 | int 358 | mallopt(void) 359 | { 360 | return -1; 361 | } 362 | #endif /* notdef */ 363 | 364 | #endif /* VMUNIX */ 365 | -------------------------------------------------------------------------------- /pkginfo: -------------------------------------------------------------------------------- 1 | # Sccsid @(#)pkginfo 1.1 (gritter) 2/25/07 2 | PKG=ex 3 | NAME=The ex/vi editor 4 | DESC=The ex/vi editor. 5 | VENDOR=Gunnar Ritter 6 | HOTLINE=http://ex-vi.sourceforge.net 7 | EMAIL=gunnarr@acm.org 8 | VERSION=070225 9 | ARCH=IA32,i386 10 | CATEGORY=utilities 11 | BASEDIR=/ 12 | -------------------------------------------------------------------------------- /wvi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | while [ $# -gt 0 ]; do 3 | case "$1" in 4 | -fg | -bg | -fn | -geometry) 5 | XFl="$XFl $1 $2" 6 | shift ;; 7 | -*) 8 | Fl="$Fl $1" ;; 9 | *) 10 | break ;; 11 | esac 12 | shift 13 | done 14 | RC=$HOME/.exrc 15 | echo $XFl | grep -q '\-geometry' || { 16 | [ -e $RC ] && grep -q '^set\{0,1\}[[:space:]]\{1,\}nu' $RC && 17 | XFl="$XFl -geometry 88" 18 | } 19 | xterm $XFl -T "vi $*" -e "BINDIR/vi $Fl $*" & 20 | -------------------------------------------------------------------------------- /wvi.1: -------------------------------------------------------------------------------- 1 | .\" Carsten Kunze, 2016 2 | .Dd August 5, 2016 3 | .Dt WVI 1 4 | .Sh NAME 5 | .Nm wvi 6 | .Nd open vi in a separate xterm 7 | .Sh SYNOPSIS 8 | .Nm 9 | .Op Ar "X options" 10 | .Op Ar "vi options" 11 | .Sh DESCRIPTION 12 | There are use cases for 13 | .Nm vi 14 | where it is desirable to start it in a separate X window. 15 | .Nm 16 | just starts 17 | .Do Nm xterm Ar "X options" Fl e Dc 18 | with 19 | .Nm vi 20 | and the 21 | .Ar "vi options" 22 | as argument. 23 | Possible X options are: 24 | .Bl -tag 25 | .It Fl bg Ar color 26 | Set background color. 27 | .It Fl fg Ar color 28 | Set foreground color. 29 | .It Fl fn Ar font name 30 | Set font name. 31 | .It Fl geometry Ar geometry string 32 | Set xterm window geometry. 33 | .El 34 | .Pp 35 | File names with spaces need to be enclosed in single or double quotes 36 | .Po Sq Li \(aq 37 | or 38 | .Sq Li \(dq 39 | .Pc 40 | .Em and 41 | the spaces needs to be protected with a backslash 42 | .Pq Sq \(rs . 43 | --------------------------------------------------------------------------------