Program: gdcm
Module: $RCSfile: gdcmArgMgr.cxx,v $
Language: C++
- Date: $Date: 2005/09/08 14:00:39 $
- Version: $Revision: 1.14 $
+ Date: $Date: 2008/05/14 10:45:11 $
+ Version: $Revision: 1.28 $
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
* @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++)
{
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();
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);
+
}
/**
bool trouve;
char *temp;
temp = Majuscule ( param ) ;
- for ( trouve = false, i = ArgCount-1; i>0; i-- )
+ for ( i = ArgCount-1; i>0; i-- )
{
trouve = ( strcmp( ArgLab[i], temp )==0 ) ;
if ( trouve )
{
+ free (temp);
ArgUsed[i] = true ;
for ( int j=1; j<i; j++)
{
ArgUsed[j] = i ;
}
return i ;
- }
+ }
}
+ free (temp);
return 0 ;
}
* \brief Search for the first not yet used label
* @return Pointer to the char array holding the first non used label
*/
-char *ArgMgr::ArgMgrUnused ( )
+const char *ArgMgr::ArgMgrUnused ( )
{
int i ;
for ( i=ArgCount-1; i>0; i-- )
*/
int ArgMgr::ArgMgrPrintUnusedLabels ()
{
- char *label;
+ const char *label;
int i=0;
while ( (label=ArgMgrUnused())!=0 )
{
* @param param char. array that defines the parameter
* @return Entier correspondant au rang dans la liste de labels
*/
-int ArgMgr::ArgMgrSave ( char *param )
+int ArgMgr::ArgMgrSave ( const char *param )
{
static int deja = 0;
FILE *fd;
* @param defaultVal default value
* @return parameter value
*/
-char *ArgMgr::ArgMgrGetString(const char *param, char *defaultVal)
+const char *ArgMgr::ArgMgrGetString(const char *param, const char *defaultVal)
{
return ( (ArgMgrDefined(param))
? (ArgMgrValue(param))
* @param val number of default value
* @return int : range of value amongst the values list
*/
-int ArgMgr::ArgMgrGetLabel (const char *param, char *liste, int val )
+int ArgMgr::ArgMgrGetLabel (const char *param, const char *liste, int val )
{
char *lab;
- char *vallab;
+ const char *vallab;
int i = 1;
char *tmp;
tmp = (char *) malloc(strlen(liste)+1);
strcpy(tmp,liste);
- if ( (vallab = ArgMgrGetString(param,(char *)NULL)) != 0 )
+ if ( (vallab = ArgMgrGetString(param,(const char *)NULL)) != 0 )
{
for ( lab = strtok (tmp,"\\");
lab != 0;
lab = strtok(0L,"\\"), i++ )
{
- if ( strcmp(maj(lab),maj(vallab))==0)
+ // strcmp ignoring case
+ if( strcasecmp(lab, vallab) == 0)
return i;
}
val=0;
* @param liste character Chain describing the various values.
* Labels are separated by '\\'.
* No case sensitive.
+ * WARNING this will be changed (not const)
* @param usage Usage program (displayed if label not found)
* @return int : range of value amongst the values list
*/
int ArgMgr::ArgMgrWantLabel (const char *param, char *liste, const char **usage )
{
char *lab;
- char *vallab;
+ const char *vallab;
int i = 1;
if ( (vallab = ArgMgrGetString(param,0)) != 0 )
{
for ( lab = strtok (liste,"\\"); lab != 0; lab = strtok(0L,"\\"), i++ )
- if ( strcmp(maj(lab),maj(vallab))==0)
+ if ( strcasecmp(lab,vallab)==0)
return i;
return 0;
}
char **elem;
char *chainecur;
if (!value)
+ {
+ *number = 0;
return 0;
+ }
*number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
taille = *number;
liste = (char **) malloc (sizeof(char*) * taille + strlen(value)+1);
int *elem;
int taille;
if (!value)
+ {
+ *number = 0;
return 0;
- *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
+ }
+ *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
taille= *number;
liste = (int *) calloc (1,sizeof(int)*taille );
if ( !liste )
return 0;
elem = liste;
- *number = 1;
+ //*number = 1;
while ( taille>0 )
{
taille= *number;
liste = (float *) calloc (1,sizeof(float)*taille );
if ( !liste )
+ {
+ *number = 0;
return 0;
+ }
elem = liste;
- *number = 1;
+ //*number = 1;
while ( taille>0 )
{
char *ptr, *ptr2, *ptr3;
ptr2 = (char *)malloc(strlen(chaine)*sizeof(char)+1);
ptr3=ptr2;
- for ( ptr = (char *)chaine ; *ptr!='\0' ; ptr ++ )
+ for ( ptr = const_cast<char *>(chaine) ; *ptr!='\0' ; ptr ++ )
{
*ptr3 = toupper ( * ptr ); ptr3++;
}
* Valeur retournee . : false if OK. *
* true if KO. *
**************************************************************************/
-int ArgMgr::FiltreLong ( char *arg )
+int ArgMgr::FiltreLong ( const char *arg )
{
int n = 0 ;
while ( (n++<ARG_LONG_MAX) && (*(arg++) != '\0') ) ;
const char *ArgMgr::LoadedParam ( const char *param, FILE *fd )
{
int carlu;
- char *car = (char *)param;
+ char *car = const_cast<char *>(param);
int quote = false;
int nbcar = 0;
/* remove spaces at the beginning****/
- while ( isspace(carlu=fgetc (fd)) );
+ while ( isspace(carlu=fgetc (fd)) ) {}
if (carlu==EOF)
return 0;
/* Search for a " */
| Role : parameter File name
|
+------------------------------------------------------------------------*/
-int ArgMgr::ArgLoadFromFile ( char *filename )
+int ArgMgr::ArgLoadFromFile ( const char *filename )
{
- int nbl = 0;
+ size_t nbl = 0;
char param[ARG_LONG_MAX+1];
FILE *fch;
fch = fopen ( filename, ID_RFILE_TEXT );
while ( LoadedParam (param, fch ) )
{
- int n = strlen(param);
+ size_t n = strlen(param);
if ( param[0]=='@' )
{
nbl += ArgLoadFromFile ( ¶m[1] );
}
}
fclose ( fch );
- return nbl;
+ return static_cast< int >( nbl );
}
/*------------------------------------------------------------------------
char *logfile;
FILE *fd;
- if ( (ArgParamOut=ArgMgrValue((char*)ARG_LABEL_PARAMOUT))==0 )
+ if ( (ArgParamOut=ArgMgrValue(const_cast<char*>(ARG_LABEL_PARAMOUT)))==0 )
ArgParamOut = ARG_DEFAULT_PARAMOUT;
- if ( (logfile = ArgMgrValue((char*)ARG_LABEL_LOGFILE))!=0)
+ if ( (logfile = ArgMgrValue(const_cast<char*>(ARG_LABEL_LOGFILE)))!=0)
{
if ( *logfile == '\0' )
- logfile = (char *)ARG_DEFAULT_LOGFILE;
+ logfile = const_cast<char *>(ARG_DEFAULT_LOGFILE);
fd = fopen ( logfile, "a+" );
if ( fd )
{