string.c revision 1161a5c2b6f7f91fce7d3649f06fc27a07b2714e
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include "cr_mem.h"
#include "cr_string.h"
#include "cr_error.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
{
const char *temp;
if (!str) return 0;
}
{
int len;
char *ret;
/* Allow strdup'ing of NULL strings -- this makes the __fillin functions
* much cleaner. */
return ret;
}
{
return ret;
}
{
{
{
break;
}
}
}
{
int i = 0;
{
{
break;
}
}
if (i == n) return 0;
}
static char lowercase[256] = {
'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
'\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
'\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
'\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
'\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377'
};
{
{
{
break;
}
}
}
{
;
}
{
}
else {
}
}
{
}
{
if (s)
{
}
return s;
}
{
if (s)
{
}
return s;
}
{
char first_char = *pat;
{
return (char *) str;
}
return NULL;
}
{
{
if (*str == c)
return (char *) str;
}
return NULL;
}
{
{
if (*temp == c)
return (char *) temp;
}
return NULL;
}
/* These functions are from the old wiregl net.c -- hexdumps? Not sure quite yet. */
{
int i, offset;
unsigned char *udata;
offset = 0;
{
}
else
}
{
unsigned int *udata;
/* turn byte count into word count */
ndata /= 4;
/* we need an ellipsis if all the words won't fit in the string */
if ( ellipsis )
{
/* if the ellipsis won't fit then print one less word */
ndata--;
}
offset = 0;
for ( i = 0; i < ndata; i++ )
{
}
if ( ellipsis )
else if ( offset > 0 )
}
int crStrToInt( const char *str )
{
if (!str) return 0;
}
float crStrToFloat( const char *str )
{
if (!str) return 0.0f;
}
{
int ret = 0;
{
ret++;
}
return ret;
}
/**
* Split str into a NULL-terminated array of strings, using splitstr as
* the separator.
* It's the same as the Python call string.split(str, splitstr).
* Note: crStrSplit("a b c", " ") returns ["a", "b", "", "c", NULL] though!!!
*/
{
int i;
for (i = 0 ; i < num_args ; i++)
{
char *end;
if (!end)
}
return faked_argv;
}
{
char **faked_argv;
int i;
if (num_args > n)
num_args = n;
num_args++;
for (i = 0 ; i < num_args ; i++)
{
char *end;
}
return faked_argv;
}
/* Free an array of strings, as returned by crStrSplit() and crStrSplitn(). */
void crFreeStrings( char **strings )
{
int i;
for (i = 0; strings[i]; i++) {
}
}
/* Intersect two strings on a word-by-word basis (separated by spaces).
* We typically use this to intersect OpenGL extension strings.
* Example: if s1 = "apple banana plum pear"
* and s2 = "plum banana orange"
* then return "banana plum" (or "plum banana").
*/
{
int resultLen;
char *result;
int i, j;
/* null strings, no intersection */
return NULL;
}
/* allocate storage for result (a conservative estimate) */
if (!result)
{
return NULL;
}
result[0] = 0;
/* split s1 and s2 at space chars */
for (i = 0; exten1[i]; i++)
{
for (j = 0; exten2[j]; j++)
{
{
/* found an intersection, append to result */
break;
}
}
}
/* free split strings */
crFreeStrings( exten1 );
crFreeStrings( exten2 );
/*CRASSERT(crStrlen(result) < resultLen);*/
/* all done! */
return result;
}
int crIsDigit(char c)
{
return c >= '0' && c <= '9';
}
{
int val = 0;
for(;;++ver)
{
{
if(!val)
{
if(*ver == '0')
continue;
}
else
{
val *= 10;
}
}
else if(*ver == '.')
{
break;
}
else if(*ver == '\0')
{
break;
}
{
{
if(!val)
{
continue;
}
}
/* treat this as the end of version string */
break;
}
else
{
val = -1;
break;
}
}
return val;
}
int crStrParseGlVersion(const char * ver)
{
int tmp;
if(iVer <= 0)
{
return iVer;
}
if (iVer > CR_GLVERSION_MAX_MAJOR)
{
crWarning("major version %d is bigger than the max supported %#x, this is somewhat not expected, failing", iVer, CR_GLVERSION_MAX_MAJOR);
return -1;
}
if(!ver)
{
crDebug("no minor version supplied");
goto done;
}
if (tmp < 0)
{
return -1;
}
if (tmp > CR_GLVERSION_MAX_MINOR)
{
crWarning("minor version %d is bigger than the max supported %#x, this is somewhat not expected, failing", iVer, CR_GLVERSION_MAX_MAJOR);
return -1;
}
if (!ver)
{
crDebug("no build version supplied");
goto done;
}
if (tmp < 0)
{
tmp = 0;
}
if (tmp > CR_GLVERSION_MAX_BUILD)
{
crWarning("build version %d is bigger than the max supported, using max supported val %#x", tmp, CR_GLVERSION_MAX_BUILD);
}
done:
return iVer;
}