3 Commits

3 changed files with 29 additions and 10 deletions

View File

@@ -5,9 +5,13 @@ fmt:
go fmt ./... go fmt ./...
vet: fmt vet: fmt
go vet ./... go vet ./...
buildLib: vet buildLibUnopt: vet
go build -gcflags="all=-N -l" ./... go build -gcflags="all=-N -l" ./...
buildCmd: buildLib unopt: buildLibUnopt
go build -C kg/ -gcflags="all=-N -l" -o kg ./... go build -C kg/ -gcflags="all=-N -l" -o kg ./...
buildLib: vet
go build ./...
buildCmd: buildLib
go build -C kg/ -o kg ./...
test: buildCmd test: buildCmd
go test -v ./... go test -v ./...

View File

@@ -5,7 +5,9 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/fs"
"os" "os"
"path/filepath"
"slices" "slices"
"github.com/fatih/color" "github.com/fatih/color"
@@ -101,7 +103,24 @@ func main() {
os.Exit(2) os.Exit(2)
} else { } else {
if fileStat.Mode().IsDir() { if fileStat.Mode().IsDir() {
if *recursiveFlag {
// Walk the directory and open every file in it. Add each file to the filelist.
filepath.WalkDir(inputFilename, func(filename string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() {
f, err := os.Open(filename)
if err != nil {
return err
}
inputFiles = append(inputFiles, f)
}
return nil
})
} else {
fmt.Printf("%s: %s: Is a directory\n", os.Args[0], inputFilename) fmt.Printf("%s: %s: Is a directory\n", os.Args[0], inputFilename)
}
} else { } else {
var nullCharPresent bool var nullCharPresent bool
if nullCharPresent, err = fileContainsNullChar(inputFilename); nullCharPresent { if nullCharPresent, err = fileContainsNullChar(inputFilename); nullCharPresent {

View File

@@ -131,13 +131,9 @@ func newEscapedNode(c rune, inCharClass bool) (postfixNode, error) {
case 'v': // Vertical tab case 'v': // Vertical tab
toReturn.nodetype = characterNode toReturn.nodetype = characterNode
toReturn.contents = append(toReturn.contents, rune(11)) toReturn.contents = append(toReturn.contents, rune(11))
case '-': // Literal hyphen - only in character class case '-': // Literal hyphen
if inCharClass {
toReturn.nodetype = characterNode toReturn.nodetype = characterNode
toReturn.contents = append(toReturn.contents, '-') toReturn.contents = append(toReturn.contents, '-')
} else {
return postfixNode{}, fmt.Errorf("invalid escape character")
}
default: // None of the above - append it as a regular character default: // None of the above - append it as a regular character
if isNormalChar(c) { // Normal characters cannot be escaped if isNormalChar(c) { // Normal characters cannot be escaped
return postfixNode{}, fmt.Errorf("invalid escape character") return postfixNode{}, fmt.Errorf("invalid escape character")