tags:

views:

82

answers:

1

I have some C++ code from somewhere that reads and writes data in binary format. I want to see what it's reading and writing in the file, so I want to convert it's binary read and write to non-binary read and write. Also, when I convert the binary write to non-binary write, I want it to still be able to read in the information correctly. How can this be done?

The write function:

int btwrite(short rrn, BTPAGE *page_ptr)
{
//    long lseek(), addr;
    long addr;
    addr = (long) rrn * (long) PAGESIZE + HEADERSIZE;
    lseek(btfd, addr, 0);
    return (write(btfd, page_ptr, PAGESIZE));
}

The read function:

int btread(short rrn, BTPAGE *page_ptr)
{
//  long lseek(), addr;
    long addr;

    addr = (long)rrn * (long)PAGESIZE + HEADERSIZE;
    lseek(btfd, addr, 0);
    return ( read(btfd, page_ptr, PAGESIZE) );
}

Here is the definition of BTPAGE:

typedef struct {
    short keycount;             /* number of keys in page   */
    int  key[MAXKEYS];              /* the actual keys      */
    short child[MAXKEYS+1];     /* ptrs to rrns of descendants  */
} BTPAGE;
+1  A: 

In C++, add an overloaded stream insertion operator to the BTPAGE class. After you read the BTPage, add the following:

  cout << *page_ptr << endl;

Otherwise you will have to edit your questions with more details about what you are looking for. For example:

  1. Do you want the data read to be output in 1's and 0's?
  2. Do you want a byte by byte dump?

Also, please provide the declaration of BTPAGE.

Thomas Matthews
I don't want to see binary I want to see actual values before they are converted to binary and written to disk.
Phenom