Ejemplo n.º 1
0
static int compile_psrt (PScore_Regexp_Type *psrt, Score_Regexp_Type *srt,
			 int *generic)
{
   SLRegexp_Type *re;

   while (psrt != NULL)
     {
        unsigned int flags = psrt->flags;

        if (SCORE_GENERIC == (srt->header_type = psrt->header_type))
          {
             *generic += 1;
	     slrn_request_additional_header (psrt->keyword,
					     Slrn_Perform_Scoring & SLRN_EXPENSIVE_SCORING);
          }
	
        srt->not_flag = (0 != (flags & NOT_FLAG));
	  
	if ((srt->header_type == SCORE_SUB_AND) || 
		(srt->header_type == SCORE_SUB_OR))
	  {
             srt->search.srt = (Score_Regexp_Type *) slrn_malloc (sizeof (Score_Regexp_Type), 1, 0);
             if (srt->search.srt == NULL) return -1;

	     if (compile_psrt(psrt->ireg.psrt, srt->search.srt, generic) != 0)
	       return -1;
          }
	else
	  {
             srt->generic_keyword = psrt->keyword;

	     if (flags & USE_INTEGER)
               {
                  srt->search.ival = psrt->ireg.ival;
               }
             else
               {
                  re = &srt->search.re.regexp;
                  re->pat = psrt->ireg.regexp_str;
                  re->buf = srt->search.re.buf;
                  re->buf_len = sizeof (srt->search.re.buf);
                  re->case_sensitive = 0;

                  if (0 != SLang_regexp_compile(re))
                    {
                       return -1;
                    }

                  /* If an ordinary search is ok, use it. */
                  if (re->osearch)
                    {
                       srt->do_osearch = 1;
                       SLsearch_init ((char *) psrt->ireg.regexp_str, 1, 0, &srt->search.se);
                    }
               }
          }
		
        psrt = psrt->next;
        if (psrt == NULL) break;

        srt->next = (Score_Regexp_Type *) slrn_malloc (sizeof (Score_Regexp_Type), 1, 0);
        if (NULL == (srt = srt->next)) return -1;
     } /* while (psrt != NULL)*/
   return 0;
}
Ejemplo n.º 2
0
static int compile_group_names (char *group, Group_Score_Type *gst)
{
   char *comma;
   Group_Score_Name_Type *gsnt;
   unsigned int num_processed = 0;
   
   gsnt = &gst->gsnt;
   
   comma = group;
   while (comma != NULL)
     {
	SLRegexp_Type *re;
	
	group = slrn_skip_whitespace (group);
	
	comma = slrn_strchr ((char *) group, ',');
	if (comma != NULL) 
	  {
	     *comma++ = 0;
	     
	     while (1)
	       {
		  comma = slrn_skip_whitespace (comma);
		  if (*comma == 0)
		    {
		       comma = NULL;
		       break;
		    }
		  if (*comma != ',')
		    break;
		  comma++;
	       }
	  }
	
	(void) slrn_trim_string (group);
	if (*group == 0) continue;
	
	strncpy (gsnt->name, group, MAX_GROUP_NAME_LEN - 1);
	/* Note: because of the memset, this string is null terminated. */
   
	re = &gsnt->group_regexp;
	re->pat = (unsigned char *) slrn_fix_regexp ((char *)group);
	re->buf = gsnt->buf;
	re->buf_len = MAX_GROUP_REGEXP_SIZE;
	re->case_sensitive = 0;
	if (0 != SLang_regexp_compile (re))
	  {
	     return -1;
	  }
	
	if (comma != NULL)
	  {
	     Group_Score_Name_Type *gsnt1;
	     
	     gsnt1 = (Group_Score_Name_Type *) slrn_safe_malloc (sizeof (Group_Score_Name_Type));
	     
	     gsnt->next = gsnt1;
	     gsnt = gsnt1;
	     group = comma;
	  }
	num_processed++;
     }
   if (num_processed) return 0;
   return -1;
}
Ejemplo n.º 3
0
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;
}