/*---------------------------------------------------------------------------*/ static void hao_message(char *buf) { char work[HAO_WKLEN]; regmatch_t rm; int i; /* copy and strip spaces */ hao_cpstrp(work, buf); /* strip the herc prefix */ while(!strncmp(work, "herc", 4)) hao_cpstrp(work, &work[4]); /* Ignore the message if we should (e.g. if one of our own!) */ if (hao_ignoremsg( work )) return; /* serialize */ obtain_lock(&ao_lock); /* check all defined rules */ for(i = 0; i < HAO_MAXRULE; i++) { if(ao_tgt[i] && ao_cmd[i]) /* complete rule defined in this slot? */ { /* does this rule match our message? */ if(!regexec(&ao_preg[i], work, 1, &rm, 0)) { /* issue command for this rule */ WRMSG(HHC00081, "I", i, ao_cmd[i]); panel_command(ao_cmd[i]); } } } release_lock(&ao_lock); }
/*---------------------------------------------------------------------------*/ static void hao_message(char *buf) { char work[HAO_WKLEN]; char cmd[HAO_WKLEN]; regmatch_t rm[HAO_MAXCAPT+1]; int i, j, k, numcapt; size_t n; char *p; /* copy and strip spaces */ hao_cpstrp(work, buf); /* strip the herc prefix */ while(!strncmp(work, "herc", 4)) hao_cpstrp(work, &work[4]); /* Ignore the message if we should (e.g. if one of our own!) */ if (hao_ignoremsg( work )) return; /* serialize */ obtain_lock(&ao_lock); /* check all defined rules */ for(i = 0; i < HAO_MAXRULE; i++) { if(ao_tgt[i] && ao_cmd[i]) /* complete rule defined in this slot? */ { /* does this rule match our message? */ if (regexec(&ao_preg[i], work, HAO_MAXCAPT+1, rm, 0) == 0) { /* count the capturing group matches */ for (j = 0; j <= HAO_MAXCAPT && rm[j].rm_so >= 0; j++); numcapt = j - 1; /* copy the command and process replacement patterns */ for (n=0, p=ao_cmd[i]; *p && n < sizeof(cmd)-1; ) { /* replace $$ by $ */ if (*p == '$' && p[1] == '$') { cmd[n++] = '$'; p += 2; continue; } /* replace $` by characters to the left of the match */ if (*p == '$' && p[1] == '`') { n += hao_subst(work, 0, rm[0].rm_so, cmd, n, sizeof(cmd)); p += 2; continue; } /* replace $' by characters to the right of the match */ if (*p == '$' && p[1] == '\'') { n += hao_subst(work, rm[0].rm_eo, strlen(work), cmd, n, sizeof(cmd)); p += 2; continue; } /* replace $1..$99 by the corresponding capturing group */ if (*p == '$' && isdigit(p[1])) { if (isdigit(p[2])) { j = (p[1]-'0') * 10 + (p[2]-'0'); k = 3; } else { j = p[1]-'0'; k = 2; } if (j > 0 && j <= numcapt) { n += hao_subst(work, rm[j].rm_so, rm[j].rm_eo, cmd, n, sizeof(cmd)); p += k; continue; } } /* otherwise copy one character */ cmd[n++] = *p++; } cmd[n] = '\0'; /* issue command for this rule */ WRMSG(HHC00081, "I", i, cmd); panel_command(cmd); } } } release_lock(&ao_lock); }