| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f |
| From: | "Goh, Yong Kwang" <gohyongkwang AT hotmail DOT com> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Printing out regex matches |
| Date: | Mon, 1 Apr 2002 17:36:12 +0800 |
| Organization: | Singapore Telecommunications Ltd |
| Lines: | 69 |
| Message-ID: | <a89rvc$p7v$1@violet.singnet.com.sg> |
| NNTP-Posting-Host: | tns01925.singnet.com.sg |
| X-Priority: | 3 |
| X-MSMail-Priority: | Normal |
| X-Newsreader: | Microsoft Outlook Express 5.50.4133.2400 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
I've a problem with printing out the regex matches in the regmatch_t
pmatch[] array returned from a regexec function call.
the code excerpt as below:
void PrintMatch(regmatch_t pmatch[])
{
int index = 0;
int so;
int eo;
char match[80];
do{
so = pmatch[index].rm_so;
eo = pmatch[index].rm_eo;
if(so != -1 && eo != -1 && so != eo){
printf("so=%d, eo=%d\n", so, eo);
strncpy(match, string, (eo - so));
}
index++;
}while(so != -1 && eo != -1 && so != eo);
}
It gives the following output:
D:\TEMP>tyregex
tyregex> = string helloworld <= some command to set variables.
tyregex> = pattern world
tyregex> !
helloworld <= prints out string for diagnostic purpose.
world <= prints out pattern for diagnostic purpose.
OK <= indicates regex compilation OK
OK <= indicates regex execution OK i.e. pattern matches string.
so=132617, eo=0 <= value of so and eo. Printed by PrintMatch.
Exiting due to signal SIGSEGV <= Program starts to bomb out.
General Protection Fault at eip=00008220
eax=0144ff00 ebx=000130cb ecx=01450000 edx=fffdf8fb esi=0144ff04
edi=000131c0
ebp=0144fef0 esp=0144fee8 program=D:\TEMP\TYREGEX.EXE
cs: sel=00af base=829e0000 limit=0144ffff
ds: sel=00b7 base=829e0000 limit=0144ffff
es: sel=00b7 base=829e0000 limit=0144ffff
fs: sel=0087 base=0000ffa0 limit=0000ffff
gs: sel=00c7 base=00000000 limit=ffffffff
ss: sel=00b7 base=829e0000 limit=0144ffff
Call frame traceback EIPs:
0x00008220
0x000024e6
D:\TEMP>
One thing weird about it is that 'so' is supposed to store the starting
offset and 'eo' the ending offset of the match in the original string. But
how could the starting offset be more than the ending offset? it doesn't
make sense and is obviously wrong.
--
Yong-Kwang Goh
Singapore
gohyongkwang AT hotmail DOT com
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.342 / Virus Database: 189 - Release Date: 3/14/02
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |