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) {
37 rowptr[row].cells=realloc(rowptr[row].cells,newcol*sizeof(char *));
38 if (rowptr[row].cells == NULL) {
39 perror("allocating row");
42 memset(rowptr[row].cells+rowptr[row].end,0,(newcol-rowptr[row].end)
44 rowptr[row].end=newcol;
46 if (col>rowptr[row].last) rowptr[row].last=col;
47 return (rowptr[row].cells+col);
50 * Frees up all memory used by sheet
52 void free_sheet(void) {
56 for (row=rowptr,i=0;i<lastrow;i++,row++) {
57 if (!row->cells) continue;
58 for (col=row->cells,j=0;j<row->end;j++,col++) {
71 * prints out one value with quoting
72 * uses global variable quote_mode
74 void print_value(unsigned char *value)
79 len=strlen((char *)value);
86 case QUOTE_SPACES_ONLY:
88 if (isspace(value[i]) || value[i]==cell_separator ||
95 case QUOTE_ALL_STRINGS:
97 strtod(value,&endptr);
98 quotes=(*endptr != '0');
101 case QUOTE_EVERYTHING:
107 for (i=0;i<len;i++) {
108 if (value[i]=='\"') {
112 fputc(value[i],stdout);
117 fputs((char *)value,stdout);
121 * Prints sheet to stdout. Uses global variable cell_separator
123 void print_sheet(void) {
125 struct rowdescr *row;
128 while (lastrow>0&&!rowptr[lastrow].cells) lastrow--;
129 for(i=0,row=rowptr;i<=lastrow;i++,row++) {
131 for (j=0,col=row->cells;j<=row->last;j++,col++) {
133 fputc(cell_separator,stdout);
147 fputs(sheet_separator,stdout);