Если не указан целевой файл - то вывод в stdout

Этот коммит содержится в:
Softonik 2022-11-19 21:42:54 +03:00 коммит произвёл Nikolay Kopitonenko
родитель 0cb0897021
коммит 5df60345e4

Просмотреть файл

@ -35,7 +35,7 @@ func getFlags() (int, string, string) {
} }
func checkFlagsAreValid(source, target string) { func checkFlagsAreValid(source, target string) {
if source == "" || target == "" { if source == "" {
printUsage() printUsage()
os.Exit(1) os.Exit(1)
} }
@ -58,12 +58,16 @@ func safeTranspile(mode int, source, target string) {
os.Exit(1) os.Exit(1)
} }
defer in.Close() defer in.Close()
// Create the Arduino sketch file.
os.Remove(target) out := os.Stdout
out, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR|os.O_SYNC, 0666) if target != "" {
if err != nil { // Create the Arduino sketch file.
fmt.Fprintf(os.Stderr, "Arduino sketch file [%s] could not be opened! %v", target, err) os.Remove(target)
os.Exit(1) out, err = os.OpenFile(target, os.O_CREATE|os.O_RDWR|os.O_SYNC, 0666)
if err != nil {
fmt.Fprintf(os.Stderr, "Arduino sketch file [%s] could not be opened! %v", target, err)
os.Exit(1)
}
} }
switch mode { switch mode {
case CPP_MODE: case CPP_MODE: