Commits

juster committed 2f57322

Parse cmdline args as mirrorlist paths. Code cleanup.

Use PingCount properly. Fix indents.

  • Participants
  • Parent commits 99184cf

Comments (0)

Files changed (1)

     "strings"
     "regexp"
     "bytes"
-    "flag"
     "fmt"
     "net"
     "os"
     "io"
 )
 
-const PINGCOUNT = 10
+const PingCount = 10 // Later this will be a variable
 
 type Mirror struct {
     Country   string
-    Pings     *[10]uint
+    Pings     []uint
     URLs      []string
     Addr      *net.IPAddr
     Hostname  string
 
 func NewMirror (entry *ServerEntry) (*Mirror) {
     return &Mirror{ entry.Country,
-                    nil,
+                    make( []uint, PingCount ),
                     make( []string, 0, 4 ),
                     nil,
                     entry.Hostname }
 }
 
 func (mlist *MirrorList) ParseFile (mfile io.Reader) () {
-    reader    := line.NewReader( mfile, 1000 )
+    reader := line.NewReader( mfile, 1000 )
 
     /* Prepare regexps */
     comment, err := regexp.Compile( "^[ \t]*#[ \t]*(.*)"  )
                                     "*=[ \t]*([^#]+)" )
     if ( err != nil ) { panic( err.String() ) }
 
-    var country string = ""
+    country := ""
 
     SERVER_LOOP:
     for {
 }
 
 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 )
+    FILE_LOOP:
+    for _, mpath := range os.Args[1:] {
+        mfile, err := os.Open( mpath, os.O_RDONLY, 0 )
+        if err != nil {
+            fmt.Fprintln( os.Stderr, err.String() )
+            continue FILE_LOOP
+        }
+
+        fmt.Fprintf( os.Stderr, "*DBG* Parsing %s...\n", mpath )
+        mlist.ParseFile( mfile )
     }
-
-    mlist.ParseFile( mfile )
 }