modernc.org/knuth@v0.0.4/cmd/gogftopk/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 gogftopk is the GFtype program by Tomas Rokicki, transpiled to Go.
     6  //
     7  //	http://mirrors.ctan.org/systems/knuth/dist/mfware/gftopk.web
     8  
     9  // For more details about the original Pascal program and its usage please see
    10  // the modernc.org/knuth/gftype package.
    11  package main // modernc.org/knuth/cmd/gogftopk
    12  
    13  import (
    14  	"flag"
    15  	"fmt"
    16  	"os"
    17  
    18  	"modernc.org/knuth/gftopk"
    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 GFtoPK( gf_file, pk_file, output)
    27  // gf_file:byte_file; {the stuff we are \.[GFtoPK]ing}
    28  // pk_file:byte_file; {the stuff we have \.[GFtoPK]ed}
    29  
    30  // Main executes the gftype program using the supplied arguments.
    31  func main() {
    32  	flag.Parse()
    33  	nArg := flag.NArg()
    34  	if nArg != 2 {
    35  		fail(2, "expected 2 arguments: gf_file pk_file\n")
    36  	}
    37  
    38  	gfFile, err := os.Open(flag.Arg(0))
    39  	if err != nil {
    40  		fail(1, "%s\n", err)
    41  	}
    42  
    43  	defer gfFile.Close()
    44  
    45  	pkFile, err := os.Create(flag.Arg(1))
    46  	if err != nil {
    47  		fail(1, "creating pk_file: %v", err)
    48  	}
    49  
    50  	if err = gftopk.Main(gfFile, pkFile, os.Stdout, os.Stderr); err != nil {
    51  		fail(1, "FAIL: %s\n", err)
    52  	}
    53  }