merrg.c 1.9 KB
/*
 *  merrg.c - merge errors from output log into output tab file
 *
 *
 */
#include <stdio.h>



main(int argc, char **argv)
{
  FILE *Outfile, *Tabfile;
  int i, err_no, vec_no = 0, done = 0;
  char tab_line[2048], err_line[1024], time_str[50], comment;

  if(argc != 3)
  {
    printf("Usage: %s <tab_file> <out_file>\n", argv[0]);
    exit(0);
  }

  if((Outfile = fopen(argv[2], "r")) == NULL)
  {
    fprintf(stderr,"Unable to open outfile %s\n", argv[2]);
    exit(911);
  }

  if((Tabfile = fopen(argv[1], "r")) == NULL)
  {
    fprintf(stderr,"Unable to open tabfile %s\n", argv[1]);
    exit(911);
  }

  /* echo header */
  while(fgets(tab_line, 2048, Tabfile))
  {
    printf("%s", tab_line);
    if(tab_line[0] == '\n')
      break;
  } 

  /* read first error, skip first two lines */
  for(i = 0; i < 3; i++)
  {
    if(!fgets(err_line, 2048, Outfile))
      ++done;
  }

  time_str[0] = '\0';
  sscanf(err_line, "%s %*s %*s %d\n", time_str, &err_no);
  if(strcmp(time_str, "Time")) /* out of errors */
    ++done;

  /* read vectors */
  while(fgets(tab_line, 2048, Tabfile))
  {
    printf("%04d: %s", vec_no+1, tab_line);
    sscanf(tab_line,"%c", &comment);
    
    if(comment != '#')
      ++vec_no;

    /* really a vector, and we still have errors */
    if(!done && comment != '#')
    {
      if(vec_no == err_no)
      {
        printf("****** %s", err_line);
        /* echo all errors for this vector */
        while(fgets(err_line, 2048, Outfile))
        {
          time_str[0] = '\0';
          sscanf(err_line, "%s %*s %*s %d\n", time_str, &err_no);

          if(strcmp(time_str, "Time")) /* out of errors */
          {
            ++done;
            break;
          }

          if(err_no == vec_no)
            printf("****** %s", err_line);
          else
            break;
        }
        if(feof(Outfile))
          ++done;
      }
    }
  }
  fclose(Outfile);
  fclose(Tabfile);

  return(0);
}