Ejemplo n.º 1
0
Archivo: fmt.c Proyecto: alhazred/onarm
/*
 * header_chk -
 * Called when done looking for a set mail header lines.
 * Either a blank line was seen, or EOF was reached.
 *
 * Verifies if current hdrbuf of potential mail header lines
 * is really a mail header.  A mail header must be at least 2
 * lines and more than half of them must start with one of the
 * known mail header strings in headnames.
 *
 * header_chk sets hdr_state to do_hdr if hdrbuf contained a valid
 * mail header.  Otherwise, it sets hdr_state to flush_hdr.
 *
 * h_lines = hdrbuf index for next line to be saved;
 *	     also indicates current # of lines in potential header
 */
static void
header_chk(void)
{
	wchar_t  *cp; 		/* ptr to current char of line */
	wchar_t **hp; 		/* ptr to current char of a valid */
				/* mail header string */
	int	  l;		/* index */
				/*
				 * number of lines in hdrbuf that look
				 * like mail header lines (start with
				 * a known mail header prefix)
				 */
	int	 hdrcount = 0;
		/* header must have at least 2 lines (h_lines > 1) */
		if (h_lines < 2) {
			hdr_state = flush_hdr;
			return;
		}
		/*
		 * go through each line in hdrbuf and see how many
		 * look like mail header lines
		 */
		for (l = 0; l < h_lines; l++) {
			/* skip initial blanks */
			for (cp = hdrbuf[l]; *cp == L' '; cp++);
			for (hp = &headnames[0]; *hp != (wchar_t *)0; hp++)
				if (ispref(*hp, cp)) {
					hdrcount++;
					break;
				}
		}
		/*
		 * if over half match, we'll assume this is a header;
		 * set hdr_state to indicate whether to treat
		 * these lines as mail header (do_hdr) or not (flush_hdr)
		 */
		if (hdrcount > h_lines / 2)
			hdr_state = do_hdr;
		else
			hdr_state = flush_hdr;
}
Ejemplo n.º 2
0
int *prepare_str_UTF8 (int *x) {
  int *v = prep_ibuf;

  int i, n;
  for (i = 0; x[i]; i++) {
    v[i] = convert_prep (x[i]);
  }

  int j = 0;
//  yo, jo -> e
/*  for (i = 0; v[i]; i++) {
    if ((v[i] == 'y' || v[i] == 'j') && v[i + 1] == 'o') {
      v[j++] = 'e'; i++;
    } else {
      v[j++] = v[i];
    }
  }
  v[j] = 0;
  i = j;
  j = 0;*/

  n = i;
  for (i = 0; v[i] == ' '; i++) {
  }

  int k = 0;
  while (i < n) {
    words_ibuf[k++] = v + i;
    while (v[i] && v[i] != ' ') {
      i++;
    }
    while (v[i] == ' ') {
      i++;
    }
  }
  v[n] = ' ';

  j = 0;
  qsort (words_ibuf, k, sizeof (int *), stricmp_void);

  for (i = 0; i < k; i++) {
    if (i == 0 || !ispref (words_ibuf[j - 1], words_ibuf[i])) {
      words_ibuf[j++] = words_ibuf[i];
    } else {
      words_ibuf[j - 1] = words_ibuf[i];
    }
  }
  k = j;

  int *res = prep_ibuf_res;
  for (i = 0; i < k; i++) {
    int *tmp = words_ibuf[i];
    while (*tmp != ' ') {
      *res++ = *tmp++;
    }
    *res++ = '+';
  }
  *res++ = 0;

  assert (res - prep_ibuf_res < MAX_NAME_SIZE);
  return prep_ibuf_res;
}