Logo Search packages:      
Sourcecode: dballe version File versions

void dba_var_diff ( dba_var  var1,
dba_var  var2,
int *  diffs,
FILE *  out 
)

Print the difference between two variables to an output stream. If there is no difference, it does not print anything.

Parameters:
var1 The first variable to compare
var2 The second variable to compare
Return values:
diffs Incremented by 1 if the variables differ
Parameters:
out The output stream to use for printing

Definition at line 562 of file dba_var.c.

References DBA_VAR_F, DBA_VAR_X, and DBA_VAR_Y.

{
      if (var1 == NULL && var2 == NULL)
            return;
      if (var1 == NULL)
      {
            fprintf(out, "[%d%02d%03d %s] first var is NULL, second is %s\n",
                  DBA_VAR_F(var2->info->var), DBA_VAR_X(var2->info->var), DBA_VAR_Y(var2->info->var), var2->info->desc, var2->value);
            (*diffs)++;
            return;
      }
      else if (var2 == NULL)
      {
            fprintf(out, "[%d%02d%03d %s] second var is NULL, first is %s\n",
                  DBA_VAR_F(var1->info->var), DBA_VAR_X(var1->info->var), DBA_VAR_Y(var1->info->var), var1->info->desc, var1->value);
            (*diffs)++;
            return;
      }
      if (dba_var_code(var1) != dba_var_code(var2))
      {
            fprintf(out, "varcodes differ: first is %d%02d%03d'%s', second is %d%02d%03d'%s'\n",
                  DBA_VAR_F(var1->info->var), DBA_VAR_X(var1->info->var), DBA_VAR_Y(var1->info->var), var1->info->desc,
                  DBA_VAR_F(var2->info->var), DBA_VAR_X(var2->info->var), DBA_VAR_Y(var2->info->var), var2->info->desc);
            (*diffs)++;
            return;
      }
      if (var1->value == NULL && var2->value == NULL)
            return;
      if (var1->value == NULL)
      {
            fprintf(out, "[%d%02d%03d %s] first value is NULL, second value is %s\n",
                  DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)), var1->info->desc,
                  var2->value);
            (*diffs)++;
            return;
      }
      if (var2->value == NULL)
      {
            fprintf(out, "[%d%02d%03d %s] first value is %s, second value is NULL\n",
                  DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)), var1->info->desc,
                  var1->value);
            (*diffs)++;
            return;
      }
      if (var1->info->is_string || var1->info->scale == 0)
      {
            if (strcmp(var1->value, var2->value) != 0)
            {
                  fprintf(out, "[%d%02d%03d %s] values differ: first is %s, second is %s\n",
                        DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)), var1->info->desc,
                        var1->value, var2->value);
                  (*diffs)++;
                  return;
            }
      }
      else
      {
            double val1, val2;
            dba_var_enqd(var1, &val1);
            dba_var_enqd(var2, &val2);
            if (val1 != val2)
            {
                  fprintf(out, "[%d%02d%03d %s] values differ: first is %f, second is %f\n",
                        DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)), var1->info->desc,
                        val1, val2);
                  (*diffs)++;
                  return;
            }
      }

      if ((var1->attrs != 0) != (var2->attrs != 0))
      {
            if (var1->attrs)
            {
                  fprintf(out, "[%d%02d%03d %s] attributes differ: first has attributes, second does not\n",
                        DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)),
                        var1->info->desc);
                  (*diffs)++;
            }
            else
            {
                  fprintf(out, "[%d%02d%03d %s] attributes differ: first does not have attributes, second does\n",
                        DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)),
                        var1->info->desc);
                  (*diffs)++;
            }
      } else {
            dba_var_attr cur;
            int count1 = 0, count2 = 0;

            for (cur = var1->attrs; cur != NULL; cur = cur->next)
                  ++count1;
            for (cur = var2->attrs; cur != NULL; cur = cur->next)
                  ++count2;

            if (count1 != count2)
            {
                  fprintf(out, "[%d%02d%03d %s] attributes differ: first has %d, second has %d\n",
                        DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)),
                        var1->info->desc, count1, count2);
                  (*diffs) += abs(count1 - count2);
            } else {
                  /* Check attributes */
                  for (cur = var1->attrs; cur != NULL; cur = cur->next)
                  {
                        dba_var_attr cur2;
                        int found = 0;

                        /* We cannot call enqa because it would tamper the error status */
                        for (cur2 = var2->attrs; cur2 != NULL; cur2 = cur2->next)
                              if (dba_var_code(cur2->var) == dba_var_code(cur->var))
                              {
                                    found = 1;
                                    dba_var_diff(cur->var, cur2->var, diffs, out);
                                    break;
                              }

                        if (!found)
                        {
                              fprintf(out, "[%d%02d%03d %s] attributes differ: attribute %d%02d%03d exists only on first\n",
                                    DBA_VAR_F(dba_var_code(var1)), DBA_VAR_X(dba_var_code(var1)), DBA_VAR_Y(dba_var_code(var1)),
                                    var1->info->desc, 
                                    DBA_VAR_F(dba_var_code(cur->var)), DBA_VAR_X(dba_var_code(cur->var)), DBA_VAR_Y(dba_var_code(cur->var)));
                              (*diffs)++;
                        }
                  }
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index