X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmArgMgr.cxx;h=4950d679f4280944ba7cdc47fbe05c6720cde36f;hb=721d134c6e594b9a23bf1ce002ed87bfbc1576a7;hp=79ef553c6ee482dc23064859eebe2a71dd9ae98f;hpb=2d3b99ded7b569f8624ae85b99126821098a429a;p=gdcm.git diff --git a/src/gdcmArgMgr.cxx b/src/gdcmArgMgr.cxx index 79ef553c..4950d679 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/08/28 16:56:05 $ - Version: $Revision: 1.13 $ + 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 @@ -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-- ) + for ( i = ArgCount-1; i>0; i-- ) { - trouve = ! strcmp( ArgLab[i], temp ) ; + trouve = ( strcmp( ArgLab[i], temp )==0 ) ; if ( trouve ) { + free (temp); ArgUsed[i] = true ; for ( int j=1; j0; i-- ) @@ -181,7 +200,7 @@ char *ArgMgr::ArgMgrUnused ( ) */ int ArgMgr::ArgMgrPrintUnusedLabels () { - char *label; + const char *label; int i=0; while ( (label=ArgMgrUnused())!=0 ) { @@ -216,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; @@ -276,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)) @@ -294,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; @@ -325,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; } @@ -404,7 +425,10 @@ char **ArgMgr::ArgMgrGetListOfString ( const char *label, int *number ) 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); @@ -434,14 +458,17 @@ int *ArgMgr::ArgMgrGetListOfInt ( const char *label, int *number ) 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 ) { @@ -476,9 +503,12 @@ float *ArgMgr::ArgMgrGetListOfFloat ( const char *label, int *number ) taille= *number; liste = (float *) calloc (1,sizeof(float)*taille ); if ( !liste ) + { + *number = 0; return 0; + } elem = liste; - *number = 1; + //*number = 1; while ( taille>0 ) { @@ -751,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++