Documentation ¶
Overview ¶
Package filekind contains types for dealing with the various 'kinds' of file present in a subject.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadKind = errors.New("unknown kind")
ErrBadKind occurs if we try to convert a kind from a string that doesn't match any known kind string.
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind uint8
Kind is the bitflag enumeration of file kinds.
const ( // Other states that the kind of this file doesn't fit in any of the above categorisations. Other Kind = 1 << iota // Litmus states that this file is a litmus test. Litmus // Bin states that this file is a binary. Bin // Log states that this file is a compile log. Log // Trace states that this file is a fuzzer trace. Trace // CSrc states that this file is C source code (.c). CSrc // CHeader states that this file is a C header (.h). CHeader // C is shorthand for CSrc|CHeader. C = CSrc | CHeader // Any is a suggestive alias for both Loc and Kind saturation. Any = math.MaxUint8 )
func GuessFromFile ¶
GuessFromFile tries to guess the kind of the file whose filepath is path. It does so only from the file extension.
Example ¶
ExampleGuessFromFile is a runnable example for GuessFromFile.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/filekind" ) func main() { fmt.Println(filekind.GuessFromFile("foo.litmus.c") == filekind.CSrc) fmt.Println(filekind.GuessFromFile("stdio.h") == filekind.CHeader) fmt.Println(filekind.GuessFromFile("foo.litmus") == filekind.Litmus) fmt.Println(filekind.GuessFromFile("foo.litmus.c") == filekind.Litmus) }
Output: true true true false
func KindFromString ¶
KindFromString tries to map str to a filekind.
func KindFromStrings ¶
KindFromStrings returns the union of the kinds corresponding to each string in strs.
Example ¶
ExampleKindFromStrings is a runnable example for KindFromStrings.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/filekind" ) func main() { k, err := filekind.KindFromStrings("other", "c") if err != nil { fmt.Println("ERROR:", err) } else { fmt.Println(k.String()) } }
Output: other|c
func (Kind) ArchivePerm ¶
ArchivePerm gets the idealised Unix permission set for archiving a file of this kind.
func (Kind) FilterFiles ¶
FilterFiles filters fpaths to paths whose guess matches this kind.
Example ¶
ExampleKind_FilterFiles is a runnable example for FilterFiles.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/filekind" ) func main() { for _, f := range filekind.C.FilterFiles([]string{ "barbaz.trace", "foo.c", "foo.h", "baz.sh", "a.out", "bar.c.litmus", "bar.c", }) { fmt.Println(f) } }
Output: foo.c foo.h bar.c
func (Kind) MarshalJSON ¶
MarshalJSON marshals a filekind to JSON using its string-list form.
func (Kind) Strings ¶
Strings produces a stringified representation of each flag enabled in this filekind.
Example ¶
ExampleKind_Strings is a runnable example for Strings.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/filekind" ) func main() { for _, s := range (filekind.C | filekind.Litmus | filekind.Trace).Strings() { fmt.Println(s) } }
Output: c litmus trace
func (*Kind) UnmarshalJSON ¶
UnmarshalJSON unmarshals an op from JSON using its string-list form.