filtress/main.go

77 lines
1.4 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"tildegit.org/sloum/filtress/parser"
)
type point struct {
x int
y int
maxX int
maxY int
}
type filter struct {
max int
min int
val int
}
type filterState struct {
red filter
green filter
blue filter
alpha filter
location point
mode filter
}
var variables = map[string]int{}
func openFileFromPath(path string) *os.File {
file, err := os.Open(path)
if err != nil {
panic(err)
}
return file
}
func main() {
// Handle checking filter file argument
flag.Parse()
posArgs := flag.Args()
if len(posArgs) > 1 || len(posArgs) < 1 {
panic(fmt.Sprintf("Input error: Too many positional arguments. Expected one, received %d", len(flag.Args())))
}
fpath := posArgs[0]
fext := strings.ToUpper(filepath.Ext(fpath))
_, fname := filepath.Split(fpath)
if fext != ".FRS" {
panic(fmt.Sprintf("Input error: Incorrect filetype. Expected .FRS, received \".%s\"", fext))
}
// Open file and parse
fmt.Println("Filtress v0.2.0")
filterFile := openFileFromPath(fpath)
parser := parser.NewParser(filterFile)
fmt.Printf("Parsing file: %s ...\n", fname)
tree := parser.Parse()
if len(tree.Loops) > 0 {
fmt.Printf("File has %d procedures\n", len(tree.Loops))
fmt.Println("File is valid")
} else {
fmt.Println("Invalid input file")
}
fmt.Print(tree)
fmt.Println()
}