All pastes #496519 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-05-19 09:00 UTC
rendered paste body
/*



*/
#define uint8 unsigned char

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEBUGPRNT(A) printf(A);

const int SPECIFICATION_VERSION = 0;
const char* POINTER32 = "<L";
const char* POINTER64 = "<Q";
//FILE *fopen(const char *filename, const char *mode);
// int fread( void *buffer, size_t size, size_t num, FILE *stream );

FILE * loadFile (const char* filePath) {
    const char fileHeader[] = "RBLOB";

    /* Meta Infomation */
    char strHeader [5];
    int dbname_len;
    int notes_len;

    long lSize;
    char * buffer;


    // Open the File
    printf("Opening RBLOB file %s ...\n",filePath);
    FILE * rblobFile = fopen(filePath, "rb");

    if (rblobFile == NULL) {
        return NULL;
    }

    // Get the file size
    fseek (rblobFile , 0 , SEEK_END);
    lSize = ftell (rblobFile);
    rewind (rblobFile);

    // allocate memory to contain the whole file.
    buffer = (char*) malloc (lSize);
    if (buffer == NULL) exit (2);

    fgets (strHeader , 6, rblobFile);
    //puts(strHeader);

    //fread (buffer,1,lSize,rblobFile);
    if (strcmp(strHeader,fileHeader)) {
        DEBUGPRNT("Correct Header found")
    }

    printf("\n\n..");
    printf(strHeader);
    printf("..\n\n");

    // Check Database Name Length and get Database Name
    unsigned char dbnamelen_data[3];

    fgets (dbnamelen_data , 3, rblobFile);
    dbname_len = dbnamelen_data[1] + 1;

    unsigned char dbname[dbname_len];
    fgets (dbname , dbname_len, rblobFile);

    //fread(&dbname_len, sizeof(dbname_len), 1, rblobFile); //| dbname_len[1]  <<8;    //fread(dbname_len, 1, 3,rblobFile);
    //*p = dbname_len[0] | dbname_len[1] << 8 | dbname_len[2] << 16 | dbname_len[3] << 24;

    printf("Database '%s' opened, %i records.\n",dbname, 0);

    unsigned char cTemp2;

    for (int x = 0; x < 2; x++) {
        cTemp2 = fgetc (rblobFile);
        printf(":%i",cTemp2);
        //printf("|%c:",cTemp2);
    }

    notes_len = fgetc (rblobFile) + 1;
    fgetc (rblobFile);// gets NULL

    unsigned char notes[notes_len];
    fgets (notes , notes_len, rblobFile);
    printf("\nNotes: %s.\n\n",notes);

    /*
    fgets (buffer , 5, rblobFile);
    printf("%i",buffer);*/
    //printf(buffer)

    /*
    dbdate, notes_len = unpack("<HH", self.rblob.read(4))
    notes = self.rblob.read(notes_len)*/
    /*
    unsigned char cTemp;
    for (int x = 0; x < 100; x++) {
        cTemp = fgetc (rblobFile);
        printf("%c",cTemp);
    }*/

    //dbname_len = unpack("<B", self.rblob.read(1))[0]
    fclose (rblobFile);
    free (buffer);
    //free (fileHeader);
    return rblobFile;
}

int main (int argc, char** argv) {
    FILE * rblobFile;


    printf("librBlob Testing Program (C)\n");
    printf("Specification Version: %i\n", SPECIFICATION_VERSION);

    /*  Check Command Line Arugments */
    if (argc < 3) {
        printf("Invalid Number of Arugments given\n");
        printf("Usage: %s rblobFile rIndexFile\n",argv[0]);

        return 0;
    } else if (argc == 3) {
        rblobFile = loadFile(argv[1]);

        if (rblobFile != NULL) {
            printf("File Loaded");
        } else {
            printf("Failed to open the RBLOB File");
        }
    }

    //fclose (pFile);



    return 0;
}