llcppsigfetch:use fmt to log because linux nil defer of log
This commit is contained in:
@@ -19,7 +19,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -43,7 +42,6 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ags.Verbose {
|
if ags.Verbose {
|
||||||
log.SetFlags(0)
|
|
||||||
parse.SetDebug(parse.DbgFlagAll)
|
parse.SetDebug(parse.DbgFlagAll)
|
||||||
}
|
}
|
||||||
extract := false
|
extract := false
|
||||||
@@ -63,7 +61,7 @@ func main() {
|
|||||||
extractFile = remainArgs[i+1]
|
extractFile = remainArgs[i+1]
|
||||||
i++
|
i++
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Error: --extract requires a valid file argument")
|
fmt.Fprintln(os.Stderr, "Error: --extract requires a valid file argument")
|
||||||
printUsage()
|
printUsage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@@ -80,18 +78,18 @@ func main() {
|
|||||||
|
|
||||||
if extract {
|
if extract {
|
||||||
if ags.Verbose {
|
if ags.Verbose {
|
||||||
log.Println("runExtract: extractFile:", extractFile)
|
fmt.Fprintln(os.Stderr, "runExtract: extractFile:", extractFile)
|
||||||
log.Println("isTemp:", isTemp)
|
fmt.Fprintln(os.Stderr, "isTemp:", isTemp)
|
||||||
log.Println("isCpp:", isCpp)
|
fmt.Fprintln(os.Stderr, "isCpp:", isCpp)
|
||||||
log.Println("out:", out)
|
fmt.Fprintln(os.Stderr, "out:", out)
|
||||||
log.Println("otherArgs:", otherArgs)
|
fmt.Fprintln(os.Stderr, "otherArgs:", otherArgs)
|
||||||
}
|
}
|
||||||
runExtract(extractFile, isTemp, isCpp, out, otherArgs, ags.Verbose)
|
runExtract(extractFile, isTemp, isCpp, out, otherArgs, ags.Verbose)
|
||||||
} else {
|
} else {
|
||||||
if ags.Verbose {
|
if ags.Verbose {
|
||||||
log.Println("runFromConfig: config file:", ags.CfgFile)
|
fmt.Fprintln(os.Stderr, "runFromConfig: config file:", ags.CfgFile)
|
||||||
log.Println("use stdin:", ags.UseStdin)
|
fmt.Fprintln(os.Stderr, "use stdin:", ags.UseStdin)
|
||||||
log.Println("output to file:", out)
|
fmt.Fprintln(os.Stderr, "output to file:", out)
|
||||||
}
|
}
|
||||||
runFromConfig(ags.CfgFile, ags.UseStdin, out, ags.Verbose)
|
runFromConfig(ags.CfgFile, ags.UseStdin, out, ags.Verbose)
|
||||||
}
|
}
|
||||||
@@ -136,9 +134,9 @@ func runFromConfig(cfgFile string, useStdin bool, outputToFile bool, verbose boo
|
|||||||
}
|
}
|
||||||
if verbose {
|
if verbose {
|
||||||
if useStdin {
|
if useStdin {
|
||||||
log.Println("runFromConfig: read from stdin")
|
fmt.Fprintln(os.Stderr, "runFromConfig: read from stdin")
|
||||||
} else {
|
} else {
|
||||||
log.Println("runFromConfig: read from file", cfgFile)
|
fmt.Fprintln(os.Stderr, "runFromConfig: read from file", cfgFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check(err)
|
check(err)
|
||||||
@@ -148,7 +146,7 @@ func runFromConfig(cfgFile string, useStdin bool, outputToFile bool, verbose boo
|
|||||||
defer conf.Delete()
|
defer conf.Delete()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to parse config file:", cfgFile)
|
fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,9 +156,9 @@ func runFromConfig(cfgFile string, useStdin bool, outputToFile bool, verbose boo
|
|||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Println("runFromConfig: header file paths", files)
|
fmt.Fprintln(os.Stderr, "runFromConfig: header file paths", files)
|
||||||
if len(notFounds) > 0 {
|
if len(notFounds) > 0 {
|
||||||
log.Println("runFromConfig: not found header files", notFounds)
|
fmt.Fprintln(os.Stderr, "runFromConfig: not found header files", notFounds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +202,7 @@ func outputResult(result *c.Char, outputToFile bool) {
|
|||||||
fmt.Fprintf(os.Stderr, "Error writing to output file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error writing to output file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Printf("Results saved to %s\n", outputFile)
|
fmt.Fprintf(os.Stderr, "Results saved to %s\n", outputFile)
|
||||||
} else {
|
} else {
|
||||||
c.Printf(result)
|
c.Printf(result)
|
||||||
}
|
}
|
||||||
@@ -263,12 +261,12 @@ func outputInfo(context *parse.Context, outputToFile bool) {
|
|||||||
func parseBoolArg(arg, name string, defaultValue bool) bool {
|
func parseBoolArg(arg, name string, defaultValue bool) bool {
|
||||||
parts := strings.SplitN(arg, "=", 2)
|
parts := strings.SplitN(arg, "=", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
fmt.Printf("Warning: Invalid -%s= argument, defaulting to %v\n", name, defaultValue)
|
fmt.Fprintf(os.Stderr, "Warning: Invalid -%s= argument, defaulting to %v\n", name, defaultValue)
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
value, err := strconv.ParseBool(parts[1])
|
value, err := strconv.ParseBool(parts[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Warning: Invalid -%s= value '%s', defaulting to %v\n", name, parts[1], defaultValue)
|
fmt.Fprintf(os.Stderr, "Warning: Invalid -%s= value '%s', defaulting to %v\n", name, parts[1], defaultValue)
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package parse
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -67,11 +66,11 @@ type Config struct {
|
|||||||
|
|
||||||
func NewConverter(config *clangutils.Config) (*Converter, error) {
|
func NewConverter(config *clangutils.Config) (*Converter, error) {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
log.Println("NewConverter: config")
|
fmt.Fprintln(os.Stderr, "NewConverter: config")
|
||||||
log.Println("config.File", config.File)
|
fmt.Fprintln(os.Stderr, "config.File", config.File)
|
||||||
log.Println("config.Args", config.Args)
|
fmt.Fprintln(os.Stderr, "config.Args", config.Args)
|
||||||
log.Println("config.IsCpp", config.IsCpp)
|
fmt.Fprintln(os.Stderr, "config.IsCpp", config.IsCpp)
|
||||||
log.Println("config.Temp", config.Temp)
|
fmt.Fprintln(os.Stderr, "config.Temp", config.Temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
index, unit, err := clangutils.CreateTranslationUnit(config)
|
index, unit, err := clangutils.CreateTranslationUnit(config)
|
||||||
@@ -130,16 +129,16 @@ func (ct *Converter) decIndent() {
|
|||||||
|
|
||||||
func (ct *Converter) logf(format string, args ...interface{}) {
|
func (ct *Converter) logf(format string, args ...interface{}) {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
log.Printf(ct.logBase()+format, args...)
|
fmt.Fprintf(os.Stderr, ct.logBase()+format, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (ct *Converter) logln(args ...interface{}) {
|
func (ct *Converter) logln(args ...interface{}) {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
firstArg := fmt.Sprintf("%s%v", ct.logBase(), args[0])
|
firstArg := fmt.Sprintf("%s%v", ct.logBase(), args[0])
|
||||||
log.Println(append([]interface{}{firstArg}, args[1:]...)...)
|
fmt.Fprintln(os.Stderr, append([]interface{}{firstArg}, args[1:]...)...)
|
||||||
} else {
|
} else {
|
||||||
log.Println(ct.logBase())
|
fmt.Fprintln(os.Stderr, ct.logBase())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package parse
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/goplus/llgo/c/cjson"
|
"github.com/goplus/llgo/c/cjson"
|
||||||
"github.com/goplus/llgo/chore/_xtool/llcppsymg/clangutils"
|
"github.com/goplus/llgo/chore/_xtool/llcppsymg/clangutils"
|
||||||
@@ -42,7 +43,7 @@ func (p *Context) Output() *cjson.JSON {
|
|||||||
// ProcessFiles processes the given files and adds them to the context
|
// ProcessFiles processes the given files and adds them to the context
|
||||||
func (p *Context) ProcessFiles(files []string) error {
|
func (p *Context) ProcessFiles(files []string) error {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
log.Println("ProcessFiles: files", files, "isCpp", p.IsCpp)
|
fmt.Fprintln(os.Stderr, "ProcessFiles: files", files, "isCpp", p.IsCpp)
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if err := p.processFile(file); err != nil {
|
if err := p.processFile(file); err != nil {
|
||||||
@@ -55,12 +56,12 @@ func (p *Context) ProcessFiles(files []string) error {
|
|||||||
// parse file and add it to the context,avoid duplicate parsing
|
// parse file and add it to the context,avoid duplicate parsing
|
||||||
func (p *Context) processFile(path string) error {
|
func (p *Context) processFile(path string) error {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
log.Println("processFile: path", path)
|
fmt.Fprintln(os.Stderr, "processFile: path", path)
|
||||||
}
|
}
|
||||||
for _, entry := range p.Files {
|
for _, entry := range p.Files {
|
||||||
if entry.Path == path {
|
if entry.Path == path {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
log.Println("processFile: already parsed", path)
|
fmt.Fprintln(os.Stderr, "processFile: already parsed", path)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -76,7 +77,7 @@ func (p *Context) processFile(path string) error {
|
|||||||
|
|
||||||
func (p *Context) parseFile(path string) ([]*FileEntry, error) {
|
func (p *Context) parseFile(path string) ([]*FileEntry, error) {
|
||||||
if debugParse {
|
if debugParse {
|
||||||
log.Println("parseFile: path", path)
|
fmt.Fprintln(os.Stderr, "parseFile: path", path)
|
||||||
}
|
}
|
||||||
converter, err := NewConverter(&clangutils.Config{
|
converter, err := NewConverter(&clangutils.Config{
|
||||||
File: path,
|
File: path,
|
||||||
|
|||||||
Reference in New Issue
Block a user