1 /*****************************************************************/
2 /* Representation and handling of Excell worksheets in memory */
4 /* This file is part of catdoc project */
5 /* (c) Victor Wagner 1998-2003, (c) Alex Ott 2003 */
6 /*****************************************************************/
14 struct rowdescr *rowptr=NULL;
15 int startrow=0,lastrow=0;
16 char cell_separator = ',';
17 int quote_mode = QUOTE_ALL_STRINGS;
18 char *sheet_separator = "\f";
20 * Allocates cell for given row and col and returns pointer to poitrer
23 unsigned char **allocate (int row,int col) {
24 unsigned int newrow,newcol;
27 rowptr=realloc(rowptr,newrow*sizeof(struct rowdescr));
29 perror("allocating sheet ");
32 memset(rowptr+lastrow,0,(newrow-lastrow)*sizeof(struct rowdescr));
35 if (col>=rowptr[row].end) {
38 (unsigned char**)realloc(rowptr[row].cells,
39 newcol*sizeof(unsigned char *));
40 if (rowptr[row].cells == NULL) {
41 perror("allocating row");
44 memset(rowptr[row].cells+rowptr[row].end,0,(newcol-rowptr[row].end)
46 rowptr[row].end=newcol;
48 if (col>rowptr[row].last) rowptr[row].last=col;
49 return (rowptr[row].cells+col);
52 * Frees up all memory used by sheet
54 void free_sheet(void) {
58 for (row=rowptr,i=0;i<lastrow;i++,row++) {
59 if (!row->cells) continue;
60 for (col=row->cells,j=0;j<row->end;j++,col++) {
73 * prints out one value with quoting
74 * uses global variable quote_mode
76 void print_value(unsigned char *value)
81 len=strlen((char *)value);
88 case QUOTE_SPACES_ONLY:
90 if (isspace(value[i]) || value[i]==cell_separator ||
97 case QUOTE_ALL_STRINGS:
99 strtod((char *)value,&endptr);
100 quotes=(*endptr != '0');
103 case QUOTE_EVERYTHING:
109 for (i=0;i<len;i++) {
110 if (value[i]=='\"') {
114 fputc(value[i],stdout);
119 fputs((char *)value,stdout);
123 * Prints sheet to stdout. Uses global variable cell_separator
125 void print_sheet(void) {
127 struct rowdescr *row;
130 while (lastrow>0&&!rowptr[lastrow].cells) lastrow--;
131 for(i=0,row=rowptr;i<=lastrow;i++,row++) {
133 for (j=0,col=row->cells;j<=row->last;j++,col++) {
135 fputc(cell_separator,stdout);
149 fputs(sheet_separator,stdout);