Skip to contentSkip to conversation

Beautification patches

PATCH New Adrian Knoth 1 participant 5 messages Feb 3, 2011

lore
Share & tools
lore
#0 lore raw

cover Beautification patches

Hi!

Here's a line of code beautification patches for hdspmixer. I broke them up into smaller pieces to ease the review, though one may find four patches for no added functionality a little bit excessive. If so, please feel free simply commit them as a single commit.

Cheers

Adrian Knoth (4):
hdspmixer: retab and reindent code.
hdspmixer: Improve readability.
hdspmixer: Beautification; Lower nesting depth
hdspmixer: Break overlong line and don't plenken.

Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/4 hdspmixer: retab and reindent code.

Something seriously was wrong, probably different patches with different tabwidth levels. I switched to spaces to avoid ambiguity and let vim reindent everything.

hdspmixer/src/hdspmixer.cxx +29 -29
index 2a7c5c9..49a9985 100644
@@ -39,18 +39,18 @@ int main(int argc, char **argv)
     char *name;
     int card;
     int cards = 0;
-    
+
     card = -1;
     printf("\nHDSPMixer %s - Copyright (C) 2003 Thomas Charbonnel <[email protected]>\n", VERSION);
     printf("This program comes with ABSOLUTELY NO WARRANTY\n");
     printf("HDSPMixer is free software, see the file COPYING for details\n\n");
     printf("Looking for RME cards :\n");
     while (snd_card_next(&card) >= 0) {
-	if (card < 0) {
-	    break;
-	} else {
-	    snd_card_get_longname(card, &name);
-	    printf("Card %d : %s\n", card, name);
+        if (card < 0) {
+            break;
+        } else {
+            snd_card_get_longname(card, &name);
+            printf("Card %d : %s\n", card, name);
             if (!strncmp(name, "RME Hammerfall DSP + Multiface", 30)) {
                 printf("Multiface found !\n");
                 hdsp_cards[cards] = new HDSPMixerCard(Multiface, card);
@@ -67,34 +67,34 @@ int main(int argc, char **argv)
                 printf("HDSP 9632 found !\n");
                 hdsp_cards[cards] = new HDSPMixerCard(H9632, card);
                 cards++;
-	    } else if (!strncmp(name, "RME MADIface", 12)) {
-		printf("RME MADIface found !\n");
-		hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
-		cards++;
-	    } else if (!strncmp(name, "RME MADI", 8)) {
-		printf("RME MADI found !\n");
-		hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
-		cards++;
-	    } else if (!strncmp(name, "RME RayDAT", 10)) {
-		printf("RME RayDAT found !\n");
-		hdsp_cards[cards] = new HDSPMixerCard(HDSPeRayDAT, card);
-		cards++;
-	    } else if (!strncmp(name, "RME AIO", 7)) {
-		printf("RME AIO found !\n");
-		hdsp_cards[cards] = new HDSPMixerCard(HDSPeAIO, card);
-		cards++;
-	    } else if (!strncmp(name, "RME Hammerfall DSP", 18)) {
-		printf("Uninitialized HDSP card found.\nUse hdsploader to upload configuration data to the card.\n");
-	    } 
-	}
+            } else if (!strncmp(name, "RME MADIface", 12)) {
+                printf("RME MADIface found !\n");
+                hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
+                cards++;
+            } else if (!strncmp(name, "RME MADI", 8)) {
+                printf("RME MADI found !\n");
+                hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
+                cards++;
+            } else if (!strncmp(name, "RME RayDAT", 10)) {
+                printf("RME RayDAT found !\n");
+                hdsp_cards[cards] = new HDSPMixerCard(HDSPeRayDAT, card);
+                cards++;
+            } else if (!strncmp(name, "RME AIO", 7)) {
+                printf("RME AIO found !\n");
+                hdsp_cards[cards] = new HDSPMixerCard(HDSPeAIO, card);
+                cards++;
+            } else if (!strncmp(name, "RME Hammerfall DSP", 18)) {
+                printf("Uninitialized HDSP card found.\nUse hdsploader to upload configuration data to the card.\n");
+            } 
+        }
     }
     free(name);
     if (!cards) {
-	printf("No RME cards found.\n");
-	exit(EXIT_FAILURE);
+        printf("No RME cards found.\n");
+        exit(EXIT_FAILURE);
     }
     for (int i = cards; i < 3; ++i) {
-	hdsp_cards[i] = NULL;
+        hdsp_cards[i] = NULL;
     }
     printf("%d RME cards %s found.\n", cards, (cards > 1) ? "cards" : "card");
     window = new HDSPMixerWindow(0, 0, hdsp_cards[0]->window_width, hdsp_cards[0]->window_height, "HDSPMixer", hdsp_cards[0], hdsp_cards[1], hdsp_cards[2]);
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/4 hdspmixer: Improve readability.

In reply to Adrian Knoth

Group the statements into logical blocks.

hdspmixer/src/hdspmixer.cxx +5 -0
index 49a9985..7e83c23 100644
@@ -45,6 +45,7 @@ int main(int argc, char **argv)
     printf("This program comes with ABSOLUTELY NO WARRANTY\n");
     printf("HDSPMixer is free software, see the file COPYING for details\n\n");
     printf("Looking for RME cards :\n");
+
     while (snd_card_next(&card) >= 0) {
         if (card < 0) {
             break;
@@ -88,17 +89,21 @@ int main(int argc, char **argv)
             } 
         }
     }
+
     free(name);
     if (!cards) {
         printf("No RME cards found.\n");
         exit(EXIT_FAILURE);
     }
+
     for (int i = cards; i < 3; ++i) {
         hdsp_cards[i] = NULL;
     }
+
     printf("%d RME cards %s found.\n", cards, (cards > 1) ? "cards" : "card");
     window = new HDSPMixerWindow(0, 0, hdsp_cards[0]->window_width, hdsp_cards[0]->window_height, "HDSPMixer", hdsp_cards[0], hdsp_cards[1], hdsp_cards[2]);
     Fl::visual(FL_DOUBLE|FL_INDEX);
     window->show(argc, argv);
+
     return Fl::run();    
 }
Signature · 1 line
1.7.2.3
#3 lore raw

PATCH 3/4 hdspmixer: Beautification; Lower nesting depth

In reply to Adrian Knoth

Exit the loop if card < 0. No need to nest the actual code in the else branch.

hdspmixer/src/hdspmixer.cxx +38 -38
index 7e83c23..6d85062 100644
@@ -49,45 +49,45 @@ int main(int argc, char **argv)
     while (snd_card_next(&card) >= 0) {
         if (card < 0) {
             break;
-        } else {
-            snd_card_get_longname(card, &name);
-            printf("Card %d : %s\n", card, name);
-            if (!strncmp(name, "RME Hammerfall DSP + Multiface", 30)) {
-                printf("Multiface found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(Multiface, card);
-                cards++;
-            } else if (!strncmp(name, "RME Hammerfall DSP + Digiface", 29)) {
-                printf("Digiface found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(Digiface, card);
-                cards++;
-            } else if (!strncmp(name, "RME Hammerfall HDSP 9652", 24)) {
-                printf("HDSP 9652 found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(H9652, card);
-                cards++;
-            } else if (!strncmp(name, "RME Hammerfall HDSP 9632", 24)) {
-                printf("HDSP 9632 found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(H9632, card);
-                cards++;
-            } else if (!strncmp(name, "RME MADIface", 12)) {
-                printf("RME MADIface found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
-                cards++;
-            } else if (!strncmp(name, "RME MADI", 8)) {
-                printf("RME MADI found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
-                cards++;
-            } else if (!strncmp(name, "RME RayDAT", 10)) {
-                printf("RME RayDAT found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(HDSPeRayDAT, card);
-                cards++;
-            } else if (!strncmp(name, "RME AIO", 7)) {
-                printf("RME AIO found !\n");
-                hdsp_cards[cards] = new HDSPMixerCard(HDSPeAIO, card);
-                cards++;
-            } else if (!strncmp(name, "RME Hammerfall DSP", 18)) {
-                printf("Uninitialized HDSP card found.\nUse hdsploader to upload configuration data to the card.\n");
-            } 
         }
+
+        snd_card_get_longname(card, &name);
+        printf("Card %d : %s\n", card, name);
+        if (!strncmp(name, "RME Hammerfall DSP + Multiface", 30)) {
+            printf("Multiface found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(Multiface, card);
+            cards++;
+        } else if (!strncmp(name, "RME Hammerfall DSP + Digiface", 29)) {
+            printf("Digiface found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(Digiface, card);
+            cards++;
+        } else if (!strncmp(name, "RME Hammerfall HDSP 9652", 24)) {
+            printf("HDSP 9652 found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(H9652, card);
+            cards++;
+        } else if (!strncmp(name, "RME Hammerfall HDSP 9632", 24)) {
+            printf("HDSP 9632 found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(H9632, card);
+            cards++;
+        } else if (!strncmp(name, "RME MADIface", 12)) {
+            printf("RME MADIface found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
+            cards++;
+        } else if (!strncmp(name, "RME MADI", 8)) {
+            printf("RME MADI found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
+            cards++;
+        } else if (!strncmp(name, "RME RayDAT", 10)) {
+            printf("RME RayDAT found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(HDSPeRayDAT, card);
+            cards++;
+        } else if (!strncmp(name, "RME AIO", 7)) {
+            printf("RME AIO found !\n");
+            hdsp_cards[cards] = new HDSPMixerCard(HDSPeAIO, card);
+            cards++;
+        } else if (!strncmp(name, "RME Hammerfall DSP", 18)) {
+            printf("Uninitialized HDSP card found.\nUse hdsploader to upload configuration data to the card.\n");
+        } 
     }
 
     free(name);
Signature · 1 line
1.7.2.3
#4 lore raw

PATCH 4/4 hdspmixer: Break overlong line and don't plenken.

In reply to Adrian Knoth

Pure code beautification, just in case somebody ever needs to touch this again.

hdspmixer/src/hdspmixer.cxx +13 -11
index 6d85062..866afda 100644
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
     printf("\nHDSPMixer %s - Copyright (C) 2003 Thomas Charbonnel <[email protected]>\n", VERSION);
     printf("This program comes with ABSOLUTELY NO WARRANTY\n");
     printf("HDSPMixer is free software, see the file COPYING for details\n\n");
-    printf("Looking for RME cards :\n");
+    printf("Looking for RME cards:\n");
 
     while (snd_card_next(&card) >= 0) {
         if (card < 0) {
@@ -52,37 +52,37 @@ int main(int argc, char **argv)
         }
 
         snd_card_get_longname(card, &name);
-        printf("Card %d : %s\n", card, name);
+        printf("Card %d: %s\n", card, name);
         if (!strncmp(name, "RME Hammerfall DSP + Multiface", 30)) {
-            printf("Multiface found !\n");
+            printf("Multiface found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(Multiface, card);
             cards++;
         } else if (!strncmp(name, "RME Hammerfall DSP + Digiface", 29)) {
-            printf("Digiface found !\n");
+            printf("Digiface found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(Digiface, card);
             cards++;
         } else if (!strncmp(name, "RME Hammerfall HDSP 9652", 24)) {
-            printf("HDSP 9652 found !\n");
+            printf("HDSP 9652 found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(H9652, card);
             cards++;
         } else if (!strncmp(name, "RME Hammerfall HDSP 9632", 24)) {
-            printf("HDSP 9632 found !\n");
+            printf("HDSP 9632 found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(H9632, card);
             cards++;
         } else if (!strncmp(name, "RME MADIface", 12)) {
-            printf("RME MADIface found !\n");
+            printf("RME MADIface found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
             cards++;
         } else if (!strncmp(name, "RME MADI", 8)) {
-            printf("RME MADI found !\n");
+            printf("RME MADI found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(HDSPeMADI, card);
             cards++;
         } else if (!strncmp(name, "RME RayDAT", 10)) {
-            printf("RME RayDAT found !\n");
+            printf("RME RayDAT found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(HDSPeRayDAT, card);
             cards++;
         } else if (!strncmp(name, "RME AIO", 7)) {
-            printf("RME AIO found !\n");
+            printf("RME AIO found!\n");
             hdsp_cards[cards] = new HDSPMixerCard(HDSPeAIO, card);
             cards++;
         } else if (!strncmp(name, "RME Hammerfall DSP", 18)) {
@@ -101,7 +101,9 @@ int main(int argc, char **argv)
     }
 
     printf("%d RME cards %s found.\n", cards, (cards > 1) ? "cards" : "card");
-    window = new HDSPMixerWindow(0, 0, hdsp_cards[0]->window_width, hdsp_cards[0]->window_height, "HDSPMixer", hdsp_cards[0], hdsp_cards[1], hdsp_cards[2]);
+    window = new HDSPMixerWindow(0, 0, hdsp_cards[0]->window_width,
+            hdsp_cards[0]->window_height, "HDSPMixer", hdsp_cards[0],
+            hdsp_cards[1], hdsp_cards[2]);
     Fl::visual(FL_DOUBLE|FL_INDEX);
     window->show(argc, argv);
 
Signature · 1 line
1.7.2.3