Skip to content

Commit

Permalink
changed to suncommand pnml
Browse files Browse the repository at this point in the history
to avoid overwriting input file
when option -o is not used
  • Loading branch information
dalzilio committed Jan 27, 2020
1 parent d5e04ca commit b6ea045
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cmd/pnml.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ func pnmlConvert(filename string) {
return
}

// compute name of the output file. There are three possible cases
// compute name of the output file. There are three possible cases. We try
// to avoid overwriting over the input file by adding suffix -PT when not
// using option -o.
_, file := filepath.Split(filename)
outfile := pnmlOutFileName
if outfile == "" {
outfile = file[0 : len(file)-len(".pnml")]
outfile = file[0:len(file)-len(".pnml")] + "-PT"
}
if pnmlUseName {
outfile = p.Name
Expand All @@ -111,7 +113,7 @@ func pnmlConvert(filename string) {
} else {
out, err = os.Create(outfile + ".pnml")
if err != nil {
hlnetLogger.Println("Error creating result file: ", err, " (you may be trying to overwrite your input file!)")
hlnetLogger.Println("Error creating result file: ", err)
os.Exit(1)
return
}
Expand Down
2 changes: 1 addition & 1 deletion corenet/pnmlwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
DOCTYPE = `<?xml version="1.0" encoding="UTF-8"?>` + "\n"
)

// wpnml is the type of PNML for a P/T net ithout graphical information
// wpnml is the type of PNML for a P/T net without graphical information
type wpnml struct {
XMLName xml.Name `xml:"http://www.pnml.org/version-2009/grammar/pnml pnml"`
WNET wnet `xml:"net"`
Expand Down

0 comments on commit b6ea045

Please sign in to comment.