Commits

juster committed e974b56

Rename prankm to rankm.

The p stood for parallel but even the old version wasn't really parallel.

Comments (0)

Files changed (2)

prankm.go

-package main
-
-import (
-	"encoding/line"
-    "strings"
-    "regexp"
-	"bytes"
-    "flag"
-    "fmt"
- 	"net"
-    "os"
-    "io"
-)
-
-const PINGCOUNT = 10
-
-type Mirror struct {
-    Country   string
-    Pings     *[10]uint
-    URLs      []string
-    Addr      *net.IPAddr
-    Hostname  string
-}
-
-type MirrorList []*Mirror
-
-type ServerEntry struct {
-    Country  string
-    URL      string
-    Hostname string
-}
-
-func NewServerEntry (country, url string) (*ServerEntry) {
-    host, err := regexp.Compile( "^(https?|ftp)://([^/]+)" )
-
-    if err != nil {
-        panic( err.String() )
-    }
-
-    if matches := host.FindStringSubmatch( url ) ; matches != nil {
-        return &ServerEntry{ country, url, matches[2] }
-    }
-
-    return nil
-}
-
-func NewMirror (entry *ServerEntry) (*Mirror) {
-    return &Mirror{ entry.Country,
-                    nil,
-                    make( []string, 0, 4 ),
-                    nil,
-                    entry.Hostname }
-}
-
-func (mlist *MirrorList) FindHostname (hostname string) (*Mirror) {
-    for _, m := range *mlist {
-        if m.Hostname == hostname { return m }
-    }
-
-    return nil
-}
-
-func (mlist *MirrorList) AddServerEntry (entry *ServerEntry) (*Mirror) {
-    existing := mlist.FindHostname( entry.Hostname )
-    if existing != nil {
-        existing.URLs = append( existing.URLs, entry.URL )
-        return existing
-    }
-
-    newmirror := NewMirror( entry )
-    *mlist = append( *mlist, newmirror )
-    return newmirror
-}
-
-func (mlist *MirrorList) ParseFile (mfile io.Reader) () {
-    reader    := line.NewReader( mfile, 1000 )
-
-    /* Prepare regexps */
-    comment, err := regexp.Compile( "^[ \t]*#[ \t]*(.*)"  )
-    if ( err != nil ) { panic( err.String() ) }
-
-    server, err  := regexp.Compile( "^[ \t]*(#+[ \t]*)?Server[ \t]"+
-                                    "*=[ \t]*([^#]+)" )
-    if ( err != nil ) { panic( err.String() ) }
-
-    var country string = ""
-
-    SERVER_LOOP:
-	for {
-		line_bytes, is_pre, readerr := reader.ReadLine()
-		if is_pre || readerr != nil { break }
-		line_buff := bytes.NewBuffer( line_bytes )
-        line := line_buff.String()
-// 		fmt.Println( line )
-
-        /* Servers are most important, obviously... */
-        if subs := server.FindStringSubmatch( line ) ; subs != nil {
-            srv := NewServerEntry( country, subs[2] )
-            if srv == nil {
-                fmt.Fprintf( os.Stderr, "Invalid entry: %s\n", line )
-            } else {
-                mlist.AddServerEntry( srv )
-                fmt.Printf( "%+v\n", *srv )
-            }
-        } else if com := comment.FindStringSubmatch( line ) ; com != nil {
-            /* Now we check for country comments. */
-            country = strings.TrimRight( com[1], " \t" )
-        }
-
-	}
-}
-
-func main() {
-    var mpath *string = flag.String( "path",
-                                      "mirrorlist",
-                                      "Path to mirrorlist" )
-    flag.Parse()
-    fmt.Printf( "mpath = %s\n", *mpath )
-
-    mlist := make( MirrorList, 0, 128 )
-
-	mfile, err := os.Open( *mpath, os.O_RDONLY, 0 )
-	if err != nil {
-        fmt.Fprintln( os.Stderr, err.String() )
-	    os.Exit( 1 )
-	}
-
-	mlist.ParseFile( mfile )
-}
+package main
+
+import (
+	"encoding/line"
+    "strings"
+    "regexp"
+	"bytes"
+    "flag"
+    "fmt"
+ 	"net"
+    "os"
+    "io"
+)
+
+const PINGCOUNT = 10
+
+type Mirror struct {
+    Country   string
+    Pings     *[10]uint
+    URLs      []string
+    Addr      *net.IPAddr
+    Hostname  string
+}
+
+type MirrorList []*Mirror
+
+type ServerEntry struct {
+    Country  string
+    URL      string
+    Hostname string
+}
+
+func NewServerEntry (country, url string) (*ServerEntry) {
+    host, err := regexp.Compile( "^(https?|ftp)://([^/]+)" )
+
+    if err != nil {
+        panic( err.String() )
+    }
+
+    if matches := host.FindStringSubmatch( url ) ; matches != nil {
+        return &ServerEntry{ country, url, matches[2] }
+    }
+
+    return nil
+}
+
+func NewMirror (entry *ServerEntry) (*Mirror) {
+    return &Mirror{ entry.Country,
+                    nil,
+                    make( []string, 0, 4 ),
+                    nil,
+                    entry.Hostname }
+}
+
+func (mlist *MirrorList) FindHostname (hostname string) (*Mirror) {
+    for _, m := range *mlist {
+        if m.Hostname == hostname { return m }
+    }
+
+    return nil
+}
+
+func (mlist *MirrorList) AddServerEntry (entry *ServerEntry) (*Mirror) {
+    existing := mlist.FindHostname( entry.Hostname )
+    if existing != nil {
+        existing.URLs = append( existing.URLs, entry.URL )
+        return existing
+    }
+
+    newmirror := NewMirror( entry )
+    *mlist = append( *mlist, newmirror )
+    return newmirror
+}
+
+func (mlist *MirrorList) ParseFile (mfile io.Reader) () {
+    reader    := line.NewReader( mfile, 1000 )
+
+    /* Prepare regexps */
+    comment, err := regexp.Compile( "^[ \t]*#[ \t]*(.*)"  )
+    if ( err != nil ) { panic( err.String() ) }
+
+    server, err  := regexp.Compile( "^[ \t]*(#+[ \t]*)?Server[ \t]"+
+                                    "*=[ \t]*([^#]+)" )
+    if ( err != nil ) { panic( err.String() ) }
+
+    var country string = ""
+
+    SERVER_LOOP:
+	for {
+		line_bytes, is_pre, readerr := reader.ReadLine()
+		if is_pre || readerr != nil { break }
+		line_buff := bytes.NewBuffer( line_bytes )
+        line := line_buff.String()
+// 		fmt.Println( line )
+
+        /* Servers are most important, obviously... */
+        if subs := server.FindStringSubmatch( line ) ; subs != nil {
+            srv := NewServerEntry( country, subs[2] )
+            if srv == nil {
+                fmt.Fprintf( os.Stderr, "Invalid entry: %s\n", line )
+            } else {
+                mlist.AddServerEntry( srv )
+                fmt.Printf( "%+v\n", *srv )
+            }
+        } else if com := comment.FindStringSubmatch( line ) ; com != nil {
+            /* Now we check for country comments. */
+            country = strings.TrimRight( com[1], " \t" )
+        }
+
+	}
+}
+
+func main() {
+    var mpath *string = flag.String( "path",
+                                      "mirrorlist",
+                                      "Path to mirrorlist" )
+    flag.Parse()
+    fmt.Printf( "mpath = %s\n", *mpath )
+
+    mlist := make( MirrorList, 0, 128 )
+
+	mfile, err := os.Open( *mpath, os.O_RDONLY, 0 )
+	if err != nil {
+        fmt.Fprintln( os.Stderr, err.String() )
+	    os.Exit( 1 )
+	}
+
+	mlist.ParseFile( mfile )
+}