]> Creatis software - gdcm.git/blobdiff - src/gdcmArgMgr.cxx
ENH: avoid writing illegal images with a double dots.
[gdcm.git] / src / gdcmArgMgr.cxx
index 82cc2a0aa9667cce49c8cecd9d59792d4398fc37..4950d679f4280944ba7cdc47fbe05c6720cde36f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmArgMgr.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/01/26 16:01:04 $
-  Version:   $Revision: 1.18 $
+  Date:      $Date: 2007/10/04 17:50:42 $
+  Version:   $Revision: 1.26 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include <ctype.h>
 #include <string.h>  // For strlen
 
+// No strcasecmp in WIN32 world, but stricmp
+// http://www.opengroup.org/onlinepubs/007908799/xsh/strcasecmp.html
+#ifdef _WIN32
+#define strcasecmp stricmp
+#endif
+
 #include <string.h>  // For strtok and strlen
 #include <stdlib.h>  // For strtol and strtod
 
 #include "gdcmArgMgr.h"
 
-namespace gdcm 
+namespace GDCM_NAME_SPACE 
 {
 //-------------------------------------------------------------------------
 // Constructor / Destructor
@@ -37,12 +43,13 @@ namespace gdcm
  * @param argv  pointers array on the arguments passed to main()  
  */
  ArgMgr::ArgMgr(int argc, char **argv)
+ : ArgParamOut (NULL), ArgUsed(NULL), ArgLab(NULL), ArgStr(NULL), ArgCount(0), Appel(NULL)
  {
    int i;
-   int nblettre;
-   ArgUsed = NULL;
-   Appel   = NULL;
-  
+   int nblettre;   
+   ArgLab = new char *[ARGMAXCOUNT];
+   ArgStr = new char *[ARGMAXCOUNT];
+   
    /* Read the parameters of the command line *************************/
    for ( ArgCount=0, nblettre=1 , i=0; i<argc; i++) 
    {
@@ -88,13 +95,19 @@ namespace gdcm
       char * egaloufin = ArgLab[i] ;
       while ( (*egaloufin != '\0') && (*egaloufin != '=') ) 
          egaloufin ++ ;
-      if ( *egaloufin ) *(egaloufin++) = '\0';
+      if ( *egaloufin )
+          *(egaloufin++) = '\0';
       ArgStr[i]= egaloufin;
    }
 
    /* Set labels to upper-case (labels are not case sensitive ) *********/
+   //char *secu;
    for ( i=0; i<ArgCount; i++)
+   {
+      //secu = ArgLab[i];
       ArgLab[i] = Majuscule ( ArgLab[i] ) ;
+      //free (secu); //we still need it in the caller pgm.
+   }
 
   /* Standard arguments are managed by ArgStdArgs **********************/
    ArgStdArgs(); 
@@ -108,10 +121,13 @@ ArgMgr::~ArgMgr()
    for(int i=0;i<ArgCount;i++)
       if ( ArgLab[i] )
          free(ArgLab[i]);
+   delete ArgLab;   
+   delete ArgStr;  
    if ( ArgUsed )
       free(ArgUsed);
    if ( Appel )
       free(Appel);
 }
  
 /**
@@ -131,6 +147,7 @@ int ArgMgr::ArgMgrDefined( const char *param )
     trouve = ( strcmp( ArgLab[i], temp )==0 ) ;
     if ( trouve )
     {
+      free (temp);
       ArgUsed[i] = true ;           
       for ( int j=1; j<i; j++)
       {                     
@@ -138,8 +155,9 @@ int ArgMgr::ArgMgrDefined( const char *param )
             ArgUsed[j] = i ;
       }
       return i ;
-    }
+    }   
   }
+  free (temp);
   return 0 ;
 }