Esempio n. 1
0
/* data が改行のみのとき、空文字列が返ること。改行がCRLF。 */
static void test_sgetline_emptylines_crlf(void)
{
	const char *data = "\r\n\r\n\r\n";
	char* line;

	/* 1行め */
	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("", line);
	free(line);

	/* 2行め */
	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("", line);
	free(line);

	/* 3行め */
	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("", line);
	free(line);

	line = sgetline(&data);
	PCU_ASSERT_PTR_NULL(line);
}
Esempio n. 2
0
/* data が複数行のとき、各行を取得できること。改行がCR。 */
static void test_sgetline_multilines_cr(void)
{
	const char *data = "abc\rdef\rghi";
	char* line;

	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("abc", line);

	free(line);

	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("def", line);

	free(line);

	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("ghi", line);

	free(line);

	PCU_ASSERT_EQUAL('\0', *data);
}
Esempio n. 3
0
static enum okay 
pop3_answer(struct mailbox *mp)
{
	int sz;
	enum okay ok = STOP;

retry:	if ((sz = sgetline(&pop3buf, &pop3bufsize, NULL, &mp->mb_sock)) > 0) {
		if ((mp->mb_active & (MB_COMD|MB_MULT)) == MB_MULT)
			goto multiline;
		if (verbose)
			fputs(pop3buf, stderr);
		switch (*pop3buf) {
		case '+':
			ok = OKAY;
			mp->mb_active &= ~MB_COMD;
			break;
		case '-':
			ok = STOP;
			mp->mb_active = MB_NONE;
			fprintf(stderr, catgets(catd, CATSET, 218,
					"POP3 error: %s"), pop3buf);
			break;
		default:
			/*
			 * If the answer starts neither with '+' nor with
			 * '-', it must be part of a multiline response,
			 * e. g. because the user interrupted a file
			 * download. Get lines until a single dot appears.
			 */
	multiline:	 while (pop3buf[0] != '.' || pop3buf[1] != '\r' ||
					pop3buf[2] != '\n' ||
					pop3buf[3] != '\0') {
				sz = sgetline(&pop3buf, &pop3bufsize,
						NULL, &mp->mb_sock);
				if (sz <= 0)
					goto eof;
			}
			mp->mb_active &= ~MB_MULT;
			if (mp->mb_active != MB_NONE)
				goto retry;
		}
	} else {
	eof: 	ok = STOP;
		mp->mb_active = MB_NONE;
	}
	return ok;
}
Esempio n. 4
0
/* 空文字列のとき、 NULL が返ること */
static void test_sgetline_empty(void)
{
	const char *data = "";
	char* line;

	line = sgetline(&data);
	PCU_ASSERT_PTR_NULL(line);
}
Esempio n. 5
0
/* 引数 data が無いとき、エラーとなること */
static void test_sgetline_data_null(void)
{
	char* line;

	line = sgetline(NULL);
	PCU_ASSERT_PTR_NULL(line);
	PCU_ASSERT_EQUAL(EINVAL, errno);
}
Esempio n. 6
0
/*
 * readbuf - reads in a buffer.
 */
void
readbuf(char **buf)
{
        register LINE   *lp1;
        register LINE   *lp2;
        register BUFFER *bp;
        register WINDOW *wp;
        register int    i;
        register int    s;
        char   *sptr;          /* pointer into buffer string */
        int		nbytes;
        char            line[NLINE];
	CELL            ac;
 
	bp = curbp;
        bp->b_flag &= ~(BFTEMP|BFCHG);
	sptr = *buf;
	ac.a  = 0;

        while((s=sgetline(&sptr,&nbytes,line,NLINE)) == FIOSUC || s == FIOLNG){

                if ((lp1=lalloc(nbytes)) == NULL) {
                        s = FIOERR;             /* Keep message on the  */
                        break;                  /* display.             */
                }
                lp2 = lback(curbp->b_linep);
                lp2->l_fp = lp1;
                lp1->l_fp = curbp->b_linep;
                lp1->l_bp = lp2;
                curbp->b_linep->l_bp = lp1;
                for (i=0; i<nbytes; ++i){
		    ac.c = line[i];
		    lputc(lp1, i, ac);
		}
        }

        for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) {
                if (wp->w_bufp == curbp) {
                        wheadp->w_linep = lforw(curbp->b_linep);
                        wheadp->w_dotp  = lback(curbp->b_linep);
                        wheadp->w_doto  = 0;
                        wheadp->w_markp = NULL;
                        wheadp->w_marko = 0;
                        wheadp->w_flag |= WFHARD;
                }
        }

	strncpy(bp->b_bname, "main", sizeof(bp->b_bname));
	bp->b_bname[sizeof(bp->b_bname)-1] = '\0';
	strncpy(bp->b_fname, "", sizeof(bp->b_fname));
	bp->b_fname[sizeof(bp->b_fname)-1] = '\0';

	bp->b_dotp = bp->b_linep;
	bp->b_doto = 0;
}
Esempio n. 7
0
/* data が1行のとき、1行を取得し、'\0' が返ること */
static void test_sgetline_oneline(void)
{
	const char *data = "abc";
	char* line;

	line = sgetline(&data);
	PCU_ASSERT_PTR_NOT_NULL(line);
	PCU_ASSERT_STRING_EQUAL("abc", line);
	free(line);

	PCU_ASSERT_EQUAL('\0', *data);

}
Esempio n. 8
0
/* 最初のセクションの解釈 */
static void ini_parse_first_section(Ini *ini, const char **data)
{
	char *line;

	/* 空行をとばす */
	while (1) {
		line = sgetline(data);
		if (line == NULL)
			return;
		if (!isingnorableline(line))
			break;
		free(line);
	}

	ini->current = section_parse(line);
	free(line);
	if (ini->current == NULL)
		return;

	if (ini_add_section(ini, ini->current))
		section_delete(ini->current);
}
Esempio n. 9
0
static void ini_parse_sections_and_keys(Ini *ini, const char *data)
{
	Key *key;
	Section *section;
	char *line;

	while ((line = sgetline(&data)) != NULL) {

		if (isingnorableline(line))
			continue;

		/* キーとして解釈 */
		if ((key = key_parse(line)) != NULL) {
			free(line);
			if (section_add_key(ini->current, key)) {
				key_delete(key);
				return;
			}
			continue;
		}

		/* セクションとして解釈 */
		if ((section = section_parse(line)) != NULL) {
			ini->current = section;
			free(line);
			if (ini_add_section(ini, ini->current)) {
				section_delete(ini->current);
				return;
			}
			continue;
		}

		free(line);

		return; /* 無効な文字列の場合にここまで来る */
	}
}