diff --git a/AT5/Makefile b/AT5/Makefile index 02a7d6a..4969ccd 100644 --- a/AT5/Makefile +++ b/AT5/Makefile @@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go metadata: cmd/metadata/*.go go build -o $@ $^ -at5: cmd/at5/*.go - go build -o $@ $^ +at5: cmd/at5/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/AT5/cmd/at5/at5.go b/AT5/cmd/at5/at5.go index 6feb3fe..9f739f1 100644 --- a/AT5/cmd/at5/at5.go +++ b/AT5/cmd/at5/at5.go @@ -3,13 +3,14 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "encoding/xml" "fmt" "io" "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -46,7 +47,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/AT5/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -110,16 +111,3 @@ func main() { }() } } - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -} diff --git a/NOS/Makefile b/NOS/Makefile index f30d292..ec1328a 100644 --- a/NOS/Makefile +++ b/NOS/Makefile @@ -9,5 +9,5 @@ json2txt: cmd/json2txt/*.go ../internal/util/*.go metadata: cmd/metadata/*.go go build -o $@ $^ -nos: cmd/nos/*.go - go build -o $@ $^ +nos: cmd/nos/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/NOS/cmd/nos/nos.go b/NOS/cmd/nos/nos.go index 72291e4..903fc8a 100644 --- a/NOS/cmd/nos/nos.go +++ b/NOS/cmd/nos/nos.go @@ -3,6 +3,8 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "encoding/xml" "fmt" "html" @@ -10,7 +12,6 @@ import ( "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -62,7 +63,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/NOS/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -194,16 +195,3 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool p(os.Chtimes(filename+".json", timestamp, timestamp)) return true } - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -} diff --git a/NU/Makefile b/NU/Makefile index 2f5ecfa..15c40ae 100644 --- a/NU/Makefile +++ b/NU/Makefile @@ -5,5 +5,5 @@ all: \ metadata: cmd/metadata/*.go go build -o $@ $^ -nu: cmd/nu/*.go - go build -o $@ $^ +nu: cmd/nu/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/NU/cmd/nu/nu.go b/NU/cmd/nu/nu.go index a45001c..3ba3c8e 100644 --- a/NU/cmd/nu/nu.go +++ b/NU/cmd/nu/nu.go @@ -3,6 +3,8 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "bytes" "encoding/json" "encoding/xml" @@ -12,7 +14,6 @@ import ( "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -73,7 +74,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/NU/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -226,7 +227,7 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool // text bevat kopjes zonder punt aan het eind lines := strings.Split(text, "\n") for i, line := range lines { - line = fixSpace(line) + line = u.FixSpace(line) n := len(line) if n > 0 { if strings.ContainsAny(line[n-1:], ".!?") { @@ -249,7 +250,7 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool p(fmt.Fprintln(fp, "##META text tag =")) } else { for _, tag := range tags { - p(fmt.Fprintf(fp, "##META text tag = %s\n", fixSpace(tag))) + p(fmt.Fprintf(fp, "##META text tag = %s\n", u.FixSpace(tag))) } } p(fp.WriteString(text)) @@ -259,20 +260,3 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool return true } - -func fixSpace(s string) string { - return strings.Join(strings.Fields(s), " ") -} - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -} diff --git a/Oog/Makefile b/Oog/Makefile index 66f58fe..98a2808 100644 --- a/Oog/Makefile +++ b/Oog/Makefile @@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go metadata: cmd/metadata/*.go go build -o $@ $^ -oog: cmd/oog/*.go - go build -o $@ $^ +oog: cmd/oog/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/Oog/cmd/oog/oog.go b/Oog/cmd/oog/oog.go index dc07f7e..5d2ef4c 100644 --- a/Oog/cmd/oog/oog.go +++ b/Oog/cmd/oog/oog.go @@ -3,13 +3,14 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "encoding/xml" "fmt" "io" "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -46,7 +47,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/Oog/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -111,16 +112,3 @@ func main() { } } - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -} diff --git a/RO/Makefile b/RO/Makefile index ee3079c..2af8d72 100644 --- a/RO/Makefile +++ b/RO/Makefile @@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go metadata: cmd/metadata/*.go go build -o $@ $^ -ro: cmd/ro/*.go - go build -o $@ $^ +ro: cmd/ro/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/RO/cmd/ro/ro.go b/RO/cmd/ro/ro.go index 7ec983a..7d65f88 100644 --- a/RO/cmd/ro/ro.go +++ b/RO/cmd/ro/ro.go @@ -3,13 +3,14 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "encoding/xml" "fmt" "io" "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -46,7 +47,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/RO/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -111,16 +112,3 @@ func main() { } } - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -} diff --git a/Sargasso/Makefile b/Sargasso/Makefile index be57db7..fb375a2 100644 --- a/Sargasso/Makefile +++ b/Sargasso/Makefile @@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go metadata: cmd/metadata/*.go go build -o $@ $^ -sargasso: cmd/sargasso/*.go - go build -o $@ $^ +sargasso: cmd/sargasso/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/Sargasso/cmd/sargasso/sargasso.go b/Sargasso/cmd/sargasso/sargasso.go index 23dfb3b..c5ceb59 100644 --- a/Sargasso/cmd/sargasso/sargasso.go +++ b/Sargasso/cmd/sargasso/sargasso.go @@ -3,13 +3,14 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "encoding/xml" "fmt" "io" "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -46,7 +47,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/Sargasso/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -111,16 +112,3 @@ func main() { } } - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -} diff --git a/Tzum/Makefile b/Tzum/Makefile index 6df7f18..b187720 100644 --- a/Tzum/Makefile +++ b/Tzum/Makefile @@ -9,5 +9,5 @@ xml2txt: cmd/xml2txt/*.go ../internal/util/*.go metadata: cmd/metadata/*.go go build -o $@ $^ -tzum: cmd/tzum/*.go - go build -o $@ $^ +tzum: cmd/tzum/*.go ../internal/util/*.go + go build -o $@ $< diff --git a/Tzum/cmd/tzum/tzum.go b/Tzum/cmd/tzum/tzum.go index 337759c..f115b44 100644 --- a/Tzum/cmd/tzum/tzum.go +++ b/Tzum/cmd/tzum/tzum.go @@ -3,13 +3,14 @@ package main import ( e "codeberg.org/pebbe/errors" + u "git.web.rug.nl/p209327/nlnieuws/internal/util" + "encoding/xml" "fmt" "io" "net/http" "net/url" "os" - "path/filepath" "strings" "time" ) @@ -46,7 +47,7 @@ func main() { }() myLock := "/net/corpora/nlnieuws/Tzum/lock" - mkLock(myLock) + u.MkLock(myLock) defer func() { _ = os.Remove(myLock) }() @@ -111,16 +112,3 @@ func main() { } } - -func mkLock(filename string) { - pid := os.Getpid() - link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid) - p(os.Symlink(link, filename)) - - name, err := os.Readlink(filename) - p(err) - - if name != link { - p(fmt.Errorf("wrong lock name %q, should be %q", name, link)) - } -}