#include <sys/types.h>
#include <stdio.h>

#include <tre/tre.h>

#define MYSTRING "/Developer/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -std=c99 -fobjc-gc-only -Wno-trigraphs -O0 -Wmissing-field-initializers -Wmissing-prototypes -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wunknown-pragmas -Wshadow -Wfour-char-constants -Wsign-compare -Wshorten-64-to-32 -Wnewline-eof -Wstrict-selector-match -Wundeclared-selector -fasm-blocks -fprofile-arcs -ftest-coverage -mmacosx-version-min=10.6 -gdwarf-2 -Wno-sign-conversion \"-DIBOutlet=__attribute__((iboutlet))\" \"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\" \"-DIBAction=void)__attribute__((ibaction)\" -iquote /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-generated-files.hmap -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-own-target-headers.hmap -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-all-target-headers.hmap -iquote /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-project-headers.hmap -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/Quesa/trunk/Includes -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/GDCM/trunk/Debug/include/gdcm-2.0 -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Algorithms -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/BasicFilters -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Common -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/IO -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Numerics -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/itkExtHdrs -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Review -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/core -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/vcl -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/NetCDF/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/HDF5/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/MINC2/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/libusb/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/vtk/trunk/Debug/include/vtk-5.8 -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Algorithms -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/BasicFilters -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Common -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/IO -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Numerics -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/itkExtHdrs -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Review -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/core -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/vcl -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/Glib/trunk/Debug/include/glib-2.0 -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/Glib/trunk/Debug/lib/glib-2.0/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/GTS/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/DerivedSources/x86_64 -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/DerivedSources -Wall -Wextra -Wundef -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wdisabled-optimization -Wfloat-equal -Winit-self -Wextra-tokens -Wvolatile-register-var -Winvalid-pch -fdiagnostics-show-option -Wlarger-than-30000 -Wno-format-nonliteral -Wno-strict-aliasing -F/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Debug -F/Users/alex/RogueSVNWorkingCopy1/3rdParty/FeedbackReporter/trunk/Debug -Wstrict-prototypes -Wold-style-definition -Wnested-externs -Wmissing-prototypes -Wmissing-declarations -Wdiv-by-zero -fstrict-overflow -fstack-protector-all -D_FORTIFY_SOURCE=2 -ftrapv -include /var/folders/_d/qv6wq6vn2yx905skz34h8fnc0000gp/C/com.apple.Xcode.502/SharedPrecompiledHeaders/BwhateverPrefixDebug-dkuubzkawhrreebihjtvyeqphdyw/BwhateverPrefixDebug.pch -MMD -MT dependencies -MF /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Objects-normal/x86_64/_BS17Segmentation.d -c /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/Bwhatever/src/ManagedObjectsAuto/BS17Project/_BS17Segmentation.m -o /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Objects-normal/x86_64/_BS17Segmentation.o"
//#define MYSTRING "/Developer/usr/bin/clang -x : warning 123 : objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -std=c99 -fobjc-gc-only -Wno-trigraphs -O0 -Wmissing-field-initializers -Wmissing-prototypes -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wunknown-pragmas -Wshadow -Wfour-char-constants -Wsign-compare -Wshorten-64-to-32 -Wnewline-eof -Wstrict-selector-match -Wundeclared-selector -fasm-blocks -fprofile-arcs -ftest-coverage -mmacosx-version-min=10.6 -gdwarf-2 -Wno-sign-conversion \"-DIBOutlet=__attribute__((iboutlet))\" \"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\" \"-DIBAction=void)__attribute__((ibaction)\" -iquote /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-generated-files.hmap -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-own-target-headers.hmap -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-all-target-headers.hmap -iquote /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Bwhatever-project-headers.hmap -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/Quesa/trunk/Includes -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/GDCM/trunk/Debug/include/gdcm-2.0 -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Algorithms -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/BasicFilters -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Common -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/IO -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Numerics -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/itkExtHdrs -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Review -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/core -iquote/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/vcl -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/NetCDF/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/HDF5/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/MINC2/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/libusb/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/vtk/trunk/Debug/include/vtk-5.8 -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Algorithms -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/BasicFilters -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Common -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/IO -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Numerics -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/itkExtHdrs -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Review -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/core -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/itk/trunk/Debug/include/InsightToolkit/Utilities/vxl/vcl -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/Glib/trunk/Debug/include/glib-2.0 -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/Glib/trunk/Debug/lib/glib-2.0/include -I/Users/alex/RogueSVNWorkingCopy1/3rdParty/GTS/trunk/Debug/include -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/DerivedSources/x86_64 -I/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/DerivedSources -Wall -Wextra -Wundef -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wdisabled-optimization -Wfloat-equal -Winit-self -Wextra-tokens -Wvolatile-register-var -Winvalid-pch -fdiagnostics-show-option -Wlarger-than-30000 -Wno-format-nonliteral -Wno-strict-aliasing -F/Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Debug -F/Users/alex/RogueSVNWorkingCopy1/3rdParty/FeedbackReporter/trunk/Debug -Wstrict-prototypes -Wold-style-definition -Wnested-externs -Wmissing-prototypes -Wmissing-declarations -Wdiv-by-zero -fstrict-overflow -fstack-protector-all -D_FORTIFY_SOURCE=2 -ftrapv -include /var/folders/_d/qv6wq6vn2yx905skz34h8fnc0000gp/C/com.apple.Xcode.502/SharedPrecompiledHeaders/BwhateverPrefixDebug-dkuubzkawhrreebihjtvyeqphdyw/BwhateverPrefixDebug.pch -MMD -MT dependencies -MF /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Objects-normal/x86_64/_BS17Segmentation.d -c /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/Bwhatever/src/ManagedObjectsAuto/BS17Project/_BS17Segmentation.m -o /Users/alex/RogueSVNWorkingCopy1/bwhatever2/trunk/build/Bwhatever2.build/Debug/Bwhatever.build/Objects-normal/x86_64/_BS17Segmentation.o"
#define MYREGEX  "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:"

#define MAXMATCH 10

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

        regex_t regex;
		regmatch_t pmatch[MAXMATCH];

        int reti;
        char msgbuf[100];

		/* Compile regular expression */
        reti = tre_regcomp(&regex, MYREGEX, REG_EXTENDED);
        if( reti ){ fprintf(stderr, "Could not compile regex\n"); exit(1); }

		/* Execute regular expression */
	
		//puts(MYSTRING);
		const char *s = MYSTRING;

		int i = 0;
		int j = 0;
		for (i=0; i<1000; i++) {
        	reti = tre_regexec(&regex, MYSTRING, MAXMATCH, &pmatch, 0);
        	if( !reti ){
        	        puts("Match");
					for (j=0; j<MAXMATCH; j++) {
						printf("match %d: ", j);
						int k = pmatch[j].rm_so;
						if (k==-1) continue;
						for (; k<pmatch[j].rm_eo; k++) {
							printf("%c", s[k]);
						}
						printf("\n");
					}
        	}
        	else if( reti == REG_NOMATCH ){
        	        puts("No match");
        	}
        	else{
        	        regerror(reti, &regex, msgbuf, sizeof(msgbuf));
        	        fprintf(stderr, "Regex match failed: %s\n", msgbuf);
        	        exit(1);
        	}
		}

		/* Free compiled regular expression if you want to use the regex_t again */
		tre_regfree(&regex);

        return 0;
}



