modernc.org/knuth@v0.0.4/cmd/govptovf/main.go (about) 1 // Copyright 2023 The Knuth Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Command govftovp is the VPtoVF program by D. E. Knuth, transpiled to Go. 6 // 7 // http://mirrors.ctan.org/systems/knuth/dist/etc/vptovf.web 8 // 9 // For more details about the original Pascal program and its usage please see 10 // the modernc.org/knuth/vftovp package. 11 package main // modernc.org/knuth/cmd/govptovf 12 13 import ( 14 "flag" 15 "fmt" 16 "os" 17 18 "modernc.org/knuth/vptovf" 19 ) 20 21 func fail(rc int, s string, args ...interface{}) { 22 fmt.Fprintf(os.Stderr, s, args...) 23 os.Exit(rc) 24 } 25 26 // program VPtoVF( vpl_file, vf_file, tfm_file, output, stderr); 27 // vpl_file:text; 28 // vf_file:packed file of 0..255; 29 // tfm_file:packed file of 0..255; 30 func main() { 31 flag.Parse() 32 nArg := flag.NArg() 33 if nArg != 3 { 34 fail(2, "expected 3 arguments: vpl_file vf_file tfm_file\n") 35 } 36 37 vplFile, err := os.Open(flag.Arg(0)) 38 if err != nil { 39 fail(1, "%s\n", err) 40 } 41 42 defer vplFile.Close() 43 44 vfFile, err := os.Create(flag.Arg(1)) 45 if err != nil { 46 fail(1, "%s\n", err) 47 } 48 49 defer func() { 50 if err := vfFile.Close(); err != nil { 51 fail(1, "closing %s: %v", flag.Arg(1), err) 52 } 53 }() 54 55 tfmFile, err := os.Create(flag.Arg(2)) 56 if err != nil { 57 fail(1, "%s\n", err) 58 } 59 60 defer func() { 61 if err := tfmFile.Close(); err != nil { 62 fail(1, "closing %s: %v", flag.Arg(2), err) 63 } 64 }() 65 66 if err = vptovf.Main(vplFile, vfFile, tfmFile, os.Stdout, os.Stderr); err != nil { 67 fail(2, "FAIL: %s\n", err) 68 } 69 }