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,15 +1,43 @@ +/* + =. This file is part of the Opie Project + .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ +#include "Excel.h" +/* STD */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <sys/types.h> #include <strings.h> -#include "Excel.h" static xfrecord formatter[] = { { 0xe , DATEFORMAT, "%m/%d/%y"}, { 0xf , DATEFORMAT, "%d-%b-%y"}, { 0x10, DATEFORMAT, "%d-%b"}, { 0x11, DATEFORMAT, "%b-%y"}, @@ -60,13 +88,14 @@ int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) int i1 = Integer2Byte(b1, b2); int i2 = Integer2Byte(b3, b4); int val = i2 << 16 | i1; return val; }; -int ExcelBook::Integer2ByteFile(FILE *f) { +int ExcelBook::Integer2ByteFile(FILE *f) +{ int i1, i2; i1 = fgetc(f); i2 = fgetc(f); return Integer2Byte(i1,i2); }; @@ -99,13 +128,14 @@ double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) printf("Double4Byte: VALUEINT=%f\r\n",value); if ( (rk & 0x01) != 0) { value /= 100.0; }; return value; - }else + } + else { union { double d; unsigned long int b[2]; } dbl_byte; unsigned long int valbits = (rk & 0xfffffffc); #if defined(__arm__) && !defined(__vfp__) dbl_byte.b[0]=valbits; @@ -129,34 +159,40 @@ double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) void ExcelBook::DetectEndian(void) { int end; long i = 0x44332211; unsigned char* a = (unsigned char*) &i; end = (*a != 0x11); - if (end == 1) { + if (end == 1) + { endian = BIG_ENDIAN; printf("BIGENDIAN!\r\n"); - } else { + } + else + { endian = LITTLE_ENDIAN; printf("LITTLEENDIAN!\r\n"); } }; double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) { int i; double d; unsigned char *ieee; ieee = (unsigned char *)&d; for (i = 0; i < 8; i++) ieee[i] = 0; - if (endian == BIG_ENDIAN) { + if (endian == BIG_ENDIAN) + { ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; - } else { + } + else + { ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; } return d; @@ -390,13 +426,14 @@ int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) case XL_DIMENSION: data = GetDataOfBREC(record); if (record->length == 10) { sheet->rows = Integer2Byte(data[2], data[3]); sheet->cols = Integer2Byte(data[6], data[7]); - } else + } + else { sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); sheet->cols = Integer2Byte(data[10], data[11]); } sheet->InitCells(); break; @@ -599,13 +636,14 @@ void ExcelBook::HandleBoundSheet(ExcelBREC* rec) visibility = data[5]; length = data[6]; if(data[7]==0) { //ascii name=GetASCII(data,pos,length); - }else + } + else { name=GetUnicode(data,pos,length); }; Names.resize(Names.count()+1); Names[Names.count()-1]=new QString(name); }; @@ -805,26 +843,29 @@ QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) format = XFRecords[c->xfindex]->format; date = (time_t) ((c->valued - utcOffsetDays) * sInADay); tmptr = gmtime(&date); if (dateformat) { strftime(str,1024,dateformat.ascii(),tmptr); - } else + } + else { strftime(str,1024,format.ascii(),tmptr); }; - } else + } + else if (XFRecords[c->xfindex]->type == NUMBERFORMAT) { format = XFRecords[c->xfindex]->format; //sprintf(str,format.ascii(),c->valued); // the real format is ignored... // because there is more work to be done in the field precision = CellGetPrecision(c->valued); sprintf(str,"%.*f",precision,c->valued); - }else + } + else { precision = CellGetPrecision(c->valued); sprintf(str,"%.*f",precision,c->valued); }; break; case CELL_DATE: @@ -999,17 +1040,19 @@ void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record) data = GetDataOfBREC(record); row = Integer2Byte(data[0], data[1]); col = Integer2Byte(data[2], data[3]); if (data[6] == 0 && data[12] == -1 && data[13] == -1) { // string - } else + } + else if (data[6] == 1 && data[12] == -1 && data[13] == -1) { // boolean - } else + } + else if ( data[6] == 2 && data[12] == -1 && data[13] == -1) { // error } else { @@ -1120,13 +1163,14 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i if (fareaststring) { idx += fareastsize; }; s1=QString("""")+s1+QString(""""); operands.prepend(new QString(s1)); - }else + } + else { w1=data[idx];idx++; s1=GetASCII(data,idx,w1); s1=QString("""")+s1+QString(""""); idx=idx+w1; operands.prepend(new QString(s1)); @@ -1139,13 +1183,14 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i if(Version==8) { w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2 - }else + } + else { w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1 w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1 w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2 }; @@ -1158,13 +1203,14 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i case 0x44: case 0x64://ptgRef if(Version==8) { w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col - }else + } + else { w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col }; s1=FindCellName(w1,w2); printf("token:ptgRef,ref=%s\r\n",s1.ascii()); @@ -1329,13 +1375,14 @@ QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, i case 0x61://ptgFunction printf("token:ptgFunction\r\n"); if(token==0x22||token==0x42||token==0x62) { w2=(int)data[idx];idx++; w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; - }else + } + else { w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; }; switch(w1) { case 0xf://SIN |