Skip to content

Commit

Permalink
Use a pragma to silence the C99 extensions warnings (#459)
Browse files Browse the repository at this point in the history
* Use a pragma to silence the C99 extensions warnings

This also reverts changing the flexible array members to single element
arrays.

* Avoid NOTEs on R-devel

* Fix pragmas for GCC

* Only use const char** for iconv on Solaris

* Extend Solaris iconv solution to Windows
  • Loading branch information
jimhester authored and jennybc committed Apr 19, 2018
1 parent b8a6d66 commit 33d9167
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/ColSpec.h
@@ -1,6 +1,9 @@
#ifndef READXL_COLSPEC_
#define READXL_COLSPEC_

# pragma GCC diagnostic ignored "-Wpedantic"
# pragma clang diagnostic ignored "-Wc99-extensions"

#include <Rcpp.h>
#include <libxls/xls.h>
#include "StringSet.h"
Expand Down
4 changes: 4 additions & 0 deletions src/XlsWorkBook.cpp
@@ -1,4 +1,8 @@
#include <Rcpp.h>

# pragma GCC diagnostic ignored "-Wpedantic"
# pragma clang diagnostic ignored "-Wc99-extensions"

#include "XlsWorkBook.h"
using namespace Rcpp;

Expand Down
2 changes: 1 addition & 1 deletion src/XlsWorkSheet.cpp
@@ -1,7 +1,7 @@
#include <Rcpp.h>

#include "XlsWorkSheet.h"
#include "ColSpec.h"
#include "XlsWorkSheet.h"
#include <libxls/xls.h>
using namespace Rcpp;

Expand Down
2 changes: 1 addition & 1 deletion src/XlsxWorkSheet.cpp
@@ -1,6 +1,6 @@
#include <Rcpp.h>
#include "XlsxWorkSheet.h"
#include "ColSpec.h"
#include "XlsxWorkSheet.h"
#include "utils.h"
using namespace Rcpp;

Expand Down
16 changes: 12 additions & 4 deletions src/libxls/xlsstruct.h
Expand Up @@ -33,6 +33,10 @@
#ifndef XLS_STRUCT_INC
#define XLS_STRUCT_INC

#ifdef __cplusplus
extern "C" {
#endif

#include "libxls/ole.h"

#define XLS_RECORD_EOF 0x000A
Expand Down Expand Up @@ -194,7 +198,7 @@ typedef struct MULRK
struct {
WORD xf;
DWORD_UA value;
} rk[1]; // readxl
} rk[];
//WORD last_col;
}
MULRK;
Expand All @@ -203,7 +207,7 @@ typedef struct MULBLANK
{
WORD row;
WORD col;
WORD xf[1]; // readxl
WORD xf[];
//WORD last_col;
}
MULBLANK;
Expand Down Expand Up @@ -240,7 +244,7 @@ typedef struct SST
{
DWORD num;
DWORD numofstr;
BYTE strings[0];
BYTE strings[];
}
SST;

Expand Down Expand Up @@ -312,7 +316,7 @@ typedef struct FONT
BYTE family;
BYTE charset;
BYTE notused;
char name[1]; // readxl
char name[];
}
FONT;

Expand Down Expand Up @@ -530,4 +534,8 @@ xlsSummaryInfo;

typedef void (*xls_formula_handler)(WORD bof, WORD len, BYTE *formula);

#ifdef __cplusplus
} // extern c block
#endif

#endif
12 changes: 6 additions & 6 deletions src/xls.c
Expand Up @@ -90,7 +90,7 @@ typedef struct {
uint32_t os;
uint32_t format[4];
uint32_t count;
sectionList secList[1]; // readxl
sectionList secList[];
} header;

typedef struct {
Expand All @@ -101,12 +101,12 @@ typedef struct {
typedef struct {
uint32_t length;
uint32_t numProperties;
propertyList properties[1]; // readxl
propertyList properties[];
} sectionHeader;

typedef struct {
uint32_t propertyID;
uint32_t data[1]; // readxl
uint32_t data[];
} property;

#pragma pack(pop)
Expand Down Expand Up @@ -785,7 +785,7 @@ xls_error_t xls_parseWorkBook(xlsWorkBook* pWB)
if(xls_debug > 10) {
printf("READ WORKBOOK filePos=%ld\n", (long)pWB->filepos);
printf(" OLE: start=%d pos=%zd size=%zd fatPos=%zu\n",
pWB->olestr->start, pWB->olestr->pos, pWB->olestr->size, pWB->olestr->fatpos);
pWB->olestr->start, pWB->olestr->pos, pWB->olestr->size, pWB->olestr->fatpos);
}

if (ole2_read(&bof1, 1, 4, pWB->olestr) != 4) {
Expand Down Expand Up @@ -1018,7 +1018,7 @@ xls_error_t xls_parseWorkBook(xlsWorkBook* pWB)
printf(" mode: 0x%x\n", pWB->is1904);
}
break;

case XLS_RECORD_DEFINEDNAME:
if(xls_debug) {
int i;
Expand All @@ -1027,7 +1027,7 @@ xls_error_t xls_parseWorkBook(xlsWorkBook* pWB)
printf("\n");
}
break;

default:
if(xls_debug)
{
Expand Down
24 changes: 15 additions & 9 deletions src/xlstool.c
Expand Up @@ -138,13 +138,13 @@ char *utf8_decode(const char *str, DWORD len, char *encoding)
int utf8_chars = 0;
char *ret = NULL;
DWORD i;

for(i=0; i<len; ++i) {
if(str[i] & (BYTE)0x80) {
++utf8_chars;
}
}

if(utf8_chars == 0 || strcmp(encoding, "UTF-8")) {
ret = malloc(len+1);
memcpy(ret, str, len);
Expand Down Expand Up @@ -174,11 +174,17 @@ char *utf8_decode(const char *str, DWORD len, char *encoding)
char* unicode_decode(const char *s, size_t len, size_t *newlen, const char* to_enc)
{
#ifdef HAVE_ICONV
// Do iconv conversion
// Do iconv conversion
#if defined(_AIX) || defined(__sun)
const char *from_enc = "UTF-16le";
#define ICONV_CONST const
#else
const char *from_enc = "UTF-16LE";
#if defined(_WIN32)
#define ICONV_CONST const
#else
#define ICONV_CONST
#endif
#endif
char* outbuf = 0;

Expand Down Expand Up @@ -212,15 +218,15 @@ char* unicode_decode(const char *s, size_t len, size_t *newlen, const char* to_e
return outbuf;
}
}
size_t st;
size_t st;
outbuf = malloc(outlen + 1);

if(outbuf)
{
out_ptr = outbuf;
while(inlenleft)
{
st = iconv(ic, (char **)&src_ptr, &inlenleft, (char **)&out_ptr,(size_t *) &outlenleft);
st = iconv(ic, (ICONV_CONST char **)&src_ptr, &inlenleft, (char **)&out_ptr,(size_t *) &outlenleft);
if(st == (size_t)(-1))
{
if(errno == E2BIG)
Expand Down Expand Up @@ -307,7 +313,7 @@ char *get_string(const char *s, size_t len, BYTE is2, BYTE is5ver, char *charset
BYTE flag = 0;
const char *str = s;
char *ret = NULL;

if (is2) {
// length is two bytes
if (ofs + 2 > len) {
Expand Down Expand Up @@ -361,9 +367,9 @@ char *get_string(const char *s, size_t len, BYTE is2, BYTE is5ver, char *charset
printf("ofs=%d ret[0]=%d\n", ofs, *ret);
{
unsigned char *ptr;

ptr = ret;

printf("%x %x %x %x %x %x %x %x\n", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7] );
printf("%s\n", ret);
}
Expand Down Expand Up @@ -544,7 +550,7 @@ void xls_showFormat(struct st_format_data* frmt)
void xls_showXF(XF8* xf)
{
static int idx;

printf(" Index: %u\n",idx++);
printf(" Font: %u\n",xf->font);
printf(" Format: %u\n",xf->format);
Expand Down

0 comments on commit 33d9167

Please sign in to comment.