3 Commits

3 changed files with 29 additions and 10 deletions

View File

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

View File

@@ -5,7 +5,9 @@ import (
"flag"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"slices"
"github.com/fatih/color"
@@ -101,7 +103,24 @@ func main() {
os.Exit(2)
} else {
if fileStat.Mode().IsDir() {
fmt.Printf("%s: %s: Is a directory\n", os.Args[0], inputFilename)
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)
}
} else {
var nullCharPresent bool
if nullCharPresent, err = fileContainsNullChar(inputFilename); nullCharPresent {

View File

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