Beispiel #1
0
static void convert_lines(prescanner_t* prescanner)
{
    // INCLUDE stuff
	regex_t match_include_directive;
	// It is enough with 2
	regmatch_t sub_matching[2];

    int code;
	if ((code = regcomp(&match_include_directive, INCLUDE_DIRECTIVE_REGEX, REG_EXTENDED | REG_ICASE)) != 0)
	{
		char error_message[120];
		regerror(code, &match_include_directive, error_message, 120);
		internal_error("Error when compiling regular expression (%s)\n", error_message);
	}

	// This is a global variable with local scope
	static language_level next = LANG_TOP_LEVEL;
	line_t* iter = file_lines;

	while (iter != NULL)
	{
		if (regexec(&match_include_directive, iter->line, 2, sub_matching, 0) == 0)
		{
            handle_include_line(prescanner, iter, sub_matching);
        }
        else
        {
            next = convert_line(prescanner, next, &iter->line, iter->line_number);
        }
        iter = iter->next;
	}
}
Beispiel #2
0
static int phrase_score_file (char *file, FILE *fp, Score_Context_Type *c,
			      unsigned int *linenum,
			      PScore_Regexp_Type *sub_psrt)
{
    char line[1024];
    PScore_Regexp_Type *psrt;

    char *description = NULL;
    
    while (fgets (line, sizeof (line) - 1, fp))
     {
	unsigned char *lp;
	int ret, not_flag;
	
	(*linenum)++;

	psrt = NULL;
	
	if (0 == SLprep_line_ok (line, &c->pt))
	  continue;

	lp = (unsigned char *) slrn_skip_whitespace (line);
	if ((*lp == '#') || (*lp == '%') || (*lp <= ' ')) continue;

	if (sub_psrt == NULL)
	  {
	     if ((0 == slrn_case_strncmp (lp, (unsigned char *) "include", 7))
		 && ((lp[7] == ' ') || (lp[7] == '\t')))
	       {
		  if (0 == handle_include_line (file, (char *)lp + 7, c))
		    continue;
		  
		  score_error (_("Error handling INCLUDE line"), line, *linenum,
			       file);
		  slrn_free (description);
		  return -1;
	       }
	     
	     if (*lp == '[')
	       {
		  unsigned char *g, *gmax, ch;
		  g = c->group;
		  gmax = g + sizeof (c->group);
		  
		  lp++;
		  lp = (unsigned char *) slrn_skip_whitespace ((char *)lp);
		  
		  c->gnt_not_flag = 0;
		  if (*lp == '~')
		    {
		       c->gnt_not_flag = 1;
		       lp = (unsigned char *) slrn_skip_whitespace ((char *)lp + 1);
		    }
		  
		  while (((ch = *lp++) != 0)
			 && (ch != ']') && (g < gmax))
		    *g++ = ch;
		  
		  if ((ch != ']') || (g == gmax))
		    {
		       score_error (_("Syntax Error."), line, *linenum, file);
		       slrn_free (description);
		       return -1;
		    }
		  *g = 0;
		  c->start_new_group = 1;
		  c->score_has_expired = 0;
		  c->start_new_score = 0;
		  continue;
	       }
        
	     if (!slrn_case_strncmp (lp, (unsigned char *)"Score:", 6))
	       {
		  unsigned char *lpp = lp + 6, *eol;
		  c->pscore_flags = 0;
		  if (*lpp == ':')
		    {
		       lpp++;
		       c->pscore_flags |= SCORE_IS_OR_TYPE;
		    }
		  lpp = (unsigned char *) slrn_skip_whitespace ((char *) lpp);
		  if (*lpp == '=')
		    {
		       c->pscore_flags |= RETURN_THIS_SCORE;
		       lpp++;
		    }
		  c->score = atoi ((char *)lpp);
		  c->start_new_score = 1;

                  if (description != NULL)
		    {
		       slrn_free (description);
		       description = NULL;
		    }
                  eol = (unsigned char *) slrn_strchr ((char *)lpp, '#');
		  if (eol == NULL)
		    lpp = (unsigned char *) slrn_strchr ((char *)lpp, '%');
		  else lpp = eol;
                  if (lpp != NULL)
		    {
		       lpp = (unsigned char *) slrn_skip_whitespace ((char *)lpp + 1);
		       eol = lpp + strlen ((char*)lpp) - 1;
		       while ((eol >= lpp) && (*eol <= 32))
			 *eol-- = '\0';
		       description = slrn_safe_strmalloc ((char *)lpp);
		    }

		  continue;
	       }
	     
	     if (c->start_new_score)
	       {
		  if (!slrn_case_strncmp (lp, (unsigned char *) "Expires:", 8))
		    {
		       ret = has_score_expired (lp + 8, c->today);
		       if (ret == -1)
			 {
			    score_error (_("Expecting 'Expires: MM/DD/YYYY' or 'Expires: DD-MM-YYYY'"),
					 line, *linenum, file);
			    slrn_free (description);
			    return -1;
			 }
		       if (ret)
			 {
			    slrn_message (_("%s has expired score on line %d"),
					  file, *linenum);
#ifndef SLRNPULL_CODE
			    Slrn_Saw_Warning = 1;
#endif
			    c->start_new_score = 0;
			    c->score_has_expired = 1;
			 }
		       else c->score_has_expired = 0;
		       continue;
		    }
		  
		  if (NULL == (c->pst = create_new_score (c->group, c->start_new_group, c->gnt_not_flag,
							  c->score, c->pscore_flags,
                                                          file, *linenum, description)))
		    {
		       score_error (_("Bad group regular expression."), line,
				    *linenum, file);
		       slrn_free (description);
		       return -1;
		    }
		  c->start_new_group = 0;
		  c->start_new_score = 0;
		  c->score_has_expired = 0;

                  if (description != NULL)
		    {
		       slrn_free (description);
		       description = NULL;
		    }
	       }
	     
	     if (c->score_has_expired) continue;
	     
	     if (c->pst == NULL)
	       {
		  score_error (_("Expecting Score keyword."), line, *linenum, file);
		  return -1;
	       }
	     
	  } /*if (sub_psrt==null) */
	
	slrn_free (description);
	
	if (*lp == '~')
	  {
	     not_flag = 1;
	     lp++;
	  }
	else not_flag = 0;

	ret = -1;
	psrt = (PScore_Regexp_Type *) slrn_safe_malloc (sizeof (PScore_Regexp_Type));
	/* Otherwise the line is a kill one */
	if (!slrn_case_strncmp (lp, (unsigned char *)"Subject:", 8))
	  ret = add_group_regexp (psrt, lp + 7, lp, SCORE_SUBJECT, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"From:", 5))
	  ret = add_group_regexp (psrt, lp + 4, lp, SCORE_FROM, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Xref:", 5))
	  ret = add_group_regexp (psrt, lp + 4, lp, SCORE_XREF, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Newsgroup:", 10))
	  ret = add_group_regexp (psrt, lp + 9, lp, SCORE_NEWSGROUP, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"References:", 11))
	  ret = add_group_regexp (psrt, lp + 10, lp, SCORE_REFERENCES, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Lines:", 6))
	  ret = add_group_regexp (psrt, lp + 5, lp, SCORE_LINES, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Date:", 5))
	  ret = add_group_regexp (psrt, lp + 4, lp, SCORE_DATE, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Age:", 4))
	  ret = add_group_regexp (psrt, lp + 3, lp, SCORE_AGE, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Bytes:", 6))
	  ret = add_group_regexp (psrt, lp + 5, lp, SCORE_BYTES, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Has-Body:", 9))
	  ret = add_group_regexp (psrt, lp + 8, lp, SCORE_HAS_BODY, not_flag);
	else if (!slrn_case_strncmp (lp, (unsigned char *)"Message-Id:", 11))
	  ret = add_group_regexp (psrt, lp + 10, lp, SCORE_MESSAGE_ID, not_flag);
        else if (!slrn_case_strncmp (lp, (unsigned char *)"{:", 2))
	  {
            if (lp[2] ==':')
	      {
		ret = add_group_regexp (psrt, lp + 1, lp, SCORE_SUB_OR, not_flag);
	      }
	    else
	      {
		ret = add_group_regexp (psrt, lp + 1, lp, SCORE_SUB_AND, not_flag);
	      }
	    if (phrase_score_file(file, fp, c, linenum, psrt))  return -1;
          }
        else if (!slrn_case_strncmp (lp, (unsigned char *)"}", 1))
	  {
	     SLFREE (psrt);
	     if (sub_psrt != NULL)
	       return 0;
	     else
	       {
		  score_error (_("Missing COLON."), line, *linenum, file);
		  return -1;
	       }
	  }
	else
	  {
	     unsigned char *lpp = lp;
	     while (*lpp && (*lpp != ':')) lpp++;
	     if (*lpp != ':')
	       {
		  SLFREE (psrt);
		  score_error (_("Missing COLON."), line, *linenum, file);
		  return -1;
	       }
	     
	     ret = add_group_regexp (psrt, lpp, lp, SCORE_GENERIC, not_flag);
	  }
	
	if (ret == -1)
	  {
	     score_error (_("No regular expression given."), line, *linenum, file);
	     return -1;
	  }
	
	if (sub_psrt == NULL)
	  {
	     if (c->pst->pregexp_list == NULL)
	       {
		  c->pst->pregexp_list = psrt;
	       }
	     else
	       {
		  PScore_Regexp_Type *last = c->pst->pregexp_list;
		  while (last->next != NULL) last = last->next;
		  last->next = psrt;
	       }
	  }
	else
	  {
	     if (sub_psrt->ireg.psrt == NULL)
	       {
		  sub_psrt->ireg.psrt = psrt;
	       }
	     else
	       {
		  PScore_Regexp_Type *last = sub_psrt->ireg.psrt;
		  while (last->next != NULL) last = last->next;
		  last->next = psrt;
	       }
	  }
     } /*while (fgets (line, sizeof (line) - 1, fp))*/

   if (sub_psrt == NULL) return 0;
   else
     {
	score_error (_("Missing '}' for  subscore"), line, *linenum, file);
	return -1;
     }
}