comparison extra/NaN/src/xptopen.cpp @ 12678:e4374feb2e3f octave-forge

[nan-tb] fix bug when file open fails; address several compiler warnings
author schloegl
date Thu, 20 Aug 2015 09:01:53 +0000
parents 4e0e24d27b82
children 13815b367946
comparison
equal deleted inserted replaced
12677:e083820799fe 12678:e4374feb2e3f
299 mxGetString(PInputs[1],Mode,3); 299 mxGetString(PInputs[1],Mode,3);
300 Mode[2]=0; 300 Mode[2]=0;
301 } 301 }
302 302
303 fid = fopen(fn,Mode); 303 fid = fopen(fn,Mode);
304 if (fid < 0) { 304 if (fid == NULL) {
305 mexErrMsgTxt("Can not open file!\n"); 305 mexErrMsgTxt("Can not open file!\n");
306 } 306 }
307 307
308 if (Mode[0]=='r' || Mode[0]=='a' ) { 308 if (Mode[0]=='r' || Mode[0]=='a' ) {
309 count += fread(H0,1,80*8,fid); 309 count += fread(H0,1,80*8,fid);
370 type = bswap_32(type); 370 type = bswap_32(type);
371 FlagHasLabel = bswap_32(FlagHasLabel); 371 FlagHasLabel = bswap_32(FlagHasLabel);
372 } 372 }
373 373
374 if (rec_type != 2) 374 if (rec_type != 2)
375 ;//error('invalid SPSS file'); 375 mexErrMsgTxt("invalid SPSS file\n");
376 376
377 c2 += fread(VarNames+9*ns,1,8,fid); 377 c2 += fread(VarNames+9*ns,1,8,fid);
378 VarNames[9*ns+8] = 0; 378 VarNames[9*ns+8] = 0;
379 ListOfVarNames[ns] = VarNames+9*ns; 379 ListOfVarNames[ns] = VarNames+9*ns;
380 if (FlagHasLabel==1) { 380 if (FlagHasLabel==1) {
467 467
468 // expansion fields 468 // expansion fields
469 char typ; int32_t len; 469 char typ; int32_t len;
470 char flagSWAP = (((__BYTE_ORDER == __BIG_ENDIAN) && LittleEndian) || ((__BYTE_ORDER == __LITTLE_ENDIAN) && !LittleEndian)); 470 char flagSWAP = (((__BYTE_ORDER == __BIG_ENDIAN) && LittleEndian) || ((__BYTE_ORDER == __LITTLE_ENDIAN) && !LittleEndian));
471 do { 471 do {
472 fread(&typ,1,1,fid); 472 if (!fread(&typ,1,1,fid)) break;
473 fread(&len,4,1,fid); 473 if (!fread(&len,4,1,fid)) break;
474 if (flagSWAP) bswap_32(len); 474 if (flagSWAP) bswap_32(len);
475 fseek(fid,len,SEEK_CUR); 475 fseek(fid,len,SEEK_CUR);
476 } while (len); 476 } while (len);
477 uint8_t *typlist = (uint8_t*)H1; 477 uint8_t *typlist = (uint8_t*)H1;
478 478
722 mxSetCell(R[ns], m, mxCreateString(line+p)); 722 mxSetCell(R[ns], m, mxCreateString(line+p));
723 } 723 }
724 else if (vartyp[ns] == 6) { 724 else if (vartyp[ns] == 6) {
725 size_t kk[6],n=0, N=strlen(datestr[ns]); 725 size_t kk[6],n=0, N=strlen(datestr[ns]);
726 char T0[6][5]; 726 char T0[6][5];
727 char ix = 0; 727 int ix = 0;
728 struct tm t; 728 struct tm t;
729 729
730 for (n=0; n < N; n++) { 730 for (n=0; n < N; n++) {
731 switch (datestr[ns][n]) { 731 switch (datestr[ns][n]) {
732 case 'Y': 732 case 'Y':
1090 1090
1091 #if DEBUG 1091 #if DEBUG
1092 mexPrintf("d2xpt(%f)\n",x); 1092 mexPrintf("d2xpt(%f)\n",x);
1093 #endif 1093 #endif
1094 // see http://old.nabble.com/Re%3A-IBM-integer-and-double-formats-p20428979.html 1094 // see http://old.nabble.com/Re%3A-IBM-integer-and-double-formats-p20428979.html
1095 m = *(uint64_t*) &x; 1095 memcpy(&m, &x, 8);
1096 *(((char*)&m) + 6) &= 0x0f; // 1096 *(((char*)&m) + 6) &= 0x0f; //
1097 if (e) *(((char*)&m) + 6) |= 0x10; // reconstruct implicit leading '1' for normalized numbers 1097 if (e) *(((char*)&m) + 6) |= 0x10; // reconstruct implicit leading '1' for normalized numbers
1098 m <<= (3-(-e & 3)); 1098 m <<= (3-(-e & 3));
1099 *(((uint8_t*)&m) + 7) = s ? 0x80 : 0; 1099 *(((uint8_t*)&m) + 7) = s ? 0x80 : 0;
1100 e = (e + (-e & 3)) / 4 + 64; 1100 e = (e + (-e & 3)) / 4 + 64;