00001 /* 00002 Copyright (C) 2000-2003, Intel Corporation 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, 00006 are permitted provided that the following conditions are met: 00007 00008 Redistributions of source code must retain the above copyright notice, this list 00009 of conditions and the following disclaimer. 00010 00011 Redistributions in binary form must reproduce the above copyright notice, this list 00012 of conditions and the following disclaimer in the documentation and/or other materials 00013 provided with the distribution. 00014 00015 Neither the name of the owner nor the names of its contributors may be used to endorse or 00016 promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR 00021 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00023 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00024 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 //-*-c++-*- 00029 //============================================================================= 00030 // 00031 // Module : ekapi_util.cxx 00032 // $Date : $ 00033 // $Author: marcel $ 00034 // $Source: /proj/osprey/CVS/open64/osprey1.0/common/ipfec_targ_info/access/ekapi_util.cxx,v $ 00035 // 00036 // Description: 00037 // ============ 00038 // hold all common functions used in access layer of IPFEC. 00039 //============================================================================= 00040 #include <string.h> 00041 #include "ekapi_util.h" 00042 00043 //trim the space from beginning and tailer. 00044 char *StrTrim(char *str) 00045 { 00046 int length; 00047 if (str != NULL) 00048 { 00049 length = strlen(str); 00050 while (str[0] == ' ') 00051 { 00052 str = str +1; 00053 length = length-1; 00054 } 00055 while (str[length-1] == ' ') 00056 { 00057 str[length-1] = '\0'; 00058 length --; 00059 } 00060 } 00061 return str; 00062 }// end of strtrim 00063 00064 // convert integer to string and add prefix '%' 00065 // limitation length 100. 00066 char *itos(int num) 00067 { 00068 char str[100],result[100]; 00069 int i,j,count = 0; 00070 if ( num == 0 ) { 00071 return strdup("%0"); 00072 } 00073 while (num != 0) 00074 { 00075 j = num % 10; 00076 num = (num - j)/10; 00077 str[count] = j + '0'; 00078 count++; 00079 if (count>=100) break; 00080 } 00081 j = 1; 00082 result[0] = '%'; 00083 for(i=count-1; i>=0; i--) 00084 { 00085 result[j] = str[i]; 00086 j++; 00087 } 00088 result[j] = '\0'; 00089 00090 return strdup(result); 00091 }// end of itos() 00092 00093 // Conver string into all upper case 00094 char *StrUpper(char *src) 00095 { 00096 char *p = src; 00097 for (;*p;p++){ 00098 if ((*p>='a')&&(*p<='z')){ 00099 *p += 'A'-'a'; 00100 } 00101 } 00102 return src; 00103 }// end of StrUpper() 00104 00105 // Conver string into all lower case 00106 char *StrLower(char *src) 00107 { 00108 char *p = src; 00109 for (;*p;p++){ 00110 if ((*p>='A')&&(*p<='Z')){ 00111 *p -= 'A'-'a'; 00112 } 00113 } 00114 return src; 00115 }// end of StrLower() 00116 00117 // Remove all blank, underscore from string 00118 char *StrClean(char *src) 00119 { 00120 char *begin = src; 00121 char *dest = src; 00122 for (;*src;src++){ 00123 if ((*src!=' ')&&(*src!='_')){ 00124 *dest = *src; 00125 dest++; 00126 } 00127 } 00128 *dest = '\0'; 00129 return begin; 00130 }// end of StrClean()
1.5.6