This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Regex question (is it broken?)


	I installed Cygwin a couple of weeks ago, and I notice that the regex 
functionality seems broken.  Attached is a test program I cobbled together 
from various places, just so I could get a handle on using regex 
properly.  However, while this program compiles properly, it does not 
execute correctly on either of two machines I've tried Cygwin on (WinNT box 
and a Win98 box), while compiling this on a Sun/Solaris/etc. unix machine 
seems to make it work just fine.  I've searched the archives, etc., and 
cannot find info on this issue.  What's going on??
		Marty


Output on Unix box using native gcc:
	2Status = 1
	NOT A MATCH

	MATCH!!


Output on Windows machine using Cygwin complete install (via the setup 
program):
	1Status = 1
	NOT A MATCH

	1Status = 1
	NOT A MATCH



The test program (compile using "gcc" with no extra options):


#include <stdio.h>
#include <ctype.h>
#include <regex.h>


/*
  * Match string against the extended regular expression in
  * pattern, treating errors as no match.
  *
  * return 1 for match, 0 for no match
  */

int match(const char *string, char *pattern)
{
     int    status;
     regex_t    re;

     if (status = regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
		printf("1Status = %d\n", status);
         return(0);      /* report error */
     }
     status = regexec(&re, string, (size_t) 0, NULL, 0);
     regfree(&re);
     if (status != 0) {
		printf("2Status = %d\n", status);
         return(0);      /* report error */
     }
     return(1);
}




int main(int argc, char **argv) {

	if (match("a", "b")) {
		printf("MATCH!!\a\n");
	}
	else {
		printf("NOT A MATCH\n\n");
	}

	if (match("a", "a")) {
		printf("MATCH!!\a\n");
	}
	else {
		printf("NOT A MATCH\n\n");
	}

     return 0;

}


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]