modernc.org/knuth@v0.0.4/mft/api.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 //go:generate make generate 6 7 // Package mft is the MFT program by D. E. Knuth, transpiled to Go. 8 // 9 // http://mirrors.ctan.org/systems/knuth/dist/mfware/mft.web 10 package mft // modernc.org/knuth/mft 11 12 import ( 13 "fmt" 14 "io" 15 "runtime/debug" 16 17 "modernc.org/knuth" 18 ) 19 20 // program MFT( mf_file, change_file, style_file, tex_file, output); 21 // mf_file:text_file; {primary input} 22 // change_file:text_file; {updates} 23 // style_file:text_file; {formatting bootstrap} 24 // tex_file: text_file; 25 26 // Main executes the mft program using the supplied arguments. 27 func Main(mfFile, changeFile, styleFile io.Reader, texFile, stdout, stderr io.Writer) (mainErr error) { 28 defer func() { 29 switch x := recover().(type) { 30 case nil: 31 // ok 32 case signal: 33 switch { 34 case mainErr == nil: 35 mainErr = fmt.Errorf("aborted") 36 default: 37 mainErr = fmt.Errorf("aborted: %v", mainErr) 38 } 39 case knuth.Error: 40 mainErr = x 41 default: 42 mainErr = fmt.Errorf("PANIC %T: %[1]v, error: %v\n%s", x, mainErr, debug.Stack()) 43 } 44 }() 45 46 (&prg{ 47 mfFile: knuth.NewTextFile(mfFile, nil, nil), 48 changeFile: knuth.NewTextFile(changeFile, nil, nil), 49 styleFile: knuth.NewTextFile(styleFile, nil, nil), 50 texFile: knuth.NewTextFile(nil, texFile, nil), 51 stdout: knuth.NewTextFile(nil, stdout, nil), 52 stderr: knuth.NewTextFile(nil, stderr, nil), 53 }).main() 54 return nil 55 }