get_media_devices: code cleanup
authorMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 28 May 2011 21:02:37 +0000 (18:02 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 28 May 2011 21:11:21 +0000 (18:11 -0300)
whitespacing & coding style fixes, and a few trivial cleanups.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
utils/libmedia_dev/get_media_devices.c
utils/libmedia_dev/get_media_devices.h
utils/v4l2-sysfs-path/v4l2-sysfs-path.c

index 7f3061d..733f46e 100644 (file)
 
 static char *device_type_str[] = {
        [MEDIA_V4L_VIDEO]       = "video",
-       [MEDIA_V4L_VBI] = "vbi",
+       [MEDIA_V4L_VBI]         = "vbi",
        [MEDIA_DVB_FRONTEND]    = "dvb frontend",
        [MEDIA_DVB_DEMUX]       = "dvb demux",
-       [MEDIA_DVB_DVR] = "dvb dvr",
-       [MEDIA_DVB_NET] = "dvb net",
-       [MEDIA_DVB_CA]  = "dvb conditional access",
+       [MEDIA_DVB_DVR]         = "dvb dvr",
+       [MEDIA_DVB_NET]         = "dvb net",
+       [MEDIA_DVB_CA]          = "dvb conditional access",
        [MEDIA_SND_CARD]        = "sound card",
-       [MEDIA_SND_CAP] = "pcm capture",
-       [MEDIA_SND_OUT] = "pcm output",
+       [MEDIA_SND_CAP]         = "pcm capture",
+       [MEDIA_SND_OUT]         = "pcm output",
        [MEDIA_SND_CONTROL]     = "mixer",
-       [MEDIA_SND_HW]  = "sound hardware",
+       [MEDIA_SND_HW]          = "sound hardware",
 };
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
@@ -79,7 +79,7 @@ typedef int (*fill_data_t)(struct media_device_entry *md);
 static void get_uevent_info(struct media_device_entry *md_ptr, char *dname)
 {
        FILE *fd;
-       char file[560], *name, *val, *p;
+       char file[560], *name, *p;
        char s[1024];
 
        sprintf(file, "%s/%s/uevent", dname, md_ptr->node);
@@ -88,17 +88,16 @@ static void get_uevent_info(struct media_device_entry *md_ptr, char *dname)
                return;
        while (fgets(s, sizeof(s), fd)) {
                p = strtok(s, "=");
-               if(!p)
+               if (!p)
                        continue;
                name = p;
                p = strtok(NULL, "\n");
-               if(!p)
+               if (!p)
                        continue;
-               val = p;
                if (!strcmp(name, "MAJOR"))
-                       md_ptr->major = atol(val);
+                       md_ptr->major = atol(p);
                else if (!strcmp(name, "MINOR"))
-                       md_ptr->minor = atol(val);
+                       md_ptr->minor = atol(p);
        }
 
        fclose(fd);
@@ -150,22 +149,22 @@ static int get_class(char *class,
                        p = strstr(link, class);
                        if (!p)
                                goto error;
-                       *(p -1) = '\0';
+                       *(p - 1) = '\0';
 
                        /* Remove USB sub-devices from the path */
-                       if (strstr(device,"usb")) {
+                       if (strstr(device, "usb")) {
                                do {
                                        p = strrchr(device, '/');
                                        if (!p)
                                                goto error;
-                                       if (!strpbrk(p,":."))
+                                       if (!strpbrk(p, ":."))
                                                break;
                                        *p = '\0';
                                } while (1);
                        }
 
                        /* Don't handle virtual devices */
-                       if (!strcmp(device,"virtual"))
+                       if (!strcmp(device, "virtual"))
                                continue;
 
                        /* Add one more element to the devices struct */
@@ -333,7 +332,8 @@ char *media_device_type(enum device_type type)
 {
        if ((unsigned int)type >= ARRAY_SIZE(device_type_str))
                return "unknown";
-       else return device_type_str[type];
+       else
+               return device_type_str[type];
 }
 
 void display_media_devices(void *opaque)
@@ -345,10 +345,10 @@ void display_media_devices(void *opaque)
 
        for (i = 0; i < md->md_size; i++) {
                if (strcmp(prev, md_ptr->device)) {
-                       printf ("\nDevice %s:\n\t", md_ptr->device);
+                       printf("\nDevice %s:\n\t", md_ptr->device);
                        prev = md_ptr->device;
                }
-               printf ("%s(%s) ", md_ptr->node, media_device_type(md_ptr->type));
+               printf("%s(%s) ", md_ptr->node, media_device_type(md_ptr->type));
                md_ptr++;
        }
        printf("\n");
@@ -390,7 +390,7 @@ char *get_associated_device(void *opaque,
                prev = md_ptr->device;
                md_ptr++;
                /* Step 2: find the associated node */
-               for (;i < md->md_size && !strcmp(prev, md_ptr->device); i++, md_ptr++) {
+               for (; i < md->md_size && !strcmp(prev, md_ptr->device); i++, md_ptr++) {
                        if (last_seek && md_ptr->type == seek_type &&
                            !strcmp(md_ptr->node, last_seek)) {
                                found = 1;
@@ -402,7 +402,7 @@ char *get_associated_device(void *opaque,
                                return md_ptr->node;
                }
        } else {
-               for (i = 0;i < md->md_size; i++, md_ptr++) {
+               for (i = 0; i < md->md_size; i++, md_ptr++) {
                        if (last_seek && !strcmp(md_ptr->node, last_seek)) {
                                found = 1;
                                continue;
@@ -442,11 +442,10 @@ char *get_not_associated_device(void *opaque,
                        skip = 0;
                        result = NULL;
                }
-               if (md_ptr->type == not_desired_type) {
+               if (md_ptr->type == not_desired_type)
                        skip = 1;
-               } else if (!skip && !result && md_ptr->type == desired_type) {
+               else if (!skip && !result && md_ptr->type == desired_type)
                        result = md_ptr->node;
-               }
        }
        if (skip)
                result = NULL;
index 4d7a1f8..e889bcd 100644 (file)
@@ -111,7 +111,7 @@ void display_media_devices(void *opaque);
 
 /**
  * get_associated_device() - Return the next device not associated with
- *                              an specific device type.
+ *                          an specific device type.
  *
  * @opaque:            media devices opaque descriptor
  * @last_seek:         last seek result. Use NULL to get the first result
index dad2db1..7579612 100644 (file)
@@ -21,7 +21,7 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * Author:
- *     Mauro Carvalho Chehab <mchehab@redhat.com>
+ *     Mauro Carvalho Chehab <mchehab@redhat.com>
  */
 
 #include "../libmedia_dev/get_media_devices.h"
@@ -55,8 +55,8 @@ static void print_all_alsa_independent_playback(void *md)
        int first = 1;
 
        do {
-               devname = get_not_associated_device(md, devname,
-                                                   MEDIA_SND_OUT, MEDIA_V4L_VIDEO);
+               devname = get_not_associated_device(md, devname, MEDIA_SND_OUT,
+                                                   MEDIA_V4L_VIDEO);
                if (devname) {
                        if (first) {
                                printf("Alsa playback device(s): ");
@@ -73,7 +73,7 @@ static void print_all_alsa_independent_playback(void *md)
 int main(void)
 {
        void *md;
-       char *vid, *alsa;
+       char *vid;
        int i;
 
        md = discover_media_devices();
@@ -81,7 +81,7 @@ int main(void)
        vid = NULL;
        do {
                vid = get_associated_device(md, vid, MEDIA_V4L_VIDEO,
-                                               NULL, NONE);
+                                           NULL, NONE);
                if (!vid)
                        break;
                printf("Video device: %s\n", vid);