Handle options that are integers (e.g. HZ) or strings properly.
authorMarc Fiuczynski <mef@cs.princeton.edu>
Thu, 30 Nov 2006 17:07:03 +0000 (17:07 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Thu, 30 Nov 2006 17:07:03 +0000 (17:07 +0000)
configs/kompare

index 273f198..11df5e9 100755 (executable)
@@ -5,7 +5,7 @@
 # Marc E. Fiuczynski <mef@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: compare,v 1.1 2006/11/30 16:39:29 mef Exp $
+# $Id: kompare,v 1.1 2006/11/30 16:41:09 mef Exp $
 #
 
 import sys, re, os
@@ -15,34 +15,31 @@ def process(file):
     CONFIGS = {}
     for line in file.readlines():
         iline = line.lower()
-
-        offset=iline.find(" is not set")
-        if offset <> -1:
-            config = line[line.find("CONFIG"):offset].strip()
-            if CONFIGS.has_key(config): print "duplicate entry %s" % config
-            CONFIGS[config]=0
-            ORDER.append(config)
-            continue
-
-        offset = iline.find("=y")
-        if offset  <> -1:
-            config = line[line.find("CONFIG"):offset].strip()
-            if CONFIGS.has_key(config): print "duplicate entry %s" % config
-            CONFIGS[config]=1
-            ORDER.append(config)
-            continue
-
-        offset = iline.find("=m")
-        if iline.find("=m") <> -1:
-            config = line[line.find("CONFIG"):offset].strip()
-            if CONFIGS.has_key(config): print "duplicate entry %s" % config
-            CONFIGS[config]=2
-            ORDER.append(config)
-            continue
-
+        iline.strip()
+        if len(iline)==0: continue
+        firstchar = iline[0]
+
+        if firstchar == '#':
+            offset=iline.find(" is not set")
+            if offset <> -1:
+                config = line[line.find("CONFIG"):offset].strip()
+                if CONFIGS.has_key(config): print "duplicate entry %s" % config
+                CONFIGS[config]="is not set"
+                ORDER.append(config)
+            else:
+                # skip over comments that do not contain the "is not set" string
+                pass
+
+        else:
+            offset = iline.find('=')
+            if offset  <> -1:
+                config = line[line.find("CONFIG"):offset].strip()
+                if CONFIGS.has_key(config): print "duplicate entry %s" % config
+                CONFIGS[config] = line[offset+1:].strip()
+                ORDER.append(config)
+        
     return (CONFIGS,ORDER)
 
-
 showall=False
 args = sys.argv[1:]
 
@@ -54,11 +51,11 @@ Options
     -a    Show all differences
 
 State Legend
-    A     Added config (exists in to.config, but not in from.config)
-    R     Removed config (exists in from.config, but not in to.config)
-    B     Builtin
-    M     Module
-    D     Disabled
+    ADD     Added config (exists in to.config, but not in from.config)
+    REM     Removed config (exists in from.config, but not in to.config)
+    BLT     Builtin
+    MOD     Module
+    DIS     Disabled
     """
     sys.exit(0)
 
@@ -69,19 +66,18 @@ if args[0] == "-a":
 (old,oldorder)= process(open(args[0]))
 (new,neworder)= process(open(args[1]))
 
-oldstate = {-1:'A',0:'D',1:'B',2:'M'}
-newstate = {-1:'R',0:'D',1:'B',2:'M'}
-
+newstate = {None:'REM',"is not set":'DIS','y':'BLT','m':'MOD'}
 keys = neworder
 for key in keys:
-    o = old.get(key,-1)
+    o = old.get(key,None)
     n = new[key]
     if n==o and not showall: continue
-    print "%c -> %c : %s" % (newstate[o],newstate[n],key)
+    print "%6s -> %6s : %s" % (newstate.get(o,o),newstate.get(n,n),key)
 
 # not sure we care about what options have been removed
 # from from.config file
 sys.exit(0)
+oldstate = {None:'A',"is not set":'D','y':'B','m':'M'}
 keys = oldorder
 for key in keys:
     n = new.get(key,-1)