X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmArgMgr.cxx;h=03d8841622c91e47cd6c47c6810156ad06960b57;hb=35ee8ee8af32946514713d271177df8bb2298eb2;hp=32e3765ef519e0d623c9b9ad911003b087e294fb;hpb=e8c1403463461aa74907f63a73e85ef09c2e3373;p=gdcm.git diff --git a/src/gdcmArgMgr.cxx b/src/gdcmArgMgr.cxx index 32e3765e..03d88416 100644 --- a/src/gdcmArgMgr.cxx +++ b/src/gdcmArgMgr.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmArgMgr.cxx,v $ Language: C++ - Date: $Date: 2005/12/22 14:46:06 $ - Version: $Revision: 1.16 $ + 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 @@ -21,12 +21,18 @@ #include #include // 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 // For strtok and strlen #include // 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; i0; i-- ) @@ -182,7 +200,7 @@ char *ArgMgr::ArgMgrUnused ( ) */ int ArgMgr::ArgMgrPrintUnusedLabels () { - char *label; + const char *label; int i=0; while ( (label=ArgMgrUnused())!=0 ) { @@ -217,7 +235,7 @@ int ArgMgr::ArgMgrUsage(const char **usage ) * @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; @@ -277,7 +295,7 @@ float ArgMgr::ArgMgrGetFloat(const char *param, float defaultVal) * @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)) @@ -295,22 +313,23 @@ char *ArgMgr::ArgMgrGetString(const char *param, char *defaultVal) * @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; @@ -326,18 +345,19 @@ int ArgMgr::ArgMgrGetLabel (const char *param, char *liste, int val ) * @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; } @@ -744,7 +764,7 @@ char *ArgMgr::Majuscule (const char *chaine ) 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(chaine) ; *ptr!='\0' ; ptr ++ ) { *ptr3 = toupper ( * ptr ); ptr3++; } @@ -761,7 +781,7 @@ char *ArgMgr::Majuscule (const char *chaine ) * Valeur retournee . : false if OK. * * true if KO. * **************************************************************************/ -int ArgMgr::FiltreLong ( char *arg ) +int ArgMgr::FiltreLong ( const char *arg ) { int n = 0 ; while ( (n++(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 " */ @@ -824,16 +844,16 @@ const char *ArgMgr::LoadedParam ( const char *param, FILE *fd ) | 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] ); @@ -848,7 +868,7 @@ int ArgMgr::ArgLoadFromFile ( char *filename ) } } fclose ( fch ); - return nbl; + return static_cast< int >( nbl ); } /*------------------------------------------------------------------------ @@ -861,12 +881,12 @@ void ArgMgr::ArgStdArgs() char *logfile; FILE *fd; - if ( (ArgParamOut=ArgMgrValue((char*)ARG_LABEL_PARAMOUT))==0 ) + if ( (ArgParamOut=ArgMgrValue(const_cast(ARG_LABEL_PARAMOUT)))==0 ) ArgParamOut = ARG_DEFAULT_PARAMOUT; - if ( (logfile = ArgMgrValue((char*)ARG_LABEL_LOGFILE))!=0) + if ( (logfile = ArgMgrValue(const_cast(ARG_LABEL_LOGFILE)))!=0) { if ( *logfile == '\0' ) - logfile = (char *)ARG_DEFAULT_LOGFILE; + logfile = const_cast(ARG_DEFAULT_LOGFILE); fd = fopen ( logfile, "a+" ); if ( fd ) {