PAPI  5.7.0.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
 

Macros

#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
 

Macro Definition Documentation

◆ BOF

#define BOF   0x9

Definition at line 100 of file libbif.c.

◆ ENDIAN_1

#define ENDIAN_1   1

Definition at line 50 of file libbif.c.

◆ ENDIAN_2

#define ENDIAN_2   2

Definition at line 52 of file libbif.c.

◆ ENDIAN_3

#define ENDIAN_3   3

Definition at line 54 of file libbif.c.

◆ ENDIAN_4

#define ENDIAN_4   4

Definition at line 56 of file libbif.c.

◆ EXCEL_VERS

#define EXCEL_VERS   0x2

Definition at line 104 of file libbif.c.

◆ FLOAT

#define FLOAT   0x3

Definition at line 102 of file libbif.c.

◆ INTEGER

#define INTEGER   0x2

Definition at line 101 of file libbif.c.

◆ LABEL

#define LABEL   0x4

Definition at line 103 of file libbif.c.

◆ WORKSHEET

#define WORKSHEET   0x10

Definition at line 105 of file libbif.c.

Function Documentation

◆ close_xls()

close_xls ( int  fd)

Definition at line 169 of file libbif.c.

171 {
172 #endif
173  do_eof(fd);
174  close(fd);
175 }
int close(int fd)
Definition: appio.c:175
do_eof(int fd)
Definition: libbif.c:396
int fd
Definition: iozone.c:1291
Here is the call graph for this function:

◆ create_xls()

create_xls ( char *  name)

Definition at line 185 of file libbif.c.

187 {
188 #endif
189  int fd;
190  unlink(name);
191 #ifdef Windows
192  fd=open(name,O_BINARY|O_CREAT|O_RDWR,0666);
193 #else
194  fd=open(name,O_CREAT|O_RDWR,0666);
195 #endif
196  if(fd<0)
197  {
198  printf("Error opening file %s\n",name);
199  exit(-1);
200  }
201  do_header(fd);
202  return(fd);
203 }
static const char * name
Definition: fork_overflow.c:31
int fd
Definition: iozone.c:1291
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
do_header(int fd)
Definition: libbif.c:210
int unlink()
void exit()
Here is the call graph for this function:

◆ do_eof()

do_eof ( int  fd)

Definition at line 396 of file libbif.c.

398 {
399 #endif
400  char buf[]={0x0a,0x00,0x00,0x00};
401  junk=write(fd,buf,4);
402 }
int junk
Definition: libbif.c:58
int fd
Definition: iozone.c:1291
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_float()

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

Definition at line 270 of file libbif.c.

274 {
275 #endif
276  struct float_record floatrec;
277  short s_row,s_column;
278  unsigned char *sptr,*dptr;
279  s_row=(short)row;
280  s_column=(short)column;
281  floatrec.hi_opcode=FLOAT;
282  floatrec.lo_opcode=0x00;
283  floatrec.hi_length=0xf;
284  floatrec.lo_length=0x00;
285  floatrec.rgbhi=0x0;
286  floatrec.rgbmed=0x0;
287  floatrec.rgblo=0x0;
288  floatrec.hi_row=(char)(s_row&0xff);
289  floatrec.lo_row=(char)((s_row>>8)&0xff);
290  floatrec.hi_column=(char)(s_column&0xff);
291  floatrec.lo_column=(char)((s_column>>8)&0xff);
292  sptr =(unsigned char *) &value;
293  dptr =(unsigned char *) &floatrec.data;
294 
295  if(endian()==ENDIAN_2) /* Big Endian */
296  {
297  dptr[0]=sptr[7]; /* Convert to Little Endian */
298  dptr[1]=sptr[6];
299  dptr[2]=sptr[5];
300  dptr[3]=sptr[4];
301  dptr[4]=sptr[3];
302  dptr[5]=sptr[2];
303  dptr[6]=sptr[1];
304  dptr[7]=sptr[0];
305  }
306  if(endian()==ENDIAN_3) /* Middle Endian */
307  {
308  dptr[0]=sptr[4]; /* 16 bit swapped ARM */
309  dptr[1]=sptr[5];
310  dptr[2]=sptr[6];
311  dptr[3]=sptr[7];
312  dptr[4]=sptr[0];
313  dptr[5]=sptr[1];
314  dptr[6]=sptr[2];
315  dptr[7]=sptr[3];
316  }
317 
318  if(endian()==ENDIAN_1) /* Little Endian */
319  {
320  dptr[0]=sptr[0]; /* Do not convert to Little Endian */
321  dptr[1]=sptr[1];
322  dptr[2]=sptr[2];
323  dptr[3]=sptr[3];
324  dptr[4]=sptr[4];
325  dptr[5]=sptr[5];
326  dptr[6]=sptr[6];
327  dptr[7]=sptr[7];
328  }
329  if(endian()==-1) /* Unsupported architecture */
330  {
331  dptr[0]=0;
332  dptr[1]=0;
333  dptr[2]=0;
334  dptr[3]=0;
335  dptr[4]=0;
336  dptr[5]=0;
337  dptr[6]=0;
338  dptr[7]=0;
339  printf("Excel output not supported on this architecture.\n");
340  }
341  junk=write(fd,&floatrec,11); /* Don't write floatrec. Padding problems */
342  junk=write(fd,&floatrec.data,8); /* Write value seperately */
343 }
#define FLOAT
Definition: libbif.c:102
int junk
Definition: libbif.c:58
int fd
Definition: iozone.c:1291
char hi_opcode
Definition: libbif.c:148
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
#define ENDIAN_3
Definition: libbif.c:54
#define ENDIAN_1
Definition: libbif.c:50
#define ENDIAN_2
Definition: libbif.c:52
int endian(void)
Definition: libbif.c:411
Here is the call graph for this function:

◆ do_header()

do_header ( int  fd)

Definition at line 210 of file libbif.c.

212 {
213 #endif
214  struct bof_record bof;
215  bof.hi_opcode=BOF;
216  bof.lo_opcode = 0x0;
217  bof.hi_length=0x4;
218  bof.lo_length=0x0;
219  bof.hi_version=EXCEL_VERS;
220  bof.lo_version=0x0;
221  bof.hi_filetype=WORKSHEET;
222  bof.lo_filetype=0x0;
223  junk=write(fd,&bof,sizeof(struct bof_record));
224 }
int junk
Definition: libbif.c:58
int fd
Definition: iozone.c:1291
#define BOF
Definition: libbif.c:100
#define WORKSHEET
Definition: libbif.c:105
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
char hi_opcode
Definition: libbif.c:108
#define EXCEL_VERS
Definition: libbif.c:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_int()

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

Definition at line 234 of file libbif.c.

236 {
237 #endif
238  struct int_record intrec;
239  short s_row,s_column;
240  s_row=(short)row;
241  s_column=(short)column;
242  intrec.hi_opcode=INTEGER;
243  intrec.lo_opcode=0x00;
244  intrec.hi_length=0x09;
245  intrec.lo_length=0x00;
246  intrec.rgbhi=0x0;
247  intrec.rgbmed=0x0;
248  intrec.rgblo=0x0;
249  intrec.hi_row=(char)s_row&0xff;
250  intrec.lo_row=(char)(s_row>>8)&0xff;
251  intrec.hi_column=(char)(s_column&0xff);
252  intrec.lo_column=(char)(s_column>>8)&0xff;
253  intrec.hi_data=(val & 0xff);
254  intrec.lo_data=(val & 0xff00)>>8;
255  junk=write(fd,&intrec,13);
256 }
int junk
Definition: libbif.c:58
int fd
Definition: iozone.c:1291
char hi_opcode
Definition: libbif.c:118
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
#define INTEGER
Definition: libbif.c:101
static int val[12]
Definition: activity.c:47
Here is the call graph for this function:

◆ do_label()

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

Definition at line 353 of file libbif.c.

357 {
358 #endif
359  struct label_record labelrec;
360  short s_row,s_column;
361  int i;
362  for(i=0;i<255;i++)
363  labelrec.str_array[i]=0;
364  s_row=(short)row;
365  s_column=(short)column;
366  i=strlen(string);
367  labelrec.hi_opcode=LABEL;
368  labelrec.lo_opcode=0x00;
369  labelrec.hi_length=0x08; /* 264 total bytes */
370  labelrec.lo_length=0x01;
371  labelrec.rgblo=0x0;
372  labelrec.rgbmed=0x0;
373  labelrec.rgbhi=0x0;
374  labelrec.hi_row=(char)(s_row&0xff);
375  labelrec.lo_row=(char)((s_row>>8)&0xff);
376  labelrec.hi_column=(char)(s_column&0xff);
377  labelrec.lo_column=(char)((s_column>>8)&0xff);
378  labelrec.string_length=i;
379  if(i > 255) /* If too long then terminate it early */
380  string[254]=0;
381  i=strlen(string);
382  strcpy(labelrec.str_array,string);
383 
384  junk=write(fd,&labelrec,sizeof(struct label_record));
385 
386 }
int junk
Definition: libbif.c:58
int fd
Definition: iozone.c:1291
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
int i
Definition: fileop.c:140
#define LABEL
Definition: libbif.c:103
Here is the call graph for this function:

◆ endian()

int endian ( void  )

Definition at line 411 of file libbif.c.

412 {
413  long long foo = 0x0102030405060708LL;
414  long foo1 = 0x012345678;
415  unsigned char *c,c1,c2,c3,c4,c5,c6,c7,c8;
416  c=(unsigned char *)&foo;
417  c1=*c++;
418  c2=*c++;
419  c3=*c++;
420  c4=*c++;
421  c5=*c++;
422  c6=*c++;
423  c7=*c++;
424  c8=*c;
425 
426  /*--------------------------------------------------------------*/
427  /* printf("%x %x %x %x %x %x %x %x\n",c1,c2,c3,c4,c5,c6,c7,c8); */
428  /*--------------------------------------------------------------*/
429 
430  /* Little Endian format ? ( Intel ) */
431  if( (c1==0x08) && (c2==0x07) && (c3==0x06) && (c4==0x05) &&
432  (c5==0x04) && (c6==0x03) && (c7==0x02) && (c8==0x01) )
433  return(ENDIAN_1);
434  /* Big Endian format ? ( Sparc, Risc... */
435  if( (c1==0x01) && (c2==0x02) && (c3==0x03) && (c4==0x04) &&
436  (c5==0x05) && (c6==0x06) && (c7==0x07) && (c8==0x08) )
437  return(ENDIAN_2);
438  /* Middle Endian format ? ( ARM ... ) */
439  if( (c1==0x04) && (c2==0x03) && (c3==0x02) && (c4==0x01) &&
440  (c5==0x08) && (c6==0x07) && (c7==0x06) && (c8==0x05) )
441  return(ENDIAN_3);
442  c=(unsigned char *)&foo1;
443  c1=*c++;
444  c2=*c++;
445  c3=*c++;
446  c4=*c++;
447  /* Another middle endian format ? ( PDP-11 ... ) */
448  if( (c1==0x34) && (c2==0x12) && (c3==0x78) && (c4==0x56))
449  return(ENDIAN_4);
450 
451  return(-1);
452 }
double c
Definition: multiplex.c:22
#define ENDIAN_4
Definition: libbif.c:56
#define ENDIAN_3
Definition: libbif.c:54
#define ENDIAN_1
Definition: libbif.c:50
#define ENDIAN_2
Definition: libbif.c:52
Here is the caller graph for this function:

Variable Documentation

◆ junk

int junk

Definition at line 58 of file libbif.c.

◆ junkp

int * junkp

Definition at line 58 of file libbif.c.