diff --git a/Makefile b/Makefile index c2f5825..706faee 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,13 @@ INSTALLMAN=${INSTALL} -m 444 INSTALLCONF=${INSTALL} -m 644 AWK=awk +UUS=ansiesc.tar.uu less.vim.uu perldoc.vim.uu vimcat.uu ConcealRetab.vim.uu +ANSIESC=src/ansiesc/autoload/AnsiEsc.vim src/ansiesc/plugin/AnsiEscPlugin.vim src/ansiesc/plugin/cecutil.vim + + all: vimpager docs -vimpager: ansiesc.tar.uu less.vim.uu perldoc.vim.uu vimcat.uu ConcealRetab.vim.uu +vimpager: ${UUS} mv vimpager vimpager.work ${AWK} '\ /^begin [0-9]* ansiesc.tar/ { exit } \ @@ -82,20 +86,14 @@ vimpager: ansiesc.tar.uu less.vim.uu perldoc.vim.uu vimcat.uu ConcealRetab.vim.u rm -f vimpager.work ConcealRetab.vim.uu chmod +x vimpager -less.vim.uu: less.vim - uuencode less.vim less.vim > less.vim.uu - -perldoc.vim.uu: perldoc.vim - uuencode perldoc.vim perldoc.vim > perldoc.vim.uu +%.vim.uu: src/%.vim + (cd src; uuencode `basename $<` `basename $<` > ../$@) vimcat.uu: vimcat - uuencode vimcat vimcat > vimcat.uu - -ConcealRetab.vim.uu: ConcealRetab.vim - uuencode ConcealRetab.vim ConcealRetab.vim > ConcealRetab.vim.uu + uuencode $< $< > $@ -ansiesc.tar.uu: ansiesc/autoload/AnsiEsc.vim ansiesc/plugin/AnsiEscPlugin.vim ansiesc/plugin/cecutil.vim - (cd ansiesc; tar cf ../ansiesc.tar .) +ansiesc.tar.uu: ${ANSIESC} + (cd src/ansiesc; tar cf ../../ansiesc.tar .) uuencode ansiesc.tar ansiesc.tar > ansiesc.tar.uu rm -f ansiesc.tar @@ -135,17 +133,17 @@ install: docs docs: @if command -v pandoc >/dev/null; then \ printf '%s' 'Generating vimpager.1...'; \ - pandoc -s -w man vimpager.md -o vimpager.1; \ + pandoc -s -w man doc/vimpager.md -o vimpager.1; \ tr -d '\015' < vimpager.1 > vimpager.1.tmp; \ mv vimpager.1.tmp vimpager.1; \ echo 'done.'; \ printf '%s' 'Generating vimcat.1...'; \ - pandoc -s -w man vimcat.md -o vimcat.1; \ + pandoc -s -w man doc/vimcat.md -o vimcat.1; \ tr -d '\015' < vimcat.1 > vimcat.1.tmp; \ mv vimcat.1.tmp vimcat.1; \ echo 'done.'; \ printf '%s' 'Generating README...'; \ - pandoc -s -w plain vimpager.md -o README; \ + pandoc -s -w plain doc/vimpager.md -o README; \ tr -d '\015' < README > README.tmp; \ mv README.tmp README; \ echo 'done.'; \ diff --git a/README.md b/README.md index 70c31f0..18be9ac 120000 --- a/README.md +++ b/README.md @@ -1 +1 @@ -vimpager.md \ No newline at end of file +doc/vimpager.md \ No newline at end of file diff --git a/TODO b/TODO new file mode 100644 index 0000000..d9e02d9 --- /dev/null +++ b/TODO @@ -0,0 +1,3 @@ +add usage screen +either add multi file support or throw error and update docs +better error message for unreadable files diff --git a/vimcat.md b/doc/vimcat.md similarity index 100% rename from vimcat.md rename to doc/vimcat.md diff --git a/vimpager.md b/doc/vimpager.md similarity index 100% rename from vimpager.md rename to doc/vimpager.md diff --git a/ConcealRetab.vim b/src/ConcealRetab.vim similarity index 88% rename from ConcealRetab.vim rename to src/ConcealRetab.vim index a663967..f2d434b 100644 --- a/ConcealRetab.vim +++ b/src/ConcealRetab.vim @@ -1,6 +1,6 @@ -command! -nargs=0 -bang -bar ConcealRetab :call ConcealRetab() +command! -nargs=0 -bang -bar ConcealRetab :call ConcealRetab#ConcealRetab() -function! ConcealRetab() +function! ConcealRetab#ConcealRetab() let l:current_cursor = getpos('.') call cursor(1,1) diff --git a/ansiesc/.VimballRecord b/src/ansiesc/.VimballRecord similarity index 100% rename from ansiesc/.VimballRecord rename to src/ansiesc/.VimballRecord diff --git a/ansiesc/autoload/AnsiEsc.vim b/src/ansiesc/autoload/AnsiEsc.vim similarity index 100% rename from ansiesc/autoload/AnsiEsc.vim rename to src/ansiesc/autoload/AnsiEsc.vim diff --git a/ansiesc/plugin/AnsiEscPlugin.vim b/src/ansiesc/plugin/AnsiEscPlugin.vim similarity index 100% rename from ansiesc/plugin/AnsiEscPlugin.vim rename to src/ansiesc/plugin/AnsiEscPlugin.vim diff --git a/ansiesc/plugin/cecutil.vim b/src/ansiesc/plugin/cecutil.vim similarity index 100% rename from ansiesc/plugin/cecutil.vim rename to src/ansiesc/plugin/cecutil.vim diff --git a/less.vim b/src/less.vim similarity index 100% rename from less.vim rename to src/less.vim diff --git a/patches/ansiesc-add-support-for-x1b-1-39m-bold.patch b/src/patches/ansiesc-add-support-for-x1b-1-39m-bold.patch similarity index 100% rename from patches/ansiesc-add-support-for-x1b-1-39m-bold.patch rename to src/patches/ansiesc-add-support-for-x1b-1-39m-bold.patch diff --git a/patches/ansiesc-fix-bg-bleed-in-git-diff-for-whitespace-errors.patch b/src/patches/ansiesc-fix-bg-bleed-in-git-diff-for-whitespace-errors.patch similarity index 100% rename from patches/ansiesc-fix-bg-bleed-in-git-diff-for-whitespace-errors.patch rename to src/patches/ansiesc-fix-bg-bleed-in-git-diff-for-whitespace-errors.patch diff --git a/perldoc.vim b/src/perldoc.vim similarity index 100% rename from perldoc.vim rename to src/perldoc.vim diff --git a/prototypes/bitwise.awk b/src/prototypes/bitwise.awk similarity index 100% rename from prototypes/bitwise.awk rename to src/prototypes/bitwise.awk diff --git a/prototypes/debian_mawk_bug.sh b/src/prototypes/debian_mawk_bug.sh similarity index 100% rename from prototypes/debian_mawk_bug.sh rename to src/prototypes/debian_mawk_bug.sh diff --git a/prototypes/gen_awk_uudecode_lookup.py b/src/prototypes/gen_awk_uudecode_lookup.py similarity index 100% rename from prototypes/gen_awk_uudecode_lookup.py rename to src/prototypes/gen_awk_uudecode_lookup.py diff --git a/prototypes/gen_awk_uudecode_lookup_v1.py b/src/prototypes/gen_awk_uudecode_lookup_v1.py similarity index 100% rename from prototypes/gen_awk_uudecode_lookup_v1.py rename to src/prototypes/gen_awk_uudecode_lookup_v1.py diff --git a/src/prototypes/gen_awk_uuencode_lookup.py b/src/prototypes/gen_awk_uuencode_lookup.py new file mode 100755 index 0000000..1c6d17b --- /dev/null +++ b/src/prototypes/gen_awk_uuencode_lookup.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +# Generate lookup tables code to be placed in BEGIN for an awk lookup table +# based uuencode utility. +# +# Copyright (c) 2015, Rafael Kitover +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from sys import stdout, stderr +from collections import defaultdict +import string + +def escape(s): + s = s.replace('\\', '\\\\').replace('"', '\\"') + for c in s: + if c not in string.printable or c.isspace(): + s = s.replace(c, '\\%03d' % (int(oct(ord(c))))) + return s + +left = {} +right = {} + +for c1 in range(0, 256): + for c2 in range(0, 256): + left[ chr(c1) + chr(c2)] = chr((c1 >> 2) + 32) + chr(((((c1 & 0b11) << 6) | (c2 >> 2)) >> 2) + 32) + right[chr(c1) + chr(c2)] = chr(((((c1 & 0xF) << 2) & 0b111111) | ((c2 >> 6))) + 32) + chr((c2 & 0b111111) + 32) + +lookup = defaultdict(list) + +for lr, s, v in [("l", k, v) for k, v in left.items()] + [("r", k, v) for k, v in right.items()]: + lookup[v].append('%s["%s"]' % (lr, escape(s))) + +print """\ +#!/bin/sh + +if command -v gawk >/dev/null; then + awk=gawk +elif command -v nawk >/dev/null; then + awk=nawk +elif command -v mawk >/dev/null; then + awk=mawk +elif [ -x /usr/xpg4/bin/awk ]; then + awk=/usr/xpg4/bin/awk +elif command -v awk >/dev/null; then + awk=awk +else + echo "No awk found!" >&2 + exit 1 +fi + +mkdir /tmp/awk_uuencode_$$ +chmod 0700 /tmp/awk_uuencode_$$ + +trap 'rm -rf /tmp/awk_uuencode_'$$ HUP INT QUIT ILL TRAP KILL BUS TERM + +cat <<'EOF' > /tmp/awk_uuencode_$$/uuencode.awk +BEGIN {\ +""" + +for v, slots in lookup.iteritems(): + stdout.write("=".join(slots + ['"%s";\n' % (escape(v))])) + +print """\ + +exit +} +EOF + +$awk -f /tmp/awk_uuencode_$$/uuencode.awk + +rm -rf /tmp/awk_uuencode_$$ +""" diff --git a/prototypes/less.vim.uu b/src/prototypes/less.vim.uu similarity index 100% rename from prototypes/less.vim.uu rename to src/prototypes/less.vim.uu diff --git a/prototypes/uudecode.awk b/src/prototypes/uudecode.awk similarity index 100% rename from prototypes/uudecode.awk rename to src/prototypes/uudecode.awk diff --git a/prototypes/uudecode.pl b/src/prototypes/uudecode.pl similarity index 100% rename from prototypes/uudecode.pl rename to src/prototypes/uudecode.pl diff --git a/prototypes/uudecode.rb b/src/prototypes/uudecode.rb similarity index 100% rename from prototypes/uudecode.rb rename to src/prototypes/uudecode.rb diff --git a/prototypes/uudecode.sh b/src/prototypes/uudecode.sh similarity index 100% rename from prototypes/uudecode.sh rename to src/prototypes/uudecode.sh diff --git a/prototypes/uudecode_gawk.awk b/src/prototypes/uudecode_gawk.awk similarity index 100% rename from prototypes/uudecode_gawk.awk rename to src/prototypes/uudecode_gawk.awk diff --git a/prototypes/uudecode_no_unpack.pl b/src/prototypes/uudecode_no_unpack.pl similarity index 100% rename from prototypes/uudecode_no_unpack.pl rename to src/prototypes/uudecode_no_unpack.pl diff --git a/prototypes/uudecode_slow.awk b/src/prototypes/uudecode_slow.awk similarity index 100% rename from prototypes/uudecode_slow.awk rename to src/prototypes/uudecode_slow.awk diff --git a/vimpager b/vimpager index d446a1b..8e75414 100755 --- a/vimpager +++ b/vimpager @@ -498,8 +498,8 @@ extract_bundled_scripts() { if [ -n "${use_ansiesc}" ]; then ansiesc_tar - mkdir "${tmp}/extra_vim_home/plugin" 2>/dev/null - cd "${tmp}/extra_vim_home/plugin" + mkdir "${tmp}/extra_vim_home/autoload" 2>/dev/null + cd "${tmp}/extra_vim_home/autoload" conceal_retab_vim @@ -519,7 +519,7 @@ vim_less() { extract_bundled_scripts if [ -n "${use_ansiesc}" ]; then - ansi_command="if exists(':AnsiEsc') | exe 'autocmd VimEnter * :AnsiEsc' | exe 'autocmd VimEnter * :set buftype=nofile modifiable noreadonly' | exe 'autocmd VimEnter * :ConcealRetab' | endif" + ansi_command="if exists(':AnsiEsc') | exe 'autocmd VimEnter * :AnsiEsc' | exe 'autocmd VimEnter * :set buftype=nofile modifiable noreadonly' | exe 'autocmd VimEnter * :call ConcealRetab#ConcealRetab()' | endif" else ansi_command='silent! echo' fi @@ -4315,27 +4315,27 @@ conceal_retab_vim() { (cat <<'EOF') | do_uudecode > ConcealRetab.vim begin 644 ConcealRetab.vim M8V]M;6%N9"$@+6YA6YC;VYC96%L960H;#IL;G5M+"!L.FQI -M;F5P;W,I"@H@("`@("`@("`@("`@("`@:68@;#IC;VYC96%L961;,%T@/3TC -M(#`@?'P@;#IC;VYC96%L961;,5T@(3TC("