Update of /cvsroot/radmind/radmind-assistant/rte
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30430
Modified Files:
pathcmp.c pathcmp.h
Log Message:
Current version of pathcmp.
Index: pathcmp.h
===================================================================
RCS file: /cvsroot/radmind/radmind-assistant/rte/pathcmp.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pathcmp.h 7 Feb 2003 22:51:00 -0000 1.1
--- pathcmp.h 12 Apr 2006 19:25:47 -0000 1.2
***************
*** 4,6 ****
*/
! int pathcmp( const unsigned char *p1, const unsigned char *p2 );
--- 4,11 ----
*/
! int pathcasecmp( const unsigned char *, const unsigned char *,
! int case_sensitive );
! int pathcmp( const unsigned char *, const unsigned char * );
! int ischildcase( const unsigned char *, const unsigned char *,
! int case_sensitive );
! int ischild( const unsigned char *, const unsigned char * );
Index: pathcmp.c
===================================================================
RCS file: /cvsroot/radmind/radmind-assistant/rte/pathcmp.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pathcmp.c 19 May 2005 00:10:54 -0000 1.2
--- pathcmp.c 12 Apr 2006 19:25:47 -0000 1.3
***************
*** 1,17 ****
/*
! * Copyright (c) 2005 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
#include "pathcmp.h"
! /* Just like strcmp(), but pays attention to the meaning of '/'. */
! int
! pathcmp( const unsigned char *p1, const unsigned char *p2 )
{
int rc;
do {
! if (( rc = ( *p1 - *p2 )) != 0 ) {
if (( *p2 != '\0' ) && ( *p1 == '/' )) {
return( -1 );
--- 1,30 ----
/*
! * Copyright (c) 2003 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
+ #include "config.h"
+
+ #include <sys/param.h>
+ #include <sys/types.h>
+ #include <ctype.h>
+ #include <string.h>
+
#include "pathcmp.h"
! int
! pathcasecmp( const unsigned char *p1, const unsigned char *p2,
! int case_sensitive )
{
int rc;
do {
! if ( case_sensitive ) {
! rc = ( (unsigned char)*p1 - (unsigned char)*p2 );
! } else {
! rc = ( tolower( *p1 ) - tolower( *p2 ));
! }
!
! if ( rc != 0 ) {
if (( *p2 != '\0' ) && ( *p1 == '/' )) {
return( -1 );
***************
*** 27,28 ****
--- 40,87 ----
return( 0 );
}
+
+ /* Just like strcmp(), but pays attention to the meaning of '/'. */
+ int
+ pathcmp( const unsigned char *p1, const unsigned char *p2 )
+ {
+ return( pathcasecmp( p1, p2, 1 ));
+ }
+
+ int
+ ischildcase( const unsigned char *child, const unsigned char *parent, int
+ case_sensitive )
+ {
+ int rc;
+ size_t parentlen;
+
+
+ if ( parent == NULL ) {
+ return( 1 );
+ }
+
+ parentlen = strlen( parent );
+
+ if ( parentlen > strlen( child )) {
+ return( 0 );
+ }
+ if (( 1 == parentlen ) && ( '/' == *parent )) {
+ return( '/' == *child );
+ }
+
+ if ( case_sensitive ) {
+ rc = strncmp( parent, child, parentlen );
+ } else {
+ rc = strncasecmp( parent, child, parentlen );
+ }
+ if (( rc == 0 ) && (( '/' == child[ parentlen ] ) ||
+ ( '\0' == child[ parentlen ] ))) {
+ return( 1 );
+ }
+ return( 0 );
+ }
+
+ int
+ ischild( const unsigned char *child, const unsigned char *parent )
+ {
+ return( ischildcase( child, parent, 1 ));
+ }
|