Diffstat (limited to 'noncore/apps/opie-sheet/Excel.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 83 |
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,12 +1,40 @@ | |||
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> |
5 | #include <math.h> | 34 | #include <math.h> |
6 | #include <time.h> | 35 | #include <time.h> |
7 | #include <sys/types.h> | 36 | #include <sys/types.h> |
8 | #include <strings.h> | 37 | #include <strings.h> |
9 | #include "Excel.h" | ||
10 | 38 | ||
11 | static xfrecord formatter[] = { | 39 | static xfrecord formatter[] = { |
12 | { 0xe , DATEFORMAT, "%m/%d/%y"}, | 40 | { 0xe , DATEFORMAT, "%m/%d/%y"}, |
@@ -63,7 +91,8 @@ int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) | |||
63 | return val; | 91 | return val; |
64 | }; | 92 | }; |
65 | 93 | ||
66 | int ExcelBook::Integer2ByteFile(FILE *f) { | 94 | int ExcelBook::Integer2ByteFile(FILE *f) |
95 | { | ||
67 | int i1, i2; | 96 | int i1, i2; |
68 | i1 = fgetc(f); | 97 | i1 = fgetc(f); |
69 | i2 = fgetc(f); | 98 | i2 = fgetc(f); |
@@ -102,7 +131,8 @@ double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) | |||
102 | value /= 100.0; | 131 | value /= 100.0; |
103 | }; | 132 | }; |
104 | return value; | 133 | return value; |
105 | }else | 134 | } |
135 | else | ||
106 | { | 136 | { |
107 | 137 | ||
108 | union { double d; unsigned long int b[2]; } dbl_byte; | 138 | union { double d; unsigned long int b[2]; } dbl_byte; |
@@ -132,10 +162,13 @@ void ExcelBook::DetectEndian(void) | |||
132 | long i = 0x44332211; | 162 | long i = 0x44332211; |
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"); |
141 | } | 174 | } |
@@ -148,12 +181,15 @@ double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, in | |||
148 | unsigned char *ieee; | 181 | unsigned char *ieee; |
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; |
159 | ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; | 195 | ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; |
@@ -393,7 +429,8 @@ int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) | |||
393 | { | 429 | { |
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]); |
399 | sheet->cols = Integer2Byte(data[10], data[11]); | 436 | sheet->cols = Integer2Byte(data[10], data[11]); |
@@ -602,7 +639,8 @@ void ExcelBook::HandleBoundSheet(ExcelBREC* rec) | |||
602 | { | 639 | { |
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); |
608 | }; | 646 | }; |
@@ -808,11 +846,13 @@ QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) | |||
808 | if (dateformat) | 846 | if (dateformat) |
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 | { |
818 | format = XFRecords[c->xfindex]->format; | 858 | format = XFRecords[c->xfindex]->format; |
@@ -821,7 +861,8 @@ QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) | |||
821 | // because there is more work to be done in the field | 861 | // because there is more work to be done in the field |
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); |
827 | sprintf(str,"%.*f",precision,c->valued); | 868 | sprintf(str,"%.*f",precision,c->valued); |
@@ -1002,11 +1043,13 @@ void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record) | |||
1002 | if (data[6] == 0 && data[12] == -1 && data[13] == -1) | 1043 | if (data[6] == 0 && data[12] == -1 && data[13] == -1) |
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 | { |
1012 | // error | 1055 | // error |
@@ -1123,7 +1166,8 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i | |||
1123 | }; | 1166 | }; |
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++; |
1129 | s1=GetASCII(data,idx,w1); | 1173 | s1=GetASCII(data,idx,w1); |
@@ -1142,7 +1186,8 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i | |||
1142 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 | 1186 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 |
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 |
1148 | w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 | 1193 | w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 |
@@ -1161,7 +1206,8 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i | |||
1161 | { | 1206 | { |
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 |
1167 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col | 1213 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col |
@@ -1332,7 +1378,8 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i | |||
1332 | { | 1378 | { |
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; |
1338 | }; | 1385 | }; |