Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

str.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: str.c,v 1.1 2005/09/09 08:22:55 bellet Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 /************************************************************************* 00037 * 00038 * Description : Divers utilitaires Chaine de caract. 00039 * 00040 **************************************************************************/ 00041 00042 #include <string.h> // For strtok, strstr, strlen 00043 #include <stdlib.h> // For strtol and strtod 00044 #include <stdio.h> // For sprintf 00045 #include <ctype.h> // For toupper 00046 00047 #include "idstr.h" 00048 #include "iderr.h" 00049 //#include "idprint.h" 00050 #include <stdio.h> 00051 #include "iddicom.h" 00052 00053 /* FUNCTION DESCRIPTION ************************************************** 00054 * 00055 * IdStrCreateNewSuffix (fonction) 00056 * 00057 * RESUME: change le suffixe d'un nom de fichier 00058 * 00059 * DESCRIPTION: Cree une chaine de caractere decrivant le nom d'un fichier 00060 * a partir d'un nom existant, en changeant le suffixe. 00061 * 00062 * SYNTAXE: char *newfilename = IdStrCreateNewSuffix (char * oldname, char * suffix); 00063 * 00064 * RETOUR: type : char * 00065 * role : pointeur vers la zone allouee contenant le nouveau 00066 * nom de fichier. 00067 * 00068 * PARAMETRES: nom : oldname 00069 * type : char * 00070 * role : Nom du fichier 'modele'. 00071 * 00072 * nom : suffix 00073 * type : char * 00074 * role : Nom du suffixe qui sera mis a la place du suffixe 00075 * precedent. 00076 * 00077 * FICHIER: idstr.c 00078 * 00079 * EXEMPLES: filename = IdStrCreateNewSuffix ("nom.txt",".lis"); 00080 * 00081 * => filename = "nom.lis" 00082 * 00083 * filename = IdStrCreateNewSuffix ("nom.txt","00.lis"); 00084 * 00085 * => filename = "nom00.lis" 00086 * 00087 * (sur vax) filename = IdStrCreateNewSuffix ("d$extern:[txt.dir]nom",".txt"); 00088 * 00089 * => filename = "d$extern:[txt.dir]nom.txt" 00090 * 00091 * (sur unix)filename = IdStrCreateNewSuffix ("/usr/test.dir/nom.o.t",".txt"); 00092 * 00093 * => filename = "/usr/test.dir/nom.o.txt" 00094 * 00095 * (sur dos) filename = IdStrCreateNewSuffix ("c:\ess.dir\nom",".text"); 00096 * 00097 * => filename = "c:\ess.dir\nom.text" 00098 * 00099 ******************************************************** END DESCRIPTION */ 00100 00109 char * IdStrCreateNewSuffix (char * nom, char * suffix ) 00110 { 00111 char * fin; 00112 char * nouveau; 00113 char * ajout; 00114 int car_copie; 00115 int taille; 00116 00117 /* fin pointe sur fin du nom **/ 00118 for ( fin = nom; *fin != '\0'; fin ++ ); 00119 /* cherche 1 '.' avant la fin */ 00120 for ( ajout = fin; (*ajout!='.'); ajout -- ) { 00121 /* Pas de '.' trouve **********/ 00122 if ( ajout <= nom ) { 00123 ajout = fin ; 00124 break; 00125 } 00126 /* carac. interdit trouve *****/ 00127 if ( 00128 00129 #if defined(_MSC_VER) 00130 (*ajout==':')||(*ajout=='\\') 00131 #else 00132 (*ajout=='/') 00133 #endif 00134 00135 ) { 00136 ajout = fin ; 00137 break; 00138 } 00139 } 00140 /* calcul taille finale *******/ 00141 taille = (int) (ajout-nom) + 2 + strlen(suffix) ; 00142 /* et reservation memoire *****/ 00143 nouveau = (char *)malloc (taille) ; 00144 /* copie du prefixe ***********/ 00145 for ( car_copie = 0; nom < ajout; car_copie ++ ) 00146 nouveau[car_copie] = *(nom++); 00147 /* et ajout du suffixe ********/ 00148 for ( ajout = suffix; car_copie < taille; car_copie++ ) 00149 nouveau[car_copie] = *(ajout++); 00150 00151 return nouveau; 00152 } 00153 00154 00155 00156 00157 /* FUNCTION DESCRIPTION ************************************************** 00158 00159 IdStrRemoveSuffix (fonction) 00160 00161 RESUME: Supprime le suffixe d'un nom de fichier 00162 00163 DESCRIPTION: Cree une chaine de caractere decrivant le nom d'un fichier 00164 a partir d'un nom existant, en suprimant le suffixe. 00165 00166 SYNTAXE: char *newfilename = IdStrRemoveSuffix (char * oldname); 00167 00168 RETOUR: type : char * 00169 role : pointeur vers la zone allouee contenant le nouveau 00170 nom de fichier. 00171 00172 PARAMETRES: nom : oldname 00173 type : char * 00174 role : Nom du fichier 'modele'. 00175 00176 FICHIER: idstr.c 00177 00178 EXEMPLES: filename = IdStrRemoveSuffix ("nom.txt"); 00179 00180 => filename = "nom" 00181 00182 filename = IdStrRemoveSuffix ("/export/home/nom/test/nom.txt"); 00183 00184 => filename = "/export/home/nom/test/nom" 00185 00186 (sur vax) filename = IdStrRemoveSuffix ("d$extern:[txt.dir]nom"); 00187 00188 => filename = "d$extern:[txt.dir]nom" 00189 00190 (sur unix)filename = IdStrRemoveSuffix ("/usr/test.dir/nom.o"); 00191 00192 => filename = "/usr/test.dir/nom" 00193 00194 (sur dos) filename = IdStrRemoveSuffix ("c:\ess.dir\nom.str"); 00195 00196 => filename = "c:\ess.dir\nom" 00197 00198 ******************************************************** END DESCRIPTION */ 00199 00207 char * 00208 IdStrRemoveSuffix ( char *nom ) 00209 { 00210 char * fin; 00211 char * nouveau; 00212 char * ajout; 00213 int car_copie; 00214 int taille; 00215 00216 /* fin pointe sur fin du nom **/ 00217 for ( fin = nom; *fin != '\0'; fin ++ ); 00218 /* cherche 1 '.' avant la fin */ 00219 for ( ajout = fin; (*ajout!='.'); ajout -- ) { 00220 /* Pas de '.' trouve **********/ 00221 if ( ajout <= nom ) { 00222 ajout = fin ; 00223 break; 00224 } 00225 /* carac. interdit trouve *****/ 00226 if ( 00227 00228 #if defined(_MSC_VER) 00229 (*ajout==':')||(*ajout=='\\') 00230 #else 00231 (*ajout=='/') 00232 #endif 00233 00234 ) { 00235 ajout = fin ; 00236 break; 00237 } 00238 } 00239 /* calcul taille finale *******/ 00240 taille = (int) (ajout-nom) + 1 ; 00241 /* et reservation memoire *****/ 00242 nouveau = (char *)malloc (taille) ; 00243 /* copie du prefixe ***********/ 00244 for ( car_copie = 0; nom < ajout; car_copie ++ ) 00245 nouveau[car_copie] = *(nom++); 00246 /* et ajout fin de chaine ********/ 00247 00248 nouveau[car_copie++] = 0; 00249 00250 return nouveau; 00251 } 00252 00253 00254 00255 00256 00257 /* FUNCTION DESCRIPTION ************************************************** 00258 00259 IdStrCreateUpperCase (fonction) 00260 00261 RESUME: Renvoie une chaine en Majuscules 00262 00263 DESCRIPTION: Renvoie une chaine en Majuscules 00264 00265 SYNTAXE: char *nouvChaine = IdStrCreateUpperCase (char *ancChaine); 00266 00267 RETOUR: 00268 type : char * 00269 role : pointeur vers la zone allouee contenant la nouvelle 00270 chaine 00271 00272 PARAMETRES: nom : ancChaine 00273 type : char * 00274 role : pointeur sur l'ancienne chaine. 00275 00276 FICHIER: idstr.c 00277 00278 EXEMPLES: 00279 ******************************************************** END DESCRIPTION */ 00280 00281 /************************************************************************** 00282 * * 00283 * Nom de la fonction : Majuscule * 00284 * Role ............. : Met une chaine de caracteres en majuscules. * 00285 * Parametres ....... : Pointeur vers la chaine. * 00286 * Valeur retournee . : pointeur vers cette meme chaine en majuscule. * 00287 * * 00288 **************************************************************************/ 00289 00297 char * 00298 IdStrCreateUpperCase (char *chaine ) 00299 { 00300 char * ptr, *ptr2, *ptr3; 00301 ptr2 =(char *)malloc(strlen(chaine)*sizeof(char)+1); 00302 ptr3=ptr2; 00303 00304 for ( ptr = chaine ; *ptr!='\0' ; ptr ++ ) 00305 { *ptr3 = toupper ( * ptr ); ptr3++; 00306 } 00307 *ptr3='\0'; 00308 00309 return ptr2; 00310 } 00311 00312 00313 /* FUNCTION DESCRIPTION ************************************************** 00314 00315 IdStrSetUpperCase (fonction) 00316 00317 RESUME: Transforme sur place une chaine en Majuscules 00318 00319 DESCRIPTION: Transforme sur place une chaine en Majuscules 00320 00321 SYNTAXE: char *chaine = IdStrSetUpperCase (char *chaine); 00322 00323 RETOUR: type : char * 00324 role : pointeur vers la zone contenant la chaine 00325 00326 PARAMETRES: nom : chaine 00327 type : char * 00328 role : pointeur sur la chaine. 00329 00330 FICHIER: idstr.c 00331 00332 EXEMPLES: 00333 00334 ******************************************************** END DESCRIPTION */ 00335 00336 00344 char * IdStrSetUpperCase (char *chaine ) 00345 { 00346 char *ptr; 00347 for ( ptr = chaine ; *ptr!='\0' ; *ptr = toupper (*ptr), ptr++ ) ; 00348 return chaine; 00349 } 00350 00351 /* FUNCTION DESCRIPTION ************************************************** 00352 00353 IdStrCountChar (fonction) 00354 00355 RESUME: Compte le nb d'occurrences d'1 caract ds une chaine 00356 00357 DESCRIPTION:Compte le nb d'occurrences d'1 caract ds une chaine 00358 00359 SYNTAXE: int nbOccCaract = IdStrCountChar (char *chaine, char caract); 00360 00361 RETOUR: type : int 00362 role : nb d'occurrences du caract ds la chaine 00363 00364 PARAMETRES: nom : chaine 00365 type : char * 00366 role : pointeur sur la chaine. 00367 00368 nom : caract 00369 type : char 00370 role : caract compte 00371 00372 FICHIER: idstr.c 00373 00374 EXEMPLES: 00375 00376 ******************************************************** END DESCRIPTION */ 00385 int 00386 IdStrCountChar (char *chaine, int caract) 00387 { 00388 int i=0; 00389 char * ptr; 00390 00391 for ( ptr = chaine ; *ptr!='\0' ; ptr ++ ) 00392 { if (*ptr==caract) i++; 00393 } 00394 00395 return i; 00396 } 00397 00398 /* FUNCTION DESCRIPTION ************************************************** 00399 00400 IdStrDirName (fonction) 00401 00402 RESUME: Extrait le DirectoryName d'un FullPathName 00403 00404 DESCRIPTION: cree une chaine de caractere donnant le chemin fourni 00405 sans non de fichier 00406 00407 SYNTAXE: char *dirOnly = IdStrDirName (char * path); 00408 00409 RETOUR: type : char * 00410 role : pointeur vers la zone allouee contenant le 00411 DirectoryName 00412 00413 PARAMETRES: nom : path 00414 type : char * 00415 role : chemin fourni 00416 00417 FICHIER: idstr.c 00418 00419 EXEMPLE: nom_fichier = IdStrDirName("/rep1/rep2/toto.truc"); 00420 renvoie "/rep1/rep2/" 00421 00422 ******************************************************** END DESCRIPTION */ 00423 00431 char * 00432 IdStrDirName (char * nom ) 00433 { 00434 00435 char *fin, *pnomfic, *nouveau, *debnouveau; 00436 int taille; 00437 /* fin pointe sur fin du nom */ 00438 for ( fin = nom; *fin != '\0'; fin ++ ); 00439 /* cherche '/' ou '\' avant la fin */ 00440 for ( pnomfic = fin; 00441 #if defined(_MSC_VER) 00442 *pnomfic != '\\'; 00443 #else 00444 *pnomfic != '/'; 00445 #endif 00446 pnomfic -- ) 00447 { 00448 /* pas de '\' ou '/' trouve */ 00449 if ( pnomfic == nom ) break; 00450 } 00451 00452 if (pnomfic != nom) /* si rep present */ 00453 { 00454 /* calcul taille finale */ 00455 taille = (int) (pnomfic - nom) + 2; 00456 /* et reservation memoire */ 00457 nouveau = debnouveau = (char *) malloc (taille); 00458 /* copie du path */ 00459 for ( ; nom <= pnomfic; *(nouveau++) = *(nom++) ); 00460 } 00461 else nouveau = debnouveau = (char *) malloc (1); 00462 /* ajoute fin */ 00463 *nouveau = '\0'; 00464 00465 return debnouveau; 00466 } 00467 00468 /* FUNCTION DESCRIPTION ************************************************** 00469 00470 IdStrFileName (fonction) 00471 00472 RESUME: Extrait le FileName d'un FullPathName 00473 00474 DESCRIPTION: cree une chaine de caractere donnant le dernier nom trouve dans 00475 le chemin d'acces fourni 00476 00477 SYNTAXE: char *lastName = IdStrFileName (char * path); 00478 00479 RETOUR: type : char * 00480 role : pointeur vers la zone allouee contenant le 00481 nom de fichier. 00482 00483 PARAMETRES: nom : path 00484 type : char * 00485 role : chemin fourni 00486 00487 FICHIER: idstr.c 00488 00489 EXEMPLE: nom_fichier = IdStrFileName("/rep1/rep2/toto.truc"); 00490 00491 ******************************************************** END DESCRIPTION */ 00492 00500 char * 00501 IdStrFileName (char * nom ) 00502 { 00503 char *fin, *pnomfic, *nouveau, *debnouveau; 00504 int taille; 00505 /* fin pointe sur fin du nom */ 00506 for ( fin = nom; *fin != '\0'; fin ++ ); 00507 /* cherche '/' ou '\' avant la fin */ 00508 for ( pnomfic = fin; 00509 00510 #if defined(_MSC_VER) 00511 *pnomfic != '\\'; 00512 #else 00513 *pnomfic != '/'; 00514 #endif 00515 pnomfic -- ) 00516 { 00517 /* pas de '\' ou '/' trouve */ 00518 if ( pnomfic == nom ) 00519 { 00520 pnomfic --; 00521 break; 00522 } 00523 } 00524 /* calcul taille finale */ 00525 taille = (int) (fin - (++ pnomfic)) + 1; 00526 /* et reservation memoire */ 00527 nouveau = debnouveau = (char *) malloc (taille); 00528 /* copie du nom */ 00529 for ( ; pnomfic <= fin; ) *(nouveau++) = *(pnomfic++); 00530 00531 return debnouveau; 00532 } 00533 00534 00535 /* FUNCTION DESCRIPTION ************************************************** 00536 00537 IdStrMakeFullPathName (fonction) 00538 00539 RESUME: Fabrique le FullPathName d'un Fichier 00540 00541 DESCRIPTION: cree une chaine de caractere donnant le nom hierachique complet 00542 00543 SYNTAXE: char *FullPathName = IdStrFileName (char * dirName, char * fileName); 00544 00545 RETOUR: type : char * 00546 role : pointeur vers la zone allouee contenant le 00547 nom de fichier. 00548 00549 PARAMETRES: nom : dirName 00550 type : char * 00551 role : nom Dir 00552 00553 nom : fileName 00554 type : char * 00555 role : nom Fich 00556 FICHIER: idstr.c 00557 00558 EXEMPLE: nom_fichier = IdStrMakeFullPathName("/rep1/rep2/toto","truc"); 00559 00560 ******************************************************** END DESCRIPTION */ 00561 00570 char * 00571 IdStrMakeFullPathName (char * dirName,char * fileName ) 00572 { 00573 char *FullPathName; 00574 int taille; 00575 00576 00577 if(dirName) { 00578 taille=strlen(dirName)+strlen(fileName)+1; 00579 } else { 00580 taille=strlen(fileName)+1; 00581 } 00582 FullPathName=(char *) malloc(taille+1); 00583 if (!FullPathName) { 00584 printf("IdStrMakeFullPathName : impossible allouer FullPathName\n"); 00585 return (NULL); 00586 } 00587 00588 if (strlen(dirName)!=0) { 00589 #if defined(_MSC_VER) 00590 sprintf(FullPathName,"%s\\%s",dirName,fileName); 00591 #else 00592 sprintf(FullPathName,"%s/%s",dirName,fileName); 00593 #endif 00594 } else { 00595 sprintf(FullPathName,"%s",fileName); 00596 } 00597 00598 return FullPathName; 00599 } 00600 00601 00602 /* FUNCTION DESCRIPTION ************************************************** 00603 00604 IdStrIntEnum (fonction) 00605 00606 RESUME: renvoie 1 tableau contenant une liste d'intervalles entiers 00607 00608 DESCRIPTION:renvoie 1 tableau contenant une liste d'intervalles entiers 00609 00610 SYNTAXE: int [] TabInterv= IdStrIntEnum (char * chaine, int * nbInterv); 00611 00612 RETOUR: type : int * 00613 role : pointeur vers la zone allouee contenant les 00614 intervalles (deb1,fin1, deb2,fin2, ...) 00615 00616 PARAMETRES: nom : path 00617 type : char * 00618 role : chaine caract a decoder 00619 00620 nom : nbInterv 00621 type : int * 00622 role : nb d'interv trouves 00623 00624 FICHIER: idstr.c 00625 00626 EXEMPLE: 00627 00628 ******************************************************** END DESCRIPTION */ 00629 00630 00641 int * 00642 IdStrIntEnum ( char*value, int *number) 00643 00644 { 00645 int* liste; 00646 int taille; 00647 int i; 00648 00649 *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Virgules +1 */ 00650 taille= *number; 00651 /* printf ("taille %d\n",taille); */ 00652 liste = (int *) calloc (2*taille , sizeof(int)); 00653 if ( !liste ) { 00654 IdErrno = IDERR_ALLOC_MEM; 00655 return 0; 00656 } 00657 00658 i=0; 00659 00660 while ( taille>0 ) { 00661 liste[i] = (int) strtol ( value, &value, 10 ); 00662 00663 if ( *value == '\0' ) 00664 { 00665 liste[i+1]=liste[i]; 00666 return liste; 00667 } 00668 00669 if ( *(value++) != '-' ) { 00670 liste[i+1]=liste[i]; 00671 value--; 00672 } 00673 else { 00674 liste[i+1] = (int) strtol ( value, &value, 10 ); 00675 } 00676 if ( *value == '\0' ) return liste; 00677 00678 if ( *(value++) != ',' ) { 00679 free (liste); 00680 IdErrno = IDERR_NOT_INTLIST; 00681 return 0; 00682 } 00683 taille --; i+=2; 00684 } 00685 return liste; 00686 00687 } 00688 00689 00690 /* FUNCTION DESCRIPTION ************************************************** 00691 00692 IdStrFloatEnum (fonction) 00693 00694 RESUME: renvoie 1 tableau contenant une liste d'intervalles FLOAT 00695 00696 DESCRIPTION:renvoie 1 tableau contenant une liste d'intervalles entiers 00697 00698 SYNTAXE: float [] TabInterv= IdStrFloatEnum (char * chaine, int * nbInterv); 00699 00700 RETOUR: type : char * 00701 role : pointeur vers la zone allouee contenant le 00702 nom de fichier. 00703 00704 PARAMETRES: nom : path 00705 type : char * 00706 role : chaine caract a decoder 00707 00708 nom : nbInterv 00709 type : int * 00710 role : nb d'interv trouves 00711 00712 FICHIER: idstr.c 00713 00714 EXEMPLE: 00715 00716 ******************************************************** END DESCRIPTION */ 00727 float * 00728 IdStrFloatEnum (char* value, int * number) 00729 { 00730 float* liste; 00731 int taille; 00732 int i; 00733 00734 *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Virgules +1 */ 00735 taille= *number; 00736 /* printf ("taille %d\n",taille); */ 00737 liste = (float *) calloc (2*taille , sizeof(float)); 00738 if ( !liste ) { 00739 IdErrno = IDERR_ALLOC_MEM; 00740 return 0; 00741 } 00742 00743 i=0; 00744 00745 while ( taille>0 ) { 00746 liste[i] = (float) strtod ( value, &value ); 00747 00748 if ( *value == '\0' ) 00749 { 00750 liste[i+1]=liste[i]; 00751 return liste; 00752 } 00753 00754 if ( *(value++) != '-' ) { 00755 liste[i+1]=liste[i]; 00756 value--; 00757 } 00758 else { 00759 liste[i+1] = (float) strtod ( value, &value ); 00760 } 00761 if ( *value == '\0' ) return liste; 00762 00763 if ( *(value++) != ',' ) { 00764 free (liste); 00765 IdErrno = IDERR_NOT_INTLIST; 00766 return 0; 00767 } 00768 taille --; i+=2; 00769 } 00770 return liste; 00771 00772 } 00773 00774 /* FUNCTION DESCRIPTION ************************************************** 00775 00776 IdStrSwap (fonction) 00777 00778 RESUME: renvoie l'entier correspondant au Swap des pixels 00779 00780 DESCRIPTION: renvoie l'entier correspondant au Swap des pixels 00781 00782 SYNTAXE: int typeSwap= IdStrSwap (char * chaine); 00783 00784 RETOUR: type : int 00785 role : entier correspondant au Swap des pixels. 00786 "O" -> 2143 SHORT, USHORT 00787 "o" -> 2143 00788 "N" -> 1234 00789 "n" -> 1234 00790 00791 "1234" -> 1234 LONG, ULONG 00792 "2143" -> 2143 00793 "3412" -> 3412 00794 "4321" -> 4321 00795 00796 PARAMETRES: nom : chaine 00797 type : char * 00798 role : chaine caract a decoder 00799 00800 FICHIER: idstr.c 00801 00802 EXEMPLE: 00803 00804 ******************************************************** END DESCRIPTION */ 00812 int IdStrSwap (char *chaine) 00813 { 00814 if (IdStrCmpNoCase(chaine,"O")==0) return 2143; 00815 if (IdStrCmpNoCase(chaine,"Y")==0) return 2143; 00816 if (IdStrCmpNoCase(chaine,"N")==0) return 1234; 00817 if (IdStrCmpNoCase(chaine,"1234")==0) return 1234; 00818 if (IdStrCmpNoCase(chaine,"ABCD")==0) return 1234; 00819 if (IdStrCmpNoCase(chaine,"2143")==0) return 2143; 00820 if (IdStrCmpNoCase(chaine,"BADC")==0) return 2143; 00821 if (IdStrCmpNoCase(chaine,"3412")==0) return 3412; 00822 if (IdStrCmpNoCase(chaine,"CDAB")==0) return 3412; 00823 if (IdStrCmpNoCase(chaine,"4321")==0) return 4321; 00824 if (IdStrCmpNoCase(chaine,"DCBA")==0) return 4321; 00825 00826 return 0; 00827 } 00828 00829 00830 /* FUNCTION DESCRIPTION ************************************************** 00831 * 00832 * IdStrSort (fonction) 00833 * 00834 * RESUME: Tri d'un tableau de pointeurs sur N'IMPORTE QUOI, sur N'IMPORTE QUEL critere 00835 * 00836 * DESCRIPTION: Tri d'un tableau de pointeurs sur N'IMPORTE QUOI, 00837 * sur N'IMPORTE QUEL critere. 00838 * (Methode de Shell-Metzner) 00839 * La fonction de comparaison de deux objets 00840 * est a la charge de l'utilisateur. 00841 * (lui seul connait leur structure, et le critere de tri) 00842 * 00843 * SYNTAXE: IdStrSort ( void *tab, int (*foncComparObj)(void * ptrObj1, void * ptrObj2); 00844 * 00845 * 00846 * RETOUR: type : aucun 00847 * 00848 * PARAMETRES: nom : tab 00849 * type : void * 00850 * role : tableau de pointeurs sur N'IMPORTE QUOI 00851 * 00852 * nom : n 00853 * type : int 00854 * role : nb d'elements du tableau 00855 * 00856 * nom : foncComparObj 00857 * type : pointeur sur fonction 00858 * role : Fonction de comparaison de deux Objets 00859 * retourne -1 si 1 er < 2 eme 00860 * 0 si 1 er = 2 eme 00861 * +1 si 1 er > 2 eme 00862 * -2 si les deux Objets 00863 * NE SONT PAS comparables 00864 * 00865 * FICHIER: idstr.c 00866 * 00867 * EXEMPLE: Soit le tableau T1, de pointeurs vers des 'Objets' 00868 * qui sont des tableaux de chaines de caracteres 00869 * le critere de tri est la chaine num 16 du tableau ... 00870 * 00871 * on triera comme suit: 00872 * 00873 * int comp (void *, void *); 00874 * IdStrSort(T1, comp); 00875 * 00876 * avec : 00877 * 00878 * int comp (a, b) 00879 * void *a, *b; 00880 * { 00881 * int i; 00882 * i=strcmp( ((char **)a)[16],((char **)b)[16]); 00883 * if (i<0) i=-1; 00884 * else if (i>0) i= 1; 00885 * return i; 00886 * } 00887 * 00888 * 00889 ******************************************************** END DESCRIPTION */ 00890 00900 int * IdStrSort (void **tab, int n, 00901 INT_FUNCTION_VOIDP_VOIDP_POINTER foncComparObj) 00902 { 00903 int i,j,m; 00904 void *b; 00905 int *tabInd =(int *) malloc(n*sizeof(int)); 00906 if (!tabInd) 00907 return NULL; 00908 for(i=0;i<n;i++) 00909 tabInd[i]=i; 00910 00911 // Shell-Metzner' Method 00912 00913 m=1; 00914 do { 00915 m = 3*m+1; 00916 } while(m <= n); 00917 do { 00918 m = m/3; 00919 for (i=m; i<n; i++) { 00920 j = i-m; 00921 b = tab[i]; 00922 while( foncComparObj(tab[tabInd[j]],b)==1) { 00923 tab[tabInd[j+m]] = tab[tabInd[j]]; 00924 j = j-m; 00925 if (j<0) break; 00926 } 00927 tab[j+m] = b; 00928 } 00929 }while (m>1); 00930 00931 return (tabInd); 00932 00933 } 00934 00935 /* FUNCTION DESCRIPTION ************************************************** 00936 00937 IdStrPatternMatching (fonction) 00938 00939 RESUME: Teste la concordance d'une chaine de caract a un masque 00940 00941 DESCRIPTION: Teste la concordance d'une chaine de caract a un masque 00942 (caractere JOKER : * ) 00943 00944 SYNTAXE: int retCode= IdStrPatternMatching (char * chaine, char *masque); 00945 00946 RETOUR: type : int 00947 role : pointeur vers la zone allouee contenant le 00948 nom de fichier. 00949 00950 PARAMETRES: nom : chaine 00951 type : char * 00952 role : chaine caract a decoder 00953 00954 nom : masque 00955 type : char * 00956 role : masque de concordance 00957 00958 FICHIER: idstr.c 00959 00960 EXEMPLE: bool = IdStrPatternMatching (fileName, *.ima); 00961 00962 ******************************************************** END DESCRIPTION */ 00963 int 00964 IdStrPatternMatching (char * chaine, char * masque ) 00965 { 00966 int taille, nbElem, i; 00967 char ** liste; 00968 char ** elem; 00969 char * chainecur; 00970 char * ptrDeb; 00971 00972 if (!masque) { 00973 IdErrno = IDERR_LABEL_UNDEF; 00974 return 0; 00975 } 00976 00977 nbElem = IdStrCountChar(masque,'*'); 00978 00979 if (masque[0] == '*') nbElem--; 00980 if (masque[strlen(masque)-1] != '*') nbElem++; 00981 00982 taille = nbElem; 00983 00984 liste = (char **) malloc (sizeof(char*) * taille + strlen(masque)+1); 00985 if ( !liste ) { 00986 IdErrno = IDERR_ALLOC_MEM; 00987 return 0; 00988 } 00989 00990 masque = strcpy( ((char*)liste)+sizeof(char*) * taille, masque ); 00991 00992 for ( elem = liste, chainecur = strtok(masque,"*"); 00993 taille>0; 00994 taille--, chainecur = (chainecur) ? strtok ( 0, "*" ) : 0 ) 00995 { 00996 *(elem++) = chainecur; 00997 } 00998 00999 /*printf ("fin Rech :nbElem %d \n",nbElem); */ 01000 /*for(i=0;i<nbElem;i++) printf (">%s<\n",liste[i]); */ 01001 01002 ptrDeb=chaine; 01003 for(i=0;i<nbElem;i++) 01004 { 01005 ptrDeb=strstr(ptrDeb,liste[i]); 01006 if (!ptrDeb) return(0); 01007 ptrDeb=ptrDeb + strlen(liste[i]) - 1; 01008 } 01009 01010 /* 01011 printf ("ptrDeb %x chaine %x strlen(chaine) %d \n", ptrDeb,chaine,strlen(chaine)); 01012 */ 01013 01014 if(ptrDeb != chaine+strlen(chaine)-1 ) return 0; 01015 01016 return 1; 01017 } 01018 01019 01029 char * IdStrCleanName (char * nom) 01030 { 01031 char *ptr, *ptr2, *ptrSecu; 01032 int indJpr; 01033 01034 ptr=nom; 01035 ptr2=ptrSecu=(char *) malloc(strlen(nom)+1); 01036 indJpr=0; 01037 while(*ptr != 0) 01038 { 01039 if (0) 01040 { 01041 indJpr ++; 01042 printf ("%d : %c %x\n",indJpr,*ptr,*ptr); 01043 } 01044 if(*ptr != ' ') 01045 { 01046 if( (*ptr == '/') || (*ptr == '\\') || (*ptr == '\'') || (*ptr == 0x5e)) 01047 { 01048 *ptr2++ = '_'; 01049 *ptr++; 01050 } 01051 else 01052 *ptr2++ = *ptr++; 01053 } 01054 else 01055 ptr++; 01056 } 01057 *ptr2++=0; 01058 01059 return(ptrSecu); 01060 } 01061 01070 char * _IdStrShowTransfertSyntax (char * codeTransfSynt) { 01071 int i; 01072 int nbTransfSynt=23; // voir dicom.c, Sorry 01073 for(i=0; i<nbTransfSynt; i++) { 01074 if( strcmp(codeTransfSynt, _ID_transfert_syntax[i].transf_synt_code) == 0 ) 01075 return(_ID_transfert_syntax[i].transf_synt_libelle); 01076 } 01077 01078 printf("code Transfert Syntax inconnu : [%s]\n",codeTransfSynt); 01079 01080 return("code Transfert Syntax inconnu"); 01081 }

Generated on Wed Oct 19 09:28:34 2005 for SIMRI3D by doxygen 1.3.7