12b678704Santon#!/bin/sh 22b678704Santon# 3*f45a9042Sjasper# $OpenBSD: filec.sh,v 1.7 2021/09/02 07:14:15 jasper Exp $ 45ed25df9Santon# 52b678704Santon# Copyright (c) 2017 Anton Lindqvist <anton@openbsd.org> 62b678704Santon# 72b678704Santon# Permission to use, copy, modify, and distribute this software for any 82b678704Santon# purpose with or without fee is hereby granted, provided that the above 92b678704Santon# copyright notice and this permission notice appear in all copies. 102b678704Santon# 112b678704Santon# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 122b678704Santon# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 132b678704Santon# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 142b678704Santon# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 152b678704Santon# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 162b678704Santon# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 172b678704Santon# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 182b678704Santon 192b678704Santontestseq() { 202b678704Santon stdin=$1 212b678704Santon exp=$(echo "$2") 2292960836Santon act=$(echo -n "$stdin" | ./edit -p "$PS1" $CSH) 2390e71d7fSanton [ $? = 0 ] && [ "$exp" = "$act" ] && return 0 242b678704Santon 252b678704Santon echo input: 262b678704Santon echo ">>>${stdin}<<<" 27cd87b141Santon echo -n "$stdin" | hexdump -Cv 282b678704Santon echo expected: 292b678704Santon echo ">>>${exp}<<<" 30cd87b141Santon echo -n "$exp" | hexdump -Cv 312b678704Santon echo actual: 322b678704Santon echo ">>>${act}<<<" 33cd87b141Santon echo -n "$act" | hexdump -Cv 342b678704Santon 3590e71d7fSanton exit 1 362b678704Santon} 372b678704Santon 3892960836SantonCSH=${1:-/bin/csh} 3990e71d7fSantonPS1='? ' 4090e71d7fSanton 412b678704Santon# Create a fake HOME with a minimal .cshrc and a few files used for completion. 422b678704Santontmp=$(mktemp -d) 432b678704Santontrap 'rm -r $tmp' 0 44cd87b141Santontouch $tmp/ambiguous.{1,2} $tmp/complete $tmp/ignore.{c,o} $tmp/only.o 45cd87b141Santoncat >$tmp/.cshrc <<! 462b678704Santonset filec 47cd87b141Santonset fignore = (.o) 4890e71d7fSantonset prompt = "$PS1" 492b678704Santoncd ~ 502b678704Santon! 512b678704Santon 522b678704SantonHOME=$tmp 53*f45a9042Sjasperexport HOME 542b678704Santon 552b678704Santon# NL: Execute command. 5690e71d7fSantontestseq "echo a\n" "? echo a\r\na\r\n? " 5790e71d7fSantontestseq "echo \0001\n" "? echo ^A\r\n\0001\r\n? " 582b678704Santon 592b678704Santon# VEOF: List all completions or exit. 6090e71d7fSantontestseq "a\0004" "? a^D\r\nambiguous.1 ambiguous.2 \r\r\n? a" 6190e71d7fSantontestseq "ignore\0004" "? ignore^D\r\nignore.c ignore.o \r\r\n? ignore" 622b678704Santontestseq "set ignoreeof\n\0004" \ 6390e71d7fSanton "? set ignoreeof\r\n? ^D\r\nUse \"exit\" to leave csh.\r\n? " 64cd87b141Santontestseq "set ignoreeof\na\0004" \ 6590e71d7fSanton "? set ignoreeof\r\n? a^D\r\nambiguous.1 ambiguous.2 \r\r\n? a" 662b678704Santon 672b678704Santon# VEOL: File name completion. 6890e71d7fSantontestseq "\0033" "? \0007" 6990e71d7fSantontestseq "c\0033" "? complete" 7090e71d7fSantontestseq "a\0033" "? a\0007mbiguous." 7190e71d7fSantontestseq "~${USER}\0033" "? ~${USER}" 7290e71d7fSantontestseq "ignore\0033" "? ignore.c" 7390e71d7fSantontestseq "only\0033" "? only.o" 742b678704Santon 752b678704Santon# VERASE: Delete character. 7690e71d7fSantontestseq "\0177" "? " 7790e71d7fSantontestseq "ab\0177\0177\0177" "? ab\b \b\b \b" 7890e71d7fSantontestseq "a\0002\0177" "? a^B\b\b \b\b" 7990e71d7fSantontestseq "\0001\0002\0177" "? ^A^B\b\b \b\b" 8090e71d7fSantontestseq "\t\0177" "? \b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b" 812b678704Santon 822b678704Santon# VINTR: Abort line. 8390e71d7fSantontestseq "\0003" "? ^C\r\n? " 8490e71d7fSantontestseq "ab\0003" "? ab^C\r\n? " 8590e71d7fSantontestseq "foreach i ()\n\0003" "? foreach i ()\r\n? ^C\r\r\n? " 862b678704Santon 872b678704Santon# VKILL: Kill line. 8890e71d7fSantontestseq "\0025" "? " 8990e71d7fSantontestseq "ab\0025" "? ab\b\b \b\b" 902b678704Santon 912b678704Santon# VLNEXT: Insert literal. 9290e71d7fSantontestseq "\0026\0007" "? ^G" 9390e71d7fSantontestseq "\0026\0033" "? ^[" 9490e71d7fSantontestseq "echo \0026\0001a\n" "? echo ^Aa\r\n\0001a\r\n? " 952b678704Santon 962b678704Santon# VREPRINT: Reprint line. 9790e71d7fSantontestseq "ab\0022" "? ab^R\r\nab" 982b678704Santon 992b678704Santon# XXX VSTATUS: Send TIOCSTAT. 1002b678704Santon 1012b678704Santon# VWERASE: Delete word. 10290e71d7fSantontestseq "\0027" "? " 10390e71d7fSantontestseq "ab\0027" "? ab\b\b \b\b" 10490e71d7fSantontestseq "ab cd\0027\0027" "? ab cd\b\b \b\b\b\b\b \b\b\b" 1052b678704Santon 1062b678704Santon# VWERASE: Delete word using altwerase. 10790e71d7fSantontestseq "stty altwerase\n\0027" "? stty altwerase\r\n? " 10890e71d7fSantontestseq "stty altwerase\nab\0027" "? stty altwerase\r\n? ab\b\b \b\b" 1092b678704Santontestseq "stty altwerase\nab/cd\0027\0027" \ 11090e71d7fSanton "? stty altwerase\r\n? ab/cd\b\b \b\b\b\b\b \b\b\b" 111