⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc.c

📁 内容正如其名
💻 C
字号:
/******************************************************************************  Copyright(C) 2005,2006 Frank ZHANG  All Rights Reserved.      This program is free software; you can redistribute it and/or modify it  under the terms of the GNU General Public License as published by the Free  Software Foundation; either version 2 of the License, or (at your option)  any later version.  This program is distributed in the hope that it will be useful, but WITHOUT  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for   more details.      You should have received a copy of the GNU General Public License along with  this program; if not, write to the Free Software Foundation, Inc., 59 Temple  Place, Suite 330, Boston, MA 02111-1307 USA.  ******************************************************************************   If you want to distribute this software with modifications under any terms  other than the GPL or distribute the software linked with proprietary  applications that are not distributed in full compliance with the GNU Public  License, a Commercial License is needed.    Commercial licensing and support of this software are available at a fee. For  more information, See http://www.openmgcp.org  ******************************************************************************//*******************************************************************************      Authors                   :  Frank ZHANG*      Description               :  ***      Date of creation          :  04/15/2005***      History                   :*      2005/04/15 Frank ZHANG    : - Creation******************************************************************************/#include <stdlib.h>#include <string.h>#include "debg.h"#include "misc.h"/*************************************************************************** * Function          : Itoa * * Description       : Conver the integer value to string. *                                          * Input parameters  : val - Integer value *                      * Output parameters :  * * Return value      : String. * * Comments          :  * * History           : *  2005/04/15       : Creation * * Date              : April 15 2005, Frank ZHANG **************************************************************************/char * Itoa(int val){   char *p;   int flg = 0;   if( val < 0 )   {      flg++;      val= -val;   }   p = Ultoa((unsigned long)val);   if(flg)    *--p = '-';   return p;}/*************************************************************************** * Function          : Ultoa * * Description       : Conver the integer value to string. *                                          * Input parameters  : val - Integer value *                      * Output parameters :  * * Return value      : String. * * Comments          :  * * History           : *  2005/04/15       : Creation * * Date              : April 15 2005, Frank ZHANG **************************************************************************/static char buf[12];char* Ultoa(unsigned long val){   char *p;   p = buf + sizeof(buf);   *--p = '\0';   do   {     *--p = (char)('0' + (val%10));     val/=10;   }      while(val);   return p;}/*************************************************************************** * Function          : StrClone * * Description       : Copy src string to des string, if des string is not  *                     NULL, free it firstly. *                                          * Input parameters  : Src - source string *                     Des - pointer of destination string *                      * Output parameters : Des - destination string * * Return value      : NULL - if source is NULL *                     Destination string - if source is not NULL. * * Comments          :  * * History           : *  2005/04/15       : Creation * * Date              : April 15 2005, Frank ZHANG **************************************************************************/char* StrClone(char **Des, const char *Src){  if (*Des != NULL)  {    free(*Des);    *Des = NULL;  }  if (Src != NULL)  {    *Des = (char *)malloc(strlen(Src)+1);    Assert(*Des);    strcpy(*Des, Src);  }  return *Des;}/*************************************************************************** * Function          : StrCaseCmp * * Description       : Compare two strings without case sensitive *                                          * Input parameters  : s1 - string 1 *                     s2 - string 2 *                      * Output parameters : None * * Return value      : 0 -  Srings are same *                     Other value - Srtings are different * * Comments          :  * * History           : *  2005/04/15       : Creation * * Date              : April 15 2005, Frank ZHANG **************************************************************************/int StrCaseCmp(const char *s1,const char *s2){  unsigned int i;  unsigned int StrLen;  char Value1, Value2;  Assert(s1);  Assert(s2);  /* Check the length */  StrLen = strlen(s1);  if(StrLen != strlen(s2) )    return -1;  for(i = 0; i < StrLen; i++)   {    if((s1[i] >= 'A') && (s1[i] <= 'Z'))      Value1 = s1[i] + 'a' - 'A';  	else Value1 = s1[i];    if((s2[i] >= 'A') && (s2[i] <= 'Z'))      Value2 = s2[i] + 'a' - 'A';  	else Value2 = s2[i];    if (Value1 != Value2)      return -1;  }  return 0;}/*************************************************************************** * Function          : AllUpperCase * * Description       : Check if letters in sting are "0-9" or "A-Z" or '_' or '-' *                                          * Input parameters  : String - string *                      * Output parameters : None * * Return value      : None 0 if string is capital, otherwise 0. * * Comments          :  * * History           : *  2005/04/15       : Creation * * Date              : April 15 2005, Frank ZHANG **************************************************************************/int AllUpperCase(const char *String){  while (*String)   {    if (!(*String >= 'A' && *String <= 'Z')         && !(*String >= '0' && *String <= '9')         && *String != '_' && *String != '-')      return 0;    String++;  }    return -1;}/*************************************************************************** * Function          : Strdup * * Description       : Dup a string and return its pointer *                                          * Input parameters  : s1 - src string *                      * Output parameters : None * * Return value      : The new string pointer * * Comments          :  * * History           : *  2005/04/15       : Creation * * Date              : April 15 2005, Frank ZHANG **************************************************************************/char *Strdup(const char *s1){  size_t length;  char *newStr;  Assert(s1);    length = strlen(s1);  newStr = (char*)malloc(length+1);  if (newStr == NULL)    return NULL;  else  {    strcpy(newStr, s1);    return newStr;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -