Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:45:00 UTC

view on githubraw file Latest commit ec6cf3b0 on 2003-08-26 20:45:25 UTC
ec6cf3b09d Ed H*0001 /*
                0002  * String manipulation routines
                0003  */
                0004 /* (C) Copyright 1993,1994 by Carnegie Mellon University
                0005  * All Rights Reserved.
                0006  *
                0007  * Permission to use, copy, modify, distribute, and sell this software
                0008  * and its documentation for any purpose is hereby granted without
                0009  * fee, provided that the above copyright notice appear in all copies
                0010  * and that both that copyright notice and this permission notice
                0011  * appear in supporting documentation, and that the name of Carnegie
                0012  * Mellon University not be used in advertising or publicity
                0013  * pertaining to distribution of the software without specific,
                0014  * written prior permission.  Carnegie Mellon University makes no
                0015  * representations about the suitability of this software for any
                0016  * purpose.  It is provided "as is" without express or implied
                0017  * warranty.
                0018  *
                0019  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
                0020  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
                0021  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
                0022  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                0023  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
                0024  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                0025  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                0026  * SOFTWARE.
                0027  */
                0028 
                0029 #include <ctype.h>
                0030 
                0031 static unsigned char upcase[256] = {
                0032     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
                0033    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
                0034   ' ','!','"','#','$','%','&', 39,'(',')','*','+',',','-','.','/',
                0035   '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
                0036   '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
                0037   'P','Q','R','S','T','U','V','W','X','Y','Z','[', 92,']','^','_',
                0038   '`','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
                0039   'P','Q','R','S','T','U','V','W','X','Y','Z','{','|','}','~',127,
                0040   128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
                0041   144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
                0042   160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
                0043   176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
                0044   192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
                0045   208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
                0046   224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
                0047   240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255};
                0048 
                0049 #define UPC(x) (upcase[(unsigned char)(x)])
                0050 
                0051 /*
                0052  * Same as strcmp, but case-insensitive.
                0053  */
                0054 int
                0055 strcasecmp(register char *s1, register char *s2)
                0056 {
                0057     register char c1;
                0058     while ((c1 = *s1) && UPC(c1) == UPC(*s2)) {
                0059     s1++;
                0060     s2++;
                0061     }
                0062     return UPC(c1) - UPC(*s2);
                0063 }
                0064 
                0065 /*
                0066  * Same as strncmp, but case-insensitive.
                0067  */
                0068 int
                0069 strncasecmp(register char *s1, register char *s2, int n)
                0070 {
                0071     register char c1;
                0072     while (n-- && (c1 = *s1) && UPC(c1) == UPC(*s2)) {
                0073     s1++;
                0074     s2++;
                0075     }
                0076     if (n == -1) return 0;
                0077     return UPC(c1) - UPC(*s2);
                0078 }
                0079