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.

00171 {
00172 #endif
00173     do_eof(fd);
00174     close(fd);
00175 }

Here is the call graph for this function:

create_xls ( char *  name  ) 

Definition at line 185 of file libbif.c.

00187 {
00188 #endif
00189     int fd;
00190     unlink(name);
00191 #ifdef Windows
00192     fd=open(name,O_BINARY|O_CREAT|O_RDWR,0666);
00193 #else
00194     fd=open(name,O_CREAT|O_RDWR,0666);
00195 #endif
00196     if(fd<0)
00197     {
00198         printf("Error opening file %s\n",name);
00199         exit(-1);
00200     }
00201     do_header(fd);
00202     return(fd);
00203 }

Here is the call graph for this function:

do_eof ( int  fd  ) 

Definition at line 396 of file libbif.c.

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

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.

00274 {
00275 #endif
00276     struct float_record floatrec;
00277     short s_row,s_column;
00278     unsigned char *sptr,*dptr;
00279     s_row=(short)row;
00280     s_column=(short)column;
00281         floatrec.hi_opcode=FLOAT;
00282         floatrec.lo_opcode=0x00;
00283         floatrec.hi_length=0xf;
00284         floatrec.lo_length=0x00;
00285         floatrec.rgbhi=0x0;
00286         floatrec.rgbmed=0x0;
00287         floatrec.rgblo=0x0;
00288         floatrec.hi_row=(char)(s_row&0xff);
00289         floatrec.lo_row=(char)((s_row>>8)&0xff);
00290         floatrec.hi_column=(char)(s_column&0xff);
00291         floatrec.lo_column=(char)((s_column>>8)&0xff);
00292     sptr =(unsigned char *) &value;
00293     dptr =(unsigned char *) &floatrec.data;
00294 
00295     if(endian()==ENDIAN_2) /* Big Endian */
00296     {
00297        dptr[0]=sptr[7]; /* Convert to Little Endian */
00298        dptr[1]=sptr[6];
00299        dptr[2]=sptr[5];
00300        dptr[3]=sptr[4];
00301        dptr[4]=sptr[3];
00302        dptr[5]=sptr[2];
00303        dptr[6]=sptr[1];
00304        dptr[7]=sptr[0];
00305     }
00306     if(endian()==ENDIAN_3)  /* Middle Endian */
00307     {
00308        dptr[0]=sptr[4]; /* 16 bit swapped ARM */
00309        dptr[1]=sptr[5];
00310        dptr[2]=sptr[6];
00311        dptr[3]=sptr[7];
00312        dptr[4]=sptr[0];
00313        dptr[5]=sptr[1];
00314        dptr[6]=sptr[2];
00315        dptr[7]=sptr[3];
00316     }
00317 
00318     if(endian()==ENDIAN_1) /* Little Endian */
00319     {
00320        dptr[0]=sptr[0]; /* Do not convert to Little Endian */
00321        dptr[1]=sptr[1];
00322        dptr[2]=sptr[2];
00323        dptr[3]=sptr[3];
00324        dptr[4]=sptr[4];
00325        dptr[5]=sptr[5];
00326        dptr[6]=sptr[6];
00327        dptr[7]=sptr[7];
00328     }
00329     if(endian()==-1) /* Unsupported architecture */
00330     {
00331        dptr[0]=0;
00332        dptr[1]=0;
00333        dptr[2]=0;
00334        dptr[3]=0;
00335        dptr[4]=0;
00336        dptr[5]=0;
00337        dptr[6]=0;
00338        dptr[7]=0;
00339        printf("Excel output not supported on this architecture.\n");
00340     }
00341     junk=write(fd,&floatrec,11); /* Don't write floatrec. Padding problems */
00342     junk=write(fd,&floatrec.data,8); /* Write value seperately */
00343 }

Here is the call graph for this function:

do_header ( int  fd  ) 

Definition at line 210 of file libbif.c.

00212 {
00213 #endif
00214     struct bof_record bof;
00215     bof.hi_opcode=BOF;
00216     bof.lo_opcode = 0x0;
00217     bof.hi_length=0x4;
00218     bof.lo_length=0x0;
00219     bof.hi_version=EXCEL_VERS;
00220     bof.lo_version=0x0;
00221     bof.hi_filetype=WORKSHEET;
00222     bof.lo_filetype=0x0;
00223     junk=write(fd,&bof,sizeof(struct bof_record));
00224 }

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.

00236 {
00237 #endif
00238     struct int_record intrec;
00239     short s_row,s_column;
00240     s_row=(short)row;
00241     s_column=(short)column;
00242         intrec.hi_opcode=INTEGER;
00243         intrec.lo_opcode=0x00;
00244         intrec.hi_length=0x09;
00245         intrec.lo_length=0x00;
00246         intrec.rgbhi=0x0;
00247         intrec.rgbmed=0x0;
00248         intrec.rgblo=0x0;
00249         intrec.hi_row=(char)s_row&0xff;
00250         intrec.lo_row=(char)(s_row>>8)&0xff;
00251         intrec.hi_column=(char)(s_column&0xff);
00252         intrec.lo_column=(char)(s_column>>8)&0xff;
00253         intrec.hi_data=(val & 0xff);
00254         intrec.lo_data=(val & 0xff00)>>8;
00255     junk=write(fd,&intrec,13);
00256 }

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.

00357 {
00358 #endif
00359     struct label_record labelrec;
00360     short s_row,s_column;
00361     int i;
00362     for(i=0;i<255;i++)
00363         labelrec.str_array[i]=0;
00364     s_row=(short)row;
00365     s_column=(short)column;
00366     i=strlen(string);
00367         labelrec.hi_opcode=LABEL;
00368         labelrec.lo_opcode=0x00;
00369         labelrec.hi_length=0x08; /* 264 total bytes */
00370         labelrec.lo_length=0x01;
00371         labelrec.rgblo=0x0;
00372         labelrec.rgbmed=0x0;
00373         labelrec.rgbhi=0x0;
00374         labelrec.hi_row=(char)(s_row&0xff);
00375         labelrec.lo_row=(char)((s_row>>8)&0xff);
00376         labelrec.hi_column=(char)(s_column&0xff);
00377         labelrec.lo_column=(char)((s_column>>8)&0xff);
00378     labelrec.string_length=i;
00379     if(i > 255) /* If too long then terminate it early */
00380         string[254]=0;
00381     i=strlen(string);
00382     strcpy(labelrec.str_array,string);
00383 
00384     junk=write(fd,&labelrec,sizeof(struct label_record));
00385 
00386 }

Here is the call graph for this function:

int endian ( void   ) 

Definition at line 411 of file libbif.c.

00412 {
00413     long long foo = 0x0102030405060708LL;
00414     long foo1 = 0x012345678;
00415     unsigned char *c,c1,c2,c3,c4,c5,c6,c7,c8;
00416     c=(unsigned char *)&foo;
00417     c1=*c++;
00418     c2=*c++;
00419     c3=*c++;
00420     c4=*c++;
00421     c5=*c++;
00422     c6=*c++;
00423     c7=*c++;
00424     c8=*c;
00425 
00426     /*--------------------------------------------------------------*/
00427     /* printf("%x %x %x %x %x %x %x %x\n",c1,c2,c3,c4,c5,c6,c7,c8); */
00428     /*--------------------------------------------------------------*/
00429 
00430     /* Little Endian format ? ( Intel ) */
00431     if( (c1==0x08) && (c2==0x07) && (c3==0x06) && (c4==0x05) &&
00432         (c5==0x04) && (c6==0x03) && (c7==0x02) && (c8==0x01) )
00433         return(ENDIAN_1);
00434     /* Big Endian format ?    ( Sparc, Risc... */
00435     if( (c1==0x01) && (c2==0x02) && (c3==0x03) && (c4==0x04) &&
00436         (c5==0x05) && (c6==0x06) && (c7==0x07) && (c8==0x08) )
00437         return(ENDIAN_2);
00438     /* Middle Endian format ? ( ARM ... ) */
00439     if( (c1==0x04) && (c2==0x03) && (c3==0x02) && (c4==0x01) &&
00440         (c5==0x08) && (c6==0x07) && (c7==0x06) && (c8==0x05) )
00441         return(ENDIAN_3);
00442     c=(unsigned char *)&foo1;
00443     c1=*c++;
00444     c2=*c++;
00445     c3=*c++;
00446     c4=*c++;
00447     /* Another middle endian format ? ( PDP-11 ... ) */
00448     if( (c1==0x34) && (c2==0x12) && (c3==0x78) && (c4==0x56))
00449         return(ENDIAN_4);
00450 
00451     return(-1);
00452 }

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.


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1