"Fossies" - the Fresh Open Source Software Archive

Member "rename-1.3/misc.c" (6 May 2002, 2523 Bytes) of package /linux/privat/old/rename-1.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 /*
    3    misc.c -- miscellany functions
    4     
    5    Copyright (C) 1998, 1999  Xuming <xuming@bigfoot.com>
    6    
    7    This program is free software; you can redistribute it and/or 
    8    modify it under the terms of the GNU General Public License as 
    9    published by the Free Software Foundation; either version 2, or 
   10    (at your option) any later version.
   11        
   12    This program is distributed in the hope that it will be useful, 
   13    but WITHOUT ANY WARRANTY; without even the implied warranty of 
   14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15    General Public License, the file COPYING in this directory, for
   16    more details.
   17    
   18    You should have received a copy of the GNU General Public License
   19    along with this program; if not, write to the Free Software
   20    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
   21 */
   22 
   23 #ifdef HAVE_CONFIG_H
   24 #include "config.h"
   25 #endif
   26 
   27 #include <stdio.h>
   28 #include <stdlib.h>
   29 #include <string.h>
   30 #include <unistd.h>
   31 #include <ctype.h>
   32 
   33 
   34 
   35 #ifndef HAVE_STRCASECMP
   36 
   37 int strcasecmp(char *sour, char *dest)
   38 {
   39     char    a, b;
   40 
   41     while (1)  {
   42     if ((*sour < 'a') || (*sour > 'z'))  
   43         a = *sour;
   44     else  
   45         a = *sour - 'a' + 'A';
   46     
   47     if ((*dest < 'a') || (*dest > 'z'))  
   48         b = *dest;
   49     else  
   50         b = *dest - 'a' + 'A';
   51     
   52     if (a != b)  
   53         return 1;
   54     if (a == '\0')  
   55         break;
   56     sour++, dest++;
   57     }
   58     return 0;
   59 }
   60 
   61 #endif
   62 
   63 #ifndef HAVE_STRNCASECMP
   64 
   65 int strncasecmp(char *sour, char *dest, int leng)
   66 {
   67     int     i;
   68     char    a, b;
   69 
   70     for (i = 0; i < leng; i++, sour++, dest++)  {
   71         if ((*sour < 'a') || (*sour > 'z'))  
   72         a = *sour;
   73         else  
   74         a = *sour - 'a' + 'A';
   75     
   76         if ((*dest < 'a') || (*dest > 'z'))  
   77         b = *dest;
   78         else  
   79         b = *dest - 'a' + 'A';
   80     
   81         if (a != b)  
   82         return 1;
   83         if (a == '\0')  
   84         break;
   85     }
   86     return 0;
   87 }
   88 
   89 #endif
   90 
   91 
   92 #ifndef HAVE_STRCASESTR
   93 
   94 char *strcasestr(const char *haystack, const char *needle)
   95 {
   96     char  *p;
   97     int   nlen;
   98 
   99     if (!needle || !haystack)  
  100     return (char*) haystack;
  101 
  102     nlen = strlen(needle);
  103     for (p = (char*) haystack; *p; p++)  {
  104         if (!strncasecmp(p, needle, nlen))  
  105         return p;
  106     }
  107     
  108     return NULL;
  109 }
  110 
  111 #endif
  112 
  113 #ifndef HAVE_STRSTR
  114 #endif
  115 
  116 
  117 char *dup_str(char *s)
  118 {
  119     char *d, *tmp;
  120 
  121     if (!s)  
  122     return NULL;
  123 
  124     d = tmp = (char *) malloc(strlen(s) + 1);
  125     if ( d )
  126         while ((*d++ = *s++) != '\0');
  127     return tmp;
  128 }
  129 
  130 
  131 char *skip_space(char *sour)
  132 {
  133     while (*sour && isspace(*sour))  
  134     sour++;
  135     return sour;
  136 }
  137 
  138 
  139