hdhomerun plugin code cleanup (part 2)

Change-Id: I9d006091c50830603786c3d5d5d9139c5aeaddac
diff --git a/Makefile b/Makefile
index 3f3ea2b..1679151 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@
   DEBUG_CFLAGS= -O3
 endif
 
-ifdef  TARGET
+ifdef TARGET
 	CROSS_PREFIX:=$(TARGET)
 else
 	CROSS_PREFIX:=
@@ -23,9 +23,9 @@
 
 CFLAGS= -Wall -fPIC -O2 -Wpointer-arith
 
-FILES=sagelog.c hdhomerun_tuner.c hdhomerun_http.c hdhomerun_dev.c  utility.c hdhomerun_plugin.c
-INC=  sagelog.h hdhomerun_tuner.h hdhomerun_http.h hdhomerun_dev.h  utility.h
-EXTRA_INCS= ../tvstreamparser  
+FILES=sagelog.c hdhomerun_tuner.c hdhomerun_http.c hdhomerun_dev.c utility.c hdhomerun_plugin.c
+INC=  sagelog.h hdhomerun_tuner.h hdhomerun_http.h hdhomerun_dev.h utility.h
+EXTRA_INCS= ../tvstreamparser
 
 #all:hdhomerun
 all:hdhr_plugin.so
@@ -47,4 +47,3 @@
 
 get_http:hdhomerun_http.c hdhomerun_http.h
 	$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -DHTTP_GET_APP hdhomerun_http.c -o get_http
-
diff --git a/channel_buffer.c b/channel_buffer.c
index a6c4796..0a8ded0 100644
--- a/channel_buffer.c
+++ b/channel_buffer.c
@@ -33,9 +33,6 @@
 #include <inttypes.h>
 #include "channel_buffer.h"
 
-#define sage_log(x) _sagelog x
-void _sagelog(int type, int level, const char *cstr, ...);
-
 static const char *delimiter = " \t,;\r\n:=|'\"#";
 
 static int is_delimiter(char ch)
@@ -212,7 +209,7 @@
   name[0] = 0;
   *Val = 0;
   ext[0] = 0;
-  ;
+
   token = (char *)strtok_r(string, delima, &saved_ptr);
   if (token != NULL)
     strncpy(name, token, max_name_lenn);
@@ -437,7 +434,7 @@
     // file_name, errno );
     return -1;
   }
-  fputs("#Google sagetv channel table ver 1.0., maxium 2048 bytes per line\n",
+  fputs("#Google sagetv channel table ver 1.0., maximum 2048 bytes per line\n",
         fp);
   fprintf(fp, "total_channel:%d\n", cl->channel_num);
   for (i = 0; i < cl->channel_num; i++) {
diff --git a/channel_buffer.h b/channel_buffer.h
index 34fadec..194ebd1 100644
--- a/channel_buffer.h
+++ b/channel_buffer.h
@@ -14,7 +14,7 @@
 struct channel_entry_t {
   int ch;
   int state;
-  int ctrl_bits;  // 0x01 fix muticast IP/port
+  int ctrl_bits;  // 0x01 fix multicast IP/port
   char ch_name[20];
   char ch_desc[32];
   char src_ip[16];
diff --git a/hdhomerun_dev.c b/hdhomerun_dev.c
index e1db136..62e12fa 100644
--- a/hdhomerun_dev.c
+++ b/hdhomerun_dev.c
@@ -1,4 +1,3 @@
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -63,7 +62,7 @@
   struct vchan_tbl_t *vt = (struct vchan_tbl_t *)context;
   int pos, used_bytes;
   char guide_num[16], guide_name[64];
-  ;
+
   pos = 0;
   while (pos < bytes) {
     used_bytes =
diff --git a/hdhomerun_dev.h b/hdhomerun_dev.h
index 70d7ef4..2848ce0 100644
--- a/hdhomerun_dev.h
+++ b/hdhomerun_dev.h
@@ -1,4 +1,3 @@
-
 #ifndef _HDHOMERUN_DEV_H_
 #define _HDHOMERUN_DEV_H_
 
diff --git a/hdhomerun_http.c b/hdhomerun_http.c
index f03ca93..a22c57e 100644
--- a/hdhomerun_http.c
+++ b/hdhomerun_http.c
@@ -14,6 +14,7 @@
 #define USERAGENT "SAGETV 1.0"
 
 #define _MIN_(x, y) ((x) > (y) ? (y) : (x))
+
 static char *get_ip(char *host, char *buf, int size)
 {
   struct hostent *hent;
@@ -88,7 +89,7 @@
     sent += ret;
   }
 
-  // recieve page
+  // receive page
   int remain = 0;
   while ((ret = recv(sock, buf + remain, BUFSIZ - remain, 0)) > 0) {
     int used_bytes = 0;
@@ -109,12 +110,12 @@
 }
 
 #ifdef HTTP_GET_APP
-static void usage()
+static void usage(void)
 {
   fprintf(stderr,
-          "USAGE: htmlget host [page]\n\
-\thost: the website hostname. ex: coding.debuntu.org\n\
-\tpage: the page to retrieve. ex: index.html, default: /\n");
+          "USAGE: htmlget host [page]\n"
+          "\thost: the website hostname. ex: coding.debuntu.org\n"
+          "\tpage: the page to retrieve. ex: index.html, default: /\n");
 }
 
 static int noop_parser(void *context, char *buf, int bytes)
diff --git a/hdhomerun_http.h b/hdhomerun_http.h
index 9275166..0c61c7b 100644
--- a/hdhomerun_http.h
+++ b/hdhomerun_http.h
@@ -1,4 +1,3 @@
-
 #ifndef _HDHOMERUN_HTTP_H_
 #define _HDHOMERUN_HTTP_H_
 
diff --git a/hdhomerun_plugin.c b/hdhomerun_plugin.c
index 18ee6db..adc2c25 100644
--- a/hdhomerun_plugin.c
+++ b/hdhomerun_plugin.c
@@ -140,7 +140,7 @@
   }
 
   if (hdhr->cc_tuner) {
-    /* HDHomeRun PRIME */
+    // HDHomeRun PRIME
     if (strstr(channel, "vchan:") == NULL) {
       char vchan[32];
       snprintf(vchan, sizeof(vchan), "vchan:%d", atoi(channel));
@@ -148,25 +148,21 @@
     } else
       ret = tune_channel(hdhr->hd, channel, "", stream_tar);
   } else {
-    /* HDHomeRun US */
+    // HDHomeRun US
     char tune_str[32], map_str[32], prog_str[8];
     int ch = -1, prog = -1, vch_major = -1, vch_minor = -1;
     char *ps, *pe;
     map_str[0] = 0x0;
 
-    /*
-     * channel format: xx-yy-zz
-     * xx=physical channel, yy=virtual major channel, zz=virtual minor channel
-     */
+    // channel format: xx-yy-zz
+    // xx=physical channel, yy=virtual major channel, zz=virtual minor channel
     if (sscanf(channel, "%d-%d-%d", &ch, &vch_major, &vch_minor) == 3) {
       ret = tune_vchannel(hdhr->hd, ch, vch_major, vch_minor, stream_tar);
       goto out;
     }
 
-    /*
-     * channel format: xx-yy
-     * xx=physical channel, yy=virtual major channel
-     */
+    // channel format: xx-yy
+    // xx=physical channel, yy=virtual major channel
     if (sscanf(channel, "%d-%d", &ch, &vch_major) == 2) {
       vch_minor = 0;
       ret = tune_vchannel(hdhr->hd, ch, vch_major, vch_minor, stream_tar);
diff --git a/hdhomerun_plugin.h b/hdhomerun_plugin.h
index d5a2cb5..8d8fc84 100644
--- a/hdhomerun_plugin.h
+++ b/hdhomerun_plugin.h
@@ -1,4 +1,3 @@
-
 #ifndef _HDHOMERUN_PLUGIN_H_
 #define _HDHOMERUN_PLUGIN_H_
 
diff --git a/hdhomerun_tuner.c b/hdhomerun_tuner.c
index 2734b74..bff2315 100644
--- a/hdhomerun_tuner.c
+++ b/hdhomerun_tuner.c
@@ -16,8 +16,10 @@
 #define PARSE_TIMEOUT 2
 #define CHANNE_SCAN_SRC "227.0.0.1"
 #define CHANNEL_SCAN_PORT 6069
+
 static volatile sig_atomic_t sigabort_flag = FALSE;
 static volatile sig_atomic_t siginfo_flag = FALSE;
+
 static const char *map_tbl[] = {"us-bcast", "us-cable", "us-hrc",   "us-irc",
                                 "au-bcast", "tw-bcast", "eu-bcast", 0x0};
 
@@ -174,7 +176,7 @@
 
   hd = (struct hdhomerun_device_t *)device;
 
-  /* Set tuner channel map to US broadcast */
+  // Set tuner channel map to US broadcast
   snprintf(channel_map, sizeof(channel_map), "us-bcast");
   ret = hdhomerun_device_set_tuner_channelmap(hd, channel_map);
   if (ret < 0) {
@@ -182,7 +184,7 @@
     goto out;
   }
 
-  /* Tune to physical channel */
+  // Tune to physical channel
   snprintf(channel_str, sizeof(channel_str), "auto:%u", channel);
   ret = hdhomerun_device_set_tuner_channel(hd, channel_str);
   if (ret <= 0) {
@@ -190,7 +192,7 @@
     goto out;
   }
 
-  /* Wait for SER to hit 100% (max 3 secs) */
+  // Wait for SER to hit 100% (max 3 secs)
   usleep(500000);
   for (i = 0; i < 10; i++) {
     ret = hdhomerun_device_get_tuner_status(hd, NULL, &ts);
@@ -200,7 +202,7 @@
     usleep(250000);
   }
 
-  /* Get MPEG2-TS stream info */
+  // Get MPEG2-TS stream info
   ret = hdhomerun_device_get_tuner_streaminfo(hd, &streaminfo);
   if (ret <= 0) {
     printf("hdhr:ERROR: get tuner streaminfo\n");
@@ -208,7 +210,7 @@
   }
   printf("hdhr:hdhomerun streaminfo:\n%s", streaminfo);
 
-  /* Translate virtual channel (major.minor) to program number */
+  // Translate virtual channel (major.minor) to program number
   ret = vchan_to_prog_num(streaminfo, vchannel_major, vchannel_minor, &program);
   if (ret <= 0) {
     printf("hdhr:ERROR: vchannel %d.%d not found in streaminfo\n",
@@ -218,7 +220,7 @@
   printf("hdhr:hdhomerun vchannel %u.%u -> program %u\n", vchannel_major,
          vchannel_minor, program);
 
-  /* Set tuner program */
+  // Set tuner program
   snprintf(program_str, sizeof(program_str), "%u", program);
   ret = hdhomerun_device_set_tuner_program(hd, program_str);
   if (ret <= 0) {
@@ -226,7 +228,7 @@
     goto out;
   }
 
-  /* Set tuner stream target */
+  // Set tuner stream target
   snprintf(target_str, sizeof(target_str), "%s ttl=2", stream_target);
   ret = hdhomerun_device_set_tuner_target(hd, target_str);
   if (ret <= 0) {
@@ -473,8 +475,7 @@
 void release_vchan_tbl(struct vchan_tbl_t *vt)
 {
   if (vt->vchan)
-    ;
-  free(vt->vchan);
+    free(vt->vchan);
   free(vt);
 }
 
@@ -552,7 +553,7 @@
     if (ret <= 0) {
       break;
     }
-    /* skip dumplicated channel*/
+    // skip duplicated channel
     for (i = 0; i < ce_channel_num; i++) {
       if (ce->frq == result.frequency)
         break;
@@ -695,7 +696,7 @@
     // file_name, errno );
     return -1;
   }
-  fputs("#Google sagetv channel table ver 1.0., maxium 2048 bytes per line\n",
+  fputs("#Google sagetv channel table ver 1.0., maximum 2048 bytes per line\n",
         fp);
   fprintf(fp, "total_channel:%d\n", num);
   for (i = 0; i < num; i++) {
@@ -747,44 +748,41 @@
     _save_channel_entry("channel-scan.txt", ce, channel_num);
   }
 
-  /*
-  //test vchannel scan
-  if ( 1 ) {
+  // test vchannel scan
+  if (0) {
     struct hdhr_tuner_t *cc_ht = NULL;
-    for ( i = 0; i<tuner_count; i++ ) {
-      if ( ht[i].cc_tuner ) {
+    for (i = 0; i < tuner_count; i++) {
+      if (ht[i].cc_tuner) {
         cc_ht = &ht[i];
         break;
       }
     }
 
-
-    if (  cc_ht != NULL ) {
-      time_t t0 = time( NULL );
-      struct vchan_tbl_t * vt = create_vchan_tbl( cc_ht );
-      ret = get_vchannel_list( vt );
-      if ( ret > 0 ) {
+    if (cc_ht != NULL) {
+      time_t t0 = time(NULL);
+      struct vchan_tbl_t *vt = create_vchan_tbl(cc_ht);
+      ret = get_vchannel_list(vt);
+      if (ret > 0) {
         int n;
         int channel_num = 0;
-        struct channel_list_t *cl = create_channel_list( ret );
-        for ( n = 1; n<vt->channel_num && channel_num < 500 ; n++ ) {
-          printf( "TRACE %d %s\n", n, vt->vchan[n].guide_name );
-          ret = scan_vchannel( vt, n, cl );
-          if ( ret > 0 ) {
+        struct channel_list_t *cl = create_channel_list(ret);
+        for (n = 1; n < vt->channel_num && channel_num < 500; n++) {
+          printf("TRACE %d %s\n", n, vt->vchan[n].guide_name);
+          ret = scan_vchannel(vt, n, cl);
+          if (ret > 0) {
             struct channel_entry_t *ce_p = &cl->ce[channel_num];
-            snprintf( ce_p->dev_name, sizeof(ce_p->dev_name), "HDHR.%s", device,
-  sizeof(ce_p->dev_name) );
+            snprintf(ce_p->dev_name, sizeof(ce_p->dev_name), "HDHR.%s", device,
+                     sizeof(ce_p->dev_name));
             channel_num++;
           }
-          printf( "TRACE channel %d, %d\n", channel_num, n );
+          printf("TRACE channel %d, %d\n", channel_num, n);
         }
-         _save_channel_entry( "channel-scan.txt", cl );
+        _save_channel_entry("channel-scan.txt", cl);
       }
-      release_vchan_tbl( vt );
-      printf( "time:%ld\n", time( NULL) - t0 );
+      release_vchan_tbl(vt);
+      printf("time:%ld\n", time(NULL) - t0);
     }
   }
-  */
 
   // test tune
   if (1) {
@@ -800,4 +798,5 @@
 
   return ret;
 }
+
 #endif
diff --git a/hdhomerun_tuner.h b/hdhomerun_tuner.h
index d581b92..54791ed 100644
--- a/hdhomerun_tuner.h
+++ b/hdhomerun_tuner.h
@@ -1,5 +1,3 @@
-
-
 #ifndef _HDHOMERUN_TUNER_H_
 #define _HDHOMERUN_TUNER_H_
 
@@ -28,13 +26,12 @@
 };
 
 struct channel_entry_t;
+
 int discover_device(struct hdhr_tuner_t *ht, int max_ht_num);
-// get unit name of a tuner, one unit contains 1-6 tuners
 void *open_hdhr(char *name);
 void close_hdhr(void *device);
 char *get_unit_name(struct hdhr_tuner_t *ht, char *name, int size);
 int scan_all(void *device, struct channel_entry_t *ce, int ce_num);
-int tuner_input_sharing(struct hdhr_tuner_t *ht1, struct hdhr_tuner_t *ht2);
 int tune_channel(void *device, char *channel, char *program,
                  char *stream_target);
 int tune_vchannel(void *device, unsigned int channel,
diff --git a/sagelog.c b/sagelog.c
index f4b932b..d0e7038 100644
--- a/sagelog.c
+++ b/sagelog.c
@@ -14,11 +14,12 @@
 int trace_level = 3;
 char log_filename[128] = "/tmp/SageEncoder.log";
 
-void _enable_native_log()
+void _enable_native_log(void)
 {
   sagelog_enabled = 1;
 }
-void _disable_native_log()
+
+void _disable_native_log(void)
 {
   sagelog_enabled = 0;
 }
@@ -81,17 +82,17 @@
   sagelog_enabled = enable;
 }
 
-char *_get_flog_path()
+char *_get_flog_path(void)
 {
   return log_filename;
 }
 
-int _get_flog_state()
+int _get_flog_state(void)
 {
   return sagelog_enabled;
 }
 
-int _flog_check()
+int _flog_check(void)
 {
   FILE *fp = fopen("NATIVE_LOG.ENABLE", "r");
   if (fp != NULL) {
diff --git a/sagelog.h b/sagelog.h
index 79d06d2..164ba9d 100644
--- a/sagelog.h
+++ b/sagelog.h
@@ -42,10 +42,11 @@
 
 void _sagelog(int type, int level, const char *cstr, ...);
 void _flog_setup(char *filename, int enable);
-char *_get_flog_path();
-int _get_flog_state();
-int _flog_check();
+char *_get_flog_path(void);
+int _get_flog_state(void);
+int _flog_check(void);
 void _set_native_log(int level);
-void _enable_native_log();
-void _disable_native_log();
-#endif /* SAGELOG_H_ */
+void _enable_native_log(void);
+void _disable_native_log(void);
+
+#endif
diff --git a/utility.c b/utility.c
index 246ca3d..5770319 100644
--- a/utility.c
+++ b/utility.c
@@ -1,15 +1,13 @@
 // Copyright 2011 Google Inc. All Rights Reserved.
 // Author: qianzhang@google.com (ken Zhang)
+
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include "channel_buffer.h"
-
 #include "utility.h"
-#define sage_log(x) _sagelog x
-void _sagelog(int type, int level, const char *cstr, ...);
 
 static const char *delimiter = " \t,;\r\n:=|'\"#";
 
@@ -176,6 +174,7 @@
   }
   return 0;
 }
+
 struct channel_list_t *_create_channel_list(int num)
 {
   if (num <= 0)
diff --git a/utility.h b/utility.h
index 00b02de..b62b9ce 100644
--- a/utility.h
+++ b/utility.h
@@ -1,5 +1,3 @@
-
-
 #ifndef _UTILITY_H_
 #define _UTILITY_H_