Example #1
0
struct group *getgrent(void)
/* Read one entry from the group file. */
{
	char *p;
	char **mem;

	/* Open the file if not yet open. */
	if (grfd < 0 && setgrent() < 0) return nil;

	/* Until a good line is read. */
	for (;;) {
		if (!getline()) return nil;	/* EOF or corrupt. */

		if ((entry.gr_name= scan_punct(':')) == nil) continue;
		if ((entry.gr_passwd= scan_punct(':')) == nil) continue;
		if ((p= scan_punct(':')) == nil) continue;
		entry.gr_gid= strtol(p, nil, 0);

		entry.gr_mem= mem= members;
		if (*lineptr != '\n') {
			do {
				if ((*mem= scan_punct(',')) == nil) goto again;
				if (mem < arraylimit(members) - 1) mem++;
			} while (*lineptr != 0);
		}
		*mem= nil;
		return &entry;
	again:;
	}
}
Example #2
0
static void test_case(const char *data)
{
    AoS_Copy *tokens = aosc_create(20);

    printf("Test: [%s]\n", data);
    const char *word = data;
    while (*word != '\0')
    {
        const char *eow;
        eow = word = skip_space(word);
        if (is_alnum(*word) || (word[0] == '\'' && is_alnum(word[1])))
            eow = scan_alnum(word);
        else if (is_punct(*word))
            eow = scan_punct(word);
        if (eow == word)
            break;
        aosc_addbytes(tokens, word, eow);
        word = eow;
    }

    int num = 0;
    aosc_apply_ctxt(tokens, 0, aosc_length(tokens), printer, &num);
    putchar('\n');

    aosc_destroy(tokens);
}