Some cleanups/enhancements on subgop file format

Adds support for comments in subgop config file fmt.
Any thing after a '#' character in config file is
not parsed for ingestion purposes.

Change-Id: Ic11bce127496ab23229266715502ab510738e328
diff --git a/av1/encoder/subgop.c b/av1/encoder/subgop.c
index 1f43311..cc21bd4 100644
--- a/av1/encoder/subgop.c
+++ b/av1/encoder/subgop.c
@@ -21,9 +21,9 @@
   char *x = strstr(str, delim);
   if (x) {
     *x = 0;
-    *saveptr = x + strlen(delim);
+    if (saveptr) *saveptr = x + strlen(delim);
   } else {
-    *saveptr = NULL;
+    if (saveptr) *saveptr = NULL;
     return ptr;
   }
   return ptr;
@@ -38,10 +38,10 @@
     ptr = x + strlen(delim);
     while (*x != 0 && !isspace(*x)) x++;
     *x = 0;
-    *saveptr = x + 1;
+    if (saveptr) *saveptr = x + 1;
     return ptr;
   } else {
-    *saveptr = NULL;
+    if (saveptr) *saveptr = NULL;
     return NULL;
   }
 }
@@ -56,6 +56,7 @@
       return false;
     } else {
       if ((tmp = strrchr(buf, '\n')) != NULL) *tmp = '\0';
+      if ((tmp = strchr(buf, '#')) != NULL) *tmp = '\0';
       for (int i = 0; i < (int)strlen(buf); ++i) {
         if (!isspace(buf[i])) return true;
       }
@@ -352,18 +353,8 @@
   if (!fp) return 0;
   char line[256];
   int linesize = 256;
-  char *tok, *str;
-  if (readline(line, linesize, fp)) {
-    tok = read_token_after(line, "[num_configs:", &str);
-    if (!tok) rewind(fp);
-  } else {
-    // Blank file
-    return 1;
-  }
   while (readline(line, linesize, fp)) {
-    str = line;
-    tok = read_token_after(str, "config:", &str);
-    if (tok) {
+    if (read_token_after(line, "config:", NULL)) {
       int res = process_subgop_config_fromfile(
           fp, &config_set->config[config_set->num_configs]);
       if (res) {
@@ -395,11 +386,11 @@
 
 void av1_print_subgop_config_set(SubGOPSetCfg *config_set) {
   if (!config_set->num_configs) return;
-  printf("SUBGOP CONFIG SET\n");
-  printf("=================\n");
-  printf("[num_configs:%d]\n", config_set->num_configs);
+  printf("#SUBGOP CONFIG SET\n");
+  printf("##################\n");
+  printf("#num_configs:%d\n", config_set->num_configs);
   for (int i = 0; i < config_set->num_configs; ++i) {
-    printf("config:[%d]\n", i);
+    printf("config:#%d\n", i);
     SubGOPCfg *config = &config_set->config[i];
     printf("  num_frames:%d", config->num_frames);
     printf(" subgop_in_gop_code:%d", config->subgop_in_gop_code);