Exemplo n.º 1
0
Arquivo: hmine.c Projeto: arekfu/dbacl
void hprocess_file(FILE *input, HEADER_State *head) {
  char *pptextbuf = NULL;
  bool_t in_header = 1;
  int extra_lines = 0;
  hline_t *h = NULL;

  set_iobuf_mode(input);
  inputline = 0;

  /* now start processing */
  while( fill_textbuf(input, &extra_lines) ) {
    inputline++;

    if( u_options & (1<<U_OPTION_FILTER) ) {
	fprintf(stdout, "%s", textbuf);
    }

    if( in_header ) {
      if( (textbuf[0] == '\0') || 
	  (textbuf[0] == '\n') ||
	  ((textbuf[0] == '\r') && (textbuf[1] == '\n')) ) {
	in_header = 0;
      } else {
	if( pptextbuf && !isblank(*textbuf) ) {
	  h = head_push_header(head, pptextbuf);
	}
	pptextbuf = head_append_hline(head, textbuf);
      }
    } else {
      /* body of email */
    }


  }
}
Exemplo n.º 2
0
/* reads a text file as input, and applies several
   filters. */
void b_process_file(FILE *input, 
		  void (*line_fun)(void)) {
  category_count_t i;
  RegMatch *r;
  regmatch_t pmatch[MAX_SUBMATCH];
  submatch_order_t z;
  int extra_lines = 2;

  /* now start processing */
  while( fill_textbuf(input, &extra_lines) ) {

    /* now summarize this line if required */
    if( line_fun ) { (*line_fun)(); }


    if( (textbuf[0] == '#') && 
	(strncmp(MAGIC, textbuf, 7) == 0) ) {
      if( !parse_dbacl_scores(textbuf) ) {
	errormsg(E_FATAL,"scores don't match risk specification\n");
      } else if( options & (1<<OPTION_DEBUG) ) {
	for(i = 0; i < spec.num_cats; i++) {
	  fprintf(stdout, 
		  "category %s\t cross_entropy %7.2f complexity %7.0f\n",
		  spec.catname[i], spec.cross_entropy[i], spec.complexity[i]);
	}
	fprintf(stdout, "\n");
      }
    } else {
      /* for each regex in our list, try for a match */
      for( r = spec.regs; r != 0; r = r->next) {
	if( regexec(&(r->reg), textbuf, MAX_SUBMATCH, pmatch, 0) == 0 ) {
	  r->lv->found = 1;
	  /* convert each submatch to a number - pad remaining
	     elements to zero */
	  for(z = 1; z < MAX_SUBMATCH; z++) {
	    if(pmatch[z].rm_so > -1) {
	      r->lv->sm[z-1] = strtod(textbuf + pmatch[z].rm_so, NULL);
	    } else {
	      r->lv->sm[z-1] = 0.0;
	    }
	  }

	  if( options & (1<<OPTION_DEBUG) ) {
	    fprintf(stdout, 
		    "match \"%s\"", r->lv->re);
	    for(z = 1; (z < MAX_SUBMATCH) && (pmatch[z].rm_so > -1); z++) {
	      fprintf(stdout,
		      " %f", r->lv->sm[z-1]);
	    }
	    fprintf(stdout, "\n");
	  }
	}
      }
    }

  }
}
Exemplo n.º 3
0
/* call this as: cat sample.headers.2822.good | pcheck 2822 good */
int main(int argc, char **argv) {
  options_t mask = 0;
  hline_count_t i = 0;

  char *pptextbuf = NULL;
  int extra_lines = 0;
  hline_t *h = NULL;

#if defined(HAVE_GETPAGESIZE)
  system_pagesize = getpagesize();
#endif
  if( system_pagesize == -1 ) { system_pagesize = BUFSIZ; }

  init_buffers();
  init_head_filter(&head);
  set_iobuf_mode(stdin);

/*   u_options |= (1<<U_OPTION_DEBUG); */

  /* now start processing */
  while( fill_textbuf(stdin, &extra_lines) ) {
      if( (textbuf[0] == '\0') || 
	  (textbuf[0] == '\n') ||
	  ((textbuf[0] == '\r') && (textbuf[1] == '\n')) ) {
	break;
      } else {
	if( pptextbuf && !isblank(*textbuf) ) {
	  pptextbuf = head_append_hline(&head, textbuf);
	  h = head_push_header(&head, pptextbuf);
	}
      }
  }

  if( (argc < 2) ) {
    fprintf(stdout, "missing arguments.\n");
    return 1;
  }
  if( strcmp(argv[1], "821") == 0 ) {
    mask |= (1<<H_STATE_RFC821);
  } else if( strcmp(argv[1], "822") == 0 ) {
    mask |= (1<<H_STATE_RFC822);
  } else if( strcmp(argv[1], "2822") == 0 ) {
    mask |= (1<<H_STATE_RFC2822)|(1<<H_STATE_RFC2822obs);
  } else if( strcmp(argv[1], "2821") == 0 ) {
    mask |= (1<<H_STATE_RFC2821);
  }

  if( !mask ) {
    fprintf(stdout, "bad mask.\n");
    return 1;
  }

  if( strcmp(argv[2], "good") == 0 ) {
    for(i = 0; i < head.hstack.top; i++) {
      if( !(head.hstack.hlines[i].state & mask) ) {
	fprintf(stdout, "incorrectly parsed %dth header\n", i+1);
	return 1;
      }
    }
    return 0;
  } else {
    for(i = 0; i < head.hstack.top; i++) {
      if( head.hstack.hlines[i].state & mask ) {
	fprintf(stdout, "incorrectly parsed %d'th header\n", i+1);
	return 1;
      }
    }
    return 0;
  }

  return 1;
}