示例#1
0
文件: strfile.c 项目: coyizumi/cs111
/*
 * cmp_str:
 *	Compare two strings in the file
 */
int
cmp_str(const void *s1, const void *s2)
{
	const STR *p1, *p2;
	int c1, c2, n1, n2, r;

#define	SET_N(nf,ch)	(nf = (ch == '\n'))
#define	IS_END(ch,nf)	(ch == EOF || (ch == (unsigned char)Delimch && nf))

	p1 = (const STR *)s1;
	p2 = (const STR *)s2;

	c1 = (unsigned char)p1->first;
	c2 = (unsigned char)p2->first;
	if ((r = stable_collate_range_cmp(c1, c2)) != 0)
		return (r);

	fseeko(Sort_1, p1->pos, SEEK_SET);
	fseeko(Sort_2, p2->pos, SEEK_SET);

	n1 = false;
	n2 = false;
	while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0' && c1 != EOF)
		SET_N(n1, c1);
	while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0' && c2 != EOF)
		SET_N(n2, c2);

	while (!IS_END(c1, n1) && !IS_END(c2, n2)) {
		if (Iflag) {
			if (isupper(c1))
				c1 = tolower(c1);
			if (isupper(c2))
				c2 = tolower(c2);
		}
		if ((r = stable_collate_range_cmp(c1, c2)) != 0)
			return (r);
		SET_N(n1, c1);
		SET_N(n2, c2);
		c1 = getc(Sort_1);
		c2 = getc(Sort_2);
	}
	if (IS_END(c1, n1))
		c1 = 0;
	if (IS_END(c2, n2))
		c2 = 0;

	return (stable_collate_range_cmp(c1, c2));
}
示例#2
0
/*
 * cmp_str:
 *      Compare two strings in the file
 */
int cmp_str(const void *v1, const void *v2)
{
    register int c1, c2;
    register int n1, n2;
    register STR *p1, *p2;

#define	SET_N(nf,ch)	(nf = (ch == '\n'))
#define	IS_END(ch,nf)	(ch == Delimch && nf)

    p1 = (STR *) v1;
    p2 = (STR *) v2;
    c1 = p1->first;
    c2 = p2->first;
    if (c1 != c2)
	return c1 - c2;

    fseek(Sort_1, p1->pos, 0);
    fseek(Sort_2, p2->pos, 0);

    n1 = FALSE;
    n2 = FALSE;
    while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0')
	SET_N(n1, c1);
    while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')
	SET_N(n2, c2);

    while (!IS_END(c1, n1) && !IS_END(c2, n2))
    {
	if (Iflag)
	{
	    if (isupper(c1))
		c1 = tolower(c1);
	    if (isupper(c2))
		c2 = tolower(c2);
	}
	if (c1 != c2)
	    return c1 - c2;
	SET_N(n1, c1);
	SET_N(n2, c2);
	c1 = getc(Sort_1);
	c2 = getc(Sort_2);
    }
    if (IS_END(c1, n1))
	c1 = 0;
    if (IS_END(c2, n2))
	c2 = 0;
    return c1 - c2;
}
示例#3
0
文件: sn.c 项目: 5310/n2n_v2_fork
static void send_snm_req(n2n_sn_t         *sss,
                         n2n_sock_t       *sn,
                         int               req_communities,
                         snm_comm_name_t  *communities,
                         int               communities_num)
{
    uint8_t pktbuf[N2N_PKT_BUF_SIZE];
    size_t idx;
    n2n_sock_str_t sockbuf;
    snm_hdr_t hdr = { SNM_TYPE_REQ_LIST_MSG, 0, ++sss->seq_num };
    n2n_SNM_REQ_t req = { 0, NULL };

    if (sn_is_loopback(sn, sss->sn_port))
        return;

    SET_S(hdr.flags);

    if (req_communities)
    {
        SET_C(hdr.flags);
    }
    else if (communities)
    {
        SET_N(hdr.flags);
        req.comm_num = communities_num & 0xFFFF;
        req.comm_ptr = communities;
    }

    idx = 0;
    encode_SNM_REQ(pktbuf, &idx, &hdr, &req);

    traceEvent(TRACE_INFO, "send SNM_REQ to %s", sock_to_cstr(sockbuf, sn));

    sendto_sock(sss->sn_sock, sn, pktbuf, idx);
}
示例#4
0
文件: strfile.c 项目: lattera/openbsd
int
cmp_str(const void *p1, const void *p2)
{
	int	c1, c2;
	int	n1, n2;

# define	SET_N(nf,ch)	(nf = (ch == '\n'))
# define	IS_END(ch,nf)	(ch == Delimch && nf)

	c1 = ((STR *)p1)->first;
	c2 = ((STR *)p2)->first;
	if (c1 != c2)
		return c1 - c2;

	(void) fseek(Sort_1, ((STR *)p1)->pos, SEEK_SET);
	(void) fseek(Sort_2, ((STR *)p2)->pos, SEEK_SET);

	n1 = FALSE;
	n2 = FALSE;
	while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0')
		SET_N(n1, c1);
	while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')
		SET_N(n2, c2);

	while (!IS_END(c1, n1) && !IS_END(c2, n2)) {
		if (Iflag) {
			if (isupper(c1))
				c1 = tolower(c1);
			if (isupper(c2))
				c2 = tolower(c2);
		}
		if (c1 != c2)
			return c1 - c2;
		SET_N(n1, c1);
		SET_N(n2, c2);
		c1 = getc(Sort_1);
		c2 = getc(Sort_2);
	}
	if (IS_END(c1, n1))
		c1 = 0;
	if (IS_END(c2, n2))
		c2 = 0;
	return c1 - c2;
}