Skip to content

Commit

Permalink
using package flags (for future flags), codec name case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
squeeze69 committed Jun 17, 2021
1 parent d2e4ee8 commit 8a795c2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions vcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,50 @@ package main

import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"

"golang.org/x/image/riff"
)

var exitValue = 0

func main() {
if len(os.Args) < 3 {
fmt.Print("Usage: vcodec riff_file codec1 codec2 ...\ncodec name case DO matter\n")
flag.Parse()
if len(flag.Args()) < 2 {
fmt.Print("Usage: vcodec riff_file codec1 codec2 ...\ncodec name is case insensitive\n")
os.Exit(2)
}
//A little trick to handle the "panic", os.Exit doesn't call deferred functions
main2()
fmt.Printf("Exitvalue: %d\n", exitValue)
fmt.Printf("Exit Value: %d\n", exitValue)
os.Exit(exitValue)
}

func main2() {
f, err := os.Open(os.Args[1])
f, err := os.Open(flag.Arg(0))
if err != nil {
log.Fatal(err)
}
defer f.Close()
defer func() {
if r := recover(); r != nil {
fmt.Printf("Codec: %s\n", r)
for _, v := range os.Args[2:] {
if r == v {
codec := fmt.Sprintf("%s", r)
for _, v := range flag.Args()[1:] {
if strings.EqualFold(codec, v) {
exitValue = 1
break
}
}
}
}()
formType, r, err := riff.NewReader(bufio.NewReader(io.LimitReader(f, 16384)))
formType, r, err := riff.NewReader(bufio.NewReader(io.LimitReader(f, 8192)))
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 8a795c2

Please sign in to comment.