PAPI  5.0.1.0
libbif.c File Reference
Include dependency graph for libbif.c:

Go to the source code of this file.

Data Structures

struct  bof_record
struct  int_record
struct  label_record
struct  float_record

Defines

#define ENDIAN_1   1
#define ENDIAN_2   2
#define ENDIAN_3   3
#define ENDIAN_4   4
#define BOF   0x9
#define INTEGER   0x2
#define FLOAT   0x3
#define LABEL   0x4
#define EXCEL_VERS   0x2
#define WORKSHEET   0x10

Functions

 close_xls (int fd)
 create_xls (char *name)
 do_header (int fd)
 do_int (int fd, int val, int row, int column)
 do_float (int fd, double value, int row, int column)
 do_label (int fd, char *string, int row, int column)
 do_eof (int fd)
int endian (void)

Variables

int junk
int * junkp

Define Documentation

#define BOF   0x9

Definition at line 100 of file libbif.c.

#define ENDIAN_1   1

Definition at line 50 of file libbif.c.

#define ENDIAN_2   2

Definition at line 52 of file libbif.c.

#define ENDIAN_3   3

Definition at line 54 of file libbif.c.

#define ENDIAN_4   4

Definition at line 56 of file libbif.c.

#define EXCEL_VERS   0x2

Definition at line 104 of file libbif.c.

#define FLOAT   0x3

Definition at line 102 of file libbif.c.

#define INTEGER   0x2

Definition at line 101 of file libbif.c.

#define LABEL   0x4

Definition at line 103 of file libbif.c.

#define WORKSHEET   0x10

Definition at line 105 of file libbif.c.


Function Documentation

close_xls ( int  fd)

Definition at line 169 of file libbif.c.

{
#endif
    do_eof(fd);
    close(fd);
}

Here is the call graph for this function:

create_xls ( char *  name)

Definition at line 185 of file libbif.c.

{
#endif
    int fd;
    unlink(name);
#ifdef Windows
    fd=open(name,O_BINARY|O_CREAT|O_RDWR,0666);
#else
    fd=open(name,O_CREAT|O_RDWR,0666);
#endif
    if(fd<0)
    {
        printf("Error opening file %s\n",name);
        exit(-1);
    }
    do_header(fd);
    return(fd);
}

Here is the call graph for this function:

do_eof ( int  fd)

Definition at line 396 of file libbif.c.

{
#endif
    char buf[]={0x0a,0x00,0x00,0x00};
    junk=write(fd,buf,4);
}

Here is the call graph for this function:

Here is the caller graph for this function:

do_float ( int  fd,
double  value,
int  row,
int  column 
)

Definition at line 270 of file libbif.c.

{
#endif
    struct float_record floatrec;
    short s_row,s_column;
    unsigned char *sptr,*dptr;
    s_row=(short)row;
    s_column=(short)column;
        floatrec.hi_opcode=FLOAT;
        floatrec.lo_opcode=0x00;
        floatrec.hi_length=0xf;
        floatrec.lo_length=0x00;
        floatrec.rgbhi=0x0;
        floatrec.rgbmed=0x0;
        floatrec.rgblo=0x0;
        floatrec.hi_row=(char)(s_row&0xff);
        floatrec.lo_row=(char)((s_row>>8)&0xff);
        floatrec.hi_column=(char)(s_column&0xff);
        floatrec.lo_column=(char)((s_column>>8)&0xff);
    sptr =(unsigned char *) &value;
    dptr =(unsigned char *) &floatrec.data;

    if(endian()==ENDIAN_2) /* Big Endian */
    {
       dptr[0]=sptr[7]; /* Convert to Little Endian */
       dptr[1]=sptr[6];
       dptr[2]=sptr[5];
       dptr[3]=sptr[4];
       dptr[4]=sptr[3];
       dptr[5]=sptr[2];
       dptr[6]=sptr[1];
       dptr[7]=sptr[0];
    }
    if(endian()==ENDIAN_3)  /* Middle Endian */
    {
       dptr[0]=sptr[4]; /* 16 bit swapped ARM */
       dptr[1]=sptr[5];
       dptr[2]=sptr[6];
       dptr[3]=sptr[7];
       dptr[4]=sptr[0];
       dptr[5]=sptr[1];
       dptr[6]=sptr[2];
       dptr[7]=sptr[3];
    }

    if(endian()==ENDIAN_1) /* Little Endian */
    {
       dptr[0]=sptr[0]; /* Do not convert to Little Endian */
       dptr[1]=sptr[1];
       dptr[2]=sptr[2];
       dptr[3]=sptr[3];
       dptr[4]=sptr[4];
       dptr[5]=sptr[5];
       dptr[6]=sptr[6];
       dptr[7]=sptr[7];
    }
    if(endian()==-1) /* Unsupported architecture */
    {
       dptr[0]=0;
       dptr[1]=0;
       dptr[2]=0;
       dptr[3]=0;
       dptr[4]=0;
       dptr[5]=0;
       dptr[6]=0;
       dptr[7]=0;
       printf("Excel output not supported on this architecture.\n");
    }
    junk=write(fd,&floatrec,11); /* Don't write floatrec. Padding problems */
    junk=write(fd,&floatrec.data,8); /* Write value seperately */
}

Here is the call graph for this function:

do_header ( int  fd)

Definition at line 210 of file libbif.c.

{
#endif
    struct bof_record bof;
    bof.hi_opcode=BOF;
    bof.lo_opcode = 0x0;
    bof.hi_length=0x4;
    bof.lo_length=0x0;
    bof.hi_version=EXCEL_VERS;
    bof.lo_version=0x0;
    bof.hi_filetype=WORKSHEET;
    bof.lo_filetype=0x0;
    junk=write(fd,&bof,sizeof(struct bof_record));
}

Here is the call graph for this function:

Here is the caller graph for this function:

do_int ( int  fd,
int  val,
int  row,
int  column 
)

Definition at line 234 of file libbif.c.

{
#endif
    struct int_record intrec;
    short s_row,s_column;
    s_row=(short)row;
    s_column=(short)column;
        intrec.hi_opcode=INTEGER;
        intrec.lo_opcode=0x00;
        intrec.hi_length=0x09;
        intrec.lo_length=0x00;
        intrec.rgbhi=0x0;
        intrec.rgbmed=0x0;
        intrec.rgblo=0x0;
        intrec.hi_row=(char)s_row&0xff;
        intrec.lo_row=(char)(s_row>>8)&0xff;
        intrec.hi_column=(char)(s_column&0xff);
        intrec.lo_column=(char)(s_column>>8)&0xff;
        intrec.hi_data=(val & 0xff);
        intrec.lo_data=(val & 0xff00)>>8;
    junk=write(fd,&intrec,13);
}

Here is the call graph for this function:

do_label ( int  fd,
char *  string,
int  row,
int  column 
)

Definition at line 353 of file libbif.c.

{
#endif
    struct label_record labelrec;
    short s_row,s_column;
    int i;
    for(i=0;i<255;i++)
        labelrec.str_array[i]=0;
    s_row=(short)row;
    s_column=(short)column;
    i=strlen(string);
        labelrec.hi_opcode=LABEL;
        labelrec.lo_opcode=0x00;
        labelrec.hi_length=0x08; /* 264 total bytes */
        labelrec.lo_length=0x01;
        labelrec.rgblo=0x0;
        labelrec.rgbmed=0x0;
        labelrec.rgbhi=0x0;
        labelrec.hi_row=(char)(s_row&0xff);
        labelrec.lo_row=(char)((s_row>>8)&0xff);
        labelrec.hi_column=(char)(s_column&0xff);
        labelrec.lo_column=(char)((s_column>>8)&0xff);
    labelrec.string_length=i;
    if(i > 255) /* If too long then terminate it early */
        string[254]=0;
    i=strlen(string);
    strcpy(labelrec.str_array,string);

    junk=write(fd,&labelrec,sizeof(struct label_record));

}

Here is the call graph for this function:

int endian ( void  )

Definition at line 411 of file libbif.c.

{
    long long foo = 0x0102030405060708LL;
    long foo1 = 0x012345678;
    unsigned char *c,c1,c2,c3,c4,c5,c6,c7,c8;
    c=(unsigned char *)&foo;
    c1=*c++;
    c2=*c++;
    c3=*c++;
    c4=*c++;
    c5=*c++;
    c6=*c++;
    c7=*c++;
    c8=*c;

    /*--------------------------------------------------------------*/
    /* printf("%x %x %x %x %x %x %x %x\n",c1,c2,c3,c4,c5,c6,c7,c8); */
    /*--------------------------------------------------------------*/

    /* Little Endian format ? ( Intel ) */
    if( (c1==0x08) && (c2==0x07) && (c3==0x06) && (c4==0x05) &&
        (c5==0x04) && (c6==0x03) && (c7==0x02) && (c8==0x01) )
        return(ENDIAN_1);
    /* Big Endian format ?    ( Sparc, Risc... */
    if( (c1==0x01) && (c2==0x02) && (c3==0x03) && (c4==0x04) &&
        (c5==0x05) && (c6==0x06) && (c7==0x07) && (c8==0x08) )
        return(ENDIAN_2);
    /* Middle Endian format ? ( ARM ... ) */
    if( (c1==0x04) && (c2==0x03) && (c3==0x02) && (c4==0x01) &&
        (c5==0x08) && (c6==0x07) && (c7==0x06) && (c8==0x05) )
        return(ENDIAN_3);
    c=(unsigned char *)&foo1;
    c1=*c++;
    c2=*c++;
    c3=*c++;
    c4=*c++;
    /* Another middle endian format ? ( PDP-11 ... ) */
    if( (c1==0x34) && (c2==0x12) && (c3==0x78) && (c4==0x56))
        return(ENDIAN_4);

    return(-1);
}

Here is the caller graph for this function:


Variable Documentation

int junk

Definition at line 58 of file libbif.c.

int * junkp

Definition at line 58 of file libbif.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines