├── .bash_test ├── .bash_test_extra ├── .gitignore ├── .krsrc ├── BitVector.h ├── COPYING ├── GNUmakefile ├── K.ico ├── NOTES.univ-tags ├── README.adoc ├── README.linux_port ├── astyle.cfg ├── attr_format.h ├── bin.lua ├── bld_cmdtbl.lua ├── bld_datetime.lua ├── bld_link_unref.lua ├── build-for-coverity ├── buildexecute.cpp ├── changers.cpp ├── cmdidx.cpp ├── cmdtbl.dat ├── conin_ncurses.md ├── conio.h ├── ctags.d ├── k-kbackup.ctags ├── k-lua51.ctags └── k-src.ctags ├── cursor.cpp ├── display.cpp ├── dlink.h ├── dlink_unittest.cpp ├── docs ├── musings.adoc └── wuc.md ├── drmingw_jit_install.bat ├── dump_ntfs_streams.cpp ├── dv.bat ├── ed_core.h ├── ed_edkc.h ├── ed_main.h ├── ed_mem.h ├── ed_os_generic.h ├── ed_protos.h ├── ed_search.h ├── ed_vars.h ├── fbuf.cpp ├── fbuf_edit.cpp ├── fbuf_undo.cpp ├── features ├── cygpath_mode.txt └── std_filesystem_conv.txt ├── filename.cpp ├── filename.h ├── fn_misc.cpp ├── fn_text.cpp ├── fname_gen.cpp ├── fname_gen.h ├── getopt.cpp ├── getopt.h ├── git_cat_local_config ├── git_set_fwmechanic_ident ├── historical_scans_fair_use ├── 1986.08.04-Z.TXT ├── 1988.09-MS.Journal-Notenboom-Customizing.M.Editor.pdf ├── 2001.07-MSDN.News-Michell-PWB.pdf ├── README.txt └── Z-cleaned.TXT ├── impl_towinclip.h ├── install_build_tools_ubuntu.sh ├── k.cpp ├── k.filesettings ├── k.luaedit ├── k.luastate ├── k.rc ├── k.workspace ├── keys.cpp ├── krbtree.cpp ├── krbtree.h ├── krmbak ├── krmlog ├── linux_api.cpp ├── linux_base.h ├── linux_process.cpp ├── lua-5.1 ├── COPYRIGHT ├── HISTORY ├── INSTALL ├── MANIFEST ├── Makefile ├── README ├── doc │ ├── contents.html │ ├── cover.png │ ├── logo.gif │ ├── lrexlib │ │ ├── html4css1.css │ │ ├── lrexlib.css │ │ └── manual.html │ ├── lua.1 │ ├── lua.css │ ├── lua.html │ ├── luac.1 │ ├── luac.html │ ├── manual.css │ ├── manual.html │ └── readme.html ├── etc │ ├── Makefile │ ├── README │ ├── all.c │ ├── lua.hpp │ ├── lua.ico │ ├── lua.pc │ ├── luavs.bat │ ├── min.c │ ├── noparser.c │ └── strict.lua ├── src │ ├── Makefile │ ├── fix_coverity.h │ ├── k_lib.c │ ├── k_lib.h │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lcode.c │ ├── lcode.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── loslib.c │ ├── lpack.c │ ├── lpack.readme.txt │ ├── lparser.c │ ├── lparser.h │ ├── lpcap.c │ ├── lpcap.h │ ├── lpcode.c │ ├── lpcode.h │ ├── lpcre2.c │ ├── lpcre2_algo.h │ ├── lpcre2_common.c │ ├── lpcre2_common.h │ ├── lpcre2_f.c │ ├── lpeg-128.gif │ ├── lpeg.HISTORY │ ├── lpeg.html │ ├── lpprint.c │ ├── lpprint.h │ ├── lptree.c │ ├── lptree.h │ ├── lptypes.h │ ├── lpvm.c │ ├── lpvm.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua.link │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ ├── lzio.h │ ├── print.c │ ├── re.html │ └── re.lua └── test │ ├── README │ ├── bisect.lua │ ├── cf.lua │ ├── echo.lua │ ├── env.lua │ ├── factorial.lua │ ├── fib.lua │ ├── fibfor.lua │ ├── globals.lua │ ├── hello.lua │ ├── k_lib.lua │ ├── life.lua │ ├── lpeg.lua │ ├── luac.lua │ ├── printf.lua │ ├── readonly.lua │ ├── sieve.lua │ ├── sort.lua │ ├── table.lua │ ├── trace-calls.lua │ ├── trace-globals.lua │ └── xd.lua ├── lua_edlib.cpp ├── lua_intf.cpp ├── lua_intf_common.h ├── macro.cpp ├── main.cpp ├── mark.cpp ├── menu.lua ├── my_fio.cpp ├── my_fio.h ├── my_log.h ├── my_strutils.cpp ├── my_strutils.h ├── my_types.h ├── ncurses_conin.cpp ├── ncurses_conout.cpp ├── odkey.sh ├── os_services.cpp ├── os_services.h ├── patch-coverity ├── pcre_intf.cpp ├── pdconv.lua ├── re.lua ├── regex_rplc_test.txt ├── rm_util.cpp ├── rm_util.h ├── rsrc.cpp ├── search.cpp ├── setconsoleinfo.cpp ├── show.lua ├── std.dynlib.linux ├── std.dynlib.mingw ├── strict.lua ├── stringlist.cpp ├── stringlist.h ├── switch_impl.cpp ├── switch_impl.h ├── switches.cpp ├── sysbufs.cpp ├── tabs.md ├── tagfind.cpp ├── test ├── pst01.ps1 └── traildisp.txt ├── test_tagfind ├── tu.lua ├── ubuntu_univ-ctags_build_install ├── user.lua ├── util.lua ├── win32.cpp ├── win32_api.cpp ├── win32_base.h ├── win32_clipbd.cpp ├── win32_conin.cpp ├── win32_conout.cpp ├── win32_contit.cpp ├── win32_filename.cpp ├── win32_process.cpp ├── win32_pvt.h ├── wnd.cpp └── xk.bat /.bash_test: -------------------------------------------------------------------------------- 1 | 2 | alias alert='notify "$([ $? = 0 ] && echo terminal || echo error)"' 3 | TEST1="this" # comment 4 | -------------------------------------------------------------------------------- /.bash_test_extra: -------------------------------------------------------------------------------- 1 | alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)"' 2 | alias alert='"$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' 3 | 4 | alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' 5 | 6 | TEST0="" # comment 7 | TEST0="a" # comment 8 | TEST1="this" # comment 9 | TEST2='this' # comment 10 | TEST3='this "is" not' # comment 11 | TEST4="this 'is' not" # comment 12 | TEST5="this 'is another "test" ' not" # comment 13 | TEST6="this is a 'test containing "more" "quotes" than' I know 'to "really" shake' a stick at" # comment 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | k 2 | dif 3 | lua 4 | k-*.log 5 | .svn/ 6 | cov-int/ 7 | .kbackup/ 8 | bkz/ 9 | *_unittest 10 | *.k? 11 | *.args 12 | *.makedeps 13 | *.o 14 | *.obj 15 | *.cod 16 | *.optc 17 | *.sout 18 | *.exe 19 | *.xref 20 | *.pdb 21 | *.a 22 | *.lib 23 | *.ii 24 | *.s 25 | # !pcre.lib this (git syntax) does not work in hg 26 | 27 | cmdtbl.h 28 | fxns 29 | tags 30 | tags_fields 31 | tags_extras 32 | tags_kinds 33 | k_rls.* 34 | k.RES 35 | k_D.LRF 36 | k_E.lrf 37 | _buildtime.c 38 | kx.def 39 | *.dll 40 | *.dllmap 41 | *.exp 42 | *.lrf 43 | *.LRF 44 | *.map 45 | *.mapi 46 | .nfs* 47 | 48 | cfiles 49 | ctout.list 50 | depsout.mak 51 | errors 52 | noisewarnings 53 | vars 54 | warnings 55 | whole_run.out 56 | .hgdif 57 | link.errs 58 | link.unref 59 | mkabat.bat 60 | *.testout 61 | 62 | _buildtime.i 63 | datetime.i 64 | 65 | # coverity data collection file 66 | k_edit.tgz 67 | -------------------------------------------------------------------------------- /.krsrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/.krsrc -------------------------------------------------------------------------------- /BitVector.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2016 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | /* 23 | The BitVector class is designed for efficiency in checking whether any bit is 24 | set. Initial target is screen refresh code: a set bit indicates a screen line 25 | needing refresh, so if any are set we go off into the refresh logic. Since 26 | the "anything pending" parallel/cached status bit no longer exists, it's 27 | important that the any-bit-set? test be speedy. 28 | 29 | Note that BitVector is as efficient as it gets on a 32-bit CPU (big 30 | shock there!); a BitVector is no better. 31 | 32 | 20090223 kgoodwin 33 | */ 34 | template 35 | class BitVector { 36 | typedef T *P; 37 | typedef const T *CP; 38 | enum { BITS_PER_EL = 8*sizeof(T), ALLBITS = ~static_cast(0) }; 39 | 40 | const size_t d_T_els ; 41 | const P d_bits ; 42 | 43 | private: 44 | 45 | size_t bitnum( size_t bn ) const { return bn % BITS_PER_EL; } 46 | size_t elenum( size_t bn ) const { return bn / BITS_PER_EL; } 47 | 48 | public: 49 | 50 | BitVector( size_t bits ) 51 | : d_T_els( (bits+BITS_PER_EL-1)/BITS_PER_EL ) 52 | , d_bits( P( Alloc0d( d_T_els * sizeof(T) ) ) ) 53 | {} 54 | 55 | ~BitVector() { delete d_bits; } 56 | 57 | void SetBit ( size_t bn ) { d_bits[ elenum( bn ) ] |= BIT( bitnum( bn ) ); } 58 | void ClrBit ( size_t bn ) { d_bits[ elenum( bn ) ] &= ~BIT( bitnum( bn ) ); } 59 | bool IsBitSet( size_t bn ) const { return (d_bits[ elenum( bn ) ] & BIT( bitnum( bn ) )) != 0; } 60 | bool IsAnyBitSet() const { // _this_ is the reason for this class existing: fast search for any bit being set 61 | const P pastEnd( d_bits + d_T_els ); 62 | for( P pel=d_bits ; pel < pastEnd ; ++pel ) { 63 | if( *pel ) { 64 | return true; 65 | } 66 | } 67 | return false; 68 | } 69 | void ClrAllBits() { 70 | const P pastEnd( d_bits + d_T_els ); 71 | for( P pel=d_bits ; pel < pastEnd ; ++pel ) { 72 | *pel = 0; 73 | } 74 | } 75 | void SetAllBits() { 76 | const P pastEnd( d_bits + d_T_els ); 77 | for( P pel=d_bits ; pel < pastEnd ; ++pel ) { 78 | *pel = ALLBITS; 79 | } 80 | } 81 | }; 82 | -------------------------------------------------------------------------------- /K.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/K.ico -------------------------------------------------------------------------------- /NOTES.univ-tags: -------------------------------------------------------------------------------- 1 | --fields=+ ID 2 | N/name tag name the first field, being the primary key which the tags file is sorted on 3 | F/input input file name of file in which tagged object is defined 4 | P/pattern pattern content governed by --excmd value: when --excmd=number, this has the value 'n;"' where n is a decimal (line) number 5 | 6 | f/file "File-restricted scoping" (dflt enabled for C++) add a field "file:" to file-scoped tagged objects (don't add to global-scoped tagged objects) (#def macs in .c files, static objects) 7 | 8 | K "Kind of tag as full name" 9 | k "Kind of tag as a single letter" even though this is (dflt enabled for C++), it appears to be overridden by --fields=+K 10 | 11 | s/NONE "Scope of tag definition" does not seem to do anything (C++, with --fields=+f in effect) 12 | p/scopeKind "Kind of scope as full name" does not seem to do anything (C++, with --fields=+f in effect) 13 | 14 | t "Type and name of a variable or typedef" (dflt enabled for C++) add a field "typeref:" for fxns: return type 15 | -------------------------------------------------------------------------------- /README.linux_port: -------------------------------------------------------------------------------- 1 | 2 | CODING CONVENTIONS *** existing code is uniformly formatted. Get used to it. 3 | Some notable divergences from common conventions are called out next: 4 | 5 | * USE NO TABS (except as required in makefiles) 6 | * USE NO 1-character identifiers! Even "ii" is better than "i"! 7 | * 3 spaces per indent level 8 | * DO NOT slavishly WRAP source code LINES @ 80th column; I haven't used a 9 | no-more-than-80-column terminal ... _ever_ (and I've been using Linux via 10 | xterms and Putty off and on for > 10 years; since it's now essential that 11 | my devenv include the ability to run a browser (Firefox), I can foresee NO 12 | situation in which I'll be _developing_ K under an 80-column constraint). 13 | BTW the market (Hollywood?) has driven monitor aspect ratio in a 14 | pro-width-bias direction, something I don't see being reversed in the next 15 | decade ... 16 | * curly brace format: my preference (as expressed in K source code) has evolved to 17 | https://en.wikipedia.org/wiki/Indent_style#Ratliff_style which is same as 18 | https://en.wikipedia.org/wiki/Indent_style#Banner_style ? 19 | both modified by: 20 | if( bool ) { } // yes 21 | if (bool) { } // NO! 22 | function( my, params ); // yes 23 | function (my,params); // NO! 24 | but: "return yes;" 25 | not "return( no );" // return is not a function call 26 | * terminology: to avoid redundancy, do not use the term "whitespace" or "white"; 27 | use "blank" instead. 28 | 29 | Semantic Coding Guidelines 30 | 31 | * When strings are being assembled, prefer std::string 32 | * When strings are being referenced, prefer stref (std::string_view) 33 | * Deprecate (pointer to) ASCI_Z_ string in lieu of the above whereever possible. 34 | * You will see many duplications of methods and functions along the axis of 35 | * std::string vs. Xbuf param or retval 36 | * stref (std::string_view) vs. PCChar param or retval 37 | in all cases, prefer the first to the second (try to rmv the second) 38 | this does not mean that the first is as well-tested as the second! 39 | 40 | Weaknesses 41 | 42 | * As per #1 coding convention, I eschew tabs; Tabs are responsible for a large 43 | amount of cruft in the K code, and even so, are not superbly supported. if 44 | not for GNU Make (which uses tabs as a syntactic element), I would have long 45 | ago declared tab characters an unsupported "feature" and removed from K all 46 | related code. 47 | 48 | Key goals 49 | 50 | * http://fte.sourceforge.net/ seems to have a nicely structured architecture 51 | supporting multiple/diverse screen+kybd I/O environments. While my immediate 52 | goals for K are far less diverse (ncurses should be totally sufficient?), 53 | adopting FTE's framework in toto _MIGHT_ be a net win... 54 | 55 | * when I use K, in direct contrast to the "fingers on home keys" mantra of vi 56 | etc., my right hand is almost always over the numeric keypad; cursor keys, 57 | arg (center key), cut, copy, paste are all "at hand". Note that cut, copy, 58 | paste are used in preference to manually typing alpha(num) strings appearing 59 | on the screen (something I see vi users do on an every minute-basis, which 60 | just seems wrong to me (I am an error-prone transcriber)). A KEY GOAL is to 61 | preserve this capability on all platforms (yes I understand that 62 | small-form-factor laptops (which some people prefer) are problematic in this 63 | regard). 64 | 65 | 66 | Major Tasks 67 | 68 | - screen output [done 20141214] 69 | - reading/processing normal input (keyboard, screen-size change, mouse) events 70 | - react to screen-size changes (even w/>1 window extant) [done 20141111] 71 | - command and dflt-key-mapping tables 72 | - child processes and stdout/err capturing to buffer 73 | - signal handling 74 | -------------------------------------------------------------------------------- /astyle.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | # 4 | # This file is part of K. 5 | # 6 | # K is free software: you can redistribute it and/or modify it under the 7 | # terms of the GNU General Public License as published by the Free Software 8 | # Foundation, either version 3 of the License, or (at your option) any later 9 | # version. 10 | # 11 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | # details. 15 | # 16 | # You should have received a copy of the GNU General Public License along 17 | # with K. If not, see . 18 | # 19 | 20 | # http://sourceforge.net/projects/astyle/ 21 | # invoke with `astyle --config=astyle.cfg ...` 22 | 23 | --indent=spaces=3 24 | --style=banner 25 | --indent-preproc-block 26 | --indent-modifiers 27 | --indent-preproc-cond 28 | --attach-namespaces 29 | --attach-classes 30 | -p 31 | -PUDJo 32 | --align-pointer=name 33 | --align-reference=name 34 | --close-templates 35 | --remove-comment-prefix 36 | -------------------------------------------------------------------------------- /attr_format.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2018 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html 23 | #define GCC_VERSION ( __GNUC__ * 10000 \ 24 | + __GNUC_MINOR__ * 100 \ 25 | + __GNUC_PATCHLEVEL__ ) 26 | // Test for GCC > 7.1.0 #if GCC_VERSION > 70100 27 | 28 | // NOTE! Applying ATTR_FORMAT to printf-like function extern declarations 29 | // DOES NOT GUARANTEE that said function will honor 'gnu_printf' style 30 | // format strings e.g. PR_SIZET!!! 31 | // e.g. MinGW GCC 4.8.1 (last 32-bit Nuwen MinGW GCC release): 32 | // vfprintf DOES NOT honor 'gnu_printf', while 33 | // vsnprintf DOES honor 'gnu_printf' 34 | // UNLESS: must 35 | // #define __USE_MINGW_ANSI_STDIO 1 36 | // before 37 | // #include'ing any stdlib h files 38 | // this is (now) done in ed_main.h 39 | 40 | #ifndef ATTR_FORMAT 41 | #ifdef __GNUC__ 42 | #define ATTR_FORMAT(xx,yy) __attribute__ ((format (gnu_printf, xx, yy))) 43 | #else 44 | #define ATTR_FORMAT(xx,yy) 45 | #endif 46 | #endif 47 | 48 | #define ATTR_FALLTHRU [[fallthrough]] 49 | -------------------------------------------------------------------------------- /bin.lua: -------------------------------------------------------------------------------- 1 | -- if you change or add to this module, _please_ update test\k_lib.lua accordingly! 2 | 3 | module( "bin", package.seeall ) 4 | 5 | require "util" 6 | 7 | -- very simple un/packer: supports only fixed length byte strings and 1-/2-/4-byte binary numbers 8 | 9 | local function unpack_one( tt, byteSrc, ix, endian ) 10 | local at, bytes = tt:match( "^(%a?)(%d+)$" ) 11 | local errstr = string.format( "unknown unpack[%d] template specifier '%s'", ix, tt ) 12 | util.errassert( bytes, errstr, 3 ) 13 | bytes = 0+bytes 14 | local raw = byteSrc( bytes, string.format( "unpack[%d] '%s'", ix, tt ) ) 15 | if at =="" then return _bin.unpack_num( raw, endian ) end 16 | if at == "s" then return raw end 17 | error( errstr, 3 ) 18 | end 19 | 20 | -- ********** NB!!! There is a 'unpack' function in the Lua global scope! See PiL2e pg 39 21 | 22 | local function unpack( tmplt, endian, byteString ) 23 | local bsbs = util.byteSource( byteString ) 24 | local aTmplts = util.matches( tmplt ) 25 | local rv = {} 26 | for ix,ta in ipairs( aTmplts ) do 27 | rv[ #rv + 1 ] = unpack_one( ta, bsbs, ix, endian ) 28 | end 29 | return rv 30 | end 31 | 32 | function unpackLE( tmplt, byteString ) return unpack( tmplt, false, byteString ) end 33 | function unpackBE( tmplt, byteString ) return unpack( tmplt, true , byteString ) end 34 | 35 | ------------ 36 | 37 | local function pack_one( tt, data, ix, endian ) 38 | local at, bytes = tt:match( "^(%a?)(%d+)$" ) 39 | -- print( "pattern '"..tt.."'".. at ) 40 | local errstr = string.format( "unknown pack[%d] template specifier '%s'", ix, tt ) 41 | util.errassert( bytes, errstr, 3 ) 42 | bytes = 0+bytes 43 | local badparam = string.format( "bad pack[%d] parameter (%s) for template specifier '%s'", ix, type(data), tt ) 44 | if at == "" then 45 | util.errassert( type(data) == "number", badparam, 3 ) 46 | return _bin.pack_num( data, bytes, endian ) 47 | end 48 | if at == "s" then 49 | util.errassert( type(data) == "string", badparam, 3 ) 50 | local rv = data:sub( 1, bytes ) 51 | if #rv < bytes then rv = rv .. string.rep( string.char(0), bytes - #rv ) end 52 | return rv 53 | end 54 | error( errstr, 3 ) 55 | end 56 | 57 | local function pack( tmplt, endian, ... ) 58 | local aData = { ... } 59 | local aTmplts = util.matches( tmplt ) 60 | local rv = {} 61 | for ix,ta in ipairs( aTmplts ) do 62 | local data = table.remove( aData, 1 ) 63 | assert( data, "" ) 64 | rv[ #rv + 1 ] = pack_one( ta, data, ix, endian ) 65 | end 66 | return table.concat( rv ) 67 | end 68 | 69 | function packLE( tmplt, ... ) return pack( tmplt, false, ... ) end 70 | function packBE( tmplt, ... ) return pack( tmplt, true , ... ) end 71 | 72 | -------------------------------------------------------------------------------- /bld_datetime.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2015-2017 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | -- 4 | -- This file is part of K. 5 | -- 6 | -- K is free software: you can redistribute it and/or modify it under the 7 | -- terms of the GNU General Public License as published by the Free Software 8 | -- Foundation, either version 3 of the License, or (at your option) any later 9 | -- version. 10 | -- 11 | -- K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | -- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | -- details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License along 17 | -- with K. If not, see . 18 | -- 19 | 20 | io.write( "/* dynamically generated by bld_datetime.lua */\n", 21 | 'const char kszDtTmOfBuild[] = "'..os.date( '%Y%m%d_%H%M%S' )..'";\n' 22 | ) 23 | -------------------------------------------------------------------------------- /bld_link_unref.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | -- 4 | -- This file is part of K. 5 | -- 6 | -- K is free software: you can redistribute it and/or modify it under the 7 | -- terms of the GNU General Public License as published by the Free Software 8 | -- Foundation, either version 3 of the License, or (at your option) any later 9 | -- version. 10 | -- 11 | -- K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | -- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | -- details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License along 17 | -- with K. If not, see . 18 | -- 19 | 20 | require "strict" 21 | require "tu" 22 | 23 | local ofnm = "link.unref" 24 | 25 | local ofh = assert( io.open( ofnm, "wt" ) ) 26 | 27 | local unrefs = {} 28 | 29 | for line in io.lines() do 30 | local unref = line:match( "undefined reference to `(.+)'" ) 31 | if unref then 32 | unrefs[unref] = (unrefs[unref] or 0) + 1 33 | end 34 | end 35 | 36 | local unrefdCount = 0 37 | for nm, count in pairs( unrefs ) do -- print( "-> \"" .. ix, tb.fxn .. "\"" ) 38 | -- for nm, count in tu.pairsBySortedValues( unrefs ) do -- print( "-> \"" .. ix, tb.fxn .. "\"" ) 39 | ofh:write( string.format("%3d", count), " '", nm, "'\n" ) 40 | unrefdCount = 1+ unrefdCount 41 | end 42 | 43 | if unrefdCount > 0 then 44 | io.stderr:write( unrefdCount, " undefined references, see ", ofnm, "\n" ) 45 | os.exit(1) 46 | end 47 | -------------------------------------------------------------------------------- /build-for-coverity: -------------------------------------------------------------------------------- 1 | # after "installing" (untarring) the coverity tool (which creates directory $coverity_version/), need to create a symlink: 2 | # ln -s $HOME/coverity/$coverity_version $HOME/coverity/cov 3 | cov_bin="$HOME/coverity/cov" ; [ -L "$cov_bin" ] || { printf "symlink $cov_bin does not exist" ; exit 1 ; } 4 | cov_bin="$HOME/coverity/cov/bin" ; [ -d "$cov_bin" ] || { printf "dir $cov_bin does not exist" ; exit 1 ; } 5 | PATH="$PATH:$cov_bin" 6 | cov_bin="$cov_bin/cov-build" ; [ -x "$cov_bin" ] || { printf "$cov_bin is not executable" ; exit 1 ; } 7 | 8 | # apparently the tarball filename MUST BE same as the Coverity Project Name? 9 | my_cov_projnm=k_edit 10 | tarball=${my_cov_projnm}.tgz 11 | cov_output_dir=cov-int 12 | k_make_cmd="make -j 6" 13 | 14 | rm -rf $cov_output_dir \ 15 | && rm -f $tarball \ 16 | && mkdir -p $cov_output_dir \ 17 | && make clean \ 18 | && cov-build --dir $cov_output_dir $k_make_cmd \ 19 | && tar czvf $tarball $cov_output_dir \ 20 | && printf "%s/$tarball\nis ready to submit to\nhttps://scan.coverity.com/projects/fwmechanic-k_edit\n" `pwd` 21 | -------------------------------------------------------------------------------- /cmdtbl.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/cmdtbl.dat -------------------------------------------------------------------------------- /ctags.d/k-kbackup.ctags: -------------------------------------------------------------------------------- 1 | #!bash 2 | # 3 | # Copyright 2017 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 4 | # 5 | # This file is part of K. 6 | # 7 | # K is free software: you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, either version 3 of the License, or (at your option) any later 10 | # version. 11 | # 12 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | # details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with K. If not, see . 19 | # 20 | 21 | # project-level options for https://github.com/universal-ctags/ctags 22 | 23 | # K drops backup files into child dir .kbackup of the dir of the file 24 | # being backed up, which means .kbackup dirs may be encountered anywhere. 25 | # While these backup files have an extension .yyyyMMdd_hhmmss which 26 | # prevents ctags operating in file-extension pattern-matching mode from 27 | # seeing them, if ctags is operated in --guess-language-eagerly mode 28 | # the peculiar extension of backup files does not inhibit ctags from 29 | # scanning these files. 30 | # 31 | # To make this option, which prevents backup files from being tagged, 32 | # globally effective, this file should be copied to one of: 33 | # $HOME/.ctags.d/*.ctags 34 | # $HOMEDRIVE$HOMEPATH/ctags.d/*.ctags (on MSWindows only) 35 | --exclude=.kbackup 36 | -------------------------------------------------------------------------------- /ctags.d/k-lua51.ctags: -------------------------------------------------------------------------------- 1 | #!bash 2 | # 3 | # Copyright 2020 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 4 | # 5 | # This file is part of K. 6 | # 7 | # K is free software: you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, either version 3 of the License, or (at your option) any later 10 | # version. 11 | # 12 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | # details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with K. If not, see . 19 | # 20 | 21 | # project-level options for https://github.com/universal-ctags/ctags 22 | 23 | # mask Lua's doc files 24 | --exclude=lua-5.1/doc/* 25 | -------------------------------------------------------------------------------- /ctags.d/k-src.ctags: -------------------------------------------------------------------------------- 1 | #!bash 2 | # 3 | # Copyright 2018 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 4 | # 5 | # This file is part of K. 6 | # 7 | # K is free software: you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, either version 3 of the License, or (at your option) any later 10 | # version. 11 | # 12 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | # details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with K. If not, see . 19 | # 20 | 21 | # project-level options for https://github.com/universal-ctags/ctags 22 | 23 | # the two K Lua source files that don't have .lua extension: 24 | --langmap=Lua:+(k.luaedit)(k.filesettings) 25 | 26 | # K uses several macros that hide (expand to) 'static'. This inhibits 27 | # generation of "file:" tag fields, so we unhide them for u-ctags thus: 28 | -I STATIC_FXN=static 29 | -I STATIC_VAR=static 30 | -I STATIC_CONST=static 31 | -I STIL=static 32 | -I GLOBAL_VAR 33 | -I GLOBAL_CONST 34 | -I COMPLEX_STATIC_VAR=static 35 | -------------------------------------------------------------------------------- /display.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/display.cpp -------------------------------------------------------------------------------- /dlink_unittest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015,2021 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #include 21 | #include 22 | #include 23 | #include "my_types.h" 24 | #include "dlink.h" 25 | 26 | #define AEOB( array ) array , ELEMENTS(array), #array 27 | 28 | struct inta { 29 | const int a; 30 | DLinkEntry dlink; 31 | inta( int a_ ) : a( a_ ) {} 32 | }; 33 | 34 | typedef DLinkHead head_t; 35 | 36 | void assert_inta( const head_t &hd, const int arr[], const size_t els, const char *nm ) { 37 | if( els != hd.length() ) { 38 | std::cerr << nm << ": count miscmp: " << els << " != " << hd.length() << "\n"; 39 | exit(1); 40 | } 41 | auto ix = 0u; 42 | DLINKC_FIRST_TO_LASTA( hd, dlink, pEl ) { 43 | if( pEl->a != arr[ix] ) { 44 | std::cerr << nm << "[" << ix << "]: miscmp: " << pEl->a << " != " << arr[ix] << "\n"; 45 | exit(1); 46 | } 47 | ++ix; 48 | } 49 | if( els != ix ) { 50 | std::cerr << nm << ": overrun: " << els << " != " << ix << "\n"; 51 | exit(1); 52 | } 53 | } 54 | 55 | int main() { 56 | head_t Hd; 57 | 58 | DLINK_INSERT_FIRST(Hd, new inta( 1 ), dlink); { const int ref1[] = { 1 }; assert_inta( Hd, AEOB( ref1 ) ); } 59 | DLINK_INSERT_LAST(Hd, new inta( 2 ), dlink); { const int ref2[] = { 1,2 }; assert_inta( Hd, AEOB( ref2 ) ); } 60 | DLINK_INSERT_LAST(Hd, new inta( 3 ), dlink); { const int ref3[] = { 1,2,3 }; assert_inta( Hd, AEOB( ref3 ) ); } 61 | DLINK_INSERT_FIRST( Hd, new inta( 12 ), dlink ); { const int ref3[] = { 12,1,2,3 }; assert_inta( Hd, AEOB( ref3 ) ); } 62 | auto pNew = new inta( 0 ); 63 | DLINK_INSERT_BEFORE( Hd, Hd.front(), pNew, dlink ); { const int ref4[] = { 0,12,1,2,3 }; assert_inta( Hd, AEOB( ref4 ) ); } 64 | assert( Hd.front() == pNew ); 65 | 66 | DLINK_INSERT_BEFORE( Hd, pNew, new inta( -1 ), dlink ); { const int ref5[] = { -1,0,12,1,2,3 }; assert_inta( Hd, AEOB( ref5 ) ); } 67 | DLINK_INSERT_AFTER( Hd, pNew, new inta( -2 ), dlink ); { const int ref8[] = { -1,0,-2,12,1,2,3 }; assert_inta( Hd, AEOB( ref8 ) ); } 68 | DLINK_REMOVE(Hd, pNew, dlink); { const int ref6[] = { -1,-2,12,1,2,3 }; assert_inta( Hd, AEOB( ref6 ) ); } 69 | delete pNew; 70 | DLINK_INSERT_BEFORE( Hd, Hd.back(),new inta( 0 ),dlink ); 71 | head_t Hd2; 72 | { const int ref7[] = { -1,-2,12,1,2,0,3 }; assert_inta( Hd, AEOB( ref7 ) ); 73 | DLINK_MOVE_HD( Hd2, Hd ); assert_inta( Hd2, AEOB( ref7 ) ); 74 | assert( Hd.empty() ); 75 | } 76 | DLINK_INSERT_FIRST( Hd, new inta( 20 ), dlink ); 77 | DLINK_INSERT_FIRST( Hd, new inta( 21 ), dlink ); 78 | DLINK_INSERT_FIRST( Hd, new inta( 22 ), dlink ); { const int ref9[] = { 22,21,20 }; assert_inta( Hd, AEOB( ref9 ) ); } 79 | DLINK_JOIN(Hd, Hd2, dlink); { const int refA[] = { 22,21,20,-1,-2,12,1,2,0,3 }; assert_inta( Hd, AEOB( refA ) ); } 80 | assert( Hd2.empty() ); 81 | std::cout << "PASS\n"; 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /docs/wuc.md: -------------------------------------------------------------------------------- 1 | ## WUC = "Word Under Cursor" display highlighting 2 | 3 | This is a K facility that (unbidden, as part of the display (highlight) 4 | subsystem) highlights _other_ instances of the WUC. 5 | 6 | WUC-determination is done using the `wordchars` switch setting (plus evolutions; see below). 7 | 8 | This feature _does not highlight_ the actual WUC; I find this too distracting 9 | (highlighting gyrations atop the cursor make it hard to follow the cursor 10 | itself). Highlight changes _away from the cursor_ are less distracting (and are 11 | the _entire_ point of WUC highlighting!). 12 | 13 | The WUC is used (by default) for tag lookups (NOARG `tags`). This of course has 14 | some interesting/unforeseen implications (the effect of "simple changes" is 15 | seldom simple)... 16 | 17 | This feature started out simple, and evolved to become more complex. The 18 | evolution is ongoing... 19 | 20 | ### Evolution: variant-WUC highlighting 21 | 22 | In my career, I encountered identifiers which were semantically identical, but 23 | syntactically different. Examples: 24 | 25 | 1. __bash__ variables: assigned with `var=val`, referenced (read) with `$var` or `${var}`. 26 | 27 | 2. __make__ variables; similar to __bash__; assigned with `VAR=val`, referenced with `$(VAR)` 28 | 29 | 3. Hexadecimal values: some tools inconsistently provide or omit "0x" prefix (in the same file) on hex values. 30 | 31 | Variant-WUC highlighting will highlight-match any variant. These capabilities 32 | are hard-coded in K's C++ code ; see `HiliteAddin_WordUnderCursor::SetNewWuc()` 33 | and are sufficiently non-intersecting or benign that they are enabled always. 34 | 35 | ### Evolution: class/struct name hierarchial-join 36 | 37 | Experimental feature: as I get more involved in comprehending Python code which tends to be coded as 38 | 39 | ```python 40 | def __init__(self, deduct) 41 | self.deduct = deduct 42 | ``` 43 | 44 | in such code, existing K WUC highlighting will not distinguish between 45 | `self.deduct` and `deduct`; all instances will be highlighted. There is more 46 | value in highlighting only instances of `self.deduct` or only instances of 47 | `deduct` (the coincidence of variable and member names cannot be relied upon the 48 | confer an actual relationship (worth highlighting) between the two). To 49 | accomplish this in a (mostly-)language-independent manner, a switch `hljoinchars` 50 | was created, and when looking for the left end of the WUC, the set of chars from 51 | the union of hljoinchars and wordchars is used to define the set chars that 52 | comprise the WUC. 53 | 54 | ### More heuristic exploration 55 | 56 | I'm finding that `self.deduct` is an interesting WUC whereas `self.deduct()` is 57 | less so (especially if `deduct()` is a mutator). Meaning I might be more 58 | interested in _all_ occurrences of `deduct()` being called rather than only calls 59 | to `deduct()` on `self`. But there isn't a clear winner here; it's very 60 | situational. 61 | 62 | ### Implementation shortcomings 63 | 64 | Some languages use a multicharacter "hierarchial-join 65 | phrase" (`->`) which does not align correctly with a simpleminded character-set 66 | implementation. `hljoinchars: .->` might be set for such languages, and would 67 | see all of `yourval-myval` as a WUC when a char of `myval` is under the cursor 68 | (instead of `myval` alone). So far this has not bit me, as in most code I would 69 | write `yourval - myval` (spaces surrounding `-`). But for code I didn't write, 70 | this will likely be a problem (and demand switching the WUC parsing 71 | implementation `GetWordUnderPoint()` from charset-based to regex-based). 72 | 73 | The interesting part of the implementation is that `GetWordUnderPoint()` 74 | searches forward __and backward__ from the cursor location. I'm unsure whether 75 | searching backward is something Regex supports (my gut feel is "no"). I think I 76 | would have to find all matches on a line, and then find if the cursor falls 77 | within any of them. This seems to not scale well for very long lines, unless the 78 | result for the line could be cached until the cursor line changes (by the cursor 79 | changing lines or the cursor line content changing). 80 | -------------------------------------------------------------------------------- /drmingw_jit_install.bat: -------------------------------------------------------------------------------- 1 | @if not exist %~dp0drmingw.exe echo you need to copy this script to a directory containing drmingw.exe& goto :eof 2 | echo versioning&@%~dp0drmingw.exe --version || (echo @%~dp0drmingw.exe --version FAILED& goto :eof) 3 | echo installing&@%~dp0drmingw.exe --install --auto || (echo @%~dp0drmingw.exe --install --auto FAILED& goto :eof) 4 | echo @%~dp0drmingw.exe --install --auto SUCCEEDED 5 | -------------------------------------------------------------------------------- /dv.bat: -------------------------------------------------------------------------------- 1 | @start dbgview.exe 2 | -------------------------------------------------------------------------------- /ed_main.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2018 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | #if !defined(WL) 23 | // porting abbreviation tool 24 | #if defined(_WIN32) 25 | # define WL(ww,ll) ww 26 | #else 27 | # define WL(ww,ll) ll 28 | #endif 29 | #endif 30 | 31 | #if defined(_WIN32) 32 | // in order to use _stat64 33 | // http://stackoverflow.com/questions/12539488/determine-64-bit-file-size-in-c-on-mingw-32-bit 34 | // MUST be defined before any MINGW .h file is #included 35 | #define __MSVCRT_VERSION__ 0x0601 36 | #endif 37 | 38 | #if defined(_WIN32) 39 | // see https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/ 40 | // must define __USE_MINGW_ANSI_STDIO before ANY toolchain #includes 41 | // though we're theoretically NOT supposed to be doing this http://mingw.5.n7.nabble.com/snprintf-and-USE-MINGW-ANSI-STDIO-td35399.html 42 | #define __USE_MINGW_ANSI_STDIO 1 43 | #endif 44 | 45 | // std C/C++ headers 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #if defined(__USE_MINGW_ANSI_STDIO) && (__USE_MINGW_ANSI_STDIO != 0) 52 | // for some reason, fprintf is excluded from the effect of __USE_MINGW_ANSI_STDIO in stdio.h ? 53 | # define fprintf __mingw_fprintf 54 | #endif 55 | #include 56 | #include 57 | #include 58 | // standard-ish C headers 59 | #include // for alloca() 60 | #include // for struct _stat 61 | #if !defined(_WIN32) 62 | // Linux-specific string fxns: strcasecmp, strncasecmp, etc. 63 | #include "strings.h" 64 | #endif 65 | 66 | // std C++ headers 67 | #include 68 | #include // for std::move,std::swap 69 | #include 70 | #include 71 | #include 72 | #include 73 | 74 | //***************** ***************** 75 | //***************** begin project-header includes ***************** 76 | //***************** ***************** 77 | 78 | // "feature-flags" for project-header includes 79 | #define DEBUG_LOGGING 1 80 | #define OLDGREP 0 81 | #define DBGHILITE 0 82 | #define MOUSE_SUPPORT WL(1,0) 83 | #define VARIABLE_WINBORDER WL(1,0) 84 | #define USE_STAT64 0 85 | 86 | #if defined(_WIN32) 87 | #else 88 | #define _MAX_PATH 513 89 | #endif 90 | 91 | #include "my_types.h" 92 | #include "ed_mem.h" 93 | #include "my_strutils.h" 94 | #include "filename.h" 95 | #include "dlink.h" 96 | #include "stringlist.h" 97 | #include "krbtree.h" 98 | #include "ed_core.h" 99 | #include "ed_os_generic.h" 100 | 101 | //--------------------------------- 102 | #define CMDTBL_H_CMD_TBL_PTR_MACROS 103 | #include "cmdtbl.h" 104 | #undef CMDTBL_H_CMD_TBL_PTR_MACROS 105 | //--------------------------------- 106 | 107 | #include "ed_vars.h" 108 | #include "ed_edkc.h" 109 | #include "ed_protos.h" 110 | #include "my_log.h" 111 | -------------------------------------------------------------------------------- /ed_os_generic.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015, 2021 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | #include "os_services.h" 23 | 24 | #include "stringlist.h" 25 | 26 | //-------------------------------------------------------------------------------------------- 27 | 28 | #if defined(_WIN32) 29 | extern int EditorLoadCount(); 30 | extern bool EditorLoadCountChanged(); 31 | 32 | extern bool RunChildSpawnOrSystem( PCChar pCmdStr ); 33 | extern bool KillAllBkgndProcesses(); 34 | 35 | extern bool popen_rd_ok( std::string &dest, PCChar szcmdline ); 36 | extern bool cygpath_xlat( std::string &stbuf ); 37 | 38 | extern size_t GetProcessMem(); 39 | 40 | extern bool IsCompileJobQueueThreadActive(); 41 | 42 | extern bool CompileJobQueueWaitExeDoneTimedout( int timeoutMS ); 43 | 44 | extern int CompilePty_CmdsAsyncExec( const StringList &sl, bool fAppend ); 45 | 46 | extern int CompilePty_KillAllJobs(); 47 | 48 | extern void win_fully_on_desktop(); 49 | 50 | extern int StartGuiProcess( PCChar pFullCommandLine ); 51 | extern int StartConProcess( PCChar pFullCommandLine ); 52 | // extern int StartProcess( PCChar pFullCommandLine, int fWaitForProcessDone, int fDetachedProcess ); 53 | #else 54 | STIL int EditorLoadCount() { return 1; } 55 | STIL bool EditorLoadCountChanged() { return false; } 56 | STIL bool RunChildSpawnOrSystem( PCChar pCmdStr ) { return true; } 57 | STIL bool KillAllBkgndProcesses() { return true; } 58 | STIL size_t GetProcessMem() { return 8 * 1024 * 1024; } 59 | STIL bool IsCompileJobQueueThreadActive() { return false; } 60 | STIL bool CompileJobQueueWaitExeDoneTimedout( int timeoutMS ) { return true; } 61 | STIL int CompilePty_CmdsAsyncExec( const StringList &sl, bool fAppend ) { return 0; } 62 | STIL int CompilePty_KillAllJobs() { return 1; } 63 | STIL void win_fully_on_desktop() {} 64 | STIL int StartGuiProcess( PCChar pFullCommandLine ) { return 1; } 65 | STIL int StartConProcess( PCChar pFullCommandLine ) { return 1; } 66 | #endif 67 | extern void StartShellExecuteProcess( PCChar pFullCmdLn, PCChar pExeFile=nullptr ); 68 | 69 | extern PFBUF StartInternalShellJob( StringList *sl, bool fAppend ); 70 | extern void DetachIdleThread(); 71 | 72 | extern PCChar OsErrStr( PChar dest, size_t sizeofDest, int errorCode ); 73 | extern PCChar OsErrStr( PChar dest, size_t sizeofDest ); 74 | -------------------------------------------------------------------------------- /ed_search.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2016 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | class RegexMatchCapture { 23 | sridx d_ofs; 24 | stref d_value; 25 | public: 26 | RegexMatchCapture() : d_ofs( eosr ), d_value( ) {} 27 | RegexMatchCapture( int ofs_, stref val_ ) : d_ofs(ofs_ < 0 ? eosr : ofs_), d_value(val_) {} 28 | bool valid() const { return d_ofs != eosr; } 29 | stref value() const { return d_value; } 30 | sridx offset() const { return d_ofs ; } 31 | }; 32 | typedef std::vector RegexMatchCaptures; 33 | extern int DbgDumpCaptures( RegexMatchCaptures &captures, PCChar tag ); 34 | 35 | #if USE_PCRE 36 | 37 | #include "pcre2.h" 38 | 39 | class CompiledRegex; 40 | extern CompiledRegex *Regex_Compile( stref pszSearchStr, bool fCase ); 41 | extern CompiledRegex *Regex_Delete0( CompiledRegex *pcr ); 42 | extern RegexMatchCaptures::size_type Regex_Match( CompiledRegex *pcr, RegexMatchCaptures &captures, stref haystack, COL haystack_offset, int pcre_exec_options ); 43 | extern void register_atexit_search(); 44 | extern stref RegexVersion(); 45 | 46 | #else 47 | 48 | #define register_atexit_search() 49 | STIL stref RegexVersion() { return ""; } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /fbuf.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/fbuf.cpp -------------------------------------------------------------------------------- /fbuf_edit.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/fbuf_edit.cpp -------------------------------------------------------------------------------- /features/cygpath_mode.txt: -------------------------------------------------------------------------------- 1 | Problem: 2 | My chosen Windows shell environment is GitForWindows bash. In this 3 | environment, constructing [bash] cmdlines using "Windows format" filenames 4 | provided by K (e.g. from ) is labor-intensive and error-prone. 5 | 6 | Possible solutions: 7 | 8 | Implementation of CYPTL ("CYgPath Translation Layer") mimicking the 9 | functionality of `cygpath` (reinvention of the wheel? Would rather not). 10 | 11 | When to enable this translation layer? if $SHELL:match("[/\\]bash.exe$") 12 | 13 | What about shell cmdline param translation? Ugh, parsing a cmdline would suck. 14 | 15 | What about declaring a bash alias/function cyp() { cygpath "$1" ; } and 16 | (yes, manually) coding cmdline tokens w/ "$(cyp 'pasted-filename')" ; but 17 | that's still __A LOT__ of picky TYPING. 18 | 19 | Maybe a new function derivative of lasttext which runs cygpath on the select text? 20 | 21 | But maybe it's better to wait 22 | -------------------------------------------------------------------------------- /fn_text.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/fn_text.cpp -------------------------------------------------------------------------------- /fname_gen.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015,2021 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | #include "ed_main.h" 23 | 24 | class PathStrGenerator { // interface class 25 | NO_COPYCTOR(PathStrGenerator); 26 | NO_ASGN_OPR(PathStrGenerator); 27 | std::string d_src; 28 | public: 29 | PathStrGenerator( std::string &src ) : d_src( src ) {} 30 | virtual bool VGetNextName( Path::str_t &dest ) = 0; 31 | stref srSrc() { return d_src; } 32 | virtual ~PathStrGenerator() {} 33 | }; 34 | 35 | class WildcardFilenameGenerator : public PathStrGenerator { 36 | NO_COPYCTOR(WildcardFilenameGenerator); 37 | NO_ASGN_OPR(WildcardFilenameGenerator); 38 | DirMatches d_dm; 39 | public: 40 | WildcardFilenameGenerator( std::string &&src, PCChar string, WildCardMatchMode matchMode=ONLY_FILES ) 41 | : PathStrGenerator( src ) 42 | , d_dm( string, nullptr, matchMode ) 43 | {} 44 | // DTOR auto-generated 45 | bool VGetNextName( Path::str_t &dest ) override; 46 | }; 47 | 48 | class DirListGenerator : public PathStrGenerator { 49 | NO_COPYCTOR( DirListGenerator ); 50 | NO_ASGN_OPR( DirListGenerator ); 51 | StringList d_input ; 52 | StringList d_output; 53 | void AddName( stref name ); 54 | public: 55 | DirListGenerator( std::string &&src, PCChar dirName=nullptr ); 56 | ~DirListGenerator(); 57 | bool VGetNextName( Path::str_t &dest ) override; 58 | }; 59 | 60 | class DicedOnDelimString : public DiceableString { 61 | public: 62 | DicedOnDelimString( stref str, PCChar pszDelims ) 63 | : DiceableString( str ) 64 | { 65 | extern void ChopAscizzOnDelim( PChar cur, PCChar pszDelim ); 66 | ChopAscizzOnDelim( d_heapString, pszDelims ); 67 | } 68 | }; 69 | 70 | class StrSubstituterGenerator; // "static" 71 | 72 | class CfxFilenameGenerator : public PathStrGenerator { 73 | NO_COPYCTOR(CfxFilenameGenerator); 74 | NO_ASGN_OPR(CfxFilenameGenerator); 75 | WildcardFilenameGenerator *d_pWcGen = nullptr; 76 | StrSubstituterGenerator *d_pSSG = nullptr; 77 | DicedOnDelimString d_splitLine; 78 | WildCardMatchMode d_matchMode; 79 | PCChar d_pszEntrySuffix = nullptr; 80 | public: 81 | CfxFilenameGenerator( std::string &&src, stref macroText, WildCardMatchMode matchMode ); 82 | bool VGetNextName( Path::str_t &dest ) override; 83 | virtual ~CfxFilenameGenerator(); 84 | }; 85 | 86 | //----------------------------------- 87 | 88 | class FilelistCfxFilenameGenerator : public PathStrGenerator { 89 | NO_COPYCTOR( FilelistCfxFilenameGenerator ); 90 | NO_ASGN_OPR( FilelistCfxFilenameGenerator ); 91 | PFBUF d_pFBuf; 92 | LINE d_curLine = 0; 93 | CfxFilenameGenerator *d_pCfxGen = nullptr; 94 | Path::str_t d_sbuf; 95 | std::string d_nmBuf; 96 | public: 97 | FilelistCfxFilenameGenerator( std::string &&src, PFBUF pFBuf ) 98 | : PathStrGenerator( src ) 99 | , d_pFBuf( pFBuf ) 100 | , d_nmBuf( src ) 101 | {} 102 | bool VGetNextName( Path::str_t &dest ) override; 103 | virtual ~FilelistCfxFilenameGenerator() { Delete0( d_pCfxGen ); } 104 | }; 105 | 106 | //----------------------------------- 107 | -------------------------------------------------------------------------------- /getopt.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | 23 | #include "ed_main.h" 24 | #include "my_strutils.h" 25 | 26 | class Getopt 27 | { 28 | const int d_argc; // saved parameter 29 | const PPCChar d_argv; // saved parameter 30 | const PCChar d_pOptSet; // saved parameter 31 | 32 | int d_argi = 1; // index of which argument is next 33 | PCChar d_pOptarg = nullptr; // pointer to argument of current option (if any) 34 | PCChar d_pAddlOpt = nullptr; // remember next option char's location. If d_pAddlOpt is not nullptr 35 | // it is pointing into a string at an option character (a SW 36 | // char has already been seen) 37 | typedef char pathbuf[_MAX_PATH+1]; 38 | 39 | 40 | protected: 41 | 42 | Path::str_t d_pgm; // name w/o path or extension 43 | 44 | public: 45 | 46 | virtual void VErrorOut( PCChar emsg ) = 0; 47 | 48 | Getopt( int argc_, PPCChar argv_, PCChar optset_ ); 49 | virtual ~Getopt() {} 50 | int NextOptCh(); 51 | PCChar optarg() const { return d_pOptarg; } 52 | PCChar nextarg() { return (d_argi < d_argc) ? d_argv[d_argi++] : nullptr; } 53 | }; 54 | -------------------------------------------------------------------------------- /git_cat_local_config: -------------------------------------------------------------------------------- 1 | cat .git/config 2 | -------------------------------------------------------------------------------- /git_set_fwmechanic_ident: -------------------------------------------------------------------------------- 1 | git config --local user.email fwmechanic@gmail.com 2 | git config --local user.name "Kevin Goodwin" 3 | -------------------------------------------------------------------------------- /historical_scans_fair_use/1988.09-MS.Journal-Notenboom-Customizing.M.Editor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/historical_scans_fair_use/1988.09-MS.Journal-Notenboom-Customizing.M.Editor.pdf -------------------------------------------------------------------------------- /historical_scans_fair_use/2001.07-MSDN.News-Michell-PWB.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/historical_scans_fair_use/2001.07-MSDN.News-Michell-PWB.pdf -------------------------------------------------------------------------------- /historical_scans_fair_use/README.txt: -------------------------------------------------------------------------------- 1 | 1986.08.04-Z.TXT "User's Guide to the Z Editor", Mark Zbikowski, 4 August 1986 2 | retrieved from http://www.pcjs.org/disks/pcx86/tools/microsoft/misc/root/Z.TXT 3 | 4 | Z-cleaned.TXT is 1986.08.04-Z.TXT with pagination and page headers/footers 5 | removed. 6 | 7 | see also a scan of the M 1.00 manual (included as part of MSC 5.1): 8 | http://archive.pcjs.org/pubs/pc/software/tools/microsoft/c/5.10/MSC51-EDITOR.pdf 9 | -------------------------------------------------------------------------------- /install_build_tools_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2015-2021 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 5 | # 6 | # This file is part of K. 7 | # 8 | # K is free software: you can redistribute it and/or modify it under the 9 | # terms of the GNU General Public License as published by the Free Software 10 | # Foundation, either version 3 of the License, or (at your option) any later 11 | # version. 12 | # 13 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 14 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 | # details. 17 | # 18 | # You should have received a copy of the GNU General Public License along 19 | # with K. If not, see . 20 | # 21 | 22 | # run to unilaterally install prereqs for building & running K 23 | 24 | hdr="$ID K-prereq-install: " 25 | complete() { 26 | local rv="$?" 27 | [ "$rv" -gt "0" ] && { echo "${hdr}FAILED" ; exit 1 ; } 28 | echo "to build & install universal-ctags: run ./ubuntu_univ-ctags_build_install" 29 | echo "${hdr}SUCCEEDED" 30 | exit 0 31 | } 32 | 33 | . /etc/os-release 34 | 35 | if [[ "$ID" = "ubuntu" || "$ID" = "pop" ]] ; then 36 | echo "${hdr}STARTING" 37 | sudo apt-get install -yq \ 38 | build-essential \ 39 | g++ \ 40 | libboost-dev \ 41 | libboost-filesystem-dev \ 42 | libboost-system-dev \ 43 | libncurses5-dev \ 44 | libpcre2-dev \ 45 | ncurses-term \ 46 | libreadline-dev \ 47 | universal-ctags \ 48 | xclip 49 | complete 50 | fi 51 | 52 | if [ "$ID" = "centos" ] ; then 53 | echo "${hdr}STARTING" 54 | yum -yq groupinstall "Development Tools" && 55 | yum -yq install boost-devel ncurses-devel pcre2-devel pcre2-static ncurses-term readline-devel && 56 | yum -yq install exuberant-ctags && 57 | yum -yq install xclip 58 | complete 59 | fi 60 | 61 | echo "${hdr}FAILED: '$ID' unknown" ; 62 | exit 1 63 | 64 | # notes (not used): alternative yum version 65 | yum groupinstall "Development Tools" 66 | yum install libboost-devel 67 | yum install libboost-filesystem-devel 68 | yum install libboost-system-devel 69 | yum install libncurses5-devel 70 | yum install libpcre3-devel 71 | yum install exuberant-ctags 72 | yum install ncurses-term 73 | yum install xclip 74 | -------------------------------------------------------------------------------- /k.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2016 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | // 21 | // CONVERTING THIS TO COMPILE WITH C-language to make k.exe smaller DOES NOT 22 | // WORK. Don't bother (again). 23 | // 24 | 25 | #include 26 | #include 27 | 28 | const char entrypoint[] = 29 | #if defined(__GNUC__) 30 | 31 | #ifdef __x86_64 32 | "Main" ; 33 | #else 34 | "Main@12" ; 35 | #endif 36 | 37 | int _CRT_glob = 0; // suppress default MinGW argv globbing http://cygwin.com/ml/cygwin/1999-11/msg00052.html 38 | 39 | #else 40 | "_Main@12"; 41 | #endif 42 | 43 | #if defined(_WIN32) 44 | #define CDECL__ __cdecl 45 | #else 46 | #define CDECL__ 47 | #endif 48 | 49 | int CDECL__ main( int argc, char *argv[], char *envp[] ) { 50 | char buf[ MAX_PATH+1 ]; 51 | const auto len( GetModuleFileName( nullptr, buf, sizeof buf ) ); 52 | if( len >= sizeof(buf) ) { 53 | fprintf( stderr, "GetModuleFileName rv (%lu) >= sizeof(buf) (%" PR_SIZET ")\n", len, sizeof(buf) ); 54 | return 1; 55 | } 56 | 57 | for( auto pExt = buf + strlen( buf ) - 1; pExt > buf; --pExt ) { 58 | // fprintf( stderr, "'%c' ?\n" ); 59 | if( *pExt == '.' ) { 60 | #if 0 61 | pExt[1] = 'd'; // load K.DLL 62 | pExt[2] = 'l'; 63 | pExt[3] = 'l'; 64 | pExt[4] = 0 ; 65 | #elif 1 66 | pExt[0] = 'x'; // load KX.DLL 67 | pExt[1] = '.'; 68 | pExt[2] = 'd'; 69 | pExt[3] = 'l'; 70 | pExt[4] = 'l'; 71 | pExt[5] = 0 ; 72 | #else 73 | # error 74 | #endif 75 | 76 | // fprintf( stderr, "MFN '%s'\n", buf ); 77 | 78 | auto hDLL = LoadLibrary( buf ); 79 | if( !hDLL ) { 80 | fprintf( stderr, "LoadLibrary( '%s' ) failed; Error: %lu\n", buf, GetLastError() ); 81 | return 1; 82 | } 83 | 84 | typedef void (*FxnMain)( int argc, char *argv[], char *envp[] ); 85 | 86 | const auto editor_main( FxnMain( GetProcAddress( hDLL, entrypoint ) ) ); // NB: cannot use static_cast to replace C-style cast here 87 | if( !editor_main ) { 88 | FreeLibrary( hDLL ); 89 | fprintf( stderr, "GetProcAddress(%s) failed\n", argv[0] ); 90 | return 1; 91 | } 92 | 93 | editor_main( argc, argv, envp ); // never returns 94 | return 1; // just in case ... 95 | } 96 | } 97 | return 1; // should not get here 98 | } 99 | -------------------------------------------------------------------------------- /k.luaedit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/k.luaedit -------------------------------------------------------------------------------- /k.rc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | // http://stackoverflow.com/questions/708238/how-do-i-add-an-icon-to-a-mingw-gcc-compiled-executable 21 | 22 | id ICON "k.ico" 23 | 24 | 1 VERSIONINFO 25 | FILEVERSION 1,0,0,0 26 | PRODUCTVERSION 1,0,0,0 27 | BEGIN 28 | BLOCK "StringFileInfo" 29 | BEGIN 30 | BLOCK "040904E4" 31 | BEGIN 32 | VALUE "CompanyName", "My Company Name" 33 | VALUE "FileDescription", "Kevin's excellent programmer's text editor" 34 | VALUE "FileVersion", "1.0" 35 | VALUE "InternalName", "K" 36 | VALUE "LegalCopyright", "" 37 | VALUE "OriginalFilename", "k.exe" 38 | VALUE "ProductName", "K Editor" 39 | VALUE "ProductVersion", "1.0" 40 | END 41 | END 42 | 43 | BLOCK "VarFileInfo" 44 | BEGIN 45 | VALUE "Translation", 0x409, 1252 46 | END 47 | END 48 | -------------------------------------------------------------------------------- /k.workspace: -------------------------------------------------------------------------------- 1 | #!lua 2 | -- 3 | -- Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 4 | -- 5 | -- This file is part of K. 6 | -- 7 | -- K is free software: you can redistribute it and/or modify it under the 8 | -- terms of the GNU General Public License as published by the Free Software 9 | -- Foundation, either version 3 of the License, or (at your option) any later 10 | -- version. 11 | -- 12 | -- K is distributed in the hope that it will be useful, but WITHOUT ANY 13 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | -- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | -- details. 16 | -- 17 | -- You should have received a copy of the GNU General Public License along 18 | -- with K. If not, see . 19 | -- 20 | 21 | -- bring ObjectShow !!! 22 | 23 | local a_wsdir = { wsdir } 24 | local a_luasrc = { wsdir.."lua-5.1/src/" } 25 | local wc_c = { "*.h", "*.c", "*.cpp" } 26 | 27 | mfx = { 28 | ksrc = a_cross( a_wsdir , wc_c ), 29 | luac = a_cross( a_luasrc, wc_c ), 30 | } 31 | mfx.all_c = a_cat( mfx.ksrc, mfx.luac ) 32 | 33 | show( mfx ) 34 | -------------------------------------------------------------------------------- /krmbak: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dnm='.kbackup' 3 | dinpath='*/'"$dnm"'/*' 4 | show() ( 5 | dct="$(find . -type d -name "$dnm" | wc -l)" 6 | fct="$(find . -path "$dinpath" -type f | wc -l)" 7 | echo "$1 $fct files in $dct $dnm dirs" 8 | ) 9 | list() ( 10 | find . -path "$dinpath" -type f | sort -i 11 | ) 12 | case "$1" in 13 | rmall) show "deleting" ; 14 | find . -type d -name "$dnm" -exec rm -r {} + 15 | ;; 16 | list) list 17 | ;; 18 | *) show "there are" 19 | echo " list to list all files" 20 | echo " rmall to delete all files/dirs" 21 | ;; 22 | esac 23 | -------------------------------------------------------------------------------- /krmlog: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find $(dirname $0) -name 'k-*.log' | xargs rm -f 3 | -------------------------------------------------------------------------------- /linux_base.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | #if defined(__GNUC__) 23 | #pragma GCC diagnostic push 24 | #pragma GCC diagnostic ignored "-Wold-style-cast" 25 | #endif 26 | 27 | //############################################################################## 28 | 29 | STIL void DebugLog( PCChar string ) { /* Win32::OutputDebugString( string ); */ } 30 | 31 | extern bool IsFileReadonly( PCChar pFBufName ); 32 | extern bool FileOrDirExists( PCChar lpFBufName ); 33 | 34 | struct WhileHoldingGlobalVariableLock 35 | { 36 | WhileHoldingGlobalVariableLock() ; 37 | ~WhileHoldingGlobalVariableLock() ; 38 | }; 39 | 40 | extern void MainThreadGiveUpGlobalVariableLock() ; 41 | extern void MainThreadWaitForGlobalVariableLock() ; 42 | -------------------------------------------------------------------------------- /lua-5.1/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 1994-2012 Lua.org, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /lua-5.1/MANIFEST: -------------------------------------------------------------------------------- 1 | MANIFEST contents of Lua 5.1 distribution on Mon Feb 20 11:37:30 BRT 2006 2 | lua-5.1 3 | lua-5.1/COPYRIGHT 4 | lua-5.1/HISTORY 5 | lua-5.1/INSTALL 6 | lua-5.1/MANIFEST 7 | lua-5.1/Makefile 8 | lua-5.1/README 9 | lua-5.1/doc 10 | lua-5.1/doc/contents.html 11 | lua-5.1/doc/logo.gif 12 | lua-5.1/doc/lua.1 13 | lua-5.1/doc/lua.css 14 | lua-5.1/doc/lua.html 15 | lua-5.1/doc/luac.1 16 | lua-5.1/doc/luac.html 17 | lua-5.1/doc/manual.html 18 | lua-5.1/doc/readme.html 19 | lua-5.1/etc 20 | lua-5.1/etc/Makefile 21 | lua-5.1/etc/README 22 | lua-5.1/etc/all.c 23 | lua-5.1/etc/lua.hpp 24 | lua-5.1/etc/lua.ico 25 | lua-5.1/etc/lua.pc 26 | lua-5.1/etc/luavs.bat 27 | lua-5.1/etc/min.c 28 | lua-5.1/etc/noparser.c 29 | lua-5.1/etc/strict.lua 30 | lua-5.1/src 31 | lua-5.1/src/Makefile 32 | lua-5.1/src/lapi.c 33 | lua-5.1/src/lapi.h 34 | lua-5.1/src/lauxlib.c 35 | lua-5.1/src/lauxlib.h 36 | lua-5.1/src/lbaselib.c 37 | lua-5.1/src/lcode.c 38 | lua-5.1/src/lcode.h 39 | lua-5.1/src/ldblib.c 40 | lua-5.1/src/ldebug.c 41 | lua-5.1/src/ldebug.h 42 | lua-5.1/src/ldo.c 43 | lua-5.1/src/ldo.h 44 | lua-5.1/src/ldump.c 45 | lua-5.1/src/lfunc.c 46 | lua-5.1/src/lfunc.h 47 | lua-5.1/src/lgc.c 48 | lua-5.1/src/lgc.h 49 | lua-5.1/src/linit.c 50 | lua-5.1/src/liolib.c 51 | lua-5.1/src/llex.c 52 | lua-5.1/src/llex.h 53 | lua-5.1/src/llimits.h 54 | lua-5.1/src/lmathlib.c 55 | lua-5.1/src/lmem.c 56 | lua-5.1/src/lmem.h 57 | lua-5.1/src/loadlib.c 58 | lua-5.1/src/lobject.c 59 | lua-5.1/src/lobject.h 60 | lua-5.1/src/lopcodes.c 61 | lua-5.1/src/lopcodes.h 62 | lua-5.1/src/loslib.c 63 | lua-5.1/src/lparser.c 64 | lua-5.1/src/lparser.h 65 | lua-5.1/src/lstate.c 66 | lua-5.1/src/lstate.h 67 | lua-5.1/src/lstring.c 68 | lua-5.1/src/lstring.h 69 | lua-5.1/src/lstrlib.c 70 | lua-5.1/src/ltable.c 71 | lua-5.1/src/ltable.h 72 | lua-5.1/src/ltablib.c 73 | lua-5.1/src/ltm.c 74 | lua-5.1/src/ltm.h 75 | lua-5.1/src/lua.c 76 | lua-5.1/src/lua.h 77 | lua-5.1/src/luac.c 78 | lua-5.1/src/luaconf.h 79 | lua-5.1/src/lualib.h 80 | lua-5.1/src/lundump.c 81 | lua-5.1/src/lundump.h 82 | lua-5.1/src/lvm.c 83 | lua-5.1/src/lvm.h 84 | lua-5.1/src/lzio.c 85 | lua-5.1/src/lzio.h 86 | lua-5.1/src/print.c 87 | lua-5.1/test 88 | lua-5.1/test/README 89 | lua-5.1/test/bisect.lua 90 | lua-5.1/test/cf.lua 91 | lua-5.1/test/echo.lua 92 | lua-5.1/test/env.lua 93 | lua-5.1/test/factorial.lua 94 | lua-5.1/test/fib.lua 95 | lua-5.1/test/fibfor.lua 96 | lua-5.1/test/globals.lua 97 | lua-5.1/test/hello.lua 98 | lua-5.1/test/life.lua 99 | lua-5.1/test/luac.lua 100 | lua-5.1/test/printf.lua 101 | lua-5.1/test/readonly.lua 102 | lua-5.1/test/sieve.lua 103 | lua-5.1/test/sort.lua 104 | lua-5.1/test/table.lua 105 | lua-5.1/test/trace-calls.lua 106 | lua-5.1/test/trace-globals.lua 107 | lua-5.1/test/xd.lua 108 | END OF MANIFEST 109 | -------------------------------------------------------------------------------- /lua-5.1/README: -------------------------------------------------------------------------------- 1 | README for Lua 5.1 2 | 3 | See INSTALL for installation instructions. 4 | See HISTORY for a summary of changes since the last released version. 5 | 6 | * What is Lua? 7 | ------------ 8 | Lua is a powerful, light-weight programming language designed for extending 9 | applications. Lua is also frequently used as a general-purpose, stand-alone 10 | language. Lua is free software. 11 | 12 | For complete information, visit Lua's web site at http://www.lua.org/ . 13 | For an executive summary, see http://www.lua.org/about.html . 14 | 15 | Lua has been used in many different projects around the world. 16 | For a short list, see http://www.lua.org/uses.html . 17 | 18 | * Availability 19 | ------------ 20 | Lua is freely available for both academic and commercial purposes. 21 | See COPYRIGHT and http://www.lua.org/license.html for details. 22 | Lua can be downloaded at http://www.lua.org/download.html . 23 | 24 | * Installation 25 | ------------ 26 | Lua is implemented in pure ANSI C, and compiles unmodified in all known 27 | platforms that have an ANSI C compiler. In most Unix-like platforms, simply 28 | do "make" with a suitable target. See INSTALL for detailed instructions. 29 | 30 | * Origin 31 | ------ 32 | Lua is developed at Lua.org, a laboratory of the Department of Computer 33 | Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro 34 | in Brazil). 35 | For more information about the authors, see http://www.lua.org/authors.html . 36 | 37 | (end of README) 38 | -------------------------------------------------------------------------------- /lua-5.1/doc/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/lua-5.1/doc/cover.png -------------------------------------------------------------------------------- /lua-5.1/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/lua-5.1/doc/logo.gif -------------------------------------------------------------------------------- /lua-5.1/doc/lrexlib/lrexlib.css: -------------------------------------------------------------------------------- 1 | /* 2 | :Author: Shmuel Zeigerman 3 | :Contact: shmuz at actcom co il 4 | :Copyright: This stylesheet has been placed in the public domain. 5 | 6 | [Optionally place a description here.] 7 | */ 8 | 9 | @import url(html4css1.css); 10 | 11 | hr.docutils { 12 | width: 100% 13 | } 14 | 15 | .funcdef { 16 | font-weight: bold ; 17 | font-size: 100% 18 | } 19 | 20 | body { 21 | margin-left: 1em ; 22 | margin-right: 1em ; 23 | font-family: "Verdana", sans-serif ; 24 | } 25 | 26 | table { 27 | border-spacing: 0; 28 | } 29 | 30 | tr { 31 | margin: 0; 32 | padding: 0; 33 | } 34 | -------------------------------------------------------------------------------- /lua-5.1/doc/lua.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #000000 ; 3 | background-color: #FFFFFF ; 4 | font-family: Helvetica, Arial, sans-serif ; 5 | text-align: justify ; 6 | margin-right: 30px ; 7 | margin-left: 30px ; 8 | } 9 | 10 | h1, h2, h3, h4 { 11 | font-family: Verdana, Geneva, sans-serif ; 12 | font-weight: normal ; 13 | font-style: italic ; 14 | } 15 | 16 | h2 { 17 | padding-top: 0.4em ; 18 | padding-bottom: 0.4em ; 19 | padding-left: 30px ; 20 | padding-right: 30px ; 21 | margin-left: -30px ; 22 | background-color: #E0E0FF ; 23 | } 24 | 25 | h3 { 26 | padding-left: 0.5em ; 27 | border-left: solid #E0E0FF 1em ; 28 | } 29 | 30 | table h3 { 31 | padding-left: 0px ; 32 | border-left: none ; 33 | } 34 | 35 | a:link { 36 | color: #000080 ; 37 | background-color: inherit ; 38 | text-decoration: none ; 39 | } 40 | 41 | a:visited { 42 | background-color: inherit ; 43 | text-decoration: none ; 44 | } 45 | 46 | a:link:hover, a:visited:hover { 47 | color: #000080 ; 48 | background-color: #E0E0FF ; 49 | } 50 | 51 | a:link:active, a:visited:active { 52 | color: #FF0000 ; 53 | } 54 | 55 | hr { 56 | border: 0 ; 57 | height: 1px ; 58 | color: #a0a0a0 ; 59 | background-color: #a0a0a0 ; 60 | } 61 | 62 | :target { 63 | background-color: #F8F8F8 ; 64 | padding: 8px ; 65 | border: solid #a0a0a0 2px ; 66 | } 67 | 68 | .footer { 69 | color: gray ; 70 | font-size: small ; 71 | } 72 | 73 | input[type=text] { 74 | border: solid #a0a0a0 2px ; 75 | border-radius: 2em ; 76 | -moz-border-radius: 2em ; 77 | background-image: url('images/search.png') ; 78 | background-repeat: no-repeat; 79 | background-position: 4px center ; 80 | padding-left: 20px ; 81 | height: 2em ; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /lua-5.1/doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2006/01/06 16:03:34 $" 3 | .SH NAME 4 | luac \- Lua compiler 5 | .SH SYNOPSIS 6 | .B luac 7 | [ 8 | .I options 9 | ] [ 10 | .I filenames 11 | ] 12 | .SH DESCRIPTION 13 | .B luac 14 | is the Lua compiler. 15 | It translates programs written in the Lua programming language 16 | into binary files that can be later loaded and executed. 17 | .LP 18 | The main advantages of precompiling chunks are: 19 | faster loading, 20 | protecting source code from accidental user changes, 21 | and 22 | off-line syntax checking. 23 | .LP 24 | Pre-compiling does not imply faster execution 25 | because in Lua chunks are always compiled into bytecodes before being executed. 26 | .B luac 27 | simply allows those bytecodes to be saved in a file for later execution. 28 | .LP 29 | Pre-compiled chunks are not necessarily smaller than the corresponding source. 30 | The main goal in pre-compiling is faster loading. 31 | .LP 32 | The binary files created by 33 | .B luac 34 | are portable only among architectures with the same word size and byte order. 35 | .LP 36 | .B luac 37 | produces a single output file containing the bytecodes 38 | for all source files given. 39 | By default, 40 | the output file is named 41 | .BR luac.out , 42 | but you can change this with the 43 | .B \-o 44 | option. 45 | .LP 46 | In the command line, 47 | you can mix 48 | text files containing Lua source and 49 | binary files containing precompiled chunks. 50 | This is useful to combine several precompiled chunks, 51 | even from different (but compatible) platforms, 52 | into a single precompiled chunk. 53 | .LP 54 | You can use 55 | .B "'\-'" 56 | to indicate the standard input as a source file 57 | and 58 | .B "'\--'" 59 | to signal the end of options 60 | (that is, 61 | all remaining arguments will be treated as files even if they start with 62 | .BR "'\-'" ). 63 | .LP 64 | The internal format of the binary files produced by 65 | .B luac 66 | is likely to change when a new version of Lua is released. 67 | So, 68 | save the source files of all Lua programs that you precompile. 69 | .LP 70 | .SH OPTIONS 71 | Options must be separate. 72 | .TP 73 | .B \-l 74 | produce a listing of the compiled bytecode for Lua's virtual machine. 75 | Listing bytecodes is useful to learn about Lua's virtual machine. 76 | If no files are given, then 77 | .B luac 78 | loads 79 | .B luac.out 80 | and lists its contents. 81 | .TP 82 | .BI \-o " file" 83 | output to 84 | .IR file , 85 | instead of the default 86 | .BR luac.out . 87 | (You can use 88 | .B "'\-'" 89 | for standard output, 90 | but not on platforms that open standard output in text mode.) 91 | The output file may be a source file because 92 | all files are loaded before the output file is written. 93 | Be careful not to overwrite precious files. 94 | .TP 95 | .B \-p 96 | load files but do not generate any output file. 97 | Used mainly for syntax checking and for testing precompiled chunks: 98 | corrupted files will probably generate errors when loaded. 99 | Lua always performs a thorough integrity test on precompiled chunks. 100 | Bytecode that passes this test is completely safe, 101 | in the sense that it will not break the interpreter. 102 | However, 103 | there is no guarantee that such code does anything sensible. 104 | (None can be given, because the halting problem is unsolvable.) 105 | If no files are given, then 106 | .B luac 107 | loads 108 | .B luac.out 109 | and tests its contents. 110 | No messages are displayed if the file passes the integrity test. 111 | .TP 112 | .B \-s 113 | strip debug information before writing the output file. 114 | This saves some space in very large chunks, 115 | but if errors occur when running a stripped chunk, 116 | then the error messages may not contain the full information they usually do. 117 | For instance, 118 | line numbers and names of local variables are lost. 119 | .TP 120 | .B \-v 121 | show version information. 122 | .SH FILES 123 | .TP 15 124 | .B luac.out 125 | default output file 126 | .SH "SEE ALSO" 127 | .BR lua (1) 128 | .br 129 | http://www.lua.org/ 130 | .SH DIAGNOSTICS 131 | Error messages should be self explanatory. 132 | .SH AUTHORS 133 | L. H. de Figueiredo, 134 | R. Ierusalimschy and 135 | W. Celes 136 | .\" EOF 137 | -------------------------------------------------------------------------------- /lua-5.1/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | float: right ; 12 | font-family: inherit ; 13 | font-style: normal ; 14 | font-size: small ; 15 | color: gray ; 16 | } 17 | 18 | p+h1, ul+h1 { 19 | padding-top: 0.4em ; 20 | padding-bottom: 0.4em ; 21 | padding-left: 30px ; 22 | margin-left: -30px ; 23 | background-color: #E0E0FF ; 24 | } 25 | -------------------------------------------------------------------------------- /lua-5.1/doc/readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lua documentation 4 | 5 | 6 | 7 | 8 | 9 |
10 |

11 | Lua 12 | Documentation 13 |

14 | 15 | This is the documentation included in the source distribution of Lua 5.1.5. 16 | 17 | 25 | 26 | Lua's 27 | official web site 28 | contains updated documentation, 29 | especially the 30 | reference manual. 31 |

32 | 33 |


34 | 35 | Last update: 36 | Fri Feb 3 09:44:42 BRST 2012 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /lua-5.1/etc/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for Lua etc 2 | 3 | TOP= .. 4 | LIB= $(TOP)/src 5 | INC= $(TOP)/src 6 | BIN= $(TOP)/src 7 | SRC= $(TOP)/src 8 | TST= $(TOP)/test 9 | 10 | CC= gcc 11 | CFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS) 12 | MYCFLAGS= 13 | MYLDFLAGS= -Wl,-E 14 | MYLIBS= -lm 15 | #MYLIBS= -lm -Wl,-E -ldl -lreadline -lhistory -lncurses 16 | RM= rm -f 17 | 18 | default: 19 | @echo 'Please choose a target: min noparser one strict clean' 20 | 21 | min: min.c 22 | $(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS) 23 | echo 'print"Hello there!"' | ./a.out 24 | 25 | noparser: noparser.o 26 | $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS) 27 | $(BIN)/luac $(TST)/hello.lua 28 | -./a.out luac.out 29 | -./a.out -e'a=1' 30 | 31 | one: 32 | $(CC) $(CFLAGS) all.c $(MYLIBS) 33 | ./a.out $(TST)/hello.lua 34 | 35 | strict: 36 | -$(BIN)/lua -e 'print(a);b=2' 37 | -$(BIN)/lua -lstrict -e 'print(a)' 38 | -$(BIN)/lua -e 'function f() b=2 end f()' 39 | -$(BIN)/lua -lstrict -e 'function f() b=2 end f()' 40 | 41 | clean: 42 | $(RM) a.out core core.* *.o luac.out 43 | 44 | .PHONY: default min noparser one strict clean 45 | -------------------------------------------------------------------------------- /lua-5.1/etc/README: -------------------------------------------------------------------------------- 1 | This directory contains some useful files and code. 2 | Unlike the code in ../src, everything here is in the public domain. 3 | 4 | If any of the makes fail, you're probably not using the same libraries 5 | used to build Lua. Set MYLIBS in Makefile accordingly. 6 | 7 | all.c 8 | Full Lua interpreter in a single file. 9 | Do "make one" for a demo. 10 | 11 | lua.hpp 12 | Lua header files for C++ using 'extern "C"'. 13 | 14 | lua.ico 15 | A Lua icon for Windows (and web sites: save as favicon.ico). 16 | Drawn by hand by Markus Gritsch . 17 | 18 | lua.pc 19 | pkg-config data for Lua 20 | 21 | luavs.bat 22 | Script to build Lua under "Visual Studio .NET Command Prompt". 23 | Run it from the toplevel as etc\luavs.bat. 24 | 25 | min.c 26 | A minimal Lua interpreter. 27 | Good for learning and for starting your own. 28 | Do "make min" for a demo. 29 | 30 | noparser.c 31 | Linking with noparser.o avoids loading the parsing modules in lualib.a. 32 | Do "make noparser" for a demo. 33 | 34 | strict.lua 35 | Traps uses of undeclared global variables. 36 | Do "make strict" for a demo. 37 | 38 | -------------------------------------------------------------------------------- /lua-5.1/etc/all.c: -------------------------------------------------------------------------------- 1 | /* 2 | * all.c -- Lua core, libraries and interpreter in a single file 3 | */ 4 | 5 | #define luaall_c 6 | 7 | #include "lapi.c" 8 | #include "lcode.c" 9 | #include "ldebug.c" 10 | #include "ldo.c" 11 | #include "ldump.c" 12 | #include "lfunc.c" 13 | #include "lgc.c" 14 | #include "llex.c" 15 | #include "lmem.c" 16 | #include "lobject.c" 17 | #include "lopcodes.c" 18 | #include "lparser.c" 19 | #include "lstate.c" 20 | #include "lstring.c" 21 | #include "ltable.c" 22 | #include "ltm.c" 23 | #include "lundump.c" 24 | #include "lvm.c" 25 | #include "lzio.c" 26 | 27 | #include "lauxlib.c" 28 | #include "lbaselib.c" 29 | #include "ldblib.c" 30 | #include "liolib.c" 31 | #include "linit.c" 32 | #include "lmathlib.c" 33 | #include "loadlib.c" 34 | #include "loslib.c" 35 | #include "lstrlib.c" 36 | #include "ltablib.c" 37 | 38 | #include "lua.c" 39 | -------------------------------------------------------------------------------- /lua-5.1/etc/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /lua-5.1/etc/lua.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/lua-5.1/etc/lua.ico -------------------------------------------------------------------------------- /lua-5.1/etc/lua.pc: -------------------------------------------------------------------------------- 1 | # lua.pc -- pkg-config data for Lua 2 | 3 | # vars from install Makefile 4 | 5 | # grep '^V=' ../Makefile 6 | V= 5.1 7 | # grep '^R=' ../Makefile 8 | R= 5.1.5 9 | 10 | # grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' 11 | prefix= /usr/local 12 | INSTALL_BIN= ${prefix}/bin 13 | INSTALL_INC= ${prefix}/include 14 | INSTALL_LIB= ${prefix}/lib 15 | INSTALL_MAN= ${prefix}/man/man1 16 | INSTALL_LMOD= ${prefix}/share/lua/${V} 17 | INSTALL_CMOD= ${prefix}/lib/lua/${V} 18 | 19 | # canonical vars 20 | exec_prefix=${prefix} 21 | libdir=${exec_prefix}/lib 22 | includedir=${prefix}/include 23 | 24 | Name: Lua 25 | Description: An Extensible Extension Language 26 | Version: ${R} 27 | Requires: 28 | Libs: -L${libdir} -llua -lm 29 | Cflags: -I${includedir} 30 | 31 | # (end of lua.pc) 32 | -------------------------------------------------------------------------------- /lua-5.1/etc/luavs.bat: -------------------------------------------------------------------------------- 1 | @rem Script to build Lua under "Visual Studio .NET Command Prompt". 2 | @rem Do not run from this directory; run it from the toplevel: etc\luavs.bat . 3 | @rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src. 4 | @rem (contributed by David Manura and Mike Pall) 5 | 6 | @setlocal 7 | @set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE 8 | @set MYLINK=link /nologo 9 | @set MYMT=mt /nologo 10 | 11 | cd src 12 | %MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c 13 | del lua.obj luac.obj 14 | %MYLINK% /DLL /out:lua51.dll l*.obj 15 | if exist lua51.dll.manifest^ 16 | %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2 17 | %MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c 18 | %MYLINK% /out:lua.exe lua.obj lua51.lib 19 | if exist lua.exe.manifest^ 20 | %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe 21 | %MYCOMPILE% l*.c print.c 22 | del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^ 23 | loslib.obj ltablib.obj lstrlib.obj loadlib.obj 24 | %MYLINK% /out:luac.exe *.obj 25 | if exist luac.exe.manifest^ 26 | %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe 27 | del *.obj *.manifest 28 | cd .. 29 | -------------------------------------------------------------------------------- /lua-5.1/etc/min.c: -------------------------------------------------------------------------------- 1 | /* 2 | * min.c -- a minimal Lua interpreter 3 | * loads stdin only with minimal error handling. 4 | * no interaction, and no standard library, only a "print" function. 5 | */ 6 | 7 | #include 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | 12 | static int print(lua_State *L) 13 | { 14 | int n=lua_gettop(L); 15 | int i; 16 | for (i=1; i<=n; i++) 17 | { 18 | if (i>1) printf("\t"); 19 | if (lua_isstring(L,i)) 20 | printf("%s",lua_tostring(L,i)); 21 | else if (lua_isnil(L,i)) 22 | printf("%s","nil"); 23 | else if (lua_isboolean(L,i)) 24 | printf("%s",lua_toboolean(L,i) ? "true" : "false"); 25 | else 26 | printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); 27 | } 28 | printf("\n"); 29 | return 0; 30 | } 31 | 32 | int main(void) 33 | { 34 | lua_State *L=lua_open(); 35 | lua_register(L,"print",print); 36 | if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); 37 | lua_close(L); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /lua-5.1/etc/noparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The code below can be used to make a Lua core that does not contain the 3 | * parsing modules (lcode, llex, lparser), which represent 35% of the total core. 4 | * You'll only be able to load binary files and strings, precompiled with luac. 5 | * (Of course, you'll have to build luac with the original parsing modules!) 6 | * 7 | * To use this module, simply compile it ("make noparser" does that) and list 8 | * its object file before the Lua libraries. The linker should then not load 9 | * the parsing modules. To try it, do "make luab". 10 | * 11 | * If you also want to avoid the dump module (ldump.o), define NODUMP. 12 | * #define NODUMP 13 | */ 14 | 15 | #define LUA_CORE 16 | 17 | #include "llex.h" 18 | #include "lparser.h" 19 | #include "lzio.h" 20 | 21 | LUAI_FUNC void luaX_init (lua_State *L) { 22 | UNUSED(L); 23 | } 24 | 25 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { 26 | UNUSED(z); 27 | UNUSED(buff); 28 | UNUSED(name); 29 | lua_pushliteral(L,"parser not loaded"); 30 | lua_error(L); 31 | return NULL; 32 | } 33 | 34 | #ifdef NODUMP 35 | #include "lundump.h" 36 | 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { 38 | UNUSED(f); 39 | UNUSED(w); 40 | UNUSED(data); 41 | UNUSED(strip); 42 | #if 1 43 | UNUSED(L); 44 | return 0; 45 | #else 46 | lua_pushliteral(L,"dumper not loaded"); 47 | lua_error(L); 48 | #endif 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /lua-5.1/etc/strict.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- strict.lua 3 | -- checks uses of undeclared global variables 4 | -- All global variables must be 'declared' through a regular assignment 5 | -- (even assigning nil will do) in a main chunk before being used 6 | -- anywhere or assigned to inside a function. 7 | -- 8 | 9 | local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget 10 | 11 | local mt = getmetatable(_G) 12 | if mt == nil then 13 | mt = {} 14 | setmetatable(_G, mt) 15 | end 16 | 17 | mt.__declared = {} 18 | 19 | local function what () 20 | local d = getinfo(3, "S") 21 | return d and d.what or "C" 22 | end 23 | 24 | mt.__newindex = function (t, n, v) 25 | if not mt.__declared[n] then 26 | local w = what() 27 | if w ~= "main" and w ~= "C" then 28 | error("assign to undeclared variable '"..n.."'", 2) 29 | end 30 | mt.__declared[n] = true 31 | end 32 | rawset(t, n, v) 33 | end 34 | 35 | mt.__index = function (t, n) 36 | if not mt.__declared[n] and what() ~= "C" then 37 | error("variable '"..n.."' is not declared", 2) 38 | end 39 | return rawget(t, n) 40 | end 41 | 42 | -------------------------------------------------------------------------------- /lua-5.1/src/fix_coverity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fix_coverity.h 3 | * Copyright 2017 Peter Jones 4 | * 5 | * Distributed under terms of the GPLv3 license. 6 | */ 7 | 8 | #ifndef FIX_COVERITY_H 9 | #define FIX_COVERITY_H 10 | 11 | #ifndef _GNU_SOURCE 12 | #define _GNU_SOURCE 13 | #endif 14 | 15 | #ifndef __COVERITY_GCC_VERSION_AT_LEAST 16 | #define __COVERITY_GCC_VERSION_AT_LEAST(x, y) 0 17 | #define FAKE__COVERITY_GCC_VERSION_AT_LEAST__ 18 | #endif /* __COVERITY_GCC_VERSION_AT_LEAST */ 19 | 20 | /* With gcc 7 on x86_64 (at least), coverity pretends to be GCC but 21 | * accidentally doesn't create all of the types GCC would. 22 | * 23 | * In glibc's headers, bits/floatn.h has: 24 | * 25 | * #if (defined __x86_64__ \ 26 | * ? __GNUC_PREREQ (4, 3) \ 27 | * : (defined __GNU__ ? __GNUC_PREREQ (4, 5) : __GNUC_PREREQ (4, 4))) 28 | * # define __HAVE_FLOAT128 1 29 | * #else 30 | * # define __HAVE_FLOAT128 0 31 | * #endif 32 | * 33 | * and stdlib.h has: 34 | * 35 | * #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) 36 | * slash* Likewise for the '_Float128' format *slash 37 | * extern _Float128 strtof128 (const char *__restrict __nptr, 38 | * char **__restrict __endptr) 39 | * __THROW __nonnull ((1)); 40 | * #endif 41 | * 42 | * Which then causes cov-emit to lose its shit: 43 | * 44 | * "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is 45 | * undefined 46 | * extern _Float128 strtof128 (const char *__restrict __nptr, 47 | * ^ 48 | * "/usr/include/stdlib.h", line 190: error #20: identifier "_Float128" is 49 | * undefined 50 | * _Float128 __f) 51 | * ^ 52 | * "/usr/include/stdlib.h", line 236: error #20: identifier "_Float128" is 53 | * undefined 54 | * extern _Float128 strtof128_l (const char *__restrict __nptr, 55 | * ^ 56 | * 57 | * And then you'll notice something like this later on: 58 | * [WARNING] Emitted 0 C/C++ compilation units (0%) successfully 59 | * 60 | * 0 C/C++ compilation units (0%) are ready for analysis 61 | * For more details, please look at: 62 | * /home/pjones/devel/github.com/dbxtool/master/cov-int/build-log.txt 63 | * 64 | * You would think that if you're writing something that pretends to be 65 | * gcc, and you've got a "build a configuration by running shit through gcc 66 | * and looking at the output" stage (which they do), you would run "gcc -da 67 | * -fdump-tree-all -c -o foo.o foo.c" on an empty file and snarf up all the 68 | * types defined in the foo.c.001t.tu output. Apparently, they do not. 69 | * 70 | * Anyway, even just defining the type doesn't always work in the face of 71 | * how _Complex is defined, so we cheat a bit here. Be prepared to vomit. 72 | */ 73 | #ifdef __x86_64__ 74 | #if __COVERITY_GCC_VERSION_AT_LEAST(7, 0) 75 | #if 0 76 | typedef float _Float128 __attribute__((__mode__(__TF__))); 77 | typedef __complex__ float __cfloat128 __attribute__ ((__mode__ (__TC__))); 78 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__))); 79 | #else 80 | #include 81 | #define __cplusplus 201103L 82 | #include 83 | #undef __cplusplus 84 | #endif 85 | #endif 86 | #endif 87 | 88 | #ifdef FAKE__COVERITY_GCC_VERSION_AT_LEAST__ 89 | #undef FAKE__COVERITY_GCC_VERSION_AT_LEAST 90 | #undef __COVERITY_GCC_VERSION_AT_LEAST 91 | #endif 92 | 93 | #endif /* !FIX_COVERITY_H */ 94 | // vim:fenc=utf-8:tw=75 95 | -------------------------------------------------------------------------------- /lua-5.1/src/k_lib.h: -------------------------------------------------------------------------------- 1 | // 2 | // Kevin's macros to make writing Lua functions in C easy 3 | // 4 | 5 | #pragma once 6 | 7 | // accessing parameters 8 | 9 | // I_(n) macro does not handle corner case where int value would have MSBit 10 | // set. For those cases where it is assumed that the "integer" value is 11 | // actually unsigned, you should use U_ which calls GetUint_Hack. 12 | // 13 | // note also that if a numeric RETURN value could be > MAX_INT, you should use R_num instead of R_int 14 | // 15 | // this behavior seen with Lua 5.1.2 and 5.1.3 16 | // 17 | // NB: if this code is condensed, it may stop working... 18 | // 19 | // 20080505 kgoodwin discovered/wrote 20 | 21 | extern unsigned GetUint_Hack( lua_State *L, int n ); 22 | 23 | #define S_(n) luaL_checkstring( L, (n) ) 24 | #define I_(n) luaL_checkint( L, (n) ) 25 | #define U_(n) GetUint_Hack( L, (n) ) 26 | #define N_(n) luaL_checknumber( L, (n) ) 27 | #define So0_(n) luaL_optstring( L, (n), 0 ) 28 | #define Io_(n,dflt) luaL_optint( L, (n), (dflt)) 29 | #ifdef __cplusplus 30 | #define LuaBool(n) bool(lua_toboolean(L, (n) ) != 0) 31 | #endif 32 | #define B_(n) (luaL_checkint( L, (n) ) != 0) 33 | #define Bytes_(n,bytes) ( luaL_checklstring( L, (n), &bytes )) 34 | #define UBytes_(n,bytes) ((const unsigned char *)luaL_checklstring( L, (n), &bytes )) 35 | 36 | // returning 0 or 1 items from a function 37 | 38 | #define RZ return 0 39 | #define P_nil() lua_pushnil( L ) 40 | #define P_bool(val) lua_pushboolean( L, (val) ) 41 | #define P_int(val) lua_pushinteger( L, (val) ) 42 | #define P_num(val) lua_pushnumber( L, (val) ) 43 | #define P_str(val) lua_pushstring ( L, (val) ) 44 | #define P_lstr(pbuf,bytes) lua_pushlstring( L, (pbuf), (bytes) ) 45 | #define P_strf(fmt,val) lua_pushfstring( L, (fmt), (val) ) 46 | 47 | #define R_nil() P_nil() ; return 1 48 | #define R_bool(val) P_bool(val) ; return 1 49 | #define R_int(val) P_int(val) ; return 1 50 | #define R_num(val) P_num(val) ; return 1 51 | #define R_str(val) P_str(val) ; return 1 52 | #define R_lstr(pbuf,bytes) P_lstr(pbuf,bytes) ; return 1 53 | #define R_strf(fmt,val) P_strf(fmt,val) ; return 1 54 | 55 | 56 | #define ERR_strf(fmt,val) lua_pushfstring( L, fmt, (val) ); lua_error( L ) 57 | 58 | #define LUAFUNC_( func ) static int func( lua_State *L ) 59 | 60 | #define LUA_KLIBNAME "klib" 61 | LUALIB_API int luaopen_klib (lua_State *L); 62 | LUALIB_API int luaopen_rex_pcre2 (lua_State *L); 63 | LUALIB_API int luaopen_lpeg (lua_State *L); 64 | -------------------------------------------------------------------------------- /lua-5.1/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lua-5.1/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_NE, OPR_EQ, 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | 36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37 | 38 | 39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) 40 | 41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42 | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44 | 45 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 46 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 47 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 48 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 49 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 50 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 51 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 52 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 53 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 54 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 55 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 56 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 57 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 58 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 59 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 60 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 61 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 62 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 63 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 64 | LUAI_FUNC int luaK_jump (FuncState *fs); 65 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 66 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 67 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 68 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 69 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 70 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); 71 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 72 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); 73 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /lua-5.1/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lua-5.1/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /lua-5.1/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | 9 | #define ldump_c 10 | #define LUA_CORE 11 | 12 | #include "lua.h" 13 | 14 | #include "lobject.h" 15 | #include "lstate.h" 16 | #include "lundump.h" 17 | 18 | typedef struct { 19 | lua_State* L; 20 | lua_Writer writer; 21 | void* data; 22 | int strip; 23 | int status; 24 | } DumpState; 25 | 26 | #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) 27 | #define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) 28 | 29 | static void DumpBlock(const void* b, size_t size, DumpState* D) 30 | { 31 | if (D->status==0) 32 | { 33 | lua_unlock(D->L); 34 | D->status=(*D->writer)(D->L,b,size,D->data); 35 | lua_lock(D->L); 36 | } 37 | } 38 | 39 | static void DumpChar(int y, DumpState* D) 40 | { 41 | char x=(char)y; 42 | DumpVar(x,D); 43 | } 44 | 45 | static void DumpInt(int x, DumpState* D) 46 | { 47 | DumpVar(x,D); 48 | } 49 | 50 | static void DumpNumber(lua_Number x, DumpState* D) 51 | { 52 | DumpVar(x,D); 53 | } 54 | 55 | static void DumpVector(const void* b, int n, size_t size, DumpState* D) 56 | { 57 | DumpInt(n,D); 58 | DumpMem(b,n,size,D); 59 | } 60 | 61 | static void DumpString(const TString* s, DumpState* D) 62 | { 63 | if (s==NULL /* || getstr(s)==NULL 20240401 kgoodwin GCC 13.2.0 warns this is an always-false expression: non-NULL pointer + small constant will never be NULL */ 64 | ) 65 | { 66 | size_t size=0; 67 | DumpVar(size,D); 68 | } 69 | else 70 | { 71 | size_t size=s->tsv.len+1; /* include trailing '\0' */ 72 | DumpVar(size,D); 73 | DumpBlock(getstr(s),size,D); 74 | } 75 | } 76 | 77 | #define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) 78 | 79 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D); 80 | 81 | static void DumpConstants(const Proto* f, DumpState* D) 82 | { 83 | int i,n=f->sizek; 84 | DumpInt(n,D); 85 | for (i=0; ik[i]; 88 | DumpChar(ttype(o),D); 89 | switch (ttype(o)) 90 | { 91 | case LUA_TNIL: 92 | break; 93 | case LUA_TBOOLEAN: 94 | DumpChar(bvalue(o),D); 95 | break; 96 | case LUA_TNUMBER: 97 | DumpNumber(nvalue(o),D); 98 | break; 99 | case LUA_TSTRING: 100 | DumpString(rawtsvalue(o),D); 101 | break; 102 | default: 103 | lua_assert(0); /* cannot happen */ 104 | break; 105 | } 106 | } 107 | n=f->sizep; 108 | DumpInt(n,D); 109 | for (i=0; ip[i],f->source,D); 110 | } 111 | 112 | static void DumpDebug(const Proto* f, DumpState* D) 113 | { 114 | int i,n; 115 | n= (D->strip) ? 0 : f->sizelineinfo; 116 | DumpVector(f->lineinfo,n,sizeof(int),D); 117 | n= (D->strip) ? 0 : f->sizelocvars; 118 | DumpInt(n,D); 119 | for (i=0; ilocvars[i].varname,D); 122 | DumpInt(f->locvars[i].startpc,D); 123 | DumpInt(f->locvars[i].endpc,D); 124 | } 125 | n= (D->strip) ? 0 : f->sizeupvalues; 126 | DumpInt(n,D); 127 | for (i=0; iupvalues[i],D); 128 | } 129 | 130 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D) 131 | { 132 | DumpString((f->source==p || D->strip) ? NULL : f->source,D); 133 | DumpInt(f->linedefined,D); 134 | DumpInt(f->lastlinedefined,D); 135 | DumpChar(f->nups,D); 136 | DumpChar(f->numparams,D); 137 | DumpChar(f->is_vararg,D); 138 | DumpChar(f->maxstacksize,D); 139 | DumpCode(f,D); 140 | DumpConstants(f,D); 141 | DumpDebug(f,D); 142 | } 143 | 144 | static void DumpHeader(DumpState* D) 145 | { 146 | char h[LUAC_HEADERSIZE]; 147 | luaU_header(h); 148 | DumpBlock(h,LUAC_HEADERSIZE,D); 149 | } 150 | 151 | /* 152 | ** dump Lua function as precompiled chunk 153 | */ 154 | int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) 155 | { 156 | DumpState D; 157 | D.L=L; 158 | D.writer=w; 159 | D.data=data; 160 | D.strip=strip; 161 | D.status=0; 162 | DumpHeader(&D); 163 | DumpFunction(f,NULL,&D); 164 | return D.status; 165 | } 166 | -------------------------------------------------------------------------------- /lua-5.1/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lua-5.1/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | ** Possible states of the Garbage Collector 16 | */ 17 | #define GCSpause 0 18 | #define GCSpropagate 1 19 | #define GCSsweepstring 2 20 | #define GCSsweep 3 21 | #define GCSfinalize 4 22 | 23 | 24 | /* 25 | ** some userful bit tricks 26 | */ 27 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 28 | #define setbits(x,m) ((x) |= (m)) 29 | #define testbits(x,m) ((x) & (m)) 30 | #define bitmask(b) (1<<(b)) 31 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 32 | #define l_setbit(x,b) setbits(x, bitmask(b)) 33 | #define resetbit(x,b) resetbits(x, bitmask(b)) 34 | #define testbit(x,b) testbits(x, bitmask(b)) 35 | #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) 36 | #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) 37 | #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) 38 | 39 | 40 | 41 | /* 42 | ** Layout for bit use in `marked' field: 43 | ** bit 0 - object is white (type 0) 44 | ** bit 1 - object is white (type 1) 45 | ** bit 2 - object is black 46 | ** bit 3 - for userdata: has been finalized 47 | ** bit 3 - for tables: has weak keys 48 | ** bit 4 - for tables: has weak values 49 | ** bit 5 - object is fixed (should not be collected) 50 | ** bit 6 - object is "super" fixed (only the main thread) 51 | */ 52 | 53 | 54 | #define WHITE0BIT 0 55 | #define WHITE1BIT 1 56 | #define BLACKBIT 2 57 | #define FINALIZEDBIT 3 58 | #define KEYWEAKBIT 3 59 | #define VALUEWEAKBIT 4 60 | #define FIXEDBIT 5 61 | #define SFIXEDBIT 6 62 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 63 | 64 | 65 | #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) 66 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT) 67 | #define isgray(x) (!isblack(x) && !iswhite(x)) 68 | 69 | #define otherwhite(g) (g->currentwhite ^ WHITEBITS) 70 | #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) 71 | 72 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS) 73 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) 74 | 75 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) 76 | 77 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 78 | 79 | 80 | #define luaC_checkGC(L) { \ 81 | condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ 82 | if (G(L)->totalbytes >= G(L)->GCthreshold) \ 83 | luaC_step(L); } 84 | 85 | 86 | #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ 87 | luaC_barrierf(L,obj2gco(p),gcvalue(v)); } 88 | 89 | #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ 90 | luaC_barrierback(L,t); } 91 | 92 | #define luaC_objbarrier(L,p,o) \ 93 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ 94 | luaC_barrierf(L,obj2gco(p),obj2gco(o)); } 95 | 96 | #define luaC_objbarriert(L,t,o) \ 97 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } 98 | 99 | LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); 100 | LUAI_FUNC void luaC_callGCTM (lua_State *L); 101 | LUAI_FUNC void luaC_freeall (lua_State *L); 102 | LUAI_FUNC void luaC_step (lua_State *L); 103 | LUAI_FUNC void luaC_fullgc (lua_State *L); 104 | LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 105 | LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); 106 | LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); 107 | LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); 108 | 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /lua-5.1/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | #include "k_lib.h" /* 20060825 kgoodwin private library (k_lib.c) */ 16 | 17 | extern int luaopen_pack(lua_State *L); /* 20070313 kgoodwin PubDomain code (lpack.c) */ 18 | 19 | static const luaL_Reg lualibs[] = { 20 | {"", luaopen_base}, 21 | {LUA_LOADLIBNAME, luaopen_package}, 22 | {LUA_TABLIBNAME, luaopen_table}, 23 | {LUA_IOLIBNAME, luaopen_io}, 24 | {LUA_OSLIBNAME, luaopen_os}, 25 | {LUA_STRLIBNAME, luaopen_string}, 26 | {LUA_MATHLIBNAME, luaopen_math}, 27 | {LUA_DBLIBNAME, luaopen_debug}, 28 | {LUA_KLIBNAME, luaopen_klib}, /* 20060825 kgoodwin private library (k_lib.c) */ 29 | {"lpack", luaopen_pack }, /* 20070313 kgoodwin PubDomain code (lpack.c) */ 30 | //{"pcre", luaopen_rex_pcre2 }, /* 20080105 kgoodwin PubDomain code (lrexlib w/significant hacks to static compile) */ 31 | {"lpeg", luaopen_lpeg }, /* 20081110 kgoodwin PubDomain code (lpeg.c) */ 32 | {NULL, NULL} 33 | }; 34 | 35 | 36 | LUALIB_API void luaL_openlibs (lua_State *L) { 37 | const luaL_Reg *lib = lualibs; 38 | for (; lib->func; lib++) { 39 | lua_pushcfunction(L, lib->func); 40 | lua_pushstring(L, lib->name); 41 | lua_call(L, 1, 0); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lua-5.1/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_NAME, TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | /* array with token `names' */ 40 | LUAI_DATA const char *const luaX_tokens []; 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | TString *ts; 46 | } SemInfo; /* semantics information */ 47 | 48 | 49 | typedef struct Token { 50 | int token; 51 | SemInfo seminfo; 52 | } Token; 53 | 54 | 55 | typedef struct LexState { 56 | int current; /* current character (charint) */ 57 | int linenumber; /* input line counter */ 58 | int lastline; /* line of last token `consumed' */ 59 | Token t; /* current token */ 60 | Token lookahead; /* look ahead token */ 61 | struct FuncState *fs; /* `FuncState' is private to the parser */ 62 | struct lua_State *L; 63 | ZIO *z; /* input stream */ 64 | Mbuffer *buff; /* buffer for tokens */ 65 | TString *source; /* current source name */ 66 | char decpoint; /* locale decimal point */ 67 | } LexState; 68 | 69 | 70 | LUAI_FUNC void luaX_init (lua_State *L); 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 72 | TString *source); 73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 74 | LUAI_FUNC void luaX_next (LexState *ls); 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /lua-5.1/src/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Limits, basic types, and some other `installation-dependent' definitions 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llimits_h 8 | #define llimits_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #include "lua.h" 16 | 17 | 18 | typedef LUAI_UINT32 lu_int32; 19 | 20 | typedef LUAI_UMEM lu_mem; 21 | 22 | typedef LUAI_MEM l_mem; 23 | 24 | 25 | 26 | /* chars used as small naturals (so that `char' is reserved for characters) */ 27 | typedef unsigned char lu_byte; 28 | 29 | 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) 31 | 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 33 | 34 | 35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 36 | 37 | /* 38 | ** conversion of pointer to integer 39 | ** this is for hashing only; there is no problem if the integer 40 | ** cannot hold the whole pointer value 41 | */ 42 | #define IntPoint(p) ((unsigned int)(lu_mem)(p)) 43 | 44 | 45 | 46 | /* type to ensure maximum alignment */ 47 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 48 | 49 | 50 | /* result of a `usual argument conversion' over lua_Number */ 51 | typedef LUAI_UACNUMBER l_uacNumber; 52 | 53 | 54 | /* internal assertions for in-house debugging */ 55 | #ifdef lua_assert 56 | 57 | #define check_exp(c,e) (lua_assert(c), (e)) 58 | #define api_check(l,e) lua_assert(e) 59 | 60 | #else 61 | 62 | #define lua_assert(c) ((void)0) 63 | #define check_exp(c,e) (e) 64 | #define api_check luai_apicheck 65 | 66 | #endif 67 | 68 | 69 | #ifndef UNUSED 70 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ 71 | #endif 72 | 73 | 74 | #ifndef cast 75 | #define cast(t, exp) ((t)(exp)) 76 | #endif 77 | 78 | #define cast_byte(i) cast(lu_byte, (i)) 79 | #define cast_num(i) cast(lua_Number, (i)) 80 | #define cast_int(i) cast(int, (i)) 81 | 82 | 83 | 84 | /* 85 | ** type for virtual-machine instructions 86 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 87 | */ 88 | typedef lu_int32 Instruction; 89 | 90 | 91 | 92 | /* maximum stack for a Lua function */ 93 | #define MAXSTACK 250 94 | 95 | 96 | 97 | /* minimum size for the string table (must be power of 2) */ 98 | #ifndef MINSTRTABSIZE 99 | #define MINSTRTABSIZE 32 100 | #endif 101 | 102 | 103 | /* minimum size for string buffer */ 104 | #ifndef LUA_MINBUFFER 105 | #define LUA_MINBUFFER 32 106 | #endif 107 | 108 | 109 | #ifndef lua_lock 110 | #define lua_lock(L) ((void) 0) 111 | #define lua_unlock(L) ((void) 0) 112 | #endif 113 | 114 | #ifndef luai_threadyield 115 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 116 | #endif 117 | 118 | 119 | /* 120 | ** macro to control inclusion of some hard tests on stack reallocation 121 | */ 122 | #ifndef HARDSTACKTESTS 123 | #define condhardstacktests(x) ((void)0) 124 | #else 125 | #define condhardstacktests(x) x 126 | #endif 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /lua-5.1/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | /* 24 | ** About the realloc function: 25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 26 | ** (`osize' is the old size, `nsize' is the new size) 27 | ** 28 | ** Lua ensures that (ptr == NULL) iff (osize == 0). 29 | ** 30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL). 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *errormsg) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, errormsg); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | void *luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | return NULL; /* to avoid warnings */ 69 | } 70 | 71 | 72 | 73 | /* 74 | ** generic allocation routine. 75 | */ 76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 77 | global_State *g = G(L); 78 | lua_assert((osize == 0) == (block == NULL)); 79 | block = (*g->frealloc)(g->ud, block, osize, nsize); 80 | if (block == NULL && nsize > 0) 81 | luaD_throw(L, LUA_ERRMEM); 82 | lua_assert((nsize == 0) == (block == NULL)); 83 | g->totalbytes = (g->totalbytes - osize) + nsize; 84 | return block; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /lua-5.1/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /lua-5.1/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** See Copyright Notice in lua.h 4 | */ 5 | 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | 11 | #include "lopcodes.h" 12 | 13 | 14 | /* ORDER OP */ 15 | 16 | const char *const luaP_opnames[NUM_OPCODES+1] = { 17 | "MOVE", 18 | "LOADK", 19 | "LOADBOOL", 20 | "LOADNIL", 21 | "GETUPVAL", 22 | "GETGLOBAL", 23 | "GETTABLE", 24 | "SETGLOBAL", 25 | "SETUPVAL", 26 | "SETTABLE", 27 | "NEWTABLE", 28 | "SELF", 29 | "ADD", 30 | "SUB", 31 | "MUL", 32 | "DIV", 33 | "MOD", 34 | "POW", 35 | "UNM", 36 | "NOT", 37 | "LEN", 38 | "CONCAT", 39 | "JMP", 40 | "EQ", 41 | "LT", 42 | "LE", 43 | "TEST", 44 | "TESTSET", 45 | "CALL", 46 | "TAILCALL", 47 | "RETURN", 48 | "FORLOOP", 49 | "FORPREP", 50 | "TFORLOOP", 51 | "SETLIST", 52 | "CLOSE", 53 | "CLOSURE", 54 | "VARARG", 55 | NULL 56 | }; 57 | 58 | 59 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 60 | 61 | const lu_byte luaP_opmodes[NUM_OPCODES] = { 62 | /* T A B C mode opcode */ 63 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 64 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 65 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 66 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ 67 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 68 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ 69 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 70 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ 71 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 73 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 75 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 89 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ 90 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 91 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 92 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 93 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ 97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ 99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /lua-5.1/src/lpack.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/lua-5.1/src/lpack.c -------------------------------------------------------------------------------- /lua-5.1/src/lpack.readme.txt: -------------------------------------------------------------------------------- 1 | This is a simple Lua library for packing and unpacking binary data. 2 | 3 | To try the library, just edit Makefile to reflect your installation of Lua and 4 | then run make. This will build the library and run a simple test. For detailed 5 | installation instructions, see 6 | http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html 7 | 8 | The library adds two functions to the string library: pack and unpack. 9 | 10 | pack is called as follows: pack(F,x1,x2,...), where F is a string describing 11 | how the values x1, x2, ... are to be interpreted and formatted. Each letter 12 | in the format string F consumes one of the given values. Only values of type 13 | number or string are accepted. pack returns a (binary) string containing the 14 | values packed as described in F. The letter codes understood by pack are listed 15 | in lpack.c (they are inspired by Perl's codes but are not the same). Numbers 16 | following letter codes in F indicate repetitions. 17 | 18 | unpack is called as follows: unpack(s,F,[init]), where s is a (binary) string 19 | containing data packed as if by pack, F is a format string describing what is 20 | to be read from s, and the optional init marks where in s to begin reading the 21 | values. unpack returns one value per letter in F until F or s is exhausted 22 | (the letters codes are the same as for pack, except that numbers following `A' 23 | are interpreted as the number of characters to read into the string, not as 24 | repetitions). 25 | 26 | The first value returned by unpack is the next unread position in s, which can 27 | be used as the init position in a subsequent call to unpack. This allows you to 28 | unpack values in a loop or in several steps. If the position returned by unpack 29 | is beyond the end of s, then s has been exhausted; any calls to unpack starting 30 | beyond the end of s will always return nil values. 31 | 32 | This code is hereby placed in the public domain. 33 | Please send comments, suggestions, and bug reports to lhf@tecgraf.puc-rio.br . 34 | 35 | ------------------------------------------------------------------------------- 36 | 37 | pack library: 38 | pack(f,...) unpack(s,f,[init]) 39 | 40 | ------------------------------------------------------------------------------- 41 | -------------------------------------------------------------------------------- /lua-5.1/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in `k' */ 25 | VKNUM, /* nval = numerical value */ 26 | VLOCAL, /* info = local register */ 27 | VUPVAL, /* info = index of upvalue in `upvalues' */ 28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 29 | VINDEXED, /* info = table register; aux = index register (or `k') */ 30 | VJMP, /* info = instruction pc */ 31 | VRELOCABLE, /* info = instruction pc */ 32 | VNONRELOC, /* info = result register */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | typedef struct expdesc { 38 | expkind k; 39 | union { 40 | struct { int info, aux; } s; 41 | lua_Number nval; 42 | } u; 43 | int t; /* patch list of `exit when true' */ 44 | int f; /* patch list of `exit when false' */ 45 | } expdesc; 46 | 47 | 48 | typedef struct upvaldesc { 49 | lu_byte k; 50 | lu_byte info; 51 | } upvaldesc; 52 | 53 | 54 | struct BlockCnt; /* defined in lparser.c */ 55 | 56 | 57 | /* state needed to generate code for a given function */ 58 | typedef struct FuncState { 59 | Proto *f; /* current function header */ 60 | Table *h; /* table to find (and reuse) elements in `k' */ 61 | struct FuncState *prev; /* enclosing function */ 62 | struct LexState *ls; /* lexical state */ 63 | struct lua_State *L; /* copy of the Lua state */ 64 | struct BlockCnt *bl; /* chain of current blocks */ 65 | int pc; /* next position to code (equivalent to `ncode') */ 66 | int lasttarget; /* `pc' of last `jump target' */ 67 | int jpc; /* list of pending jumps to `pc' */ 68 | int freereg; /* first free register */ 69 | int nk; /* number of elements in `k' */ 70 | int np; /* number of elements in `p' */ 71 | short nlocvars; /* number of elements in `locvars' */ 72 | lu_byte nactvar; /* number of active local variables */ 73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ 74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ 75 | } FuncState; 76 | 77 | 78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 79 | const char *name); 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /lua-5.1/src/lpcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcap.h,v 1.3 2016/09/13 17:45:58 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcap_h) 6 | #define lpcap_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* kinds of captures */ 13 | typedef enum CapKind { 14 | Cclose, /* not used in trees */ 15 | Cposition, 16 | Cconst, /* ktable[key] is Lua constant */ 17 | Cbackref, /* ktable[key] is "name" of group to get capture */ 18 | Carg, /* 'key' is arg's number */ 19 | Csimple, /* next node is pattern */ 20 | Ctable, /* next node is pattern */ 21 | Cfunction, /* ktable[key] is function; next node is pattern */ 22 | Cquery, /* ktable[key] is table; next node is pattern */ 23 | Cstring, /* ktable[key] is string; next node is pattern */ 24 | Cnum, /* numbered capture; 'key' is number of value to return */ 25 | Csubst, /* substitution capture; next node is pattern */ 26 | Cfold, /* ktable[key] is function; next node is pattern */ 27 | Cruntime, /* not used in trees (is uses another type for tree) */ 28 | Cgroup /* ktable[key] is group's "name" */ 29 | } CapKind; 30 | 31 | 32 | typedef struct Capture { 33 | const char *s; /* subject position */ 34 | unsigned short idx; /* extra info (group name, arg index, etc.) */ 35 | byte kind; /* kind of capture */ 36 | byte siz; /* size of full capture + 1 (0 = not a full capture) */ 37 | } Capture; 38 | 39 | 40 | typedef struct CapState { 41 | Capture *cap; /* current capture */ 42 | Capture *ocap; /* (original) capture list */ 43 | lua_State *L; 44 | int ptop; /* index of last argument to 'match' */ 45 | const char *s; /* original string */ 46 | int valuecached; /* value stored in cache slot */ 47 | } CapState; 48 | 49 | 50 | int runtimecap (CapState *cs, Capture *close, const char *s, int *rem); 51 | int getcaptures (lua_State *L, const char *s, const char *r, int ptop); 52 | int finddyncap (Capture *cap, Capture *last); 53 | 54 | #endif 55 | 56 | 57 | -------------------------------------------------------------------------------- /lua-5.1/src/lpcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcode.h,v 1.8 2016/09/15 17:46:13 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcode_h) 6 | #define lpcode_h 7 | 8 | #include "lua.h" 9 | 10 | #include "lptypes.h" 11 | #include "lptree.h" 12 | #include "lpvm.h" 13 | 14 | int tocharset (TTree *tree, Charset *cs); 15 | int checkaux (TTree *tree, int pred); 16 | int fixedlen (TTree *tree); 17 | int hascaptures (TTree *tree); 18 | int lp_gc (lua_State *L); 19 | Instruction *compile (lua_State *L, Pattern *p); 20 | void realloccode (lua_State *L, Pattern *p, int nsize); 21 | int sizei (const Instruction *i); 22 | 23 | 24 | #define PEnullable 0 25 | #define PEnofail 1 26 | 27 | /* 28 | ** nofail(t) implies that 't' cannot fail with any input 29 | */ 30 | #define nofail(t) checkaux(t, PEnofail) 31 | 32 | /* 33 | ** (not nullable(t)) implies 't' cannot match without consuming 34 | ** something 35 | */ 36 | #define nullable(t) checkaux(t, PEnullable) 37 | 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lua-5.1/src/lpcre2_common.h: -------------------------------------------------------------------------------- 1 | /* common.h */ 2 | /* See Copyright Notice in the file LICENSE */ 3 | 4 | #ifndef COMMON_H 5 | #define COMMON_H 6 | 7 | #include "lua.h" 8 | 9 | #if LUA_VERSION_NUM > 501 10 | # define lua_objlen lua_rawlen 11 | int luaL_typerror (lua_State *L, int narg, const char *tname); 12 | #endif 13 | 14 | /* REX_API can be overridden from the command line or Makefile */ 15 | #ifndef REX_API 16 | # define REX_API LUALIB_API 17 | #endif 18 | 19 | /* Special values for maxmatch in gsub. They all must be negative. */ 20 | #define GSUB_UNLIMITED -1 21 | #define GSUB_CONDITIONAL -2 22 | 23 | /* Common structs and functions */ 24 | 25 | typedef struct { 26 | const char* key; 27 | int val; 28 | } flag_pair; 29 | 30 | typedef struct { /* compile arguments */ 31 | const char * pattern; 32 | size_t patlen; 33 | void * ud; 34 | int cflags; 35 | const char * locale; /* PCRE, Oniguruma */ 36 | const unsigned char * tables; /* PCRE */ 37 | int tablespos; /* PCRE */ 38 | void * syntax; /* Oniguruma */ 39 | const unsigned char * translate; /* GNU */ 40 | int gnusyn; /* GNU */ 41 | } TArgComp; 42 | 43 | typedef struct { /* exec arguments */ 44 | const char * text; 45 | size_t textlen; 46 | int startoffset; 47 | int eflags; 48 | int funcpos; 49 | int maxmatch; 50 | int funcpos2; /* used with gsub */ 51 | int reptype; /* used with gsub */ 52 | size_t ovecsize; /* PCRE: dfa_exec */ 53 | size_t wscount; /* PCRE: dfa_exec */ 54 | } TArgExec; 55 | 56 | struct tagFreeList; /* forward declaration */ 57 | 58 | struct tagBuffer { 59 | size_t size; 60 | size_t top; 61 | char * arr; 62 | lua_State * L; 63 | struct tagFreeList * freelist; 64 | }; 65 | 66 | struct tagFreeList { 67 | struct tagBuffer * list[16]; 68 | int top; 69 | }; 70 | 71 | typedef struct tagBuffer TBuffer; 72 | typedef struct tagFreeList TFreeList; 73 | 74 | void freelist_init (TFreeList *fl); 75 | void freelist_add (TFreeList *fl, TBuffer *buf); 76 | void freelist_free (TFreeList *fl); 77 | 78 | void buffer_init (TBuffer *buf, size_t sz, lua_State *L, TFreeList *fl); 79 | void buffer_free (TBuffer *buf); 80 | void buffer_clear (TBuffer *buf); 81 | void buffer_addbuffer (TBuffer *trg, TBuffer *src); 82 | void buffer_addlstring (TBuffer *buf, const void *src, size_t sz); 83 | void buffer_addvalue (TBuffer *buf, int stackpos); 84 | void buffer_pushresult (TBuffer *buf); 85 | 86 | void bufferZ_putrepstring (TBuffer *buf, int reppos, int nsub); 87 | int bufferZ_next (TBuffer *buf, size_t *iter, size_t *len, const char **str); 88 | void bufferZ_addlstring (TBuffer *buf, const void *src, size_t len); 89 | void bufferZ_addnum (TBuffer *buf, size_t num); 90 | 91 | int get_int_field (lua_State *L, const char* field); 92 | void set_int_field (lua_State *L, const char* field, int val); 93 | int get_flags (lua_State *L, const flag_pair **arr); 94 | const char *get_flag_key (const flag_pair *fp, int val); 95 | void *Lmalloc (lua_State *L, size_t size); 96 | void *Lrealloc (lua_State *L, void *p, size_t osize, size_t nsize); 97 | void Lfree (lua_State *L, void *p, size_t size); 98 | 99 | #ifndef REX_NOEMBEDDEDTEST 100 | int newmembuffer (lua_State *L); 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /lua-5.1/src/lpeg-128.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/lua-5.1/src/lpeg-128.gif -------------------------------------------------------------------------------- /lua-5.1/src/lpeg.HISTORY: -------------------------------------------------------------------------------- 1 | HISTORY for LPeg 1.0 2 | 3 | * Changes from version 0.12 to 1.0 4 | --------------------------------- 5 | + group "names" can be any Lua value 6 | + some bugs fixed 7 | + other small improvements 8 | 9 | * Changes from version 0.11 to 0.12 10 | --------------------------------- 11 | + no "unsigned short" limit for pattern sizes 12 | + mathtime captures considered nullable 13 | + some bugs fixed 14 | 15 | * Changes from version 0.10 to 0.11 16 | ------------------------------- 17 | + complete reimplementation of the code generator 18 | + new syntax for table captures 19 | + new functions in module 're' 20 | + other small improvements 21 | 22 | * Changes from version 0.9 to 0.10 23 | ------------------------------- 24 | + backtrack stack has configurable size 25 | + better error messages 26 | + Notation for non-terminals in 're' back to A instead o 27 | + experimental look-behind pattern 28 | + support for external extensions 29 | + works with Lua 5.2 30 | + consumes less C stack 31 | 32 | - "and" predicates do not keep captures 33 | 34 | * Changes from version 0.8 to 0.9 35 | ------------------------------- 36 | + The accumulator capture was replaced by a fold capture; 37 | programs that used the old 'lpeg.Ca' will need small changes. 38 | + Some support for character classes from old C locales. 39 | + A new named-group capture. 40 | 41 | * Changes from version 0.7 to 0.8 42 | ------------------------------- 43 | + New "match-time" capture. 44 | + New "argument capture" that allows passing arguments into the pattern. 45 | + Better documentation for 're'. 46 | + Several small improvements for 're'. 47 | + The 're' module has an incompatibility with previous versions: 48 | now, any use of a non-terminal must be enclosed in angle brackets 49 | (like ). 50 | 51 | * Changes from version 0.6 to 0.7 52 | ------------------------------- 53 | + Several improvements in module 're': 54 | - better documentation; 55 | - support for most captures (all but accumulator); 56 | - limited repetitions p{n,m}. 57 | + Small improvements in efficiency. 58 | + Several small bugs corrected (special thanks to Hans Hagen 59 | and Taco Hoekwater). 60 | 61 | * Changes from version 0.5 to 0.6 62 | ------------------------------- 63 | + Support for non-numeric indices in grammars. 64 | + Some bug fixes (thanks to the luatex team). 65 | + Some new optimizations; (thanks to Mike Pall). 66 | + A new page layout (thanks to Andre Carregal). 67 | + Minimal documentation for module 're'. 68 | 69 | * Changes from version 0.4 to 0.5 70 | ------------------------------- 71 | + Several optimizations. 72 | + lpeg.P now accepts booleans. 73 | + Some new examples. 74 | + A proper license. 75 | + Several small improvements. 76 | 77 | * Changes from version 0.3 to 0.4 78 | ------------------------------- 79 | + Static check for loops in repetitions and grammars. 80 | + Removed label option in captures. 81 | + The implementation of captures uses less memory. 82 | 83 | * Changes from version 0.2 to 0.3 84 | ------------------------------- 85 | + User-defined patterns in Lua. 86 | + Several new captures. 87 | 88 | * Changes from version 0.1 to 0.2 89 | ------------------------------- 90 | + Several small corrections. 91 | + Handles embedded zeros like any other character. 92 | + Capture "name" can be any Lua value. 93 | + Unlimited number of captures. 94 | + Match gets an optional initial position. 95 | 96 | (end of HISTORY) 97 | -------------------------------------------------------------------------------- /lua-5.1/src/lpprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $ 3 | */ 4 | 5 | 6 | #if !defined(lpprint_h) 7 | #define lpprint_h 8 | 9 | 10 | #include "lptree.h" 11 | #include "lpvm.h" 12 | 13 | 14 | #if defined(LPEG_DEBUG) 15 | 16 | void printpatt (Instruction *p, int n); 17 | void printtree (TTree *tree, int ident); 18 | void printktable (lua_State *L, int idx); 19 | void printcharset (const byte *st); 20 | void printcaplist (Capture *cap, Capture *limit); 21 | void printinst (const Instruction *op, const Instruction *p); 22 | 23 | #else 24 | 25 | #define printktable(L,idx) \ 26 | luaL_error(L, "function only implemented in debug mode") 27 | #define printtree(tree,i) \ 28 | luaL_error(L, "function only implemented in debug mode") 29 | #define printpatt(p,n) \ 30 | luaL_error(L, "function only implemented in debug mode") 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /lua-5.1/src/lptree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lptree_h) 6 | #define lptree_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* 13 | ** types of trees 14 | */ 15 | typedef enum TTag { 16 | TChar = 0, /* 'n' = char */ 17 | TSet, /* the set is stored in next CHARSETSIZE bytes */ 18 | TAny, 19 | TTrue, 20 | TFalse, 21 | TRep, /* 'sib1'* */ 22 | TSeq, /* 'sib1' 'sib2' */ 23 | TChoice, /* 'sib1' / 'sib2' */ 24 | TNot, /* !'sib1' */ 25 | TAnd, /* &'sib1' */ 26 | TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */ 27 | TOpenCall, /* ktable[key] is rule's key */ 28 | TRule, /* ktable[key] is rule's key (but key == 0 for unused rules); 29 | 'sib1' is rule's pattern; 30 | 'sib2' is next rule; 'cap' is rule's sequential number */ 31 | TGrammar, /* 'sib1' is initial (and first) rule */ 32 | TBehind, /* 'sib1' is pattern, 'n' is how much to go back */ 33 | TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind'); 34 | ktable[key] is Lua value associated with capture; 35 | 'sib1' is capture body */ 36 | TRunTime /* run-time capture: 'key' is Lua function; 37 | 'sib1' is capture body */ 38 | } TTag; 39 | 40 | 41 | /* 42 | ** Tree trees 43 | ** The first child of a tree (if there is one) is immediately after 44 | ** the tree. A reference to a second child (ps) is its position 45 | ** relative to the position of the tree itself. 46 | */ 47 | typedef struct TTree { 48 | byte tag; 49 | byte cap; /* kind of capture (if it is a capture) */ 50 | unsigned short key; /* key in ktable for Lua data (0 if no key) */ 51 | union { 52 | int ps; /* occasional second child */ 53 | int n; /* occasional counter */ 54 | } u; 55 | } TTree; 56 | 57 | 58 | /* 59 | ** A complete pattern has its tree plus, if already compiled, 60 | ** its corresponding code 61 | */ 62 | typedef struct Pattern { 63 | union Instruction *code; 64 | int codesize; 65 | TTree tree[1]; 66 | } Pattern; 67 | 68 | 69 | /* number of children for each tree */ 70 | extern const byte numsiblings[]; 71 | 72 | /* access to children */ 73 | #define sib1(t) ((t) + 1) 74 | #define sib2(t) ((t) + (t)->u.ps) 75 | 76 | 77 | 78 | 79 | 80 | 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /lua-5.1/src/lptypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptypes.h,v 1.16 2017/01/13 13:33:17 roberto Exp $ 3 | ** LPeg - PEG pattern matching for Lua 4 | ** Copyright 2007-2017, Lua.org & PUC-Rio (see 'lpeg.html' for license) 5 | ** written by Roberto Ierusalimschy 6 | */ 7 | 8 | #if !defined(lptypes_h) 9 | #define lptypes_h 10 | 11 | 12 | #if !defined(LPEG_DEBUG) 13 | #define NDEBUG 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #include "lua.h" 20 | 21 | 22 | #define VERSION "1.0.1" 23 | 24 | 25 | #define PATTERN_T "lpeg-pattern" 26 | #define MAXSTACKIDX "lpeg-maxstack" 27 | 28 | 29 | /* 30 | ** compatibility with Lua 5.1 31 | */ 32 | #if (LUA_VERSION_NUM == 501) 33 | 34 | #define lp_equal lua_equal 35 | 36 | #define lua_getuservalue lua_getfenv 37 | #define lua_setuservalue lua_setfenv 38 | 39 | #define lua_rawlen lua_objlen 40 | 41 | #define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f) 42 | #define luaL_newlib(L,f) luaL_register(L,"lpeg",f) 43 | 44 | #endif 45 | 46 | 47 | #if !defined(lp_equal) 48 | #define lp_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) 49 | #endif 50 | 51 | 52 | /* default maximum size for call/backtrack stack */ 53 | #if !defined(MAXBACK) 54 | #define MAXBACK 400 55 | #endif 56 | 57 | 58 | /* maximum number of rules in a grammar (limited by 'unsigned char') */ 59 | #if !defined(MAXRULES) 60 | #define MAXRULES 250 61 | #endif 62 | 63 | 64 | 65 | /* initial size for capture's list */ 66 | #define INITCAPSIZE 32 67 | 68 | 69 | /* index, on Lua stack, for subject */ 70 | #define SUBJIDX 2 71 | 72 | /* number of fixed arguments to 'match' (before capture arguments) */ 73 | #define FIXEDARGS 3 74 | 75 | /* index, on Lua stack, for capture list */ 76 | #define caplistidx(ptop) ((ptop) + 2) 77 | 78 | /* index, on Lua stack, for pattern's ktable */ 79 | #define ktableidx(ptop) ((ptop) + 3) 80 | 81 | /* index, on Lua stack, for backtracking stack */ 82 | #define stackidx(ptop) ((ptop) + 4) 83 | 84 | 85 | 86 | typedef unsigned char byte; 87 | 88 | 89 | #define BITSPERCHAR 8 90 | 91 | #define CHARSETSIZE ((UCHAR_MAX/BITSPERCHAR) + 1) 92 | 93 | 94 | 95 | typedef struct Charset { 96 | byte cs[CHARSETSIZE]; 97 | } Charset; 98 | 99 | 100 | 101 | #define loopset(v,b) { int v; for (v = 0; v < CHARSETSIZE; v++) {b;} } 102 | 103 | /* access to charset */ 104 | #define treebuffer(t) ((byte *)((t) + 1)) 105 | 106 | /* number of slots needed for 'n' bytes */ 107 | #define bytes2slots(n) (((n) - 1) / sizeof(TTree) + 1) 108 | 109 | /* set 'b' bit in charset 'cs' */ 110 | #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7))) 111 | 112 | 113 | /* 114 | ** in capture instructions, 'kind' of capture and its offset are 115 | ** packed in field 'aux', 4 bits for each 116 | */ 117 | #define getkind(op) ((op)->i.aux & 0xF) 118 | #define getoff(op) (((op)->i.aux >> 4) & 0xF) 119 | #define joinkindoff(k,o) ((k) | ((o) << 4)) 120 | 121 | #define MAXOFF 0xF 122 | #define MAXAUX 0xFF 123 | 124 | 125 | /* maximum number of bytes to look behind */ 126 | #define MAXBEHIND MAXAUX 127 | 128 | 129 | /* maximum size (in elements) for a pattern */ 130 | #define MAXPATTSIZE (SHRT_MAX - 10) 131 | 132 | 133 | /* size (in elements) for an instruction plus extra l bytes */ 134 | #define instsize(l) (((l) + sizeof(Instruction) - 1)/sizeof(Instruction) + 1) 135 | 136 | 137 | /* size (in elements) for a ISet instruction */ 138 | #define CHARSETINSTSIZE instsize(CHARSETSIZE) 139 | 140 | /* size (in elements) for a IFunc instruction */ 141 | #define funcinstsize(p) ((p)->i.aux + 2) 142 | 143 | 144 | 145 | #define testchar(st,c) (((int)(st)[((c) >> 3)] & (1 << ((c) & 7)))) 146 | 147 | 148 | #endif 149 | 150 | -------------------------------------------------------------------------------- /lua-5.1/src/lpvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpvm.h,v 1.3 2014/02/21 13:06:41 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpvm_h) 6 | #define lpvm_h 7 | 8 | #include "lpcap.h" 9 | 10 | 11 | /* Virtual Machine's instructions */ 12 | typedef enum Opcode { 13 | IAny, /* if no char, fail */ 14 | IChar, /* if char != aux, fail */ 15 | ISet, /* if char not in buff, fail */ 16 | ITestAny, /* in no char, jump to 'offset' */ 17 | ITestChar, /* if char != aux, jump to 'offset' */ 18 | ITestSet, /* if char not in buff, jump to 'offset' */ 19 | ISpan, /* read a span of chars in buff */ 20 | IBehind, /* walk back 'aux' characters (fail if not possible) */ 21 | IRet, /* return from a rule */ 22 | IEnd, /* end of pattern */ 23 | IChoice, /* stack a choice; next fail will jump to 'offset' */ 24 | IJmp, /* jump to 'offset' */ 25 | ICall, /* call rule at 'offset' */ 26 | IOpenCall, /* call rule number 'key' (must be closed to a ICall) */ 27 | ICommit, /* pop choice and jump to 'offset' */ 28 | IPartialCommit, /* update top choice to current position and jump */ 29 | IBackCommit, /* "fails" but jump to its own 'offset' */ 30 | IFailTwice, /* pop one choice and then fail */ 31 | IFail, /* go back to saved state on choice and jump to saved offset */ 32 | IGiveup, /* internal use */ 33 | IFullCapture, /* complete capture of last 'off' chars */ 34 | IOpenCapture, /* start a capture */ 35 | ICloseCapture, 36 | ICloseRunTime 37 | } Opcode; 38 | 39 | 40 | 41 | typedef union Instruction { 42 | struct Inst { 43 | byte code; 44 | byte aux; 45 | short key; 46 | } i; 47 | int offset; 48 | byte buff[1]; 49 | } Instruction; 50 | 51 | 52 | void printpatt (Instruction *p, int n); 53 | const char *match (lua_State *L, const char *o, const char *s, const char *e, 54 | Instruction *op, Capture *capture, int ptop); 55 | 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /lua-5.1/src/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lstring_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lmem.h" 16 | #include "lobject.h" 17 | #include "lstate.h" 18 | #include "lstring.h" 19 | 20 | 21 | 22 | void luaS_resize (lua_State *L, int newsize) { 23 | GCObject **newhash; 24 | stringtable *tb; 25 | int i; 26 | if (G(L)->gcstate == GCSsweepstring) 27 | return; /* cannot resize during GC traverse */ 28 | newhash = luaM_newvector(L, newsize, GCObject *); 29 | tb = &G(L)->strt; 30 | for (i=0; isize; i++) { 33 | GCObject *p = tb->hash[i]; 34 | while (p) { /* for each node in the list */ 35 | GCObject *next = p->gch.next; /* save next */ 36 | unsigned int h = gco2ts(p)->hash; 37 | int h1 = lmod(h, newsize); /* new position */ 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); 39 | p->gch.next = newhash[h1]; /* chain it */ 40 | newhash[h1] = p; 41 | p = next; 42 | } 43 | } 44 | luaM_freearray(L, tb->hash, tb->size, TString *); 45 | tb->size = newsize; 46 | tb->hash = newhash; 47 | } 48 | 49 | 50 | static TString *newlstr (lua_State *L, const char *str, size_t l, 51 | unsigned int h) { 52 | TString *ts; 53 | stringtable *tb; 54 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) 55 | luaM_toobig(L); 56 | ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); 57 | ts->tsv.len = l; 58 | ts->tsv.hash = h; 59 | ts->tsv.marked = luaC_white(G(L)); 60 | ts->tsv.tt = LUA_TSTRING; 61 | ts->tsv.reserved = 0; 62 | memcpy(ts+1, str, l*sizeof(char)); 63 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ 64 | tb = &G(L)->strt; 65 | h = lmod(h, tb->size); 66 | ts->tsv.next = tb->hash[h]; /* chain new entry */ 67 | tb->hash[h] = obj2gco(ts); 68 | tb->nuse++; 69 | if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) 70 | luaS_resize(L, tb->size*2); /* too crowded */ 71 | return ts; 72 | } 73 | 74 | 75 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 76 | GCObject *o; 77 | unsigned int h = cast(unsigned int, l); /* seed */ 78 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ 79 | size_t l1; 80 | for (l1=l; l1>=step; l1-=step) /* compute hash */ 81 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); 82 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; 83 | o != NULL; 84 | o = o->gch.next) { 85 | TString *ts = rawgco2ts(o); 86 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { 87 | /* string may be dead */ 88 | if (isdead(G(L), o)) changewhite(o); 89 | return ts; 90 | } 91 | } 92 | return newlstr(L, str, l, h); /* not found */ 93 | } 94 | 95 | 96 | Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { 97 | Udata *u; 98 | if (s > MAX_SIZET - sizeof(Udata)) 99 | luaM_toobig(L); 100 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); 101 | u->uv.marked = luaC_white(G(L)); /* is not finalized */ 102 | u->uv.tt = LUA_TUSERDATA; 103 | u->uv.len = s; 104 | u->uv.metatable = NULL; 105 | u->uv.env = e; 106 | /* chain it on udata list (after main thread) */ 107 | u->uv.next = G(L)->mainthread->next; 108 | G(L)->mainthread->next = obj2gco(u); 109 | return u; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /lua-5.1/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lua-5.1/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lua-5.1/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /lua-5.1/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lua-5.1/src/lua.link: -------------------------------------------------------------------------------- 1 | Microsoft (R) Incremental Linker Version 7.10.3052 2 | Copyright (C) Microsoft Corporation. All rights reserved. 3 | 4 | -------------------------------------------------------------------------------- /lua-5.1/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lua-5.1/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lua-5.1/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lua-5.1/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /lua-5.1/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /lua-5.1/test/README: -------------------------------------------------------------------------------- 1 | These are simple tests for Lua. Some of them contain useful code. 2 | They are meant to be run to make sure Lua is built correctly and also 3 | to be read, to see how Lua programs look. 4 | 5 | Here is a one-line summary of each program: 6 | 7 | bisect.lua bisection method for solving non-linear equations 8 | cf.lua temperature conversion table (celsius to farenheit) 9 | echo.lua echo command line arguments 10 | env.lua environment variables as automatic global variables 11 | factorial.lua factorial without recursion 12 | fib.lua fibonacci function with cache 13 | fibfor.lua fibonacci numbers with coroutines and generators 14 | globals.lua report global variable usage 15 | hello.lua the first program in every language 16 | life.lua Conway's Game of Life 17 | luac.lua bare-bones luac 18 | printf.lua an implementation of printf 19 | readonly.lua make global variables readonly 20 | sieve.lua the sieve of of Eratosthenes programmed with coroutines 21 | sort.lua two implementations of a sort function 22 | table.lua make table, grouping all data for the same item 23 | trace-calls.lua trace calls 24 | trace-globals.lua trace assigments to global variables 25 | xd.lua hex dump 26 | 27 | -------------------------------------------------------------------------------- /lua-5.1/test/bisect.lua: -------------------------------------------------------------------------------- 1 | -- bisection method for solving non-linear equations 2 | 3 | delta=1e-6 -- tolerance 4 | 5 | function bisect(f,a,b,fa,fb) 6 | local c=(a+b)/2 7 | io.write(n," c=",c," a=",a," b=",b,"\n") 8 | if c==a or c==b or math.abs(a-b) '%s'", k_dir, _dir.fullpath( k_dir ) ) 17 | if pds ~= ods then printf( "_dir tests: begin (cwd=%s)", _dir.current(pds) ) 18 | for ix,nm in ipairs( _dir.read_names( ".."..ods..".."..pds, 0 ) ) do printf( "%4d: %-40s -> '%s'", ix, nm, _dir.fullpath( nm ) ) end 19 | printf( "-----------------------------------------------" ) 20 | for ix,nm in ipairs( _dir.read_names( ".."..pds..".."..ods, 0 ) ) do printf( "%4d: %-40s -> '%s'", ix, nm, _dir.fullpath( nm ) ) end 21 | printf( "-----------------------------------------------" ) 22 | end 23 | for ix,nm in ipairs( _dir.read_names( k_dir, 0 ) ) do printf( "%4d: %-40s -> '%s'", ix, nm, _dir.fullpath( nm ) ) end 24 | printf( "-----------------------------------------------" ) 25 | for ix,nm in ipairs( _dir.read_dirnames( k_dir, 1 ) ) do printf( "%4d: %-40s -> '%s'", ix, nm, _dir.fullpath( nm ) ) end 26 | printf( "-----------------------------------------------" ) 27 | printf( "_dir tests: passed; took %f", os.gettimeofday() - start ) 28 | end 29 | 30 | print( stars ) 31 | -------------------------------------------------------------------------------- /lua-5.1/test/life.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/lua-5.1/test/life.lua -------------------------------------------------------------------------------- /lua-5.1/test/luac.lua: -------------------------------------------------------------------------------- 1 | -- bare-bones luac in Lua 2 | -- usage: lua luac.lua file.lua 3 | 4 | assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua") 5 | f=assert(io.open("luac.out","wb")) 6 | assert(f:write(string.dump(assert(loadfile(arg[1]))))) 7 | assert(f:close()) 8 | -------------------------------------------------------------------------------- /lua-5.1/test/printf.lua: -------------------------------------------------------------------------------- 1 | -- an implementation of printf 2 | 3 | function printf(...) 4 | io.write(string.format(...)) 5 | end 6 | 7 | printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date()) 8 | -------------------------------------------------------------------------------- /lua-5.1/test/readonly.lua: -------------------------------------------------------------------------------- 1 | -- make global variables readonly 2 | 3 | local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end 4 | local g={} 5 | local G=getfenv() 6 | setmetatable(g,{__index=G,__newindex=f}) 7 | setfenv(1,g) 8 | 9 | -- an example 10 | rawset(g,"x",3) 11 | x=2 12 | y=1 -- cannot redefine `y' 13 | -------------------------------------------------------------------------------- /lua-5.1/test/sieve.lua: -------------------------------------------------------------------------------- 1 | -- the sieve of of Eratosthenes programmed with coroutines 2 | -- typical usage: lua -e N=1000 sieve.lua | column 3 | 4 | -- generate all the numbers from 2 to n 5 | function gen (n) 6 | return coroutine.wrap(function () 7 | for i=2,n do coroutine.yield(i) end 8 | end) 9 | end 10 | 11 | -- filter the numbers generated by `g', removing multiples of `p' 12 | function filter (p, g) 13 | return coroutine.wrap(function () 14 | while 1 do 15 | local n = g() 16 | if n == nil then return end 17 | if math.mod(n, p) ~= 0 then coroutine.yield(n) end 18 | end 19 | end) 20 | end 21 | 22 | N=N or 1000 -- from command line 23 | x = gen(N) -- generate primes up to N 24 | while 1 do 25 | local n = x() -- pick a number until done 26 | if n == nil then break end 27 | print(n) -- must be a prime number 28 | x = filter(n, x) -- now remove its multiples 29 | end 30 | -------------------------------------------------------------------------------- /lua-5.1/test/sort.lua: -------------------------------------------------------------------------------- 1 | -- two implementations of a sort function 2 | -- this is an example only. Lua has now a built-in function "sort" 3 | 4 | -- extracted from Programming Pearls, page 110 5 | function qsort(x,l,u,f) 6 | if ly end) 58 | show("after reverse selection sort",x) 59 | qsort(x,1,n,function (x,y) return x>> ",string.rep(" ",level)) 9 | if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end 10 | t=debug.getinfo(2) 11 | if event=="call" then 12 | level=level+1 13 | else 14 | level=level-1 if level<0 then level=0 end 15 | end 16 | if t.what=="main" then 17 | if event=="call" then 18 | io.write("begin ",t.short_src) 19 | else 20 | io.write("end ",t.short_src) 21 | end 22 | elseif t.what=="Lua" then 23 | -- table.foreach(t,print) 24 | io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") 25 | else 26 | io.write(event," ",t.name or "(C)"," [",t.what,"] ") 27 | end 28 | io.write("\n") 29 | end 30 | 31 | debug.sethook(hook,"cr") 32 | level=0 33 | -------------------------------------------------------------------------------- /lua-5.1/test/trace-globals.lua: -------------------------------------------------------------------------------- 1 | -- trace assigments to global variables 2 | 3 | do 4 | -- a tostring that quotes strings. note the use of the original tostring. 5 | local _tostring=tostring 6 | local tostring=function(a) 7 | if type(a)=="string" then 8 | return string.format("%q",a) 9 | else 10 | return _tostring(a) 11 | end 12 | end 13 | 14 | local log=function (name,old,new) 15 | local t=debug.getinfo(3,"Sl") 16 | local line=t.currentline 17 | io.write(t.short_src) 18 | if line>=0 then io.write(":",line) end 19 | io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n") 20 | end 21 | 22 | local g={} 23 | local set=function (t,name,value) 24 | log(name,g[name],value) 25 | g[name]=value 26 | end 27 | setmetatable(getfenv(),{__index=g,__newindex=set}) 28 | end 29 | 30 | -- an example 31 | 32 | a=1 33 | b=2 34 | a=10 35 | b=20 36 | b=nil 37 | b=200 38 | print(a,b,c) 39 | -------------------------------------------------------------------------------- /lua-5.1/test/xd.lua: -------------------------------------------------------------------------------- 1 | -- hex dump 2 | -- usage: lua xd.lua < file 3 | 4 | local offset=0 5 | while true do 6 | local s=io.read(16) 7 | if s==nil then return end 8 | io.write(string.format("%08X ",offset)) 9 | string.gsub(s,"(.)", 10 | function (c) io.write(string.format("%02X ",string.byte(c))) end) 11 | io.write(string.rep(" ",3*(16-string.len(s)))) 12 | io.write(" ",string.gsub(s,"%c","."),"\n") 13 | offset=offset+16 14 | end 15 | -------------------------------------------------------------------------------- /lua_intf_common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | #include "ed_main.h" 23 | #include "fname_gen.h" 24 | 25 | #if defined(__GNUC__) 26 | #pragma GCC diagnostic push 27 | #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" 28 | 29 | #pragma GCC diagnostic push 30 | #pragma GCC diagnostic ignored "-Wold-style-cast" 31 | #endif 32 | 33 | // book http://www.lua.org/pil/ 34 | // file://c:/klg/sn/k/lua-5.1/doc/contents.html 35 | 36 | // see http://www.allacrost.org/ (open-)source code for an example of cooperating Lua and C++ interface 37 | 38 | extern "C" 39 | { 40 | #include 41 | #include 42 | #include 43 | #include 44 | } 45 | 46 | static inline stref Sr_( lua_State *L, int n ) { 47 | size_t length; 48 | const auto data( luaL_checklstring( L, (n), &length ) ); 49 | if( !data ) return stref(); 50 | else return stref( data, length ); 51 | } 52 | 53 | enum { DBG_LUA=0 }; 54 | 55 | //######### lua_edlib exports 56 | 57 | extern void l_OpenStdLibs ( lua_State *L ); 58 | extern void l_register_EdLib( lua_State *L ); 59 | 60 | extern int l_construct_View( lua_State *L, PView pView ); 61 | extern int l_construct_FBUF( lua_State *L, PFBUF pFBuf ); 62 | extern int l_construct_Win ( lua_State *L, PWin pWin ); 63 | 64 | extern int l_View_function_cur( lua_State *L ); 65 | 66 | //######### utility externs 67 | 68 | extern int LDS( PCChar tag, lua_State *L ); 69 | 70 | //######### common inlines 71 | 72 | STIL PChar getfieldStrdup( lua_State *L, const char *key ) { lua_getfield(L, -1, key); PChar rv( Strdup( luaL_checkstring(L, -1) ) ); lua_pop(L, 1); return rv; } 73 | STIL int getfieldInt( lua_State *L, const char *key ) { lua_getfield(L, -1, key); const int rv( luaL_checkint(L, -1) ) ; lua_pop(L, 1); return rv; } 74 | 75 | STIL void setfield( lua_State *L, PCChar key, PCChar val ) { lua_pushstring( L, val ); lua_setfield( L, -2, key ); } 76 | STIL void setfield( lua_State *L, PCChar key, int val ) { lua_pushinteger( L, val ); lua_setfield( L, -2, key ); } 77 | STIL void setfield( lua_State *L, PCChar key, lua_CFunction val ) { lua_pushcfunction( L, val ); lua_setfield( L, -2, key ); } 78 | 79 | STIL void setglobal( lua_State *L, PCChar key, PCChar val ) { lua_pushstring( L, val ); lua_setglobal( L, key ); } 80 | STIL void setglobal( lua_State *L, PCChar key, int val ) { lua_pushinteger( L, val ); lua_setglobal( L, key ); } 81 | 82 | #if defined(__GNUC__) 83 | #pragma GCC diagnostic pop 84 | #endif 85 | -------------------------------------------------------------------------------- /menu.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/menu.lua -------------------------------------------------------------------------------- /my_fio.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | // 21 | // FileIO System-call wrappers 22 | // 23 | 24 | #pragma once 25 | 26 | #include "my_types.h" 27 | #include 28 | 29 | #if defined(_WIN32) 30 | #include 31 | #include 32 | #endif 33 | 34 | #include 35 | #include 36 | 37 | #define DFLT_TEXTFILE_CREATE_MODE 0666 38 | 39 | class fio { // could use namespace vs. class but cannot declare private members of namespace 40 | STATIC_FXN ssize_t Read ( int fh, PVoid pBuf, ssize_t bytesToRead ); 41 | STATIC_FXN ssize_t Write( int fh, PCVoid pBuf, ssize_t bytesToWrite ); 42 | 43 | public: 44 | STATIC_FXN bool OpenFileFailed( int *pfh, PCChar pszFileName, bool fWrAccess, int create_mode=0 ); 45 | STIL bool ReadOk( int fh, PVoid pBuffer, int bytes ) { return Read( fh, pBuffer, bytes ) == bytes; } 46 | STIL bool WriteOk( int fh, PCVoid pBuffer, int bytes ) { return Write( fh, pBuffer, bytes ) == bytes; } 47 | #if defined(_WIN32) 48 | STIL int Close( int fh ) { return _close( fh ); } // -1 == error, 0 == success 49 | STIL int Fsync( int fh ) { return _commit( fh ); } // -1 == error, 0 == success 50 | STIL __int64 Lseek( int fh, __int64 lDistanceToMove, int dwMoveMethod ) { return _lseeki64( fh, lDistanceToMove, dwMoveMethod ); } 51 | STIL __int64 SeekEoF( int fh ) { return Lseek( fh, 0, SEEK_END ); } 52 | #else 53 | STIL int Close( int fh ) { return close( fh ); } // -1 == error, 0 == success 54 | STIL int Fsync( int fh ) { return fsync( fh ); } // -1 == error, 0 == success 55 | STIL off_t Lseek( int fh, off_t lDistanceToMove, int dwMoveMethod ) { return lseek( fh, lDistanceToMove, dwMoveMethod ); } 56 | STIL off_t SeekEoF( int fh ) { return Lseek( fh, 0, SEEK_END ); } 57 | #endif 58 | STIL void SeekBoF( int fh ) { Lseek( fh, 0, SEEK_SET ); } 59 | }; 60 | 61 | extern bool MoveFileOk( PCChar pszCurFileName, PCChar pszNewFilename ); 62 | 63 | #define CopyFileManuallyOk( pszCurFileName, pszNewFilename ) CopyFileManuallyOk_( pszCurFileName, pszNewFilename, __func__ ) 64 | extern bool CopyFileManuallyOk_( PCChar pszCurFileName, PCChar pszNewFilename, PCChar caller ); 65 | 66 | #define VERBOSE_READ 1 67 | #if VERBOSE_READ 68 | # define VR_( x ) x 69 | #else 70 | # define VR_( x ) 71 | #endif 72 | 73 | #if 0 74 | 75 | // read: classic look 76 | 77 | #define kszRdNoiseOpen " Open " 78 | #define kszRdNoiseSeek " Open Size " 79 | #define kszRdNoiseAllc " Open Size Alloc " 80 | #define kszRdNoiseRead " Open Size Alloc Read " 81 | #define kszRdNoiseScan " Open Size Alloc Read Scan " 82 | 83 | #else 84 | 85 | // read: duty-cycle look 86 | 87 | #define kszRdNoiseOpen " Open " 88 | #define kszRdNoiseSeek " Size " 89 | #define kszRdNoiseAllc " Alloc " 90 | #define kszRdNoiseRead " Read " 91 | #define kszRdNoiseScan " Scan " 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /my_log.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | // 21 | // Logging classes/APIs 22 | // 23 | 24 | #pragma once 25 | 26 | #define NO_LOG 0 27 | #if NO_LOG 28 | // #define version does make smaller code, but causes almost 300 of "warning C4002: too many actual parameters for macro 'DBG'" 29 | // #define DBG() (1) 30 | // STIL version results in almost NO code size change since the params are all evaluated even if the function does nothing 31 | STIL int DBG( char const *kszFormat, ... ) ATTR_FORMAT(1, 2) { return 1; } 32 | STIL void DBG_init() {} 33 | STIL void DBG_init() {} 34 | STIL void DBGNL() {} 35 | #else 36 | extern int DBG( char const *kszFormat, ... ) ATTR_FORMAT(1, 2); 37 | extern void DBGNL(); 38 | extern void DBG_init(); 39 | #endif 40 | -------------------------------------------------------------------------------- /odkey.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # http://unix.stackexchange.com/questions/110236/how-to-find-out-the-escape-sequence-my-keyboards-sends-to-terminal 3 | { 4 | stty raw min 1 time 20 -echo 5 | dd count=1 2> /dev/null | od -vAn -tc | sed -e 's/ \+/ /g' -e 's/^ 033 \[ /CSI /' -e 's/^ 033 O /SS3 /' 6 | stty sane 7 | } 8 | -------------------------------------------------------------------------------- /patch-coverity: -------------------------------------------------------------------------------- 1 | diff --git a/ed_core.h b/ed_core.h 2 | index 9d828f6..9e509b3 100644 3 | --- a/ed_core.h 4 | +++ b/ed_core.h 5 | @@ -19,7 +19,7 @@ 6 | 7 | #pragma once 8 | 9 | -static_assert( CHAR_MAX > SCHAR_MAX, "char not unsigned" ); 10 | +// static_assert( CHAR_MAX > SCHAR_MAX, "char not unsigned" ); 11 | 12 | // 13 | // MACRO_BACKSLASH_ESCAPES - Affects escape char defn and behavior in macro 14 | -------------------------------------------------------------------------------- /pdconv.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwmechanic/k_edit/6c2ef6a1151a0ed5f719e868d6bd437538d26587/pdconv.lua -------------------------------------------------------------------------------- /regex_rplc_test.txt: -------------------------------------------------------------------------------- 1 | 2 | arg qreplace "stcapt1secondcapt2again" nl "foo" 3 | arg arg qreplace "^first([a-z0-9]+)se(co)nd([a-z0-9]+)again" nl "*\2*\1*\9*" 4 | arg arg qreplace "first([a-z0-9]+)se(co)nd([a-z0-9]+)again" nl "*\2*\1*\9*" 5 | arg arg qreplace "first([a-z0-9]+)se(co)nd([a-z0-9]+)again" nl "*\2*\1*\3*" 6 | arg arg "first([a-z0-9]+)second([a-z0-9]+)again" grep 7 | arg arg qreplace "first([a-z0-9]+)second([a-z0-9]+)again" nl "*\1*\2*" 8 | arg arg replace "first([a-z0-9]+)second([a-z0-9]+)again" nl "*\1*\2*" nl . 18 | // 19 | 20 | #include "ed_main.h" 21 | #include "rm_util.h" 22 | #include "my_log.h" 23 | #include "filename.h" 24 | #include 25 | #include "my_strutils.h" 26 | #include "my_fio.h" 27 | #if defined(_WIN32) 28 | #include "win32_base.h" 29 | #endif 30 | 31 | int SaveFileMultiGenerationBackup( PCChar pszFileName, const struct_stat &stat_buf ) { enum { SD=0 }; 32 | SD && DBG( "SFMG+ '%s'", pszFileName ); 33 | auto dest( std::string(Path::RefDirnm( pszFileName )) + kszBakDirNm ); 34 | auto mkdirLen( dest.length() ); 35 | NewScope { // validity of dirname 36 | const auto dirname( dest.c_str() ); 37 | const auto err( WL( _mkdir( dirname ), mkdir( dirname, 0777 ) ) == -1 ); 38 | if( !err ) { 0 && DBG( "mkdir (by %s) created dir '%s'", __func__, dirname ); 39 | #if defined(_WIN32) 40 | SetFileAttrsOk( dirname, FILE_ATTRIBUTE_HIDDEN ); 41 | #endif 42 | } 43 | else { 44 | mkdirLen = 0; 45 | switch( errno ) { 46 | case EEXIST: break; 47 | default : DBG( "!!! mkdir (by %s) of '%s' failed, emsg='%s'", __func__, dirname, strerror( errno ) ); 48 | return SFMG_CANT_MK_BAKDIR; 49 | } 50 | } 51 | } 52 | struct tm tt; 53 | const auto fOk( 54 | #if defined(_WIN32) 55 | 0 == localtime_s( &tt, &stat_buf.st_mtime ) 56 | #else 57 | nullptr != localtime_r( &stat_buf.st_mtime, &tt ) 58 | #endif 59 | ); 60 | char tbuf[32]; 61 | if( fOk ) { strftime( BSOB(tbuf), "%Y%m%d_%H%M%S", &tt ); } 62 | else { bcpy( tbuf, "XlocaltimeX" ); } 63 | const auto filenameNoPath( Path::RefFnameExt( pszFileName ) ); SD && DBG("SFMG B '%" PR_BSR "'", BSR(filenameNoPath) ); 64 | dest.append( (DIRSEP_STR + std::string( filenameNoPath ) + "." + tbuf ) ); 65 | #if defined(_WIN32) 66 | unlinkOk( dest.c_str() ); 67 | #endif 68 | if( rename( pszFileName, dest.c_str() ) ) { 69 | SD && DBG( "SFMG! [2] mv '%s' -> '%s' failed", pszFileName, dest.c_str() ); 70 | if( mkdirLen ) { // something to undo? 71 | dest.resize( mkdirLen ); // retrieve dirname as ASCIZ 72 | WL( _rmdir, rmdir )( dest.c_str() ); // undo mkdir 73 | } 74 | return SFMG_CANT_MV_ORIG; 75 | } 76 | 77 | SD && DBG( "SFMG- [0]" ); 78 | return SFMG_OK; 79 | } 80 | -------------------------------------------------------------------------------- /rm_util.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #if defined(_WIN32) 31 | #include 32 | #include 33 | #endif 34 | #include // for alloca() 35 | #include // for struct _stat 36 | 37 | #include "my_types.h" 38 | 39 | enum { SFMG_OK, SFMG_CANT_MV_ORIG, SFMG_CANT_MK_BAKDIR }; 40 | extern int SaveFileMultiGenerationBackup( PCChar pszFileName, const struct_stat &stat_buf ); 41 | -------------------------------------------------------------------------------- /show.lua: -------------------------------------------------------------------------------- 1 | -- This function conditions a key or value for display 2 | 3 | local function LclRenderStr(Obj, TruncLen) 4 | local TpStr = type(Obj) 5 | if TpStr == "string" then 6 | Obj = string.gsub(Obj, "[^%w%p ]", function(Ch) 7 | return "\\" .. string.format("%03d", string.byte(Ch)) end ) 8 | if TruncLen and TruncLen > 0 and string.len(Obj) > TruncLen + 3 then 9 | -- This could misleadingly truncate numeric escape value 10 | Obj = string.sub(Obj, 1, TruncLen) .. "..." 11 | end 12 | Obj = '"' .. Obj .. '"' 13 | elseif TpStr == "boolean" then 14 | Obj = "boolean: " .. tostring(Obj) 15 | else 16 | Obj = tostring(Obj) 17 | end 18 | return Obj 19 | end 20 | 21 | -- This function replaces ["x"]["y"] stubble with x.y. Keys are assumed to be 22 | -- identifier-compatible. 23 | 24 | local function LclShave(Str) 25 | local Count 26 | Str, Count = string.gsub(Str, '^%[%"(.+)%"%]$', '%1') 27 | if Count == 1 then 28 | Str = string.gsub(Str, '%"%]%[%"', '.') 29 | end 30 | return Str 31 | end 32 | 33 | local function LclRender(Tbl, Val, KeyStr, TruncLen, Lvl, Visited, KeyPathStr) 34 | local VtpStr, ValStr 35 | VtpStr = type(Val) 36 | if Visited[Val] then 37 | ValStr = "same as " .. Visited[Val] 38 | else 39 | ValStr = LclRenderStr(Val, TruncLen) 40 | if VtpStr == "function" then -- Display function's environment 41 | local Env = getfenv(Val) 42 | Env = Visited[Env] or Env 43 | ValStr = string.gsub(ValStr, "(function:%s*.*)$", "%1 (env " .. 44 | string.gsub(tostring(Env), "table: ", "") .. ")") 45 | elseif VtpStr == "table" then 46 | ValStr = ValStr .. string.format(" (n = %d)", #Val) 47 | end 48 | end 49 | KeyPathStr = KeyPathStr .. "[" .. KeyStr .. "]" 50 | table.insert(Tbl, { Lvl, string.format('[%s] %s', 51 | KeyStr, ValStr) }) 52 | if VtpStr == "table" and not Visited[Val] then 53 | Visited[Val] = LclShave(KeyPathStr) 54 | local SrtTbl = {} 55 | for K, V in pairs(Val) do 56 | table.insert(SrtTbl, { LclRenderStr(K, TruncLen), V, K, type(K) }) 57 | end 58 | local function LclCmp(A, B) 59 | local Cmp 60 | local Ta, Tb = A[4], B[4] 61 | if Ta == "number" then 62 | if Tb == "number" then 63 | Cmp = A[3] < B[3] 64 | else 65 | Cmp = true -- Numbers appear first 66 | end 67 | else -- A is not a number 68 | if Tb == "number" then 69 | Cmp = false -- Numbers appear first 70 | else 71 | Cmp = A[1] < B[1] 72 | end 73 | end 74 | return Cmp 75 | end 76 | table.sort(SrtTbl, LclCmp) 77 | for J, Rec in ipairs(SrtTbl) do 78 | LclRender(Tbl, Rec[2], Rec[1], TruncLen, Lvl + 1, Visited, KeyPathStr) 79 | end 80 | end 81 | end 82 | 83 | -- This function appends a series of records of the form { level, 84 | -- description_string } to the indexed table specified by Tbl. When this 85 | -- function returns, Tbl can be used to inspect the Lua object specified by 86 | -- Val. Key specifies the name of the object. TruncLen specifies the maximum 87 | -- length of each description string; if this value is zero, no truncation will 88 | -- take place. Keys are sorted natively (that is, numbers are sorted 89 | -- numerically and everything else lexically). String values are displayed with 90 | -- quotes, numbers are unadorned, and all other values have an identifying 91 | -- prefix such as "boolean". Consequently, all keys are displayed within their 92 | -- type partition. This function returns nothing; its only effect is to augment 93 | -- Tbl. 94 | 95 | function ObjectDescribe(Tbl, Val, Key, TruncLen) 96 | LclRender(Tbl, Val, LclRenderStr(Key, TruncLen), TruncLen or 0, 1, {}, "") 97 | end 98 | 99 | -- This function prints a hierarchical summary of the object specified by Val 100 | -- to standard out. See ObjectDescribe for more details. 101 | 102 | function ObjectShow(Val, Key, TruncLen) 103 | local Tbl = {} 104 | ObjectDescribe(Tbl, Val, Key, TruncLen) 105 | for J, Rec in ipairs(Tbl) do 106 | print(string.rep(" ", Rec[1] - 1) .. Rec[2]) -- 20070411 kgoodwin original uses io.write in lieu of K's print 107 | end 108 | end 109 | -------------------------------------------------------------------------------- /std.dynlib.linux: -------------------------------------------------------------------------------- 1 | libncurses.so 2 | libtinfo.so 3 | libpthread.so 4 | libpcre.so 5 | libm.so 6 | libc.so 7 | libdl.so 8 | ld-linux-x86-64.so 9 | -------------------------------------------------------------------------------- /std.dynlib.mingw: -------------------------------------------------------------------------------- 1 | KERNEL32.dll 2 | msvcrt.dll 3 | PSAPI.DLL 4 | SHELL32.dll 5 | USER32.dll 6 | ADVAPI32.dll 7 | bcrypt.dll 8 | -------------------------------------------------------------------------------- /strict.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- strict.lua 3 | -- checks uses of undeclared global variables 4 | -- All global variables must be 'declared' through a regular assignment 5 | -- (even assigning nil will do) in a main chunk before being used 6 | -- anywhere or assigned to inside a function. 7 | -- 8 | 9 | local mt = getmetatable(_G) 10 | if mt == nil then 11 | mt = {} 12 | setmetatable(_G, mt) 13 | end 14 | 15 | mt.__declared = {} 16 | 17 | mt.__newindex = function (t, n, v) 18 | if not mt.__declared[n] then 19 | local w = debug.getinfo(2, "S").what 20 | if w ~= "main" and w ~= "C" then 21 | error("assign to undeclared variable '"..n.."'", 2) 22 | end 23 | mt.__declared[n] = true 24 | end 25 | rawset(t, n, v) 26 | end 27 | 28 | mt.__index = function (t, n) 29 | if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then 30 | error("variable '"..n.."' is not declared", 2) 31 | end 32 | return rawget(t, n) 33 | end 34 | 35 | -------------------------------------------------------------------------------- /stringlist.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2021 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #include "ed_main.h" 21 | #include "stringlist.h" 22 | 23 | StringListEl *StringList::NewStringListEl( stref src ) { 24 | const auto len( src.length() ); 25 | StringListEl *rv; 26 | AllocBytesNZ( rv, sizeof( *rv ) + len + 1 ); 27 | rv->dlink.clear(); 28 | rv->len = len; 29 | memcpy( rv->string, src.data(), len ); 30 | rv->string[len] = '\0'; 31 | return rv; 32 | } 33 | -------------------------------------------------------------------------------- /stringlist.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015,2021 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | #include "my_types.h" 23 | #include "dlink.h" 24 | #include 25 | 26 | struct StringListEl { 27 | DLinkEntry dlink; 28 | size_t len; 29 | char string[0]; 30 | stref ref() const { return stref(string,len); } 31 | }; 32 | 33 | #define FreeStringListEl( pSLE ) Free0( pSLE ) 34 | 35 | class StringList { 36 | public: 37 | DLinkHead d_head; // _public_ so DLINKC_FIRST_TO_LASTA can be used to efficiently walk the list 38 | StringList() {} 39 | StringList( PCChar str ) { push_back( str ); } 40 | ~StringList() { clear(); } 41 | unsigned length() const { return d_head.length(); } 42 | void clear() { 43 | while( auto pEl=remove_first() ) { 44 | FreeStringListEl( pEl ); 45 | } 46 | } 47 | static StringListEl *NewStringListEl( stref src ); 48 | void push_back( stref src ) { 49 | auto pIns( NewStringListEl( src ) ); 50 | DLINK_INSERT_LAST( d_head, pIns, dlink ); 51 | } 52 | StringListEl *remove_first() { StringListEl *rv; DLINK_REMOVE_FIRST( d_head, rv, dlink ); return rv; } 53 | }; 54 | -------------------------------------------------------------------------------- /switch_impl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2018 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #pragma once 21 | 22 | // Disable a picky gcc-8 compiler warning 23 | #if defined(__GNUC__) && (__GNUC__ >= 8) 24 | #pragma GCC diagnostic ignored "-Wcast-function-type" 25 | #endif 26 | 27 | // 28 | // Switch definition table defintions 29 | // 30 | 31 | class SWI_intf { 32 | public: 33 | SWI_intf() {} 34 | virtual ~SWI_intf() {} 35 | virtual std::string defn( stref newValue ) = 0; // { return "not implemented!"; } 36 | virtual std::string disp() = 0; // { return "not implemented!"; } 37 | }; 38 | 39 | struct enum_nm { int val; PCChar name; }; 40 | 41 | struct SWI_impl_factory { 42 | SWI_intf *SWIs( stref (* get_)(), stref (* set_)( stref ) ); 43 | SWI_intf *SWIsb( void (*dsp_)( PChar dest, size_t sizeofDest ), void (* set_)( stref ) ); 44 | SWI_intf *SWIi_bv( bool &var_ ); 45 | SWI_intf *SWIi_iv( int &var_ ); 46 | SWI_intf *SWIi_ci( int (*get_)(), void (*set_)(int), int (*min_)(), int (*max_)(), bool fUseConstrained_=true ); 47 | SWI_intf *SWI_color( uint8_t &var_ ); 48 | SWI_intf *SWI_chdisp( char &var_ ); 49 | SWI_intf *SWI_enum( int (*get_)(), void (*set_)(int), const enum_nm *enums_, size_t num_enums_ ); 50 | }; 51 | -------------------------------------------------------------------------------- /test/pst01.ps1: -------------------------------------------------------------------------------- 1 | ### https://ss64.com/ps/syntax-comments.html example 1 2 | Copy-Item demo.msi C:\install\demo.msi #copy the installer 3 | 4 | <# 5 | Running this script will make your computer catch fire! 6 | Last updated: 1666-09-02 7 | #> 8 | 9 | Get-Content -Path <#configuration file#> C:\app64.ini 10 | 11 | 12 | ### https://ss64.com/ps/syntax-esc.html 13 | echo 1 `# 1 14 | echo 1 # 1 15 | 16 | 17 | $msg = 'Every "lecture" should cost $5000' 18 | 19 | $msg = "Every ""lecture"" should cost `$5000" 20 | $msg = "Every 'lecture' should cost `$5000" 21 | $var = 45 22 | "The value of " + '$var' + "is '$var'" 23 | "The value of `$var is '$var'" 24 | $query = "SELECT * FROM Customers WHERE Name LIKE '%JONES%'" 25 | 26 | 27 | $myHereString = @' 28 | some text with "quotes" and variable names $printthis 29 | some more text 30 | '@ 31 | 32 | $anotherHereString = @" 33 | The value of `$var is $var 34 | some more text 35 | "@ 36 | -------------------------------------------------------------------------------- /test/traildisp.txt: -------------------------------------------------------------------------------- 1 | 3 trail 2 | 2 trail 3 | 1 trail 4 | 4 trail 5 | 5 trail 6 | 6 trail 7 | 7 trail 8 | 8 trail 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | many many spaces 18 | end -------------------------------------------------------------------------------- /test_tagfind: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2015-2019 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 5 | # 6 | # This file is part of K. 7 | # 8 | # K is free software: you can redistribute it and/or modify it under the 9 | # terms of the GNU General Public License as published by the Free Software 10 | # Foundation, either version 3 of the License, or (at your option) any later 11 | # version. 12 | # 13 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 14 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 | # details. 17 | # 18 | # You should have received a copy of the GNU General Public License along 19 | # with K. If not, see . 20 | # 21 | 22 | die() { printf %s "${@+$@$'\n'}" 1>&2 ; exit 1 ; } 23 | 24 | export LC_ALL="en_US.utf8" # fix `grep -P` 25 | num_rand_tags=50 # test param 26 | 27 | tagfnm=tags 28 | first_tag="$(head -n 1 "$tagfnm" | cut -f 1)" 29 | last_tag="$(tail -n 1 "$tagfnm" | cut -f 1)" 30 | before_first="${first_tag%?}" # remove last char of first_tag https://unix.stackexchange.com/a/259042 31 | after_last="${last_tag}_nonexistent" 32 | 33 | tgtexe=unittest_tagfind.exe 34 | 35 | make "$tgtexe" || die 36 | 37 | chk_tagfind() { 38 | local ans ; ans="$(grep --count -P '^\Q'"$1"'\E\t' "$tagfnm")" 39 | # echo "$1: expect $ans" 40 | local lc ; lc="$(./"$tgtexe" "$1" | wc -l)" ; ((lc==ans)) || die "FAIL: for T=$1, expected $ans, got $lc" 41 | } 42 | chk_tagfind "$before_first" 43 | chk_tagfind "$first_tag" 44 | chk_tagfind "$last_tag" 45 | chk_tagfind "$after_last" 46 | 47 | readarray -t test_tags <<<"$( cut -f 1 "$tagfnm" | sort -u | sort -R | head -n "$num_rand_tags" )" # https://unix.stackexchange.com/a/322505 48 | # echo "${test_tags[@]}" 49 | 50 | for tag in "${test_tags[@]}"; do 51 | #echo "tag=$tag'" 52 | chk_tagfind "$tag" 53 | done 54 | 55 | chk_tagged_files() { 56 | local file_tag_field ; file_tag_field=$'\t'"kind:file" 57 | local ref ; ref="$(grep -P "$file_tag_field"'(\t|$)' tags | cut -f2 | sort -u | wc -l)" 58 | local tst ; tst="$(./"$tgtexe" "$file_tag_field" | wc -l)" 59 | ((tst==ref)) || die "FAIL: chk_tagged_files, expected $ref, got $lc" 60 | } 61 | 62 | chk_tagged_files 63 | -------------------------------------------------------------------------------- /ubuntu_univ-ctags_build_install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright 2018 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 5 | # 6 | # This file is part of K. 7 | # 8 | # K is free software: you can redistribute it and/or modify it under the 9 | # terms of the GNU General Public License as published by the Free Software 10 | # Foundation, either version 3 of the License, or (at your option) any later 11 | # version. 12 | # 13 | # K is distributed in the hope that it will be useful, but WITHOUT ANY 14 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 | # details. 17 | # 18 | # You should have received a copy of the GNU General Public License along 19 | # with K. If not, see . 20 | # 21 | 22 | # run to unilaterally install universal-ctags from source code on ubuntu 23 | 24 | # based on https://askubuntu.com/a/836521 whose comments contain necessary updates reflected below 25 | 26 | reponm="ctags" 27 | repo="https://github.com/universal-ctags/$reponm.git" 28 | pkgs=( # prereqs from askubuntu ticket comments 29 | "autoconf" 30 | "automake" 31 | "pkg-config" 32 | ) 33 | join_by() { local IFS="$1"; shift; echo "$*"; } 34 | 35 | # if we're in a repo/worktree dir, cd to its parent dir before cloning 36 | wtpath="$(git rev-parse --show-toplevel)" 37 | [ "$wtpath" ] && wtpath="$(dirname "$wtpath")" 38 | [ "$wtpath" ] && cd "$wtpath" 39 | 40 | sudo apt-get install -yq $(join_by " " "${pkgs[@]}") && 41 | git clone "$repo" && 42 | cd "$reponm" && 43 | ./autogen.sh && 44 | ./configure && 45 | make && 46 | sudo make install 47 | -------------------------------------------------------------------------------- /util.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2015 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | -- 4 | -- This file is part of K. 5 | -- 6 | -- K is free software: you can redistribute it and/or modify it under the 7 | -- terms of the GNU General Public License as published by the Free Software 8 | -- Foundation, either version 3 of the License, or (at your option) any later 9 | -- version. 10 | -- 11 | -- K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | -- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | -- details. 15 | -- 16 | -- You should have received a copy of the GNU General Public License along 17 | -- with K. If not, see . 18 | -- 19 | 20 | module( "util", package.seeall ) 21 | 22 | 23 | -- http://www.lua.org/pil/ 24 | -- http://lua-users.org/wiki/StringRecipes 25 | -- http://lua-users.org/lists/lua-l/ 26 | -- file://c:/klg/sn/k/lua-5.1/doc/contents.html luaL_openlib see luaL_register 27 | 28 | 29 | function trim( strval, spcrplc ) 30 | return strval:gsub( "^%s*(.-)%s*$" , "%1" ) 31 | end 32 | 33 | 34 | function nowhite( strval, spcrplc ) 35 | return strval:gsub( "(%s+)", "" ) 36 | end 37 | 38 | 39 | function rpad( str, maxwidth ) 40 | local len = str:len() 41 | if len < maxwidth then return str .. string.rep( " ", maxwidth - len ) 42 | else return str end 43 | end 44 | 45 | function case_insensitive_pattern( str ) return str:gsub( "%a", function(ch) return "["..ch:upper()..ch:lower(ch).."]" end ) end 46 | function pattern_escape_magic( str ) return str:gsub( "[-%[%]().+*?^$%%]", function(ch) return "%"..ch end ) end 47 | 48 | 49 | function errassert( expr, msg, level ) 50 | if not expr then error( msg, level+1 ) end 51 | return expr 52 | end 53 | 54 | 55 | function matches( text, pat ) -- splitp 56 | local rv = {} 57 | text:gsub( pat or "(%S+)", 58 | function( match ) rv[ #rv + 1 ] = match end 59 | ) 60 | return rv 61 | end 62 | 63 | 64 | function byteSource( buffer, offset ) 65 | printf( "byteSource: len %d", buffer:len() ) 66 | offset = offset or 0 67 | return function( len, errstr ) 68 | if not len then return buffer:len() end -- parameterless call returns bytes remaining/available 69 | assert( buffer:len() >= len, fmt( "error reading %s, offset %d: needed %d bytes, had %d\n", errstr, offset, len, buffer:len() ) ) 70 | local rvOfs = offset 71 | local rvBuf = buffer:sub( 1, len ) 72 | buffer = buffer:sub( len+1 ) 73 | offset = offset + len 74 | return rvBuf, rvOfs 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /win32.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2015-2022 by Kevin L. Goodwin [fwmechanic@gmail.com]; All rights reserved 3 | // 4 | // This file is part of K. 5 | // 6 | // K is free software: you can redistribute it and/or modify it under the 7 | // terms of the GNU General Public License as published by the Free Software 8 | // Foundation, either version 3 of the License, or (at your option) any later 9 | // version. 10 | // 11 | // K is distributed in the hope that it will be useful, but WITHOUT ANY 12 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 | // details. 15 | // 16 | // You should have received a copy of the GNU General Public License along 17 | // with K. If not, see . 18 | // 19 | 20 | #include "ed_main.h" 21 | #include "win32_pvt.h" 22 | 23 | //================================================================================================================ 24 | // 25 | // s_GlobalVariableLock is a std::mutex 26 | // 27 | // We use it to allow multiple threads to exclusively access the "MainThread" 28 | // variables (the vast majority of global editor data structures). When the 29 | // main thread waits for user input, it passes the lock to other threads that 30 | // might be waiting for it. 31 | // 32 | // Due to the organization of the code, there are two circumstances: 33 | // 34 | // 1) (main thread): assumed to hold the lock except during small regions of 35 | // the code during which the lock is relinquished. The code construct used 36 | // "releases ownership during a particular scope". Due to the conditionals 37 | // involved, I have not created a class/object for this case. 38 | // 39 | // 2) (aux threads): assumed to NOT hold the lock except during small regions 40 | // of the code during which the lock is held. The code construct used 41 | // "takes ownership during a particular scope": construct then destroy a 42 | // WhileHoldingGlobalVariableLock object. 43 | // 44 | //================================================================================================================ 45 | 46 | const auto mainThreadId( std::this_thread::get_id() ); 47 | 48 | STIL void ASSERT_MAIN_THREAD() { Assert(mainThreadId == std::this_thread::get_id()); } 49 | STIL void ASSERT_NOT_MAIN_THREAD() { Assert(mainThreadId != std::this_thread::get_id()); } 50 | 51 | STATIC_VAR std::mutex s_GlobalVariableLock; 52 | STIL void GiveUpGlobalVariableLock() { /* DBG( "rls baton" ); */ s_GlobalVariableLock.unlock(); } 53 | STIL void WaitForGlobalVariableLock() { s_GlobalVariableLock.lock(); /* DBG( "got baton" ); */ } 54 | 55 | WhileHoldingGlobalVariableLock::WhileHoldingGlobalVariableLock() { WaitForGlobalVariableLock(); } 56 | WhileHoldingGlobalVariableLock::~WhileHoldingGlobalVariableLock() { GiveUpGlobalVariableLock(); } 57 | 58 | void MainThreadGiveUpGlobalVariableLock() { ASSERT_MAIN_THREAD(); MainThreadPerfCounter::PauseAll() ; GiveUpGlobalVariableLock() ; } 59 | void MainThreadWaitForGlobalVariableLock() { ASSERT_MAIN_THREAD(); WaitForGlobalVariableLock() ; MainThreadPerfCounter::ResumeAll() ; } 60 | 61 | #undef GiveUpGlobalVariableLock 62 | #undef WaitForGlobalVariableLock 63 | 64 | // 65 | // do NOT reference s_GlobalVariableLock by name below this line! 66 | //================================================================================================================ 67 | -------------------------------------------------------------------------------- /xk.bat: -------------------------------------------------------------------------------- 1 | rm k.exe 2 | --------------------------------------------------------------------------------