⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mhn.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
		    }		    if (!checksw) {			free (cp);			goto got_header;		    }		    if (ct -> c_digested) {			advise (NULLCP,				"message %s has multiple %s: fields (%s)",				ct -> c_file, MD5_FIELD,				dp = trimcpy (cp));			free (dp);			free (cp);			goto out;		    }		    ep = cp;		    while (isspace (*cp))			cp++;		    for (dp = index (cp, '\n'); dp; dp = index (dp, '\n'))			*dp++ = ' ';		    for (dp = cp + strlen (cp) - 1; dp >= cp; dp--)			if (!isspace (*dp))			    break;		    *++dp = '\0';		    if (debugsw)			fprintf (stderr, "%s: %s\n", MD5_FIELD, cp);		    if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) {			free (ep);			goto out;		    }		    for (dp = cp; *dp && !isspace (*dp); dp++)			continue;		    *dp = '\0';		    (void) readDigest (ct, cp);		    free (ep);		    ct -> c_digested++;		    goto got_header;		}#ifdef	notdef		if (uprf (name, XXX_FIELD_PRF))		    advise (NULLCP, "unknown field (%s) in message %s",			    name, ct -> c_file);		/* and fall... */#endif		while (state == FLDPLUS)		    state = m_getfld (state, name, buf, sizeof buf, in);got_header: ;		if (state != FLDEOF) {		    ct -> c_begin = ftell (in) + 1;		    continue;		}		/* else fall... */	    case BODY:	    case BODYEOF:		break;	    case FILEEOF:		ct -> c_begin = ftell (in);		break;	    case LENERR:	    case FMTERR:		adios (NULLCP, "message format error in component #%d",		       compnum);	    default:		adios (NULLCP, "getfld() returned %d", state);	}	break;    }    if (!ct -> c_ctline) {	if (toplevel < 0) {	    if (get_ctinfo ("message/rfc822", ct, 0) == NOTOK)		goto out;	    ct -> c_type = CT_MESSAGE;	    ct -> c_ctinitfnx = InitMessage;	}	else {	    if (get_ctinfo ("text/plain", ct, 0) == NOTOK)		goto out;	    ct -> c_type = CT_TEXT;	    ct -> c_ctinitfnx = InitText;	}    }    if (!ct -> c_ctlistfnx)	ct -> c_ctlistfnx = list_content;    if (!ct -> c_ctshowfnx)	ct -> c_ctshowfnx = show_content;    if (!ct -> c_ctstorefnx)	ct -> c_ctstorefnx = store_content;    if (!ct -> c_celine) {	ct -> c_encoding = CE_7BIT;	(void) Init7Bit (ct);    }    return ct;out:    free_content (ct);    return NULLCT;}/*  */static int  get_ctinfo (cp, ct, magic)char  *cp;register CT	ct;int	magic;{    int	    i = strlen (invo_name) + 2;    register char  *dp,		  **ap,		  **ep;    char    c;    register CI	    ci = &ct -> c_ctinfo;    cp = ct -> c_ctline = add (cp, NULLCP);    while (isspace (*cp))	cp++;    for (dp = index (cp, '\n'); dp; dp = index (dp, '\n'))	*dp++ = ' ';    for (dp = cp + strlen (cp) - 1; dp >= cp; dp--)	if (!isspace (*dp))	    break;    *++dp = '\0';    if (debugsw)	fprintf (stderr, "%s: %s\n", TYPE_FIELD, cp);    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)	return NOTOK;    for (dp = cp; istoken (*dp); dp++)	continue;    c = *dp, *dp = '\0';    ci -> ci_type = add (cp, NULLCP);    *dp = c, cp = dp;    if (!*ci -> ci_type) {	advise (NULLCP, "invalid %s: field in message %s (empty type)", 		TYPE_FIELD, ct -> c_file);	return NOTOK;    }    for (dp = ci -> ci_type; *dp; dp++)	if (isalpha(*dp) && isupper (*dp))	    *dp = tolower (*dp);    while (isspace (*cp))	cp++;    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)	return NOTOK;    if (*cp != '/') {	if (!magic)	    ci -> ci_subtype = add ("", NULLCP);	goto magic_skip;    }    cp++;    while (isspace (*cp))	cp++;    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)	return NOTOK;    for (dp = cp; istoken (*dp); dp++)	continue;    c = *dp, *dp = '\0';    ci -> ci_subtype = add (cp, NULLCP);    *dp = c, cp = dp;    if (!*ci -> ci_subtype) {	advise (NULLCP,		"invalid %s: field in message %s (empty subtype for \"%s\")",		TYPE_FIELD, ct -> c_file, ci -> ci_type);	return NOTOK;    }    for (dp = ci -> ci_subtype; *dp; dp++)	if (isalpha(*dp) && isupper (*dp))	    *dp = tolower (*dp);magic_skip: ;    while (isspace (*cp))	cp++;    if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)	return NOTOK;    ep = (ap = ci -> ci_attrs) + NPARMS;    while (*cp == ';') {	char   *vp,	       *up;	if (ap >= ep) {	    advise (NULLCP,		    "too many parameters in message %s's %s: field (%d max)",		    ct -> c_file, TYPE_FIELD, NPARMS);	    return NOTOK;	}	cp++;	while (isspace (*cp))	    cp++;	if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)	    return NOTOK;	if (*cp == 0) {	    advise (NULLCP,		    "extraneous trailing ';' in message %s's %s: parameter list",		    ct -> c_file, TYPE_FIELD);	    return OK;	}	for (dp = cp; istoken (*dp); dp++)	    if (isalpha(*dp) && isupper (*dp))		*dp = tolower (*dp);	for (up = dp; isspace (*dp); )	    dp++;	if (dp == cp || *dp != '=') {	    advise (NULLCP,		    "invalid parameter in message %s's %s: field\n%*.*sparameter %s (error detected at offset %d)",		    ct -> c_file, TYPE_FIELD, i, i, "", cp, dp - cp);	    return NOTOK;	}	vp = (*ap = add (cp, NULLCP)) + (up - cp);	*vp = '\0';	for (dp++; isspace (*dp); )	    dp++;	ci -> ci_values[ap - ci -> ci_attrs] = vp = *ap + (dp - cp);	if (*dp == '"') {	    for (cp = ++dp, dp = vp;;) {		switch (c = *cp++) {		    case '\0':bad_quote: ;		        advise (NULLCP,				"invalid quoted-string in message %s's %s: field\n%*.*s(parameter %s)",				ct -> c_file, TYPE_FIELD, i, i, "", *ap);			return NOTOK;		    case '\\':			*dp++ = c;			if ((c = *cp++) == '\0')			    goto bad_quote;			/* else fall... */		    default:    			*dp++ = c;    			continue;		    case '"':			*dp = '\0';			break;		}		break;	    }	}	else {	    for (cp = dp, dp = vp; istoken (*cp); cp++, dp++)		continue;	    *dp = '\0';	}	if (!*vp) {	    advise (NULLCP,		    "invalid parameter in message %s's %s: field\n%*.*s(parameter %s)",		    ct -> c_file, TYPE_FIELD, i, i, "", *ap);	    return NOTOK;	}	ap++;	while (isspace (*cp))	    cp++;	if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)	    return NOTOK;    }    if (magic && *cp == '<') {	if (ct -> c_id)	    free (ct -> c_id), ct -> c_id = NULL;	if (!(dp = index (ct -> c_id = ++cp, '>'))) {	    advise (NULLCP, "invalid ID in message %s", ct -> c_file);	    return NOTOK;	}		c = *dp, *dp = '\0';	if (*ct -> c_id)	    ct -> c_id = concat ("<", ct -> c_id, ">\n", NULLCP);	else	    ct -> c_id = NULL;	*dp++ = c, cp = dp;	while (isspace (*cp))	    cp++;    }    if (magic && *cp == '[') {	ct -> c_descr = ++cp;	for (dp = cp + strlen (cp) - 1; dp >= cp; dp--)	    if (*dp == ']')		break;	if (dp < cp) {	    advise (NULLCP, "invalid description in message %s", ct -> c_file);	    ct -> c_descr = NULL;	    return NOTOK;	}		c = *dp, *dp = '\0';	if (*ct -> c_descr)	    ct -> c_descr = concat (ct -> c_descr, "\n", NULLCP);	else	    ct -> c_descr = NULL;	*dp++ = c, cp = dp;	while (isspace (*cp))	    cp++;    }    if (*cp) {	if (magic)	    ci -> ci_magic = add (cp, NULLCP);	else	    advise (NULLCP,		    "extraneous information in message %s's %s: field\n%*.*s(%s)",		ct -> c_file, TYPE_FIELD, i, i, "", cp);    }    return OK;}/*  */static int  get_comment (ct, ap, istype)CT	ct;char  **ap;int	istype;{    register int    i;    register char  *bp,		   *cp;    char    c,	    buffer[BUFSIZ],	   *dp;    register CI	    ci = &ct -> c_ctinfo;    cp = *ap;    bp = buffer;    cp++;    for (i = 0;;) {	switch (c = *cp++) {	    case '\0':invalid: ;	        advise (NULLCP, "invalid comment in message %s's %s: field",			ct -> c_file, istype ? TYPE_FIELD : VRSN_FIELD);		return NOTOK;	    case '\\':		*bp++ = c;		if ((c = *cp++) == '\0')		    goto invalid;		*bp++ = c;		continue;	    case '(':		i++;		/* and fall... */    	    default:		*bp++ = c;		continue;	    case ')':		if (--i < 0)		    break;		*bp++ = c;		continue;	}	break;    }    *bp = '\0';    if (istype) {	if (dp = ci -> ci_comment) {	    ci -> ci_comment = concat (dp, " ", buffer, NULLCP);	    free (dp);	}	else	    ci -> ci_comment = add (buffer, NULLCP);    }    while (isspace (*cp))	cp++;    *ap = cp;    return OK;}/*  */#define	empty(s)	((s) ? (s) : "")static int  list_content (ct, toplevel)register CT	ct;int	toplevel;{    unsigned long size;    register char **ap,		  **ep;    char   *cp,	    buffer[BUFSIZ];    register CI	    ci = &ct -> c_ctinfo;    printf (toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : "     ",	    atoi (r1bindex (empty (ct -> c_file), '/')));    (void) sprintf (buffer, "%s/%s", empty (ci -> ci_type),		    empty (ci -> ci_subtype));    printf (LSTFMT2b, empty (ct -> c_partno), buffer);    size = ct -> c_cesizefnx && sizesw ? (*ct -> c_cesizefnx) (ct)				       : ct -> c_end - ct -> c_begin;    for (cp = " KMGT"; size > 9999; size >>= 10)	if (!*++cp)	    break;    switch (*cp) {        case ' ':	    if (size > 0 || ct -> c_encoding != CE_EXTERNAL)		printf (LSTFMT2c1, size);	    else		printf (LSTFMT2c4);	    break;	default:	    printf (LSTFMT2c2, size, *cp);	    break;	case '\0':	    printf (LSTFMT2c3);    }    if (ct -> c_descr) {	char   *dp;	dp = trimcpy (cp = add (ct -> c_descr, NULLCP));	free (cp);	printf (LSTFMT2d1, dp);	free (dp);    }    printf ("\n");    if (verbosw && ci -> ci_comment) {	char   *dp;	dp = trimcpy (cp = add (ci -> ci_comment, NULLCP));	free (cp);	(void) sprintf (buffer, "(%s)", dp);	free (dp);	printf (LSTFMT2d2, buffer);    }    if (!debugsw)	return OK;    (void) fflush (stdout);    fprintf (stderr, "  partno \"%s\"\n", empty (ct -> c_partno));    if (ct -> c_vrsn)	fprintf (stderr, "  %s:%s\n", VRSN_FIELD, ct -> c_vrsn);    if (ct -> c_ctline)	fprintf (stderr, "  %s:%s", TYPE_FIELD, ct -> c_ctline);    fprintf (stderr,	     "    type \"%s\"  subtype \"%s\"  comment \"%s\"  magic \"%s\"\n",	     empty (ci -> ci_type), empty (ci -> ci_subtype),	     empty (ci -> ci_comment), empty (ci -> ci_magic));    for (ap = ci -> ci_attrs, ep = ci -> ci_values; *ap; ap++, ep++)	fprintf (stderr, "      parameter %s=\"%s\"\n", *ap, *ep);    fprintf (stderr,	     "    type 0x%x subtype 0x%x params 0x%x\n",	     ct -> c_type, ct -> c_subtype, ct -> c_ctparams);    fprintf (stderr, "     showproc \"%s\"\n", empty (ct -> c_showproc));    fprintf (stderr, "     termproc \"%s\"\n", empty (ct -> c_termproc));    fprintf (stderr, "    storeproc \"%s\"\n", empty (ct -> c_storeproc));    if (ct -> c_celine)	fprintf (stderr, "  %s:%s", ENCODING_FIELD, ct -> c_celine);    fprintf (stderr, "    encoding 0x%x params 0x%x\n",	     ct -> c_encoding, ct -> c_ceparams);    if (ct -> c_id)	fprintf (stderr, "  %s:%s", ID_FIELD, ct -> c_id);    if (ct -> c_descr)	fprintf (stderr, "  %s:%s", DESCR_FIELD, ct -> c_descr);    fprintf (stderr, "  fp 0x%x file \"%s\" begin %d end %d\n",	     ct -> c_fp, empty (ct -> c_file), ct -> c_begin, ct -> c_end);    if (ct -> c_celistfnx)	(void) (*ct -> c_celistfnx) (ct);    return OK;}#undef	empty/*  */#ifdef VSPRINTF#ifdef __STDC__#include <stdarg.h>#else#include <varargs.h>#endif#endif#ifdef VSPRINTF#ifdef __STDC__static void content_error (char *what, register CT ct, char *fmt, ...)#elsestatic void  content_error (va_alist)va_dcl#endif#else	/* !VSPRINTF *//* VARARGS3 */static void  content_error (what, ct, fmt, a, b, c, d, e, f)char   *what,       *fmt,       *a,       *b,       *c,       *d,       *e,       *f;register CT	ct;#endif{#ifdef VSPRINTF    va_list arglist;#endif#if defined(VSPRINTF) && !defined(__STDC__)    char *what, *fmt;    register CT ct;#endif    int	    i;    register char *bp;    char   buffer[BUFSIZ];    register CI	   ci;    bp = buffer;    if (userrs && invo_name && *invo_name) {	(void) sprintf (bp, "%s: ", invo_name);	bp += strlen (bp);    }#ifdef VSPRINTF#ifdef __STDC__    va_start (arglist, fmt);#else    va_start (arglist);    what = va_arg(arglist, char *);    ct   = va_arg(arglist, CT);    fmt  = va_arg(arglist, char *);#endif    (void) vsprintf (bp, fmt, arglist);    bp += strlen (bp);#else    (void) sprintf (bp, fmt, a, b, c, d, e, f);    bp += strlen (bp);#endif    ci = &ct -> c_ctinfo;    if (what) {	if (*what) {	    (void) sprintf (bp, " %s: ", what);	    bp += strlen (bp);	}	if (errno > 0 && errno < sys_nerr)	    (void) sprintf (bp, "%s", sys_errlist[errno]);	else	    (void) sprintf (bp, "Error %d", errno);	bp += strlen (bp);    }    i = strlen (invo_name) + 2;    (void) sprintf (bp, "\n%*.*s(content %s/%s", i, i, "", ci -> ci_type,		    ci -> ci_subtype);    bp += strlen (bp);    if (ct -> c_file) {	(void) sprintf (bp, " in message %s", ct -> c_file);	bp += strlen (bp);	if (ct -> c_partno) {	    (void) sprintf (bp, ", part %s", ct -> c_partno);	    bp += strlen (bp);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -