Exemplo n.º 1
0
struct passwd *getpwent(void)
/* Read one entry from the password file. */
{
	char *p;

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

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

		if ((entry.pw_name= scan_colon()) == nil) continue;
		if ((entry.pw_passwd= scan_colon()) == nil) continue;
		if ((p= scan_colon()) == nil) continue;
		entry.pw_uid= strtol(p, nil, 0);
		if ((p= scan_colon()) == nil) continue;
		entry.pw_gid= strtol(p, nil, 0);
		if ((entry.pw_gecos= scan_colon()) == nil) continue;
		if ((entry.pw_dir= scan_colon()) == nil) continue;
		if ((entry.pw_shell= scan_colon()) == nil) continue;

		if (*lineptr == 0) return &entry;
	}
}
Exemplo n.º 2
0
void Scanner::scan() {
	char token = file.get();
	while (token != EOF && error == -1) {
		switch (token) {
		case ',':
			scan_punctuation(token, Token::COMMA);
			break;
		case '.':
			scan_punctuation(token, Token::PERIOD);
			break;
		case '?':
			scan_punctuation(token, Token::Q_MARK);
			break;
		case '(':
			scan_punctuation(token, Token::LEFT_PAREN);
			break;
		case ')':
			scan_punctuation(token, Token::RIGHT_PAREN);
			break;
		case ':':
			scan_colon();
			break;
		case '#':
			scan_comment();
			break;
		case '\'':
			scan_string();
			break;
		case '\n':
			line++;
			break;
		default:
			scan_id(token);
			break;
		}
		token = file.get();
	}

	if (error == -1) {
		line++;
		add_token("", Token::END);
	}
}