Beispiel #1
0
static int
CaselessCmp(const char *a, const char *b)
{				/* strcasecmp isn't portable */
    while (*a && *b) {
	int cmp = LOWERCASE(*a) - LOWERCASE(*b);
	if (cmp != 0)
	    break;
	a++, b++;
    }
    return LOWERCASE(*a) - LOWERCASE(*b);
}
Beispiel #2
0
int stricmp (const char *x, const char *y)
{
	char c1, c2;
	while ((*x != '\0') && (*y != '\0')) {
		c1 = *x++;
		c2 = *y++;
		if (LOWERCASE (c1) != LOWERCASE (c2))
			return 1;
	}
	return *x == *y ? 0 : 1;
}
Beispiel #3
0
void ToLowerCaseBuilder::BuildStringUT(WEBC_CHAR *pStringBuffer)
{
int n;
	
	for (n=0; n<GetStringLength(); n++)
	{
		pStringBuffer[n] = LOWERCASE(mpStr[n]);
	}
}
Beispiel #4
0
/*
 * Displays a yes/no question and waits for an answer. Result
 * is returned in res. 1 if yesChar was selected, 0 otherwise.
 * Function return 0 normally or 1 if carrier is dropped.
 */
int GetYesOrNo(char *preStr, char *label,
               char *yesChar, char *noChar, char *yesStr, char *noStr,
               char *postStr, int yesIsDefault, int *res) {
    int ch;
    char *response, yes, no;

    yes = yesChar != NULL ? *yesChar : *yesStr;
    no = noChar != NULL ? *noChar : *noStr;

    radcnt = 0;
    SendString("%s%s", preStr != NULL ? preStr : "", label != NULL ? label : "");
    SendString(" (%c/%c) ",
               yesIsDefault ? UPPERCASE(yes) : LOWERCASE(yes),
               yesIsDefault ? LOWERCASE(no) : UPPERCASE(no));
    for(;;) {
        ch = GetChar();
        if(ch == GETCHAR_LOGOUT) {
            return 1;
        }
        if(ch == GETCHAR_RETURN) {
            *res = yesIsDefault ? 1 : 0;
        } else if(LOWERCASE(ch) == LOWERCASE(yes)) {
            *res = 1;
        } else if(LOWERCASE(ch) == LOWERCASE(no)) {
            *res = 0;
        } else {
            continue;
        }
        response = *res ? yesStr : noStr;
        if(response != NULL)  {
            SendString("%s%s", response, postStr != NULL ? postStr : "");
        }
        return 0;
    }
}
void LowerCaseUniASCIIString (UniChar* const toLowerCase)
{
    UniChar* psz1 = toLowerCase;

    if (NULL == psz1)
        return;

    while (*psz1)
	{
		LOWERCASE (*psz1);
		psz1++;        
    }    
}
inline bool _EqualASCIICString (const T1 *const inCString1, const sLONG inString1Len, const T2 *const inCString2, const sLONG inString2Len, bool isCaseSensitive)
{
	if (!inCString1 || !inCString2 || (inString1Len != inString2Len))
		return false;
	else if (!(*inCString1) && !(*inCString2) && (inString1Len == 0))
		return true;
	
	bool result = false;
	const T1 *p1 = inCString1;
	const T2 *p2 = inCString2;
	
	while (*p1)
	{
		if ((NULL != p1) && (NULL != p2))
		{
			T1 c1 = *p1;
			T2 c2 = *p2;
			
			if (!isCaseSensitive)
			{
				LOWERCASE (c1);
				LOWERCASE (c2);
			}
			
			if (c1 == c2)
				result = true;
			else
				return false;
			p1++;
			p2++;
		}
		else
		{
			return false;
		}
	}
	
	return result;
}
Beispiel #7
0
static void
shader_parsetok(shader_t *shader, shaderpass_t *pass, shaderkey_t *keys,
		char *tok)
{
    shaderkey_t *key;
    char *c, *args[SHADER_ARGS_MAX];
    int numargs;

    /* Lowercase the token */
    c = tok;
    while (*c++) *c =  LOWERCASE(*c);
    
    /* FIXME: This should be done with a hash table! */

    for (key = keys; key->keyword != NULL; key++)
    {
	if (strcmp(tok, key->keyword) == 0)
	{
	    for (numargs=0; (c = nextarg()) != NULL; numargs++)
	    {
		/* Lowercase the argument */
		args[numargs] = c;
		while (*c) {*c = LOWERCASE(*c); c++;}
	    }
	    if (numargs < key->minargs || numargs > key->maxargs)
		Syntax();
	    
	    if (key->func)
		key->func(shader, pass, numargs, args);
	    return;
	}
    }

    /* Unidentified keyword: no error for now, just advance to end of line */
    while (*curpos != '\n')
	if (++curpos == endpos) break;    
}
Beispiel #8
0
_nc_rootname(char *path)
{
    char *result = _nc_basename(path);
#if !MIXEDCASE_FILENAMES || defined(PROG_EXT)
    static char *temp;
    char *s;

    temp = strdup(result);
    result = temp;
#if !MIXEDCASE_FILENAMES
    for (s = result; *s != '\0'; ++s) {
	*s = LOWERCASE(*s);
    }
#endif
#if defined(PROG_EXT)
    if ((s = strrchr(result, '.')) != 0) {
	if (!strcmp(s, PROG_EXT))
	    *s = '\0';
    }
#endif
#endif
    return result;
}
Beispiel #9
0
/*
*  Exact Keyword Match - unique keys, with just one piece of
*  'userdata' , for multiple entries, we could use a list
*  of 'userdata' nodes.
*/
void *  KMapFind( KMAP * ks, void * key, int n )
{
    unsigned char * T = (unsigned char *)key;
    KMAPNODE      * root;
    unsigned char   xkey[256];
    int             i;

    if( n <= 0 )
    {
        n = strlen( (char*)key );
        if( n > (int)sizeof(xkey) )
            return 0;

    }
    if( ks->nocase )
    {
        for(i=0;i<n;i++)
            xkey[i] = LOWERCASE( T[i] );

        T = xkey;
    }
    //printf("finding key='%.*s'\n",n,T);

    /* Check if any keywords start with this character */
    root = ks->root[ *T ];
    if( !root ) return NULL;

    while( n )
    {
        if( root->nodechar == *T )
        {
            T++;
            n--;
            if( n && root->child )
            {
                root = root->child;
            }
            else /* cannot continue -- match is over */
            {
                break;
            }
        }
        else
        {
            if( root->sibling )
            {
                root = root->sibling;
            }
            else /* cannot continue */
            {
                break;
            }
        }
    }

    if( !n )
    {
        if (root && root->knode)
            return root->knode->userdata; /* success */
    }

    return NULL;
}
Beispiel #10
0
/*
*    key : ptr to bytes of data used to identify this item
*          may be text string, or binary character sequence.
*    n   : > 0 number of bytes in the key
*          <=0 key is a null terminated  ascii string
*    userdata - ptr to data to associate with this key
*
*   returns:
*            -1 - no memory
*             1 - key already in table
*             0 - key added successfully
*/
int KMapAdd( KMAP *km, void * key, int n, void * userdata )
{
    int            i,ksize;
    int            type = 0;
    unsigned char *P = (unsigned char *)key;
    KMAPNODE      *root;
    unsigned char  xkey[256];

    if( n <= 0 )
    {
        n = strlen( (char*) key );
        if( n > (int)sizeof(xkey) )
            return -99;
    }

    if( km->nocase )
    {
        for(i=0;i<n;i++)
            xkey[i] = LOWERCASE( P[i] );
        P = xkey;
    }

    /* Save key size */
    ksize = n;

    //printf("adding key='%.*s'\n",n,P);

    /* Make sure we at least have a root character for the tree */
    if( !km->root[ *P ] )
    {
        root = KMapCreateNode(km);
        if( !root )
            return -1;
        km->root[ *P ] = root;
        root->nodechar = *P;

    }else{

        root = km->root[ *P ];
    }

    /* Walk exisitng Patterns */
    while( n )
    {
        if( root->nodechar == *P )
        {
            //printf("matched char = %c, nleft = %d\n",*P,n-1);
            P++;
            n--;
            if( n && root->child )
            {
                root=root->child;
            }
            else /* cannot continue */
            {
                type = 0; /* Expand the tree via the child */
                break;
            }
        }
        else
        {
            if( root->sibling )
            {
                root=root->sibling;
            }
            else /* cannot continue */
            {
                type = 1; /* Expand the tree via the sibling */
                break;
            }
        }
    }


    /*
    * Add the next char of the Keyword, if any
    */
    if( n )
    {
        if( type == 0 )
        {
        /*
        *  Start with a new child to finish this Keyword
            */
            //printf("added child branch nodechar = %c \n",*P);
            root->child= KMapCreateNode( km );
            if( !root->child )
                return -1;
            root=root->child;
            root->nodechar  = *P;
            P++;
            n--;
        }
        else
        {
        /*
        *  Start a new sibling bracnch to finish this Keyword
            */
            //printf("added sibling branch nodechar = %c \n",*P);
            root->sibling= KMapCreateNode( km );
            if( !root->sibling )
                return -1;
            root=root->sibling;
            root->nodechar  = *P;
            P++;
            n--;
        }
    }

    /*
    *    Finish the keyword as child nodes
    */
    while( n )
    {
        //printf("added child nodechar = %c \n",*P);
        root->child = KMapCreateNode(km);
        if( !root->child )
            return -1;
        root=root->child;
        root->nodechar  = *P;
        P++;
        n--;
    }

    /*
    * Iteration support - Add this key/data to the linked list
    * This allows us to do a findfirst/findnext search of
    * all map nodes.
    */
    if( root->knode ) /* Already present */
        return 1;

    root->knode = KMapAddKeyNode( km, key, ksize, userdata );
    if( !root->knode )
        return -1;

    return 0;
}
inline sLONG _FindASCIICString (const T1 *inText, const sLONG inTextLen, const T2 *inPattern, const sLONG inPatternLen, bool isCaseSensitive)
{
	// see http://fr.wikipedia.org/wiki/Algorithme_de_Knuth-Morris-Pratt

	if (inPatternLen > inTextLen)
		return 0;

	sLONG	textSize = inTextLen;
	sLONG	patternSize = inPatternLen;
	sLONG *	target = (sLONG *)malloc (sizeof(sLONG) * (patternSize + 1));

	if (NULL != target)
	{
		sLONG	m = 0;
		sLONG	i = 0;
		sLONG	j = -1;
		T2		c = '\0';

		target[0] = j;
		while (i != patternSize)
		{
			T2 pchar = inPattern[i];

			if (!isCaseSensitive)
				LOWERCASE (pchar);

			if (pchar == c)
			{
				target[i + 1] = j + 1;
				++j;
				++i;
			}
			else if (j > 0)
			{
				j = target[j];
			}
			else
			{
				target[i + 1] = 0;
				++i;
				j = 0;
			}

			pchar = inPattern[j];
			if (!isCaseSensitive)
				LOWERCASE (pchar);

			c = pchar;
		}

		m = 0;
		i = 0;
		while ((m + i != textSize) && (i != patternSize))
		{
			T1		tchar = inText[m + i];
			T2		pchar = inPattern[i];

			if (!isCaseSensitive)
			{
				LOWERCASE (tchar);
				LOWERCASE (pchar);
			}

			if (tchar == (T1)pchar)
			{
				++i;
			}
			else
			{
				m += i - target[i];
				if (i > 0)
					i = target[i];
			}
		}

		free (target);

		if (i >= patternSize)
			return m + 1; // 1-based position !!! Just to work as VString.Find()
	}

	return 0;
}
Beispiel #12
0
/**
 * Normalize an URL. The URL will be cleaned with url_RemoveTabCRLF(), then its 
 * fragment will be removed with url_RemoveFragment(). The URL will be unescaped
 * with url_Unescape() before being normalizes. Return a normalized URL in a 
 * newly allocated block of memory or NULL if error. WARNING : current limitation is 
 * that we don't do any normalization if the hostname is replaced by an IP address.
 * @param  src     Pointer to string holding the URL to be normalized.
 * @param  len     Length of source string. If 0, strlen() will be called.
 * @param  new_len If not NULL, pointer to a long where the length of the new string will be stored.
 * @return         Pointer to a newly allocated string. Must freed using free(). Or
 *                 NULL of error.
 */
extern char *url_Normalize(const char *src, const long len, long *new_len)
{
	long tmp;

	if(new_len == NULL)
		new_len = &tmp;

	// printf("url_Normalize() [%s]\n", src);

	char *str1 = url_RemoveTabCRLF(src, len, new_len);
	// printf("%-16s = [%s]\n", "CLEANED", str1);
	// printf("new_len = %ld\n", *new_len);
	url_RemoveFragment(str1, new_len);
	// printf("%-16s = [%s]\n", "FRAGMENT REMOVED", str1);
	// printf("new_len = %ld\n", *new_len);	
	char *str2 = url_Unescape(str1, *new_len, new_len);
	// printf("%-16s = [%s]\n", "UNESCAPED", str2);
	// printf("new_len = %ld\n", *new_len);		

	// Save begining of source string
	char *begin_source = str2;

	// Destination string cannot be longer that the initial string + "http://" + trailing '/'
	char *dest = malloc(*new_len+1+8);
	if(dest==NULL)
		return(NULL);

	// Save the beginning of the destination string
	char *begin_dest = dest;

	// Copy the scheme part
	for( ; *str2 && *str2!=':'; dest++, str2++)
		*dest = LOWERCASE(*str2);

	if(*str2=='\0') {
		// There is no scheme part, use "http" as default
		str2 = begin_source;
		dest = begin_dest;
		strcpy(dest, "http://");
		dest +=7;	
	} else if( *(str2)==':' && *(str2+1)=='/' && *(str2+2)=='/') {
		// Copy the "://" part
		*(dest++) = *(str2++); *(dest++) = *(str2++); *(dest++) = *(str2++);
	} else
		goto bad;

	// Find the next '/' so we can have the beginning and the end of the host name
	char *begin_hostname = str2;
	while(*str2 && *str2!='/')
		str2++;
	str2--;
	char *end_hostname = str2;

	// Ignore leading dots
	while(*begin_hostname && *begin_hostname=='.')
		begin_hostname++;

	// Ignore trailing dots
	while(end_hostname-begin_hostname>0 && *end_hostname=='.')
		end_hostname--;

	// We should normalize the IP addresse, but we expect the IP address to be a 4 dot-separated decimal values
	
	// Copy the host name, making sure all characters are lowercase
	for( ; end_hostname-begin_hostname>=0; dest++, begin_hostname++)
		*dest = LOWERCASE(*begin_hostname);

	str2++;
	*(dest++)='/';

	if(*str2!='/') {
		*dest = '\0';
		goto good;
	}

	char *after_hostname = dest;

	bool in_query = false;
	while(*str2) {
		if(in_query) {
			// If in query, just copy the character
			*(dest++) = *(str2++);
		} else {
			// We are in the path
			switch(*str2) {
				case '?':
					// Entering query
					*(dest++) = *(str2++);
					in_query = true;
					break;
				case '/':
					if(*(str2+1)=='.' && *(str2+2)=='/') {
						// replace "/./" with "/"
						*(dest++) = '/';
						str2 +=3;
					} else if(*(str2+1)=='.' && *(str2+2)=='.' && (*(str2+3)=='/' || *(str2+3)=='\0')) {
						// Remove "/../" along with the preceding path component.
						if(*(str2+3)=='\0')
							str2 +=3;
						else str2 +=4;
						do {
							dest--;
						} while(dest-after_hostname>=0 && *dest!='/');
						dest++;
					} else
						*(dest++) = *(str2++);
					// Replace runs of consecutive slashes with a single slash character.
					if(*(dest-1)=='/' && *(dest-2)=='/')
						dest--;
					break;
				default:
					*(dest++) = *(str2++);
			}
		}
	}
	*dest='\0';

good:
	free(str1); free(begin_source);
	if(new_len)
		*new_len = dest - begin_dest;
	// printf("url_Normalize() END dest=[%s] len=%ld\n", begin_dest, dest-begin_dest);
	return(begin_dest);

bad:
	free(str1); free(begin_source);
	if(dest)
		free(dest);
	return(NULL);
}