Fix some unreachable code 97/5997/2
Sylvestre Ledru [Sun, 22 Jan 2012 10:03:31 +0000 (11:03 +0100)]
Change-Id: I59b4c17e16ba17072aac5c8a870671b72adb0957

scilab/modules/fileio/sci_gateway/c/sci_mscanf.c
scilab/modules/fileio/sci_gateway/c/sci_msscanf.c
scilab/modules/fileio/src/c/do_xxscanf.c
scilab/modules/fileio/src/c/fullpath.c
scilab/modules/fileio/src/c/mget.c
scilab/modules/spreadsheet/sci_gateway/c/sci_xls_open.c
scilab/modules/spreadsheet/src/c/ripole/ole.c
scilab/modules/spreadsheet/src/c/ripole/ripole.c

index cbee95b..6ab281a 100644 (file)
 #include "StringConvert.h"
 #include "xscion.h"
 #include "../../../console/includes/zzledt.h"
-#include "../../../console/includes/GetCommandLine.h" /* getConsoleInputLine */
+#include "../../../console/includes/GetCommandLine.h"   /* getConsoleInputLine */
 #ifdef _MSC_VER
 #include "strdup_windows.h"
 #endif
 /*--------------------------------------------------------------------------*/
 #define MAXSTR 512
 /*--------------------------------------------------------------------------*/
-int sci_scanf(char *fname,unsigned long fname_len)
+int sci_scanf(char *fname, unsigned long fname_len)
 {
     static char *String = NULL;
-    static int l1 = 0, m1 = 0, n1 = 0, len = MAXSTR-1,iarg  = 0,maxrow = 0,nrow = 0,rowcount = 0,ncol = 0;
-    int args = 0,retval = 0,retval_s = 0,lline = 0,iflag = 0,err = 0,n_count = 0;
+    static int l1 = 0, m1 = 0, n1 = 0, len = MAXSTR - 1, iarg = 0, maxrow = 0, nrow = 0, rowcount = 0, ncol = 0;
+    int args = 0, retval = 0, retval_s = 0, lline = 0, iflag = 0, err = 0, n_count = 0;
     entry *data = NULL;
     rec_entry buf[MAXSCAN];
-    sfdir  type[MAXSCAN],type_s[MAXSCAN];
+    sfdir type[MAXSCAN], type_s[MAXSCAN];
 
     Nbvars = 0;
-    CheckRhs(1,2);
+    CheckRhs(1, 2);
 
-    if (Rhs==2)
+    if (Rhs == 2)
     {
-        GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l1);
-        if (m1*n1 != 1)
+        GetRhsVar(1, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1, &l1);
+        if (m1 * n1 != 1)
         {
-            Scierror(999,_("%s: Wrong size for input argument #%d: Scalar expected.\n"),fname,1);
+            Scierror(999, _("%s: Wrong size for input argument #%d: Scalar expected.\n"), fname, 1);
             return 0;
         }
-        iarg=2;
-        maxrow=*istk(l1);
+        iarg = 2;
+        maxrow = *istk(l1);
     }
     else
     {
-        iarg=1;
-        maxrow=1;
+        iarg = 1;
+        maxrow = 1;
     }
 
-    GetRhsVar(iarg,STRING_DATATYPE,&m1,&n1,&l1); /** format **/
-    n_count=StringConvert(cstk(l1))+1;  /* conversion */
+    GetRhsVar(iarg, STRING_DATATYPE, &m1, &n1, &l1);
+                                                 /** format **/
+    n_count = StringConvert(cstk(l1)) + 1;  /* conversion */
 
-    if (n_count>1)
+    if (n_count > 1)
     {
-        Scierror(999,_("%s: Specified format cannot include any '\\n'\n"),fname);
+        Scierror(999, _("%s: Specified format cannot include any '\\n'\n"), fname);
         return 0;
     }
 
-    nrow=maxrow;
-    rowcount = -1; /* number-1 of result lines already got */
+    nrow = maxrow;
+    rowcount = -1;              /* number-1 of result lines already got */
     while (1)
     {
         rowcount++;
-        if ((maxrow >= 0) && (rowcount >= maxrow)) break;
+        if ((maxrow >= 0) && (rowcount >= maxrow))
+            break;
 
         /* get a line */
-        C2F(xscion)(&iflag);
+        C2F(xscion) (&iflag);
         //C2F(zzledt)(String,&len,&lline,&status,&interrupt,&iflag,(long int)strlen(String));
         //getLine(String,&len,&lline,&status);
         String = getConsoleInputLine();
         if (String == NULL)
         {
-            Scierror(999,_("%s: Data mismatch.\n"),fname);
+            Scierror(999, _("%s: Data mismatch.\n"), fname);
             return 0;
         }
         lline = (int)strlen(String);
 
-        if (lline == 0) 
+        if (lline == 0)
         {
             FREE(String);
             String = strdup(" ");
@@ -94,40 +96,51 @@ int sci_scanf(char *fname,unsigned long fname_len)
         }
 
         /** use the scaned line as input **/
-        args = Rhs; /* args set to Rhs on entry */
-        if (do_xxscanf("scanf",(FILE *) 0,cstk(l1),&args,String,&retval,buf,type) < 0) 
+        args = Rhs;             /* args set to Rhs on entry */
+        if (do_xxscanf("scanf", (FILE *) 0, cstk(l1), &args, String, &retval, buf, type) < 0)
         {
-            if (String) {FREE(String); String = NULL;}
+            if (String)
+            {
+                FREE(String);
+                String = NULL;
+            }
             return 0;
         }
-        if (String) {FREE(String); String = NULL;}
+        if (String)
+        {
+            FREE(String);
+            String = NULL;
+        }
 
-        if ((err=Store_Scan(&nrow,&ncol,type_s,type,&retval,&retval_s,buf,&data,rowcount,args)) <0 )
+        if ((err = Store_Scan(&nrow, &ncol, type_s, type, &retval, &retval_s, buf, &data, rowcount, args)) < 0)
         {
             switch (err)
             {
             case MISMATCH:
-                if (maxrow>=0)
+                if (maxrow >= 0)
                 {
-                    Free_Scan(rowcount,ncol,type_s,&data);
-                    Scierror(999,_("%s: Data mismatch.\n"),fname);
+                    Free_Scan(rowcount, ncol, type_s, &data);
+                    Scierror(999, _("%s: Data mismatch.\n"), fname);
                     return 0;
                 }
                 break;
 
             case MEM_LACK:
-                Free_Scan(rowcount,ncol,type_s,&data);
-                Scierror(999,_("%s: No more memory.\n"),fname);
+                Free_Scan(rowcount, ncol, type_s, &data);
+                Scierror(999, _("%s: No more memory.\n"), fname);
                 return 0;
-                break;
             }
         }
-    } /*  while (1) */
+    }                           /*  while (1) */
 
     /* create Scilab variables with each column of data */
-    err=Sci_Store(rowcount,ncol,data,type_s,retval_s);
-    Free_Scan(rowcount,ncol,type_s,&data);
-    if (err==MEM_LACK) { Scierror(999,_("%s: No more memory.\n"),fname);}
+    err = Sci_Store(rowcount, ncol, data, type_s, retval_s);
+    Free_Scan(rowcount, ncol, type_s, &data);
+    if (err == MEM_LACK)
+    {
+        Scierror(999, _("%s: No more memory.\n"), fname);
+    }
     return 0;
 }
+
 /*--------------------------------------------------------------------------*/
index 04aedb5..899ed1e 100644 (file)
 #include "localization.h"
 
 /*--------------------------------------------------------------------------*/
-int sci_sscanf(char *fname,unsigned long fname_len)
+int sci_sscanf(char *fname, unsigned long fname_len)
 {
-       static int l1 = 0, m1 = 0, n1 = 0,l2 = 0,m2 = 0,n2 = 0,iarg = 0,maxrow = 0,nrow = 0,rowcount = 0,ncol = 0;
-       int args = 0,retval = 0,retval_s = 0,err = 0,n_count = 0,lw = 0,il1 = 0,ild1 = 0,skip = 0;
-       int k = 0;
+    static int l1 = 0, m1 = 0, n1 = 0, l2 = 0, m2 = 0, n2 = 0, iarg = 0, maxrow = 0, nrow = 0, rowcount = 0, ncol = 0;
+    int args = 0, retval = 0, retval_s = 0, err = 0, n_count = 0, lw = 0, il1 = 0, ild1 = 0, skip = 0;
+    int k = 0;
 
-       entry *data = NULL;
-       rec_entry buf[MAXSCAN];
-       sfdir  type[MAXSCAN],type_s[MAXSCAN];
-       char* str = NULL;
+    entry *data = NULL;
+    rec_entry buf[MAXSCAN];
+    sfdir type[MAXSCAN], type_s[MAXSCAN];
+    char *str = NULL;
 
-       Nbvars = 0;
-       CheckRhs(2,3);
+    Nbvars = 0;
+    CheckRhs(2, 3);
 
-       if (Rhs==3)
-       {
-               GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l1);
-               if (m1*n1!=1)
-               {
-                       Scierror(999,_("%s: Wrong size for input argument #%d: Scalar expected.\n"),fname,1);
-                       return 0;
-               }
+    if (Rhs == 3)
+    {
+        GetRhsVar(1, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1, &l1);
+        if (m1 * n1 != 1)
+        {
+            Scierror(999, _("%s: Wrong size for input argument #%d: Scalar expected.\n"), fname, 1);
+            return 0;
+        }
 
-               iarg=2;
-               maxrow=*istk(l1);
-       }
-       else
-       {
-               iarg=1;
-               maxrow=1;
-       }
+        iarg = 2;
+        maxrow = *istk(l1);
+    }
+    else
+    {
+        iarg = 1;
+        maxrow = 1;
+    }
 
-       lw = iarg + Top - Rhs; /* Scilab string vector */
-       if (! C2F(getwsmat)("sscanf",&Top,&lw,&m1,&n1,&il1,&ild1,6L)) return 0;
-       GetRhsVar(iarg+1,STRING_DATATYPE,&m2,&n2,&l2); /* Format */
-       n_count=StringConvert(cstk(l2))+1;  /* conversion */
+    lw = iarg + Top - Rhs;      /* Scilab string vector */
+    if (!C2F(getwsmat) ("sscanf", &Top, &lw, &m1, &n1, &il1, &ild1, 6L))
+        return 0;
+    GetRhsVar(iarg + 1, STRING_DATATYPE, &m2, &n2, &l2);    /* Format */
+    n_count = StringConvert(cstk(l2)) + 1;  /* conversion */
 
-       if ( (maxrow >= 0) && (maxrow*n_count>m1*n1) )
-       {
-               Scierror(999,_("%s: An error occurred: %s\n"),fname,_("Not enough entries."));
-               return 0;
-       }
+    if ((maxrow >= 0) && (maxrow * n_count > m1 * n1))
+    {
+        Scierror(999, _("%s: An error occurred: %s\n"), fname, _("Not enough entries."));
+        return 0;
+    }
 
-       k=0;
-       nrow=maxrow;
-       rowcount = -1; /* number-1 of result lines already got */
-       while (1)
-       {
-               rowcount++;
-               if ((maxrow >= 0) && (rowcount >= maxrow)) break;
-               if ( k >= m1*n1 ) break;
-               skip=*istk(ild1+k)-1;
-               SciStrtoStr(istk(il1+skip),&n_count,istk(ild1+k),&str);
-               k +=n_count;
+    k = 0;
+    nrow = maxrow;
+    rowcount = -1;              /* number-1 of result lines already got */
+    while (1)
+    {
+        rowcount++;
+        if ((maxrow >= 0) && (rowcount >= maxrow))
+            break;
+        if (k >= m1 * n1)
+            break;
+        skip = *istk(ild1 + k) - 1;
+        SciStrtoStr(istk(il1 + skip), &n_count, istk(ild1 + k), &str);
+        k += n_count;
 
-               args = Rhs; /* args set to Rhs on entry */
-               err = do_xxscanf("sscanf",(FILE *)0,cstk(l2),&args,str,&retval,buf,type);
-               FREE(str);
-               if ( err < 0 )  return 0;
+        args = Rhs;             /* args set to Rhs on entry */
+        err = do_xxscanf("sscanf", (FILE *) 0, cstk(l2), &args, str, &retval, buf, type);
+        FREE(str);
+        if (err < 0)
+            return 0;
 
-               if ((err=Store_Scan(&nrow,&ncol,type_s,type,&retval,&retval_s,buf,&data,rowcount,args)) <0 )
-               {
-                       switch (err)
-                       {
-                       case MISMATCH:
-                               if (maxrow>=0)
-                               {
-                                       Free_Scan(rowcount,ncol,type_s,&data);
-                                       Scierror(999,_("%s: Data mismatch.\n"),fname);
-                                       return 0;
-                               }
-                               break;
+        if ((err = Store_Scan(&nrow, &ncol, type_s, type, &retval, &retval_s, buf, &data, rowcount, args)) < 0)
+        {
+            switch (err)
+            {
+            case MISMATCH:
+                if (maxrow >= 0)
+                {
+                    Free_Scan(rowcount, ncol, type_s, &data);
+                    Scierror(999, _("%s: Data mismatch.\n"), fname);
+                    return 0;
+                }
+                break;
 
-                       case MEM_LACK:
-                               Free_Scan(rowcount,ncol,type_s,&data);
-                               Scierror(999,_("%s: No more memory.\n"),fname);
-                               return 0;
-                               break;
-                       }
+            case MEM_LACK:
+                Free_Scan(rowcount, ncol, type_s, &data);
+                Scierror(999, _("%s: No more memory.\n"), fname);
+                return 0;
+            }
 
-                       if (err==MISMATCH) break;
-               }
-       } /* while */
+            if (err == MISMATCH)
+                break;
+        }
+    }                           /* while */
 
-       /* create Scilab variables with each column of data */
-       err=Sci_Store(rowcount,ncol,data,type_s,retval_s);
-       Free_Scan(rowcount,ncol,type_s,&data);
-       if (err==MEM_LACK) { Scierror(999,_("%s: No more memory.\n"),fname);}
-       return 0;
+    /* create Scilab variables with each column of data */
+    err = Sci_Store(rowcount, ncol, data, type_s, retval_s);
+    Free_Scan(rowcount, ncol, type_s, &data);
+    if (err == MEM_LACK)
+    {
+        Scierror(999, _("%s: No more memory.\n"), fname);
+    }
+    return 0;
 }
+
 /*--------------------------------------------------------------------------*/
index 90d25ed..8a0ea14 100644 (file)
  */
 /*--------------------------------------------------------------------------*/
 #if defined(__linux__)
-#define _GNU_SOURCE /* Bug 5673 fix: avoid dependency on GLIBC_2.7 */
+#define _GNU_SOURCE             /* Bug 5673 fix: avoid dependency on GLIBC_2.7 */
 #endif
 
 #include <stdio.h>
-#include <ctype.h>  /* isdigit */
+#include <ctype.h>              /* isdigit */
 #include <string.h>
 #include "BOOL.h"
 #include "MALLOC.h"
 #include "do_xxprintf.h"
 #include "core_math.h"
 /*--------------------------------------------------------------------------*/
-typedef int (*XXSCANF)(FILE *, char *,...);
-typedef int (*FLUSH)(FILE *);
+typedef int (*XXSCANF) (FILE *, char *, ...);
+typedef int (*FLUSH) (FILE *);
+
 /*--------------------------------------------------------------------------*/
-static void set_xxscanf(FILE *fp,XXSCANF *xxscanf,char **target,char **strv)
+static void set_xxscanf(FILE * fp, XXSCANF * xxscanf, char **target, char **strv)
 {
-       if (fp == (FILE *) 0)
-       {
-               *target = *strv;
-               *xxscanf = (XXSCANF) sscanf;
-       }
-       else
-       {
-               *target = (char *) fp;
-               *xxscanf = (XXSCANF) fscanf;
-       }
+    if (fp == (FILE *) 0)
+    {
+        *target = *strv;
+        *xxscanf = (XXSCANF) sscanf;
+    }
+    else
+    {
+        *target = (char *)fp;
+        *xxscanf = (XXSCANF) fscanf;
+    }
 }
+
 /*--------------------------------------------------------------------------*/
-int do_xxscanf (char *fname, FILE *fp, char *format, int *nargs, char *strv, int *retval, rec_entry *buf, sfdir *type)
+int do_xxscanf(char *fname, FILE * fp, char *format, int *nargs, char *strv, int *retval, rec_entry * buf, sfdir * type)
 {
-       int nc[MAXSCAN];
-       int n_directive_count=0;
-       int i=0;
-       int l_flag=0;
-       int h_flag=0;
-       int width_flag=0;
-       int width_val=0;
-       int ignore_flag=0;
-       int str_width_flag=0;
-       int num_conversion = -1;
-       void *ptrtab[MAXSCAN];
-       char sformat[MAX_STR];
-       char backupcurrrentchar;
-       char directive;
-       char *p=NULL;
-       char *p1=NULL;
-       char *target=NULL;
-       char *sval=NULL;
-       register char *currentchar=NULL;
-
-       XXSCANF xxscanf;
-
-       set_xxscanf(fp,&xxscanf,&target,&strv);
-       currentchar = format;
-       *retval = 0;
-
-       while (TRUE)
-       {
-               /* scanf */
-               p=currentchar;
-               while (*currentchar != '%' && *currentchar != '\0' ) currentchar++;
-               if ( *currentchar == '%' && *(currentchar+1) == '%' )
-               {
-                       currentchar=currentchar+2;
-                       while (*currentchar != '%' && *currentchar != '\0' ) currentchar++;
-               }
-
-               if (*currentchar == 0)
-               {
-                       break ;
-               }
-
-               currentchar++;
-               p1 = currentchar - 1;
-
-               while ( isdigit(((int)*currentchar)) ) currentchar++;
-
-               width_flag =0;
-
-               if ( p1+1 != currentchar )
-               {
-                       char w= *currentchar;
-                       *currentchar='\0';
-                       width_flag = 1;
-                       sscanf(p1+1,"%d",&width_val);
-                       *currentchar=w;
-               }
-
-               ignore_flag=0;
-
-               if (*currentchar == '*')
-               {
-                       ignore_flag = 1;
-                       currentchar++;
-               }
-               else
-               {
-                       l_flag = h_flag = 0;
-               }
-
-               if (*currentchar == 'l')
-               {
-                       currentchar++;
-                       l_flag = 1;
-               }
-               else if (*currentchar == 'h')
-               {
-                       currentchar++;
-                       h_flag = 1;
-               }
-
-               /* directive points to the scan directive  */
-
-               directive = *currentchar++;
-
-               if ( directive == '[' )
-               {
-                       char *currentchar1=currentchar--;
-                       while ( *currentchar1 != '\0' && *currentchar1 != ']') currentchar1++;
-
-                       if ( *currentchar1 == '\0')
-                       {
-                               Scierror(998,_("%s: An error occurred: %s\n"),fname,_("unclosed [ directive."));
-                               return RET_BUG;
-                       }
-
-                       if ( currentchar1 == currentchar +1 || strncmp(currentchar,"[^]",3)==0 )
-                       {
-                               currentchar1++;
-                               while ( *currentchar1 != '\0' && *currentchar1 != ']') currentchar1++;
-
-                               if ( *currentchar1 == '\0')
-                               {
-                                       Scierror(998,_("%s: An error occurred: %s\n"),fname,_("unclosed [ directive."));
-                                       return RET_BUG;
-                               }
-                       }
-
-                       directive = *currentchar1++;
-                       currentchar=currentchar1;
-               }
-
-               backupcurrrentchar = *currentchar;
-
-               if ( ignore_flag != 1)
-               {
-                       num_conversion++;
-
-                       if ( num_conversion >= MAXSCAN )
-                       {
-                               Scierror(998,_("%s: An error occurred: too many (> %d) conversion required.\n"),fname,MAXSCAN);
-                               return RET_BUG;
-                       }
-
-                       switch (directive )
-                       {
-                       case ']':
-                               if (width_flag == 0 ) str_width_flag = 1;
-
-                               if (width_flag == 1 && width_val > MAX_STR-1 )
-                               {
-                                       Scierror(998,_("%s: An error occurred: field %d is too long (> %d) for %%[ directive.\n"),fname,width_val,MAX_STR-1);
-                                       return RET_BUG;
-                               }
-
-                               if ((buf[num_conversion].c=MALLOC(MAX_STR))==NULL) return MEM_LACK;
-                               ptrtab[num_conversion] =  buf[num_conversion].c;
-                               type[num_conversion] = SF_S;
-                               break;
-
-                       case 's':
-                               if (l_flag + h_flag)
-                               {
-                                       Scierror(998,_("%s: An error occurred: %s\n"),fname,_("Bad conversion."));
-                                       return RET_BUG;
-                               }
-
-                               if (width_flag == 0 ) str_width_flag = 1;
-                               if (width_flag == 1 && width_val > MAX_STR-1 )
-                               {
-                                       Scierror(998,_("%s: An error occurred: field %d is too long (< %d) for %%s directive.\n"),fname,width_val,MAX_STR-1);
-                                       return RET_BUG;
-                               }
-
-                               if ((buf[num_conversion].c=MALLOC(MAX_STR))==NULL) return MEM_LACK;
-
-                               ptrtab[num_conversion] =  buf[num_conversion].c;
-                               type[num_conversion] = SF_S;
-                               break;
-
-                       case 'c':
-                               if (l_flag + h_flag)
-                               {
-                                       Scierror(998,_("%s: An error occurred: %s\n"),fname,_("Bad conversion."));
-                                       return RET_BUG;
-                               }
-
-                               if ( width_flag == 1 ) nc[num_conversion ] = width_val;
-                               else nc[num_conversion ] = 1;
-
-                               if (width_flag == 1 && width_val > MAX_STR-1 )
-                               {
-                                       Scierror(998,_("%s: An error occurred: field %d is too long (< %d) for %%c directive.\n"),fname,width_val,MAX_STR-1);
-                                       return RET_BUG;
-                               }
-
-                               if ((buf[num_conversion].c=MALLOC(MAX_STR))==NULL) return MEM_LACK;
-
-                               ptrtab[num_conversion] =  buf[num_conversion].c;
-                               type[num_conversion] = SF_C;
-                               break;
-
-                       case 'o': case 'u': case 'x': case 'X':
-                               if ( l_flag )
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].lui;
-                                       type[num_conversion] = SF_LUI;
-                               }
-                               else if ( h_flag)
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].sui;
-                                       type[num_conversion] = SF_SUI;
-                               }
-                               else
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].ui;
-                                       type[num_conversion] = SF_UI;
-                               }
-                               break;
-
-                       case 'D':
-                               ptrtab[num_conversion] =  &buf[num_conversion].li;
-                               type[num_conversion] = SF_LI;
-                               break;
-
-                       case 'n':
-                               n_directive_count++;
-
-                       case 'i': case 'd':
-                               if ( l_flag )
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].li;
-                                       type[num_conversion] = SF_LI;
-                               }
-                               else if ( h_flag)
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].si;
-                                       type[num_conversion] = SF_SI;
-                               }
-                               else
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].i;
-                                       type[num_conversion] = SF_I;
-                               }
-                               break;
-
-                       case 'e': case 'f': case 'g': case 'E': case 'G':
-                               if (h_flag)
-                               {
-                                       Scierror(998,_("%s: An error occurred: %s\n"),fname,_("Bad conversion."));
-                                       return RET_BUG;
-                               }
-                               else if (l_flag)
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].lf;
-                                       type[num_conversion] = SF_LF;
-                               }
-                               else
-                               {
-                                       ptrtab[num_conversion] =  &buf[num_conversion].f;
-                                       type[num_conversion] = SF_F;
-                               }
-                               break;
-
-                       default:
-                               Scierror(998,_("%s: An error occurred: %s\n"),fname,_("Bad conversion."));
-                               return RET_BUG;
-                               break;
-                       }
-                       *currentchar = backupcurrrentchar;
-               }
-       }
-
-       if ( str_width_flag == 1)
-       {
-               char *f1=format;
-               char *f2=sformat;
-               char *slast = sformat + MAX_STR - 1 - 4;
-
-               while ( *f1 != '\0'  )
-               {
-                       int n;
-                       *f2++ = *f1++;
-
-                       if ( *(f1-1) == '%' && ( *(f1) == 's'  || *(f1) == '['))
-                       {
-                               n=sprintf(f2,"%d",MAX_STR-1);
-                               f2 += n;
-                               *f2++ = *f1++;
-                       }
-
-                       if ( f2 == slast )
-                       {
-                               Scierror(998,_("%s: An error occurred: format is too long (> %d).\n"),fname,MAX_STR-1);
-                               return RET_BUG;
-                       }
-               }
-
-               *f2='\0';
-               format = sformat;
-       }
-
-       *retval = (*xxscanf) ((VPTR) target,format,
-               ptrtab[0],ptrtab[1],ptrtab[2],ptrtab[3],ptrtab[4],ptrtab[5],ptrtab[6],ptrtab[7],ptrtab[8],ptrtab[9],
-               ptrtab[10],ptrtab[11],ptrtab[12],ptrtab[13],ptrtab[14],ptrtab[15],ptrtab[16],ptrtab[17],ptrtab[18],ptrtab[19],
-               ptrtab[20],ptrtab[21],ptrtab[22],ptrtab[23],ptrtab[24],ptrtab[25],ptrtab[26],ptrtab[27],ptrtab[28],ptrtab[29],
-               ptrtab[30],ptrtab[31],ptrtab[32],ptrtab[33],ptrtab[34],ptrtab[35],ptrtab[36],ptrtab[37],ptrtab[38],ptrtab[39],
-               ptrtab[40],ptrtab[41],ptrtab[42],ptrtab[43],ptrtab[44],ptrtab[45],ptrtab[46],ptrtab[47],ptrtab[48],ptrtab[49],
-               ptrtab[50],ptrtab[51],ptrtab[52],ptrtab[53],ptrtab[54],ptrtab[55],ptrtab[56],ptrtab[57],ptrtab[58],ptrtab[59],
-               ptrtab[60],ptrtab[61],ptrtab[62],ptrtab[63],ptrtab[64],ptrtab[65],ptrtab[66],ptrtab[67],ptrtab[68],ptrtab[69],
-               ptrtab[70],ptrtab[71],ptrtab[72],ptrtab[73],ptrtab[74],ptrtab[75],ptrtab[76],ptrtab[77],ptrtab[78],ptrtab[79],
-               ptrtab[80],ptrtab[81],ptrtab[82],ptrtab[83],ptrtab[84],ptrtab[85],ptrtab[86],ptrtab[87],ptrtab[88],ptrtab[89],
-               ptrtab[90],ptrtab[91],ptrtab[92],ptrtab[93],ptrtab[94],ptrtab[95],ptrtab[96],ptrtab[97],ptrtab[98],ptrtab[MAXSCAN-1]);
-
-       *nargs = Min(num_conversion+1,Max(*retval+n_directive_count,0));
-
-       for ( i=1 ; i <= *nargs ; i++)
-       {
-               if ( type[i-1]  == SF_C )
-               {
-                       sval=(char *) ptrtab[i-1];
-                       sval[nc[i-1]]='\0';
-               }
-       }
-
-       return 0;
+    int nc[MAXSCAN];
+    int n_directive_count = 0;
+    int i = 0;
+    int l_flag = 0;
+    int h_flag = 0;
+    int width_flag = 0;
+    int width_val = 0;
+    int ignore_flag = 0;
+    int str_width_flag = 0;
+    int num_conversion = -1;
+    void *ptrtab[MAXSCAN];
+    char sformat[MAX_STR];
+    char backupcurrrentchar;
+    char directive;
+    char *p = NULL;
+    char *p1 = NULL;
+    char *target = NULL;
+    char *sval = NULL;
+    register char *currentchar = NULL;
+
+    XXSCANF xxscanf;
+
+    set_xxscanf(fp, &xxscanf, &target, &strv);
+    currentchar = format;
+    *retval = 0;
+
+    while (TRUE)
+    {
+        /* scanf */
+        p = currentchar;
+        while (*currentchar != '%' && *currentchar != '\0')
+            currentchar++;
+        if (*currentchar == '%' && *(currentchar + 1) == '%')
+        {
+            currentchar = currentchar + 2;
+            while (*currentchar != '%' && *currentchar != '\0')
+                currentchar++;
+        }
+
+        if (*currentchar == 0)
+        {
+            break;
+        }
+
+        currentchar++;
+        p1 = currentchar - 1;
+
+        while (isdigit(((int)*currentchar)))
+            currentchar++;
+
+        width_flag = 0;
+
+        if (p1 + 1 != currentchar)
+        {
+            char w = *currentchar;
+
+            *currentchar = '\0';
+            width_flag = 1;
+            sscanf(p1 + 1, "%d", &width_val);
+            *currentchar = w;
+        }
+
+        ignore_flag = 0;
+
+        if (*currentchar == '*')
+        {
+            ignore_flag = 1;
+            currentchar++;
+        }
+        else
+        {
+            l_flag = h_flag = 0;
+        }
+
+        if (*currentchar == 'l')
+        {
+            currentchar++;
+            l_flag = 1;
+        }
+        else if (*currentchar == 'h')
+        {
+            currentchar++;
+            h_flag = 1;
+        }
+
+        /* directive points to the scan directive  */
+
+        directive = *currentchar++;
+
+        if (directive == '[')
+        {
+            char *currentchar1 = currentchar--;
+
+            while (*currentchar1 != '\0' && *currentchar1 != ']')
+                currentchar1++;
+
+            if (*currentchar1 == '\0')
+            {
+                Scierror(998, _("%s: An error occurred: %s\n"), fname, _("unclosed [ directive."));
+                return RET_BUG;
+            }
+
+            if (currentchar1 == currentchar + 1 || strncmp(currentchar, "[^]", 3) == 0)
+            {
+                currentchar1++;
+                while (*currentchar1 != '\0' && *currentchar1 != ']')
+                    currentchar1++;
+
+                if (*currentchar1 == '\0')
+                {
+                    Scierror(998, _("%s: An error occurred: %s\n"), fname, _("unclosed [ directive."));
+                    return RET_BUG;
+                }
+            }
+
+            directive = *currentchar1++;
+            currentchar = currentchar1;
+        }
+
+        backupcurrrentchar = *currentchar;
+
+        if (ignore_flag != 1)
+        {
+            num_conversion++;
+
+            if (num_conversion >= MAXSCAN)
+            {
+                Scierror(998, _("%s: An error occurred: too many (> %d) conversion required.\n"), fname, MAXSCAN);
+                return RET_BUG;
+            }
+
+            switch (directive)
+            {
+            case ']':
+                if (width_flag == 0)
+                    str_width_flag = 1;
+
+                if (width_flag == 1 && width_val > MAX_STR - 1)
+                {
+                    Scierror(998, _("%s: An error occurred: field %d is too long (> %d) for %%[ directive.\n"), fname, width_val, MAX_STR - 1);
+                    return RET_BUG;
+                }
+
+                if ((buf[num_conversion].c = MALLOC(MAX_STR)) == NULL)
+                    return MEM_LACK;
+                ptrtab[num_conversion] = buf[num_conversion].c;
+                type[num_conversion] = SF_S;
+                break;
+
+            case 's':
+                if (l_flag + h_flag)
+                {
+                    Scierror(998, _("%s: An error occurred: %s\n"), fname, _("Bad conversion."));
+                    return RET_BUG;
+                }
+
+                if (width_flag == 0)
+                    str_width_flag = 1;
+                if (width_flag == 1 && width_val > MAX_STR - 1)
+                {
+                    Scierror(998, _("%s: An error occurred: field %d is too long (< %d) for %%s directive.\n"), fname, width_val, MAX_STR - 1);
+                    return RET_BUG;
+                }
+
+                if ((buf[num_conversion].c = MALLOC(MAX_STR)) == NULL)
+                    return MEM_LACK;
+
+                ptrtab[num_conversion] = buf[num_conversion].c;
+                type[num_conversion] = SF_S;
+                break;
+
+            case 'c':
+                if (l_flag + h_flag)
+                {
+                    Scierror(998, _("%s: An error occurred: %s\n"), fname, _("Bad conversion."));
+                    return RET_BUG;
+                }
+
+                if (width_flag == 1)
+                    nc[num_conversion] = width_val;
+                else
+                    nc[num_conversion] = 1;
+
+                if (width_flag == 1 && width_val > MAX_STR - 1)
+                {
+                    Scierror(998, _("%s: An error occurred: field %d is too long (< %d) for %%c directive.\n"), fname, width_val, MAX_STR - 1);
+                    return RET_BUG;
+                }
+
+                if ((buf[num_conversion].c = MALLOC(MAX_STR)) == NULL)
+                    return MEM_LACK;
+
+                ptrtab[num_conversion] = buf[num_conversion].c;
+                type[num_conversion] = SF_C;
+                break;
+
+            case 'o':
+            case 'u':
+            case 'x':
+            case 'X':
+                if (l_flag)
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].lui;
+                    type[num_conversion] = SF_LUI;
+                }
+                else if (h_flag)
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].sui;
+                    type[num_conversion] = SF_SUI;
+                }
+                else
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].ui;
+                    type[num_conversion] = SF_UI;
+                }
+                break;
+
+            case 'D':
+                ptrtab[num_conversion] = &buf[num_conversion].li;
+                type[num_conversion] = SF_LI;
+                break;
+
+            case 'n':
+                n_directive_count++;
+
+            case 'i':
+            case 'd':
+                if (l_flag)
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].li;
+                    type[num_conversion] = SF_LI;
+                }
+                else if (h_flag)
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].si;
+                    type[num_conversion] = SF_SI;
+                }
+                else
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].i;
+                    type[num_conversion] = SF_I;
+                }
+                break;
+
+            case 'e':
+            case 'f':
+            case 'g':
+            case 'E':
+            case 'G':
+                if (h_flag)
+                {
+                    Scierror(998, _("%s: An error occurred: %s\n"), fname, _("Bad conversion."));
+                    return RET_BUG;
+                }
+                else if (l_flag)
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].lf;
+                    type[num_conversion] = SF_LF;
+                }
+                else
+                {
+                    ptrtab[num_conversion] = &buf[num_conversion].f;
+                    type[num_conversion] = SF_F;
+                }
+                break;
+
+            default:
+                Scierror(998, _("%s: An error occurred: %s\n"), fname, _("Bad conversion."));
+                return RET_BUG;
+            }
+            *currentchar = backupcurrrentchar;
+        }
+    }
+
+    if (str_width_flag == 1)
+    {
+        char *f1 = format;
+        char *f2 = sformat;
+        char *slast = sformat + MAX_STR - 1 - 4;
+
+        while (*f1 != '\0')
+        {
+            int n;
+
+            *f2++ = *f1++;
+
+            if (*(f1 - 1) == '%' && (*(f1) == 's' || *(f1) == '['))
+            {
+                n = sprintf(f2, "%d", MAX_STR - 1);
+                f2 += n;
+                *f2++ = *f1++;
+            }
+
+            if (f2 == slast)
+            {
+                Scierror(998, _("%s: An error occurred: format is too long (> %d).\n"), fname, MAX_STR - 1);
+                return RET_BUG;
+            }
+        }
+
+        *f2 = '\0';
+        format = sformat;
+    }
+
+    *retval = (*xxscanf) ((VPTR) target, format,
+                          ptrtab[0], ptrtab[1], ptrtab[2], ptrtab[3], ptrtab[4], ptrtab[5], ptrtab[6], ptrtab[7], ptrtab[8], ptrtab[9],
+                          ptrtab[10], ptrtab[11], ptrtab[12], ptrtab[13], ptrtab[14], ptrtab[15], ptrtab[16], ptrtab[17], ptrtab[18], ptrtab[19],
+                          ptrtab[20], ptrtab[21], ptrtab[22], ptrtab[23], ptrtab[24], ptrtab[25], ptrtab[26], ptrtab[27], ptrtab[28], ptrtab[29],
+                          ptrtab[30], ptrtab[31], ptrtab[32], ptrtab[33], ptrtab[34], ptrtab[35], ptrtab[36], ptrtab[37], ptrtab[38], ptrtab[39],
+                          ptrtab[40], ptrtab[41], ptrtab[42], ptrtab[43], ptrtab[44], ptrtab[45], ptrtab[46], ptrtab[47], ptrtab[48], ptrtab[49],
+                          ptrtab[50], ptrtab[51], ptrtab[52], ptrtab[53], ptrtab[54], ptrtab[55], ptrtab[56], ptrtab[57], ptrtab[58], ptrtab[59],
+                          ptrtab[60], ptrtab[61], ptrtab[62], ptrtab[63], ptrtab[64], ptrtab[65], ptrtab[66], ptrtab[67], ptrtab[68], ptrtab[69],
+                          ptrtab[70], ptrtab[71], ptrtab[72], ptrtab[73], ptrtab[74], ptrtab[75], ptrtab[76], ptrtab[77], ptrtab[78], ptrtab[79],
+                          ptrtab[80], ptrtab[81], ptrtab[82], ptrtab[83], ptrtab[84], ptrtab[85], ptrtab[86], ptrtab[87], ptrtab[88], ptrtab[89],
+                          ptrtab[90], ptrtab[91], ptrtab[92], ptrtab[93], ptrtab[94], ptrtab[95], ptrtab[96], ptrtab[97], ptrtab[98],
+                          ptrtab[MAXSCAN - 1]);
+
+    *nargs = Min(num_conversion + 1, Max(*retval + n_directive_count, 0));
+
+    for (i = 1; i <= *nargs; i++)
+    {
+        if (type[i - 1] == SF_C)
+        {
+            sval = (char *)ptrtab[i - 1];
+            sval[nc[i - 1]] = '\0';
+        }
+    }
+
+    return 0;
 }
-/*--------------------------------------------------------------------------*/
 
+/*--------------------------------------------------------------------------*/
index 96115c7..4e4d2eb 100644 (file)
 /*--------------------------------------------------------------------------*/
 static unsigned int isDirSeparator(const char c);
 static int normalizePath(char *path);
+
 /*--------------------------------------------------------------------------*/
-char * get_full_path(char * _FullPath, const char * _Path, size_t _SizeInBytes)
+char *get_full_path(char *_FullPath, const char *_Path, size_t _SizeInBytes)
 {
 #if defined(_MSC_VER)
-    char *returnedFullPath = NULL;     
+    char *returnedFullPath = NULL;
 
-    wchar_t *wPath = to_wide_string((char*)_Path);
-    wchar_t *wFullPath = (wchar_t *) MALLOC(sizeof(wchar_t)*_SizeInBytes);
+    wchar_t *wPath = to_wide_string((char *)_Path);
+    wchar_t *wFullPath = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);
 
-    _wfullpath(wFullPath,wPath, _SizeInBytes );
+    _wfullpath(wFullPath, wPath, _SizeInBytes);
     returnedFullPath = wide_string_to_UTF8(wFullPath);
     if (returnedFullPath)
     {
-        strcpy(_FullPath,returnedFullPath);
+        strcpy(_FullPath, returnedFullPath);
         FREE(returnedFullPath);
         returnedFullPath = NULL;
     }
 
-    if (wPath) {FREE(wPath);wPath=NULL;}
-    if (wFullPath) {FREE(wFullPath);wFullPath=NULL;}
+    if (wPath)
+    {
+        FREE(wPath);
+        wPath = NULL;
+    }
+    if (wFullPath)
+    {
+        FREE(wFullPath);
+        wFullPath = NULL;
+    }
 
     return _FullPath;
 #else
     char *rp = NULL;
     int lenPath = (int)strlen(_Path);
+
     rp = realpath(_Path, _FullPath);
     int lenFullPath = 0;
-    int haveFileSep = ( (lenPath > 1) && isDirSeparator(_Path[lenPath - 1]) );
+    int haveFileSep = ((lenPath > 1) && isDirSeparator(_Path[lenPath - 1]));
     int addFileSep = 0;
 
     if (!rp)
@@ -61,10 +71,11 @@ char * get_full_path(char * _FullPath, const char * _Path, size_t _SizeInBytes)
         normalizePath(_FullPath);
     }
     lenFullPath = (int)strlen(_FullPath);
-    addFileSep = ( (lenFullPath > 1) && (!isDirSeparator(_FullPath[lenFullPath - 1])) && haveFileSep );
+    addFileSep = ((lenFullPath > 1) && (!isDirSeparator(_FullPath[lenFullPath - 1])) && haveFileSep);
     if (addFileSep)
     {
-        char *bufTmp = (char *) MALLOC(sizeof(char)* (lenFullPath + strlen(DIR_SEPARATOR) + 1));
+        char *bufTmp = (char *)MALLOC(sizeof(char) * (lenFullPath + strlen(DIR_SEPARATOR) + 1));
+
         if (bufTmp)
         {
             sprintf(bufTmp, "%s%s", _FullPath, DIR_SEPARATOR);
@@ -76,17 +87,19 @@ char * get_full_path(char * _FullPath, const char * _Path, size_t _SizeInBytes)
     return _FullPath;
 #endif
 }
+
 /*--------------------------------------------------------------------------*/
-wchar_t * get_full_pathW(wchar_t * _wcFullPath, const wchar_t * _wcPath, size_t _SizeInBytes)
+wchar_t *get_full_pathW(wchar_t * _wcFullPath, const wchar_t * _wcPath, size_t _SizeInBytes)
 {
     wchar_t *wcResult = NULL;
+
 #if defined(_MSC_VER)
     if (_wcPath)
     {
-        wcResult = (wchar_t *) MALLOC(sizeof(wchar_t)*_SizeInBytes);
+        wcResult = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);
         if (wcResult)
         {
-            _wfullpath(wcResult, _wcPath, _SizeInBytes );
+            _wfullpath(wcResult, _wcPath, _SizeInBytes);
             wcscpy(_wcFullPath, wcResult);
         }
     }
@@ -94,12 +107,15 @@ wchar_t * get_full_pathW(wchar_t * _wcFullPath, const wchar_t * _wcPath, size_t
     if (_wcPath)
     {
         char *_Path = wide_string_to_UTF8(_wcPath);
+
         if (_Path)
         {
-            char *_FullPath = (char *) MALLOC(sizeof(char)*(_SizeInBytes));
+            char *_FullPath = (char *)MALLOC(sizeof(char) * (_SizeInBytes));
+
             if (_FullPath)
             {
                 char *rp = NULL;
+
                 rp = realpath(_Path, _FullPath);
                 if (!rp)
                 {
@@ -121,11 +137,13 @@ wchar_t * get_full_pathW(wchar_t * _wcFullPath, const wchar_t * _wcPath, size_t
 #endif
     return wcResult;
 }
+
 /*--------------------------------------------------------------------------*/
 static unsigned int isDirSeparator(const char c)
 {
     return (c == '/' || c == '\\');
 }
+
 /*--------------------------------------------------------------------------*/
 static int normalizePath(char *path)
 {
@@ -137,7 +155,7 @@ static int normalizePath(char *path)
     dirs[0] = path;
     depth++;
 
-    while(1)
+    while (1)
     {
         if ((srcptr[0] == '.') && isDirSeparator(srcptr[1]))
         {
@@ -147,7 +165,7 @@ static int normalizePath(char *path)
         else if (srcptr[0] == '.' && srcptr[1] == '.' && isDirSeparator(srcptr[2]))
         {
             /* ../ */
-            if(depth == 1)
+            if (depth == 1)
             {
                 /* ../ */
                 dstptr[0] = '.';
@@ -161,14 +179,14 @@ static int normalizePath(char *path)
             {
                 /* a/b/../c */
                 depth--;
-                dstptr = dirs[depth-1];
+                dstptr = dirs[depth - 1];
                 srcptr += 3;
             }
         }
-        else if(srcptr[0] == '.'  && srcptr[1] == '.' && srcptr[2] == 0)
+        else if (srcptr[0] == '.' && srcptr[1] == '.' && srcptr[2] == 0)
         {
             /* .. */
-            if(depth == 1)
+            if (depth == 1)
             {
                 dstptr[0] = '.';
                 dstptr[1] = '.';
@@ -179,33 +197,33 @@ static int normalizePath(char *path)
             else
             {
                 depth--;
-                dstptr = dirs[depth-1];
+                dstptr = dirs[depth - 1];
                 srcptr += 2;
             }
         }
         else
         {
-            while(!isDirSeparator(srcptr[0]) && srcptr[0])
+            while (!isDirSeparator(srcptr[0]) && srcptr[0])
             {
                 *dstptr++ = *srcptr++;
             }
 
-            if(srcptr[0] == 0)
+            if (srcptr[0] == 0)
             {
-                if(dstptr != path && isDirSeparator(dstptr[-1]))
+                if (dstptr != path && isDirSeparator(dstptr[-1]))
                 {
                     dstptr[-1] = 0;
                 }
                 dstptr[0] = 0;
                 return 0;
             }
-            else if(isDirSeparator(srcptr[0]))
+            else if (isDirSeparator(srcptr[0]))
             {
                 *dstptr++ = *srcptr++;
                 dirs[depth] = dstptr;
                 depth++;
                 /* // */
-                while(isDirSeparator(srcptr[0]) && srcptr[0])
+                while (isDirSeparator(srcptr[0]) && srcptr[0])
                 {
                     srcptr++;
                 }
@@ -217,6 +235,6 @@ static int normalizePath(char *path)
             }
         }
     }
-    return 0;
 }
+
 /*--------------------------------------------------------------------------*/
index a89dfdc..8746cd9 100644 (file)
@@ -137,7 +137,6 @@ void C2F(mgetnc) (int *fd, void *res, int *n1, char *type, int *ierr)
         default:
             *ierr = 1;
             return;
-            break;
         }
         break;
     default:
@@ -229,7 +228,6 @@ void mget2(FILE * fa, int swap2, double *res, int n, char *type, int *ierr)
         default:
             *ierr = 1;
             return;
-            break;
         }
         break;
     default:
index d57195f..6d8ed51 100644 (file)
 #include "freeArrayOfString.h"
 #include "FileExist.h"
 /*--------------------------------------------------------------------------*/
-static char *xls_basename (char *name);
+static char *xls_basename(char *name);
+
 /*--------------------------------------------------------------------------*/
-int sci_xls_open(char *fname,unsigned long fname_len)
+int sci_xls_open(char *fname, unsigned long fname_len)
 {
 #undef IN
-       #define max_char_xls_open 256
-       int i = 0,m1 = 0,n1 = 0,l1 = 0,l2 = 0,one = 1,fd = 0,f_swap = 0;
-       int ierr = 0,ns = 0,result = 0;
-       double res;
-       char **sst = NULL;
-       char **Sheetnames = NULL;
-       int *Abspos = NULL;
-       int nsheets = 0;
-       char *filename_IN = NULL;
-       char TMP[max_char_xls_open];
-
-       char sep[2];
-       char *TMPDIR = NULL;
+#define max_char_xls_open 256
+    int i = 0, m1 = 0, n1 = 0, l1 = 0, l2 = 0, one = 1, fd = 0, f_swap = 0;
+    int ierr = 0, ns = 0, result = 0;
+    double res;
+    char **sst = NULL;
+    char **Sheetnames = NULL;
+    int *Abspos = NULL;
+    int nsheets = 0;
+    char *filename_IN = NULL;
+    char TMP[max_char_xls_open];
+
+    char sep[2];
+    char *TMPDIR = NULL;
+
 #ifdef _MSC_VER
-       sep[0]='\\';
+    sep[0] = '\\';
 #else
-       sep[0]='/';
+    sep[0] = '/';
 #endif
-       sep[1]='\0';
-
-       CheckLhs(4,4);
-       CheckRhs(1,1);
-
-       if (VarType(1) != sci_strings)
-       {
-               Scierror(999,"%s: Invalid type of input argument: String expected.", fname);
-               return 0;
-       }
-
-       /*  checking variable file */
-       GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-
-       filename_IN = expandPathVariable(cstk(l1));
-       if (filename_IN)
-       {
-               /* bug 5615 */
-               /* remove blank characters @ the end */
-               int len =(int)strlen(filename_IN);
-               int i = 0;
-
-               if (len >= 1)
-               {
-                       for (i = len - 1; i >= 0  ; i--)
-                       {
-                               if (filename_IN[i] == ' ')  filename_IN[i] = '\0';
-                               else break;
-                       }
-               }
-
-               if (!FileExist(filename_IN))
-               {
-                       Scierror(999,_("The file %s does not exist.\n"), filename_IN);
-                       return 0;
-               }
-       }
-
-       TMPDIR = getTMPDIR();
-       strcpy(TMP, TMPDIR);
-       if (TMPDIR){FREE(TMPDIR);TMPDIR=NULL;}
-
-       strcat(TMP,sep);
-       strcat(TMP,xls_basename(filename_IN));
-       result = ripole(filename_IN, TMP, 0, 0);
-       if (result != OLE_OK) 
-       {
-               if (result == OLEER_NO_INPUT_FILE) 
-               {
-                       Scierror(999,_("The file %s does not exist.\n"), filename_IN);
-               }
-               else if(result == OLEER_NOT_OLE_FILE || 
-                       result == OLEER_INSANE_OLE_FILE || 
-                       result == OLEER_LOADFAT_BAD_BOUNDARY || 
-                       result == OLEER_MINIFAT_READ_FAIL || 
-                       result == OLEER_PROPERTIES_READ_FAIL)
-               {
-                       Scierror(999,_("%s: File %s is not an ole2 file.\n"),fname, filename_IN);
-                       if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
-               }
-               else if(result == -1)
-               {
-                       Scierror(999,_("%s: Cannot open file %s.\n"),fname, filename_IN);
-                       if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
-               }
-               return 0;
-       }
-       strcat(TMP,sep);
-       strcat(TMP,"Workbook");
-       C2F(mopen)(&fd, TMP,"rb", &f_swap, &res, &ierr);
-       if (ierr != 0)
-       {
-               Scierror(999,_("%s: There is no xls stream in the ole2 file %s.\n"),fname, filename_IN);
-               if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
-               return 0;
-       }
-
-       if (filename_IN) {FREE(filename_IN); filename_IN = NULL;}
-
-       CreateVar(Rhs+1,MATRIX_OF_INTEGER_DATATYPE,&one,&one,&l2);
-       *istk(l2)=fd; /* logical unit */
-
-       xls_open(&ierr, &fd, &sst ,&ns, &Sheetnames, &Abspos,&nsheets);
-       /*return *err:
-       0 = OK
-       1 = not an OLE file
-       2 = no Workbook included
-       3 = memory allocation problem
-       4 = incorrect file
-       5 = not a BIFF8 xls file
-       */
-       switch (ierr)
-       {
-               case 0:
-                       /* OK */
-                       break;
-
-               case 1:
-                       Scierror(999,_("%s: Not an ole2 file.\n"),fname);
-                       return 0;
-                       break;
-
-               case 2:
-                       Scierror(999,_("%s: The file has no Workbook directory.\n"),fname);
-                       return 0;
-                       break;
-
-               case 3:
-                       Scierror(999,_("%s: No more memory.\n"),fname);
-                       return 0;
-                       break;
-
-               case 4:
-                       Scierror(990,_("%s: Incorrect or corrupted file.\n"),fname);
-                       return 0;
-                       break;
-
-               case 5:
-                       Scierror(999,_("%s: Only BIFF8 file format is handled.\n"),fname);
-                       return 0;
-                       break;
-               default :
-                       break;
-
-       }
-
-       if (ns != 0) 
-       {
-               /* Create a typed list to return the properties */
-               CreateVarFromPtr(Rhs+2,MATRIX_OF_STRING_DATATYPE, &one, &ns, sst);
-               freeArrayOfString(sst, ns);
-       }
-       else CreateVar(Rhs+2,MATRIX_OF_DOUBLE_DATATYPE,&ns,&ns,&l2);
-
-       if (nsheets != 0) 
-       {
-               /* Create a typed list to return the properties */
-               CreateVarFromPtr(Rhs+3,MATRIX_OF_STRING_DATATYPE, &one, &nsheets, Sheetnames);
-               freeArrayOfString(Sheetnames, nsheets);
-
-               CreateVar(Rhs+4,MATRIX_OF_DOUBLE_DATATYPE, &one, &nsheets, &l2);
-               for (i = 0;i < nsheets;i++) *stk(l2+i) = Abspos[i];
-               if (Abspos)
-               {
-                       FREE(Abspos);
-                       Abspos = NULL;
-               }
-       }
-       else 
-       {
-               CreateVar(Rhs+3,MATRIX_OF_DOUBLE_DATATYPE,&nsheets,&nsheets,&l2);
-               CreateVar(Rhs+4,MATRIX_OF_DOUBLE_DATATYPE,&nsheets,&nsheets,&l2);
-       }
-
-       LhsVar(1)= Rhs+1;
-       LhsVar(2)= Rhs+2;
-       LhsVar(3)= Rhs+3;
-       LhsVar(4)= Rhs+4;
-
-       PutLhsVar();
-
-       return 0;
+    sep[1] = '\0';
+
+    CheckLhs(4, 4);
+    CheckRhs(1, 1);
+
+    if (VarType(1) != sci_strings)
+    {
+        Scierror(999, "%s: Invalid type of input argument: String expected.", fname);
+        return 0;
+    }
+
+    /*  checking variable file */
+    GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
+
+    filename_IN = expandPathVariable(cstk(l1));
+    if (filename_IN)
+    {
+        /* bug 5615 */
+        /* remove blank characters @ the end */
+        int len = (int)strlen(filename_IN);
+        int i = 0;
+
+        if (len >= 1)
+        {
+            for (i = len - 1; i >= 0; i--)
+            {
+                if (filename_IN[i] == ' ')
+                    filename_IN[i] = '\0';
+                else
+                    break;
+            }
+        }
+
+        if (!FileExist(filename_IN))
+        {
+            Scierror(999, _("The file %s does not exist.\n"), filename_IN);
+            return 0;
+        }
+    }
+
+    TMPDIR = getTMPDIR();
+    strcpy(TMP, TMPDIR);
+    if (TMPDIR)
+    {
+        FREE(TMPDIR);
+        TMPDIR = NULL;
+    }
+
+    strcat(TMP, sep);
+    strcat(TMP, xls_basename(filename_IN));
+    result = ripole(filename_IN, TMP, 0, 0);
+    if (result != OLE_OK)
+    {
+        if (result == OLEER_NO_INPUT_FILE)
+        {
+            Scierror(999, _("The file %s does not exist.\n"), filename_IN);
+        }
+        else if (result == OLEER_NOT_OLE_FILE ||
+                 result == OLEER_INSANE_OLE_FILE ||
+                 result == OLEER_LOADFAT_BAD_BOUNDARY || result == OLEER_MINIFAT_READ_FAIL || result == OLEER_PROPERTIES_READ_FAIL)
+        {
+            Scierror(999, _("%s: File %s is not an ole2 file.\n"), fname, filename_IN);
+            if (filename_IN)
+            {
+                FREE(filename_IN);
+                filename_IN = NULL;
+            }
+        }
+        else if (result == -1)
+        {
+            Scierror(999, _("%s: Cannot open file %s.\n"), fname, filename_IN);
+            if (filename_IN)
+            {
+                FREE(filename_IN);
+                filename_IN = NULL;
+            }
+        }
+        return 0;
+    }
+    strcat(TMP, sep);
+    strcat(TMP, "Workbook");
+    C2F(mopen) (&fd, TMP, "rb", &f_swap, &res, &ierr);
+    if (ierr != 0)
+    {
+        Scierror(999, _("%s: There is no xls stream in the ole2 file %s.\n"), fname, filename_IN);
+        if (filename_IN)
+        {
+            FREE(filename_IN);
+            filename_IN = NULL;
+        }
+        return 0;
+    }
+
+    if (filename_IN)
+    {
+        FREE(filename_IN);
+        filename_IN = NULL;
+    }
+
+    CreateVar(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &one, &one, &l2);
+    *istk(l2) = fd;             /* logical unit */
+
+    xls_open(&ierr, &fd, &sst, &ns, &Sheetnames, &Abspos, &nsheets);
+    /*return *err:
+     * 0 = OK
+     * 1 = not an OLE file
+     * 2 = no Workbook included
+     * 3 = memory allocation problem
+     * 4 = incorrect file
+     * 5 = not a BIFF8 xls file
+     */
+    switch (ierr)
+    {
+    case 0:
+        /* OK */
+        break;
+
+    case 1:
+        Scierror(999, _("%s: Not an ole2 file.\n"), fname);
+        return 0;
+
+    case 2:
+        Scierror(999, _("%s: The file has no Workbook directory.\n"), fname);
+        return 0;
+
+    case 3:
+        Scierror(999, _("%s: No more memory.\n"), fname);
+        return 0;
+
+    case 4:
+        Scierror(990, _("%s: Incorrect or corrupted file.\n"), fname);
+        return 0;
+
+    case 5:
+        Scierror(999, _("%s: Only BIFF8 file format is handled.\n"), fname);
+        return 0;
+
+    default:
+        break;
+
+    }
+
+    if (ns != 0)
+    {
+        /* Create a typed list to return the properties */
+        CreateVarFromPtr(Rhs + 2, MATRIX_OF_STRING_DATATYPE, &one, &ns, sst);
+        freeArrayOfString(sst, ns);
+    }
+    else
+        CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE, &ns, &ns, &l2);
+
+    if (nsheets != 0)
+    {
+        /* Create a typed list to return the properties */
+        CreateVarFromPtr(Rhs + 3, MATRIX_OF_STRING_DATATYPE, &one, &nsheets, Sheetnames);
+        freeArrayOfString(Sheetnames, nsheets);
+
+        CreateVar(Rhs + 4, MATRIX_OF_DOUBLE_DATATYPE, &one, &nsheets, &l2);
+        for (i = 0; i < nsheets; i++)
+            *stk(l2 + i) = Abspos[i];
+        if (Abspos)
+        {
+            FREE(Abspos);
+            Abspos = NULL;
+        }
+    }
+    else
+    {
+        CreateVar(Rhs + 3, MATRIX_OF_DOUBLE_DATATYPE, &nsheets, &nsheets, &l2);
+        CreateVar(Rhs + 4, MATRIX_OF_DOUBLE_DATATYPE, &nsheets, &nsheets, &l2);
+    }
+
+    LhsVar(1) = Rhs + 1;
+    LhsVar(2) = Rhs + 2;
+    LhsVar(3) = Rhs + 3;
+    LhsVar(4) = Rhs + 4;
+
+    PutLhsVar();
+
+    return 0;
 }
+
 /*--------------------------------------------------------------------------*/
-static char *xls_basename (char *name)
+static char *xls_basename(char *name)
 {
-       char *base=NULL;
+    char *base = NULL;
+
 #ifdef _MSC_VER
-       base = strrchr (name, '\\');
+    base = strrchr(name, '\\');
 #else
-       base = strrchr (name, '/');
+    base = strrchr(name, '/');
 #endif
-       return base ? base + 1 : name;
+    return base ? base + 1 : name;
 }
+
 /*--------------------------------------------------------------------------*/
index 0763087..d6b0cac 100644 (file)
@@ -21,8 +21,7 @@
 #define OLE_SECTORID_SAT       -3 /** Sector used by sector allocation Table  **/
 #define OLE_SECTORID_MSAT      -4 /** Sector used by master sector allocation Table **/
 
-#include "MALLOC.h" /* MALLOC */
-
+#include "MALLOC.h"             /* MALLOC */
 
 /* Main header accessors*/
 #define header_id(x)                                           ((x) +0)
@@ -75,9 +74,8 @@
 #define DOLE   if (OLE_DNORMAL(ole->debug))
 #define VOLE   if (ole->verbose)
 
-
-unsigned char OLE_id_v2[]={ 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 };
-unsigned char OLE_id_v1[]={ 0x0e, 0x11, 0xfc, 0x0d, 0xd0, 0xcf, 0x11, 0xe0 };
+unsigned char OLE_id_v2[] = { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 };
+unsigned char OLE_id_v1[] = { 0x0e, 0x11, 0xfc, 0x0d, 0xd0, 0xcf, 0x11, 0xe0 };
 
 /*-----------------------------------------------------------------\
 Function Name  : OLE_version
@@ -94,14 +92,13 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_version( void )
+int OLE_version(void)
 {
-       fprintf(stderr,_("ripOLE: %s\n"), LIBOLE_VERSION);
+    fprintf(stderr, _("ripOLE: %s\n"), LIBOLE_VERSION);
 
-       return 0;
+    return 0;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_init
 Returns Type   : int
@@ -117,28 +114,28 @@ Comments:
 Changes:
 20041127-2029:PLD: Added file_size initialization
 \------------------------------------------------------------------*/
-int OLE_init( struct OLE_object *ole )
+int OLE_init(struct OLE_object *ole)
 {
-       ole->debug = 0;
-       ole->verbose = 0;
-       ole->quiet = 0;
-       ole->filename_report_fn = NULL;
-       ole->f = NULL;
-       ole->file_size = 0;
-
-       ole->FAT = NULL;
-       ole->FAT_limit = NULL;
-       ole->miniFAT = NULL;
-       ole->miniFAT_limit = NULL;
-
-       ole->header_block[0] = '\0';
-       ole->ministream = NULL;
-       ole->properties = NULL;
-
-       ole->header.sector_shift = 0;
-       ole->header.mini_sector_shift = 0;
-
-       return OLE_OK;
+    ole->debug = 0;
+    ole->verbose = 0;
+    ole->quiet = 0;
+    ole->filename_report_fn = NULL;
+    ole->f = NULL;
+    ole->file_size = 0;
+
+    ole->FAT = NULL;
+    ole->FAT_limit = NULL;
+    ole->miniFAT = NULL;
+    ole->miniFAT_limit = NULL;
+
+    ole->header_block[0] = '\0';
+    ole->ministream = NULL;
+    ole->properties = NULL;
+
+    ole->header.sector_shift = 0;
+    ole->header.mini_sector_shift = 0;
+
+    return OLE_OK;
 }
 
 /*-----------------------------------------------------------------\
@@ -156,25 +153,25 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_dir_init(struct OLE_directory_entry *dir )
+int OLE_dir_init(struct OLE_directory_entry *dir)
 {
-       memset(dir->element_name,'\0', OLE_DIRECTORY_ELEMENT_NAME_SIZE);
-       dir->element_name_byte_count = 0;
+    memset(dir->element_name, '\0', OLE_DIRECTORY_ELEMENT_NAME_SIZE);
+    dir->element_name_byte_count = 0;
 
-       dir->element_type = 0;
-       dir->element_colour = 0;
+    dir->element_type = 0;
+    dir->element_colour = 0;
 
-       dir->left_child = 0;
-       dir->right_child = 0;
-       dir->root = 0;
+    dir->left_child = 0;
+    dir->right_child = 0;
+    dir->root = 0;
 
-       dir->class[0] = '\0';
-       dir->userflags = 0;
-       dir->timestamps[0] = '\0';
-       dir->start_sector = 0;
-       dir->stream_size = 0;
+    dir->class[0] = '\0';
+    dir->userflags = 0;
+    dir->timestamps[0] = '\0';
+    dir->start_sector = 0;
+    dir->stream_size = 0;
 
-       return 0;
+    return 0;
 };
 
 /*-----------------------------------------------------------------\
@@ -193,14 +190,12 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_set_verbose( struct OLE_object *ole, int level )
+int OLE_set_verbose(struct OLE_object *ole, int level)
 {
-       ole->verbose = level;
-       return OLE_OK;
+    ole->verbose = level;
+    return OLE_OK;
 }
 
-
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_set_quiet
 Returns Type   : int
@@ -217,16 +212,15 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_set_quiet( struct OLE_object *ole, int level )
+int OLE_set_quiet(struct OLE_object *ole, int level)
 {
-       ole->quiet = level;
-       ole->verbose = 0;
-       ole->debug = 0;
+    ole->quiet = level;
+    ole->verbose = 0;
+    ole->debug = 0;
 
-       return OLE_OK;
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_set_debug
 Returns Type   : int
@@ -243,15 +237,15 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_set_debug( struct OLE_object *ole, int level )
+int OLE_set_debug(struct OLE_object *ole, int level)
 {
-       ole->debug = level;
-       if (ole->debug > 0) LOGGER_log(_("%s:%d:OLE_set_debug: Debug level set to %d"),FL, ole->debug);
+    ole->debug = level;
+    if (ole->debug > 0)
+        LOGGER_log(_("%s:%d:OLE_set_debug: Debug level set to %d"), FL, ole->debug);
 
-       return OLE_OK;
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_set_save_unknown_streams
 Returns Type   : int
@@ -268,14 +262,13 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_set_save_unknown_streams( struct OLE_object  *ole, int level )
+int OLE_set_save_unknown_streams(struct OLE_object *ole, int level)
 {
-       ole->save_unknown_streams = level;
+    ole->save_unknown_streams = level;
 
-       return OLE_OK;
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_sectorpos
 Returns Type   : int
@@ -297,16 +290,15 @@ is the size of the OLE header)
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_sectorpos( struct OLE_object *ole, int SID )
+int OLE_sectorpos(struct OLE_object *ole, int SID)
 {
-       int pos = 0;
+    int pos = 0;
 
-       pos = 512 +(SID *ole->header.sector_size);
+    pos = 512 + (SID * ole->header.sector_size);
 
-       return pos;
+    return pos;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_get_block
 Returns Type   : int
@@ -324,75 +316,90 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_get_block( struct OLE_object *ole, int block_index, unsigned char *block_buffer )
+int OLE_get_block(struct OLE_object *ole, int block_index, unsigned char *block_buffer)
 {
-       if (block_buffer == NULL)
-       {
-               LOGGER_log(_("%s:%d:OLE_get_block:ERROR: Block buffer is NULL"),FL);
-               return -1;
-       }
-
-       if (ole->f != NULL)
-       {
-               int read_count = 0;
-               int fseek_result = 0;
-               size_t offset = 0;
-               unsigned char *bb = NULL;
-
-               bb = MALLOC(sizeof(unsigned char) *ole->header.sector_size);
-               if (bb == NULL)
-               {
-                       LOGGER_log(_("%s:%d:OLE_get_block:ERROR: Cannot allocate %d bytes for OLE block"),FL, ole->header.sector_size);
-                       return -1;
-               }
-
-               DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: BlockIndex=%d, Buffer=0x%x",FL, block_index, block_buffer);
-
-               /*20051211-2343:PLD: offset = (block_index +1) << ole->header.sector_shift;*/
-               offset = OLE_sectorpos(ole, block_index);
-
-               DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Read offset in file = 0x%x size to read= 0x%x",FL,offset,ole->header.sector_size);
-
-               fseek_result = fseek(ole->f, (long)offset, SEEK_SET);
-               if (fseek_result != 0)
-               {
-                       if (bb != NULL) { FREE(bb); bb = NULL; }
-                       LOGGER_log(_("%s:%d:OLE_get_block:ERROR: Seek failure (block=%d:%d)"),FL, block_index,offset, strerror(errno));
-                       return OLEER_GET_BLOCK_SEEK;
-               }
-
-               /*read_count = fread(block_buffer, sizeof(unsigned char), ole->header.sector_size, ole->f);*/
-               read_count = (int)fread(bb, sizeof(unsigned char), ole->header.sector_size, ole->f);
-               DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Read %d byte of data",FL,read_count);
-               if (read_count != (int)ole->header.sector_size)
-               {
-                       if (bb != NULL){ FREE(bb); bb = NULL; }
-                       VOLE LOGGER_log(_("%s:%d:Mismatch in bytes read. Requested %d, got %d\n"), FL, ole->header.sector_size, read_count);
-                       return OLEER_GET_BLOCK_READ;
-               }
-
-               DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Copying over memory read from file",FL);
-
-               memcpy(block_buffer, bb, ole->header.sector_size);
-
-               DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: memory block copied to block_buffer",FL);
-
-               /* We're now done with BB, dispose of it */
-               if (bb) { FREE(bb); bb = NULL; }
-
-               DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Disposed of temporary bb block",FL);
-
-       } else {
-               LOGGER_log(_("%s:%d:OLE_get_block:ERROR: OLE file is closed\n"),FL);
-               return -1;
-       }
-
-       DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Done",FL);
-
-       return OLE_OK;
+    if (block_buffer == NULL)
+    {
+        LOGGER_log(_("%s:%d:OLE_get_block:ERROR: Block buffer is NULL"), FL);
+        return -1;
+    }
+
+    if (ole->f != NULL)
+    {
+        int read_count = 0;
+        int fseek_result = 0;
+        size_t offset = 0;
+        unsigned char *bb = NULL;
+
+        bb = MALLOC(sizeof(unsigned char) * ole->header.sector_size);
+        if (bb == NULL)
+        {
+            LOGGER_log(_("%s:%d:OLE_get_block:ERROR: Cannot allocate %d bytes for OLE block"), FL, ole->header.sector_size);
+            return -1;
+        }
+
+        DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: BlockIndex=%d, Buffer=0x%x", FL, block_index, block_buffer);
+
+        /*20051211-2343:PLD: offset = (block_index +1) << ole->header.sector_shift; */
+        offset = OLE_sectorpos(ole, block_index);
+
+        DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Read offset in file = 0x%x size to read= 0x%x", FL, offset, ole->header.sector_size);
+
+        fseek_result = fseek(ole->f, (long)offset, SEEK_SET);
+        if (fseek_result != 0)
+        {
+            if (bb != NULL)
+            {
+                FREE(bb);
+                bb = NULL;
+            }
+            LOGGER_log(_("%s:%d:OLE_get_block:ERROR: Seek failure (block=%d:%d)"), FL, block_index, offset, strerror(errno));
+            return OLEER_GET_BLOCK_SEEK;
+        }
+
+        /*read_count = fread(block_buffer, sizeof(unsigned char), ole->header.sector_size, ole->f); */
+        read_count = (int)fread(bb, sizeof(unsigned char), ole->header.sector_size, ole->f);
+        DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Read %d byte of data", FL, read_count);
+
+        if (read_count != (int)ole->header.sector_size)
+        {
+            if (bb != NULL)
+            {
+                FREE(bb);
+                bb = NULL;
+            }
+            VOLE LOGGER_log(_("%s:%d:Mismatch in bytes read. Requested %d, got %d\n"), FL, ole->header.sector_size, read_count);
+
+            return OLEER_GET_BLOCK_READ;
+        }
+
+        DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Copying over memory read from file", FL);
+
+        memcpy(block_buffer, bb, ole->header.sector_size);
+
+        DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: memory block copied to block_buffer", FL);
+
+        /* We're now done with BB, dispose of it */
+        if (bb)
+        {
+            FREE(bb);
+            bb = NULL;
+        }
+
+        DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Disposed of temporary bb block", FL);
+
+    }
+    else
+    {
+        LOGGER_log(_("%s:%d:OLE_get_block:ERROR: OLE file is closed\n"), FL);
+        return -1;
+    }
+
+    DOLE LOGGER_log("%s:%d:OLE_get_block:DEBUG: Done", FL);
+
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_get_miniblock
 Returns Type   : int
@@ -410,19 +417,19 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_get_miniblock( struct OLE_object *ole, int block_index, unsigned char *block_buffer )
+int OLE_get_miniblock(struct OLE_object *ole, int block_index, unsigned char *block_buffer)
 {
-       /* This code may refer memory outside of the allocated one for  ole->ministream *
-       in case of VBA Streams Serge Steer 26/01/2007*/
-       if (ole->ministream)
-       {
-               int offset = block_index << ole->header.mini_sector_shift;
-               memcpy( block_buffer, ole->ministream +offset, ole->header.mini_sector_size);
-       }
-
-       return OLE_OK;
-}
+    /* This code may refer memory outside of the allocated one for  ole->ministream *
+     * in case of VBA Streams Serge Steer 26/01/2007 */
+    if (ole->ministream)
+    {
+        int offset = block_index << ole->header.mini_sector_shift;
+
+        memcpy(block_buffer, ole->ministream + offset, ole->header.mini_sector_size);
+    }
 
+    return OLE_OK;
+}
 
 /*-----------------------------------------------------------------\
 Function Name  : OLE_dbstosbs
@@ -441,27 +448,27 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_dbstosbs( char *raw_string, size_t byte_count, char *clean_string, int clean_string_len )
+int OLE_dbstosbs(char *raw_string, size_t byte_count, char *clean_string, int clean_string_len)
 {
-       char *limit = raw_string +byte_count -1;
+    char *limit = raw_string + byte_count - 1;
 
-       clean_string_len--;
+    clean_string_len--;
 
-       while ((raw_string < limit)&&(byte_count >0)&&(byte_count--)&&(clean_string_len--))
-       {
-               int v = (char)*raw_string;
+    while ((raw_string < limit) && (byte_count > 0) && (byte_count--) && (clean_string_len--))
+    {
+        int v = (char)*raw_string;
 
-               if (isprint(v))
-               {
-                       *clean_string = (char)v;
-                       clean_string++;
-               }
+        if (isprint(v))
+        {
+            *clean_string = (char)v;
+            clean_string++;
+        }
 
-               raw_string += 2;
-       }
-       *clean_string = '\0';
+        raw_string += 2;
+    }
+    *clean_string = '\0';
 
-       return OLE_OK;
+    return OLE_OK;
 }
 
 /*-----------------------------------------------------------------\
@@ -480,15 +487,16 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_print_string( char *string, size_t char_count)
+int OLE_print_string(char *string, size_t char_count)
 {
-       while (char_count--)
-       {
-               printf("%c",*string);
-               string += 2;
-       }
-       return OLE_OK;
+    while (char_count--)
+    {
+        printf("%c", *string);
+        string += 2;
+    }
+    return OLE_OK;
 }
+
 /*-----------------------------------------------------------------\
 Function Name  : OLE_print_sector
 Returns Type   : int
@@ -505,28 +513,32 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-static int OLE_print_sector( struct OLE_object *ole, unsigned char *sector, unsigned int bytes)
+static int OLE_print_sector(struct OLE_object *ole, unsigned char *sector, unsigned int bytes)
 {
-       int current_byte;
-       int ubytes = bytes;
-
-       printf("\n");
-       for (current_byte = 0; current_byte < ubytes; current_byte++ )
-       {
-               printf("%02X ", *(sector +current_byte));
-               if (((current_byte+1) %32)==0) {
-                       int j;
-                       for (j = current_byte -31; j <=current_byte; j++)
-                       {
-                               if (isalnum(*(sector +j))) printf("%c",*(sector+j));
-                               else printf(".");
-                       }
-                       printf("\n");
-               }
-       }
-       printf("\n");
-
-       return OLE_OK;
+    int current_byte;
+    int ubytes = bytes;
+
+    printf("\n");
+    for (current_byte = 0; current_byte < ubytes; current_byte++)
+    {
+        printf("%02X ", *(sector + current_byte));
+        if (((current_byte + 1) % 32) == 0)
+        {
+            int j;
+
+            for (j = current_byte - 31; j <= current_byte; j++)
+            {
+                if (isalnum(*(sector + j)))
+                    printf("%c", *(sector + j));
+                else
+                    printf(".");
+            }
+            printf("\n");
+        }
+    }
+    printf("\n");
+
+    return OLE_OK;
 }
 
 /*-----------------------------------------------------------------\
@@ -544,13 +556,15 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_is_file_OLE( struct OLE_object *ole )
+int OLE_is_file_OLE(struct OLE_object *ole)
 {
 
-       if (memcmp(OLE_id_v1, ole->header_block, sizeof(OLE_id_v1))==0) return 1;
-       if (memcmp(OLE_id_v2, ole->header_block, sizeof(OLE_id_v2))==0) return 1;
+    if (memcmp(OLE_id_v1, ole->header_block, sizeof(OLE_id_v1)) == 0)
+        return 1;
+    if (memcmp(OLE_id_v2, ole->header_block, sizeof(OLE_id_v2)) == 0)
+        return 1;
 
-       return 0;
+    return 0;
 
 }
 
@@ -569,18 +583,19 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_get_header( struct OLE_object *ole )
+int OLE_get_header(struct OLE_object *ole)
 {
-       int result = 0;
-       ole->header.sector_size = OLE_HEADER_BLOCK_SIZE;
-       result = OLE_get_block( ole, -1, ole->header_block );
+    int result = 0;
+
+    ole->header.sector_size = OLE_HEADER_BLOCK_SIZE;
+    result = OLE_get_block(ole, -1, ole->header_block);
 
-       if (OLE_is_file_OLE( ole ) == 0)
-       {
-               return OLEER_NOT_OLE_FILE;
-       }
+    if (OLE_is_file_OLE(ole) == 0)
+    {
+        return OLEER_NOT_OLE_FILE;
+    }
 
-       return OLE_OK;
+    return OLE_OK;
 }
 
 /*-----------------------------------------------------------------\
@@ -598,57 +613,57 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_convert_header( struct OLE_object *ole )
+int OLE_convert_header(struct OLE_object *ole)
 {
-       struct OLE_header *h;
-       unsigned char *hb; /** pointer to the header block **/
-       unsigned char *fat_start;
-       unsigned int i;
+    struct OLE_header *h;
+    unsigned char *hb; /** pointer to the header block **/
+    unsigned char *fat_start;
+    unsigned int i;
 
-       h = &(ole->header);
-       hb = ole->header_block;
+    h = &(ole->header);
+    hb = ole->header_block;
 
-       /** Note that the header_*(hb) calls are actually macros which are
+    /** Note that the header_*(hb) calls are actually macros which are
        ** defined in the ole.h file.  These macros basically take the
        ** hb value and add the required offset, they don't affect the
        ** value of hb (or they certainly SHOULD NOT! )
        **/
 
-       h->minor_version = get_2byte_value(header_minor_version(hb));
-       h->dll_version = get_2byte_value(header_dll_version(hb));
-       h->byte_order = get_2byte_value(header_byte_order(hb)); /** 0xFEFF = Little endian, 0xFFFE = big endian **/
-       h->sector_shift = get_2byte_value(header_sector_shift(hb));
-       h->sector_size = 1 << h->sector_shift;
+    h->minor_version = get_2byte_value(header_minor_version(hb));
+    h->dll_version = get_2byte_value(header_dll_version(hb));
+    h->byte_order = get_2byte_value(header_byte_order(hb)); /** 0xFEFF = Little endian, 0xFFFE = big endian **/
+    h->sector_shift = get_2byte_value(header_sector_shift(hb));
+    h->sector_size = 1 << h->sector_shift;
 
-       h->mini_sector_shift = get_2byte_value(header_mini_sector_shift(hb));
-       h->mini_sector_size = 1 << h->mini_sector_shift;
+    h->mini_sector_shift = get_2byte_value(header_mini_sector_shift(hb));
+    h->mini_sector_size = 1 << h->mini_sector_shift;
 
-       h->fat_sector_count = get_4byte_value(header_fat_sector_count(hb)); /** Total number of sectors use for the SAT **/
-       h->directory_stream_start_sector = get_4byte_value(header_directory_stream_start_sector(hb)); /** Start sector-ID for the DIRECTORY STREAM **/
-       h->mini_cutoff_size = get_4byte_value(header_mini_cutoff_size(hb));
-       h->mini_fat_start = get_4byte_value(header_mini_fat_start(hb));
-       h->mini_fat_sector_count = get_4byte_value(header_mini_fat_sector_count(hb));
-       h->dif_start_sector = get_4byte_value(header_dif_start_sector(hb));
-       h->dif_sector_count = get_4byte_value(header_dif_sector_count(hb));
+    h->fat_sector_count = get_4byte_value(header_fat_sector_count(hb)); /** Total number of sectors use for the SAT **/
+    h->directory_stream_start_sector = get_4byte_value(header_directory_stream_start_sector(hb)); /** Start sector-ID for the DIRECTORY STREAM **/
+    h->mini_cutoff_size = get_4byte_value(header_mini_cutoff_size(hb));
+    h->mini_fat_start = get_4byte_value(header_mini_fat_start(hb));
+    h->mini_fat_sector_count = get_4byte_value(header_mini_fat_sector_count(hb));
+    h->dif_start_sector = get_4byte_value(header_dif_start_sector(hb));
+    h->dif_sector_count = get_4byte_value(header_dif_sector_count(hb));
 
-       /** Compute the maximum possible sector number by taking our OLE filesize
+    /** Compute the maximum possible sector number by taking our OLE filesize
        ** and dividing it by the size of our sector size.  While this isn't
        ** absolutely accurate it is at least useful in providing us with an
        ** upper-bound of what is an acceptable sector ID **/
-       ole->last_sector = (int)(ole->file_size  >> h->sector_shift);
-
-       /** Decode our first 109 sector-ID's into the master sector allocation table (MSAT/FAT) **/
-       fat_start = header_fat_sectors(hb);
-       for (i = 0; i < h->fat_sector_count; i++)
-       {
-               if (i >= OLE_HEADER_FAT_SECTOR_COUNT_LIMIT) break;
-               h->FAT[i] = get_4byte_value( fat_start +(LEN_ULONG *i));
-       }
-
-       return OLE_OK;
+    ole->last_sector = (int)(ole->file_size >> h->sector_shift);
+
+    /** Decode our first 109 sector-ID's into the master sector allocation table (MSAT/FAT) **/
+    fat_start = header_fat_sectors(hb);
+    for (i = 0; i < h->fat_sector_count; i++)
+    {
+        if (i >= OLE_HEADER_FAT_SECTOR_COUNT_LIMIT)
+            break;
+        h->FAT[i] = get_4byte_value(fat_start + (LEN_ULONG * i));
+    }
+
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_header_sanity_check
 Returns Type   : int
@@ -667,26 +682,30 @@ Changes:
 20041127-2027:PLD: Initial version
 
 \------------------------------------------------------------------*/
-static int OLE_header_sanity_check( struct OLE_object *ole )
+static int OLE_header_sanity_check(struct OLE_object *ole)
 {
-       int insanity=0;
-       int max_sectors;
-       struct OLE_header *h;
-
-       h = &(ole->header);
-
-       max_sectors = (int)(ole->file_size / h->sector_size);
-
-       if (h->sector_shift > 20) insanity++;
-       if (h->mini_sector_shift > 10) insanity++;
-       if ((int)h->fat_sector_count < 0) insanity++;
-       if (h->fat_sector_count > (unsigned int)max_sectors) insanity++;
-       if (h->directory_stream_start_sector > (unsigned int) max_sectors) insanity++;
-
-       return insanity;
+    int insanity = 0;
+    int max_sectors;
+    struct OLE_header *h;
+
+    h = &(ole->header);
+
+    max_sectors = (int)(ole->file_size / h->sector_size);
+
+    if (h->sector_shift > 20)
+        insanity++;
+    if (h->mini_sector_shift > 10)
+        insanity++;
+    if ((int)h->fat_sector_count < 0)
+        insanity++;
+    if (h->fat_sector_count > (unsigned int)max_sectors)
+        insanity++;
+    if (h->directory_stream_start_sector > (unsigned int)max_sectors)
+        insanity++;
+
+    return insanity;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_print_header
 Returns Type   : int
@@ -702,60 +721,42 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_print_header( struct OLE_object *ole )
+int OLE_print_header(struct OLE_object *ole)
 {
-       unsigned int i;
-       struct OLE_header *h;
-
-       h = &(ole->header);
-
-       printf( "Minor version = %d\n"
-               "DLL version = %d\n"
-               "Byte order = %d\n\n"
-
-               "Sector shift = %d\n"
-               "Sector size  = %d\n"
-               "Mini Sector shift = %d\n"
-               "Mini sector size  = %d\n\n"
-
-               "FAT sector count = %d\n"
-               "First FAT sector = %d\n\n"
-
-               "Maximum ministream size = %d\n\n"
-
-               "First MiniFAT sector = %d\n"
-               "MiniFAT sector count = %d\n\n"
-
-               "First DIF sector = %d\n"
-               "DIF sector count = %d\n"
-               "--------------------------------\n"
-               ,h->minor_version
-               ,h->dll_version
-               ,h->byte_order
-               ,h->sector_shift
-               ,h->sector_size
-               ,h->mini_sector_shift
-               ,h->mini_sector_size
-               ,h->fat_sector_count
-               ,h->directory_stream_start_sector
-               ,h->mini_cutoff_size
-               ,h->mini_fat_start
-               ,h->mini_fat_sector_count
-               ,h->dif_start_sector
-               ,h->dif_sector_count
-               );
-
-       /* Print out the FAT chain*/
-       for (i = 0; i < h->fat_sector_count; i++)
-       {
-               if (i >= OLE_HEADER_FAT_SECTOR_COUNT_LIMIT) break; /* We can't read beyond the 109th sector location*/
-               printf("FAT[%d] = %d\n", i, h->FAT[i]);
-       }
-
-       return OLE_OK;
+    unsigned int i;
+    struct OLE_header *h;
+
+    h = &(ole->header);
+
+    printf("Minor version = %d\n"
+           "DLL version = %d\n"
+           "Byte order = %d\n\n"
+           "Sector shift = %d\n"
+           "Sector size  = %d\n"
+           "Mini Sector shift = %d\n"
+           "Mini sector size  = %d\n\n"
+           "FAT sector count = %d\n"
+           "First FAT sector = %d\n\n"
+           "Maximum ministream size = %d\n\n"
+           "First MiniFAT sector = %d\n"
+           "MiniFAT sector count = %d\n\n"
+           "First DIF sector = %d\n"
+           "DIF sector count = %d\n"
+           "--------------------------------\n", h->minor_version, h->dll_version, h->byte_order, h->sector_shift, h->sector_size,
+           h->mini_sector_shift, h->mini_sector_size, h->fat_sector_count, h->directory_stream_start_sector, h->mini_cutoff_size, h->mini_fat_start,
+           h->mini_fat_sector_count, h->dif_start_sector, h->dif_sector_count);
+
+    /* Print out the FAT chain */
+    for (i = 0; i < h->fat_sector_count; i++)
+    {
+        if (i >= OLE_HEADER_FAT_SECTOR_COUNT_LIMIT)
+            break;              /* We can't read beyond the 109th sector location */
+        printf("FAT[%d] = %d\n", i, h->FAT[i]);
+    }
+
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_convert_directory
 Returns Type   : int
@@ -772,30 +773,30 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_convert_directory( struct OLE_object *ole, unsigned char *buf, struct OLE_directory_entry *dir )
+int OLE_convert_directory(struct OLE_object *ole, unsigned char *buf, struct OLE_directory_entry *dir)
 {
-       /** Converts a  raw block of 128 bytes from the file to a
+    /** Converts a  raw block of 128 bytes from the file to a
        ** struct OLE_directory_entry data structure
        **/
 
-       /** Flush the element name **/
-       memset( dir->element_name, '\0', OLE_DIRECTORY_ELEMENT_NAME_SIZE);
+    /** Flush the element name **/
+    memset(dir->element_name, '\0', OLE_DIRECTORY_ELEMENT_NAME_SIZE);
 
-       /** The first 64 bytes of the structure are the element's name
+    /** The first 64 bytes of the structure are the element's name
        ** in 16-bite UNICODE, meaning a maximum of 31 characters when
        ** we account for the trailing zero byte
        **/
 
-       /** Copy the first 64 bytes of our *buf parameter into the element name **/
-       memcpy( dir->element_name, buf, OLE_DIRECTORY_ELEMENT_NAME_SIZE );
+    /** Copy the first 64 bytes of our *buf parameter into the element name **/
+    memcpy(dir->element_name, buf, OLE_DIRECTORY_ELEMENT_NAME_SIZE);
 
-       /** how many bytes of the above 64 bytes are used for the name (NOT CHARACTERS!), **
+    /** how many bytes of the above 64 bytes are used for the name (NOT CHARACTERS!), **
        ** example, for a 8 character string with a trailing zero we use **
        ** (8+1)*2 = 18 bytes
        **/
-       dir->element_name_byte_count = get_2byte_value( buf + 0x40 );
+    dir->element_name_byte_count = get_2byte_value(buf + 0x40);
 
-       /** Element type is of the following:
+    /** Element type is of the following:
        ** 0x00 - empty
        ** 0x01 - user storage
        ** 0x02 - user stream
@@ -803,44 +804,38 @@ int OLE_convert_directory( struct OLE_object *ole, unsigned char *buf, struct OL
        ** 0x04 - property (again, we don't know)
        ** 0x05 - root storage
        **/
-       dir->element_type = (char)get_1byte_value( buf +0x42 );
+    dir->element_type = (char)get_1byte_value(buf + 0x42);
 
-       /** Element colour for the red-black tree:
+    /** Element colour for the red-black tree:
        ** 0x00 - Red
        ** 0x01 - Black
        **/
-       dir->element_colour = (char)get_1byte_value( buf +0x43 );
-
-       /** Directory ID (DID) of the left child, -1 if no sibling **/
-       dir->left_child = get_4byte_value( buf +0x44 );
+    dir->element_colour = (char)get_1byte_value(buf + 0x43);
 
-       /** Directory ID (DID) of the right child, -1 if no sibling **/
-       dir->right_child = get_4byte_value( buf +0x48 );
+    /** Directory ID (DID) of the left child, -1 if no sibling **/
+    dir->left_child = get_4byte_value(buf + 0x44);
 
+    /** Directory ID (DID) of the right child, -1 if no sibling **/
+    dir->right_child = get_4byte_value(buf + 0x48);
 
-       /** Directory ID (DID) of the root node entry of the RB tree of all
+    /** Directory ID (DID) of the root node entry of the RB tree of all
        ** storage members (if this entry is a storage), else -1.
        **/
-       dir->root = get_4byte_value( buf +0x4c );
-
-       memcpy( dir->class, buf +0x50, 16 );
-       dir->userflags = get_4byte_value( buf +0x60 );
-       memcpy( dir->timestamps, buf +0x64, 16 ); /** Actually consists of 2 8 byte stamps **/
-
-       /** Sector ID of the first sector or short-sector **/
-       dir->start_sector = get_4byte_value( buf +0x74 );
-
-       /** Size of this stream **/
-       DOLE LOGGER_log("%s:%d:OLE_directory_entry:DEBUG: stream size = 0x%x %x %x %x"
-               ,FL
-               ,*(buf +0x78)
-               ,*(buf +0x79)
-               ,*(buf +0x7A)
-               ,*(buf +0x7B)
-               );
-       dir->stream_size = get_4byte_value( buf +0x78 );
-
-       return OLE_OK;
+    dir->root = get_4byte_value(buf + 0x4c);
+
+    memcpy(dir->class, buf + 0x50, 16);
+    dir->userflags = get_4byte_value(buf + 0x60);
+    memcpy(dir->timestamps, buf + 0x64, 16);  /** Actually consists of 2 8 byte stamps **/
+
+    /** Sector ID of the first sector or short-sector **/
+    dir->start_sector = get_4byte_value(buf + 0x74);
+
+    /** Size of this stream **/
+    DOLE LOGGER_log("%s:%d:OLE_directory_entry:DEBUG: stream size = 0x%x %x %x %x", FL, *(buf + 0x78), *(buf + 0x79), *(buf + 0x7A), *(buf + 0x7B));
+
+    dir->stream_size = get_4byte_value(buf + 0x78);
+
+    return OLE_OK;
 }
 
 /*-----------------------------------------------------------------\
@@ -859,36 +854,26 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_print_directory( struct OLE_object *ole, struct OLE_directory_entry *dir )
+int OLE_print_directory(struct OLE_object *ole, struct OLE_directory_entry *dir)
 {
-       char element[64];
-       OLE_dbstosbs( dir->element_name, dir->element_name_byte_count, element, sizeof(element) );
-
-       printf(
-               "Element Name = %s\n"
-               "Element type = %d\n"
-               "Element colour = %d\n"
-               "Left Child = %d\n"
-               "Right Child = %d\n"
-               "Root = %d\n"
-               "User flags = %d\n"
-               "Start sector = %d\n"
-               "Stream Size = %d\n"
-               ,element
-               ,dir->element_type
-               ,dir->element_colour
-               ,dir->left_child
-               ,dir->right_child
-               ,dir->root
-               ,dir->userflags
-               ,dir->start_sector
-               ,dir->stream_size
-               );
-
-       return OLE_OK;
+    char element[64];
+
+    OLE_dbstosbs(dir->element_name, dir->element_name_byte_count, element, sizeof(element));
+
+    printf("Element Name = %s\n"
+           "Element type = %d\n"
+           "Element colour = %d\n"
+           "Left Child = %d\n"
+           "Right Child = %d\n"
+           "Root = %d\n"
+           "User flags = %d\n"
+           "Start sector = %d\n"
+           "Stream Size = %d\n", element, dir->element_type, dir->element_colour, dir->left_child, dir->right_child, dir->root, dir->userflags,
+           dir->start_sector, dir->stream_size);
+
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_load_FAT
 Returns Type   : int
@@ -904,188 +889,199 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_load_FAT( struct OLE_object *ole )
+int OLE_load_FAT(struct OLE_object *ole)
 {
-       unsigned int FAT_size;
-
-       FAT_size = ole->header.fat_sector_count << ole->header.sector_shift;
-       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG:Allocating for %d sectors (%d bytes)\n"
-               ,FL,ole->header.fat_sector_count, FAT_size);
-
-       ole->FAT = MALLOC( FAT_size *sizeof(unsigned char));
-       ole->FAT_limit = ole->FAT +FAT_size;
-       if (ole->FAT != NULL)
-       {
-               unsigned int i;
-               unsigned char *fat_position = ole->FAT;
-               unsigned int sector_count = ole->header.fat_sector_count;
-
-               if (sector_count > OLE_HEADER_FAT_SECTOR_COUNT_LIMIT)
-               {
-                       sector_count = OLE_HEADER_FAT_SECTOR_COUNT_LIMIT;
-                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: sector count greater than limit; set to %d",FL, sector_count);
-               }
-
-               /* Load in all our primary-FAT sectors from the OLE file*/
-               for (i = 0; i < sector_count; i++)
-               {
-                       int getblock_result = 0;
-
-                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Loading sector %d",FL, i);
-                       getblock_result = OLE_get_block(ole, ole->header.FAT[i], fat_position);
-                       if (getblock_result != 0)
-                       {
-                               /* if the get block fails, return the error - but keep the FAT*/
-                               /*              pointer alive - so that we can facilitate debugging*/
-                               /*              otherwise the caller is always going to get a NULL pointer*/
-                               /*              and have no idea to what extent the data was read.*/
-                               /**/
-                               /* This behavior may be changed later - but for now (beta development)*/
-                               /*              it'll be okay to leave it here - just make sure we know to*/
-                               /*              free the FAT block later.*/
-
-                               return getblock_result;
-                       }
-
-                       fat_position += ole->header.sector_size;
-                       if (fat_position > ole->FAT_limit)
-                       {
-                               LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: FAT boundary limit exceeded %p > %p", FL, fat_position, ole->FAT_limit);
-                               return -1;
-                       }
-               }
-
-               /* If our DIF count is > 0, this means we have a pretty big*/
-               /*              file on hand (> 7Mb) and thus we now have to do some*/
-               /*              fancy double-dereferenced sector request - enough to */
-               /*              twist your brain if you're not alert, you have been*/
-               /*              warned.*/
-
-               if (ole->header.dif_sector_count > 0)
-               {
-                       unsigned char *fat_block;
-                       unsigned char *fat_block_end;
-                       unsigned int current_sector = ole->header.dif_start_sector;
-
-                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Allocating %d bytes to fat_block\n",FL, ole->header.sector_size);
-
-                       fat_block = MALLOC( ole->header.sector_size );
-
-                       if (fat_block == NULL)
-                       {
-                               LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: Unable to allocate %d bytes\n"), FL, ole->header.sector_size);
-                               return -1;
-                               /*                      exit(1);*/
-                       }
-
-                       /* We need to know where the end of this block is - because it's*/
-                       /*              used to show us where the NEXT FAT block is going to come from*/
-                       /*              NOTE - this only occurs if we do have another block, else */
-                       /*              we'll simply have to just realise that we don't need any more*/
-                       /*              blocks and stop with this one.*/
-
-                       fat_block_end = fat_block +ole->header.sector_size -LEN_ULONG;
-
-                       /* We know we've got 'dif_sector_count' blocks to read, each of*/
-                       /*              these blocks hold no more than 127 sector addresses which*/
-                       /*              contain the actual FAT data we're after (this is the double*/
-                       /*              dereference bit that twists your brain )*/
-
-                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Loading DIF sectors (count = %d)",FL,ole->header.dif_sector_count);
-
-                       for (i = 0; i < ole->header.dif_sector_count; i++)
-                       {
-                               int import_sector;
-                               unsigned char *DIF = fat_block;
-                               int tick = 0;
-                               int getblock_result;
-
-                               DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Reading DIF/XBAT index-data[%d] from sector 0x%x",FL,i,current_sector);
-                               getblock_result = OLE_get_block(ole, current_sector, fat_block);
-                               if (getblock_result != OLE_OK)
-                               {
-                                       if (fat_block) FREE(fat_block);
-                                       return getblock_result;
-                               }
-
-                               if (OLE_DPEDANTIC(ole->debug)) OLE_print_sector(ole, fat_block, ole->header.sector_size);
-
-                               /* Now, traverse this block until we hit a < 0*/
-                               /*              If we get what is a non-valid sector value*/
-                               /*              we know we've reached the end of the valid*/
-                               /*              sectors from which to read more extended FAT*/
-                               /*              data.*/
-
-                               do {
-                                       import_sector = get_4byte_value( DIF );
-                                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: import sector = 0x%x",FL,import_sector);
-                                       if (import_sector >= 0)
-                                       {
-                                               if (fat_position +ole->header.sector_size <= ole->FAT_limit)
-                                               {
-                                                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Reading DIF/XBAT-data[%d] from sector 0x%x",FL,tick,import_sector);
-                                                       getblock_result = OLE_get_block(ole, import_sector, fat_position);
-                                                       if (getblock_result != OLE_OK)
-                                                       {
-                                                               LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: Not able to load block, import sector = 0x%x, fat position = 0x%x"),FL, import_sector, fat_position);
-                                                               if (fat_block) FREE(fat_block);
-                                                               return getblock_result;
-                                                       }
-
-                                                       fat_position += ole->header.sector_size;
-                                                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: FAT position = 0x%x (start = 0x%x, end = 0x%x)"
-                                                               ,FL
-                                                               ,fat_position
-                                                               ,fat_block
-                                                               ,ole->FAT_limit
-                                                               );
-
-                                                       /*if (fat_position +ole->header.sector_size > ole->FAT_limit)*/
-                                                       if (fat_position > ole->FAT_limit)
-                                                       {
-                                                               DOLE LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: FAT memory boundary limit exceeded %p >= %p"),FL,fat_position,ole->FAT_limit);
-                                                               if (fat_block) FREE(fat_block);
-                                                               return OLEER_MEMORY_OVERFLOW;
-                                                       }
-                                                       tick++;
-                                                       DIF += LEN_ULONG;
-                                               }  else {
-                                                       LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: FAT memory boundary limit exceeded %p >= %p"),FL,fat_position,ole->FAT_limit);
-                                                       if (fat_block) FREE(fat_block);
-                                                       return OLEER_MEMORY_OVERFLOW;
-                                               }
-                                       } else {
-                                               VOLE LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: sector request was negative (%d)"),FL, import_sector);
-                                       }
-
-                                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: DIF = 0x%x",FL,DIF);
-                               } while ((import_sector >= 0)&&(DIF < fat_block_end));
-
-                               /* Get the next sector of DIF/XBAT data ...*/
-                               /**/
-                               /* If we still have more sectors full of extended FAT*/
-                               /*              sectors that we have to read, then we neet to*/
-                               /*              obtain the address of the next FAT-sector filled*/
-                               /*              sector*/
-
-                               if ( i < ole->header.dif_sector_count -1 )
-                               {
-                                       current_sector = get_4byte_value( fat_block_end );
-                                       DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Next DIF/XBAT index sector located at 0x%x",FL,current_sector);
-                                       if ((int)current_sector < 0) break;
-                               }
-                       } /* For every DIF/XBAT sector we're supposed to read*/
-
-                       if (fat_block) FREE(fat_block);
-               } /* If we have DIF/XBAT sectors to read into the FAT*/
-
-       } /* If we managed to allocate memory for our FAT table*/
-
-       return OLE_OK;
+    unsigned int FAT_size;
+
+    FAT_size = ole->header.fat_sector_count << ole->header.sector_shift;
+    DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG:Allocating for %d sectors (%d bytes)\n", FL, ole->header.fat_sector_count, FAT_size);
+
+    ole->FAT = MALLOC(FAT_size * sizeof(unsigned char));
+    ole->FAT_limit = ole->FAT + FAT_size;
+    if (ole->FAT != NULL)
+    {
+        unsigned int i;
+        unsigned char *fat_position = ole->FAT;
+        unsigned int sector_count = ole->header.fat_sector_count;
+
+        if (sector_count > OLE_HEADER_FAT_SECTOR_COUNT_LIMIT)
+        {
+            sector_count = OLE_HEADER_FAT_SECTOR_COUNT_LIMIT;
+            DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: sector count greater than limit; set to %d", FL, sector_count);
+        }
+
+        /* Load in all our primary-FAT sectors from the OLE file */
+        for (i = 0; i < sector_count; i++)
+        {
+            int getblock_result = 0;
+
+            DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Loading sector %d", FL, i);
+
+            getblock_result = OLE_get_block(ole, ole->header.FAT[i], fat_position);
+            if (getblock_result != 0)
+            {
+                /* if the get block fails, return the error - but keep the FAT */
+                /*      pointer alive - so that we can facilitate debugging */
+                /*      otherwise the caller is always going to get a NULL pointer */
+                /*      and have no idea to what extent the data was read. */
+                 /**/
+                    /* This behavior may be changed later - but for now (beta development) */
+                    /*      it'll be okay to leave it here - just make sure we know to */
+                    /*      free the FAT block later. */
+                    return getblock_result;
+            }
+
+            fat_position += ole->header.sector_size;
+            if (fat_position > ole->FAT_limit)
+            {
+                LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: FAT boundary limit exceeded %p > %p", FL, fat_position, ole->FAT_limit);
+                return -1;
+            }
+        }
+
+        /* If our DIF count is > 0, this means we have a pretty big */
+        /*      file on hand (> 7Mb) and thus we now have to do some */
+        /*      fancy double-dereferenced sector request - enough to */
+        /*      twist your brain if you're not alert, you have been */
+        /*      warned. */
+
+        if (ole->header.dif_sector_count > 0)
+        {
+            unsigned char *fat_block;
+            unsigned char *fat_block_end;
+            unsigned int current_sector = ole->header.dif_start_sector;
+
+            DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Allocating %d bytes to fat_block\n", FL, ole->header.sector_size);
+
+            fat_block = MALLOC(ole->header.sector_size);
+
+            if (fat_block == NULL)
+            {
+                LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: Unable to allocate %d bytes\n"), FL, ole->header.sector_size);
+                return -1;
+                /*          exit(1); */
+            }
+
+            /* We need to know where the end of this block is - because it's */
+            /*      used to show us where the NEXT FAT block is going to come from */
+            /*      NOTE - this only occurs if we do have another block, else */
+            /*      we'll simply have to just realise that we don't need any more */
+            /*      blocks and stop with this one. */
+
+            fat_block_end = fat_block + ole->header.sector_size - LEN_ULONG;
+
+            /* We know we've got 'dif_sector_count' blocks to read, each of */
+            /*      these blocks hold no more than 127 sector addresses which */
+            /*      contain the actual FAT data we're after (this is the double */
+            /*      dereference bit that twists your brain ) */
+
+            DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Loading DIF sectors (count = %d)", FL, ole->header.dif_sector_count);
+
+            for (i = 0; i < ole->header.dif_sector_count; i++)
+            {
+                int import_sector;
+                unsigned char *DIF = fat_block;
+                int tick = 0;
+                int getblock_result;
+
+                DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Reading DIF/XBAT index-data[%d] from sector 0x%x", FL, i, current_sector);
+
+                getblock_result = OLE_get_block(ole, current_sector, fat_block);
+                if (getblock_result != OLE_OK)
+                {
+                    if (fat_block)
+                        FREE(fat_block);
+                    return getblock_result;
+                }
+
+                if (OLE_DPEDANTIC(ole->debug))
+                    OLE_print_sector(ole, fat_block, ole->header.sector_size);
+
+                /* Now, traverse this block until we hit a < 0 */
+                /*      If we get what is a non-valid sector value */
+                /*      we know we've reached the end of the valid */
+                /*      sectors from which to read more extended FAT */
+                /*      data. */
+
+                do
+                {
+                    import_sector = get_4byte_value(DIF);
+                    DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: import sector = 0x%x", FL, import_sector);
+
+                    if (import_sector >= 0)
+                    {
+                        if (fat_position + ole->header.sector_size <= ole->FAT_limit)
+                        {
+                            DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Reading DIF/XBAT-data[%d] from sector 0x%x", FL, tick, import_sector);
+
+                            getblock_result = OLE_get_block(ole, import_sector, fat_position);
+                            if (getblock_result != OLE_OK)
+                            {
+                                LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: Not able to load block, import sector = 0x%x, fat position = 0x%x"), FL,
+                                           import_sector, fat_position);
+                                if (fat_block)
+                                    FREE(fat_block);
+                                return getblock_result;
+                            }
+
+                            fat_position += ole->header.sector_size;
+                            DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: FAT position = 0x%x (start = 0x%x, end = 0x%x)", FL, fat_position, fat_block,
+                                            ole->FAT_limit);
+
+                            /*if (fat_position +ole->header.sector_size > ole->FAT_limit) */
+                            if (fat_position > ole->FAT_limit)
+                            {
+                                DOLE LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: FAT memory boundary limit exceeded %p >= %p"), FL, fat_position,
+                                                ole->FAT_limit);
+                                if (fat_block)
+                                    FREE(fat_block);
+                                return OLEER_MEMORY_OVERFLOW;
+                            }
+                            tick++;
+                            DIF += LEN_ULONG;
+                        }
+                        else
+                        {
+                            LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: FAT memory boundary limit exceeded %p >= %p"), FL, fat_position, ole->FAT_limit);
+                            if (fat_block)
+                                FREE(fat_block);
+                            return OLEER_MEMORY_OVERFLOW;
+                        }
+                    }
+                    else
+                    {
+                        VOLE LOGGER_log(_("%s:%d:OLE_load_FAT:ERROR: sector request was negative (%d)"), FL, import_sector);
+                    }
+
+                    DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: DIF = 0x%x", FL, DIF);
+                }
+                while ((import_sector >= 0) && (DIF < fat_block_end));
+
+                /* Get the next sector of DIF/XBAT data ... */
+                 /**/
+                    /* If we still have more sectors full of extended FAT */
+                    /*      sectors that we have to read, then we neet to */
+                    /*      obtain the address of the next FAT-sector filled */
+                    /*      sector */
+                    if (i < ole->header.dif_sector_count - 1)
+                {
+                    current_sector = get_4byte_value(fat_block_end);
+                    DOLE LOGGER_log("%s:%d:OLE_load_FAT:DEBUG: Next DIF/XBAT index sector located at 0x%x", FL, current_sector);
+
+                    if ((int)current_sector < 0)
+                        break;
+                }
+            }                   /* For every DIF/XBAT sector we're supposed to read */
+
+            if (fat_block)
+                FREE(fat_block);
+        }                       /* If we have DIF/XBAT sectors to read into the FAT */
+
+    }                           /* If we managed to allocate memory for our FAT table */
+
+    return OLE_OK;
 }
 
-
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_follow_chain
 Returns Type   : int
@@ -1102,70 +1098,79 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_follow_chain( struct OLE_object *ole, int FAT_sector_start )
+int OLE_follow_chain(struct OLE_object *ole, int FAT_sector_start)
 {
-       int current_sector = FAT_sector_start;
-       int chain_length=0;
-       int last_sector_of_file = ole->last_sector;
-       int break_out = 0;
-       struct bti_node *n;
+    int current_sector = FAT_sector_start;
+    int chain_length = 0;
+    int last_sector_of_file = ole->last_sector;
+    int break_out = 0;
+    struct bti_node *n;
 
-       BTI_init(&n);
+    BTI_init(&n);
 
-       if (FAT_sector_start < 0) return 0;
+    if (FAT_sector_start < 0)
+        return 0;
 
-       DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: Starting chain follow at sector %d",FL, FAT_sector_start );
+    DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: Starting chain follow at sector %d", FL, FAT_sector_start);
 
-       do {
-               int next_sector;
-               unsigned char *next_sector_location;
+    do
+    {
+        int next_sector;
+        unsigned char *next_sector_location;
 
-               next_sector_location = ole->FAT +(LEN_ULONG *current_sector);
-               if (next_sector_location > (ole->FAT_limit -4)) {
-                       DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: ERROR: Next sector was outside of the limits of this file (%ld > %ld)",FL, next_sector_location, ole->FAT_limit);
-                       break;
-               }
+        next_sector_location = ole->FAT + (LEN_ULONG * current_sector);
+        if (next_sector_location > (ole->FAT_limit - 4))
+        {
+            DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: ERROR: Next sector was outside of the limits of this file (%ld > %ld)", FL,
+                            next_sector_location, ole->FAT_limit);
+            break;
+        }
 
-               /*next_sector = get_4byte_value( ole->FAT +(LEN_ULONG *current_sector));*/
-               next_sector = get_4byte_value( next_sector_location );
+        /*next_sector = get_4byte_value( ole->FAT +(LEN_ULONG *current_sector)); */
+        next_sector = get_4byte_value(next_sector_location);
 
-               if (BTI_add(&n, next_sector) != 0)
-               {
-                       DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: Sector collision, terminating chain traversal",FL);
-                       chain_length=-1;
+        if (BTI_add(&n, next_sector) != 0)
+        {
+            DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: Sector collision, terminating chain traversal", FL);
 
-                       break;
-               }
+            chain_length = -1;
 
-               DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: 0x%0X:%d)->(0x%0X:%d)\n",FL, current_sector, current_sector, next_sector, next_sector);
+            break;
+        }
 
-               /* 20040729-10H37 Added this to prevent endless loop which sometimes occurs at sector 0*/
+        DOLE LOGGER_log("%s:%d:OLE_follow_chain:DEBUG: 0x%0X:%d)->(0x%0X:%d)\n", FL, current_sector, current_sector, next_sector, next_sector);
 
-               if (next_sector == current_sector) break;
+        /* 20040729-10H37 Added this to prevent endless loop which sometimes occurs at sector 0 */
 
-               /*              fflush(stdout);*/
-               current_sector = next_sector;
-               chain_length++;
+        if (next_sector == current_sector)
+            break;
 
-               /** Test to see if we should terminate this chain traversal **/
-               switch (current_sector) {
-               case OLE_SECTORID_MSAT:
-               case OLE_SECTORID_SAT:
-               case OLE_SECTORID_ENDOFCHAIN:
-               case OLE_SECTORID_FREE:
-                       break_out=1;
-                       break;
-               default:
-                       break_out=0;
-               };
+        /*      fflush(stdout); */
+        current_sector = next_sector;
+        chain_length++;
 
-               if (current_sector < 0) break_out = 1;
+        /** Test to see if we should terminate this chain traversal **/
+        switch (current_sector)
+        {
+        case OLE_SECTORID_MSAT:
+        case OLE_SECTORID_SAT:
+        case OLE_SECTORID_ENDOFCHAIN:
+        case OLE_SECTORID_FREE:
+            break_out = 1;
+            break;
+        default:
+            break_out = 0;
+        };
 
-       } while ((break_out==0)&&(current_sector < last_sector_of_file));
+        if (current_sector < 0)
+            break_out = 1;
 
-       BTI_done(&n);
+    }
+    while ((break_out == 0) && (current_sector < last_sector_of_file));
 
-       return chain_length;
+    BTI_done(&n);
+
+    return chain_length;
 }
 
 /*-----------------------------------------------------------------\
@@ -1184,60 +1189,68 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_follow_minichain( struct OLE_object *ole, int miniFAT_sector_start )
+int OLE_follow_minichain(struct OLE_object *ole, int miniFAT_sector_start)
 {
-       /*unsigned int current_sector = miniFAT_sector_start;*/
-       int current_sector = miniFAT_sector_start;
-       int chain_length=0;
-       int break_out = 0;
-
-       DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Starting at sector %d",FL, miniFAT_sector_start);
-
-       if (miniFAT_sector_start < 0) return 0;
-
-       do {
-               /*unsigned int next_sector;*/
-               int next_sector;
-
-               DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Requesting 4-byte value at '%d'",FL, ole->miniFAT +(LEN_ULONG *current_sector));
-               /* next text commented out because ole->miniFAT_limit is set to null ans vever change
-               if (ole->miniFAT +(LEN_ULONG *current_sector) > ole->miniFAT_limit) {
-               DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Requested location is out of bounds\n",FL);
-               return 0;
-               }
-               */
-
-               next_sector = get_4byte_value( ole->miniFAT +(LEN_ULONG *current_sector));
-
-               DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Current Msector(0x%0X:%d)->next(0x%0X:%d)\n", FL, current_sector, current_sector, next_sector, next_sector);
-
-               /** Check for conditions that indicate we should stop traversing this chain **/
-
-               /** 1. We cannot point to ourselves **/
-               if (current_sector == next_sector) break;
-
-               chain_length++;
-               current_sector = next_sector;
-
-               /** Test for non-positive type sector ID's **/
-               switch (current_sector) {
-               case OLE_SECTORID_MSAT:
-               case OLE_SECTORID_SAT:
-               case OLE_SECTORID_ENDOFCHAIN:
-               case OLE_SECTORID_FREE:
-                       break_out=1;
-                       break;
-               default:
-                       break_out=0;
-               };
-
-               DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: current sector = %d",FL,current_sector);
-               /* Test changed  Serge Steer Scilab */
-               /*      } while ((break_out==0) &&(current_sector <= ole->last_sector));*/
-       } while ((break_out==0));
-       DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Done.  Chainlength=%d",FL, chain_length);
-
-       return chain_length;
+    /*unsigned int current_sector = miniFAT_sector_start; */
+    int current_sector = miniFAT_sector_start;
+    int chain_length = 0;
+    int break_out = 0;
+
+    DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Starting at sector %d", FL, miniFAT_sector_start);
+
+    if (miniFAT_sector_start < 0)
+        return 0;
+
+    do
+    {
+        /*unsigned int next_sector; */
+        int next_sector;
+
+        DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Requesting 4-byte value at '%d'", FL, ole->miniFAT + (LEN_ULONG * current_sector));
+
+        /* next text commented out because ole->miniFAT_limit is set to null ans vever change
+         * if (ole->miniFAT +(LEN_ULONG *current_sector) > ole->miniFAT_limit) {
+         * DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Requested location is out of bounds\n",FL);
+         * return 0;
+         * }
+         */
+
+        next_sector = get_4byte_value(ole->miniFAT + (LEN_ULONG * current_sector));
+
+        DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Current Msector(0x%0X:%d)->next(0x%0X:%d)\n", FL, current_sector, current_sector,
+                        next_sector, next_sector);
+
+        /** Check for conditions that indicate we should stop traversing this chain **/
+
+        /** 1. We cannot point to ourselves **/
+        if (current_sector == next_sector)
+            break;
+
+        chain_length++;
+        current_sector = next_sector;
+
+        /** Test for non-positive type sector ID's **/
+        switch (current_sector)
+        {
+        case OLE_SECTORID_MSAT:
+        case OLE_SECTORID_SAT:
+        case OLE_SECTORID_ENDOFCHAIN:
+        case OLE_SECTORID_FREE:
+            break_out = 1;
+            break;
+        default:
+            break_out = 0;
+        };
+
+        DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: current sector = %d", FL, current_sector);
+
+        /* Test changed  Serge Steer Scilab */
+        /*  } while ((break_out==0) &&(current_sector <= ole->last_sector)); */
+    }
+    while (break_out == 0);
+    DOLE LOGGER_log("%s:%d:OLE_follow_minichain:DEBUG: Done.  Chainlength=%d", FL, chain_length);
+
+    return chain_length;
 }
 
 /*-----------------------------------------------------------------\
@@ -1259,65 +1272,73 @@ value so that we didn't try to load up a miniFAT starting on a
 negative value
 
 \------------------------------------------------------------------*/
-unsigned char *OLE_load_minichain( struct OLE_object *ole, int miniFAT_sector_start )
+unsigned char *OLE_load_minichain(struct OLE_object *ole, int miniFAT_sector_start)
 {
 
-       int chain_length = 0;
-       int current_sector = miniFAT_sector_start;
-       unsigned char *buffer;
-       unsigned char *bp;
-       int break_out = 0;
-
-       DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Loading minichain starting at %d",FL, miniFAT_sector_start);
-
-       /* Added this sanity checking 2003 Aug 28*/
-       if (miniFAT_sector_start < 0) return NULL;
-
-       chain_length = OLE_follow_minichain( ole, miniFAT_sector_start );
-       DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Found %d mini-sectors to load (%d bytes)\n",FL, chain_length, chain_length *ole->header.mini_sector_size);
-
-       /* 20040911-21H59*/
-       /* If our chain is 0 length, then there's nothing to return*/
-       if (chain_length == 0) return NULL;
-
-       bp = buffer = MALLOC( chain_length *ole->header.mini_sector_size *sizeof(unsigned char));
-       if (buffer != NULL)
-       {
-               do {
-                       int next_sector;
-
-                       DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Loading sector %d",FL, current_sector);
-                       OLE_get_miniblock( ole, current_sector, bp );
-                       bp += ole->header.mini_sector_size;
-
-                       next_sector = get_4byte_value( ole->miniFAT +(LEN_ULONG *current_sector));
-                       current_sector = next_sector;
-                       /* NEXT LINES ADDED TO BE COHERENT WITH  OLE_follow_minichain ABOVE Serge Steer Scilab */
-                       switch (current_sector) {
-       case OLE_SECTORID_MSAT:
-       case OLE_SECTORID_SAT:
-       case OLE_SECTORID_ENDOFCHAIN:
-       case OLE_SECTORID_FREE:
-               break_out=1;
-               break;
-       default:
-               break_out=0;
-                       };
-                       /* Test changed  Serge Steer Scilab */
-                       /* } while ((current_sector != OLE_SECTORID_ENDOFCHAIN)&&(current_sector >= 0)&&(current_sector <= ole->last_sector));*/
-
-               } while ((break_out==0));
-
-       } else {
-               LOGGER_log(_("%s:%d:OLE_get_miniblock:ERROR: Failed to allocate enough memory for miniChain"),FL);
-       }
-
-       DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Done. buffer=%p",FL, buffer);
-
-       return buffer;
+    int chain_length = 0;
+    int current_sector = miniFAT_sector_start;
+    unsigned char *buffer;
+    unsigned char *bp;
+    int break_out = 0;
+
+    DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Loading minichain starting at %d", FL, miniFAT_sector_start);
+
+    /* Added this sanity checking 2003 Aug 28 */
+    if (miniFAT_sector_start < 0)
+        return NULL;
+
+    chain_length = OLE_follow_minichain(ole, miniFAT_sector_start);
+    DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Found %d mini-sectors to load (%d bytes)\n", FL, chain_length,
+                    chain_length * ole->header.mini_sector_size);
+
+    /* 20040911-21H59 */
+    /* If our chain is 0 length, then there's nothing to return */
+    if (chain_length == 0)
+        return NULL;
+
+    bp = buffer = MALLOC(chain_length * ole->header.mini_sector_size * sizeof(unsigned char));
+    if (buffer != NULL)
+    {
+        do
+        {
+            int next_sector;
+
+            DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Loading sector %d", FL, current_sector);
+
+            OLE_get_miniblock(ole, current_sector, bp);
+            bp += ole->header.mini_sector_size;
+
+            next_sector = get_4byte_value(ole->miniFAT + (LEN_ULONG * current_sector));
+            current_sector = next_sector;
+            /* NEXT LINES ADDED TO BE COHERENT WITH  OLE_follow_minichain ABOVE Serge Steer Scilab */
+            switch (current_sector)
+            {
+            case OLE_SECTORID_MSAT:
+            case OLE_SECTORID_SAT:
+            case OLE_SECTORID_ENDOFCHAIN:
+            case OLE_SECTORID_FREE:
+                break_out = 1;
+                break;
+            default:
+                break_out = 0;
+            };
+            /* Test changed  Serge Steer Scilab */
+            /* } while ((current_sector != OLE_SECTORID_ENDOFCHAIN)&&(current_sector >= 0)&&(current_sector <= ole->last_sector)); */
+
+        }
+        while (break_out == 0);
+
+    }
+    else
+    {
+        LOGGER_log(_("%s:%d:OLE_get_miniblock:ERROR: Failed to allocate enough memory for miniChain"), FL);
+    }
+
+    DOLE LOGGER_log("%s:%d:OLE_load_minichain:DEBUG: Done. buffer=%p", FL, buffer);
+
+    return buffer;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : char
 Returns Type   : unsigned
@@ -1336,70 +1357,79 @@ Make the loading aware of negative-value sectors so that it can
 make more intelligent exit strategies.
 
 \------------------------------------------------------------------*/
-unsigned char *OLE_load_chain( struct OLE_object *ole, int FAT_sector_start )
+unsigned char *OLE_load_chain(struct OLE_object *ole, int FAT_sector_start)
 {
 
-       int chain_length = 0;
-       int current_sector = FAT_sector_start;
-       unsigned char *buffer = NULL;
-       unsigned char *bp = NULL;
-
-
-       ole->last_chain_size = 0;
-
-       if (FAT_sector_start < 0) return NULL;
-
-       DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: Loading chain, starting at sector %d",FL,FAT_sector_start);
-
-       chain_length = OLE_follow_chain( ole, FAT_sector_start );
-       DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: %d sectors need to be loaded",FL,chain_length);
-
-       if (chain_length > 0)
-       {
-               size_t offset;
-
-               offset = ole->last_chain_size = chain_length << ole->header.sector_shift;
-               bp = buffer = MALLOC( (offset) *sizeof(unsigned char));
-               if (buffer == NULL)
-               {
-                       LOGGER_log("%s:%d:OLE_load_chain:ERROR: Cannot allocate %d bytes for OLE chain",FL,offset);
-                       return NULL;
-               }
-
-               if (buffer != NULL)
-               {
-                       int tick = 0;
-                       unsigned char *bp_limit;
-                       bp_limit = bp +offset;
-
-                       do {
-                               int next_sector;
-
-                               DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: Loading sector[%d] %d",FL, tick, current_sector );
-
-                               ole->error = OLE_get_block( ole, current_sector, bp );
-                               if (ole->error != OLE_OK)
-                               {
-                                       /*FREE5                                 if (bp != NULL) FREE(bp);*/
-                                       return NULL;
-                               }
-
-                               bp += ole->header.sector_size;
-                               if (bp > bp_limit) {
-                                       if (buffer != NULL) { FREE(buffer); bp = buffer = NULL; }
-                                       VOLE LOGGER_log(_("%s:%d:OLE_load_chain:ERROR: Load-chain went over memory boundary"),FL);
-                                       return NULL;
-                               };
-
-                               next_sector = get_4byte_value( ole->FAT +(LEN_ULONG *current_sector));
-                               current_sector = next_sector;
-                               tick++;
-                       } while ((current_sector >= 0)&&(current_sector <= ole->last_sector));
-               }
-       }
-       DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: Done loading chain",FL);
-
-       return buffer;
+    int chain_length = 0;
+    int current_sector = FAT_sector_start;
+    unsigned char *buffer = NULL;
+    unsigned char *bp = NULL;
+
+    ole->last_chain_size = 0;
+
+    if (FAT_sector_start < 0)
+        return NULL;
+
+    DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: Loading chain, starting at sector %d", FL, FAT_sector_start);
+
+    chain_length = OLE_follow_chain(ole, FAT_sector_start);
+    DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: %d sectors need to be loaded", FL, chain_length);
+
+    if (chain_length > 0)
+    {
+        size_t offset;
+
+        offset = ole->last_chain_size = chain_length << ole->header.sector_shift;
+        bp = buffer = MALLOC((offset) * sizeof(unsigned char));
+        if (buffer == NULL)
+        {
+            LOGGER_log("%s:%d:OLE_load_chain:ERROR: Cannot allocate %d bytes for OLE chain", FL, offset);
+            return NULL;
+        }
+
+        if (buffer != NULL)
+        {
+            int tick = 0;
+            unsigned char *bp_limit;
+
+            bp_limit = bp + offset;
+
+            do
+            {
+                int next_sector;
+
+                DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: Loading sector[%d] %d", FL, tick, current_sector);
+
+                ole->error = OLE_get_block(ole, current_sector, bp);
+                if (ole->error != OLE_OK)
+                {
+                    /*FREE5                 if (bp != NULL) FREE(bp); */
+                    return NULL;
+                }
+
+                bp += ole->header.sector_size;
+                if (bp > bp_limit)
+                {
+                    if (buffer != NULL)
+                    {
+                        FREE(buffer);
+                        bp = buffer = NULL;
+                    }
+                    VOLE LOGGER_log(_("%s:%d:OLE_load_chain:ERROR: Load-chain went over memory boundary"), FL);
+
+                    return NULL;
+                };
+
+                next_sector = get_4byte_value(ole->FAT + (LEN_ULONG * current_sector));
+                current_sector = next_sector;
+                tick++;
+            }
+            while ((current_sector >= 0) && (current_sector <= ole->last_sector));
+        }
+    }
+    DOLE LOGGER_log("%s:%d:OLE_load_chain:DEBUG: Done loading chain", FL);
+
+    return buffer;
 }
 
 /*-----------------------------------------------------------------\
@@ -1422,50 +1452,55 @@ requested sectors are outside of the possible valid
 filesize range.
 
 \------------------------------------------------------------------*/
-int OLE_open_file( struct OLE_object *ole, char *fullpath )
+int OLE_open_file(struct OLE_object *ole, char *fullpath)
 {
 #ifdef _MSC_VER
-       struct _stat st;
+    struct _stat st;
 #else
-       struct stat st;
+    struct stat st;
 #endif
-       int stat_result;
-       FILE *f;
+    int stat_result;
+    FILE *f;
 
 #ifdef _MSC_VER
-       stat_result = wcstat(fullpath, &st);
+    stat_result = wcstat(fullpath, &st);
 #else
-       stat_result = stat(fullpath, &st);
+    stat_result = stat(fullpath, &st);
 #endif
-       if (stat_result != 0) {
-               DOLE LOGGER_log(_("%s:%d:OLE_open_file:ERROR: Cannot locate file '%s' for opening (%s)"),FL, fullpath, strerror(errno));
-               return OLEER_BAD_INPUT_FILE;
-       }
-
-       DOLE LOGGER_log("%s:%d:OLE_open_file:DEBUG: File size of %s = %ld",FL, fullpath, st.st_size);
-       if ((stat_result == 0) && (st.st_size < 512)) return OLEER_NOT_OLE_FILE;
-
-       ole->file_size = st.st_size;
-
-       wcfopen(f, fullpath, "rb");
-
-       if (f == NULL)
-       {
-               ole->f = NULL;
-               if (ole->quiet == 0)
-               {
-                       LOGGER_log(_("%s:%d:OLE_open_file:ERROR:Cannot open %s for reading (%s)\n"),FL,fullpath, strerror(errno));
-               }
-               return -1;
-       } else {
-               ole->f = f;
-               ole->file_size = st.st_size;
-               ole->last_sector = -1;
-       }
-       return OLE_OK;
+    if (stat_result != 0)
+    {
+        DOLE LOGGER_log(_("%s:%d:OLE_open_file:ERROR: Cannot locate file '%s' for opening (%s)"), FL, fullpath, strerror(errno));
+
+        return OLEER_BAD_INPUT_FILE;
+    }
+
+    DOLE LOGGER_log("%s:%d:OLE_open_file:DEBUG: File size of %s = %ld", FL, fullpath, st.st_size);
+
+    if ((stat_result == 0) && (st.st_size < 512))
+        return OLEER_NOT_OLE_FILE;
+
+    ole->file_size = st.st_size;
+
+    wcfopen(f, fullpath, "rb");
+
+    if (f == NULL)
+    {
+        ole->f = NULL;
+        if (ole->quiet == 0)
+        {
+            LOGGER_log(_("%s:%d:OLE_open_file:ERROR:Cannot open %s for reading (%s)\n"), FL, fullpath, strerror(errno));
+        }
+        return -1;
+    }
+    else
+    {
+        ole->f = f;
+        ole->file_size = st.st_size;
+        ole->last_sector = -1;
+    }
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_open_directory
 Returns Type   : int
@@ -1482,31 +1517,34 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_open_directory( struct OLE_object *ole, char *directory )
+int OLE_open_directory(struct OLE_object *ole, char *directory)
 {
-       int result=0;
+    int result = 0;
 
 #ifndef _MSC_VER
-       result = mkdir( directory, S_IRWXU );
+    result = mkdir(directory, S_IRWXU);
 #else
-       {
-               wchar_t *wdirectory = to_wide_string(directory);
-               result = CreateDirectoryW( wdirectory,NULL);
-               FREE(wdirectory);
-       }
-       /* If the function succeeds, the return value is nonzero.
-       If the function fails, the return value is zero. */
-       if (result) result=0;
+    {
+        wchar_t *wdirectory = to_wide_string(directory);
+
+        result = CreateDirectoryW(wdirectory, NULL);
+        FREE(wdirectory);
+    }
+    /* If the function succeeds, the return value is nonzero.
+     * If the function fails, the return value is zero. */
+    if (result)
+        result = 0;
 #endif
-       if ((result != 0)&&(errno != EEXIST))
-       {
-               LOGGER_log(_("%s:%d:OLE_open_directory:ERROR: %s"),FL,strerror(errno));
-       } else result = OLE_OK;
-
-       return result;
+    if ((result != 0) && (errno != EEXIST))
+    {
+        LOGGER_log(_("%s:%d:OLE_open_directory:ERROR: %s"), FL, strerror(errno));
+    }
+    else
+        result = OLE_OK;
+
+    return result;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_set_filename_report_fn
 Returns Type   : int
@@ -1525,13 +1563,12 @@ having to #include the OLEUW headers as well
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_set_filename_report_fn( struct OLE_object *ole, int (*ptr_to_fn)(char *) )
+int OLE_set_filename_report_fn(struct OLE_object *ole, int (*ptr_to_fn) (char *))
 {
-       ole->filename_report_fn = ptr_to_fn;
-       return OLE_OK;
+    ole->filename_report_fn = ptr_to_fn;
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
 Function Name  : OLE_store_stream
 Returns Type   : int
@@ -1550,57 +1587,57 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int OLE_store_stream( struct OLE_object *ole, char *stream_name, char *directory, char *stream, size_t stream_size )
+int OLE_store_stream(struct OLE_object *ole, char *stream_name, char *directory, char *stream, size_t stream_size)
 {
-       char *full_path = NULL;
-
-       full_path = PLD_dprintf("%s/%s", directory, stream_name);
-       if (full_path == NULL)
-       {
-               LOGGER_log(_("%s:%d:OLE_store_stream:ERROR: Cannot compose full filename string from '%s' and '%s'"), FL, directory, stream_name);
-               return -1;
-       } 
-       else
-       {
-               FILE *f;
-               wcfopen(f, full_path, "wb");
-               
-               if (f == NULL)
-               {
-                       LOGGER_log(_("%s:%d:OLE_store_stream:ERROR: Cannot open %s for writing (%s)"),FL, full_path, strerror(errno));
-                       if (full_path)
-                       {
-                               FREE(full_path);
-                       }
-                       return -1;
-               } 
-               else 
-               {
-                       size_t written_bytes;
-
-                       written_bytes = fwrite( stream, 1, stream_size, f );
-                       if (written_bytes != stream_size)
-                       {
-                               LOGGER_log(_("%s:%d:OLE_store_stream:WARNING: Only wrote %d of %d bytes to file %s"),FL,written_bytes,stream_size,full_path);
-                       }
-                       fclose(f);
-
-                       if ((OLE_VNORMAL(ole->verbose))&&(ole->filename_report_fn != NULL))
-                       {
-                               ole->filename_report_fn( stream_name );
-                       }
-               } /* if file is valid*/
-       } /* if full_path is valid*/
-
-       if (full_path)
-       {
-               FREE(full_path);
-       }
-
-       return OLE_OK;
+    char *full_path = NULL;
+
+    full_path = PLD_dprintf("%s/%s", directory, stream_name);
+    if (full_path == NULL)
+    {
+        LOGGER_log(_("%s:%d:OLE_store_stream:ERROR: Cannot compose full filename string from '%s' and '%s'"), FL, directory, stream_name);
+        return -1;
+    }
+    else
+    {
+        FILE *f;
+
+        wcfopen(f, full_path, "wb");
+
+        if (f == NULL)
+        {
+            LOGGER_log(_("%s:%d:OLE_store_stream:ERROR: Cannot open %s for writing (%s)"), FL, full_path, strerror(errno));
+            if (full_path)
+            {
+                FREE(full_path);
+            }
+            return -1;
+        }
+        else
+        {
+            size_t written_bytes;
+
+            written_bytes = fwrite(stream, 1, stream_size, f);
+            if (written_bytes != stream_size)
+            {
+                LOGGER_log(_("%s:%d:OLE_store_stream:WARNING: Only wrote %d of %d bytes to file %s"), FL, written_bytes, stream_size, full_path);
+            }
+            fclose(f);
+
+            if ((OLE_VNORMAL(ole->verbose)) && (ole->filename_report_fn != NULL))
+            {
+                ole->filename_report_fn(stream_name);
+            }
+        }                       /* if file is valid */
+    }                           /* if full_path is valid */
+
+    if (full_path)
+    {
+        FREE(full_path);
+    }
+
+    return OLE_OK;
 }
 
-
 /*-----------------------------------------------------------------\
        Function Name   : OLE_decode_file_done
        Returns Type    : int
@@ -1616,20 +1653,24 @@ int OLE_store_stream( struct OLE_object *ole, char *stream_name, char *directory
        Changes:
 
        \------------------------------------------------------------------*/
-       int OLE_decode_file_done( struct OLE_object *ole )
-       {
-               if (ole->f) fclose(ole->f);
-               /** Why weren't these active? (they were commented out ) **/
-               if (ole->FAT) FREE(ole->FAT);
-               if (ole->miniFAT) FREE(ole->miniFAT);
-               if (ole->ministream) FREE(ole->ministream);
-               if (ole->properties) FREE(ole->properties);
-
-               return 0;
-       }
-
+int OLE_decode_file_done(struct OLE_object *ole)
+{
+    if (ole->f)
+        fclose(ole->f);
+        /** Why weren't these active? (they were commented out ) **/
+    if (ole->FAT)
+        FREE(ole->FAT);
+    if (ole->miniFAT)
+        FREE(ole->miniFAT);
+    if (ole->ministream)
+        FREE(ole->ministream);
+    if (ole->properties)
+        FREE(ole->properties);
+
+    return 0;
+}
 
-       /*-----------------------------------------------------------------\
+    /*-----------------------------------------------------------------\
        Function Name   : OLE_terminate_and_return
        Returns Type    : int
        ----Parameter List
@@ -1645,139 +1686,153 @@ int OLE_store_stream( struct OLE_object *ole, char *stream_name, char *directory
        Changes:
 
        \------------------------------------------------------------------*/
-       int OLE_terminate_and_return( struct OLE_object *ole, int result )
-       {
-               OLE_decode_file_done(ole);
-               return result;
-       }
-
+int OLE_terminate_and_return(struct OLE_object *ole, int result)
+{
+    OLE_decode_file_done(ole);
+    return result;
+}
 
 #ifdef RIPOLE_WALK_TREE
-       int OLE_walk_tree( struct OLE_object *ole, char *fname, char *decode_path, int depth )
-       {
-
-               /** Sanity check **/
-
-               if (depth > 100) return 0;
-               if (ole->total_file_count > 10000) return 0;
-               if (element_type < 0) return 0;
-
-               switch (element_type) {
-
-       case STGTY_ROOT:
-               /** ROOT DIRECTORY ENTRY **/
-               /** ROOT DIRECTORY ENTRY **/
-               /** ROOT DIRECTORY ENTRY **/
-               DOLE LOGGER_log("%s:%d:OLE_walk_tree:DEBUG: Loading ministream/SmallBlockArray",FL);
-               ole->ministream = OLE_load_chain( ole, adir->start_sector );
-               if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL;
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: ministream done",FL);
-               }
-
-       } else if (adir->element_type == STGTY_STORAGE) {
-               /** STORAGE ELEMENT **/
-               /** STORAGE ELEMENT **/
-               /** STORAGE ELEMENT **/
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Item is directory, start child is at index %d\n",FL,i);
-               ole->ministream = OLE_load_chain( ole, adir->start_sector );
-               if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL;
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: DIRECTORY ministream done",FL);
-
-
-       }
-#endif
+int OLE_walk_tree(struct OLE_object *ole, char *fname, char *decode_path, int depth)
+{
+
+        /** Sanity check **/
+
+    if (depth > 100)
+        return 0;
+    if (ole->total_file_count > 10000)
+        return 0;
+    if (element_type < 0)
+        return 0;
+
+    switch (element_type)
+    {
+
+    case STGTY_ROOT:
+        /** ROOT DIRECTORY ENTRY **/
+        /** ROOT DIRECTORY ENTRY **/
+        /** ROOT DIRECTORY ENTRY **/
+        DOLE LOGGER_log("%s:%d:OLE_walk_tree:DEBUG: Loading ministream/SmallBlockArray", FL);
+        ole->ministream = OLE_load_chain(ole, adir->start_sector);
+        if (ole->ministream == NULL)
+            return OLEER_MINISTREAM_READ_FAIL;
+        DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: ministream done", FL);
+    }
+
+}
+
+else
+if (adir->element_type == STGTY_STORAGE)
+{
+        /** STORAGE ELEMENT **/
+        /** STORAGE ELEMENT **/
+        /** STORAGE ELEMENT **/
+DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Item is directory, start child is at index %d\n", FL, i);
 
+ole->ministream = OLE_load_chain(ole, adir->start_sector);
+if (ole->ministream == NULL)
+    return OLEER_MINISTREAM_READ_FAIL;
+DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: DIRECTORY ministream done", FL);
 
+}
+#endif
 
-       int OLE_decode_stream( struct OLE_object *ole,  struct OLE_directory_entry *adir, char *decode_path )
-       {
-               char *stream_data;
-               struct OLEUNWRAP_object oleuw;
-               int decode_result = OLEUW_STREAM_NOT_DECODED;
-               char element_name[64];
-               int result = 0;
-
-               memset(element_name, '\0', 64);
-               OLE_dbstosbs( adir->element_name, adir->element_name_byte_count, element_name, 64 );
-
-               DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Decoding stream '%s'",FL, element_name);
-
-               DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Initializing stream unwrapper",FL);
-               OLEUNWRAP_init(&oleuw);
-               OLEUNWRAP_set_debug(&oleuw,ole->debug);
-               OLEUNWRAP_set_verbose(&oleuw,ole->verbose);
-               OLEUNWRAP_set_filename_report_fn(&oleuw, ole->filename_report_fn);
-               OLEUNWRAP_set_save_unknown_streams(&oleuw, ole->save_unknown_streams);
-               DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Unwrap engine set.",FL);
-
-               if (adir->stream_size >= ole->header.mini_cutoff_size)
-               {
-                       /** Standard size sector stored stream **/
-                       /** Standard size sector stored stream **/
-                       /** Standard size sector stored stream **/
-                       DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG:  Loading normal sized chain starting at sector %d",FL, adir->start_sector);
-                       stream_data = (char *) OLE_load_chain( ole, adir->start_sector );
-                       if (stream_data == NULL)
-                       {
-                               DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Terminating from stream data being NULL  ",FL);
-                               /*OLE_decode_file_done(ole);*/
-                               return OLEER_MINISTREAM_STREAM_READ_FAIL;
-                       }
-                       DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Normal decode START. element name ='%s' stream size = '%ld'",FL, element_name, adir->stream_size);
-                       decode_result = OLEUNWRAP_decodestream( &oleuw, element_name, stream_data, adir->stream_size, decode_path );
-                       DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Normal decode done.",FL);
-               } else {
-
-
-                       /** Minichain/Minisector stored stream **/
-                       /** Minichain/Minisector stored stream **/
-                       /** Minichain/Minisector stored stream **/
-                       DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Minichain loader, starting at sector %d"
-                               ,FL
-                               ,adir->start_sector
-                               );
-                       stream_data = (char *) OLE_load_minichain( ole, adir->start_sector );
-                       if (stream_data == NULL)
-                       {
-                               DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Ministream was non-existant, terminating",FL);
-                               /*OLE_decode_file_done(ole);*/
-                               return OLEER_NORMALSTREAM_STREAM_READ_FAIL;
-                       }
-                       DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Mini decode START.",FL);
-                       decode_result = OLEUNWRAP_decodestream( &oleuw, element_name, stream_data, adir->stream_size, decode_path );
-                       DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Mini decode done.",FL);
-               }
-
-               /* Added for Scilab */
-               if ((stream_data != NULL)&&(decode_result == OLEUW_STREAM_NOT_DECODED)&&
-                       (ole->save_unknown_streams==2)&&((strcmp(element_name,"Workbook")==0)||(strcmp(element_name,"Book")==0)))
-               {
-                       strcpy(element_name,"Workbook");
-                       OLE_store_stream( ole, element_name, decode_path, stream_data, adir->stream_size );
-
-               } /* If we needed to save an unknown stream*/
-
-               else /* end Scilab addition */if ((stream_data != NULL)&&(decode_result == OLEUW_STREAM_NOT_DECODED)&&(ole->save_unknown_streams))
-               {
-                       char *lfname;
-
-                       lfname = PLD_dprintf("ole-stream.%d",adir->start_sector);
-                       if (lfname != NULL)
-                       {
-                               DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Saving stream to %s",FL,lfname);
-                               OLE_store_stream( ole, lfname, decode_path, stream_data, adir->stream_size );
-                               FREE(lfname);
-                       }
-               } /* If we needed to save an unknown stream*/
-
-               /* Clean up an stream_data which we may have */
-               /* read in from the chain-loader.*/
-               if (stream_data) FREE(stream_data);
-
-               return result;
-       }
-
-       /*-----------------------------------------------------------------\
+int OLE_decode_stream(struct OLE_object *ole, struct OLE_directory_entry *adir, char *decode_path)
+{
+    char *stream_data;
+    struct OLEUNWRAP_object oleuw;
+    int decode_result = OLEUW_STREAM_NOT_DECODED;
+    char element_name[64];
+    int result = 0;
+
+    memset(element_name, '\0', 64);
+    OLE_dbstosbs(adir->element_name, adir->element_name_byte_count, element_name, 64);
+
+    DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Decoding stream '%s'", FL, element_name);
+
+    DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Initializing stream unwrapper", FL);
+
+    OLEUNWRAP_init(&oleuw);
+    OLEUNWRAP_set_debug(&oleuw, ole->debug);
+    OLEUNWRAP_set_verbose(&oleuw, ole->verbose);
+    OLEUNWRAP_set_filename_report_fn(&oleuw, ole->filename_report_fn);
+    OLEUNWRAP_set_save_unknown_streams(&oleuw, ole->save_unknown_streams);
+    DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Unwrap engine set.", FL);
+
+    if (adir->stream_size >= ole->header.mini_cutoff_size)
+    {
+            /** Standard size sector stored stream **/
+            /** Standard size sector stored stream **/
+            /** Standard size sector stored stream **/
+        DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG:  Loading normal sized chain starting at sector %d", FL, adir->start_sector);
+
+        stream_data = (char *)OLE_load_chain(ole, adir->start_sector);
+        if (stream_data == NULL)
+        {
+            DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Terminating from stream data being NULL  ", FL);
+
+            /*OLE_decode_file_done(ole); */
+            return OLEER_MINISTREAM_STREAM_READ_FAIL;
+        }
+        DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Normal decode START. element name ='%s' stream size = '%ld'", FL, element_name,
+                        adir->stream_size);
+        decode_result = OLEUNWRAP_decodestream(&oleuw, element_name, stream_data, adir->stream_size, decode_path);
+        DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Normal decode done.", FL);
+    }
+    else
+    {
+
+            /** Minichain/Minisector stored stream **/
+            /** Minichain/Minisector stored stream **/
+            /** Minichain/Minisector stored stream **/
+        DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Minichain loader, starting at sector %d", FL, adir->start_sector);
+
+        stream_data = (char *)OLE_load_minichain(ole, adir->start_sector);
+        if (stream_data == NULL)
+        {
+            DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Ministream was non-existant, terminating", FL);
+
+            /*OLE_decode_file_done(ole); */
+            return OLEER_NORMALSTREAM_STREAM_READ_FAIL;
+        }
+        DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Mini decode START.", FL);
+
+        decode_result = OLEUNWRAP_decodestream(&oleuw, element_name, stream_data, adir->stream_size, decode_path);
+        DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Mini decode done.", FL);
+    }
+
+    /* Added for Scilab */
+    if ((stream_data != NULL) && (decode_result == OLEUW_STREAM_NOT_DECODED) &&
+        (ole->save_unknown_streams == 2) && ((strcmp(element_name, "Workbook") == 0) || (strcmp(element_name, "Book") == 0)))
+    {
+        strcpy(element_name, "Workbook");
+        OLE_store_stream(ole, element_name, decode_path, stream_data, adir->stream_size);
+
+    }                           /* If we needed to save an unknown stream */
+
+    else /* end Scilab addition */ if ((stream_data != NULL) && (decode_result == OLEUW_STREAM_NOT_DECODED) && (ole->save_unknown_streams))
+    {
+        char *lfname;
+
+        lfname = PLD_dprintf("ole-stream.%d", adir->start_sector);
+        if (lfname != NULL)
+        {
+            DOLE LOGGER_log("%s:%d:OLE_decode_stream:DEBUG: Saving stream to %s", FL, lfname);
+
+            OLE_store_stream(ole, lfname, decode_path, stream_data, adir->stream_size);
+            FREE(lfname);
+        }
+    }                           /* If we needed to save an unknown stream */
+
+    /* Clean up an stream_data which we may have */
+    /* read in from the chain-loader. */
+    if (stream_data)
+        FREE(stream_data);
+
+    return result;
+}
+
+    /*-----------------------------------------------------------------\
        Function Name   : OLE_decode_file
        Returns Type    : int
        ----Parameter List
@@ -1793,150 +1848,183 @@ int OLE_store_stream( struct OLE_object *ole, char *stream_name, char *directory
        Changes:
 
        \------------------------------------------------------------------*/
-       int OLE_decode_file( struct OLE_object *ole, char *fname, char *decode_path )
-       {
-               unsigned char *current_property, *property_limit;
-               int result = 0;
-               int i;
-
-               /* Reject any bad paramters.*/
-               if (ole == NULL) return OLEER_DECODE_NULL_OBJECT;
-               if (fname == NULL) return OLEER_DECODE_NULL_FILENAME;
-               if (decode_path == NULL) return OLEER_DECODE_NULL_PATH;
-
-               /* We need to gain access to the OLE2 data file, without*/
-               /*              this pretty much everything is pointless.*/
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: opening %s", FL, fname );
-               result = OLE_open_file( ole, fname );
-               if (result != 0) return result;
-
-               /* Try create the output directory which we're using*/
-               /*              to write the decoded files out to.*/
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: opening output directory %s", FL, decode_path);
-               result = OLE_open_directory( ole, decode_path );
-               if (result != 0) return result;
-
-               /* In order to successfully decode an OLE2 stream, we have to read*/
-               /*              and understand the first 512 bytes of the file, this is the */
-               /*              OLE2 header. */
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Getting main header", FL);
-               result = OLE_get_header( ole );
-               if (result != 0) return result;
-
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Converting main header", FL);
-               result = OLE_convert_header( ole );
-               if (result != 0) return result;
-
-               result = OLE_header_sanity_check( ole );
-               if (result > 0) return OLEER_INSANE_OLE_FILE;
-
-               DOLE OLE_print_header( ole );
-
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading FAT", FL);
-               result = OLE_load_FAT( ole );
-               if (result != 0) return result;
-
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading miniFAT chain", FL);
-               ole->miniFAT = OLE_load_chain( ole, ole->header.mini_fat_start );
-               /* commented out by Serge Steer for Scilab*/
-               /* if (ole->miniFAT == NULL) return OLEER_MINIFAT_READ_FAIL;*/
-
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading Directory stream chain", FL);
-               ole->properties = OLE_load_chain( ole, ole->header.directory_stream_start_sector );
-               if (ole->properties == NULL) return OLEER_PROPERTIES_READ_FAIL;
-
-               i=0;
-               current_property = ole->properties;
-               property_limit = current_property +ole->last_chain_size ;
-               /* while(1)*/
-               while (current_property < property_limit)
-               {
-                       struct OLE_directory_entry a_dir_object, *adir;
-                       int property_value=0;
-
-                       adir = &a_dir_object;
-
-                       OLE_dir_init(adir);
-
-                       property_value = get_1byte_value(current_property);
-                       if (property_value < 1) break;
-
-                       DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG:--------- DIRECTORY INDEX: %d",FL,i);
-
-                       OLE_convert_directory( ole, current_property, adir );
-
-                       DOLE {
-                               LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Printing directory details...",FL);
-                               OLE_print_directory( ole, adir);
-                               LOGGER_log("%s:%d:OLE_decode_file:DEBUG: End of directory details",FL);
-                       }
-
-                       if (adir->element_colour > 1) break;
-
-                       if ((adir->element_type == STGTY_INVALID)||(adir->element_type > STGTY_ROOT))
-                       {
-                               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: breaking out due to element type %d",FL, adir->element_type);
-                               break;
-
-                       } else if (adir->element_type == STGTY_ROOT){
-                               /** ROOT DIRECTORY ENTRY **/
-                               /** ROOT DIRECTORY ENTRY **/
-                               /** ROOT DIRECTORY ENTRY **/
-                               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading ministream/SmallBlockArray",FL);
-                               ole->ministream = OLE_load_chain( ole, adir->start_sector );
-                               /* commented out by Serge Steer for Scilab*/
-                               /*if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL;*/
-                               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: ministream done",FL);
-
-                       } else if (adir->element_type == STGTY_STORAGE) {
-                               /** STORAGE ELEMENT **/
-                               /** STORAGE ELEMENT **/
-                               /** STORAGE ELEMENT **/
-                               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Item is directory, start child is at index %d\n",FL,i);
-                               ole->ministream = OLE_load_chain( ole, adir->start_sector );
-                               /* commented out by Serge Steer for Scilab*/
-                               /*if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL;*/
-                               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: DIRECTORY ministream done",FL);
-
-                       } else if (adir->element_type == STGTY_STREAM) {
-                               /** STREAM ELEMENT **/
-                               /** STREAM ELEMENT **/
-                               /** STREAM ELEMENT **/
-                               /* due to ole.c bugs we restrict here steams to decode to Workbooks (Excel) */
-                               char element_name[64];
-                               memset(element_name, '\0', 64);
-                               OLE_dbstosbs( adir->element_name, adir->element_name_byte_count, element_name, 64 );
-
-                               if ((strcmp(element_name,"Workbook")==0)||(strcmp(element_name,"Book")==0)) {
-                                       OLE_decode_stream( ole, adir, decode_path );
-                               }
-                               /*end of replacment code */
-                               /* Original code */
-                               /*  OLE_decode_stream( ole, adir, decode_path );*/
-                       } else {
-                               /** If the element isn't of the above types then it's possibly
+int OLE_decode_file(struct OLE_object *ole, char *fname, char *decode_path)
+{
+    unsigned char *current_property, *property_limit;
+    int result = 0;
+    int i;
+
+    /* Reject any bad paramters. */
+    if (ole == NULL)
+        return OLEER_DECODE_NULL_OBJECT;
+    if (fname == NULL)
+        return OLEER_DECODE_NULL_FILENAME;
+    if (decode_path == NULL)
+        return OLEER_DECODE_NULL_PATH;
+
+    /* We need to gain access to the OLE2 data file, without */
+    /*      this pretty much everything is pointless. */
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: opening %s", FL, fname);
+
+    result = OLE_open_file(ole, fname);
+    if (result != 0)
+        return result;
+
+    /* Try create the output directory which we're using */
+    /*      to write the decoded files out to. */
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: opening output directory %s", FL, decode_path);
+
+    result = OLE_open_directory(ole, decode_path);
+    if (result != 0)
+        return result;
+
+    /* In order to successfully decode an OLE2 stream, we have to read */
+    /*      and understand the first 512 bytes of the file, this is the */
+    /*      OLE2 header. */
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Getting main header", FL);
+
+    result = OLE_get_header(ole);
+    if (result != 0)
+        return result;
+
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Converting main header", FL);
+
+    result = OLE_convert_header(ole);
+    if (result != 0)
+        return result;
+
+    result = OLE_header_sanity_check(ole);
+    if (result > 0)
+        return OLEER_INSANE_OLE_FILE;
+
+    DOLE OLE_print_header(ole);
+
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading FAT", FL);
+
+    result = OLE_load_FAT(ole);
+    if (result != 0)
+        return result;
+
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading miniFAT chain", FL);
+
+    ole->miniFAT = OLE_load_chain(ole, ole->header.mini_fat_start);
+    /* commented out by Serge Steer for Scilab */
+    /* if (ole->miniFAT == NULL) return OLEER_MINIFAT_READ_FAIL; */
+
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading Directory stream chain", FL);
+
+    ole->properties = OLE_load_chain(ole, ole->header.directory_stream_start_sector);
+    if (ole->properties == NULL)
+        return OLEER_PROPERTIES_READ_FAIL;
+
+    i = 0;
+    current_property = ole->properties;
+    property_limit = current_property + ole->last_chain_size;
+    /* while(1) */
+    while (current_property < property_limit)
+    {
+        struct OLE_directory_entry a_dir_object, *adir;
+        int property_value = 0;
+
+        adir = &a_dir_object;
+
+        OLE_dir_init(adir);
+
+        property_value = get_1byte_value(current_property);
+        if (property_value < 1)
+            break;
+
+        DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG:--------- DIRECTORY INDEX: %d", FL, i);
+
+        OLE_convert_directory(ole, current_property, adir);
+
+        DOLE
+        {
+            LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Printing directory details...", FL);
+            OLE_print_directory(ole, adir);
+            LOGGER_log("%s:%d:OLE_decode_file:DEBUG: End of directory details", FL);
+        }
+
+        if (adir->element_colour > 1)
+            break;
+
+        if ((adir->element_type == STGTY_INVALID) || (adir->element_type > STGTY_ROOT))
+        {
+            DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: breaking out due to element type %d", FL, adir->element_type);
+
+            break;
+
+        }
+        else if (adir->element_type == STGTY_ROOT)
+        {
+                /** ROOT DIRECTORY ENTRY **/
+                /** ROOT DIRECTORY ENTRY **/
+                /** ROOT DIRECTORY ENTRY **/
+            DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading ministream/SmallBlockArray", FL);
+
+            ole->ministream = OLE_load_chain(ole, adir->start_sector);
+            /* commented out by Serge Steer for Scilab */
+            /*if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL; */
+            DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: ministream done", FL);
+
+        }
+        else if (adir->element_type == STGTY_STORAGE)
+        {
+                /** STORAGE ELEMENT **/
+                /** STORAGE ELEMENT **/
+                /** STORAGE ELEMENT **/
+            DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Item is directory, start child is at index %d\n", FL, i);
+
+            ole->ministream = OLE_load_chain(ole, adir->start_sector);
+            /* commented out by Serge Steer for Scilab */
+            /*if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL; */
+            DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: DIRECTORY ministream done", FL);
+
+        }
+        else if (adir->element_type == STGTY_STREAM)
+        {
+                /** STREAM ELEMENT **/
+                /** STREAM ELEMENT **/
+                /** STREAM ELEMENT **/
+            /* due to ole.c bugs we restrict here steams to decode to Workbooks (Excel) */
+            char element_name[64];
+
+            memset(element_name, '\0', 64);
+            OLE_dbstosbs(adir->element_name, adir->element_name_byte_count, element_name, 64);
+
+            if ((strcmp(element_name, "Workbook") == 0) || (strcmp(element_name, "Book") == 0))
+            {
+                OLE_decode_stream(ole, adir, decode_path);
+            }
+            /*end of replacment code */
+            /* Original code */
+            /*  OLE_decode_stream( ole, adir, decode_path ); */
+        }
+        else
+        {
+                /** If the element isn't of the above types then it's possibly
                                ** an empty element or just one used for the MSAT/SAT
                                ** either way we just step over it and carry on **/
-                               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Element type %d does not need to be handled",FL,adir->element_type);
-                       }
+            DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Element type %d does not need to be handled", FL, adir->element_type);
+        }
 
-                       /* Jump to the next property record, which*/
-                       /*              is always 128 bytes ahead.*/
-                       current_property += 128;
-                       i++;
+        /* Jump to the next property record, which */
+        /*      is always 128 bytes ahead. */
+        current_property += 128;
+        i++;
 
-               } /* While there are still more directory entries to read in.*/
+    }                           /* While there are still more directory entries to read in. */
 
-               DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Finished",FL);
+    DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Finished", FL);
 
-               /*
-               if (ole->f) fclose(ole->f);
-               fclose(ole->f);
-               if (ole->FAT) FREE(ole->FAT);
-               if (ole->miniFAT) FREE(ole->miniFAT);
-               if (ole->ministream) FREE(ole->ministream);
-               if (ole->properties) FREE(ole->properties);
-               */
+    /*
+     * if (ole->f) fclose(ole->f);
+     * fclose(ole->f);
+     * if (ole->FAT) FREE(ole->FAT);
+     * if (ole->miniFAT) FREE(ole->miniFAT);
+     * if (ole->ministream) FREE(ole->ministream);
+     * if (ole->properties) FREE(ole->properties);
+     */
 
-               return OLE_OK;
-       }
+    return OLE_OK;
+}
index 274acc6..658dd1d 100644 (file)
 #include "MALLOC.h"
 
 #ifdef _MSC_VER
-       #include "strdup_windows.h"
+#include "strdup_windows.h"
 #endif
 
 #define ROLE_VERSION "0.2.0"
 
-static char defaultdir[]=".";
-static char version[]="0.2.0 - 12-December-2005 (C) PLDaniels http:/*www.pldaniels.com/ripole";
-static char help[]="ripOLE -i <OLE2 file> [ -d <directory> ] [--save-unknown-streams] [--version|-V] [--verbose|-v] [--debug] [--help|-h]";
+static char defaultdir[] = ".";
+static char version[] = "0.2.0 - 12-December-2005 (C) PLDaniels http:/*www.pldaniels.com/ripole";
+static char help[] = "ripOLE -i <OLE2 file> [ -d <directory> ] [--save-unknown-streams] [--version|-V] [--verbose|-v] [--debug] [--help|-h]";
 
 /*-----------------------------------------------------------------\
   Function Name        : set_defaults
@@ -41,152 +41,18 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int ROLE_set_defaults( struct ripOLE_object *role )
+int ROLE_set_defaults(struct ripOLE_object *role)
 {
-       role->outputdir = defaultdir;
-       role->debug = 0;
-       role->verbose = 0;
-       role->save_unknown_streams = 0;
-       role->inputfile = NULL;
+    role->outputdir = defaultdir;
+    role->debug = 0;
+    role->verbose = 0;
+    role->save_unknown_streams = 0;
+    role->inputfile = NULL;
 
-       return 0;
+    return 0;
 }
 
 /*-----------------------------------------------------------------\
-  Function Name        : parse_parameters
-  Returns Type : int
-  ----Parameter List
-  1. struct ripOLE_object *role, 
-  2.  int argc, 
-  3.  char **argv , 
-  ------------------
-  Exit Codes   : 
-  Side Effects : 
-  --------------------------------------------------------------------
-Comments:
-
---------------------------------------------------------------------
-Changes:
-
-\------------------------------------------------------------------*/
-int ROLE_parse_parameters( struct ripOLE_object *role, int argc, char **argv )
-{
-       int i;
-       int result = 0;
-
-       role->outputdir = defaultdir;
-
-       for (i = 1; i < argc; i++)
-       {
-               if (argv[i][0] == '-')
-               {
-                       switch (argv[i][1])
-                       {
-                               case 'i':
-                                       i++;
-                                       role->inputfile = strdup(argv[i]);
-                                       break;
-
-                               case 'd':
-                                       i++;
-                                       role->outputdir = strdup(argv[i]);
-                                       break;
-
-                               case 'v':
-                                       role->verbose = 1;
-                                       break;
-
-                               case 'V':
-                                       fprintf (stdout, "%s\n", version);
-                                       exit (1);
-                                       break;
-                               case 'h':
-                                       fprintf (stdout, "%s\n", help);
-                                       exit (1);
-                                       break;
-
-                                       /* if we get ANOTHER - symbol, then we have an extended flag*/
-
-                               case '-':
-                                       if (strncmp (&(argv[i][2]), "verbose", 7) == 0)
-                                       {
-                                               role->verbose=1;
-
-                                       } else if (strncmp (&(argv[i][2]), "save-unknown-streams", 20) == 0) {
-                                               role->save_unknown_streams = 1;
-
-                                       } else if (strncmp (&(argv[i][2]), "debug", 5) == 0) {
-                                               role->debug=1;
-
-                                       } else if (strncmp (&(argv[i][2]), "version", 7) == 0) {
-                                               fprintf (stdout, "%s\n", version);
-                                               exit (1);
-
-                                       } else if (strncmp(&(argv[i][2]),"help",4)==0) {
-                                               fprintf(stdout,"%s\n",help);
-                                               exit(1);
-
-                                       } else {
-                                               fprintf(stdout,_("Cannot interpret option \"%s\"\n%s\n"), argv[i], help);
-                                               exit (1);
-                                               break;
-                                       }
-                                       break;
-
-                                       /* else, just dump out the help message*/
-
-                               default:
-                                       fprintf(stdout,_("Cannot interpret option \"%s\"\n%s\n"), argv[i], help);
-                                       exit (1);
-                                       break;
-
-                       }                       /* Switch argv[i][1]*/
-
-               }                       /* if argv[i][0] == -*/
-
-       }                               /* for*/
-
-       return result;
-}
-
-/*-----------------------------------------------------------------\
-  Function Name        : set_parameters
-  Returns Type : int
-  ----Parameter List
-  1. struct ripOLE_object *role, 
-  2.  struct OLE_object *ole , 
-  ------------------
-  Exit Codes   : 
-  Side Effects : 
-  --------------------------------------------------------------------
-Comments:
-
---------------------------------------------------------------------
-Changes:
-
-\------------------------------------------------------------------*/
-int ROLE_set_parameters( struct ripOLE_object *role, struct OLE_object *ole )
-{
-       if(role->debug == 1)
-       {
-               OLE_set_debug(ole, OLE_DEBUG_NORMAL);
-       } 
-
-       if (role->verbose == 1)
-       {
-               OLE_set_verbose(ole, OLE_VERBOSE_NORMAL);
-       }
-
-       if (role->save_unknown_streams == 1)
-       {
-               OLE_set_save_unknown_streams(ole, 1);
-       }
-
-       return 0;
-}
-
-
-/*-----------------------------------------------------------------\
   Function Name        : ripOLE_report_filename_decoded
   Returns Type : int
   ----Parameter List
@@ -203,13 +69,11 @@ Changes:
 \------------------------------------------------------------------*/
 int ROLE_report_filename_decoded(char *filename)
 {
-       LOGGER_log(_("Decoding filename=%s"), filename);
+    LOGGER_log(_("Decoding filename=%s"), filename);
 
-       return 0;
+    return 0;
 }
 
-
-
 /*-----------------------------------------------------------------\
   Function Name        : ROLE_init
   Returns Type : int
@@ -227,17 +91,16 @@ Changes:
 \------------------------------------------------------------------*/
 int ROLE_init(struct ripOLE_object *role)
 {
-       role->debug = 0;
-       role->verbose = 0;
-       role->save_unknown_streams = 0;
+    role->debug = 0;
+    role->verbose = 0;
+    role->save_unknown_streams = 0;
 
-       role->inputfile = NULL;
-       role->outputdir = NULL;
+    role->inputfile = NULL;
+    role->outputdir = NULL;
 
-       return 0;
+    return 0;
 }
 
-
 /*-----------------------------------------------------------------\
   Function Name        : ROLE_done
   Returns Type : int
@@ -255,13 +118,14 @@ Changes:
 \------------------------------------------------------------------*/
 int ROLE_done(struct ripOLE_object *role)
 {
-       if (role->inputfile != NULL) FREE(role->inputfile);
-       if (role->outputdir != NULL) FREE(role->outputdir);
+    if (role->inputfile != NULL)
+        FREE(role->inputfile);
+    if (role->outputdir != NULL)
+        FREE(role->outputdir);
 
-       return 0;
+    return 0;
 }
 
-
 /*-----------------------------------------------------------------\
   Function Name        : ROLE_validate
   Returns Type : int
@@ -277,127 +141,51 @@ Comments:
 Changes:
 
 \------------------------------------------------------------------*/
-int ROLE_validate(struct ripOLE_object *role )
+int ROLE_validate(struct ripOLE_object *role)
 {
-       int result = 0;
-
-       if (role->inputfile == NULL) {
-               fprintf(stderr,_("ripOLE requires an input file to decode.\n"));
-               return -1;
-       }
-
-       return result;
-}
-#ifdef WITHMAIN
-/*-----------------------------------------------------------------\
-  Function Name        : main
-  Returns Type : int
-  ----Parameter List
-  1. int argc, 
-  2.  char **argv , 
-  ------------------
-  Exit Codes   : 
-  Side Effects : 
-  --------------------------------------------------------------------
-Comments:
+    int result = 0;
 
---------------------------------------------------------------------
-Changes:
+    if (role->inputfile == NULL)
+    {
+        fprintf(stderr, _("ripOLE requires an input file to decode.\n"));
+        return -1;
+    }
 
-\------------------------------------------------------------------*/
-int main( int argc, char **argv )
-{
-       struct ripOLE_object role;
-       struct OLE_object *ole = NULL;
-       int result = 0;
-
-       if (argc == 1) { fprintf (stdout, "%s\n", help); exit(1); }
-
-       ole = MALLOC(sizeof(struct OLE_object));
-       if (ole == NULL)
-       {
-               LOGGER_log(_("ripOLE: Cannot allocate memory for OLE object."));
-               return 1;
-       }
-
-
-       LOGGER_set_output_mode(_LOGGER_STDOUT);
-
-       OLE_init(ole);
-       ROLE_init(&role);
-
-       ROLE_set_defaults( &role );
-       ROLE_parse_parameters(&role, argc, argv);
-       result = ROLE_validate(&role);
-       if (result != 0) return result;
-
-       ROLE_set_parameters(&role, ole);
-
-       OLE_set_filename_report_fn(ole, ROLE_report_filename_decoded );
-
-       result = OLE_decode_file( ole, role.inputfile, role.outputdir );
-       OLE_decode_file_done(ole);
-
-       if ((result != 0)) {
-               if (role.verbose) {
-                       switch (result) {
-                               case OLEER_NO_INPUT_FILE:
-                               case OLEER_BAD_INPUT_FILE:
-                                       LOGGER_log(_("Cannot locate input file '%s'"),role.inputfile);
-                                       break;
-                               case OLEER_NOT_OLE_FILE:
-                                       LOGGER_log(_("File '%s' is not OLE2 format"),role.inputfile);
-                                       break;
-                               case OLEER_INSANE_OLE_FILE:
-                                       LOGGER_log(_("OLE input file '%s' is insane"), role.inputfile);
-                                       break;
-                               default:
-                                       LOGGER_log(_("ripOLE: decoding of %s resulted in error %d\n"), role.inputfile, result );
-                       }
-               }
-               return result;
-       }
-
-       if (ole != NULL) FREE(ole);
-       ROLE_done(&role);
-
-       return result;
+    return result;
 }
 
-#endif
-/** end of ripOLE **/
-
 int ripole(char *inputfile, char *outputdir, int debug, int verbose)
 {
-  /*struct OLE_object *ole = NULL;*/
-  struct OLE_object ole;
-       int result = 0;
-
-       /*ole = MALLOC(sizeof(struct OLE_object));
-       if (ole == NULL)
-       {
-               LOGGER_log(_("ripOLE: Cannot allocate memory for OLE object"));
-               return 1;
-       }*/
-
-       LOGGER_set_output_mode(_LOGGER_STDOUT);
-
-       OLE_init(&ole);
-       if (debug ==1 ) OLE_set_debug(&ole, OLE_DEBUG_NORMAL);
-       if (verbose == 1) OLE_set_verbose(&ole, OLE_VERBOSE_NORMAL);
-       /*ole->save_unknown_streams==2 added for Scilab to extract onlyspreadsheet streams
-        see  OLE_decode_stream in ole.c file */
-       OLE_set_save_unknown_streams(&ole, 2); /* get only spreadsheet streams */
-
-       OLE_set_filename_report_fn(&ole, ROLE_report_filename_decoded );
-
-       result = OLE_decode_file( &ole, inputfile, outputdir);
-       OLE_decode_file_done(&ole);
-
-
-       if ((result != 0)&&(verbose==1))
-         LOGGER_log(_("ripOLE: decoding of %s resulted in error %d.\n"), inputfile, result );
-
-       /*if (ole != NULL) FREE(ole);*/
-       return result;
+    /*struct OLE_object *ole = NULL; */
+    struct OLE_object ole;
+    int result = 0;
+
+    /*ole = MALLOC(sizeof(struct OLE_object));
+     * if (ole == NULL)
+     * {
+     * LOGGER_log(_("ripOLE: Cannot allocate memory for OLE object"));
+     * return 1;
+     * } */
+
+    LOGGER_set_output_mode(_LOGGER_STDOUT);
+
+    OLE_init(&ole);
+    if (debug == 1)
+        OLE_set_debug(&ole, OLE_DEBUG_NORMAL);
+    if (verbose == 1)
+        OLE_set_verbose(&ole, OLE_VERBOSE_NORMAL);
+    /*ole->save_unknown_streams==2 added for Scilab to extract onlyspreadsheet streams
+     * see  OLE_decode_stream in ole.c file */
+    OLE_set_save_unknown_streams(&ole, 2);  /* get only spreadsheet streams */
+
+    OLE_set_filename_report_fn(&ole, ROLE_report_filename_decoded);
+
+    result = OLE_decode_file(&ole, inputfile, outputdir);
+    OLE_decode_file_done(&ole);
+
+    if ((result != 0) && (verbose == 1))
+        LOGGER_log(_("ripOLE: decoding of %s resulted in error %d.\n"), inputfile, result);
+
+    /*if (ole != NULL) FREE(ole); */
+    return result;
 }