G
gert
based on http://souptonuts.sourceforge.net/code/regexp.c.html
#include <stdio.h>
#include <string.h>
#include <regex.h>
int split(char * output[100], char * input){
regex_t preg;
regmatch_t pmatch[100];
size_t i;
char inputsub[sizeof(input)];
if(regcomp (&preg, "select", REG_EXTENDED)) output[0]="Invalid
expression";
else {
if(regexec (&preg, input, 100, pmatch, 0)) output[0]="No
match"; else {
for (i = 0; i <= preg.re_nsub; i++){
strncpy (inputsub, input + pmatch.rm_so, pmatch.rm_eo -
pmatch.rm_so);
//inputsub[pmatch.rm_eo - pmatch.rm_so] = '\0'; //
<-------????????
output=inputsub;
}
}
}
regfree (&preg);
printf (""); //<----------????????????????
return 0;
}
int xml(char * input){
char * output[100];
split(output,input);
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s</xml>"
"\n",output[0]);
return 0;
}
is this line really necessary ?
inputsub[pmatch.rm_eo - pmatch.rm_so] = '\0';
and why do i have to do printf ("") ? if i dont do printf("") the
second printf doesnt have a output[0] value ?
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s</xml>"
"\n",output[0]);
#include <stdio.h>
#include <string.h>
#include <regex.h>
int split(char * output[100], char * input){
regex_t preg;
regmatch_t pmatch[100];
size_t i;
char inputsub[sizeof(input)];
if(regcomp (&preg, "select", REG_EXTENDED)) output[0]="Invalid
expression";
else {
if(regexec (&preg, input, 100, pmatch, 0)) output[0]="No
match"; else {
for (i = 0; i <= preg.re_nsub; i++){
strncpy (inputsub, input + pmatch.rm_so, pmatch.rm_eo -
pmatch.rm_so);
//inputsub[pmatch.rm_eo - pmatch.rm_so] = '\0'; //
<-------????????
output=inputsub;
}
}
}
regfree (&preg);
printf (""); //<----------????????????????
return 0;
}
int xml(char * input){
char * output[100];
split(output,input);
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s</xml>"
"\n",output[0]);
return 0;
}
is this line really necessary ?
inputsub[pmatch.rm_eo - pmatch.rm_so] = '\0';
and why do i have to do printf ("") ? if i dont do printf("") the
second printf doesnt have a output[0] value ?
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s</xml>"
"\n",output[0]);