syntax parser: reintroduce header regex in .hdr files

Replacing header patterns with signature patterns was a mistake, since
both have their own uses. So restore support for header regex, while
keeping support for signature regex as well.
This commit is contained in:
Dmytro Maluka
2024-03-23 18:26:22 +01:00
parent 2b8d925925
commit 3f4942cedb
2 changed files with 24 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ type HeaderYaml struct {
FileType string `yaml:"filetype"`
Detect struct {
FNameRgx string `yaml:"filename"`
HeaderRgx string `yaml:"header"`
SignatureRgx string `yaml:"signature"`
} `yaml:"detect"`
}
@@ -25,6 +26,7 @@ type HeaderYaml struct {
type Header struct {
FileType string
FNameRgx string
HeaderRgx string
SignatureRgx string
}
@@ -59,6 +61,7 @@ func encode(name string, c HeaderYaml) {
f, _ := os.Create(name + ".hdr")
f.WriteString(c.FileType + "\n")
f.WriteString(c.Detect.FNameRgx + "\n")
f.WriteString(c.Detect.HeaderRgx + "\n")
f.WriteString(c.Detect.SignatureRgx + "\n")
f.Close()
}
@@ -70,7 +73,8 @@ func decode(name string) Header {
var hdr Header
hdr.FileType = string(strs[0])
hdr.FNameRgx = string(strs[1])
hdr.SignatureRgx = string(strs[2])
hdr.HeaderRgx = string(strs[2])
hdr.SignatureRgx = string(strs[3])
fmt.Printf("took %v\n", time.Since(start))
return hdr