本文整理汇总了C++中regfree函数的典型用法代码示例。如果您正苦于以下问题:C++ regfree函数的具体用法?C++ regfree怎么用?C++ regfree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了regfree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_config_gui
//.........这里部分代码省略.........
}
break;
}
case VIEWPOS_FILE:
{
lat = INVALID_COORD;
lon = INVALID_COORD;
viewpos_file = (char *)e_widget_entry_text_get(cfdata->gui.o_viewpos_file_val);
switch(read_viewpos_file(viewpos_file, &lat, &lon))
{
case VIEWPOS_FILE_NO_PERM:
{
sprintf(error_message + strlen(error_message),
"<br>* No permissions to read viewing position file");
config_ok = 0;
break;
}
case VIEWPOS_FILE_NOT_FOUND:
{
sprintf(error_message + strlen(error_message),
"<br>* The viewing position file cannot be found");
config_ok = 0;
break;
}
case VIEWPOS_FILE_IS_DIR:
{
sprintf(error_message + strlen(error_message),
"<br>* The viewing position file is a directory");
config_ok = 0;
break;
}
case VIEWPOS_FILE_FORMAT_ERROR:
{
sprintf(error_message + strlen(error_message),
"<br>* The viewing position file is in the wrong format (must be 2 numbers, lat then lon)");
config_ok = 0;
break;
}
case VIEWPOS_FILE_OK:
cfdata->local_xplanet.viewpos_file = (char *)eina_stringshare_add(viewpos_file);
break;
}
break;
}
default:
break;
}
cfdata->local_xplanet.use_localtime = e_widget_check_checked_get(cfdata->gui.o_use_localtime);
cfdata->local_xplanet.localtime = cfdata->gui.o_localtime;
cfdata->local_xplanet.show_label = e_widget_check_checked_get(cfdata->gui.o_show_label);
cfdata->local_xplanet.label_text = strdup(e_widget_entry_text_get(cfdata->gui.o_label_text));
text_value = strdup(e_widget_entry_text_get(cfdata->gui.o_label_pos_other_text));
if (!text_value || strlen(text_value) == 0)
{
cfdata->local_xplanet.label_pos_other = "";
if (cfdata->local_xplanet.label_pos == LABEL_POS_OTHER)
{
sprintf(error_message + strlen(error_message),
"<br>* You have not entered a label position");
config_ok = 0;
}
}
else
{
reg_expression = E_NEW(regex_t, 1);
regcomp(reg_expression, "^[+-][0-9][0-9]*[+-][0-9][0-9]*$", 0);
regex_result = regexec(reg_expression, text_value, 0, NULL, 0);
if (regex_result)
{
sprintf(error_message + strlen(error_message),
"<br>* The entered label position is invalid - must be of the form -15+15");
config_ok = 0;
}
else cfdata->local_xplanet.label_pos_other = text_value;
regfree(reg_expression);
free(reg_expression);
}
cfdata->local_xplanet.use_config = e_widget_check_checked_get(cfdata->gui.o_config_check);
cfdata->local_xplanet.config_name = strdup(e_widget_entry_text_get(cfdata->gui.o_config_name));
cfdata->local_xplanet.extra_options = strdup(e_widget_entry_text_get(cfdata->gui.o_extra_options));
if (!config_ok)
{
error_popup = e_dialog_new(e_container_current_get(
e_manager_current_get()), "eplanet_error", "eplanet/error");
e_dialog_title_set(error_popup, "Configuration error");
e_dialog_text_set(error_popup, (const char *) &error_message);
e_dialog_button_add(error_popup, D_("OK"), NULL, NULL, NULL);
e_dialog_show(error_popup);
}
return config_ok;
}
开发者ID:squaregoldfish,项目名称:eplanet,代码行数:101,代码来源:e_mod_config.c
示例2: sprintf
//.........这里部分代码省略.........
BPatch_function * bpfunc = proc->findOrCreateBPFunc(int_funcs[miter], this);
funcs.push_back(bpfunc);
}
}
}
}
if (size != funcs.size())
return &funcs;
}
else {
// Regular expression search. As with BPatch_image, we handle it here
#if !defined(i386_unknown_nt4_0) && !defined(mips_unknown_ce2_11) // no regex for M$
// REGEX falls through:
regex_t comp_pat;
int err, cflags = REG_NOSUB | REG_EXTENDED;
if( !regex_case_sensitive )
cflags |= REG_ICASE;
//cerr << "compiling regex: " <<name<<endl;
if (0 != (err = regcomp( &comp_pat, name, cflags ))) {
char errbuf[80];
regerror( err, &comp_pat, errbuf, 80 );
if (notify_on_failure) {
cerr << __FILE__ << ":" << __LINE__ << ": REGEXEC ERROR: "<< errbuf << endl;
pdstring msg = pdstring("Image: Unable to find function pattern: ")
+ pdstring(name) + ": regex error --" + pdstring(errbuf);
BPatch_reportError(BPatchSerious, 100, msg.c_str());
}
// remove this line
//cerr << __FILE__ << ":" << __LINE__ << ": REGEXEC ERROR: "<< errbuf << endl;
return NULL;
}
// Regular expression search. This used to be handled at the image
// class level, but was moved up here to simplify semantics. We
// have to iterate over every function known to the process at some
// point, so it might as well be top-level. This is also an
// excellent candidate for a "value-added" library.
const pdvector<int_function *> &int_funcs = mod->getAllFunctions();
for (unsigned ai = 0; ai < int_funcs.size(); ai++) {
int_function *func = int_funcs[ai];
// If it matches, push onto the vector
// Check all pretty names (and then all mangled names if there is no match)
bool found_match = false;
for (unsigned piter = 0; piter < func->prettyNameVector().size(); piter++) {
const pdstring &pName = func->prettyNameVector()[piter];
int err;
if (0 == (err = regexec(&comp_pat, pName.c_str(), 1, NULL, 0 ))){
if (func->isInstrumentable() || incUninstrumentable) {
BPatch_function *foo = proc->findOrCreateBPFunc(func, NULL);
funcs.push_back(foo);
}
found_match = true;
break;
}
}
if (found_match) continue; // Don't check mangled names
for (unsigned miter = 0; miter < func->symTabNameVector().size(); miter++) {
const pdstring &mName = func->symTabNameVector()[miter];
int err;
if (0 == (err = regexec(&comp_pat, mName.c_str(), 1, NULL, 0 ))){
if (func->isInstrumentable() || incUninstrumentable) {
BPatch_function *foo = proc->findOrCreateBPFunc(func, NULL);
funcs.push_back(foo);
}
found_match = true;
break;
}
}
}
regfree(&comp_pat);
if (funcs.size() != size) {
return &funcs;
}
if (notify_on_failure) {
pdstring msg = pdstring("Unable to find pattern: ") + pdstring(name);
BPatch_reportError(BPatchSerious, 100, msg.c_str());
}
#endif
}
if(notify_on_failure) {
char msg[1024];
sprintf(msg, "%s[%d]: Module %s: unable to find function %s",
__FILE__, __LINE__, mod->fileName().c_str(), name);
BPatch_reportError(BPatchSerious, 100, msg);
}
return &funcs;
}
开发者ID:vishalmistry,项目名称:imitate,代码行数:101,代码来源:BPatch_module.C
示例3: make_device
/* mknod in /dev based on a path like "/sys/block/hda/hda1" */
static void make_device(char *path)
{
char *device_name,*s;
int major,minor,type,len,fd;
int mode=0660;
uid_t uid=0;
gid_t gid=0;
RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
/* Try to read major/minor string */
snprintf(temp, PATH_MAX, "%s/dev", path);
fd = open(temp, O_RDONLY);
len = read(fd, temp, PATH_MAX-1);
if (len<1) goto end;
temp[len] = 0;
close(fd);
/* Determine device name, type, major and minor */
device_name = strrchr(path, '/') + 1;
type = strncmp(path+5, "block/" ,6) ? S_IFCHR : S_IFBLK;
major = minor = 0;
for (s = temp; *s; s++) {
if (*s == ':') {
major = minor;
minor = 0;
} else {
minor *= 10;
minor += (*s) - '0';
}
}
/* If we have a config file, look up permissions for this device */
if (ENABLE_FEATURE_MDEV_CONF) {
char *conf,*pos,*end;
/* mmap the config file */
if (-1!=(fd=open("/etc/mdev.conf",O_RDONLY))) {
len=lseek(fd,0,SEEK_END);
conf=mmap(NULL,len,PROT_READ,MAP_PRIVATE,fd,0);
if (conf) {
int line=0;
/* Loop through lines in mmaped file*/
for (pos=conf;pos-conf<len;) {
int field;
char *end2;
line++;
/* find end of this line */
for(end=pos;end-conf<len && *end!='\n';end++);
/* Three fields: regex, uid:gid, mode */
for (field=3;field;field--) {
/* Skip whitespace */
while (pos<end && isspace(*pos)) pos++;
if (pos==end || *pos=='#') break;
for (end2=pos;
end2<end && !isspace(*end2) && *end2!='#'; end2++);
switch(field) {
/* Regex to match this device */
case 3:
{
char *regex=strndupa(pos,end2-pos);
regex_t match;
regmatch_t off;
int result;
/* Is this it? */
xregcomp(&match,regex,REG_EXTENDED);
result=regexec(&match,device_name,1,&off,0);
regfree(&match);
/* If not this device, skip rest of line */
if(result || off.rm_so
|| off.rm_eo!=strlen(device_name))
goto end_line;
break;
}
/* uid:gid */
case 2:
{
char *s2;
/* Find : */
for(s=pos;s<end2 && *s!=':';s++);
if(s==end2) goto end_line;
/* Parse UID */
uid=strtoul(pos,&s2,10);
if(s!=s2) {
struct passwd *pass;
pass=getpwnam(strndupa(pos,s-pos));
if(!pass) goto end_line;
uid=pass->pw_uid;
//.........这里部分代码省略.........
开发者ID:K0T0LI,项目名称:busybox,代码行数:101,代码来源:mdev.c
示例4: get_compiled_regex
//.........这里部分代码省略.........
{
case RE_SUBST:
re = ((dc != '\n' && re_search) || ed->exec->subst->r_f ? re_search
: re_subst);
if (!re_subst)
re_subst = re;
break;
case RE_SEARCH:
re = re_search ? re_search : re_subst;
if (!re_search)
re_search = re;
break;
}
if (!re)
ed->exec->err = _("No previous pattern");
return re;
}
if (!(pattern = regular_expression (dc, &len, ed)))
return NULL;
if (!(re = (regex_t *) malloc (sizeof (regex_t))))
{
fprintf (stderr, "%s\n", strerror (errno));
ed->exec->err = _("Memory exhausted");
return NULL;
}
#ifdef HAVE_REG_SYNTAX_T
/* GNU regcomp () has no hooks for setting re_syntax_options, and
pattern cannot contain NUL chars, so use re_compile_pattern (). */
re->translate = NULL;
re->fastmap = NULL;
re->buffer = NULL;
re->allocated = 0;
if ((compile_err = re_compile_pattern (pattern, len, re)))
{
regfree (re);
free (re);
ed->exec->err = compile_err;
return NULL;
}
#else
# ifdef REG_ENHANCED
/* Darwin regcomp () supports enhanced basic and extended regular
expressions. */
re->re_endp = pattern + len;
if (status =
regcomp (re, pattern, (REG_PEND | REG_ENHANCED |
(ed->exec->opt & REGEX_EXTENDED
? REG_EXTENDED : 0))))
# else
# ifdef REG_PEND
/* BSD regcomp () accepts pattern with NUL chars via REG_PEND, but
has no equivalent of GNU's re_syntax_options. */
re->re_endp = pattern + len;
if (status =
regcomp (re, pattern, (REG_PEND | (ed->exec->opt & REGEX_EXTENDED
? REG_EXTENDED : 0))))
# else
/* Use generic POSIX regular expression library. */
if (status = regcomp (re, pattern, (ed->exec->opt & REGEX_EXTENDED
? REG_EXTENDED : 0)))
# endif /* !defined (REG_PEND) */
# endif /* !defined (REG_ENHANCED) */
{
regerror (status, re, re_err, sizeof re_err);
ed->exec->err = re_err;
free (re);
return NULL;
}
#endif /* !defined (HAVE_REG_SYNTAX_T) */
switch (re_type)
{
case RE_SUBST:
if (re_subst && re_subst != re_search)
{
regfree (re_subst);
free (re_subst);
}
re_subst = re;
break;
case RE_SEARCH:
if (re_search && re_search != re_subst)
{
regfree (re_search);
free (re_search);
}
re_search = re;
break;
}
return re;
}
开发者ID:slewsys,项目名称:ed,代码行数:101,代码来源:re.c
示例5: gen
void
gen(Node *n)
{
Node *l, nod;
Prog *sp, *spc, *spb;
Case *cn;
long sbc, scc;
int snbreak, sncontin;
int f, o, oldreach;
loop:
if(n == Z)
return;
nearln = n->lineno;
o = n->op;
if(debug['G'])
if(o != OLIST)
print("%L %O\n", nearln, o);
if(!canreach) {
switch(o) {
case OLABEL:
case OCASE:
case OLIST:
case OBREAK:
case OFOR:
case OWHILE:
case ODWHILE:
/* all handled specially - see switch body below */
break;
default:
if(warnreach) {
warn(n, "unreachable code %O", o);
warnreach = 0;
}
}
}
switch(o) {
default:
complex(n);
cgen(n, Z);
break;
case OLIST:
gen(n->left);
rloop:
n = n->right;
goto loop;
case ORETURN:
canreach = 0;
warnreach = !suppress;
complex(n);
if(n->type == T)
break;
l = n->left;
if(l == Z) {
noretval(3);
gbranch(ORETURN);
break;
}
if(typecmplx[n->type->etype]) {
sugen(l, nodret, n->type->width);
noretval(3);
gbranch(ORETURN);
break;
}
regret(&nod, n);
cgen(l, &nod);
regfree(&nod);
if(typefd[n->type->etype])
noretval(1);
else
noretval(2);
gbranch(ORETURN);
break;
case OLABEL:
canreach = 1;
l = n->left;
if(l) {
l->pc = pc;
if(l->label)
patch(l->label, pc);
}
gbranch(OGOTO); /* prevent self reference in reg */
patch(p, pc);
goto rloop;
case OGOTO:
canreach = 0;
warnreach = !suppress;
n = n->left;
if(n == Z)
return;
if(n->complex == 0) {
diag(Z, "label undefined: %s", n->sym->name);
//.........这里部分代码省略.........
开发者ID:funkygao,项目名称:govtil,代码行数:101,代码来源:pgen.c
示例6: regicide
void regicide(char * spec, char * s)
{
regex_t regex;
int reti;
char msgbuf[100];
regmatch_t matches[NUMM];
/* Compile regular expression */
reti = regcomp(®ex, spec, 0);
if (reti) {
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Could not compile regex: %s\n", msgbuf);
exit(1);
}
/* Execute regular expression */
reti = regexec(®ex, s, NUMM, matches, 0);
if (!reti) {
if (DETAIL) {
puts("MATCH");
puts("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
}
puts("---------");
int j;
for (j = matches[2].rm_so; j < matches[2].rm_eo; j++) {
putchar(s[j]);
}
printf("\n");
puts(s);
if (DETAIL) {
/* show matches */
int i;
for (i = 1; i < NUMM; i++) {
printf("%d%d%d%d%d%d%d%d%d%d%d\n",i,i,i,i,i,i,i,i,i,i,i);
printf("%d %d\n", matches[i].rm_so, matches[i].rm_eo);
int j;
for (j = matches[i].rm_so; j < matches[i].rm_eo; j++) {
putchar(s[j]);
}
printf("\n");
}
puts("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
}
}
else if (reti == REG_NOMATCH) {
puts("NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
puts("NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
puts("NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
puts("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
puts(s);
puts("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
}
else {
regerror(reti, ®ex, 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 */
regfree(®ex);
}
开发者ID:kdbanman,项目名称:simpleC,代码行数:66,代码来源:subexp.c
示例7: retr_handler
//.........这里部分代码省略.........
sprintf(buff_req, "RETR %d\r\n", id_msg);
if(fwrite(buff_req, strlen(buff_req), sizeof(char), fsock) == -1){
perror("Error write in socket");
exit(EXIT_FAILURE);
}
regex_t r;
int status= regcomp(&r, regex_content_type, REG_EXTENDED | REG_NEWLINE);
if(status != 0){
printf("Error: regcomp regex\n");
exit(EXIT_FAILURE);
}
char* ext= (char*) malloc(sizeof(char) * MAXEXTLENGTH);
strcpy(ext, "txt");
char buff_ans[128];
char* boundary=(char*) malloc(sizeof(char) * LINELENGTH);
boundary[0]='-';
boundary[1]='-';
//recuperation reponse
bool multipart=annalyser_Entete(r, ext, boundary+2);
FILE* out=NULL;
char name_file[LINELENGTH];
char dir_name[LINELENGTH];
dir_name[0]='\0';
if(multipart == true){
sprintf(dir_name, "%d", id_msg);
mkdir(dir_name, 0744); // pas de verification, si le dossier est absent,
// on le cree sinon on peut deja ajouter les fichiers
sprintf(dir_name,"%s/", dir_name);
int size_tmp= strlen(boundary);
boundary[size_tmp]= '-'; // on ajouter les caracteres au bondary pour
boundary[size_tmp+1]= '-'; // avoir chaine delimitant la fin du mail
boundary[size_tmp+2]= '\r';
boundary[size_tmp+3]= '\n';
boundary[size_tmp+4]= '\0';
int premier_bound=0;
while(strcmp(fgets(buff_ans, 128, fsock), boundary)!=0){ // on parcours toutes parties
if(strncmp(buff_ans, boundary, strlen(boundary) - 4) == 0){
if(out != NULL)
fclose(out);
char* uselessBoundary=NULL;
multipart= annalyser_Entete(r, ext, uselessBoundary);
if(multipart){
printf("Error email format\n");
exit(EXIT_FAILURE);
}
sprintf(name_file, "%s%d.%s", dir_name, id_msg, ext);
out= fopen(name_file, "w+");
if(out == NULL){
perror("Error open file out RETR");
exit(EXIT_FAILURE);
}
if(strcmp(ext,"asc") != 0 && strcmp(ext,"txt") != 0){
premier_bound++;
}
premier_bound++;
}
else{
if( out!= NULL)
fprintf(out, "%s", buff_ans);
if( sortie != NULL && premier_bound == 1){
strcat(sortie, buff_ans);
}
}
}
while(strcmp(fgets(buff_ans, 128, fsock), ".\r\n")!=0){} // vide la fin du mail qui ne contient plus de fichier
}
else{ //si c'est un mail simple
sprintf(name_file, "%s%d.%s", dir_name, id_msg, ext);
out= fopen(name_file, "w+");
if(out == NULL){
perror("Error open file out RETR");
exit(EXIT_FAILURE);
}
while(strcmp(fgets(buff_ans, 128, fsock), ".\r\n")!=0){
fprintf(out, "%s", buff_ans);
if(sortie != NULL){
strcat(sortie, buff_ans);
}
}
fclose(out);
}
free(ext);
regfree(&r);
}
开发者ID:Pmea,项目名称:Projet-ACII,代码行数:101,代码来源:basique-pop.c
示例8: main
int main(int argc, char** argv)
{
FILE* fp = NULL; // file pointer for input file
char* line = NULL; // line of input
size_t len = 0; // length of input read
ssize_t read = 0; // length of line
int regex_error = 0; // regex error in execution
regmatch_t pm[6]; // regex matches
long offset = 0; // offset of regex match
int r_len = 0; // length of matched object
char result[256]; // buffer to hold match
char* end; // end pointer used in string conversions
// false: OFF; true: ON
// also works with enum Command
long lights[1000][1000] = { 0 }; // lights 2D array
long start_pos[2]; // starting position of command
long end_pos[2]; // ending position of command
long i = 0; // temp ; x-axis
long j = 0; // temp ; y-axis
long brightness = 0; // counter for brightness
Command command = OFF; // parsed command
// Compile regex
if (regcomp(&r_compiled, pattern, REG_EXTENDED)) {
printf("Regex compilation error.\n");
return -1;
}
// open and read file line by line
fp = fopen("./input.txt", "r");
while((read=getline(&line, &len, fp)) != -1) {
// execute regex to extract matches
// if there's any error, exit the program
regex_error = regexec(&r_compiled, line, 6, pm, REG_EXTENDED);
if (regex_error == REG_NOMATCH) {
printf("No matches.\n");
return -1;
}
// COMMAND
// get length of command, and copy to buffer.
r_len = pm[1].rm_eo - pm[1].rm_so;
memcpy(result, line + pm[1].rm_so, r_len);
result[len] = '\0'; // set
// parse result into enum Command
command = parse_command(result);
// START POS (x)
len = pm[2].rm_eo - pm[2].rm_so;
start_pos[0] = strtol(line + pm[2].rm_so, &end, 10);
// START POS (y)
len = pm[3].rm_eo - pm[3].rm_so;
start_pos[1] = strtol(line + pm[3].rm_so, &end, 10);
// END POS (x)
len = pm[4].rm_eo - pm[4].rm_so;
end_pos[0] = strtol(line + pm[4].rm_so, &end, 10);
// END POS (y)
len = pm[5].rm_eo - pm[5].rm_so;
end_pos[1] = strtol(line + pm[5].rm_so, &end, 10);
// Set lights brightness
for (i=start_pos[0]; i<=end_pos[0]; i++) {
for (j=start_pos[1]; j<=end_pos[1]; j++) {
if (command == OFF) {
if (lights[i][j] > 0) {
lights[i][j] -= 1;
}
} else if (command == ON) {
lights[i][j] += 1;
} else if (command == TOGGLE) {
lights[i][j] += 2;
}
}
}
}
// Calculate the total brightness of lights
for (i=0, brightness=0; i<1000; i++) {
for (j=0; j<1000; j++) {
brightness += lights[i][j];
}
}
printf("%ld\n", brightness);
regfree(&r_compiled);
fclose(fp);
return 0;
}
开发者ID:YouriAckx,项目名称:Advent-Of-Code-Polyglot,代码行数:99,代码来源:part2.c
示例9: uintptr_t
void printSourceFileAndLine
(
Ostream& os,
const fileName& filename,
Dl_info *info,
void *addr
)
{
uintptr_t address = uintptr_t(addr);
word myAddress = addressToWord(address);
#if ! defined(darwin64)
if (filename.ext() == "so")
{
// Convert address into offset into dynamic library
uintptr_t offset = uintptr_t(info->dli_fbase);
intptr_t relativeAddress = address - offset;
myAddress = addressToWord(relativeAddress);
}
#endif
if (filename[0] == '/')
{
string line = pOpen
(
#if ! defined(darwin64)
"addr2line -f --demangle=auto --exe "
+ filename
+ " "
+ myAddress,
1
#else
"echo 'image lookup -a "
+ myAddress
+ " "
+ filename
+ "'"
+ " | xcrun lldb "
+ "-O 'target create --no-dependents -a x86_64 "
+ filename
+ "' -o '"
+ "target modules load -f "
+ filename
+ " __TEXT "
+ addressToWord(reinterpret_cast<const uintptr_t>(info->dli_fbase))
+ "'"
+ " | tail -1"
#endif
);
#if defined(darwin64)
{
const char *buf = line.c_str();
regex_t re;
regmatch_t mt[3];
int st;
regcomp(&re, ".\\+at \\(.\\+\\):\\(\\d\\+\\)", REG_ENHANCED);
st = regexec(&re, buf, 3, mt, 0);
if (st == REG_NOMATCH)
{
line = "??:0";
}
else
{
size_t len = mt[1].rm_eo - mt[1].rm_so;
string fname(buf + mt[1].rm_so, len);
len = mt[2].rm_eo - mt[2].rm_so;
string lnum(buf + mt[2].rm_so, len);
line = fname + ":" + lnum;
}
regfree(&re);
}
#endif
if (line == "")
{
os << " addr2line failed";
}
else if (line == "??:0")
{
line = filename;
string cwdLine(line.replaceAll(cwd() + '/', ""));
string homeLine(cwdLine.replaceAll(home(), '~'));
os << " in " << homeLine.c_str();
}
else
{
string cwdLine(line.replaceAll(cwd() + '/', ""));
string homeLine(cwdLine.replaceAll(home(), '~'));
os << " at " << homeLine.c_str();
}
}
}
开发者ID:Broekie007,项目名称:openfoam-os-x,代码行数:97,代码来源:printStack.C
示例10: deinit_parse_uri
void
deinit_parse_uri(regex_t * preg)
{
regfree(preg);
}
开发者ID:uplusplus,项目名称:libmicrohttpd,代码行数:5,代码来源:mhd2spdy_structures.c
示例11: radius_compare_vps
/** Compares check and vp by value.
*
* Does not call any per-attribute comparison function, but does honour
* check.operator. Basically does "vp.value check.op check.value".
*
* @param request Current request.
* @param check rvalue, and operator.
* @param vp lvalue.
* @return 0 if check and vp are equal, -1 if vp value is less than check value, 1 is vp value is more than check
* value, -2 on error.
*/
int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp)
{
int ret = 0;
/*
* Check for =* and !* and return appropriately
*/
if (check->op == T_OP_CMP_TRUE) return 0;
if (check->op == T_OP_CMP_FALSE) return 1;
#ifdef HAVE_REGEX_H
if (check->op == T_OP_REG_EQ) {
int compare;
regex_t reg;
char value[1024];
regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];
vp_prints_value(value, sizeof(value), vp, -1);
/*
* Include substring matches.
*/
compare = regcomp(®, check->vp_strvalue, REG_EXTENDED);
if (compare != 0) {
char buffer[256];
regerror(compare, ®, buffer, sizeof(buffer));
RDEBUG("Invalid regular expression %s: %s", check->vp_strvalue, buffer);
return -2;
}
memset(&rxmatch, 0, sizeof(rxmatch)); /* regexec does not seem to initialise unused elements */
compare = regexec(®, value, REQUEST_MAX_REGEX + 1, rxmatch, 0);
regfree(®);
rad_regcapture(request, compare, value, rxmatch);
ret = (compare == 0) ? 0 : -1;
goto finish;
}
if (check->op == T_OP_REG_NE) {
int compare;
regex_t reg;
char value[1024];
regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];
vp_prints_value(value, sizeof(value), vp, -1);
/*
* Include substring matches.
*/
compare = regcomp(®, check->vp_strvalue, REG_EXTENDED);
if (compare != 0) {
char buffer[256];
regerror(compare, ®, buffer, sizeof(buffer));
RDEBUG("Invalid regular expression %s: %s", check->vp_strvalue, buffer);
return -2;
}
compare = regexec(®, value, REQUEST_MAX_REGEX + 1, rxmatch, 0);
regfree(®);
ret = (compare != 0) ? 0 : -1;
}
#endif
/*
* Attributes must be of the same type.
*
* FIXME: deal with type mismatch properly if one side contain
* ABINARY, OCTETS or STRING by converting the other side to
* a string
*
*/
if (vp->da->type != check->da->type) return -1;
/*
* Tagged attributes are equal if and only if both the
* tag AND value match.
*/
if (check->da->flags.has_tag) {
ret = ((int) vp->tag) - ((int) check->tag);
if (ret != 0) goto finish;
}
/*
* Not a regular expression, compare the types.
*/
switch(check->da->type) {
//.........这里部分代码省略.........
开发者ID:kcnwogu,项目名称:freeradius-server,代码行数:101,代码来源:valuepair.c
示例12: memset
time_t CDBThread::Datetime2time_t(int fmt, char* str)
{
static char *ptmFmt1 = "([0-9]{4})\\.([0-9]{2})\\.([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})"; //yyyy.mm.dd hh:mm:ss
static char *ptmFmt2 = "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})"; //yyyy-mm-dd hh:mm:ss
if(NULL == str || 0 == strlen(str)) return 0;
//使用正则表达式
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
regex_t tmFmtReg;
int ii = 1;
bool parseOK = true;
int iRet = -1;;
if(fmt == 1)
{
iRet = regcomp(&tmFmtReg, ptmFmt1, REG_EXTENDED);
}
else if(fmt == 2)
{
iRet = regcomp(&tmFmtReg, ptmFmt2, REG_EXTENDED);
}
if(iRet >= 0)
{
regmatch_t match[8];
size_t matchLen = 0;
char resultBuf[8] = {0};
iRet = regexec(&tmFmtReg, str, 8, &match[0], 0);
if(0 == iRet)
{
for(;ii < 8; ++ii)
{
if(match[ii].rm_so >= 0)
{
memset(resultBuf, 0, sizeof(resultBuf));
memcpy(resultBuf, str+match[ii].rm_so, match[ii].rm_eo - match[ii].rm_so);
switch(ii)
{
case 1:
//year
tm.tm_year=atoi(resultBuf);
if(tm.tm_year < 1900) parseOK = false;
else tm.tm_year -= 1900;
break;
case 2:
//month
tm.tm_mon=atoi(resultBuf);
if(tm.tm_mon < 0 || tm.tm_mon > 11) parseOK = false;
else tm.tm_mon -= 1;
break;
case 3:
//day
tm.tm_mday=atoi(resultBuf);
if(tm.tm_mday < 1 || tm.tm_mday > 31) parseOK = false;
break;
case 4:
//hour
tm.tm_hour=atoi(resultBuf);
if(tm.tm_hour < 0 || tm.tm_hour > 23) parseOK = false;
break;
case 5:
//minute
tm.tm_min=atoi(resultBuf);
if(tm.tm_min < 0 || tm.tm_min > 59) parseOK = false;
break;
case 6:
//second
tm.tm_sec=atoi(resultBuf);
if(tm.tm_sec < 0 || tm.tm_sec > 59) parseOK = false;
break;
}
}
else
{
break;
}
}
}
else
{
//char errorbuf[256] = {0};
//regerror(iRet, &tmFmtReg, errorbuf, 256);
//printf("%s\n", errorbuf);
}
regfree(&tmFmtReg);
if(ii < 7 || !parseOK) return 0;
time_t ct;
ct = mktime(&tm);
return ct;
}
//////////////////////////////////////////////////
return 0;
}
开发者ID:cocti-zhonghao,项目名称:gx_missCallAlert,代码行数:94,代码来源:DBThread.cpp
示例13: ThreadRoutine
//.........这里部分代码省略.........
regex_t getFile;
regmatch_t matches[2];
char filename[BUFSIZE] = "\0";
FILE* temp;
struct stat st;
char tempStr[BUFSIZE] = "\0";
//ensure that request starts with / and not ..
QA( regcomp(&getFile, "^GET /(.+) HTTP/1\\.1", REG_EXTENDED | REG_ICASE) == 0 );
//receive data
n = recv(con.sock, buffer, BUFSIZE-1, 0);
QAP(n >= 0, "Error reading from socket.\n", NULL);
buffer[n] = '\0'; //make sure 0 is set at the end
//write to weblog
fputs("REMOTE ADDRESS: ", weblog);
fputs(inet_ntoa(con.from.sin_addr), weblog);
fputs("\n", weblog);
fputs(buffer, weblog);
fflush(weblog);
//get file info
regexec(&getFile, buffer, 2, matches, 0);
strncpy(filename, buffer + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
//handle "GET / HTTP/1.1"
if( strcmp(filename, "") == 0 )
{
sprintf(tempStr, "ls %s > .temp", filename);
system(tempStr);
strcpy(filename, ".temp");
}
//get file info
found = stat(filename, &st);
//build return header
strcpy(retMsg, "HTTP/1.1 ");
if( found == -1 )
{
strncat(retMsg, "404 NOT FOUND\r\n", BUFSIZE - strlen(retMsg));
strncat(retMsg, "Status: 404 NOT FOUND\r\n", BUFSIZE - strlen(retMsg));
strncat(retMsg, "\r\n", BUFSIZE - strlen(retMsg));
}
else
{
strncat(retMsg, "200 OK\r\n", BUFSIZE - strlen(retMsg));
strncat(retMsg, "Status: 200 OK\r\n", BUFSIZE - strlen(retMsg));
strncat(retMsg, "Content-length: ", BUFSIZE - strlen(retMsg));
sprintf(retMsg, "%s%u\r\n", retMsg, st.st_size);
strncat(retMsg, "Content-type: ", BUFSIZE - strlen(retMsg));
sprintf(retMsg, "%s%s\r\n", retMsg, "text/html");
strncat(retMsg, "\r\n", BUFSIZE - strlen(retMsg));
}
//send headers
n = send(con.sock, retMsg, strlen(retMsg), 0);
QAP(n == strlen(retMsg), "Error sending headers.\n", NULL);
//send body
if( found == 0 )
{
temp = fopen(filename, "r");
//send chunks at a time
while( !feof(temp) )
{
memset(retMsg, 0, BUFSIZE);
fread(retMsg, 1, BUFSIZE, temp);
n = send(con.sock, retMsg, strlen(retMsg), 0);
QAP(n == strlen(retMsg), "Error sending body.\n", NULL);
}
fclose(temp);
}
else
{
//print a text body for the user
strcpy(retMsg, "404 File not found");
n = send(con.sock, retMsg, strlen(retMsg), 0);
QAP(n == strlen(retMsg), "Error sending body.\n", NULL);
}
//delete .temp file
if( strcmp(filename, ".temp") )
{
system("rm .temp");
}
//close the connection
close(con.sock);
regfree(&getFile);
free(arg);
return 0;
}
开发者ID:Sjokie,项目名称:WebClientServer-V1.1,代码行数:101,代码来源:webserver.c
示例14: insert_diffs
//.........这里部分代码省略.........
goto end;
regex_inited = true;
size_t line_sz;
for (;;) {
errno = 0;
ssize_t r = getline(&line, &line_sz, in);
if (r < 0) {
ret = -errno;
if (feof(in))
break;
goto end;
}
regmatch_t match[3];
if (regexec(&pick, line, sizeof match / sizeof match[0], match, 0) == 0) {
// this line is a commit
assert(match[2].rm_so != -1);
// Lop off the newline if there is one
if (line[r - 1] == '\n')
r--;
// Write the line with a Vim marker to indicate the start of a fold
if (fprintf(out, "%.*s {{{\n", (int)r, line) < 0) {
ret = -1;
goto end;
}
// Create a Git command to get a diff of this commit
char *command;
if (asprintf(&command, "git show %.*s", (int)(match[2].rm_eo - match[2].rm_so),
&line[match[2].rm_so]) < 0) {
ret = -ENOMEM;
goto end;
}
// Retrieve the diff and write it to the output
errno = 0;
FILE *pipe = popen(command, "r");
if (pipe == NULL)
ret = errno == 0 ? -ENOMEM : -errno;
free(command);
if (ret != 0)
goto end;
char *l = NULL;
size_t l_sz;
for (;;) {
errno = 0;
if (getline(&l, &l_sz, pipe) < 0) {
ret = -errno;
if (feof(pipe))
break;
free(l);
pclose(pipe);
goto end;
}
if (fprintf(out, " # %s", l) < 0) {
ret = -1;
free(l);
pclose(pipe);
goto end;
}
}
free(l);
int status = pclose(pipe);
if (status == -1) {
ret = -1;
goto end;
}
if (WEXITSTATUS(status) != EXIT_SUCCESS) {
ret = WEXITSTATUS(status);
goto end;
}
// write a fold close marker
if (fputs(" # }}}\n", out) < 0) {
ret = -1;
goto end;
}
} else {
// normal line; write it out as-is
size_t w = fwrite(line, 1, (size_t)r, out);
if (w != (size_t)r) {
ret = -1;
goto end;
}
}
}
end:
free(line);
if (regex_inited)
regfree(&pick);
return ret;
}
开发者ID:Smattr,项目名称:mattutils,代码行数:101,代码来源:rerebase.c
示例15: virStringSearch
/**
* virStringSearch:
* @str: string to search
* @regexp: POSIX Extended regular expression pattern used for matching
* @max_matches: maximum number of substrings to return
* @result: pointer to an array to be filled with NULL terminated list of matches
*
* Performs a POSIX extended regex search against a string and return all matching substrings.
* The @result value should be freed with virStringFreeList() when no longer
* required.
*
* @code
* char *source = "6853a496-1c10-472e-867a-8244937bd6f0
* 773ab075-4cd7-4fc2-8b6e-21c84e9cb391
* bbb3c75c-d60f-43b0-b802-fd56b84a4222
* 60c04aa1-0375-4654-8d9f-e149d9885273
* 4548d465-9891-4c34-a184-3b1c34a26aa8";
* char **matches = NULL;
* virStringSearch(source,
* "([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})",
* 3,
* &matches);
*
* // matches[0] == "6853a496-1c10-472e-867a-8244937bd6f0";
* // matches[1] == "773ab075-4cd7-4fc2-8b6e-21c84e9cb391";
* // matches[2] == "bbb3c75c-d60f-43b0-b802-fd56b84a4222"
* // matches[3] == NULL;
*
* virStringFreeList(matches);
* @endcode
*
* Returns: -1 on error, or number of matches
*/
ssize_t
virStringSearch(const char *str,
const char *regexp,
size_t max_matches,
char ***matches)
{
regex_t re;
regmatch_t rem;
size_t nmatches = 0;
ssize_t ret = -1;
int rv = -1;
*matches = NULL;
VIR_DEBUG("search '%s' for '%s'", str, regexp);
if ((rv = regcomp(&re, regexp, REG_EXTENDED)) != 0) {
char error[100];
regerror(rv, &re, error, sizeof(error));
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Error while compiling regular expression '%s': %s"),
regexp, error);
return -1;
}
if (re.re_nsub != 1) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Regular expression '%s' must have exactly 1 match group, not %zu"),
regexp, re.re_nsub);
goto cleanup;
}
/* '*matches' must always be NULL terminated in every iteration
* of the loop, so start by allocating 1 element
*/
if (VIR_EXPAND_N(*matches, nmatches, 1) < 0)
goto cleanup;
while ((nmatches - 1) < max_matches) {
char *match;
if (regexec(&re, str, 1, &rem, 0) != 0)
break;
if (VIR_EXPAND_N(*matches, nmatches, 1) < 0)
goto cleanup;
if (VIR_STRNDUP(match, str + rem.rm_so,
rem.rm_eo - rem.rm_so) < 0)
goto cleanup;
VIR_DEBUG("Got '%s'", match);
(*matches)[nmatches-2] = match;
str = str + rem.rm_eo;
}
ret = nmatches - 1; /* don't count the trailing null */
cleanup:
regfree(&re);
if (ret < 0) {
virStringFreeList(*matches);
*matches = NULL;
}
return ret;
//.........这里部分代码省略.........
开发者ID:AGSaidi,项目名称:hacked-libvirt,代码行数:101,代码来源:virstring.c
示例16: regex_find_jobids
static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1,
const char *query2, const char *type)
{
dlist *item_chain;
uitem *item = NULL;
uitem *last_item = NULL;
regex_t preg;
char prbuf[500];
int rc;
bool ok = false;
POOL_MEM query(PM_MESSAGE);
item_chain = New(dlist(item, &item->link));
if (!jcr->job->selection_pattern) {
Jmsg(jcr, M_FATAL, 0, _("No %s %s selection pattern specified.\n"),
jcr->get_OperationName(), type);
goto bail_out;
}
Dmsg1(dbglevel, "regex-sel-pattern=%s\n", jcr->job->selection_pattern);
/* Basic query for names */
Mmsg(query, query1, jcr->rpool->name());
Dmsg1(dbglevel, "get name query1=%s\n", query.c_str());
if (!db_sql_query(jcr->db, query.c_str(), unique_name_handler,
(void *)item_chain)) {
Jmsg(jcr, M_FATAL, 0,
_("SQL to get %s failed. ERR=%s\n"), type, db_strerror(jcr->db));
goto bail_out;
}
Dmsg1(dbglevel, "query1 returned %d names\n", item_chain->size());
if (item_chain->size() == 0) {
Jmsg(jcr, M_INFO, 0, _("Query of Pool \"%s\" returned no Jobs to %s.\n"),
jcr->rpool->name(), jcr->get_ActionName(0));
ok = true;
goto bail_out; /* skip regex match */
} else {
/* Compile regex expression */
rc = regcomp(&preg, jcr->job->selection_pattern, REG_EXTENDED);
if (rc != 0) {
regerror(rc, &preg, prbuf, sizeof(prbuf));
Jmsg(jcr, M_FATAL, 0, _("Could not compile regex pattern \&
|
请发表评论