summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/Excel.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-sheet/Excel.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/Excel.cpp83
1 files changed, 65 insertions, 18 deletions
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp
index fc49d56..57aef20 100644
--- a/noncore/apps/opie-sheet/Excel.cpp
+++ b/noncore/apps/opie-sheet/Excel.cpp
@@ -1,4 +1,33 @@
1/*
2 =. This file is part of the Opie Project
3 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
4 .>+-=
5 _;:, .> :=|. This program is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU General Public
8.="- .-=="i, .._ License as published by the Free Software
9 - . .-<_> .<> Foundation; either version 2 of the License,
10 ._= =} : or (at your option) any later version.
11 .%`+i> _;_.
12 .i_,=:_. -<s. This program is distributed in the hope that
13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
14 : .. .:, . . . without even the implied warranty of
15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.= = ; Library General Public License for more
18++= -. .` .: details.
19 : = ...= . :.=-
20 -. .:....=;==+<; You should have received a copy of the GNU
21 -_. . . )=. = Library General Public License along with
22 -- :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
1 28
29#include "Excel.h"
2 30
31/* STD */
3#include <stdio.h> 32#include <stdio.h>
4#include <stdlib.h> 33#include <stdlib.h>
@@ -7,5 +36,4 @@
7#include <sys/types.h> 36#include <sys/types.h>
8#include <strings.h> 37#include <strings.h>
9#include "Excel.h"
10 38
11static xfrecord formatter[] = { 39static xfrecord formatter[] = {
@@ -64,5 +92,6 @@ int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4)
64}; 92};
65 93
66int ExcelBook::Integer2ByteFile(FILE *f) { 94int ExcelBook::Integer2ByteFile(FILE *f)
95{
67 int i1, i2; 96 int i1, i2;
68 i1 = fgetc(f); 97 i1 = fgetc(f);
@@ -103,5 +132,6 @@ double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4)
103 }; 132 };
104 return value; 133 return value;
105 }else 134 }
135 else
106 { 136 {
107 137
@@ -133,8 +163,11 @@ void ExcelBook::DetectEndian(void)
133 unsigned char* a = (unsigned char*) &i; 163 unsigned char* a = (unsigned char*) &i;
134 end = (*a != 0x11); 164 end = (*a != 0x11);
135 if (end == 1) { 165 if (end == 1)
166 {
136 endian = BIG_ENDIAN; 167 endian = BIG_ENDIAN;
137 printf("BIGENDIAN!\r\n"); 168 printf("BIGENDIAN!\r\n");
138 } else { 169 }
170 else
171 {
139 endian = LITTLE_ENDIAN; 172 endian = LITTLE_ENDIAN;
140 printf("LITTLEENDIAN!\r\n"); 173 printf("LITTLEENDIAN!\r\n");
@@ -149,10 +182,13 @@ double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, in
149 ieee = (unsigned char *)&d; 182 ieee = (unsigned char *)&d;
150 for (i = 0; i < 8; i++) ieee[i] = 0; 183 for (i = 0; i < 8; i++) ieee[i] = 0;
151 if (endian == BIG_ENDIAN) { 184 if (endian == BIG_ENDIAN)
185 {
152 ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; 186 ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff;
153 ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; 187 ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff;
154 ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; 188 ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff;
155 ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; 189 ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff;
156 } else { 190 }
191 else
192 {
157 ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; 193 ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff;
158 ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; 194 ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff;
@@ -394,5 +430,6 @@ int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record)
394 sheet->rows = Integer2Byte(data[2], data[3]); 430 sheet->rows = Integer2Byte(data[2], data[3]);
395 sheet->cols = Integer2Byte(data[6], data[7]); 431 sheet->cols = Integer2Byte(data[6], data[7]);
396 } else 432 }
433 else
397 { 434 {
398 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); 435 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]);
@@ -603,5 +640,6 @@ void ExcelBook::HandleBoundSheet(ExcelBREC* rec)
603 //ascii 640 //ascii
604 name=GetASCII(data,pos,length); 641 name=GetASCII(data,pos,length);
605 }else 642 }
643 else
606 { 644 {
607 name=GetUnicode(data,pos,length); 645 name=GetUnicode(data,pos,length);
@@ -809,9 +847,11 @@ QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col)
809 { 847 {
810 strftime(str,1024,dateformat.ascii(),tmptr); 848 strftime(str,1024,dateformat.ascii(),tmptr);
811 } else 849 }
850 else
812 { 851 {
813 strftime(str,1024,format.ascii(),tmptr); 852 strftime(str,1024,format.ascii(),tmptr);
814 }; 853 };
815 } else 854 }
855 else
816 if (XFRecords[c->xfindex]->type == NUMBERFORMAT) 856 if (XFRecords[c->xfindex]->type == NUMBERFORMAT)
817 { 857 {
@@ -822,5 +862,6 @@ QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col)
822 precision = CellGetPrecision(c->valued); 862 precision = CellGetPrecision(c->valued);
823 sprintf(str,"%.*f",precision,c->valued); 863 sprintf(str,"%.*f",precision,c->valued);
824 }else 864 }
865 else
825 { 866 {
826 precision = CellGetPrecision(c->valued); 867 precision = CellGetPrecision(c->valued);
@@ -1003,9 +1044,11 @@ void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record)
1003 { 1044 {
1004 // string 1045 // string
1005 } else 1046 }
1047 else
1006 if (data[6] == 1 && data[12] == -1 && data[13] == -1) 1048 if (data[6] == 1 && data[12] == -1 && data[13] == -1)
1007 { 1049 {
1008 // boolean 1050 // boolean
1009 } else 1051 }
1052 else
1010 if ( data[6] == 2 && data[12] == -1 && data[13] == -1) 1053 if ( data[6] == 2 && data[12] == -1 && data[13] == -1)
1011 { 1054 {
@@ -1124,5 +1167,6 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i
1124 s1=QString("""")+s1+QString(""""); 1167 s1=QString("""")+s1+QString("""");
1125 operands.prepend(new QString(s1)); 1168 operands.prepend(new QString(s1));
1126 }else 1169 }
1170 else
1127 { 1171 {
1128 w1=data[idx];idx++; 1172 w1=data[idx];idx++;
@@ -1143,5 +1187,6 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i
1143 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1 1187 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1
1144 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2 1188 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2
1145 }else 1189 }
1190 else
1146 { 1191 {
1147 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1 1192 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1
@@ -1162,5 +1207,6 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i
1162 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row 1207 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row
1163 w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col 1208 w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col
1164 }else 1209 }
1210 else
1165 { 1211 {
1166 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row 1212 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row
@@ -1333,5 +1379,6 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i
1333 w2=(int)data[idx];idx++; 1379 w2=(int)data[idx];idx++;
1334 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1380 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1335 }else 1381 }
1382 else
1336 { 1383 {
1337 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1384 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;