示例#1
0
static void
test_ctype(void)
{
	int c;

	for (c = -1; c < 256; c++) {
		/* Test blank. */
		if (c == '\t' || c == ' ')
			test_pass(c_isblank(c));
		else
			test_fail(c_isblank(c));

		/* Test white. */
		if (c == '\t' || c == ' ' || c == '\n')
			test_pass(c_iswhite(c));
		else
			test_fail(c_iswhite(c));

		/* Test space. */
		if (c == '\t' || c == '\v' || c == '\f' ||
		    c == '\r' || c == '\n' || c == ' ')
			test_pass(c_isspace(c));
		else
			test_fail(c_isspace(c));

		/* Test digit. */
		if (c >= '0' && c <= '9')
			test_pass(c_isdigit(c));
		else
			test_fail(c_isdigit(c));

		/* Test lower case. */
		if (c >= 'a' && c <= 'z')
			test_pass(c_islower(c));
		else
			test_fail(c_islower(c));

		/* Test upper case. */
		if (c >= 'A' && c <= 'Z')
			test_pass(c_isupper(c));
		else
			test_fail(c_isupper(c));

		/* Test alpha. */
		if (c_islower(c) || c_isupper(c))
			test_pass(c_isalpha(c));
		else
			test_fail(c_isalpha(c));

		/* Test alphanumeric. */
		if (c_isdigit(c) || c_isalpha(c))
			test_pass(c_isalnum(c));
		else
			test_fail(c_isalnum(c));
	}
}
示例#2
0
文件: triglib.c 项目: guillemj/dpkg
void
trig_parse_ci(const char *file, trig_parse_cicb *interest,
              trig_parse_cicb *activate, struct pkginfo *pkg,
              struct pkgbin *pkgbin)
{
	FILE *f;
	char linebuf[MAXTRIGDIRECTIVE], *cmd, *spc, *eol;
	int l;

	f = fopen(file, "r");
	if (!f) {
		if (errno == ENOENT)
			return; /* No file is just like an empty one. */
		ohshite(_("unable to open triggers ci file '%.250s'"), file);
	}
	push_cleanup(cu_closestream, ~0, 1, f);

	while ((l = fgets_checked(linebuf, sizeof(linebuf), f, file)) >= 0) {
		for (cmd = linebuf; c_iswhite(*cmd); cmd++) ;
		if (*cmd == '#')
			continue;
		for (eol = linebuf + l; eol > cmd && c_iswhite(eol[-1]); eol--) ;
		if (eol == cmd)
			continue;
		*eol = '\0';

		for (spc = cmd; *spc && !c_iswhite(*spc); spc++) ;
		if (!*spc)
			ohshit(_("triggers ci file contains unknown directive syntax"));
		*spc++ = '\0';
		while (c_iswhite(*spc))
			spc++;
		if (strcmp(cmd, "interest") == 0 ||
		    strcmp(cmd, "interest-await") == 0) {
			parse_ci_call(file, cmd, interest, spc, pkg, pkgbin, TRIG_AWAIT);
		} else if (strcmp(cmd, "interest-noawait") == 0) {
			parse_ci_call(file, cmd, interest, spc, pkg, pkgbin, TRIG_NOAWAIT);
		} else if (strcmp(cmd, "activate") == 0 ||
		           strcmp(cmd, "activate-await") == 0) {
			parse_ci_call(file, cmd, activate, spc, pkg, pkgbin, TRIG_AWAIT);
		} else if (strcmp(cmd, "activate-noawait") == 0) {
			parse_ci_call(file, cmd, activate, spc, pkg, pkgbin, TRIG_NOAWAIT);
		} else {
			ohshit(_("triggers ci file contains unknown directive '%.250s'"),
			       cmd);
		}
	}
	pop_cleanup(ehflag_normaltidy); /* fclose() */
}