Пример #1
0
pwr_tStatus wb_bck_list::print( char *outfile)
{
  pwr_tFileName fname;
  FILE *fout;
  pwr_tStatus sts;

  dcli_translate_filename( fname, outfile);
  fout = fopen( fname, "w");
  if ( !fout)
    return LDH__NOSUCHFILE;

  bck_sItem *ip = m_first;
  while (ip) {
    char str[1024];
    pwr_eType atype;
    int printed = 0;
    char *anamep;
    int size;

    sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
    if ( EVEN(sts)) return sts;

    fprintf( fout, "%s", anamep);

    sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype);
    if ( ODD(sts)) {
      sts = cdh_AttrValueToString( atype, ip->valuep, str, sizeof(str));
      if ( ODD(sts)) {
	fprintf( fout, "\n	%s\n", str);
	printed = 1;
      }
    }
    
    if ( !printed) {
      // Print as hex code
      unsigned char *p = (unsigned char *)ip->valuep;
      for ( int i = 0; i < (int)ip->size; i++, p++) {
	if ((i % 16) == 0) fprintf( fout, "\n	");
	fprintf( fout, "%02x ", *p);
      }
      fprintf( fout, "\n");
    }
    ip = ip->next;
  }
  fclose( fout);

  return LDH__SUCCESS;
}
Пример #2
0
int main (int argc, char **argv)
{
  pwr_tStatus sts;
  char *c;
  int cidopt = 0;
  pwr_tObjName cidstr;
  pwr_tAName astr;
  int i;

  if ( argc <= 1) {
    usage();
    exit(1);
  }

  sts = gdh_Init("rt_gdhget");
  if ( EVEN(sts)) {
    exit(sts);
  }

  for ( i = 1; i < argc; i++) {
    c = argv[i];
    if ( *c == '-') {
      c++;
      switch ( *c) {
      case 'h':
	usage();
	exit(0);
     
      case 'c':
	if ( argc <= i+1) {
	  usage();
	  exit(1);
	}
	strncpy( cidstr, argv[i+1], sizeof(cidstr));
	cidopt = 1;
	i++;
	break;
      }
    }
    else
      strcpy( astr, argv[i]);
  }
  
  if ( cidopt) {
    // Get the first object of class cidstr, and print the value of attribute 
    // astr in this object

    pwr_tCid cid;
    pwr_tOid oid;
    pwr_tAttrRef aref, aaref;
    pwr_tTid a_tid;
    unsigned int a_size, a_offs, a_dim;
    void *a_valp;
    char str[256];

    sts = gdh_ClassNameToId( cidstr, &cid);
    if ( EVEN(sts)) {
      exit(sts);
    }

    sts = gdh_GetClassList( cid, &oid);
    if ( EVEN(sts)) {
      exit(sts);
    }

    aref = cdh_ObjidToAref( oid);
    sts = gdh_ArefANameToAref( &aref, astr, &aaref);
    if ( EVEN(sts)) {
      exit(sts);
    }

    sts = gdh_GetAttributeCharAttrref( &aaref, &a_tid, &a_size, &a_offs, &a_dim);
    if ( EVEN(sts)) {
      exit(sts);
    }
    a_valp = calloc( 1, a_size);
    sts = gdh_GetObjectInfoAttrref( &aaref, a_valp, a_size);
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }
    
    sts = cdh_AttrValueToString( a_tid, a_valp, str, sizeof(str));
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }

    printf( "%s\n", str);
    free( a_valp);

    exit(0);

  }
  else {
    // Print the value of the attriute in astr

    pwr_tTypeId a_tid;
    pwr_tUInt32 a_size, a_offs, a_elem;
    void *a_valp;
    char str[256];
    
    sts = gdh_GetAttributeCharacteristics( astr,
					 &a_tid, &a_size, &a_offs, &a_elem);
    if ( EVEN(sts)) {
      exit(sts);
    }
    a_valp = calloc( 1, a_size);

    sts = gdh_GetObjectInfo( astr, a_valp, a_size);
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }
    
    sts = cdh_AttrValueToString( a_tid, a_valp, str, sizeof(str));
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }

    printf( "%s\n", str);
    free( a_valp);

    exit(0);
  }    
  exit(1);
}
Пример #3
0
pwr_tStatus bck_dump( ldh_tSession ldhses, char *filename, char *out)
{
  pwr_tFileName fname;
  FILE *f, *fout;
  BCK_FILEHEAD_STRUCT fh;
  bck_t_cycleheader ch;
  bck_t_writeheader dh;
  char timstr [24];
  int c, d;
  unsigned char *datap, *p;
  int i;
  pwr_tStatus sts;
  int csts;
  char *namep;
  pwr_tAName aname;
  int size;
  int dump = 0;

  // Open file

  dcli_translate_filename( fname, filename);
  f = fopen( fname, "rb");
  if ( !f)
    return LDH__NOSUCHFILE;

  dcli_translate_filename( fname, out);
  fout = fopen( fname, "w");
  if ( !fout)
    return LDH__NOSUCHFILE;

  // Read header and print it

  fseek (f, 0, 0);
  fread (&fh, sizeof fh, 1, f);
  fprintf( fout, "Layout version:       %d\n", fh.version);
  if (fh.version != BCK_FILE_VERSION) {
    printf ("This program is built with header version %d\n", BCK_FILE_VERSION);
    return LDH__BCKVERSION;
  }

  time_AtoAscii(&fh.creationtime, time_eFormat_DateAndTime, timstr, sizeof(timstr));

  fprintf( fout, "Created:              %s\n", timstr);

  for (c=0; c<2; c++) {
    fseek(f, fh.curdata [c], 0);
    fread(&ch, sizeof ch, 1, f);

    /* Work thru the data segments */

    for ( d = 0; d < (int)ch.segments; d++) {
      csts = fread(&dh, sizeof dh, 1, f);
      if (csts != 0) {
	if (dh.namesize > 0) {
	  namep = (char *)malloc(dh.namesize + 1);
	  csts = fread(namep, dh.namesize + 1, 1, f);
	} else 
	  namep = NULL;
	datap = (unsigned char *)malloc(dh.size);
	csts = fread(datap, dh.size, 1, f);
      }
      if (csts == 0) {
	fprintf( fout, "Read error\n");
	break;
      }
	  
      if (dh.valid) {
	if ( dump) {
	  fprintf( fout, "%s%s", cdh_ObjidToString(0, dh.objid, 1), namep);

	  p = datap;
	  for ( i = 0; i < (int)dh.size; i++, p++) {
	    if ((i % 16) == 0) fprintf( fout, "\n	");
	    fprintf( fout, "%02x ", *p);
	  }
	  fprintf( fout, "\n");
	}
	else {
	  sts = ldh_ObjidToName( ldhses, dh.objid, cdh_mName_volumeStrict, aname, sizeof(aname), &size);
	  if ( EVEN(sts))
	    strcpy( aname, cdh_ObjidToString(0, dh.objid, 1));
	  strncat( aname, namep, sizeof(aname));

	  fprintf( fout, "%s", aname);

	  char str[1024];
	  pwr_tAttrRef aref;
	  pwr_eType atype;
	  int printed = 0;
	  sts = ldh_NameToAttrRef( ldhses, aname, &aref);
	  if ( ODD(sts)) {
	    sts = ldh_GetAttrRefType( ldhses, &aref, &atype);
	    if ( ODD(sts)) {
	      sts = cdh_AttrValueToString( atype, datap, str, sizeof(str));
	      if ( ODD(sts)) {
		fprintf( fout, "\n	%s\n", str);
		printed = 1;
	      }
	    }
	  }

	  if ( !printed) {
	    // Print as hex code
	    p = datap;
	    for ( i = 0; i < (int)dh.size; i++, p++) {
	      if ((i % 16) == 0) fprintf( fout, "\n	");
	      fprintf( fout, "%02x ", *p);
	    }
	    fprintf( fout, "\n");
	  }
	}
      }

      free(datap);
      free(namep);
    }
  }

  fclose (f);
  fclose (fout);

  return LDH__SUCCESS;
}
Пример #4
0
pwr_tStatus wb_bck_list::diff( wb_bck_list *lp, char *outfile)
{
  pwr_tFileName fname;
  FILE *fout;
  pwr_tStatus sts;
  int diff_cnt = 0;

  dcli_translate_filename( fname, outfile);
  fout = fopen( fname, "w");
  if ( !fout)
    return LDH__NOSUCHFILE;

  if ( lp)
    fprintf( fout, "Backup difference: 1: %s, 2: %s\n", m_filename, lp->m_filename);
  else
    fprintf( fout, "Backup difference: 1: %s, 2: Workbench\n", m_filename);


  bck_sItem *ip = m_first;
  while (ip) {
    char str[1024];
    char str2[1024];
    pwr_eType atype;
    char *anamep;
    int size;

    sts = ldh_AttrRefToName( m_ldhses, &ip->aref, cdh_mName_volumeStrict, &anamep, &size);
    if ( EVEN(sts)) return sts;

    sts = ldh_GetAttrRefType( m_ldhses, &ip->aref, &atype);
    if ( ODD(sts)) {
      void *value2p;

      bck_sItem *ip2 = lp->find( &ip->aref);
      if ( ip2) {
	value2p = ip2->valuep;

	int is_equal = 0;
	switch ( atype) {
	case pwr_eType_String:
	case pwr_eType_Text:
	  is_equal = strcmp( (const char *)value2p, (const char *)ip->valuep) == 0 ? 1 : 0;
	  break;
	default:
	  is_equal = memcmp( value2p, ip->valuep, ip->size) == 0 ? 1 : 0;
	}
	if ( is_equal) {
	  ip = ip->next;
	  continue;
	}

	sts = cdh_AttrValueToString( atype, value2p, str2, sizeof(str2));
	if ( EVEN(sts))
	  strcpy( str2, "-");
      }      
      else
	strcpy( str2, "-");

      sts = cdh_AttrValueToString( atype, ip->valuep, str, sizeof(str));
      if ( EVEN(sts))
	strcpy( str, "-");

      fprintf( fout, "%s\n", anamep);
      fprintf( fout, "1>	%s\n", str);
      fprintf( fout, "2>	%s\n", str2);
      diff_cnt++;
    }
    
    ip = ip->next;
  }
  if ( diff_cnt)
    fprintf( fout, "%d differences found\n", diff_cnt);
  else
    fprintf( fout, "No differences found\n");

  fclose( fout);

  return LDH__SUCCESS;
}