Update of /cvsroot/arcem/arcem/arch
In directory vz-cvs-4.sog:/tmp/cvs-serv7721/arch

Modified Files:
      Tag: arcem-fast
        i2c.c 
Log Message:
Re-format SetUpCMOS(), streamline preprocessor conditionals by chaining
#if-elif-else-endif instead of nested #ifs.


Index: i2c.c
===================================================================
RCS file: /cvsroot/arcem/arcem/arch/i2c.c,v
retrieving revision 1.12.2.3
retrieving revision 1.12.2.4
diff -u -d -r1.12.2.3 -r1.12.2.4
--- i2c.c       30 Oct 2011 00:20:21 -0000      1.12.2.3
+++ i2c.c       31 Oct 2011 00:52:14 -0000      1.12.2.4
@@ -426,56 +426,47 @@
   }; /* Transmitter */
 } /* I2C_Update */
 
-/* ------------------------------------------------------------------------- */
-static void SetUpCMOS(ARMul_State *state) {
-  int loop,dest;
-  unsigned int val;
-  FILE *InFile;
+/* ------------------------------------------------------------------ */
 
-#ifdef __riscos__
-  InFile = fopen("<ArcEm$Dir>.hexcmos", "r");
-#else
-#ifdef MACOSX
-  {
-      chdir(arcemDir);
-      InFile = fopen("hexcmos", "r");
-  }
-#else
-#ifdef SYSTEM_gp2x
-  InFile = fopen("/mnt/sd/arcem/hexcmos", "r");
+static void SetUpCMOS(ARMul_State *state)
+{
+    FILE *fp;
+    int byte, dest;
+    unsigned int val;
+
+#if defined(__riscos__)
+    fp = fopen("<ArcEm$Dir>.hexcmos", "r");
+#elif defined(MACOSX)
+    chdir(arcemDir);
+    fp = fopen("hexcmos", "r");
+#elif defined(SYSTEM_gp2x)
+    fp = fopen("/mnt/sd/arcem/hexcmos", "r");
 #else
-  InFile = fopen("hexcmos", "r");
-#endif
-#endif
+    fp = fopen("hexcmos", "r");
 #endif
 
-  if (InFile == NULL) {
-    fprintf(stderr,"SetUpCMOS: Could not open (hexcmos) CMOS settings file, 
resetting to internal defaults.\n");
-//    exit(1);
-  };
-
+    if (fp == NULL)
+        fputs("SetUpCMOS: Could not open (hexcmos) CMOS settings file, "
+            "resetting to internal defaults.\n", stderr);
 
-  for (loop = 0; loop < 240; loop++) {
-       if (InFile == NULL)
-       {
-               val=CMOSDefaults[loop];
-       }
-       else
-       {
-       fscanf(InFile,"%x\n",&val);
-       }
+    for (byte = 0; byte < 240; byte++) {
+        if (fp) {
+            fscanf(fp, "%x\n", &val);
+        } else {
+            val = CMOSDefaults[byte];
+        }
 
-    dest=loop+64;
-    if (dest>255) dest-=240;
+        /* Map 0..191 to 64...255, and 192...239 to 16...63. */
+        dest = byte + 64;
+        if (dest > 255) dest -= 240;
+        I2C.Data[dest] = val;
+    }
 
-    I2C.Data[dest]=val;
-  };
+    if (fp) fclose(fp);
+}
 
-       if(InFile)
-               fclose(InFile);
-} /* SetUpCMOS */
+/* ------------------------------------------------------------------ */
 
-/* ------------------------------------------------------------------------- */
 void
 I2C_Init(ARMul_State *state)
 {


------------------------------------------------------------------------------
Get your Android app more play: Bring it to the BlackBerry PlayBook 
in minutes. BlackBerry App World&#153; now supports Android&#153; Apps 
for the BlackBerry&reg; PlayBook&#153;. Discover just how easy and simple 
it is! http://p.sf.net/sfu/android-dev2dev
-- 
arcem-cvs mailing list
arcem-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/arcem-cvs

Reply via email to