2003-02-18 20:35:35 +00:00
|
|
|
/* $Id: strutil.c,v 1.8 2003-02-18 20:35:35 btb Exp $ */
|
2001-01-19 03:30:16 +00:00
|
|
|
/*
|
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2003-02-18 20:35:35 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2001-01-19 03:30:16 +00:00
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
2003-02-18 20:35:35 +00:00
|
|
|
|
2001-01-31 15:18:05 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2001-01-19 03:30:16 +00:00
|
|
|
#include <conf.h>
|
2001-01-31 15:18:05 +00:00
|
|
|
#endif
|
|
|
|
|
2001-01-19 03:30:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "error.h"
|
|
|
|
|
2001-10-12 00:18:40 +00:00
|
|
|
#if 0
|
2001-01-19 03:30:16 +00:00
|
|
|
// string compare without regard to case
|
|
|
|
|
|
|
|
int stricmp( char *s1, char *s2 )
|
|
|
|
{
|
|
|
|
while( *s1 && *s2 ) {
|
|
|
|
if ( tolower(*s1) != tolower(*s2) ) return 1;
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
if ( *s1 || *s2 ) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int strnicmp( char *s1, char *s2, int n )
|
|
|
|
{
|
|
|
|
while( *s1 && *s2 && n) {
|
|
|
|
if ( tolower(*s1) != tolower(*s2) ) return 1;
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
if (n) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-01-19 03:34:09 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-12 00:18:40 +00:00
|
|
|
#ifndef __MINGW32__
|
2001-10-12 10:03:32 +00:00
|
|
|
#ifndef __DJGPP__
|
2001-01-19 03:30:16 +00:00
|
|
|
void strlwr( char *s1 )
|
|
|
|
{
|
|
|
|
while( *s1 ) {
|
|
|
|
*s1 = tolower(*s1);
|
|
|
|
s1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void strupr( char *s1 )
|
|
|
|
{
|
|
|
|
while( *s1 ) {
|
|
|
|
*s1 = toupper(*s1);
|
|
|
|
s1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-19 03:34:09 +00:00
|
|
|
#endif
|
|
|
|
|
2001-01-19 03:30:16 +00:00
|
|
|
void strrev( char *s1 )
|
|
|
|
{
|
2002-07-16 19:05:31 +00:00
|
|
|
char *h, *t;
|
|
|
|
h = s1;
|
|
|
|
t = s1 + strlen(s1) - 1;
|
|
|
|
while (h < t) {
|
|
|
|
char c;
|
|
|
|
c = *h;
|
|
|
|
*h++ = *t;
|
|
|
|
*t-- = c;
|
|
|
|
}
|
2001-01-19 03:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _splitpath(char *name, char *drive, char *path, char *base, char *ext)
|
|
|
|
{
|
|
|
|
char *s, *p;
|
|
|
|
|
|
|
|
p = name;
|
|
|
|
s = strchr(p, ':');
|
|
|
|
if ( s != NULL ) {
|
|
|
|
if (drive) {
|
|
|
|
*s = '\0';
|
|
|
|
strcpy(drive, p);
|
|
|
|
*s = ':';
|
|
|
|
}
|
|
|
|
p = s+1;
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
} else if (drive)
|
|
|
|
*drive = '\0';
|
|
|
|
|
|
|
|
s = strrchr(p, '\\');
|
|
|
|
if ( s != NULL) {
|
|
|
|
if (path) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
c = *(s+1);
|
|
|
|
*(s+1) = '\0';
|
|
|
|
strcpy(path, p);
|
|
|
|
*(s+1) = c;
|
|
|
|
}
|
|
|
|
p = s+1;
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
} else if (path)
|
|
|
|
*path = '\0';
|
|
|
|
|
|
|
|
s = strchr(p, '.');
|
|
|
|
if ( s != NULL) {
|
|
|
|
if (base) {
|
|
|
|
*s = '\0';
|
|
|
|
strcpy(base, p);
|
|
|
|
*s = '.';
|
|
|
|
}
|
|
|
|
p = s+1;
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
} else if (base)
|
|
|
|
*base = '\0';
|
|
|
|
|
|
|
|
if (ext)
|
|
|
|
strcpy(ext, p);
|
|
|
|
}
|
2001-10-12 00:18:40 +00:00
|
|
|
#endif
|
2001-01-19 03:30:16 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
char drive[10], path[50], name[16], ext[5];
|
|
|
|
|
|
|
|
drive[0] = path[0] = name[0] = ext[0] = '\0';
|
|
|
|
_splitpath("f:\\tmp\\x.out", drive, path, name, ext);
|
|
|
|
drive[0] = path[0] = name[0] = ext[0] = '\0';
|
|
|
|
_splitpath("tmp\\x.out", drive, path, name, ext);
|
|
|
|
drive[0] = path[0] = name[0] = ext[0] = '\0';
|
|
|
|
_splitpath("f:\\tmp\\a.out", NULL, NULL, name, NULL);
|
|
|
|
drive[0] = path[0] = name[0] = ext[0] = '\0';
|
|
|
|
_splitpath("tmp\\*.dem", drive, path, NULL, NULL);
|
|
|
|
drive[0] = path[0] = name[0] = ext[0] = '\0';
|
|
|
|
_splitpath(".\\tmp\\*.dem", drive, path, NULL, NULL);
|
|
|
|
}
|
|
|
|
#endif
|