Exemple #1
0
void
yyrestart(void)
{

    if (yytext) clearbuf();
    state = _S_;
}
void FHealthBar::FillBar (int min, int max, BYTE light, BYTE dark)
{
#ifdef __BIG_ENDIAN__
	SDWORD fill = (light << 24) | (dark << 16) | (light << 8) | dark;
#else
	SDWORD fill = light | (dark << 8) | (light << 16) | (dark << 24);
#endif
	if (max > min)
	{
		clearbuf (&Pixels[min*4], max - min, fill);
	}
}
Exemple #3
0
void
lsd_lex(int c)
{
    /* printf("=%c", c);*/
    if (yytext == 0)
	yytext = (char *) emalloc(bufsize * sizeof(int));
    switch (state) {
      case _S_:
	if (isalpha(c) || c == '_') {
	    save(c);
	    state = _A_;
	} else if (c == ' ' || c == '\t') {
	    state = _S_;
	} else if (c == '\n') {
	    state = _S_;
	} else if (c == '\r') {
	    state = _S_;
	} else if (c == '#') {
	    state = _COMMENT_;
	} else {
	    lsd_parse(c);
	    state = _S_;
	}
	break;
      case _A_:
	if (isalnum(c) || c == '_') {
	    save(c);
	    state = _A_;
	} else {
	    action_A();
	    clearbuf();
	    state = _S_;
	    lsd_lex(c);
	}
	break;
      case _COMMENT_:
	if (c == '\n' || c == '\r') {
	  state = _S_;
	}
	break;
    }
}
Exemple #4
0
void
yyrestart(void)
{
    clearbuf();
    state = _S_;
}
Exemple #5
0
void
yylex(int c)
{
    switch (state) {
    case _S_:
	switch (c) {
	case ' ':
	case '\t':
	    state = _S_;
	    break;
	case '\n':
	    yyparse(NEWLINE);
	    state = _S_;
	    break;
	case '\r':
	    yyparse(NEWLINE);
	    state = _IGNORENL_;
	    break;
	case '.':
	    save(c);
	    state = _DOT_;
	    break;
	case '?':
	    state = _QUERY_;
	    break;
	case '"':
	    save(c);
	    state = _QUOTE_;
	    break;
	case '\\':
	    state = _BSLASH_;
	    break;
	case '#':
	    state = _HASH_;
	    break;
	case '&':
	    state = _AND_;
	    break;
	case '|':
	    state = _OR_;
	    break;
	case '=':
	    state = _EQ_;
	    break;
	case '!':
	    state = _NOT_;
	    break;
	case '<':
	    gtarget = _I_;
	    state = _B_;
	    break;
	case '>':
	    state = _GT_;
	    break;
	case '/':
	    state = _SLASH_;
	    break;
	case 'f':
	    gtarget = _F_;
	    state = _F_;
	    save(c);
	    break;
	case 'x':
	    gtarget = _X_;
	    state = _X_;
	    save(c);
	    break;
	case 'I':
	    state = _II_;
	    break;
	case '~':
	    state = _TILDE_;
	    break;
	default:
	    if (isalpha(c) || c == '_') {
		save(c);
		state = _A_;
	    } else if (isdigit(c)) {
		save(c);
		state = _D_;
	    } else {
		yyparse(tokenize(c));
		state = _S_;
	    }
	    break;
	}
	break;
    case _A_:
	if (isalnum(c) || c == '_') {
	    save(c);
	    state = _A_;
	} else {
	    action_A();
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _D_:
	if (isdigit(c)) {
	    save(c);
	    state = _D_;
	} else if (c == '.') {
	    save(c);
	    state = _DDOT_;
	} else if (c == 'E' || c == 'e') {
	    save(c);
	    state = _DE_;
	} else {
	    yylval.i = atoi(yytext);
	    yyparse(INUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DDOT_:
	if (isdigit(c)) {
	    save(c);
	    state = _DDOT_;
	} else if (c == '.') {
	    yylval.r = atof(yytext);
	    yyparse(RNUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	} else if (c == 'E' || c == 'e') {
	    save(c);
	    state = _DE_;
	} else {
	    yylval.r = atof(yytext);
	    yyparse(RNUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DE_:
	if (isdigit(c)) {
	    save(c);
	    state = _DED_;
	} else if (c == '+' || c == '-') {
	    save(c);
	    state = _DES_;
	} else {
	    yylval.r = atof(yytext);
	    yyparse(RNUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DED_:
    case _DESD_:
	if (isdigit(c)) {
	    save(c);
	    state = _DED_;
	} else {
	    yylval.r = atof(yytext);
	    yyparse(RNUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DES_:
	if (isdigit(c)) {
	    save(c);
	    state = _DESD_;
	} else {
	    int E, S;
	    yylval.r = atof(yytext);
	    yyparse(RNUMBER);
	    E = yytext[yyleng-2];
	    S = yytext[yyleng-1];
	    clearbuf();
	    state = _S_;
	    yylex(E);
	    yylex(S);
	    yylex(c);
	}
	break;
    case _DOT_:
	if (c == 'x') {
	    yyparse(DOTX);
	    clearbuf();
	    state = _S_;
	} else if (c == 'y') {
	    yyparse(DOTY);
	    clearbuf();
	    state = _S_;
	} else if (c == '1') {
	    save(c);
	    state = _DOT1_;
	} else if (c == '2') {
	    save(c);
	    state = _DOT2_;
	} else if (c == 'a') {
	    save(c);
	    state = _DA_;
	} else if (c == 'r') {
	    save(c);
	    state = _DR_;
	} else if (isdigit(c)) {
	    save(c);
	    state = _DDOT_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DOT1_:
	if (isdigit(c)) {
	    state = _DDOT_;
	    yylex(c);
	} else {
	    yyparse(DOT1);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DOT2_:
	if (isdigit(c)) {
	    state = _DDOT_;
	    yylex(c);
	} else {
	    yyparse(DOT2);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DA_:
	if (c == 'r') {
	    save(c);
	    state = _DAR_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex('a');
	    yylex(c);
	}
	break;
    case _DAR_:
	if (c == 'g') {
	    yyparse(DOTARG);
	    clearbuf();
	    state = _S_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex('a');
	    yylex('r');
	    yylex(c);
	}
	break;
    case _DR_:
	if (c == 'a') {
	    save(c);
	    state = _DRA_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex('r');
	    yylex(c);
	}
	break;
    case _DRA_:
	if (c == 'd') {
	    yyparse(DOTRAD);
	    clearbuf();
	    state = _S_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex('r');
	    yylex('a');
	    yylex(c);
	}
	break;
    case _QUOTE_:
	if (c == '"') {
	    save(c);
	    yylval.s = strdup(yytext);
	    yyparse(CSTRING);
	    clearbuf();
	    state = _S_;
	} else if (c == '\n' || c == '\r') {
	    save('"');
	    yylval.s = strdup(yytext);
	    yyparse(CSTRING);
	    clearbuf();
	    state = _S_;
	} else {
	    save(c);
	    state = _QUOTE_;
	}
	break;
    case _QUERY_:
	if (c == '\n' || c == '\r') {
	    yylval.s = strdup(yytext);
	    yyparse(QUERY);
	    yyparse(NEWLINE);
	    clearbuf();
	    state = _S_;
	} else {
	    save(c);
	    state = _QUERY_;
	}
	break;
    case _BSLASH_:
	if (c == '\n' || c == '\r') {
	    state = _S_;
	} else {
	    yyparse('\\');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _HASH_:
	if (c == '\n' || c == '\r') {
	    yyparse(NEWLINE);
	    state = _S_;
	} else {
	    state = _HASH_;
	}
	break;
    case _AND_:
	if (c == '&') {
	    yyparse(AND);
	    state = _S_;
	} else {
	    yyparse(AMPERSAND);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _OR_:
	if (c == '|') {
	    yyparse(OR);
	    state = _S_;
	} else {
	    yyparse(VERTBAR);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _EQ_:
	if (c == '=') {
	    yyparse(EQ_EQ);
	    state = _S_;
	} else {
	    yyparse(EQUALS);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _NOT_:
	if (c == '=') {
	    yyparse(NOT_EQ);
	    state = _S_;
	} else {
	    yyparse(NOT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _LT_:
	if (c == '=') {
	    yyparse(LT_EQ);
	    state = _S_;
	} else {
	    yyparse(LT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _GT_:
	if (c == '=') {
	    yyparse(GT_EQ);
	    state = _S_;
	} else {
	    yyparse(GT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _SLASH_:
	if (c == '/') {
	    yyparse(SLASH_SLASH);
	    state = _S_;
	} else {
	    yyparse(SLASH);
	    state = _S_;
	    DonaldAppAgentName = 0;
	    yylex(c);
	}
	break;
    case _TILDE_:
	if (c == '/') {
	    DonaldAppAgentName = 1;
	    dd_appAgentName++;
	    yyparse(TILDE_SLASH);
	    state = _S_;
	} else {
	    DonaldAppAgentName = 0;
	    state = _S_;
	    yylex(c);
	}
	break;
    case _F_:
	if (c == ' ' || c == '\t') {
	    state = _F_;
	} else if (c == '<') {
	    state = _B_;
	} else {
	    state = _A_;
	    yylex(c);
	}
	break;
    case _X_:
	if (c == ' ' || c == '\t') {
	    state = _X_;
	} else if (c == '<') {
	    state = _B_;
	} else {
	    state = _A_;
	    yylex(c);
	}
	break;
    case _B_:
	if (c == ' ' || c == '\t') {
	    state = _B_;
	} else if (c == 'i') {
	    state = _BI_;
	} else {
	    switch (gtarget) {
	    case _F_:
	    case _X_:
		state = _A_;
		yylex('<');
		yylex(c);
		break;
	    default:
		state = _LT_;
		yylex(c);
		break;
	    }
	}
	break;
    case _BI_:
    case _BISP_:
	if (c == ' ' || c == '\t') {
            state = _BISP_;
        } else if (c == '-') {
	    state = _BI__;
	} else if (c == '>') {
	    switch (gtarget) {
	    case _F_:
		yyparse(FI);
		break;
	    case _X_:
		yyparse(XI);
		break;
	    case _I_:
		yyparse(I);
		break;
	    }
	    clearbuf();
	    state = _S_;
	} else {
	    switch (gtarget) {
	    case _F_:
	    case _X_:
		state = _A_;
		yylex('<');
		yylex('i');
		if (state == _BISP_) yylex(' ');
		yylex(c);
		break;
	    default:
		state = _LT_;
		yylex('i');
		if (state == _BISP_) yylex(' ');
		yylex(c);
		break;
	    }
	}
	break;
    case _BI__:
	if (c == ' ' || c == '\t') {
            state = _BI__;
        } else if (c == '1') {
            state = _BI_1_;
	} else {
	    switch (gtarget) {
	    case _F_:
	    case _X_:
		state = _A_;
		yylex('<');
		yylex('i');
		yylex('-');
		yylex(c);
		break;
	    default:
		state = _LT_;
		yylex('i');
		yylex('-');
		yylex(c);
		break;
	    }
	}
	break;
    case _BI_1_:
    case _BI_1SP_:
	if (c == ' ' || c == '\t') {
            state = _BI_1SP_;
        } else if (c == '>') {
	    switch (gtarget) {
	    case _F_:
		yyparse(FI_1);
		break;
	    case _X_:
		yyparse(XI_1);
		break;
	    case _I_:
		yyparse(I_1);
		break;
	    }
	    clearbuf();
	    state = _S_;
	} else {
	    switch (gtarget) {
	    case _F_:
	    case _X_:
		state = _A_;
		yylex('<');
		yylex('i');
		yylex('-');
		yylex('1');
		if (state == _BI_1SP_) yylex(' ');
		yylex(c);
		break;
	    default:
		state = _LT_;
		yylex('i');
		yylex('-');
		yylex('1');
		if (state == _BI_1SP_) yylex(' ');
		yylex(c);
		break;
	    }
	}
	break;
    case _II_:
	if (c == '!') {
	    state = _IN_;
	} else {
	    state = _A_;
	    yylex('I');
	    yylex(c);
	}
	break;
    case _IN_:
	if (isalpha(c)) {
	   save(c);
	   state = _INA_;
	} else {
	    state = _S_;
	    yylex('I');
	    yylex('!');
	    yylex(c);
	}
	break;
    case _INA_:
	if (isalpha(c)) {
	   save(c);
	   state = _INA_;
	} else {
	    yylval.s = strdup(yytext);
	    yyparse(IMGFUNC);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _IGNORENL_:
      if (c == '\n') {
	state = _S_;		/* discard \n after \r */
      } else {
	state = _S_;
	yylex(c);
      }
      break;
    }
}
Exemple #6
0
/*--------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	int fd, ret_val;
	FILE *fp;

	setup();		/* temp file is now open */
/*--------------------------------------------------------------*/
	blenter();

	/* Check that system SEV_LEVEL output is correct */

	close(2);		/* redirect stderr to file */
	fd = creat("fmtfile", 0644);
	ret_val = fmtmsg(MM_PRINT | MM_SOFT, "LTP:fmtmsg", MM_INFO,
			 "LTP fmtmsg() test1 message, NOT an error",
			 "This is correct output, no action needed",
			 "LTP:msg:001");
	close(fd);

	if (ret_val != 0) {
		fprintf(temp, "fmtmsg returned %d, expected 0\n\n", ret_val);
		local_flag = FAILED;
	}

	fp = fopen("fmtfile", "r");
	clearbuf();
	fread(buf, sizeof(buf[0]), strlen(str1), fp);
	if (strcmp(str1, buf) != 0) {
		fprintf(temp, "Expected string: %s\n", str1);
		fprintf(temp, "does not match\n");
		fprintf(temp, "received string: %s\n\n", buf);
		local_flag = FAILED;
	}

	/* Read past spaces in output */
	fread(&ch, sizeof(ch), 1, fp);
	while (isspace(ch))
		fread(&ch, sizeof(ch), 1, fp);
	ungetc(ch, fp);

	clearbuf();
	fread(buf, sizeof(buf[0]), strlen(str2), fp);
	fclose(fp);
	if (strcmp(str2, buf) != 0) {
		fprintf(temp, "Expected string: %s\n", str2);
		fprintf(temp, "does not match\n");
		fprintf(temp, "received string: %s\n\n", buf);
		local_flag = FAILED;
	}

	blexit();
/*--------------------------------------------------------------*/
	blenter();

	/* Check that a system defined SEV_LEVEL cannot get redefined */

	ret_val = addseverity(3, "INVALID");
	if (ret_val != MM_NOTOK) {
		fprintf(temp, "addseverity returned %d, expected MM_NOTOK\n",
			ret_val);
		local_flag = FAILED;
	}

	blexit();
/*--------------------------------------------------------------*/
	blenter();

	/* Check that we can define our own */
	/* SEV_LEVEL and output is correct  */

	ret_val = addseverity(5, "LTP_TEST");
	if (ret_val != MM_OK) {
		fprintf(temp, "addseverity returned %d, expected MM_OK\n",
			ret_val);
		local_flag = FAILED;
	}

	close(2);		/* redirect stderr to file */
	fd = creat("fmtfile", 0644);
	ret_val = fmtmsg(MM_PRINT | MM_HARD | MM_OPSYS, "LTP:fmtmsg", 5,
			 "LTP fmtmsg() test2 message, NOT an error",
			 "This is correct output, no action needed",
			 "LTP:msg:002");
	close(fd);

	if (ret_val != 0) {
		fprintf(temp, "fmtmsg returned %d, expected 0\n", ret_val);
		local_flag = FAILED;
	}

	fp = fopen("fmtfile", "r");
	clearbuf();
	fread(buf, sizeof(buf[0]), strlen(str3), fp);
	if (strcmp(str3, buf) != 0) {
		fprintf(temp, "Expected string: %s\n", str3);
		fprintf(temp, "does not match\n");
		fprintf(temp, "received string: %s\n\n", buf);
		local_flag = FAILED;
	}

	/* Read past spaces in output */
	fread(&ch, sizeof(ch), 1, fp);
	while (isspace(ch))
		fread(&ch, sizeof(ch), 1, fp);
	ungetc(ch, fp);

	clearbuf();
	fread(buf, sizeof(buf[0]), strlen(str4), fp);
	if (strcmp(str4, buf) != 0) {
		fprintf(temp, "Expected string: %s\n", str4);
		fprintf(temp, "does not match\n");
		fprintf(temp, "received string: %s\n\n", buf);
		local_flag = FAILED;
	}

	fclose(fp);
	remove("fmtfile");

	blexit();
/*--------------------------------------------------------------*/
	blenter();

	/* Test result of writing to /dev/console */

	ret_val = fmtmsg(MM_CONSOLE | MM_HARD | MM_OPSYS, "LTP:fmtmsg", 5,
			 "LTP fmtmsg() test3 message, NOT an error",
			 "This is correct output, no action needed",
			 "LTP:msg:003");
	if (ret_val != MM_OK) {
		fprintf(temp, "fmtmsg returned %d, expected MM_OK\n", ret_val);
		fprintf(temp, "failed to write to console\n\n");
		local_flag = FAILED;
	}

	blexit();
/*--------------------------------------------------------------*/
/* Clean up any files created by test before call to anyfail.   */

	anyfail();		/* THIS CALL DOES NOT RETURN - EXITS!!  */
	tst_exit();
}
Exemple #7
0
void R_InitSpriteDefs () 
{
	struct Hasher
	{
		int Head, Next;
	} *hashes;
	struct VHasher
	{
		int Head, Next, Name, Spin;
		char Frame;
	} *vhashes;
	unsigned int i, j, smax, vmax;
	DWORD intname;

	// Create a hash table to speed up the process
	smax = TexMan.NumTextures();
	hashes = new Hasher[smax];
	clearbuf(hashes, sizeof(Hasher)*smax/4, -1);
	for (i = 0; i < smax; ++i)
	{
		FTexture *tex = TexMan.ByIndex(i);
		if (tex->UseType == FTexture::TEX_Sprite && strlen(tex->Name) >= 6)
		{
			size_t bucket = TEX_DWNAME(tex) % smax;
			hashes[i].Next = hashes[bucket].Head;
			hashes[bucket].Head = i;
		}
	}

	// Repeat, for voxels
	vmax = Wads.GetNumLumps();
	vhashes = new VHasher[vmax];
	clearbuf(vhashes, sizeof(VHasher)*vmax/4, -1);
	for (i = 0; i < vmax; ++i)
	{
		if (Wads.GetLumpNamespace(i) == ns_voxels)
		{
			char name[9];
			size_t namelen;
			int spin;
			int sign;

			Wads.GetLumpName(name, i);
			name[8] = 0;
			namelen = strlen(name);
			if (namelen < 4)
			{ // name is too short
				continue;
			}
			if (name[4] != '\0' && name[4] != ' ' && (name[4] < 'A' || name[4] >= 'A' + MAX_SPRITE_FRAMES))
			{ // frame char is invalid
				continue;
			}
			spin = 0;
			sign = 2;	// 2 to convert from deg/halfsec to deg/sec
			j = 5;
			if (j < namelen && name[j] == '-')
			{ // a minus sign is okay, but only before any digits
				j++;
				sign = -2;
			}
			for (; j < namelen; ++j)
			{ // the remainder to the end of the name must be digits
				if (name[j] >= '0' && name[j] <= '9')
				{
					spin = spin * 10 + name[j] - '0';
				}
				else
				{
					break;
				}
			}
			if (j < namelen)
			{ // the spin part is invalid
				continue;
			}
			memcpy(&vhashes[i].Name, name, 4);
			vhashes[i].Frame = name[4];
			vhashes[i].Spin = spin * sign;
			size_t bucket = vhashes[i].Name % vmax;
			vhashes[i].Next = vhashes[bucket].Head;
			vhashes[bucket].Head = i;
		}
	}

	// scan all the lump names for each of the names, noting the highest frame letter.
	for (i = 0; i < sprites.Size(); ++i)
	{
		memset (sprtemp, 0xFF, sizeof(sprtemp));
		for (j = 0; j < MAX_SPRITE_FRAMES; ++j)
		{
			sprtemp[j].Flip = 0;
			sprtemp[j].Voxel = NULL;
		}
				
		maxframe = -1;
		intname = sprites[i].dwName;

		// scan the lumps, filling in the frames for whatever is found
		int hash = hashes[intname % smax].Head;
		while (hash != -1)
		{
			FTexture *tex = TexMan[hash];
			if (TEX_DWNAME(tex) == intname)
			{
				bool res = R_InstallSpriteLump (FTextureID(hash), tex->Name[4] - 'A', tex->Name[5], false);

				if (tex->Name[6] && res)
					R_InstallSpriteLump (FTextureID(hash), tex->Name[6] - 'A', tex->Name[7], true);
			}
			hash = hashes[hash].Next;
		}

		// repeat, for voxels
		hash = vhashes[intname % vmax].Head;
		while (hash != -1)
		{
			VHasher *vh = &vhashes[hash];
			if (vh->Name == (int)intname)
			{
				FVoxelDef *voxdef = R_LoadVoxelDef(hash, vh->Spin);
				if (voxdef != NULL)
				{
					if (vh->Frame == ' ' || vh->Frame == '\0')
					{ // voxel applies to every sprite frame
						for (j = 0; j < MAX_SPRITE_FRAMES; ++j)
						{
							if (sprtemp[j].Voxel == NULL)
							{
								sprtemp[j].Voxel = voxdef;
							}
						}
						maxframe = MAX_SPRITE_FRAMES-1;
					}
					else
					{ // voxel applies to a specific frame
						j = vh->Frame - 'A';
						sprtemp[j].Voxel = voxdef;
						maxframe = MAX<int>(maxframe, j);
					}
				}
			}
			hash = vh->Next;
		}
		
		R_InstallSprite ((int)i);
	}

	delete[] hashes;
	delete[] vhashes;
}
Exemple #8
0
void yylex(int c)
{
    switch (state) {
	case _S_:
	if (isalpha(c) || c == '_') {
	    save(c);
	    state = _A_;
	    ScoutAppAgentName = 1;
	} else if (isdigit(c)) {
	    save(c);
	    state = _D_;
	} else if (c == ' ' || c == '\t') {
	    state = _S_;
	} else if (c == '\n') {
	    state = _S_;
	} else if (c == '\r') {
	    state = _S_;
	} else if (c == '.') {
	    state = _DOT_;
	} else if (c == '"') {
	    state = _QUOTE_;
	} else if (c == '#') {
	    state = _HASH_;
	} else if (c == '&') {
	    state = _AND_;
	} else if (c == '|') {
	    state = _OR_;
	} else if (c == '=') {
	    state = _EQ_;
	} else if (c == '!') {
	    state = _NOT_;
	} else if (c == '<') {
	    state = _LT_;
	} else if (c == '>') {
	    state = _GT_;
	} else if (c == '/') {
	    state = _SLASH_;
	} else if (c == '~') {   /*  for agency -- sun */
	    state = _A_;
	    ScoutAppAgentName = 0;
	} else {
	    yyparse(c);
	    state = _S_;
	}
	break;
    case _A_:
	if (isalnum(c) || c == '_') {
	    save(c);
	    state = _A_;
	} else {
	    action_A();
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _D_:
	if (isdigit(c)) {
	    save(c);
	    state = _D_;
	} else if (c == '.') {
	    save(c);
	    state = _DDOT_;
	} else {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DDOT_:
	if (isdigit(c)) {
	    save(c);
	    state = _DDOTD_;
	} else if (c == '.') {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _DOT_;
	} else {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _DOT_;
	    yylex(c);
	}
	break;
    case _DDOTD_:
	if (isdigit(c)) {
	    save(c);
	    state = _DDOTD_;
	} else {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DOT_:
	if (c == ' ' || c == '\t') {
	    state = _DOT_;
	} else if (isalpha(c)) {
	    save(c);
	    state = _DOTA_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DOTA_:
	if (isalpha(c)) {
	    save(c);
	    state = _DOTA_;
	} else {
	    int         pos = search_field(yytext);

	    clearbuf();
	    yyparse(pos == -1 ? ERROR : fields[pos].token);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _QUOTE_:
	if (c == '"') {
	    yylval.s = strdup(yytext);
	    yyparse(STR);
	    clearbuf();
	    state = _S_;
	} else if (c == '\\') {
	    state = _QBSLASH_;
	} else {
	    save(c);
	    state = _QUOTE_;
	}
	break;
    case _QBSLASH_:
	switch (c) {
	case 'n':
	    save('\n');
	    break;
	case '\n':		/* ignore \newline */
	    break;
	default:
	    save(c);
	    break;
	}
	state = _QUOTE_;
	break;
    case _HASH_:
	state = c == '\n' ? _S_ : _HASH_;
	break;
    case _AND_:
	if (c == '&') {
	    yyparse(AND);
	    state = _S_;
	} else {
	    yyparse('&');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _OR_:
	if (c == '|') {
	    yyparse(OR);
	    state = _S_;
	} else {
	    yyparse('|');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _EQ_:
	if (c == '=') {
	    yyparse(EQ);
	    state = _S_;
	} else {
	    yyparse('=');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _NOT_:
	if (c == '=') {
	    yyparse(NE);
	    state = _S_;
	} else {
	    yyparse('!');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _LT_:
	if (c == '=') {
	    yyparse(LE);
	    state = _S_;
	} else {
	    yyparse(LT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _GT_:
	if (c == '=') {
	    yyparse(GE);
	    state = _S_;
	} else {
	    yyparse(GT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _SLASH_:
	if (c == '/') {
	    yyparse(CONCAT);
	    state = _S_;
	} else {
	    yyparse('/');
	    state = _S_;
	    yylex(c);
	}
	break;
    }
}
Exemple #9
0
void
pressanykey()
{
	refresh();
	clearbuf();
}
Exemple #10
0
void
winloop()
{
	int x, y, c, marked, t0, inited;
	char buf[100];
	x = 10;
	y = 8;
	inited = 0;
	marked = 0;
	clearbuf();
	t0 = time(0);
	while (1) {
		c = egetch();
		if (c == 257 && y > 1)
			y--;
		if (c == 258 && y < 16)
			y++;
		if (c == 260 && x > 1)
			x--;
		if (c == 259 && x < 30)
			x++;
		move(0, 20);
		sprintf(buf, "ʱ¼ä: %d ", (int) (time(0) - t0));
		prints(buf);
		move(40, 20);
		sprintf(buf, "񈬀: %d ", marked);
		prints(buf);
		move(0, 22);
		sprintf(buf, "×ø±ê: %3d, %3d", x, y);
		prints(buf);
		move(x * 2 - 2, y - 1);
		if (c == 'h' || c == 'H')
			winhelp();
		if (c == 'd' || c == 'D')
			winrefresh();
		if (c == 'a' || c == 'A') {
			if (!inited) {
				wininit(x, y);
				inited = 1;
			}
			dig(x, y);
		}
		if ((c == 83 || c == 115) && !o[x][y]) {
			if (m[x][y]) {
				m[x][y] = 0;
				marked--;
			} else {
				m[x][y] = 1;
				marked++;
			}
			winsh(x, y);
		}
		if (checkwin() == 1) {
			move(0, 22);
			prints("×£ºØÄ㣡Äã³É¹¦ÁË£¡                    ");
			{
				char buf[100];
				sprintf(buf, "finished in %d s.",
					(int) (time(0) - t0));
				win_checkrec(time(0) - t0);
				winminelog(buf);
			}
			gameover = 0;
			return;
		}
		if (gameover) {
			move(0, 22);
			prints("ºÜÒź¶£¬Äãʧ°ÜÁË... ÔÙÀ´Ò»´Î°É£¡    ");
			{
				char buf[100];
				sprintf(buf, "failed in %d s.",
					(int) (time(0) - t0));
				winminelog(buf);
			}
			gameover = 0;
			return;
		}
		move(x * 2 - 2, y - 1);
		refresh();
	}
}
Exemple #11
0
int winloop()
{
    int x, y, c, marked, t0, inited;
    char buf[100];
    x= 10;
    y= 8;
    inited= 0; 
    marked= 0; 
    clearbuf();
    t0= time(0);
    while(1) {
        c= egetch();
        if((c==257||c=='k')&&y>1) y--;
        if((c==258||c=='j')&&y<16) y++;
        if((c==260||c=='h')&&x>1) x--;
        if((c==259||c=='l')&&x<30) x++;
        move(0, 20);
        //% sprintf(buf, "时间: %ld ", time(0)-t0);
        sprintf(buf, "\xca\xb1\xbc\xe4: %ld ", time(0)-t0);
        prints(buf);
        move(40, 20);
        //% sprintf(buf, "标记: %d ", marked);
        sprintf(buf, "\xb1\xea\xbc\xc7: %d ", marked);
        prints(buf);
        move(0, 21);
        //% sprintf(buf, "坐标: %3d, %3d", x, y);
        sprintf(buf, "\xd7\xf8\xb1\xea: %3d, %3d", x, y);
        prints(buf);
        move(x*2-2, y-1);
        if(c=='H') winhelp();
        if(c=='d'|| c=='D') winrefresh();
        if(c=='f'|| c=='F'){
             if(!inited) {
                  wininit(x, y);
                  inited= 1;
             } 
             dig(x, y);      
        } 
        if((c==83|| c==115)&&!o[x][y]) {
             if(m[x][y]){
                  m[x][y]=0;
                  marked--;
             } else {
                  m[x][y]=1;
                  marked++;
             }
             winsh(x, y);
        }
        if(checkwin()==1) {
            move(0, 22);
            //% prints("祝贺你!你成功了!                    ");
            prints("\xd7\xa3\xba\xd8\xc4\xe3\xa3\xa1\xc4\xe3\xb3\xc9\xb9\xa6\xc1\xcb\xa3\xa1                    ");
            {  char buf[100];
               sprintf(buf, "finished in %ld s.", time(0)-t0);
               syslog(buf);
            }
            gameover= 0;
 	    win_checkrec(time(0)-t0);/* added by soff 进行排行检查 */
            return;
        }
        if(gameover) {
            move(0, 22);
            //% prints("很遗憾,你失败了... 再来一次吧!                                 ");
            prints("\xba\xdc\xd2\xc5\xba\xb6\xa3\xac\xc4\xe3\xca\xa7\xb0\xdc\xc1\xcb... \xd4\xd9\xc0\xb4\xd2\xbb\xb4\xce\xb0\xc9\xa3\xa1                                 ");
            {  char buf[100];
               sprintf(buf, "failed in %ld s.", time(0)-t0);
               syslog(buf);
            }
            gameover= 0;
            return;
        }
        move(x*2-2, y-1);
        refresh();
    }
}