/* returns 1 on match 0 if failed */ static int match_srt (Slrn_Header_Type *h, Score_Regexp_Type *srt, char *newsgroup, int or_type) { char *s= NULL; int ival = 0; unsigned int len; while (srt != NULL) { switch (srt->header_type) { case SCORE_LINES: ival = h->lines; goto integer_compare; case SCORE_BYTES: ival = h->bytes; goto integer_compare; case SCORE_HAS_BODY: ival = (h->flags & HEADER_WITHOUT_BODY) ? 0 : 1; goto boolean_compare; case SCORE_SUBJECT: s = h->subject; break; case SCORE_FROM: s = h->from; break; case SCORE_DATE: s = h->date; break; case SCORE_AGE: ival = slrn_date_to_order_parm(h->date); goto integer_compare; case SCORE_MESSAGE_ID: s = h->msgid; break; case SCORE_XREF: s = h->xref; break; case SCORE_REFERENCES: s = h->refs; break; case SCORE_NEWSGROUP: s = newsgroup; break; case SCORE_GENERIC: s = slrn_extract_add_header (h, srt->generic_keyword); break; case SCORE_SUB_AND: if (match_srt(h, srt->search.srt, newsgroup, 0)) { /* sub matches */ if (srt->not_flag) { if (or_type) goto next_srt; return 0; } } else /* sub does not match */ { if (srt->not_flag == 0) { if (or_type) goto next_srt; return 0; } } if (or_type) return 1; goto next_srt; break; case SCORE_SUB_OR: if (match_srt(h, srt->search.srt, newsgroup, 1)) { /* sub matches */ if (srt->not_flag) { if (or_type) goto next_srt; return 0; } } else /* sub does not match */ { if (srt->not_flag == 0) { if (or_type) goto next_srt; return 0; } } if (or_type) return 1; goto next_srt; break; default: s = NULL; /* not supposed to happen */ } /*switch (srt->header_type)*/ if (s == NULL) { if (srt->not_flag) { /* Match */ if (or_type) return 1; goto next_srt; } /* Match failed */ if (or_type) goto next_srt; return 0; } len = strlen (s); if (srt->do_osearch) { SLsearch_Type *se = &srt->search.se; if ((len < (unsigned int) se->key_len) || (NULL == SLsearch ((unsigned char *) s, (unsigned char *) s + len, se))) { /* expr does not match */ if (srt->not_flag == 0) { if (or_type) goto next_srt; return 0; } } else if (srt->not_flag) { if (or_type) goto next_srt; return 0; } } else { SLRegexp_Type *re; re = &srt->search.re.regexp; if ((len < re->min_length) || (NULL == SLang_regexp_match ((unsigned char *)s, len, re))) { if (srt->not_flag == 0) { if (or_type) goto next_srt; return 0; } } else if (srt->not_flag) { if (or_type) goto next_srt; return 0; } } /* Get here if above matched */ if (or_type) return 1; srt = srt->next; continue; /* This is ugly but I am worried about speed. --- we only get * here for those headers that have integer values. */ integer_compare: if ((ival < srt->search.ival) == (srt->not_flag == 0)) { if (or_type) goto next_srt; return 0; } /* If we get here, the integer comparison matched. */ if (or_type) return 1; srt = srt->next; continue; boolean_compare: if ((ival != srt->search.ival) == (srt->not_flag == 0)) { if (or_type) goto next_srt; return 0; } if (or_type) return 1; next_srt: srt = srt->next; } /*while (srt != NULL)*/ if (or_type) return 0; else return 1; }
int slrn_open_score (char *group_name) { Group_Score_Type *gsc; unsigned int n; int generic; free_group_chain (); if (Slrn_Scorefile_Open != NULL) { slrn_message_now (_("Reloading score file ...")); if (-1 == slrn_read_score_file (Slrn_Scorefile_Open)) slrn_error (_("Error processing score file %s."), Slrn_Scorefile_Open); slrn_free (Slrn_Scorefile_Open); Slrn_Scorefile_Open = NULL; } if ((Slrn_Perform_Scoring == 0) || (Group_Score_Root == NULL)) { Slrn_Apply_Score = 0; return 0; } n = strlen (group_name); generic = 0; gsc = Group_Score_Root; while (gsc != NULL) { Group_Score_Name_Type *gsnt; int match; gsnt = &gsc->gsnt; match = 0; while ((gsnt != NULL) && (match == 0)) { SLRegexp_Type *re = &gsnt->group_regexp; match = ((re->min_length <= n) && (NULL != SLang_regexp_match ((unsigned char *) group_name, n, re))); gsnt = gsnt->next; } if (gsc->gst_not_flag) match = !match; if (match) { if (-1 == chain_group_regexp (gsc->pst, &generic)) { free_group_chain (); return -1; } } gsc = gsc->next; } if (Score_Root == NULL) return 0; Slrn_Apply_Score = 1; #ifndef SLRNPULL_CODE if (generic && (Slrn_Prefer_Head || (1 != Slrn_Server_Obj->sv_has_cmd("XHDR Path")))) slrn_open_suspend_xover (); #endif return 1; }
SLang_Array_Type *_SLnspace_apropos (SLang_NameSpace_Type *ns, char *pat, unsigned int what) { SLang_Array_Type *at; unsigned int table_size; SLang_Name_Type *t, **table; int num_matches; unsigned int i; SLRegexp_Type rexp; unsigned char rbuf[512]; unsigned int two; at = NULL; if ((ns == NULL) || ((table = ns->table) == NULL)) return NULL; memset ((char *) &rexp, 0, sizeof (SLRegexp_Type)); rexp.case_sensitive = 1; rexp.buf = rbuf; rexp.buf_len = sizeof (rbuf); rexp.pat = (unsigned char *)pat; if (0 != SLang_regexp_compile (&rexp)) { SLang_verror (SL_INVALID_PARM, "Invalid regular expression: %s", pat); return NULL; } table_size = ns->table_size; two = 2; while (two != 0) { two--; num_matches = 0; for (i = 0; i < table_size; i++) { t = table[i]; while (t != NULL) { unsigned int flags; char *name = t->name; switch (t->name_type) { case SLANG_GVARIABLE: flags = 8; break; case SLANG_ICONSTANT: case SLANG_DCONSTANT: case SLANG_RVARIABLE: case SLANG_IVARIABLE: flags = 4; break; case SLANG_INTRINSIC: case SLANG_MATH_UNARY: case SLANG_APP_UNARY: flags = 1; break; case SLANG_FUNCTION: flags = 2; break; default: flags = 0; break; } if ((flags & what) && (NULL != SLang_regexp_match ((unsigned char *)name, strlen (name), &rexp))) { if (at != NULL) { if (-1 == SLang_set_array_element (at, &num_matches, (VOID_STAR)&name)) goto return_error; } num_matches++; } t = t->next; } } if (at == NULL) { at = SLang_create_array (SLANG_STRING_TYPE, 0, NULL, &num_matches, 1); if (at == NULL) goto return_error; } } return at; return_error: SLang_free_array (at); return NULL; }